1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
/*
* Copyright © 2013 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the copyright holders not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The copyright holders make
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <stdio.h>
#include <check.h>
#include <errno.h>
#include <fcntl.h>
#include <libinput.h>
#include <math.h>
#include <unistd.h>
#include <values.h>
#include "libinput-util.h"
#include "litest.h"
static struct libinput_event_pointer *
get_accelerated_motion_event(struct libinput *li)
{
struct libinput_event *event;
struct libinput_event_pointer *ptrev;
while (1) {
event = libinput_get_event(li);
ck_assert_notnull(event);
ck_assert_int_eq(libinput_event_get_type(event),
LIBINPUT_EVENT_POINTER_MOTION);
ptrev = libinput_event_get_pointer_event(event);
ck_assert_notnull(ptrev);
if (fabs(libinput_event_pointer_get_dx(ptrev)) < DBL_MIN &&
fabs(libinput_event_pointer_get_dy(ptrev)) < DBL_MIN) {
libinput_event_destroy(event);
continue;
}
return ptrev;
}
ck_abort_msg("No accelerated pointer motion event found");
return NULL;
}
static void
test_relative_event(struct litest_device *dev, int dx, int dy)
{
struct libinput *li = dev->libinput;
struct libinput_event_pointer *ptrev;
double ev_dx, ev_dy;
double expected_dir;
double expected_length;
double actual_dir;
double actual_length;
/* Send two deltas, as the first one may be eaten up by an
* acceleration filter. */
litest_event(dev, EV_REL, REL_X, dx);
litest_event(dev, EV_REL, REL_Y, dy);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
litest_event(dev, EV_REL, REL_X, dx);
litest_event(dev, EV_REL, REL_Y, dy);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
libinput_dispatch(li);
ptrev = get_accelerated_motion_event(li);
expected_length = sqrt(4 * dx*dx + 4 * dy*dy);
expected_dir = atan2(dx, dy);
ev_dx = libinput_event_pointer_get_dx(ptrev);
ev_dy = libinput_event_pointer_get_dy(ptrev);
actual_length = sqrt(ev_dx*ev_dx + ev_dy*ev_dy);
actual_dir = atan2(ev_dx, ev_dy);
/* Check the length of the motion vector (tolerate 1.0 indifference). */
ck_assert(fabs(expected_length) >= actual_length);
/* Check the direction of the motion vector (tolerate 2π/4 radians
* indifference). */
ck_assert(fabs(expected_dir - actual_dir) < M_PI_2);
libinput_event_destroy(libinput_event_pointer_get_base_event(ptrev));
litest_drain_events(dev->libinput);
}
START_TEST(pointer_motion_relative)
{
struct litest_device *dev = litest_current_device();
litest_drain_events(dev->libinput);
test_relative_event(dev, 1, 0);
test_relative_event(dev, 1, 1);
test_relative_event(dev, 1, -1);
test_relative_event(dev, 0, 1);
test_relative_event(dev, -1, 0);
test_relative_event(dev, -1, 1);
test_relative_event(dev, -1, -1);
test_relative_event(dev, 0, -1);
}
END_TEST
static void
test_absolute_event(struct litest_device *dev, double x, double y)
{
struct libinput *li = dev->libinput;
struct libinput_event *event;
struct libinput_event_pointer *ptrev;
double ex, ey;
litest_touch_down(dev, 0, x, y);
libinput_dispatch(li);
event = libinput_get_event(li);
ck_assert_int_eq(libinput_event_get_type(event),
LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
ptrev = libinput_event_get_pointer_event(event);
ck_assert(ptrev != NULL);
ex = libinput_event_pointer_get_absolute_x_transformed(ptrev, 100);
ey = libinput_event_pointer_get_absolute_y_transformed(ptrev, 100);
ck_assert_int_eq(ex + 0.5, x);
ck_assert_int_eq(ey + 0.5, y);
libinput_event_destroy(event);
}
START_TEST(pointer_motion_absolute)
{
struct litest_device *dev = litest_current_device();
litest_drain_events(dev->libinput);
test_absolute_event(dev, 0, 100);
test_absolute_event(dev, 100, 0);
test_absolute_event(dev, 50, 50);
}
END_TEST
static void
test_unaccel_event(struct litest_device *dev, int dx, int dy)
{
struct libinput *li = dev->libinput;
struct libinput_event *event;
struct libinput_event_pointer *ptrev;
double ev_dx, ev_dy;
litest_event(dev, EV_REL, REL_X, dx);
litest_event(dev, EV_REL, REL_Y, dy);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
libinput_dispatch(li);
event = libinput_get_event(li);
ck_assert_notnull(event);
ck_assert_int_eq(libinput_event_get_type(event),
LIBINPUT_EVENT_POINTER_MOTION);
ptrev = libinput_event_get_pointer_event(event);
ck_assert(ptrev != NULL);
ev_dx = libinput_event_pointer_get_dx_unaccelerated(ptrev);
ev_dy = libinput_event_pointer_get_dy_unaccelerated(ptrev);
ck_assert_int_eq(dx, ev_dx);
ck_assert_int_eq(dy, ev_dy);
libinput_event_destroy(event);
litest_drain_events(dev->libinput);
}
START_TEST(pointer_motion_unaccel)
{
struct litest_device *dev = litest_current_device();
litest_drain_events(dev->libinput);
test_unaccel_event(dev, 10, 0);
test_unaccel_event(dev, 10, 10);
test_unaccel_event(dev, 10, -10);
test_unaccel_event(dev, 0, 10);
test_unaccel_event(dev, -10, 0);
test_unaccel_event(dev, -10, 10);
test_unaccel_event(dev, -10, -10);
test_unaccel_event(dev, 0, -10);
}
END_TEST
static void
test_button_event(struct litest_device *dev, unsigned int button, int state)
{
struct libinput *li = dev->libinput;
litest_event(dev, EV_KEY, button, state);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
litest_assert_button_event(li, button,
state ? LIBINPUT_BUTTON_STATE_PRESSED :
LIBINPUT_BUTTON_STATE_RELEASED);
}
START_TEST(pointer_button)
{
struct litest_device *dev = litest_current_device();
litest_drain_events(dev->libinput);
test_button_event(dev, BTN_LEFT, 1);
test_button_event(dev, BTN_LEFT, 0);
/* press it twice for good measure */
test_button_event(dev, BTN_LEFT, 1);
test_button_event(dev, BTN_LEFT, 0);
if (libevdev_has_event_code(dev->evdev, EV_KEY, BTN_RIGHT)) {
test_button_event(dev, BTN_RIGHT, 1);
test_button_event(dev, BTN_RIGHT, 0);
}
/* Skip middle button test on trackpoints (used for scrolling) */
if (!libevdev_has_property(dev->evdev, INPUT_PROP_POINTING_STICK) &&
libevdev_has_event_code(dev->evdev, EV_KEY, BTN_MIDDLE)) {
test_button_event(dev, BTN_MIDDLE, 1);
test_button_event(dev, BTN_MIDDLE, 0);
}
}
END_TEST
START_TEST(pointer_button_auto_release)
{
struct libinput *libinput;
struct litest_device *dev;
struct libinput_event *event;
enum libinput_event_type type;
struct libinput_event_pointer *pevent;
struct {
int code;
int released;
} buttons[] = {
{ .code = BTN_LEFT, },
{ .code = BTN_MIDDLE, },
{ .code = BTN_EXTRA, },
{ .code = BTN_SIDE, },
{ .code = BTN_BACK, },
{ .code = BTN_FORWARD, },
{ .code = BTN_4, },
};
int events[2 * (ARRAY_LENGTH(buttons) + 1)];
unsigned i;
int button;
int valid_code;
/* Enable all tested buttons on the device */
for (i = 0; i < 2 * ARRAY_LENGTH(buttons);) {
button = buttons[i / 2].code;
events[i++] = EV_KEY;
events[i++] = button;
}
events[i++] = -1;
events[i++] = -1;
libinput = litest_create_context();
dev = litest_add_device_with_overrides(libinput,
LITEST_MOUSE,
"Generic mouse",
NULL, NULL, events);
litest_drain_events(libinput);
/* Send pressed events, without releasing */
for (i = 0; i < ARRAY_LENGTH(buttons); ++i) {
test_button_event(dev, buttons[i].code, 1);
}
litest_drain_events(libinput);
/* "Disconnect" device */
litest_delete_device(dev);
/* Mark all released buttons until device is removed */
while (1) {
event = libinput_get_event(libinput);
ck_assert_notnull(event);
type = libinput_event_get_type(event);
if (type == LIBINPUT_EVENT_DEVICE_REMOVED) {
libinput_event_destroy(event);
break;
}
ck_assert_int_eq(type, LIBINPUT_EVENT_POINTER_BUTTON);
pevent = libinput_event_get_pointer_event(event);
ck_assert_int_eq(libinput_event_pointer_get_button_state(pevent),
LIBINPUT_BUTTON_STATE_RELEASED);
button = libinput_event_pointer_get_button(pevent);
valid_code = 0;
for (i = 0; i < ARRAY_LENGTH(buttons); ++i) {
if (buttons[i].code == button) {
ck_assert_int_eq(buttons[i].released, 0);
buttons[i].released = 1;
valid_code = 1;
}
}
ck_assert_int_eq(valid_code, 1);
libinput_event_destroy(event);
}
/* Check that all pressed buttons has been released. */
for (i = 0; i < ARRAY_LENGTH(buttons); ++i) {
ck_assert_int_eq(buttons[i].released, 1);
}
libinput_unref(libinput);
}
END_TEST
static void
test_wheel_event(struct litest_device *dev, int which, int amount)
{
struct libinput *li = dev->libinput;
struct libinput_event *event;
struct libinput_event_pointer *ptrev;
enum libinput_pointer_axis axis;
/* the current evdev implementation scales the scroll wheel events
up by a factor 15 */
const int scroll_step = 15;
int expected = amount * scroll_step;
int discrete = amount;
if (libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device)) {
expected *= -1;
discrete *= -1;
}
/* mouse scroll wheels are 'upside down' */
if (which == REL_WHEEL)
amount *= -1;
litest_event(dev, EV_REL, which, amount);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
libinput_dispatch(li);
event = libinput_get_event(li);
ck_assert(event != NULL);
ck_assert_int_eq(libinput_event_get_type(event),
LIBINPUT_EVENT_POINTER_AXIS);
ptrev = libinput_event_get_pointer_event(event);
ck_assert(ptrev != NULL);
axis = (which == REL_WHEEL) ?
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL :
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
ck_assert_int_eq(libinput_event_pointer_get_axis_value(ptrev, axis),
expected);
ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev),
LIBINPUT_POINTER_AXIS_SOURCE_WHEEL);
ck_assert_int_eq(libinput_event_pointer_get_axis_value_discrete(ptrev, axis),
discrete);
libinput_event_destroy(event);
}
START_TEST(pointer_scroll_wheel)
{
struct litest_device *dev = litest_current_device();
litest_drain_events(dev->libinput);
test_wheel_event(dev, REL_WHEEL, -1);
test_wheel_event(dev, REL_WHEEL, 1);
test_wheel_event(dev, REL_WHEEL, -5);
test_wheel_event(dev, REL_WHEEL, 6);
if (libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)) {
test_wheel_event(dev, REL_HWHEEL, -1);
test_wheel_event(dev, REL_HWHEEL, 1);
test_wheel_event(dev, REL_HWHEEL, -5);
test_wheel_event(dev, REL_HWHEEL, 6);
}
}
END_TEST
START_TEST(pointer_scroll_natural_defaults)
{
struct litest_device *dev = litest_current_device();
ck_assert_int_ge(libinput_device_config_scroll_has_natural_scroll(dev->libinput_device), 1);
ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0);
ck_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), 0);
}
END_TEST
START_TEST(pointer_scroll_natural_enable_config)
{
struct litest_device *dev = litest_current_device();
enum libinput_config_status status;
status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 1);
status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 0);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0);
}
END_TEST
START_TEST(pointer_scroll_natural_wheel)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *device = dev->libinput_device;
litest_drain_events(dev->libinput);
libinput_device_config_scroll_set_natural_scroll_enabled(device, 1);
test_wheel_event(dev, REL_WHEEL, -1);
test_wheel_event(dev, REL_WHEEL, 1);
test_wheel_event(dev, REL_WHEEL, -5);
test_wheel_event(dev, REL_WHEEL, 6);
if (libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)) {
test_wheel_event(dev, REL_HWHEEL, -1);
test_wheel_event(dev, REL_HWHEEL, 1);
test_wheel_event(dev, REL_HWHEEL, -5);
test_wheel_event(dev, REL_HWHEEL, 6);
}
}
END_TEST
START_TEST(pointer_seat_button_count)
{
const int num_devices = 4;
struct litest_device *devices[num_devices];
struct libinput *libinput;
struct libinput_event *ev;
struct libinput_event_pointer *tev;
int i;
int seat_button_count;
int expected_seat_button_count = 0;
char device_name[255];
libinput = litest_create_context();
for (i = 0; i < num_devices; ++i) {
sprintf(device_name, "litest Generic mouse (%d)", i);
devices[i] = litest_add_device_with_overrides(libinput,
LITEST_MOUSE,
device_name,
NULL, NULL, NULL);
}
for (i = 0; i < num_devices; ++i)
litest_button_click(devices[i], BTN_LEFT, true);
libinput_dispatch(libinput);
while ((ev = libinput_get_event(libinput))) {
if (libinput_event_get_type(ev) !=
LIBINPUT_EVENT_POINTER_BUTTON) {
libinput_event_destroy(ev);
libinput_dispatch(libinput);
continue;
}
tev = libinput_event_get_pointer_event(ev);
ck_assert_notnull(tev);
ck_assert_int_eq(libinput_event_pointer_get_button(tev),
BTN_LEFT);
ck_assert_int_eq(libinput_event_pointer_get_button_state(tev),
LIBINPUT_BUTTON_STATE_PRESSED);
++expected_seat_button_count;
seat_button_count =
libinput_event_pointer_get_seat_button_count(tev);
ck_assert_int_eq(expected_seat_button_count, seat_button_count);
libinput_event_destroy(ev);
libinput_dispatch(libinput);
}
ck_assert_int_eq(seat_button_count, num_devices);
for (i = 0; i < num_devices; ++i)
litest_button_click(devices[i], BTN_LEFT, false);
libinput_dispatch(libinput);
while ((ev = libinput_get_event(libinput))) {
if (libinput_event_get_type(ev) !=
LIBINPUT_EVENT_POINTER_BUTTON) {
libinput_event_destroy(ev);
libinput_dispatch(libinput);
continue;
}
tev = libinput_event_get_pointer_event(ev);
ck_assert_notnull(tev);
ck_assert_int_eq(libinput_event_pointer_get_button(tev),
BTN_LEFT);
ck_assert_int_eq(libinput_event_pointer_get_button_state(tev),
LIBINPUT_BUTTON_STATE_RELEASED);
--expected_seat_button_count;
seat_button_count =
libinput_event_pointer_get_seat_button_count(tev);
ck_assert_int_eq(expected_seat_button_count, seat_button_count);
libinput_event_destroy(ev);
libinput_dispatch(libinput);
}
ck_assert_int_eq(seat_button_count, 0);
for (i = 0; i < num_devices; ++i)
litest_delete_device(devices[i]);
libinput_unref(libinput);
}
END_TEST
START_TEST(pointer_no_calibration)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *d = dev->libinput_device;
enum libinput_config_status status;
int rc;
float calibration[6] = {0};
rc = libinput_device_config_calibration_has_matrix(d);
ck_assert_int_eq(rc, 0);
rc = libinput_device_config_calibration_get_matrix(d, calibration);
ck_assert_int_eq(rc, 0);
rc = libinput_device_config_calibration_get_default_matrix(d,
calibration);
ck_assert_int_eq(rc, 0);
status = libinput_device_config_calibration_set_matrix(d,
calibration);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
}
END_TEST
START_TEST(pointer_left_handed_defaults)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *d = dev->libinput_device;
int rc;
rc = libinput_device_config_left_handed_is_available(d);
ck_assert_int_ne(rc, 0);
rc = libinput_device_config_left_handed_get(d);
ck_assert_int_eq(rc, 0);
rc = libinput_device_config_left_handed_get_default(d);
ck_assert_int_eq(rc, 0);
}
END_TEST
START_TEST(pointer_left_handed)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *d = dev->libinput_device;
struct libinput *li = dev->libinput;
enum libinput_config_status status;
status = libinput_device_config_left_handed_set(d, 1);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
litest_drain_events(li);
litest_button_click(dev, BTN_LEFT, 1);
litest_button_click(dev, BTN_LEFT, 0);
litest_assert_button_event(li,
BTN_RIGHT,
LIBINPUT_BUTTON_STATE_PRESSED);
litest_assert_button_event(li,
BTN_RIGHT,
LIBINPUT_BUTTON_STATE_RELEASED);
litest_button_click(dev, BTN_RIGHT, 1);
litest_button_click(dev, BTN_RIGHT, 0);
litest_assert_button_event(li,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_PRESSED);
litest_assert_button_event(li,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
if (libevdev_has_event_code(dev->evdev,
EV_KEY,
BTN_MIDDLE)) {
litest_button_click(dev, BTN_MIDDLE, 1);
litest_button_click(dev, BTN_MIDDLE, 0);
litest_assert_button_event(li,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_PRESSED);
litest_assert_button_event(li,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_RELEASED);
}
}
END_TEST
START_TEST(pointer_left_handed_during_click)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *d = dev->libinput_device;
struct libinput *li = dev->libinput;
enum libinput_config_status status;
litest_drain_events(li);
litest_button_click(dev, BTN_LEFT, 1);
libinput_dispatch(li);
/* Change while button is down, expect correct release event */
status = libinput_device_config_left_handed_set(d, 1);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
litest_button_click(dev, BTN_LEFT, 0);
litest_assert_button_event(li,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_PRESSED);
litest_assert_button_event(li,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
}
END_TEST
START_TEST(pointer_left_handed_during_click_multiple_buttons)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *d = dev->libinput_device;
struct libinput *li = dev->libinput;
enum libinput_config_status status;
litest_drain_events(li);
litest_button_click(dev, BTN_LEFT, 1);
libinput_dispatch(li);
status = libinput_device_config_left_handed_set(d, 1);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
/* No left-handed until all buttons were down */
litest_button_click(dev, BTN_RIGHT, 1);
litest_button_click(dev, BTN_RIGHT, 0);
litest_button_click(dev, BTN_LEFT, 0);
litest_assert_button_event(li,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_PRESSED);
litest_assert_button_event(li,
BTN_RIGHT,
LIBINPUT_BUTTON_STATE_PRESSED);
litest_assert_button_event(li,
BTN_RIGHT,
LIBINPUT_BUTTON_STATE_RELEASED);
litest_assert_button_event(li,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
}
END_TEST
START_TEST(pointer_scroll_button)
{
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
/* Make left button switch to scrolling mode */
libinput_device_config_scroll_set_method(dev->libinput_device,
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
libinput_device_config_scroll_set_button(dev->libinput_device,
BTN_LEFT);
litest_drain_events(li);
litest_button_scroll(dev, BTN_LEFT, 1, 6);
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6);
litest_button_scroll(dev, BTN_LEFT, 1, -7);
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7);
litest_button_scroll(dev, BTN_LEFT, 8, 1);
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 8);
litest_button_scroll(dev, BTN_LEFT, -9, 1);
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9);
/* scroll smaller than the threshold should not generate events */
litest_button_scroll(dev, BTN_LEFT, 1, 1);
/* left press without movement should not generate events */
litest_button_scroll(dev, BTN_LEFT, 0, 0);
litest_assert_empty_queue(li);
/* Restore default scroll behavior */
libinput_device_config_scroll_set_method(dev->libinput_device,
libinput_device_config_scroll_get_default_method(
dev->libinput_device));
libinput_device_config_scroll_set_button(dev->libinput_device,
libinput_device_config_scroll_get_default_button(
dev->libinput_device));
}
END_TEST
START_TEST(pointer_accel_defaults)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *device = dev->libinput_device;
enum libinput_config_status status;
double speed;
ck_assert(libinput_device_config_accel_is_available(device));
ck_assert(libinput_device_config_accel_get_default_speed(device) == 0.0);
ck_assert(libinput_device_config_accel_get_speed(device) == 0.0);
for (speed = -2.0; speed < -1.0; speed += 0.2) {
status = libinput_device_config_accel_set_speed(device,
speed);
ck_assert_int_eq(status,
LIBINPUT_CONFIG_STATUS_INVALID);
ck_assert(libinput_device_config_accel_get_speed(device) == 0.0);
}
for (speed = -1.0; speed <= 1.0; speed += 0.2) {
status = libinput_device_config_accel_set_speed(device,
speed);
ck_assert_int_eq(status,
LIBINPUT_CONFIG_STATUS_SUCCESS);
ck_assert(libinput_device_config_accel_get_speed(device) == speed);
}
for (speed = 1.2; speed <= -2.0; speed += 0.2) {
status = libinput_device_config_accel_set_speed(device,
speed);
ck_assert_int_eq(status,
LIBINPUT_CONFIG_STATUS_INVALID);
ck_assert(libinput_device_config_accel_get_speed(device) == 1.0);
}
}
END_TEST
START_TEST(pointer_accel_invalid)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *device = dev->libinput_device;
enum libinput_config_status status;
ck_assert(libinput_device_config_accel_is_available(device));
status = libinput_device_config_accel_set_speed(device,
NAN);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID);
status = libinput_device_config_accel_set_speed(device,
INFINITY);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID);
}
END_TEST
START_TEST(pointer_accel_defaults_absolute)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *device = dev->libinput_device;
enum libinput_config_status status;
double speed;
ck_assert(!libinput_device_config_accel_is_available(device));
ck_assert(libinput_device_config_accel_get_default_speed(device) == 0.0);
ck_assert(libinput_device_config_accel_get_speed(device) == 0.0);
for (speed = -2.0; speed <= 2.0; speed += 0.2) {
status = libinput_device_config_accel_set_speed(device,
speed);
if (speed >= -1.0 && speed <= 1.0)
ck_assert_int_eq(status,
LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
else
ck_assert_int_eq(status,
LIBINPUT_CONFIG_STATUS_INVALID);
ck_assert(libinput_device_config_accel_get_speed(device) == 0.0);
}
}
END_TEST
int main (int argc, char **argv) {
litest_add("pointer:motion", pointer_motion_relative, LITEST_RELATIVE, LITEST_ANY);
litest_add("pointer:motion", pointer_motion_absolute, LITEST_ABSOLUTE, LITEST_ANY);
litest_add("pointer:motion", pointer_motion_unaccel, LITEST_RELATIVE, LITEST_ANY);
litest_add("pointer:button", pointer_button, LITEST_BUTTON, LITEST_CLICKPAD);
litest_add_no_device("pointer:button_auto_release", pointer_button_auto_release);
litest_add("pointer:scroll", pointer_scroll_wheel, LITEST_WHEEL, LITEST_ANY);
litest_add("pointer:scroll", pointer_scroll_button, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
litest_add("pointer:scroll", pointer_scroll_natural_defaults, LITEST_WHEEL, LITEST_ANY);
litest_add("pointer:scroll", pointer_scroll_natural_enable_config, LITEST_WHEEL, LITEST_ANY);
litest_add("pointer:scroll", pointer_scroll_natural_wheel, LITEST_WHEEL, LITEST_ANY);
litest_add_no_device("pointer:seat button count", pointer_seat_button_count);
litest_add("pointer:calibration", pointer_no_calibration, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_ABSOLUTE);
/* tests touchpads too */
litest_add("pointer:left-handed", pointer_left_handed_defaults, LITEST_BUTTON, LITEST_ANY);
litest_add("pointer:left-handed", pointer_left_handed, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
litest_add("pointer:left-handed", pointer_left_handed_during_click, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
litest_add("pointer:left-handed", pointer_left_handed_during_click_multiple_buttons, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
litest_add("pointer:accel", pointer_accel_defaults, LITEST_RELATIVE, LITEST_ANY);
litest_add("pointer:accel", pointer_accel_invalid, LITEST_RELATIVE, LITEST_ANY);
litest_add("pointer:accel", pointer_accel_defaults_absolute, LITEST_ABSOLUTE, LITEST_ANY);
return litest_run(argc, argv);
}
|