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_1fg_double_tap_click)
325 struct litest_device *dev = litest_current_device();
326 struct libinput *li = dev->libinput;
328 litest_drain_events(dev->libinput);
330 /* one finger down, up, down, button click, finger up
331 -> two button left event pairs */
332 litest_touch_down(dev, 0, 50, 50);
333 litest_touch_up(dev, 0);
334 litest_touch_down(dev, 0, 50, 50);
335 litest_event(dev, EV_KEY, BTN_LEFT, 1);
336 litest_event(dev, EV_SYN, SYN_REPORT, 0);
337 litest_event(dev, EV_KEY, BTN_LEFT, 0);
338 litest_event(dev, EV_SYN, SYN_REPORT, 0);
339 litest_touch_up(dev, 0);
341 libinput_dispatch(li);
343 assert_button_event(li, BTN_LEFT,
344 LIBINPUT_BUTTON_STATE_PRESSED);
345 assert_button_event(li, BTN_LEFT,
346 LIBINPUT_BUTTON_STATE_RELEASED);
347 assert_button_event(li, BTN_LEFT,
348 LIBINPUT_BUTTON_STATE_PRESSED);
349 assert_button_event(li, BTN_LEFT,
350 LIBINPUT_BUTTON_STATE_RELEASED);
352 litest_assert_empty_queue(li);
356 START_TEST(touchpad_1fg_tap_n_drag_click)
358 struct litest_device *dev = litest_current_device();
359 struct libinput *li = dev->libinput;
360 struct libinput_event *event;
362 litest_drain_events(dev->libinput);
364 /* one finger down, up, down, move, button click, finger up
365 -> two button left event pairs, motion allowed */
366 litest_touch_down(dev, 0, 50, 50);
367 litest_touch_up(dev, 0);
368 litest_touch_down(dev, 0, 50, 50);
369 litest_touch_move_to(dev, 0, 50, 50, 80, 50, 10);
371 assert_button_event(li, BTN_LEFT,
372 LIBINPUT_BUTTON_STATE_PRESSED);
374 libinput_dispatch(li);
376 ck_assert_int_eq(libinput_next_event_type(li),
377 LIBINPUT_EVENT_POINTER_MOTION);
378 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
379 event = libinput_get_event(li);
380 libinput_event_destroy(event);
381 libinput_dispatch(li);
384 litest_event(dev, EV_KEY, BTN_LEFT, 1);
385 litest_event(dev, EV_SYN, SYN_REPORT, 0);
387 assert_button_event(li, BTN_LEFT,
388 LIBINPUT_BUTTON_STATE_RELEASED);
389 assert_button_event(li, BTN_LEFT,
390 LIBINPUT_BUTTON_STATE_PRESSED);
392 litest_event(dev, EV_KEY, BTN_LEFT, 0);
393 litest_event(dev, EV_SYN, SYN_REPORT, 0);
394 litest_touch_up(dev, 0);
396 libinput_dispatch(li);
398 assert_button_event(li, BTN_LEFT,
399 LIBINPUT_BUTTON_STATE_RELEASED);
401 litest_assert_empty_queue(li);
405 START_TEST(touchpad_1fg_clickfinger)
407 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
408 struct libinput *li = dev->libinput;
410 litest_drain_events(li);
412 litest_touch_down(dev, 0, 50, 50);
413 litest_event(dev, EV_KEY, BTN_LEFT, 1);
414 litest_event(dev, EV_SYN, SYN_REPORT, 0);
415 litest_event(dev, EV_KEY, BTN_LEFT, 0);
416 litest_event(dev, EV_SYN, SYN_REPORT, 0);
417 litest_touch_up(dev, 0);
419 libinput_dispatch(li);
421 assert_button_event(li, BTN_LEFT,
422 LIBINPUT_BUTTON_STATE_PRESSED);
423 assert_button_event(li, BTN_LEFT,
424 LIBINPUT_BUTTON_STATE_RELEASED);
426 litest_delete_device(dev);
430 START_TEST(touchpad_2fg_clickfinger)
432 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
433 struct libinput *li = dev->libinput;
435 litest_drain_events(li);
437 litest_touch_down(dev, 0, 50, 50);
438 litest_touch_down(dev, 1, 70, 70);
439 litest_event(dev, EV_KEY, BTN_LEFT, 1);
440 litest_event(dev, EV_SYN, SYN_REPORT, 0);
441 litest_event(dev, EV_KEY, BTN_LEFT, 0);
442 litest_event(dev, EV_SYN, SYN_REPORT, 0);
443 litest_touch_up(dev, 0);
444 litest_touch_up(dev, 1);
446 libinput_dispatch(li);
448 assert_button_event(li, BTN_RIGHT,
449 LIBINPUT_BUTTON_STATE_PRESSED);
450 assert_button_event(li, BTN_RIGHT,
451 LIBINPUT_BUTTON_STATE_RELEASED);
453 litest_delete_device(dev);
457 START_TEST(touchpad_btn_left)
459 struct litest_device *dev = litest_current_device();
460 struct libinput *li = dev->libinput;
462 litest_drain_events(li);
464 litest_event(dev, EV_KEY, BTN_LEFT, 1);
465 litest_event(dev, EV_SYN, SYN_REPORT, 0);
466 litest_event(dev, EV_KEY, BTN_LEFT, 0);
467 litest_event(dev, EV_SYN, SYN_REPORT, 0);
469 libinput_dispatch(li);
471 assert_button_event(li, BTN_LEFT,
472 LIBINPUT_BUTTON_STATE_PRESSED);
473 assert_button_event(li, BTN_LEFT,
474 LIBINPUT_BUTTON_STATE_RELEASED);
478 START_TEST(clickpad_btn_left)
480 struct litest_device *dev = litest_current_device();
481 struct libinput *li = dev->libinput;
483 litest_drain_events(li);
485 /* A clickpad always needs a finger down to tell where the
487 litest_event(dev, EV_KEY, BTN_LEFT, 1);
488 litest_event(dev, EV_SYN, SYN_REPORT, 0);
489 litest_event(dev, EV_KEY, BTN_LEFT, 0);
490 litest_event(dev, EV_SYN, SYN_REPORT, 0);
492 libinput_dispatch(li);
493 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
497 START_TEST(clickpad_click_n_drag)
499 struct litest_device *dev = litest_current_device();
500 struct libinput *li = dev->libinput;
501 struct libinput_event *event;
503 litest_drain_events(li);
505 litest_touch_down(dev, 0, 50, 50);
506 litest_event(dev, EV_KEY, BTN_LEFT, 1);
507 litest_event(dev, EV_SYN, SYN_REPORT, 0);
509 libinput_dispatch(li);
510 assert_button_event(li, BTN_LEFT,
511 LIBINPUT_BUTTON_STATE_PRESSED);
513 libinput_dispatch(li);
514 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
516 /* now put a second finger down */
517 litest_touch_down(dev, 1, 70, 70);
518 litest_touch_move_to(dev, 1, 70, 70, 80, 50, 5);
519 litest_touch_up(dev, 1);
521 libinput_dispatch(li);
522 ck_assert_int_eq(libinput_next_event_type(li),
523 LIBINPUT_EVENT_POINTER_MOTION);
525 event = libinput_get_event(li);
526 libinput_event_destroy(event);
527 libinput_dispatch(li);
528 } while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION);
530 litest_event(dev, EV_KEY, BTN_LEFT, 0);
531 litest_event(dev, EV_SYN, SYN_REPORT, 0);
532 litest_touch_up(dev, 0);
534 assert_button_event(li, BTN_LEFT,
535 LIBINPUT_BUTTON_STATE_RELEASED);
539 START_TEST(clickpad_softbutton_left)
541 struct litest_device *dev = litest_current_device();
542 struct libinput *li = dev->libinput;
544 litest_drain_events(li);
546 litest_touch_down(dev, 0, 10, 90);
547 litest_event(dev, EV_KEY, BTN_LEFT, 1);
548 litest_event(dev, EV_SYN, SYN_REPORT, 0);
550 assert_button_event(li,
552 LIBINPUT_BUTTON_STATE_PRESSED);
554 litest_event(dev, EV_KEY, BTN_LEFT, 0);
555 litest_event(dev, EV_SYN, SYN_REPORT, 0);
556 litest_touch_up(dev, 0);
558 assert_button_event(li,
560 LIBINPUT_BUTTON_STATE_RELEASED);
562 libinput_dispatch(li);
564 litest_assert_empty_queue(li);
568 START_TEST(clickpad_softbutton_right)
570 struct litest_device *dev = litest_current_device();
571 struct libinput *li = dev->libinput;
573 litest_drain_events(li);
575 litest_touch_down(dev, 0, 90, 90);
576 litest_event(dev, EV_KEY, BTN_LEFT, 1);
577 litest_event(dev, EV_SYN, SYN_REPORT, 0);
579 assert_button_event(li,
581 LIBINPUT_BUTTON_STATE_PRESSED);
583 litest_event(dev, EV_KEY, BTN_LEFT, 0);
584 litest_event(dev, EV_SYN, SYN_REPORT, 0);
585 litest_touch_up(dev, 0);
587 assert_button_event(li,
589 LIBINPUT_BUTTON_STATE_RELEASED);
591 libinput_dispatch(li);
593 litest_assert_empty_queue(li);
597 START_TEST(clickpad_softbutton_left_tap_n_drag)
599 struct litest_device *dev = litest_current_device();
600 struct libinput *li = dev->libinput;
602 litest_drain_events(li);
604 /* Tap in left button area, then finger down, button click
605 -> expect left button press/release and left button press
606 Release button, finger up
607 -> expect right button release
609 litest_touch_down(dev, 0, 20, 90);
610 litest_touch_up(dev, 0);
611 litest_touch_down(dev, 0, 20, 90);
612 litest_event(dev, EV_KEY, BTN_LEFT, 1);
613 litest_event(dev, EV_SYN, SYN_REPORT, 0);
615 assert_button_event(li,
617 LIBINPUT_BUTTON_STATE_PRESSED);
618 assert_button_event(li,
620 LIBINPUT_BUTTON_STATE_RELEASED);
621 assert_button_event(li,
623 LIBINPUT_BUTTON_STATE_PRESSED);
624 litest_assert_empty_queue(li);
626 litest_event(dev, EV_KEY, BTN_LEFT, 0);
627 litest_event(dev, EV_SYN, SYN_REPORT, 0);
628 litest_touch_up(dev, 0);
630 assert_button_event(li,
632 LIBINPUT_BUTTON_STATE_RELEASED);
633 litest_assert_empty_queue(li);
637 START_TEST(clickpad_softbutton_right_tap_n_drag)
639 struct litest_device *dev = litest_current_device();
640 struct libinput *li = dev->libinput;
642 litest_drain_events(li);
644 /* Tap in right button area, then finger down, button click
645 -> expect left button press/release and right button press
646 Release button, finger up
647 -> expect right button release
649 litest_touch_down(dev, 0, 90, 90);
650 litest_touch_up(dev, 0);
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);
658 assert_button_event(li,
660 LIBINPUT_BUTTON_STATE_RELEASED);
661 assert_button_event(li,
663 LIBINPUT_BUTTON_STATE_PRESSED);
664 litest_assert_empty_queue(li);
666 litest_event(dev, EV_KEY, BTN_LEFT, 0);
667 litest_event(dev, EV_SYN, SYN_REPORT, 0);
668 litest_touch_up(dev, 0);
670 assert_button_event(li,
672 LIBINPUT_BUTTON_STATE_RELEASED);
673 litest_assert_empty_queue(li);
677 START_TEST(clickpad_softbutton_left_1st_fg_move)
679 struct litest_device *dev = litest_current_device();
680 struct libinput *li = dev->libinput;
681 struct libinput_event *event;
685 litest_drain_events(li);
687 /* One finger down in the left button area, button press
688 -> expect a button event
689 Move finger up out of the area, wait for timeout
690 Move finger around diagonally down left
691 -> expect motion events down left
693 -> expect a button event */
695 /* finger down, press in left button */
696 litest_touch_down(dev, 0, 20, 90);
697 litest_event(dev, EV_KEY, BTN_LEFT, 1);
698 litest_event(dev, EV_SYN, SYN_REPORT, 0);
700 assert_button_event(li,
702 LIBINPUT_BUTTON_STATE_PRESSED);
703 litest_assert_empty_queue(li);
705 /* move out of the area, then wait for softbutton timer */
706 litest_touch_move_to(dev, 0, 20, 90, 90, 20, 10);
707 libinput_dispatch(li);
709 libinput_dispatch(li);
710 litest_drain_events(li);
712 /* move down left, expect motion */
713 litest_touch_move_to(dev, 0, 90, 20, 20, 90, 10);
715 libinput_dispatch(li);
716 event = libinput_get_event(li);
717 ck_assert(event != NULL);
719 struct libinput_event_pointer *p;
721 ck_assert_int_eq(libinput_event_get_type(event),
722 LIBINPUT_EVENT_POINTER_MOTION);
723 p = libinput_event_get_pointer_event(event);
725 /* we moved up/right, now down/left so the pointer accel
726 code may lag behind with the dx/dy vectors. Hence, add up
727 the x/y movements and expect that on average we moved
729 x += libinput_event_pointer_get_dx(p);
730 y += libinput_event_pointer_get_dy(p);
733 libinput_event_destroy(event);
734 libinput_dispatch(li);
735 event = libinput_get_event(li);
738 ck_assert(x/nevents < 0);
739 ck_assert(y/nevents > 0);
741 litest_event(dev, EV_KEY, BTN_LEFT, 0);
742 litest_event(dev, EV_SYN, SYN_REPORT, 0);
743 litest_touch_up(dev, 0);
745 assert_button_event(li,
747 LIBINPUT_BUTTON_STATE_RELEASED);
749 litest_assert_empty_queue(li);
753 START_TEST(clickpad_softbutton_left_2nd_fg_move)
755 struct litest_device *dev = litest_current_device();
756 struct libinput *li = dev->libinput;
757 struct libinput_event *event;
759 litest_drain_events(li);
761 /* One finger down in the left button area, button press
762 -> expect a button event
763 Put a second finger down in the area, move it right, release
764 -> expect motion events right
765 Put a second finger down in the area, move it down, release
766 -> expect motion events down
767 Release second finger, release first finger
768 -> expect a button event */
769 litest_touch_down(dev, 0, 20, 90);
770 litest_event(dev, EV_KEY, BTN_LEFT, 1);
771 litest_event(dev, EV_SYN, SYN_REPORT, 0);
773 assert_button_event(li,
775 LIBINPUT_BUTTON_STATE_PRESSED);
776 litest_assert_empty_queue(li);
778 litest_touch_down(dev, 1, 20, 20);
779 litest_touch_move_to(dev, 1, 20, 20, 80, 20, 10);
781 libinput_dispatch(li);
782 event = libinput_get_event(li);
783 ck_assert(event != NULL);
785 struct libinput_event_pointer *p;
788 ck_assert_int_eq(libinput_event_get_type(event),
789 LIBINPUT_EVENT_POINTER_MOTION);
790 p = libinput_event_get_pointer_event(event);
792 x = libinput_event_pointer_get_dx(p);
793 y = libinput_event_pointer_get_dy(p);
798 libinput_event_destroy(event);
799 libinput_dispatch(li);
800 event = libinput_get_event(li);
802 litest_touch_up(dev, 1);
804 /* second finger down */
805 litest_touch_down(dev, 1, 20, 20);
806 litest_touch_move_to(dev, 1, 20, 20, 20, 80, 10);
808 libinput_dispatch(li);
809 event = libinput_get_event(li);
810 ck_assert(event != NULL);
812 struct libinput_event_pointer *p;
815 ck_assert_int_eq(libinput_event_get_type(event),
816 LIBINPUT_EVENT_POINTER_MOTION);
817 p = libinput_event_get_pointer_event(event);
819 x = libinput_event_pointer_get_dx(p);
820 y = libinput_event_pointer_get_dy(p);
825 libinput_event_destroy(event);
826 libinput_dispatch(li);
827 event = libinput_get_event(li);
830 litest_event(dev, EV_KEY, BTN_LEFT, 0);
831 litest_event(dev, EV_SYN, SYN_REPORT, 0);
832 litest_touch_up(dev, 0);
834 assert_button_event(li,
836 LIBINPUT_BUTTON_STATE_RELEASED);
838 litest_assert_empty_queue(li);
842 START_TEST(clickpad_softbutton_left_to_right)
844 struct litest_device *dev = litest_current_device();
845 struct libinput *li = dev->libinput;
847 litest_drain_events(li);
849 /* One finger down in left software button area,
850 move to right button area immediately, click
851 -> expect right button event
854 litest_touch_down(dev, 0, 20, 90);
855 litest_touch_move_to(dev, 0, 20, 90, 90, 90, 10);
856 litest_event(dev, EV_KEY, BTN_LEFT, 1);
857 litest_event(dev, EV_SYN, SYN_REPORT, 0);
859 assert_button_event(li,
861 LIBINPUT_BUTTON_STATE_PRESSED);
862 litest_assert_empty_queue(li);
864 litest_event(dev, EV_KEY, BTN_LEFT, 0);
865 litest_event(dev, EV_SYN, SYN_REPORT, 0);
866 litest_touch_up(dev, 0);
868 assert_button_event(li,
870 LIBINPUT_BUTTON_STATE_RELEASED);
872 litest_assert_empty_queue(li);
876 START_TEST(clickpad_softbutton_right_to_left)
878 struct litest_device *dev = litest_current_device();
879 struct libinput *li = dev->libinput;
881 litest_drain_events(li);
883 /* One finger down in right software button area,
884 move to left button area immediately, click
885 -> expect left button event
888 litest_touch_down(dev, 0, 90, 90);
889 litest_touch_move_to(dev, 0, 90, 90, 20, 90, 10);
890 litest_event(dev, EV_KEY, BTN_LEFT, 1);
891 litest_event(dev, EV_SYN, SYN_REPORT, 0);
893 assert_button_event(li,
895 LIBINPUT_BUTTON_STATE_PRESSED);
896 litest_assert_empty_queue(li);
898 litest_event(dev, EV_KEY, BTN_LEFT, 0);
899 litest_event(dev, EV_SYN, SYN_REPORT, 0);
900 litest_touch_up(dev, 0);
902 assert_button_event(li,
904 LIBINPUT_BUTTON_STATE_RELEASED);
906 litest_assert_empty_queue(li);
910 START_TEST(clickpad_topsoftbuttons_left)
912 struct litest_device *dev = litest_current_device();
913 struct libinput *li = dev->libinput;
915 litest_drain_events(li);
917 litest_touch_down(dev, 0, 10, 5);
918 litest_event(dev, EV_KEY, BTN_LEFT, 1);
919 litest_event(dev, EV_SYN, SYN_REPORT, 0);
921 assert_button_event(li,
923 LIBINPUT_BUTTON_STATE_PRESSED);
924 litest_assert_empty_queue(li);
926 litest_event(dev, EV_KEY, BTN_LEFT, 0);
927 litest_event(dev, EV_SYN, SYN_REPORT, 0);
928 litest_touch_up(dev, 0);
930 assert_button_event(li,
932 LIBINPUT_BUTTON_STATE_RELEASED);
934 litest_assert_empty_queue(li);
938 START_TEST(clickpad_topsoftbuttons_right)
940 struct litest_device *dev = litest_current_device();
941 struct libinput *li = dev->libinput;
943 litest_drain_events(li);
945 litest_touch_down(dev, 0, 90, 5);
946 litest_event(dev, EV_KEY, BTN_LEFT, 1);
947 litest_event(dev, EV_SYN, SYN_REPORT, 0);
949 assert_button_event(li,
951 LIBINPUT_BUTTON_STATE_PRESSED);
952 litest_assert_empty_queue(li);
954 litest_event(dev, EV_KEY, BTN_LEFT, 0);
955 litest_event(dev, EV_SYN, SYN_REPORT, 0);
956 litest_touch_up(dev, 0);
958 assert_button_event(li,
960 LIBINPUT_BUTTON_STATE_RELEASED);
962 litest_assert_empty_queue(li);
966 START_TEST(clickpad_topsoftbuttons_middle)
968 struct litest_device *dev = litest_current_device();
969 struct libinput *li = dev->libinput;
971 litest_drain_events(li);
973 litest_touch_down(dev, 0, 50, 5);
974 litest_event(dev, EV_KEY, BTN_LEFT, 1);
975 litest_event(dev, EV_SYN, SYN_REPORT, 0);
977 assert_button_event(li,
979 LIBINPUT_BUTTON_STATE_PRESSED);
980 litest_assert_empty_queue(li);
982 litest_event(dev, EV_KEY, BTN_LEFT, 0);
983 litest_event(dev, EV_SYN, SYN_REPORT, 0);
984 litest_touch_up(dev, 0);
986 assert_button_event(li,
988 LIBINPUT_BUTTON_STATE_RELEASED);
990 litest_assert_empty_queue(li);
994 START_TEST(clickpad_topsoftbuttons_move_out_ignore)
996 struct litest_device *dev = litest_current_device();
997 struct libinput *li = dev->libinput;
999 /* Finger down in top button area, wait past enter timeout
1000 Move into main area, wait past leave timeout
1005 litest_drain_events(li);
1007 litest_touch_down(dev, 0, 50, 5);
1008 libinput_dispatch(li);
1010 libinput_dispatch(li);
1011 litest_assert_empty_queue(li);
1013 litest_touch_move_to(dev, 0, 50, 5, 80, 90, 20);
1014 libinput_dispatch(li);
1016 libinput_dispatch(li);
1018 litest_event(dev, EV_KEY, BTN_LEFT, 1);
1019 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1020 litest_event(dev, EV_KEY, BTN_LEFT, 0);
1021 litest_event(dev, EV_SYN, SYN_REPORT, 0);
1023 litest_touch_up(dev, 0);
1025 litest_assert_empty_queue(li);
1030 test_2fg_scroll(struct litest_device *dev, int dx, int dy, int sleep)
1032 struct libinput *li = dev->libinput;
1034 litest_touch_down(dev, 0, 47, 50);
1035 litest_touch_down(dev, 1, 53, 50);
1037 litest_touch_move_to(dev, 0, 47, 50, 47 + dx, 50 + dy, 5);
1038 litest_touch_move_to(dev, 1, 53, 50, 53 + dx, 50 + dy, 5);
1040 /* Avoid a small scroll being seen as a tap */
1042 libinput_dispatch(li);
1044 libinput_dispatch(li);
1047 litest_touch_up(dev, 1);
1048 litest_touch_up(dev, 0);
1050 libinput_dispatch(li);
1054 check_2fg_scroll(struct litest_device *dev, int axis, int dir)
1056 struct libinput *li = dev->libinput;
1057 struct libinput_event *event, *next_event;
1058 struct libinput_event_pointer *ptrev;
1060 event = libinput_get_event(li);
1061 next_event = libinput_get_event(li);
1062 ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
1065 ck_assert_int_eq(libinput_event_get_type(event),
1066 LIBINPUT_EVENT_POINTER_AXIS);
1067 ptrev = libinput_event_get_pointer_event(event);
1068 ck_assert(ptrev != NULL);
1069 ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev), axis);
1072 /* Normal scroll event, check dir */
1075 libinput_event_pointer_get_axis_value(ptrev),
1079 libinput_event_pointer_get_axis_value(ptrev),
1083 /* Last scroll event, must be 0 */
1085 libinput_event_pointer_get_axis_value(ptrev),
1088 libinput_event_destroy(event);
1090 next_event = libinput_get_event(li);
1094 START_TEST(touchpad_2fg_scroll)
1096 struct litest_device *dev = litest_current_device();
1097 struct libinput *li = dev->libinput;
1099 litest_drain_events(li);
1101 /* Note this mixes in a tiny amount of movement in the wrong direction,
1102 which should be ignored */
1103 test_2fg_scroll(dev, 1, 40, 0);
1104 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
1105 test_2fg_scroll(dev, 1, -40, 0);
1106 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
1107 test_2fg_scroll(dev, 40, 1, 0);
1108 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
1109 test_2fg_scroll(dev, -40, 1, 0);
1110 check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
1112 /* 2fg scroll smaller than the threshold should not generate events */
1113 test_2fg_scroll(dev, 1, 1, 200);
1114 litest_assert_empty_queue(li);
1118 int main(int argc, char **argv) {
1120 litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
1121 litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1123 litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
1124 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
1125 litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1126 litest_add("touchpad:tap", touchpad_2fg_tap_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1127 litest_add("touchpad:tap", touchpad_1fg_tap_click, LITEST_TOUCHPAD, LITEST_ANY);
1128 litest_add("touchpad:tap", touchpad_2fg_tap_click, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD);
1129 litest_add("touchpad:tap", touchpad_2fg_tap_click_apple, LITEST_APPLE_CLICKPAD, LITEST_ANY);
1130 /* Real buttons don't interfere with tapping, so don't run those for
1131 pads with buttons */
1132 litest_add("touchpad:tap", touchpad_1fg_double_tap_click, LITEST_CLICKPAD, LITEST_ANY);
1133 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
1135 litest_add_no_device("touchpad:clickfinger", touchpad_1fg_clickfinger);
1136 litest_add_no_device("touchpad:clickfinger", touchpad_2fg_clickfinger);
1138 litest_add("touchpad:click", touchpad_btn_left, LITEST_TOUCHPAD, LITEST_CLICKPAD);
1139 litest_add("touchpad:click", clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY);
1140 litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
1142 litest_add("touchpad:softbutton", clickpad_softbutton_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1143 litest_add("touchpad:softbutton", clickpad_softbutton_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1144 litest_add("touchpad:softbutton", clickpad_softbutton_left_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1145 litest_add("touchpad:softbutton", clickpad_softbutton_right_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1146 litest_add("touchpad:softbutton", clickpad_softbutton_left_1st_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1147 litest_add("touchpad:softbutton", clickpad_softbutton_left_2nd_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1148 litest_add("touchpad:softbutton", clickpad_softbutton_left_to_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1149 litest_add("touchpad:softbutton", clickpad_softbutton_right_to_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1151 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_left, LITEST_TOPBUTTONPAD, LITEST_ANY);
1152 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_right, LITEST_TOPBUTTONPAD, LITEST_ANY);
1153 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_middle, LITEST_TOPBUTTONPAD, LITEST_ANY);
1154 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_move_out_ignore, LITEST_TOPBUTTONPAD, LITEST_ANY);
1156 litest_add("touchpad:scroll", touchpad_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1158 return litest_run(argc, argv);