Debian Codegraph @

test/litest-device-elan-tablet.c

raw
1 /*
2 * Copyright © 2020 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 struct input_event proximity_in_events[] = {
30 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
31 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
32 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
33 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
34 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
35 { .type = -1, .code = -1 },
36 };
37
38 static struct input_event proximity_out_events[] = {
39 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
40 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
41 { .type = -1, .code = -1 },
42 };
43
44 static struct input_event motion_events[] = {
45 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
46 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
47 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
48 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
49 { .type = -1, .code = -1 },
50 };
51
52 static bool
53 proximity_in(struct litest_device *d,
54 unsigned int tool_type,
55 double *x,
56 double *y,
57 struct axis_replacement *axes)
58 {
59 /* nothing special needed for the pen tool, so let litest handle
60 * this */
61 if (tool_type == BTN_TOOL_PEN)
62 return false;
63
64 /* a non-pen tool requires the pen to be in proximity as well. */
65 int sx = litest_scale(d, ABS_X, *x);
66 int sy = litest_scale(d, ABS_Y, *y);
67 litest_event(d, EV_ABS, ABS_X, sx);
68 litest_event(d, EV_ABS, ABS_X, sy);
69 litest_event(d, EV_KEY, BTN_TOOL_PEN, 1);
70 litest_event(d, EV_SYN, SYN_REPORT, 0);
71
72 /* litest will append the proximity_in_events if we return false,
73 * including the right tool event */
74 return false;
75 }
76
77 static bool
78 proximity_out(struct litest_device *d, unsigned int tool_type)
79 {
80 /* a non-pen tool requires the pen to go out of proximity as well.
81 * litest will append the proximity_out_events if we return false
82 */
83 if (tool_type != BTN_TOOL_PEN)
84 litest_event(d, EV_KEY, BTN_TOOL_PEN, 0);
85
86 return false;
87 }
88
89 static int
90 get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
91 {
92 switch (evcode) {
93 case ABS_PRESSURE:
94 *value = 100;
95 return 0;
96 }
97 return 1;
98 }
99
100 static struct litest_device_interface interface = {
101 .tablet_proximity_in_events = proximity_in_events,
102 .tablet_proximity_out_events = proximity_out_events,
103 .tablet_motion_events = motion_events,
104 .tablet_proximity_in = proximity_in,
105 .tablet_proximity_out = proximity_out,
106
107 .get_axis_default = get_axis_default,
108 };
109
110 /* clang-format off */
111 static struct input_absinfo absinfo[] = {
112 { ABS_X, 0, 18176, 0, 0, 62 },
113 { ABS_Y, 0, 10240, 0, 0, 62 },
114 { ABS_PRESSURE, 0, 4096, 0, 0, 0 },
115 { .value = -1 },
116 };
117 /* clang-format on */
118
119 static struct input_id input_id = {
120 .bustype = 0x18,
121 .vendor = 0x4f3,
122 .product = 0x23b9,
123 .version = 0x100,
124 };
125
126 /* Note: this tablet is one that sets both BTN_TOOL_PEN and BTN_TOOL_RUBBER,
127 * see https://gitlab.freedesktop.org/libinput/libinput/-/issues/259
128 * The one in the issue isn't the exact same model, but only the pid and x/y
129 * axis max differs differs.
130 */
131 /* clang-format off */
132 static int events[] = {
133 EV_KEY, BTN_TOOL_PEN,
134 EV_KEY, BTN_TOOL_RUBBER,
135 EV_KEY, BTN_TOUCH,
136 EV_KEY, BTN_STYLUS,
137 EV_MSC, MSC_SCAN,
138 -1, -1,
139 };
140 /* clang-format on */
141
142 TEST_DEVICE(LITEST_ELAN_TABLET,
143 .features = LITEST_TABLET,
144 .interface = &interface,
145
146 .name = "ELAN2514:00 04F3:23B9",
147 .id = &input_id,
148 .events = events,
149 .absinfo = absinfo, )