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, 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 litest_drain_events(li);
121 litest_touch_down(dev, 0, 50, 50);
122 litest_touch_up(dev, 0);
124 libinput_dispatch(li);
126 assert_button_event(li, BTN_LEFT,
127 LIBINPUT_BUTTON_STATE_PRESSED);
128 msleep(300); /* tap-n-drag timeout */
129 assert_button_event(li, BTN_LEFT,
130 LIBINPUT_BUTTON_STATE_RELEASED);
132 libinput_dispatch(li);
133 event = libinput_get_event(li);
134 ck_assert(event == NULL);
138 START_TEST(touchpad_1fg_tap_n_drag)
140 struct litest_device *dev = litest_current_device();
141 struct libinput *li = dev->libinput;
142 struct libinput_event *event;
144 litest_drain_events(li);
146 litest_touch_down(dev, 0, 50, 50);
147 litest_touch_up(dev, 0);
148 litest_touch_down(dev, 0, 50, 50);
149 litest_touch_move_to(dev, 0, 50, 50, 80, 80, 5);
150 litest_touch_up(dev, 0);
152 libinput_dispatch(li);
154 assert_button_event(li, BTN_LEFT,
155 LIBINPUT_BUTTON_STATE_PRESSED);
157 libinput_dispatch(li);
158 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
159 event = libinput_get_event(li);
160 libinput_event_destroy(event);
161 libinput_dispatch(li);
164 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
166 /* lift finger, set down again, should continue dragging */
167 litest_touch_down(dev, 0, 50, 50);
168 litest_touch_move_to(dev, 0, 50, 50, 80, 80, 5);
169 litest_touch_up(dev, 0);
171 libinput_dispatch(li);
172 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
173 event = libinput_get_event(li);
174 libinput_event_destroy(event);
175 libinput_dispatch(li);
178 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
180 msleep(300); /* tap-n-drag timeout */
182 assert_button_event(li, BTN_LEFT,
183 LIBINPUT_BUTTON_STATE_RELEASED);
185 litest_assert_empty_queue(li);
189 START_TEST(touchpad_2fg_tap)
191 struct litest_device *dev = litest_current_device();
192 struct libinput *li = dev->libinput;
194 litest_drain_events(dev->libinput);
196 litest_touch_down(dev, 0, 50, 50);
197 litest_touch_down(dev, 1, 70, 70);
198 litest_touch_up(dev, 0);
199 litest_touch_up(dev, 1);
201 libinput_dispatch(li);
203 assert_button_event(li, BTN_RIGHT,
204 LIBINPUT_BUTTON_STATE_PRESSED);
205 msleep(300); /* tap-n-drag timeout */
206 assert_button_event(li, BTN_RIGHT,
207 LIBINPUT_BUTTON_STATE_RELEASED);
209 litest_assert_empty_queue(li);
213 START_TEST(touchpad_2fg_tap_inverted)
215 struct litest_device *dev = litest_current_device();
216 struct libinput *li = dev->libinput;
218 litest_drain_events(dev->libinput);
220 litest_touch_down(dev, 0, 50, 50);
221 litest_touch_down(dev, 1, 70, 70);
222 litest_touch_up(dev, 1);
223 litest_touch_up(dev, 0);
225 libinput_dispatch(li);
227 assert_button_event(li, BTN_RIGHT,
228 LIBINPUT_BUTTON_STATE_PRESSED);
229 msleep(300); /* tap-n-drag timeout */
230 assert_button_event(li, BTN_RIGHT,
231 LIBINPUT_BUTTON_STATE_RELEASED);
233 litest_assert_empty_queue(li);
237 START_TEST(touchpad_1fg_tap_click)
239 struct litest_device *dev = litest_current_device();
240 struct libinput *li = dev->libinput;
242 litest_drain_events(dev->libinput);
244 /* finger down, button click, finger up
245 -> only one button left event pair */
246 litest_touch_down(dev, 0, 50, 50);
247 litest_event(dev, EV_KEY, BTN_LEFT, 1);
248 litest_event(dev, EV_SYN, SYN_REPORT, 0);
249 litest_event(dev, EV_KEY, BTN_LEFT, 0);
250 litest_event(dev, EV_SYN, SYN_REPORT, 0);
251 litest_touch_up(dev, 0);
253 libinput_dispatch(li);
255 assert_button_event(li, BTN_LEFT,
256 LIBINPUT_BUTTON_STATE_PRESSED);
257 assert_button_event(li, BTN_LEFT,
258 LIBINPUT_BUTTON_STATE_RELEASED);
260 litest_assert_empty_queue(li);
264 START_TEST(touchpad_2fg_tap_click)
266 struct litest_device *dev = litest_current_device();
267 struct libinput *li = dev->libinput;
269 litest_drain_events(dev->libinput);
271 /* two fingers down, button click, fingers up
272 -> only one button left event pair */
273 litest_touch_down(dev, 0, 50, 50);
274 litest_touch_down(dev, 1, 70, 50);
275 litest_event(dev, EV_KEY, BTN_LEFT, 1);
276 litest_event(dev, EV_SYN, SYN_REPORT, 0);
277 litest_event(dev, EV_KEY, BTN_LEFT, 0);
278 litest_event(dev, EV_SYN, SYN_REPORT, 0);
279 litest_touch_up(dev, 1);
280 litest_touch_up(dev, 0);
282 libinput_dispatch(li);
284 assert_button_event(li, BTN_LEFT,
285 LIBINPUT_BUTTON_STATE_PRESSED);
286 assert_button_event(li, BTN_LEFT,
287 LIBINPUT_BUTTON_STATE_RELEASED);
289 litest_assert_empty_queue(li);
293 START_TEST(touchpad_2fg_tap_click_apple)
295 struct litest_device *dev = litest_current_device();
296 struct libinput *li = dev->libinput;
298 litest_drain_events(dev->libinput);
300 /* two fingers down, button click, fingers up
301 -> only one button right event pair
302 (apple have clickfinger enabled by default) */
303 litest_touch_down(dev, 0, 50, 50);
304 litest_touch_down(dev, 1, 70, 50);
305 litest_event(dev, EV_KEY, BTN_LEFT, 1);
306 litest_event(dev, EV_SYN, SYN_REPORT, 0);
307 litest_event(dev, EV_KEY, BTN_LEFT, 0);
308 litest_event(dev, EV_SYN, SYN_REPORT, 0);
309 litest_touch_up(dev, 1);
310 litest_touch_up(dev, 0);
312 libinput_dispatch(li);
314 assert_button_event(li, BTN_RIGHT,
315 LIBINPUT_BUTTON_STATE_PRESSED);
316 assert_button_event(li, BTN_RIGHT,
317 LIBINPUT_BUTTON_STATE_RELEASED);
319 litest_assert_empty_queue(li);
323 START_TEST(touchpad_no_2fg_tap_after_move)
325 struct litest_device *dev = litest_current_device();
326 struct libinput *li = dev->libinput;
328 litest_drain_events(dev->libinput);
330 /* one finger down, move past threshold,
331 second finger down, first finger up
334 litest_touch_down(dev, 0, 50, 50);
335 litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
336 litest_drain_events(dev->libinput);
338 litest_touch_down(dev, 1, 70, 50);
339 litest_touch_up(dev, 0);
341 litest_assert_empty_queue(li);
345 START_TEST(touchpad_no_2fg_tap_after_timeout)
347 struct litest_device *dev = litest_current_device();
348 struct libinput *li = dev->libinput;
350 litest_drain_events(dev->libinput);
352 /* one finger down, wait past tap timeout,
353 second finger down, first finger up
356 litest_touch_down(dev, 0, 50, 50);
357 libinput_dispatch(dev->libinput);
359 libinput_dispatch(dev->libinput);
360 litest_drain_events(dev->libinput);
362 litest_touch_down(dev, 1, 70, 50);
363 litest_touch_up(dev, 0);
365 litest_assert_empty_queue(li);
369 START_TEST(touchpad_no_first_fg_tap_after_move)
371 struct litest_device *dev = litest_current_device();
372 struct libinput *li = dev->libinput;
373 struct libinput_event *event;
375 litest_drain_events(dev->libinput);
377 /* one finger down, second finger down,
378 second finger moves beyond threshold,
382 litest_touch_down(dev, 0, 50, 50);
383 litest_touch_down(dev, 1, 70, 50);
384 libinput_dispatch(dev->libinput);
385 litest_touch_move_to(dev, 1, 70, 50, 90, 90, 10);
386 libinput_dispatch(dev->libinput);
387 litest_touch_up(dev, 0);
388 litest_touch_up(dev, 1);
389 libinput_dispatch(dev->libinput);
391 while ((event = libinput_get_event(li))) {
392 ck_assert_int_ne(libinput_event_get_type(event),
393 LIBINPUT_EVENT_POINTER_BUTTON);
394 libinput_event_destroy(event);
399 START_TEST(touchpad_1fg_double_tap_click)
401 struct litest_device *dev = litest_current_device();
402 struct libinput *li = dev->libinput;
404 litest_drain_events(dev->libinput);
406 /* one finger down, up, down, button click, finger up
407 -> two button left event pairs */
408 litest_touch_down(dev, 0, 50, 50);
409 litest_touch_up(dev, 0);
410 litest_touch_down(dev, 0, 50, 50);
411 litest_event(dev, EV_KEY, BTN_LEFT, 1);
412 litest_event(dev, EV_SYN, SYN_REPORT, 0);
413 litest_event(dev, EV_KEY, BTN_LEFT, 0);
414 litest_event(dev, EV_SYN, SYN_REPORT, 0);
415 litest_touch_up(dev, 0);
417 libinput_dispatch(li);
419 assert_button_event(li, BTN_LEFT,
420 LIBINPUT_BUTTON_STATE_PRESSED);
421 assert_button_event(li, BTN_LEFT,
422 LIBINPUT_BUTTON_STATE_RELEASED);
423 assert_button_event(li, BTN_LEFT,
424 LIBINPUT_BUTTON_STATE_PRESSED);
425 assert_button_event(li, BTN_LEFT,
426 LIBINPUT_BUTTON_STATE_RELEASED);
428 litest_assert_empty_queue(li);
432 START_TEST(touchpad_1fg_tap_n_drag_click)
434 struct litest_device *dev = litest_current_device();
435 struct libinput *li = dev->libinput;
436 struct libinput_event *event;
438 litest_drain_events(dev->libinput);
440 /* one finger down, up, down, move, button click, finger up
441 -> two button left event pairs, motion allowed */
442 litest_touch_down(dev, 0, 50, 50);
443 litest_touch_up(dev, 0);
444 litest_touch_down(dev, 0, 50, 50);
445 litest_touch_move_to(dev, 0, 50, 50, 80, 50, 10);
447 assert_button_event(li, BTN_LEFT,
448 LIBINPUT_BUTTON_STATE_PRESSED);
450 libinput_dispatch(li);
452 ck_assert_int_eq(libinput_next_event_type(li),
453 LIBINPUT_EVENT_POINTER_MOTION);
454 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
455 event = libinput_get_event(li);
456 libinput_event_destroy(event);
457 libinput_dispatch(li);
460 litest_event(dev, EV_KEY, BTN_LEFT, 1);
461 litest_event(dev, EV_SYN, SYN_REPORT, 0);
463 assert_button_event(li, BTN_LEFT,
464 LIBINPUT_BUTTON_STATE_RELEASED);
465 assert_button_event(li, BTN_LEFT,
466 LIBINPUT_BUTTON_STATE_PRESSED);
468 litest_event(dev, EV_KEY, BTN_LEFT, 0);
469 litest_event(dev, EV_SYN, SYN_REPORT, 0);
470 litest_touch_up(dev, 0);
472 libinput_dispatch(li);
474 assert_button_event(li, BTN_LEFT,
475 LIBINPUT_BUTTON_STATE_RELEASED);
477 litest_assert_empty_queue(li);
481 START_TEST(touchpad_1fg_clickfinger)
483 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
484 struct libinput *li = dev->libinput;
486 litest_drain_events(li);
488 litest_touch_down(dev, 0, 50, 50);
489 litest_event(dev, EV_KEY, BTN_LEFT, 1);
490 litest_event(dev, EV_SYN, SYN_REPORT, 0);
491 litest_event(dev, EV_KEY, BTN_LEFT, 0);
492 litest_event(dev, EV_SYN, SYN_REPORT, 0);
493 litest_touch_up(dev, 0);
495 libinput_dispatch(li);
497 assert_button_event(li, BTN_LEFT,
498 LIBINPUT_BUTTON_STATE_PRESSED);
499 assert_button_event(li, BTN_LEFT,
500 LIBINPUT_BUTTON_STATE_RELEASED);
502 litest_delete_device(dev);
506 START_TEST(touchpad_2fg_clickfinger)
508 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
509 struct libinput *li = dev->libinput;
511 litest_drain_events(li);
513 litest_touch_down(dev, 0, 50, 50);
514 litest_touch_down(dev, 1, 70, 70);
515 litest_event(dev, EV_KEY, BTN_LEFT, 1);
516 litest_event(dev, EV_SYN, SYN_REPORT, 0);
517 litest_event(dev, EV_KEY, BTN_LEFT, 0);
518 litest_event(dev, EV_SYN, SYN_REPORT, 0);
519 litest_touch_up(dev, 0);
520 litest_touch_up(dev, 1);
522 libinput_dispatch(li);
524 assert_button_event(li, BTN_RIGHT,
525 LIBINPUT_BUTTON_STATE_PRESSED);
526 assert_button_event(li, BTN_RIGHT,
527 LIBINPUT_BUTTON_STATE_RELEASED);
529 litest_delete_device(dev);
533 START_TEST(touchpad_btn_left)
535 struct litest_device *dev = litest_current_device();
536 struct libinput *li = dev->libinput;
538 litest_drain_events(li);
540 litest_event(dev, EV_KEY, BTN_LEFT, 1);
541 litest_event(dev, EV_SYN, SYN_REPORT, 0);
542 litest_event(dev, EV_KEY, BTN_LEFT, 0);
543 litest_event(dev, EV_SYN, SYN_REPORT, 0);
545 libinput_dispatch(li);
547 assert_button_event(li, BTN_LEFT,
548 LIBINPUT_BUTTON_STATE_PRESSED);
549 assert_button_event(li, BTN_LEFT,
550 LIBINPUT_BUTTON_STATE_RELEASED);
554 START_TEST(clickpad_btn_left)
556 struct litest_device *dev = litest_current_device();
557 struct libinput *li = dev->libinput;
559 litest_drain_events(li);
561 /* A clickpad always needs a finger down to tell where the
563 litest_event(dev, EV_KEY, BTN_LEFT, 1);
564 litest_event(dev, EV_SYN, SYN_REPORT, 0);
565 litest_event(dev, EV_KEY, BTN_LEFT, 0);
566 litest_event(dev, EV_SYN, SYN_REPORT, 0);
568 libinput_dispatch(li);
569 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
573 START_TEST(clickpad_click_n_drag)
575 struct litest_device *dev = litest_current_device();
576 struct libinput *li = dev->libinput;
577 struct libinput_event *event;
579 litest_drain_events(li);
581 litest_touch_down(dev, 0, 50, 50);
582 litest_event(dev, EV_KEY, BTN_LEFT, 1);
583 litest_event(dev, EV_SYN, SYN_REPORT, 0);
585 libinput_dispatch(li);
586 assert_button_event(li, BTN_LEFT,
587 LIBINPUT_BUTTON_STATE_PRESSED);
589 libinput_dispatch(li);
590 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
592 /* now put a second finger down */
593 litest_touch_down(dev, 1, 70, 70);
594 litest_touch_move_to(dev, 1, 70, 70, 80, 50, 5);
595 litest_touch_up(dev, 1);
597 libinput_dispatch(li);
598 ck_assert_int_eq(libinput_next_event_type(li),
599 LIBINPUT_EVENT_POINTER_MOTION);
601 event = libinput_get_event(li);
602 libinput_event_destroy(event);
603 libinput_dispatch(li);
604 } while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION);
606 litest_event(dev, EV_KEY, BTN_LEFT, 0);
607 litest_event(dev, EV_SYN, SYN_REPORT, 0);
608 litest_touch_up(dev, 0);
610 assert_button_event(li, BTN_LEFT,
611 LIBINPUT_BUTTON_STATE_RELEASED);
615 START_TEST(clickpad_softbutton_left)
617 struct litest_device *dev = litest_current_device();
618 struct libinput *li = dev->libinput;
620 litest_drain_events(li);
622 litest_touch_down(dev, 0, 10, 90);
623 litest_event(dev, EV_KEY, BTN_LEFT, 1);
624 litest_event(dev, EV_SYN, SYN_REPORT, 0);
626 assert_button_event(li,
628 LIBINPUT_BUTTON_STATE_PRESSED);
630 litest_event(dev, EV_KEY, BTN_LEFT, 0);
631 litest_event(dev, EV_SYN, SYN_REPORT, 0);
632 litest_touch_up(dev, 0);
634 assert_button_event(li,
636 LIBINPUT_BUTTON_STATE_RELEASED);
638 libinput_dispatch(li);
640 litest_assert_empty_queue(li);
644 START_TEST(clickpad_softbutton_right)
646 struct litest_device *dev = litest_current_device();
647 struct libinput *li = dev->libinput;
649 litest_drain_events(li);
651 litest_touch_down(dev, 0, 90, 90);
652 litest_event(dev, EV_KEY, BTN_LEFT, 1);
653 litest_event(dev, EV_SYN, SYN_REPORT, 0);
655 assert_button_event(li,
657 LIBINPUT_BUTTON_STATE_PRESSED);
659 litest_event(dev, EV_KEY, BTN_LEFT, 0);
660 litest_event(dev, EV_SYN, SYN_REPORT, 0);
661 litest_touch_up(dev, 0);
663 assert_button_event(li,
665 LIBINPUT_BUTTON_STATE_RELEASED);
667 libinput_dispatch(li);
669 litest_assert_empty_queue(li);
673 START_TEST(clickpad_softbutton_left_tap_n_drag)
675 struct litest_device *dev = litest_current_device();
676 struct libinput *li = dev->libinput;
678 litest_drain_events(li);
680 /* Tap in left button area, then finger down, button click
681 -> expect left button press/release and left button press
682 Release button, finger up
683 -> expect right button release
685 litest_touch_down(dev, 0, 20, 90);
686 litest_touch_up(dev, 0);
687 litest_touch_down(dev, 0, 20, 90);
688 litest_event(dev, EV_KEY, BTN_LEFT, 1);
689 litest_event(dev, EV_SYN, SYN_REPORT, 0);
691 assert_button_event(li,
693 LIBINPUT_BUTTON_STATE_PRESSED);
694 assert_button_event(li,
696 LIBINPUT_BUTTON_STATE_RELEASED);
697 assert_button_event(li,
699 LIBINPUT_BUTTON_STATE_PRESSED);
700 litest_assert_empty_queue(li);
702 litest_event(dev, EV_KEY, BTN_LEFT, 0);
703 litest_event(dev, EV_SYN, SYN_REPORT, 0);
704 litest_touch_up(dev, 0);
706 assert_button_event(li,
708 LIBINPUT_BUTTON_STATE_RELEASED);
709 litest_assert_empty_queue(li);
713 START_TEST(clickpad_softbutton_right_tap_n_drag)
715 struct litest_device *dev = litest_current_device();
716 struct libinput *li = dev->libinput;
718 litest_drain_events(li);
720 /* Tap in right button area, then finger down, button click
721 -> expect left button press/release and right button press
722 Release button, finger up
723 -> expect right button release
725 litest_touch_down(dev, 0, 90, 90);
726 litest_touch_up(dev, 0);
727 litest_touch_down(dev, 0, 90, 90);
728 litest_event(dev, EV_KEY, BTN_LEFT, 1);
729 litest_event(dev, EV_SYN, SYN_REPORT, 0);
731 assert_button_event(li,
733 LIBINPUT_BUTTON_STATE_PRESSED);
734 assert_button_event(li,
736 LIBINPUT_BUTTON_STATE_RELEASED);
737 assert_button_event(li,
739 LIBINPUT_BUTTON_STATE_PRESSED);
740 litest_assert_empty_queue(li);
742 litest_event(dev, EV_KEY, BTN_LEFT, 0);
743 litest_event(dev, EV_SYN, SYN_REPORT, 0);
744 litest_touch_up(dev, 0);
746 assert_button_event(li,
748 LIBINPUT_BUTTON_STATE_RELEASED);
749 litest_assert_empty_queue(li);
753 START_TEST(clickpad_softbutton_left_1st_fg_move)
755 struct litest_device *dev = litest_current_device();
756 struct libinput *li = dev->libinput;
757 struct libinput_event *event;
761 litest_drain_events(li);
763 /* One finger down in the left button area, button press
764 -> expect a button event
765 Move finger up out of the area, wait for timeout
766 Move finger around diagonally down left
767 -> expect motion events down left
769 -> expect a button event */
771 /* finger down, press in left button */
772 litest_touch_down(dev, 0, 20, 90);
773 litest_event(dev, EV_KEY, BTN_LEFT, 1);
774 litest_event(dev, EV_SYN, SYN_REPORT, 0);
776 assert_button_event(li,
778 LIBINPUT_BUTTON_STATE_PRESSED);
779 litest_assert_empty_queue(li);
781 /* move out of the area, then wait for softbutton timer */
782 litest_touch_move_to(dev, 0, 20, 90, 90, 20, 10);
783 libinput_dispatch(li);
785 libinput_dispatch(li);
786 litest_drain_events(li);
788 /* move down left, expect motion */
789 litest_touch_move_to(dev, 0, 90, 20, 20, 90, 10);
791 libinput_dispatch(li);
792 event = libinput_get_event(li);
793 ck_assert(event != NULL);
795 struct libinput_event_pointer *p;
797 ck_assert_int_eq(libinput_event_get_type(event),
798 LIBINPUT_EVENT_POINTER_MOTION);
799 p = libinput_event_get_pointer_event(event);
801 /* we moved up/right, now down/left so the pointer accel
802 code may lag behind with the dx/dy vectors. Hence, add up
803 the x/y movements and expect that on average we moved
805 x += libinput_event_pointer_get_dx(p);
806 y += libinput_event_pointer_get_dy(p);
809 libinput_event_destroy(event);
810 libinput_dispatch(li);
811 event = libinput_get_event(li);
814 ck_assert(x/nevents < 0);
815 ck_assert(y/nevents > 0);
817 litest_event(dev, EV_KEY, BTN_LEFT, 0);
818 litest_event(dev, EV_SYN, SYN_REPORT, 0);
819 litest_touch_up(dev, 0);
821 assert_button_event(li,
823 LIBINPUT_BUTTON_STATE_RELEASED);
825 litest_assert_empty_queue(li);
829 START_TEST(clickpad_softbutton_left_2nd_fg_move)
831 struct litest_device *dev = litest_current_device();
832 struct libinput *li = dev->libinput;
833 struct libinput_event *event;
835 litest_drain_events(li);
837 /* One finger down in the left button area, button press
838 -> expect a button event
839 Put a second finger down in the area, move it right, release
840 -> expect motion events right
841 Put a second finger down in the area, move it down, release
842 -> expect motion events down
843 Release second finger, release first finger
844 -> expect a button event */
845 litest_touch_down(dev, 0, 20, 90);
846 litest_event(dev, EV_KEY, BTN_LEFT, 1);
847 litest_event(dev, EV_SYN, SYN_REPORT, 0);
849 assert_button_event(li,
851 LIBINPUT_BUTTON_STATE_PRESSED);
852 litest_assert_empty_queue(li);
854 litest_touch_down(dev, 1, 20, 20);
855 litest_touch_move_to(dev, 1, 20, 20, 80, 20, 10);
857 libinput_dispatch(li);
858 event = libinput_get_event(li);
859 ck_assert(event != NULL);
861 struct libinput_event_pointer *p;
864 ck_assert_int_eq(libinput_event_get_type(event),
865 LIBINPUT_EVENT_POINTER_MOTION);
866 p = libinput_event_get_pointer_event(event);
868 x = libinput_event_pointer_get_dx(p);
869 y = libinput_event_pointer_get_dy(p);
874 libinput_event_destroy(event);
875 libinput_dispatch(li);
876 event = libinput_get_event(li);
878 litest_touch_up(dev, 1);
880 /* second finger down */
881 litest_touch_down(dev, 1, 20, 20);
882 litest_touch_move_to(dev, 1, 20, 20, 20, 80, 10);
884 libinput_dispatch(li);
885 event = libinput_get_event(li);
886 ck_assert(event != NULL);
888 struct libinput_event_pointer *p;
891 ck_assert_int_eq(libinput_event_get_type(event),
892 LIBINPUT_EVENT_POINTER_MOTION);
893 p = libinput_event_get_pointer_event(event);
895 x = libinput_event_pointer_get_dx(p);
896 y = libinput_event_pointer_get_dy(p);
901 libinput_event_destroy(event);
902 libinput_dispatch(li);
903 event = libinput_get_event(li);
906 litest_event(dev, EV_KEY, BTN_LEFT, 0);
907 litest_event(dev, EV_SYN, SYN_REPORT, 0);
908 litest_touch_up(dev, 0);
910 assert_button_event(li,
912 LIBINPUT_BUTTON_STATE_RELEASED);
914 litest_assert_empty_queue(li);
918 START_TEST(clickpad_softbutton_left_to_right)
920 struct litest_device *dev = litest_current_device();
921 struct libinput *li = dev->libinput;
923 litest_drain_events(li);
925 /* One finger down in left software button area,
926 move to right button area immediately, click
927 -> expect right button event
930 litest_touch_down(dev, 0, 20, 90);
931 litest_touch_move_to(dev, 0, 20, 90, 90, 90, 10);
932 litest_event(dev, EV_KEY, BTN_LEFT, 1);
933 litest_event(dev, EV_SYN, SYN_REPORT, 0);
935 assert_button_event(li,
937 LIBINPUT_BUTTON_STATE_PRESSED);
938 litest_assert_empty_queue(li);
940 litest_event(dev, EV_KEY, BTN_LEFT, 0);
941 litest_event(dev, EV_SYN, SYN_REPORT, 0);
942 litest_touch_up(dev, 0);
944 assert_button_event(li,
946 LIBINPUT_BUTTON_STATE_RELEASED);
948 litest_assert_empty_queue(li);
952 START_TEST(clickpad_softbutton_right_to_left)
954 struct litest_device *dev = litest_current_device();
955 struct libinput *li = dev->libinput;
957 litest_drain_events(li);
959 /* One finger down in right software button area,
960 move to left button area immediately, click
961 -> expect left button event
964 litest_touch_down(dev, 0, 90, 90);
965 litest_touch_move_to(dev, 0, 90, 90, 20, 90, 10);
966 litest_event(dev, EV_KEY, BTN_LEFT, 1);
967 litest_event(dev, EV_SYN, SYN_REPORT, 0);
969 assert_button_event(li,
971 LIBINPUT_BUTTON_STATE_PRESSED);
972 litest_assert_empty_queue(li);
974 litest_event(dev, EV_KEY, BTN_LEFT, 0);
975 litest_event(dev, EV_SYN, SYN_REPORT, 0);
976 litest_touch_up(dev, 0);
978 assert_button_event(li,
980 LIBINPUT_BUTTON_STATE_RELEASED);
982 litest_assert_empty_queue(li);
986 START_TEST(clickpad_topsoftbuttons_left)
988 struct litest_device *dev = litest_current_device();
989 struct libinput *li = dev->libinput;
991 litest_drain_events(li);
993 litest_touch_down(dev, 0, 10, 5);
994 litest_event(dev, EV_KEY, BTN_LEFT, 1);
995 litest_event(dev, EV_SYN, SYN_REPORT, 0);
997 assert_button_event(li,
999 LIBINPUT_BUTTON_STATE_PRESSED);
1000 litest_assert_empty_queue(li);
1002 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1003 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1004 litest_touch_up(dev, 0);
1006 assert_button_event(li,
1008 LIBINPUT_BUTTON_STATE_RELEASED);
1010 litest_assert_empty_queue(li);
1014 START_TEST(clickpad_topsoftbuttons_right)
1016 struct litest_device *dev = litest_current_device();
1017 struct libinput *li = dev->libinput;
1019 litest_drain_events(li);
1021 litest_touch_down(dev, 0, 90, 5);
1022 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1023 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1025 assert_button_event(li,
1027 LIBINPUT_BUTTON_STATE_PRESSED);
1028 litest_assert_empty_queue(li);
1030 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1031 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1032 litest_touch_up(dev, 0);
1034 assert_button_event(li,
1036 LIBINPUT_BUTTON_STATE_RELEASED);
1038 litest_assert_empty_queue(li);
1042 START_TEST(clickpad_topsoftbuttons_middle)
1044 struct litest_device *dev = litest_current_device();
1045 struct libinput *li = dev->libinput;
1047 litest_drain_events(li);
1049 litest_touch_down(dev, 0, 50, 5);
1050 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1051 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1053 assert_button_event(li,
1055 LIBINPUT_BUTTON_STATE_PRESSED);
1056 litest_assert_empty_queue(li);
1058 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1059 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1060 litest_touch_up(dev, 0);
1062 assert_button_event(li,
1064 LIBINPUT_BUTTON_STATE_RELEASED);
1066 litest_assert_empty_queue(li);
1070 START_TEST(clickpad_topsoftbuttons_move_out_ignore)
1072 struct litest_device *dev = litest_current_device();
1073 struct libinput *li = dev->libinput;
1075 /* Finger down in top button area, wait past enter timeout
1076 Move into main area, wait past leave timeout
1081 litest_drain_events(li);
1083 litest_touch_down(dev, 0, 50, 5);
1084 libinput_dispatch(li);
1086 libinput_dispatch(li);
1087 litest_assert_empty_queue(li);
1089 litest_touch_move_to(dev, 0, 50, 5, 80, 90, 20);
1090 libinput_dispatch(li);
1092 libinput_dispatch(li);
1094 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1095 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1096 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1097 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1099 litest_touch_up(dev, 0);
1101 litest_assert_empty_queue(li);
1106 test_2fg_scroll(struct litest_device *dev, int dx, int dy, int sleep)
1108 struct libinput *li = dev->libinput;
1110 litest_touch_down(dev, 0, 47, 50);
1111 litest_touch_down(dev, 1, 53, 50);
1113 litest_touch_move_to(dev, 0, 47, 50, 47 + dx, 50 + dy, 5);
1114 litest_touch_move_to(dev, 1, 53, 50, 53 + dx, 50 + dy, 5);
1116 /* Avoid a small scroll being seen as a tap */
1118 libinput_dispatch(li);
1120 libinput_dispatch(li);
1123 litest_touch_up(dev, 1);
1124 litest_touch_up(dev, 0);
1126 libinput_dispatch(li);
1130 check_2fg_scroll(struct litest_device *dev, int axis, int dir)
1132 struct libinput *li = dev->libinput;
1133 struct libinput_event *event, *next_event;
1134 struct libinput_event_pointer *ptrev;
1136 event = libinput_get_event(li);
1137 next_event = libinput_get_event(li);
1138 ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
1141 ck_assert_int_eq(libinput_event_get_type(event),
1142 LIBINPUT_EVENT_POINTER_AXIS);
1143 ptrev = libinput_event_get_pointer_event(event);
1144 ck_assert(ptrev != NULL);
1145 ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev), axis);
1148 /* Normal scroll event, check dir */
1151 libinput_event_pointer_get_axis_value(ptrev),
1155 libinput_event_pointer_get_axis_value(ptrev),
1159 /* Last scroll event, must be 0 */
1161 libinput_event_pointer_get_axis_value(ptrev),
1164 libinput_event_destroy(event);
1166 next_event = libinput_get_event(li);
1170 START_TEST(touchpad_2fg_scroll)
1172 struct litest_device *dev = litest_current_device();
1173 struct libinput *li = dev->libinput;
1175 litest_drain_events(li);
1177 /* Note this mixes in a tiny amount of movement in the wrong direction,
1178 which should be ignored */
1179 test_2fg_scroll(dev, 1, 40, 0);
1180 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
1181 test_2fg_scroll(dev, 1, -40, 0);
1182 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
1183 test_2fg_scroll(dev, 40, 1, 0);
1184 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
1185 test_2fg_scroll(dev, -40, 1, 0);
1186 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
1188 /* 2fg scroll smaller than the threshold should not generate events */
1189 test_2fg_scroll(dev, 1, 1, 200);
1190 litest_assert_empty_queue(li);
1194 int main(int argc, char **argv) {
1196 litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
1197 litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1199 litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
1200 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
1201 litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1202 litest_add("touchpad:tap", touchpad_2fg_tap_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1203 litest_add("touchpad:tap", touchpad_1fg_tap_click, LITEST_TOUCHPAD, LITEST_ANY);
1204 litest_add("touchpad:tap", touchpad_2fg_tap_click, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD);
1205 litest_add("touchpad:tap", touchpad_2fg_tap_click_apple, LITEST_APPLE_CLICKPAD, LITEST_ANY);
1206 litest_add("touchpad:tap", touchpad_no_2fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1207 litest_add("touchpad:tap", touchpad_no_2fg_tap_after_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1208 litest_add("touchpad:tap", touchpad_no_first_fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1209 litest_add("touchpad:tap", touchpad_no_first_fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1211 /* Real buttons don't interfere with tapping, so don't run those for
1212 pads with buttons */
1213 litest_add("touchpad:tap", touchpad_1fg_double_tap_click, LITEST_CLICKPAD, LITEST_ANY);
1214 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
1216 litest_add_no_device("touchpad:clickfinger", touchpad_1fg_clickfinger);
1217 litest_add_no_device("touchpad:clickfinger", touchpad_2fg_clickfinger);
1219 litest_add("touchpad:click", touchpad_btn_left, LITEST_TOUCHPAD, LITEST_CLICKPAD);
1220 litest_add("touchpad:click", clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY);
1221 litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
1223 litest_add("touchpad:softbutton", clickpad_softbutton_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1224 litest_add("touchpad:softbutton", clickpad_softbutton_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1225 litest_add("touchpad:softbutton", clickpad_softbutton_left_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1226 litest_add("touchpad:softbutton", clickpad_softbutton_right_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1227 litest_add("touchpad:softbutton", clickpad_softbutton_left_1st_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1228 litest_add("touchpad:softbutton", clickpad_softbutton_left_2nd_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1229 litest_add("touchpad:softbutton", clickpad_softbutton_left_to_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1230 litest_add("touchpad:softbutton", clickpad_softbutton_right_to_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1232 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_left, LITEST_TOPBUTTONPAD, LITEST_ANY);
1233 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_right, LITEST_TOPBUTTONPAD, LITEST_ANY);
1234 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_middle, LITEST_TOPBUTTONPAD, LITEST_ANY);
1235 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_move_out_ignore, LITEST_TOPBUTTONPAD, LITEST_ANY);
1237 litest_add("touchpad:scroll", touchpad_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1239 return litest_run(argc, argv);