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