| 1 |
/* |
| 2 |
* Copyright © 2018 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 <errno.h> |
| 27 |
#include <fcntl.h> |
| 28 |
#include <libinput.h> |
| 29 |
#include <stdarg.h> |
| 30 |
#include <stdbool.h> |
| 31 |
#include <unistd.h> |
| 32 |
|
| 33 |
#include "util-input-event.h" |
| 34 |
|
| 35 |
#include "libinput-util.h" |
| 36 |
#include "litest.h" |
| 37 |
|
| 38 |
START_TEST(totem_type) |
| 39 |
{ |
| 40 |
struct litest_device *dev = litest_current_device(); |
| 41 |
struct libinput *li = dev->libinput; |
| 42 |
struct libinput_event *event; |
| 43 |
struct libinput_event_tablet_tool *t; |
| 44 |
struct libinput_tablet_tool *tool; |
| 45 |
|
| 46 |
litest_drain_events(li); |
| 47 |
|
| 48 |
litest_tablet_proximity_in(dev, 50, 50, NULL); |
| 49 |
litest_dispatch(li); |
| 50 |
|
| 51 |
event = libinput_get_event(li); |
| 52 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 53 |
tool = libinput_event_tablet_tool_get_tool(t); |
| 54 |
|
| 55 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 56 |
LIBINPUT_TABLET_TOOL_TYPE_TOTEM); |
| 57 |
libinput_event_destroy(event); |
| 58 |
} |
| 59 |
END_TEST |
| 60 |
|
| 61 |
START_TEST(totem_axes) |
| 62 |
{ |
| 63 |
struct litest_device *dev = litest_current_device(); |
| 64 |
struct libinput *li = dev->libinput; |
| 65 |
struct libinput_event *event; |
| 66 |
struct libinput_event_tablet_tool *t; |
| 67 |
struct libinput_tablet_tool *tool; |
| 68 |
|
| 69 |
litest_drain_events(li); |
| 70 |
|
| 71 |
litest_tablet_proximity_in(dev, 50, 50, NULL); |
| 72 |
litest_dispatch(li); |
| 73 |
|
| 74 |
event = libinput_get_event(li); |
| 75 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 76 |
tool = libinput_event_tablet_tool_get_tool(t); |
| 77 |
|
| 78 |
litest_assert(libinput_tablet_tool_has_rotation(tool)); |
| 79 |
litest_assert(libinput_tablet_tool_has_size(tool)); |
| 80 |
litest_assert(libinput_tablet_tool_has_button(tool, BTN_0)); |
| 81 |
|
| 82 |
libinput_event_destroy(event); |
| 83 |
} |
| 84 |
END_TEST |
| 85 |
|
| 86 |
START_TEST(totem_proximity_in_out) |
| 87 |
{ |
| 88 |
struct litest_device *dev = litest_current_device(); |
| 89 |
struct libinput *li = dev->libinput; |
| 90 |
struct libinput_event *event; |
| 91 |
struct libinput_event_tablet_tool *t; |
| 92 |
|
| 93 |
litest_drain_events(li); |
| 94 |
|
| 95 |
litest_tablet_proximity_in(dev, 50, 50, NULL); |
| 96 |
litest_dispatch(li); |
| 97 |
|
| 98 |
event = libinput_get_event(li); |
| 99 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 100 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), |
| 101 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 102 |
libinput_event_destroy(event); |
| 103 |
|
| 104 |
event = libinput_get_event(li); |
| 105 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 106 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), |
| 107 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 108 |
libinput_event_destroy(event); |
| 109 |
|
| 110 |
litest_assert_empty_queue(li); |
| 111 |
litest_tablet_proximity_out(dev); |
| 112 |
litest_dispatch(li); |
| 113 |
|
| 114 |
event = libinput_get_event(li); |
| 115 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 116 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), |
| 117 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 118 |
libinput_event_destroy(event); |
| 119 |
|
| 120 |
event = libinput_get_event(li); |
| 121 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 122 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), |
| 123 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 124 |
libinput_event_destroy(event); |
| 125 |
} |
| 126 |
END_TEST |
| 127 |
|
| 128 |
START_TEST(totem_proximity_in_on_init) |
| 129 |
{ |
| 130 |
struct litest_device *dev = litest_current_device(); |
| 131 |
struct libinput_event *event; |
| 132 |
struct libinput_event_tablet_tool *t; |
| 133 |
const char *devnode; |
| 134 |
double x, y; |
| 135 |
double w, h; |
| 136 |
const struct input_absinfo *abs; |
| 137 |
|
| 138 |
abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_X); |
| 139 |
w = absinfo_range(abs) / abs->resolution; |
| 140 |
abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_Y); |
| 141 |
h = absinfo_range(abs) / abs->resolution; |
| 142 |
|
| 143 |
litest_tablet_proximity_in(dev, 50, 50, NULL); |
| 144 |
|
| 145 |
/* for simplicity, we create a new litest context */ |
| 146 |
devnode = libevdev_uinput_get_devnode(dev->uinput); |
| 147 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 148 |
libinput_path_add_device(li, devnode); |
| 149 |
litest_dispatch(li); |
| 150 |
|
| 151 |
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); |
| 152 |
event = libinput_get_event(li); |
| 153 |
libinput_event_destroy(event); |
| 154 |
|
| 155 |
event = libinput_get_event(li); |
| 156 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 157 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), |
| 158 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 159 |
x = libinput_event_tablet_tool_get_x(t); |
| 160 |
y = libinput_event_tablet_tool_get_y(t); |
| 161 |
|
| 162 |
litest_assert_double_gt(x, w / 2 - 1); |
| 163 |
litest_assert_double_lt(x, w / 2 + 1); |
| 164 |
litest_assert_double_gt(y, h / 2 - 1); |
| 165 |
litest_assert_double_lt(y, h / 2 + 1); |
| 166 |
|
| 167 |
libinput_event_destroy(event); |
| 168 |
|
| 169 |
event = libinput_get_event(li); |
| 170 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 171 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), |
| 172 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 173 |
x = libinput_event_tablet_tool_get_x(t); |
| 174 |
y = libinput_event_tablet_tool_get_y(t); |
| 175 |
|
| 176 |
litest_assert_double_gt(x, w / 2 - 1); |
| 177 |
litest_assert_double_lt(x, w / 2 + 1); |
| 178 |
litest_assert_double_gt(y, h / 2 - 1); |
| 179 |
litest_assert_double_lt(y, h / 2 + 1); |
| 180 |
|
| 181 |
libinput_event_destroy(event); |
| 182 |
|
| 183 |
litest_assert_empty_queue(li); |
| 184 |
} |
| 185 |
END_TEST |
| 186 |
|
| 187 |
START_TEST(totem_proximity_out_on_suspend) |
| 188 |
{ |
| 189 |
struct litest_device *dev = litest_current_device(); |
| 190 |
struct libinput_event *event; |
| 191 |
struct libinput_event_tablet_tool *t; |
| 192 |
const char *devnode; |
| 193 |
|
| 194 |
/* for simplicity, we create a new litest context */ |
| 195 |
devnode = libevdev_uinput_get_devnode(dev->uinput); |
| 196 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 197 |
libinput_path_add_device(li, devnode); |
| 198 |
|
| 199 |
litest_tablet_proximity_in(dev, 50, 50, NULL); |
| 200 |
litest_drain_events(li); |
| 201 |
|
| 202 |
libinput_suspend(li); |
| 203 |
|
| 204 |
litest_dispatch(li); |
| 205 |
event = libinput_get_event(li); |
| 206 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 207 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), |
| 208 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 209 |
libinput_event_destroy(event); |
| 210 |
|
| 211 |
event = libinput_get_event(li); |
| 212 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 213 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), |
| 214 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 215 |
libinput_event_destroy(event); |
| 216 |
|
| 217 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); |
| 218 |
} |
| 219 |
END_TEST |
| 220 |
|
| 221 |
START_TEST(totem_motion) |
| 222 |
{ |
| 223 |
struct litest_device *dev = litest_current_device(); |
| 224 |
struct libinput *li = dev->libinput; |
| 225 |
struct libinput_event *event; |
| 226 |
double x = 50, y = 50; |
| 227 |
double current_x, current_y, old_x, old_y; |
| 228 |
|
| 229 |
litest_tablet_proximity_in(dev, x, y, NULL); |
| 230 |
litest_drain_events(li); |
| 231 |
|
| 232 |
for (int i = 0; i < 30; i++, x++, y--) { |
| 233 |
struct libinput_event_tablet_tool *t; |
| 234 |
|
| 235 |
litest_tablet_motion(dev, x + 1, y + 1, NULL); |
| 236 |
litest_dispatch(li); |
| 237 |
|
| 238 |
event = libinput_get_event(li); |
| 239 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 240 |
|
| 241 |
litest_assert(libinput_event_tablet_tool_x_has_changed(t)); |
| 242 |
litest_assert(libinput_event_tablet_tool_y_has_changed(t)); |
| 243 |
|
| 244 |
current_x = libinput_event_tablet_tool_get_x(t); |
| 245 |
current_y = libinput_event_tablet_tool_get_y(t); |
| 246 |
if (i != 0) { |
| 247 |
litest_assert_double_gt(current_x, old_x); |
| 248 |
litest_assert_double_lt(current_y, old_y); |
| 249 |
} |
| 250 |
old_x = current_x; |
| 251 |
old_y = current_y; |
| 252 |
|
| 253 |
libinput_event_destroy(event); |
| 254 |
} |
| 255 |
} |
| 256 |
END_TEST |
| 257 |
|
| 258 |
START_TEST(totem_rotation) |
| 259 |
{ |
| 260 |
struct litest_device *dev = litest_current_device(); |
| 261 |
struct libinput *li = dev->libinput; |
| 262 |
struct libinput_event *event; |
| 263 |
double r, old_r; |
| 264 |
struct axis_replacement axes[] = { |
| 265 |
{ ABS_MT_ORIENTATION, 50 }, /* mid-point is 0 */ |
| 266 |
{ -1, -1 }, |
| 267 |
}; |
| 268 |
|
| 269 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 270 |
litest_drain_events(li); |
| 271 |
|
| 272 |
old_r = 360; |
| 273 |
|
| 274 |
for (int i = 1; i < 30; i++) { |
| 275 |
struct libinput_event_tablet_tool *t; |
| 276 |
|
| 277 |
litest_axis_set_value(axes, ABS_MT_ORIENTATION, 50 + i); |
| 278 |
litest_tablet_motion(dev, 50, 50, axes); |
| 279 |
litest_dispatch(li); |
| 280 |
|
| 281 |
event = libinput_get_event(li); |
| 282 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 283 |
|
| 284 |
litest_assert(!libinput_event_tablet_tool_x_has_changed(t)); |
| 285 |
litest_assert(!libinput_event_tablet_tool_y_has_changed(t)); |
| 286 |
litest_assert(libinput_event_tablet_tool_rotation_has_changed(t)); |
| 287 |
|
| 288 |
r = libinput_event_tablet_tool_get_rotation(t); |
| 289 |
litest_assert_double_lt(r, old_r); |
| 290 |
old_r = r; |
| 291 |
|
| 292 |
libinput_event_destroy(event); |
| 293 |
} |
| 294 |
|
| 295 |
old_r = 0; |
| 296 |
|
| 297 |
for (int i = 1; i < 30; i++) { |
| 298 |
struct libinput_event_tablet_tool *t; |
| 299 |
|
| 300 |
litest_axis_set_value(axes, ABS_MT_ORIENTATION, 50 - i); |
| 301 |
litest_tablet_motion(dev, 50, 50, axes); |
| 302 |
litest_dispatch(li); |
| 303 |
|
| 304 |
event = libinput_get_event(li); |
| 305 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 306 |
|
| 307 |
litest_assert(!libinput_event_tablet_tool_x_has_changed(t)); |
| 308 |
litest_assert(!libinput_event_tablet_tool_y_has_changed(t)); |
| 309 |
litest_assert(libinput_event_tablet_tool_rotation_has_changed(t)); |
| 310 |
|
| 311 |
r = libinput_event_tablet_tool_get_rotation(t); |
| 312 |
litest_assert_double_gt(r, old_r); |
| 313 |
old_r = r; |
| 314 |
|
| 315 |
libinput_event_destroy(event); |
| 316 |
} |
| 317 |
} |
| 318 |
END_TEST |
| 319 |
|
| 320 |
START_TEST(totem_size) |
| 321 |
{ |
| 322 |
struct litest_device *dev = litest_current_device(); |
| 323 |
struct libinput *li = dev->libinput; |
| 324 |
struct libinput_event *event; |
| 325 |
struct libinput_event_tablet_tool *t; |
| 326 |
double smin, smaj; |
| 327 |
|
| 328 |
litest_drain_events(li); |
| 329 |
|
| 330 |
litest_tablet_proximity_in(dev, 50, 50, NULL); |
| 331 |
litest_dispatch(li); |
| 332 |
|
| 333 |
event = libinput_get_event(li); |
| 334 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 335 |
litest_assert(libinput_event_tablet_tool_size_major_has_changed(t)); |
| 336 |
litest_assert(libinput_event_tablet_tool_size_minor_has_changed(t)); |
| 337 |
smaj = libinput_event_tablet_tool_get_size_major(t); |
| 338 |
smin = libinput_event_tablet_tool_get_size_minor(t); |
| 339 |
libinput_event_destroy(event); |
| 340 |
|
| 341 |
litest_assert_double_eq(smaj, 71.8); |
| 342 |
litest_assert_double_eq(smin, 71.8); |
| 343 |
|
| 344 |
litest_drain_events(li); |
| 345 |
} |
| 346 |
END_TEST |
| 347 |
|
| 348 |
START_TEST(totem_button) |
| 349 |
{ |
| 350 |
struct litest_device *dev = litest_current_device(); |
| 351 |
struct libinput *li = dev->libinput; |
| 352 |
struct libinput_event *event; |
| 353 |
struct libinput_event_tablet_tool *t; |
| 354 |
|
| 355 |
litest_tablet_proximity_in(dev, 30, 40, NULL); |
| 356 |
litest_drain_events(li); |
| 357 |
|
| 358 |
litest_button_click(dev, BTN_0, true); |
| 359 |
litest_dispatch(li); |
| 360 |
event = libinput_get_event(li); |
| 361 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 362 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(t), |
| 363 |
(unsigned int)BTN_0); |
| 364 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(t), |
| 365 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 366 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), |
| 367 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 368 |
libinput_event_destroy(event); |
| 369 |
|
| 370 |
litest_button_click(dev, BTN_0, false); |
| 371 |
litest_dispatch(li); |
| 372 |
|
| 373 |
event = libinput_get_event(li); |
| 374 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 375 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(t), |
| 376 |
(unsigned int)BTN_0); |
| 377 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(t), |
| 378 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 379 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), |
| 380 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 381 |
libinput_event_destroy(event); |
| 382 |
} |
| 383 |
END_TEST |
| 384 |
|
| 385 |
START_TEST(totem_button_down_on_init) |
| 386 |
{ |
| 387 |
struct litest_device *dev = litest_current_device(); |
| 388 |
struct libinput_event *event; |
| 389 |
struct libinput_event_tablet_tool *t; |
| 390 |
const char *devnode; |
| 391 |
|
| 392 |
litest_tablet_proximity_in(dev, 50, 50, NULL); |
| 393 |
litest_button_click(dev, BTN_0, true); |
| 394 |
|
| 395 |
/* for simplicity, we create a new litest context */ |
| 396 |
devnode = libevdev_uinput_get_devnode(dev->uinput); |
| 397 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 398 |
libinput_path_add_device(li, devnode); |
| 399 |
litest_dispatch(li); |
| 400 |
|
| 401 |
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); |
| 402 |
event = libinput_get_event(li); |
| 403 |
libinput_event_destroy(event); |
| 404 |
|
| 405 |
event = libinput_get_event(li); |
| 406 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 407 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), |
| 408 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 409 |
|
| 410 |
libinput_event_destroy(event); |
| 411 |
|
| 412 |
event = libinput_get_event(li); |
| 413 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 414 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), |
| 415 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 416 |
|
| 417 |
libinput_event_destroy(event); |
| 418 |
|
| 419 |
/* The button is down on init but we don't expect an event */ |
| 420 |
litest_assert_empty_queue(li); |
| 421 |
|
| 422 |
litest_button_click(dev, BTN_0, false); |
| 423 |
litest_dispatch(li); |
| 424 |
litest_assert_empty_queue(li); |
| 425 |
|
| 426 |
/* but buttons after this should be sent */ |
| 427 |
litest_button_click(dev, BTN_0, true); |
| 428 |
litest_dispatch(li); |
| 429 |
litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_PRESSED); |
| 430 |
litest_button_click(dev, BTN_0, false); |
| 431 |
litest_dispatch(li); |
| 432 |
litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_RELEASED); |
| 433 |
} |
| 434 |
END_TEST |
| 435 |
|
| 436 |
START_TEST(totem_button_up_on_delete) |
| 437 |
{ |
| 438 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 439 |
struct litest_device *dev = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM); |
| 440 |
|
| 441 |
litest_tablet_proximity_in(dev, 10, 10, NULL); |
| 442 |
litest_drain_events(li); |
| 443 |
|
| 444 |
litest_button_click(dev, BTN_0, true); |
| 445 |
litest_drain_events(li); |
| 446 |
|
| 447 |
litest_device_destroy(dev); |
| 448 |
litest_dispatch(li); |
| 449 |
|
| 450 |
litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_RELEASED); |
| 451 |
|
| 452 |
litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_UP); |
| 453 |
litest_assert_tablet_proximity_event(li, |
| 454 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 455 |
} |
| 456 |
END_TEST |
| 457 |
|
| 458 |
START_TEST(totem_arbitration_below) |
| 459 |
{ |
| 460 |
struct litest_device *totem = litest_current_device(); |
| 461 |
struct litest_device *touch; |
| 462 |
struct libinput *li = totem->libinput; |
| 463 |
|
| 464 |
touch = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM_TOUCH); |
| 465 |
litest_drain_events(li); |
| 466 |
|
| 467 |
/* touches below the totem, cancelled once the totem is down */ |
| 468 |
litest_touch_down(touch, 0, 50, 50); |
| 469 |
litest_dispatch(li); |
| 470 |
litest_assert_touch_down_frame(li); |
| 471 |
litest_touch_move_to(touch, 0, 50, 50, 50, 70, 10); |
| 472 |
litest_dispatch(li); |
| 473 |
while (libinput_next_event_type(li)) { |
| 474 |
litest_assert_touch_motion_frame(li); |
| 475 |
} |
| 476 |
|
| 477 |
litest_tablet_proximity_in(totem, 50, 70, NULL); |
| 478 |
litest_dispatch(li); |
| 479 |
|
| 480 |
litest_assert_tablet_proximity_event(li, |
| 481 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 482 |
litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 483 |
litest_assert_touch_cancel(li); |
| 484 |
|
| 485 |
litest_touch_move_to(touch, 0, 50, 70, 20, 50, 10); |
| 486 |
litest_assert_empty_queue(li); |
| 487 |
|
| 488 |
litest_tablet_motion(totem, 20, 50, NULL); |
| 489 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 490 |
|
| 491 |
litest_touch_up(touch, 0); |
| 492 |
litest_assert_empty_queue(li); |
| 493 |
|
| 494 |
litest_device_destroy(touch); |
| 495 |
} |
| 496 |
END_TEST |
| 497 |
|
| 498 |
START_TEST(totem_arbitration_during) |
| 499 |
{ |
| 500 |
struct litest_device *totem = litest_current_device(); |
| 501 |
struct litest_device *touch; |
| 502 |
struct libinput *li = totem->libinput; |
| 503 |
|
| 504 |
touch = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM_TOUCH); |
| 505 |
litest_drain_events(li); |
| 506 |
|
| 507 |
litest_tablet_proximity_in(totem, 50, 50, NULL); |
| 508 |
litest_dispatch(li); |
| 509 |
|
| 510 |
litest_drain_events(li); |
| 511 |
|
| 512 |
for (int i = 0; i < 3; i++) { |
| 513 |
litest_touch_down(touch, 0, 51, 51); |
| 514 |
litest_touch_move_to(touch, 0, 51, 50, 90, 80, 10); |
| 515 |
litest_touch_up(touch, 0); |
| 516 |
|
| 517 |
litest_assert_empty_queue(li); |
| 518 |
} |
| 519 |
|
| 520 |
litest_device_destroy(touch); |
| 521 |
} |
| 522 |
END_TEST |
| 523 |
|
| 524 |
START_TEST(totem_arbitration_outside_rect) |
| 525 |
{ |
| 526 |
struct litest_device *totem = litest_current_device(); |
| 527 |
struct litest_device *touch; |
| 528 |
struct libinput *li = totem->libinput; |
| 529 |
|
| 530 |
touch = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM_TOUCH); |
| 531 |
litest_drain_events(li); |
| 532 |
|
| 533 |
litest_tablet_proximity_in(totem, 50, 50, NULL); |
| 534 |
litest_dispatch(li); |
| 535 |
|
| 536 |
litest_drain_events(li); |
| 537 |
|
| 538 |
for (int i = 0; i < 3; i++) { |
| 539 |
litest_touch_down(touch, 0, 81, 51); |
| 540 |
litest_touch_move_to(touch, 0, 81, 50, 90, 80, 10); |
| 541 |
litest_touch_up(touch, 0); |
| 542 |
litest_dispatch(li); |
| 543 |
|
| 544 |
litest_assert_touch_sequence(li); |
| 545 |
} |
| 546 |
|
| 547 |
/* moving onto the totem is fine */ |
| 548 |
litest_touch_down(touch, 0, 81, 51); |
| 549 |
litest_touch_move_to(touch, 0, 81, 50, 50, 50, 10); |
| 550 |
litest_touch_up(touch, 0); |
| 551 |
litest_dispatch(li); |
| 552 |
|
| 553 |
litest_assert_touch_sequence(li); |
| 554 |
|
| 555 |
litest_device_destroy(touch); |
| 556 |
} |
| 557 |
END_TEST |
| 558 |
|
| 559 |
START_TEST(totem_touch_size_missing_resolution) |
| 560 |
{ |
| 561 |
struct libinput_device *device; |
| 562 |
/* Match the Dell Canvas Totem quirk: vendor=0x2575, product=0x0204, |
| 563 |
* name matching "*System Multi Axis", bus=USB */ |
| 564 |
struct input_id id = { |
| 565 |
.bustype = 0x3, |
| 566 |
.vendor = 0x2575, |
| 567 |
.product = 0x0204, |
| 568 |
}; |
| 569 |
struct input_absinfo absinfo[] = { |
| 570 |
{ ABS_MT_SLOT, 0, 4, 0, 0, 0 }, |
| 571 |
{ ABS_MT_TOUCH_MAJOR, 0, 32767, 0, 0, 10 }, |
| 572 |
{ ABS_MT_TOUCH_MINOR, 0, 32767, 0, 0, 0 }, /* resolution missing */ |
| 573 |
{ ABS_MT_ORIENTATION, -89, 89, 0, 0, 0 }, |
| 574 |
{ ABS_MT_POSITION_X, 0, 32767, 0, 0, 55 }, |
| 575 |
{ ABS_MT_POSITION_Y, 0, 32767, 0, 0, 98 }, |
| 576 |
{ ABS_MT_TOOL_TYPE, 9, 10, 0, 0, 0 }, |
| 577 |
{ ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, |
| 578 |
{ -1, -1, -1, -1, -1, -1 }, |
| 579 |
}; |
| 580 |
/* clang-format off */ |
| 581 |
int events[] = { |
| 582 |
EV_KEY, BTN_0, |
| 583 |
INPUT_PROP_MAX, INPUT_PROP_DIRECT, |
| 584 |
-1, -1, |
| 585 |
}; |
| 586 |
/* clang-format on */ |
| 587 |
|
| 588 |
_destroy_(libevdev_uinput) *uinput = |
| 589 |
litest_create_uinput_device_from_description( |
| 590 |
"CoolTouch System Multi Axis", |
| 591 |
&id, |
| 592 |
absinfo, |
| 593 |
events); |
| 594 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 595 |
litest_disable_log_handler(li); |
| 596 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 597 |
litest_restore_log_handler(li); |
| 598 |
|
| 599 |
/* The device matches the Dell Canvas Totem quirk but has |
| 600 |
* ABS_MT_TOUCH_MINOR resolution missing. The totem dispatch |
| 601 |
* should reject it, so it must not be recognized as a tablet |
| 602 |
* tool device. */ |
| 603 |
if (device) |
| 604 |
litest_assert(!libinput_device_has_capability( |
| 605 |
device, |
| 606 |
LIBINPUT_DEVICE_CAP_TABLET_TOOL)); |
| 607 |
} |
| 608 |
END_TEST |
| 609 |
|
| 610 |
TEST_COLLECTION(totem) |
| 611 |
{ |
| 612 |
/* clang-format off */ |
| 613 |
litest_add(totem_type, LITEST_TOTEM, LITEST_ANY); |
| 614 |
litest_add(totem_axes, LITEST_TOTEM, LITEST_ANY); |
| 615 |
litest_add(totem_proximity_in_out, LITEST_TOTEM, LITEST_ANY); |
| 616 |
litest_add(totem_proximity_in_on_init, LITEST_TOTEM, LITEST_ANY); |
| 617 |
litest_add(totem_proximity_out_on_suspend, LITEST_TOTEM, LITEST_ANY); |
| 618 |
|
| 619 |
litest_add(totem_motion, LITEST_TOTEM, LITEST_ANY); |
| 620 |
litest_add(totem_rotation, LITEST_TOTEM, LITEST_ANY); |
| 621 |
litest_add(totem_size, LITEST_TOTEM, LITEST_ANY); |
| 622 |
litest_add(totem_button, LITEST_TOTEM, LITEST_ANY); |
| 623 |
litest_add(totem_button_down_on_init, LITEST_TOTEM, LITEST_ANY); |
| 624 |
litest_add_no_device(totem_button_up_on_delete); |
| 625 |
litest_add_no_device(totem_touch_size_missing_resolution); |
| 626 |
|
| 627 |
litest_add(totem_arbitration_below, LITEST_TOTEM, LITEST_ANY); |
| 628 |
litest_add(totem_arbitration_during, LITEST_TOTEM, LITEST_ANY); |
| 629 |
litest_add(totem_arbitration_outside_rect, LITEST_TOTEM, LITEST_ANY); |
| 630 |
/* clang-format on */ |
| 631 |
} |