1
0

gestures.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. .. _gestures:
  2. ==============================================================================
  3. Gestures
  4. ==============================================================================
  5. libinput supports :ref:`gestures_pinch` and :ref:`gestures_swipe` on most
  6. modern touchpads and other indirect touch devices. Note that libinput **does
  7. not** support gestures on touchscreens, see :ref:`gestures_touchscreens`.
  8. .. _gestures_lifetime:
  9. -----------------------------------------------------------------------------
  10. Lifetime of a gesture
  11. -----------------------------------------------------------------------------
  12. A gesture starts when the finger position and/or finger motion is
  13. unambiguous as to what gesture to trigger and continues until the first
  14. finger belonging to this gesture is lifted.
  15. A single gesture cannot change the finger count. For example, if a user
  16. puts down a fourth finger during a three-finger swipe gesture, libinput will
  17. end (cancel) the three-finger gesture and, if applicable, start a
  18. four-finger swipe gesture. A caller may however decide that those gestures
  19. are semantically identical and continue the two gestures as one single
  20. gesture.
  21. .. _gestures_pinch:
  22. ------------------------------------------------------------------------------
  23. Pinch gestures
  24. ------------------------------------------------------------------------------
  25. Pinch gestures are executed when two or more fingers are located on the
  26. touchpad and are either changing the relative distance to each other
  27. (pinching) or are changing the relative angle (rotate). Pinch gestures may
  28. change both rotation and distance at the same time. For such gestures,
  29. libinput calculates a logical center for the gestures and provides the
  30. caller with the delta x/y coordinates of that center, the relative angle of
  31. the fingers compared to the previous event, and the absolute scale compared
  32. to the initial finger position.
  33. .. figure:: pinch-gestures.svg
  34. :align: center
  35. The pinch and rotate gestures
  36. The illustration above shows a basic pinch in the left image and a rotate in
  37. the right angle. Not shown is a movement of the logical center if the
  38. fingers move unevenly. Such a movement is supported by libinput, it is
  39. merely left out of the illustration.
  40. Note that while position and angle is relative to the previous event, the
  41. scale is always absolute and a multiplier of the initial finger position's
  42. scale.
  43. .. _gestures_swipe:
  44. ------------------------------------------------------------------------------
  45. Swipe gestures
  46. ------------------------------------------------------------------------------
  47. Swipe gestures are executed when three or more fingers are moved
  48. synchronously in the same direction. libinput provides x and y coordinates
  49. in the gesture and thus allows swipe gestures in any direction, including
  50. the tracing of complex paths. It is up to the caller to interpret the
  51. gesture into an action or limit a gesture to specific directions only.
  52. .. figure:: swipe-gestures.svg
  53. :align: center
  54. The swipe gestures
  55. The illustration above shows a vertical three-finger swipe. The coordinates
  56. provided during the gesture are the movements of the logical center.
  57. .. _gestures_hold:
  58. ------------------------------------------------------------------------------
  59. Hold gestures
  60. ------------------------------------------------------------------------------
  61. A hold gesture is one where the user places one or more fingers on the
  62. device without significant movement. The exact conditions when a hold gesture
  63. transitions to pointer motion, scrolling or other gestures
  64. are implementation-defined.
  65. The hold gesture is intended to allow for the implementation of two specific
  66. features:
  67. - where a two-finger scrolling starts kinetic scrolling in the caller, a
  68. subsequent hold gesture can be used to stop that kinetic scroll motion,
  69. and
  70. - hold-to-trigger interactions where the interaction could be a click, a
  71. context menu, or some other context-specific interaction.
  72. Hold gestures have three potential logical states:
  73. - **begin**: one or more fingers are placed on the device at the same time
  74. - **end**: all fingers are removed and the device enters a neutral logical state
  75. - **end(cancelled)**: all fingers are part of a known interaction and the
  76. current hold gesture is no longer active. This may also occur when
  77. switching between hold gestures with different finger counts.
  78. .. note:: By definition, a hold gesture does not move and thus no coordinate
  79. updates are available.
  80. For example, a user that puts one finger, then a second finger down and
  81. releases them later may trigger the following event sequence:
  82. ============= ============== ============
  83. Action Event Finger count
  84. ============= ============== ============
  85. Finger 1 down **begin** 1
  86. Finger 2 down **cancel** 1
  87. \ **begin** 2
  88. Finger 2 up **end** 2
  89. Finger 1 up <no event>
  90. ============= ============== ============
  91. A hold gesture may by be **cancelled**. This occurs
  92. when the hold gesture changes into some other interaction and should no
  93. longer be considered the current hold gesture. A **end(cancelled)** event
  94. applies to the whole gesture (all fingers). For example, a pointer motion on
  95. a touchpad may trigger this sequence:
  96. +-------------------+-----------------------+
  97. | Action | Event |
  98. +===================+=======================+
  99. | | Finger 1 down | | **hold begin** |
  100. +-------------------+-----------------------+
  101. | | Finger 1 motion | | **hold cancel** |
  102. | | | | **pointer motion** |
  103. +-------------------+-----------------------+
  104. | | Finger 1 motion | | **pointer motion** |
  105. +-------------------+-----------------------+
  106. | | Finger 1 up | | *no event* |
  107. +-------------------+-----------------------+
  108. .. note:: Many interactions with a touchpad will start with a hold
  109. gesture that is then cancelled as that gesture turns into e.g.
  110. pointer motion. A caller **must** handle hold gesture
  111. cancellations correctly.
  112. A two-finger scroll motion on a touchpad may trigger this sequence:
  113. +------------------------+---------------------+--------------+
  114. | Action | Event | Finger count |
  115. +========================+=====================+==============+
  116. | | Finger 1 down | | **hold begin** | | 1 |
  117. +------------------------+---------------------+--------------+
  118. | | Finger 2 down | | **hold cancel** | | 1 |
  119. | | | | **hold begin** | | 2 |
  120. +------------------------+---------------------+--------------+
  121. | | Finger 1+2 motion | | **hold cancel** | | 2 |
  122. | | | | **pointer axis** | | |
  123. +------------------------+---------------------+--------------+
  124. | | Finger 1+2 motion | | **pointer axis** | |
  125. +------------------------+---------------------+--------------+
  126. | | Finger 1 up | | **pointer axis** | |
  127. | | Finger 2 up | | (scroll stop) | |
  128. +------------------------+---------------------+--------------+
  129. A three-finger-swipe on a touchpad may trigger this sequence:
  130. +---------------------+---------------------+--------------+
  131. | Action | Event | Finger count |
  132. +=====================+=====================+==============+
  133. | | Finger 1 down | | **hold begin** | | 1 |
  134. +---------------------+---------------------+--------------+
  135. | | Finger 2 down | | **hold cancel** | | 1 |
  136. | | | | **hold begin** | | 2 |
  137. +---------------------+---------------------+--------------+
  138. | | Finger 3 down | | **hold cancel** | | 2 |
  139. | | | | **hold begin** | | 3 |
  140. +---------------------+---------------------+--------------+
  141. | | Finger motion | | **hold cancel** | | 3 |
  142. | | | | **swipe begin** | | 3 |
  143. +---------------------+---------------------+--------------+
  144. | | Finger motion | | **swipe update** | | 3 |
  145. +---------------------+---------------------+--------------+
  146. | | Finger 1 up | | **swipe end** | | 3 |
  147. | | Finger 2 up | | | | |
  148. | | Finger 3 up | | | | |
  149. +---------------------+---------------------+--------------+
  150. Single-finger hold gestures
  151. ...........................
  152. libinput uses implementation-defined timeouts based on other interactions
  153. to determine whether a single-finger hold gestures should start. In other
  154. words, a caller **must not** rely on a hold gesture always being triggered
  155. as soon as a single finger is placed on the touchpad. This is true for any
  156. hold gesture but especially so for single-finger hold gestures.
  157. Hold gestures with a single finger are prone to being extremely short-lived.
  158. On many devices it is impossible to hold a finger still enough for there to
  159. be no pointer motion events, even if those deltas are miniscule. Changing
  160. movement thresholds to rely on hold gestures would reduce device
  161. responsiveness.
  162. It is thus the responsibility of the caller to determine where hold gestures
  163. transition in and out of other interactions. For example, a two-finger hold
  164. may produce a cancelled single-finger hold gesture first:
  165. +--------------------+----------------------+--------------+--------------+
  166. | Action | Event | Finger count | Notes |
  167. +====================+======================+==============+==============+
  168. | | Finger 1 down | | **hold begin** | | 1 | |
  169. +--------------------+----------------------+--------------+--------------+
  170. | | Finger 1 motion | | **hold cancel** | | 1 | | tiny deltas|
  171. | | | | **pointer motion** | | | | |
  172. +--------------------+----------------------+--------------+--------------+
  173. | | Finger 2 down | | **hold begin** | | 2 | |
  174. +--------------------+----------------------+--------------+--------------+
  175. | | Finger 1 up | | **hold end** | | | |
  176. | | Finger 2 up | | | | | |
  177. +--------------------+----------------------+--------------+--------------+
  178. Note how the second hold gesture started with a finger count of 2 - without
  179. the user ever lifting the first finger. Cancellation of hold gesture does
  180. not imply the user has lifted a finger.
  181. A hold gesture may start after a previous gesture completed. For example, a
  182. single finger move-and-hold may trigger different sequences for the same
  183. user interaction:
  184. +--------------------+---------------------+-------------------+--------------+
  185. | Action | Device 1 | Device 2 | Notes |
  186. +====================+=====================+===================+==============+
  187. | | Finger 1 down | | **hold begin** | | **hold begin** | |
  188. +--------------------+---------------------+-------------------+--------------+
  189. | | Finger 1 motion | | **hold cancel** | | | tiny deltas|
  190. | | | **pointer motion**| | | |
  191. +--------------------+---------------------+-------------------+--------------+
  192. | | | **hold begin** | | |
  193. +--------------------+---------------------+-------------------+--------------+
  194. | | Finger 1 up | | **hold end** | | **hold end** | |
  195. +--------------------+---------------------+-------------------+--------------+
  196. A caller that wants to use hold gestures must thus be able to infer the same
  197. interaction based on a stream of pointer motion events with small deltas.
  198. libinput may start a new hold begin gesture once the pointer stops moving.
  199. The time between the last pointer motion event and the hold begin event is
  200. implementation-defined.
  201. Hold gestures and thumb/palm detection
  202. ......................................
  203. Thumb and palm detection effectively remove touches from being counted
  204. towards an interaction, see :ref:`thumb_detection` and
  205. :ref:`palm_detection` for details.
  206. In the context of hold gestures, thumbs and palms are treated by libinput as
  207. if the finger was removed from the device. Where other non-thumb/non-palm
  208. fingers remain on the device, the current hold gesture is cancelled and a
  209. new **hold begin** event with the updated finger count is sent. Otherwise,
  210. the hold gesture terminates with a **hold cancel** event.
  211. Notably, libinput's thumb and palm detection is not a simple boolean per
  212. touch but specific to the state of that touch in the overall context. For
  213. example, a touch may be a thumb for tapping but not for clickfinger
  214. interactions. A caller must not infer the number of physical fingers from
  215. the hold gesture.
  216. Likewise, libinput may classify a finger as thumb in the same hardware event
  217. as a new finger is placed on the touchpad. In that case, the hold gesture
  218. **may** continue as one-finger gesture despite there being two physical
  219. touch points.
  220. Information to determine whether a touch is a thumb or a palm may not be
  221. available until some time into an interaction. Thus very short brushes
  222. of the touchpad by a palm may trigger a **hold begin** followed by an
  223. immediate **hold end** as libinput lacks sufficient information to identify
  224. the touch as thumb/palm and send the corresponding **hold cancel**
  225. event. A caller must not assume that a hold gesture always represents a
  226. valid finger down.
  227. Hold gestures and tap-to-click
  228. ..............................
  229. :ref:`tapping` is the feature that enables short-lived touches to trigger
  230. button presses.
  231. .. warning:: Summary: do not use hold gestures to do your own tap-to-click
  232. implementation
  233. In the context of hold gestures, tap-to-click cancels current hold gestures
  234. and a finger dragging (see :ref:`tapndrag`) does not begin a hold
  235. gesture. Where tap-to-click is disabled a tap-like gesture may create
  236. **hold begin** followed by a **hold end** event. Callers **must not** use
  237. hold gestures for their own tap-to-click implementation as the data is not
  238. reliable enough. libinput may change internal timeouts and thresholds
  239. depending on whether tap-to-click is enabled and the hold gesture event may
  240. not match touch sequences that a user would expect to be a tap-to-click
  241. interaction.
  242. .. _gestures_touchscreens:
  243. ------------------------------------------------------------------------------
  244. Touchscreen gestures
  245. ------------------------------------------------------------------------------
  246. Touchscreen gestures are **not** interpreted by libinput. Rather, any touch
  247. point is passed to the caller and any interpretation of gestures is up to
  248. the caller or, eventually, the X or Wayland client.
  249. Interpreting gestures on a touchscreen requires context that libinput does
  250. not have, such as the location of windows and other virtual objects on the
  251. screen as well as the context of those virtual objects:
  252. .. figure:: touchscreen-gestures.svg
  253. :align: center
  254. Context-sensitivity of touchscreen gestures
  255. In the above example, the finger movements are identical but in the left
  256. case both fingers are located within the same window, thus suggesting an
  257. attempt to zoom. In the right case both fingers are located on a window
  258. border, thus suggesting a window movement. libinput has no knowledge of the
  259. window coordinates and thus cannot differentiate the two.
  260. .. _gestures_softbuttons:
  261. ------------------------------------------------------------------------------
  262. Gestures with enabled software buttons
  263. ------------------------------------------------------------------------------
  264. If the touchpad device is a :ref:`Clickpad <touchpads_buttons_clickpads>`, it
  265. is recommended that a caller switches to :ref:`clickfinger`.
  266. Usually fingers placed in a :ref:`software button area <software_buttons>`
  267. are not considered for gestures, resulting in some gestures to be
  268. interpreted as pointer motion or two-finger scroll events.
  269. .. figure:: pinch-gestures-softbuttons.svg
  270. :align: center
  271. Interference of software buttons and pinch gestures
  272. In the example above, the software button area is highlighted in red. The
  273. user executes a three-finger pinch gesture, with the thumb remaining in the
  274. software button area. libinput ignores fingers within the software button
  275. areas, the movement of the remaining fingers is thus interpreted as a
  276. two-finger scroll motion.
  277. .. _gestures_twofinger_touchpads:
  278. ------------------------------------------------------------------------------
  279. Gestures on two-finger touchpads
  280. ------------------------------------------------------------------------------
  281. As of kernel 4.2, many :ref:`touchpads_touch_partial_mt` provide only two
  282. slots. This affects how gestures can be interpreted. Touchpads with only two
  283. slots can identify two touches by position but can usually tell that there
  284. is a third (or fourth) finger down on the touchpad - without providing
  285. positional information for that finger.
  286. Touchpoints are assigned in sequential order and only the first two touch
  287. points are trackable. For libinput this produces an ambiguity where it is
  288. impossible to detect whether a gesture is a pinch gesture or a swipe gesture
  289. whenever a user puts the index and middle finger down first. Since the third
  290. finger does not have positional information, its location cannot be
  291. determined.
  292. .. figure:: gesture-2fg-ambiguity.svg
  293. :align: center
  294. Ambiguity of three-finger gestures on two-finger touchpads
  295. The image above illustrates this ambiguity. The index and middle finger are
  296. set down first, the data stream from both finger positions looks identical.
  297. In this case, libinput assumes the fingers are in a horizontal arrangement
  298. (the right image above) and use a swipe gesture.