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 usleep(300000); /* 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 usleep(300000); /* 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 usleep(300000); /* 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_1fg_tap_click)
215 struct litest_device *dev = litest_current_device();
216 struct libinput *li = dev->libinput;
218 litest_drain_events(dev->libinput);
220 /* finger down, button click, finger up
221 -> only one button left event pair */
222 litest_touch_down(dev, 0, 50, 50);
223 litest_event(dev, EV_KEY, BTN_LEFT, 1);
224 litest_event(dev, EV_SYN, SYN_REPORT, 0);
225 litest_event(dev, EV_KEY, BTN_LEFT, 0);
226 litest_event(dev, EV_SYN, SYN_REPORT, 0);
227 litest_touch_up(dev, 0);
229 libinput_dispatch(li);
231 assert_button_event(li, BTN_LEFT,
232 LIBINPUT_BUTTON_STATE_PRESSED);
233 assert_button_event(li, BTN_LEFT,
234 LIBINPUT_BUTTON_STATE_RELEASED);
236 litest_assert_empty_queue(li);
240 START_TEST(touchpad_2fg_tap_click)
242 struct litest_device *dev = litest_current_device();
243 struct libinput *li = dev->libinput;
245 litest_drain_events(dev->libinput);
247 /* two fingers down, button click, fingers up
248 -> only one button left event pair */
249 litest_touch_down(dev, 0, 50, 50);
250 litest_touch_down(dev, 1, 70, 50);
251 litest_event(dev, EV_KEY, BTN_LEFT, 1);
252 litest_event(dev, EV_SYN, SYN_REPORT, 0);
253 litest_event(dev, EV_KEY, BTN_LEFT, 0);
254 litest_event(dev, EV_SYN, SYN_REPORT, 0);
255 litest_touch_up(dev, 1);
256 litest_touch_up(dev, 0);
258 libinput_dispatch(li);
260 assert_button_event(li, BTN_LEFT,
261 LIBINPUT_BUTTON_STATE_PRESSED);
262 assert_button_event(li, BTN_LEFT,
263 LIBINPUT_BUTTON_STATE_RELEASED);
265 litest_assert_empty_queue(li);
269 START_TEST(touchpad_2fg_tap_click_apple)
271 struct litest_device *dev = litest_current_device();
272 struct libinput *li = dev->libinput;
274 litest_drain_events(dev->libinput);
276 /* two fingers down, button click, fingers up
277 -> only one button right event pair
278 (apple have clickfinger enabled by default) */
279 litest_touch_down(dev, 0, 50, 50);
280 litest_touch_down(dev, 1, 70, 50);
281 litest_event(dev, EV_KEY, BTN_LEFT, 1);
282 litest_event(dev, EV_SYN, SYN_REPORT, 0);
283 litest_event(dev, EV_KEY, BTN_LEFT, 0);
284 litest_event(dev, EV_SYN, SYN_REPORT, 0);
285 litest_touch_up(dev, 1);
286 litest_touch_up(dev, 0);
288 libinput_dispatch(li);
290 assert_button_event(li, BTN_RIGHT,
291 LIBINPUT_BUTTON_STATE_PRESSED);
292 assert_button_event(li, BTN_RIGHT,
293 LIBINPUT_BUTTON_STATE_RELEASED);
295 litest_assert_empty_queue(li);
299 START_TEST(touchpad_1fg_double_tap_click)
301 struct litest_device *dev = litest_current_device();
302 struct libinput *li = dev->libinput;
304 litest_drain_events(dev->libinput);
306 /* one finger down, up, down, button click, finger up
307 -> two button left event pairs */
308 litest_touch_down(dev, 0, 50, 50);
309 litest_touch_up(dev, 0);
310 litest_touch_down(dev, 0, 50, 50);
311 litest_event(dev, EV_KEY, BTN_LEFT, 1);
312 litest_event(dev, EV_SYN, SYN_REPORT, 0);
313 litest_event(dev, EV_KEY, BTN_LEFT, 0);
314 litest_event(dev, EV_SYN, SYN_REPORT, 0);
315 litest_touch_up(dev, 0);
317 libinput_dispatch(li);
319 assert_button_event(li, BTN_LEFT,
320 LIBINPUT_BUTTON_STATE_PRESSED);
321 assert_button_event(li, BTN_LEFT,
322 LIBINPUT_BUTTON_STATE_RELEASED);
323 assert_button_event(li, BTN_LEFT,
324 LIBINPUT_BUTTON_STATE_PRESSED);
325 assert_button_event(li, BTN_LEFT,
326 LIBINPUT_BUTTON_STATE_RELEASED);
328 litest_assert_empty_queue(li);
332 START_TEST(touchpad_1fg_tap_n_drag_click)
334 struct litest_device *dev = litest_current_device();
335 struct libinput *li = dev->libinput;
336 struct libinput_event *event;
338 litest_drain_events(dev->libinput);
340 /* one finger down, up, down, move, button click, finger up
341 -> two button left event pairs, motion allowed */
342 litest_touch_down(dev, 0, 50, 50);
343 litest_touch_up(dev, 0);
344 litest_touch_down(dev, 0, 50, 50);
345 litest_touch_move_to(dev, 0, 50, 50, 80, 50, 10);
347 assert_button_event(li, BTN_LEFT,
348 LIBINPUT_BUTTON_STATE_PRESSED);
350 libinput_dispatch(li);
352 ck_assert_int_eq(libinput_next_event_type(li),
353 LIBINPUT_EVENT_POINTER_MOTION);
354 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
355 event = libinput_get_event(li);
356 libinput_event_destroy(event);
357 libinput_dispatch(li);
360 litest_event(dev, EV_KEY, BTN_LEFT, 1);
361 litest_event(dev, EV_SYN, SYN_REPORT, 0);
363 assert_button_event(li, BTN_LEFT,
364 LIBINPUT_BUTTON_STATE_RELEASED);
365 assert_button_event(li, BTN_LEFT,
366 LIBINPUT_BUTTON_STATE_PRESSED);
368 litest_event(dev, EV_KEY, BTN_LEFT, 0);
369 litest_event(dev, EV_SYN, SYN_REPORT, 0);
370 litest_touch_up(dev, 0);
372 libinput_dispatch(li);
374 assert_button_event(li, BTN_LEFT,
375 LIBINPUT_BUTTON_STATE_RELEASED);
377 litest_assert_empty_queue(li);
381 START_TEST(touchpad_1fg_clickfinger)
383 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
384 struct libinput *li = dev->libinput;
386 litest_drain_events(li);
388 litest_touch_down(dev, 0, 50, 50);
389 litest_event(dev, EV_KEY, BTN_LEFT, 1);
390 litest_event(dev, EV_SYN, SYN_REPORT, 0);
391 litest_event(dev, EV_KEY, BTN_LEFT, 0);
392 litest_event(dev, EV_SYN, SYN_REPORT, 0);
393 litest_touch_up(dev, 0);
395 libinput_dispatch(li);
397 assert_button_event(li, BTN_LEFT,
398 LIBINPUT_BUTTON_STATE_PRESSED);
399 assert_button_event(li, BTN_LEFT,
400 LIBINPUT_BUTTON_STATE_RELEASED);
402 litest_delete_device(dev);
406 START_TEST(touchpad_2fg_clickfinger)
408 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
409 struct libinput *li = dev->libinput;
411 litest_drain_events(li);
413 litest_touch_down(dev, 0, 50, 50);
414 litest_touch_down(dev, 1, 70, 70);
415 litest_event(dev, EV_KEY, BTN_LEFT, 1);
416 litest_event(dev, EV_SYN, SYN_REPORT, 0);
417 litest_event(dev, EV_KEY, BTN_LEFT, 0);
418 litest_event(dev, EV_SYN, SYN_REPORT, 0);
419 litest_touch_up(dev, 0);
420 litest_touch_up(dev, 1);
422 libinput_dispatch(li);
424 assert_button_event(li, BTN_RIGHT,
425 LIBINPUT_BUTTON_STATE_PRESSED);
426 assert_button_event(li, BTN_RIGHT,
427 LIBINPUT_BUTTON_STATE_RELEASED);
429 litest_delete_device(dev);
433 START_TEST(touchpad_btn_left)
435 struct litest_device *dev = litest_current_device();
436 struct libinput *li = dev->libinput;
438 litest_drain_events(li);
440 litest_event(dev, EV_KEY, BTN_LEFT, 1);
441 litest_event(dev, EV_SYN, SYN_REPORT, 0);
442 litest_event(dev, EV_KEY, BTN_LEFT, 0);
443 litest_event(dev, EV_SYN, SYN_REPORT, 0);
445 libinput_dispatch(li);
447 assert_button_event(li, BTN_LEFT,
448 LIBINPUT_BUTTON_STATE_PRESSED);
449 assert_button_event(li, BTN_LEFT,
450 LIBINPUT_BUTTON_STATE_RELEASED);
454 START_TEST(clickpad_btn_left)
456 struct litest_device *dev = litest_current_device();
457 struct libinput *li = dev->libinput;
459 litest_drain_events(li);
461 /* A clickpad always needs a finger down to tell where the
463 litest_event(dev, EV_KEY, BTN_LEFT, 1);
464 litest_event(dev, EV_SYN, SYN_REPORT, 0);
465 litest_event(dev, EV_KEY, BTN_LEFT, 0);
466 litest_event(dev, EV_SYN, SYN_REPORT, 0);
468 libinput_dispatch(li);
469 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
473 START_TEST(clickpad_click_n_drag)
475 struct litest_device *dev = litest_current_device();
476 struct libinput *li = dev->libinput;
477 struct libinput_event *event;
479 litest_drain_events(li);
481 litest_touch_down(dev, 0, 50, 50);
482 litest_event(dev, EV_KEY, BTN_LEFT, 1);
483 litest_event(dev, EV_SYN, SYN_REPORT, 0);
485 libinput_dispatch(li);
486 assert_button_event(li, BTN_LEFT,
487 LIBINPUT_BUTTON_STATE_PRESSED);
489 libinput_dispatch(li);
490 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
492 /* now put a second finger down */
493 litest_touch_down(dev, 1, 70, 70);
494 litest_touch_move_to(dev, 1, 70, 70, 80, 50, 5);
495 litest_touch_up(dev, 1);
497 libinput_dispatch(li);
498 ck_assert_int_eq(libinput_next_event_type(li),
499 LIBINPUT_EVENT_POINTER_MOTION);
501 event = libinput_get_event(li);
502 libinput_event_destroy(event);
503 libinput_dispatch(li);
504 } while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION);
506 litest_event(dev, EV_KEY, BTN_LEFT, 0);
507 litest_event(dev, EV_SYN, SYN_REPORT, 0);
508 litest_touch_up(dev, 0);
510 assert_button_event(li, BTN_LEFT,
511 LIBINPUT_BUTTON_STATE_RELEASED);
515 START_TEST(clickpad_softbutton_left)
517 struct litest_device *dev = litest_current_device();
518 struct libinput *li = dev->libinput;
520 litest_drain_events(li);
522 litest_touch_down(dev, 0, 10, 90);
523 litest_event(dev, EV_KEY, BTN_LEFT, 1);
524 litest_event(dev, EV_SYN, SYN_REPORT, 0);
526 assert_button_event(li,
528 LIBINPUT_BUTTON_STATE_PRESSED);
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,
536 LIBINPUT_BUTTON_STATE_RELEASED);
538 libinput_dispatch(li);
540 litest_assert_empty_queue(li);
544 START_TEST(clickpad_softbutton_right)
546 struct litest_device *dev = litest_current_device();
547 struct libinput *li = dev->libinput;
549 litest_drain_events(li);
551 litest_touch_down(dev, 0, 90, 90);
552 litest_event(dev, EV_KEY, BTN_LEFT, 1);
553 litest_event(dev, EV_SYN, SYN_REPORT, 0);
555 assert_button_event(li,
557 LIBINPUT_BUTTON_STATE_PRESSED);
559 litest_event(dev, EV_KEY, BTN_LEFT, 0);
560 litest_event(dev, EV_SYN, SYN_REPORT, 0);
561 litest_touch_up(dev, 0);
563 assert_button_event(li,
565 LIBINPUT_BUTTON_STATE_RELEASED);
567 libinput_dispatch(li);
569 litest_assert_empty_queue(li);
573 START_TEST(clickpad_softbutton_left_tap_n_drag)
575 struct litest_device *dev = litest_current_device();
576 struct libinput *li = dev->libinput;
578 litest_drain_events(li);
580 /* Tap in left button area, then finger down, button click
581 -> expect left button press/release and left button press
582 Release button, finger up
583 -> expect right button release
585 litest_touch_down(dev, 0, 20, 90);
586 litest_touch_up(dev, 0);
587 litest_touch_down(dev, 0, 20, 90);
588 litest_event(dev, EV_KEY, BTN_LEFT, 1);
589 litest_event(dev, EV_SYN, SYN_REPORT, 0);
591 assert_button_event(li,
593 LIBINPUT_BUTTON_STATE_PRESSED);
594 assert_button_event(li,
596 LIBINPUT_BUTTON_STATE_RELEASED);
597 assert_button_event(li,
599 LIBINPUT_BUTTON_STATE_PRESSED);
600 litest_assert_empty_queue(li);
602 litest_event(dev, EV_KEY, BTN_LEFT, 0);
603 litest_event(dev, EV_SYN, SYN_REPORT, 0);
604 litest_touch_up(dev, 0);
606 assert_button_event(li,
608 LIBINPUT_BUTTON_STATE_RELEASED);
609 litest_assert_empty_queue(li);
613 START_TEST(clickpad_softbutton_right_tap_n_drag)
615 struct litest_device *dev = litest_current_device();
616 struct libinput *li = dev->libinput;
618 litest_drain_events(li);
620 /* Tap in right button area, then finger down, button click
621 -> expect left button press/release and right button press
622 Release button, finger up
623 -> expect right button release
625 litest_touch_down(dev, 0, 90, 90);
626 litest_touch_up(dev, 0);
627 litest_touch_down(dev, 0, 90, 90);
628 litest_event(dev, EV_KEY, BTN_LEFT, 1);
629 litest_event(dev, EV_SYN, SYN_REPORT, 0);
631 assert_button_event(li,
633 LIBINPUT_BUTTON_STATE_PRESSED);
634 assert_button_event(li,
636 LIBINPUT_BUTTON_STATE_RELEASED);
637 assert_button_event(li,
639 LIBINPUT_BUTTON_STATE_PRESSED);
640 litest_assert_empty_queue(li);
642 litest_event(dev, EV_KEY, BTN_LEFT, 0);
643 litest_event(dev, EV_SYN, SYN_REPORT, 0);
644 litest_touch_up(dev, 0);
646 assert_button_event(li,
648 LIBINPUT_BUTTON_STATE_RELEASED);
649 litest_assert_empty_queue(li);
653 START_TEST(clickpad_softbutton_left_1st_fg_move)
655 struct litest_device *dev = litest_current_device();
656 struct libinput *li = dev->libinput;
657 struct libinput_event *event;
661 litest_drain_events(li);
663 /* One finger down in the left button area, button press
664 -> expect a button event
665 Move finger up out of the area, wait for timeout
666 Move finger around diagonally down left
667 -> expect motion events down left
669 -> expect a button event */
671 /* finger down, press in left button */
672 litest_touch_down(dev, 0, 20, 90);
673 litest_event(dev, EV_KEY, BTN_LEFT, 1);
674 litest_event(dev, EV_SYN, SYN_REPORT, 0);
676 assert_button_event(li,
678 LIBINPUT_BUTTON_STATE_PRESSED);
679 litest_assert_empty_queue(li);
681 /* move out of the area, then wait for softbutton timer */
682 litest_touch_move_to(dev, 0, 20, 90, 90, 20, 10);
683 libinput_dispatch(li);
685 libinput_dispatch(li);
686 litest_drain_events(li);
688 /* move down left, expect motion */
689 litest_touch_move_to(dev, 0, 90, 20, 20, 90, 10);
691 libinput_dispatch(li);
692 event = libinput_get_event(li);
693 ck_assert(event != NULL);
695 struct libinput_event_pointer *p;
697 ck_assert_int_eq(libinput_event_get_type(event),
698 LIBINPUT_EVENT_POINTER_MOTION);
699 p = libinput_event_get_pointer_event(event);
701 /* we moved up/right, now down/left so the pointer accel
702 code may lag behind with the dx/dy vectors. Hence, add up
703 the x/y movements and expect that on average we moved
705 x += libinput_event_pointer_get_dx(p);
706 y += libinput_event_pointer_get_dy(p);
709 libinput_event_destroy(event);
710 libinput_dispatch(li);
711 event = libinput_get_event(li);
714 ck_assert(x/nevents < 0);
715 ck_assert(y/nevents > 0);
717 litest_event(dev, EV_KEY, BTN_LEFT, 0);
718 litest_event(dev, EV_SYN, SYN_REPORT, 0);
719 litest_touch_up(dev, 0);
721 assert_button_event(li,
723 LIBINPUT_BUTTON_STATE_RELEASED);
725 litest_assert_empty_queue(li);
729 START_TEST(clickpad_softbutton_left_2nd_fg_move)
731 struct litest_device *dev = litest_current_device();
732 struct libinput *li = dev->libinput;
733 struct libinput_event *event;
735 litest_drain_events(li);
737 /* One finger down in the left button area, button press
738 -> expect a button event
739 Put a second finger down in the area, move it right, release
740 -> expect motion events right
741 Put a second finger down in the area, move it down, release
742 -> expect motion events down
743 Release second finger, release first finger
744 -> expect a button event */
745 litest_touch_down(dev, 0, 20, 90);
746 litest_event(dev, EV_KEY, BTN_LEFT, 1);
747 litest_event(dev, EV_SYN, SYN_REPORT, 0);
749 assert_button_event(li,
751 LIBINPUT_BUTTON_STATE_PRESSED);
752 litest_assert_empty_queue(li);
754 litest_touch_down(dev, 1, 20, 20);
755 litest_touch_move_to(dev, 1, 20, 20, 80, 20, 10);
757 libinput_dispatch(li);
758 event = libinput_get_event(li);
759 ck_assert(event != NULL);
761 struct libinput_event_pointer *p;
764 ck_assert_int_eq(libinput_event_get_type(event),
765 LIBINPUT_EVENT_POINTER_MOTION);
766 p = libinput_event_get_pointer_event(event);
768 x = libinput_event_pointer_get_dx(p);
769 y = libinput_event_pointer_get_dy(p);
774 libinput_event_destroy(event);
775 libinput_dispatch(li);
776 event = libinput_get_event(li);
778 litest_touch_up(dev, 1);
780 /* second finger down */
781 litest_touch_down(dev, 1, 20, 20);
782 litest_touch_move_to(dev, 1, 20, 20, 20, 80, 10);
784 libinput_dispatch(li);
785 event = libinput_get_event(li);
786 ck_assert(event != NULL);
788 struct libinput_event_pointer *p;
791 ck_assert_int_eq(libinput_event_get_type(event),
792 LIBINPUT_EVENT_POINTER_MOTION);
793 p = libinput_event_get_pointer_event(event);
795 x = libinput_event_pointer_get_dx(p);
796 y = libinput_event_pointer_get_dy(p);
801 libinput_event_destroy(event);
802 libinput_dispatch(li);
803 event = libinput_get_event(li);
806 litest_event(dev, EV_KEY, BTN_LEFT, 0);
807 litest_event(dev, EV_SYN, SYN_REPORT, 0);
808 litest_touch_up(dev, 0);
810 assert_button_event(li,
812 LIBINPUT_BUTTON_STATE_RELEASED);
814 litest_assert_empty_queue(li);
818 START_TEST(clickpad_softbutton_left_to_right)
820 struct litest_device *dev = litest_current_device();
821 struct libinput *li = dev->libinput;
823 litest_drain_events(li);
825 /* One finger down in left software button area,
826 move to right button area immediately, click
827 -> expect right button event
830 litest_touch_down(dev, 0, 20, 90);
831 litest_touch_move_to(dev, 0, 20, 90, 90, 90, 10);
832 litest_event(dev, EV_KEY, BTN_LEFT, 1);
833 litest_event(dev, EV_SYN, SYN_REPORT, 0);
835 assert_button_event(li,
837 LIBINPUT_BUTTON_STATE_PRESSED);
838 litest_assert_empty_queue(li);
840 litest_event(dev, EV_KEY, BTN_LEFT, 0);
841 litest_event(dev, EV_SYN, SYN_REPORT, 0);
842 litest_touch_up(dev, 0);
844 assert_button_event(li,
846 LIBINPUT_BUTTON_STATE_RELEASED);
848 litest_assert_empty_queue(li);
852 START_TEST(clickpad_softbutton_right_to_left)
854 struct litest_device *dev = litest_current_device();
855 struct libinput *li = dev->libinput;
857 litest_drain_events(li);
859 /* One finger down in right software button area,
860 move to left button area immediately, click
861 -> expect left button event
864 litest_touch_down(dev, 0, 90, 90);
865 litest_touch_move_to(dev, 0, 90, 90, 20, 90, 10);
866 litest_event(dev, EV_KEY, BTN_LEFT, 1);
867 litest_event(dev, EV_SYN, SYN_REPORT, 0);
869 assert_button_event(li,
871 LIBINPUT_BUTTON_STATE_PRESSED);
872 litest_assert_empty_queue(li);
874 litest_event(dev, EV_KEY, BTN_LEFT, 0);
875 litest_event(dev, EV_SYN, SYN_REPORT, 0);
876 litest_touch_up(dev, 0);
878 assert_button_event(li,
880 LIBINPUT_BUTTON_STATE_RELEASED);
882 litest_assert_empty_queue(li);
886 START_TEST(clickpad_topsoftbuttons_left)
888 struct litest_device *dev = litest_current_device();
889 struct libinput *li = dev->libinput;
891 litest_drain_events(li);
893 litest_touch_down(dev, 0, 10, 5);
894 litest_event(dev, EV_KEY, BTN_LEFT, 1);
895 litest_event(dev, EV_SYN, SYN_REPORT, 0);
897 assert_button_event(li,
899 LIBINPUT_BUTTON_STATE_PRESSED);
900 litest_assert_empty_queue(li);
902 litest_event(dev, EV_KEY, BTN_LEFT, 0);
903 litest_event(dev, EV_SYN, SYN_REPORT, 0);
904 litest_touch_up(dev, 0);
906 assert_button_event(li,
908 LIBINPUT_BUTTON_STATE_RELEASED);
910 litest_assert_empty_queue(li);
914 START_TEST(clickpad_topsoftbuttons_right)
916 struct litest_device *dev = litest_current_device();
917 struct libinput *li = dev->libinput;
919 litest_drain_events(li);
921 litest_touch_down(dev, 0, 90, 5);
922 litest_event(dev, EV_KEY, BTN_LEFT, 1);
923 litest_event(dev, EV_SYN, SYN_REPORT, 0);
925 assert_button_event(li,
927 LIBINPUT_BUTTON_STATE_PRESSED);
928 litest_assert_empty_queue(li);
930 litest_event(dev, EV_KEY, BTN_LEFT, 0);
931 litest_event(dev, EV_SYN, SYN_REPORT, 0);
932 litest_touch_up(dev, 0);
934 assert_button_event(li,
936 LIBINPUT_BUTTON_STATE_RELEASED);
938 litest_assert_empty_queue(li);
942 START_TEST(clickpad_topsoftbuttons_middle)
944 struct litest_device *dev = litest_current_device();
945 struct libinput *li = dev->libinput;
947 litest_drain_events(li);
949 litest_touch_down(dev, 0, 50, 5);
950 litest_event(dev, EV_KEY, BTN_LEFT, 1);
951 litest_event(dev, EV_SYN, SYN_REPORT, 0);
953 assert_button_event(li,
955 LIBINPUT_BUTTON_STATE_PRESSED);
956 litest_assert_empty_queue(li);
958 litest_event(dev, EV_KEY, BTN_LEFT, 0);
959 litest_event(dev, EV_SYN, SYN_REPORT, 0);
960 litest_touch_up(dev, 0);
962 assert_button_event(li,
964 LIBINPUT_BUTTON_STATE_RELEASED);
966 litest_assert_empty_queue(li);
970 START_TEST(clickpad_topsoftbuttons_move_out_ignore)
972 struct litest_device *dev = litest_current_device();
973 struct libinput *li = dev->libinput;
975 /* Finger down in top button area, wait past enter timeout
976 Move into main area, wait past leave timeout
981 litest_drain_events(li);
983 litest_touch_down(dev, 0, 50, 5);
984 libinput_dispatch(li);
986 libinput_dispatch(li);
987 litest_assert_empty_queue(li);
989 litest_touch_move_to(dev, 0, 50, 5, 80, 90, 20);
990 libinput_dispatch(li);
992 libinput_dispatch(li);
994 litest_event(dev, EV_KEY, BTN_LEFT, 1);
995 litest_event(dev, EV_SYN, SYN_REPORT, 0);
996 litest_event(dev, EV_KEY, BTN_LEFT, 0);
997 litest_event(dev, EV_SYN, SYN_REPORT, 0);
999 litest_touch_up(dev, 0);
1001 litest_assert_empty_queue(li);
1005 int main(int argc, char **argv) {
1007 litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
1008 litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1010 litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
1011 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
1012 litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
1013 litest_add("touchpad:tap", touchpad_1fg_tap_click, LITEST_TOUCHPAD, LITEST_ANY);
1014 litest_add("touchpad:tap", touchpad_2fg_tap_click, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD);
1015 litest_add("touchpad:tap", touchpad_2fg_tap_click_apple, LITEST_APPLE_CLICKPAD, LITEST_ANY);
1016 /* Real buttons don't interfere with tapping, so don't run those for
1017 pads with buttons */
1018 litest_add("touchpad:tap", touchpad_1fg_double_tap_click, LITEST_CLICKPAD, LITEST_ANY);
1019 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
1021 litest_add_no_device("touchpad:clickfinger", touchpad_1fg_clickfinger);
1022 litest_add_no_device("touchpad:clickfinger", touchpad_2fg_clickfinger);
1024 litest_add("touchpad:click", touchpad_btn_left, LITEST_TOUCHPAD, LITEST_CLICKPAD);
1025 litest_add("touchpad:click", clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY);
1026 litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
1028 litest_add("touchpad:softbutton", clickpad_softbutton_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1029 litest_add("touchpad:softbutton", clickpad_softbutton_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1030 litest_add("touchpad:softbutton", clickpad_softbutton_left_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1031 litest_add("touchpad:softbutton", clickpad_softbutton_right_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1032 litest_add("touchpad:softbutton", clickpad_softbutton_left_1st_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1033 litest_add("touchpad:softbutton", clickpad_softbutton_left_2nd_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1034 litest_add("touchpad:softbutton", clickpad_softbutton_left_to_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1035 litest_add("touchpad:softbutton", clickpad_softbutton_right_to_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
1037 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_left, LITEST_TOPBUTTONPAD, LITEST_ANY);
1038 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_right, LITEST_TOPBUTTONPAD, LITEST_ANY);
1039 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_middle, LITEST_TOPBUTTONPAD, LITEST_ANY);
1040 litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_move_out_ignore, LITEST_TOPBUTTONPAD, LITEST_ANY);
1042 return litest_run(argc, argv);