test-touch.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. /*
  2. * Copyright © 2013 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 <errno.h>
  25. #include <fcntl.h>
  26. #include <libevdev/libevdev.h>
  27. #include <libinput.h>
  28. #include <unistd.h>
  29. #include "libinput-util.h"
  30. #include "litest.h"
  31. START_TEST(touch_frame_events)
  32. {
  33. struct litest_device *dev = litest_current_device();
  34. struct libinput *li = dev->libinput;
  35. struct libinput_event *event;
  36. int have_frame_event = 0;
  37. litest_drain_events(dev->libinput);
  38. litest_touch_down(dev, 0, 10, 10);
  39. litest_dispatch(li);
  40. while ((event = libinput_get_event(li))) {
  41. if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME)
  42. have_frame_event++;
  43. libinput_event_destroy(event);
  44. }
  45. litest_assert_int_eq(have_frame_event, 1);
  46. litest_touch_down(dev, 1, 10, 10);
  47. litest_dispatch(li);
  48. while ((event = libinput_get_event(li))) {
  49. if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME)
  50. have_frame_event++;
  51. libinput_event_destroy(event);
  52. }
  53. litest_assert_int_eq(have_frame_event, 2);
  54. }
  55. END_TEST
  56. START_TEST(touch_downup_no_motion)
  57. {
  58. struct litest_device *dev = litest_current_device();
  59. struct libinput *li = dev->libinput;
  60. litest_drain_events(li);
  61. litest_touch_down(dev, 0, 10, 10);
  62. litest_dispatch(li);
  63. litest_assert_touch_down_frame(li);
  64. litest_touch_up(dev, 0);
  65. litest_dispatch(li);
  66. litest_assert_touch_up_frame(li);
  67. }
  68. END_TEST
  69. START_TEST(touch_abs_transform)
  70. {
  71. struct litest_device *dev;
  72. struct libinput *libinput;
  73. struct libinput_event *ev;
  74. struct libinput_event_touch *tev;
  75. double fx, fy;
  76. bool tested = false;
  77. struct input_absinfo abs[] = {
  78. { ABS_X, 0, 32767, 75, 0, 10 },
  79. { ABS_Y, 0, 32767, 129, 0, 9 },
  80. { ABS_MT_POSITION_X, 0, 32767, 0, 0, 10 },
  81. { ABS_MT_POSITION_Y, 0, 32767, 0, 0, 9 },
  82. { .value = -1 },
  83. };
  84. dev = litest_create_device_with_overrides(LITEST_WACOM_ISDV4_E6_FINGER,
  85. "litest Highres touch device",
  86. NULL,
  87. abs,
  88. NULL);
  89. libinput = dev->libinput;
  90. litest_touch_down(dev, 0, 100, 100);
  91. litest_dispatch(libinput);
  92. while ((ev = libinput_get_event(libinput))) {
  93. if (libinput_event_get_type(ev) != LIBINPUT_EVENT_TOUCH_DOWN) {
  94. libinput_event_destroy(ev);
  95. continue;
  96. }
  97. tev = libinput_event_get_touch_event(ev);
  98. fx = libinput_event_touch_get_x_transformed(tev, 1920);
  99. litest_assert_double_eq_epsilon(fx, 1920.0, 0.1);
  100. litest_assert_double_lt(fx, 1920.0);
  101. fy = libinput_event_touch_get_y_transformed(tev, 720);
  102. litest_assert_double_eq_epsilon(fy, 720.0, 0.1);
  103. litest_assert_double_lt(fy, 720.0);
  104. tested = true;
  105. libinput_event_destroy(ev);
  106. }
  107. litest_assert(tested);
  108. litest_device_destroy(dev);
  109. }
  110. END_TEST
  111. static inline void
  112. touch_assert_seat_slot(struct libinput *li,
  113. enum libinput_event_type type,
  114. unsigned int slot,
  115. unsigned int seat_slot)
  116. {
  117. struct libinput_event *ev;
  118. struct libinput_event_touch *tev;
  119. litest_dispatch(li);
  120. ev = libinput_get_event(li);
  121. tev = litest_is_touch_event(ev, type);
  122. slot = libinput_event_touch_get_slot(tev);
  123. litest_assert_int_eq(slot, slot);
  124. slot = libinput_event_touch_get_seat_slot(tev);
  125. litest_assert_int_eq(slot, seat_slot);
  126. libinput_event_destroy(ev);
  127. ev = libinput_get_event(li);
  128. litest_assert_event_type(ev, LIBINPUT_EVENT_TOUCH_FRAME);
  129. libinput_event_destroy(ev);
  130. }
  131. START_TEST(touch_seat_slot)
  132. {
  133. struct litest_device *dev1 = litest_current_device();
  134. struct litest_device *dev2;
  135. struct libinput *li = dev1->libinput;
  136. dev2 = litest_add_device(li, LITEST_WACOM_ISDV4_E6_FINGER);
  137. litest_drain_events(li);
  138. litest_touch_down(dev1, 0, 50, 50);
  139. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 0, 0);
  140. litest_touch_down(dev2, 0, 50, 50);
  141. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 0, 1);
  142. litest_touch_down(dev2, 1, 60, 50);
  143. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 1, 2);
  144. litest_touch_down(dev1, 1, 60, 50);
  145. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 1, 3);
  146. litest_touch_move_to(dev1, 0, 50, 50, 60, 70, 10);
  147. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_MOTION, 0, 0);
  148. litest_drain_events(li);
  149. litest_touch_move_to(dev2, 1, 50, 50, 60, 70, 10);
  150. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_MOTION, 1, 2);
  151. litest_drain_events(li);
  152. litest_touch_up(dev1, 0);
  153. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 0, 0);
  154. litest_touch_up(dev2, 0);
  155. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 0, 1);
  156. litest_touch_up(dev2, 1);
  157. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 1, 2);
  158. litest_touch_up(dev1, 1);
  159. touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 1, 3);
  160. litest_device_destroy(dev2);
  161. }
  162. END_TEST
  163. START_TEST(touch_many_slots)
  164. {
  165. struct libinput *libinput;
  166. struct litest_device *dev;
  167. struct libinput_event *ev;
  168. int slot;
  169. const int num_tps = 100;
  170. int slot_count = 0;
  171. enum libinput_event_type type;
  172. struct input_absinfo abs[] = {
  173. { ABS_MT_SLOT, 0, num_tps - 1, 0, 0, 0 },
  174. { .value = -1 },
  175. };
  176. dev = litest_create_device_with_overrides(LITEST_WACOM_ISDV4_E6_FINGER,
  177. "litest Multi-touch device",
  178. NULL,
  179. abs,
  180. NULL);
  181. libinput = dev->libinput;
  182. for (slot = 0; slot < num_tps; ++slot)
  183. litest_touch_down(dev, slot, 0, 0);
  184. for (slot = 0; slot < num_tps; ++slot)
  185. litest_touch_up(dev, slot);
  186. litest_dispatch(libinput);
  187. while ((ev = libinput_get_event(libinput))) {
  188. type = libinput_event_get_type(ev);
  189. if (type == LIBINPUT_EVENT_TOUCH_DOWN)
  190. slot_count++;
  191. else if (type == LIBINPUT_EVENT_TOUCH_UP)
  192. break;
  193. libinput_event_destroy(ev);
  194. litest_dispatch(libinput);
  195. }
  196. litest_assert_notnull(ev);
  197. litest_assert_int_gt(slot_count, 0);
  198. litest_dispatch(libinput);
  199. do {
  200. type = libinput_event_get_type(ev);
  201. litest_assert_enum_ne(type, LIBINPUT_EVENT_TOUCH_DOWN);
  202. if (type == LIBINPUT_EVENT_TOUCH_UP)
  203. slot_count--;
  204. libinput_event_destroy(ev);
  205. litest_dispatch(libinput);
  206. } while ((ev = libinput_get_event(libinput)));
  207. litest_assert_int_eq(slot_count, 0);
  208. litest_device_destroy(dev);
  209. }
  210. END_TEST
  211. START_TEST(touch_double_touch_down_up)
  212. {
  213. struct libinput *libinput;
  214. struct litest_device *dev;
  215. struct libinput_event *ev;
  216. bool got_down = false;
  217. bool got_up = false;
  218. dev = litest_current_device();
  219. libinput = dev->libinput;
  220. litest_disable_log_handler(libinput);
  221. /* note: this test is a false negative, libevdev will filter
  222. * tracking IDs re-used in the same slot. */
  223. litest_touch_down(dev, 0, 0, 0);
  224. litest_touch_down(dev, 0, 0, 0);
  225. litest_touch_up(dev, 0);
  226. litest_touch_up(dev, 0);
  227. litest_dispatch(libinput);
  228. litest_restore_log_handler(libinput);
  229. while ((ev = libinput_get_event(libinput))) {
  230. switch (libinput_event_get_type(ev)) {
  231. case LIBINPUT_EVENT_TOUCH_DOWN:
  232. litest_assert(!got_down);
  233. got_down = true;
  234. break;
  235. case LIBINPUT_EVENT_TOUCH_UP:
  236. litest_assert(got_down);
  237. litest_assert(!got_up);
  238. got_up = true;
  239. break;
  240. default:
  241. break;
  242. }
  243. libinput_event_destroy(ev);
  244. litest_dispatch(libinput);
  245. }
  246. litest_assert(got_down);
  247. litest_assert(got_up);
  248. }
  249. END_TEST
  250. START_TEST(touch_calibration_scale)
  251. {
  252. struct libinput *li;
  253. struct litest_device *dev;
  254. struct libinput_event *ev;
  255. struct libinput_event_touch *tev;
  256. float matrix[6] = { 1, 0, 0, 0, 1, 0 };
  257. float calibration;
  258. double x, y;
  259. const int width = 640, height = 480;
  260. dev = litest_current_device();
  261. li = dev->libinput;
  262. for (calibration = 0.1; calibration < 1; calibration += 0.1) {
  263. libinput_device_config_calibration_set_matrix(dev->libinput_device,
  264. matrix);
  265. litest_drain_events(li);
  266. litest_touch_down(dev, 0, 100, 100);
  267. litest_touch_up(dev, 0);
  268. litest_dispatch(li);
  269. ev = libinput_get_event(li);
  270. tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
  271. x = libinput_event_touch_get_x_transformed(tev, width);
  272. y = libinput_event_touch_get_y_transformed(tev, height);
  273. litest_assert_int_eq(round(x), round(width * matrix[0]));
  274. litest_assert_int_eq(round(y), round(height * matrix[4]));
  275. libinput_event_destroy(ev);
  276. litest_drain_events(li);
  277. matrix[0] = calibration;
  278. matrix[4] = 1 - calibration;
  279. }
  280. }
  281. END_TEST
  282. START_TEST(touch_calibration_rotation)
  283. {
  284. struct libinput *li;
  285. struct litest_device *dev;
  286. struct libinput_event *ev;
  287. struct libinput_event_touch *tev;
  288. float matrix[6];
  289. int i;
  290. double x, y;
  291. int width = 1024, height = 480;
  292. dev = litest_current_device();
  293. li = dev->libinput;
  294. for (i = 0; i < 4; i++) {
  295. float angle = i * M_PI / 2;
  296. /* [ cos -sin tx ]
  297. [ sin cos ty ]
  298. [ 0 0 1 ] */
  299. matrix[0] = cos(angle);
  300. matrix[1] = -sin(angle);
  301. matrix[3] = sin(angle);
  302. matrix[4] = cos(angle);
  303. switch (i) {
  304. case 0: /* 0 deg */
  305. matrix[2] = 0;
  306. matrix[5] = 0;
  307. break;
  308. case 1: /* 90 deg cw */
  309. matrix[2] = 1;
  310. matrix[5] = 0;
  311. break;
  312. case 2: /* 180 deg cw */
  313. matrix[2] = 1;
  314. matrix[5] = 1;
  315. break;
  316. case 3: /* 270 deg cw */
  317. matrix[2] = 0;
  318. matrix[5] = 1;
  319. break;
  320. }
  321. libinput_device_config_calibration_set_matrix(dev->libinput_device,
  322. matrix);
  323. litest_drain_events(li);
  324. litest_touch_down(dev, 0, 80, 20);
  325. litest_touch_up(dev, 0);
  326. litest_dispatch(li);
  327. ev = libinput_get_event(li);
  328. tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
  329. x = libinput_event_touch_get_x_transformed(tev, width);
  330. y = libinput_event_touch_get_y_transformed(tev, height);
  331. /* rounding errors... */
  332. switch (i) {
  333. case 0: /* 0 deg */
  334. litest_assert_double_eq_epsilon(x, width * 0.8, 1.0);
  335. litest_assert_double_eq_epsilon(y, height * 0.2, 1.0);
  336. break;
  337. case 1: /* 90 deg cw */
  338. litest_assert_double_eq_epsilon(x, width * 0.8, 1.0);
  339. litest_assert_double_eq_epsilon(y, height * 0.8, 1.0);
  340. break;
  341. case 2: /* 180 deg cw */
  342. litest_assert_double_eq_epsilon(x, width * 0.2, 1.0);
  343. litest_assert_double_eq_epsilon(y, height * 0.8, 1.0);
  344. break;
  345. case 3: /* 270 deg cw */
  346. litest_assert_double_eq_epsilon(x, width * 0.2, 1.0);
  347. litest_assert_double_eq_epsilon(y, height * 0.2, 1.0);
  348. break;
  349. }
  350. libinput_event_destroy(ev);
  351. litest_drain_events(li);
  352. }
  353. }
  354. END_TEST
  355. START_TEST(touch_calibration_translation)
  356. {
  357. struct libinput *li;
  358. struct litest_device *dev;
  359. struct libinput_event *ev;
  360. struct libinput_event_touch *tev;
  361. float matrix[6] = { 1, 0, 0, 0, 1, 0 };
  362. float translate;
  363. double x, y;
  364. const int width = 640, height = 480;
  365. dev = litest_current_device();
  366. li = dev->libinput;
  367. /* translating from 0 up to 1 device width/height */
  368. for (translate = 0.1; translate <= 1; translate += 0.1) {
  369. libinput_device_config_calibration_set_matrix(dev->libinput_device,
  370. matrix);
  371. litest_drain_events(li);
  372. litest_touch_down(dev, 0, 100, 100);
  373. litest_touch_up(dev, 0);
  374. litest_dispatch(li);
  375. ev = libinput_get_event(li);
  376. tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
  377. x = libinput_event_touch_get_x_transformed(tev, width);
  378. y = libinput_event_touch_get_y_transformed(tev, height);
  379. /* sigh. rounding errors */
  380. litest_assert_int_ge(round(x), width + round(width * matrix[2]) - 1);
  381. litest_assert_int_ge(round(y), height + round(height * matrix[5]) - 1);
  382. litest_assert_int_le(round(x), width + round(width * matrix[2]) + 1);
  383. litest_assert_int_le(round(y), height + round(height * matrix[5]) + 1);
  384. libinput_event_destroy(ev);
  385. litest_drain_events(li);
  386. matrix[2] = translate;
  387. matrix[5] = 1 - translate;
  388. }
  389. }
  390. END_TEST
  391. START_TEST(touch_calibrated_screen_path)
  392. {
  393. struct litest_device *dev = litest_current_device();
  394. float matrix[6];
  395. int rc;
  396. rc = libinput_device_config_calibration_has_matrix(dev->libinput_device);
  397. litest_assert_int_eq(rc, 1);
  398. rc = libinput_device_config_calibration_get_matrix(dev->libinput_device,
  399. matrix);
  400. litest_assert_int_eq(rc, 1);
  401. litest_assert_double_eq(matrix[0], 1.2);
  402. litest_assert_double_eq(matrix[1], 3.4);
  403. litest_assert_double_eq(matrix[2], 5.6);
  404. litest_assert_double_eq(matrix[3], 7.8);
  405. litest_assert_double_eq(matrix[4], 9.10);
  406. litest_assert_double_eq(matrix[5], 11.12);
  407. }
  408. END_TEST
  409. START_TEST(touch_calibration_config)
  410. {
  411. struct litest_device *dev = litest_current_device();
  412. float identity[6] = { 1, 0, 0, 0, 1, 0 };
  413. float nonidentity[6] = { 1, 2, 3, 4, 5, 6 };
  414. float matrix[6];
  415. enum libinput_config_status status;
  416. int rc;
  417. rc = libinput_device_config_calibration_has_matrix(dev->libinput_device);
  418. litest_assert_int_eq(rc, 1);
  419. /* Twice so we have every to-fro combination */
  420. for (int i = 0; i < 2; i++) {
  421. status = libinput_device_config_calibration_set_matrix(
  422. dev->libinput_device,
  423. identity);
  424. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  425. libinput_device_config_calibration_get_matrix(dev->libinput_device,
  426. matrix);
  427. litest_assert_int_eq(memcmp(matrix, identity, sizeof(matrix)), 0);
  428. status = libinput_device_config_calibration_set_matrix(
  429. dev->libinput_device,
  430. nonidentity);
  431. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  432. libinput_device_config_calibration_get_matrix(dev->libinput_device,
  433. matrix);
  434. litest_assert_int_eq(memcmp(matrix, nonidentity, sizeof(matrix)), 0);
  435. }
  436. }
  437. END_TEST
  438. static int
  439. open_restricted(const char *path, int flags, void *data)
  440. {
  441. int fd;
  442. fd = open(path, flags);
  443. return fd < 0 ? -errno : fd;
  444. }
  445. static void
  446. close_restricted(int fd, void *data)
  447. {
  448. close(fd);
  449. }
  450. static const struct libinput_interface simple_interface = {
  451. .open_restricted = open_restricted,
  452. .close_restricted = close_restricted,
  453. };
  454. START_TEST(touch_calibrated_screen_udev)
  455. {
  456. struct libinput *li;
  457. struct libinput_event *ev;
  458. struct libinput_device *device = NULL;
  459. struct udev *udev;
  460. float matrix[6];
  461. int rc;
  462. udev = udev_new();
  463. litest_assert_notnull(udev);
  464. li = libinput_udev_create_context(&simple_interface, NULL, udev);
  465. litest_assert_notnull(li);
  466. litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
  467. litest_dispatch(li);
  468. while ((ev = libinput_get_event(li))) {
  469. struct libinput_device *d;
  470. if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED) {
  471. libinput_event_destroy(ev);
  472. continue;
  473. }
  474. d = libinput_event_get_device(ev);
  475. if (libinput_device_get_id_vendor(d) == 0x22 &&
  476. libinput_device_get_id_product(d) == 0x33) {
  477. device = libinput_device_ref(d);
  478. litest_drain_events(li);
  479. }
  480. libinput_event_destroy(ev);
  481. }
  482. litest_drain_events(li);
  483. litest_assert_notnull(device);
  484. rc = libinput_device_config_calibration_has_matrix(device);
  485. litest_assert_int_eq(rc, 1);
  486. rc = libinput_device_config_calibration_get_matrix(device, matrix);
  487. litest_assert_int_eq(rc, 1);
  488. litest_assert_double_eq(matrix[0], 1.2);
  489. litest_assert_double_eq(matrix[1], 3.4);
  490. litest_assert_double_eq(matrix[2], 5.6);
  491. litest_assert_double_eq(matrix[3], 7.8);
  492. litest_assert_double_eq(matrix[4], 9.10);
  493. litest_assert_double_eq(matrix[5], 11.12);
  494. libinput_device_unref(device);
  495. libinput_unref(li);
  496. udev_unref(udev);
  497. }
  498. END_TEST
  499. START_TEST(touch_no_left_handed)
  500. {
  501. struct litest_device *dev = litest_current_device();
  502. struct libinput_device *d = dev->libinput_device;
  503. enum libinput_config_status status;
  504. int rc;
  505. rc = libinput_device_config_left_handed_is_available(d);
  506. litest_assert_int_eq(rc, 0);
  507. rc = libinput_device_config_left_handed_get(d);
  508. litest_assert_int_eq(rc, 0);
  509. rc = libinput_device_config_left_handed_get_default(d);
  510. litest_assert_int_eq(rc, 0);
  511. status = libinput_device_config_left_handed_set(d, 0);
  512. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
  513. }
  514. END_TEST
  515. START_TEST(fake_mt_exists)
  516. {
  517. struct litest_device *dev = litest_current_device();
  518. struct libinput *li = dev->libinput;
  519. struct libinput_event *event;
  520. struct libinput_device *device;
  521. litest_dispatch(li);
  522. event = libinput_get_event(li);
  523. device = libinput_event_get_device(event);
  524. litest_assert(
  525. !libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH));
  526. /* This test may need fixing if we add other fake-mt devices that
  527. * have different capabilities */
  528. litest_assert(
  529. libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER));
  530. libinput_event_destroy(event);
  531. }
  532. END_TEST
  533. START_TEST(fake_mt_no_touch_events)
  534. {
  535. struct litest_device *dev = litest_current_device();
  536. struct libinput *li = dev->libinput;
  537. litest_drain_events(li);
  538. litest_touch_down(dev, 0, 50, 50);
  539. litest_touch_move_to(dev, 0, 50, 50, 70, 70, 5);
  540. litest_touch_up(dev, 0);
  541. litest_touch_down(dev, 0, 50, 50);
  542. litest_touch_down(dev, 1, 70, 70);
  543. litest_touch_move_to(dev, 0, 50, 50, 90, 40, 10);
  544. litest_touch_move_to(dev, 0, 70, 70, 40, 50, 10);
  545. litest_touch_up(dev, 0);
  546. litest_touch_up(dev, 1);
  547. litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
  548. }
  549. END_TEST
  550. START_TEST(touch_protocol_a_init)
  551. {
  552. struct litest_device *dev = litest_current_device();
  553. struct libinput *li = dev->libinput;
  554. struct libinput_device *device = dev->libinput_device;
  555. litest_wait_for_event(li);
  556. litest_assert(
  557. libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH));
  558. }
  559. END_TEST
  560. START_TEST(touch_protocol_a_touch)
  561. {
  562. struct litest_device *dev = litest_current_device();
  563. struct libinput *li = dev->libinput;
  564. struct libinput_event *ev;
  565. struct libinput_event_touch *tev;
  566. double x, y, oldx, oldy;
  567. litest_drain_events(li);
  568. litest_touch_down(dev, 0, 5, 95);
  569. litest_dispatch(li);
  570. ev = libinput_get_event(li);
  571. tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
  572. oldx = libinput_event_touch_get_x(tev);
  573. oldy = libinput_event_touch_get_y(tev);
  574. libinput_event_destroy(ev);
  575. ev = libinput_get_event(li);
  576. litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME);
  577. libinput_event_destroy(ev);
  578. litest_touch_move_to(dev, 0, 10, 90, 90, 10, 20);
  579. litest_dispatch(li);
  580. while ((ev = libinput_get_event(li))) {
  581. if (libinput_event_get_type(ev) == LIBINPUT_EVENT_TOUCH_FRAME) {
  582. libinput_event_destroy(ev);
  583. continue;
  584. }
  585. litest_assert_event_type(ev, LIBINPUT_EVENT_TOUCH_MOTION);
  586. tev = libinput_event_get_touch_event(ev);
  587. x = libinput_event_touch_get_x(tev);
  588. y = libinput_event_touch_get_y(tev);
  589. litest_assert_int_gt(x, oldx);
  590. litest_assert_int_lt(y, oldy);
  591. oldx = x;
  592. oldy = y;
  593. libinput_event_destroy(ev);
  594. }
  595. litest_touch_up(dev, 0);
  596. litest_dispatch(li);
  597. ev = libinput_get_event(li);
  598. litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_UP);
  599. libinput_event_destroy(ev);
  600. }
  601. END_TEST
  602. START_TEST(touch_protocol_a_2fg_touch)
  603. {
  604. struct litest_device *dev = litest_current_device();
  605. struct libinput *li = dev->libinput;
  606. struct libinput_event *ev;
  607. struct libinput_event_touch *tev;
  608. int pos;
  609. litest_drain_events(li);
  610. litest_touch_down(dev, 0, 5, 95);
  611. litest_touch_down(dev, 1, 95, 5);
  612. litest_dispatch(li);
  613. litest_assert_touch_down_frame(li);
  614. ev = libinput_get_event(li);
  615. litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
  616. libinput_event_destroy(ev);
  617. ev = libinput_get_event(li);
  618. litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME);
  619. libinput_event_destroy(ev);
  620. for (pos = 10; pos < 100; pos += 10) {
  621. litest_touch_move(dev, 0, pos, 100 - pos);
  622. litest_touch_move(dev, 1, 100 - pos, pos);
  623. litest_dispatch(li);
  624. ev = libinput_get_event(li);
  625. tev = libinput_event_get_touch_event(ev);
  626. litest_assert_int_eq(libinput_event_touch_get_slot(tev), 0);
  627. libinput_event_destroy(ev);
  628. ev = libinput_get_event(li);
  629. litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME);
  630. libinput_event_destroy(ev);
  631. ev = libinput_get_event(li);
  632. tev = libinput_event_get_touch_event(ev);
  633. litest_assert_int_eq(libinput_event_touch_get_slot(tev), 1);
  634. libinput_event_destroy(ev);
  635. ev = libinput_get_event(li);
  636. litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME);
  637. libinput_event_destroy(ev);
  638. }
  639. litest_touch_up(dev, 0);
  640. litest_dispatch(li);
  641. litest_assert_touch_up_frame(li);
  642. litest_touch_up(dev, 1);
  643. litest_dispatch(li);
  644. litest_assert_touch_up_frame(li);
  645. }
  646. END_TEST
  647. START_TEST(touch_initial_state)
  648. {
  649. struct litest_device *dev;
  650. struct libinput *libinput1;
  651. struct libinput_event *ev1 = NULL;
  652. struct libinput_event *ev2 = NULL;
  653. struct libinput_event_touch *t1, *t2;
  654. struct libinput_device *device1, *device2;
  655. int axis = litest_test_param_get_i32(test_env->params, "axis");
  656. dev = litest_current_device();
  657. device1 = dev->libinput_device;
  658. libinput_device_config_tap_set_enabled(device1, LIBINPUT_CONFIG_TAP_DISABLED);
  659. libinput1 = dev->libinput;
  660. litest_touch_down(dev, 0, 40, 60);
  661. litest_touch_up(dev, 0);
  662. /* device is now on some x/y value */
  663. litest_drain_events(libinput1);
  664. _litest_context_destroy_ struct libinput *libinput2 = litest_create_context();
  665. device2 = libinput_path_add_device(libinput2,
  666. libevdev_uinput_get_devnode(dev->uinput));
  667. libinput_device_config_tap_set_enabled(device2, LIBINPUT_CONFIG_TAP_DISABLED);
  668. litest_drain_events(libinput2);
  669. if (axis == ABS_X)
  670. litest_touch_down(dev, 0, 40, 70);
  671. else
  672. litest_touch_down(dev, 0, 70, 60);
  673. litest_touch_up(dev, 0);
  674. litest_dispatch(libinput1);
  675. litest_dispatch(libinput2);
  676. while (libinput_next_event_type(libinput1)) {
  677. ev1 = libinput_get_event(libinput1);
  678. ev2 = libinput_get_event(libinput2);
  679. t1 = litest_is_touch_event(ev1, 0);
  680. t2 = litest_is_touch_event(ev2, 0);
  681. litest_assert_int_eq(libinput_event_get_type(ev1),
  682. libinput_event_get_type(ev2));
  683. if (libinput_event_get_type(ev1) == LIBINPUT_EVENT_TOUCH_UP ||
  684. libinput_event_get_type(ev1) == LIBINPUT_EVENT_TOUCH_FRAME)
  685. break;
  686. litest_assert_double_eq(libinput_event_touch_get_x(t1),
  687. libinput_event_touch_get_x(t2));
  688. litest_assert_double_eq(libinput_event_touch_get_y(t1),
  689. libinput_event_touch_get_y(t2));
  690. libinput_event_destroy(ev1);
  691. libinput_event_destroy(ev2);
  692. ev1 = NULL;
  693. ev2 = NULL;
  694. }
  695. libinput_event_destroy(ev1);
  696. libinput_event_destroy(ev2);
  697. }
  698. END_TEST
  699. START_TEST(touch_time_usec)
  700. {
  701. struct litest_device *dev = litest_current_device();
  702. struct libinput *li = dev->libinput;
  703. struct libinput_event *event;
  704. struct libinput_event_touch *tev;
  705. uint64_t time_usec;
  706. litest_drain_events(dev->libinput);
  707. litest_touch_down(dev, 0, 10, 10);
  708. litest_dispatch(li);
  709. event = libinput_get_event(li);
  710. tev = litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_DOWN);
  711. time_usec = libinput_event_touch_get_time_usec(tev);
  712. litest_assert_int_eq(libinput_event_touch_get_time(tev),
  713. (uint32_t)(time_usec / 1000));
  714. libinput_event_destroy(event);
  715. }
  716. END_TEST
  717. START_TEST(touch_fuzz)
  718. {
  719. struct litest_device *dev = litest_current_device();
  720. struct libinput *li = dev->libinput;
  721. struct libinput_event *event;
  722. int i;
  723. int x = 700, y = 300;
  724. litest_drain_events(dev->libinput);
  725. litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 30);
  726. litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
  727. litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
  728. litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
  729. litest_event(dev, EV_KEY, BTN_TOUCH, 1);
  730. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  731. litest_dispatch(li);
  732. event = libinput_get_event(li);
  733. litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_DOWN);
  734. libinput_event_destroy(event);
  735. event = libinput_get_event(li);
  736. litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME);
  737. libinput_event_destroy(event);
  738. litest_drain_events(li);
  739. for (i = 0; i < 50; i++) {
  740. if (i % 2) {
  741. x++;
  742. y--;
  743. } else {
  744. x--;
  745. y++;
  746. }
  747. litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
  748. litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
  749. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  750. litest_dispatch(li);
  751. litest_assert_empty_queue(li);
  752. }
  753. }
  754. END_TEST
  755. START_TEST(touch_fuzz_property)
  756. {
  757. struct litest_device *dev = litest_current_device();
  758. struct udev_device *d;
  759. const char *prop;
  760. int fuzz = 0;
  761. litest_assert_int_eq(libevdev_get_abs_fuzz(dev->evdev, ABS_X), 0);
  762. litest_assert_int_eq(libevdev_get_abs_fuzz(dev->evdev, ABS_Y), 0);
  763. d = libinput_device_get_udev_device(dev->libinput_device);
  764. prop = udev_device_get_property_value(d, "LIBINPUT_FUZZ_00");
  765. litest_assert_notnull(prop);
  766. litest_assert(safe_atoi(prop, &fuzz));
  767. litest_assert_int_eq(fuzz, 10); /* device-specific */
  768. prop = udev_device_get_property_value(d, "LIBINPUT_FUZZ_01");
  769. litest_assert_notnull(prop);
  770. litest_assert(safe_atoi(prop, &fuzz));
  771. litest_assert_int_eq(fuzz, 12); /* device-specific */
  772. udev_device_unref(d);
  773. }
  774. END_TEST
  775. START_TEST(touch_release_on_unplug)
  776. {
  777. struct litest_device *dev;
  778. struct libinput_event *ev;
  779. _litest_context_destroy_ struct libinput *li = litest_create_context();
  780. dev = litest_add_device(li, LITEST_GENERIC_MULTITOUCH_SCREEN);
  781. litest_drain_events(li);
  782. litest_touch_down(dev, 0, 50, 50);
  783. litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
  784. litest_drain_events(li);
  785. /* Touch is still down when device is removed, expect a release */
  786. litest_device_destroy(dev);
  787. litest_dispatch(li);
  788. ev = libinput_get_event(li);
  789. litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_CANCEL);
  790. libinput_event_destroy(ev);
  791. ev = libinput_get_event(li);
  792. litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME);
  793. libinput_event_destroy(ev);
  794. ev = libinput_get_event(li);
  795. litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_REMOVED);
  796. libinput_event_destroy(ev);
  797. }
  798. END_TEST
  799. START_TEST(touch_invalid_range_over)
  800. {
  801. struct litest_device *dev = litest_current_device();
  802. struct libinput *li = dev->libinput;
  803. struct libinput_event *ev;
  804. struct libinput_event_touch *t;
  805. double x, y;
  806. litest_drain_events(li);
  807. /* Touch outside the valid area */
  808. litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
  809. litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1);
  810. litest_event(dev, EV_ABS, ABS_X, 4000);
  811. litest_event(dev, EV_ABS, ABS_Y, 5000);
  812. litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000);
  813. litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 5000);
  814. litest_event(dev, EV_KEY, BTN_TOUCH, 1);
  815. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  816. litest_dispatch(li);
  817. /* Expect the mm to be correct regardless */
  818. ev = libinput_get_event(li);
  819. t = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
  820. x = libinput_event_touch_get_x(t);
  821. y = libinput_event_touch_get_y(t);
  822. litest_assert_double_eq(x, 300); /* device has resolution 10 */
  823. litest_assert_double_eq(y, 300); /* device has resolution 10 */
  824. /* Expect the percentage to be correct too, even if > 100% */
  825. x = libinput_event_touch_get_x_transformed(t, 100);
  826. y = libinput_event_touch_get_y_transformed(t, 100);
  827. litest_assert_double_eq(round(x), 200);
  828. litest_assert_double_eq(round(y), 120);
  829. libinput_event_destroy(ev);
  830. }
  831. END_TEST
  832. START_TEST(touch_invalid_range_under)
  833. {
  834. struct litest_device *dev = litest_current_device();
  835. struct libinput *li = dev->libinput;
  836. struct libinput_event *ev;
  837. struct libinput_event_touch *t;
  838. double x, y;
  839. litest_drain_events(li);
  840. /* Touch outside the valid area */
  841. litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
  842. litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1);
  843. litest_event(dev, EV_ABS, ABS_X, -500);
  844. litest_event(dev, EV_ABS, ABS_Y, 1000);
  845. litest_event(dev, EV_ABS, ABS_MT_POSITION_X, -500);
  846. litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 1000);
  847. litest_event(dev, EV_KEY, BTN_TOUCH, 1);
  848. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  849. litest_dispatch(li);
  850. /* Expect the mm to be correct regardless */
  851. ev = libinput_get_event(li);
  852. t = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
  853. x = libinput_event_touch_get_x(t);
  854. y = libinput_event_touch_get_y(t);
  855. litest_assert_double_eq(x, -150); /* device has resolution 10 */
  856. litest_assert_double_eq(y, -100); /* device has resolution 10 */
  857. /* Expect the percentage to be correct too, even if > 100% */
  858. x = libinput_event_touch_get_x_transformed(t, 100);
  859. y = libinput_event_touch_get_y_transformed(t, 100);
  860. litest_assert_double_eq(round(x), -100);
  861. litest_assert_double_eq(round(y), -40);
  862. libinput_event_destroy(ev);
  863. }
  864. END_TEST
  865. START_TEST(touch_count_st)
  866. {
  867. struct litest_device *dev = litest_current_device();
  868. struct libinput_device *device = dev->libinput_device;
  869. litest_assert_int_eq(libinput_device_touch_get_touch_count(device), 1);
  870. }
  871. END_TEST
  872. START_TEST(touch_count_mt)
  873. {
  874. struct litest_device *dev = litest_current_device();
  875. struct libinput_device *device = dev->libinput_device;
  876. struct libevdev *evdev = dev->evdev;
  877. litest_assert_int_eq(libinput_device_touch_get_touch_count(device),
  878. libevdev_get_num_slots(evdev));
  879. }
  880. END_TEST
  881. START_TEST(touch_count_mtdev)
  882. {
  883. struct litest_device *dev = litest_current_device();
  884. struct libinput_device *device = dev->libinput_device;
  885. /* We hardcode this to 10 */
  886. litest_assert_int_eq(libinput_device_touch_get_touch_count(device), 10);
  887. }
  888. END_TEST
  889. START_TEST(touch_count_invalid)
  890. {
  891. struct litest_device *dev = litest_current_device();
  892. struct libinput_device *device = dev->libinput_device;
  893. litest_assert_int_eq(libinput_device_touch_get_touch_count(device), -1);
  894. }
  895. END_TEST
  896. static inline bool
  897. touch_has_tool_palm(struct litest_device *dev)
  898. {
  899. return libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_TOOL_TYPE);
  900. }
  901. START_TEST(touch_palm_detect_tool_palm)
  902. {
  903. struct litest_device *dev = litest_current_device();
  904. struct libinput *li = dev->libinput;
  905. struct axis_replacement axes[] = {
  906. { ABS_MT_TOOL_TYPE, MT_TOOL_PALM },
  907. { -1, 0 },
  908. };
  909. if (!touch_has_tool_palm(dev))
  910. return LITEST_NOT_APPLICABLE;
  911. litest_touch_down(dev, 0, 50, 50);
  912. litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
  913. litest_drain_events(li);
  914. litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10);
  915. litest_dispatch(li);
  916. litest_assert_touch_cancel(li);
  917. litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10);
  918. litest_touch_up(dev, 0);
  919. litest_assert_empty_queue(li);
  920. }
  921. END_TEST
  922. START_TEST(touch_palm_detect_tool_palm_on_off)
  923. {
  924. struct litest_device *dev = litest_current_device();
  925. struct libinput *li = dev->libinput;
  926. struct axis_replacement axes[] = {
  927. { ABS_MT_TOOL_TYPE, MT_TOOL_PALM },
  928. { -1, 0 },
  929. };
  930. if (!touch_has_tool_palm(dev))
  931. return LITEST_NOT_APPLICABLE;
  932. litest_touch_down(dev, 0, 50, 50);
  933. litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
  934. litest_drain_events(li);
  935. litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10);
  936. litest_dispatch(li);
  937. litest_assert_touch_cancel(li);
  938. litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10);
  939. litest_assert_empty_queue(li);
  940. litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
  941. litest_touch_move_to_extended(dev, 0, 50, 40, 70, 70, axes, 10);
  942. litest_touch_up(dev, 0);
  943. litest_assert_empty_queue(li);
  944. }
  945. END_TEST
  946. START_TEST(touch_palm_detect_tool_palm_keep_type)
  947. {
  948. struct litest_device *dev = litest_current_device();
  949. struct libinput *li = dev->libinput;
  950. struct axis_replacement axes[] = {
  951. { ABS_MT_TOOL_TYPE, MT_TOOL_PALM },
  952. { -1, 0 },
  953. };
  954. if (!touch_has_tool_palm(dev))
  955. return LITEST_NOT_APPLICABLE;
  956. litest_touch_down(dev, 0, 50, 50);
  957. litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
  958. litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10);
  959. litest_touch_up(dev, 0);
  960. litest_drain_events(li);
  961. /* ABS_MT_TOOL_TYPE never reset to finger, so a new touch
  962. should be ignored outright */
  963. litest_touch_down_extended(dev, 0, 50, 50, axes);
  964. /* Test the revert to finger case too */
  965. litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
  966. litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10);
  967. litest_touch_up(dev, 0);
  968. litest_assert_empty_queue(li);
  969. }
  970. END_TEST
  971. START_TEST(touch_palm_detect_tool_palm_2fg)
  972. {
  973. struct litest_device *dev = litest_current_device();
  974. struct libinput *li = dev->libinput;
  975. struct axis_replacement axes[] = {
  976. { ABS_MT_TOOL_TYPE, MT_TOOL_PALM },
  977. { -1, 0 },
  978. };
  979. if (!touch_has_tool_palm(dev))
  980. return LITEST_NOT_APPLICABLE;
  981. litest_touch_down(dev, 0, 50, 50);
  982. litest_touch_down(dev, 1, 50, 50);
  983. litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
  984. litest_drain_events(li);
  985. litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10);
  986. litest_dispatch(li);
  987. litest_assert_touch_cancel(li);
  988. litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10);
  989. litest_dispatch(li);
  990. litest_assert_touch_motion_frame(li);
  991. litest_touch_up(dev, 1);
  992. litest_dispatch(li);
  993. litest_assert_touch_up_frame(li);
  994. litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10);
  995. litest_touch_up(dev, 0);
  996. litest_assert_empty_queue(li);
  997. }
  998. END_TEST
  999. START_TEST(touch_palm_detect_tool_palm_on_off_2fg)
  1000. {
  1001. struct litest_device *dev = litest_current_device();
  1002. struct libinput *li = dev->libinput;
  1003. struct axis_replacement axes[] = {
  1004. { ABS_MT_TOOL_TYPE, MT_TOOL_PALM },
  1005. { -1, 0 },
  1006. };
  1007. if (!touch_has_tool_palm(dev))
  1008. return LITEST_NOT_APPLICABLE;
  1009. litest_touch_down(dev, 0, 50, 50);
  1010. litest_touch_down(dev, 1, 50, 50);
  1011. litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
  1012. litest_drain_events(li);
  1013. litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10);
  1014. litest_dispatch(li);
  1015. litest_assert_touch_cancel(li);
  1016. litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10);
  1017. litest_dispatch(li);
  1018. litest_assert_touch_motion_frame(li);
  1019. litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
  1020. litest_touch_move_to_extended(dev, 0, 50, 40, 70, 70, axes, 10);
  1021. litest_assert_empty_queue(li);
  1022. litest_touch_move_to(dev, 1, 70, 70, 50, 40, 10);
  1023. litest_dispatch(li);
  1024. litest_assert_touch_motion_frame(li);
  1025. litest_touch_up(dev, 1);
  1026. litest_dispatch(li);
  1027. litest_assert_touch_up_frame(li);
  1028. litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10);
  1029. litest_touch_up(dev, 0);
  1030. litest_assert_empty_queue(li);
  1031. }
  1032. END_TEST
  1033. START_TEST(touch_palm_detect_tool_palm_keep_type_2fg)
  1034. {
  1035. struct litest_device *dev = litest_current_device();
  1036. struct libinput *li = dev->libinput;
  1037. struct axis_replacement axes[] = {
  1038. { ABS_MT_TOOL_TYPE, MT_TOOL_PALM },
  1039. { -1, 0 },
  1040. };
  1041. if (!touch_has_tool_palm(dev))
  1042. return LITEST_NOT_APPLICABLE;
  1043. litest_touch_down(dev, 0, 50, 50);
  1044. litest_touch_down(dev, 1, 50, 50);
  1045. litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
  1046. litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10);
  1047. litest_touch_up(dev, 0);
  1048. litest_drain_events(li);
  1049. litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10);
  1050. litest_dispatch(li);
  1051. litest_assert_touch_motion_frame(li);
  1052. /* ABS_MT_TOOL_TYPE never reset to finger, so a new touch
  1053. should be ignored outright */
  1054. litest_touch_down_extended(dev, 0, 50, 50, axes);
  1055. /* Test the revert to finger case too */
  1056. litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
  1057. litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10);
  1058. litest_touch_up(dev, 0);
  1059. litest_assert_empty_queue(li);
  1060. litest_touch_up(dev, 1);
  1061. litest_dispatch(li);
  1062. litest_assert_touch_up_frame(li);
  1063. }
  1064. END_TEST
  1065. TEST_COLLECTION(touch)
  1066. {
  1067. /* clang-format off */
  1068. litest_add(touch_frame_events, LITEST_TOUCH, LITEST_ANY);
  1069. litest_add(touch_downup_no_motion, LITEST_TOUCH, LITEST_ANY);
  1070. litest_add(touch_downup_no_motion, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
  1071. litest_add_no_device(touch_abs_transform);
  1072. litest_add(touch_seat_slot, LITEST_TOUCH, LITEST_TOUCHPAD);
  1073. litest_add_no_device(touch_many_slots);
  1074. litest_add(touch_double_touch_down_up, LITEST_TOUCH, LITEST_PROTOCOL_A);
  1075. litest_add(touch_calibration_scale, LITEST_TOUCH, LITEST_TOUCHPAD);
  1076. litest_add(touch_calibration_scale, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
  1077. litest_add(touch_calibration_rotation, LITEST_TOUCH, LITEST_TOUCHPAD);
  1078. litest_add(touch_calibration_rotation, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
  1079. litest_add(touch_calibration_translation, LITEST_TOUCH, LITEST_TOUCHPAD);
  1080. litest_add(touch_calibration_translation, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
  1081. litest_add_for_device(touch_calibrated_screen_path, LITEST_CALIBRATED_TOUCHSCREEN);
  1082. litest_add_for_device(touch_calibrated_screen_udev, LITEST_CALIBRATED_TOUCHSCREEN);
  1083. litest_add(touch_calibration_config, LITEST_TOUCH, LITEST_ANY);
  1084. litest_add(touch_no_left_handed, LITEST_TOUCH, LITEST_ANY);
  1085. litest_add(fake_mt_exists, LITEST_FAKE_MT, LITEST_ANY);
  1086. litest_add(fake_mt_no_touch_events, LITEST_FAKE_MT, LITEST_ANY);
  1087. #ifdef HAVE_MTDEV
  1088. litest_add(touch_protocol_a_init, LITEST_PROTOCOL_A, LITEST_ANY);
  1089. litest_add(touch_protocol_a_touch, LITEST_PROTOCOL_A, LITEST_ANY);
  1090. litest_add(touch_protocol_a_2fg_touch, LITEST_PROTOCOL_A, LITEST_ANY);
  1091. #endif
  1092. litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(ABS_X), litest_named_i32(ABS_Y)) {
  1093. litest_add_parametrized(touch_initial_state, LITEST_TOUCH, LITEST_PROTOCOL_A, params);
  1094. }
  1095. litest_add(touch_time_usec, LITEST_TOUCH, LITEST_TOUCHPAD);
  1096. litest_add_for_device(touch_fuzz, LITEST_MULTITOUCH_FUZZ_SCREEN);
  1097. litest_add_for_device(touch_fuzz_property, LITEST_MULTITOUCH_FUZZ_SCREEN);
  1098. litest_add_no_device(touch_release_on_unplug);
  1099. litest_add_for_device(touch_invalid_range_over, LITEST_TOUCHSCREEN_INVALID_RANGE);
  1100. litest_add_for_device(touch_invalid_range_under, LITEST_TOUCHSCREEN_INVALID_RANGE);
  1101. litest_add(touch_count_st, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
  1102. litest_add(touch_count_mt, LITEST_TOUCH, LITEST_SINGLE_TOUCH|LITEST_PROTOCOL_A);
  1103. #ifdef HAVE_MTDEV
  1104. litest_add(touch_count_mtdev, LITEST_PROTOCOL_A, LITEST_ANY);
  1105. litest_add(touch_count_invalid, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_PROTOCOL_A);
  1106. #endif
  1107. litest_add(touch_palm_detect_tool_palm, LITEST_TOUCH, LITEST_ANY);
  1108. litest_add(touch_palm_detect_tool_palm_on_off, LITEST_TOUCH, LITEST_ANY);
  1109. litest_add(touch_palm_detect_tool_palm_keep_type, LITEST_TOUCH, LITEST_ANY);
  1110. litest_add(touch_palm_detect_tool_palm_2fg, LITEST_TOUCH, LITEST_SINGLE_TOUCH);
  1111. litest_add(touch_palm_detect_tool_palm_on_off_2fg, LITEST_TOUCH, LITEST_SINGLE_TOUCH);
  1112. litest_add(touch_palm_detect_tool_palm_keep_type_2fg, LITEST_TOUCH, LITEST_ANY);
  1113. /* clang-format on */
  1114. }