1 /*
2 * Copyright © 2014 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
24 #include <config.h>
25
26 #include <check.h>
27 #include <errno.h>
28 #include <fcntl.h>
29 #include <libinput.h>
30 #include <unistd.h>
31
32 #include "libinput-util.h"
33 #include "litest.h"
34
35 static inline bool
has_disable_while_typing(struct litest_device * device)36 has_disable_while_typing(struct litest_device *device)
37 {
38 return libinput_device_config_dwt_is_available(device->libinput_device);
39 }
40
41 static inline struct litest_device *
dwt_init_paired_keyboard(struct libinput * li,struct litest_device * touchpad)42 dwt_init_paired_keyboard(struct libinput *li,
43 struct litest_device *touchpad)
44 {
45 enum litest_device_type which = LITEST_KEYBOARD;
46
47 if (libevdev_get_id_vendor(touchpad->evdev) == VENDOR_ID_APPLE)
48 which = LITEST_APPLE_KEYBOARD;
49
50 if (libevdev_get_id_vendor(touchpad->evdev) == VENDOR_ID_CHICONY)
51 which = LITEST_ACER_HAWAII_KEYBOARD;
52
53 return litest_add_device(li, which);
54 }
55
START_TEST(touchpad_1fg_motion)56 START_TEST(touchpad_1fg_motion)
57 {
58 struct litest_device *dev = litest_current_device();
59 struct libinput *li = dev->libinput;
60 struct libinput_event *event;
61
62 litest_disable_tap(dev->libinput_device);
63 litest_disable_hold_gestures(dev->libinput_device);
64 litest_drain_events(li);
65
66 litest_touch_down(dev, 0, 50, 50);
67 litest_touch_move_to(dev, 0, 50, 50, 80, 50, 20);
68 litest_touch_up(dev, 0);
69
70 libinput_dispatch(li);
71
72 event = libinput_get_event(li);
73 ck_assert_notnull(event);
74
75 while (event) {
76 struct libinput_event_pointer *ptrev;
77
78 ptrev = litest_is_motion_event(event);
79 ck_assert_int_ge(libinput_event_pointer_get_dx(ptrev), 0);
80 ck_assert_int_eq(libinput_event_pointer_get_dy(ptrev), 0);
81 libinput_event_destroy(event);
82 event = libinput_get_event(li);
83 }
84 }
85 END_TEST
86
START_TEST(touchpad_2fg_no_motion)87 START_TEST(touchpad_2fg_no_motion)
88 {
89 struct litest_device *dev = litest_current_device();
90 struct libinput *li = dev->libinput;
91 struct libinput_event *event;
92
93 libinput_device_config_tap_set_enabled(dev->libinput_device,
94 LIBINPUT_CONFIG_TAP_DISABLED);
95
96 litest_drain_events(li);
97
98 litest_touch_down(dev, 0, 20, 20);
99 litest_touch_down(dev, 1, 70, 20);
100 litest_touch_move_two_touches(dev, 20, 20, 70, 20, 20, 30, 20);
101 litest_touch_up(dev, 1);
102 litest_touch_up(dev, 0);
103
104 libinput_dispatch(li);
105
106 event = libinput_get_event(li);
107 while (event) {
108 ck_assert_int_ne(libinput_event_get_type(event),
109 LIBINPUT_EVENT_POINTER_MOTION);
110 libinput_event_destroy(event);
111 event = libinput_get_event(li);
112 }
113 }
114 END_TEST
115
116 static void
test_2fg_scroll(struct litest_device * dev,double dx,double dy,bool want_sleep)117 test_2fg_scroll(struct litest_device *dev, double dx, double dy, bool want_sleep)
118 {
119 struct libinput *li = dev->libinput;
120
121 litest_touch_down(dev, 0, 49, 50);
122 litest_touch_down(dev, 1, 51, 50);
123
124 litest_touch_move_two_touches(dev, 49, 50, 51, 50, dx, dy, 10);
125
126 /* Avoid a small scroll being seen as a tap */
127 if (want_sleep) {
128 libinput_dispatch(li);
129 litest_timeout_tap();
130 libinput_dispatch(li);
131 }
132
133 litest_touch_up(dev, 1);
134 litest_touch_up(dev, 0);
135
136 libinput_dispatch(li);
137 }
138
START_TEST(touchpad_2fg_scroll)139 START_TEST(touchpad_2fg_scroll)
140 {
141 struct litest_device *dev = litest_current_device();
142 struct libinput *li = dev->libinput;
143
144 if (!litest_has_2fg_scroll(dev))
145 return;
146
147 litest_enable_2fg_scroll(dev);
148 litest_disable_hold_gestures(dev->libinput_device);
149 litest_drain_events(li);
150
151 test_2fg_scroll(dev, 0.1, 40, false);
152 litest_assert_scroll(li,
153 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
154 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
155 9);
156 test_2fg_scroll(dev, 0.1, -40, false);
157 litest_assert_scroll(li,
158 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
159 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
160 -9);
161 test_2fg_scroll(dev, 40, 0.1, false);
162 litest_assert_scroll(li,
163 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
164 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
165 9);
166 test_2fg_scroll(dev, -40, 0.1, false);
167 litest_assert_scroll(li,
168 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
169 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
170 -9);
171
172 /* 2fg scroll smaller than the threshold should not generate events */
173 test_2fg_scroll(dev, 0.1, 0.1, true);
174 litest_assert_empty_queue(li);
175 }
176 END_TEST
177
START_TEST(touchpad_2fg_scroll_initially_diagonal)178 START_TEST(touchpad_2fg_scroll_initially_diagonal)
179 {
180 struct litest_device *dev = litest_current_device();
181 struct libinput *li = dev->libinput;
182 struct libinput_event *event;
183 int i;
184 int expected_nevents;
185 double w, h;
186 double ratio;
187 double ydelta;
188
189 if (!litest_has_2fg_scroll(dev))
190 return;
191
192 ck_assert_int_eq(libinput_device_get_size(dev->libinput_device, &w, &h), 0);
193 ratio = w/h;
194 litest_enable_2fg_scroll(dev);
195 litest_drain_events(li);
196
197 litest_touch_down(dev, 0, 45, 30);
198 litest_touch_down(dev, 1, 55, 30);
199
200 /* start diagonally */
201 ydelta = 15 * ratio;
202 litest_touch_move_two_touches(dev, 45, 30, 55, 30, 15, ydelta, 10);
203 libinput_dispatch(li);
204 litest_wait_for_event_of_type(li,
205 LIBINPUT_EVENT_POINTER_AXIS,
206 -1);
207 litest_drain_events(li);
208
209 /* get rid of any touch history still adding x deltas sideways */
210 for (i = 0; i < 5; i++)
211 litest_touch_move(dev, 0, 60, 30 + ydelta + (i * ratio));
212 litest_drain_events(li);
213
214 /* scroll vertical only and make sure the horiz axis is never set */
215 expected_nevents = 0;
216 for (i = 6; i < 15; i++) {
217 litest_touch_move(dev, 0, 60, 30 + ydelta + i * ratio);
218 expected_nevents++;
219 }
220
221 /* both high-resolution and low-resolution events are generated */
222 expected_nevents *= 2;
223
224 libinput_dispatch(li);
225 event = libinput_get_event(li);
226
227 do {
228 struct libinput_event_pointer *ptrev;
229
230 ptrev = litest_is_axis_event(event,
231 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
232 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
233 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
234 ck_assert(!libinput_event_pointer_has_axis(ptrev,
235 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL));
236 libinput_event_destroy(event);
237 event = libinput_get_event(li);
238 expected_nevents--;
239 } while (event);
240
241 ck_assert_int_eq(expected_nevents, 0);
242
243 litest_touch_up(dev, 1);
244 litest_touch_up(dev, 0);
245 libinput_dispatch(li);
246 }
247 END_TEST
248
249 static bool
is_single_axis_2fg_scroll(struct litest_device * dev,enum libinput_pointer_axis axis)250 is_single_axis_2fg_scroll(struct litest_device *dev,
251 enum libinput_pointer_axis axis)
252 {
253 struct libinput *li = dev->libinput;
254 struct libinput_event *event;
255 struct libinput_event_pointer *ptrev;
256 enum libinput_pointer_axis on_axis = axis;
257 enum libinput_pointer_axis off_axis =
258 (axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL) ?
259 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL :
260 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
261 bool has_on_axis, has_off_axis;
262 bool val = true;
263
264 event = libinput_get_event(li);
265 while (event) {
266 ptrev = litest_is_axis_event(event,
267 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
268 on_axis,
269 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
270
271 has_on_axis = libinput_event_pointer_has_axis(ptrev, on_axis);
272 has_off_axis = libinput_event_pointer_has_axis(ptrev, off_axis);
273
274 if (has_on_axis && has_off_axis) {
275 val = (litest_event_pointer_get_value(ptrev, off_axis) == 0.0);
276
277 /* There must be an extra low/high-resolution event with
278 * the same axis value (0.0). */
279 libinput_event_destroy(event);
280 event = libinput_get_event(li);
281 ck_assert_notnull(event);
282 ptrev = litest_is_axis_event(event,
283 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
284 on_axis,
285 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
286 ck_assert(val == (litest_event_pointer_get_value(ptrev, off_axis) == 0.0));
287 break;
288 }
289
290 ck_assert(has_on_axis);
291 ck_assert(!has_off_axis);
292
293 libinput_event_destroy(event);
294 event = libinput_get_event(li);
295 }
296
297 libinput_event_destroy(event);
298 return val;
299 }
300
START_TEST(touchpad_2fg_scroll_axis_lock)301 START_TEST(touchpad_2fg_scroll_axis_lock)
302 {
303 struct litest_device *dev = litest_current_device();
304 struct libinput *li = dev->libinput;
305 enum libinput_pointer_axis axis;
306 double delta[4][2] = {
307 { 7, 40},
308 { 7, -40},
309 {-7, 40},
310 {-7, -40}
311 };
312 /* 10 degrees off from horiz/vert should count as straight */
313
314 if (!litest_has_2fg_scroll(dev))
315 return;
316
317 litest_enable_2fg_scroll(dev);
318 litest_drain_events(li);
319
320 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
321 for (int i = 0; i < 4; i++) {
322 test_2fg_scroll(dev, delta[i][0], delta[i][1], false);
323 ck_assert(is_single_axis_2fg_scroll(dev, axis));
324 litest_assert_empty_queue(li);
325 }
326
327 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
328 for (int i = 0; i < 4; i++) {
329 test_2fg_scroll(dev, delta[i][1], delta[i][0], false);
330 ck_assert(is_single_axis_2fg_scroll(dev, axis));
331 litest_assert_empty_queue(li);
332 }
333 }
334 END_TEST
335
START_TEST(touchpad_2fg_scroll_axis_lock_switch)336 START_TEST(touchpad_2fg_scroll_axis_lock_switch)
337 {
338 struct litest_device *dev = litest_current_device();
339 struct libinput *li = dev->libinput;
340 enum libinput_pointer_axis axis;
341
342 if (!litest_has_2fg_scroll(dev))
343 return;
344
345 litest_enable_2fg_scroll(dev);
346 litest_drain_events(li);
347
348 litest_touch_down(dev, 0, 20, 20);
349 litest_touch_down(dev, 1, 25, 20);
350
351 /* Move roughly straight horizontally for >100ms to set axis lock */
352 litest_touch_move_two_touches(dev, 20, 20, 25, 20, 55, 10, 15);
353 libinput_dispatch(li);
354 litest_wait_for_event_of_type(li,
355 LIBINPUT_EVENT_POINTER_AXIS,
356 -1);
357
358 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
359 ck_assert(is_single_axis_2fg_scroll(dev, axis));
360 litest_drain_events(li);
361
362 msleep(200);
363 libinput_dispatch(li);
364
365 /* Move roughly vertically for >100ms to switch axis lock. This will
366 * contain some horizontal movement while the lock changes; don't
367 * check for single-axis yet
368 */
369 litest_touch_move_two_touches(dev, 75, 30, 80, 30, 2, 20, 15);
370 libinput_dispatch(li);
371 litest_wait_for_event_of_type(li,
372 LIBINPUT_EVENT_POINTER_AXIS,
373 -1);
374 litest_drain_events(li);
375
376 /* Move some more, roughly vertically, and check new axis lock */
377 litest_touch_move_two_touches(dev, 77, 50, 82, 50, 1, 40, 15);
378 libinput_dispatch(li);
379 litest_wait_for_event_of_type(li,
380 LIBINPUT_EVENT_POINTER_AXIS,
381 -1);
382
383 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
384 ck_assert(is_single_axis_2fg_scroll(dev, axis));
385 litest_drain_events(li);
386
387 /* Move in a clear diagonal direction to ensure the lock releases */
388 litest_touch_move_two_touches(dev, 78, 90, 83, 90, -60, -60, 20);
389 libinput_dispatch(li);
390 litest_wait_for_event_of_type(li,
391 LIBINPUT_EVENT_POINTER_AXIS,
392 -1);
393
394 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
395 ck_assert(!is_single_axis_2fg_scroll(dev, axis));
396
397 litest_touch_up(dev, 1);
398 litest_touch_up(dev, 0);
399 libinput_dispatch(li);
400 litest_drain_events(li);
401 }
402 END_TEST
403
START_TEST(touchpad_2fg_scroll_slow_distance)404 START_TEST(touchpad_2fg_scroll_slow_distance)
405 {
406 struct litest_device *dev = litest_current_device();
407 struct libinput *li = dev->libinput;
408 struct libinput_event *event;
409 double width, height;
410 double y_move = 100;
411 bool last_hi_res_event_found, last_low_res_event_found;
412
413 if (!litest_has_2fg_scroll(dev))
414 return;
415
416 last_hi_res_event_found = false;
417 last_low_res_event_found = false;
418
419 /* We want to move > 5 mm. */
420 ck_assert_int_eq(libinput_device_get_size(dev->libinput_device,
421 &width,
422 &height), 0);
423 y_move = 100.0/height * 7;
424
425 litest_enable_2fg_scroll(dev);
426 litest_disable_hold_gestures(dev->libinput_device);
427 litest_drain_events(li);
428
429 litest_touch_down(dev, 0, 49, 50);
430 litest_touch_down(dev, 1, 51, 50);
431 litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, y_move, 100);
432 litest_touch_up(dev, 1);
433 litest_touch_up(dev, 0);
434 libinput_dispatch(li);
435
436 event = libinput_get_event(li);
437 ck_assert_notnull(event);
438
439 while (event) {
440 struct libinput_event_pointer *ptrev;
441 double axisval;
442
443 ptrev = litest_is_axis_event(event,
444 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
445 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
446 0);
447 axisval = litest_event_pointer_get_value(ptrev,
448 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
449
450 if (litest_is_high_res_axis_event(event)) {
451 litest_assert(!last_hi_res_event_found);
452 if (axisval == 0)
453 last_hi_res_event_found = true;
454 } else {
455 litest_assert(!last_low_res_event_found);
456 if (axisval == 0)
457 last_low_res_event_found = true;
458 }
459
460 ck_assert(axisval >= 0.0);
461
462 /* this is to verify we test the right thing, if the value
463 is greater than scroll.threshold we triggered the wrong
464 condition */
465 ck_assert(axisval < 5.0);
466
467 libinput_event_destroy(event);
468 event = libinput_get_event(li);
469 }
470
471 litest_assert(last_low_res_event_found);
472 litest_assert(last_hi_res_event_found);
473 litest_assert_empty_queue(li);
474 libinput_event_destroy(event);
475 }
476 END_TEST
477
START_TEST(touchpad_2fg_scroll_source)478 START_TEST(touchpad_2fg_scroll_source)
479 {
480 struct litest_device *dev = litest_current_device();
481 struct libinput *li = dev->libinput;
482 struct libinput_event *event;
483
484 if (!litest_has_2fg_scroll(dev))
485 return;
486
487 litest_enable_2fg_scroll(dev);
488 litest_drain_events(li);
489
490 test_2fg_scroll(dev, 0, 30, false);
491 litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);
492
493 while ((event = libinput_get_event(li))) {
494 litest_is_axis_event(event,
495 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
496 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
497 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
498 libinput_event_destroy(event);
499 }
500 }
501 END_TEST
502
START_TEST(touchpad_2fg_scroll_semi_mt)503 START_TEST(touchpad_2fg_scroll_semi_mt)
504 {
505 struct litest_device *dev = litest_current_device();
506 struct libinput *li = dev->libinput;
507
508 if (!litest_has_2fg_scroll(dev))
509 return;
510
511 litest_enable_2fg_scroll(dev);
512 litest_drain_events(li);
513
514 litest_touch_down(dev, 0, 20, 20);
515 litest_touch_down(dev, 1, 30, 20);
516 libinput_dispatch(li);
517 litest_touch_move_two_touches(dev,
518 20, 20,
519 30, 20,
520 30, 40,
521 10);
522
523 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
524 }
525 END_TEST
526
START_TEST(touchpad_2fg_scroll_return_to_motion)527 START_TEST(touchpad_2fg_scroll_return_to_motion)
528 {
529 struct litest_device *dev = litest_current_device();
530 struct libinput *li = dev->libinput;
531
532 if (!litest_has_2fg_scroll(dev))
533 return;
534
535 litest_enable_2fg_scroll(dev);
536 litest_drain_events(li);
537
538 /* start with motion */
539 litest_touch_down(dev, 0, 70, 70);
540 litest_touch_move_to(dev, 0, 70, 70, 49, 50, 10);
541 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
542
543 /* 2fg scroll */
544 litest_touch_down(dev, 1, 51, 50);
545 litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, 20, 5);
546 litest_touch_up(dev, 1);
547 libinput_dispatch(li);
548 litest_timeout_finger_switch();
549 libinput_dispatch(li);
550 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
551
552 litest_touch_move_to(dev, 0, 49, 70, 49, 50, 10);
553 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
554
555 /* back to 2fg scroll, lifting the other finger */
556 litest_touch_down(dev, 1, 51, 50);
557 litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, 20, 5);
558 litest_touch_up(dev, 0);
559 libinput_dispatch(li);
560 litest_timeout_finger_switch();
561 libinput_dispatch(li);
562 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
563
564 /* move with second finger */
565 litest_touch_move_to(dev, 1, 51, 70, 51, 50, 10);
566 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
567
568 litest_touch_up(dev, 1);
569 litest_assert_empty_queue(li);
570 }
571 END_TEST
572
START_TEST(touchpad_2fg_scroll_from_btnareas)573 START_TEST(touchpad_2fg_scroll_from_btnareas)
574 {
575 struct litest_device *dev = litest_current_device();
576 struct libinput *li = dev->libinput;
577
578 if (!litest_has_2fg_scroll(dev) ||
579 !litest_has_btnareas(dev))
580 return;
581
582 litest_enable_2fg_scroll(dev);
583 litest_enable_buttonareas(dev);
584 litest_drain_events(li);
585
586 litest_touch_down(dev, 0, 30, 95);
587 litest_touch_down(dev, 1, 50, 95);
588 libinput_dispatch(li);
589
590 /* First finger moves out of the area first but it's a scroll
591 * motion, should not trigger POINTER_MOTION */
592 for (int i = 0; i < 5; i++) {
593 litest_touch_move(dev, 0, 30, 95 - i);
594 }
595 libinput_dispatch(li);
596
597 for (int i = 0; i < 20; i++) {
598 litest_touch_move(dev, 0, 30, 90 - i);
599 litest_touch_move(dev, 1, 50, 95 - i);
600 }
601 libinput_dispatch(li);
602
603 litest_touch_up(dev, 0);
604 litest_touch_up(dev, 1);
605
606 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
607 }
608 END_TEST
609
START_TEST(touchpad_scroll_natural_defaults)610 START_TEST(touchpad_scroll_natural_defaults)
611 {
612 struct litest_device *dev = litest_current_device();
613
614 int enabled = libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE;
615
616 ck_assert_int_ge(libinput_device_config_scroll_has_natural_scroll(dev->libinput_device), 1);
617 ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), enabled);
618 ck_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), enabled);
619 }
620 END_TEST
621
START_TEST(touchpad_scroll_natural_enable_config)622 START_TEST(touchpad_scroll_natural_enable_config)
623 {
624 struct litest_device *dev = litest_current_device();
625 enum libinput_config_status status;
626
627 status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1);
628 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
629 ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 1);
630
631 status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 0);
632 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
633 ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0);
634 }
635 END_TEST
636
START_TEST(touchpad_scroll_natural_2fg)637 START_TEST(touchpad_scroll_natural_2fg)
638 {
639 struct litest_device *dev = litest_current_device();
640 struct libinput *li = dev->libinput;
641
642 if (!litest_has_2fg_scroll(dev))
643 return;
644
645 litest_enable_2fg_scroll(dev);
646 litest_drain_events(li);
647
648 libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1);
649
650 test_2fg_scroll(dev, 0.1, 40, false);
651 litest_assert_scroll(li,
652 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
653 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
654 -9);
655 test_2fg_scroll(dev, 0.1, -40, false);
656 litest_assert_scroll(li,
657 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
658 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
659 9);
660 test_2fg_scroll(dev, 40, 0.1, false);
661 litest_assert_scroll(li,
662 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
663 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
664 -9);
665 test_2fg_scroll(dev, -40, 0.1, false);
666 litest_assert_scroll(li,
667 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
668 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
669 9);
670
671 }
672 END_TEST
673
START_TEST(touchpad_scroll_natural_edge)674 START_TEST(touchpad_scroll_natural_edge)
675 {
676 struct litest_device *dev = litest_current_device();
677 struct libinput *li = dev->libinput;
678
679 litest_enable_edge_scroll(dev);
680 litest_drain_events(li);
681
682 libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1);
683
684 litest_touch_down(dev, 0, 99, 20);
685 litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10);
686 litest_touch_up(dev, 0);
687
688 libinput_dispatch(li);
689 litest_assert_scroll(li,
690 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
691 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
692 -4);
693 litest_assert_empty_queue(li);
694
695 litest_touch_down(dev, 0, 99, 80);
696 litest_touch_move_to(dev, 0, 99, 80, 99, 20, 10);
697 litest_touch_up(dev, 0);
698
699 libinput_dispatch(li);
700 litest_assert_scroll(li,
701 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
702 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
703 4);
704 litest_assert_empty_queue(li);
705
706 }
707 END_TEST
708
START_TEST(touchpad_edge_scroll_vert)709 START_TEST(touchpad_edge_scroll_vert)
710 {
711 struct litest_device *dev = litest_current_device();
712 struct libinput *li = dev->libinput;
713
714 litest_touch_down(dev, 0, 99, 20);
715 litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10);
716 litest_touch_up(dev, 0);
717
718 litest_drain_events(li);
719 litest_enable_edge_scroll(dev);
720
721 litest_touch_down(dev, 0, 99, 20);
722 litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10);
723 litest_touch_up(dev, 0);
724
725 libinput_dispatch(li);
726 litest_assert_scroll(li,
727 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
728 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
729 4);
730 litest_assert_empty_queue(li);
731
732 litest_touch_down(dev, 0, 99, 80);
733 litest_touch_move_to(dev, 0, 99, 80, 99, 20, 10);
734 litest_touch_up(dev, 0);
735
736 libinput_dispatch(li);
737 litest_assert_scroll(li,
738 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
739 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
740 -4);
741 litest_assert_empty_queue(li);
742 }
743 END_TEST
744
745 static int
touchpad_has_horiz_edge_scroll_size(struct litest_device * dev)746 touchpad_has_horiz_edge_scroll_size(struct litest_device *dev)
747 {
748 double width, height;
749 int rc;
750
751 rc = libinput_device_get_size(dev->libinput_device, &width, &height);
752
753 return rc == 0 && height >= 40;
754 }
755
START_TEST(touchpad_edge_scroll_horiz)756 START_TEST(touchpad_edge_scroll_horiz)
757 {
758 struct litest_device *dev = litest_current_device();
759 struct libinput *li = dev->libinput;
760
761 litest_touch_down(dev, 0, 99, 20);
762 litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10);
763 litest_touch_up(dev, 0);
764
765 if (!touchpad_has_horiz_edge_scroll_size(dev))
766 return;
767
768 litest_drain_events(li);
769 litest_enable_edge_scroll(dev);
770
771 litest_touch_down(dev, 0, 20, 99);
772 litest_touch_move_to(dev, 0, 20, 99, 70, 99, 10);
773 litest_touch_up(dev, 0);
774
775 libinput_dispatch(li);
776 litest_assert_scroll(li,
777 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
778 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
779 4);
780 litest_assert_empty_queue(li);
781
782 litest_touch_down(dev, 0, 70, 99);
783 litest_touch_move_to(dev, 0, 70, 99, 20, 99, 10);
784 litest_touch_up(dev, 0);
785
786 libinput_dispatch(li);
787 litest_assert_scroll(li,
788 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
789 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
790 -4);
791 litest_assert_empty_queue(li);
792 }
793 END_TEST
794
START_TEST(touchpad_edge_scroll_horiz_clickpad)795 START_TEST(touchpad_edge_scroll_horiz_clickpad)
796 {
797 struct litest_device *dev = litest_current_device();
798 struct libinput *li = dev->libinput;
799
800 litest_drain_events(li);
801 litest_enable_edge_scroll(dev);
802
803 litest_touch_down(dev, 0, 20, 99);
804 litest_touch_move_to(dev, 0, 20, 99, 70, 99, 15);
805 litest_touch_up(dev, 0);
806
807 libinput_dispatch(li);
808 litest_assert_scroll(li,
809 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
810 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
811 4);
812 litest_assert_empty_queue(li);
813
814 litest_touch_down(dev, 0, 70, 99);
815 litest_touch_move_to(dev, 0, 70, 99, 20, 99, 15);
816 litest_touch_up(dev, 0);
817
818 libinput_dispatch(li);
819 litest_assert_scroll(li,
820 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
821 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
822 -4);
823 litest_assert_empty_queue(li);
824 }
825 END_TEST
826
START_TEST(touchpad_edge_scroll_no_horiz)827 START_TEST(touchpad_edge_scroll_no_horiz)
828 {
829 struct litest_device *dev = litest_current_device();
830 struct libinput *li = dev->libinput;
831
832 if (touchpad_has_horiz_edge_scroll_size(dev))
833 return;
834
835 litest_drain_events(li);
836 litest_enable_edge_scroll(dev);
837
838 litest_touch_down(dev, 0, 20, 99);
839 litest_touch_move_to(dev, 0, 20, 99, 70, 99, 10);
840 litest_touch_up(dev, 0);
841
842 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
843
844 litest_touch_down(dev, 0, 70, 99);
845 litest_touch_move_to(dev, 0, 70, 99, 20, 99, 10);
846 litest_touch_up(dev, 0);
847
848 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
849 }
850 END_TEST
851
START_TEST(touchpad_scroll_defaults)852 START_TEST(touchpad_scroll_defaults)
853 {
854 struct litest_device *dev = litest_current_device();
855 struct libinput_device *device = dev->libinput_device;
856 struct libevdev *evdev = dev->evdev;
857 enum libinput_config_scroll_method method, expected;
858 enum libinput_config_status status;
859 bool should_have_2fg = false;
860
861 if (libevdev_get_num_slots(evdev) > 1 ||
862 (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE &&
863 libevdev_get_id_product(dev->evdev) == PRODUCT_ID_APPLE_APPLETOUCH))
864 should_have_2fg = true;
865
866 method = libinput_device_config_scroll_get_methods(device);
867 ck_assert(method & LIBINPUT_CONFIG_SCROLL_EDGE);
868 if (should_have_2fg)
869 ck_assert(method & LIBINPUT_CONFIG_SCROLL_2FG);
870 else
871 ck_assert((method & LIBINPUT_CONFIG_SCROLL_2FG) == 0);
872
873 if (should_have_2fg)
874 expected = LIBINPUT_CONFIG_SCROLL_2FG;
875 else
876 expected = LIBINPUT_CONFIG_SCROLL_EDGE;
877
878 method = libinput_device_config_scroll_get_method(device);
879 ck_assert_int_eq(method, expected);
880 method = libinput_device_config_scroll_get_default_method(device);
881 ck_assert_int_eq(method, expected);
882
883 status = libinput_device_config_scroll_set_method(device,
884 LIBINPUT_CONFIG_SCROLL_EDGE);
885 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
886 status = libinput_device_config_scroll_set_method(device,
887 LIBINPUT_CONFIG_SCROLL_2FG);
888
889 if (should_have_2fg)
890 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
891 else
892 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
893 }
894 END_TEST
895
START_TEST(touchpad_edge_scroll_timeout)896 START_TEST(touchpad_edge_scroll_timeout)
897 {
898 struct litest_device *dev = litest_current_device();
899 struct libinput *li = dev->libinput;
900 struct libinput_event *event;
901 double width = 0, height = 0;
902 int nevents = 0;
903 double mm; /* one mm in percent of the device */
904
905 ck_assert_int_eq(libinput_device_get_size(dev->libinput_device,
906 &width,
907 &height), 0);
908 mm = 100.0/height;
909
910 /* timeout-based scrolling is disabled when software buttons are
911 * active, so switch to clickfinger. Not all test devices support
912 * that, hence the extra check. */
913 if (libinput_device_config_click_get_methods(dev->libinput_device) &
914 LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER)
915 litest_enable_clickfinger(dev);
916
917 litest_drain_events(li);
918 litest_enable_edge_scroll(dev);
919
920 /* move 0.5mm, enough to load up the motion history, but less than
921 * the scroll threshold of 2mm */
922 litest_touch_down(dev, 0, 99, 20);
923 libinput_dispatch(li);
924 litest_timeout_hysteresis();
925 libinput_dispatch(li);
926
927 litest_touch_move_to(dev, 0, 99, 20, 99, 20 + mm/2, 8);
928 libinput_dispatch(li);
929 litest_assert_empty_queue(li);
930
931 litest_timeout_edgescroll();
932 libinput_dispatch(li);
933
934 litest_assert_empty_queue(li);
935
936 /* now move slowly up to the 2mm scroll threshold. we expect events */
937 litest_touch_move_to(dev, 0, 99, 20 + mm/2, 99, 20 + mm * 2, 20);
938 litest_touch_up(dev, 0);
939 libinput_dispatch(li);
940
941 litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);
942
943 while ((event = libinput_get_event(li))) {
944 struct libinput_event_pointer *ptrev;
945 double value;
946
947 ptrev = litest_is_axis_event(event,
948 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
949 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
950 0);
951 value = litest_event_pointer_get_value(ptrev,
952 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
953 ck_assert_double_lt(value, 5.0);
954 libinput_event_destroy(event);
955 nevents++;
956 }
957
958 /* we sent 20 events but allow for some to be swallowed by rounding
959 * errors, the hysteresis, etc. */
960 ck_assert_int_ge(nevents, 10);
961
962 litest_assert_empty_queue(li);
963 libinput_event_destroy(event);
964 }
965 END_TEST
966
START_TEST(touchpad_edge_scroll_no_motion)967 START_TEST(touchpad_edge_scroll_no_motion)
968 {
969 struct litest_device *dev = litest_current_device();
970 struct libinput *li = dev->libinput;
971
972 litest_drain_events(li);
973 litest_enable_edge_scroll(dev);
974
975 litest_touch_down(dev, 0, 99, 10);
976 litest_touch_move_to(dev, 0, 99, 10, 99, 70, 12);
977 /* moving outside -> no motion event */
978 litest_touch_move_to(dev, 0, 99, 70, 20, 70, 12);
979 /* moving down outside edge once scrolling had started -> scroll */
980 litest_touch_move_to(dev, 0, 20, 70, 40, 99, 12);
981 litest_touch_up(dev, 0);
982 libinput_dispatch(li);
983
984 litest_assert_scroll(li,
985 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
986 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
987 4);
988 litest_assert_empty_queue(li);
989 }
990 END_TEST
991
START_TEST(touchpad_edge_scroll_no_edge_after_motion)992 START_TEST(touchpad_edge_scroll_no_edge_after_motion)
993 {
994 struct litest_device *dev = litest_current_device();
995 struct libinput *li = dev->libinput;
996
997 litest_drain_events(li);
998 litest_enable_edge_scroll(dev);
999
1000 /* moving into the edge zone must not trigger scroll events */
1001 litest_touch_down(dev, 0, 20, 20);
1002 litest_touch_move_to(dev, 0, 20, 20, 99, 20, 22);
1003 litest_touch_move_to(dev, 0, 99, 20, 99, 80, 22);
1004 litest_touch_up(dev, 0);
1005 libinput_dispatch(li);
1006
1007 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1008 litest_assert_empty_queue(li);
1009 }
1010 END_TEST
1011
START_TEST(touchpad_edge_scroll_source)1012 START_TEST(touchpad_edge_scroll_source)
1013 {
1014 struct litest_device *dev = litest_current_device();
1015 struct libinput *li = dev->libinput;
1016 struct libinput_event *event;
1017
1018 litest_drain_events(li);
1019 litest_enable_edge_scroll(dev);
1020
1021 litest_touch_down(dev, 0, 99, 20);
1022 litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10);
1023 litest_touch_up(dev, 0);
1024
1025 litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);
1026
1027 while ((event = libinput_get_event(li))) {
1028 struct libinput_event_pointer *ptrev;
1029 ptrev = litest_is_axis_event(event,
1030 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
1031 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
1032 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
1033 ck_assert_int_eq(litest_event_pointer_get_axis_source(ptrev),
1034 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
1035 libinput_event_destroy(event);
1036 }
1037 }
1038 END_TEST
1039
START_TEST(touchpad_edge_scroll_no_2fg)1040 START_TEST(touchpad_edge_scroll_no_2fg)
1041 {
1042 struct litest_device *dev = litest_current_device();
1043 struct libinput *li = dev->libinput;
1044
1045 litest_drain_events(li);
1046 litest_enable_edge_scroll(dev);
1047
1048 litest_touch_down(dev, 0, 49, 50);
1049 litest_touch_down(dev, 1, 51, 50);
1050 litest_touch_move_two_touches(dev, 49, 50, 51, 50, 20, 30, 10);
1051 libinput_dispatch(li);
1052 litest_touch_up(dev, 0);
1053 litest_touch_up(dev, 1);
1054 libinput_dispatch(li);
1055
1056 litest_assert_empty_queue(li);
1057 }
1058 END_TEST
1059
START_TEST(touchpad_edge_scroll_into_buttonareas)1060 START_TEST(touchpad_edge_scroll_into_buttonareas)
1061 {
1062 struct litest_device *dev = litest_current_device();
1063 struct libinput *li = dev->libinput;
1064
1065 litest_enable_buttonareas(dev);
1066 litest_enable_edge_scroll(dev);
1067 litest_drain_events(li);
1068
1069 litest_touch_down(dev, 0, 99, 40);
1070 litest_touch_move_to(dev, 0, 99, 40, 99, 95, 10);
1071 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1072 /* in the button zone now, make sure we still get events */
1073 litest_touch_move_to(dev, 0, 99, 95, 99, 100, 10);
1074 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1075
1076 /* and out of the zone again */
1077 litest_touch_move_to(dev, 0, 99, 100, 99, 70, 10);
1078 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1079
1080 /* still out of the zone */
1081 litest_touch_move_to(dev, 0, 99, 70, 99, 50, 10);
1082 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1083 }
1084 END_TEST
1085
START_TEST(touchpad_edge_scroll_within_buttonareas)1086 START_TEST(touchpad_edge_scroll_within_buttonareas)
1087 {
1088 struct litest_device *dev = litest_current_device();
1089 struct libinput *li = dev->libinput;
1090
1091 if (!touchpad_has_horiz_edge_scroll_size(dev))
1092 return;
1093
1094 litest_enable_buttonareas(dev);
1095 litest_enable_edge_scroll(dev);
1096 litest_drain_events(li);
1097
1098 litest_touch_down(dev, 0, 20, 99);
1099
1100 /* within left button */
1101 litest_touch_move_to(dev, 0, 20, 99, 40, 99, 10);
1102 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1103
1104 /* over to right button */
1105 litest_touch_move_to(dev, 0, 40, 99, 60, 99, 10);
1106 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1107
1108 /* within right button */
1109 litest_touch_move_to(dev, 0, 60, 99, 80, 99, 10);
1110 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1111 }
1112 END_TEST
1113
START_TEST(touchpad_edge_scroll_buttonareas_click_stops_scroll)1114 START_TEST(touchpad_edge_scroll_buttonareas_click_stops_scroll)
1115 {
1116 struct litest_device *dev = litest_current_device();
1117 struct libinput *li = dev->libinput;
1118 struct libinput_event *event;
1119
1120 if (!touchpad_has_horiz_edge_scroll_size(dev))
1121 return;
1122
1123 litest_enable_buttonareas(dev);
1124 litest_enable_edge_scroll(dev);
1125 litest_drain_events(li);
1126
1127 litest_touch_down(dev, 0, 20, 95);
1128 litest_touch_move_to(dev, 0, 20, 95, 70, 95, 15);
1129 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1130
1131 litest_button_click(dev, BTN_LEFT, true);
1132 libinput_dispatch(li);
1133
1134 litest_assert_axis_end_sequence(li,
1135 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
1136 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
1137 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
1138
1139 event = libinput_get_event(li);
1140 litest_is_button_event(event,
1141 BTN_RIGHT,
1142 LIBINPUT_BUTTON_STATE_PRESSED);
1143
1144 libinput_event_destroy(event);
1145
1146 /* move within button areas but we cancelled the scroll so now we
1147 * get pointer motion events when moving.
1148 *
1149 * This is not ideal behavior, but the use-case of horizontal
1150 * edge scrolling, click, then scrolling without lifting the finger
1151 * is so small we'll let it pass.
1152 */
1153 litest_touch_move_to(dev, 0, 70, 95, 90, 95, 15);
1154 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1155
1156 litest_button_click(dev, BTN_LEFT, false);
1157
1158 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
1159
1160 litest_touch_up(dev, 0);
1161 }
1162 END_TEST
1163
START_TEST(touchpad_edge_scroll_clickfinger_click_stops_scroll)1164 START_TEST(touchpad_edge_scroll_clickfinger_click_stops_scroll)
1165 {
1166 struct litest_device *dev = litest_current_device();
1167 struct libinput *li = dev->libinput;
1168 struct libinput_event *event;
1169
1170 if (!touchpad_has_horiz_edge_scroll_size(dev))
1171 return;
1172
1173 litest_enable_clickfinger(dev);
1174 litest_enable_edge_scroll(dev);
1175 litest_drain_events(li);
1176
1177 litest_touch_down(dev, 0, 20, 95);
1178 litest_touch_move_to(dev, 0, 20, 95, 70, 95, 15);
1179 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1180
1181 litest_button_click(dev, BTN_LEFT, true);
1182 libinput_dispatch(li);
1183
1184 litest_assert_axis_end_sequence(li,
1185 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
1186 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
1187 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
1188
1189 event = libinput_get_event(li);
1190 litest_is_button_event(event,
1191 BTN_LEFT,
1192 LIBINPUT_BUTTON_STATE_PRESSED);
1193
1194 libinput_event_destroy(event);
1195
1196 /* clickfinger releases pointer -> expect movement */
1197 litest_touch_move_to(dev, 0, 70, 95, 90, 95, 15);
1198 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1199 litest_assert_empty_queue(li);
1200
1201 litest_button_click(dev, BTN_LEFT, false);
1202
1203 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
1204
1205 litest_touch_up(dev, 0);
1206 }
1207 END_TEST
1208
START_TEST(touchpad_edge_scroll_into_area)1209 START_TEST(touchpad_edge_scroll_into_area)
1210 {
1211 struct litest_device *dev = litest_current_device();
1212 struct libinput *li = dev->libinput;
1213
1214 litest_enable_edge_scroll(dev);
1215 litest_drain_events(li);
1216
1217 /* move into area, move vertically, move back to edge */
1218
1219 litest_touch_down(dev, 0, 99, 20);
1220 litest_touch_move_to(dev, 0, 99, 20, 99, 50, 15);
1221 litest_touch_move_to(dev, 0, 99, 50, 20, 50, 15);
1222 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1223
1224 litest_touch_move_to(dev, 0, 20, 50, 20, 20, 15);
1225 litest_touch_move_to(dev, 0, 20, 20, 99, 20, 15);
1226 litest_assert_empty_queue(li);
1227
1228 litest_touch_move_to(dev, 0, 99, 20, 99, 50, 15);
1229 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1230 }
1231 END_TEST
1232
1233 static bool
touchpad_has_top_palm_detect_size(struct litest_device * dev)1234 touchpad_has_top_palm_detect_size(struct litest_device *dev)
1235 {
1236 double width, height;
1237 int rc;
1238
1239 if (!litest_has_palm_detect_size(dev))
1240 return false;
1241
1242 rc = libinput_device_get_size(dev->libinput_device, &width, &height);
1243
1244 return rc == 0 && height > 55;
1245 }
1246
START_TEST(touchpad_palm_detect_at_edge)1247 START_TEST(touchpad_palm_detect_at_edge)
1248 {
1249 struct litest_device *dev = litest_current_device();
1250 struct libinput *li = dev->libinput;
1251
1252 if (!litest_has_palm_detect_size(dev) ||
1253 !litest_has_2fg_scroll(dev))
1254 return;
1255
1256 litest_enable_2fg_scroll(dev);
1257
1258 litest_disable_tap(dev->libinput_device);
1259 litest_disable_hold_gestures(dev->libinput_device);
1260 litest_drain_events(li);
1261
1262 litest_touch_down(dev, 0, 99, 50);
1263 litest_touch_move_to(dev, 0, 99, 50, 99, 70, 5);
1264 litest_touch_up(dev, 0);
1265
1266 litest_assert_empty_queue(li);
1267
1268 litest_touch_down(dev, 0, 5, 50);
1269 litest_touch_move_to(dev, 0, 5, 50, 5, 70, 5);
1270 litest_touch_up(dev, 0);
1271
1272 litest_assert_empty_queue(li);
1273 }
1274 END_TEST
1275
START_TEST(touchpad_palm_detect_at_top)1276 START_TEST(touchpad_palm_detect_at_top)
1277 {
1278 struct litest_device *dev = litest_current_device();
1279 struct libinput *li = dev->libinput;
1280
1281 if (!touchpad_has_top_palm_detect_size(dev))
1282 return;
1283
1284 litest_disable_tap(dev->libinput_device);
1285 litest_disable_hold_gestures(dev->libinput_device);
1286 litest_drain_events(li);
1287
1288 litest_touch_down(dev, 0, 20, 1);
1289 litest_touch_move_to(dev, 0, 20, 1, 70, 1, 15);
1290 litest_touch_up(dev, 0);
1291
1292 litest_assert_empty_queue(li);
1293 }
1294 END_TEST
1295
START_TEST(touchpad_no_palm_detect_at_edge_for_edge_scrolling)1296 START_TEST(touchpad_no_palm_detect_at_edge_for_edge_scrolling)
1297 {
1298 struct litest_device *dev = litest_current_device();
1299 struct libinput *li = dev->libinput;
1300
1301 if (!litest_has_palm_detect_size(dev))
1302 return;
1303
1304 litest_enable_edge_scroll(dev);
1305
1306 litest_drain_events(li);
1307
1308 litest_touch_down(dev, 0, 99, 50);
1309 litest_touch_move_to(dev, 0, 99, 50, 99, 70, 5);
1310 litest_touch_up(dev, 0);
1311
1312 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1313 }
1314 END_TEST
1315
START_TEST(touchpad_palm_detect_at_bottom_corners)1316 START_TEST(touchpad_palm_detect_at_bottom_corners)
1317 {
1318 struct litest_device *dev = litest_current_device();
1319 struct libinput *li = dev->libinput;
1320
1321 if (!litest_has_palm_detect_size(dev) ||
1322 !litest_has_2fg_scroll(dev))
1323 return;
1324
1325 litest_enable_2fg_scroll(dev);
1326
1327 litest_disable_tap(dev->libinput_device);
1328 litest_disable_hold_gestures(dev->libinput_device);
1329
1330 /* Run for non-clickpads only: make sure the bottom corners trigger
1331 palm detection too */
1332 litest_drain_events(li);
1333
1334 litest_touch_down(dev, 0, 99, 95);
1335 litest_touch_move_to(dev, 0, 99, 95, 99, 99, 10);
1336 litest_touch_up(dev, 0);
1337
1338 litest_assert_empty_queue(li);
1339
1340 litest_touch_down(dev, 0, 5, 95);
1341 litest_touch_move_to(dev, 0, 5, 95, 5, 99, 5);
1342 litest_touch_up(dev, 0);
1343 }
1344 END_TEST
1345
START_TEST(touchpad_palm_detect_at_top_corners)1346 START_TEST(touchpad_palm_detect_at_top_corners)
1347 {
1348 struct litest_device *dev = litest_current_device();
1349 struct libinput *li = dev->libinput;
1350
1351 if (!litest_has_palm_detect_size(dev) ||
1352 !litest_has_2fg_scroll(dev))
1353 return;
1354
1355 litest_enable_2fg_scroll(dev);
1356
1357 litest_disable_tap(dev->libinput_device);
1358 litest_disable_hold_gestures(dev->libinput_device);
1359
1360 /* Run for non-clickpads only: make sure the bottom corners trigger
1361 palm detection too */
1362 litest_drain_events(li);
1363
1364 litest_touch_down(dev, 0, 99, 5);
1365 litest_touch_move_to(dev, 0, 99, 5, 99, 9, 10);
1366 litest_touch_up(dev, 0);
1367
1368 litest_assert_empty_queue(li);
1369
1370 litest_touch_down(dev, 0, 5, 5);
1371 litest_touch_move_to(dev, 0, 5, 5, 5, 9, 5);
1372 litest_touch_up(dev, 0);
1373
1374 litest_assert_empty_queue(li);
1375 }
1376 END_TEST
1377
START_TEST(touchpad_palm_detect_palm_stays_palm)1378 START_TEST(touchpad_palm_detect_palm_stays_palm)
1379 {
1380 struct litest_device *dev = litest_current_device();
1381 struct libinput *li = dev->libinput;
1382
1383 if (!litest_has_palm_detect_size(dev) ||
1384 !litest_has_2fg_scroll(dev))
1385 return;
1386
1387 litest_enable_2fg_scroll(dev);
1388
1389 litest_disable_tap(dev->libinput_device);
1390 litest_disable_hold_gestures(dev->libinput_device);
1391 litest_drain_events(li);
1392
1393 litest_touch_down(dev, 0, 99, 20);
1394 litest_touch_move_to(dev, 0, 99, 20, 75, 99, 20);
1395 litest_touch_up(dev, 0);
1396 litest_assert_empty_queue(li);
1397 }
1398 END_TEST
1399
START_TEST(touchpad_palm_detect_top_palm_stays_palm)1400 START_TEST(touchpad_palm_detect_top_palm_stays_palm)
1401 {
1402 struct litest_device *dev = litest_current_device();
1403 struct libinput *li = dev->libinput;
1404
1405 if (!touchpad_has_top_palm_detect_size(dev))
1406 return;
1407
1408 litest_disable_tap(dev->libinput_device);
1409 litest_disable_hold_gestures(dev->libinput_device);
1410 litest_drain_events(li);
1411
1412 litest_touch_down(dev, 0, 20, 1);
1413 litest_touch_move_to(dev, 0, 20, 1, 50, 30, 20);
1414 litest_touch_up(dev, 0);
1415
1416 litest_assert_empty_queue(li);
1417 }
1418 END_TEST
1419
START_TEST(touchpad_palm_detect_palm_becomes_pointer)1420 START_TEST(touchpad_palm_detect_palm_becomes_pointer)
1421 {
1422 struct litest_device *dev = litest_current_device();
1423 struct libinput *li = dev->libinput;
1424
1425 if (!litest_has_palm_detect_size(dev) ||
1426 !litest_has_2fg_scroll(dev))
1427 return;
1428
1429 litest_enable_2fg_scroll(dev);
1430
1431 litest_disable_tap(dev->libinput_device);
1432 litest_disable_hold_gestures(dev->libinput_device);
1433 litest_drain_events(li);
1434
1435 litest_touch_down(dev, 0, 99, 50);
1436 litest_touch_move_to(dev, 0, 99, 50, 0, 70, 25);
1437 litest_touch_up(dev, 0);
1438
1439 libinput_dispatch(li);
1440
1441 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1442
1443 litest_assert_empty_queue(li);
1444 }
1445 END_TEST
1446
START_TEST(touchpad_palm_detect_top_palm_becomes_pointer)1447 START_TEST(touchpad_palm_detect_top_palm_becomes_pointer)
1448 {
1449 struct litest_device *dev = litest_current_device();
1450 struct libinput *li = dev->libinput;
1451
1452 if (!touchpad_has_top_palm_detect_size(dev))
1453 return;
1454
1455 litest_disable_tap(dev->libinput_device);
1456 litest_disable_hold_gestures(dev->libinput_device);
1457 litest_drain_events(li);
1458
1459 litest_touch_down(dev, 0, 50, 1);
1460 litest_touch_move_to(dev, 0, 50, 1, 50, 60, 20);
1461 litest_touch_up(dev, 0);
1462
1463 libinput_dispatch(li);
1464
1465 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1466
1467 litest_assert_empty_queue(li);
1468 }
1469 END_TEST
1470
START_TEST(touchpad_palm_detect_no_palm_moving_into_edges)1471 START_TEST(touchpad_palm_detect_no_palm_moving_into_edges)
1472 {
1473 struct litest_device *dev = litest_current_device();
1474 struct libinput *li = dev->libinput;
1475
1476 if (!litest_has_palm_detect_size(dev))
1477 return;
1478
1479 litest_disable_tap(dev->libinput_device);
1480 litest_disable_hold_gestures(dev->libinput_device);
1481
1482 /* moving non-palm into the edge does not label it as palm */
1483 litest_drain_events(li);
1484
1485 litest_touch_down(dev, 0, 50, 50);
1486 litest_touch_move_to(dev, 0, 50, 50, 99, 50, 15);
1487
1488 litest_drain_events(li);
1489
1490 litest_touch_move_to(dev, 0, 99, 50, 99, 90, 15);
1491 libinput_dispatch(li);
1492
1493 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1494
1495 litest_touch_up(dev, 0);
1496 libinput_dispatch(li);
1497 litest_assert_empty_queue(li);
1498 }
1499 END_TEST
1500
START_TEST(touchpad_palm_detect_no_palm_moving_into_top)1501 START_TEST(touchpad_palm_detect_no_palm_moving_into_top)
1502 {
1503 struct litest_device *dev = litest_current_device();
1504 struct libinput *li = dev->libinput;
1505
1506 if (!touchpad_has_top_palm_detect_size(dev))
1507 return;
1508
1509 litest_disable_tap(dev->libinput_device);
1510 litest_disable_hold_gestures(dev->libinput_device);
1511
1512 /* moving non-palm into the edge does not label it as palm */
1513 litest_drain_events(li);
1514
1515 litest_touch_down(dev, 0, 50, 50);
1516 litest_touch_move_to(dev, 0, 50, 50, 0, 2, 15);
1517
1518 litest_drain_events(li);
1519
1520 litest_touch_move_to(dev, 0, 0, 2, 50, 50, 15);
1521 libinput_dispatch(li);
1522
1523 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1524
1525 litest_touch_up(dev, 0);
1526 libinput_dispatch(li);
1527 litest_assert_empty_queue(li);
1528 }
1529 END_TEST
1530
START_TEST(touchpad_palm_detect_no_tap_top_edge)1531 START_TEST(touchpad_palm_detect_no_tap_top_edge)
1532 {
1533 struct litest_device *dev = litest_current_device();
1534 struct libinput *li = dev->libinput;
1535
1536 if (!touchpad_has_top_palm_detect_size(dev))
1537 return;
1538
1539 litest_enable_tap(dev->libinput_device);
1540 litest_disable_hold_gestures(dev->libinput_device);
1541 litest_drain_events(li);
1542
1543 litest_touch_down(dev, 0, 50, 1);
1544 litest_touch_up(dev, 0);
1545 libinput_dispatch(li);
1546
1547 litest_timeout_tap();
1548 litest_assert_empty_queue(li);
1549 }
1550 END_TEST
1551
START_TEST(touchpad_palm_detect_tap_hardbuttons)1552 START_TEST(touchpad_palm_detect_tap_hardbuttons)
1553 {
1554 struct litest_device *dev = litest_current_device();
1555 struct libinput *li = dev->libinput;
1556
1557 if (!litest_has_palm_detect_size(dev))
1558 return;
1559
1560 litest_enable_tap(dev->libinput_device);
1561 litest_disable_hold_gestures(dev->libinput_device);
1562 litest_drain_events(li);
1563
1564 litest_touch_down(dev, 0, 95, 5);
1565 litest_touch_up(dev, 0);
1566 libinput_dispatch(li);
1567
1568 litest_timeout_tap();
1569 litest_assert_empty_queue(li);
1570
1571 litest_touch_down(dev, 0, 5, 5);
1572 litest_touch_up(dev, 0);
1573 libinput_dispatch(li);
1574
1575 litest_timeout_tap();
1576 litest_assert_empty_queue(li);
1577
1578 litest_touch_down(dev, 0, 5, 99);
1579 litest_touch_up(dev, 0);
1580 libinput_dispatch(li);
1581
1582 litest_timeout_tap();
1583 litest_assert_empty_queue(li);
1584
1585 litest_touch_down(dev, 0, 95, 99);
1586 litest_touch_up(dev, 0);
1587 libinput_dispatch(li);
1588
1589 litest_timeout_tap();
1590 litest_assert_empty_queue(li);
1591 }
1592 END_TEST
1593
START_TEST(touchpad_palm_detect_tap_softbuttons)1594 START_TEST(touchpad_palm_detect_tap_softbuttons)
1595 {
1596 struct litest_device *dev = litest_current_device();
1597 struct libinput *li = dev->libinput;
1598
1599 if (!litest_has_palm_detect_size(dev))
1600 return;
1601
1602 litest_enable_tap(dev->libinput_device);
1603 litest_enable_buttonareas(dev);
1604 litest_disable_hold_gestures(dev->libinput_device);
1605 litest_drain_events(li);
1606
1607 /* Two touches in the software button area, but inside
1608 * the palm detection edge zone -> expect palm detection */
1609 litest_touch_down(dev, 0, 99, 99);
1610 litest_touch_up(dev, 0);
1611 libinput_dispatch(li);
1612
1613 litest_timeout_tap();
1614 litest_assert_empty_queue(li);
1615
1616 litest_touch_down(dev, 0, 1, 99);
1617 litest_touch_up(dev, 0);
1618 libinput_dispatch(li);
1619
1620 litest_timeout_tap();
1621 litest_assert_empty_queue(li);
1622
1623 /* Two touches in the software button area, but
1624 * not in the palm detection edge zone -> expect taps */
1625 litest_touch_down(dev, 0, 10, 99);
1626 litest_touch_up(dev, 0);
1627 libinput_dispatch(li);
1628
1629 litest_timeout_tap();
1630 litest_assert_button_event(li,
1631 BTN_LEFT,
1632 LIBINPUT_BUTTON_STATE_PRESSED);
1633 litest_assert_button_event(li,
1634 BTN_LEFT,
1635 LIBINPUT_BUTTON_STATE_RELEASED);
1636 litest_assert_empty_queue(li);
1637
1638 litest_touch_down(dev, 0, 90, 99);
1639 litest_touch_up(dev, 0);
1640 libinput_dispatch(li);
1641
1642 litest_timeout_tap();
1643 litest_assert_button_event(li,
1644 BTN_LEFT,
1645 LIBINPUT_BUTTON_STATE_PRESSED);
1646 litest_assert_button_event(li,
1647 BTN_LEFT,
1648 LIBINPUT_BUTTON_STATE_RELEASED);
1649 litest_assert_empty_queue(li);
1650 }
1651 END_TEST
1652
START_TEST(touchpad_palm_detect_tap_clickfinger)1653 START_TEST(touchpad_palm_detect_tap_clickfinger)
1654 {
1655 struct litest_device *dev = litest_current_device();
1656 struct libinput *li = dev->libinput;
1657
1658 if (!litest_has_palm_detect_size(dev))
1659 return;
1660
1661 litest_enable_tap(dev->libinput_device);
1662 litest_enable_clickfinger(dev);
1663 litest_disable_hold_gestures(dev->libinput_device);
1664 litest_drain_events(li);
1665
1666 /* Taps in each of the 4 corners of the touchpad, all
1667 * inside the palm detection edge zone*/
1668 litest_touch_down(dev, 0, 95, 5);
1669 litest_touch_up(dev, 0);
1670 libinput_dispatch(li);
1671
1672 litest_timeout_tap();
1673 litest_assert_empty_queue(li);
1674
1675 litest_touch_down(dev, 0, 5, 5);
1676 litest_touch_up(dev, 0);
1677 libinput_dispatch(li);
1678
1679 litest_timeout_tap();
1680 litest_assert_empty_queue(li);
1681
1682 litest_touch_down(dev, 0, 5, 99);
1683 litest_touch_up(dev, 0);
1684 libinput_dispatch(li);
1685
1686 litest_timeout_tap();
1687 litest_assert_empty_queue(li);
1688
1689 litest_touch_down(dev, 0, 95, 99);
1690 litest_touch_up(dev, 0);
1691 libinput_dispatch(li);
1692
1693 litest_timeout_tap();
1694 litest_assert_empty_queue(li);
1695 }
1696 END_TEST
1697
START_TEST(touchpad_no_palm_detect_2fg_scroll)1698 START_TEST(touchpad_no_palm_detect_2fg_scroll)
1699 {
1700 struct litest_device *dev = litest_current_device();
1701 struct libinput *li = dev->libinput;
1702
1703 if (!litest_has_palm_detect_size(dev) ||
1704 !litest_has_2fg_scroll(dev))
1705 return;
1706
1707 litest_enable_2fg_scroll(dev);
1708
1709 litest_drain_events(li);
1710
1711 /* first finger is palm, second finger isn't so we trigger 2fg
1712 * scrolling */
1713 litest_touch_down(dev, 0, 99, 50);
1714 litest_touch_move_to(dev, 0, 99, 50, 99, 40, 45);
1715 litest_touch_move_to(dev, 0, 99, 40, 99, 50, 45);
1716 litest_assert_empty_queue(li);
1717 litest_touch_down(dev, 1, 50, 50);
1718 litest_assert_empty_queue(li);
1719
1720 litest_touch_move_two_touches(dev, 99, 50, 50, 50, 0, -20, 10);
1721 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
1722 }
1723 END_TEST
1724
START_TEST(touchpad_palm_detect_both_edges)1725 START_TEST(touchpad_palm_detect_both_edges)
1726 {
1727 struct litest_device *dev = litest_current_device();
1728 struct libinput *li = dev->libinput;
1729
1730 if (!litest_has_palm_detect_size(dev) ||
1731 !litest_has_2fg_scroll(dev))
1732 return;
1733
1734 litest_enable_2fg_scroll(dev);
1735
1736 litest_drain_events(li);
1737
1738 /* two fingers moving up/down in the left/right palm zone must not
1739 * generate events */
1740 litest_touch_down(dev, 0, 99, 50);
1741 litest_touch_move_to(dev, 0, 99, 50, 99, 40, 10);
1742 litest_touch_move_to(dev, 0, 99, 40, 99, 50, 10);
1743 litest_assert_empty_queue(li);
1744 /* This set generates events */
1745 litest_touch_down(dev, 1, 1, 50);
1746 litest_touch_move_to(dev, 1, 1, 50, 1, 40, 10);
1747 litest_touch_move_to(dev, 1, 1, 40, 1, 50, 10);
1748 litest_assert_empty_queue(li);
1749
1750 litest_touch_move_two_touches(dev, 99, 50, 1, 50, 0, -20, 10);
1751 litest_assert_empty_queue(li);
1752 }
1753 END_TEST
1754
1755 static inline bool
touchpad_has_tool_palm(struct litest_device * dev)1756 touchpad_has_tool_palm(struct litest_device *dev)
1757 {
1758 return libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_TOOL_TYPE);
1759 }
1760
START_TEST(touchpad_palm_detect_tool_palm)1761 START_TEST(touchpad_palm_detect_tool_palm)
1762 {
1763 struct litest_device *dev = litest_current_device();
1764 struct libinput *li = dev->libinput;
1765
1766 if (!touchpad_has_tool_palm(dev))
1767 return;
1768
1769 litest_touch_down(dev, 0, 50, 50);
1770 litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
1771 litest_drain_events(li);
1772
1773 litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM);
1774 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1775 litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10);
1776 litest_touch_up(dev, 0);
1777
1778 litest_assert_empty_queue(li);
1779 }
1780 END_TEST
1781
START_TEST(touchpad_palm_detect_tool_palm_on_off)1782 START_TEST(touchpad_palm_detect_tool_palm_on_off)
1783 {
1784 struct litest_device *dev = litest_current_device();
1785 struct libinput *li = dev->libinput;
1786
1787 if (!touchpad_has_tool_palm(dev))
1788 return;
1789
1790 litest_touch_down(dev, 0, 50, 50);
1791 litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
1792 litest_drain_events(li);
1793
1794 litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM);
1795 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1796 litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10);
1797
1798 litest_assert_empty_queue(li);
1799
1800 litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
1801 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1802 litest_touch_move_to(dev, 0, 50, 40, 70, 70, 10);
1803 litest_touch_up(dev, 0);
1804
1805 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1806 }
1807 END_TEST
1808
START_TEST(touchpad_palm_detect_tool_palm_tap_after)1809 START_TEST(touchpad_palm_detect_tool_palm_tap_after)
1810 {
1811 struct litest_device *dev = litest_current_device();
1812 struct libinput *li = dev->libinput;
1813
1814 if (!touchpad_has_tool_palm(dev))
1815 return;
1816
1817 litest_enable_tap(dev->libinput_device);
1818 litest_disable_hold_gestures(dev->libinput_device);
1819 litest_drain_events(li);
1820
1821 litest_push_event_frame(dev);
1822 litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM);
1823 litest_touch_down(dev, 0, 50, 50);
1824 litest_pop_event_frame(dev);
1825 libinput_dispatch(li);
1826
1827 litest_touch_move_to(dev, 0, 50, 50, 50, 80, 10);
1828 libinput_dispatch(li);
1829
1830 litest_assert_empty_queue(li);
1831
1832 litest_push_event_frame(dev);
1833 litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
1834 litest_touch_up(dev, 0);
1835 litest_pop_event_frame(dev);
1836 libinput_dispatch(li);
1837 litest_timeout_tap();
1838 litest_assert_empty_queue(li);
1839
1840 litest_touch_down(dev, 0, 50, 50);
1841 libinput_dispatch(li);
1842 litest_touch_up(dev, 0);
1843 libinput_dispatch(li);
1844 litest_timeout_tap();
1845
1846 litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
1847 litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
1848 litest_assert_empty_queue(li);
1849 }
1850 END_TEST
1851
START_TEST(touchpad_palm_detect_tool_palm_tap)1852 START_TEST(touchpad_palm_detect_tool_palm_tap)
1853 {
1854 struct litest_device *dev = litest_current_device();
1855 struct libinput *li = dev->libinput;
1856
1857 if (!touchpad_has_tool_palm(dev))
1858 return;
1859
1860 litest_enable_tap(dev->libinput_device);
1861 litest_disable_hold_gestures(dev->libinput_device);
1862 litest_drain_events(li);
1863
1864 litest_push_event_frame(dev);
1865 litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM);
1866 litest_touch_down(dev, 0, 50, 50);
1867 litest_pop_event_frame(dev);
1868 libinput_dispatch(li);
1869 litest_assert_empty_queue(li);
1870
1871 litest_touch_up(dev, 0);
1872 libinput_dispatch(li);
1873 litest_timeout_tap();
1874
1875 litest_assert_empty_queue(li);
1876 }
1877 END_TEST
1878
1879 static inline bool
touchpad_has_palm_pressure(struct litest_device * dev)1880 touchpad_has_palm_pressure(struct litest_device *dev)
1881 {
1882 struct libevdev *evdev = dev->evdev;
1883
1884 if (dev->which == LITEST_SYNAPTICS_PRESSUREPAD)
1885 return false;
1886
1887 if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_PRESSURE))
1888 return libevdev_get_abs_resolution(evdev,
1889 ABS_MT_PRESSURE) == 0;
1890
1891 return false;
1892 }
1893
START_TEST(touchpad_palm_detect_pressure)1894 START_TEST(touchpad_palm_detect_pressure)
1895 {
1896 struct litest_device *dev = litest_current_device();
1897 struct libinput *li = dev->libinput;
1898 struct axis_replacement axes[] = {
1899 { ABS_MT_PRESSURE, 75 },
1900 { -1, 0 }
1901 };
1902
1903 if (!touchpad_has_palm_pressure(dev))
1904 return;
1905
1906 litest_disable_tap(dev->libinput_device);
1907 litest_disable_hold_gestures(dev->libinput_device);
1908 litest_drain_events(li);
1909
1910 litest_touch_down_extended(dev, 0, 50, 99, axes);
1911 litest_touch_move_to(dev, 0, 50, 50, 80, 99, 10);
1912 litest_touch_up(dev, 0);
1913
1914 litest_assert_empty_queue(li);
1915 }
1916 END_TEST
1917
START_TEST(touchpad_palm_detect_pressure_late_tap)1918 START_TEST(touchpad_palm_detect_pressure_late_tap)
1919 {
1920 struct litest_device *dev = litest_current_device();
1921 struct libinput *li = dev->libinput;
1922 struct axis_replacement axes[] = {
1923 { ABS_MT_PRESSURE, 75 },
1924 { -1, 0 }
1925 };
1926
1927 if (!touchpad_has_palm_pressure(dev))
1928 return;
1929
1930 litest_enable_tap(dev->libinput_device);
1931 litest_enable_clickfinger(dev);
1932 litest_disable_hold_gestures(dev->libinput_device);
1933 litest_drain_events(li);
1934
1935 /* event after touch down is palm */
1936 litest_touch_down(dev, 0, 50, 80);
1937 litest_touch_move_extended(dev, 0, 51, 99, axes);
1938 litest_touch_up(dev, 0);
1939 libinput_dispatch(li);
1940 litest_timeout_tap();
1941 litest_assert_empty_queue(li);
1942
1943 /* make sure normal tap still works */
1944 litest_touch_down(dev, 0, 50, 99);
1945 litest_touch_up(dev, 0);
1946 libinput_dispatch(li);
1947 litest_timeout_tap();
1948 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
1949 }
1950 END_TEST
1951
START_TEST(touchpad_palm_detect_pressure_tap_hold)1952 START_TEST(touchpad_palm_detect_pressure_tap_hold)
1953 {
1954 struct litest_device *dev = litest_current_device();
1955 struct libinput *li = dev->libinput;
1956 struct axis_replacement axes[] = {
1957 { ABS_MT_PRESSURE, 75 },
1958 { -1, 0 }
1959 };
1960
1961 if (!touchpad_has_palm_pressure(dev))
1962 return;
1963
1964 litest_enable_tap(dev->libinput_device);
1965 litest_enable_clickfinger(dev);
1966 litest_disable_hold_gestures(dev->libinput_device);
1967 litest_drain_events(li);
1968
1969 /* event in state HOLD is thumb */
1970 litest_touch_down(dev, 0, 50, 99);
1971 libinput_dispatch(li);
1972 litest_timeout_tap();
1973 libinput_dispatch(li);
1974 litest_touch_move_extended(dev, 0, 51, 99, axes);
1975 litest_touch_up(dev, 0);
1976 litest_assert_empty_queue(li);
1977
1978 /* make sure normal tap still works */
1979 litest_touch_down(dev, 0, 50, 99);
1980 litest_touch_up(dev, 0);
1981 libinput_dispatch(li);
1982 litest_timeout_tap();
1983 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
1984 }
1985 END_TEST
1986
START_TEST(touchpad_palm_detect_pressure_tap_hold_2ndfg)1987 START_TEST(touchpad_palm_detect_pressure_tap_hold_2ndfg)
1988 {
1989 struct litest_device *dev = litest_current_device();
1990 struct libinput *li = dev->libinput;
1991 struct axis_replacement axes[] = {
1992 { ABS_MT_PRESSURE, 75 },
1993 { -1, 0 }
1994 };
1995
1996 if (!touchpad_has_palm_pressure(dev))
1997 return;
1998
1999 litest_enable_tap(dev->libinput_device);
2000 litest_enable_clickfinger(dev);
2001 litest_disable_hold_gestures(dev->libinput_device);
2002 litest_drain_events(li);
2003
2004 /* event in state HOLD is thumb */
2005 litest_touch_down(dev, 0, 50, 99);
2006 libinput_dispatch(li);
2007 litest_timeout_tap();
2008 libinput_dispatch(li);
2009 litest_touch_move_extended(dev, 0, 51, 99, axes);
2010
2011 litest_assert_empty_queue(li);
2012
2013 /* one finger is a thumb, now get second finger down */
2014 litest_touch_down(dev, 1, 60, 50);
2015 litest_assert_empty_queue(li);
2016 /* release thumb */
2017 litest_touch_up(dev, 0);
2018 litest_assert_empty_queue(li);
2019
2020 /* timeout -> into HOLD, no event on release */
2021 libinput_dispatch(li);
2022 litest_timeout_tap();
2023 libinput_dispatch(li);
2024 litest_touch_up(dev, 1);
2025 litest_assert_empty_queue(li);
2026
2027 /* make sure normal tap still works */
2028 litest_touch_down(dev, 0, 50, 99);
2029 litest_touch_up(dev, 0);
2030 libinput_dispatch(li);
2031 litest_timeout_tap();
2032 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
2033 }
2034 END_TEST
2035
START_TEST(touchpad_palm_detect_move_and_tap)2036 START_TEST(touchpad_palm_detect_move_and_tap)
2037 {
2038 struct litest_device *dev = litest_current_device();
2039 struct libinput *li = dev->libinput;
2040 struct axis_replacement axes[] = {
2041 { ABS_MT_PRESSURE, 75 },
2042 { -1, 0 }
2043 };
2044
2045 if (!touchpad_has_palm_pressure(dev))
2046 return;
2047
2048 litest_enable_tap(dev->libinput_device);
2049 litest_disable_hold_gestures(dev->libinput_device);
2050 litest_drain_events(li);
2051
2052 /* trigger thumb detection by pressure after a slight movement */
2053 litest_touch_down(dev, 0, 50, 99);
2054 litest_touch_move(dev, 0, 51, 99);
2055 litest_touch_move_extended(dev, 0, 55, 99, axes);
2056 libinput_dispatch(li);
2057
2058 litest_assert_empty_queue(li);
2059
2060 /* thumb is resting, check if tapping still works */
2061 litest_touch_down(dev, 1, 50, 50);
2062 litest_touch_up(dev, 1);
2063 libinput_dispatch(li);
2064 litest_timeout_tap();
2065
2066 litest_assert_button_event(li,
2067 BTN_LEFT,
2068 LIBINPUT_BUTTON_STATE_PRESSED);
2069 litest_assert_button_event(li,
2070 BTN_LEFT,
2071 LIBINPUT_BUTTON_STATE_RELEASED);
2072 litest_assert_empty_queue(li);
2073 }
2074 END_TEST
2075
START_TEST(touchpad_palm_detect_pressure_late)2076 START_TEST(touchpad_palm_detect_pressure_late)
2077 {
2078 struct litest_device *dev = litest_current_device();
2079 struct libinput *li = dev->libinput;
2080 struct axis_replacement axes[] = {
2081 { ABS_MT_PRESSURE, 75 },
2082 { -1, 0 }
2083 };
2084
2085 if (!touchpad_has_palm_pressure(dev))
2086 return;
2087
2088 litest_disable_tap(dev->libinput_device);
2089 litest_disable_hold_gestures(dev->libinput_device);
2090 litest_drain_events(li);
2091
2092 litest_touch_down(dev, 0, 50, 50);
2093 litest_touch_move_to(dev, 0, 50, 70, 80, 90, 10);
2094 litest_drain_events(li);
2095 libinput_dispatch(li);
2096 litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10);
2097 litest_touch_up(dev, 0);
2098
2099 litest_assert_empty_queue(li);
2100 }
2101 END_TEST
2102
START_TEST(touchpad_palm_detect_pressure_keep_palm)2103 START_TEST(touchpad_palm_detect_pressure_keep_palm)
2104 {
2105 struct litest_device *dev = litest_current_device();
2106 struct libinput *li = dev->libinput;
2107 struct axis_replacement axes[] = {
2108 { ABS_MT_PRESSURE, 75 },
2109 { -1, 0 }
2110 };
2111
2112 if (!touchpad_has_palm_pressure(dev))
2113 return;
2114
2115 litest_disable_tap(dev->libinput_device);
2116 litest_disable_hold_gestures(dev->libinput_device);
2117 litest_drain_events(li);
2118
2119 litest_touch_down(dev, 0, 80, 90);
2120 litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10);
2121 litest_touch_move_to(dev, 0, 50, 20, 80, 90, 10);
2122 litest_touch_up(dev, 0);
2123
2124 litest_assert_empty_queue(li);
2125 }
2126 END_TEST
2127
START_TEST(touchpad_palm_detect_pressure_after_edge)2128 START_TEST(touchpad_palm_detect_pressure_after_edge)
2129 {
2130 struct litest_device *dev = litest_current_device();
2131 struct libinput *li = dev->libinput;
2132 struct axis_replacement axes[] = {
2133 { ABS_MT_PRESSURE, 75 },
2134 { -1, 0 }
2135 };
2136
2137 if (!touchpad_has_palm_pressure(dev) ||
2138 !litest_has_palm_detect_size(dev) ||
2139 !litest_has_2fg_scroll(dev))
2140 return;
2141
2142 litest_enable_2fg_scroll(dev);
2143 litest_disable_tap(dev->libinput_device);
2144 litest_disable_hold_gestures(dev->libinput_device);
2145 litest_drain_events(li);
2146
2147 litest_touch_down(dev, 0, 99, 50);
2148 litest_touch_move_to_extended(dev, 0, 99, 50, 20, 50, axes, 20);
2149 litest_touch_up(dev, 0);
2150 libinput_dispatch(li);
2151
2152 litest_assert_empty_queue(li);
2153 }
2154 END_TEST
2155
START_TEST(touchpad_palm_detect_pressure_after_dwt)2156 START_TEST(touchpad_palm_detect_pressure_after_dwt)
2157 {
2158 struct litest_device *touchpad = litest_current_device();
2159 struct litest_device *keyboard;
2160 struct libinput *li = touchpad->libinput;
2161 struct axis_replacement axes[] = {
2162 { ABS_MT_PRESSURE, 75 },
2163 { -1, 0 }
2164 };
2165
2166 if (!touchpad_has_palm_pressure(touchpad))
2167 return;
2168
2169 keyboard = dwt_init_paired_keyboard(li, touchpad);
2170 litest_disable_tap(touchpad->libinput_device);
2171 litest_disable_hold_gestures(touchpad->libinput_device);
2172 litest_drain_events(li);
2173
2174 litest_keyboard_key(keyboard, KEY_A, true);
2175 litest_keyboard_key(keyboard, KEY_A, false);
2176 litest_drain_events(li);
2177
2178 /* within dwt timeout, dwt blocks events */
2179 litest_touch_down(touchpad, 0, 50, 50);
2180 litest_touch_move_to_extended(touchpad, 0, 50, 50, 20, 50, axes, 20);
2181 litest_assert_empty_queue(li);
2182
2183 litest_timeout_dwt_short();
2184 libinput_dispatch(li);
2185 litest_assert_empty_queue(li);
2186
2187 /* after dwt timeout, pressure blocks events */
2188 litest_touch_move_to_extended(touchpad, 0, 20, 50, 50, 50, axes, 20);
2189 litest_touch_up(touchpad, 0);
2190
2191 litest_assert_empty_queue(li);
2192
2193 litest_delete_device(keyboard);
2194 }
2195 END_TEST
2196
START_TEST(touchpad_palm_ignore_threshold_zero)2197 START_TEST(touchpad_palm_ignore_threshold_zero)
2198 {
2199 struct litest_device *dev = litest_current_device();
2200 struct libinput *li = dev->libinput;
2201 struct axis_replacement axes[] = {
2202 { ABS_MT_PRESSURE, 75 },
2203 { -1, 0 }
2204 };
2205
2206 litest_disable_tap(dev->libinput_device);
2207 litest_disable_hold_gestures(dev->libinput_device);
2208 litest_drain_events(li);
2209
2210 litest_touch_down_extended(dev, 0, 50, 99, axes);
2211 litest_touch_move_to(dev, 0, 50, 50, 80, 99, 10);
2212 litest_touch_up(dev, 0);
2213
2214 libinput_dispatch(li);
2215 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
2216 }
2217 END_TEST
2218
START_TEST(touchpad_palm_clickfinger_pressure)2219 START_TEST(touchpad_palm_clickfinger_pressure)
2220 {
2221 struct litest_device *dev = litest_current_device();
2222 struct libinput *li = dev->libinput;
2223 struct axis_replacement axes[] = {
2224 { ABS_MT_PRESSURE, 75 },
2225 { -1, 0 }
2226 };
2227
2228 if (!touchpad_has_palm_pressure(dev))
2229 return;
2230
2231 litest_enable_clickfinger(dev);
2232 litest_disable_tap(dev->libinput_device);
2233 litest_disable_hold_gestures(dev->libinput_device);
2234 litest_drain_events(li);
2235
2236 litest_touch_down_extended(dev, 0, 50, 95, axes);
2237 litest_touch_down(dev, 1, 50, 50);
2238 litest_button_click(dev, BTN_LEFT, true);
2239 litest_button_click(dev, BTN_LEFT, false);
2240
2241 litest_touch_up(dev, 1);
2242 litest_touch_up(dev, 0);
2243
2244 litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
2245 litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
2246 litest_assert_empty_queue(li);
2247 }
2248 END_TEST
2249
START_TEST(touchpad_palm_clickfinger_pressure_2fg)2250 START_TEST(touchpad_palm_clickfinger_pressure_2fg)
2251 {
2252 struct litest_device *dev = litest_current_device();
2253 struct libinput *li = dev->libinput;
2254 struct axis_replacement axes[] = {
2255 { ABS_MT_PRESSURE, 75 },
2256 { -1, 0 }
2257 };
2258
2259 if (!touchpad_has_palm_pressure(dev))
2260 return;
2261
2262 if (libevdev_get_num_slots(dev->evdev) < 3)
2263 return;
2264
2265 litest_enable_clickfinger(dev);
2266 litest_disable_tap(dev->libinput_device);
2267 litest_disable_hold_gestures(dev->libinput_device);
2268 litest_drain_events(li);
2269
2270 litest_touch_down_extended(dev, 0, 50, 95, axes);
2271 litest_touch_down(dev, 1, 50, 50);
2272 litest_touch_down(dev, 2, 50, 60);
2273 litest_button_click(dev, BTN_LEFT, true);
2274 litest_button_click(dev, BTN_LEFT, false);
2275
2276 litest_touch_up(dev, 1);
2277 litest_touch_up(dev, 2);
2278 litest_touch_up(dev, 0);
2279
2280 litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED);
2281 litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED);
2282 litest_assert_empty_queue(li);
2283 }
2284 END_TEST
2285
2286
2287 static inline bool
touchpad_has_touch_size(struct litest_device * dev)2288 touchpad_has_touch_size(struct litest_device *dev)
2289 {
2290 struct libevdev *evdev = dev->evdev;
2291
2292 if (!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_TOUCH_MAJOR))
2293 return false;
2294
2295 if (libevdev_get_id_vendor(evdev) == VENDOR_ID_APPLE)
2296 return true;
2297
2298 return false;
2299 }
2300
START_TEST(touchpad_palm_clickfinger_size)2301 START_TEST(touchpad_palm_clickfinger_size)
2302 {
2303 struct litest_device *dev = litest_current_device();
2304 struct libinput *li = dev->libinput;
2305 struct axis_replacement axes[] = {
2306 { ABS_MT_TOUCH_MAJOR, 0 },
2307 { ABS_MT_TOUCH_MINOR, 0 },
2308 { ABS_MT_ORIENTATION, 0 },
2309 { -1, 0 }
2310 };
2311
2312 if (!touchpad_has_touch_size(dev))
2313 return;
2314
2315 litest_enable_clickfinger(dev);
2316 litest_disable_tap(dev->libinput_device);
2317 litest_disable_hold_gestures(dev->libinput_device);
2318 litest_drain_events(li);
2319
2320 litest_touch_down_extended(dev, 0, 50, 95, axes);
2321 litest_touch_down(dev, 1, 50, 50);
2322 litest_button_click(dev, BTN_LEFT, true);
2323 litest_button_click(dev, BTN_LEFT, false);
2324
2325 litest_touch_up(dev, 1);
2326 litest_touch_up(dev, 0);
2327
2328 litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
2329 litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
2330 litest_assert_empty_queue(li);
2331 }
2332 END_TEST
2333
START_TEST(touchpad_palm_clickfinger_size_2fg)2334 START_TEST(touchpad_palm_clickfinger_size_2fg)
2335 {
2336 struct litest_device *dev = litest_current_device();
2337 struct libinput *li = dev->libinput;
2338 struct axis_replacement axes[] = {
2339 { ABS_MT_TOUCH_MAJOR, 0 },
2340 { ABS_MT_TOUCH_MINOR, 0 },
2341 { ABS_MT_ORIENTATION, 0 },
2342 { -1, 0 }
2343 };
2344
2345 if (!touchpad_has_touch_size(dev))
2346 return;
2347
2348 if (libevdev_get_num_slots(dev->evdev) < 3)
2349 return;
2350
2351 litest_enable_clickfinger(dev);
2352 litest_disable_tap(dev->libinput_device);
2353 litest_disable_hold_gestures(dev->libinput_device);
2354 litest_drain_events(li);
2355
2356 litest_touch_down_extended(dev, 0, 50, 95, axes);
2357 litest_touch_down(dev, 1, 50, 50);
2358 litest_touch_down(dev, 2, 50, 60);
2359 litest_button_click(dev, BTN_LEFT, true);
2360 litest_button_click(dev, BTN_LEFT, false);
2361
2362 litest_touch_up(dev, 1);
2363 litest_touch_up(dev, 2);
2364 litest_touch_up(dev, 0);
2365
2366 litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED);
2367 litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED);
2368 litest_assert_empty_queue(li);
2369 }
2370 END_TEST
2371
START_TEST(touchpad_left_handed)2372 START_TEST(touchpad_left_handed)
2373 {
2374 struct litest_device *dev = litest_current_device();
2375 struct libinput_device *d = dev->libinput_device;
2376 struct libinput *li = dev->libinput;
2377 enum libinput_config_status status;
2378
2379 if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE &&
2380 libevdev_get_id_product(dev->evdev) == PRODUCT_ID_APPLE_APPLETOUCH)
2381 return;
2382
2383 status = libinput_device_config_left_handed_set(d, 1);
2384 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2385
2386 litest_drain_events(li);
2387 litest_button_click(dev, BTN_LEFT, 1);
2388 litest_button_click(dev, BTN_LEFT, 0);
2389
2390 litest_assert_button_event(li,
2391 BTN_RIGHT,
2392 LIBINPUT_BUTTON_STATE_PRESSED);
2393 litest_assert_button_event(li,
2394 BTN_RIGHT,
2395 LIBINPUT_BUTTON_STATE_RELEASED);
2396
2397 litest_button_click(dev, BTN_RIGHT, 1);
2398 litest_button_click(dev, BTN_RIGHT, 0);
2399 litest_assert_button_event(li,
2400 BTN_LEFT,
2401 LIBINPUT_BUTTON_STATE_PRESSED);
2402 litest_assert_button_event(li,
2403 BTN_LEFT,
2404 LIBINPUT_BUTTON_STATE_RELEASED);
2405
2406 if (libevdev_has_event_code(dev->evdev,
2407 EV_KEY,
2408 BTN_MIDDLE)) {
2409 litest_button_click(dev, BTN_MIDDLE, 1);
2410 litest_button_click(dev, BTN_MIDDLE, 0);
2411 litest_assert_button_event(li,
2412 BTN_MIDDLE,
2413 LIBINPUT_BUTTON_STATE_PRESSED);
2414 litest_assert_button_event(li,
2415 BTN_MIDDLE,
2416 LIBINPUT_BUTTON_STATE_RELEASED);
2417 }
2418 }
2419 END_TEST
2420
START_TEST(touchpad_left_handed_appletouch)2421 START_TEST(touchpad_left_handed_appletouch)
2422 {
2423 struct litest_device *dev = litest_current_device();
2424 struct libinput_device *d = dev->libinput_device;
2425 enum libinput_config_status status;
2426
2427 ck_assert_int_eq(libinput_device_config_left_handed_is_available(d), 0);
2428 status = libinput_device_config_left_handed_set(d, 1);
2429 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
2430 ck_assert_int_eq(libinput_device_config_left_handed_get(d), 0);
2431 }
2432 END_TEST
2433
START_TEST(touchpad_left_handed_clickpad)2434 START_TEST(touchpad_left_handed_clickpad)
2435 {
2436 struct litest_device *dev = litest_current_device();
2437 struct libinput_device *d = dev->libinput_device;
2438 struct libinput *li = dev->libinput;
2439 enum libinput_config_status status;
2440
2441 if (!libinput_device_config_left_handed_is_available(d))
2442 return;
2443
2444 status = libinput_device_config_left_handed_set(d, 1);
2445 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2446
2447 litest_drain_events(li);
2448 litest_touch_down(dev, 0, 10, 90);
2449 litest_button_click(dev, BTN_LEFT, 1);
2450 litest_button_click(dev, BTN_LEFT, 0);
2451 litest_touch_up(dev, 0);
2452
2453 litest_assert_button_event(li,
2454 BTN_RIGHT,
2455 LIBINPUT_BUTTON_STATE_PRESSED);
2456 litest_assert_button_event(li,
2457 BTN_RIGHT,
2458 LIBINPUT_BUTTON_STATE_RELEASED);
2459
2460 litest_drain_events(li);
2461 litest_touch_down(dev, 0, 90, 90);
2462 litest_button_click(dev, BTN_LEFT, 1);
2463 litest_button_click(dev, BTN_LEFT, 0);
2464 litest_touch_up(dev, 0);
2465
2466 litest_assert_button_event(li,
2467 BTN_LEFT,
2468 LIBINPUT_BUTTON_STATE_PRESSED);
2469 litest_assert_button_event(li,
2470 BTN_LEFT,
2471 LIBINPUT_BUTTON_STATE_RELEASED);
2472
2473 litest_drain_events(li);
2474 litest_touch_down(dev, 0, 50, 50);
2475 litest_button_click(dev, BTN_LEFT, 1);
2476 litest_button_click(dev, BTN_LEFT, 0);
2477 litest_touch_up(dev, 0);
2478
2479 litest_assert_button_event(li,
2480 BTN_LEFT,
2481 LIBINPUT_BUTTON_STATE_PRESSED);
2482 litest_assert_button_event(li,
2483 BTN_LEFT,
2484 LIBINPUT_BUTTON_STATE_RELEASED);
2485 }
2486 END_TEST
2487
START_TEST(touchpad_left_handed_clickfinger)2488 START_TEST(touchpad_left_handed_clickfinger)
2489 {
2490 struct litest_device *dev = litest_current_device();
2491 struct libinput_device *d = dev->libinput_device;
2492 struct libinput *li = dev->libinput;
2493 enum libinput_config_status status;
2494
2495 if (!libinput_device_config_left_handed_is_available(d))
2496 return;
2497
2498 status = libinput_device_config_left_handed_set(d, 1);
2499 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2500
2501 litest_drain_events(li);
2502 litest_touch_down(dev, 0, 10, 90);
2503 litest_button_click(dev, BTN_LEFT, 1);
2504 litest_button_click(dev, BTN_LEFT, 0);
2505 litest_touch_up(dev, 0);
2506
2507 /* Clickfinger is unaffected by left-handed setting */
2508 litest_assert_button_event(li,
2509 BTN_LEFT,
2510 LIBINPUT_BUTTON_STATE_PRESSED);
2511 litest_assert_button_event(li,
2512 BTN_LEFT,
2513 LIBINPUT_BUTTON_STATE_RELEASED);
2514
2515 litest_drain_events(li);
2516 litest_touch_down(dev, 0, 10, 90);
2517 litest_touch_down(dev, 1, 30, 90);
2518 litest_button_click(dev, BTN_LEFT, 1);
2519 litest_button_click(dev, BTN_LEFT, 0);
2520 litest_touch_up(dev, 0);
2521 litest_touch_up(dev, 1);
2522
2523 litest_assert_button_event(li,
2524 BTN_RIGHT,
2525 LIBINPUT_BUTTON_STATE_PRESSED);
2526 litest_assert_button_event(li,
2527 BTN_RIGHT,
2528 LIBINPUT_BUTTON_STATE_RELEASED);
2529 }
2530 END_TEST
2531
START_TEST(touchpad_left_handed_tapping)2532 START_TEST(touchpad_left_handed_tapping)
2533 {
2534 struct litest_device *dev = litest_current_device();
2535 struct libinput_device *d = dev->libinput_device;
2536 struct libinput *li = dev->libinput;
2537 enum libinput_config_status status;
2538
2539 if (!libinput_device_config_left_handed_is_available(d))
2540 return;
2541
2542 litest_enable_tap(dev->libinput_device);
2543 litest_disable_hold_gestures(dev->libinput_device);
2544
2545 status = libinput_device_config_left_handed_set(d, 1);
2546 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2547
2548 litest_drain_events(li);
2549
2550 litest_touch_down(dev, 0, 50, 50);
2551 litest_touch_up(dev, 0);
2552
2553 libinput_dispatch(li);
2554 litest_timeout_tap();
2555 libinput_dispatch(li);
2556
2557 /* Tapping is unaffected by left-handed setting */
2558 litest_assert_button_event(li,
2559 BTN_LEFT,
2560 LIBINPUT_BUTTON_STATE_PRESSED);
2561 litest_assert_button_event(li,
2562 BTN_LEFT,
2563 LIBINPUT_BUTTON_STATE_RELEASED);
2564 }
2565 END_TEST
2566
START_TEST(touchpad_left_handed_tapping_2fg)2567 START_TEST(touchpad_left_handed_tapping_2fg)
2568 {
2569 struct litest_device *dev = litest_current_device();
2570 struct libinput_device *d = dev->libinput_device;
2571 struct libinput *li = dev->libinput;
2572 enum libinput_config_status status;
2573
2574 if (!libinput_device_config_left_handed_is_available(d))
2575 return;
2576
2577 litest_enable_tap(dev->libinput_device);
2578 litest_disable_hold_gestures(dev->libinput_device);
2579
2580 status = libinput_device_config_left_handed_set(d, 1);
2581 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2582
2583 litest_drain_events(li);
2584
2585 litest_touch_down(dev, 0, 50, 50);
2586 litest_touch_down(dev, 1, 70, 50);
2587 litest_touch_up(dev, 1);
2588 litest_touch_up(dev, 0);
2589
2590 libinput_dispatch(li);
2591 litest_timeout_tap();
2592 libinput_dispatch(li);
2593
2594 /* Tapping is unaffected by left-handed setting */
2595 litest_assert_button_event(li,
2596 BTN_RIGHT,
2597 LIBINPUT_BUTTON_STATE_PRESSED);
2598 litest_assert_button_event(li,
2599 BTN_RIGHT,
2600 LIBINPUT_BUTTON_STATE_RELEASED);
2601 }
2602 END_TEST
2603
START_TEST(touchpad_left_handed_delayed)2604 START_TEST(touchpad_left_handed_delayed)
2605 {
2606 struct litest_device *dev = litest_current_device();
2607 struct libinput_device *d = dev->libinput_device;
2608 struct libinput *li = dev->libinput;
2609 enum libinput_config_status status;
2610
2611 if (!libinput_device_config_left_handed_is_available(d))
2612 return;
2613
2614 litest_drain_events(li);
2615 litest_button_click(dev, BTN_LEFT, 1);
2616 libinput_dispatch(li);
2617
2618 status = libinput_device_config_left_handed_set(d, 1);
2619 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2620
2621 litest_button_click(dev, BTN_LEFT, 0);
2622
2623 litest_assert_button_event(li,
2624 BTN_LEFT,
2625 LIBINPUT_BUTTON_STATE_PRESSED);
2626 litest_assert_button_event(li,
2627 BTN_LEFT,
2628 LIBINPUT_BUTTON_STATE_RELEASED);
2629
2630 /* left-handed takes effect now */
2631 litest_button_click(dev, BTN_RIGHT, 1);
2632 libinput_dispatch(li);
2633 litest_timeout_middlebutton();
2634 libinput_dispatch(li);
2635 litest_button_click(dev, BTN_LEFT, 1);
2636 libinput_dispatch(li);
2637
2638 status = libinput_device_config_left_handed_set(d, 0);
2639 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2640
2641 litest_button_click(dev, BTN_RIGHT, 0);
2642 litest_button_click(dev, BTN_LEFT, 0);
2643
2644 litest_assert_button_event(li,
2645 BTN_LEFT,
2646 LIBINPUT_BUTTON_STATE_PRESSED);
2647 litest_assert_button_event(li,
2648 BTN_RIGHT,
2649 LIBINPUT_BUTTON_STATE_PRESSED);
2650 litest_assert_button_event(li,
2651 BTN_LEFT,
2652 LIBINPUT_BUTTON_STATE_RELEASED);
2653 litest_assert_button_event(li,
2654 BTN_RIGHT,
2655 LIBINPUT_BUTTON_STATE_RELEASED);
2656 }
2657 END_TEST
2658
START_TEST(touchpad_left_handed_clickpad_delayed)2659 START_TEST(touchpad_left_handed_clickpad_delayed)
2660 {
2661 struct litest_device *dev = litest_current_device();
2662 struct libinput_device *d = dev->libinput_device;
2663 struct libinput *li = dev->libinput;
2664 enum libinput_config_status status;
2665
2666 if (!libinput_device_config_left_handed_is_available(d))
2667 return;
2668
2669 litest_drain_events(li);
2670 litest_touch_down(dev, 0, 10, 90);
2671 litest_button_click(dev, BTN_LEFT, 1);
2672 libinput_dispatch(li);
2673
2674 status = libinput_device_config_left_handed_set(d, 1);
2675 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2676
2677 litest_button_click(dev, BTN_LEFT, 0);
2678 litest_touch_up(dev, 0);
2679
2680 litest_assert_button_event(li,
2681 BTN_LEFT,
2682 LIBINPUT_BUTTON_STATE_PRESSED);
2683 litest_assert_button_event(li,
2684 BTN_LEFT,
2685 LIBINPUT_BUTTON_STATE_RELEASED);
2686
2687 /* left-handed takes effect now */
2688 litest_drain_events(li);
2689 litest_touch_down(dev, 0, 90, 90);
2690 litest_button_click(dev, BTN_LEFT, 1);
2691 libinput_dispatch(li);
2692
2693 status = libinput_device_config_left_handed_set(d, 0);
2694 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2695
2696 litest_button_click(dev, BTN_LEFT, 0);
2697 litest_touch_up(dev, 0);
2698
2699 litest_assert_button_event(li,
2700 BTN_LEFT,
2701 LIBINPUT_BUTTON_STATE_PRESSED);
2702 litest_assert_button_event(li,
2703 BTN_LEFT,
2704 LIBINPUT_BUTTON_STATE_RELEASED);
2705 }
2706 END_TEST
2707
2708 #if HAVE_LIBWACOM
2709 static inline bool
touchpad_has_rotation(struct libevdev * evdev)2710 touchpad_has_rotation(struct libevdev *evdev)
2711 {
2712 return libevdev_get_id_vendor(evdev) == VENDOR_ID_WACOM;
2713 }
2714 #endif /* HAVE_LIBWACOM */
2715
START_TEST(touchpad_left_handed_rotation)2716 START_TEST(touchpad_left_handed_rotation)
2717 {
2718 #if HAVE_LIBWACOM
2719 struct litest_device *dev = litest_current_device();
2720 struct libinput_device *d = dev->libinput_device;
2721 struct libinput *li = dev->libinput;
2722 enum libinput_config_status status;
2723 struct libinput_event *event;
2724 bool rotate = touchpad_has_rotation(dev->evdev);
2725
2726 if (!libinput_device_config_left_handed_is_available(d))
2727 return;
2728
2729 status = libinput_device_config_left_handed_set(d, 1);
2730 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
2731
2732 litest_drain_events(li);
2733
2734 litest_touch_down(dev, 0, 20, 80);
2735 litest_touch_move_to(dev, 0, 20, 80, 80, 20, 20);
2736 litest_touch_up(dev, 0);
2737 libinput_dispatch(li);
2738
2739 event = libinput_get_event(li);
2740 ck_assert_notnull(event);
2741 do {
2742 struct libinput_event_pointer *p;
2743 double x, y, ux, uy;
2744
2745 p = litest_is_motion_event(event);
2746
2747 x = libinput_event_pointer_get_dx(p);
2748 y = libinput_event_pointer_get_dy(p);
2749 ux = libinput_event_pointer_get_dx_unaccelerated(p);
2750 uy = libinput_event_pointer_get_dy_unaccelerated(p);
2751
2752 if (rotate) {
2753 ck_assert_double_lt(x, 0);
2754 ck_assert_double_gt(y, 0);
2755 ck_assert_double_lt(ux, 0);
2756 ck_assert_double_gt(uy, 0);
2757 } else {
2758 ck_assert_double_gt(x, 0);
2759 ck_assert_double_lt(y, 0);
2760 ck_assert_double_gt(ux, 0);
2761 ck_assert_double_lt(uy, 0);
2762 }
2763
2764 libinput_event_destroy(event);
2765 } while ((event = libinput_get_event(li)));
2766 #endif
2767 }
2768 END_TEST
2769
2770 static void
hover_continue(struct litest_device * dev,unsigned int slot,int x,int y)2771 hover_continue(struct litest_device *dev, unsigned int slot,
2772 int x, int y)
2773 {
2774 litest_event(dev, EV_ABS, ABS_MT_SLOT, slot);
2775 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
2776 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
2777 litest_event(dev, EV_ABS, ABS_X, x);
2778 litest_event(dev, EV_ABS, ABS_Y, y);
2779 litest_event(dev, EV_ABS, ABS_PRESSURE, 10);
2780 litest_event(dev, EV_ABS, ABS_TOOL_WIDTH, 6);
2781 /* WARNING: no SYN_REPORT! */
2782 }
2783
2784 static void
hover_start(struct litest_device * dev,unsigned int slot,int x,int y)2785 hover_start(struct litest_device *dev, unsigned int slot,
2786 int x, int y)
2787 {
2788 static unsigned int tracking_id;
2789
2790 litest_event(dev, EV_ABS, ABS_MT_SLOT, slot);
2791 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, ++tracking_id);
2792 hover_continue(dev, slot, x, y);
2793 /* WARNING: no SYN_REPORT! */
2794 }
2795
START_TEST(touchpad_semi_mt_hover_noevent)2796 START_TEST(touchpad_semi_mt_hover_noevent)
2797 {
2798 struct litest_device *dev = litest_current_device();
2799 struct libinput *li = dev->libinput;
2800 int i;
2801 int x = 2400,
2802 y = 2400;
2803
2804 litest_drain_events(li);
2805
2806 hover_start(dev, 0, x, y);
2807 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
2808 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2809
2810 for (i = 0; i < 10; i++) {
2811 x += 200;
2812 y -= 200;
2813 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
2814 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
2815 litest_event(dev, EV_ABS, ABS_X, x);
2816 litest_event(dev, EV_ABS, ABS_Y, y);
2817 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2818 }
2819
2820 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
2821 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2822
2823 litest_assert_empty_queue(li);
2824 }
2825 END_TEST
2826
START_TEST(touchpad_semi_mt_hover_down)2827 START_TEST(touchpad_semi_mt_hover_down)
2828 {
2829 struct litest_device *dev = litest_current_device();
2830 struct libinput *li = dev->libinput;
2831 struct libinput_event *event;
2832 int i;
2833 int x = 2400,
2834 y = 2400;
2835
2836 litest_drain_events(li);
2837
2838 hover_start(dev, 0, x, y);
2839 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
2840 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2841
2842 for (i = 0; i < 10; i++) {
2843 x += 200;
2844 y -= 200;
2845 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
2846 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
2847 litest_event(dev, EV_ABS, ABS_X, x);
2848 litest_event(dev, EV_ABS, ABS_Y, y);
2849 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2850 }
2851
2852 litest_assert_empty_queue(li);
2853
2854 litest_event(dev, EV_ABS, ABS_X, x + 100);
2855 litest_event(dev, EV_ABS, ABS_Y, y + 100);
2856 litest_event(dev, EV_ABS, ABS_PRESSURE, 50);
2857 litest_event(dev, EV_KEY, BTN_TOUCH, 1);
2858 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2859 libinput_dispatch(li);
2860 for (i = 0; i < 10; i++) {
2861 x -= 200;
2862 y += 200;
2863 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
2864 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
2865 litest_event(dev, EV_ABS, ABS_X, x);
2866 litest_event(dev, EV_ABS, ABS_Y, y);
2867 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2868 }
2869
2870 libinput_dispatch(li);
2871
2872 ck_assert_int_ne(libinput_next_event_type(li),
2873 LIBINPUT_EVENT_NONE);
2874 while ((event = libinput_get_event(li)) != NULL) {
2875 ck_assert_int_eq(libinput_event_get_type(event),
2876 LIBINPUT_EVENT_POINTER_MOTION);
2877 libinput_event_destroy(event);
2878 libinput_dispatch(li);
2879 }
2880
2881 /* go back to hover */
2882 hover_continue(dev, 0, x, y);
2883 litest_event(dev, EV_ABS, ABS_PRESSURE, 0);
2884 litest_event(dev, EV_KEY, BTN_TOUCH, 0);
2885 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2886
2887 for (i = 0; i < 10; i++) {
2888 x += 200;
2889 y -= 200;
2890 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
2891 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
2892 litest_event(dev, EV_ABS, ABS_X, x);
2893 litest_event(dev, EV_ABS, ABS_Y, y);
2894 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2895 }
2896
2897 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
2898 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2899
2900 litest_assert_empty_queue(li);
2901 }
2902 END_TEST
2903
START_TEST(touchpad_semi_mt_hover_down_hover_down)2904 START_TEST(touchpad_semi_mt_hover_down_hover_down)
2905 {
2906 struct litest_device *dev = litest_current_device();
2907 struct libinput *li = dev->libinput;
2908 int i, j;
2909 int x = 1400,
2910 y = 1400;
2911
2912 litest_drain_events(li);
2913
2914 /* hover */
2915 hover_start(dev, 0, x, y);
2916 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
2917 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2918 litest_assert_empty_queue(li);
2919
2920 for (i = 0; i < 3; i++) {
2921 /* touch */
2922 litest_event(dev, EV_ABS, ABS_X, x + 100);
2923 litest_event(dev, EV_ABS, ABS_Y, y + 100);
2924 litest_event(dev, EV_ABS, ABS_PRESSURE, 50);
2925 litest_event(dev, EV_KEY, BTN_TOUCH, 1);
2926 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2927 libinput_dispatch(li);
2928
2929 for (j = 0; j < 5; j++) {
2930 x += 200;
2931 y += 200;
2932 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
2933 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
2934 litest_event(dev, EV_ABS, ABS_X, x);
2935 litest_event(dev, EV_ABS, ABS_Y, y);
2936 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2937 }
2938
2939 libinput_dispatch(li);
2940
2941 litest_assert_only_typed_events(li,
2942 LIBINPUT_EVENT_POINTER_MOTION);
2943
2944 /* go back to hover */
2945 hover_continue(dev, 0, x, y);
2946 litest_event(dev, EV_ABS, ABS_PRESSURE, 0);
2947 litest_event(dev, EV_KEY, BTN_TOUCH, 0);
2948 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2949
2950 for (j = 0; j < 5; j++) {
2951 x -= 200;
2952 y -= 200;
2953 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
2954 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
2955 litest_event(dev, EV_ABS, ABS_X, x);
2956 litest_event(dev, EV_ABS, ABS_Y, y);
2957 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2958 }
2959
2960 litest_assert_empty_queue(li);
2961 }
2962
2963 /* touch */
2964 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
2965 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2966
2967 litest_assert_empty_queue(li);
2968
2969 /* start a new touch to be sure */
2970 litest_push_event_frame(dev);
2971 litest_touch_down(dev, 0, 50, 50);
2972 litest_event(dev, EV_ABS, ABS_PRESSURE, 50);
2973 litest_pop_event_frame(dev);
2974 litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
2975 litest_touch_up(dev, 0);
2976
2977 libinput_dispatch(li);
2978 litest_assert_only_typed_events(li,
2979 LIBINPUT_EVENT_POINTER_MOTION);
2980 }
2981 END_TEST
2982
START_TEST(touchpad_semi_mt_hover_down_up)2983 START_TEST(touchpad_semi_mt_hover_down_up)
2984 {
2985 struct litest_device *dev = litest_current_device();
2986 struct libinput *li = dev->libinput;
2987 int i;
2988 int x = 1400,
2989 y = 1400;
2990
2991 litest_drain_events(li);
2992
2993 /* hover two fingers, then touch */
2994 hover_start(dev, 0, x, y);
2995 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
2996 litest_event(dev, EV_SYN, SYN_REPORT, 0);
2997 litest_assert_empty_queue(li);
2998
2999 hover_start(dev, 1, x, y);
3000 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
3001 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1);
3002 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3003 litest_assert_empty_queue(li);
3004
3005 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
3006 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
3007 litest_event(dev, EV_KEY, BTN_TOUCH, 1);
3008 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3009
3010 litest_assert_empty_queue(li);
3011
3012 /* hover first finger, end second in same frame */
3013 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
3014 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
3015 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0);
3016 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
3017 litest_event(dev, EV_KEY, BTN_TOUCH, 0);
3018 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3019
3020 litest_assert_empty_queue(li);
3021
3022 litest_event(dev, EV_ABS, ABS_PRESSURE, 50);
3023 litest_event(dev, EV_KEY, BTN_TOUCH, 1);
3024 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3025 libinput_dispatch(li);
3026
3027 /* now move the finger */
3028 for (i = 0; i < 10; i++) {
3029 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
3030 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
3031 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
3032 litest_event(dev, EV_ABS, ABS_X, x);
3033 litest_event(dev, EV_ABS, ABS_Y, y);
3034 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3035 x -= 100;
3036 y -= 100;
3037 }
3038
3039 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3040
3041 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
3042 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
3043 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
3044 litest_event(dev, EV_KEY, BTN_TOUCH, 0);
3045 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3046 libinput_dispatch(li);
3047 }
3048 END_TEST
3049
START_TEST(touchpad_semi_mt_hover_2fg_noevent)3050 START_TEST(touchpad_semi_mt_hover_2fg_noevent)
3051 {
3052 struct litest_device *dev = litest_current_device();
3053 struct libinput *li = dev->libinput;
3054 int i;
3055 int x = 2400,
3056 y = 2400;
3057
3058 litest_drain_events(li);
3059
3060 hover_start(dev, 0, x, y);
3061 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
3062 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3063
3064 hover_start(dev, 1, x + 500, y + 500);
3065 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
3066 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1);
3067 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3068
3069 for (i = 0; i < 10; i++) {
3070 x += 200;
3071 y -= 200;
3072 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
3073 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
3074 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
3075 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
3076 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x + 500);
3077 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y + 500);
3078 litest_event(dev, EV_ABS, ABS_X, x);
3079 litest_event(dev, EV_ABS, ABS_Y, y);
3080 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3081 }
3082
3083 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
3084 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3085
3086 litest_assert_empty_queue(li);
3087
3088 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
3089 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3090
3091 litest_assert_empty_queue(li);
3092 }
3093 END_TEST
3094
START_TEST(touchpad_semi_mt_hover_2fg_1fg_down)3095 START_TEST(touchpad_semi_mt_hover_2fg_1fg_down)
3096 {
3097 struct litest_device *dev = litest_current_device();
3098 struct libinput *li = dev->libinput;
3099 int i;
3100 int x = 2400,
3101 y = 2400;
3102
3103 litest_drain_events(li);
3104
3105 /* two slots active, but BTN_TOOL_FINGER only */
3106 hover_start(dev, 0, x, y);
3107 hover_start(dev, 1, x + 500, y + 500);
3108 litest_event(dev, EV_ABS, ABS_PRESSURE, 50);
3109 litest_event(dev, EV_KEY, BTN_TOUCH, 1);
3110 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
3111 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3112
3113 for (i = 0; i < 10; i++) {
3114 x += 200;
3115 y -= 200;
3116 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
3117 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x);
3118 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y);
3119 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
3120 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x + 500);
3121 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y + 500);
3122 litest_event(dev, EV_ABS, ABS_X, x);
3123 litest_event(dev, EV_ABS, ABS_Y, y);
3124 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3125 }
3126
3127 litest_event(dev, EV_ABS, ABS_PRESSURE, 0);
3128 litest_event(dev, EV_KEY, BTN_TOUCH, 0);
3129 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
3130 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3131
3132 libinput_dispatch(li);
3133
3134 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3135 }
3136 END_TEST
3137
START_TEST(touchpad_semi_mt_hover_2fg_up)3138 START_TEST(touchpad_semi_mt_hover_2fg_up)
3139 {
3140 struct litest_device *dev = litest_current_device();
3141 struct libinput *li = dev->libinput;
3142
3143 litest_touch_down(dev, 0, 70, 50);
3144 litest_touch_down(dev, 1, 50, 50);
3145
3146 litest_push_event_frame(dev);
3147 litest_touch_move(dev, 0, 72, 50);
3148 litest_touch_move(dev, 1, 52, 50);
3149 litest_event(dev, EV_ABS, ABS_PRESSURE, 0);
3150 litest_event(dev, EV_KEY, BTN_TOUCH, 0);
3151 litest_pop_event_frame(dev);
3152
3153 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
3154 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
3155 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
3156 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
3157 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
3158 litest_event(dev, EV_SYN, SYN_REPORT, 0);
3159
3160 litest_drain_events(li);
3161 }
3162 END_TEST
3163
START_TEST(touchpad_hover_noevent)3164 START_TEST(touchpad_hover_noevent)
3165 {
3166 struct litest_device *dev = litest_current_device();
3167 struct libinput *li = dev->libinput;
3168
3169 litest_drain_events(li);
3170
3171 litest_hover_start(dev, 0, 50, 50);
3172 litest_hover_move_to(dev, 0, 50, 50, 70, 70, 10);
3173 litest_hover_end(dev, 0);
3174
3175 litest_assert_empty_queue(li);
3176 }
3177 END_TEST
3178
START_TEST(touchpad_hover_down)3179 START_TEST(touchpad_hover_down)
3180 {
3181 struct litest_device *dev = litest_current_device();
3182 struct libinput *li = dev->libinput;
3183
3184 litest_drain_events(li);
3185
3186 /* hover the finger */
3187 litest_hover_start(dev, 0, 50, 50);
3188
3189 litest_hover_move_to(dev, 0, 50, 50, 70, 70, 10);
3190
3191 litest_assert_empty_queue(li);
3192
3193 /* touch the finger on the sensor */
3194 litest_touch_move_to(dev, 0, 70, 70, 50, 50, 10);
3195
3196 libinput_dispatch(li);
3197
3198 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3199
3200 /* go back to hover */
3201 litest_hover_move_to(dev, 0, 50, 50, 70, 70, 10);
3202 litest_hover_end(dev, 0);
3203
3204 litest_assert_empty_queue(li);
3205 }
3206 END_TEST
3207
START_TEST(touchpad_hover_down_hover_down)3208 START_TEST(touchpad_hover_down_hover_down)
3209 {
3210 struct litest_device *dev = litest_current_device();
3211 struct libinput *li = dev->libinput;
3212 int i;
3213
3214 litest_drain_events(li);
3215
3216 litest_hover_start(dev, 0, 50, 50);
3217
3218 for (i = 0; i < 3; i++) {
3219
3220 /* hover the finger */
3221 litest_hover_move_to(dev, 0, 50, 50, 70, 70, 10);
3222
3223 litest_assert_empty_queue(li);
3224
3225 /* touch the finger */
3226 litest_touch_move_to(dev, 0, 70, 70, 50, 50, 10);
3227
3228 libinput_dispatch(li);
3229
3230 litest_assert_only_typed_events(li,
3231 LIBINPUT_EVENT_POINTER_MOTION);
3232 }
3233
3234 litest_hover_end(dev, 0);
3235
3236 /* start a new touch to be sure */
3237 litest_touch_down(dev, 0, 50, 50);
3238 litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
3239 litest_touch_up(dev, 0);
3240
3241 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3242 }
3243 END_TEST
3244
START_TEST(touchpad_hover_down_up)3245 START_TEST(touchpad_hover_down_up)
3246 {
3247 struct litest_device *dev = litest_current_device();
3248 struct libinput *li = dev->libinput;
3249
3250 litest_drain_events(li);
3251
3252 /* hover two fingers, and a touch */
3253 litest_push_event_frame(dev);
3254 litest_hover_start(dev, 0, 50, 50);
3255 litest_hover_start(dev, 1, 50, 50);
3256 litest_touch_down(dev, 2, 50, 50);
3257 litest_pop_event_frame(dev);
3258
3259 litest_assert_empty_queue(li);
3260
3261 /* hover first finger, end second and third in same frame */
3262 litest_push_event_frame(dev);
3263 litest_hover_move(dev, 0, 55, 55);
3264 litest_hover_end(dev, 1);
3265 litest_touch_up(dev, 2);
3266 litest_pop_event_frame(dev);
3267
3268 litest_assert_empty_queue(li);
3269
3270 /* now move the finger */
3271 litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10);
3272
3273 litest_touch_up(dev, 0);
3274
3275 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3276 }
3277 END_TEST
3278
START_TEST(touchpad_hover_2fg_noevent)3279 START_TEST(touchpad_hover_2fg_noevent)
3280 {
3281 struct litest_device *dev = litest_current_device();
3282 struct libinput *li = dev->libinput;
3283
3284 litest_drain_events(li);
3285
3286 /* hover two fingers */
3287 litest_push_event_frame(dev);
3288 litest_hover_start(dev, 0, 25, 25);
3289 litest_hover_start(dev, 1, 50, 50);
3290 litest_pop_event_frame(dev);
3291
3292 litest_hover_move_two_touches(dev, 25, 25, 50, 50, 50, 50, 10);
3293
3294 litest_push_event_frame(dev);
3295 litest_hover_end(dev, 0);
3296 litest_hover_end(dev, 1);
3297 litest_pop_event_frame(dev);
3298
3299 litest_assert_empty_queue(li);
3300 }
3301 END_TEST
3302
START_TEST(touchpad_hover_2fg_1fg_down)3303 START_TEST(touchpad_hover_2fg_1fg_down)
3304 {
3305 struct litest_device *dev = litest_current_device();
3306 struct libinput *li = dev->libinput;
3307 int i;
3308
3309 litest_drain_events(li);
3310
3311 /* hover two fingers */
3312 litest_push_event_frame(dev);
3313 litest_hover_start(dev, 0, 25, 25);
3314 litest_touch_down(dev, 1, 50, 50);
3315 litest_pop_event_frame(dev);
3316
3317 for (i = 0; i < 10; i++) {
3318 litest_push_event_frame(dev);
3319 litest_hover_move(dev, 0, 25 + 5 * i, 25 + 5 * i);
3320 litest_touch_move(dev, 1, 50 + 5 * i, 50 - 5 * i);
3321 litest_pop_event_frame(dev);
3322 }
3323
3324 litest_push_event_frame(dev);
3325 litest_hover_end(dev, 0);
3326 litest_touch_up(dev, 1);
3327 litest_pop_event_frame(dev);
3328
3329 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3330 }
3331 END_TEST
3332
START_TEST(touchpad_hover_1fg_tap)3333 START_TEST(touchpad_hover_1fg_tap)
3334 {
3335 struct litest_device *dev = litest_current_device();
3336 struct libinput *li = dev->libinput;
3337
3338 litest_enable_tap(dev->libinput_device);
3339 litest_disable_hold_gestures(dev->libinput_device);
3340 litest_drain_events(li);
3341
3342 litest_hover_start(dev, 0, 50, 50);
3343 litest_hover_end(dev, 0);
3344
3345 libinput_dispatch(li);
3346 litest_assert_empty_queue(li);
3347
3348 }
3349 END_TEST
3350
3351 static void
assert_btnevent_from_device(struct litest_device * device,unsigned int button,enum libinput_button_state state)3352 assert_btnevent_from_device(struct litest_device *device,
3353 unsigned int button,
3354 enum libinput_button_state state)
3355 {
3356 struct libinput *li = device->libinput;
3357 struct libinput_event *e;
3358
3359 libinput_dispatch(li);
3360 e = libinput_get_event(li);
3361 litest_is_button_event(e, button, state);
3362
3363 litest_assert_ptr_eq(libinput_event_get_device(e), device->libinput_device);
3364 libinput_event_destroy(e);
3365 }
3366
START_TEST(touchpad_trackpoint_buttons)3367 START_TEST(touchpad_trackpoint_buttons)
3368 {
3369 struct litest_device *touchpad = litest_current_device();
3370 struct litest_device *trackpoint;
3371 struct libinput *li = touchpad->libinput;
3372
3373 const struct buttons {
3374 unsigned int device_value;
3375 unsigned int real_value;
3376 } buttons[] = {
3377 { BTN_0, BTN_LEFT },
3378 { BTN_1, BTN_RIGHT },
3379 { BTN_2, BTN_MIDDLE },
3380 };
3381
3382 trackpoint = litest_add_device(li,
3383 LITEST_TRACKPOINT);
3384 libinput_device_config_scroll_set_method(trackpoint->libinput_device,
3385 LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
3386
3387 litest_drain_events(li);
3388
3389 ARRAY_FOR_EACH(buttons, b) {
3390 litest_button_click_debounced(touchpad, li, b->device_value, true);
3391 assert_btnevent_from_device(trackpoint,
3392 b->real_value,
3393 LIBINPUT_BUTTON_STATE_PRESSED);
3394
3395 litest_button_click_debounced(touchpad, li, b->device_value, false);
3396
3397 assert_btnevent_from_device(trackpoint,
3398 b->real_value,
3399 LIBINPUT_BUTTON_STATE_RELEASED);
3400 }
3401
3402 litest_delete_device(trackpoint);
3403 }
3404 END_TEST
3405
START_TEST(touchpad_trackpoint_mb_scroll)3406 START_TEST(touchpad_trackpoint_mb_scroll)
3407 {
3408 struct litest_device *touchpad = litest_current_device();
3409 struct litest_device *trackpoint;
3410 struct libinput *li = touchpad->libinput;
3411
3412 trackpoint = litest_add_device(li,
3413 LITEST_TRACKPOINT);
3414
3415 litest_drain_events(li);
3416 litest_button_click(touchpad, BTN_2, true); /* middle */
3417 libinput_dispatch(li);
3418 litest_timeout_buttonscroll();
3419 libinput_dispatch(li);
3420 litest_event(trackpoint, EV_REL, REL_Y, -2);
3421 litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
3422 litest_event(trackpoint, EV_REL, REL_Y, -2);
3423 litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
3424 litest_event(trackpoint, EV_REL, REL_Y, -2);
3425 litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
3426 litest_event(trackpoint, EV_REL, REL_Y, -2);
3427 litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
3428 litest_button_click(touchpad, BTN_2, false);
3429
3430 litest_assert_only_axis_events(li,
3431 LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS);
3432
3433 litest_delete_device(trackpoint);
3434 }
3435 END_TEST
3436
START_TEST(touchpad_trackpoint_mb_click)3437 START_TEST(touchpad_trackpoint_mb_click)
3438 {
3439 struct litest_device *touchpad = litest_current_device();
3440 struct litest_device *trackpoint;
3441 struct libinput *li = touchpad->libinput;
3442 enum libinput_config_status status;
3443
3444 trackpoint = litest_add_device(li,
3445 LITEST_TRACKPOINT);
3446 status = libinput_device_config_scroll_set_method(
3447 trackpoint->libinput_device,
3448 LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
3449 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
3450
3451 litest_drain_events(li);
3452 litest_button_click_debounced(touchpad, li, BTN_2, true); /* middle */
3453 litest_button_click_debounced(touchpad, li, BTN_2, false);
3454
3455 assert_btnevent_from_device(trackpoint,
3456 BTN_MIDDLE,
3457 LIBINPUT_BUTTON_STATE_PRESSED);
3458 assert_btnevent_from_device(trackpoint,
3459 BTN_MIDDLE,
3460 LIBINPUT_BUTTON_STATE_RELEASED);
3461 litest_delete_device(trackpoint);
3462 }
3463 END_TEST
3464
START_TEST(touchpad_trackpoint_buttons_softbuttons)3465 START_TEST(touchpad_trackpoint_buttons_softbuttons)
3466 {
3467 struct litest_device *touchpad = litest_current_device();
3468 struct litest_device *trackpoint;
3469 struct libinput *li = touchpad->libinput;
3470
3471 trackpoint = litest_add_device(li,
3472 LITEST_TRACKPOINT);
3473
3474 litest_drain_events(li);
3475
3476 litest_touch_down(touchpad, 0, 95, 90);
3477 litest_button_click_debounced(touchpad, li, BTN_LEFT, true);
3478 litest_button_click_debounced(touchpad, li, BTN_1, true);
3479 litest_button_click_debounced(touchpad, li, BTN_LEFT, false);
3480 litest_touch_up(touchpad, 0);
3481 litest_button_click_debounced(touchpad, li, BTN_1, false);
3482
3483 assert_btnevent_from_device(touchpad,
3484 BTN_RIGHT,
3485 LIBINPUT_BUTTON_STATE_PRESSED);
3486 assert_btnevent_from_device(trackpoint,
3487 BTN_RIGHT,
3488 LIBINPUT_BUTTON_STATE_PRESSED);
3489 assert_btnevent_from_device(touchpad,
3490 BTN_RIGHT,
3491 LIBINPUT_BUTTON_STATE_RELEASED);
3492 assert_btnevent_from_device(trackpoint,
3493 BTN_RIGHT,
3494 LIBINPUT_BUTTON_STATE_RELEASED);
3495
3496 litest_touch_down(touchpad, 0, 95, 90);
3497 litest_button_click_debounced(touchpad, li, BTN_LEFT, true);
3498 litest_button_click_debounced(touchpad, li, BTN_1, true);
3499 litest_button_click_debounced(touchpad, li, BTN_1, false);
3500 litest_button_click_debounced(touchpad, li, BTN_LEFT, false);
3501 litest_touch_up(touchpad, 0);
3502
3503 assert_btnevent_from_device(touchpad,
3504 BTN_RIGHT,
3505 LIBINPUT_BUTTON_STATE_PRESSED);
3506 assert_btnevent_from_device(trackpoint,
3507 BTN_RIGHT,
3508 LIBINPUT_BUTTON_STATE_PRESSED);
3509 assert_btnevent_from_device(trackpoint,
3510 BTN_RIGHT,
3511 LIBINPUT_BUTTON_STATE_RELEASED);
3512 assert_btnevent_from_device(touchpad,
3513 BTN_RIGHT,
3514 LIBINPUT_BUTTON_STATE_RELEASED);
3515
3516 litest_delete_device(trackpoint);
3517 }
3518 END_TEST
3519
START_TEST(touchpad_trackpoint_buttons_2fg_scroll)3520 START_TEST(touchpad_trackpoint_buttons_2fg_scroll)
3521 {
3522 struct litest_device *touchpad = litest_current_device();
3523 struct litest_device *trackpoint;
3524 struct libinput *li = touchpad->libinput;
3525 struct libinput_event *e;
3526 double val;
3527
3528 trackpoint = litest_add_device(li,
3529 LITEST_TRACKPOINT);
3530
3531 litest_drain_events(li);
3532
3533 litest_touch_down(touchpad, 0, 40, 70);
3534 litest_touch_down(touchpad, 1, 60, 70);
3535 litest_touch_move_two_touches(touchpad, 40, 70, 60, 70, 0, -40, 10);
3536
3537 libinput_dispatch(li);
3538 litest_wait_for_event(li);
3539
3540 /* Make sure we get scroll events but _not_ the scroll release */
3541 while ((e = libinput_get_event(li))) {
3542 struct libinput_event_pointer *pev;
3543
3544 pev = litest_is_axis_event(e,
3545 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
3546 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
3547 0);
3548 val = litest_event_pointer_get_value(pev,
3549 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
3550 ck_assert(val != 0.0);
3551 libinput_event_destroy(e);
3552 }
3553
3554 litest_button_click_debounced(touchpad, li, BTN_1, true);
3555 assert_btnevent_from_device(trackpoint,
3556 BTN_RIGHT,
3557 LIBINPUT_BUTTON_STATE_PRESSED);
3558
3559 litest_touch_move_to(touchpad, 0, 40, 30, 40, 70, 10);
3560 litest_touch_move_to(touchpad, 1, 60, 30, 60, 70, 10);
3561
3562 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
3563
3564 while ((e = libinput_get_event(li))) {
3565 struct libinput_event_pointer *pev;
3566
3567 pev = litest_is_axis_event(e,
3568 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
3569 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
3570 0);
3571 val = litest_event_pointer_get_value(pev,
3572 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
3573 ck_assert(val != 0.0);
3574 libinput_event_destroy(e);
3575 }
3576
3577 litest_button_click_debounced(touchpad, li, BTN_1, false);
3578 assert_btnevent_from_device(trackpoint,
3579 BTN_RIGHT,
3580 LIBINPUT_BUTTON_STATE_RELEASED);
3581
3582 /* the movement lags behind the touch movement, so the first couple
3583 events can be downwards even though we started scrolling up. do a
3584 short scroll up, drain those events, then we can use
3585 litest_assert_scroll() which tests for the trailing 0/0 scroll
3586 for us.
3587 */
3588 litest_touch_move_to(touchpad, 0, 40, 70, 40, 60, 10);
3589 litest_touch_move_to(touchpad, 1, 60, 70, 60, 60, 10);
3590 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
3591 litest_touch_move_to(touchpad, 0, 40, 60, 40, 30, 10);
3592 litest_touch_move_to(touchpad, 1, 60, 60, 60, 30, 10);
3593
3594 litest_touch_up(touchpad, 0);
3595 litest_touch_up(touchpad, 1);
3596
3597 libinput_dispatch(li);
3598
3599 litest_assert_scroll(li,
3600 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
3601 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
3602 -1);
3603
3604 litest_delete_device(trackpoint);
3605 }
3606 END_TEST
3607
START_TEST(touchpad_trackpoint_no_trackpoint)3608 START_TEST(touchpad_trackpoint_no_trackpoint)
3609 {
3610 struct litest_device *touchpad = litest_current_device();
3611 struct libinput *li = touchpad->libinput;
3612
3613 litest_drain_events(li);
3614 litest_button_click(touchpad, BTN_0, true); /* left */
3615 litest_button_click(touchpad, BTN_0, false);
3616 litest_assert_empty_queue(li);
3617
3618 litest_button_click(touchpad, BTN_1, true); /* right */
3619 litest_button_click(touchpad, BTN_1, false);
3620 litest_assert_empty_queue(li);
3621
3622 litest_button_click(touchpad, BTN_2, true); /* middle */
3623 litest_button_click(touchpad, BTN_2, false);
3624 litest_assert_empty_queue(li);
3625 }
3626 END_TEST
3627
START_TEST(touchpad_initial_state)3628 START_TEST(touchpad_initial_state)
3629 {
3630 struct litest_device *dev;
3631 struct libinput *libinput1, *libinput2;
3632 int axis = _i; /* looped test */
3633 int x = 40, y = 60;
3634
3635 dev = litest_current_device();
3636 libinput1 = dev->libinput;
3637
3638 litest_disable_tap(dev->libinput_device);
3639 litest_disable_hold_gestures(dev->libinput_device);
3640
3641 litest_touch_down(dev, 0, x, y);
3642 litest_touch_up(dev, 0);
3643
3644 /* device is now on some x/y value */
3645 litest_drain_events(libinput1);
3646
3647 libinput2 = litest_create_context();
3648 libinput_path_add_device(libinput2,
3649 libevdev_uinput_get_devnode(dev->uinput));
3650 litest_drain_events(libinput2);
3651
3652 if (axis == ABS_X)
3653 x = 30;
3654 else
3655 y = 30;
3656 litest_touch_down(dev, 0, x, y);
3657 litest_touch_move_to(dev, 0, x, y, 70, 70, 10);
3658 litest_touch_up(dev, 0);
3659 libinput_dispatch(libinput1);
3660 libinput_dispatch(libinput2);
3661
3662 litest_wait_for_event(libinput1);
3663 litest_wait_for_event(libinput2);
3664
3665 while (libinput_next_event_type(libinput1)) {
3666 struct libinput_event *ev1, *ev2;
3667 struct libinput_event_pointer *p1, *p2;
3668
3669 ev1 = libinput_get_event(libinput1);
3670 ev2 = libinput_get_event(libinput2);
3671
3672 p1 = litest_is_motion_event(ev1);
3673 p2 = litest_is_motion_event(ev2);
3674
3675 ck_assert_int_eq(libinput_event_get_type(ev1),
3676 libinput_event_get_type(ev2));
3677
3678 ck_assert_int_eq(libinput_event_pointer_get_dx(p1),
3679 libinput_event_pointer_get_dx(p2));
3680 ck_assert_int_eq(libinput_event_pointer_get_dy(p1),
3681 libinput_event_pointer_get_dy(p2));
3682 libinput_event_destroy(ev1);
3683 libinput_event_destroy(ev2);
3684 }
3685
3686 litest_destroy_context(libinput2);
3687 }
3688 END_TEST
3689
START_TEST(touchpad_fingers_down_before_init)3690 START_TEST(touchpad_fingers_down_before_init)
3691 {
3692 struct litest_device *dev = litest_current_device();
3693 struct libinput *li;
3694
3695 int finger_count = _i; /* looped test */
3696 unsigned int map[] = {0, BTN_TOOL_PEN, BTN_TOOL_DOUBLETAP,
3697 BTN_TOOL_TRIPLETAP, BTN_TOOL_QUADTAP,
3698 BTN_TOOL_QUINTTAP};
3699
3700 if (!libevdev_has_event_code(dev->evdev, EV_KEY, map[finger_count]))
3701 return;
3702
3703 /* Fingers down but before we have the real context */
3704 for (int i = 0; i < finger_count; i++) {
3705 if (litest_slot_count(dev) >= finger_count) {
3706 litest_touch_down(dev, i, 20 + 10 * i, 30);
3707 } else {
3708 litest_event(dev, EV_KEY, map[finger_count], 1);
3709 }
3710 }
3711
3712 litest_drain_events(dev->libinput);
3713
3714 /* create anew context that already has the fingers down */
3715 li = litest_create_context();
3716 libinput_path_add_device(li,
3717 libevdev_uinput_get_devnode(dev->uinput));
3718 litest_drain_events(li);
3719
3720 for (int x = 0; x < 10; x++) {
3721 for (int i = 0; i < finger_count; i++) {
3722 if (litest_slot_count(dev) < finger_count)
3723 break;
3724 litest_touch_move(dev, i, 20 + 10 * i + x, 30);
3725 }
3726 }
3727 libinput_dispatch(li);
3728 litest_assert_empty_queue(li);
3729
3730 for (int i = 0; i < finger_count; i++) {
3731 if (litest_slot_count(dev) >= finger_count) {
3732 litest_touch_up(dev, i);
3733 } else {
3734 litest_event(dev, EV_KEY, map[finger_count], 0);
3735 }
3736 }
3737
3738 litest_assert_empty_queue(li);
3739
3740 litest_destroy_context(li);
3741 }
3742 END_TEST
3743
3744
3745 /* This just tests that we don't completely screw up in one specific case.
3746 * The test likely needs to be removed if it starts failing in the future.
3747 *
3748 * Where we get touch releases during SYN_DROPPED, libevdev < 1.9.0 gives us
3749 * wrong event sequence during sync, see
3750 * https://gitlab.freedesktop.org/libevdev/libevdev/merge_requests/19
3751 *
3752 * libinput 1.15.1 ended up dropping our slot count to 0, making the
3753 * touchpad unusable, see #422. This test just checks that we can still move
3754 * the pointer and scroll where we trigger such a sequence. This tests for
3755 * the worst-case scenario - where we previously reset to a slot count of 0.
3756 *
3757 * However, the exact behavior depends on how many slots were
3758 * stopped/restarted during SYN_DROPPED, a single test is barely useful.
3759 * libinput will still do the wrong thing if you start with e.g. 3fg on the
3760 * touchpad and release one or two of them. But since this needs to be fixed
3761 * in libevdev, here is the most important test.
3762 */
START_TEST(touchpad_state_after_syn_dropped_2fg_change)3763 START_TEST(touchpad_state_after_syn_dropped_2fg_change)
3764 {
3765 struct litest_device *dev = litest_current_device();
3766 struct libinput *li = dev->libinput;
3767
3768 litest_drain_events(li);
3769 litest_disable_tap(dev->libinput_device);
3770 litest_disable_hold_gestures(dev->libinput_device);
3771
3772 litest_touch_down(dev, 0, 10, 10);
3773 libinput_dispatch(li);
3774
3775 /* Force a SYN_DROPPED */
3776 for (int i = 0; i < 500; i++)
3777 litest_touch_move(dev, 0, 10 + 0.1 * i, 10 + 0.1 * i);
3778
3779 /* still within SYN_DROPPED */
3780 litest_touch_up(dev, 0);
3781 litest_touch_down(dev, 0, 50, 50);
3782 litest_touch_down(dev, 1, 70, 50);
3783
3784 libinput_dispatch(li);
3785 litest_drain_events(li);
3786
3787 litest_touch_up(dev, 0);
3788 litest_touch_up(dev, 1);
3789
3790 /* 2fg scrolling still works? */
3791 litest_touch_down(dev, 0, 50, 50);
3792 litest_touch_down(dev, 1, 70, 50);
3793 litest_touch_move_two_touches(dev, 50, 50, 70, 50, 0, -20, 10);
3794 litest_touch_up(dev, 0);
3795 litest_touch_up(dev, 1);
3796 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
3797
3798 /* pointer motion still works? */
3799 litest_touch_down(dev, 0, 50, 50);
3800 for (int i = 0; i < 10; i++)
3801 litest_touch_move(dev, 0, 10 + 0.1 * i, 10 + 0.1 * i);
3802 litest_touch_up(dev, 0);
3803 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3804 }
3805 END_TEST
3806
START_TEST(touchpad_dwt)3807 START_TEST(touchpad_dwt)
3808 {
3809 struct litest_device *touchpad = litest_current_device();
3810 struct litest_device *keyboard;
3811 struct libinput *li = touchpad->libinput;
3812
3813 if (!has_disable_while_typing(touchpad))
3814 return;
3815
3816 keyboard = dwt_init_paired_keyboard(li, touchpad);
3817 litest_disable_tap(touchpad->libinput_device);
3818 litest_disable_hold_gestures(touchpad->libinput_device);
3819 litest_drain_events(li);
3820
3821 litest_keyboard_key(keyboard, KEY_A, true);
3822 litest_keyboard_key(keyboard, KEY_A, false);
3823 libinput_dispatch(li);
3824 litest_touch_down(touchpad, 0, 50, 50);
3825 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
3826 litest_touch_up(touchpad, 0);
3827
3828 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
3829
3830 litest_timeout_dwt_short();
3831 libinput_dispatch(li);
3832
3833 /* after timeout - motion events*/
3834 litest_touch_down(touchpad, 0, 50, 50);
3835 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
3836 litest_touch_up(touchpad, 0);
3837
3838 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3839
3840 litest_delete_device(keyboard);
3841 }
3842 END_TEST
3843
START_TEST(touchpad_dwt_ext_and_int_keyboard)3844 START_TEST(touchpad_dwt_ext_and_int_keyboard)
3845 {
3846 struct litest_device *touchpad = litest_current_device();
3847 struct litest_device *keyboard, *yubikey;
3848 struct libinput *li = touchpad->libinput;
3849
3850 if (!has_disable_while_typing(touchpad))
3851 return;
3852
3853 litest_disable_tap(touchpad->libinput_device);
3854 litest_disable_hold_gestures(touchpad->libinput_device);
3855
3856 /* Yubikey is initialized first */
3857 yubikey = litest_add_device(li, LITEST_YUBIKEY);
3858 litest_drain_events(li);
3859
3860 keyboard = dwt_init_paired_keyboard(li, touchpad);
3861 litest_drain_events(li);
3862
3863 litest_keyboard_key(keyboard, KEY_A, true);
3864 litest_keyboard_key(keyboard, KEY_A, false);
3865 libinput_dispatch(li);
3866 litest_touch_down(touchpad, 0, 50, 50);
3867 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
3868 litest_touch_up(touchpad, 0);
3869
3870 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
3871
3872 litest_timeout_dwt_short();
3873 libinput_dispatch(li);
3874
3875 /* after timeout - motion events*/
3876 litest_touch_down(touchpad, 0, 50, 50);
3877 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
3878 litest_touch_up(touchpad, 0);
3879
3880 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3881
3882 litest_delete_device(keyboard);
3883 litest_delete_device(yubikey);
3884 }
3885 END_TEST
3886
START_TEST(touchpad_dwt_enable_touch)3887 START_TEST(touchpad_dwt_enable_touch)
3888 {
3889 struct litest_device *touchpad = litest_current_device();
3890 struct litest_device *keyboard;
3891 struct libinput *li = touchpad->libinput;
3892
3893 if (!has_disable_while_typing(touchpad))
3894 return;
3895
3896 keyboard = dwt_init_paired_keyboard(li, touchpad);
3897 litest_disable_tap(touchpad->libinput_device);
3898 litest_disable_hold_gestures(touchpad->libinput_device);
3899 litest_drain_events(li);
3900
3901 litest_keyboard_key(keyboard, KEY_A, true);
3902 litest_keyboard_key(keyboard, KEY_A, false);
3903 libinput_dispatch(li);
3904 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
3905
3906 /* finger down after last key event, but
3907 we're still within timeout - no events */
3908 msleep(10);
3909 litest_touch_down(touchpad, 0, 50, 50);
3910 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
3911 litest_assert_empty_queue(li);
3912
3913 litest_timeout_dwt_short();
3914 libinput_dispatch(li);
3915
3916 /* same touch after timeout - motion events*/
3917 litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 10);
3918 litest_touch_up(touchpad, 0);
3919
3920 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3921
3922 litest_delete_device(keyboard);
3923 }
3924 END_TEST
3925
START_TEST(touchpad_dwt_touch_hold)3926 START_TEST(touchpad_dwt_touch_hold)
3927 {
3928 struct litest_device *touchpad = litest_current_device();
3929 struct litest_device *keyboard;
3930 struct libinput *li = touchpad->libinput;
3931
3932 if (!has_disable_while_typing(touchpad))
3933 return;
3934
3935 keyboard = dwt_init_paired_keyboard(li, touchpad);
3936 litest_disable_tap(touchpad->libinput_device);
3937 litest_disable_hold_gestures(touchpad->libinput_device);
3938 litest_drain_events(li);
3939
3940 litest_keyboard_key(keyboard, KEY_A, true);
3941 msleep(1); /* make sure touch starts after key press */
3942 litest_touch_down(touchpad, 0, 50, 50);
3943 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
3944
3945 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
3946
3947 /* touch still down - no events */
3948 litest_keyboard_key(keyboard, KEY_A, false);
3949 libinput_dispatch(li);
3950 litest_touch_move_to(touchpad, 0, 70, 50, 30, 50, 5);
3951 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
3952
3953 /* touch still down - no events */
3954 litest_timeout_dwt_short();
3955 libinput_dispatch(li);
3956 litest_touch_move_to(touchpad, 0, 30, 50, 50, 50, 5);
3957 litest_touch_up(touchpad, 0);
3958 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
3959
3960 litest_delete_device(keyboard);
3961 }
3962 END_TEST
3963
START_TEST(touchpad_dwt_key_hold)3964 START_TEST(touchpad_dwt_key_hold)
3965 {
3966 struct litest_device *touchpad = litest_current_device();
3967 struct litest_device *keyboard;
3968 struct libinput *li = touchpad->libinput;
3969
3970 if (!has_disable_while_typing(touchpad))
3971 return;
3972
3973 keyboard = dwt_init_paired_keyboard(li, touchpad);
3974 litest_disable_tap(touchpad->libinput_device);
3975 litest_disable_hold_gestures(touchpad->libinput_device);
3976 litest_drain_events(li);
3977
3978 litest_keyboard_key(keyboard, KEY_A, true);
3979 libinput_dispatch(li);
3980 litest_touch_down(touchpad, 0, 50, 50);
3981 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
3982 litest_touch_up(touchpad, 0);
3983
3984 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
3985 litest_keyboard_key(keyboard, KEY_A, false);
3986 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
3987
3988 litest_delete_device(keyboard);
3989 }
3990 END_TEST
3991
START_TEST(touchpad_dwt_key_hold_timeout)3992 START_TEST(touchpad_dwt_key_hold_timeout)
3993 {
3994 struct litest_device *touchpad = litest_current_device();
3995 struct litest_device *keyboard;
3996 struct libinput *li = touchpad->libinput;
3997
3998 if (!has_disable_while_typing(touchpad))
3999 return;
4000
4001 keyboard = dwt_init_paired_keyboard(li, touchpad);
4002 litest_disable_tap(touchpad->libinput_device);
4003 litest_disable_hold_gestures(touchpad->libinput_device);
4004 litest_drain_events(li);
4005
4006 litest_keyboard_key(keyboard, KEY_A, true);
4007 libinput_dispatch(li);
4008 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4009 litest_timeout_dwt_long();
4010 libinput_dispatch(li);
4011 litest_touch_down(touchpad, 0, 50, 50);
4012 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4013 litest_touch_up(touchpad, 0);
4014
4015 litest_assert_empty_queue(li);
4016
4017 litest_keyboard_key(keyboard, KEY_A, false);
4018 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4019 /* key is up, but still within timeout */
4020 litest_touch_down(touchpad, 0, 50, 50);
4021 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4022 litest_touch_up(touchpad, 0);
4023 litest_assert_empty_queue(li);
4024
4025 /* expire timeout */
4026 litest_timeout_dwt_long();
4027 libinput_dispatch(li);
4028 litest_touch_down(touchpad, 0, 50, 50);
4029 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4030 litest_touch_up(touchpad, 0);
4031 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4032
4033 litest_delete_device(keyboard);
4034 }
4035 END_TEST
4036
START_TEST(touchpad_dwt_key_hold_timeout_existing_touch_cornercase)4037 START_TEST(touchpad_dwt_key_hold_timeout_existing_touch_cornercase)
4038 {
4039 struct litest_device *touchpad = litest_current_device();
4040 struct litest_device *keyboard;
4041 struct libinput *li = touchpad->libinput;
4042
4043 if (!has_disable_while_typing(touchpad))
4044 return;
4045
4046 /* Note: this tests for the current behavior of a cornercase, and
4047 * the behaviour is essentially a bug. If this test fails it may be
4048 * because the buggy behavior was fixed.
4049 */
4050
4051 keyboard = dwt_init_paired_keyboard(li, touchpad);
4052 litest_disable_tap(touchpad->libinput_device);
4053 litest_disable_hold_gestures(touchpad->libinput_device);
4054 litest_drain_events(li);
4055
4056 litest_keyboard_key(keyboard, KEY_A, true);
4057 libinput_dispatch(li);
4058 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4059 litest_timeout_dwt_long();
4060 libinput_dispatch(li);
4061
4062 /* Touch starting after re-issuing the dwt timeout */
4063 litest_touch_down(touchpad, 0, 50, 50);
4064 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4065
4066 litest_assert_empty_queue(li);
4067
4068 litest_keyboard_key(keyboard, KEY_A, false);
4069 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4070 /* key is up, but still within timeout */
4071 litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5);
4072 litest_assert_empty_queue(li);
4073
4074 /* Expire dwt timeout. Because the touch started after re-issuing
4075 * the last timeout, it looks like the touch started after the last
4076 * key press. Such touches are enabled for pointer motion by
4077 * libinput when dwt expires.
4078 * This is buggy behavior and not what a user would typically
4079 * expect. But it's hard to trigger in real life too.
4080 */
4081 litest_timeout_dwt_long();
4082 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4083 litest_touch_up(touchpad, 0);
4084 /* If the below check for motion event fails because no events are
4085 * in the pipe, the buggy behavior was fixed and this test case
4086 * can be removed */
4087 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4088
4089 litest_delete_device(keyboard);
4090 }
4091 END_TEST
4092
START_TEST(touchpad_dwt_key_hold_timeout_existing_touch)4093 START_TEST(touchpad_dwt_key_hold_timeout_existing_touch)
4094 {
4095 struct litest_device *touchpad = litest_current_device();
4096 struct litest_device *keyboard;
4097 struct libinput *li = touchpad->libinput;
4098
4099 if (!has_disable_while_typing(touchpad))
4100 return;
4101
4102 keyboard = dwt_init_paired_keyboard(li, touchpad);
4103 litest_disable_tap(touchpad->libinput_device);
4104 litest_disable_hold_gestures(touchpad->libinput_device);
4105 litest_drain_events(li);
4106
4107 litest_keyboard_key(keyboard, KEY_A, true);
4108 libinput_dispatch(li);
4109 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4110 litest_touch_down(touchpad, 0, 50, 50);
4111 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4112 libinput_dispatch(li);
4113 litest_timeout_dwt_long();
4114 libinput_dispatch(li);
4115
4116 litest_assert_empty_queue(li);
4117
4118 litest_keyboard_key(keyboard, KEY_A, false);
4119 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4120 /* key is up, but still within timeout */
4121 litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5);
4122 litest_assert_empty_queue(li);
4123
4124 /* expire timeout, but touch started before release */
4125 litest_timeout_dwt_long();
4126 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4127 litest_touch_up(touchpad, 0);
4128 litest_assert_empty_queue(li);
4129
4130 litest_delete_device(keyboard);
4131 }
4132 END_TEST
4133
START_TEST(touchpad_dwt_type)4134 START_TEST(touchpad_dwt_type)
4135 {
4136 struct litest_device *touchpad = litest_current_device();
4137 struct litest_device *keyboard;
4138 struct libinput *li = touchpad->libinput;
4139 int i;
4140
4141 if (!has_disable_while_typing(touchpad))
4142 return;
4143
4144 keyboard = dwt_init_paired_keyboard(li, touchpad);
4145 litest_disable_tap(touchpad->libinput_device);
4146 litest_disable_hold_gestures(touchpad->libinput_device);
4147 litest_drain_events(li);
4148
4149 for (i = 0; i < 5; i++) {
4150 litest_keyboard_key(keyboard, KEY_A, true);
4151 litest_keyboard_key(keyboard, KEY_A, false);
4152 libinput_dispatch(li);
4153 }
4154
4155 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4156
4157 litest_touch_down(touchpad, 0, 50, 50);
4158 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4159 litest_touch_up(touchpad, 0);
4160 litest_assert_empty_queue(li);
4161
4162 litest_timeout_dwt_long();
4163 libinput_dispatch(li);
4164 litest_touch_down(touchpad, 0, 50, 50);
4165 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4166 litest_touch_up(touchpad, 0);
4167 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4168
4169 litest_delete_device(keyboard);
4170 }
4171 END_TEST
4172
START_TEST(touchpad_dwt_type_short_timeout)4173 START_TEST(touchpad_dwt_type_short_timeout)
4174 {
4175 struct litest_device *touchpad = litest_current_device();
4176 struct litest_device *keyboard;
4177 struct libinput *li = touchpad->libinput;
4178 int i;
4179
4180 if (!has_disable_while_typing(touchpad))
4181 return;
4182
4183 keyboard = dwt_init_paired_keyboard(li, touchpad);
4184 litest_disable_tap(touchpad->libinput_device);
4185 litest_disable_hold_gestures(touchpad->libinput_device);
4186 litest_drain_events(li);
4187
4188 for (i = 0; i < 5; i++) {
4189 litest_keyboard_key(keyboard, KEY_A, true);
4190 litest_keyboard_key(keyboard, KEY_A, false);
4191 libinput_dispatch(li);
4192 }
4193
4194 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4195
4196 litest_touch_down(touchpad, 0, 50, 50);
4197 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4198 litest_touch_up(touchpad, 0);
4199 litest_assert_empty_queue(li);
4200
4201 litest_timeout_dwt_short();
4202 libinput_dispatch(li);
4203 litest_touch_down(touchpad, 0, 50, 50);
4204 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4205 litest_touch_up(touchpad, 0);
4206 litest_assert_empty_queue(li);
4207
4208 litest_delete_device(keyboard);
4209 }
4210 END_TEST
4211
START_TEST(touchpad_dwt_modifier_no_dwt)4212 START_TEST(touchpad_dwt_modifier_no_dwt)
4213 {
4214 struct litest_device *touchpad = litest_current_device();
4215 struct litest_device *keyboard;
4216 struct libinput *li = touchpad->libinput;
4217 unsigned int modifiers[] = {
4218 KEY_LEFTCTRL,
4219 KEY_RIGHTCTRL,
4220 KEY_LEFTALT,
4221 KEY_RIGHTALT,
4222 KEY_LEFTSHIFT,
4223 KEY_RIGHTSHIFT,
4224 KEY_FN,
4225 KEY_CAPSLOCK,
4226 KEY_TAB,
4227 KEY_COMPOSE,
4228 KEY_RIGHTMETA,
4229 KEY_LEFTMETA,
4230 KEY_ESC,
4231 KEY_KPASTERISK,
4232 KEY_F1,
4233 };
4234
4235 if (!has_disable_while_typing(touchpad))
4236 return;
4237
4238 keyboard = dwt_init_paired_keyboard(li, touchpad);
4239 litest_disable_tap(touchpad->libinput_device);
4240 litest_disable_hold_gestures(touchpad->libinput_device);
4241 litest_drain_events(li);
4242
4243 ARRAY_FOR_EACH(modifiers, key) {
4244 litest_keyboard_key(keyboard, *key, true);
4245 litest_keyboard_key(keyboard, *key, false);
4246 libinput_dispatch(li);
4247
4248 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4249
4250 litest_touch_down(touchpad, 0, 50, 50);
4251 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4252 litest_touch_up(touchpad, 0);
4253 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4254 }
4255
4256 litest_delete_device(keyboard);
4257 }
4258 END_TEST
4259
START_TEST(touchpad_dwt_modifier_combo_no_dwt)4260 START_TEST(touchpad_dwt_modifier_combo_no_dwt)
4261 {
4262 struct litest_device *touchpad = litest_current_device();
4263 struct litest_device *keyboard;
4264 struct libinput *li = touchpad->libinput;
4265 unsigned int modifiers[] = {
4266 KEY_LEFTCTRL,
4267 KEY_RIGHTCTRL,
4268 KEY_LEFTALT,
4269 KEY_RIGHTALT,
4270 KEY_LEFTSHIFT,
4271 KEY_RIGHTSHIFT,
4272 KEY_FN,
4273 KEY_CAPSLOCK,
4274 KEY_TAB,
4275 KEY_COMPOSE,
4276 KEY_RIGHTMETA,
4277 KEY_LEFTMETA,
4278 };
4279
4280 if (!has_disable_while_typing(touchpad))
4281 return;
4282
4283 keyboard = dwt_init_paired_keyboard(li, touchpad);
4284 litest_disable_tap(touchpad->libinput_device);
4285 litest_disable_hold_gestures(touchpad->libinput_device);
4286 litest_drain_events(li);
4287
4288 ARRAY_FOR_EACH(modifiers, key) {
4289 litest_keyboard_key(keyboard, *key, true);
4290 litest_keyboard_key(keyboard, KEY_A, true);
4291 litest_keyboard_key(keyboard, KEY_A, false);
4292 litest_keyboard_key(keyboard, KEY_B, true);
4293 litest_keyboard_key(keyboard, KEY_B, false);
4294 litest_keyboard_key(keyboard, *key, false);
4295 libinput_dispatch(li);
4296
4297 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4298
4299 litest_touch_down(touchpad, 0, 50, 50);
4300 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4301 litest_touch_up(touchpad, 0);
4302 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4303 }
4304
4305 litest_delete_device(keyboard);
4306 }
4307 END_TEST
4308
START_TEST(touchpad_dwt_modifier_combo_dwt_after)4309 START_TEST(touchpad_dwt_modifier_combo_dwt_after)
4310 {
4311 struct litest_device *touchpad = litest_current_device();
4312 struct litest_device *keyboard;
4313 struct libinput *li = touchpad->libinput;
4314 unsigned int modifiers[] = {
4315 KEY_LEFTCTRL,
4316 KEY_RIGHTCTRL,
4317 KEY_LEFTALT,
4318 KEY_RIGHTALT,
4319 KEY_LEFTSHIFT,
4320 KEY_RIGHTSHIFT,
4321 KEY_FN,
4322 KEY_CAPSLOCK,
4323 KEY_TAB,
4324 KEY_COMPOSE,
4325 KEY_RIGHTMETA,
4326 KEY_LEFTMETA,
4327 };
4328
4329 if (!has_disable_while_typing(touchpad))
4330 return;
4331
4332 keyboard = dwt_init_paired_keyboard(li, touchpad);
4333 litest_disable_tap(touchpad->libinput_device);
4334 litest_disable_hold_gestures(touchpad->libinput_device);
4335 litest_drain_events(li);
4336
4337 ARRAY_FOR_EACH(modifiers, key) {
4338 litest_keyboard_key(keyboard, *key, true);
4339 litest_keyboard_key(keyboard, KEY_A, true);
4340 litest_keyboard_key(keyboard, KEY_A, false);
4341 litest_keyboard_key(keyboard, *key, false);
4342 libinput_dispatch(li);
4343
4344 litest_keyboard_key(keyboard, KEY_A, true);
4345 litest_keyboard_key(keyboard, KEY_A, false);
4346 libinput_dispatch(li);
4347 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4348
4349 litest_touch_down(touchpad, 0, 50, 50);
4350 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4351 litest_touch_up(touchpad, 0);
4352 litest_assert_empty_queue(li);
4353
4354 litest_timeout_dwt_long();
4355 libinput_dispatch(li);
4356 }
4357
4358 litest_delete_device(keyboard);
4359 }
4360 END_TEST
4361
START_TEST(touchpad_dwt_modifier_combo_dwt_remains)4362 START_TEST(touchpad_dwt_modifier_combo_dwt_remains)
4363 {
4364 struct litest_device *touchpad = litest_current_device();
4365 struct litest_device *keyboard;
4366 struct libinput *li = touchpad->libinput;
4367 unsigned int modifiers[] = {
4368 KEY_LEFTCTRL,
4369 KEY_RIGHTCTRL,
4370 KEY_LEFTALT,
4371 KEY_RIGHTALT,
4372 KEY_LEFTSHIFT,
4373 KEY_RIGHTSHIFT,
4374 KEY_FN,
4375 KEY_CAPSLOCK,
4376 KEY_TAB,
4377 KEY_COMPOSE,
4378 KEY_RIGHTMETA,
4379 KEY_LEFTMETA,
4380 };
4381
4382 if (!has_disable_while_typing(touchpad))
4383 return;
4384
4385 keyboard = dwt_init_paired_keyboard(li, touchpad);
4386 litest_disable_tap(touchpad->libinput_device);
4387 litest_disable_hold_gestures(touchpad->libinput_device);
4388 litest_drain_events(li);
4389
4390 ARRAY_FOR_EACH(modifiers, key) {
4391 litest_keyboard_key(keyboard, KEY_A, true);
4392 litest_keyboard_key(keyboard, KEY_A, false);
4393 libinput_dispatch(li);
4394
4395 /* this can't really be tested directly. The above key
4396 * should enable dwt, the next key continues and extends the
4397 * timeout as usual (despite the modifier combo). but
4398 * testing for timeout differences is fickle, so all we can
4399 * test though is that dwt is still on after the modifier
4400 * combo and does not get disabled immediately.
4401 */
4402 litest_keyboard_key(keyboard, *key, true);
4403 litest_keyboard_key(keyboard, KEY_A, true);
4404 litest_keyboard_key(keyboard, KEY_A, false);
4405 litest_keyboard_key(keyboard, *key, false);
4406 libinput_dispatch(li);
4407
4408 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4409
4410 litest_touch_down(touchpad, 0, 50, 50);
4411 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4412 litest_touch_up(touchpad, 0);
4413 litest_assert_empty_queue(li);
4414
4415 litest_timeout_dwt_long();
4416 libinput_dispatch(li);
4417 }
4418
4419 litest_delete_device(keyboard);
4420 }
4421 END_TEST
4422
START_TEST(touchpad_dwt_fkeys_no_dwt)4423 START_TEST(touchpad_dwt_fkeys_no_dwt)
4424 {
4425 struct litest_device *touchpad = litest_current_device();
4426 struct litest_device *keyboard;
4427 struct libinput *li = touchpad->libinput;
4428 unsigned int key;
4429
4430 if (!has_disable_while_typing(touchpad))
4431 return;
4432
4433 keyboard = dwt_init_paired_keyboard(li, touchpad);
4434 litest_disable_tap(touchpad->libinput_device);
4435 litest_disable_hold_gestures(touchpad->libinput_device);
4436 litest_drain_events(li);
4437
4438 for (key = KEY_F1; key < KEY_CNT; key++) {
4439 if (!libinput_device_keyboard_has_key(keyboard->libinput_device,
4440 key))
4441 continue;
4442
4443 litest_keyboard_key(keyboard, key, true);
4444 litest_keyboard_key(keyboard, key, false);
4445 libinput_dispatch(li);
4446
4447 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4448
4449 litest_touch_down(touchpad, 0, 50, 50);
4450 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4451 litest_touch_up(touchpad, 0);
4452 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4453 }
4454
4455 litest_delete_device(keyboard);
4456 }
4457 END_TEST
4458
START_TEST(touchpad_dwt_tap)4459 START_TEST(touchpad_dwt_tap)
4460 {
4461 struct litest_device *touchpad = litest_current_device();
4462 struct litest_device *keyboard;
4463 struct libinput *li = touchpad->libinput;
4464
4465 if (!has_disable_while_typing(touchpad))
4466 return;
4467
4468 keyboard = dwt_init_paired_keyboard(li, touchpad);
4469 litest_enable_tap(touchpad->libinput_device);
4470 litest_disable_hold_gestures(touchpad->libinput_device);
4471 litest_drain_events(li);
4472
4473 litest_keyboard_key(keyboard, KEY_A, true);
4474 libinput_dispatch(li);
4475 litest_touch_down(touchpad, 0, 50, 50);
4476 litest_touch_up(touchpad, 0);
4477
4478 litest_keyboard_key(keyboard, KEY_A, false);
4479 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4480
4481 litest_timeout_dwt_short();
4482 litest_touch_down(touchpad, 0, 50, 50);
4483 litest_touch_up(touchpad, 0);
4484 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
4485
4486 litest_delete_device(keyboard);
4487 }
4488 END_TEST
4489
START_TEST(touchpad_dwt_tap_drag)4490 START_TEST(touchpad_dwt_tap_drag)
4491 {
4492 struct litest_device *touchpad = litest_current_device();
4493 struct litest_device *keyboard;
4494 struct libinput *li = touchpad->libinput;
4495
4496 if (!has_disable_while_typing(touchpad))
4497 return;
4498
4499 keyboard = dwt_init_paired_keyboard(li, touchpad);
4500 litest_enable_tap(touchpad->libinput_device);
4501 litest_disable_hold_gestures(touchpad->libinput_device);
4502 litest_drain_events(li);
4503
4504 litest_keyboard_key(keyboard, KEY_A, true);
4505 libinput_dispatch(li);
4506 msleep(1); /* make sure touch starts after key press */
4507 litest_touch_down(touchpad, 0, 50, 50);
4508 litest_touch_up(touchpad, 0);
4509 litest_touch_down(touchpad, 0, 50, 50);
4510 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
4511
4512 litest_keyboard_key(keyboard, KEY_A, false);
4513 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4514
4515 litest_timeout_dwt_short();
4516 libinput_dispatch(li);
4517 litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5);
4518 litest_touch_up(touchpad, 0);
4519 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4520
4521 litest_delete_device(keyboard);
4522 }
4523 END_TEST
4524
START_TEST(touchpad_dwt_click)4525 START_TEST(touchpad_dwt_click)
4526 {
4527 struct litest_device *touchpad = litest_current_device();
4528 struct litest_device *keyboard;
4529 struct libinput *li = touchpad->libinput;
4530
4531 if (!has_disable_while_typing(touchpad))
4532 return;
4533
4534 keyboard = dwt_init_paired_keyboard(li, touchpad);
4535 litest_disable_tap(touchpad->libinput_device);
4536 litest_disable_hold_gestures(touchpad->libinput_device);
4537 litest_drain_events(li);
4538
4539 litest_keyboard_key(keyboard, KEY_A, true);
4540 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4541
4542 litest_touch_down(touchpad, 0, 50, 50);
4543 litest_button_click(touchpad, BTN_LEFT, true);
4544 litest_button_click(touchpad, BTN_LEFT, false);
4545 libinput_dispatch(li);
4546 litest_touch_up(touchpad, 0);
4547 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
4548
4549 litest_keyboard_key(keyboard, KEY_A, false);
4550
4551 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4552
4553 litest_delete_device(keyboard);
4554 }
4555 END_TEST
4556
START_TEST(touchpad_dwt_edge_scroll)4557 START_TEST(touchpad_dwt_edge_scroll)
4558 {
4559 struct litest_device *touchpad = litest_current_device();
4560 struct litest_device *keyboard;
4561 struct libinput *li = touchpad->libinput;
4562
4563 if (!has_disable_while_typing(touchpad))
4564 return;
4565
4566 litest_enable_edge_scroll(touchpad);
4567
4568 keyboard = dwt_init_paired_keyboard(li, touchpad);
4569 litest_drain_events(li);
4570
4571 litest_keyboard_key(keyboard, KEY_A, true);
4572 litest_keyboard_key(keyboard, KEY_A, false);
4573 litest_keyboard_key(keyboard, KEY_A, true);
4574 litest_keyboard_key(keyboard, KEY_A, false);
4575 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4576
4577 litest_touch_down(touchpad, 0, 99, 20);
4578 libinput_dispatch(li);
4579 litest_timeout_edgescroll();
4580 libinput_dispatch(li);
4581 litest_assert_empty_queue(li);
4582
4583 /* edge scroll timeout is 300ms atm, make sure we don't accidentally
4584 exit the DWT timeout */
4585 litest_keyboard_key(keyboard, KEY_A, true);
4586 litest_keyboard_key(keyboard, KEY_A, false);
4587 libinput_dispatch(li);
4588 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4589
4590 litest_touch_move_to(touchpad, 0, 99, 20, 99, 80, 60);
4591 libinput_dispatch(li);
4592 litest_assert_empty_queue(li);
4593
4594 litest_touch_move_to(touchpad, 0, 99, 80, 99, 20, 60);
4595 litest_touch_up(touchpad, 0);
4596 libinput_dispatch(li);
4597 litest_assert_empty_queue(li);
4598
4599 litest_delete_device(keyboard);
4600 }
4601 END_TEST
4602
START_TEST(touchpad_dwt_edge_scroll_interrupt)4603 START_TEST(touchpad_dwt_edge_scroll_interrupt)
4604 {
4605 struct litest_device *touchpad = litest_current_device();
4606 struct litest_device *keyboard;
4607 struct libinput *li = touchpad->libinput;
4608
4609 if (!has_disable_while_typing(touchpad))
4610 return;
4611
4612 litest_enable_edge_scroll(touchpad);
4613
4614 keyboard = dwt_init_paired_keyboard(li, touchpad);
4615 litest_drain_events(li);
4616
4617 litest_touch_down(touchpad, 0, 99, 20);
4618 libinput_dispatch(li);
4619 litest_timeout_edgescroll();
4620 litest_touch_move_to(touchpad, 0, 99, 20, 99, 30, 10);
4621 libinput_dispatch(li);
4622 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
4623
4624 litest_keyboard_key(keyboard, KEY_A, true);
4625 litest_keyboard_key(keyboard, KEY_A, false);
4626 litest_keyboard_key(keyboard, KEY_A, true);
4627 litest_keyboard_key(keyboard, KEY_A, false);
4628
4629 /* scroll stop events (low and high resolution) */
4630 litest_wait_for_event(li);
4631 litest_assert_axis_end_sequence(li,
4632 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
4633 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
4634 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
4635
4636 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4637
4638 litest_timeout_dwt_long();
4639
4640 /* Known bad behavior: a touch starting to edge-scroll before dwt
4641 * kicks in will stop to scroll but be recognized as normal
4642 * pointer-moving touch once the timeout expires. We'll fix that
4643 * when we need to.
4644 */
4645 litest_touch_move_to(touchpad, 0, 99, 30, 99, 80, 10);
4646 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4647
4648 litest_delete_device(keyboard);
4649 }
4650 END_TEST
4651
START_TEST(touchpad_dwt_config_default_on)4652 START_TEST(touchpad_dwt_config_default_on)
4653 {
4654 struct litest_device *dev = litest_current_device();
4655 struct libinput_device *device = dev->libinput_device;
4656 enum libinput_config_status status;
4657 enum libinput_config_dwt_state state;
4658
4659 if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM ||
4660 libevdev_get_id_bustype(dev->evdev) == BUS_BLUETOOTH) {
4661 ck_assert(!libinput_device_config_dwt_is_available(device));
4662 return;
4663 }
4664
4665 ck_assert(libinput_device_config_dwt_is_available(device));
4666 state = libinput_device_config_dwt_get_enabled(device);
4667 ck_assert_int_eq(state, LIBINPUT_CONFIG_DWT_ENABLED);
4668 state = libinput_device_config_dwt_get_default_enabled(device);
4669 ck_assert_int_eq(state, LIBINPUT_CONFIG_DWT_ENABLED);
4670
4671 status = libinput_device_config_dwt_set_enabled(device,
4672 LIBINPUT_CONFIG_DWT_ENABLED);
4673 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
4674 status = libinput_device_config_dwt_set_enabled(device,
4675 LIBINPUT_CONFIG_DWT_DISABLED);
4676 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
4677
4678 status = libinput_device_config_dwt_set_enabled(device, 3);
4679 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID);
4680 }
4681 END_TEST
4682
START_TEST(touchpad_dwtp_config_default_on)4683 START_TEST(touchpad_dwtp_config_default_on)
4684 {
4685 struct litest_device *dev = litest_current_device();
4686 struct libinput_device *device = dev->libinput_device;
4687 enum libinput_config_status status;
4688 enum libinput_config_dwtp_state state;
4689
4690 if (litest_touchpad_is_external(dev)) {
4691 ck_assert(!libinput_device_config_dwtp_is_available(device));
4692 return;
4693 }
4694
4695 ck_assert(libinput_device_config_dwtp_is_available(device));
4696 state = libinput_device_config_dwtp_get_enabled(device);
4697 ck_assert_int_eq(state, LIBINPUT_CONFIG_DWTP_ENABLED);
4698 state = libinput_device_config_dwtp_get_default_enabled(device);
4699 ck_assert_int_eq(state, LIBINPUT_CONFIG_DWTP_ENABLED);
4700
4701 status = libinput_device_config_dwtp_set_enabled(device,
4702 LIBINPUT_CONFIG_DWTP_ENABLED);
4703 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
4704 status = libinput_device_config_dwtp_set_enabled(device,
4705 LIBINPUT_CONFIG_DWTP_DISABLED);
4706 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
4707
4708 status = libinput_device_config_dwtp_set_enabled(device, 3);
4709 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID);
4710 }
4711 END_TEST
4712
START_TEST(touchpad_dwt_config_default_off)4713 START_TEST(touchpad_dwt_config_default_off)
4714 {
4715 struct litest_device *dev = litest_current_device();
4716 struct libinput_device *device = dev->libinput_device;
4717 enum libinput_config_status status;
4718 enum libinput_config_dwt_state state;
4719
4720 ck_assert(!libinput_device_config_dwt_is_available(device));
4721 state = libinput_device_config_dwt_get_enabled(device);
4722 ck_assert_int_eq(state, LIBINPUT_CONFIG_DWT_DISABLED);
4723 state = libinput_device_config_dwt_get_default_enabled(device);
4724 ck_assert_int_eq(state, LIBINPUT_CONFIG_DWT_DISABLED);
4725
4726 status = libinput_device_config_dwt_set_enabled(device,
4727 LIBINPUT_CONFIG_DWT_ENABLED);
4728 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
4729 status = libinput_device_config_dwt_set_enabled(device,
4730 LIBINPUT_CONFIG_DWT_DISABLED);
4731 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
4732
4733 status = libinput_device_config_dwt_set_enabled(device, 3);
4734 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID);
4735 }
4736 END_TEST
4737
START_TEST(touchpad_dwtp_config_default_off)4738 START_TEST(touchpad_dwtp_config_default_off)
4739 {
4740 struct litest_device *dev = litest_current_device();
4741 struct libinput_device *device = dev->libinput_device;
4742 enum libinput_config_status status;
4743 enum libinput_config_dwtp_state state;
4744
4745 ck_assert(!libinput_device_config_dwtp_is_available(device));
4746 state = libinput_device_config_dwtp_get_enabled(device);
4747 ck_assert_int_eq(state, LIBINPUT_CONFIG_DWTP_DISABLED);
4748 state = libinput_device_config_dwtp_get_default_enabled(device);
4749 ck_assert_int_eq(state, LIBINPUT_CONFIG_DWTP_DISABLED);
4750
4751 status = libinput_device_config_dwtp_set_enabled(device,
4752 LIBINPUT_CONFIG_DWTP_ENABLED);
4753 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
4754 status = libinput_device_config_dwtp_set_enabled(device,
4755 LIBINPUT_CONFIG_DWTP_DISABLED);
4756 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
4757
4758 status = libinput_device_config_dwtp_set_enabled(device, 3);
4759 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID);
4760 }
4761 END_TEST
4762
4763 static inline void
disable_dwt(struct litest_device * dev)4764 disable_dwt(struct litest_device *dev)
4765 {
4766 enum libinput_config_status status,
4767 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
4768 status = libinput_device_config_dwt_set_enabled(dev->libinput_device,
4769 LIBINPUT_CONFIG_DWT_DISABLED);
4770 litest_assert_int_eq(status, expected);
4771 }
4772
4773 static inline void
enable_dwt(struct litest_device * dev)4774 enable_dwt(struct litest_device *dev)
4775 {
4776 enum libinput_config_status status,
4777 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
4778 status = libinput_device_config_dwt_set_enabled(dev->libinput_device,
4779 LIBINPUT_CONFIG_DWT_ENABLED);
4780 litest_assert_int_eq(status, expected);
4781 }
4782
START_TEST(touchpad_dwt_disabled)4783 START_TEST(touchpad_dwt_disabled)
4784 {
4785 struct litest_device *touchpad = litest_current_device();
4786 struct litest_device *keyboard;
4787 struct libinput *li = touchpad->libinput;
4788
4789 if (!has_disable_while_typing(touchpad))
4790 return;
4791
4792 disable_dwt(touchpad);
4793
4794 keyboard = dwt_init_paired_keyboard(li, touchpad);
4795 litest_disable_tap(touchpad->libinput_device);
4796 litest_disable_hold_gestures(touchpad->libinput_device);
4797 litest_drain_events(li);
4798
4799 litest_keyboard_key(keyboard, KEY_A, true);
4800 litest_keyboard_key(keyboard, KEY_A, false);
4801 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4802
4803 litest_touch_down(touchpad, 0, 50, 50);
4804 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
4805 litest_touch_up(touchpad, 0);
4806
4807 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4808
4809 litest_delete_device(keyboard);
4810 }
4811 END_TEST
4812
START_TEST(touchpad_dwt_disable_during_touch)4813 START_TEST(touchpad_dwt_disable_during_touch)
4814 {
4815 struct litest_device *touchpad = litest_current_device();
4816 struct litest_device *keyboard;
4817 struct libinput *li = touchpad->libinput;
4818
4819 if (!has_disable_while_typing(touchpad))
4820 return;
4821
4822 enable_dwt(touchpad);
4823
4824 keyboard = dwt_init_paired_keyboard(li, touchpad);
4825 litest_disable_tap(touchpad->libinput_device);
4826 litest_disable_hold_gestures(touchpad->libinput_device);
4827 litest_drain_events(li);
4828
4829 litest_keyboard_key(keyboard, KEY_A, true);
4830 litest_keyboard_key(keyboard, KEY_A, false);
4831
4832 litest_touch_down(touchpad, 0, 50, 50);
4833
4834 litest_keyboard_key(keyboard, KEY_A, true);
4835 litest_keyboard_key(keyboard, KEY_A, false);
4836 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4837
4838 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
4839 litest_assert_empty_queue(li);
4840
4841 litest_timeout_dwt_long();
4842 libinput_dispatch(li);
4843
4844 disable_dwt(touchpad);
4845
4846 /* touch already down -> keeps being ignored */
4847 litest_touch_move_to(touchpad, 0, 70, 50, 50, 70, 10);
4848 litest_touch_up(touchpad, 0);
4849
4850 litest_assert_empty_queue(li);
4851
4852 litest_delete_device(keyboard);
4853 }
4854 END_TEST
4855
START_TEST(touchpad_dwt_disable_before_touch)4856 START_TEST(touchpad_dwt_disable_before_touch)
4857 {
4858 struct litest_device *touchpad = litest_current_device();
4859 struct litest_device *keyboard;
4860 struct libinput *li = touchpad->libinput;
4861
4862 if (!has_disable_while_typing(touchpad))
4863 return;
4864
4865 enable_dwt(touchpad);
4866
4867 keyboard = dwt_init_paired_keyboard(li, touchpad);
4868 litest_disable_tap(touchpad->libinput_device);
4869 litest_disable_hold_gestures(touchpad->libinput_device);
4870 litest_drain_events(li);
4871
4872 litest_keyboard_key(keyboard, KEY_A, true);
4873 litest_keyboard_key(keyboard, KEY_A, false);
4874 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4875
4876 disable_dwt(touchpad);
4877 libinput_dispatch(li);
4878
4879 /* touch down during timeout -> still discarded */
4880 litest_touch_down(touchpad, 0, 50, 50);
4881 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
4882 litest_assert_empty_queue(li);
4883
4884 litest_delete_device(keyboard);
4885 }
4886 END_TEST
4887
START_TEST(touchpad_dwt_disable_during_key_release)4888 START_TEST(touchpad_dwt_disable_during_key_release)
4889 {
4890 struct litest_device *touchpad = litest_current_device();
4891 struct litest_device *keyboard;
4892 struct libinput *li = touchpad->libinput;
4893
4894 if (!has_disable_while_typing(touchpad))
4895 return;
4896
4897 enable_dwt(touchpad);
4898
4899 keyboard = dwt_init_paired_keyboard(li, touchpad);
4900 litest_disable_tap(touchpad->libinput_device);
4901 litest_disable_hold_gestures(touchpad->libinput_device);
4902 litest_drain_events(li);
4903
4904 litest_keyboard_key(keyboard, KEY_A, true);
4905 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4906
4907 disable_dwt(touchpad);
4908 libinput_dispatch(li);
4909 litest_keyboard_key(keyboard, KEY_A, false);
4910 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4911
4912 /* touch down during timeout, wait, should generate events */
4913 litest_touch_down(touchpad, 0, 50, 50);
4914 libinput_dispatch(li);
4915 litest_timeout_dwt_long();
4916 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
4917 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4918
4919 litest_delete_device(keyboard);
4920 }
4921 END_TEST
4922
START_TEST(touchpad_dwt_disable_during_key_hold)4923 START_TEST(touchpad_dwt_disable_during_key_hold)
4924 {
4925 struct litest_device *touchpad = litest_current_device();
4926 struct litest_device *keyboard;
4927 struct libinput *li = touchpad->libinput;
4928
4929 if (!has_disable_while_typing(touchpad))
4930 return;
4931
4932 enable_dwt(touchpad);
4933
4934 keyboard = dwt_init_paired_keyboard(li, touchpad);
4935 litest_disable_tap(touchpad->libinput_device);
4936 litest_disable_hold_gestures(touchpad->libinput_device);
4937 litest_drain_events(li);
4938
4939 litest_keyboard_key(keyboard, KEY_A, true);
4940 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4941
4942 disable_dwt(touchpad);
4943 libinput_dispatch(li);
4944
4945 /* touch down during timeout, wait, should generate events */
4946 litest_touch_down(touchpad, 0, 50, 50);
4947 libinput_dispatch(li);
4948 litest_timeout_dwt_long();
4949 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
4950 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4951
4952 litest_delete_device(keyboard);
4953 }
4954 END_TEST
4955
START_TEST(touchpad_dwt_enable_during_touch)4956 START_TEST(touchpad_dwt_enable_during_touch)
4957 {
4958 struct litest_device *touchpad = litest_current_device();
4959 struct litest_device *keyboard;
4960 struct libinput *li = touchpad->libinput;
4961
4962 if (!has_disable_while_typing(touchpad))
4963 return;
4964
4965 disable_dwt(touchpad);
4966
4967 keyboard = dwt_init_paired_keyboard(li, touchpad);
4968 litest_disable_tap(touchpad->libinput_device);
4969 litest_disable_hold_gestures(touchpad->libinput_device);
4970 litest_drain_events(li);
4971
4972 litest_keyboard_key(keyboard, KEY_A, true);
4973 litest_keyboard_key(keyboard, KEY_A, false);
4974 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
4975
4976 litest_touch_down(touchpad, 0, 50, 50);
4977 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
4978 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4979
4980 enable_dwt(touchpad);
4981
4982 /* touch already down -> still sends events */
4983 litest_touch_move_to(touchpad, 0, 70, 50, 50, 70, 10);
4984 litest_touch_up(touchpad, 0);
4985 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
4986
4987 litest_delete_device(keyboard);
4988 }
4989 END_TEST
4990
START_TEST(touchpad_dwt_enable_before_touch)4991 START_TEST(touchpad_dwt_enable_before_touch)
4992 {
4993 struct litest_device *touchpad = litest_current_device();
4994 struct litest_device *keyboard;
4995 struct libinput *li = touchpad->libinput;
4996
4997 if (!has_disable_while_typing(touchpad))
4998 return;
4999
5000 disable_dwt(touchpad);
5001
5002 keyboard = dwt_init_paired_keyboard(li, touchpad);
5003 litest_disable_tap(touchpad->libinput_device);
5004 litest_disable_hold_gestures(touchpad->libinput_device);
5005 litest_drain_events(li);
5006
5007 litest_keyboard_key(keyboard, KEY_A, true);
5008 litest_keyboard_key(keyboard, KEY_A, false);
5009 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
5010
5011 enable_dwt(touchpad);
5012 libinput_dispatch(li);
5013
5014 litest_touch_down(touchpad, 0, 50, 50);
5015 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5016 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
5017
5018 litest_delete_device(keyboard);
5019 }
5020 END_TEST
5021
START_TEST(touchpad_dwt_enable_during_tap)5022 START_TEST(touchpad_dwt_enable_during_tap)
5023 {
5024 struct litest_device *touchpad = litest_current_device();
5025 struct litest_device *keyboard;
5026 struct libinput *li = touchpad->libinput;
5027
5028 if (!has_disable_while_typing(touchpad))
5029 return;
5030
5031 litest_enable_tap(touchpad->libinput_device);
5032 disable_dwt(touchpad);
5033 litest_disable_hold_gestures(touchpad->libinput_device);
5034
5035 keyboard = dwt_init_paired_keyboard(li, touchpad);
5036 litest_drain_events(li);
5037
5038 litest_keyboard_key(keyboard, KEY_A, true);
5039 litest_keyboard_key(keyboard, KEY_A, false);
5040 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
5041
5042 litest_touch_down(touchpad, 0, 50, 50);
5043 libinput_dispatch(li);
5044 enable_dwt(touchpad);
5045 libinput_dispatch(li);
5046 litest_touch_up(touchpad, 0);
5047 libinput_dispatch(li);
5048
5049 litest_timeout_tap();
5050 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
5051
5052 litest_touch_down(touchpad, 0, 50, 50);
5053 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5054 litest_touch_up(touchpad, 0);
5055 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
5056
5057 litest_delete_device(keyboard);
5058 }
5059 END_TEST
5060
START_TEST(touchpad_dwt_remove_kbd_while_active)5061 START_TEST(touchpad_dwt_remove_kbd_while_active)
5062 {
5063 struct litest_device *touchpad = litest_current_device();
5064 struct litest_device *keyboard;
5065 struct libinput *li = touchpad->libinput;
5066
5067 if (!has_disable_while_typing(touchpad))
5068 return;
5069
5070 litest_enable_tap(touchpad->libinput_device);
5071 enable_dwt(touchpad);
5072 litest_disable_hold_gestures(touchpad->libinput_device);
5073
5074 keyboard = dwt_init_paired_keyboard(li, touchpad);
5075 litest_drain_events(li);
5076
5077 litest_keyboard_key(keyboard, KEY_A, true);
5078 litest_keyboard_key(keyboard, KEY_A, false);
5079 libinput_dispatch(li);
5080
5081 litest_touch_down(touchpad, 0, 50, 50);
5082 libinput_dispatch(li);
5083
5084 litest_keyboard_key(keyboard, KEY_A, true);
5085 litest_keyboard_key(keyboard, KEY_A, false);
5086 litest_drain_events(li);
5087
5088 litest_delete_device(keyboard);
5089 litest_drain_events(li);
5090
5091 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5092 litest_touch_up(touchpad, 0);
5093 litest_assert_empty_queue(li);
5094
5095 litest_touch_down(touchpad, 0, 50, 50);
5096 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5097 litest_touch_up(touchpad, 0);
5098 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
5099
5100 }
5101 END_TEST
5102
START_TEST(touchpad_dwt_apple)5103 START_TEST(touchpad_dwt_apple)
5104 {
5105 struct litest_device *touchpad = litest_current_device();
5106 struct litest_device *apple_keyboard;
5107 struct libinput *li = touchpad->libinput;
5108
5109 ck_assert(has_disable_while_typing(touchpad));
5110
5111 apple_keyboard = litest_add_device(li, LITEST_APPLE_KEYBOARD);
5112 litest_drain_events(li);
5113
5114 litest_keyboard_key(apple_keyboard, KEY_A, true);
5115 litest_keyboard_key(apple_keyboard, KEY_A, false);
5116 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
5117
5118 litest_touch_down(touchpad, 0, 50, 50);
5119 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5120 litest_touch_up(touchpad, 0);
5121 libinput_dispatch(li);
5122 litest_assert_empty_queue(li);
5123
5124 litest_delete_device(apple_keyboard);
5125 }
5126 END_TEST
5127
START_TEST(touchpad_dwt_acer_hawaii)5128 START_TEST(touchpad_dwt_acer_hawaii)
5129 {
5130 struct litest_device *touchpad = litest_current_device();
5131 struct litest_device *keyboard, *hawaii_keyboard;
5132 struct libinput *li = touchpad->libinput;
5133
5134 ck_assert(has_disable_while_typing(touchpad));
5135
5136 /* Only the hawaii keyboard can trigger DWT */
5137 keyboard = litest_add_device(li, LITEST_KEYBOARD);
5138 litest_drain_events(li);
5139
5140 litest_keyboard_key(keyboard, KEY_A, true);
5141 litest_keyboard_key(keyboard, KEY_A, false);
5142 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
5143
5144 litest_touch_down(touchpad, 0, 50, 50);
5145 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5146 litest_touch_up(touchpad, 0);
5147 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
5148
5149 hawaii_keyboard = litest_add_device(li, LITEST_ACER_HAWAII_KEYBOARD);
5150 litest_drain_events(li);
5151
5152 litest_keyboard_key(hawaii_keyboard, KEY_A, true);
5153 litest_keyboard_key(hawaii_keyboard, KEY_A, false);
5154 litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
5155
5156 litest_touch_down(touchpad, 0, 50, 50);
5157 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5158 litest_touch_up(touchpad, 0);
5159 libinput_dispatch(li);
5160 litest_assert_empty_queue(li);
5161
5162 litest_delete_device(keyboard);
5163 litest_delete_device(hawaii_keyboard);
5164 }
5165 END_TEST
5166
START_TEST(touchpad_dwt_multiple_keyboards)5167 START_TEST(touchpad_dwt_multiple_keyboards)
5168 {
5169 struct litest_device *touchpad = litest_current_device();
5170 struct litest_device *k1, *k2;
5171 struct libinput *li = touchpad->libinput;
5172
5173 ck_assert(has_disable_while_typing(touchpad));
5174
5175 enable_dwt(touchpad);
5176
5177 k1 = litest_add_device(li, LITEST_KEYBOARD);
5178 k2 = litest_add_device(li, LITEST_KEYBOARD);
5179
5180 litest_keyboard_key(k1, KEY_A, true);
5181 litest_keyboard_key(k1, KEY_A, false);
5182 litest_drain_events(li);
5183
5184 litest_touch_down(touchpad, 0, 50, 50);
5185 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5186 litest_touch_up(touchpad, 0);
5187 litest_assert_empty_queue(li);
5188
5189 litest_timeout_dwt_short();
5190
5191 litest_keyboard_key(k2, KEY_A, true);
5192 litest_keyboard_key(k2, KEY_A, false);
5193 litest_drain_events(li);
5194
5195 litest_touch_down(touchpad, 0, 50, 50);
5196 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5197 litest_touch_up(touchpad, 0);
5198 litest_assert_empty_queue(li);
5199
5200 litest_timeout_dwt_short();
5201
5202 litest_delete_device(k1);
5203 litest_delete_device(k2);
5204 }
5205 END_TEST
5206
START_TEST(touchpad_dwt_remove_before_keyboard)5207 START_TEST(touchpad_dwt_remove_before_keyboard)
5208 {
5209 struct litest_device *keyboard = litest_current_device();
5210 struct litest_device *touchpad;
5211 struct libinput *li = keyboard->libinput;
5212
5213 touchpad = litest_add_device(li, LITEST_SYNAPTICS_RMI4);
5214 ck_assert(has_disable_while_typing(touchpad));
5215
5216 libinput_dispatch(li);
5217
5218 /* remove the touchpad before the keyboard.
5219 * this test can fail in valgrind only */
5220 litest_delete_device(touchpad);
5221 }
5222 END_TEST
5223
START_TEST(touchpad_dwt_multiple_keyboards_bothkeys)5224 START_TEST(touchpad_dwt_multiple_keyboards_bothkeys)
5225 {
5226 struct litest_device *touchpad = litest_current_device();
5227 struct litest_device *k1, *k2;
5228 struct libinput *li = touchpad->libinput;
5229
5230 ck_assert(has_disable_while_typing(touchpad));
5231
5232 enable_dwt(touchpad);
5233
5234 k1 = litest_add_device(li, LITEST_KEYBOARD);
5235 k2 = litest_add_device(li, LITEST_KEYBOARD);
5236
5237 litest_keyboard_key(k1, KEY_A, true);
5238 litest_keyboard_key(k1, KEY_A, false);
5239 litest_keyboard_key(k2, KEY_B, true);
5240 litest_keyboard_key(k2, KEY_B, false);
5241 litest_drain_events(li);
5242
5243 litest_touch_down(touchpad, 0, 50, 50);
5244 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5245 litest_touch_up(touchpad, 0);
5246 litest_assert_empty_queue(li);
5247
5248 litest_delete_device(k1);
5249 litest_delete_device(k2);
5250 }
5251 END_TEST
5252
START_TEST(touchpad_dwt_multiple_keyboards_bothkeys_modifier)5253 START_TEST(touchpad_dwt_multiple_keyboards_bothkeys_modifier)
5254 {
5255 struct litest_device *touchpad = litest_current_device();
5256 struct litest_device *k1, *k2;
5257 struct libinput *li = touchpad->libinput;
5258
5259 ck_assert(has_disable_while_typing(touchpad));
5260
5261 enable_dwt(touchpad);
5262
5263 k1 = litest_add_device(li, LITEST_KEYBOARD);
5264 k2 = litest_add_device(li, LITEST_KEYBOARD);
5265
5266 litest_keyboard_key(k1, KEY_RIGHTCTRL, true);
5267 litest_keyboard_key(k1, KEY_RIGHTCTRL, false);
5268 litest_keyboard_key(k2, KEY_B, true);
5269 litest_keyboard_key(k2, KEY_B, false);
5270 litest_drain_events(li);
5271
5272 /* If the keyboard is a single physical device, the above should
5273 * trigger the modifier behavior for dwt. But libinput views it as
5274 * two separate devices and this is such a niche case that it
5275 * doesn't matter. So we test for the easy behavior:
5276 * ctrl+B across two devices is *not* a dwt modifier combo
5277 */
5278 litest_touch_down(touchpad, 0, 50, 50);
5279 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5280 litest_touch_up(touchpad, 0);
5281 litest_assert_empty_queue(li);
5282
5283 litest_delete_device(k1);
5284 litest_delete_device(k2);
5285 }
5286 END_TEST
5287
START_TEST(touchpad_dwt_multiple_keyboards_remove)5288 START_TEST(touchpad_dwt_multiple_keyboards_remove)
5289 {
5290 struct litest_device *touchpad = litest_current_device();
5291 struct litest_device *keyboards[2];
5292 struct libinput *li = touchpad->libinput;
5293 int which = _i; /* ranged test */
5294 struct litest_device *removed, *remained;
5295
5296 ck_assert_int_le(which, 1);
5297
5298 ck_assert(has_disable_while_typing(touchpad));
5299
5300 enable_dwt(touchpad);
5301
5302 keyboards[0] = litest_add_device(li, LITEST_KEYBOARD);
5303 keyboards[1] = litest_add_device(li, LITEST_KEYBOARD);
5304
5305 litest_keyboard_key(keyboards[0], KEY_A, true);
5306 litest_keyboard_key(keyboards[0], KEY_A, false);
5307 litest_keyboard_key(keyboards[1], KEY_B, true);
5308 litest_keyboard_key(keyboards[1], KEY_B, false);
5309 litest_drain_events(li);
5310
5311 litest_timeout_dwt_short();
5312
5313 removed = keyboards[which % 2];
5314 remained = keyboards[(which + 1) % 2];
5315
5316 litest_delete_device(removed);
5317 litest_keyboard_key(remained, KEY_C, true);
5318 litest_keyboard_key(remained, KEY_C, false);
5319 litest_drain_events(li);
5320
5321 litest_touch_down(touchpad, 0, 50, 50);
5322 litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
5323 litest_touch_up(touchpad, 0);
5324 litest_assert_empty_queue(li);
5325
5326 litest_delete_device(remained);
5327 }
5328 END_TEST
5329
5330 static int
has_thumb_detect(struct litest_device * dev)5331 has_thumb_detect(struct litest_device *dev)
5332 {
5333 double w, h;
5334
5335 if (libinput_device_get_size(dev->libinput_device, &w, &h) != 0)
5336 return 0;
5337
5338 return h >= 50.0;
5339 }
5340
START_TEST(touchpad_thumb_lower_area_movement)5341 START_TEST(touchpad_thumb_lower_area_movement)
5342 {
5343 struct litest_device *dev = litest_current_device();
5344 struct libinput *li = dev->libinput;
5345
5346 if (!has_thumb_detect(dev))
5347 return;
5348
5349 litest_disable_tap(dev->libinput_device);
5350 litest_disable_hold_gestures(dev->libinput_device);
5351 litest_drain_events(li);
5352
5353 /* Thumb below lower line - slow movement - no events */
5354 litest_touch_down(dev, 0, 50, 99);
5355 litest_touch_move_to(dev, 0, 55, 99, 60, 99, 50);
5356 litest_assert_empty_queue(li);
5357
5358 /* Thumb below lower line - fast movement - events */
5359 litest_touch_move_to(dev, 0, 60, 99, 90, 99, 30);
5360 litest_touch_up(dev, 0);
5361
5362 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
5363 }
5364 END_TEST
5365
START_TEST(touchpad_thumb_lower_area_movement_rethumb)5366 START_TEST(touchpad_thumb_lower_area_movement_rethumb)
5367 {
5368 struct litest_device *dev = litest_current_device();
5369 struct libinput *li = dev->libinput;
5370
5371 if (!has_thumb_detect(dev))
5372 return;
5373
5374 litest_disable_tap(dev->libinput_device);
5375 litest_disable_hold_gestures(dev->libinput_device);
5376 litest_drain_events(li);
5377
5378 /* Thumb below lower line - fast movement - events */
5379 litest_touch_down(dev, 0, 50, 99);
5380 litest_touch_move_to(dev, 0, 50, 99, 90, 99, 30);
5381 litest_drain_events(li);
5382
5383 /* slow movement after being a non-touch - still events */
5384 litest_touch_move_to(dev, 0, 90, 99, 60, 99, 50);
5385 litest_touch_up(dev, 0);
5386
5387 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
5388 }
5389 END_TEST
5390
START_TEST(touchpad_thumb_speed_empty_slots)5391 START_TEST(touchpad_thumb_speed_empty_slots)
5392 {
5393 struct litest_device *dev = litest_current_device();
5394 struct libinput *li = dev->libinput;
5395
5396 litest_disable_tap(dev->libinput_device);
5397 litest_enable_2fg_scroll(dev);
5398 litest_disable_hold_gestures(dev->libinput_device);
5399
5400 if (libevdev_get_num_slots(dev->evdev) < 3)
5401 return;
5402
5403 litest_drain_events(li);
5404
5405 /* exceed the speed movement threshold in slot 0, then lift the
5406 * finger */
5407 litest_touch_down(dev, 0, 50, 20);
5408 litest_touch_move_to(dev, 0, 50, 20, 70, 99, 15);
5409 litest_touch_up(dev, 0);
5410
5411 litest_drain_events(li);
5412
5413 /* now scroll in slots 1 and 2, this should be a normal scroll event
5414 * despite slot 0 exceeding the speed threshold earlier */
5415 litest_touch_down(dev, 1, 50, 50);
5416 litest_touch_down(dev, 2, 55, 50);
5417 libinput_dispatch(li);
5418 for (int i = 0, y = 50; i < 10; i++, y++) {
5419 litest_touch_move_to(dev, 1, 50, y, 50, y + 1, 1);
5420 litest_touch_move_to(dev, 2, 55, y, 55, y + 1, 1);
5421 }
5422 libinput_dispatch(li);
5423 litest_touch_up(dev, 1);
5424 litest_touch_up(dev, 2);
5425 libinput_dispatch(li);
5426 litest_assert_scroll(li,
5427 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
5428 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
5429 2);
5430
5431 }
5432 END_TEST
5433
START_TEST(touchpad_thumb_area_clickfinger)5434 START_TEST(touchpad_thumb_area_clickfinger)
5435 {
5436 struct litest_device *dev = litest_current_device();
5437 struct libinput *li = dev->libinput;
5438 struct libinput_event *event;
5439
5440 if (!has_thumb_detect(dev))
5441 return;
5442
5443 litest_disable_tap(dev->libinput_device);
5444 litest_disable_hold_gestures(dev->libinput_device);
5445
5446 libinput_device_config_click_set_method(dev->libinput_device,
5447 LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
5448
5449 litest_drain_events(li);
5450
5451 litest_touch_down(dev, 0, 50, 99); /* thumb */
5452 libinput_dispatch(li);
5453 litest_touch_down(dev, 1, 60, 50);
5454 libinput_dispatch(li);
5455 litest_button_click(dev, BTN_LEFT, true);
5456
5457 libinput_dispatch(li);
5458 event = libinput_get_event(li);
5459 litest_is_button_event(event,
5460 BTN_LEFT,
5461 LIBINPUT_BUTTON_STATE_PRESSED);
5462 libinput_event_destroy(event);
5463
5464 litest_assert_empty_queue(li);
5465
5466 litest_button_click(dev, BTN_LEFT, false);
5467 litest_touch_up(dev, 0);
5468 litest_touch_up(dev, 1);
5469
5470 litest_drain_events(li);
5471
5472 litest_touch_down(dev, 1, 60, 99); /* thumb */
5473 libinput_dispatch(li);
5474 litest_touch_down(dev, 0, 50, 50);
5475 libinput_dispatch(li);
5476 litest_button_click(dev, BTN_LEFT, true);
5477
5478 libinput_dispatch(li);
5479 event = libinput_get_event(li);
5480 litest_is_button_event(event,
5481 BTN_LEFT,
5482 LIBINPUT_BUTTON_STATE_PRESSED);
5483 libinput_event_destroy(event);
5484
5485 litest_assert_empty_queue(li);
5486 }
5487 END_TEST
5488
START_TEST(touchpad_thumb_area_btnarea)5489 START_TEST(touchpad_thumb_area_btnarea)
5490 {
5491 struct litest_device *dev = litest_current_device();
5492 struct libinput *li = dev->libinput;
5493 struct libinput_event *event;
5494
5495 if (!has_thumb_detect(dev))
5496 return;
5497
5498 litest_disable_tap(dev->libinput_device);
5499 litest_disable_hold_gestures(dev->libinput_device);
5500
5501 libinput_device_config_click_set_method(dev->libinput_device,
5502 LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
5503
5504 litest_drain_events(li);
5505
5506 litest_touch_down(dev, 0, 90, 99); /* thumb */
5507 libinput_dispatch(li);
5508 litest_button_click(dev, BTN_LEFT, true);
5509
5510 /* button areas work as usual with a thumb */
5511
5512 libinput_dispatch(li);
5513 event = libinput_get_event(li);
5514 litest_is_button_event(event,
5515 BTN_RIGHT,
5516 LIBINPUT_BUTTON_STATE_PRESSED);
5517 libinput_event_destroy(event);
5518
5519 litest_assert_empty_queue(li);
5520 }
5521 END_TEST
5522
START_TEST(touchpad_thumb_no_doublethumb)5523 START_TEST(touchpad_thumb_no_doublethumb)
5524 {
5525 struct litest_device *dev = litest_current_device();
5526 struct libinput *li = dev->libinput;
5527
5528 litest_disable_tap(dev->libinput_device);
5529 litest_enable_clickfinger(dev);
5530 litest_disable_hold_gestures(dev->libinput_device);
5531
5532 if (!has_thumb_detect(dev))
5533 return;
5534
5535 litest_drain_events(li);
5536
5537 /* two touches in thumb area but we can't have two thumbs */
5538 litest_touch_down(dev, 0, 50, 99);
5539 /* random sleep interval. we don't have a thumb timer, but let's not
5540 * put both touches down and move them immediately because that
5541 * should always be a scroll event anyway. Go with a delay in
5542 * between to make it more likely that this is really testing thumb
5543 * detection.
5544 */
5545 msleep(200);
5546 libinput_dispatch(li);
5547 litest_touch_down(dev, 1, 70, 99);
5548 libinput_dispatch(li);
5549
5550 litest_touch_move_two_touches(dev, 50, 99, 70, 99, 0, -20, 10);
5551 litest_touch_up(dev, 0);
5552 litest_touch_up(dev, 1);
5553
5554 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
5555 }
5556 END_TEST
5557
START_TEST(touchpad_tool_tripletap_touch_count)5558 START_TEST(touchpad_tool_tripletap_touch_count)
5559 {
5560 struct litest_device *dev = litest_current_device();
5561 struct libinput *li = dev->libinput;
5562 struct libinput_event *event;
5563
5564 /* Synaptics touchpads sometimes end one touch point while
5565 * simultaneously setting BTN_TOOL_TRIPLETAP.
5566 * https://bugs.freedesktop.org/show_bug.cgi?id=91352
5567 */
5568 litest_drain_events(li);
5569 litest_enable_clickfinger(dev);
5570
5571 /* touch 1 down */
5572 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5573 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1);
5574 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 1200);
5575 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3200);
5576 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78);
5577 litest_event(dev, EV_ABS, ABS_X, 1200);
5578 litest_event(dev, EV_ABS, ABS_Y, 3200);
5579 litest_event(dev, EV_ABS, ABS_PRESSURE, 78);
5580 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
5581 litest_event(dev, EV_KEY, BTN_TOUCH, 1);
5582 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5583 libinput_dispatch(li);
5584 msleep(2);
5585
5586 /* touch 2 down */
5587 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
5588 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1);
5589 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500);
5590 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500);
5591 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73);
5592 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
5593 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1);
5594 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5595 libinput_dispatch(li);
5596 msleep(2);
5597
5598 /* touch 3 down, coordinate jump + ends slot 1 */
5599 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5600 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000);
5601 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 4000);
5602 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78);
5603 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
5604 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
5605 litest_event(dev, EV_ABS, ABS_X, 4000);
5606 litest_event(dev, EV_ABS, ABS_Y, 4000);
5607 litest_event(dev, EV_ABS, ABS_PRESSURE, 78);
5608 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
5609 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
5610 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5611 libinput_dispatch(li);
5612 msleep(2);
5613
5614 /* slot 2 reactivated */
5615 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5616 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000);
5617 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 4000);
5618 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78);
5619 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
5620 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 3);
5621 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500);
5622 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500);
5623 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73);
5624 litest_event(dev, EV_ABS, ABS_X, 4000);
5625 litest_event(dev, EV_ABS, ABS_Y, 4000);
5626 litest_event(dev, EV_ABS, ABS_PRESSURE, 78);
5627 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5628 libinput_dispatch(li);
5629 msleep(2);
5630
5631 /* now a click should trigger middle click */
5632 litest_event(dev, EV_KEY, BTN_LEFT, 1);
5633 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5634 libinput_dispatch(li);
5635 litest_event(dev, EV_KEY, BTN_LEFT, 0);
5636 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5637 libinput_dispatch(li);
5638
5639 litest_wait_for_event(li);
5640 event = libinput_get_event(li);
5641 litest_is_button_event(event,
5642 BTN_MIDDLE,
5643 LIBINPUT_BUTTON_STATE_PRESSED);
5644 libinput_event_destroy(event);
5645 event = libinput_get_event(li);
5646 litest_is_button_event(event,
5647 BTN_MIDDLE,
5648 LIBINPUT_BUTTON_STATE_RELEASED);
5649 libinput_event_destroy(event);
5650
5651 /* release everything */
5652 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5653 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
5654 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5655 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
5656 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
5657 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
5658 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0);
5659 litest_event(dev, EV_KEY, BTN_TOUCH, 0);
5660 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5661 }
5662 END_TEST
5663
START_TEST(touchpad_tool_tripletap_touch_count_late)5664 START_TEST(touchpad_tool_tripletap_touch_count_late)
5665 {
5666 struct litest_device *dev = litest_current_device();
5667 struct libinput *li = dev->libinput;
5668 struct libinput_event *event;
5669
5670 /* Synaptics touchpads sometimes end one touch point after
5671 * setting BTN_TOOL_TRIPLETAP.
5672 * https://gitlab.freedesktop.org/libinput/libinput/issues/99
5673 */
5674 litest_drain_events(li);
5675 litest_enable_clickfinger(dev);
5676
5677 /* touch 1 down */
5678 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5679 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1);
5680 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 2200);
5681 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3200);
5682 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78);
5683 litest_event(dev, EV_ABS, ABS_X, 2200);
5684 litest_event(dev, EV_ABS, ABS_Y, 3200);
5685 litest_event(dev, EV_ABS, ABS_PRESSURE, 78);
5686 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
5687 litest_event(dev, EV_KEY, BTN_TOUCH, 1);
5688 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5689 libinput_dispatch(li);
5690 msleep(10);
5691
5692 /* touch 2 and TRIPLETAP down */
5693 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
5694 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1);
5695 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500);
5696 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500);
5697 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73);
5698 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
5699 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
5700 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5701 libinput_dispatch(li);
5702 msleep(10);
5703
5704 /* touch 2 up, coordinate jump + ends slot 1, TRIPLETAP stays */
5705 litest_disable_log_handler(li);
5706 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5707 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000);
5708 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 4000);
5709 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78);
5710 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
5711 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
5712 litest_event(dev, EV_ABS, ABS_X, 4000);
5713 litest_event(dev, EV_ABS, ABS_Y, 4000);
5714 litest_event(dev, EV_ABS, ABS_PRESSURE, 78);
5715 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5716 libinput_dispatch(li);
5717 msleep(10);
5718
5719 /* slot 2 reactivated */
5720 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5721 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000);
5722 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 4000);
5723 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78);
5724 litest_event(dev, EV_ABS, ABS_MT_SLOT, 1);
5725 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 3);
5726 litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500);
5727 litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500);
5728 litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73);
5729 litest_event(dev, EV_ABS, ABS_X, 4000);
5730 litest_event(dev, EV_ABS, ABS_Y, 4000);
5731 litest_event(dev, EV_ABS, ABS_PRESSURE, 78);
5732 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5733 libinput_dispatch(li);
5734 msleep(10);
5735 litest_restore_log_handler(li);
5736
5737 /* now a click should trigger middle click */
5738 litest_event(dev, EV_KEY, BTN_LEFT, 1);
5739 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5740 libinput_dispatch(li);
5741 litest_event(dev, EV_KEY, BTN_LEFT, 0);
5742 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5743 libinput_dispatch(li);
5744
5745 litest_wait_for_event(li);
5746 event = libinput_get_event(li);
5747 litest_is_button_event(event,
5748 BTN_MIDDLE,
5749 LIBINPUT_BUTTON_STATE_PRESSED);
5750 libinput_event_destroy(event);
5751 event = libinput_get_event(li);
5752 litest_is_button_event(event,
5753 BTN_MIDDLE,
5754 LIBINPUT_BUTTON_STATE_RELEASED);
5755 libinput_event_destroy(event);
5756
5757 /* release everything */
5758 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5759 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
5760 litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
5761 litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
5762 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
5763 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
5764 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0);
5765 litest_event(dev, EV_KEY, BTN_TOUCH, 0);
5766 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5767 }
5768 END_TEST
5769
START_TEST(touchpad_slot_swap)5770 START_TEST(touchpad_slot_swap)
5771 {
5772 struct litest_device *dev = litest_current_device();
5773 struct libinput *li = dev->libinput;
5774 struct libinput_event *event;
5775 int first, second;
5776
5777 /* Synaptics touchpads sometimes end the wrong touchpoint on finger
5778 * up, causing the remaining slot to continue with the other slot's
5779 * coordinates.
5780 * https://bugs.freedesktop.org/show_bug.cgi?id=91352
5781 */
5782 litest_drain_events(li);
5783
5784 for (first = 0; first <= 1; first++) {
5785 const double start[2][2] = {{50, 50}, {60, 60}};
5786 second = 1 - first;
5787
5788 litest_touch_down(dev, 0, start[0][0], start[0][1]);
5789 libinput_dispatch(li);
5790 litest_touch_down(dev, 1, start[1][0], start[1][1]);
5791 libinput_dispatch(li);
5792
5793 litest_touch_move_two_touches(dev,
5794 start[first][0],
5795 start[first][1],
5796 start[second][0],
5797 start[second][1],
5798 30, 30, 10);
5799 litest_drain_events(li);
5800
5801 /* release touch 0, continue other slot with 0's coords */
5802 litest_push_event_frame(dev);
5803 litest_touch_up(dev, first);
5804 litest_touch_move(dev, second,
5805 start[second][0] + 30,
5806 start[second][1] + 30.1);
5807 litest_pop_event_frame(dev);
5808 libinput_dispatch(li);
5809 /* If a gesture was detected, we need to go past the gesture
5810 * timeout to trigger events. So let's move a bit first to
5811 * make sure it looks continuous, then wait, then move again
5812 * to make sure we trigger events */
5813 litest_touch_move_to(dev, second,
5814 start[first][0] + 30,
5815 start[first][1] + 30,
5816 50, 21, 10);
5817 libinput_dispatch(li);
5818 litest_timeout_gesture();
5819 libinput_dispatch(li);
5820 /* drain a potential scroll stop */
5821 litest_drain_events(li);
5822 litest_touch_move_to(dev, second, 50, 21, 50, 11, 20);
5823 libinput_dispatch(li);
5824 event = libinput_get_event(li);
5825 do {
5826 struct libinput_event_pointer *ptrev;
5827
5828 ptrev = litest_is_motion_event(event);
5829 ck_assert_double_eq(libinput_event_pointer_get_dx(ptrev), 0.0);
5830 ck_assert_double_lt(libinput_event_pointer_get_dy(ptrev), 1.0);
5831
5832 libinput_event_destroy(event);
5833 event = libinput_get_event(li);
5834 } while (event);
5835 litest_assert_empty_queue(li);
5836
5837 litest_touch_up(dev, second);
5838 }
5839 }
5840 END_TEST
5841
START_TEST(touchpad_finger_always_down)5842 START_TEST(touchpad_finger_always_down)
5843 {
5844 struct litest_device *dev = litest_current_device();
5845 struct libinput *li;
5846
5847 /* Set BTN_TOOL_FINGER before a new context is initialized */
5848 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
5849 litest_event(dev, EV_SYN, SYN_REPORT, 0);
5850
5851 li = litest_create_context();
5852 libinput_path_add_device(li,
5853 libevdev_uinput_get_devnode(dev->uinput));
5854 litest_drain_events(li);
5855
5856 litest_touch_down(dev, 0, 50, 50);
5857 litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10);
5858
5859 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
5860
5861 litest_destroy_context(li);
5862 }
5863 END_TEST
5864
START_TEST(touchpad_time_usec)5865 START_TEST(touchpad_time_usec)
5866 {
5867 struct litest_device *dev = litest_current_device();
5868 struct libinput *li = dev->libinput;
5869 struct libinput_event *event;
5870
5871 litest_disable_tap(dev->libinput_device);
5872 litest_disable_hold_gestures(dev->libinput_device);
5873 litest_drain_events(li);
5874
5875 litest_touch_down(dev, 0, 50, 50);
5876 litest_touch_move_to(dev, 0, 50, 50, 80, 50, 20);
5877 litest_touch_up(dev, 0);
5878
5879 libinput_dispatch(li);
5880
5881 event = libinput_get_event(li);
5882 ck_assert_notnull(event);
5883
5884 while (event) {
5885 struct libinput_event_pointer *ptrev;
5886 uint64_t utime;
5887
5888 ptrev = litest_is_motion_event(event);
5889 utime = libinput_event_pointer_get_time_usec(ptrev);
5890
5891 ck_assert_int_eq(libinput_event_pointer_get_time(ptrev),
5892 (uint32_t) (utime / 1000));
5893 libinput_event_destroy(event);
5894 event = libinput_get_event(li);
5895 }
5896 }
5897 END_TEST
5898
START_TEST(touchpad_jump_finger_motion)5899 START_TEST(touchpad_jump_finger_motion)
5900 {
5901 struct litest_device *dev = litest_current_device();
5902 struct libinput *li = dev->libinput;
5903 struct libinput_event *event;
5904
5905 litest_touch_down(dev, 0, 20, 30);
5906 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
5907 litest_drain_events(li);
5908
5909 /* this test uses a specific test device to trigger a >20mm jump to
5910 * test jumps. These numbers may not work on any other device */
5911 litest_disable_log_handler(li);
5912 litest_touch_move_to(dev, 0, 90, 30, 20, 80, 1);
5913 litest_assert_empty_queue(li);
5914 litest_restore_log_handler(li);
5915
5916 litest_touch_move_to(dev, 0, 20, 80, 21, 81, 10);
5917 litest_touch_up(dev, 0);
5918
5919 /* expect lots of little events, no big jump */
5920 libinput_dispatch(li);
5921 event = libinput_get_event(li);
5922 do {
5923 struct libinput_event_pointer *ptrev;
5924 double dx, dy;
5925
5926 ptrev = litest_is_motion_event(event);
5927 dx = libinput_event_pointer_get_dx(ptrev);
5928 dy = libinput_event_pointer_get_dy(ptrev);
5929 ck_assert_int_lt(abs((int)dx), 20);
5930 ck_assert_int_lt(abs((int)dy), 20);
5931
5932 libinput_event_destroy(event);
5933 event = libinput_get_event(li);
5934 } while (event != NULL);
5935 }
5936 END_TEST
5937
START_TEST(touchpad_jump_delta)5938 START_TEST(touchpad_jump_delta)
5939 {
5940 struct litest_device *dev = litest_current_device();
5941 struct libinput *li = dev->libinput;
5942 struct libinput_event *event;
5943
5944 litest_touch_down(dev, 0, 20, 30);
5945 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
5946 litest_drain_events(li);
5947
5948 /* this test uses a specific test device to trigger a >7mm but <20mm
5949 * jump to test the delta jumps. These numbers may not work on any
5950 * other device */
5951 litest_disable_log_handler(li);
5952 litest_touch_move(dev, 0, 90, 88);
5953 litest_assert_empty_queue(li);
5954 litest_restore_log_handler(li);
5955
5956 litest_touch_move_to(dev, 0, 90, 88, 91, 89, 10);
5957 litest_touch_up(dev, 0);
5958
5959 /* expect lots of little events, no big jump */
5960 libinput_dispatch(li);
5961 event = libinput_get_event(li);
5962 do {
5963 struct libinput_event_pointer *ptrev;
5964 double dx, dy;
5965
5966 ptrev = litest_is_motion_event(event);
5967 dx = libinput_event_pointer_get_dx(ptrev);
5968 dy = libinput_event_pointer_get_dy(ptrev);
5969 ck_assert_int_lt(abs((int)dx), 20);
5970 ck_assert_int_lt(abs((int)dy), 20);
5971
5972 libinput_event_destroy(event);
5973 event = libinput_get_event(li);
5974 } while (event != NULL);
5975 }
5976 END_TEST
5977
START_TEST(touchpad_disabled_on_mouse)5978 START_TEST(touchpad_disabled_on_mouse)
5979 {
5980 struct litest_device *dev = litest_current_device();
5981 struct litest_device *mouse;
5982 struct libinput *li = dev->libinput;
5983 enum libinput_config_status status;
5984
5985 litest_drain_events(li);
5986
5987 status = libinput_device_config_send_events_set_mode(
5988 dev->libinput_device,
5989 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE);
5990 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
5991
5992 litest_touch_down(dev, 0, 20, 30);
5993 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
5994 litest_touch_up(dev, 0);
5995 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
5996
5997 mouse = litest_add_device(li, LITEST_MOUSE);
5998 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED);
5999
6000 litest_touch_down(dev, 0, 20, 30);
6001 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6002 litest_touch_up(dev, 0);
6003 litest_assert_empty_queue(li);
6004
6005 litest_delete_device(mouse);
6006 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
6007
6008 litest_touch_down(dev, 0, 20, 30);
6009 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6010 litest_touch_up(dev, 0);
6011 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6012 }
6013 END_TEST
6014
START_TEST(touchpad_disabled_on_mouse_suspend_mouse)6015 START_TEST(touchpad_disabled_on_mouse_suspend_mouse)
6016 {
6017 struct litest_device *dev = litest_current_device();
6018 struct litest_device *mouse;
6019 struct libinput *li = dev->libinput;
6020 enum libinput_config_status status;
6021
6022 litest_drain_events(li);
6023
6024 status = libinput_device_config_send_events_set_mode(
6025 dev->libinput_device,
6026 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE);
6027 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
6028
6029 litest_touch_down(dev, 0, 20, 30);
6030 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6031 litest_touch_up(dev, 0);
6032 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6033
6034 mouse = litest_add_device(li, LITEST_MOUSE);
6035 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED);
6036
6037 /* Disable external mouse -> expect touchpad events */
6038 status = libinput_device_config_send_events_set_mode(
6039 mouse->libinput_device,
6040 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
6041 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
6042
6043 litest_touch_down(dev, 0, 20, 30);
6044 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6045 litest_touch_up(dev, 0);
6046 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6047
6048 litest_delete_device(mouse);
6049 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
6050
6051 litest_touch_down(dev, 0, 20, 30);
6052 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6053 litest_touch_up(dev, 0);
6054 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6055 }
6056 END_TEST
6057
START_TEST(touchpad_disabled_double_mouse)6058 START_TEST(touchpad_disabled_double_mouse)
6059 {
6060 struct litest_device *dev = litest_current_device();
6061 struct litest_device *mouse1, *mouse2;
6062 struct libinput *li = dev->libinput;
6063 enum libinput_config_status status;
6064
6065 litest_drain_events(li);
6066
6067 status = libinput_device_config_send_events_set_mode(
6068 dev->libinput_device,
6069 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE);
6070 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
6071
6072 litest_touch_down(dev, 0, 20, 30);
6073 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6074 litest_touch_up(dev, 0);
6075 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6076
6077 mouse1 = litest_add_device(li, LITEST_MOUSE);
6078 mouse2 = litest_add_device(li, LITEST_MOUSE_LOW_DPI);
6079 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED);
6080
6081 litest_touch_down(dev, 0, 20, 30);
6082 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6083 litest_touch_up(dev, 0);
6084 litest_assert_empty_queue(li);
6085
6086 litest_delete_device(mouse1);
6087 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
6088
6089 litest_touch_down(dev, 0, 20, 30);
6090 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6091 litest_touch_up(dev, 0);
6092 litest_assert_empty_queue(li);
6093
6094 litest_delete_device(mouse2);
6095 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
6096
6097 litest_touch_down(dev, 0, 20, 30);
6098 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6099 litest_touch_up(dev, 0);
6100 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6101 }
6102 END_TEST
6103
START_TEST(touchpad_disabled_double_mouse_one_suspended)6104 START_TEST(touchpad_disabled_double_mouse_one_suspended)
6105 {
6106 struct litest_device *dev = litest_current_device();
6107 struct litest_device *mouse1, *mouse2;
6108 struct libinput *li = dev->libinput;
6109 enum libinput_config_status status;
6110
6111 litest_drain_events(li);
6112
6113 status = libinput_device_config_send_events_set_mode(
6114 dev->libinput_device,
6115 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE);
6116 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
6117
6118 litest_touch_down(dev, 0, 20, 30);
6119 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6120 litest_touch_up(dev, 0);
6121 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6122
6123 mouse1 = litest_add_device(li, LITEST_MOUSE);
6124 mouse2 = litest_add_device(li, LITEST_MOUSE_LOW_DPI);
6125 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED);
6126
6127 /* Disable one external mouse -> don't expect touchpad events */
6128 status = libinput_device_config_send_events_set_mode(
6129 mouse1->libinput_device,
6130 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
6131 ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
6132
6133 litest_touch_down(dev, 0, 20, 30);
6134 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6135 litest_touch_up(dev, 0);
6136 litest_assert_empty_queue(li);
6137
6138 litest_delete_device(mouse1);
6139 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
6140
6141 litest_touch_down(dev, 0, 20, 30);
6142 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6143 litest_touch_up(dev, 0);
6144 litest_assert_empty_queue(li);
6145
6146 litest_delete_device(mouse2);
6147 litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
6148
6149 litest_touch_down(dev, 0, 20, 30);
6150 litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10);
6151 litest_touch_up(dev, 0);
6152 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6153 }
6154 END_TEST
6155
6156 static inline bool
touchpad_has_pressure(struct litest_device * dev)6157 touchpad_has_pressure(struct litest_device *dev)
6158 {
6159 struct libevdev *evdev = dev->evdev;
6160
6161 if (dev->which == LITEST_SYNAPTICS_PRESSUREPAD)
6162 return false;
6163
6164 if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_PRESSURE))
6165 return libevdev_get_abs_resolution(evdev,
6166 ABS_MT_PRESSURE) == 0;
6167
6168 if (libevdev_has_event_code(evdev, EV_ABS, ABS_PRESSURE) &&
6169 !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT))
6170 return true;
6171
6172 return false;
6173 }
6174
START_TEST(touchpad_pressure)6175 START_TEST(touchpad_pressure)
6176 {
6177 struct litest_device *dev = litest_current_device();
6178 struct libinput *li = dev->libinput;
6179 struct axis_replacement axes[] = {
6180 { ABS_MT_PRESSURE, 1 },
6181 { ABS_PRESSURE, 1 },
6182 { -1, 0 }
6183 };
6184 double pressure; /* in percent */
6185 double threshold = 12.0;
6186
6187 if (!touchpad_has_pressure(dev))
6188 return;
6189
6190 litest_drain_events(li);
6191
6192 for (pressure = 1; pressure <= threshold + 1; pressure++) {
6193 litest_axis_set_value(axes, ABS_MT_PRESSURE, pressure);
6194 litest_axis_set_value(axes, ABS_PRESSURE, pressure);
6195 litest_touch_down_extended(dev, 0, 50, 50, axes);
6196 litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes,
6197 10);
6198 litest_touch_up(dev, 0);
6199 if (pressure < threshold)
6200 litest_assert_empty_queue(li);
6201 else
6202 litest_assert_only_typed_events(li,
6203 LIBINPUT_EVENT_POINTER_MOTION);
6204
6205 }
6206 }
6207 END_TEST
6208
START_TEST(touchpad_pressure_2fg)6209 START_TEST(touchpad_pressure_2fg)
6210 {
6211 struct litest_device *dev = litest_current_device();
6212 struct libinput *li = dev->libinput;
6213 struct axis_replacement axes[] = {
6214 { ABS_MT_PRESSURE, 5 },
6215 { ABS_PRESSURE, 5 },
6216 { -1, 0 }
6217 };
6218
6219 if (!touchpad_has_pressure(dev))
6220 return;
6221
6222 litest_drain_events(li);
6223
6224 litest_touch_down(dev, 0, 30, 50);
6225 litest_touch_down_extended(dev, 1, 50, 50, axes);
6226 libinput_dispatch(li);
6227 litest_touch_move_to(dev, 0, 30, 50, 80, 80, 10);
6228 libinput_dispatch(li);
6229 litest_assert_only_typed_events(li,
6230 LIBINPUT_EVENT_POINTER_MOTION);
6231 litest_touch_move_to_extended(dev, 1, 50, 50, 80, 80, axes, 10);
6232 litest_assert_empty_queue(li);
6233 litest_touch_move_to(dev, 0, 80, 80, 20, 50, 10);
6234 litest_touch_move_to_extended(dev, 1, 80, 80, 50, 50, axes, 10);
6235 litest_assert_only_typed_events(li,
6236 LIBINPUT_EVENT_POINTER_MOTION);
6237 }
6238 END_TEST
6239
START_TEST(touchpad_pressure_2fg_st)6240 START_TEST(touchpad_pressure_2fg_st)
6241 {
6242 struct litest_device *dev = litest_current_device();
6243 struct libinput *li = dev->libinput;
6244 struct axis_replacement axes[] = {
6245 { ABS_MT_PRESSURE, 5 },
6246 { ABS_PRESSURE, 5 },
6247 { -1, 0 }
6248 };
6249
6250 if (!touchpad_has_pressure(dev))
6251 return;
6252
6253 /* This is a bit of a weird test. We expect two fingers to be down as
6254 * soon as doubletap is set, regardless of pressure. But we don't
6255 * have 2fg scrolling on st devices and 2 fingers down on a touchpad
6256 * without 2fg scrolling simply does not generate events. But that's
6257 * the same result as if the fingers were ignored because of
6258 * pressure and we cannot know the difference.
6259 * So this test only keeps your CPU warm, not much else.
6260 */
6261 litest_drain_events(li);
6262
6263 litest_touch_down_extended(dev, 0, 50, 50, axes);
6264 libinput_dispatch(li);
6265 litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0);
6266 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1);
6267 litest_event(dev, EV_SYN, SYN_REPORT, 0);
6268 libinput_dispatch(li);
6269 litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10);
6270 litest_assert_empty_queue(li);
6271 }
6272 END_TEST
6273
START_TEST(touchpad_pressure_tap)6274 START_TEST(touchpad_pressure_tap)
6275 {
6276 struct litest_device *dev = litest_current_device();
6277 struct libinput *li = dev->libinput;
6278 struct axis_replacement axes[] = {
6279 { ABS_MT_PRESSURE, 5 },
6280 { ABS_PRESSURE, 5 },
6281 { -1, 0 }
6282 };
6283
6284 if (!touchpad_has_pressure(dev))
6285 return;
6286
6287 litest_enable_tap(dev->libinput_device);
6288 litest_disable_hold_gestures(dev->libinput_device);
6289 litest_drain_events(li);
6290
6291 litest_touch_down_extended(dev, 0, 50, 50, axes);
6292 libinput_dispatch(li);
6293 litest_touch_up(dev, 0);
6294 litest_assert_empty_queue(li);
6295 }
6296 END_TEST
6297
START_TEST(touchpad_pressure_tap_2fg)6298 START_TEST(touchpad_pressure_tap_2fg)
6299 {
6300 struct litest_device *dev = litest_current_device();
6301 struct libinput *li = dev->libinput;
6302 struct axis_replacement axes[] = {
6303 { ABS_MT_PRESSURE, 5 },
6304 { ABS_PRESSURE, 5 },
6305 { -1, 0 }
6306 };
6307
6308 if (!touchpad_has_pressure(dev))
6309 return;
6310
6311 litest_enable_tap(dev->libinput_device);
6312 litest_disable_hold_gestures(dev->libinput_device);
6313 litest_drain_events(li);
6314
6315 /* tap but too light */
6316 litest_touch_down_extended(dev, 0, 40, 50, axes);
6317 litest_touch_down_extended(dev, 1, 50, 50, axes);
6318 libinput_dispatch(li);
6319 litest_touch_up(dev, 0);
6320 litest_touch_up(dev, 1);
6321 litest_assert_empty_queue(li);
6322 }
6323 END_TEST
6324
START_TEST(touchpad_pressure_tap_2fg_1fg_light)6325 START_TEST(touchpad_pressure_tap_2fg_1fg_light)
6326 {
6327 struct litest_device *dev = litest_current_device();
6328 struct libinput *li = dev->libinput;
6329 struct libinput_event *event;
6330 struct axis_replacement axes[] = {
6331 { ABS_MT_PRESSURE, 5 },
6332 { ABS_PRESSURE, 5 },
6333 { -1, 0 }
6334 };
6335
6336 if (!touchpad_has_pressure(dev))
6337 return;
6338
6339 litest_enable_tap(dev->libinput_device);
6340 litest_disable_hold_gestures(dev->libinput_device);
6341 litest_drain_events(li);
6342
6343 /* double-tap with one finger too light */
6344 litest_touch_down(dev, 0, 40, 50);
6345 litest_touch_down_extended(dev, 1, 50, 50, axes);
6346 libinput_dispatch(li);
6347 litest_touch_up(dev, 0);
6348 litest_touch_up(dev, 1);
6349 libinput_dispatch(li);
6350
6351 event = libinput_get_event(li);
6352 litest_is_button_event(event,
6353 BTN_LEFT,
6354 LIBINPUT_BUTTON_STATE_PRESSED);
6355 libinput_event_destroy(event);
6356
6357 litest_timeout_tap();
6358 libinput_dispatch(li);
6359
6360 event = libinput_get_event(li);
6361 litest_is_button_event(event,
6362 BTN_LEFT,
6363 LIBINPUT_BUTTON_STATE_RELEASED);
6364 libinput_event_destroy(event);
6365 }
6366 END_TEST
6367
START_TEST(touchpad_pressure_btntool)6368 START_TEST(touchpad_pressure_btntool)
6369 {
6370 struct litest_device *dev = litest_current_device();
6371 struct libinput *li = dev->libinput;
6372 struct axis_replacement axes[] = {
6373 { ABS_MT_PRESSURE, 5 },
6374 { ABS_PRESSURE, 5 },
6375 { -1, 0 }
6376 };
6377
6378 /* we only have tripletap, can't test 4 slots because nothing will
6379 * happen */
6380 if (libevdev_get_num_slots(dev->evdev) != 2)
6381 return;
6382
6383 if (!touchpad_has_pressure(dev))
6384 return;
6385
6386 litest_enable_tap(dev->libinput_device);
6387 litest_disable_hold_gestures(dev->libinput_device);
6388 litest_drain_events(li);
6389
6390 /* Two light touches down, doesn't count */
6391 litest_touch_down_extended(dev, 0, 40, 50, axes);
6392 litest_touch_down_extended(dev, 1, 45, 50, axes);
6393 libinput_dispatch(li);
6394 litest_assert_empty_queue(li);
6395
6396 /* Tripletap but since no finger is logically down, it doesn't count */
6397 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
6398 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
6399 litest_event(dev, EV_SYN, SYN_REPORT, 0);
6400 litest_assert_empty_queue(li);
6401
6402 /* back to two fingers */
6403 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1);
6404 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0);
6405 litest_event(dev, EV_SYN, SYN_REPORT, 0);
6406 libinput_dispatch(li);
6407
6408 /* make one finger real */
6409 litest_touch_move(dev, 0, 40, 50);
6410 litest_drain_events(li);
6411
6412 /* tripletap should now be 3 fingers tap */
6413 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
6414 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
6415 litest_event(dev, EV_SYN, SYN_REPORT, 0);
6416 libinput_dispatch(li);
6417
6418 litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1);
6419 litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0);
6420 litest_event(dev, EV_SYN, SYN_REPORT, 0);
6421 libinput_dispatch(li);
6422
6423 litest_timeout_tap();
6424 libinput_dispatch(li);
6425
6426 litest_assert_button_event(li,
6427 BTN_MIDDLE,
6428 LIBINPUT_BUTTON_STATE_PRESSED);
6429 litest_assert_button_event(li,
6430 BTN_MIDDLE,
6431 LIBINPUT_BUTTON_STATE_RELEASED);
6432 }
6433 END_TEST
6434
START_TEST(touchpad_pressure_semi_mt_2fg_goes_light)6435 START_TEST(touchpad_pressure_semi_mt_2fg_goes_light)
6436 {
6437 struct litest_device *dev = litest_current_device();
6438 struct libinput *li = dev->libinput;
6439 struct axis_replacement axes[] = {
6440 { ABS_PRESSURE, 2 },
6441 { -1, 0 }
6442 };
6443
6444 litest_enable_2fg_scroll(dev);
6445 litest_drain_events(li);
6446
6447 litest_touch_down(dev, 0, 40, 50);
6448 litest_touch_down(dev, 1, 60, 50);
6449 litest_touch_move_two_touches(dev, 40, 50, 60, 50, 0, -20, 10);
6450
6451 /* This should trigger a scroll end event */
6452 litest_push_event_frame(dev);
6453 litest_touch_move_extended(dev, 0, 40, 31, axes);
6454 litest_touch_move_extended(dev, 1, 60, 31, axes);
6455 litest_pop_event_frame(dev);
6456 libinput_dispatch(li);
6457
6458 litest_assert_scroll(li,
6459 LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
6460 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
6461 0);
6462
6463 litest_push_event_frame(dev);
6464 litest_touch_move_extended(dev, 0, 40, 35, axes);
6465 litest_touch_move_extended(dev, 1, 60, 35, axes);
6466 litest_pop_event_frame(dev);
6467
6468 litest_push_event_frame(dev);
6469 litest_touch_move_extended(dev, 0, 40, 40, axes);
6470 litest_touch_move_extended(dev, 1, 60, 40, axes);
6471 litest_pop_event_frame(dev);
6472 libinput_dispatch(li);
6473 litest_assert_empty_queue(li);
6474 }
6475 END_TEST
6476
START_TEST(touchpad_touch_size)6477 START_TEST(touchpad_touch_size)
6478 {
6479 struct litest_device *dev = litest_current_device();
6480 struct libinput *li = dev->libinput;
6481 struct axis_replacement axes[] = {
6482 { ABS_MT_TOUCH_MAJOR, 0 },
6483 { ABS_MT_TOUCH_MINOR, 0 },
6484 { ABS_MT_ORIENTATION, 0 },
6485 { -1, 0 }
6486 };
6487
6488 if (!touchpad_has_touch_size(dev))
6489 return;
6490
6491 litest_drain_events(li);
6492
6493 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 1);
6494 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 1);
6495 litest_touch_down_extended(dev, 0, 50, 50, axes);
6496 litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10);
6497 litest_touch_up(dev, 0);
6498 litest_assert_empty_queue(li);
6499
6500 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 15);
6501 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 15);
6502 litest_touch_down_extended(dev, 0, 50, 50, axes);
6503 litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10);
6504 litest_touch_up(dev, 0);
6505 litest_assert_only_typed_events(li,
6506 LIBINPUT_EVENT_POINTER_MOTION);
6507 }
6508 END_TEST
6509
START_TEST(touchpad_touch_size_2fg)6510 START_TEST(touchpad_touch_size_2fg)
6511 {
6512 struct litest_device *dev = litest_current_device();
6513 struct libinput *li = dev->libinput;
6514 struct axis_replacement axes[] = {
6515 { ABS_MT_TOUCH_MAJOR, 0 },
6516 { ABS_MT_TOUCH_MINOR, 0 },
6517 { ABS_MT_ORIENTATION, 0 },
6518 { -1, 0 }
6519 };
6520
6521 if (!touchpad_has_touch_size(dev))
6522 return;
6523
6524 litest_drain_events(li);
6525 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 15);
6526 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 15);
6527 litest_touch_down_extended(dev, 0, 50, 50, axes);
6528 litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10);
6529
6530 litest_assert_only_typed_events(li,
6531 LIBINPUT_EVENT_POINTER_MOTION);
6532
6533 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 1);
6534 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 1);
6535 litest_touch_down_extended(dev, 1, 70, 70, axes);
6536 litest_touch_move_to_extended(dev, 1, 70, 70, 80, 90, axes, 10);
6537 litest_assert_empty_queue(li);
6538
6539 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 15);
6540 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 15);
6541 litest_touch_move_to_extended(dev, 0, 80, 80, 50, 50, axes, 10);
6542
6543 litest_assert_only_typed_events(li,
6544 LIBINPUT_EVENT_POINTER_MOTION);
6545
6546 litest_touch_up(dev, 1);
6547 litest_touch_up(dev, 0);
6548 }
6549 END_TEST
6550
START_TEST(touchpad_palm_detect_touch_size)6551 START_TEST(touchpad_palm_detect_touch_size)
6552 {
6553 struct litest_device *dev = litest_current_device();
6554 struct libinput *li = dev->libinput;
6555 struct axis_replacement axes[] = {
6556 { ABS_MT_TOUCH_MAJOR, 0 },
6557 { ABS_MT_TOUCH_MINOR, 0 },
6558 { -1, 0 }
6559 };
6560
6561 if (!touchpad_has_touch_size(dev) ||
6562 litest_touchpad_is_external(dev))
6563 return;
6564
6565 litest_drain_events(li);
6566
6567 /* apply insufficient pressure */
6568 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 30);
6569 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 30);
6570 litest_touch_down_extended(dev, 0, 50, 50, axes);
6571 litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10);
6572 litest_assert_only_typed_events(li,
6573 LIBINPUT_EVENT_POINTER_MOTION);
6574
6575 /* apply sufficient pressure */
6576 litest_axis_set_value_unchecked(axes, ABS_MT_TOUCH_MAJOR, 90);
6577 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90);
6578 litest_touch_move_to_extended(dev, 0, 80, 80, 50, 50, axes, 10);
6579 litest_assert_empty_queue(li);
6580 }
6581 END_TEST
6582
START_TEST(touchpad_palm_detect_touch_size_late)6583 START_TEST(touchpad_palm_detect_touch_size_late)
6584 {
6585 struct litest_device *dev = litest_current_device();
6586 struct libinput *li = dev->libinput;
6587 struct axis_replacement axes[] = {
6588 { ABS_MT_TOUCH_MAJOR, 0 },
6589 { ABS_MT_TOUCH_MINOR, 0 },
6590 { -1, 0 }
6591 };
6592
6593 if (!touchpad_has_touch_size(dev) ||
6594 litest_touchpad_is_external(dev))
6595 return;
6596
6597 litest_drain_events(li);
6598
6599 /* apply insufficient pressure */
6600 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 30);
6601 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 30);
6602 litest_touch_down(dev, 0, 50, 50);
6603 litest_touch_move_to(dev, 0, 50, 70, 80, 90, 10);
6604 litest_drain_events(li);
6605 libinput_dispatch(li);
6606 litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10);
6607 litest_touch_up(dev, 0);
6608 litest_assert_only_typed_events(li,
6609 LIBINPUT_EVENT_POINTER_MOTION);
6610
6611 /* apply sufficient pressure */
6612 litest_axis_set_value_unchecked(axes, ABS_MT_TOUCH_MAJOR, 90);
6613 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90);
6614 litest_touch_down(dev, 0, 50, 50);
6615 litest_touch_move_to(dev, 0, 50, 70, 80, 90, 10);
6616 litest_drain_events(li);
6617 libinput_dispatch(li);
6618 litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10);
6619 litest_touch_up(dev, 0);
6620 litest_assert_empty_queue(li);
6621 }
6622 END_TEST
6623
START_TEST(touchpad_palm_detect_touch_size_keep_palm)6624 START_TEST(touchpad_palm_detect_touch_size_keep_palm)
6625 {
6626 struct litest_device *dev = litest_current_device();
6627 struct libinput *li = dev->libinput;
6628 struct axis_replacement axes[] = {
6629 { ABS_MT_TOUCH_MAJOR, 0 },
6630 { ABS_MT_TOUCH_MINOR, 0 },
6631 { -1, 0 }
6632 };
6633
6634 if (!touchpad_has_touch_size(dev) ||
6635 litest_touchpad_is_external(dev))
6636 return;
6637
6638 litest_drain_events(li);
6639
6640 /* apply insufficient pressure */
6641 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 30);
6642 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 30);
6643 litest_touch_down(dev, 0, 80, 90);
6644 litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10);
6645 litest_touch_move_to(dev, 0, 50, 20, 80, 90, 10);
6646 litest_touch_up(dev, 0);
6647 litest_assert_only_typed_events(li,
6648 LIBINPUT_EVENT_POINTER_MOTION);
6649
6650 /* apply sufficient pressure */
6651 litest_axis_set_value_unchecked(axes, ABS_MT_TOUCH_MAJOR, 90);
6652 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90);
6653 litest_touch_down(dev, 0, 80, 90);
6654 litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10);
6655 litest_touch_move_to(dev, 0, 50, 20, 80, 90, 10);
6656 litest_touch_up(dev, 0);
6657 litest_assert_empty_queue(li);
6658 }
6659 END_TEST
6660
START_TEST(touchpad_palm_detect_touch_size_after_edge)6661 START_TEST(touchpad_palm_detect_touch_size_after_edge)
6662 {
6663 struct litest_device *dev = litest_current_device();
6664 struct libinput *li = dev->libinput;
6665 struct axis_replacement axes[] = {
6666 { ABS_MT_TOUCH_MAJOR, 0 },
6667 { ABS_MT_TOUCH_MINOR, 0 },
6668 { -1, 0 }
6669 };
6670
6671 if (!touchpad_has_touch_size(dev) ||
6672 litest_touchpad_is_external(dev) ||
6673 !litest_has_palm_detect_size(dev) ||
6674 !litest_has_2fg_scroll(dev))
6675 return;
6676
6677 litest_enable_2fg_scroll(dev);
6678 litest_drain_events(li);
6679
6680 /* apply sufficient pressure */
6681 litest_axis_set_value_unchecked(axes, ABS_MT_TOUCH_MAJOR, 90);
6682 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90);
6683 litest_touch_down(dev, 0, 99, 50);
6684 litest_touch_move_to_extended(dev, 0, 99, 50, 20, 50, axes, 20);
6685 litest_touch_up(dev, 0);
6686 libinput_dispatch(li);
6687
6688 litest_assert_only_typed_events(li,
6689 LIBINPUT_EVENT_POINTER_MOTION);
6690 }
6691 END_TEST
6692
START_TEST(touchpad_palm_detect_touch_size_after_dwt)6693 START_TEST(touchpad_palm_detect_touch_size_after_dwt)
6694 {
6695 struct litest_device *touchpad = litest_current_device();
6696 struct litest_device *keyboard;
6697 struct libinput *li = touchpad->libinput;
6698 struct axis_replacement axes[] = {
6699 { ABS_MT_TOUCH_MAJOR, 0 },
6700 { ABS_MT_TOUCH_MINOR, 0 },
6701 { -1, 0 }
6702 };
6703
6704 if (!touchpad_has_touch_size(touchpad) ||
6705 litest_touchpad_is_external(touchpad))
6706 return;
6707
6708 keyboard = dwt_init_paired_keyboard(li, touchpad);
6709 litest_drain_events(li);
6710
6711 litest_keyboard_key(keyboard, KEY_A, true);
6712 litest_keyboard_key(keyboard, KEY_A, false);
6713 litest_drain_events(li);
6714
6715 /* apply sufficient pressure */
6716 litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 90);
6717 litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90);
6718
6719 /* within dwt timeout, dwt blocks events */
6720 litest_touch_down(touchpad, 0, 50, 50);
6721 litest_touch_move_to_extended(touchpad, 0, 50, 50, 20, 50, axes, 20);
6722 litest_assert_empty_queue(li);
6723
6724 litest_timeout_dwt_short();
6725 libinput_dispatch(li);
6726 litest_assert_empty_queue(li);
6727
6728 /* after dwt timeout, pressure blocks events */
6729 litest_touch_move_to_extended(touchpad, 0, 20, 50, 50, 50, axes, 20);
6730 litest_touch_up(touchpad, 0);
6731
6732 litest_assert_empty_queue(li);
6733
6734 litest_delete_device(keyboard);
6735 }
6736 END_TEST
6737
START_TEST(touchpad_speed_ignore_finger)6738 START_TEST(touchpad_speed_ignore_finger)
6739 {
6740 struct litest_device *dev = litest_current_device();
6741 struct libinput *li = dev->libinput;
6742
6743 if (!has_thumb_detect(dev))
6744 return;
6745
6746 if (litest_has_clickfinger(dev))
6747 litest_enable_clickfinger(dev);
6748
6749 litest_drain_events(li);
6750
6751 litest_touch_down(dev, 0, 20, 20);
6752 litest_touch_move_to(dev, 0, 20, 20, 85, 80, 20);
6753 litest_touch_down(dev, 1, 20, 80);
6754 litest_touch_move_two_touches(dev, 85, 80, 20, 80, -20, -20, 10);
6755 libinput_dispatch(li);
6756
6757 litest_touch_up(dev, 0);
6758 litest_touch_up(dev, 1);
6759
6760 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6761 }
6762 END_TEST
6763
START_TEST(touchpad_speed_allow_nearby_finger)6764 START_TEST(touchpad_speed_allow_nearby_finger)
6765 {
6766 struct litest_device *dev = litest_current_device();
6767 struct libinput *li = dev->libinput;
6768
6769 if (!has_thumb_detect(dev))
6770 return;
6771
6772 if (!litest_has_2fg_scroll(dev))
6773 return;
6774
6775 if (litest_has_clickfinger(dev))
6776 litest_enable_clickfinger(dev);
6777
6778 litest_enable_2fg_scroll(dev);
6779
6780 litest_drain_events(li);
6781
6782 litest_touch_down(dev, 0, 20, 20);
6783 litest_touch_move_to(dev, 0, 20, 20, 80, 80, 20);
6784 litest_drain_events(li);
6785 litest_touch_down(dev, 1, 79, 80);
6786 litest_touch_move_two_touches(dev, 80, 80, 79, 80, -20, -20, 10);
6787 libinput_dispatch(li);
6788
6789 litest_touch_up(dev, 0);
6790 litest_touch_up(dev, 1);
6791
6792 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
6793 }
6794 END_TEST
6795
START_TEST(touchpad_speed_ignore_finger_edgescroll)6796 START_TEST(touchpad_speed_ignore_finger_edgescroll)
6797 {
6798 struct litest_device *dev = litest_current_device();
6799 struct libinput *li = dev->libinput;
6800
6801 if (!has_thumb_detect(dev))
6802 return;
6803
6804 litest_enable_edge_scroll(dev);
6805 if (litest_has_clickfinger(dev))
6806 litest_enable_clickfinger(dev);
6807
6808 litest_drain_events(li);
6809
6810 litest_touch_down(dev, 0, 20, 20);
6811 litest_touch_move_to(dev, 0, 20, 20, 60, 80, 20);
6812 litest_drain_events(li);
6813 litest_touch_down(dev, 1, 59, 80);
6814 litest_touch_move_two_touches(dev, 60, 80, 59, 80, -20, -20, 10);
6815 libinput_dispatch(li);
6816
6817 litest_touch_up(dev, 0);
6818 libinput_dispatch(li);
6819 litest_touch_up(dev, 1);
6820
6821 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6822 }
6823 END_TEST
6824
START_TEST(touchpad_speed_ignore_hovering_finger)6825 START_TEST(touchpad_speed_ignore_hovering_finger)
6826 {
6827 struct litest_device *dev = litest_current_device();
6828 struct libinput *li = dev->libinput;
6829 struct axis_replacement axes[] = {
6830 { ABS_MT_TOUCH_MAJOR, 1 },
6831 { ABS_MT_TOUCH_MINOR, 1 },
6832 { -1, 0 }
6833 };
6834
6835 if (!has_thumb_detect(dev))
6836 return;
6837
6838 litest_drain_events(li);
6839
6840 /* first finger down but below touch size. we use slot 2 because
6841 * it's easier this way for litest */
6842 litest_touch_down_extended(dev, 2, 20, 20, axes);
6843 litest_touch_move_to_extended(dev, 2, 20, 20, 60, 80, axes, 20);
6844 litest_drain_events(li);
6845
6846 /* second, third finger down withn same frame */
6847 litest_push_event_frame(dev);
6848 litest_touch_down(dev, 0, 59, 70);
6849 litest_touch_down(dev, 1, 65, 70);
6850 litest_pop_event_frame(dev);
6851
6852 litest_touch_move_two_touches(dev, 59, 70, 65, 70, 0, 30, 10);
6853 libinput_dispatch(li);
6854
6855 litest_touch_up(dev, 2);
6856 libinput_dispatch(li);
6857 litest_touch_up(dev, 1);
6858 litest_touch_up(dev, 0);
6859
6860 litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
6861 }
6862 END_TEST
6863
6864 enum suspend {
6865 SUSPEND_EXT_MOUSE = 1,
6866 SUSPEND_SENDEVENTS,
6867 SUSPEND_LID,
6868 SUSPEND_TABLETMODE,
6869 SUSPEND_COUNT,
6870 };
6871
6872 static void
assert_touchpad_moves(struct litest_device * tp)6873 assert_touchpad_moves(struct litest_device *tp)
6874 {
6875 struct libinput *li = tp->libinput;
6876
6877 litest_touch_down(tp, 0, 50, 50);
6878 litest_touch_move_to(tp, 0, 50, 50, 60, 80, 20);
6879 litest_touch_up(tp, 0);
6880 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
6881 }
6882
6883 static void
assert_touchpad_does_not_move(struct litest_device * tp)6884 assert_touchpad_does_not_move(struct litest_device *tp)
6885 {
6886 struct libinput *li = tp->libinput;
6887
6888 litest_touch_down(tp, 0, 20, 20);
6889 litest_touch_move_to(tp, 0, 20, 20, 60, 80, 20);
6890 litest_touch_up(tp, 0);
6891 litest_assert_empty_queue(li);
6892 }
6893
START_TEST(touchpad_suspend_abba)6894 START_TEST(touchpad_suspend_abba)
6895 {
6896 struct litest_device *tp = litest_current_device();
6897 struct litest_device *lid, *tabletmode, *extmouse;
6898 struct libinput *li = tp->libinput;
6899 enum suspend first = _i; /* ranged test */
6900 enum suspend other;
6901
6902 if (first == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp))
6903 return;
6904
6905 lid = litest_add_device(li, LITEST_LID_SWITCH);
6906 tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
6907 extmouse = litest_add_device(li, LITEST_MOUSE);
6908
6909 litest_grab_device(lid);
6910 litest_grab_device(tabletmode);
6911
6912 litest_disable_tap(tp->libinput_device);
6913 litest_disable_hold_gestures(tp->libinput_device);
6914
6915 /* ABBA test for touchpad internal suspend:
6916 * reason A on
6917 * reason B on
6918 * reason B off
6919 * reason A off
6920 */
6921 for (other = SUSPEND_EXT_MOUSE; other < SUSPEND_COUNT; other++) {
6922 if (other == first)
6923 continue;
6924
6925 if (other == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp))
6926 goto out;
6927
6928 /* That transition is tested elsewhere and has a different
6929 * behavior */
6930 if ((other == SUSPEND_SENDEVENTS && first == SUSPEND_EXT_MOUSE) ||
6931 (first == SUSPEND_SENDEVENTS && other == SUSPEND_EXT_MOUSE))
6932 continue;
6933
6934 litest_drain_events(li);
6935 assert_touchpad_moves(tp);
6936
6937 /* First reason for suspend: on */
6938 switch (first) {
6939 case SUSPEND_EXT_MOUSE:
6940 litest_sendevents_ext_mouse(tp);
6941 break;
6942 case SUSPEND_TABLETMODE:
6943 litest_switch_action(tabletmode,
6944 LIBINPUT_SWITCH_TABLET_MODE,
6945 LIBINPUT_SWITCH_STATE_ON);
6946 break;
6947 case SUSPEND_LID:
6948 litest_switch_action(lid,
6949 LIBINPUT_SWITCH_LID,
6950 LIBINPUT_SWITCH_STATE_ON);
6951 break;
6952 case SUSPEND_SENDEVENTS:
6953 litest_sendevents_off(tp);
6954 break;
6955 default:
6956 ck_abort();
6957 }
6958
6959 litest_drain_events(li);
6960
6961 assert_touchpad_does_not_move(tp);
6962
6963 /* Second reason to suspend: on/off while first reason remains */
6964 switch (other) {
6965 case SUSPEND_EXT_MOUSE:
6966 litest_sendevents_ext_mouse(tp);
6967 litest_sendevents_on(tp);
6968 break;
6969 case SUSPEND_LID:
6970 litest_switch_action(lid,
6971 LIBINPUT_SWITCH_LID,
6972 LIBINPUT_SWITCH_STATE_ON);
6973 litest_drain_events(li);
6974 litest_switch_action(lid,
6975 LIBINPUT_SWITCH_LID,
6976 LIBINPUT_SWITCH_STATE_OFF);
6977 litest_drain_events(li);
6978 break;
6979 case SUSPEND_TABLETMODE:
6980 litest_switch_action(tabletmode,
6981 LIBINPUT_SWITCH_TABLET_MODE,
6982 LIBINPUT_SWITCH_STATE_ON);
6983 litest_drain_events(li);
6984 litest_switch_action(tabletmode,
6985 LIBINPUT_SWITCH_TABLET_MODE,
6986 LIBINPUT_SWITCH_STATE_OFF);
6987 litest_drain_events(li);
6988 break;
6989 case SUSPEND_SENDEVENTS:
6990 litest_sendevents_off(tp);
6991 litest_sendevents_on(tp);
6992 break;
6993 default:
6994 ck_abort();
6995 }
6996
6997 assert_touchpad_does_not_move(tp);
6998
6999 /* First reason for suspend: off */
7000 switch (first) {
7001 case SUSPEND_EXT_MOUSE:
7002 litest_sendevents_on(tp);
7003 break;
7004 case SUSPEND_TABLETMODE:
7005 litest_switch_action(tabletmode,
7006 LIBINPUT_SWITCH_TABLET_MODE,
7007 LIBINPUT_SWITCH_STATE_OFF);
7008 break;
7009 case SUSPEND_LID:
7010 litest_switch_action(lid,
7011 LIBINPUT_SWITCH_LID,
7012 LIBINPUT_SWITCH_STATE_OFF);
7013 break;
7014 case SUSPEND_SENDEVENTS:
7015 litest_sendevents_on(tp);
7016 break;
7017 default:
7018 ck_abort();
7019 }
7020
7021 litest_drain_events(li);
7022 assert_touchpad_moves(tp);
7023 }
7024
7025 out:
7026 litest_ungrab_device(lid);
7027 litest_ungrab_device(tabletmode);
7028 litest_delete_device(lid);
7029 litest_delete_device(tabletmode);
7030 litest_delete_device(extmouse);
7031 }
7032 END_TEST
7033
START_TEST(touchpad_suspend_abab)7034 START_TEST(touchpad_suspend_abab)
7035 {
7036 struct litest_device *tp = litest_current_device();
7037 struct litest_device *lid, *tabletmode, *extmouse;
7038 struct libinput *li = tp->libinput;
7039 enum suspend first = _i; /* ranged test */
7040 enum suspend other;
7041
7042 if (first == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp))
7043 return;
7044
7045 lid = litest_add_device(li, LITEST_LID_SWITCH);
7046 tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
7047 extmouse = litest_add_device(li, LITEST_MOUSE);
7048 litest_grab_device(lid);
7049 litest_grab_device(tabletmode);
7050
7051 litest_disable_tap(tp->libinput_device);
7052 litest_disable_hold_gestures(tp->libinput_device);
7053
7054 /* ABAB test for touchpad internal suspend:
7055 * reason A on
7056 * reason B on
7057 * reason A off
7058 * reason B off
7059 */
7060 for (other = SUSPEND_EXT_MOUSE; other < SUSPEND_COUNT; other++) {
7061 if (other == first)
7062 continue;
7063
7064 if (other == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp))
7065 goto out;
7066
7067 /* That transition is tested elsewhere and has a different
7068 * behavior */
7069 if ((other == SUSPEND_SENDEVENTS && first == SUSPEND_EXT_MOUSE) ||
7070 (first == SUSPEND_SENDEVENTS && other == SUSPEND_EXT_MOUSE))
7071 continue;
7072
7073 litest_drain_events(li);
7074 assert_touchpad_moves(tp);
7075
7076 /* First reason for suspend: on */
7077 switch (first) {
7078 case SUSPEND_EXT_MOUSE:
7079 litest_sendevents_ext_mouse(tp);
7080 break;
7081 case SUSPEND_TABLETMODE:
7082 litest_switch_action(tabletmode,
7083 LIBINPUT_SWITCH_TABLET_MODE,
7084 LIBINPUT_SWITCH_STATE_ON);
7085 break;
7086 case SUSPEND_LID:
7087 litest_switch_action(lid,
7088 LIBINPUT_SWITCH_LID,
7089 LIBINPUT_SWITCH_STATE_ON);
7090 break;
7091 case SUSPEND_SENDEVENTS:
7092 litest_sendevents_off(tp);
7093 break;
7094 default:
7095 ck_abort();
7096 }
7097
7098 litest_drain_events(li);
7099
7100 assert_touchpad_does_not_move(tp);
7101
7102 /* Second reason to suspend: on */
7103 switch (other) {
7104 case SUSPEND_EXT_MOUSE:
7105 litest_sendevents_ext_mouse(tp);
7106 break;
7107 case SUSPEND_LID:
7108 litest_switch_action(lid,
7109 LIBINPUT_SWITCH_LID,
7110 LIBINPUT_SWITCH_STATE_ON);
7111 litest_drain_events(li);
7112 break;
7113 case SUSPEND_TABLETMODE:
7114 litest_switch_action(tabletmode,
7115 LIBINPUT_SWITCH_TABLET_MODE,
7116 LIBINPUT_SWITCH_STATE_ON);
7117 litest_drain_events(li);
7118 break;
7119 case SUSPEND_SENDEVENTS:
7120 litest_sendevents_off(tp);
7121 break;
7122 default:
7123 ck_abort();
7124 }
7125
7126 assert_touchpad_does_not_move(tp);
7127
7128 /* First reason for suspend: off */
7129 switch (first) {
7130 case SUSPEND_EXT_MOUSE:
7131 litest_sendevents_on(tp);
7132 break;
7133 case SUSPEND_TABLETMODE:
7134 litest_switch_action(tabletmode,
7135 LIBINPUT_SWITCH_TABLET_MODE,
7136 LIBINPUT_SWITCH_STATE_OFF);
7137 break;
7138 case SUSPEND_LID:
7139 litest_switch_action(lid,
7140 LIBINPUT_SWITCH_LID,
7141 LIBINPUT_SWITCH_STATE_OFF);
7142 break;
7143 case SUSPEND_SENDEVENTS:
7144 litest_sendevents_on(tp);
7145 break;
7146 default:
7147 ck_abort();
7148 }
7149
7150 litest_drain_events(li);
7151 assert_touchpad_does_not_move(tp);
7152
7153 /* Second reason to suspend: off */
7154 switch (other) {
7155 case SUSPEND_EXT_MOUSE:
7156 litest_sendevents_on(tp);
7157 break;
7158 case SUSPEND_LID:
7159 litest_switch_action(lid,
7160 LIBINPUT_SWITCH_LID,
7161 LIBINPUT_SWITCH_STATE_OFF);
7162 litest_drain_events(li);
7163 break;
7164 case SUSPEND_TABLETMODE:
7165 litest_switch_action(tabletmode,
7166 LIBINPUT_SWITCH_TABLET_MODE,
7167 LIBINPUT_SWITCH_STATE_OFF);
7168 litest_drain_events(li);
7169 break;
7170 case SUSPEND_SENDEVENTS:
7171 litest_sendevents_on(tp);
7172 break;
7173 default:
7174 ck_abort();
7175 }
7176
7177 litest_drain_events(li);
7178 assert_touchpad_moves(tp);
7179 }
7180
7181 out:
7182 litest_ungrab_device(lid);
7183 litest_ungrab_device(tabletmode);
7184 litest_delete_device(lid);
7185 litest_delete_device(tabletmode);
7186 litest_delete_device(extmouse);
7187 }
7188 END_TEST
7189
START_TEST(touchpad_end_start_touch)7190 START_TEST(touchpad_end_start_touch)
7191 {
7192 struct litest_device *dev = litest_current_device();
7193 struct libinput *li = dev->libinput;
7194
7195 litest_enable_tap(dev->libinput_device);
7196 litest_disable_hold_gestures(dev->libinput_device);
7197 litest_drain_events(li);
7198
7199 litest_touch_down(dev, 0, 50, 50);
7200 litest_touch_move(dev, 0, 50.1, 50.1);
7201 libinput_dispatch(li);
7202
7203 litest_push_event_frame(dev);
7204 litest_touch_up(dev, 0);
7205 litest_touch_down(dev, 0, 50.2, 50.2);
7206 litest_pop_event_frame(dev);
7207
7208 litest_disable_log_handler(li);
7209 libinput_dispatch(li);
7210 litest_restore_log_handler(li);
7211
7212 litest_assert_empty_queue(li);
7213
7214 litest_timeout_tap();
7215 libinput_dispatch(li);
7216
7217 litest_touch_move_to(dev, 0, 50.2, 50.2, 50, 70, 10);
7218 litest_touch_up(dev, 0);
7219
7220 litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
7221 }
7222 END_TEST
7223
START_TEST(touchpad_fuzz)7224 START_TEST(touchpad_fuzz)
7225 {
7226 struct litest_device *dev = litest_current_device();
7227 struct libevdev *evdev = dev->evdev;
7228
7229 /* We expect our udev callout to always set this to 0 */
7230 ck_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_X), 0);
7231 ck_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_Y), 0);
7232
7233 if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X))
7234 ck_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_MT_POSITION_X), 0);
7235 if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y))
7236 ck_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_MT_POSITION_Y), 0);
7237 }
7238 END_TEST
7239
TEST_COLLECTION(touchpad)7240 TEST_COLLECTION(touchpad)
7241 {
7242 struct range suspends = { SUSPEND_EXT_MOUSE, SUSPEND_COUNT };
7243 struct range axis_range = {ABS_X, ABS_Y + 1};
7244 struct range twice = {0, 2 };
7245 struct range five_fingers = {1, 6};
7246
7247 litest_add(touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
7248 litest_add(touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7249
7250 litest_add(touchpad_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
7251 litest_add(touchpad_2fg_scroll_initially_diagonal, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
7252 litest_add(touchpad_2fg_scroll_axis_lock, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
7253 litest_add(touchpad_2fg_scroll_axis_lock_switch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
7254
7255 litest_add(touchpad_2fg_scroll_slow_distance, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7256 litest_add(touchpad_2fg_scroll_return_to_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7257 litest_add(touchpad_2fg_scroll_source, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7258 litest_add(touchpad_2fg_scroll_semi_mt, LITEST_SEMI_MT, LITEST_SINGLE_TOUCH);
7259 litest_add(touchpad_2fg_scroll_from_btnareas, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7260 litest_add(touchpad_scroll_natural_defaults, LITEST_TOUCHPAD, LITEST_ANY);
7261 litest_add(touchpad_scroll_natural_enable_config, LITEST_TOUCHPAD, LITEST_ANY);
7262 litest_add(touchpad_scroll_natural_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7263 litest_add(touchpad_scroll_natural_edge, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7264 litest_add(touchpad_scroll_defaults, LITEST_TOUCHPAD, LITEST_ANY);
7265 litest_add(touchpad_edge_scroll_vert, LITEST_TOUCHPAD, LITEST_ANY);
7266 litest_add(touchpad_edge_scroll_horiz, LITEST_TOUCHPAD, LITEST_CLICKPAD);
7267 litest_add(touchpad_edge_scroll_horiz_clickpad, LITEST_CLICKPAD, LITEST_ANY);
7268 litest_add(touchpad_edge_scroll_no_horiz, LITEST_TOUCHPAD, LITEST_CLICKPAD);
7269 litest_add(touchpad_edge_scroll_no_motion, LITEST_TOUCHPAD, LITEST_ANY);
7270 litest_add(touchpad_edge_scroll_no_edge_after_motion, LITEST_TOUCHPAD, LITEST_ANY);
7271 litest_add(touchpad_edge_scroll_timeout, LITEST_TOUCHPAD, LITEST_ANY);
7272 litest_add(touchpad_edge_scroll_source, LITEST_TOUCHPAD, LITEST_ANY);
7273 litest_add(touchpad_edge_scroll_no_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7274 litest_add(touchpad_edge_scroll_into_buttonareas, LITEST_CLICKPAD, LITEST_ANY);
7275 litest_add(touchpad_edge_scroll_within_buttonareas, LITEST_CLICKPAD, LITEST_ANY);
7276 litest_add(touchpad_edge_scroll_buttonareas_click_stops_scroll, LITEST_CLICKPAD, LITEST_ANY);
7277 litest_add(touchpad_edge_scroll_clickfinger_click_stops_scroll, LITEST_CLICKPAD, LITEST_ANY);
7278 litest_add(touchpad_edge_scroll_into_area, LITEST_TOUCHPAD, LITEST_ANY);
7279
7280 litest_add(touchpad_palm_detect_at_edge, LITEST_TOUCHPAD, LITEST_ANY);
7281 litest_add(touchpad_palm_detect_at_top, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD);
7282 litest_add(touchpad_palm_detect_at_bottom_corners, LITEST_TOUCHPAD, LITEST_CLICKPAD);
7283 litest_add(touchpad_palm_detect_at_top_corners, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD);
7284 litest_add(touchpad_palm_detect_palm_becomes_pointer, LITEST_TOUCHPAD, LITEST_ANY);
7285 litest_add(touchpad_palm_detect_top_palm_becomes_pointer, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD);
7286 litest_add(touchpad_palm_detect_palm_stays_palm, LITEST_TOUCHPAD, LITEST_ANY);
7287 litest_add(touchpad_palm_detect_top_palm_stays_palm, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD);
7288 litest_add(touchpad_palm_detect_no_palm_moving_into_edges, LITEST_TOUCHPAD, LITEST_ANY);
7289 litest_add(touchpad_palm_detect_no_palm_moving_into_top, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD);
7290 litest_add(touchpad_palm_detect_no_tap_top_edge, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD);
7291 litest_add(touchpad_palm_detect_tap_hardbuttons, LITEST_TOUCHPAD, LITEST_CLICKPAD);
7292 litest_add(touchpad_palm_detect_tap_softbuttons, LITEST_CLICKPAD, LITEST_ANY);
7293 litest_add(touchpad_palm_detect_tap_clickfinger, LITEST_CLICKPAD, LITEST_ANY);
7294 litest_add(touchpad_no_palm_detect_at_edge_for_edge_scrolling, LITEST_TOUCHPAD, LITEST_CLICKPAD);
7295 litest_add(touchpad_no_palm_detect_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7296 litest_add(touchpad_palm_detect_both_edges, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7297 litest_add(touchpad_palm_detect_tool_palm, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7298 litest_add(touchpad_palm_detect_tool_palm_on_off, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7299 litest_add(touchpad_palm_detect_tool_palm_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7300 litest_add(touchpad_palm_detect_tool_palm_tap_after, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7301
7302 litest_add(touchpad_palm_detect_touch_size, LITEST_APPLE_CLICKPAD, LITEST_ANY);
7303 litest_add(touchpad_palm_detect_touch_size_late, LITEST_APPLE_CLICKPAD, LITEST_ANY);
7304 litest_add(touchpad_palm_detect_touch_size_keep_palm, LITEST_APPLE_CLICKPAD, LITEST_ANY);
7305 litest_add(touchpad_palm_detect_touch_size_after_edge, LITEST_APPLE_CLICKPAD, LITEST_ANY);
7306 litest_add(touchpad_palm_detect_touch_size_after_dwt, LITEST_APPLE_CLICKPAD, LITEST_ANY);
7307
7308 litest_add(touchpad_palm_detect_pressure, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7309 litest_add(touchpad_palm_detect_pressure_late_tap, LITEST_CLICKPAD, LITEST_ANY);
7310 litest_add(touchpad_palm_detect_pressure_tap_hold, LITEST_CLICKPAD, LITEST_ANY);
7311 litest_add(touchpad_palm_detect_pressure_tap_hold_2ndfg, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
7312 litest_add(touchpad_palm_detect_move_and_tap, LITEST_TOUCHPAD, LITEST_ANY);
7313 litest_add(touchpad_palm_detect_pressure_late, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7314 litest_add(touchpad_palm_detect_pressure_keep_palm, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7315 litest_add(touchpad_palm_detect_pressure_after_edge, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7316 litest_add(touchpad_palm_detect_pressure_after_dwt, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7317 litest_add_for_device(touchpad_palm_ignore_threshold_zero, LITEST_TOUCHPAD_PALMPRESSURE_ZERO);
7318
7319 litest_add(touchpad_palm_clickfinger_pressure, LITEST_CLICKPAD, LITEST_ANY);
7320 litest_add(touchpad_palm_clickfinger_pressure_2fg, LITEST_CLICKPAD, LITEST_ANY);
7321 litest_add(touchpad_palm_clickfinger_size, LITEST_CLICKPAD, LITEST_ANY);
7322 litest_add(touchpad_palm_clickfinger_size_2fg, LITEST_CLICKPAD, LITEST_ANY);
7323
7324 litest_add(touchpad_left_handed, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD);
7325 litest_add_for_device(touchpad_left_handed_appletouch, LITEST_APPLETOUCH);
7326 litest_add(touchpad_left_handed_clickpad, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
7327 litest_add(touchpad_left_handed_clickfinger, LITEST_APPLE_CLICKPAD, LITEST_ANY);
7328 litest_add(touchpad_left_handed_tapping, LITEST_TOUCHPAD, LITEST_ANY);
7329 litest_add(touchpad_left_handed_tapping_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7330 litest_add(touchpad_left_handed_delayed, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD);
7331 litest_add(touchpad_left_handed_clickpad_delayed, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
7332 litest_add(touchpad_left_handed_rotation, LITEST_TOUCHPAD, LITEST_ANY);
7333
7334 /* Semi-MT hover tests aren't generic, they only work on this device and
7335 * ignore the semi-mt capability (it doesn't matter for the tests) */
7336 litest_add_for_device(touchpad_semi_mt_hover_noevent, LITEST_SYNAPTICS_HOVER_SEMI_MT);
7337 litest_add_for_device(touchpad_semi_mt_hover_down, LITEST_SYNAPTICS_HOVER_SEMI_MT);
7338 litest_add_for_device(touchpad_semi_mt_hover_down_up, LITEST_SYNAPTICS_HOVER_SEMI_MT);
7339 litest_add_for_device(touchpad_semi_mt_hover_down_hover_down, LITEST_SYNAPTICS_HOVER_SEMI_MT);
7340 litest_add_for_device(touchpad_semi_mt_hover_2fg_noevent, LITEST_SYNAPTICS_HOVER_SEMI_MT);
7341 litest_add_for_device(touchpad_semi_mt_hover_2fg_1fg_down, LITEST_SYNAPTICS_HOVER_SEMI_MT);
7342 litest_add_for_device(touchpad_semi_mt_hover_2fg_up, LITEST_SYNAPTICS_HOVER_SEMI_MT);
7343
7344 litest_add(touchpad_hover_noevent, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY);
7345 litest_add(touchpad_hover_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY);
7346 litest_add(touchpad_hover_down_up, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY);
7347 litest_add(touchpad_hover_down_hover_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY);
7348 litest_add(touchpad_hover_2fg_noevent, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY);
7349 litest_add(touchpad_hover_2fg_1fg_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY);
7350 litest_add(touchpad_hover_1fg_tap, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY);
7351
7352 litest_add_for_device(touchpad_trackpoint_buttons, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS);
7353 litest_add_for_device(touchpad_trackpoint_mb_scroll, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS);
7354 litest_add_for_device(touchpad_trackpoint_mb_click, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS);
7355 litest_add_for_device(touchpad_trackpoint_buttons_softbuttons, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS);
7356 litest_add_for_device(touchpad_trackpoint_buttons_2fg_scroll, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS);
7357 litest_add_for_device(touchpad_trackpoint_no_trackpoint, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS);
7358
7359 litest_add_ranged(touchpad_initial_state, LITEST_TOUCHPAD, LITEST_ANY, &axis_range);
7360 litest_add_ranged(touchpad_fingers_down_before_init, LITEST_TOUCHPAD, LITEST_ANY, &five_fingers);
7361 litest_add(touchpad_state_after_syn_dropped_2fg_change, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7362
7363 litest_add(touchpad_dwt, LITEST_TOUCHPAD, LITEST_ANY);
7364 litest_add_for_device(touchpad_dwt_ext_and_int_keyboard, LITEST_SYNAPTICS_I2C);
7365 litest_add(touchpad_dwt_enable_touch, LITEST_TOUCHPAD, LITEST_ANY);
7366 litest_add(touchpad_dwt_touch_hold, LITEST_TOUCHPAD, LITEST_ANY);
7367 litest_add(touchpad_dwt_key_hold, LITEST_TOUCHPAD, LITEST_ANY);
7368 litest_add(touchpad_dwt_key_hold_timeout, LITEST_TOUCHPAD, LITEST_ANY);
7369 litest_add(touchpad_dwt_key_hold_timeout_existing_touch, LITEST_TOUCHPAD, LITEST_ANY);
7370 litest_add(touchpad_dwt_key_hold_timeout_existing_touch_cornercase, LITEST_TOUCHPAD, LITEST_ANY);
7371 litest_add(touchpad_dwt_type, LITEST_TOUCHPAD, LITEST_ANY);
7372 litest_add(touchpad_dwt_type_short_timeout, LITEST_TOUCHPAD, LITEST_ANY);
7373 litest_add(touchpad_dwt_modifier_no_dwt, LITEST_TOUCHPAD, LITEST_ANY);
7374 litest_add(touchpad_dwt_modifier_combo_no_dwt, LITEST_TOUCHPAD, LITEST_ANY);
7375 litest_add(touchpad_dwt_modifier_combo_dwt_after, LITEST_TOUCHPAD, LITEST_ANY);
7376 litest_add(touchpad_dwt_modifier_combo_dwt_remains, LITEST_TOUCHPAD, LITEST_ANY);
7377 litest_add(touchpad_dwt_fkeys_no_dwt, LITEST_TOUCHPAD, LITEST_ANY);
7378 litest_add(touchpad_dwt_tap, LITEST_TOUCHPAD, LITEST_ANY);
7379 litest_add(touchpad_dwt_tap_drag, LITEST_TOUCHPAD, LITEST_ANY);
7380 litest_add(touchpad_dwt_click, LITEST_TOUCHPAD, LITEST_ANY);
7381 litest_add(touchpad_dwt_edge_scroll, LITEST_TOUCHPAD, LITEST_CLICKPAD);
7382 litest_add(touchpad_dwt_edge_scroll_interrupt, LITEST_TOUCHPAD, LITEST_CLICKPAD);
7383 litest_add(touchpad_dwt_config_default_on, LITEST_TOUCHPAD, LITEST_ANY);
7384 litest_add(touchpad_dwt_config_default_off, LITEST_ANY, LITEST_TOUCHPAD);
7385 litest_add(touchpad_dwt_disabled, LITEST_TOUCHPAD, LITEST_ANY);
7386 litest_add(touchpad_dwt_disable_during_touch, LITEST_TOUCHPAD, LITEST_ANY);
7387 litest_add(touchpad_dwt_disable_before_touch, LITEST_TOUCHPAD, LITEST_ANY);
7388 litest_add(touchpad_dwt_disable_during_key_release, LITEST_TOUCHPAD, LITEST_ANY);
7389 litest_add(touchpad_dwt_disable_during_key_hold, LITEST_TOUCHPAD, LITEST_ANY);
7390 litest_add(touchpad_dwt_enable_during_touch, LITEST_TOUCHPAD, LITEST_ANY);
7391 litest_add(touchpad_dwt_enable_before_touch, LITEST_TOUCHPAD, LITEST_ANY);
7392 litest_add(touchpad_dwt_enable_during_tap, LITEST_TOUCHPAD, LITEST_ANY);
7393 litest_add(touchpad_dwt_remove_kbd_while_active, LITEST_TOUCHPAD, LITEST_ANY);
7394 litest_add(touchpad_dwtp_config_default_on, LITEST_TOUCHPAD, LITEST_ANY);
7395 litest_add(touchpad_dwtp_config_default_off, LITEST_ANY, LITEST_TOUCHPAD);
7396 litest_add_for_device(touchpad_dwt_apple, LITEST_BCM5974);
7397 litest_add_for_device(touchpad_dwt_acer_hawaii, LITEST_ACER_HAWAII_TOUCHPAD);
7398 litest_add_for_device(touchpad_dwt_multiple_keyboards, LITEST_SYNAPTICS_I2C);
7399 litest_add_for_device(touchpad_dwt_multiple_keyboards_bothkeys, LITEST_SYNAPTICS_I2C);
7400 litest_add_for_device(touchpad_dwt_multiple_keyboards_bothkeys_modifier, LITEST_SYNAPTICS_I2C);
7401 litest_add_ranged_for_device(touchpad_dwt_multiple_keyboards_remove, LITEST_SYNAPTICS_I2C, &twice);
7402 litest_add_for_device(touchpad_dwt_remove_before_keyboard, LITEST_KEYBOARD);
7403
7404 litest_add(touchpad_thumb_lower_area_movement, LITEST_CLICKPAD, LITEST_ANY);
7405 litest_add(touchpad_thumb_lower_area_movement_rethumb, LITEST_CLICKPAD, LITEST_ANY);
7406 litest_add(touchpad_thumb_speed_empty_slots, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7407 litest_add(touchpad_thumb_area_clickfinger, LITEST_CLICKPAD, LITEST_ANY);
7408 litest_add(touchpad_thumb_area_btnarea, LITEST_CLICKPAD, LITEST_ANY);
7409 litest_add(touchpad_thumb_no_doublethumb, LITEST_CLICKPAD, LITEST_ANY);
7410
7411 litest_add_for_device(touchpad_tool_tripletap_touch_count, LITEST_SYNAPTICS_TOPBUTTONPAD);
7412 litest_add_for_device(touchpad_tool_tripletap_touch_count_late, LITEST_SYNAPTICS_TOPBUTTONPAD);
7413 litest_add_for_device(touchpad_slot_swap, LITEST_SYNAPTICS_TOPBUTTONPAD);
7414 litest_add_for_device(touchpad_finger_always_down, LITEST_SYNAPTICS_TOPBUTTONPAD);
7415
7416 litest_add(touchpad_time_usec, LITEST_TOUCHPAD, LITEST_ANY);
7417
7418 litest_add_for_device(touchpad_jump_finger_motion, LITEST_SYNAPTICS_CLICKPAD_X220);
7419 litest_add_for_device(touchpad_jump_delta, LITEST_SYNAPTICS_CLICKPAD_X220);
7420
7421 litest_add_for_device(touchpad_disabled_on_mouse, LITEST_SYNAPTICS_CLICKPAD_X220);
7422 litest_add_for_device(touchpad_disabled_on_mouse_suspend_mouse, LITEST_SYNAPTICS_CLICKPAD_X220);
7423 litest_add_for_device(touchpad_disabled_double_mouse, LITEST_SYNAPTICS_CLICKPAD_X220);
7424 litest_add_for_device(touchpad_disabled_double_mouse_one_suspended, LITEST_SYNAPTICS_CLICKPAD_X220);
7425
7426 litest_add(touchpad_pressure, LITEST_TOUCHPAD, LITEST_ANY);
7427 litest_add(touchpad_pressure_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7428 litest_add(touchpad_pressure_2fg_st, LITEST_TOUCHPAD|LITEST_SINGLE_TOUCH, LITEST_ANY);
7429 litest_add(touchpad_pressure_tap, LITEST_TOUCHPAD, LITEST_ANY);
7430 litest_add(touchpad_pressure_tap_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7431 litest_add(touchpad_pressure_tap_2fg_1fg_light, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7432 litest_add(touchpad_pressure_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
7433 litest_add(touchpad_pressure_semi_mt_2fg_goes_light, LITEST_SEMI_MT, LITEST_ANY);
7434
7435 litest_add(touchpad_touch_size, LITEST_APPLE_CLICKPAD, LITEST_ANY);
7436 litest_add(touchpad_touch_size_2fg, LITEST_APPLE_CLICKPAD, LITEST_ANY);
7437
7438 litest_add(touchpad_speed_ignore_finger, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
7439 litest_add(touchpad_speed_allow_nearby_finger, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
7440 litest_add(touchpad_speed_ignore_finger_edgescroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
7441 litest_add_for_device(touchpad_speed_ignore_hovering_finger, LITEST_BCM5974);
7442
7443 litest_add_ranged(touchpad_suspend_abba, LITEST_TOUCHPAD, LITEST_ANY, &suspends);
7444 litest_add_ranged(touchpad_suspend_abab, LITEST_TOUCHPAD, LITEST_ANY, &suspends);
7445
7446 /* Happens on the "Wacom Intuos Pro M Finger" but our test device
7447 * has the same properties */
7448 litest_add_for_device(touchpad_end_start_touch, LITEST_WACOM_FINGER);
7449
7450 litest_add(touchpad_fuzz, LITEST_TOUCHPAD, LITEST_ANY);
7451 }
7452