2 * Copyright © 2014 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 #include "libinput-util.h"
34 START_TEST(touchpad_1fg_motion)
36 struct litest_device *dev = litest_current_device();
37 struct libinput *li = dev->libinput;
38 struct libinput_event *event;
39 struct libinput_event_pointer *ptrev;
41 litest_drain_events(li);
43 litest_touch_down(dev, 0, 50, 50);
44 litest_touch_move_to(dev, 0, 50, 50, 80, 50, 5);
45 litest_touch_up(dev, 0);
47 libinput_dispatch(li);
49 event = libinput_get_event(li);
50 ck_assert(event != NULL);
53 ck_assert_int_eq(libinput_event_get_type(event),
54 LIBINPUT_EVENT_POINTER_MOTION);
56 ptrev = libinput_event_get_pointer_event(event);
57 ck_assert_int_ge(libinput_event_pointer_get_dx(ptrev), 0);
58 ck_assert_int_eq(libinput_event_pointer_get_dy(ptrev), 0);
59 libinput_event_destroy(event);
60 event = libinput_get_event(li);
65 START_TEST(touchpad_2fg_no_motion)
67 struct litest_device *dev = litest_current_device();
68 struct libinput *li = dev->libinput;
69 struct libinput_event *event;
71 litest_drain_events(li);
73 litest_touch_down(dev, 0, 20, 20);
74 litest_touch_down(dev, 1, 70, 20);
75 litest_touch_move_to(dev, 0, 20, 20, 80, 80, 5);
76 litest_touch_move_to(dev, 1, 70, 20, 80, 50, 5);
77 litest_touch_up(dev, 1);
78 litest_touch_up(dev, 0);
80 libinput_dispatch(li);
82 event = libinput_get_event(li);
84 ck_assert_int_ne(libinput_event_get_type(event),
85 LIBINPUT_EVENT_POINTER_MOTION);
86 libinput_event_destroy(event);
87 event = libinput_get_event(li);
93 assert_button_event(struct libinput *li, unsigned int button,
94 enum libinput_button_state state)
96 struct libinput_event *event;
97 struct libinput_event_pointer *ptrev;
99 libinput_dispatch(li);
100 event = libinput_get_event(li);
102 ck_assert(event != NULL);
103 ck_assert_int_eq(libinput_event_get_type(event),
104 LIBINPUT_EVENT_POINTER_BUTTON);
105 ptrev = libinput_event_get_pointer_event(event);
106 ck_assert_int_eq(libinput_event_pointer_get_button(ptrev),
108 ck_assert_int_eq(libinput_event_pointer_get_button_state(ptrev),
110 libinput_event_destroy(event);
113 START_TEST(touchpad_1fg_tap)
115 struct litest_device *dev = litest_current_device();
116 struct libinput *li = dev->libinput;
117 struct libinput_event *event;
119 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
121 litest_drain_events(li);
123 litest_touch_down(dev, 0, 50, 50);
124 litest_touch_up(dev, 0);
126 libinput_dispatch(li);
128 assert_button_event(li, BTN_LEFT,
129 LIBINPUT_BUTTON_STATE_PRESSED);
130 msleep(300); /* tap-n-drag timeout */
131 assert_button_event(li, BTN_LEFT,
132 LIBINPUT_BUTTON_STATE_RELEASED);
134 libinput_dispatch(li);
135 event = libinput_get_event(li);
136 ck_assert(event == NULL);
140 START_TEST(touchpad_1fg_tap_n_drag)
142 struct litest_device *dev = litest_current_device();
143 struct libinput *li = dev->libinput;
144 struct libinput_event *event;
146 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
148 litest_drain_events(li);
150 litest_touch_down(dev, 0, 50, 50);
151 litest_touch_up(dev, 0);
152 litest_touch_down(dev, 0, 50, 50);
153 litest_touch_move_to(dev, 0, 50, 50, 80, 80, 5);
154 litest_touch_up(dev, 0);
156 libinput_dispatch(li);
158 assert_button_event(li, BTN_LEFT,
159 LIBINPUT_BUTTON_STATE_PRESSED);
161 libinput_dispatch(li);
162 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
163 event = libinput_get_event(li);
164 libinput_event_destroy(event);
165 libinput_dispatch(li);
168 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
170 /* lift finger, set down again, should continue dragging */
171 litest_touch_down(dev, 0, 50, 50);
172 litest_touch_move_to(dev, 0, 50, 50, 80, 80, 5);
173 litest_touch_up(dev, 0);
175 libinput_dispatch(li);
176 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
177 event = libinput_get_event(li);
178 libinput_event_destroy(event);
179 libinput_dispatch(li);
182 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
184 msleep(300); /* tap-n-drag timeout */
186 assert_button_event(li, BTN_LEFT,
187 LIBINPUT_BUTTON_STATE_RELEASED);
189 litest_assert_empty_queue(li);
193 START_TEST(touchpad_2fg_tap)
195 struct litest_device *dev = litest_current_device();
196 struct libinput *li = dev->libinput;
198 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
200 litest_drain_events(dev->libinput);
202 litest_touch_down(dev, 0, 50, 50);
203 litest_touch_down(dev, 1, 70, 70);
204 litest_touch_up(dev, 0);
205 litest_touch_up(dev, 1);
207 libinput_dispatch(li);
209 assert_button_event(li, BTN_RIGHT,
210 LIBINPUT_BUTTON_STATE_PRESSED);
211 msleep(300); /* tap-n-drag timeout */
212 assert_button_event(li, BTN_RIGHT,
213 LIBINPUT_BUTTON_STATE_RELEASED);
215 litest_assert_empty_queue(li);
219 START_TEST(touchpad_2fg_tap_inverted)
221 struct litest_device *dev = litest_current_device();
222 struct libinput *li = dev->libinput;
224 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
226 litest_drain_events(dev->libinput);
228 litest_touch_down(dev, 0, 50, 50);
229 litest_touch_down(dev, 1, 70, 70);
230 litest_touch_up(dev, 1);
231 litest_touch_up(dev, 0);
233 libinput_dispatch(li);
235 assert_button_event(li, BTN_RIGHT,
236 LIBINPUT_BUTTON_STATE_PRESSED);
237 msleep(300); /* tap-n-drag timeout */
238 assert_button_event(li, BTN_RIGHT,
239 LIBINPUT_BUTTON_STATE_RELEASED);
241 litest_assert_empty_queue(li);
245 START_TEST(touchpad_1fg_tap_click)
247 struct litest_device *dev = litest_current_device();
248 struct libinput *li = dev->libinput;
250 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
252 litest_drain_events(dev->libinput);
254 /* finger down, button click, finger up
255 -> only one button left event pair */
256 litest_touch_down(dev, 0, 50, 50);
257 litest_event(dev, EV_KEY, BTN_LEFT, 1);
258 litest_event(dev, EV_SYN, SYN_REPORT, 0);
259 litest_event(dev, EV_KEY, BTN_LEFT, 0);
260 litest_event(dev, EV_SYN, SYN_REPORT, 0);
261 litest_touch_up(dev, 0);
263 libinput_dispatch(li);
265 assert_button_event(li, BTN_LEFT,
266 LIBINPUT_BUTTON_STATE_PRESSED);
267 assert_button_event(li, BTN_LEFT,
268 LIBINPUT_BUTTON_STATE_RELEASED);
270 litest_assert_empty_queue(li);
274 START_TEST(touchpad_2fg_tap_click)
276 struct litest_device *dev = litest_current_device();
277 struct libinput *li = dev->libinput;
279 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
281 litest_drain_events(dev->libinput);
283 /* two fingers down, button click, fingers up
284 -> only one button left event pair */
285 litest_touch_down(dev, 0, 50, 50);
286 litest_touch_down(dev, 1, 70, 50);
287 litest_event(dev, EV_KEY, BTN_LEFT, 1);
288 litest_event(dev, EV_SYN, SYN_REPORT, 0);
289 litest_event(dev, EV_KEY, BTN_LEFT, 0);
290 litest_event(dev, EV_SYN, SYN_REPORT, 0);
291 litest_touch_up(dev, 1);
292 litest_touch_up(dev, 0);
294 libinput_dispatch(li);
296 assert_button_event(li, BTN_LEFT,
297 LIBINPUT_BUTTON_STATE_PRESSED);
298 assert_button_event(li, BTN_LEFT,
299 LIBINPUT_BUTTON_STATE_RELEASED);
301 litest_assert_empty_queue(li);
305 START_TEST(touchpad_2fg_tap_click_apple)
307 struct litest_device *dev = litest_current_device();
308 struct libinput *li = dev->libinput;
310 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
312 litest_drain_events(dev->libinput);
314 /* two fingers down, button click, fingers up
315 -> only one button right event pair
316 (apple have clickfinger enabled by default) */
317 litest_touch_down(dev, 0, 50, 50);
318 litest_touch_down(dev, 1, 70, 50);
319 litest_event(dev, EV_KEY, BTN_LEFT, 1);
320 litest_event(dev, EV_SYN, SYN_REPORT, 0);
321 litest_event(dev, EV_KEY, BTN_LEFT, 0);
322 litest_event(dev, EV_SYN, SYN_REPORT, 0);
323 litest_touch_up(dev, 1);
324 litest_touch_up(dev, 0);
326 libinput_dispatch(li);
328 assert_button_event(li, BTN_RIGHT,
329 LIBINPUT_BUTTON_STATE_PRESSED);
330 assert_button_event(li, BTN_RIGHT,
331 LIBINPUT_BUTTON_STATE_RELEASED);
333 litest_assert_empty_queue(li);
337 START_TEST(touchpad_no_2fg_tap_after_move)
339 struct litest_device *dev = litest_current_device();
340 struct libinput *li = dev->libinput;
342 litest_drain_events(dev->libinput);
344 /* one finger down, move past threshold,
345 second finger down, first finger up
348 litest_touch_down(dev, 0, 50, 50);
349 litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
350 litest_drain_events(dev->libinput);
352 litest_touch_down(dev, 1, 70, 50);
353 litest_touch_up(dev, 0);
355 litest_assert_empty_queue(li);
359 START_TEST(touchpad_no_2fg_tap_after_timeout)
361 struct litest_device *dev = litest_current_device();
362 struct libinput *li = dev->libinput;
364 litest_drain_events(dev->libinput);
366 /* one finger down, wait past tap timeout,
367 second finger down, first finger up
370 litest_touch_down(dev, 0, 50, 50);
371 libinput_dispatch(dev->libinput);
373 libinput_dispatch(dev->libinput);
374 litest_drain_events(dev->libinput);
376 litest_touch_down(dev, 1, 70, 50);
377 litest_touch_up(dev, 0);
379 litest_assert_empty_queue(li);
383 START_TEST(touchpad_no_first_fg_tap_after_move)
385 struct litest_device *dev = litest_current_device();
386 struct libinput *li = dev->libinput;
387 struct libinput_event *event;
389 litest_drain_events(dev->libinput);
391 /* one finger down, second finger down,
392 second finger moves beyond threshold,
396 litest_touch_down(dev, 0, 50, 50);
397 litest_touch_down(dev, 1, 70, 50);
398 libinput_dispatch(dev->libinput);
399 litest_touch_move_to(dev, 1, 70, 50, 90, 90, 10);
400 libinput_dispatch(dev->libinput);
401 litest_touch_up(dev, 0);
402 litest_touch_up(dev, 1);
403 libinput_dispatch(dev->libinput);
405 while ((event = libinput_get_event(li))) {
406 ck_assert_int_ne(libinput_event_get_type(event),
407 LIBINPUT_EVENT_POINTER_BUTTON);
408 libinput_event_destroy(event);
413 START_TEST(touchpad_1fg_double_tap_click)
415 struct litest_device *dev = litest_current_device();
416 struct libinput *li = dev->libinput;
418 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
420 litest_drain_events(dev->libinput);
422 /* one finger down, up, down, button click, finger up
423 -> two button left event pairs */
424 litest_touch_down(dev, 0, 50, 50);
425 litest_touch_up(dev, 0);
426 litest_touch_down(dev, 0, 50, 50);
427 litest_event(dev, EV_KEY, BTN_LEFT, 1);
428 litest_event(dev, EV_SYN, SYN_REPORT, 0);
429 litest_event(dev, EV_KEY, BTN_LEFT, 0);
430 litest_event(dev, EV_SYN, SYN_REPORT, 0);
431 litest_touch_up(dev, 0);
433 libinput_dispatch(li);
435 assert_button_event(li, BTN_LEFT,
436 LIBINPUT_BUTTON_STATE_PRESSED);
437 assert_button_event(li, BTN_LEFT,
438 LIBINPUT_BUTTON_STATE_RELEASED);
439 assert_button_event(li, BTN_LEFT,
440 LIBINPUT_BUTTON_STATE_PRESSED);
441 assert_button_event(li, BTN_LEFT,
442 LIBINPUT_BUTTON_STATE_RELEASED);
444 litest_assert_empty_queue(li);
448 START_TEST(touchpad_1fg_tap_n_drag_click)
450 struct litest_device *dev = litest_current_device();
451 struct libinput *li = dev->libinput;
452 struct libinput_event *event;
454 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
456 litest_drain_events(dev->libinput);
458 /* one finger down, up, down, move, button click, finger up
459 -> two button left event pairs, motion allowed */
460 litest_touch_down(dev, 0, 50, 50);
461 litest_touch_up(dev, 0);
462 litest_touch_down(dev, 0, 50, 50);
463 litest_touch_move_to(dev, 0, 50, 50, 80, 50, 10);
465 assert_button_event(li, BTN_LEFT,
466 LIBINPUT_BUTTON_STATE_PRESSED);
468 libinput_dispatch(li);
470 ck_assert_int_eq(libinput_next_event_type(li),
471 LIBINPUT_EVENT_POINTER_MOTION);
472 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
473 event = libinput_get_event(li);
474 libinput_event_destroy(event);
475 libinput_dispatch(li);
478 litest_event(dev, EV_KEY, BTN_LEFT, 1);
479 litest_event(dev, EV_SYN, SYN_REPORT, 0);
481 assert_button_event(li, BTN_LEFT,
482 LIBINPUT_BUTTON_STATE_RELEASED);
483 assert_button_event(li, BTN_LEFT,
484 LIBINPUT_BUTTON_STATE_PRESSED);
486 litest_event(dev, EV_KEY, BTN_LEFT, 0);
487 litest_event(dev, EV_SYN, SYN_REPORT, 0);
488 litest_touch_up(dev, 0);
490 libinput_dispatch(li);
492 assert_button_event(li, BTN_LEFT,
493 LIBINPUT_BUTTON_STATE_RELEASED);
495 litest_assert_empty_queue(li);
499 START_TEST(touchpad_1fg_clickfinger)
501 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
502 struct libinput *li = dev->libinput;
504 litest_drain_events(li);
506 litest_touch_down(dev, 0, 50, 50);
507 litest_event(dev, EV_KEY, BTN_LEFT, 1);
508 litest_event(dev, EV_SYN, SYN_REPORT, 0);
509 litest_event(dev, EV_KEY, BTN_LEFT, 0);
510 litest_event(dev, EV_SYN, SYN_REPORT, 0);
511 litest_touch_up(dev, 0);
513 libinput_dispatch(li);
515 assert_button_event(li, BTN_LEFT,
516 LIBINPUT_BUTTON_STATE_PRESSED);
517 assert_button_event(li, BTN_LEFT,
518 LIBINPUT_BUTTON_STATE_RELEASED);
520 litest_delete_device(dev);
524 START_TEST(touchpad_2fg_clickfinger)
526 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
527 struct libinput *li = dev->libinput;
529 litest_drain_events(li);
531 litest_touch_down(dev, 0, 50, 50);
532 litest_touch_down(dev, 1, 70, 70);
533 litest_event(dev, EV_KEY, BTN_LEFT, 1);
534 litest_event(dev, EV_SYN, SYN_REPORT, 0);
535 litest_event(dev, EV_KEY, BTN_LEFT, 0);
536 litest_event(dev, EV_SYN, SYN_REPORT, 0);
537 litest_touch_up(dev, 0);
538 litest_touch_up(dev, 1);
540 libinput_dispatch(li);
542 assert_button_event(li, BTN_RIGHT,
543 LIBINPUT_BUTTON_STATE_PRESSED);
544 assert_button_event(li, BTN_RIGHT,
545 LIBINPUT_BUTTON_STATE_RELEASED);
547 litest_delete_device(dev);
551 START_TEST(touchpad_btn_left)
553 struct litest_device *dev = litest_current_device();
554 struct libinput *li = dev->libinput;
556 litest_drain_events(li);
558 litest_event(dev, EV_KEY, BTN_LEFT, 1);
559 litest_event(dev, EV_SYN, SYN_REPORT, 0);
560 litest_event(dev, EV_KEY, BTN_LEFT, 0);
561 litest_event(dev, EV_SYN, SYN_REPORT, 0);
563 libinput_dispatch(li);
565 assert_button_event(li, BTN_LEFT,
566 LIBINPUT_BUTTON_STATE_PRESSED);
567 assert_button_event(li, BTN_LEFT,
568 LIBINPUT_BUTTON_STATE_RELEASED);
572 START_TEST(clickpad_btn_left)
574 struct litest_device *dev = litest_current_device();
575 struct libinput *li = dev->libinput;
577 litest_drain_events(li);
579 /* A clickpad always needs a finger down to tell where the
581 litest_event(dev, EV_KEY, BTN_LEFT, 1);
582 litest_event(dev, EV_SYN, SYN_REPORT, 0);
583 litest_event(dev, EV_KEY, BTN_LEFT, 0);
584 litest_event(dev, EV_SYN, SYN_REPORT, 0);
586 libinput_dispatch(li);
587 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
591 START_TEST(clickpad_click_n_drag)
593 struct litest_device *dev = litest_current_device();
594 struct libinput *li = dev->libinput;
595 struct libinput_event *event;
597 litest_drain_events(li);
599 litest_touch_down(dev, 0, 50, 50);
600 litest_event(dev, EV_KEY, BTN_LEFT, 1);
601 litest_event(dev, EV_SYN, SYN_REPORT, 0);
603 libinput_dispatch(li);
604 assert_button_event(li, BTN_LEFT,
605 LIBINPUT_BUTTON_STATE_PRESSED);
607 libinput_dispatch(li);
608 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
610 /* now put a second finger down */
611 litest_touch_down(dev, 1, 70, 70);
612 litest_touch_move_to(dev, 1, 70, 70, 80, 50, 5);
613 litest_touch_up(dev, 1);
615 libinput_dispatch(li);
616 ck_assert_int_eq(libinput_next_event_type(li),
617 LIBINPUT_EVENT_POINTER_MOTION);
619 event = libinput_get_event(li);
620 libinput_event_destroy(event);
621 libinput_dispatch(li);
622 } while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION);
624 litest_event(dev, EV_KEY, BTN_LEFT, 0);
625 litest_event(dev, EV_SYN, SYN_REPORT, 0);
626 litest_touch_up(dev, 0);
628 assert_button_event(li, BTN_LEFT,
629 LIBINPUT_BUTTON_STATE_RELEASED);
633 START_TEST(clickpad_softbutton_left)
635 struct litest_device *dev = litest_current_device();
636 struct libinput *li = dev->libinput;
638 litest_drain_events(li);
640 litest_touch_down(dev, 0, 10, 90);
641 litest_event(dev, EV_KEY, BTN_LEFT, 1);
642 litest_event(dev, EV_SYN, SYN_REPORT, 0);
644 assert_button_event(li,
646 LIBINPUT_BUTTON_STATE_PRESSED);
648 litest_event(dev, EV_KEY, BTN_LEFT, 0);
649 litest_event(dev, EV_SYN, SYN_REPORT, 0);
650 litest_touch_up(dev, 0);
652 assert_button_event(li,
654 LIBINPUT_BUTTON_STATE_RELEASED);
656 libinput_dispatch(li);
658 litest_assert_empty_queue(li);
662 START_TEST(clickpad_softbutton_right)
664 struct litest_device *dev = litest_current_device();
665 struct libinput *li = dev->libinput;
667 litest_drain_events(li);
669 litest_touch_down(dev, 0, 90, 90);
670 litest_event(dev, EV_KEY, BTN_LEFT, 1);
671 litest_event(dev, EV_SYN, SYN_REPORT, 0);
673 assert_button_event(li,
675 LIBINPUT_BUTTON_STATE_PRESSED);
677 litest_event(dev, EV_KEY, BTN_LEFT, 0);
678 litest_event(dev, EV_SYN, SYN_REPORT, 0);
679 litest_touch_up(dev, 0);
681 assert_button_event(li,
683 LIBINPUT_BUTTON_STATE_RELEASED);
685 libinput_dispatch(li);
687 litest_assert_empty_queue(li);
691 START_TEST(clickpad_softbutton_left_tap_n_drag)
693 struct litest_device *dev = litest_current_device();
694 struct libinput *li = dev->libinput;
696 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
698 litest_drain_events(li);
700 /* Tap in left button area, then finger down, button click
701 -> expect left button press/release and left button press
702 Release button, finger up
703 -> expect right button release
705 litest_touch_down(dev, 0, 20, 90);
706 litest_touch_up(dev, 0);
707 litest_touch_down(dev, 0, 20, 90);
708 litest_event(dev, EV_KEY, BTN_LEFT, 1);
709 litest_event(dev, EV_SYN, SYN_REPORT, 0);
711 assert_button_event(li,
713 LIBINPUT_BUTTON_STATE_PRESSED);
714 assert_button_event(li,
716 LIBINPUT_BUTTON_STATE_RELEASED);
717 assert_button_event(li,
719 LIBINPUT_BUTTON_STATE_PRESSED);
720 litest_assert_empty_queue(li);
722 litest_event(dev, EV_KEY, BTN_LEFT, 0);
723 litest_event(dev, EV_SYN, SYN_REPORT, 0);
724 litest_touch_up(dev, 0);
726 assert_button_event(li,
728 LIBINPUT_BUTTON_STATE_RELEASED);
729 litest_assert_empty_queue(li);
733 START_TEST(clickpad_softbutton_right_tap_n_drag)
735 struct litest_device *dev = litest_current_device();
736 struct libinput *li = dev->libinput;
738 libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
740 litest_drain_events(li);
742 /* Tap in right button area, then finger down, button click
743 -> expect left button press/release and right button press
744 Release button, finger up
745 -> expect right button release
747 litest_touch_down(dev, 0, 90, 90);
748 litest_touch_up(dev, 0);
749 litest_touch_down(dev, 0, 90, 90);
750 litest_event(dev, EV_KEY, BTN_LEFT, 1);
751 litest_event(dev, EV_SYN, SYN_REPORT, 0);
753 assert_button_event(li,
755 LIBINPUT_BUTTON_STATE_PRESSED);
756 assert_button_event(li,
758 LIBINPUT_BUTTON_STATE_RELEASED);
759 assert_button_event(li,
761 LIBINPUT_BUTTON_STATE_PRESSED);
762 litest_assert_empty_queue(li);
764 litest_event(dev, EV_KEY, BTN_LEFT, 0);
765 litest_event(dev, EV_SYN, SYN_REPORT, 0);
766 litest_touch_up(dev, 0);
768 assert_button_event(li,
770 LIBINPUT_BUTTON_STATE_RELEASED);
771 litest_assert_empty_queue(li);
775 START_TEST(clickpad_softbutton_left_1st_fg_move)
777 struct litest_device *dev = litest_current_device();
778 struct libinput *li = dev->libinput;
779 struct libinput_event *event;
783 litest_drain_events(li);
785 /* One finger down in the left button area, button press
786 -> expect a button event
787 Move finger up out of the area, wait for timeout
788 Move finger around diagonally down left
789 -> expect motion events down left
791 -> expect a button event */
793 /* finger down, press in left button */
794 litest_touch_down(dev, 0, 20, 90);
795 litest_event(dev, EV_KEY, BTN_LEFT, 1);
796 litest_event(dev, EV_SYN, SYN_REPORT, 0);
798 assert_button_event(li,
800 LIBINPUT_BUTTON_STATE_PRESSED);
801 litest_assert_empty_queue(li);
803 /* move out of the area, then wait for softbutton timer */
804 litest_touch_move_to(dev, 0, 20, 90, 90, 20, 10);
805 libinput_dispatch(li);
807 libinput_dispatch(li);
808 litest_drain_events(li);
810 /* move down left, expect motion */
811 litest_touch_move_to(dev, 0, 90, 20, 20, 90, 10);
813 libinput_dispatch(li);
814 event = libinput_get_event(li);
815 ck_assert(event != NULL);
817 struct libinput_event_pointer *p;
819 ck_assert_int_eq(libinput_event_get_type(event),
820 LIBINPUT_EVENT_POINTER_MOTION);
821 p = libinput_event_get_pointer_event(event);
823 /* we moved up/right, now down/left so the pointer accel
824 code may lag behind with the dx/dy vectors. Hence, add up
825 the x/y movements and expect that on average we moved
827 x += libinput_event_pointer_get_dx(p);
828 y += libinput_event_pointer_get_dy(p);
831 libinput_event_destroy(event);
832 libinput_dispatch(li);
833 event = libinput_get_event(li);
836 ck_assert(x/nevents < 0);
837 ck_assert(y/nevents > 0);
839 litest_event(dev, EV_KEY, BTN_LEFT, 0);
840 litest_event(dev, EV_SYN, SYN_REPORT, 0);
841 litest_touch_up(dev, 0);
843 assert_button_event(li,
845 LIBINPUT_BUTTON_STATE_RELEASED);
847 litest_assert_empty_queue(li);
851 START_TEST(clickpad_softbutton_left_2nd_fg_move)
853 struct litest_device *dev = litest_current_device();
854 struct libinput *li = dev->libinput;
855 struct libinput_event *event;
857 litest_drain_events(li);
859 /* One finger down in the left button area, button press
860 -> expect a button event
861 Put a second finger down in the area, move it right, release
862 -> expect motion events right
863 Put a second finger down in the area, move it down, release
864 -> expect motion events down
865 Release second finger, release first finger
866 -> expect a button event */
867 litest_touch_down(dev, 0, 20, 90);
868 litest_event(dev, EV_KEY, BTN_LEFT, 1);
869 litest_event(dev, EV_SYN, SYN_REPORT, 0);
871 assert_button_event(li,
873 LIBINPUT_BUTTON_STATE_PRESSED);
874 litest_assert_empty_queue(li);
876 litest_touch_down(dev, 1, 20, 20);
877 litest_touch_move_to(dev, 1, 20, 20, 80, 20, 10);
879 libinput_dispatch(li);
880 event = libinput_get_event(li);
881 ck_assert(event != NULL);
883 struct libinput_event_pointer *p;
886 ck_assert_int_eq(libinput_event_get_type(event),
887 LIBINPUT_EVENT_POINTER_MOTION);
888 p = libinput_event_get_pointer_event(event);
890 x = libinput_event_pointer_get_dx(p);
891 y = libinput_event_pointer_get_dy(p);
896 libinput_event_destroy(event);
897 libinput_dispatch(li);
898 event = libinput_get_event(li);
900 litest_touch_up(dev, 1);
902 /* second finger down */
903 litest_touch_down(dev, 1, 20, 20);
904 litest_touch_move_to(dev, 1, 20, 20, 20, 80, 10);
906 libinput_dispatch(li);
907 event = libinput_get_event(li);
908 ck_assert(event != NULL);
910 struct libinput_event_pointer *p;
913 ck_assert_int_eq(libinput_event_get_type(event),
914 LIBINPUT_EVENT_POINTER_MOTION);
915 p = libinput_event_get_pointer_event(event);
917 x = libinput_event_pointer_get_dx(p);
918 y = libinput_event_pointer_get_dy(p);
923 libinput_event_destroy(event);
924 libinput_dispatch(li);
925 event = libinput_get_event(li);
928 litest_touch_up(dev, 1);
930 litest_event(dev, EV_KEY, BTN_LEFT, 0);
931 litest_event(dev, EV_SYN, SYN_REPORT, 0);
932 litest_touch_up(dev, 0);
934 assert_button_event(li,
936 LIBINPUT_BUTTON_STATE_RELEASED);
938 litest_assert_empty_queue(li);
942 START_TEST(clickpad_softbutton_left_to_right)
944 struct litest_device *dev = litest_current_device();
945 struct libinput *li = dev->libinput;
947 litest_drain_events(li);
949 /* One finger down in left software button area,
950 move to right button area immediately, click
951 -> expect right button event
954 litest_touch_down(dev, 0, 20, 90);
955 litest_touch_move_to(dev, 0, 20, 90, 90, 90, 10);
956 litest_event(dev, EV_KEY, BTN_LEFT, 1);
957 litest_event(dev, EV_SYN, SYN_REPORT, 0);
959 assert_button_event(li,
961 LIBINPUT_BUTTON_STATE_PRESSED);
962 litest_assert_empty_queue(li);
964 litest_event(dev, EV_KEY, BTN_LEFT, 0);
965 litest_event(dev, EV_SYN, SYN_REPORT, 0);
966 litest_touch_up(dev, 0);
968 assert_button_event(li,
970 LIBINPUT_BUTTON_STATE_RELEASED);
972 litest_assert_empty_queue(li);
976 START_TEST(clickpad_softbutton_right_to_left)
978 struct litest_device *dev = litest_current_device();
979 struct libinput *li = dev->libinput;
981 litest_drain_events(li);
983 /* One finger down in right software button area,
984 move to left button area immediately, click
985 -> expect left button event
988 litest_touch_down(dev, 0, 90, 90);
989 litest_touch_move_to(dev, 0, 90, 90, 20, 90, 10);
990 litest_event(dev, EV_KEY, BTN_LEFT, 1);
991 litest_event(dev, EV_SYN, SYN_REPORT, 0);
993 assert_button_event(li,
995 LIBINPUT_BUTTON_STATE_PRESSED);
996 litest_assert_empty_queue(li);
998 litest_event(dev, EV_KEY, BTN_LEFT, 0);
999 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1000 litest_touch_up(dev, 0);
1002 assert_button_event(li,
1004 LIBINPUT_BUTTON_STATE_RELEASED);
1006 litest_assert_empty_queue(li);
1010 START_TEST(clickpad_topsoftbuttons_left)
1012 struct litest_device *dev = litest_current_device();
1013 struct libinput *li = dev->libinput;
1015 litest_drain_events(li);
1017 litest_touch_down(dev, 0, 10, 5);
1018 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1019 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1021 assert_button_event(li,
1023 LIBINPUT_BUTTON_STATE_PRESSED);
1024 litest_assert_empty_queue(li);
1026 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1027 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1028 litest_touch_up(dev, 0);
1030 assert_button_event(li,
1032 LIBINPUT_BUTTON_STATE_RELEASED);
1034 litest_assert_empty_queue(li);
1038 START_TEST(clickpad_topsoftbuttons_right)
1040 struct litest_device *dev = litest_current_device();
1041 struct libinput *li = dev->libinput;
1043 litest_drain_events(li);
1045 litest_touch_down(dev, 0, 90, 5);
1046 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1047 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1049 assert_button_event(li,
1051 LIBINPUT_BUTTON_STATE_PRESSED);
1052 litest_assert_empty_queue(li);
1054 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1055 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1056 litest_touch_up(dev, 0);
1058 assert_button_event(li,
1060 LIBINPUT_BUTTON_STATE_RELEASED);
1062 litest_assert_empty_queue(li);
1066 START_TEST(clickpad_topsoftbuttons_middle)
1068 struct litest_device *dev = litest_current_device();
1069 struct libinput *li = dev->libinput;
1071 litest_drain_events(li);
1073 litest_touch_down(dev, 0, 50, 5);
1074 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1075 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1077 assert_button_event(li,
1079 LIBINPUT_BUTTON_STATE_PRESSED);
1080 litest_assert_empty_queue(li);
1082 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1083 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1084 litest_touch_up(dev, 0);
1086 assert_button_event(li,
1088 LIBINPUT_BUTTON_STATE_RELEASED);
1090 litest_assert_empty_queue(li);
1094 START_TEST(clickpad_topsoftbuttons_move_out_ignore)
1096 struct litest_device *dev = litest_current_device();
1097 struct libinput *li = dev->libinput;
1099 /* Finger down in top button area, wait past enter timeout
1100 Move into main area, wait past leave timeout
1105 litest_drain_events(li);
1107 litest_touch_down(dev, 0, 50, 5);
1108 libinput_dispatch(li);
1110 libinput_dispatch(li);
1111 litest_assert_empty_queue(li);
1113 litest_touch_move_to(dev, 0, 50, 5, 80, 90, 20);
1114 libinput_dispatch(li);
1116 libinput_dispatch(li);
1118 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1119 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1120 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1121 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1123 litest_touch_up(dev, 0);
1125 litest_assert_empty_queue(li);
1130 test_2fg_scroll(struct litest_device *dev, int dx, int dy, int sleep)
1132 struct libinput *li = dev->libinput;
1134 litest_touch_down(dev, 0, 47, 50);
1135 litest_touch_down(dev, 1, 53, 50);
1137 litest_touch_move_to(dev, 0, 47, 50, 47 + dx, 50 + dy, 5);
1138 litest_touch_move_to(dev, 1, 53, 50, 53 + dx, 50 + dy, 5);
1140 /* Avoid a small scroll being seen as a tap */
1142 libinput_dispatch(li);
1144 libinput_dispatch(li);
1147 litest_touch_up(dev, 1);
1148 litest_touch_up(dev, 0);
1150 libinput_dispatch(li);
1154 check_2fg_scroll(struct litest_device *dev, unsigned int axis, int dir)
1156 struct libinput *li = dev->libinput;
1157 struct libinput_event *event, *next_event;
1158 struct libinput_event_pointer *ptrev;
1160 event = libinput_get_event(li);
1161 next_event = libinput_get_event(li);
1162 ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
1165 ck_assert_int_eq(libinput_event_get_type(event),
1166 LIBINPUT_EVENT_POINTER_AXIS);
1167 ptrev = libinput_event_get_pointer_event(event);
1168 ck_assert(ptrev != NULL);
1169 ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev), axis);
1172 /* Normal scroll event, check dir */
1175 libinput_event_pointer_get_axis_value(ptrev),
1179 libinput_event_pointer_get_axis_value(ptrev),
1183 /* Last scroll event, must be 0 */
1185 libinput_event_pointer_get_axis_value(ptrev),
1188 libinput_event_destroy(event);
1190 next_event = libinput_get_event(li);
1194 START_TEST(touchpad_2fg_scroll)
1196 struct litest_device *dev = litest_current_device();
1197 struct libinput *li = dev->libinput;
1199 litest_drain_events(li);
1201 /* Note this mixes in a tiny amount of movement in the wrong direction,
1202 which should be ignored */
1203 test_2fg_scroll(dev, 1, 40, 0);
1204 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
1205 test_2fg_scroll(dev, 1, -40, 0);
1206 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
1207 test_2fg_scroll(dev, 40, 1, 0);
1208 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
1209 test_2fg_scroll(dev, -40, 1, 0);
1210 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
1212 /* 2fg scroll smaller than the threshold should not generate events */
1213 test_2fg_scroll(dev, 1, 1, 200);
1214 litest_assert_empty_queue(li);
1218 START_TEST(touchpad_tap_is_available)
1220 struct litest_device *dev = litest_current_device();
1222 ck_assert_int_ge(libinput_device_config_tap_get_finger_count(dev->libinput_device), 1);
1223 ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), 0);
1227 START_TEST(touchpad_tap_is_not_available)
1229 struct litest_device *dev = litest_current_device();
1231 ck_assert_int_eq(libinput_device_config_tap_get_finger_count(dev->libinput_device), 0);
1232 ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), 0);
1233 ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, 1),
1234 LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
1238 START_TEST(touchpad_tap_default)
1240 struct litest_device *dev = litest_current_device();
1242 ck_assert_int_eq(libinput_device_config_tap_get_default_enabled(dev->libinput_device), 0);
1246 int main(int argc, char **argv) {
1248 litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
1249 litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1251 litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
1252 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
1253 litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1254 litest_add("touchpad:tap", touchpad_2fg_tap_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1255 litest_add("touchpad:tap", touchpad_1fg_tap_click, LITEST_TOUCHPAD, LITEST_ANY);
1256 litest_add("touchpad:tap", touchpad_2fg_tap_click, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD);
1257 litest_add("touchpad:tap", touchpad_2fg_tap_click_apple, LITEST_APPLE_CLICKPAD, LITEST_ANY);
1258 litest_add("touchpad:tap", touchpad_no_2fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1259 litest_add("touchpad:tap", touchpad_no_2fg_tap_after_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1260 litest_add("touchpad:tap", touchpad_no_first_fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1261 litest_add("touchpad:tap", touchpad_no_first_fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1263 /* Real buttons don't interfere with tapping, so don't run those for
1264 pads with buttons */
1265 litest_add("touchpad:tap", touchpad_1fg_double_tap_click, LITEST_CLICKPAD, LITEST_ANY);
1266 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
1268 litest_add("touchpad:tap", touchpad_tap_default, LITEST_TOUCHPAD, LITEST_ANY);
1269 litest_add("touchpad:tap", touchpad_tap_is_available, LITEST_TOUCHPAD, LITEST_ANY);
1270 litest_add("touchpad:tap", touchpad_tap_is_not_available, LITEST_ANY, LITEST_TOUCHPAD);
1272 litest_add_no_device("touchpad:clickfinger", touchpad_1fg_clickfinger);
1273 litest_add_no_device("touchpad:clickfinger", touchpad_2fg_clickfinger);
1275 litest_add("touchpad:click", touchpad_btn_left, LITEST_TOUCHPAD, LITEST_CLICKPAD);
1276 litest_add("touchpad:click", clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY);
1277 litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
1279 litest_add("touchpad:softbutton", clickpad_softbutton_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1280 litest_add("touchpad:softbutton", clickpad_softbutton_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1281 litest_add("touchpad:softbutton", clickpad_softbutton_left_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1282 litest_add("touchpad:softbutton", clickpad_softbutton_right_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1283 litest_add("touchpad:softbutton", clickpad_softbutton_left_1st_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1284 litest_add("touchpad:softbutton", clickpad_softbutton_left_2nd_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1285 litest_add("touchpad:softbutton", clickpad_softbutton_left_to_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1286 litest_add("touchpad:softbutton", clickpad_softbutton_right_to_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1288 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_left, LITEST_TOPBUTTONPAD, LITEST_ANY);
1289 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_right, LITEST_TOPBUTTONPAD, LITEST_ANY);
1290 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_middle, LITEST_TOPBUTTONPAD, LITEST_ANY);
1291 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_move_out_ignore, LITEST_TOPBUTTONPAD, LITEST_ANY);
1293 litest_add("touchpad:scroll", touchpad_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1295 return litest_run(argc, argv);