Debian Codegraph @

test/litest-device-wacom-calibrated-tablet.c

raw
1 /*
2 * Copyright © 2023 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "config.h"
25
26 #include "litest-int.h"
27 #include "litest.h"
28
29 static bool
30 inverter(struct litest_device *dev, double *x, double *y, struct axis_replacement *axes)
31 {
32 /* Input data is in percent (0-100), so let's swap x and y around.
33 * With our matrix this should be undone by libinput later
34 * and the tablet behaves as if normal */
35 *x = 100 - *x;
36 *y = 100 - *y;
37
38 /* let the generic code handle the event */
39 return false;
40 }
41
42 static bool
43 proximity_in_handler(struct litest_device *dev,
44 unsigned int tool_type,
45 double *x,
46 double *y,
47 struct axis_replacement *axes)
48 {
49 /* let the generic code handle the event */
50 return inverter(dev, x, y, axes);
51 }
52
53 static struct input_event proximity_in[] = {
54 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
55 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
56 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
57 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
58 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
59 { .type = -1, .code = -1 },
60 };
61
62 static struct input_event proximity_out[] = {
63 { .type = EV_ABS, .code = ABS_X, .value = 0 },
64 { .type = EV_ABS, .code = ABS_Y, .value = 0 },
65 { .type = EV_ABS, .code = ABS_PRESSURE, .value = 0 },
66 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
67 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
68 { .type = -1, .code = -1 },
69 };
70
71 static struct input_event motion[] = {
72 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
73 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
74 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
75 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
76 { .type = -1, .code = -1 },
77 };
78
79 static int
80 get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
81 {
82 switch (evcode) {
83 case ABS_PRESSURE:
84 *value = 100;
85 return 0;
86 }
87 return 1;
88 }
89
90 static struct litest_device_interface interface = {
91 .tablet_proximity_in = proximity_in_handler,
92 .tablet_tip_down = inverter,
93 .tablet_tip_up = inverter,
94 .tablet_motion = inverter,
95
96 .tablet_proximity_in_events = proximity_in,
97 .tablet_proximity_out_events = proximity_out,
98 .tablet_motion_events = motion,
99
100 .get_axis_default = get_axis_default,
101 };
102
103 /* clang-format off */
104 static struct input_absinfo absinfo[] = {
105 { ABS_X, 0, 29476, 4, 0, 100 },
106 { ABS_Y, 0, 16624, 4, 0, 100 },
107 { ABS_PRESSURE, 0, 1023, 0, 0, 0 },
108 { .value = -1 },
109 };
110 /* clang-format on */
111
112 static struct input_id input_id = {
113 .bustype = 0x3,
114 .vendor = 0x56a,
115 .product = 0x501e,
116 .version = 0x111,
117 };
118
119 /* clang-format off */
120 static int events[] = {
121 EV_KEY, BTN_TOOL_PEN,
122 EV_KEY, BTN_TOOL_RUBBER,
123 EV_KEY, BTN_TOUCH,
124 EV_KEY, BTN_STYLUS,
125 EV_KEY, BTN_STYLUS2,
126 INPUT_PROP_MAX, INPUT_PROP_DIRECT,
127 -1, -1,
128 };
129 /* clang-format on */
130
131 TEST_DEVICE(LITEST_WACOM_CALIBRATED_TABLET_PEN,
132 .features = LITEST_TABLET | LITEST_PRECALIBRATED,
133 .interface = &interface,
134
135 .name = "Wacom MultiTouch Sensor Pen",
136 .id = &input_id,
137 .events = events,
138 .absinfo = absinfo,
139 .udev_properties = {
140 { "LIBINPUT_CALIBRATION_MATRIX", "-1 0 1 0 -1 1" },
141 { NULL },
142 }, )