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