1
0

test-gestures.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330
  1. /*
  2. * Copyright © 2015 Red Hat, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <config.h>
  24. #include <libinput.h>
  25. #include <valgrind/valgrind.h>
  26. #include "libinput-util.h"
  27. #include "litest.h"
  28. enum cardinal { N, NE, E, SE, S, SW, W, NW, NCARDINALS };
  29. enum hold_gesture_behaviour {
  30. HOLD_GESTURE_IGNORE,
  31. HOLD_GESTURE_REQUIRE,
  32. };
  33. static enum litest_runner_result
  34. test_gesture_swipe_3fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
  35. {
  36. struct litest_device *dev = litest_current_device();
  37. struct libinput *li = dev->libinput;
  38. struct libinput_event *event;
  39. struct libinput_event_gesture *gevent;
  40. double dx, dy;
  41. double dir_x, dir_y;
  42. int cardinals[NCARDINALS][2] = {
  43. { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
  44. { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
  45. };
  46. if (litest_slot_count(dev) < 3)
  47. return LITEST_NOT_APPLICABLE;
  48. dir_x = cardinals[cardinal][0];
  49. dir_y = cardinals[cardinal][1];
  50. litest_drain_events(li);
  51. litest_touch_down(dev, 0, 40, 40);
  52. litest_touch_down(dev, 1, 50, 40);
  53. litest_touch_down(dev, 2, 60, 40);
  54. litest_dispatch(li);
  55. if (hold == HOLD_GESTURE_REQUIRE)
  56. litest_timeout_gesture_hold(li);
  57. litest_touch_move_three_touches(dev, 40, 40, 50, 40, 60, 40, dir_x, dir_y, 10);
  58. litest_dispatch(li);
  59. if (hold == HOLD_GESTURE_REQUIRE) {
  60. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 3);
  61. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 3);
  62. }
  63. event = libinput_get_event(li);
  64. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
  65. dx = libinput_event_gesture_get_dx(gevent);
  66. dy = libinput_event_gesture_get_dy(gevent);
  67. litest_assert(dx == 0.0);
  68. litest_assert(dy == 0.0);
  69. libinput_event_destroy(event);
  70. while ((event = libinput_get_event(li)) != NULL) {
  71. gevent = litest_is_gesture_event(event,
  72. LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
  73. 3);
  74. dx = libinput_event_gesture_get_dx(gevent);
  75. dy = libinput_event_gesture_get_dy(gevent);
  76. if (dir_x == 0.0)
  77. litest_assert(dx == 0.0);
  78. else if (dir_x < 0.0)
  79. litest_assert(dx < 0.0);
  80. else if (dir_x > 0.0)
  81. litest_assert(dx > 0.0);
  82. if (dir_y == 0.0)
  83. litest_assert(dy == 0.0);
  84. else if (dir_y < 0.0)
  85. litest_assert(dy < 0.0);
  86. else if (dir_y > 0.0)
  87. litest_assert(dy > 0.0);
  88. dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
  89. dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
  90. if (dir_x == 0.0)
  91. litest_assert(dx == 0.0);
  92. else if (dir_x < 0.0)
  93. litest_assert(dx < 0.0);
  94. else if (dir_x > 0.0)
  95. litest_assert(dx > 0.0);
  96. if (dir_y == 0.0)
  97. litest_assert(dy == 0.0);
  98. else if (dir_y < 0.0)
  99. litest_assert(dy < 0.0);
  100. else if (dir_y > 0.0)
  101. litest_assert(dy > 0.0);
  102. libinput_event_destroy(event);
  103. }
  104. litest_touch_up(dev, 0);
  105. litest_touch_up(dev, 1);
  106. litest_touch_up(dev, 2);
  107. litest_dispatch(li);
  108. event = libinput_get_event(li);
  109. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3);
  110. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  111. libinput_event_destroy(event);
  112. return LITEST_PASS;
  113. }
  114. static enum litest_runner_result
  115. test_gesture_swipe_4fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
  116. {
  117. struct litest_device *dev = litest_current_device();
  118. struct libinput *li = dev->libinput;
  119. struct libinput_event *event;
  120. struct libinput_event_gesture *gevent;
  121. double dx, dy;
  122. double dir_x, dir_y;
  123. int cardinals[NCARDINALS][2] = {
  124. { 0, 3 }, { 3, 3 }, { 3, 0 }, { 3, -3 },
  125. { 0, -3 }, { -3, -3 }, { -3, 0 }, { -3, 3 },
  126. };
  127. int i;
  128. if (litest_slot_count(dev) < 4)
  129. return LITEST_NOT_APPLICABLE;
  130. dir_x = cardinals[cardinal][0];
  131. dir_y = cardinals[cardinal][1];
  132. litest_drain_events(li);
  133. litest_touch_down(dev, 0, 40, 40);
  134. litest_touch_down(dev, 1, 50, 40);
  135. litest_touch_down(dev, 2, 60, 40);
  136. litest_touch_down(dev, 3, 70, 40);
  137. litest_dispatch(li);
  138. if (hold == HOLD_GESTURE_REQUIRE)
  139. litest_timeout_gesture_hold(li);
  140. for (i = 0; i < 8; i++) {
  141. litest_push_event_frame(dev);
  142. dir_x += cardinals[cardinal][0];
  143. dir_y += cardinals[cardinal][1];
  144. litest_touch_move(dev, 0, 40 + dir_x, 40 + dir_y);
  145. litest_touch_move(dev, 1, 50 + dir_x, 40 + dir_y);
  146. litest_touch_move(dev, 2, 60 + dir_x, 40 + dir_y);
  147. litest_touch_move(dev, 3, 70 + dir_x, 40 + dir_y);
  148. litest_pop_event_frame(dev);
  149. litest_dispatch(li);
  150. }
  151. litest_dispatch(li);
  152. if (hold == HOLD_GESTURE_REQUIRE) {
  153. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 4);
  154. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 4);
  155. }
  156. event = libinput_get_event(li);
  157. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 4);
  158. dx = libinput_event_gesture_get_dx(gevent);
  159. dy = libinput_event_gesture_get_dy(gevent);
  160. litest_assert(dx == 0.0);
  161. litest_assert(dy == 0.0);
  162. libinput_event_destroy(event);
  163. while ((event = libinput_get_event(li)) != NULL) {
  164. gevent = litest_is_gesture_event(event,
  165. LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
  166. 4);
  167. dx = libinput_event_gesture_get_dx(gevent);
  168. dy = libinput_event_gesture_get_dy(gevent);
  169. if (dir_x == 0.0)
  170. litest_assert(dx == 0.0);
  171. else if (dir_x < 0.0)
  172. litest_assert(dx < 0.0);
  173. else if (dir_x > 0.0)
  174. litest_assert(dx > 0.0);
  175. if (dir_y == 0.0)
  176. litest_assert(dy == 0.0);
  177. else if (dir_y < 0.0)
  178. litest_assert(dy < 0.0);
  179. else if (dir_y > 0.0)
  180. litest_assert(dy > 0.0);
  181. dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
  182. dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
  183. if (dir_x == 0.0)
  184. litest_assert(dx == 0.0);
  185. else if (dir_x < 0.0)
  186. litest_assert(dx < 0.0);
  187. else if (dir_x > 0.0)
  188. litest_assert(dx > 0.0);
  189. if (dir_y == 0.0)
  190. litest_assert(dy == 0.0);
  191. else if (dir_y < 0.0)
  192. litest_assert(dy < 0.0);
  193. else if (dir_y > 0.0)
  194. litest_assert(dy > 0.0);
  195. libinput_event_destroy(event);
  196. }
  197. litest_touch_up(dev, 0);
  198. litest_touch_up(dev, 1);
  199. litest_touch_up(dev, 2);
  200. litest_touch_up(dev, 3);
  201. litest_dispatch(li);
  202. event = libinput_get_event(li);
  203. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 4);
  204. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  205. libinput_event_destroy(event);
  206. return LITEST_PASS;
  207. }
  208. static enum litest_runner_result
  209. test_gesture_pinch_2fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
  210. {
  211. struct litest_device *dev = litest_current_device();
  212. struct libinput *li = dev->libinput;
  213. struct libinput_event *event;
  214. struct libinput_event_gesture *gevent;
  215. double dx, dy;
  216. double dir_x, dir_y;
  217. int i;
  218. double scale, oldscale;
  219. double angle;
  220. int cardinals[NCARDINALS][2] = {
  221. { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
  222. { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
  223. };
  224. if (litest_slot_count(dev) < 2 ||
  225. !libinput_device_has_capability(dev->libinput_device,
  226. LIBINPUT_DEVICE_CAP_GESTURE))
  227. return LITEST_NOT_APPLICABLE;
  228. /* If the device is too small to provide a finger spread wide enough
  229. * to avoid the scroll bias, skip the test */
  230. if (cardinal == E || cardinal == W) {
  231. double w = 0, h = 0;
  232. libinput_device_get_size(dev->libinput_device, &w, &h);
  233. /* 0.6 because the code below gives us points like 20/y and
  234. * 80/y. 45 because the threshold in the code is 40mm */
  235. if (w * 0.6 < 45)
  236. return LITEST_NOT_APPLICABLE;
  237. }
  238. dir_x = cardinals[cardinal][0];
  239. dir_y = cardinals[cardinal][1];
  240. litest_drain_events(li);
  241. litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
  242. litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
  243. litest_dispatch(li);
  244. if (hold == HOLD_GESTURE_REQUIRE)
  245. litest_timeout_gesture_hold(li);
  246. for (i = 0; i < 8; i++) {
  247. litest_push_event_frame(dev);
  248. if (dir_x > 0.0)
  249. dir_x -= 2;
  250. else if (dir_x < 0.0)
  251. dir_x += 2;
  252. if (dir_y > 0.0)
  253. dir_y -= 2;
  254. else if (dir_y < 0.0)
  255. dir_y += 2;
  256. litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y);
  257. litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y);
  258. litest_pop_event_frame(dev);
  259. litest_dispatch(li);
  260. }
  261. if (hold == HOLD_GESTURE_REQUIRE) {
  262. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2);
  263. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2);
  264. }
  265. event = libinput_get_event(li);
  266. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 2);
  267. dx = libinput_event_gesture_get_dx(gevent);
  268. dy = libinput_event_gesture_get_dy(gevent);
  269. scale = libinput_event_gesture_get_scale(gevent);
  270. litest_assert(dx == 0.0);
  271. litest_assert(dy == 0.0);
  272. litest_assert(scale == 1.0);
  273. libinput_event_destroy(event);
  274. while ((event = libinput_get_event(li)) != NULL) {
  275. gevent = litest_is_gesture_event(event,
  276. LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
  277. 2);
  278. oldscale = scale;
  279. scale = libinput_event_gesture_get_scale(gevent);
  280. litest_assert(scale < oldscale);
  281. angle = libinput_event_gesture_get_angle_delta(gevent);
  282. litest_assert_double_le(fabs(angle), 1.0);
  283. libinput_event_destroy(event);
  284. litest_dispatch(li);
  285. }
  286. litest_touch_up(dev, 0);
  287. litest_touch_up(dev, 1);
  288. litest_dispatch(li);
  289. event = libinput_get_event(li);
  290. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 2);
  291. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  292. libinput_event_destroy(event);
  293. return LITEST_PASS;
  294. }
  295. static enum litest_runner_result
  296. test_gesture_pinch_3fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
  297. {
  298. struct litest_device *dev = litest_current_device();
  299. struct libinput *li = dev->libinput;
  300. struct libinput_event *event;
  301. struct libinput_event_gesture *gevent;
  302. double dx, dy;
  303. double dir_x, dir_y;
  304. int i;
  305. double scale, oldscale;
  306. double angle;
  307. int cardinals[NCARDINALS][2] = {
  308. { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
  309. { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
  310. };
  311. if (litest_slot_count(dev) < 3)
  312. return LITEST_NOT_APPLICABLE;
  313. dir_x = cardinals[cardinal][0];
  314. dir_y = cardinals[cardinal][1];
  315. litest_drain_events(li);
  316. litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
  317. litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
  318. litest_touch_down(dev, 2, 51 - dir_x, 51 - dir_y);
  319. litest_dispatch(li);
  320. if (hold == HOLD_GESTURE_REQUIRE)
  321. litest_timeout_gesture_hold(li);
  322. for (i = 0; i < 8; i++) {
  323. litest_push_event_frame(dev);
  324. if (dir_x > 0.0)
  325. dir_x -= 2;
  326. else if (dir_x < 0.0)
  327. dir_x += 2;
  328. if (dir_y > 0.0)
  329. dir_y -= 2;
  330. else if (dir_y < 0.0)
  331. dir_y += 2;
  332. litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y);
  333. litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y);
  334. litest_touch_move(dev, 2, 51 - dir_x, 51 - dir_y);
  335. litest_pop_event_frame(dev);
  336. litest_dispatch(li);
  337. }
  338. if (hold == HOLD_GESTURE_REQUIRE) {
  339. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 3);
  340. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 3);
  341. }
  342. event = libinput_get_event(li);
  343. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 3);
  344. dx = libinput_event_gesture_get_dx(gevent);
  345. dy = libinput_event_gesture_get_dy(gevent);
  346. scale = libinput_event_gesture_get_scale(gevent);
  347. litest_assert(dx == 0.0);
  348. litest_assert(dy == 0.0);
  349. litest_assert(scale == 1.0);
  350. libinput_event_destroy(event);
  351. while ((event = libinput_get_event(li)) != NULL) {
  352. gevent = litest_is_gesture_event(event,
  353. LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
  354. 3);
  355. oldscale = scale;
  356. scale = libinput_event_gesture_get_scale(gevent);
  357. litest_assert(scale < oldscale);
  358. angle = libinput_event_gesture_get_angle_delta(gevent);
  359. litest_assert_double_le(fabs(angle), 1.0);
  360. libinput_event_destroy(event);
  361. litest_dispatch(li);
  362. }
  363. litest_touch_up(dev, 0);
  364. litest_touch_up(dev, 1);
  365. litest_touch_up(dev, 2);
  366. litest_dispatch(li);
  367. event = libinput_get_event(li);
  368. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 3);
  369. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  370. libinput_event_destroy(event);
  371. return LITEST_PASS;
  372. }
  373. static enum litest_runner_result
  374. test_gesture_pinch_4fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
  375. {
  376. struct litest_device *dev = litest_current_device();
  377. struct libinput *li = dev->libinput;
  378. struct libinput_event *event;
  379. struct libinput_event_gesture *gevent;
  380. double dx, dy;
  381. double dir_x, dir_y;
  382. int i;
  383. double scale, oldscale;
  384. double angle;
  385. int cardinals[NCARDINALS][2] = {
  386. { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
  387. { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
  388. };
  389. if (litest_slot_count(dev) < 4)
  390. return LITEST_NOT_APPLICABLE;
  391. dir_x = cardinals[cardinal][0];
  392. dir_y = cardinals[cardinal][1];
  393. litest_drain_events(li);
  394. litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
  395. litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
  396. litest_touch_down(dev, 2, 51 - dir_x, 51 - dir_y);
  397. litest_touch_down(dev, 3, 52 - dir_x, 52 - dir_y);
  398. litest_dispatch(li);
  399. if (hold == HOLD_GESTURE_REQUIRE)
  400. litest_timeout_gesture_hold(li);
  401. for (i = 0; i < 7; i++) {
  402. litest_push_event_frame(dev);
  403. if (dir_x > 0.0)
  404. dir_x -= 2;
  405. else if (dir_x < 0.0)
  406. dir_x += 2;
  407. if (dir_y > 0.0)
  408. dir_y -= 2;
  409. else if (dir_y < 0.0)
  410. dir_y += 2;
  411. litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y);
  412. litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y);
  413. litest_touch_move(dev, 2, 51 - dir_x, 51 - dir_y);
  414. litest_touch_move(dev, 3, 52 - dir_x, 52 - dir_y);
  415. litest_pop_event_frame(dev);
  416. litest_dispatch(li);
  417. }
  418. if (hold == HOLD_GESTURE_REQUIRE) {
  419. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 4);
  420. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 4);
  421. }
  422. event = libinput_get_event(li);
  423. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 4);
  424. dx = libinput_event_gesture_get_dx(gevent);
  425. dy = libinput_event_gesture_get_dy(gevent);
  426. scale = libinput_event_gesture_get_scale(gevent);
  427. litest_assert(dx == 0.0);
  428. litest_assert(dy == 0.0);
  429. litest_assert(scale == 1.0);
  430. libinput_event_destroy(event);
  431. while ((event = libinput_get_event(li)) != NULL) {
  432. gevent = litest_is_gesture_event(event,
  433. LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
  434. 4);
  435. oldscale = scale;
  436. scale = libinput_event_gesture_get_scale(gevent);
  437. litest_assert(scale < oldscale);
  438. angle = libinput_event_gesture_get_angle_delta(gevent);
  439. litest_assert_double_le(fabs(angle), 1.0);
  440. libinput_event_destroy(event);
  441. litest_dispatch(li);
  442. }
  443. litest_touch_up(dev, 0);
  444. litest_touch_up(dev, 1);
  445. litest_touch_up(dev, 2);
  446. litest_touch_up(dev, 3);
  447. litest_dispatch(li);
  448. event = libinput_get_event(li);
  449. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 4);
  450. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  451. libinput_event_destroy(event);
  452. return LITEST_PASS;
  453. }
  454. static enum litest_runner_result
  455. test_gesture_spread(enum cardinal cardinal, enum hold_gesture_behaviour hold)
  456. {
  457. struct litest_device *dev = litest_current_device();
  458. struct libinput *li = dev->libinput;
  459. struct libinput_event *event;
  460. struct libinput_event_gesture *gevent;
  461. double dx, dy;
  462. double dir_x, dir_y;
  463. int i;
  464. double scale, oldscale;
  465. double angle;
  466. int cardinals[NCARDINALS][2] = {
  467. { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
  468. { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
  469. };
  470. if (litest_slot_count(dev) < 2 ||
  471. !libinput_device_has_capability(dev->libinput_device,
  472. LIBINPUT_DEVICE_CAP_GESTURE))
  473. return LITEST_NOT_APPLICABLE;
  474. /* If the device is too small to provide a finger spread wide enough
  475. * to avoid the scroll bias, skip the test */
  476. if (cardinal == E || cardinal == W) {
  477. double w = 0, h = 0;
  478. libinput_device_get_size(dev->libinput_device, &w, &h);
  479. /* 0.6 because the code below gives us points like 20/y and
  480. * 80/y. 45 because the threshold in the code is 40mm */
  481. if (w * 0.6 < 45)
  482. return LITEST_NOT_APPLICABLE;
  483. }
  484. dir_x = cardinals[cardinal][0];
  485. dir_y = cardinals[cardinal][1];
  486. litest_drain_events(li);
  487. litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
  488. litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
  489. litest_dispatch(li);
  490. if (hold == HOLD_GESTURE_REQUIRE)
  491. litest_timeout_gesture_hold(li);
  492. for (i = 0; i < 15; i++) {
  493. litest_push_event_frame(dev);
  494. if (dir_x > 0.0)
  495. dir_x += 1;
  496. else if (dir_x < 0.0)
  497. dir_x -= 1;
  498. if (dir_y > 0.0)
  499. dir_y += 1;
  500. else if (dir_y < 0.0)
  501. dir_y -= 1;
  502. litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y);
  503. litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y);
  504. litest_pop_event_frame(dev);
  505. litest_dispatch(li);
  506. }
  507. if (hold == HOLD_GESTURE_REQUIRE) {
  508. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2);
  509. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2);
  510. }
  511. event = libinput_get_event(li);
  512. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 2);
  513. dx = libinput_event_gesture_get_dx(gevent);
  514. dy = libinput_event_gesture_get_dy(gevent);
  515. scale = libinput_event_gesture_get_scale(gevent);
  516. litest_assert(dx == 0.0);
  517. litest_assert(dy == 0.0);
  518. litest_assert(scale == 1.0);
  519. libinput_event_destroy(event);
  520. while ((event = libinput_get_event(li)) != NULL) {
  521. gevent = litest_is_gesture_event(event,
  522. LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
  523. 2);
  524. oldscale = scale;
  525. scale = libinput_event_gesture_get_scale(gevent);
  526. litest_assert(scale > oldscale);
  527. angle = libinput_event_gesture_get_angle_delta(gevent);
  528. litest_assert_double_le(fabs(angle), 1.0);
  529. libinput_event_destroy(event);
  530. litest_dispatch(li);
  531. }
  532. litest_touch_up(dev, 0);
  533. litest_touch_up(dev, 1);
  534. litest_dispatch(li);
  535. event = libinput_get_event(li);
  536. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 2);
  537. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  538. libinput_event_destroy(event);
  539. return LITEST_PASS;
  540. }
  541. static enum litest_runner_result
  542. test_gesture_3fg_buttonarea_scroll(enum hold_gesture_behaviour hold)
  543. {
  544. struct litest_device *dev = litest_current_device();
  545. struct libinput *li = dev->libinput;
  546. if (litest_slot_count(dev) < 3)
  547. return LITEST_NOT_APPLICABLE;
  548. litest_enable_buttonareas(dev);
  549. litest_enable_2fg_scroll(dev);
  550. litest_drain_events(li);
  551. litest_touch_down(dev, 0, 40, 20);
  552. litest_touch_down(dev, 1, 30, 20);
  553. /* third finger in btnarea */
  554. litest_touch_down(dev, 2, 50, 99);
  555. litest_dispatch(li);
  556. if (hold == HOLD_GESTURE_REQUIRE)
  557. litest_timeout_gesture_hold(li);
  558. litest_touch_move_two_touches(dev, 40, 20, 30, 20, 0, 40, 10);
  559. litest_touch_up(dev, 0);
  560. litest_touch_up(dev, 1);
  561. litest_dispatch(li);
  562. if (hold == HOLD_GESTURE_REQUIRE) {
  563. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2);
  564. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2);
  565. }
  566. litest_assert_scroll(li,
  567. LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
  568. LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
  569. 4);
  570. return LITEST_PASS;
  571. }
  572. START_TEST(gestures_cap)
  573. {
  574. struct litest_device *dev = litest_current_device();
  575. struct libinput_device *device = dev->libinput_device;
  576. if (libevdev_has_property(dev->evdev, INPUT_PROP_SEMI_MT))
  577. litest_assert(
  578. !libinput_device_has_capability(device,
  579. LIBINPUT_DEVICE_CAP_GESTURE));
  580. else
  581. litest_assert(
  582. libinput_device_has_capability(device,
  583. LIBINPUT_DEVICE_CAP_GESTURE));
  584. }
  585. END_TEST
  586. START_TEST(gestures_nocap)
  587. {
  588. struct litest_device *dev = litest_current_device();
  589. struct libinput_device *device = dev->libinput_device;
  590. litest_assert(
  591. !libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE));
  592. }
  593. END_TEST
  594. START_TEST(gestures_swipe_3fg)
  595. {
  596. enum cardinal cardinal =
  597. litest_test_param_get_i32(test_env->params, "direction");
  598. return test_gesture_swipe_3fg(cardinal, HOLD_GESTURE_IGNORE);
  599. }
  600. END_TEST
  601. START_TEST(gestures_swipe_3fg_btntool)
  602. {
  603. struct litest_device *dev = litest_current_device();
  604. struct libinput *li = dev->libinput;
  605. struct libinput_event *event;
  606. struct libinput_event_gesture *gevent;
  607. double dx, dy;
  608. enum cardinal cardinal =
  609. litest_test_param_get_i32(test_env->params, "direction");
  610. double dir_x, dir_y;
  611. int cardinals[NCARDINALS][2] = {
  612. { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
  613. { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
  614. };
  615. if (litest_slot_count(dev) > 2 ||
  616. !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) ||
  617. !libinput_device_has_capability(dev->libinput_device,
  618. LIBINPUT_DEVICE_CAP_GESTURE))
  619. return LITEST_NOT_APPLICABLE;
  620. dir_x = cardinals[cardinal][0];
  621. dir_y = cardinals[cardinal][1];
  622. litest_drain_events(li);
  623. litest_touch_down(dev, 0, 40, 40);
  624. litest_touch_down(dev, 1, 50, 40);
  625. litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
  626. litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
  627. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  628. litest_dispatch(li);
  629. litest_touch_move_two_touches(dev, 40, 40, 50, 40, dir_x, dir_y, 10);
  630. litest_dispatch(li);
  631. event = libinput_get_event(li);
  632. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
  633. dx = libinput_event_gesture_get_dx(gevent);
  634. dy = libinput_event_gesture_get_dy(gevent);
  635. litest_assert(dx == 0.0);
  636. litest_assert(dy == 0.0);
  637. libinput_event_destroy(event);
  638. while ((event = libinput_get_event(li)) != NULL) {
  639. gevent = litest_is_gesture_event(event,
  640. LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
  641. 3);
  642. dx = libinput_event_gesture_get_dx(gevent);
  643. dy = libinput_event_gesture_get_dy(gevent);
  644. if (dir_x == 0.0)
  645. litest_assert(dx == 0.0);
  646. else if (dir_x < 0.0)
  647. litest_assert(dx < 0.0);
  648. else if (dir_x > 0.0)
  649. litest_assert(dx > 0.0);
  650. if (dir_y == 0.0)
  651. litest_assert(dy == 0.0);
  652. else if (dir_y < 0.0)
  653. litest_assert(dy < 0.0);
  654. else if (dir_y > 0.0)
  655. litest_assert(dy > 0.0);
  656. dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
  657. dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
  658. if (dir_x == 0.0)
  659. litest_assert(dx == 0.0);
  660. else if (dir_x < 0.0)
  661. litest_assert(dx < 0.0);
  662. else if (dir_x > 0.0)
  663. litest_assert(dx > 0.0);
  664. if (dir_y == 0.0)
  665. litest_assert(dy == 0.0);
  666. else if (dir_y < 0.0)
  667. litest_assert(dy < 0.0);
  668. else if (dir_y > 0.0)
  669. litest_assert(dy > 0.0);
  670. libinput_event_destroy(event);
  671. }
  672. litest_touch_up(dev, 0);
  673. litest_touch_up(dev, 1);
  674. litest_dispatch(li);
  675. event = libinput_get_event(li);
  676. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3);
  677. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  678. libinput_event_destroy(event);
  679. }
  680. END_TEST
  681. START_TEST(gestures_swipe_3fg_btntool_pinch_like)
  682. {
  683. struct litest_device *dev = litest_current_device();
  684. struct libinput *li = dev->libinput;
  685. struct libinput_event *event;
  686. struct libinput_event_gesture *gevent;
  687. if (litest_slot_count(dev) > 2 ||
  688. !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) ||
  689. !libinput_device_has_capability(dev->libinput_device,
  690. LIBINPUT_DEVICE_CAP_GESTURE))
  691. return LITEST_NOT_APPLICABLE;
  692. litest_drain_events(li);
  693. /* Technically a pinch position + pinch movement, but expect swipe
  694. * for nfingers > nslots */
  695. litest_touch_down(dev, 0, 20, 60);
  696. litest_touch_down(dev, 1, 50, 20);
  697. litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
  698. litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
  699. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  700. litest_dispatch(li);
  701. litest_touch_move_to(dev, 0, 20, 60, 10, 80, 20);
  702. litest_dispatch(li);
  703. event = libinput_get_event(li);
  704. litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
  705. libinput_event_destroy(event);
  706. while ((event = libinput_get_event(li)) != NULL) {
  707. litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, 3);
  708. libinput_event_destroy(event);
  709. }
  710. litest_touch_up(dev, 0);
  711. litest_touch_up(dev, 1);
  712. litest_dispatch(li);
  713. event = libinput_get_event(li);
  714. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3);
  715. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  716. libinput_event_destroy(event);
  717. }
  718. END_TEST
  719. START_TEST(gestures_swipe_4fg)
  720. {
  721. enum cardinal cardinal =
  722. litest_test_param_get_i32(test_env->params, "direction");
  723. return test_gesture_swipe_4fg(cardinal, HOLD_GESTURE_IGNORE);
  724. }
  725. END_TEST
  726. START_TEST(gestures_swipe_4fg_btntool)
  727. {
  728. struct litest_device *dev = litest_current_device();
  729. struct libinput *li = dev->libinput;
  730. struct libinput_event *event;
  731. struct libinput_event_gesture *gevent;
  732. double dx, dy;
  733. enum cardinal cardinal =
  734. litest_test_param_get_i32(test_env->params, "direction");
  735. double dir_x, dir_y;
  736. int cardinals[NCARDINALS][2] = {
  737. { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
  738. { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
  739. };
  740. if (litest_slot_count(dev) > 2 ||
  741. !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_QUADTAP) ||
  742. !libinput_device_has_capability(dev->libinput_device,
  743. LIBINPUT_DEVICE_CAP_GESTURE))
  744. return LITEST_NOT_APPLICABLE;
  745. dir_x = cardinals[cardinal][0];
  746. dir_y = cardinals[cardinal][1];
  747. litest_drain_events(li);
  748. litest_touch_down(dev, 0, 40, 40);
  749. litest_touch_down(dev, 1, 50, 40);
  750. litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
  751. litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 1);
  752. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  753. litest_dispatch(li);
  754. litest_touch_move_two_touches(dev, 40, 40, 50, 40, dir_x, dir_y, 10);
  755. litest_dispatch(li);
  756. event = libinput_get_event(li);
  757. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 4);
  758. dx = libinput_event_gesture_get_dx(gevent);
  759. dy = libinput_event_gesture_get_dy(gevent);
  760. litest_assert(dx == 0.0);
  761. litest_assert(dy == 0.0);
  762. libinput_event_destroy(event);
  763. while ((event = libinput_get_event(li)) != NULL) {
  764. gevent = litest_is_gesture_event(event,
  765. LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
  766. 4);
  767. dx = libinput_event_gesture_get_dx(gevent);
  768. dy = libinput_event_gesture_get_dy(gevent);
  769. if (dir_x == 0.0)
  770. litest_assert(dx == 0.0);
  771. else if (dir_x < 0.0)
  772. litest_assert(dx < 0.0);
  773. else if (dir_x > 0.0)
  774. litest_assert(dx > 0.0);
  775. if (dir_y == 0.0)
  776. litest_assert(dy == 0.0);
  777. else if (dir_y < 0.0)
  778. litest_assert(dy < 0.0);
  779. else if (dir_y > 0.0)
  780. litest_assert(dy > 0.0);
  781. dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
  782. dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
  783. if (dir_x == 0.0)
  784. litest_assert(dx == 0.0);
  785. else if (dir_x < 0.0)
  786. litest_assert(dx < 0.0);
  787. else if (dir_x > 0.0)
  788. litest_assert(dx > 0.0);
  789. if (dir_y == 0.0)
  790. litest_assert(dy == 0.0);
  791. else if (dir_y < 0.0)
  792. litest_assert(dy < 0.0);
  793. else if (dir_y > 0.0)
  794. litest_assert(dy > 0.0);
  795. libinput_event_destroy(event);
  796. }
  797. litest_touch_up(dev, 0);
  798. litest_touch_up(dev, 1);
  799. litest_dispatch(li);
  800. event = libinput_get_event(li);
  801. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 4);
  802. litest_assert(!libinput_event_gesture_get_cancelled(gevent));
  803. libinput_event_destroy(event);
  804. }
  805. END_TEST
  806. START_TEST(gestures_pinch)
  807. {
  808. enum cardinal cardinal =
  809. litest_test_param_get_i32(test_env->params, "direction");
  810. return test_gesture_pinch_2fg(cardinal, HOLD_GESTURE_IGNORE);
  811. }
  812. END_TEST
  813. START_TEST(gestures_pinch_3fg)
  814. {
  815. enum cardinal cardinal =
  816. litest_test_param_get_i32(test_env->params, "direction");
  817. return test_gesture_pinch_3fg(cardinal, HOLD_GESTURE_IGNORE);
  818. }
  819. END_TEST
  820. START_TEST(gestures_pinch_4fg)
  821. {
  822. enum cardinal cardinal =
  823. litest_test_param_get_i32(test_env->params, "direction");
  824. return test_gesture_pinch_4fg(cardinal, HOLD_GESTURE_IGNORE);
  825. }
  826. END_TEST
  827. START_TEST(gestures_spread)
  828. {
  829. enum cardinal cardinal =
  830. litest_test_param_get_i32(test_env->params, "direction");
  831. return test_gesture_spread(cardinal, HOLD_GESTURE_IGNORE);
  832. }
  833. END_TEST
  834. START_TEST(gestures_time_usec)
  835. {
  836. struct litest_device *dev = litest_current_device();
  837. struct libinput *li = dev->libinput;
  838. struct libinput_event *event;
  839. struct libinput_event_gesture *gevent;
  840. uint64_t time_usec;
  841. if (litest_slot_count(dev) < 3)
  842. return LITEST_NOT_APPLICABLE;
  843. litest_drain_events(li);
  844. litest_touch_down(dev, 0, 40, 40);
  845. litest_touch_down(dev, 1, 50, 40);
  846. litest_touch_down(dev, 2, 60, 40);
  847. litest_dispatch(li);
  848. litest_touch_move_three_touches(dev, 40, 40, 50, 40, 60, 40, 0, 30, 30);
  849. litest_dispatch(li);
  850. event = libinput_get_event(li);
  851. gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
  852. time_usec = libinput_event_gesture_get_time_usec(gevent);
  853. litest_assert_int_eq(libinput_event_gesture_get_time(gevent),
  854. (uint32_t)(time_usec / 1000));
  855. libinput_event_destroy(event);
  856. }
  857. END_TEST
  858. START_TEST(gestures_3fg_buttonarea_scroll)
  859. {
  860. return test_gesture_3fg_buttonarea_scroll(HOLD_GESTURE_IGNORE);
  861. }
  862. END_TEST
  863. START_TEST(gestures_3fg_buttonarea_scroll_btntool)
  864. {
  865. struct litest_device *dev = litest_current_device();
  866. struct libinput *li = dev->libinput;
  867. if (litest_slot_count(dev) > 2)
  868. return LITEST_NOT_APPLICABLE;
  869. litest_enable_buttonareas(dev);
  870. litest_enable_2fg_scroll(dev);
  871. litest_drain_events(li);
  872. /* first finger in btnarea */
  873. litest_touch_down(dev, 0, 20, 99);
  874. litest_touch_down(dev, 1, 30, 20);
  875. litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
  876. litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
  877. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  878. litest_dispatch(li);
  879. litest_touch_move_to(dev, 1, 30, 20, 30, 70, 10);
  880. litest_touch_up(dev, 1);
  881. litest_dispatch(li);
  882. litest_assert_scroll(li,
  883. LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
  884. LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
  885. 4);
  886. }
  887. END_TEST
  888. START_TEST(gestures_swipe_3fg_unaccel)
  889. {
  890. struct litest_device *dev = litest_current_device();
  891. struct libinput *li = dev->libinput;
  892. struct libinput_event *event;
  893. double reference_ux = 0, reference_uy = 0;
  894. /**
  895. * This magic number is an artifact of the acceleration code.
  896. * The maximum factor in the touchpad accel profile is 4.8 times the
  897. * speed setting (1.000875 at default setting 0). The factor
  898. * applied to the const acceleration is the 0.9 baseline.
  899. * So our two sets of coordinates are:
  900. * accel = 4.8 * delta * normalize_magic
  901. * unaccel = 0.9 * delta * normalize_magic
  902. *
  903. * Since delta and the normalization magic are the same for both,
  904. * our accelerated deltas can be a maximum of 4.8/0.9 bigger than
  905. * the unaccelerated deltas.
  906. *
  907. * If any of the accel methods numbers change, this will have to
  908. * change here too.
  909. */
  910. const double max_factor = 5.34;
  911. if (litest_slot_count(dev) < 3)
  912. return LITEST_NOT_APPLICABLE;
  913. litest_drain_events(li);
  914. litest_touch_down(dev, 0, 40, 20);
  915. litest_touch_down(dev, 1, 50, 20);
  916. litest_touch_down(dev, 2, 60, 20);
  917. litest_dispatch(li);
  918. litest_touch_move_three_touches(dev, 40, 20, 50, 20, 60, 20, 30, 40, 10);
  919. litest_dispatch(li);
  920. event = libinput_get_event(li);
  921. litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
  922. libinput_event_destroy(event);
  923. event = libinput_get_event(li);
  924. do {
  925. struct libinput_event_gesture *gevent;
  926. double dx, dy;
  927. double ux, uy;
  928. gevent = litest_is_gesture_event(event,
  929. LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
  930. 3);
  931. dx = libinput_event_gesture_get_dx(gevent);
  932. dy = libinput_event_gesture_get_dy(gevent);
  933. ux = libinput_event_gesture_get_dx_unaccelerated(gevent);
  934. uy = libinput_event_gesture_get_dy_unaccelerated(gevent);
  935. litest_assert_double_ne(ux, 0.0);
  936. litest_assert_double_ne(uy, 0.0);
  937. if (!reference_ux)
  938. reference_ux = ux;
  939. if (!reference_uy)
  940. reference_uy = uy;
  941. /* The unaccelerated delta should be the same for every
  942. * event, but we have rounding errors since we only control
  943. * input data as percentage of the touchpad size.
  944. * so we just eyeball it */
  945. litest_assert_double_gt(ux, reference_ux - 2);
  946. litest_assert_double_lt(ux, reference_ux + 2);
  947. litest_assert_double_gt(uy, reference_uy - 2);
  948. litest_assert_double_lt(uy, reference_uy + 2);
  949. /* All our touchpads are large enough to make this is a fast
  950. * swipe, we don't expect deceleration, unaccel should
  951. * always be less than accel delta */
  952. litest_assert_double_lt(ux, dx);
  953. litest_assert_double_lt(ux, dx);
  954. /* Check our accelerated delta is within the expected
  955. * maximum. */
  956. litest_assert_double_lt(dx, ux * max_factor);
  957. litest_assert_double_lt(dy, uy * max_factor);
  958. libinput_event_destroy(event);
  959. } while ((event = libinput_get_event(li)));
  960. litest_touch_up(dev, 0);
  961. litest_touch_up(dev, 1);
  962. litest_touch_up(dev, 2);
  963. }
  964. END_TEST
  965. START_TEST(gestures_hold_config_default_disabled)
  966. {
  967. struct litest_device *dev = litest_current_device();
  968. struct libinput_device *device = dev->libinput_device;
  969. litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device),
  970. 0);
  971. litest_assert_enum_eq(
  972. libinput_device_config_gesture_get_hold_default_enabled(device),
  973. LIBINPUT_CONFIG_HOLD_DISABLED);
  974. litest_assert_enum_eq(
  975. libinput_device_config_gesture_get_hold_default_enabled(device),
  976. LIBINPUT_CONFIG_HOLD_DISABLED);
  977. }
  978. END_TEST
  979. START_TEST(gestures_hold_config_default_enabled)
  980. {
  981. struct litest_device *dev = litest_current_device();
  982. struct libinput_device *device = dev->libinput_device;
  983. litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device),
  984. 1);
  985. litest_assert_enum_eq(
  986. libinput_device_config_gesture_get_hold_default_enabled(device),
  987. LIBINPUT_CONFIG_HOLD_ENABLED);
  988. litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device),
  989. LIBINPUT_CONFIG_HOLD_ENABLED);
  990. }
  991. END_TEST
  992. START_TEST(gestures_hold_config_set_invalid)
  993. {
  994. struct litest_device *dev = litest_current_device();
  995. struct libinput_device *device = dev->libinput_device;
  996. litest_assert_enum_eq(
  997. libinput_device_config_gesture_set_hold_enabled(device, -1),
  998. LIBINPUT_CONFIG_STATUS_INVALID);
  999. litest_assert_enum_eq(
  1000. libinput_device_config_gesture_set_hold_enabled(device, 2),
  1001. LIBINPUT_CONFIG_STATUS_INVALID);
  1002. }
  1003. END_TEST
  1004. START_TEST(gestures_hold_config_is_available)
  1005. {
  1006. struct litest_device *dev = litest_current_device();
  1007. struct libinput_device *device = dev->libinput_device;
  1008. litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device),
  1009. 1);
  1010. litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device),
  1011. LIBINPUT_CONFIG_HOLD_ENABLED);
  1012. litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(
  1013. device,
  1014. LIBINPUT_CONFIG_HOLD_DISABLED),
  1015. LIBINPUT_CONFIG_STATUS_SUCCESS);
  1016. litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device),
  1017. LIBINPUT_CONFIG_HOLD_DISABLED);
  1018. }
  1019. END_TEST
  1020. START_TEST(gestures_hold_config_is_not_available)
  1021. {
  1022. struct litest_device *dev = litest_current_device();
  1023. struct libinput_device *device = dev->libinput_device;
  1024. litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device),
  1025. 0);
  1026. litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device),
  1027. LIBINPUT_CONFIG_HOLD_DISABLED);
  1028. litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(
  1029. device,
  1030. LIBINPUT_CONFIG_HOLD_ENABLED),
  1031. LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
  1032. litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(
  1033. device,
  1034. LIBINPUT_CONFIG_HOLD_DISABLED),
  1035. LIBINPUT_CONFIG_STATUS_SUCCESS);
  1036. }
  1037. END_TEST
  1038. START_TEST(gestures_hold)
  1039. {
  1040. struct litest_device *dev = litest_current_device();
  1041. struct libinput *li = dev->libinput;
  1042. int nfingers = litest_test_param_get_i32(test_env->params, "fingers");
  1043. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap");
  1044. if (litest_slot_count(dev) < nfingers)
  1045. return LITEST_NOT_APPLICABLE;
  1046. if (tap_enabled)
  1047. litest_enable_tap(dev->libinput_device);
  1048. else
  1049. litest_disable_tap(dev->libinput_device);
  1050. litest_drain_events(li);
  1051. switch (nfingers) {
  1052. case 4:
  1053. litest_touch_down(dev, 3, 70, 30);
  1054. _fallthrough_;
  1055. case 3:
  1056. litest_touch_down(dev, 2, 60, 30);
  1057. _fallthrough_;
  1058. case 2:
  1059. litest_touch_down(dev, 1, 50, 30);
  1060. _fallthrough_;
  1061. case 1:
  1062. litest_touch_down(dev, 0, 40, 30);
  1063. break;
  1064. }
  1065. litest_timeout_gesture_hold(li);
  1066. if (libinput_device_has_capability(dev->libinput_device,
  1067. LIBINPUT_DEVICE_CAP_GESTURE)) {
  1068. litest_assert_gesture_event(li,
  1069. LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
  1070. nfingers);
  1071. } else {
  1072. litest_assert_empty_queue(li);
  1073. }
  1074. switch (nfingers) {
  1075. case 4:
  1076. litest_touch_up(dev, 3);
  1077. _fallthrough_;
  1078. case 3:
  1079. litest_touch_up(dev, 2);
  1080. _fallthrough_;
  1081. case 2:
  1082. litest_touch_up(dev, 1);
  1083. _fallthrough_;
  1084. case 1:
  1085. litest_touch_up(dev, 0);
  1086. break;
  1087. }
  1088. litest_dispatch(li);
  1089. if (libinput_device_has_capability(dev->libinput_device,
  1090. LIBINPUT_DEVICE_CAP_GESTURE)) {
  1091. _destroy_(libinput_event) *ev = libinput_get_event(li);
  1092. auto gev = litest_is_gesture_event(ev,
  1093. LIBINPUT_EVENT_GESTURE_HOLD_END,
  1094. nfingers);
  1095. litest_assert(!libinput_event_gesture_get_cancelled(gev));
  1096. }
  1097. litest_assert_empty_queue(li);
  1098. }
  1099. END_TEST
  1100. START_TEST(gestures_hold_cancel)
  1101. {
  1102. struct litest_device *dev = litest_current_device();
  1103. struct libinput *li = dev->libinput;
  1104. int nfingers = litest_test_param_get_i32(test_env->params, "fingers");
  1105. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap");
  1106. if (litest_slot_count(dev) < nfingers)
  1107. return LITEST_NOT_APPLICABLE;
  1108. if (tap_enabled)
  1109. litest_enable_tap(dev->libinput_device);
  1110. else
  1111. litest_disable_tap(dev->libinput_device);
  1112. litest_drain_events(li);
  1113. int last_finger = (nfingers - 1);
  1114. litest_drain_events(li);
  1115. switch (nfingers) {
  1116. case 4:
  1117. litest_touch_down(dev, 3, 70, 30);
  1118. _fallthrough_;
  1119. case 3:
  1120. litest_touch_down(dev, 2, 60, 30);
  1121. _fallthrough_;
  1122. case 2:
  1123. litest_touch_down(dev, 1, 50, 30);
  1124. _fallthrough_;
  1125. case 1:
  1126. litest_touch_down(dev, 0, 40, 30);
  1127. break;
  1128. }
  1129. litest_timeout_gesture_hold(li);
  1130. litest_touch_up(dev, last_finger);
  1131. litest_dispatch(li);
  1132. litest_timeout_gesture_hold(li);
  1133. if (libinput_device_has_capability(dev->libinput_device,
  1134. LIBINPUT_DEVICE_CAP_GESTURE)) {
  1135. litest_assert_gesture_event(li,
  1136. LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
  1137. nfingers);
  1138. _destroy_(libinput_event) *ev = libinput_get_event(li);
  1139. auto gev = litest_is_gesture_event(ev,
  1140. LIBINPUT_EVENT_GESTURE_HOLD_END,
  1141. nfingers);
  1142. if (nfingers > 1)
  1143. litest_assert(libinput_event_gesture_get_cancelled(gev));
  1144. else /* can't cancel a 1fg gesture */
  1145. litest_assert(!libinput_event_gesture_get_cancelled(gev));
  1146. }
  1147. litest_assert_empty_queue(li);
  1148. }
  1149. END_TEST
  1150. START_TEST(gestures_hold_then_swipe_3fg)
  1151. {
  1152. enum cardinal cardinal =
  1153. litest_test_param_get_i32(test_env->params, "direction");
  1154. return test_gesture_swipe_3fg(cardinal, HOLD_GESTURE_REQUIRE);
  1155. }
  1156. END_TEST
  1157. START_TEST(gestures_hold_then_swipe_4fg)
  1158. {
  1159. enum cardinal cardinal =
  1160. litest_test_param_get_i32(test_env->params, "direction");
  1161. return test_gesture_swipe_4fg(cardinal, HOLD_GESTURE_REQUIRE);
  1162. }
  1163. END_TEST
  1164. START_TEST(gestures_hold_then_pinch_2fg)
  1165. {
  1166. enum cardinal cardinal =
  1167. litest_test_param_get_i32(test_env->params, "direction");
  1168. return test_gesture_pinch_2fg(cardinal, HOLD_GESTURE_REQUIRE);
  1169. }
  1170. END_TEST
  1171. START_TEST(gestures_hold_then_pinch_3fg)
  1172. {
  1173. enum cardinal cardinal =
  1174. litest_test_param_get_i32(test_env->params, "direction");
  1175. return test_gesture_pinch_3fg(cardinal, HOLD_GESTURE_REQUIRE);
  1176. }
  1177. END_TEST
  1178. START_TEST(gestures_hold_then_pinch_4fg)
  1179. {
  1180. enum cardinal cardinal =
  1181. litest_test_param_get_i32(test_env->params, "direction");
  1182. return test_gesture_pinch_4fg(cardinal, HOLD_GESTURE_REQUIRE);
  1183. }
  1184. END_TEST
  1185. START_TEST(gestures_hold_then_spread)
  1186. {
  1187. enum cardinal cardinal =
  1188. litest_test_param_get_i32(test_env->params, "direction");
  1189. return test_gesture_spread(cardinal, HOLD_GESTURE_REQUIRE);
  1190. }
  1191. END_TEST
  1192. START_TEST(gestures_hold_then_3fg_buttonarea_scroll)
  1193. {
  1194. return test_gesture_3fg_buttonarea_scroll(HOLD_GESTURE_REQUIRE);
  1195. }
  1196. END_TEST
  1197. START_TEST(gestures_hold_once_on_double_tap)
  1198. {
  1199. struct litest_device *dev = litest_current_device();
  1200. struct libinput *li = dev->libinput;
  1201. if (!libinput_device_has_capability(dev->libinput_device,
  1202. LIBINPUT_DEVICE_CAP_GESTURE))
  1203. return LITEST_NOT_APPLICABLE;
  1204. litest_enable_tap(dev->libinput_device);
  1205. litest_drain_events(li);
  1206. /* First tap, a hold gesture must be generated */
  1207. litest_touch_down(dev, 0, 50, 50);
  1208. litest_timeout_gesture_quick_hold(li);
  1209. litest_touch_up(dev, 0);
  1210. litest_dispatch(li);
  1211. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1);
  1212. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1);
  1213. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1214. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1215. litest_assert_empty_queue(li);
  1216. /* Double tap, don't generate an extra hold gesture */
  1217. litest_touch_down(dev, 0, 50, 50);
  1218. litest_touch_up(dev, 0);
  1219. litest_timeout_gesture_quick_hold(li);
  1220. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1221. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1222. litest_assert_empty_queue(li);
  1223. }
  1224. END_TEST
  1225. START_TEST(gestures_hold_once_tap_n_drag)
  1226. {
  1227. struct litest_device *dev = litest_current_device();
  1228. struct libinput *li = dev->libinput;
  1229. int nfingers = litest_test_param_get_i32(test_env->params, "fingers");
  1230. unsigned int button = 0;
  1231. if (nfingers > litest_slot_count(dev))
  1232. return LITEST_NOT_APPLICABLE;
  1233. if (!libinput_device_has_capability(dev->libinput_device,
  1234. LIBINPUT_DEVICE_CAP_GESTURE))
  1235. return LITEST_NOT_APPLICABLE;
  1236. litest_enable_tap(dev->libinput_device);
  1237. litest_disable_drag_lock(dev->libinput_device);
  1238. litest_drain_events(li);
  1239. switch (nfingers) {
  1240. case 1:
  1241. button = BTN_LEFT;
  1242. break;
  1243. case 2:
  1244. button = BTN_RIGHT;
  1245. break;
  1246. case 3:
  1247. button = BTN_MIDDLE;
  1248. break;
  1249. default:
  1250. litest_assert_not_reached();
  1251. }
  1252. switch (nfingers) {
  1253. case 3:
  1254. litest_touch_down(dev, 2, 60, 30);
  1255. _fallthrough_;
  1256. case 2:
  1257. litest_touch_down(dev, 1, 50, 30);
  1258. _fallthrough_;
  1259. case 1:
  1260. litest_touch_down(dev, 0, 40, 30);
  1261. break;
  1262. }
  1263. litest_timeout_gesture_quick_hold(li);
  1264. switch (nfingers) {
  1265. case 3:
  1266. litest_touch_up(dev, 2);
  1267. _fallthrough_;
  1268. case 2:
  1269. litest_touch_up(dev, 1);
  1270. _fallthrough_;
  1271. case 1:
  1272. litest_touch_up(dev, 0);
  1273. break;
  1274. }
  1275. litest_dispatch(li);
  1276. /* "Quick" hold gestures are only generated when using 1 or 2 fingers */
  1277. if (nfingers == 1 || nfingers == 2) {
  1278. litest_assert_gesture_event(li,
  1279. LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
  1280. nfingers);
  1281. litest_assert_gesture_event(li,
  1282. LIBINPUT_EVENT_GESTURE_HOLD_END,
  1283. nfingers);
  1284. }
  1285. /* Tap and drag, don't generate an extra hold gesture */
  1286. litest_touch_down(dev, 0, 50, 50);
  1287. litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20);
  1288. litest_dispatch(li);
  1289. litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED);
  1290. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1291. litest_touch_up(dev, 0);
  1292. litest_dispatch(li);
  1293. litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED);
  1294. litest_assert_empty_queue(li);
  1295. }
  1296. END_TEST
  1297. START_TEST(gestures_hold_and_motion_before_timeout)
  1298. {
  1299. struct litest_device *dev = litest_current_device();
  1300. struct libinput *li = dev->libinput;
  1301. if (!libinput_device_has_capability(dev->libinput_device,
  1302. LIBINPUT_DEVICE_CAP_GESTURE))
  1303. return LITEST_NOT_APPLICABLE;
  1304. litest_drain_events(li);
  1305. litest_touch_down(dev, 0, 50, 50);
  1306. litest_dispatch(li);
  1307. litest_touch_move_to(dev, 0, 50, 50, 51, 51, 1);
  1308. litest_touch_move_to(dev, 0, 51, 51, 50, 50, 1);
  1309. litest_timeout_gesture_quick_hold(li);
  1310. litest_drain_events_of_type(li, LIBINPUT_EVENT_POINTER_MOTION);
  1311. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1);
  1312. litest_touch_up(dev, 0);
  1313. litest_dispatch(li);
  1314. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1);
  1315. litest_assert_empty_queue(li);
  1316. }
  1317. END_TEST
  1318. START_TEST(gestures_hold_and_motion_after_timeout)
  1319. {
  1320. struct litest_device *dev = litest_current_device();
  1321. struct libinput *li = dev->libinput;
  1322. if (!libinput_device_has_capability(dev->libinput_device,
  1323. LIBINPUT_DEVICE_CAP_GESTURE))
  1324. return LITEST_NOT_APPLICABLE;
  1325. litest_drain_events(li);
  1326. litest_touch_down(dev, 0, 50, 50);
  1327. litest_timeout_gesture_quick_hold(li);
  1328. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1);
  1329. litest_touch_move_to(dev, 0, 50, 50, 51, 51, 1);
  1330. litest_touch_move_to(dev, 0, 51, 51, 50, 50, 1);
  1331. litest_dispatch(li);
  1332. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1333. litest_touch_up(dev, 0);
  1334. litest_dispatch(li);
  1335. litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1);
  1336. litest_assert_empty_queue(li);
  1337. }
  1338. END_TEST
  1339. static void
  1340. drain_cancelled_swipe_gesture(struct libinput *li)
  1341. {
  1342. litest_drain_events_of_type(li,
  1343. LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
  1344. LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE);
  1345. _destroy_(libinput_event) *end = libinput_get_event(li);
  1346. auto gev = litest_is_gesture_event(end, LIBINPUT_EVENT_GESTURE_SWIPE_END, -1);
  1347. litest_assert(libinput_event_gesture_get_cancelled(gev));
  1348. }
  1349. START_TEST(gestures_3fg_drag)
  1350. {
  1351. struct litest_device *dev = litest_current_device();
  1352. struct libinput *li = dev->libinput;
  1353. uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
  1354. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
  1355. if (litest_slot_count(dev) < 3)
  1356. return LITEST_NOT_APPLICABLE;
  1357. if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
  1358. (int)finger_count)
  1359. return LITEST_NOT_APPLICABLE;
  1360. litest_enable_3fg_drag(dev->libinput_device, finger_count);
  1361. if (tap_enabled)
  1362. litest_enable_tap(dev->libinput_device);
  1363. else
  1364. litest_disable_tap(dev->libinput_device);
  1365. litest_drain_events(li);
  1366. double y = 30.0;
  1367. for (uint32_t i = 0; i < finger_count; i++)
  1368. litest_touch_down(dev, i, 10 + i, y);
  1369. litest_dispatch(li);
  1370. litest_drain_events_of_type(li,
  1371. LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
  1372. LIBINPUT_EVENT_GESTURE_HOLD_END);
  1373. if (tap_enabled) {
  1374. litest_checkpoint(
  1375. "Expecting no immediate button press as tapping is enabled");
  1376. litest_assert_empty_queue(li);
  1377. } else {
  1378. litest_checkpoint(
  1379. "Expecting immediate swipe begin tapping is disabled");
  1380. litest_assert_gesture_event(li,
  1381. LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
  1382. finger_count);
  1383. }
  1384. while (y < 60.0) {
  1385. y += 2;
  1386. for (uint32_t i = 0; i < finger_count; i++) {
  1387. litest_touch_move(dev, i, 10 + i, y);
  1388. if (i ==
  1389. 0) /* Wait after the first movement to escape the swipe */
  1390. litest_timeout_3fg_drag_or_swipe(li);
  1391. }
  1392. litest_dispatch(li);
  1393. }
  1394. drain_cancelled_swipe_gesture(li);
  1395. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1396. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1397. for (uint32_t i = 0; i < finger_count; i++)
  1398. litest_touch_up(dev, i);
  1399. litest_dispatch(li);
  1400. litest_assert_empty_queue(li);
  1401. litest_timeout_3fg_drag(li);
  1402. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1403. }
  1404. END_TEST
  1405. START_TEST(gestures_3fg_drag_lock_resume_3fg_motion)
  1406. {
  1407. struct litest_device *dev = litest_current_device();
  1408. struct libinput *li = dev->libinput;
  1409. uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
  1410. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
  1411. bool wait_for_timeout = litest_test_param_get_bool(test_env->params, "wait");
  1412. if (litest_slot_count(dev) < 3)
  1413. return LITEST_NOT_APPLICABLE;
  1414. if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
  1415. (int)finger_count)
  1416. return LITEST_NOT_APPLICABLE;
  1417. litest_enable_3fg_drag(dev->libinput_device, finger_count);
  1418. if (tap_enabled)
  1419. litest_enable_tap(dev->libinput_device);
  1420. else
  1421. litest_disable_tap(dev->libinput_device);
  1422. litest_drain_events(li);
  1423. litest_checkpoint("Putting three fingers down + movement)");
  1424. double y = 30.0;
  1425. for (uint32_t i = 0; i < finger_count; i++)
  1426. litest_touch_down(dev, i, 10 + i, y);
  1427. litest_dispatch(li);
  1428. while (y < 60.0) {
  1429. y += 2;
  1430. for (uint32_t i = 0; i < finger_count; i++) {
  1431. litest_touch_move(dev, i, 10 + i, y);
  1432. if (i ==
  1433. 0) /* Wait after the first movement to escape the swipe */
  1434. litest_timeout_3fg_drag_or_swipe(li);
  1435. }
  1436. litest_dispatch(li);
  1437. }
  1438. drain_cancelled_swipe_gesture(li);
  1439. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1440. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1441. litest_checkpoint("Releasing all fingers");
  1442. for (uint32_t i = 0; i < finger_count; i++)
  1443. litest_touch_up(dev, i);
  1444. litest_dispatch(li);
  1445. litest_assert_empty_queue(li);
  1446. litest_checkpoint("Putting three fingers down (no movement)");
  1447. y = 30.0;
  1448. for (uint32_t i = 0; i < finger_count; i++)
  1449. litest_touch_down(dev, i, 10 + i, y);
  1450. litest_dispatch(li);
  1451. litest_assert_empty_queue(li);
  1452. litest_dispatch(li);
  1453. litest_checkpoint("Waiting past finger switch timeout");
  1454. litest_timeout_finger_switch(li);
  1455. if (wait_for_timeout) {
  1456. litest_checkpoint("Waiting past tap/3fg drag timeout");
  1457. litest_timeout_3fg_drag(li);
  1458. litest_assert_empty_queue(li);
  1459. }
  1460. litest_checkpoint("Moving three fingers");
  1461. while (y < 60.0) {
  1462. y += 2;
  1463. for (uint32_t i = 0; i < finger_count; i++)
  1464. litest_touch_move(dev, i, 10 + i, y);
  1465. litest_dispatch(li);
  1466. }
  1467. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1468. litest_checkpoint("Releasing three fingers");
  1469. for (uint32_t i = 0; i < finger_count; i++)
  1470. litest_touch_up(dev, i);
  1471. litest_dispatch(li);
  1472. litest_assert_empty_queue(li);
  1473. litest_timeout_3fg_drag(li);
  1474. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1475. }
  1476. END_TEST
  1477. START_TEST(gestures_3fg_drag_lock_resume_3fg_release_no_motion)
  1478. {
  1479. struct litest_device *dev = litest_current_device();
  1480. struct libinput *li = dev->libinput;
  1481. uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
  1482. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
  1483. bool wait_for_timeout = litest_test_param_get_bool(test_env->params, "wait");
  1484. /* tap-enabled for 4fg finger count doesn't make a difference */
  1485. bool expect_tap = finger_count <= 3 && tap_enabled && !wait_for_timeout;
  1486. if (litest_slot_count(dev) < 3)
  1487. return LITEST_NOT_APPLICABLE;
  1488. if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
  1489. (int)finger_count)
  1490. return LITEST_NOT_APPLICABLE;
  1491. litest_enable_3fg_drag(dev->libinput_device, finger_count);
  1492. if (tap_enabled)
  1493. litest_enable_tap(dev->libinput_device);
  1494. else
  1495. litest_disable_tap(dev->libinput_device);
  1496. litest_drain_events(li);
  1497. litest_checkpoint("Putting %d fingers down with motion for drag", finger_count);
  1498. double y = 30.0;
  1499. for (uint32_t i = 0; i < finger_count; i++)
  1500. litest_touch_down(dev, i, 10 + i, y);
  1501. litest_dispatch(li);
  1502. while (y < 60.0) {
  1503. y += 2;
  1504. for (uint32_t i = 0; i < finger_count; i++) {
  1505. litest_touch_move(dev, i, 10 + i, y);
  1506. if (i ==
  1507. 0) /* Wait after the first movement to escape the swipe */
  1508. litest_timeout_3fg_drag_or_swipe(li);
  1509. }
  1510. litest_dispatch(li);
  1511. }
  1512. drain_cancelled_swipe_gesture(li);
  1513. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1514. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1515. for (uint32_t i = 0; i < finger_count; i++)
  1516. litest_touch_up(dev, i);
  1517. litest_dispatch(li);
  1518. litest_assert_empty_queue(li);
  1519. litest_checkpoint("Putting %d fingers down again (no motion)", finger_count);
  1520. y = 30.0;
  1521. for (uint32_t i = 0; i < finger_count; i++)
  1522. litest_touch_down(dev, i, 10 + i, y);
  1523. litest_dispatch(li);
  1524. litest_assert_empty_queue(li);
  1525. litest_checkpoint("Waiting past finger switch timeout");
  1526. litest_timeout_finger_switch(li);
  1527. if (wait_for_timeout) {
  1528. litest_checkpoint("Waiting past tap/3fg drag timeout");
  1529. litest_timeout_3fg_drag(li);
  1530. litest_assert_empty_queue(li);
  1531. }
  1532. litest_checkpoint("Releasing %d fingers", finger_count);
  1533. for (uint32_t i = 0; i < finger_count; i++)
  1534. litest_touch_up(dev, i);
  1535. litest_dispatch(li);
  1536. if (expect_tap) {
  1537. /* If we're not waiting and tapping is enabled, this is
  1538. * the equivalent of a 3fg tap within the drag timeout */
  1539. litest_checkpoint("Expecting 3fg drag release");
  1540. litest_assert_button_event(li,
  1541. BTN_LEFT,
  1542. LIBINPUT_BUTTON_STATE_RELEASED);
  1543. litest_checkpoint("Expecting 3fg tap");
  1544. litest_assert_button_event(li,
  1545. BTN_MIDDLE,
  1546. LIBINPUT_BUTTON_STATE_PRESSED);
  1547. litest_assert_button_event(li,
  1548. BTN_MIDDLE,
  1549. LIBINPUT_BUTTON_STATE_RELEASED);
  1550. }
  1551. litest_assert_empty_queue(li);
  1552. litest_timeout_3fg_drag(li);
  1553. if (!expect_tap)
  1554. litest_assert_button_event(li,
  1555. BTN_LEFT,
  1556. LIBINPUT_BUTTON_STATE_RELEASED);
  1557. litest_assert_empty_queue(li);
  1558. }
  1559. END_TEST
  1560. START_TEST(gestures_3fg_drag_lock_resume_1fg_motion)
  1561. {
  1562. struct litest_device *dev = litest_current_device();
  1563. struct libinput *li = dev->libinput;
  1564. uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
  1565. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
  1566. if (litest_slot_count(dev) < 3)
  1567. return LITEST_NOT_APPLICABLE;
  1568. if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
  1569. (int)finger_count)
  1570. return LITEST_NOT_APPLICABLE;
  1571. litest_enable_3fg_drag(dev->libinput_device, finger_count);
  1572. if (tap_enabled)
  1573. litest_enable_tap(dev->libinput_device);
  1574. else
  1575. litest_disable_tap(dev->libinput_device);
  1576. litest_drain_events(li);
  1577. litest_checkpoint("Putting 3 fingers down + motion to trigger 3fg drag");
  1578. double y = 30.0;
  1579. for (uint32_t i = 0; i < finger_count; i++)
  1580. litest_touch_down(dev, i, 10 + i, y);
  1581. while (y < 60.0) {
  1582. y += 2;
  1583. for (uint32_t i = 0; i < finger_count; i++) {
  1584. litest_touch_move(dev, i, 10 + i, y);
  1585. if (i ==
  1586. 0) /* Wait after the first movement to escape the swipe */
  1587. litest_timeout_3fg_drag_or_swipe(li);
  1588. }
  1589. litest_dispatch(li);
  1590. }
  1591. drain_cancelled_swipe_gesture(li);
  1592. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1593. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1594. litest_checkpoint("Releasing 3 fingers");
  1595. for (uint32_t i = 0; i < finger_count; i++)
  1596. litest_touch_up(dev, i);
  1597. litest_dispatch(li);
  1598. litest_assert_empty_queue(li);
  1599. litest_checkpoint("Putting 1 finger down and moving it");
  1600. /* fingers are up, now let's put one finger down and move it */
  1601. y = 30.0;
  1602. litest_touch_down(dev, 0, 10, y);
  1603. litest_dispatch(li);
  1604. litest_assert_empty_queue(li);
  1605. /* We need to wait until the gesture code accepts this is one finger only */
  1606. litest_timeout_finger_switch(li);
  1607. while (y < 60.0) {
  1608. y += 2;
  1609. litest_touch_move(dev, 0, 10, y);
  1610. litest_dispatch(li);
  1611. }
  1612. litest_checkpoint("Expecting drag button release and motion");
  1613. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1614. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1615. litest_touch_up(dev, 0);
  1616. litest_dispatch(li);
  1617. litest_assert_empty_queue(li);
  1618. litest_timeout_3fg_drag(li);
  1619. }
  1620. END_TEST
  1621. START_TEST(gestures_3fg_drag_lock_resume_2fg_scroll)
  1622. {
  1623. struct litest_device *dev = litest_current_device();
  1624. struct libinput *li = dev->libinput;
  1625. uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
  1626. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
  1627. if (litest_slot_count(dev) < 3)
  1628. return LITEST_NOT_APPLICABLE;
  1629. if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
  1630. (int)finger_count)
  1631. return LITEST_NOT_APPLICABLE;
  1632. litest_enable_3fg_drag(dev->libinput_device, finger_count);
  1633. if (tap_enabled)
  1634. litest_enable_tap(dev->libinput_device);
  1635. else
  1636. litest_disable_tap(dev->libinput_device);
  1637. litest_drain_events(li);
  1638. litest_checkpoint("Putting 3 fingers down + motion to trigger 3fg drag");
  1639. double y = 30.0;
  1640. for (uint32_t i = 0; i < finger_count; i++)
  1641. litest_touch_down(dev, i, 10 + i, y);
  1642. while (y < 60.0) {
  1643. y += 2;
  1644. for (uint32_t i = 0; i < finger_count; i++) {
  1645. litest_touch_move(dev, i, 10 + i, y);
  1646. if (i ==
  1647. 0) /* Wait after the first movement to escape the swipe */
  1648. litest_timeout_3fg_drag_or_swipe(li);
  1649. }
  1650. litest_dispatch(li);
  1651. }
  1652. drain_cancelled_swipe_gesture(li);
  1653. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1654. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1655. litest_checkpoint("Releasing 3 fingers");
  1656. for (uint32_t i = 0; i < finger_count; i++)
  1657. litest_touch_up(dev, i);
  1658. litest_dispatch(li);
  1659. litest_assert_empty_queue(li);
  1660. litest_checkpoint("Putting 2 fingers down and moving them");
  1661. y = 30.0;
  1662. litest_touch_down(dev, 0, 10, y);
  1663. litest_touch_down(dev, 1, 20, y);
  1664. litest_dispatch(li);
  1665. litest_assert_empty_queue(li);
  1666. litest_timeout_finger_switch(li);
  1667. while (y < 60.0) {
  1668. y += 2;
  1669. litest_touch_move(dev, 0, 10, y);
  1670. litest_touch_move(dev, 1, 20, y);
  1671. litest_dispatch(li);
  1672. }
  1673. litest_checkpoint("Expecting drag button release and scroll");
  1674. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1675. litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
  1676. litest_touch_up(dev, 0);
  1677. litest_dispatch(li);
  1678. litest_assert_empty_queue(li);
  1679. litest_timeout_3fg_drag(li);
  1680. }
  1681. END_TEST
  1682. START_TEST(gestures_3fg_drag_lock_resume_1fg_tap)
  1683. {
  1684. struct litest_device *dev = litest_current_device();
  1685. struct libinput *li = dev->libinput;
  1686. int finger_count = litest_test_param_get_i32(test_env->params, "fingers");
  1687. if (litest_slot_count(dev) < 3)
  1688. return LITEST_NOT_APPLICABLE;
  1689. if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
  1690. finger_count)
  1691. return LITEST_NOT_APPLICABLE;
  1692. litest_enable_3fg_drag(dev->libinput_device, finger_count);
  1693. litest_enable_tap(dev->libinput_device);
  1694. litest_drain_events(li);
  1695. litest_checkpoint("Putting 3 fingers down for 3fg drag");
  1696. double y = 30.0;
  1697. for (int i = 0; i < finger_count; i++)
  1698. litest_touch_down(dev, i, 10 + i, y);
  1699. litest_dispatch(li);
  1700. while (y < 60.0) {
  1701. y += 2;
  1702. for (int i = 0; i < finger_count; i++) {
  1703. litest_touch_move(dev, i, 10 + i, y);
  1704. if (i ==
  1705. 0) /* Wait after the first movement to escape the swipe */
  1706. litest_timeout_3fg_drag_or_swipe(li);
  1707. }
  1708. litest_dispatch(li);
  1709. }
  1710. litest_drain_events_of_type(li,
  1711. LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
  1712. LIBINPUT_EVENT_GESTURE_HOLD_END,
  1713. -1);
  1714. drain_cancelled_swipe_gesture(li);
  1715. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1716. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1717. litest_checkpoint("Releasing 3 fingers");
  1718. for (int i = 0; i < finger_count; i++)
  1719. litest_touch_up(dev, i);
  1720. litest_dispatch(li);
  1721. litest_assert_empty_queue(li);
  1722. litest_checkpoint("Tapping with 1 finger");
  1723. /* fingers are up, now let's tap with one finger */
  1724. y = 30.0;
  1725. litest_touch_down(dev, 0, 10, y);
  1726. litest_dispatch(li);
  1727. litest_assert_empty_queue(li);
  1728. litest_touch_up(dev, 0);
  1729. litest_dispatch(li);
  1730. litest_timeout_tap(li);
  1731. litest_checkpoint("Expecting drag release followed by 1fg tap");
  1732. /* 3fg drag lock must be cancelled */
  1733. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1734. /* And a 1fg tap */
  1735. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1736. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1737. litest_assert_empty_queue(li);
  1738. litest_timeout_3fg_drag(li);
  1739. }
  1740. END_TEST
  1741. START_TEST(gestures_3fg_drag_fast_swipe)
  1742. {
  1743. struct litest_device *dev = litest_current_device();
  1744. struct libinput *li = dev->libinput;
  1745. uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
  1746. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
  1747. if (litest_slot_count(dev) < 3)
  1748. return LITEST_NOT_APPLICABLE;
  1749. if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
  1750. (int)finger_count)
  1751. return LITEST_NOT_APPLICABLE;
  1752. litest_enable_3fg_drag(dev->libinput_device, finger_count);
  1753. if (tap_enabled)
  1754. litest_enable_tap(dev->libinput_device);
  1755. else
  1756. litest_disable_tap(dev->libinput_device);
  1757. litest_drain_events(li);
  1758. double y = 30.0;
  1759. for (uint32_t i = 0; i < finger_count; i++)
  1760. litest_touch_down(dev, i, 10 + i, y);
  1761. while (y < 60.0) {
  1762. y += 2;
  1763. for (uint32_t i = 0; i < finger_count; i++) {
  1764. litest_touch_move(dev, i, 10 + i, y);
  1765. }
  1766. litest_dispatch(li);
  1767. }
  1768. litest_drain_events_of_type(li,
  1769. LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
  1770. LIBINPUT_EVENT_GESTURE_HOLD_END);
  1771. auto begin = libinput_get_event(li);
  1772. litest_is_gesture_event(begin,
  1773. LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
  1774. finger_count);
  1775. libinput_event_destroy(begin);
  1776. struct libinput_event *update;
  1777. while ((update = libinput_get_event(li))) {
  1778. litest_is_gesture_event(update,
  1779. LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
  1780. finger_count);
  1781. libinput_event_destroy(update);
  1782. }
  1783. for (uint32_t i = 0; i < finger_count; i++)
  1784. litest_touch_up(dev, i);
  1785. litest_dispatch(li);
  1786. auto end = libinput_get_event(li);
  1787. auto gev = litest_is_gesture_event(end,
  1788. LIBINPUT_EVENT_GESTURE_SWIPE_END,
  1789. finger_count);
  1790. litest_assert(!libinput_event_gesture_get_cancelled(gev));
  1791. libinput_event_destroy(end);
  1792. }
  1793. END_TEST
  1794. START_TEST(gestures_3fg_drag_slow_start)
  1795. {
  1796. struct litest_device *dev = litest_current_device();
  1797. struct libinput *li = dev->libinput;
  1798. uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
  1799. bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
  1800. if (litest_slot_count(dev) < 3)
  1801. return LITEST_NOT_APPLICABLE;
  1802. if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
  1803. (int)finger_count)
  1804. return LITEST_NOT_APPLICABLE;
  1805. litest_enable_3fg_drag(dev->libinput_device, finger_count);
  1806. if (tap_enabled)
  1807. litest_enable_tap(dev->libinput_device);
  1808. else
  1809. litest_disable_tap(dev->libinput_device);
  1810. litest_drain_events(li);
  1811. /* Fingers are set down, then we do nothing, then we swipe fast. Because
  1812. * we did nothing at first even fast movement must become a 3fg drag, not
  1813. * a swipe.
  1814. */
  1815. double y = 30.0;
  1816. for (uint32_t i = 0; i < finger_count; i++)
  1817. litest_touch_down(dev, i, 10 + i, y);
  1818. litest_checkpoint("Waiting past timeout before fast finger move");
  1819. litest_timeout_3fg_drag_or_swipe(li);
  1820. /* Now move fast */
  1821. while (y < 60.0) {
  1822. y += 2;
  1823. for (uint32_t i = 0; i < finger_count; i++) {
  1824. litest_touch_move(dev, i, 10 + i, y);
  1825. }
  1826. litest_dispatch(li);
  1827. }
  1828. drain_cancelled_swipe_gesture(li);
  1829. litest_checkpoint("Expecting button press for 3fg drag");
  1830. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  1831. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
  1832. for (uint32_t i = 0; i < finger_count; i++)
  1833. litest_touch_up(dev, i);
  1834. litest_dispatch(li);
  1835. litest_assert_empty_queue(li);
  1836. litest_timeout_3fg_drag(li);
  1837. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  1838. }
  1839. END_TEST
  1840. TEST_COLLECTION(gestures)
  1841. {
  1842. /* clang-format off */
  1843. litest_add(gestures_cap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
  1844. litest_add(gestures_nocap, LITEST_ANY, LITEST_TOUCHPAD);
  1845. litest_add(gestures_swipe_3fg_btntool_pinch_like, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
  1846. litest_add(gestures_3fg_buttonarea_scroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
  1847. litest_add(gestures_3fg_buttonarea_scroll_btntool, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
  1848. litest_add(gestures_time_usec, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
  1849. litest_add(gestures_hold_config_default_disabled, LITEST_TOUCHPAD|LITEST_SEMI_MT, LITEST_ANY);
  1850. litest_add(gestures_hold_config_default_enabled, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
  1851. litest_add(gestures_hold_config_set_invalid, LITEST_TOUCHPAD, LITEST_ANY);
  1852. litest_add(gestures_hold_config_is_available, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
  1853. litest_add(gestures_hold_config_is_not_available, LITEST_TOUCHPAD|LITEST_SEMI_MT, LITEST_ANY);
  1854. litest_with_parameters(params,
  1855. "fingers", 'i', 4, 1, 2, 3, 4,
  1856. "tap", 'b') {
  1857. litest_add_parametrized(gestures_hold, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1858. litest_add_parametrized(gestures_hold_cancel, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1859. }
  1860. litest_with_parameters(params, "direction", 'I', 8, litest_named_i32(N), litest_named_i32(NE),
  1861. litest_named_i32(E), litest_named_i32(SE),
  1862. litest_named_i32(S), litest_named_i32(SW),
  1863. litest_named_i32(W), litest_named_i32(NW)) {
  1864. litest_add_parametrized(gestures_swipe_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1865. litest_add_parametrized(gestures_swipe_3fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1866. litest_add_parametrized(gestures_swipe_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1867. litest_add_parametrized(gestures_swipe_4fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1868. litest_add_parametrized(gestures_pinch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1869. litest_add_parametrized(gestures_pinch_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1870. litest_add_parametrized(gestures_pinch_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1871. litest_add_parametrized(gestures_spread, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1872. litest_add_parametrized(gestures_hold_then_swipe_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1873. litest_add_parametrized(gestures_hold_then_swipe_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1874. litest_add_parametrized(gestures_hold_then_pinch_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1875. litest_add_parametrized(gestures_hold_then_pinch_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1876. litest_add_parametrized(gestures_hold_then_pinch_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1877. litest_add_parametrized(gestures_hold_then_spread, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1878. }
  1879. litest_add(gestures_hold_then_3fg_buttonarea_scroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
  1880. litest_add(gestures_hold_once_on_double_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
  1881. litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3) {
  1882. litest_add_parametrized(gestures_hold_once_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY, params);
  1883. }
  1884. litest_add(gestures_hold_and_motion_before_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
  1885. litest_add(gestures_hold_and_motion_after_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
  1886. litest_with_parameters(params,
  1887. "fingers", 'u', 2, 3, 4,
  1888. "tap-enabled", 'b') {
  1889. litest_add_parametrized(gestures_3fg_drag, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1890. }
  1891. litest_with_parameters(params,
  1892. "fingers", 'u', 2, 3, 4,
  1893. "tap-enabled", 'b',
  1894. "wait", 'b') {
  1895. litest_add_parametrized(gestures_3fg_drag_lock_resume_3fg_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1896. litest_add_parametrized(gestures_3fg_drag_lock_resume_3fg_release_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1897. }
  1898. litest_with_parameters(params,
  1899. "fingers", 'u', 2, 3, 4,
  1900. "tap-enabled", 'b') {
  1901. litest_add_parametrized(gestures_3fg_drag_lock_resume_1fg_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1902. litest_add_parametrized(gestures_3fg_drag_lock_resume_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1903. }
  1904. litest_with_parameters(params, "fingers", 'i', 2, 3, 4) {
  1905. litest_add_parametrized(gestures_3fg_drag_lock_resume_1fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1906. }
  1907. litest_with_parameters(params,
  1908. "fingers", 'u', 2, 3, 4,
  1909. "tap-enabled", 'b') {
  1910. litest_add_parametrized(gestures_3fg_drag_fast_swipe, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1911. litest_add_parametrized(gestures_3fg_drag_slow_start, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
  1912. }
  1913. /* Timing-sensitive test, valgrind is too slow */
  1914. if (!RUNNING_ON_VALGRIND)
  1915. litest_add(gestures_swipe_3fg_unaccel, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
  1916. /* clang-format on */
  1917. }