Debian Codegraph @

test/litest-device-wacom-isdv4-524c-pen.c

raw
1 /*
2 * Copyright © 2019 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 struct priv {
30 unsigned int tool;
31 };
32
33 static bool
34 create(struct litest_device *d)
35 {
36 d->private = zalloc(sizeof(struct priv));
37 return true; /* we want litest to create our device */
38 }
39
40 static struct input_event proximity_in[] = {
41 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
42 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
43 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
44 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
45 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
46 { .type = -1, .code = -1 },
47 };
48
49 static struct input_event proximity_out[] = {
50 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
51 { .type = EV_ABS, .code = ABS_PRESSURE, .value = 0 },
52 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
53 { .type = -1, .code = -1 },
54 };
55
56 static struct input_event motion[] = {
57 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
58 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
59 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
60 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
61 { .type = -1, .code = -1 },
62 };
63
64 static int
65 get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
66 {
67 switch (evcode) {
68 case ABS_PRESSURE:
69 *value = 4000;
70 return 0;
71 case ABS_TILT_X:
72 case ABS_TILT_Y:
73 abort();
74 }
75 return 1;
76 }
77
78 static bool
79 prox_in(struct litest_device *d,
80 unsigned int tool_type,
81 double *x,
82 double *y,
83 struct axis_replacement *axes)
84 {
85 struct priv *priv = d->private;
86 priv->tool = tool_type;
87
88 return false;
89 }
90
91 static bool
92 prox_out(struct litest_device *d, unsigned int tool_type)
93 {
94 struct priv *priv = d->private;
95 priv->tool = 0;
96
97 return false;
98 }
99
100 static bool
101 tip_down(struct litest_device *d, double *x, double *y, struct axis_replacement *axes)
102 {
103 litest_event(d, EV_KEY, BTN_TOOL_PEN, 1);
104 return false; /* use the default behavior otherwise */
105 }
106
107 static bool
108 tip_up(struct litest_device *d, double *x, double *y, struct axis_replacement *axes)
109 {
110 struct priv *priv = d->private;
111 if (priv->tool != BTN_TOOL_PEN)
112 litest_event(d, EV_KEY, BTN_TOOL_PEN, 0);
113 return false; /* use the default behavior otherwise */
114 }
115
116 static struct litest_device_interface interface = {
117 .tablet_proximity_in_events = proximity_in,
118 .tablet_proximity_out_events = proximity_out,
119 .tablet_motion_events = motion,
120
121 .tablet_proximity_in = prox_in,
122 .tablet_proximity_out = prox_out,
123 .tablet_tip_down = tip_down,
124 .tablet_tip_up = tip_up,
125
126 .get_axis_default = get_axis_default,
127 };
128
129 /* clang-format off */
130 static struct input_absinfo absinfo[] = {
131 { ABS_X, 0, 30931, 0, 0, 100 },
132 { ABS_Y, 0, 17399, 0, 0, 100 },
133 /* This pen has tilt, but doesn't send events */
134 { ABS_TILT_X, -90, 90, 0, 0, 57 },
135 { ABS_TILT_Y, -90, 90, 0, 0, 57 },
136 { ABS_PRESSURE, 0, 4095, 0, 0, 0 },
137 { .value = -1 },
138 };
139 /* clang-format on */
140
141 static struct input_id input_id = {
142 .bustype = 0x3,
143 .vendor = 0x2d1f, /* Note: this is Wacom's Android VID */
144 .product = 0x524c,
145 };
146
147 /* clang-format off */
148 static int events[] = {
149 EV_KEY, BTN_TOOL_PEN,
150 EV_KEY, BTN_TOOL_RUBBER,
151 EV_KEY, BTN_TOUCH,
152 EV_KEY, BTN_STYLUS,
153 EV_KEY, BTN_STYLUS2,
154 INPUT_PROP_MAX, INPUT_PROP_DIRECT,
155 -1, -1,
156 };
157 /* clang-format on */
158
159 TEST_DEVICE(LITEST_WACOM_ISDV4_524C_PEN,
160 .features = LITEST_TABLET | LITEST_HOVER,
161 .interface = &interface,
162
163 .name = "Wacom Co.,Ltd. Pen and multitouch sensor Stylus",
164 .id = &input_id,
165 .events = events,
166 .absinfo = absinfo,
167 .create = create, )