pointer-acceleration.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. .. _pointer-acceleration:
  2. ==============================================================================
  3. Pointer acceleration
  4. ==============================================================================
  5. libinput uses device-specific pointer acceleration methods, with the default
  6. being the :ref:`ptraccel-linear`. The methods share common properties, such as
  7. :ref:`ptraccel-velocity`.
  8. This page explains the high-level concepts used in the code. It aims to
  9. provide an overview for developers and is not necessarily useful for
  10. users.
  11. .. _ptraccel-profiles:
  12. ------------------------------------------------------------------------------
  13. Pointer acceleration profiles
  14. ------------------------------------------------------------------------------
  15. The profile decides the general method of pointer acceleration.
  16. libinput currently supports three profiles: **"adaptive"**, **"flat"** and
  17. **"custom"**.
  18. - The **adaptive** profile is the default profile for all devices and takes the
  19. current speed of the device into account when deciding on acceleration.
  20. - The **flat** profile is simply a constant factor applied to all device deltas,
  21. regardless of the speed of motion (see :ref:`ptraccel-profile-flat`).
  22. - The **custom** profile allows the user to define a custom acceleration
  23. function, giving full control over accelerations behavior at different speed
  24. (see :ref:`ptraccel-profile-custom`).
  25. Most of this document describes the adaptive pointer acceleration.
  26. .. _ptraccel-velocity:
  27. ------------------------------------------------------------------------------
  28. Velocity calculation
  29. ------------------------------------------------------------------------------
  30. The device's speed of movement is measured across multiple input events
  31. through so-called "trackers". Each event prepends a tracker item, each
  32. subsequent tracker contains the delta of that item to the current position,
  33. the timestamp of the event that created it and the cardinal direction of the
  34. movement at the time. If a device moves into the same direction, the
  35. velocity is calculated across multiple trackers. For example, if a device
  36. moves steadily for 10 events to the left, the velocity is calculated across
  37. all 10 events.
  38. Whenever the movement changes direction or significantly changes speed, the
  39. velocity is calculated from the direction/speed change only. For example, if
  40. a device moves steadily for 8 events to the left and then 2 events to the
  41. right, the velocity is only that of the last 2 events.
  42. An extra time limit prevents events that are too old to factor into the
  43. velocity calculation. For example, if a device moves steadily for 5 events
  44. to the left, then pauses, then moves again for 5 events to the left, only
  45. the last 5 events are used for velocity calculation.
  46. The velocity is then used to calculate the acceleration factor
  47. .. _ptraccel-factor:
  48. ------------------------------------------------------------------------------
  49. Acceleration factor
  50. ------------------------------------------------------------------------------
  51. The acceleration factor is the final outcome of the pointer acceleration
  52. calculations. It is a unitless factor that is applied to the current delta,
  53. a factor of 2 doubles the delta (i.e. speeds up the movement), a factor of
  54. less than 1 reduces the delta (i.e. slows the movement).
  55. Any factor less than 1 requires the user to move the device further to move
  56. the visible pointer. This is called deceleration and enables high precision
  57. target selection through subpixel movements. libinput's current maximum
  58. deceleration factor is 0.3 (i.e. slow down to 30% of the pointer speed).
  59. A factor higher than 1 moves the pointer further than the physical device
  60. moves. This is acceleration and allows a user to cross the screen quickly
  61. but effectively skips pixels. libinput's current maximum acceleration factor
  62. is 3.5.
  63. .. _ptraccel-linear:
  64. ------------------------------------------------------------------------------
  65. Linear pointer acceleration
  66. ------------------------------------------------------------------------------
  67. The linear pointer acceleration method is the default for most pointer
  68. devices. It provides deceleration at very slow movements, a 1:1 mapping for
  69. regular movements and a linear increase to the maximum acceleration factor
  70. for fast movements.
  71. Linear pointer acceleration applies to devices with above 1000dpi resolution
  72. and after :ref:`motion_normalization` is applied.
  73. .. figure:: ptraccel-linear.svg
  74. :align: center
  75. Linear pointer acceleration
  76. The image above shows the linear pointer acceleration settings at various
  77. speeds. The line for 0.0 is the default acceleration curve, speed settings
  78. above 0.0 accelerate sooner, faster and to a higher maximum acceleration.
  79. Speed settings below 0 delay when acceleration kicks in, how soon the
  80. maximum acceleration is reached and the maximum acceleration factor.
  81. Extremely low speed settings provide no acceleration and additionally
  82. decelerate all movement by a constant factor.
  83. .. _ptraccel-low-dpi:
  84. ------------------------------------------------------------------------------
  85. Pointer acceleration for low-dpi devices
  86. ------------------------------------------------------------------------------
  87. Low-dpi devices are those with a physical resolution of less than 1000 dots
  88. per inch (dpi). The pointer acceleration is adjusted to provide roughly the
  89. same feel for all devices at normal to high speeds. At slow speeds, the
  90. pointer acceleration works on device-units rather than normalized
  91. coordinates (see :ref:`motion_normalization`).
  92. .. figure:: ptraccel-low-dpi.svg
  93. :align: center
  94. Pointer acceleration for low-dpi devices
  95. The image above shows the default pointer acceleration curve for a speed of
  96. 0.0 at different DPI settings. A device with low DPI has the acceleration
  97. applied sooner and with a stronger acceleration factor.
  98. .. _ptraccel-touchpad:
  99. ------------------------------------------------------------------------------
  100. Pointer acceleration on touchpads
  101. ------------------------------------------------------------------------------
  102. Touchpad pointer acceleration uses the same approach as the
  103. :ref:`ptraccel-linear` profile, with a constant deceleration factor applied. The
  104. user expectation of how much a pointer should move in response to finger
  105. movement is different to that of a mouse device, hence the constant
  106. deceleration factor.
  107. .. figure:: ptraccel-touchpad.svg
  108. :align: center
  109. Pointer acceleration curve for touchpads
  110. The image above shows the touchpad acceleration profile in comparison to the
  111. :ref:`ptraccel-linear`. The shape of the curve is identical but vertically squashed.
  112. .. _ptraccel-trackpoint:
  113. ------------------------------------------------------------------------------
  114. Pointer acceleration on trackpoints
  115. ------------------------------------------------------------------------------
  116. The main difference between trackpoint hardware and mice or touchpads is
  117. that trackpoint speed is a function of pressure rather than moving speed.
  118. But trackpoint hardware is quite varied in how it reacts to user pressure
  119. and unlike other devices it cannot easily be normalized for physical
  120. properties. Measuring pressure objectively across a variety of hardware is
  121. nontrivial. See :ref:`trackpoints` for more details.
  122. The deltas for trackpoints are converted units/ms but there is no common
  123. physical reference point for a unit. Thus, the same pressure on different
  124. trackpoints will generate different speeds and thus different acceleration
  125. behaviors. Additionally, some trackpoints provide the ability to adjust the
  126. sensitivity in hardware by modifying a sysfs file on the serio node. A
  127. higher sensitivity results in higher deltas, thus changing the definition of
  128. what is a unit again.
  129. libinput attempts to normalize unit data to the best of its abilities, see
  130. :ref:`trackpoint_multiplier`. Beyond this, it is not possible to have
  131. consistent behavior across different trackpoint devices.
  132. .. figure:: ptraccel-trackpoint.svg
  133. :align: center
  134. Pointer acceleration curves for trackpoints
  135. The image above shows the trackpoint acceleration profile for the speed in
  136. units/ms.
  137. .. _ptraccel-profile-flat:
  138. ------------------------------------------------------------------------------
  139. The flat pointer acceleration profile
  140. ------------------------------------------------------------------------------
  141. In a flat profile, the acceleration factor is constant regardless of the
  142. velocity of the pointer and each delta (dx, dy) results in an accelerated delta
  143. (dx * factor, dy * factor). This provides 1:1 movement between the device
  144. and the pointer on-screen.
  145. .. _ptraccel-tablet:
  146. ------------------------------------------------------------------------------
  147. Pointer acceleration on tablets
  148. ------------------------------------------------------------------------------
  149. Pointer acceleration for relative motion on tablet devices is a flat
  150. acceleration, with the speed setting slowing down or speeding up the pointer
  151. motion by a constant factor. Tablets do not allow for switchable profiles.
  152. .. _ptraccel-profile-custom:
  153. ------------------------------------------------------------------------------
  154. The custom acceleration profile
  155. ------------------------------------------------------------------------------
  156. libinput supports a user-defined custom acceleration profile, which can be
  157. adjusted for different movement types supported by a device. Movement types
  158. include pointer movement, scrolling, etc. but the set of supported
  159. movement types depends on the device.
  160. The custom pointer acceleration profile gives users full control over the
  161. acceleration behavior at different speeds. libinput exposes
  162. an acceleration function ``f(x)`` where the x axis is the device speed in
  163. device units per millisecond and the y axis is the pointer speed. By
  164. supplying the y axis values for this function, users can control the
  165. behavior of the device.
  166. The user should take into account the native device dpi and screen dpi in
  167. order to achieve the desired behavior/feel.
  168. The custom acceleration function is defined using ``n`` points which are spaced
  169. uniformly along the x axis, starting from 0 and continuing in constant steps.
  170. At least two points must be defined and there is an implementation-defined
  171. limit on how many points may be added.
  172. Thus the points defining the custom function are:
  173. ``(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])``
  174. where ``f`` is a list of ``n`` values defining the output velocity for each
  175. input velocity.
  176. The acceleration factor is defined by the ratio of the output velocity to the
  177. input velocity.
  178. When a velocity value does not lie exactly on those points, a linear
  179. interpolation of the two closest points will be calculated.
  180. When a velocity value is greater than the max point defined, a linear
  181. extrapolation of the two biggest points will be calculated.
  182. the calculation made by libinput: ::
  183. input_delta = device delta units
  184. delta_time = time in ms since last input_delta
  185. input_speed = hypot(input_delta) / delta_time
  186. output_speed = user_custom_function(input_speed)
  187. acceleration_factor = output_speed / input_speed
  188. output_delta = input_delta * acceleration_factor
  189. An example is the curve of ``0.0, 1.0`` with a step of ``1.0``. This curve
  190. is the equivalent of the flat acceleration profile with any input speed ``N``
  191. mapped to the same pointer speed ``N``. The curve ``1.0, 1.0`` neutralizes
  192. any input speed differences and results in a fixed pointer speed.
  193. Another example is the custom acceleration function ``x**2``,
  194. sampling the function at ``4`` points up to
  195. a maximum input speed of ``9`` will give us a custom function with
  196. a step of ``3`` and points ``[0.0, 9.0, 36.0, 81.0]``:
  197. .. figure:: ptraccel-custom.svg
  198. :align: center
  199. More sampled points can be added to improve the accuracy of the user custom
  200. function.
  201. Supported Movement types:
  202. +---------------+---------------------------------+----------------------+
  203. | Movement type | Uses | supported by |
  204. +===============+=================================+======================+
  205. | Fallback | Catch-all default movement type | All devices |
  206. +---------------+---------------------------------+----------------------+
  207. | Motion | Used for pointer motion | All devices |
  208. +---------------+---------------------------------+----------------------+
  209. | Scroll | Used for scroll movement | Mouse, Touchpad |
  210. +---------------+---------------------------------+----------------------+
  211. If a user does not provide the fallback custom acceleration function, a
  212. flat acceleration function is used, i.e. no acceleration.
  213. The fallback acceleration may be used for different types of movements, it is
  214. strongly recommended that this acceleration function is a constant function.
  215. For example, a touchpad has multiple movement types: pointer
  216. movement, scroll movement, zoom movement (pinch), etc. As there is no separate
  217. movement type for zoom yet, zoom movement is accelerated using the Fallback
  218. acceleration function. Pointer movement is accelerated using the Motion
  219. acceleration function, and Scroll movement is accelerated using the Scroll
  220. acceleration function. If no Motion/Scroll acceleration function is set, the
  221. Fallback acceleration function is used.
  222. When using custom acceleration profile, any calls to set the speed have no
  223. effect on the behavior of the custom acceleration function, but any future calls to
  224. get the speed will reflect the requested speed setting.