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_event(dev, EV_KEY, BTN_LEFT, 0);
929 litest_event(dev, EV_SYN, SYN_REPORT, 0);
930 litest_touch_up(dev, 0);
932 assert_button_event(li,
934 LIBINPUT_BUTTON_STATE_RELEASED);
936 litest_assert_empty_queue(li);
940 START_TEST(clickpad_softbutton_left_to_right)
942 struct litest_device *dev = litest_current_device();
943 struct libinput *li = dev->libinput;
945 litest_drain_events(li);
947 /* One finger down in left software button area,
948 move to right button area immediately, click
949 -> expect right button event
952 litest_touch_down(dev, 0, 20, 90);
953 litest_touch_move_to(dev, 0, 20, 90, 90, 90, 10);
954 litest_event(dev, EV_KEY, BTN_LEFT, 1);
955 litest_event(dev, EV_SYN, SYN_REPORT, 0);
957 assert_button_event(li,
959 LIBINPUT_BUTTON_STATE_PRESSED);
960 litest_assert_empty_queue(li);
962 litest_event(dev, EV_KEY, BTN_LEFT, 0);
963 litest_event(dev, EV_SYN, SYN_REPORT, 0);
964 litest_touch_up(dev, 0);
966 assert_button_event(li,
968 LIBINPUT_BUTTON_STATE_RELEASED);
970 litest_assert_empty_queue(li);
974 START_TEST(clickpad_softbutton_right_to_left)
976 struct litest_device *dev = litest_current_device();
977 struct libinput *li = dev->libinput;
979 litest_drain_events(li);
981 /* One finger down in right software button area,
982 move to left button area immediately, click
983 -> expect left button event
986 litest_touch_down(dev, 0, 90, 90);
987 litest_touch_move_to(dev, 0, 90, 90, 20, 90, 10);
988 litest_event(dev, EV_KEY, BTN_LEFT, 1);
989 litest_event(dev, EV_SYN, SYN_REPORT, 0);
991 assert_button_event(li,
993 LIBINPUT_BUTTON_STATE_PRESSED);
994 litest_assert_empty_queue(li);
996 litest_event(dev, EV_KEY, BTN_LEFT, 0);
997 litest_event(dev, EV_SYN, SYN_REPORT, 0);
998 litest_touch_up(dev, 0);
1000 assert_button_event(li,
1002 LIBINPUT_BUTTON_STATE_RELEASED);
1004 litest_assert_empty_queue(li);
1008 START_TEST(clickpad_topsoftbuttons_left)
1010 struct litest_device *dev = litest_current_device();
1011 struct libinput *li = dev->libinput;
1013 litest_drain_events(li);
1015 litest_touch_down(dev, 0, 10, 5);
1016 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1017 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1019 assert_button_event(li,
1021 LIBINPUT_BUTTON_STATE_PRESSED);
1022 litest_assert_empty_queue(li);
1024 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1025 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1026 litest_touch_up(dev, 0);
1028 assert_button_event(li,
1030 LIBINPUT_BUTTON_STATE_RELEASED);
1032 litest_assert_empty_queue(li);
1036 START_TEST(clickpad_topsoftbuttons_right)
1038 struct litest_device *dev = litest_current_device();
1039 struct libinput *li = dev->libinput;
1041 litest_drain_events(li);
1043 litest_touch_down(dev, 0, 90, 5);
1044 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1045 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1047 assert_button_event(li,
1049 LIBINPUT_BUTTON_STATE_PRESSED);
1050 litest_assert_empty_queue(li);
1052 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1053 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1054 litest_touch_up(dev, 0);
1056 assert_button_event(li,
1058 LIBINPUT_BUTTON_STATE_RELEASED);
1060 litest_assert_empty_queue(li);
1064 START_TEST(clickpad_topsoftbuttons_middle)
1066 struct litest_device *dev = litest_current_device();
1067 struct libinput *li = dev->libinput;
1069 litest_drain_events(li);
1071 litest_touch_down(dev, 0, 50, 5);
1072 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1073 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1075 assert_button_event(li,
1077 LIBINPUT_BUTTON_STATE_PRESSED);
1078 litest_assert_empty_queue(li);
1080 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1081 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1082 litest_touch_up(dev, 0);
1084 assert_button_event(li,
1086 LIBINPUT_BUTTON_STATE_RELEASED);
1088 litest_assert_empty_queue(li);
1092 START_TEST(clickpad_topsoftbuttons_move_out_ignore)
1094 struct litest_device *dev = litest_current_device();
1095 struct libinput *li = dev->libinput;
1097 /* Finger down in top button area, wait past enter timeout
1098 Move into main area, wait past leave timeout
1103 litest_drain_events(li);
1105 litest_touch_down(dev, 0, 50, 5);
1106 libinput_dispatch(li);
1108 libinput_dispatch(li);
1109 litest_assert_empty_queue(li);
1111 litest_touch_move_to(dev, 0, 50, 5, 80, 90, 20);
1112 libinput_dispatch(li);
1114 libinput_dispatch(li);
1116 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1117 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1118 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1119 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1121 litest_touch_up(dev, 0);
1123 litest_assert_empty_queue(li);
1128 test_2fg_scroll(struct litest_device *dev, int dx, int dy, int sleep)
1130 struct libinput *li = dev->libinput;
1132 litest_touch_down(dev, 0, 47, 50);
1133 litest_touch_down(dev, 1, 53, 50);
1135 litest_touch_move_to(dev, 0, 47, 50, 47 + dx, 50 + dy, 5);
1136 litest_touch_move_to(dev, 1, 53, 50, 53 + dx, 50 + dy, 5);
1138 /* Avoid a small scroll being seen as a tap */
1140 libinput_dispatch(li);
1142 libinput_dispatch(li);
1145 litest_touch_up(dev, 1);
1146 litest_touch_up(dev, 0);
1148 libinput_dispatch(li);
1152 check_2fg_scroll(struct litest_device *dev, unsigned int axis, int dir)
1154 struct libinput *li = dev->libinput;
1155 struct libinput_event *event, *next_event;
1156 struct libinput_event_pointer *ptrev;
1158 event = libinput_get_event(li);
1159 next_event = libinput_get_event(li);
1160 ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
1163 ck_assert_int_eq(libinput_event_get_type(event),
1164 LIBINPUT_EVENT_POINTER_AXIS);
1165 ptrev = libinput_event_get_pointer_event(event);
1166 ck_assert(ptrev != NULL);
1167 ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev), axis);
1170 /* Normal scroll event, check dir */
1173 libinput_event_pointer_get_axis_value(ptrev),
1177 libinput_event_pointer_get_axis_value(ptrev),
1181 /* Last scroll event, must be 0 */
1183 libinput_event_pointer_get_axis_value(ptrev),
1186 libinput_event_destroy(event);
1188 next_event = libinput_get_event(li);
1192 START_TEST(touchpad_2fg_scroll)
1194 struct litest_device *dev = litest_current_device();
1195 struct libinput *li = dev->libinput;
1197 litest_drain_events(li);
1199 /* Note this mixes in a tiny amount of movement in the wrong direction,
1200 which should be ignored */
1201 test_2fg_scroll(dev, 1, 40, 0);
1202 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
1203 test_2fg_scroll(dev, 1, -40, 0);
1204 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
1205 test_2fg_scroll(dev, 40, 1, 0);
1206 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
1207 test_2fg_scroll(dev, -40, 1, 0);
1208 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
1210 /* 2fg scroll smaller than the threshold should not generate events */
1211 test_2fg_scroll(dev, 1, 1, 200);
1212 litest_assert_empty_queue(li);
1216 START_TEST(touchpad_tap_is_available)
1218 struct litest_device *dev = litest_current_device();
1220 ck_assert_int_ge(libinput_device_config_tap_get_finger_count(dev->libinput_device), 1);
1221 ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), 0);
1225 START_TEST(touchpad_tap_is_not_available)
1227 struct litest_device *dev = litest_current_device();
1229 ck_assert_int_eq(libinput_device_config_tap_get_finger_count(dev->libinput_device), 0);
1230 ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), 0);
1231 ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, 1),
1232 LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
1236 START_TEST(touchpad_tap_default)
1238 struct litest_device *dev = litest_current_device();
1240 ck_assert_int_eq(libinput_device_config_tap_get_default_enabled(dev->libinput_device), 0);
1244 int main(int argc, char **argv) {
1246 litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
1247 litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1249 litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
1250 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
1251 litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1252 litest_add("touchpad:tap", touchpad_2fg_tap_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1253 litest_add("touchpad:tap", touchpad_1fg_tap_click, LITEST_TOUCHPAD, LITEST_ANY);
1254 litest_add("touchpad:tap", touchpad_2fg_tap_click, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD);
1255 litest_add("touchpad:tap", touchpad_2fg_tap_click_apple, LITEST_APPLE_CLICKPAD, LITEST_ANY);
1256 litest_add("touchpad:tap", touchpad_no_2fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1257 litest_add("touchpad:tap", touchpad_no_2fg_tap_after_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1258 litest_add("touchpad:tap", touchpad_no_first_fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1259 litest_add("touchpad:tap", touchpad_no_first_fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1261 /* Real buttons don't interfere with tapping, so don't run those for
1262 pads with buttons */
1263 litest_add("touchpad:tap", touchpad_1fg_double_tap_click, LITEST_CLICKPAD, LITEST_ANY);
1264 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
1266 litest_add("touchpad:tap", touchpad_tap_default, LITEST_TOUCHPAD, LITEST_ANY);
1267 litest_add("touchpad:tap", touchpad_tap_is_available, LITEST_TOUCHPAD, LITEST_ANY);
1268 litest_add("touchpad:tap", touchpad_tap_is_not_available, LITEST_ANY, LITEST_TOUCHPAD);
1270 litest_add_no_device("touchpad:clickfinger", touchpad_1fg_clickfinger);
1271 litest_add_no_device("touchpad:clickfinger", touchpad_2fg_clickfinger);
1273 litest_add("touchpad:click", touchpad_btn_left, LITEST_TOUCHPAD, LITEST_CLICKPAD);
1274 litest_add("touchpad:click", clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY);
1275 litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
1277 litest_add("touchpad:softbutton", clickpad_softbutton_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1278 litest_add("touchpad:softbutton", clickpad_softbutton_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1279 litest_add("touchpad:softbutton", clickpad_softbutton_left_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1280 litest_add("touchpad:softbutton", clickpad_softbutton_right_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1281 litest_add("touchpad:softbutton", clickpad_softbutton_left_1st_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1282 litest_add("touchpad:softbutton", clickpad_softbutton_left_2nd_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1283 litest_add("touchpad:softbutton", clickpad_softbutton_left_to_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1284 litest_add("touchpad:softbutton", clickpad_softbutton_right_to_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1286 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_left, LITEST_TOPBUTTONPAD, LITEST_ANY);
1287 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_right, LITEST_TOPBUTTONPAD, LITEST_ANY);
1288 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_middle, LITEST_TOPBUTTONPAD, LITEST_ANY);
1289 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_move_out_ignore, LITEST_TOPBUTTONPAD, LITEST_ANY);
1291 litest_add("touchpad:scroll", touchpad_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1293 return litest_run(argc, argv);