| 1 |
/* |
| 2 |
* Copyright © 2014-2015 Red Hat, Inc. |
| 3 |
* Copyright © 2014 Lyude Paul |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the next |
| 13 |
* paragraph) shall be included in all copies or substantial portions of the |
| 14 |
* Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 |
* DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <config.h> |
| 26 |
|
| 27 |
#include <errno.h> |
| 28 |
#include <fcntl.h> |
| 29 |
#include <libinput.h> |
| 30 |
#include <stdarg.h> |
| 31 |
#include <stdbool.h> |
| 32 |
#include <unistd.h> |
| 33 |
|
| 34 |
#ifdef HAVE_LIBWACOM |
| 35 |
#include <libwacom/libwacom.h> |
| 36 |
#endif |
| 37 |
|
| 38 |
#include "util-input-event.h" |
| 39 |
|
| 40 |
#include "evdev-tablet.h" |
| 41 |
#include "libinput-util.h" |
| 42 |
#include "litest.h" |
| 43 |
|
| 44 |
enum { |
| 45 |
TILT_MINIMUM, |
| 46 |
TILT_CENTER, |
| 47 |
TILT_MAXIMUM, |
| 48 |
}; |
| 49 |
|
| 50 |
static inline unsigned int |
| 51 |
pick_stylus_or_btn0(struct litest_device *dev) |
| 52 |
{ |
| 53 |
if (libevdev_has_event_code(dev->evdev, EV_KEY, BTN_STYLUS)) |
| 54 |
return BTN_STYLUS; |
| 55 |
|
| 56 |
if (libevdev_has_event_code(dev->evdev, EV_KEY, BTN_0)) |
| 57 |
return BTN_0; /* totem */ |
| 58 |
|
| 59 |
litest_abort_msg("Device has neither BTN_STYLUS nor BTN_0"); |
| 60 |
} |
| 61 |
|
| 62 |
START_TEST(button_down_up) |
| 63 |
{ |
| 64 |
struct litest_device *dev = litest_current_device(); |
| 65 |
struct libinput *li = dev->libinput; |
| 66 |
struct libinput_event *event; |
| 67 |
struct libinput_event_tablet_tool *tev; |
| 68 |
struct axis_replacement axes[] = { |
| 69 |
{ ABS_DISTANCE, 10 }, |
| 70 |
{ ABS_PRESSURE, 0 }, |
| 71 |
{ -1, -1 }, |
| 72 |
}; |
| 73 |
unsigned int button = pick_stylus_or_btn0(dev); |
| 74 |
|
| 75 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 76 |
litest_drain_events(li); |
| 77 |
|
| 78 |
litest_button_click(dev, button, true); |
| 79 |
litest_dispatch(li); |
| 80 |
|
| 81 |
event = libinput_get_event(li); |
| 82 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 83 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); |
| 84 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), |
| 85 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 86 |
libinput_event_destroy(event); |
| 87 |
litest_assert_empty_queue(li); |
| 88 |
|
| 89 |
litest_button_click(dev, button, false); |
| 90 |
litest_dispatch(li); |
| 91 |
|
| 92 |
event = libinput_get_event(li); |
| 93 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 94 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); |
| 95 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), |
| 96 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 97 |
libinput_event_destroy(event); |
| 98 |
litest_assert_empty_queue(li); |
| 99 |
} |
| 100 |
END_TEST |
| 101 |
|
| 102 |
START_TEST(button_seat_count) |
| 103 |
{ |
| 104 |
struct litest_device *dev = litest_current_device(); |
| 105 |
struct libinput *li = dev->libinput; |
| 106 |
struct libinput_event *event; |
| 107 |
struct libinput_event_tablet_tool *tev; |
| 108 |
struct litest_device *dev2 = NULL; |
| 109 |
struct axis_replacement axes[] = { |
| 110 |
{ ABS_DISTANCE, 10 }, |
| 111 |
{ ABS_PRESSURE, 0 }, |
| 112 |
{ -1, -1 }, |
| 113 |
}; |
| 114 |
unsigned int button = pick_stylus_or_btn0(dev); |
| 115 |
|
| 116 |
switch (button) { |
| 117 |
case BTN_STYLUS: |
| 118 |
dev2 = litest_add_device(li, LITEST_WACOM_CINTIQ_13HDT_PEN); |
| 119 |
break; |
| 120 |
case BTN_0: |
| 121 |
dev2 = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM); |
| 122 |
break; |
| 123 |
default: |
| 124 |
litest_abort_msg("Invalid button code"); |
| 125 |
} |
| 126 |
|
| 127 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 128 |
litest_tablet_proximity_in(dev2, 10, 10, axes); |
| 129 |
litest_drain_events(li); |
| 130 |
|
| 131 |
litest_button_click(dev, button, true); |
| 132 |
litest_button_click(dev2, button, true); |
| 133 |
litest_dispatch(li); |
| 134 |
|
| 135 |
event = libinput_get_event(li); |
| 136 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 137 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); |
| 138 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), |
| 139 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 140 |
litest_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 1U); |
| 141 |
libinput_event_destroy(event); |
| 142 |
|
| 143 |
event = libinput_get_event(li); |
| 144 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 145 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); |
| 146 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), |
| 147 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 148 |
litest_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 2U); |
| 149 |
libinput_event_destroy(event); |
| 150 |
|
| 151 |
litest_assert_empty_queue(li); |
| 152 |
|
| 153 |
litest_button_click(dev2, button, false); |
| 154 |
litest_button_click(dev, button, false); |
| 155 |
litest_dispatch(li); |
| 156 |
|
| 157 |
event = libinput_get_event(li); |
| 158 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 159 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), |
| 160 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 161 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); |
| 162 |
litest_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 1U); |
| 163 |
libinput_event_destroy(event); |
| 164 |
|
| 165 |
event = libinput_get_event(li); |
| 166 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 167 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), |
| 168 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 169 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); |
| 170 |
litest_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 0U); |
| 171 |
libinput_event_destroy(event); |
| 172 |
litest_assert_empty_queue(li); |
| 173 |
|
| 174 |
litest_device_destroy(dev2); |
| 175 |
} |
| 176 |
END_TEST |
| 177 |
|
| 178 |
START_TEST(button_up_on_delete) |
| 179 |
{ |
| 180 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 181 |
struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); |
| 182 |
struct libevdev *evdev = libevdev_new(); |
| 183 |
unsigned int code; |
| 184 |
|
| 185 |
litest_tablet_proximity_in(dev, 10, 10, NULL); |
| 186 |
litest_drain_events(li); |
| 187 |
|
| 188 |
for (code = BTN_LEFT; code <= BTN_TASK; code++) { |
| 189 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, code)) |
| 190 |
continue; |
| 191 |
|
| 192 |
libevdev_enable_event_code(evdev, EV_KEY, code, NULL); |
| 193 |
litest_event(dev, EV_KEY, code, 1); |
| 194 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 195 |
litest_dispatch(li); |
| 196 |
} |
| 197 |
|
| 198 |
litest_drain_events(li); |
| 199 |
litest_device_destroy(dev); |
| 200 |
litest_dispatch(li); |
| 201 |
|
| 202 |
for (code = BTN_LEFT; code <= BTN_TASK; code++) { |
| 203 |
if (!libevdev_has_event_code(evdev, EV_KEY, code)) |
| 204 |
continue; |
| 205 |
|
| 206 |
litest_assert_tablet_button_event(li, |
| 207 |
code, |
| 208 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 209 |
} |
| 210 |
|
| 211 |
litest_assert_tablet_proximity_event(li, |
| 212 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 213 |
libevdev_free(evdev); |
| 214 |
} |
| 215 |
END_TEST |
| 216 |
|
| 217 |
START_TEST(tip_down_up) |
| 218 |
{ |
| 219 |
struct litest_device *dev = litest_current_device(); |
| 220 |
struct libinput *li = dev->libinput; |
| 221 |
struct libinput_event *event; |
| 222 |
struct libinput_event_tablet_tool *tablet_event; |
| 223 |
struct axis_replacement axes[] = { |
| 224 |
{ ABS_DISTANCE, 10 }, |
| 225 |
{ ABS_PRESSURE, 0 }, |
| 226 |
{ -1, -1 }, |
| 227 |
}; |
| 228 |
|
| 229 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 230 |
litest_drain_events(li); |
| 231 |
|
| 232 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 233 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 234 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 235 |
|
| 236 |
litest_dispatch(li); |
| 237 |
|
| 238 |
event = libinput_get_event(li); |
| 239 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 240 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 241 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 242 |
libinput_event_destroy(event); |
| 243 |
litest_assert_empty_queue(li); |
| 244 |
|
| 245 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 246 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 247 |
litest_tablet_tip_up(dev, 10, 10, axes); |
| 248 |
|
| 249 |
litest_dispatch(li); |
| 250 |
event = libinput_get_event(li); |
| 251 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 252 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 253 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 254 |
libinput_event_destroy(event); |
| 255 |
|
| 256 |
litest_assert_empty_queue(li); |
| 257 |
} |
| 258 |
END_TEST |
| 259 |
|
| 260 |
START_TEST(tip_down_up_eraser) |
| 261 |
{ |
| 262 |
struct litest_device *dev = litest_current_device(); |
| 263 |
struct libinput *li = dev->libinput; |
| 264 |
struct libinput_event *event; |
| 265 |
struct libinput_event_tablet_tool *tablet_event; |
| 266 |
struct libinput_tablet_tool *tool; |
| 267 |
struct axis_replacement axes[] = { |
| 268 |
{ ABS_DISTANCE, 10 }, |
| 269 |
{ ABS_PRESSURE, 0 }, |
| 270 |
{ -1, -1 }, |
| 271 |
}; |
| 272 |
|
| 273 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) |
| 274 |
return LITEST_NOT_APPLICABLE; |
| 275 |
|
| 276 |
litest_tablet_set_tool_type(dev, BTN_TOOL_RUBBER); |
| 277 |
|
| 278 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 279 |
litest_drain_events(li); |
| 280 |
|
| 281 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 282 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 283 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 284 |
|
| 285 |
litest_dispatch(li); |
| 286 |
|
| 287 |
event = libinput_get_event(li); |
| 288 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 289 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 290 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 291 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 292 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 293 |
LIBINPUT_TABLET_TOOL_TYPE_ERASER); |
| 294 |
libinput_event_destroy(event); |
| 295 |
litest_assert_empty_queue(li); |
| 296 |
|
| 297 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 298 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 299 |
litest_tablet_tip_up(dev, 10, 10, axes); |
| 300 |
|
| 301 |
litest_dispatch(li); |
| 302 |
event = libinput_get_event(li); |
| 303 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 304 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 305 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 306 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 307 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 308 |
LIBINPUT_TABLET_TOOL_TYPE_ERASER); |
| 309 |
libinput_event_destroy(event); |
| 310 |
|
| 311 |
litest_assert_empty_queue(li); |
| 312 |
} |
| 313 |
END_TEST |
| 314 |
|
| 315 |
START_TEST(tip_down_prox_in) |
| 316 |
{ |
| 317 |
struct litest_device *dev = litest_current_device(); |
| 318 |
struct libinput *li = dev->libinput; |
| 319 |
struct libinput_event *event; |
| 320 |
struct libinput_event_tablet_tool *tablet_event; |
| 321 |
struct axis_replacement axes[] = { |
| 322 |
{ ABS_DISTANCE, 0 }, |
| 323 |
{ ABS_PRESSURE, 30 }, |
| 324 |
{ -1, -1 }, |
| 325 |
}; |
| 326 |
|
| 327 |
litest_drain_events(li); |
| 328 |
|
| 329 |
litest_with_event_frame(dev) { |
| 330 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 331 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 332 |
} |
| 333 |
|
| 334 |
litest_dispatch(li); |
| 335 |
event = libinput_get_event(li); |
| 336 |
tablet_event = |
| 337 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 338 |
litest_assert_enum_eq( |
| 339 |
libinput_event_tablet_tool_get_proximity_state(tablet_event), |
| 340 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 341 |
libinput_event_destroy(event); |
| 342 |
|
| 343 |
event = libinput_get_event(li); |
| 344 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 345 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 346 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 347 |
libinput_event_destroy(event); |
| 348 |
|
| 349 |
litest_assert_empty_queue(li); |
| 350 |
} |
| 351 |
END_TEST |
| 352 |
|
| 353 |
START_TEST(tip_up_prox_out) |
| 354 |
{ |
| 355 |
struct litest_device *dev = litest_current_device(); |
| 356 |
struct libinput *li = dev->libinput; |
| 357 |
struct libinput_event *event; |
| 358 |
struct libinput_event_tablet_tool *tablet_event; |
| 359 |
struct axis_replacement axes[] = { |
| 360 |
{ ABS_DISTANCE, 0 }, |
| 361 |
{ ABS_PRESSURE, 30 }, |
| 362 |
{ -1, -1 }, |
| 363 |
}; |
| 364 |
|
| 365 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 366 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 367 |
litest_drain_events(li); |
| 368 |
|
| 369 |
litest_axis_set_value(axes, ABS_DISTANCE, 30); |
| 370 |
|
| 371 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 372 |
litest_with_event_frame(dev) { |
| 373 |
litest_tablet_tip_up(dev, 10, 10, axes); |
| 374 |
litest_tablet_proximity_out(dev); |
| 375 |
} |
| 376 |
|
| 377 |
litest_dispatch(li); |
| 378 |
event = libinput_get_event(li); |
| 379 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 380 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 381 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 382 |
libinput_event_destroy(event); |
| 383 |
|
| 384 |
litest_timeout_tablet_proxout(li); |
| 385 |
event = libinput_get_event(li); |
| 386 |
tablet_event = |
| 387 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 388 |
litest_assert_enum_eq( |
| 389 |
libinput_event_tablet_tool_get_proximity_state(tablet_event), |
| 390 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 391 |
libinput_event_destroy(event); |
| 392 |
|
| 393 |
litest_assert_empty_queue(li); |
| 394 |
} |
| 395 |
END_TEST |
| 396 |
|
| 397 |
START_TEST(tip_up_btn_change) |
| 398 |
{ |
| 399 |
struct litest_device *dev = litest_current_device(); |
| 400 |
struct libinput *li = dev->libinput; |
| 401 |
struct libinput_event *event; |
| 402 |
struct libinput_event_tablet_tool *tablet_event; |
| 403 |
struct axis_replacement axes[] = { |
| 404 |
{ ABS_DISTANCE, 0 }, |
| 405 |
{ ABS_PRESSURE, 30 }, |
| 406 |
{ -1, -1 }, |
| 407 |
}; |
| 408 |
|
| 409 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 410 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 411 |
litest_drain_events(li); |
| 412 |
|
| 413 |
litest_axis_set_value(axes, ABS_DISTANCE, 30); |
| 414 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 415 |
litest_with_event_frame(dev) { |
| 416 |
litest_tablet_tip_up(dev, 10, 20, axes); |
| 417 |
litest_event(dev, EV_KEY, BTN_STYLUS, 1); |
| 418 |
} |
| 419 |
|
| 420 |
litest_dispatch(li); |
| 421 |
|
| 422 |
event = libinput_get_event(li); |
| 423 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 424 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 425 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 426 |
libinput_event_destroy(event); |
| 427 |
|
| 428 |
event = libinput_get_event(li); |
| 429 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 430 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), |
| 431 |
(unsigned int)BTN_STYLUS); |
| 432 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tablet_event), |
| 433 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 434 |
libinput_event_destroy(event); |
| 435 |
|
| 436 |
litest_assert_empty_queue(li); |
| 437 |
|
| 438 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 439 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 440 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 441 |
litest_drain_events(li); |
| 442 |
|
| 443 |
/* same thing with a release at tip-up */ |
| 444 |
litest_axis_set_value(axes, ABS_DISTANCE, 30); |
| 445 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 446 |
litest_with_event_frame(dev) { |
| 447 |
litest_tablet_tip_up(dev, 10, 10, axes); |
| 448 |
litest_event(dev, EV_KEY, BTN_STYLUS, 0); |
| 449 |
} |
| 450 |
|
| 451 |
litest_dispatch(li); |
| 452 |
|
| 453 |
event = libinput_get_event(li); |
| 454 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 455 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 456 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 457 |
libinput_event_destroy(event); |
| 458 |
|
| 459 |
event = libinput_get_event(li); |
| 460 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 461 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), |
| 462 |
(unsigned int)BTN_STYLUS); |
| 463 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tablet_event), |
| 464 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 465 |
libinput_event_destroy(event); |
| 466 |
|
| 467 |
litest_assert_empty_queue(li); |
| 468 |
} |
| 469 |
END_TEST |
| 470 |
|
| 471 |
START_TEST(tip_down_btn_change) |
| 472 |
{ |
| 473 |
struct litest_device *dev = litest_current_device(); |
| 474 |
struct libinput *li = dev->libinput; |
| 475 |
struct libinput_event *event; |
| 476 |
struct libinput_event_tablet_tool *tablet_event; |
| 477 |
struct axis_replacement axes[] = { |
| 478 |
{ ABS_DISTANCE, 10 }, |
| 479 |
{ ABS_PRESSURE, 0 }, |
| 480 |
{ -1, -1 }, |
| 481 |
}; |
| 482 |
|
| 483 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 484 |
litest_drain_events(li); |
| 485 |
|
| 486 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 487 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 488 |
litest_with_event_frame(dev) { |
| 489 |
litest_tablet_tip_down(dev, 10, 20, axes); |
| 490 |
litest_event(dev, EV_KEY, BTN_STYLUS, 1); |
| 491 |
} |
| 492 |
|
| 493 |
litest_dispatch(li); |
| 494 |
|
| 495 |
event = libinput_get_event(li); |
| 496 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 497 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 498 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 499 |
libinput_event_destroy(event); |
| 500 |
|
| 501 |
litest_dispatch(li); |
| 502 |
event = libinput_get_event(li); |
| 503 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 504 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), |
| 505 |
(unsigned int)BTN_STYLUS); |
| 506 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tablet_event), |
| 507 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 508 |
libinput_event_destroy(event); |
| 509 |
|
| 510 |
litest_assert_empty_queue(li); |
| 511 |
|
| 512 |
litest_axis_set_value(axes, ABS_DISTANCE, 30); |
| 513 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 514 |
litest_tablet_tip_up(dev, 10, 20, axes); |
| 515 |
litest_drain_events(li); |
| 516 |
|
| 517 |
/* same thing with a release at tip-down */ |
| 518 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 519 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 520 |
litest_with_event_frame(dev) { |
| 521 |
litest_tablet_tip_down(dev, 10, 20, axes); |
| 522 |
litest_event(dev, EV_KEY, BTN_STYLUS, 0); |
| 523 |
} |
| 524 |
|
| 525 |
litest_dispatch(li); |
| 526 |
|
| 527 |
event = libinput_get_event(li); |
| 528 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 529 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 530 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 531 |
libinput_event_destroy(event); |
| 532 |
|
| 533 |
litest_dispatch(li); |
| 534 |
event = libinput_get_event(li); |
| 535 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 536 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), |
| 537 |
(unsigned int)BTN_STYLUS); |
| 538 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tablet_event), |
| 539 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 540 |
libinput_event_destroy(event); |
| 541 |
|
| 542 |
litest_assert_empty_queue(li); |
| 543 |
} |
| 544 |
END_TEST |
| 545 |
|
| 546 |
START_TEST(tip_down_motion) |
| 547 |
{ |
| 548 |
struct litest_device *dev = litest_current_device(); |
| 549 |
struct libinput *li = dev->libinput; |
| 550 |
struct libinput_event *event; |
| 551 |
struct libinput_event_tablet_tool *tablet_event; |
| 552 |
struct axis_replacement axes[] = { |
| 553 |
{ ABS_DISTANCE, 10 }, |
| 554 |
{ ABS_PRESSURE, 0 }, |
| 555 |
{ -1, -1 }, |
| 556 |
}; |
| 557 |
double x, y, last_x, last_y; |
| 558 |
|
| 559 |
litest_drain_events(li); |
| 560 |
|
| 561 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 562 |
litest_dispatch(li); |
| 563 |
event = libinput_get_event(li); |
| 564 |
tablet_event = |
| 565 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 566 |
last_x = libinput_event_tablet_tool_get_x(tablet_event); |
| 567 |
last_y = libinput_event_tablet_tool_get_y(tablet_event); |
| 568 |
libinput_event_destroy(event); |
| 569 |
|
| 570 |
/* move x/y on tip down, make sure x/y changed */ |
| 571 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 572 |
litest_axis_set_value(axes, ABS_PRESSURE, 20); |
| 573 |
litest_tablet_tip_down(dev, 70, 70, axes); |
| 574 |
|
| 575 |
litest_dispatch(li); |
| 576 |
event = libinput_get_event(li); |
| 577 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 578 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 579 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 580 |
litest_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); |
| 581 |
litest_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); |
| 582 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 583 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 584 |
litest_assert_double_lt(last_x, x); |
| 585 |
litest_assert_double_lt(last_y, y); |
| 586 |
libinput_event_destroy(event); |
| 587 |
|
| 588 |
litest_assert_empty_queue(li); |
| 589 |
} |
| 590 |
END_TEST |
| 591 |
|
| 592 |
START_TEST(tip_up_motion) |
| 593 |
{ |
| 594 |
struct litest_device *dev = litest_current_device(); |
| 595 |
struct libinput *li = dev->libinput; |
| 596 |
struct libinput_event *event; |
| 597 |
struct libinput_event_tablet_tool *tablet_event; |
| 598 |
struct axis_replacement axes[] = { |
| 599 |
{ ABS_DISTANCE, 0 }, |
| 600 |
{ ABS_PRESSURE, 0 }, |
| 601 |
{ -1, -1 }, |
| 602 |
}; |
| 603 |
double x, y, last_x, last_y; |
| 604 |
|
| 605 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 606 |
litest_drain_events(li); |
| 607 |
|
| 608 |
litest_axis_set_value(axes, ABS_PRESSURE, 20); |
| 609 |
litest_tablet_tip_down(dev, 70, 70, axes); |
| 610 |
|
| 611 |
litest_dispatch(li); |
| 612 |
event = libinput_get_event(li); |
| 613 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 614 |
last_x = libinput_event_tablet_tool_get_x(tablet_event); |
| 615 |
last_y = libinput_event_tablet_tool_get_y(tablet_event); |
| 616 |
libinput_event_destroy(event); |
| 617 |
|
| 618 |
/* move x/y on tip up, make sure x/y changed */ |
| 619 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 620 |
litest_tablet_tip_up(dev, 40, 40, axes); |
| 621 |
|
| 622 |
litest_dispatch(li); |
| 623 |
event = libinput_get_event(li); |
| 624 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 625 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 626 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 627 |
litest_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); |
| 628 |
litest_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); |
| 629 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 630 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 631 |
litest_assert_double_ne(last_x, x); |
| 632 |
litest_assert_double_ne(last_y, y); |
| 633 |
libinput_event_destroy(event); |
| 634 |
|
| 635 |
litest_assert_empty_queue(li); |
| 636 |
} |
| 637 |
END_TEST |
| 638 |
|
| 639 |
START_TEST(tip_up_motion_one_axis) |
| 640 |
{ |
| 641 |
struct litest_device *dev = litest_current_device(); |
| 642 |
struct libinput *li = dev->libinput; |
| 643 |
struct libinput_event *event; |
| 644 |
struct libinput_event_tablet_tool *tablet_event; |
| 645 |
struct axis_replacement axes[] = { |
| 646 |
{ ABS_DISTANCE, 0 }, |
| 647 |
{ ABS_PRESSURE, 0 }, |
| 648 |
{ -1, -1 }, |
| 649 |
}; |
| 650 |
double x, y, last_x, last_y; |
| 651 |
double start_x = 20, start_y = 20; |
| 652 |
int axis = litest_test_param_get_i32(test_env->params, "axis"); |
| 653 |
|
| 654 |
switch (axis) { |
| 655 |
case ABS_X: |
| 656 |
start_x = 15; |
| 657 |
start_y = 20; |
| 658 |
break; |
| 659 |
case ABS_Y: |
| 660 |
start_x = 20; |
| 661 |
start_y = 15; |
| 662 |
break; |
| 663 |
default: |
| 664 |
litest_assert_not_reached(); |
| 665 |
} |
| 666 |
|
| 667 |
/* generate enough events to fill the history and move alonge the |
| 668 |
* current axis to avoid axis smoothing interference */ |
| 669 |
litest_tablet_proximity_in(dev, start_x, start_y, axes); |
| 670 |
litest_axis_set_value(axes, ABS_PRESSURE, 20); |
| 671 |
for (int i = 0; i < 5; i++) { |
| 672 |
litest_tablet_tip_down(dev, start_x, start_y, axes); |
| 673 |
|
| 674 |
switch (axis) { |
| 675 |
case ABS_X: |
| 676 |
start_x++; |
| 677 |
break; |
| 678 |
case ABS_Y: |
| 679 |
start_y++; |
| 680 |
break; |
| 681 |
} |
| 682 |
} |
| 683 |
litest_drain_events(li); |
| 684 |
|
| 685 |
litest_tablet_motion(dev, 20, 20, axes); |
| 686 |
litest_dispatch(li); |
| 687 |
event = libinput_get_event(li); |
| 688 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 689 |
last_x = libinput_event_tablet_tool_get_x(tablet_event); |
| 690 |
last_y = libinput_event_tablet_tool_get_y(tablet_event); |
| 691 |
libinput_event_destroy(event); |
| 692 |
|
| 693 |
/* move x on tip up, make sure x/y changed */ |
| 694 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 695 |
switch (axis) { |
| 696 |
case ABS_X: |
| 697 |
litest_tablet_tip_up(dev, 40, 20, axes); |
| 698 |
break; |
| 699 |
case ABS_Y: |
| 700 |
litest_tablet_tip_up(dev, 20, 40, axes); |
| 701 |
break; |
| 702 |
} |
| 703 |
|
| 704 |
litest_dispatch(li); |
| 705 |
event = libinput_get_event(li); |
| 706 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 707 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 708 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 709 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 710 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 711 |
|
| 712 |
switch (axis) { |
| 713 |
case ABS_X: |
| 714 |
litest_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); |
| 715 |
litest_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event)); |
| 716 |
litest_assert_double_ne(last_x, x); |
| 717 |
litest_assert_double_eq(last_y, y); |
| 718 |
break; |
| 719 |
case ABS_Y: |
| 720 |
litest_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); |
| 721 |
litest_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); |
| 722 |
litest_assert_double_eq(last_x, x); |
| 723 |
litest_assert_double_ne(last_y, y); |
| 724 |
break; |
| 725 |
} |
| 726 |
|
| 727 |
libinput_event_destroy(event); |
| 728 |
|
| 729 |
litest_assert_empty_queue(li); |
| 730 |
} |
| 731 |
END_TEST |
| 732 |
|
| 733 |
START_TEST(tip_state_proximity) |
| 734 |
{ |
| 735 |
struct litest_device *dev = litest_current_device(); |
| 736 |
struct libinput *li = dev->libinput; |
| 737 |
struct libinput_event *event; |
| 738 |
struct libinput_event_tablet_tool *tablet_event; |
| 739 |
struct axis_replacement axes[] = { |
| 740 |
{ ABS_DISTANCE, 10 }, |
| 741 |
{ ABS_PRESSURE, 0 }, |
| 742 |
{ -1, -1 }, |
| 743 |
}; |
| 744 |
|
| 745 |
litest_drain_events(li); |
| 746 |
|
| 747 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 748 |
litest_dispatch(li); |
| 749 |
|
| 750 |
event = libinput_get_event(li); |
| 751 |
tablet_event = |
| 752 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 753 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 754 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 755 |
libinput_event_destroy(event); |
| 756 |
|
| 757 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 758 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 759 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 760 |
|
| 761 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 762 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 763 |
litest_tablet_tip_up(dev, 10, 10, axes); |
| 764 |
|
| 765 |
litest_drain_events(li); |
| 766 |
|
| 767 |
litest_tablet_proximity_out(dev); |
| 768 |
litest_timeout_tablet_proxout(li); |
| 769 |
|
| 770 |
event = libinput_get_event(li); |
| 771 |
tablet_event = |
| 772 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 773 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 774 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 775 |
libinput_event_destroy(event); |
| 776 |
} |
| 777 |
END_TEST |
| 778 |
|
| 779 |
START_TEST(tip_state_axis) |
| 780 |
{ |
| 781 |
struct litest_device *dev = litest_current_device(); |
| 782 |
struct libinput *li = dev->libinput; |
| 783 |
struct libinput_event *event; |
| 784 |
struct libinput_event_tablet_tool *tablet_event; |
| 785 |
struct axis_replacement axes[] = { |
| 786 |
{ ABS_DISTANCE, 10 }, |
| 787 |
{ ABS_PRESSURE, 0 }, |
| 788 |
{ -1, -1 }, |
| 789 |
}; |
| 790 |
|
| 791 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 792 |
litest_drain_events(li); |
| 793 |
|
| 794 |
litest_tablet_motion(dev, 70, 70, axes); |
| 795 |
litest_dispatch(li); |
| 796 |
|
| 797 |
event = libinput_get_event(li); |
| 798 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 799 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 800 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 801 |
libinput_event_destroy(event); |
| 802 |
|
| 803 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 804 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 805 |
litest_tablet_tip_down(dev, 40, 40, axes); |
| 806 |
litest_drain_events(li); |
| 807 |
|
| 808 |
litest_tablet_motion(dev, 30, 30, axes); |
| 809 |
litest_dispatch(li); |
| 810 |
|
| 811 |
event = libinput_get_event(li); |
| 812 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 813 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 814 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 815 |
libinput_event_destroy(event); |
| 816 |
|
| 817 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 818 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 819 |
litest_tablet_tip_up(dev, 40, 40, axes); |
| 820 |
litest_drain_events(li); |
| 821 |
|
| 822 |
litest_tablet_motion(dev, 40, 80, axes); |
| 823 |
litest_dispatch(li); |
| 824 |
|
| 825 |
event = libinput_get_event(li); |
| 826 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 827 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 828 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 829 |
libinput_event_destroy(event); |
| 830 |
|
| 831 |
litest_assert_empty_queue(li); |
| 832 |
} |
| 833 |
END_TEST |
| 834 |
|
| 835 |
START_TEST(tip_state_button) |
| 836 |
{ |
| 837 |
struct litest_device *dev = litest_current_device(); |
| 838 |
struct libinput *li = dev->libinput; |
| 839 |
struct libinput_event *event; |
| 840 |
struct libinput_event_tablet_tool *tablet_event; |
| 841 |
struct axis_replacement axes[] = { |
| 842 |
{ ABS_DISTANCE, 10 }, |
| 843 |
{ ABS_PRESSURE, 0 }, |
| 844 |
{ -1, -1 }, |
| 845 |
}; |
| 846 |
unsigned int button = pick_stylus_or_btn0(dev); |
| 847 |
|
| 848 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 849 |
litest_drain_events(li); |
| 850 |
|
| 851 |
litest_button_click(dev, button, true); |
| 852 |
litest_dispatch(li); |
| 853 |
|
| 854 |
event = libinput_get_event(li); |
| 855 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 856 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 857 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 858 |
libinput_event_destroy(event); |
| 859 |
|
| 860 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 861 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 862 |
litest_tablet_tip_down(dev, 40, 40, axes); |
| 863 |
litest_drain_events(li); |
| 864 |
|
| 865 |
litest_button_click(dev, button, false); |
| 866 |
litest_dispatch(li); |
| 867 |
|
| 868 |
event = libinput_get_event(li); |
| 869 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 870 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 871 |
LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 872 |
libinput_event_destroy(event); |
| 873 |
|
| 874 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 875 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 876 |
litest_tablet_tip_up(dev, 40, 40, axes); |
| 877 |
litest_drain_events(li); |
| 878 |
|
| 879 |
litest_button_click(dev, button, true); |
| 880 |
litest_dispatch(li); |
| 881 |
|
| 882 |
event = libinput_get_event(li); |
| 883 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 884 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 885 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 886 |
libinput_event_destroy(event); |
| 887 |
|
| 888 |
litest_button_click(dev, button, false); |
| 889 |
litest_dispatch(li); |
| 890 |
|
| 891 |
event = libinput_get_event(li); |
| 892 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 893 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 894 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 895 |
libinput_event_destroy(event); |
| 896 |
|
| 897 |
litest_assert_empty_queue(li); |
| 898 |
} |
| 899 |
END_TEST |
| 900 |
|
| 901 |
START_TEST(tip_up_on_delete) |
| 902 |
{ |
| 903 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 904 |
struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); |
| 905 |
struct libinput_event *event; |
| 906 |
struct libinput_event_tablet_tool *tablet_event; |
| 907 |
struct axis_replacement axes[] = { |
| 908 |
{ ABS_DISTANCE, 10 }, |
| 909 |
{ ABS_PRESSURE, 0 }, |
| 910 |
{ -1, -1 }, |
| 911 |
}; |
| 912 |
|
| 913 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 914 |
litest_drain_events(li); |
| 915 |
|
| 916 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 917 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 918 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 919 |
|
| 920 |
litest_drain_events(li); |
| 921 |
litest_device_destroy(dev); |
| 922 |
litest_dispatch(li); |
| 923 |
|
| 924 |
event = libinput_get_event(li); |
| 925 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 926 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), |
| 927 |
LIBINPUT_TABLET_TOOL_TIP_UP); |
| 928 |
libinput_event_destroy(event); |
| 929 |
} |
| 930 |
END_TEST |
| 931 |
|
| 932 |
START_TEST(proximity_in_out) |
| 933 |
{ |
| 934 |
struct litest_device *dev = litest_current_device(); |
| 935 |
struct libinput *li = dev->libinput; |
| 936 |
struct libinput_event_tablet_tool *tablet_event; |
| 937 |
struct libinput_event *event; |
| 938 |
enum libinput_tablet_tool_type type; |
| 939 |
bool have_tool_update = false, have_proximity_out = false; |
| 940 |
|
| 941 |
struct axis_replacement axes[] = { |
| 942 |
{ ABS_DISTANCE, 10 }, |
| 943 |
{ ABS_PRESSURE, 0 }, |
| 944 |
{ -1, -1 }, |
| 945 |
}; |
| 946 |
|
| 947 |
litest_drain_events(li); |
| 948 |
|
| 949 |
switch (dev->which) { |
| 950 |
case LITEST_DELL_CANVAS_TOTEM: |
| 951 |
type = LIBINPUT_TABLET_TOOL_TYPE_TOTEM; |
| 952 |
break; |
| 953 |
default: |
| 954 |
type = LIBINPUT_TABLET_TOOL_TYPE_PEN; |
| 955 |
break; |
| 956 |
} |
| 957 |
|
| 958 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 959 |
litest_dispatch(li); |
| 960 |
|
| 961 |
while ((event = libinput_get_event(li))) { |
| 962 |
if (libinput_event_get_type(event) == |
| 963 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { |
| 964 |
struct libinput_tablet_tool *tool; |
| 965 |
|
| 966 |
litest_assert(!have_tool_update); |
| 967 |
have_tool_update = true; |
| 968 |
tablet_event = libinput_event_get_tablet_tool_event(event); |
| 969 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 970 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 971 |
type); |
| 972 |
} |
| 973 |
libinput_event_destroy(event); |
| 974 |
} |
| 975 |
litest_assert(have_tool_update); |
| 976 |
|
| 977 |
litest_tablet_proximity_out(dev); |
| 978 |
litest_timeout_tablet_proxout(li); |
| 979 |
|
| 980 |
while ((event = libinput_get_event(li))) { |
| 981 |
if (libinput_event_get_type(event) == |
| 982 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { |
| 983 |
struct libinput_event_tablet_tool *t = |
| 984 |
libinput_event_get_tablet_tool_event(event); |
| 985 |
|
| 986 |
if (libinput_event_tablet_tool_get_proximity_state(t) == |
| 987 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) |
| 988 |
have_proximity_out = true; |
| 989 |
} |
| 990 |
|
| 991 |
libinput_event_destroy(event); |
| 992 |
} |
| 993 |
litest_assert(have_proximity_out); |
| 994 |
|
| 995 |
/* Proximity out must not emit axis events */ |
| 996 |
litest_assert_empty_queue(li); |
| 997 |
} |
| 998 |
END_TEST |
| 999 |
|
| 1000 |
START_TEST(proximity_in_button_down) |
| 1001 |
{ |
| 1002 |
struct litest_device *dev = litest_current_device(); |
| 1003 |
struct libinput *li = dev->libinput; |
| 1004 |
struct axis_replacement axes[] = { |
| 1005 |
{ ABS_DISTANCE, 10 }, |
| 1006 |
{ ABS_PRESSURE, 0 }, |
| 1007 |
{ -1, -1 }, |
| 1008 |
}; |
| 1009 |
unsigned int button = pick_stylus_or_btn0(dev); |
| 1010 |
|
| 1011 |
litest_drain_events(li); |
| 1012 |
|
| 1013 |
litest_with_event_frame(dev) { |
| 1014 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1015 |
litest_event(dev, EV_KEY, button, 1); |
| 1016 |
} |
| 1017 |
litest_dispatch(li); |
| 1018 |
|
| 1019 |
litest_assert_tablet_proximity_event(li, |
| 1020 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 1021 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 1022 |
litest_assert_tablet_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); |
| 1023 |
litest_assert_empty_queue(li); |
| 1024 |
} |
| 1025 |
END_TEST |
| 1026 |
|
| 1027 |
START_TEST(proximity_out_button_up) |
| 1028 |
{ |
| 1029 |
struct litest_device *dev = litest_current_device(); |
| 1030 |
struct libinput *li = dev->libinput; |
| 1031 |
struct axis_replacement axes[] = { |
| 1032 |
{ ABS_DISTANCE, 10 }, |
| 1033 |
{ ABS_PRESSURE, 0 }, |
| 1034 |
{ -1, -1 }, |
| 1035 |
}; |
| 1036 |
unsigned int button = pick_stylus_or_btn0(dev); |
| 1037 |
|
| 1038 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1039 |
|
| 1040 |
litest_button_click(dev, button, true); |
| 1041 |
litest_drain_events(li); |
| 1042 |
|
| 1043 |
litest_with_event_frame(dev) { |
| 1044 |
litest_tablet_proximity_out(dev); |
| 1045 |
litest_event(dev, EV_KEY, button, 0); |
| 1046 |
} |
| 1047 |
litest_timeout_tablet_proxout(li); |
| 1048 |
|
| 1049 |
litest_assert_tablet_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); |
| 1050 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 1051 |
litest_assert_tablet_proximity_event(li, |
| 1052 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1053 |
litest_assert_empty_queue(li); |
| 1054 |
} |
| 1055 |
END_TEST |
| 1056 |
|
| 1057 |
START_TEST(proximity_out_clear_buttons) |
| 1058 |
{ |
| 1059 |
struct litest_device *dev = litest_current_device(); |
| 1060 |
struct libinput *li = dev->libinput; |
| 1061 |
struct libinput_event_tablet_tool *tablet_event; |
| 1062 |
struct libinput_event *event; |
| 1063 |
struct axis_replacement axes[] = { |
| 1064 |
{ ABS_DISTANCE, 10 }, |
| 1065 |
{ ABS_PRESSURE, 0 }, |
| 1066 |
{ -1, -1 }, |
| 1067 |
}; |
| 1068 |
uint32_t stylus_buttons[] = { BTN_STYLUS, BTN_STYLUS2, BTN_STYLUS3 }; |
| 1069 |
bool have_proximity = false; |
| 1070 |
double x = 50, y = 50; |
| 1071 |
|
| 1072 |
litest_drain_events(li); |
| 1073 |
|
| 1074 |
/* Test that proximity out events send button releases for any currently |
| 1075 |
* pressed stylus buttons |
| 1076 |
*/ |
| 1077 |
ARRAY_FOR_EACH(stylus_buttons, button) { |
| 1078 |
bool button_released = false; |
| 1079 |
uint32_t event_button = 0; |
| 1080 |
enum libinput_button_state state; |
| 1081 |
|
| 1082 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, *button)) |
| 1083 |
continue; |
| 1084 |
|
| 1085 |
litest_tablet_proximity_in(dev, x++, y++, axes); |
| 1086 |
litest_drain_events(li); |
| 1087 |
|
| 1088 |
litest_event(dev, EV_KEY, *button, 1); |
| 1089 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1090 |
litest_tablet_proximity_out(dev); |
| 1091 |
litest_timeout_tablet_proxout(li); |
| 1092 |
|
| 1093 |
event = libinput_get_event(li); |
| 1094 |
litest_assert_notnull(event); |
| 1095 |
do { |
| 1096 |
tablet_event = libinput_event_get_tablet_tool_event(event); |
| 1097 |
|
| 1098 |
if (libinput_event_get_type(event) == |
| 1099 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { |
| 1100 |
have_proximity = true; |
| 1101 |
libinput_event_destroy(event); |
| 1102 |
break; |
| 1103 |
} |
| 1104 |
|
| 1105 |
if (libinput_event_get_type(event) == |
| 1106 |
LIBINPUT_EVENT_TABLET_TOOL_BUTTON) { |
| 1107 |
|
| 1108 |
event_button = libinput_event_tablet_tool_get_button( |
| 1109 |
tablet_event); |
| 1110 |
state = libinput_event_tablet_tool_get_button_state( |
| 1111 |
tablet_event); |
| 1112 |
|
| 1113 |
if (event_button == *button && |
| 1114 |
state == LIBINPUT_BUTTON_STATE_RELEASED) |
| 1115 |
button_released = true; |
| 1116 |
} |
| 1117 |
|
| 1118 |
libinput_event_destroy(event); |
| 1119 |
} while ((event = libinput_get_event(li))); |
| 1120 |
|
| 1121 |
litest_assert_msg(button_released, |
| 1122 |
"Button %s (%d) was not released.", |
| 1123 |
libevdev_event_code_get_name(EV_KEY, *button), |
| 1124 |
event_button); |
| 1125 |
litest_assert(have_proximity); |
| 1126 |
litest_assert_empty_queue(li); |
| 1127 |
} |
| 1128 |
} |
| 1129 |
END_TEST |
| 1130 |
|
| 1131 |
START_TEST(proximity_has_axes) |
| 1132 |
{ |
| 1133 |
struct litest_device *dev = litest_current_device(); |
| 1134 |
struct libinput *li = dev->libinput; |
| 1135 |
struct libinput_event_tablet_tool *tablet_event; |
| 1136 |
struct libinput_event *event; |
| 1137 |
struct libinput_tablet_tool *tool; |
| 1138 |
double x, y, distance; |
| 1139 |
double last_x, last_y, last_distance = 0.0, last_tx = 0.0, last_ty = 0.0; |
| 1140 |
|
| 1141 |
struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, |
| 1142 |
{ ABS_PRESSURE, 0 }, |
| 1143 |
{ ABS_TILT_X, 10 }, |
| 1144 |
{ ABS_TILT_Y, 10 }, |
| 1145 |
{ -1, -1 } }; |
| 1146 |
|
| 1147 |
litest_drain_events(li); |
| 1148 |
|
| 1149 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1150 |
litest_dispatch(li); |
| 1151 |
|
| 1152 |
event = libinput_get_event(li); |
| 1153 |
tablet_event = |
| 1154 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 1155 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 1156 |
|
| 1157 |
litest_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); |
| 1158 |
litest_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); |
| 1159 |
|
| 1160 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 1161 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 1162 |
|
| 1163 |
litest_assert_double_ne(x, 0); |
| 1164 |
litest_assert_double_ne(y, 0); |
| 1165 |
|
| 1166 |
if (libinput_tablet_tool_has_distance(tool)) { |
| 1167 |
litest_assert( |
| 1168 |
libinput_event_tablet_tool_distance_has_changed(tablet_event)); |
| 1169 |
|
| 1170 |
distance = libinput_event_tablet_tool_get_distance(tablet_event); |
| 1171 |
litest_assert_double_ne(distance, 0); |
| 1172 |
} |
| 1173 |
|
| 1174 |
if (libinput_tablet_tool_has_tilt(tool)) { |
| 1175 |
litest_assert( |
| 1176 |
libinput_event_tablet_tool_tilt_x_has_changed(tablet_event)); |
| 1177 |
litest_assert( |
| 1178 |
libinput_event_tablet_tool_tilt_y_has_changed(tablet_event)); |
| 1179 |
|
| 1180 |
x = libinput_event_tablet_tool_get_tilt_x(tablet_event); |
| 1181 |
y = libinput_event_tablet_tool_get_tilt_y(tablet_event); |
| 1182 |
|
| 1183 |
litest_assert_double_ne(x, 0); |
| 1184 |
litest_assert_double_ne(y, 0); |
| 1185 |
} |
| 1186 |
|
| 1187 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 1188 |
|
| 1189 |
litest_assert_empty_queue(li); |
| 1190 |
libinput_event_destroy(event); |
| 1191 |
|
| 1192 |
litest_axis_set_value(axes, ABS_DISTANCE, 20); |
| 1193 |
litest_axis_set_value(axes, ABS_TILT_X, 15); |
| 1194 |
litest_axis_set_value(axes, ABS_TILT_Y, 25); |
| 1195 |
|
| 1196 |
/* work around axis smoothing */ |
| 1197 |
litest_tablet_motion(dev, 20, 30, axes); |
| 1198 |
litest_tablet_motion(dev, 20, 29, axes); |
| 1199 |
litest_tablet_motion(dev, 20, 31, axes); |
| 1200 |
litest_drain_events(li); |
| 1201 |
|
| 1202 |
litest_tablet_motion(dev, 20, 30, axes); |
| 1203 |
litest_dispatch(li); |
| 1204 |
event = libinput_get_event(li); |
| 1205 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 1206 |
|
| 1207 |
last_x = libinput_event_tablet_tool_get_x(tablet_event); |
| 1208 |
last_y = libinput_event_tablet_tool_get_y(tablet_event); |
| 1209 |
if (libinput_tablet_tool_has_distance(tool)) |
| 1210 |
last_distance = libinput_event_tablet_tool_get_distance(tablet_event); |
| 1211 |
if (libinput_tablet_tool_has_tilt(tool)) { |
| 1212 |
last_tx = libinput_event_tablet_tool_get_tilt_x(tablet_event); |
| 1213 |
last_ty = libinput_event_tablet_tool_get_tilt_y(tablet_event); |
| 1214 |
} |
| 1215 |
|
| 1216 |
libinput_event_destroy(event); |
| 1217 |
|
| 1218 |
/* Make sure that the axes are still present on proximity out */ |
| 1219 |
litest_tablet_proximity_out(dev); |
| 1220 |
litest_timeout_tablet_proxout(li); |
| 1221 |
|
| 1222 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 1223 |
|
| 1224 |
event = libinput_get_event(li); |
| 1225 |
tablet_event = |
| 1226 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 1227 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 1228 |
|
| 1229 |
litest_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); |
| 1230 |
litest_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event)); |
| 1231 |
|
| 1232 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 1233 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 1234 |
litest_assert_double_ge(x, last_x - 1); |
| 1235 |
litest_assert_double_le(x, last_x + 1); |
| 1236 |
litest_assert_double_ge(y, last_y - 1); |
| 1237 |
litest_assert_double_le(y, last_y + 1); |
| 1238 |
|
| 1239 |
if (libinput_tablet_tool_has_distance(tool)) { |
| 1240 |
litest_assert( |
| 1241 |
!libinput_event_tablet_tool_distance_has_changed(tablet_event)); |
| 1242 |
|
| 1243 |
distance = libinput_event_tablet_tool_get_distance(tablet_event); |
| 1244 |
litest_assert_double_eq(distance, last_distance); |
| 1245 |
} |
| 1246 |
|
| 1247 |
if (libinput_tablet_tool_has_tilt(tool)) { |
| 1248 |
litest_assert( |
| 1249 |
!libinput_event_tablet_tool_tilt_x_has_changed(tablet_event)); |
| 1250 |
litest_assert( |
| 1251 |
!libinput_event_tablet_tool_tilt_y_has_changed(tablet_event)); |
| 1252 |
|
| 1253 |
x = libinput_event_tablet_tool_get_tilt_x(tablet_event); |
| 1254 |
y = libinput_event_tablet_tool_get_tilt_y(tablet_event); |
| 1255 |
|
| 1256 |
litest_assert_double_eq(x, last_tx); |
| 1257 |
litest_assert_double_eq(y, last_ty); |
| 1258 |
} |
| 1259 |
|
| 1260 |
litest_assert_empty_queue(li); |
| 1261 |
libinput_event_destroy(event); |
| 1262 |
} |
| 1263 |
END_TEST |
| 1264 |
|
| 1265 |
START_TEST(proximity_range_enter) |
| 1266 |
{ |
| 1267 |
struct litest_device *dev = litest_current_device(); |
| 1268 |
struct libinput *li = dev->libinput; |
| 1269 |
struct axis_replacement axes[] = { |
| 1270 |
{ ABS_DISTANCE, 90 }, |
| 1271 |
{ -1, -1 }, |
| 1272 |
}; |
| 1273 |
|
| 1274 |
litest_drain_events(li); |
| 1275 |
|
| 1276 |
litest_with_event_frame(dev) { |
| 1277 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1278 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1279 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 1280 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1281 |
} |
| 1282 |
litest_assert_empty_queue(li); |
| 1283 |
|
| 1284 |
litest_axis_set_value(axes, ABS_DISTANCE, 20); |
| 1285 |
litest_tablet_motion(dev, 10, 10, axes); |
| 1286 |
litest_dispatch(li); |
| 1287 |
|
| 1288 |
litest_assert_tablet_proximity_event(li, |
| 1289 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 1290 |
|
| 1291 |
litest_axis_set_value(axes, ABS_DISTANCE, 90); |
| 1292 |
litest_tablet_motion(dev, 10, 10, axes); |
| 1293 |
litest_dispatch(li); |
| 1294 |
litest_assert_tablet_proximity_event(li, |
| 1295 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1296 |
|
| 1297 |
litest_with_event_frame(dev) { |
| 1298 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1299 |
litest_tablet_proximity_out(dev); |
| 1300 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); |
| 1301 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1302 |
} |
| 1303 |
litest_assert_empty_queue(li); |
| 1304 |
} |
| 1305 |
END_TEST |
| 1306 |
|
| 1307 |
START_TEST(proximity_range_in_out) |
| 1308 |
{ |
| 1309 |
struct litest_device *dev = litest_current_device(); |
| 1310 |
struct libinput *li = dev->libinput; |
| 1311 |
struct axis_replacement axes[] = { |
| 1312 |
{ ABS_DISTANCE, 20 }, |
| 1313 |
{ -1, -1 }, |
| 1314 |
}; |
| 1315 |
|
| 1316 |
litest_drain_events(li); |
| 1317 |
|
| 1318 |
litest_with_event_frame(dev) { |
| 1319 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1320 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1321 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 1322 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1323 |
} |
| 1324 |
litest_dispatch(li); |
| 1325 |
litest_assert_tablet_proximity_event(li, |
| 1326 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 1327 |
|
| 1328 |
litest_axis_set_value(axes, ABS_DISTANCE, 90); |
| 1329 |
litest_tablet_motion(dev, 10, 10, axes); |
| 1330 |
litest_dispatch(li); |
| 1331 |
litest_assert_tablet_proximity_event(li, |
| 1332 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1333 |
|
| 1334 |
litest_tablet_motion(dev, 30, 30, axes); |
| 1335 |
litest_assert_empty_queue(li); |
| 1336 |
|
| 1337 |
litest_axis_set_value(axes, ABS_DISTANCE, 20); |
| 1338 |
litest_tablet_motion(dev, 10, 10, axes); |
| 1339 |
litest_dispatch(li); |
| 1340 |
litest_assert_tablet_proximity_event(li, |
| 1341 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 1342 |
|
| 1343 |
litest_with_event_frame(dev) { |
| 1344 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1345 |
litest_tablet_proximity_out(dev); |
| 1346 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); |
| 1347 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1348 |
} |
| 1349 |
litest_timeout_tablet_proxout(li); |
| 1350 |
litest_assert_tablet_proximity_event(li, |
| 1351 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1352 |
litest_assert_empty_queue(li); |
| 1353 |
} |
| 1354 |
END_TEST |
| 1355 |
|
| 1356 |
START_TEST(proximity_range_button_click) |
| 1357 |
{ |
| 1358 |
struct litest_device *dev = litest_current_device(); |
| 1359 |
struct libinput *li = dev->libinput; |
| 1360 |
struct axis_replacement axes[] = { |
| 1361 |
{ ABS_DISTANCE, 90 }, |
| 1362 |
{ -1, -1 }, |
| 1363 |
}; |
| 1364 |
|
| 1365 |
litest_drain_events(li); |
| 1366 |
|
| 1367 |
litest_with_event_frame(dev) { |
| 1368 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1369 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1370 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 1371 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1372 |
} |
| 1373 |
litest_drain_events(li); |
| 1374 |
|
| 1375 |
litest_event(dev, EV_KEY, BTN_STYLUS, 1); |
| 1376 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1377 |
litest_dispatch(li); |
| 1378 |
litest_event(dev, EV_KEY, BTN_STYLUS, 0); |
| 1379 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1380 |
litest_dispatch(li); |
| 1381 |
|
| 1382 |
litest_with_event_frame(dev) { |
| 1383 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1384 |
litest_tablet_proximity_out(dev); |
| 1385 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); |
| 1386 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1387 |
} |
| 1388 |
litest_timeout_tablet_proxout(li); |
| 1389 |
litest_assert_empty_queue(li); |
| 1390 |
} |
| 1391 |
END_TEST |
| 1392 |
|
| 1393 |
START_TEST(proximity_range_button_press) |
| 1394 |
{ |
| 1395 |
struct litest_device *dev = litest_current_device(); |
| 1396 |
struct libinput *li = dev->libinput; |
| 1397 |
struct axis_replacement axes[] = { |
| 1398 |
{ ABS_DISTANCE, 20 }, |
| 1399 |
{ -1, -1 }, |
| 1400 |
}; |
| 1401 |
|
| 1402 |
litest_with_event_frame(dev) { |
| 1403 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1404 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1405 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 1406 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1407 |
} |
| 1408 |
litest_drain_events(li); |
| 1409 |
|
| 1410 |
litest_event(dev, EV_KEY, BTN_STYLUS, 1); |
| 1411 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1412 |
litest_dispatch(li); |
| 1413 |
|
| 1414 |
litest_assert_tablet_button_event(li, |
| 1415 |
BTN_STYLUS, |
| 1416 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 1417 |
|
| 1418 |
litest_axis_set_value(axes, ABS_DISTANCE, 90); |
| 1419 |
litest_tablet_motion(dev, 15, 15, axes); |
| 1420 |
litest_dispatch(li); |
| 1421 |
|
| 1422 |
/* expect fake button release */ |
| 1423 |
litest_assert_tablet_button_event(li, |
| 1424 |
BTN_STYLUS, |
| 1425 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 1426 |
litest_assert_tablet_proximity_event(li, |
| 1427 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1428 |
|
| 1429 |
litest_event(dev, EV_KEY, BTN_STYLUS, 0); |
| 1430 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1431 |
litest_dispatch(li); |
| 1432 |
|
| 1433 |
litest_with_event_frame(dev) { |
| 1434 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1435 |
litest_tablet_proximity_out(dev); |
| 1436 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); |
| 1437 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1438 |
} |
| 1439 |
litest_timeout_tablet_proxout(li); |
| 1440 |
litest_assert_empty_queue(li); |
| 1441 |
} |
| 1442 |
END_TEST |
| 1443 |
|
| 1444 |
START_TEST(proximity_range_button_release) |
| 1445 |
{ |
| 1446 |
struct litest_device *dev = litest_current_device(); |
| 1447 |
struct libinput *li = dev->libinput; |
| 1448 |
struct axis_replacement axes[] = { |
| 1449 |
{ ABS_DISTANCE, 90 }, |
| 1450 |
{ -1, -1 }, |
| 1451 |
}; |
| 1452 |
|
| 1453 |
litest_with_event_frame(dev) { |
| 1454 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1455 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1456 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 1457 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1458 |
} |
| 1459 |
litest_drain_events(li); |
| 1460 |
|
| 1461 |
litest_event(dev, EV_KEY, BTN_STYLUS, 1); |
| 1462 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1463 |
litest_assert_empty_queue(li); |
| 1464 |
|
| 1465 |
litest_axis_set_value(axes, ABS_DISTANCE, 20); |
| 1466 |
litest_tablet_motion(dev, 15, 15, axes); |
| 1467 |
litest_dispatch(li); |
| 1468 |
|
| 1469 |
litest_assert_tablet_proximity_event(li, |
| 1470 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 1471 |
/* expect fake button press */ |
| 1472 |
litest_assert_tablet_button_event(li, |
| 1473 |
BTN_STYLUS, |
| 1474 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 1475 |
litest_assert_empty_queue(li); |
| 1476 |
|
| 1477 |
litest_event(dev, EV_KEY, BTN_STYLUS, 0); |
| 1478 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1479 |
litest_dispatch(li); |
| 1480 |
litest_assert_tablet_button_event(li, |
| 1481 |
BTN_STYLUS, |
| 1482 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 1483 |
|
| 1484 |
litest_with_event_frame(dev) { |
| 1485 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1486 |
litest_tablet_proximity_out(dev); |
| 1487 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); |
| 1488 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 1489 |
} |
| 1490 |
litest_timeout_tablet_proxout(li); |
| 1491 |
litest_assert_tablet_proximity_event(li, |
| 1492 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1493 |
} |
| 1494 |
END_TEST |
| 1495 |
|
| 1496 |
START_TEST(proximity_out_slow_event) |
| 1497 |
{ |
| 1498 |
struct litest_device *dev = litest_current_device(); |
| 1499 |
struct libinput *li = dev->libinput; |
| 1500 |
struct axis_replacement axes[] = { |
| 1501 |
{ ABS_DISTANCE, 90 }, |
| 1502 |
{ -1, -1 }, |
| 1503 |
}; |
| 1504 |
|
| 1505 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1506 |
litest_tablet_motion(dev, 12, 12, axes); |
| 1507 |
litest_drain_events(li); |
| 1508 |
|
| 1509 |
litest_timeout_tablet_proxout(li); |
| 1510 |
|
| 1511 |
/* The forced prox out */ |
| 1512 |
litest_assert_tablet_proximity_event(li, |
| 1513 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1514 |
litest_assert_empty_queue(li); |
| 1515 |
|
| 1516 |
litest_tablet_proximity_out(dev); |
| 1517 |
litest_assert_empty_queue(li); |
| 1518 |
} |
| 1519 |
END_TEST |
| 1520 |
|
| 1521 |
START_TEST(proximity_out_not_during_contact) |
| 1522 |
{ |
| 1523 |
struct litest_device *dev = litest_current_device(); |
| 1524 |
struct libinput *li = dev->libinput; |
| 1525 |
struct axis_replacement axes[] = { |
| 1526 |
{ ABS_DISTANCE, 0 }, |
| 1527 |
{ ABS_PRESSURE, 10 }, |
| 1528 |
{ -1, -1 }, |
| 1529 |
}; |
| 1530 |
|
| 1531 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1532 |
litest_tablet_tip_down(dev, 10, 10, axes); |
| 1533 |
litest_tablet_motion(dev, 12, 12, axes); |
| 1534 |
litest_drain_events(li); |
| 1535 |
|
| 1536 |
litest_timeout_tablet_proxout(li); |
| 1537 |
|
| 1538 |
/* No forced proxout yet */ |
| 1539 |
litest_assert_empty_queue(li); |
| 1540 |
|
| 1541 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 1542 |
litest_tablet_motion(dev, 14, 14, axes); |
| 1543 |
litest_tablet_tip_up(dev, 14, 14, axes); |
| 1544 |
litest_drain_events(li); |
| 1545 |
|
| 1546 |
litest_timeout_tablet_proxout(li); |
| 1547 |
|
| 1548 |
/* The forced prox out */ |
| 1549 |
litest_assert_tablet_proximity_event(li, |
| 1550 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1551 |
|
| 1552 |
litest_tablet_proximity_out(dev); |
| 1553 |
litest_assert_empty_queue(li); |
| 1554 |
} |
| 1555 |
END_TEST |
| 1556 |
|
| 1557 |
START_TEST(proximity_out_not_during_buttonpress) |
| 1558 |
{ |
| 1559 |
struct litest_device *dev = litest_current_device(); |
| 1560 |
struct libinput *li = dev->libinput; |
| 1561 |
struct axis_replacement axes[] = { |
| 1562 |
{ ABS_DISTANCE, 10 }, |
| 1563 |
{ ABS_PRESSURE, 0 }, |
| 1564 |
{ -1, -1 }, |
| 1565 |
}; |
| 1566 |
|
| 1567 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1568 |
litest_tablet_motion(dev, 12, 12, axes); |
| 1569 |
litest_drain_events(li); |
| 1570 |
|
| 1571 |
litest_event(dev, EV_KEY, BTN_STYLUS, 1); |
| 1572 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1573 |
litest_dispatch(li); |
| 1574 |
|
| 1575 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 1576 |
|
| 1577 |
litest_timeout_tablet_proxout(li); |
| 1578 |
|
| 1579 |
/* No forced proxout yet */ |
| 1580 |
litest_assert_empty_queue(li); |
| 1581 |
|
| 1582 |
litest_event(dev, EV_KEY, BTN_STYLUS, 0); |
| 1583 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1584 |
litest_dispatch(li); |
| 1585 |
|
| 1586 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 1587 |
|
| 1588 |
litest_timeout_tablet_proxout(li); |
| 1589 |
|
| 1590 |
/* The forced prox out */ |
| 1591 |
litest_assert_tablet_proximity_event(li, |
| 1592 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1593 |
|
| 1594 |
litest_tablet_proximity_out(dev); |
| 1595 |
litest_assert_empty_queue(li); |
| 1596 |
} |
| 1597 |
END_TEST |
| 1598 |
|
| 1599 |
START_TEST(proximity_out_disables_forced) |
| 1600 |
{ |
| 1601 |
struct litest_device *dev = litest_current_device(); |
| 1602 |
struct libinput *li = dev->libinput; |
| 1603 |
struct axis_replacement axes[] = { |
| 1604 |
{ ABS_DISTANCE, 10 }, |
| 1605 |
{ ABS_PRESSURE, 0 }, |
| 1606 |
{ -1, -1 }, |
| 1607 |
}; |
| 1608 |
|
| 1609 |
/* A correct proximity out sequence from the device should disable |
| 1610 |
the forced proximity out */ |
| 1611 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1612 |
litest_tablet_proximity_out(dev); |
| 1613 |
litest_drain_events(li); |
| 1614 |
|
| 1615 |
/* expect no timeout-based prox out */ |
| 1616 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1617 |
litest_drain_events(li); |
| 1618 |
|
| 1619 |
litest_timeout_tablet_proxout(li); |
| 1620 |
|
| 1621 |
litest_assert_empty_queue(li); |
| 1622 |
litest_tablet_proximity_out(dev); |
| 1623 |
litest_assert_tablet_proximity_event(li, |
| 1624 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1625 |
litest_dispatch(li); |
| 1626 |
} |
| 1627 |
END_TEST |
| 1628 |
|
| 1629 |
START_TEST(proximity_out_disables_forced_after_forced) |
| 1630 |
{ |
| 1631 |
struct litest_device *dev = litest_current_device(); |
| 1632 |
struct libinput *li = dev->libinput; |
| 1633 |
struct axis_replacement axes[] = { |
| 1634 |
{ ABS_DISTANCE, 10 }, |
| 1635 |
{ ABS_PRESSURE, 0 }, |
| 1636 |
{ -1, -1 }, |
| 1637 |
}; |
| 1638 |
|
| 1639 |
/* A correct proximity out sequence from the device should disable |
| 1640 |
the forced proximity out, even when we had a forced prox-out */ |
| 1641 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1642 |
litest_drain_events(li); |
| 1643 |
|
| 1644 |
/* timeout-based forced prox out */ |
| 1645 |
litest_timeout_tablet_proxout(li); |
| 1646 |
litest_assert_tablet_proximity_event(li, |
| 1647 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1648 |
litest_assert_empty_queue(li); |
| 1649 |
|
| 1650 |
/* now send the real prox out (we're already in proximity out) and |
| 1651 |
* that should disable the proxout quirk */ |
| 1652 |
litest_tablet_proximity_out(dev); |
| 1653 |
litest_dispatch(li); |
| 1654 |
litest_assert_empty_queue(li); |
| 1655 |
|
| 1656 |
/* same again, but this time we expect no timeout-based prox out */ |
| 1657 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1658 |
litest_drain_events(li); |
| 1659 |
|
| 1660 |
litest_timeout_tablet_proxout(li); |
| 1661 |
|
| 1662 |
litest_assert_empty_queue(li); |
| 1663 |
litest_tablet_proximity_out(dev); |
| 1664 |
litest_assert_tablet_proximity_event(li, |
| 1665 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1666 |
litest_dispatch(li); |
| 1667 |
} |
| 1668 |
END_TEST |
| 1669 |
|
| 1670 |
START_TEST(proximity_forced_in_with_eraser_swap) |
| 1671 |
{ |
| 1672 |
struct litest_device *dev = litest_current_device(); |
| 1673 |
struct libinput *li = dev->libinput; |
| 1674 |
struct axis_replacement axes[] = { |
| 1675 |
{ ABS_DISTANCE, 10 }, |
| 1676 |
{ ABS_PRESSURE, 0 }, |
| 1677 |
{ -1, -1 }, |
| 1678 |
}; |
| 1679 |
|
| 1680 |
/* Test doesn't work with a double-tool device */ |
| 1681 |
if (dev->which == LITEST_ELAN_TABLET) |
| 1682 |
return LITEST_NOT_APPLICABLE; |
| 1683 |
|
| 1684 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) |
| 1685 |
return LITEST_NOT_APPLICABLE; |
| 1686 |
|
| 1687 |
/* https://gitlab.freedesktop.org/libinput/libinput/-/issues/1171: |
| 1688 |
* Device sends correct proximity for pen and eraser so both prox timer |
| 1689 |
* and double-tool are unregistered. Then it sends a single ABS_X event |
| 1690 |
* before an eraser proximity in - ensure that our forced proximity |
| 1691 |
* out is immediately removed. |
| 1692 |
*/ |
| 1693 |
|
| 1694 |
/* A correct proximity out sequence from the device should disable |
| 1695 |
the forced proximity out, even when we had a forced prox-out */ |
| 1696 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 1697 |
litest_tablet_proximity_out(dev); |
| 1698 |
litest_drain_events(li); |
| 1699 |
litest_timeout_tablet_proxout(li); |
| 1700 |
|
| 1701 |
/* correct eraser prox out disables forced tool plugin */ |
| 1702 |
litest_tablet_set_tool_type(dev, BTN_TOOL_RUBBER); |
| 1703 |
litest_tablet_proximity_in(dev, 12, 12, axes); |
| 1704 |
litest_tablet_proximity_out(dev); |
| 1705 |
litest_drain_events(li); |
| 1706 |
litest_timeout_tablet_proxout(li); |
| 1707 |
|
| 1708 |
litest_dispatch(li); |
| 1709 |
|
| 1710 |
litest_log_group("Expecting ABS_X to trigger a proximity event") { |
| 1711 |
/* All our tablets have this within their range so hardcoding 100 should |
| 1712 |
* be fine here. If this breaks, scale it to absinfo */ |
| 1713 |
auto abs = libevdev_get_abs_info(dev->evdev, ABS_X); |
| 1714 |
int x = absinfo_range(abs) / 3 + abs->minimum; |
| 1715 |
litest_event(dev, EV_ABS, ABS_X, x); |
| 1716 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1717 |
|
| 1718 |
litest_dispatch(li); |
| 1719 |
|
| 1720 |
_destroy_(libinput_event) *pen_in = libinput_get_event(li); |
| 1721 |
auto tev = litest_is_proximity_event( |
| 1722 |
pen_in, |
| 1723 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 1724 |
auto tool = libinput_event_tablet_tool_get_tool(tev); |
| 1725 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 1726 |
LIBINPUT_TABLET_TOOL_TYPE_PEN); |
| 1727 |
} |
| 1728 |
|
| 1729 |
litest_log_group( |
| 1730 |
"Expecting eraser prox in to trigger prox out for pen and prox in for eraser") { |
| 1731 |
litest_tablet_proximity_in(dev, 15, 15, axes); |
| 1732 |
litest_dispatch(li); |
| 1733 |
|
| 1734 |
_destroy_(libinput_event) *pen_out = libinput_get_event(li); |
| 1735 |
auto tev = litest_is_proximity_event( |
| 1736 |
pen_out, |
| 1737 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1738 |
auto tool = libinput_event_tablet_tool_get_tool(tev); |
| 1739 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 1740 |
LIBINPUT_TABLET_TOOL_TYPE_PEN); |
| 1741 |
|
| 1742 |
_destroy_(libinput_event) *eraser_in = libinput_get_event(li); |
| 1743 |
tev = litest_is_proximity_event( |
| 1744 |
eraser_in, |
| 1745 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 1746 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 1747 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 1748 |
LIBINPUT_TABLET_TOOL_TYPE_ERASER); |
| 1749 |
} |
| 1750 |
|
| 1751 |
litest_assert_empty_queue(li); |
| 1752 |
} |
| 1753 |
END_TEST |
| 1754 |
|
| 1755 |
START_TEST(proximity_out_on_delete) |
| 1756 |
{ |
| 1757 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1758 |
struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); |
| 1759 |
|
| 1760 |
litest_tablet_proximity_in(dev, 10, 10, NULL); |
| 1761 |
litest_drain_events(li); |
| 1762 |
|
| 1763 |
litest_device_destroy(dev); |
| 1764 |
litest_dispatch(li); |
| 1765 |
|
| 1766 |
litest_assert_tablet_proximity_event(li, |
| 1767 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 1768 |
} |
| 1769 |
END_TEST |
| 1770 |
|
| 1771 |
START_TEST(motion) |
| 1772 |
{ |
| 1773 |
struct litest_device *dev = litest_current_device(); |
| 1774 |
struct libinput *li = dev->libinput; |
| 1775 |
struct libinput_event_tablet_tool *tablet_event; |
| 1776 |
struct libinput_event *event; |
| 1777 |
int test_x, test_y; |
| 1778 |
double last_reported_x = 0, last_reported_y = 0; |
| 1779 |
enum libinput_event_type type; |
| 1780 |
struct axis_replacement axes[] = { |
| 1781 |
{ ABS_DISTANCE, 10 }, |
| 1782 |
{ ABS_PRESSURE, 0 }, |
| 1783 |
{ -1, -1 }, |
| 1784 |
}; |
| 1785 |
bool x_changed, y_changed; |
| 1786 |
double reported_x, reported_y; |
| 1787 |
|
| 1788 |
litest_drain_events(li); |
| 1789 |
|
| 1790 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 1791 |
litest_dispatch(li); |
| 1792 |
|
| 1793 |
event = libinput_get_event(li); |
| 1794 |
tablet_event = |
| 1795 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 1796 |
x_changed = libinput_event_tablet_tool_x_has_changed(tablet_event); |
| 1797 |
y_changed = libinput_event_tablet_tool_y_has_changed(tablet_event); |
| 1798 |
litest_assert(x_changed); |
| 1799 |
litest_assert(y_changed); |
| 1800 |
|
| 1801 |
reported_x = libinput_event_tablet_tool_get_x(tablet_event); |
| 1802 |
reported_y = libinput_event_tablet_tool_get_y(tablet_event); |
| 1803 |
|
| 1804 |
litest_assert_double_lt(reported_x, reported_y); |
| 1805 |
|
| 1806 |
last_reported_x = reported_x; |
| 1807 |
last_reported_y = reported_y; |
| 1808 |
|
| 1809 |
libinput_event_destroy(event); |
| 1810 |
|
| 1811 |
for (test_x = 10, test_y = 90; test_x <= 100; test_x += 10, test_y -= 10) { |
| 1812 |
bool x_changed, y_changed; |
| 1813 |
double reported_x, reported_y; |
| 1814 |
|
| 1815 |
litest_tablet_motion(dev, test_x, test_y, axes); |
| 1816 |
litest_dispatch(li); |
| 1817 |
|
| 1818 |
while ((event = libinput_get_event(li))) { |
| 1819 |
tablet_event = libinput_event_get_tablet_tool_event(event); |
| 1820 |
type = libinput_event_get_type(event); |
| 1821 |
|
| 1822 |
if (type == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { |
| 1823 |
x_changed = libinput_event_tablet_tool_x_has_changed( |
| 1824 |
tablet_event); |
| 1825 |
y_changed = libinput_event_tablet_tool_y_has_changed( |
| 1826 |
tablet_event); |
| 1827 |
|
| 1828 |
litest_assert(x_changed); |
| 1829 |
litest_assert(y_changed); |
| 1830 |
|
| 1831 |
reported_x = |
| 1832 |
libinput_event_tablet_tool_get_x(tablet_event); |
| 1833 |
reported_y = |
| 1834 |
libinput_event_tablet_tool_get_y(tablet_event); |
| 1835 |
|
| 1836 |
litest_assert_double_gt(reported_x, last_reported_x); |
| 1837 |
litest_assert_double_lt(reported_y, last_reported_y); |
| 1838 |
|
| 1839 |
last_reported_x = reported_x; |
| 1840 |
last_reported_y = reported_y; |
| 1841 |
} |
| 1842 |
|
| 1843 |
libinput_event_destroy(event); |
| 1844 |
} |
| 1845 |
} |
| 1846 |
} |
| 1847 |
END_TEST |
| 1848 |
|
| 1849 |
START_TEST(left_handed) |
| 1850 |
{ |
| 1851 |
#ifdef HAVE_LIBWACOM |
| 1852 |
struct litest_device *dev = litest_current_device(); |
| 1853 |
struct libinput *li = dev->libinput; |
| 1854 |
struct libinput_event *event; |
| 1855 |
struct libinput_event_tablet_tool *tablet_event; |
| 1856 |
double libinput_max_x, libinput_max_y; |
| 1857 |
double last_x = -1.0, last_y = -1.0; |
| 1858 |
double x, y; |
| 1859 |
struct axis_replacement axes[] = { |
| 1860 |
{ ABS_DISTANCE, 10 }, |
| 1861 |
{ ABS_PRESSURE, 0 }, |
| 1862 |
{ -1, -1 }, |
| 1863 |
}; |
| 1864 |
|
| 1865 |
litest_drain_events(li); |
| 1866 |
|
| 1867 |
litest_assert( |
| 1868 |
libinput_device_config_left_handed_is_available(dev->libinput_device)); |
| 1869 |
|
| 1870 |
libinput_device_get_size(dev->libinput_device, |
| 1871 |
&libinput_max_x, |
| 1872 |
&libinput_max_y); |
| 1873 |
|
| 1874 |
/* Test that left-handed mode doesn't go into effect until the tool has |
| 1875 |
* left proximity of the tablet. In order to test this, we have to bring |
| 1876 |
* the tool into proximity and make sure libinput processes the |
| 1877 |
* proximity events so that it updates it's internal tablet state, and |
| 1878 |
* then try setting it to left-handed mode. */ |
| 1879 |
litest_tablet_proximity_in(dev, 0, 100, axes); |
| 1880 |
litest_dispatch(li); |
| 1881 |
libinput_device_config_left_handed_set(dev->libinput_device, 1); |
| 1882 |
|
| 1883 |
event = libinput_get_event(li); |
| 1884 |
tablet_event = |
| 1885 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 1886 |
|
| 1887 |
last_x = libinput_event_tablet_tool_get_x(tablet_event); |
| 1888 |
last_y = libinput_event_tablet_tool_get_y(tablet_event); |
| 1889 |
|
| 1890 |
litest_assert_double_eq(last_x, 0); |
| 1891 |
litest_assert_double_eq(last_y, libinput_max_y); |
| 1892 |
|
| 1893 |
libinput_event_destroy(event); |
| 1894 |
|
| 1895 |
/* work around smoothing */ |
| 1896 |
litest_axis_set_value(axes, ABS_DISTANCE, 9); |
| 1897 |
litest_tablet_motion(dev, 100, 0, axes); |
| 1898 |
litest_axis_set_value(axes, ABS_DISTANCE, 7); |
| 1899 |
litest_tablet_motion(dev, 100, 0, axes); |
| 1900 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 1901 |
litest_tablet_motion(dev, 100, 0, axes); |
| 1902 |
litest_drain_events(li); |
| 1903 |
|
| 1904 |
litest_axis_set_value(axes, ABS_DISTANCE, 5); |
| 1905 |
litest_tablet_motion(dev, 100, 0, axes); |
| 1906 |
litest_dispatch(li); |
| 1907 |
|
| 1908 |
event = libinput_get_event(li); |
| 1909 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 1910 |
|
| 1911 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 1912 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 1913 |
|
| 1914 |
litest_assert_double_eq(x, libinput_max_x); |
| 1915 |
litest_assert_double_eq(y, 0); |
| 1916 |
|
| 1917 |
litest_assert_double_gt(x, last_x); |
| 1918 |
litest_assert_double_lt(y, last_y); |
| 1919 |
|
| 1920 |
libinput_event_destroy(event); |
| 1921 |
|
| 1922 |
litest_tablet_proximity_out(dev); |
| 1923 |
litest_drain_events(li); |
| 1924 |
litest_timeout_tablet_proxout(li); |
| 1925 |
|
| 1926 |
/* Since we've drained the events and libinput's aware the tool is out |
| 1927 |
* of proximity, it should have finally transitioned into left-handed |
| 1928 |
* mode, so the axes should be inverted once we bring it back into |
| 1929 |
* proximity */ |
| 1930 |
litest_tablet_proximity_in(dev, 0, 100, axes); |
| 1931 |
litest_dispatch(li); |
| 1932 |
|
| 1933 |
event = libinput_get_event(li); |
| 1934 |
tablet_event = |
| 1935 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 1936 |
|
| 1937 |
last_x = libinput_event_tablet_tool_get_x(tablet_event); |
| 1938 |
last_y = libinput_event_tablet_tool_get_y(tablet_event); |
| 1939 |
|
| 1940 |
litest_assert_double_eq(last_x, libinput_max_x); |
| 1941 |
litest_assert_double_eq(last_y, 0); |
| 1942 |
|
| 1943 |
libinput_event_destroy(event); |
| 1944 |
|
| 1945 |
/* work around smoothing */ |
| 1946 |
litest_axis_set_value(axes, ABS_DISTANCE, 9); |
| 1947 |
litest_tablet_motion(dev, 100, 0, axes); |
| 1948 |
litest_axis_set_value(axes, ABS_DISTANCE, 7); |
| 1949 |
litest_tablet_motion(dev, 100, 0, axes); |
| 1950 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 1951 |
litest_tablet_motion(dev, 100, 0, axes); |
| 1952 |
litest_drain_events(li); |
| 1953 |
|
| 1954 |
litest_axis_set_value(axes, ABS_DISTANCE, 5); |
| 1955 |
litest_tablet_motion(dev, 100, 0, axes); |
| 1956 |
litest_dispatch(li); |
| 1957 |
|
| 1958 |
event = libinput_get_event(li); |
| 1959 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 1960 |
|
| 1961 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 1962 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 1963 |
|
| 1964 |
litest_assert_double_eq(x, 0); |
| 1965 |
litest_assert_double_eq(y, libinput_max_y); |
| 1966 |
|
| 1967 |
litest_assert_double_lt(x, last_x); |
| 1968 |
litest_assert_double_gt(y, last_y); |
| 1969 |
|
| 1970 |
libinput_event_destroy(event); |
| 1971 |
#endif |
| 1972 |
} |
| 1973 |
END_TEST |
| 1974 |
|
| 1975 |
START_TEST(no_left_handed) |
| 1976 |
{ |
| 1977 |
struct litest_device *dev = litest_current_device(); |
| 1978 |
|
| 1979 |
/* Without libwacom we default to left-handed being available */ |
| 1980 |
#ifdef HAVE_LIBWACOM |
| 1981 |
litest_assert( |
| 1982 |
!libinput_device_config_left_handed_is_available(dev->libinput_device)); |
| 1983 |
#else |
| 1984 |
litest_assert( |
| 1985 |
libinput_device_config_left_handed_is_available(dev->libinput_device)); |
| 1986 |
#endif |
| 1987 |
} |
| 1988 |
END_TEST |
| 1989 |
|
| 1990 |
START_TEST(left_handed_tilt) |
| 1991 |
{ |
| 1992 |
#ifdef HAVE_LIBWACOM |
| 1993 |
struct litest_device *dev = litest_current_device(); |
| 1994 |
struct libinput *li = dev->libinput; |
| 1995 |
struct libinput_event *event; |
| 1996 |
struct libinput_event_tablet_tool *tev; |
| 1997 |
enum libinput_config_status status; |
| 1998 |
struct axis_replacement axes[] = { |
| 1999 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 90 }, |
| 2000 |
{ ABS_TILT_Y, 10 }, { -1, -1 }, |
| 2001 |
}; |
| 2002 |
double tx, ty; |
| 2003 |
|
| 2004 |
status = libinput_device_config_left_handed_set(dev->libinput_device, 1); |
| 2005 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 2006 |
|
| 2007 |
litest_drain_events(li); |
| 2008 |
|
| 2009 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 2010 |
litest_dispatch(li); |
| 2011 |
event = libinput_get_event(li); |
| 2012 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2013 |
tx = libinput_event_tablet_tool_get_tilt_x(tev); |
| 2014 |
ty = libinput_event_tablet_tool_get_tilt_y(tev); |
| 2015 |
|
| 2016 |
litest_assert_double_lt(tx, 0); |
| 2017 |
litest_assert_double_gt(ty, 0); |
| 2018 |
|
| 2019 |
libinput_event_destroy(event); |
| 2020 |
#endif |
| 2021 |
} |
| 2022 |
END_TEST |
| 2023 |
|
| 2024 |
static inline double |
| 2025 |
rotate_event(struct litest_device *dev, int angle_degrees) |
| 2026 |
{ |
| 2027 |
struct libinput *li = dev->libinput; |
| 2028 |
struct libinput_event *event; |
| 2029 |
struct libinput_event_tablet_tool *tev; |
| 2030 |
const struct input_absinfo *abs; |
| 2031 |
double a = (angle_degrees - 90 - 175) / 180.0 * M_PI; |
| 2032 |
double val; |
| 2033 |
int x, y; |
| 2034 |
int tilt_center_x, tilt_center_y; |
| 2035 |
|
| 2036 |
abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_X); |
| 2037 |
litest_assert_notnull(abs); |
| 2038 |
tilt_center_x = absinfo_range(abs) / 2; |
| 2039 |
|
| 2040 |
abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_Y); |
| 2041 |
litest_assert_notnull(abs); |
| 2042 |
tilt_center_y = absinfo_range(abs) / 2; |
| 2043 |
|
| 2044 |
x = cos(a) * 20 + tilt_center_x; |
| 2045 |
y = sin(a) * 20 + tilt_center_y; |
| 2046 |
|
| 2047 |
litest_event(dev, EV_ABS, ABS_TILT_X, x); |
| 2048 |
litest_event(dev, EV_ABS, ABS_TILT_Y, y); |
| 2049 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2050 |
litest_dispatch(li); |
| 2051 |
|
| 2052 |
event = libinput_get_event(li); |
| 2053 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 2054 |
litest_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); |
| 2055 |
val = libinput_event_tablet_tool_get_rotation(tev); |
| 2056 |
|
| 2057 |
libinput_event_destroy(event); |
| 2058 |
litest_assert_empty_queue(li); |
| 2059 |
|
| 2060 |
return val; |
| 2061 |
} |
| 2062 |
|
| 2063 |
START_TEST(left_handed_mouse_rotation) |
| 2064 |
{ |
| 2065 |
#ifdef HAVE_LIBWACOM |
| 2066 |
struct litest_device *dev = litest_current_device(); |
| 2067 |
struct libinput *li = dev->libinput; |
| 2068 |
enum libinput_config_status status; |
| 2069 |
int angle; |
| 2070 |
double val, old_val = 0; |
| 2071 |
struct axis_replacement axes[] = { |
| 2072 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, |
| 2073 |
{ ABS_TILT_Y, 0 }, { -1, -1 }, |
| 2074 |
}; |
| 2075 |
|
| 2076 |
status = libinput_device_config_left_handed_set(dev->libinput_device, 1); |
| 2077 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 2078 |
|
| 2079 |
litest_drain_events(li); |
| 2080 |
|
| 2081 |
litest_with_event_frame(dev) { |
| 2082 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 2083 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 2084 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 2085 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 2086 |
} |
| 2087 |
|
| 2088 |
litest_drain_events(li); |
| 2089 |
|
| 2090 |
/* cos/sin are 90 degrees offset from the north-is-zero that |
| 2091 |
libinput uses. 175 is the CCW offset in the mouse HW */ |
| 2092 |
for (angle = 185; angle < 540; angle += 5) { |
| 2093 |
int expected_angle = angle - 180; |
| 2094 |
|
| 2095 |
val = rotate_event(dev, angle % 360); |
| 2096 |
|
| 2097 |
/* rounding error galore, we can't test for anything more |
| 2098 |
precise than these */ |
| 2099 |
litest_assert_double_lt(val, 360.0); |
| 2100 |
litest_assert_double_gt(val, old_val); |
| 2101 |
litest_assert_double_lt(val, expected_angle + 5); |
| 2102 |
|
| 2103 |
old_val = val; |
| 2104 |
} |
| 2105 |
#endif |
| 2106 |
} |
| 2107 |
END_TEST |
| 2108 |
|
| 2109 |
START_TEST(left_handed_artpen_rotation) |
| 2110 |
{ |
| 2111 |
#ifdef HAVE_LIBWACOM |
| 2112 |
struct litest_device *dev = litest_current_device(); |
| 2113 |
struct libinput *li = dev->libinput; |
| 2114 |
struct libinput_event *event; |
| 2115 |
struct libinput_event_tablet_tool *tev; |
| 2116 |
const struct input_absinfo *abs; |
| 2117 |
enum libinput_config_status status; |
| 2118 |
double val; |
| 2119 |
double scale; |
| 2120 |
int angle; |
| 2121 |
|
| 2122 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_Z)) |
| 2123 |
return LITEST_NOT_APPLICABLE; |
| 2124 |
|
| 2125 |
status = libinput_device_config_left_handed_set(dev->libinput_device, 1); |
| 2126 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 2127 |
|
| 2128 |
litest_drain_events(li); |
| 2129 |
|
| 2130 |
abs = libevdev_get_abs_info(dev->evdev, ABS_Z); |
| 2131 |
litest_assert_notnull(abs); |
| 2132 |
scale = absinfo_range(abs) / 360.0; |
| 2133 |
|
| 2134 |
litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1); |
| 2135 |
litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */ |
| 2136 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 2137 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2138 |
|
| 2139 |
litest_event(dev, EV_ABS, ABS_Z, abs->minimum); |
| 2140 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2141 |
|
| 2142 |
litest_drain_events(li); |
| 2143 |
|
| 2144 |
for (angle = 188; angle < 540; angle += 8) { |
| 2145 |
int a = angle * scale + abs->minimum; |
| 2146 |
int expected_angle = angle - 180; |
| 2147 |
|
| 2148 |
litest_event(dev, EV_ABS, ABS_Z, a); |
| 2149 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2150 |
litest_dispatch(li); |
| 2151 |
event = libinput_get_event(li); |
| 2152 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 2153 |
litest_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); |
| 2154 |
val = libinput_event_tablet_tool_get_rotation(tev); |
| 2155 |
|
| 2156 |
/* artpen has a 90 deg offset cw */ |
| 2157 |
litest_assert_int_eq(round(val), (expected_angle + 90) % 360); |
| 2158 |
|
| 2159 |
libinput_event_destroy(event); |
| 2160 |
litest_assert_empty_queue(li); |
| 2161 |
} |
| 2162 |
#endif |
| 2163 |
} |
| 2164 |
END_TEST |
| 2165 |
|
| 2166 |
START_TEST(motion_event_state) |
| 2167 |
{ |
| 2168 |
struct litest_device *dev = litest_current_device(); |
| 2169 |
struct libinput *li = dev->libinput; |
| 2170 |
struct libinput_event *event; |
| 2171 |
struct libinput_event_tablet_tool *tablet_event; |
| 2172 |
int test_x, test_y; |
| 2173 |
double last_x, last_y; |
| 2174 |
struct axis_replacement axes[] = { |
| 2175 |
{ ABS_DISTANCE, 10 }, |
| 2176 |
{ ABS_PRESSURE, 0 }, |
| 2177 |
{ -1, -1 }, |
| 2178 |
}; |
| 2179 |
unsigned int button = pick_stylus_or_btn0(dev); |
| 2180 |
|
| 2181 |
litest_drain_events(li); |
| 2182 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 2183 |
litest_drain_events(li); |
| 2184 |
|
| 2185 |
/* couple of events that go left/bottom to right/top */ |
| 2186 |
for (test_x = 0, test_y = 100; test_x < 100; test_x += 10, test_y -= 10) |
| 2187 |
litest_tablet_motion(dev, test_x, test_y, axes); |
| 2188 |
|
| 2189 |
litest_dispatch(li); |
| 2190 |
|
| 2191 |
event = libinput_get_event(li); |
| 2192 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 2193 |
|
| 2194 |
last_x = libinput_event_tablet_tool_get_x(tablet_event); |
| 2195 |
last_y = libinput_event_tablet_tool_get_y(tablet_event); |
| 2196 |
|
| 2197 |
/* mark with a button event, then go back to bottom/left */ |
| 2198 |
litest_button_click(dev, button, true); |
| 2199 |
|
| 2200 |
for (test_x = 100, test_y = 0; test_x > 0; test_x -= 10, test_y += 10) |
| 2201 |
litest_tablet_motion(dev, test_x, test_y, axes); |
| 2202 |
|
| 2203 |
libinput_event_destroy(event); |
| 2204 |
litest_dispatch(li); |
| 2205 |
litest_assert_enum_eq(libinput_next_event_type(li), |
| 2206 |
LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 2207 |
|
| 2208 |
/* we expect all events up to the button event to go from |
| 2209 |
bottom/left to top/right */ |
| 2210 |
while ((event = libinput_get_event(li))) { |
| 2211 |
double x, y; |
| 2212 |
|
| 2213 |
if (libinput_event_get_type(event) != LIBINPUT_EVENT_TABLET_TOOL_AXIS) |
| 2214 |
break; |
| 2215 |
|
| 2216 |
tablet_event = libinput_event_get_tablet_tool_event(event); |
| 2217 |
litest_assert_notnull(tablet_event); |
| 2218 |
|
| 2219 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 2220 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 2221 |
|
| 2222 |
litest_assert(x > last_x); |
| 2223 |
litest_assert(y < last_y); |
| 2224 |
|
| 2225 |
last_x = x; |
| 2226 |
last_y = y; |
| 2227 |
libinput_event_destroy(event); |
| 2228 |
} |
| 2229 |
|
| 2230 |
litest_assert_enum_eq(libinput_event_get_type(event), |
| 2231 |
LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 2232 |
libinput_event_destroy(event); |
| 2233 |
} |
| 2234 |
END_TEST |
| 2235 |
|
| 2236 |
START_TEST(motion_outside_bounds) |
| 2237 |
{ |
| 2238 |
struct litest_device *dev = litest_current_device(); |
| 2239 |
struct libinput *li = dev->libinput; |
| 2240 |
struct libinput_event *event; |
| 2241 |
struct libinput_event_tablet_tool *tablet_event; |
| 2242 |
double val; |
| 2243 |
int i; |
| 2244 |
|
| 2245 |
struct axis_replacement axes[] = { |
| 2246 |
{ ABS_DISTANCE, 10 }, |
| 2247 |
{ ABS_PRESSURE, 0 }, |
| 2248 |
{ -1, -1 }, |
| 2249 |
}; |
| 2250 |
|
| 2251 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 2252 |
litest_drain_events(li); |
| 2253 |
|
| 2254 |
/* Work around smoothing */ |
| 2255 |
for (i = 5; i > 0; i--) { |
| 2256 |
litest_event(dev, EV_ABS, ABS_X, 0 + 5 * i); |
| 2257 |
litest_event(dev, EV_ABS, ABS_Y, 1000); |
| 2258 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2259 |
litest_dispatch(li); |
| 2260 |
} |
| 2261 |
litest_drain_events(li); |
| 2262 |
|
| 2263 |
/* On the 24HD x/y of 0 is outside the limit */ |
| 2264 |
litest_event(dev, EV_ABS, ABS_X, 0); |
| 2265 |
litest_event(dev, EV_ABS, ABS_Y, 1000); |
| 2266 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2267 |
litest_dispatch(li); |
| 2268 |
|
| 2269 |
event = libinput_get_event(li); |
| 2270 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 2271 |
val = libinput_event_tablet_tool_get_x(tablet_event); |
| 2272 |
litest_assert_double_lt(val, 0.0); |
| 2273 |
val = libinput_event_tablet_tool_get_y(tablet_event); |
| 2274 |
litest_assert_double_gt(val, 0.0); |
| 2275 |
|
| 2276 |
val = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); |
| 2277 |
litest_assert_double_lt(val, 0.0); |
| 2278 |
|
| 2279 |
libinput_event_destroy(event); |
| 2280 |
|
| 2281 |
/* Work around smoothing */ |
| 2282 |
for (i = 5; i > 0; i--) { |
| 2283 |
litest_event(dev, EV_ABS, ABS_X, 1000); |
| 2284 |
litest_event(dev, EV_ABS, ABS_Y, 0 + 5 * i); |
| 2285 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2286 |
litest_dispatch(li); |
| 2287 |
} |
| 2288 |
litest_drain_events(li); |
| 2289 |
|
| 2290 |
/* On the 24HD x/y of 0 is outside the limit */ |
| 2291 |
litest_event(dev, EV_ABS, ABS_X, 1000); |
| 2292 |
litest_event(dev, EV_ABS, ABS_Y, 0); |
| 2293 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2294 |
litest_dispatch(li); |
| 2295 |
|
| 2296 |
event = libinput_get_event(li); |
| 2297 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 2298 |
val = libinput_event_tablet_tool_get_x(tablet_event); |
| 2299 |
litest_assert_double_gt(val, 0.0); |
| 2300 |
val = libinput_event_tablet_tool_get_y(tablet_event); |
| 2301 |
litest_assert_double_lt(val, 0.0); |
| 2302 |
|
| 2303 |
val = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); |
| 2304 |
litest_assert_double_lt(val, 0.0); |
| 2305 |
|
| 2306 |
libinput_event_destroy(event); |
| 2307 |
} |
| 2308 |
END_TEST |
| 2309 |
|
| 2310 |
START_TEST(bad_distance_events) |
| 2311 |
{ |
| 2312 |
struct litest_device *dev = litest_current_device(); |
| 2313 |
struct libinput *li = dev->libinput; |
| 2314 |
const struct input_absinfo *absinfo; |
| 2315 |
struct axis_replacement axes[] = { |
| 2316 |
{ -1, -1 }, |
| 2317 |
}; |
| 2318 |
|
| 2319 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 2320 |
litest_tablet_proximity_out(dev); |
| 2321 |
litest_timeout_tablet_proxout(li); |
| 2322 |
litest_drain_events(li); |
| 2323 |
|
| 2324 |
absinfo = libevdev_get_abs_info(dev->evdev, ABS_DISTANCE); |
| 2325 |
litest_assert_notnull(absinfo); |
| 2326 |
|
| 2327 |
litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->maximum); |
| 2328 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2329 |
litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->minimum); |
| 2330 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2331 |
|
| 2332 |
litest_assert_empty_queue(li); |
| 2333 |
} |
| 2334 |
END_TEST |
| 2335 |
|
| 2336 |
START_TEST(tool_unique) |
| 2337 |
{ |
| 2338 |
struct litest_device *dev = litest_current_device(); |
| 2339 |
struct libinput *li = dev->libinput; |
| 2340 |
struct libinput_event_tablet_tool *tablet_event; |
| 2341 |
struct libinput_event *event; |
| 2342 |
struct libinput_tablet_tool *tool; |
| 2343 |
|
| 2344 |
litest_drain_events(li); |
| 2345 |
|
| 2346 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2347 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 2348 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2349 |
|
| 2350 |
litest_dispatch(li); |
| 2351 |
event = libinput_get_event(li); |
| 2352 |
tablet_event = |
| 2353 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2354 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2355 |
litest_assert(libinput_tablet_tool_is_unique(tool)); |
| 2356 |
libinput_event_destroy(event); |
| 2357 |
} |
| 2358 |
END_TEST |
| 2359 |
|
| 2360 |
START_TEST(tool_serial) |
| 2361 |
{ |
| 2362 |
struct litest_device *dev = litest_current_device(); |
| 2363 |
struct libinput *li = dev->libinput; |
| 2364 |
struct libinput_event_tablet_tool *tablet_event; |
| 2365 |
struct libinput_event *event; |
| 2366 |
struct libinput_tablet_tool *tool; |
| 2367 |
|
| 2368 |
litest_drain_events(li); |
| 2369 |
|
| 2370 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2371 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 2372 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2373 |
litest_dispatch(li); |
| 2374 |
|
| 2375 |
event = libinput_get_event(li); |
| 2376 |
tablet_event = |
| 2377 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2378 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2379 |
litest_assert_int_eq(libinput_tablet_tool_get_serial(tool), (uint64_t)1000); |
| 2380 |
libinput_event_destroy(event); |
| 2381 |
} |
| 2382 |
END_TEST |
| 2383 |
|
| 2384 |
START_TEST(tool_id) |
| 2385 |
{ |
| 2386 |
struct litest_device *dev = litest_current_device(); |
| 2387 |
struct libinput *li = dev->libinput; |
| 2388 |
struct libinput_event_tablet_tool *tablet_event; |
| 2389 |
struct libinput_event *event; |
| 2390 |
struct libinput_tablet_tool *tool; |
| 2391 |
uint64_t tool_id = 0; |
| 2392 |
|
| 2393 |
litest_drain_events(li); |
| 2394 |
|
| 2395 |
litest_tablet_proximity_in(dev, 10, 10, NULL); |
| 2396 |
litest_dispatch(li); |
| 2397 |
|
| 2398 |
event = libinput_get_event(li); |
| 2399 |
tablet_event = |
| 2400 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2401 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2402 |
|
| 2403 |
litest_assert_int_eq(libinput_device_get_id_vendor(dev->libinput_device), |
| 2404 |
(unsigned int)VENDOR_ID_WACOM); |
| 2405 |
|
| 2406 |
switch (libinput_device_get_id_product(dev->libinput_device)) { |
| 2407 |
case 0x27: /* Intuos 5 */ |
| 2408 |
tool_id = 1050626; |
| 2409 |
break; |
| 2410 |
case 0xc6: /* Cintiq 12WX */ |
| 2411 |
case 0xf4: /* Cintiq 24HD */ |
| 2412 |
case 0x333: /* Cintiq 13HD */ |
| 2413 |
case 0x350: /* Cintiq Pro 16 */ |
| 2414 |
tool_id = 2083; |
| 2415 |
break; |
| 2416 |
default: |
| 2417 |
litest_abort_msg("Invalid button code"); |
| 2418 |
} |
| 2419 |
|
| 2420 |
litest_assert(tool_id == libinput_tablet_tool_get_tool_id(tool)); |
| 2421 |
libinput_event_destroy(event); |
| 2422 |
} |
| 2423 |
END_TEST |
| 2424 |
|
| 2425 |
START_TEST(tool_name) |
| 2426 |
{ |
| 2427 |
struct litest_device *dev = litest_current_device(); |
| 2428 |
struct libinput *li = dev->libinput; |
| 2429 |
|
| 2430 |
int tool_id = litest_test_param_get_i32(test_env->params, "tool_id"); |
| 2431 |
struct axis_replacement axes[] = { |
| 2432 |
{ ABS_DISTANCE, 10 }, |
| 2433 |
{ ABS_PRESSURE, 0 }, |
| 2434 |
{ ABS_MISC, tool_id }, |
| 2435 |
{ -1, -1 }, |
| 2436 |
}; |
| 2437 |
|
| 2438 |
litest_drain_events(li); |
| 2439 |
|
| 2440 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 2441 |
litest_dispatch(li); |
| 2442 |
|
| 2443 |
_destroy_(libinput_event) *event = libinput_get_event(li); |
| 2444 |
auto tablet_event = |
| 2445 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2446 |
auto tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2447 |
|
| 2448 |
const char *name = libinput_tablet_tool_get_name(tool); |
| 2449 |
|
| 2450 |
#ifdef HAVE_LIBWACOM |
| 2451 |
switch (tool_id) { |
| 2452 |
case 0x823: |
| 2453 |
litest_assert_str_eq(name, "Grip Pen"); |
| 2454 |
break; |
| 2455 |
case 0x4802: |
| 2456 |
litest_assert_str_eq(name, "Classic Pen"); |
| 2457 |
break; |
| 2458 |
case 0x100902: |
| 2459 |
litest_assert_str_eq(name, "Airbrush Pen"); |
| 2460 |
break; |
| 2461 |
default: |
| 2462 |
litest_assert_not_reached(); |
| 2463 |
} |
| 2464 |
#else |
| 2465 |
litest_assert_ptr_null(name); |
| 2466 |
#endif |
| 2467 |
} |
| 2468 |
END_TEST |
| 2469 |
|
| 2470 |
START_TEST(tool_no_name) |
| 2471 |
{ |
| 2472 |
struct litest_device *dev = litest_current_device(); |
| 2473 |
struct libinput *li = dev->libinput; |
| 2474 |
|
| 2475 |
struct axis_replacement axes[] = { |
| 2476 |
{ ABS_DISTANCE, 10 }, |
| 2477 |
{ ABS_PRESSURE, 0 }, |
| 2478 |
{ -1, -1 }, |
| 2479 |
}; |
| 2480 |
|
| 2481 |
litest_drain_events(li); |
| 2482 |
|
| 2483 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 2484 |
litest_dispatch(li); |
| 2485 |
|
| 2486 |
_destroy_(libinput_event) *event = libinput_get_event(li); |
| 2487 |
auto tablet_event = |
| 2488 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2489 |
auto tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2490 |
|
| 2491 |
const char *name = libinput_tablet_tool_get_name(tool); |
| 2492 |
litest_assert_ptr_null(name); |
| 2493 |
} |
| 2494 |
END_TEST |
| 2495 |
|
| 2496 |
START_TEST(serial_changes_tool) |
| 2497 |
{ |
| 2498 |
struct litest_device *dev = litest_current_device(); |
| 2499 |
struct libinput *li = dev->libinput; |
| 2500 |
struct libinput_event_tablet_tool *tablet_event; |
| 2501 |
struct libinput_event *event; |
| 2502 |
struct libinput_tablet_tool *tool; |
| 2503 |
|
| 2504 |
litest_drain_events(li); |
| 2505 |
|
| 2506 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2507 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 2508 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2509 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); |
| 2510 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2511 |
litest_drain_events(li); |
| 2512 |
|
| 2513 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2514 |
litest_event(dev, EV_MSC, MSC_SERIAL, 2000); |
| 2515 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2516 |
litest_dispatch(li); |
| 2517 |
|
| 2518 |
event = libinput_get_event(li); |
| 2519 |
tablet_event = |
| 2520 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2521 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2522 |
|
| 2523 |
litest_assert_int_eq(libinput_tablet_tool_get_serial(tool), (uint64_t)2000); |
| 2524 |
libinput_event_destroy(event); |
| 2525 |
} |
| 2526 |
END_TEST |
| 2527 |
|
| 2528 |
START_TEST(invalid_serials) |
| 2529 |
{ |
| 2530 |
struct litest_device *dev = litest_current_device(); |
| 2531 |
struct libinput *li = dev->libinput; |
| 2532 |
struct libinput_event *event; |
| 2533 |
struct libinput_event_tablet_tool *tablet_event; |
| 2534 |
struct libinput_tablet_tool *tool; |
| 2535 |
|
| 2536 |
litest_drain_events(li); |
| 2537 |
|
| 2538 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2539 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 2540 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2541 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); |
| 2542 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2543 |
litest_drain_events(li); |
| 2544 |
|
| 2545 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2546 |
litest_event(dev, EV_MSC, MSC_SERIAL, -1); |
| 2547 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2548 |
|
| 2549 |
litest_dispatch(li); |
| 2550 |
while ((event = libinput_get_event(li))) { |
| 2551 |
if (libinput_event_get_type(event) == |
| 2552 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { |
| 2553 |
tablet_event = libinput_event_get_tablet_tool_event(event); |
| 2554 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2555 |
|
| 2556 |
litest_assert_int_eq(libinput_tablet_tool_get_serial(tool), |
| 2557 |
(uint64_t)1000); |
| 2558 |
} |
| 2559 |
|
| 2560 |
libinput_event_destroy(event); |
| 2561 |
} |
| 2562 |
} |
| 2563 |
END_TEST |
| 2564 |
|
| 2565 |
START_TEST(tool_ref) |
| 2566 |
{ |
| 2567 |
struct litest_device *dev = litest_current_device(); |
| 2568 |
struct libinput *li = dev->libinput; |
| 2569 |
struct libinput_event_tablet_tool *tablet_event; |
| 2570 |
struct libinput_event *event; |
| 2571 |
struct libinput_tablet_tool *tool; |
| 2572 |
|
| 2573 |
litest_drain_events(li); |
| 2574 |
|
| 2575 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2576 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 2577 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2578 |
litest_dispatch(li); |
| 2579 |
|
| 2580 |
event = libinput_get_event(li); |
| 2581 |
tablet_event = |
| 2582 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2583 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2584 |
|
| 2585 |
litest_assert_notnull(tool); |
| 2586 |
litest_assert(tool == libinput_tablet_tool_ref(tool)); |
| 2587 |
litest_assert(tool == libinput_tablet_tool_unref(tool)); |
| 2588 |
libinput_event_destroy(event); |
| 2589 |
} |
| 2590 |
END_TEST |
| 2591 |
|
| 2592 |
START_TEST(tool_user_data) |
| 2593 |
{ |
| 2594 |
struct litest_device *dev = litest_current_device(); |
| 2595 |
struct libinput *li = dev->libinput; |
| 2596 |
struct libinput_event_tablet_tool *tablet_event; |
| 2597 |
struct libinput_event *event; |
| 2598 |
struct libinput_tablet_tool *tool; |
| 2599 |
void *userdata = &dev; /* not dereferenced */ |
| 2600 |
|
| 2601 |
litest_drain_events(li); |
| 2602 |
|
| 2603 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2604 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 2605 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2606 |
litest_dispatch(li); |
| 2607 |
|
| 2608 |
event = libinput_get_event(li); |
| 2609 |
tablet_event = |
| 2610 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2611 |
tool = libinput_event_tablet_tool_get_tool(tablet_event); |
| 2612 |
litest_assert_notnull(tool); |
| 2613 |
|
| 2614 |
litest_assert(libinput_tablet_tool_get_user_data(tool) == NULL); |
| 2615 |
libinput_tablet_tool_set_user_data(tool, userdata); |
| 2616 |
litest_assert(libinput_tablet_tool_get_user_data(tool) == userdata); |
| 2617 |
libinput_tablet_tool_set_user_data(tool, NULL); |
| 2618 |
litest_assert(libinput_tablet_tool_get_user_data(tool) == NULL); |
| 2619 |
|
| 2620 |
libinput_event_destroy(event); |
| 2621 |
} |
| 2622 |
END_TEST |
| 2623 |
|
| 2624 |
START_TEST(pad_buttons_ignored) |
| 2625 |
{ |
| 2626 |
struct litest_device *dev = litest_current_device(); |
| 2627 |
struct libinput *li = dev->libinput; |
| 2628 |
struct axis_replacement axes[] = { |
| 2629 |
{ ABS_DISTANCE, 10 }, |
| 2630 |
{ ABS_PRESSURE, 0 }, |
| 2631 |
{ -1, -1 }, |
| 2632 |
}; |
| 2633 |
int button; |
| 2634 |
|
| 2635 |
litest_drain_events(li); |
| 2636 |
|
| 2637 |
for (button = BTN_0; button < BTN_MOUSE; button++) { |
| 2638 |
litest_event(dev, EV_KEY, button, 1); |
| 2639 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2640 |
litest_event(dev, EV_KEY, button, 0); |
| 2641 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2642 |
litest_dispatch(li); |
| 2643 |
} |
| 2644 |
|
| 2645 |
litest_assert_empty_queue(li); |
| 2646 |
|
| 2647 |
/* same thing while in prox */ |
| 2648 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 2649 |
litest_drain_events(li); |
| 2650 |
|
| 2651 |
for (button = BTN_0; button < BTN_MOUSE; button++) |
| 2652 |
litest_event(dev, EV_KEY, button, 1); |
| 2653 |
|
| 2654 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2655 |
litest_dispatch(li); |
| 2656 |
|
| 2657 |
for (button = BTN_0; button < BTN_MOUSE; button++) |
| 2658 |
litest_event(dev, EV_KEY, button, 0); |
| 2659 |
|
| 2660 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2661 |
litest_dispatch(li); |
| 2662 |
|
| 2663 |
litest_assert_empty_queue(li); |
| 2664 |
} |
| 2665 |
END_TEST |
| 2666 |
|
| 2667 |
START_TEST(tools_with_serials) |
| 2668 |
{ |
| 2669 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 2670 |
struct litest_device *dev[2]; |
| 2671 |
struct libinput_tablet_tool *tool[2] = { 0 }; |
| 2672 |
struct libinput_event *event; |
| 2673 |
struct libinput_event_tablet_tool *tev; |
| 2674 |
int i; |
| 2675 |
|
| 2676 |
for (i = 0; i < 2; i++) { |
| 2677 |
dev[i] = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); |
| 2678 |
litest_drain_events(li); |
| 2679 |
|
| 2680 |
/* WARNING: this test fails if UI_GET_SYSNAME isn't |
| 2681 |
* available or isn't used by libevdev (1.3, commit 2ff45c73). |
| 2682 |
* Put a sleep(1) here and that usually fixes it. |
| 2683 |
*/ |
| 2684 |
|
| 2685 |
litest_with_event_frame(dev[i]) { |
| 2686 |
litest_tablet_proximity_in(dev[i], 10, 10, NULL); |
| 2687 |
litest_event(dev[i], EV_MSC, MSC_SERIAL, 100); |
| 2688 |
} |
| 2689 |
|
| 2690 |
litest_dispatch(li); |
| 2691 |
event = libinput_get_event(li); |
| 2692 |
tev = litest_is_tablet_event(event, |
| 2693 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2694 |
tool[i] = libinput_event_tablet_tool_get_tool(tev); |
| 2695 |
libinput_event_destroy(event); |
| 2696 |
} |
| 2697 |
|
| 2698 |
/* We should get the same object for both devices */ |
| 2699 |
litest_assert_notnull(tool[0]); |
| 2700 |
litest_assert_notnull(tool[1]); |
| 2701 |
litest_assert_ptr_eq(tool[0], tool[1]); |
| 2702 |
|
| 2703 |
litest_device_destroy(dev[0]); |
| 2704 |
litest_device_destroy(dev[1]); |
| 2705 |
} |
| 2706 |
END_TEST |
| 2707 |
|
| 2708 |
START_TEST(tools_without_serials) |
| 2709 |
{ |
| 2710 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 2711 |
struct litest_device *dev[2]; |
| 2712 |
struct libinput_tablet_tool *tool[2] = { 0 }; |
| 2713 |
struct libinput_event *event; |
| 2714 |
struct libinput_event_tablet_tool *tev; |
| 2715 |
int i; |
| 2716 |
|
| 2717 |
for (i = 0; i < 2; i++) { |
| 2718 |
dev[i] = litest_add_device_with_overrides(li, |
| 2719 |
LITEST_WACOM_ISDV4_E6_PEN, |
| 2720 |
NULL, |
| 2721 |
NULL, |
| 2722 |
NULL, |
| 2723 |
NULL); |
| 2724 |
|
| 2725 |
litest_drain_events(li); |
| 2726 |
|
| 2727 |
/* WARNING: this test fails if UI_GET_SYSNAME isn't |
| 2728 |
* available or isn't used by libevdev (1.3, commit 2ff45c73). |
| 2729 |
* Put a sleep(1) here and that usually fixes it. |
| 2730 |
*/ |
| 2731 |
|
| 2732 |
litest_tablet_proximity_in(dev[i], 10, 10, NULL); |
| 2733 |
|
| 2734 |
litest_dispatch(li); |
| 2735 |
event = libinput_get_event(li); |
| 2736 |
tev = litest_is_tablet_event(event, |
| 2737 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2738 |
tool[i] = libinput_event_tablet_tool_get_tool(tev); |
| 2739 |
libinput_event_destroy(event); |
| 2740 |
} |
| 2741 |
|
| 2742 |
/* We should get different tool objects for each device */ |
| 2743 |
litest_assert_notnull(tool[0]); |
| 2744 |
litest_assert_notnull(tool[1]); |
| 2745 |
litest_assert_ptr_ne(tool[0], tool[1]); |
| 2746 |
|
| 2747 |
litest_device_destroy(dev[0]); |
| 2748 |
litest_device_destroy(dev[1]); |
| 2749 |
} |
| 2750 |
END_TEST |
| 2751 |
|
| 2752 |
START_TEST(tool_delayed_serial) |
| 2753 |
{ |
| 2754 |
struct litest_device *dev = litest_current_device(); |
| 2755 |
struct libinput *li = dev->libinput; |
| 2756 |
struct libinput_event *event; |
| 2757 |
struct libinput_event_tablet_tool *tev; |
| 2758 |
struct libinput_tablet_tool *tool; |
| 2759 |
unsigned int serial; |
| 2760 |
|
| 2761 |
litest_drain_events(li); |
| 2762 |
|
| 2763 |
litest_event(dev, EV_ABS, ABS_X, 4500); |
| 2764 |
litest_event(dev, EV_ABS, ABS_Y, 2000); |
| 2765 |
litest_event(dev, EV_MSC, MSC_SERIAL, 0); |
| 2766 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 2767 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2768 |
litest_dispatch(li); |
| 2769 |
|
| 2770 |
event = libinput_get_event(li); |
| 2771 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2772 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 2773 |
serial = libinput_tablet_tool_get_serial(tool); |
| 2774 |
litest_assert_int_eq(serial, (uint64_t)0); |
| 2775 |
libinput_event_destroy(event); |
| 2776 |
|
| 2777 |
for (int x = 4500; x < 8000; x += 1000) { |
| 2778 |
litest_event(dev, EV_ABS, ABS_X, x); |
| 2779 |
litest_event(dev, EV_ABS, ABS_Y, 2000); |
| 2780 |
litest_event(dev, EV_MSC, MSC_SERIAL, 0); |
| 2781 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2782 |
litest_dispatch(li); |
| 2783 |
} |
| 2784 |
litest_drain_events(li); |
| 2785 |
|
| 2786 |
/* Now send the serial */ |
| 2787 |
litest_event(dev, EV_ABS, ABS_X, 4500); |
| 2788 |
litest_event(dev, EV_ABS, ABS_Y, 2000); |
| 2789 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1234566); |
| 2790 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2791 |
litest_dispatch(li); |
| 2792 |
|
| 2793 |
event = libinput_get_event(li); |
| 2794 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 2795 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 2796 |
serial = libinput_tablet_tool_get_serial(tool); |
| 2797 |
litest_assert_int_eq(serial, (uint64_t)0); |
| 2798 |
libinput_event_destroy(event); |
| 2799 |
|
| 2800 |
for (int x = 4500; x < 8000; x += 500) { |
| 2801 |
litest_event(dev, EV_ABS, ABS_X, x); |
| 2802 |
litest_event(dev, EV_ABS, ABS_Y, 2000); |
| 2803 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1234566); |
| 2804 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2805 |
litest_dispatch(li); |
| 2806 |
} |
| 2807 |
|
| 2808 |
event = libinput_get_event(li); |
| 2809 |
do { |
| 2810 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 2811 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 2812 |
serial = libinput_tablet_tool_get_serial(tool); |
| 2813 |
litest_assert_int_eq(serial, (uint64_t)0); |
| 2814 |
libinput_event_destroy(event); |
| 2815 |
event = libinput_get_event(li); |
| 2816 |
} while (event != NULL); |
| 2817 |
|
| 2818 |
/* Quirk: tool out event is a serial of 0 */ |
| 2819 |
litest_event(dev, EV_ABS, ABS_X, 4500); |
| 2820 |
litest_event(dev, EV_ABS, ABS_Y, 2000); |
| 2821 |
litest_event(dev, EV_MSC, MSC_SERIAL, 0); |
| 2822 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); |
| 2823 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 2824 |
litest_dispatch(li); |
| 2825 |
|
| 2826 |
event = libinput_get_event(li); |
| 2827 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2828 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 2829 |
serial = libinput_tablet_tool_get_serial(tool); |
| 2830 |
litest_assert_int_eq(serial, (uint64_t)0); |
| 2831 |
libinput_event_destroy(event); |
| 2832 |
} |
| 2833 |
END_TEST |
| 2834 |
|
| 2835 |
START_TEST(tool_capability) |
| 2836 |
{ |
| 2837 |
struct litest_device *dev = litest_current_device(); |
| 2838 |
struct libinput_device *device = dev->libinput_device; |
| 2839 |
|
| 2840 |
litest_assert(libinput_device_has_capability(device, |
| 2841 |
LIBINPUT_DEVICE_CAP_TABLET_TOOL)); |
| 2842 |
} |
| 2843 |
END_TEST |
| 2844 |
|
| 2845 |
START_TEST(tool_capabilities) |
| 2846 |
{ |
| 2847 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 2848 |
struct litest_device *intuos; |
| 2849 |
struct litest_device *bamboo; |
| 2850 |
struct libinput_event *event; |
| 2851 |
struct libinput_event_tablet_tool *t; |
| 2852 |
struct libinput_tablet_tool *tool; |
| 2853 |
|
| 2854 |
/* The axis capabilities of a tool can differ depending on the type of |
| 2855 |
* tablet the tool is being used with */ |
| 2856 |
bamboo = litest_add_device(li, LITEST_WACOM_BAMBOO_16FG_PEN); |
| 2857 |
intuos = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); |
| 2858 |
litest_drain_events(li); |
| 2859 |
|
| 2860 |
litest_event(bamboo, EV_KEY, BTN_TOOL_PEN, 1); |
| 2861 |
litest_event(bamboo, EV_SYN, SYN_REPORT, 0); |
| 2862 |
|
| 2863 |
litest_dispatch(li); |
| 2864 |
|
| 2865 |
event = libinput_get_event(li); |
| 2866 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2867 |
tool = libinput_event_tablet_tool_get_tool(t); |
| 2868 |
|
| 2869 |
litest_assert(libinput_tablet_tool_has_pressure(tool)); |
| 2870 |
litest_assert(libinput_tablet_tool_has_distance(tool)); |
| 2871 |
litest_assert(!libinput_tablet_tool_has_tilt(tool)); |
| 2872 |
|
| 2873 |
libinput_event_destroy(event); |
| 2874 |
litest_assert_empty_queue(li); |
| 2875 |
|
| 2876 |
litest_event(intuos, EV_KEY, BTN_TOOL_PEN, 1); |
| 2877 |
litest_event(intuos, EV_SYN, SYN_REPORT, 0); |
| 2878 |
litest_dispatch(li); |
| 2879 |
|
| 2880 |
event = libinput_get_event(li); |
| 2881 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2882 |
tool = libinput_event_tablet_tool_get_tool(t); |
| 2883 |
|
| 2884 |
litest_assert(libinput_tablet_tool_has_pressure(tool)); |
| 2885 |
litest_assert(libinput_tablet_tool_has_distance(tool)); |
| 2886 |
litest_assert(libinput_tablet_tool_has_tilt(tool)); |
| 2887 |
|
| 2888 |
libinput_event_destroy(event); |
| 2889 |
litest_assert_empty_queue(li); |
| 2890 |
|
| 2891 |
litest_device_destroy(bamboo); |
| 2892 |
litest_device_destroy(intuos); |
| 2893 |
} |
| 2894 |
END_TEST |
| 2895 |
|
| 2896 |
static inline bool |
| 2897 |
tablet_has_mouse(struct litest_device *dev) |
| 2898 |
{ |
| 2899 |
return libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_MOUSE) && |
| 2900 |
libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM; |
| 2901 |
} |
| 2902 |
|
| 2903 |
START_TEST(tool_type) |
| 2904 |
{ |
| 2905 |
struct litest_device *dev = litest_current_device(); |
| 2906 |
struct libinput *li = dev->libinput; |
| 2907 |
struct libinput_event *event; |
| 2908 |
struct libinput_event_tablet_tool *t; |
| 2909 |
struct libinput_tablet_tool *tool; |
| 2910 |
struct axis_replacement axes[] = { |
| 2911 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, |
| 2912 |
{ ABS_TILT_Y, 0 }, { -1, -1 }, |
| 2913 |
}; |
| 2914 |
struct tool_type_match { |
| 2915 |
int code; |
| 2916 |
enum libinput_tablet_tool_type type; |
| 2917 |
} types[] = { |
| 2918 |
{ BTN_TOOL_PEN, LIBINPUT_TABLET_TOOL_TYPE_PEN }, |
| 2919 |
{ BTN_TOOL_RUBBER, LIBINPUT_TABLET_TOOL_TYPE_ERASER }, |
| 2920 |
{ BTN_TOOL_BRUSH, LIBINPUT_TABLET_TOOL_TYPE_BRUSH }, |
| 2921 |
{ BTN_TOOL_PENCIL, LIBINPUT_TABLET_TOOL_TYPE_PENCIL }, |
| 2922 |
{ BTN_TOOL_AIRBRUSH, LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH }, |
| 2923 |
{ BTN_TOOL_MOUSE, LIBINPUT_TABLET_TOOL_TYPE_MOUSE }, |
| 2924 |
{ BTN_TOOL_LENS, LIBINPUT_TABLET_TOOL_TYPE_LENS }, |
| 2925 |
{ -1, -1 }, |
| 2926 |
}; |
| 2927 |
struct tool_type_match *tt; |
| 2928 |
double x = 50, y = 50; |
| 2929 |
|
| 2930 |
litest_drain_events(li); |
| 2931 |
|
| 2932 |
for (tt = types; tt->code != -1; tt++) { |
| 2933 |
enum libinput_tablet_tool_type type; |
| 2934 |
|
| 2935 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, tt->code)) |
| 2936 |
continue; |
| 2937 |
|
| 2938 |
if ((tt->code == BTN_TOOL_MOUSE || tt->code == BTN_TOOL_LENS) && |
| 2939 |
!tablet_has_mouse(dev)) |
| 2940 |
continue; |
| 2941 |
|
| 2942 |
litest_tablet_set_tool_type(dev, tt->code); |
| 2943 |
litest_tablet_proximity_in(dev, x, y, axes); |
| 2944 |
litest_dispatch(li); |
| 2945 |
|
| 2946 |
event = libinput_get_event(li); |
| 2947 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2948 |
tool = libinput_event_tablet_tool_get_tool(t); |
| 2949 |
type = libinput_tablet_tool_get_type(tool); |
| 2950 |
|
| 2951 |
/* Devices with doubled-up tool bits send the pen |
| 2952 |
* in-prox and immediately out-of-prox before the real tool |
| 2953 |
* type. Drop those two and continue with what we expect is |
| 2954 |
* the real prox in event */ |
| 2955 |
if (tt->type != LIBINPUT_TABLET_TOOL_TYPE_PEN && |
| 2956 |
type == LIBINPUT_TABLET_TOOL_TYPE_PEN) { |
| 2957 |
libinput_event_destroy(event); |
| 2958 |
event = libinput_get_event(li); |
| 2959 |
litest_is_tablet_event(event, |
| 2960 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2961 |
libinput_event_destroy(event); |
| 2962 |
event = libinput_get_event(li); |
| 2963 |
t = litest_is_tablet_event( |
| 2964 |
event, |
| 2965 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 2966 |
tool = libinput_event_tablet_tool_get_tool(t); |
| 2967 |
type = libinput_tablet_tool_get_type(tool); |
| 2968 |
} |
| 2969 |
|
| 2970 |
litest_assert_int_eq(type, tt->type); |
| 2971 |
|
| 2972 |
libinput_event_destroy(event); |
| 2973 |
litest_assert_empty_queue(li); |
| 2974 |
|
| 2975 |
litest_tablet_proximity_out(dev); |
| 2976 |
litest_timeout_tablet_proxout(li); |
| 2977 |
litest_drain_events(li); |
| 2978 |
|
| 2979 |
x++; |
| 2980 |
y++; |
| 2981 |
} |
| 2982 |
} |
| 2983 |
END_TEST |
| 2984 |
|
| 2985 |
START_TEST(tool_in_prox_before_start) |
| 2986 |
{ |
| 2987 |
struct litest_device *dev = litest_current_device(); |
| 2988 |
struct libinput_event *event; |
| 2989 |
struct libinput_event_tablet_tool *tev; |
| 2990 |
struct libinput_tablet_tool *tool; |
| 2991 |
struct axis_replacement axes[] = { |
| 2992 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, |
| 2993 |
{ ABS_TILT_Y, 0 }, { -1, -1 }, |
| 2994 |
}; |
| 2995 |
const char *devnode; |
| 2996 |
uint64_t serial; |
| 2997 |
|
| 2998 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 2999 |
|
| 3000 |
/* for simplicity, we create a new litest context */ |
| 3001 |
devnode = libevdev_uinput_get_devnode(dev->uinput); |
| 3002 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 3003 |
libinput_path_add_device(li, devnode); |
| 3004 |
|
| 3005 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); |
| 3006 |
|
| 3007 |
litest_assert_empty_queue(li); |
| 3008 |
|
| 3009 |
litest_tablet_motion(dev, 10, 20, axes); |
| 3010 |
litest_dispatch(li); |
| 3011 |
event = libinput_get_event(li); |
| 3012 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3013 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 3014 |
serial = libinput_tablet_tool_get_serial(tool); |
| 3015 |
libinput_event_destroy(event); |
| 3016 |
|
| 3017 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 3018 |
|
| 3019 |
litest_tablet_motion(dev, 30, 40, axes); |
| 3020 |
litest_dispatch(li); |
| 3021 |
event = libinput_get_event(li); |
| 3022 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3023 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 3024 |
litest_assert_int_eq(serial, libinput_tablet_tool_get_serial(tool)); |
| 3025 |
libinput_event_destroy(event); |
| 3026 |
|
| 3027 |
litest_assert_empty_queue(li); |
| 3028 |
litest_button_click(dev, BTN_STYLUS, true); |
| 3029 |
litest_button_click(dev, BTN_STYLUS, false); |
| 3030 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 3031 |
litest_tablet_proximity_out(dev); |
| 3032 |
litest_timeout_tablet_proxout(li); |
| 3033 |
|
| 3034 |
event = libinput_get_event(li); |
| 3035 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3036 |
libinput_event_destroy(event); |
| 3037 |
} |
| 3038 |
END_TEST |
| 3039 |
|
| 3040 |
START_TEST(tool_direct_switch_skip_tool_update) |
| 3041 |
{ |
| 3042 |
struct litest_device *dev = litest_current_device(); |
| 3043 |
struct libinput *li = dev->libinput; |
| 3044 |
struct libinput_event *event; |
| 3045 |
struct libinput_event_tablet_tool *tev; |
| 3046 |
struct libinput_tablet_tool *pen = NULL, *eraser = NULL; |
| 3047 |
struct axis_replacement axes[] = { |
| 3048 |
{ ABS_DISTANCE, 10 }, |
| 3049 |
{ ABS_PRESSURE, 0 }, |
| 3050 |
{ -1, -1 }, |
| 3051 |
}; |
| 3052 |
|
| 3053 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) |
| 3054 |
return LITEST_NOT_APPLICABLE; |
| 3055 |
|
| 3056 |
litest_drain_events(li); |
| 3057 |
|
| 3058 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 3059 |
litest_dispatch(li); |
| 3060 |
|
| 3061 |
event = libinput_get_event(li); |
| 3062 |
tev = litest_is_proximity_event(event, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 3063 |
pen = libinput_event_tablet_tool_get_tool(tev); |
| 3064 |
libinput_tablet_tool_ref(pen); |
| 3065 |
libinput_event_destroy(event); |
| 3066 |
|
| 3067 |
litest_checkpoint("Switching directly to eraser"); |
| 3068 |
litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); |
| 3069 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3070 |
litest_dispatch(li); |
| 3071 |
|
| 3072 |
litest_checkpoint("Expecting pen prox out followed by eraser prox in "); |
| 3073 |
event = libinput_get_event(li); |
| 3074 |
tev = litest_is_proximity_event(event, |
| 3075 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 3076 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), pen); |
| 3077 |
libinput_event_destroy(event); |
| 3078 |
|
| 3079 |
event = libinput_get_event(li); |
| 3080 |
tev = litest_is_proximity_event(event, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 3081 |
litest_assert_ptr_ne(libinput_event_tablet_tool_get_tool(tev), pen); |
| 3082 |
eraser = libinput_event_tablet_tool_get_tool(tev); |
| 3083 |
libinput_tablet_tool_ref(eraser); |
| 3084 |
libinput_event_destroy(event); |
| 3085 |
|
| 3086 |
litest_tablet_motion(dev, 20, 30, axes); |
| 3087 |
litest_dispatch(li); |
| 3088 |
|
| 3089 |
event = libinput_get_event(li); |
| 3090 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3091 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), eraser); |
| 3092 |
libinput_event_destroy(event); |
| 3093 |
|
| 3094 |
litest_checkpoint("Switching directly to pen, expecting eraser prox out"); |
| 3095 |
litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 0); |
| 3096 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3097 |
litest_dispatch(li); |
| 3098 |
|
| 3099 |
event = libinput_get_event(li); |
| 3100 |
tev = litest_is_proximity_event(event, |
| 3101 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 3102 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), eraser); |
| 3103 |
libinput_event_destroy(event); |
| 3104 |
|
| 3105 |
litest_with_event_frame(dev) { |
| 3106 |
litest_checkpoint("Prox in for eraser (pen still in prox)"); |
| 3107 |
litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); |
| 3108 |
litest_tablet_motion(dev, 30, 40, axes); |
| 3109 |
} |
| 3110 |
litest_dispatch(li); |
| 3111 |
|
| 3112 |
event = libinput_get_event(li); |
| 3113 |
tev = litest_is_proximity_event(event, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 3114 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), eraser); |
| 3115 |
libinput_event_destroy(event); |
| 3116 |
|
| 3117 |
litest_tablet_motion(dev, 40, 30, axes); |
| 3118 |
litest_dispatch(li); |
| 3119 |
|
| 3120 |
event = libinput_get_event(li); |
| 3121 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3122 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), eraser); |
| 3123 |
libinput_event_destroy(event); |
| 3124 |
|
| 3125 |
litest_with_event_frame(dev) { |
| 3126 |
litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 0); |
| 3127 |
litest_tablet_proximity_out(dev); |
| 3128 |
} |
| 3129 |
litest_timeout_tablet_proxout(li); |
| 3130 |
|
| 3131 |
event = libinput_get_event(li); |
| 3132 |
tev = litest_is_proximity_event(event, |
| 3133 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 3134 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), eraser); |
| 3135 |
libinput_event_destroy(event); |
| 3136 |
|
| 3137 |
litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 0); |
| 3138 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3139 |
litest_assert_empty_queue(li); |
| 3140 |
|
| 3141 |
libinput_tablet_tool_unref(eraser); |
| 3142 |
libinput_tablet_tool_unref(pen); |
| 3143 |
} |
| 3144 |
END_TEST |
| 3145 |
|
| 3146 |
START_TEST(tool_direct_switch_with_forced_proxout) |
| 3147 |
{ |
| 3148 |
struct litest_device *dev = litest_current_device(); |
| 3149 |
struct libinput *li = dev->libinput; |
| 3150 |
struct axis_replacement axes[] = { |
| 3151 |
{ ABS_DISTANCE, 10 }, |
| 3152 |
{ ABS_PRESSURE, 0 }, |
| 3153 |
{ -1, -1 }, |
| 3154 |
}; |
| 3155 |
|
| 3156 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) |
| 3157 |
return LITEST_NOT_APPLICABLE; |
| 3158 |
|
| 3159 |
litest_drain_events(li); |
| 3160 |
|
| 3161 |
/* This is a *very* specific event sequence to trigger a bug: |
| 3162 |
- pen proximity in |
| 3163 |
- pen proximity forced out |
| 3164 |
- eraser proximity in without axis movement |
| 3165 |
- eraser axis move |
| 3166 |
*/ |
| 3167 |
|
| 3168 |
/* pen prox in */ |
| 3169 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 3170 |
litest_dispatch(li); |
| 3171 |
litest_assert_tablet_proximity_event(li, |
| 3172 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 3173 |
|
| 3174 |
/* pen motion */ |
| 3175 |
litest_tablet_motion(dev, 20, 30, axes); |
| 3176 |
litest_dispatch(li); |
| 3177 |
|
| 3178 |
litest_assert_tablet_axis_event(li); |
| 3179 |
|
| 3180 |
litest_checkpoint("Forcing a timeout prox-out"); |
| 3181 |
/* pen forced prox out */ |
| 3182 |
litest_timeout_tablet_proxout(li); |
| 3183 |
|
| 3184 |
litest_checkpoint("Actual prox-out"); |
| 3185 |
/* actual prox out for tablets that don't do forced prox out */ |
| 3186 |
litest_tablet_proximity_out(dev); |
| 3187 |
litest_timeout_tablet_proxout(li); |
| 3188 |
|
| 3189 |
litest_assert_tablet_proximity_event(li, |
| 3190 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 3191 |
litest_assert_empty_queue(li); |
| 3192 |
|
| 3193 |
/* eraser prox in without axes */ |
| 3194 |
litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); |
| 3195 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3196 |
litest_dispatch(li); |
| 3197 |
litest_assert_tablet_proximity_event(li, |
| 3198 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 3199 |
|
| 3200 |
/* eraser motion */ |
| 3201 |
litest_tablet_motion(dev, 30, 40, axes); |
| 3202 |
litest_tablet_motion(dev, 40, 50, axes); |
| 3203 |
litest_dispatch(li); |
| 3204 |
|
| 3205 |
litest_assert_tablet_axis_event(li); |
| 3206 |
litest_assert_tablet_axis_event(li); |
| 3207 |
|
| 3208 |
litest_assert_empty_queue(li); |
| 3209 |
} |
| 3210 |
END_TEST |
| 3211 |
|
| 3212 |
START_TEST(stylus_buttons) |
| 3213 |
{ |
| 3214 |
struct litest_device *dev = litest_current_device(); |
| 3215 |
struct libinput *li = dev->libinput; |
| 3216 |
struct libinput_event *event; |
| 3217 |
struct libinput_event_tablet_tool *tev; |
| 3218 |
struct libinput_tablet_tool *tool; |
| 3219 |
uint32_t stylus_buttons[] = { BTN_STYLUS, BTN_STYLUS2, BTN_STYLUS3 }; |
| 3220 |
|
| 3221 |
litest_drain_events(li); |
| 3222 |
|
| 3223 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 3224 |
litest_event(dev, EV_ABS, ABS_MISC, 0x200); /* 3-button stylus tool_id */ |
| 3225 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 3226 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3227 |
litest_dispatch(li); |
| 3228 |
|
| 3229 |
event = libinput_get_event(li); |
| 3230 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3231 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 3232 |
litest_assert_notnull(tool); |
| 3233 |
libinput_tablet_tool_ref(tool); |
| 3234 |
|
| 3235 |
libinput_event_destroy(event); |
| 3236 |
|
| 3237 |
ARRAY_FOR_EACH(stylus_buttons, code) { |
| 3238 |
litest_event(dev, EV_KEY, *code, 1); |
| 3239 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3240 |
litest_dispatch(li); |
| 3241 |
litest_event(dev, EV_KEY, *code, 0); |
| 3242 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3243 |
litest_dispatch(li); |
| 3244 |
|
| 3245 |
litest_assert_tablet_button_event(li, |
| 3246 |
*code, |
| 3247 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 3248 |
litest_assert_tablet_button_event(li, |
| 3249 |
*code, |
| 3250 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 3251 |
} |
| 3252 |
|
| 3253 |
libinput_tablet_tool_unref(tool); |
| 3254 |
} |
| 3255 |
END_TEST |
| 3256 |
|
| 3257 |
START_TEST(mouse_tool) |
| 3258 |
{ |
| 3259 |
struct litest_device *dev = litest_current_device(); |
| 3260 |
struct libinput *li = dev->libinput; |
| 3261 |
struct libinput_event *event; |
| 3262 |
struct libinput_event_tablet_tool *tev; |
| 3263 |
struct libinput_tablet_tool *tool; |
| 3264 |
|
| 3265 |
litest_drain_events(li); |
| 3266 |
|
| 3267 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 3268 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 3269 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3270 |
litest_dispatch(li); |
| 3271 |
|
| 3272 |
event = libinput_get_event(li); |
| 3273 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3274 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 3275 |
litest_assert_notnull(tool); |
| 3276 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 3277 |
LIBINPUT_TABLET_TOOL_TYPE_MOUSE); |
| 3278 |
|
| 3279 |
libinput_event_destroy(event); |
| 3280 |
} |
| 3281 |
END_TEST |
| 3282 |
|
| 3283 |
START_TEST(mouse_buttons) |
| 3284 |
{ |
| 3285 |
struct litest_device *dev = litest_current_device(); |
| 3286 |
struct libinput *li = dev->libinput; |
| 3287 |
struct libinput_event *event; |
| 3288 |
struct libinput_event_tablet_tool *tev; |
| 3289 |
struct libinput_tablet_tool *tool; |
| 3290 |
int code; |
| 3291 |
|
| 3292 |
litest_drain_events(li); |
| 3293 |
|
| 3294 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 3295 |
litest_event(dev, EV_ABS, ABS_MISC, 0x806); /* 5-button mouse tool_id */ |
| 3296 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 3297 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3298 |
litest_dispatch(li); |
| 3299 |
|
| 3300 |
event = libinput_get_event(li); |
| 3301 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3302 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 3303 |
litest_assert_notnull(tool); |
| 3304 |
libinput_tablet_tool_ref(tool); |
| 3305 |
|
| 3306 |
libinput_event_destroy(event); |
| 3307 |
|
| 3308 |
for (code = BTN_LEFT; code <= BTN_TASK; code++) { |
| 3309 |
bool has_button = libevdev_has_event_code(dev->evdev, EV_KEY, code); |
| 3310 |
litest_assert_int_eq(!!has_button, |
| 3311 |
!!libinput_tablet_tool_has_button(tool, code)); |
| 3312 |
|
| 3313 |
if (!has_button) |
| 3314 |
continue; |
| 3315 |
|
| 3316 |
litest_event(dev, EV_KEY, code, 1); |
| 3317 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3318 |
litest_dispatch(li); |
| 3319 |
litest_event(dev, EV_KEY, code, 0); |
| 3320 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3321 |
litest_dispatch(li); |
| 3322 |
|
| 3323 |
litest_assert_tablet_button_event(li, |
| 3324 |
code, |
| 3325 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 3326 |
litest_assert_tablet_button_event(li, |
| 3327 |
code, |
| 3328 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 3329 |
} |
| 3330 |
|
| 3331 |
libinput_tablet_tool_unref(tool); |
| 3332 |
} |
| 3333 |
END_TEST |
| 3334 |
|
| 3335 |
START_TEST(mouse_rotation) |
| 3336 |
{ |
| 3337 |
struct litest_device *dev = litest_current_device(); |
| 3338 |
struct libinput *li = dev->libinput; |
| 3339 |
int angle; |
| 3340 |
double val, old_val = 0; |
| 3341 |
|
| 3342 |
struct axis_replacement axes[] = { |
| 3343 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, |
| 3344 |
{ ABS_TILT_Y, 0 }, { -1, -1 }, |
| 3345 |
}; |
| 3346 |
|
| 3347 |
litest_drain_events(li); |
| 3348 |
|
| 3349 |
litest_with_event_frame(dev) { |
| 3350 |
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 3351 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 3352 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 3353 |
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); |
| 3354 |
} |
| 3355 |
|
| 3356 |
litest_drain_events(li); |
| 3357 |
|
| 3358 |
/* cos/sin are 90 degrees offset from the north-is-zero that |
| 3359 |
libinput uses. 175 is the CCW offset in the mouse HW */ |
| 3360 |
for (angle = 5; angle < 360; angle += 5) { |
| 3361 |
val = rotate_event(dev, angle); |
| 3362 |
|
| 3363 |
/* rounding error galore, we can't test for anything more |
| 3364 |
precise than these */ |
| 3365 |
litest_assert_double_lt(val, 360.0); |
| 3366 |
litest_assert_double_gt(val, old_val); |
| 3367 |
litest_assert_double_lt(val, angle + 5); |
| 3368 |
|
| 3369 |
old_val = val; |
| 3370 |
} |
| 3371 |
} |
| 3372 |
END_TEST |
| 3373 |
|
| 3374 |
START_TEST(mouse_wheel) |
| 3375 |
{ |
| 3376 |
struct litest_device *dev = litest_current_device(); |
| 3377 |
struct libinput *li = dev->libinput; |
| 3378 |
struct libinput_event *event; |
| 3379 |
struct libinput_event_tablet_tool *tev; |
| 3380 |
struct libinput_tablet_tool *tool; |
| 3381 |
const struct input_absinfo *abs; |
| 3382 |
double val; |
| 3383 |
int i; |
| 3384 |
|
| 3385 |
if (!libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL)) |
| 3386 |
return LITEST_NOT_APPLICABLE; |
| 3387 |
|
| 3388 |
litest_drain_events(li); |
| 3389 |
|
| 3390 |
litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); |
| 3391 |
litest_event(dev, EV_ABS, ABS_MISC, 0x806); /* 5-button mouse tool_id */ |
| 3392 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 3393 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3394 |
litest_dispatch(li); |
| 3395 |
|
| 3396 |
event = libinput_get_event(li); |
| 3397 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3398 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 3399 |
litest_assert_notnull(tool); |
| 3400 |
libinput_tablet_tool_ref(tool); |
| 3401 |
|
| 3402 |
libinput_event_destroy(event); |
| 3403 |
|
| 3404 |
litest_assert(libinput_tablet_tool_has_wheel(tool)); |
| 3405 |
|
| 3406 |
for (i = 0; i < 3; i++) { |
| 3407 |
litest_event(dev, EV_REL, REL_WHEEL, -1); |
| 3408 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3409 |
litest_dispatch(li); |
| 3410 |
|
| 3411 |
event = libinput_get_event(li); |
| 3412 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3413 |
litest_assert(libinput_event_tablet_tool_wheel_has_changed(tev)); |
| 3414 |
|
| 3415 |
val = libinput_event_tablet_tool_get_wheel_delta(tev); |
| 3416 |
litest_assert_int_eq(val, 15); |
| 3417 |
|
| 3418 |
val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev); |
| 3419 |
litest_assert_int_eq(val, 1); |
| 3420 |
|
| 3421 |
libinput_event_destroy(event); |
| 3422 |
|
| 3423 |
litest_assert_empty_queue(li); |
| 3424 |
} |
| 3425 |
|
| 3426 |
for (i = 2; i < 5; i++) { |
| 3427 |
/* send x/y events to make sure we reset the wheel */ |
| 3428 |
abs = libevdev_get_abs_info(dev->evdev, ABS_X); |
| 3429 |
litest_event(dev, EV_ABS, ABS_X, absinfo_range(abs) / i); |
| 3430 |
abs = libevdev_get_abs_info(dev->evdev, ABS_Y); |
| 3431 |
litest_event(dev, EV_ABS, ABS_Y, absinfo_range(abs) / i); |
| 3432 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3433 |
litest_dispatch(li); |
| 3434 |
|
| 3435 |
event = libinput_get_event(li); |
| 3436 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3437 |
litest_assert(!libinput_event_tablet_tool_wheel_has_changed(tev)); |
| 3438 |
|
| 3439 |
val = libinput_event_tablet_tool_get_wheel_delta(tev); |
| 3440 |
litest_assert_int_eq(val, 0); |
| 3441 |
|
| 3442 |
val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev); |
| 3443 |
litest_assert_int_eq(val, 0); |
| 3444 |
|
| 3445 |
libinput_event_destroy(event); |
| 3446 |
|
| 3447 |
litest_assert_empty_queue(li); |
| 3448 |
} |
| 3449 |
|
| 3450 |
libinput_tablet_tool_unref(tool); |
| 3451 |
} |
| 3452 |
END_TEST |
| 3453 |
|
| 3454 |
START_TEST(airbrush_tool) |
| 3455 |
{ |
| 3456 |
struct litest_device *dev = litest_current_device(); |
| 3457 |
struct libinput *li = dev->libinput; |
| 3458 |
struct libinput_event *event; |
| 3459 |
struct libinput_event_tablet_tool *tev; |
| 3460 |
struct libinput_tablet_tool *tool; |
| 3461 |
|
| 3462 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_AIRBRUSH)) |
| 3463 |
return LITEST_NOT_APPLICABLE; |
| 3464 |
|
| 3465 |
litest_drain_events(li); |
| 3466 |
|
| 3467 |
litest_event(dev, EV_KEY, BTN_TOOL_AIRBRUSH, 1); |
| 3468 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 3469 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3470 |
litest_dispatch(li); |
| 3471 |
|
| 3472 |
event = libinput_get_event(li); |
| 3473 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3474 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 3475 |
|
| 3476 |
litest_assert_notnull(tool); |
| 3477 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 3478 |
LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH); |
| 3479 |
|
| 3480 |
litest_assert(libinput_tablet_tool_has_slider(tool)); |
| 3481 |
|
| 3482 |
libinput_event_destroy(event); |
| 3483 |
} |
| 3484 |
END_TEST |
| 3485 |
|
| 3486 |
START_TEST(airbrush_slider) |
| 3487 |
{ |
| 3488 |
struct litest_device *dev = litest_current_device(); |
| 3489 |
struct libinput *li = dev->libinput; |
| 3490 |
struct libinput_event *event; |
| 3491 |
struct libinput_event_tablet_tool *tev; |
| 3492 |
const struct input_absinfo *abs; |
| 3493 |
double val; |
| 3494 |
int v; |
| 3495 |
|
| 3496 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_AIRBRUSH)) |
| 3497 |
return LITEST_NOT_APPLICABLE; |
| 3498 |
|
| 3499 |
litest_drain_events(li); |
| 3500 |
|
| 3501 |
abs = libevdev_get_abs_info(dev->evdev, ABS_WHEEL); |
| 3502 |
litest_assert_notnull(abs); |
| 3503 |
|
| 3504 |
litest_event(dev, EV_KEY, BTN_TOOL_AIRBRUSH, 1); |
| 3505 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 3506 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3507 |
|
| 3508 |
/* start with non-zero */ |
| 3509 |
litest_event(dev, EV_ABS, ABS_WHEEL, 10); |
| 3510 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3511 |
|
| 3512 |
litest_drain_events(li); |
| 3513 |
|
| 3514 |
for (v = abs->minimum; v < abs->maximum; v += 8) { |
| 3515 |
double expected = absinfo_normalize_value(abs, v) * 2 - 1; |
| 3516 |
litest_event(dev, EV_ABS, ABS_WHEEL, v); |
| 3517 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3518 |
litest_dispatch(li); |
| 3519 |
event = libinput_get_event(li); |
| 3520 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3521 |
litest_assert(libinput_event_tablet_tool_slider_has_changed(tev)); |
| 3522 |
val = libinput_event_tablet_tool_get_slider_position(tev); |
| 3523 |
|
| 3524 |
litest_assert_double_eq(val, expected); |
| 3525 |
litest_assert_double_ge(val, -1.0); |
| 3526 |
litest_assert_double_le(val, 1.0); |
| 3527 |
libinput_event_destroy(event); |
| 3528 |
litest_assert_empty_queue(li); |
| 3529 |
} |
| 3530 |
} |
| 3531 |
END_TEST |
| 3532 |
|
| 3533 |
START_TEST(artpen_tool) |
| 3534 |
{ |
| 3535 |
struct litest_device *dev = litest_current_device(); |
| 3536 |
struct libinput *li = dev->libinput; |
| 3537 |
struct libinput_event *event; |
| 3538 |
struct libinput_event_tablet_tool *tev; |
| 3539 |
struct libinput_tablet_tool *tool; |
| 3540 |
|
| 3541 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_Z)) |
| 3542 |
return LITEST_NOT_APPLICABLE; |
| 3543 |
|
| 3544 |
litest_drain_events(li); |
| 3545 |
|
| 3546 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 3547 |
litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */ |
| 3548 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 3549 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3550 |
litest_dispatch(li); |
| 3551 |
event = libinput_get_event(li); |
| 3552 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3553 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 3554 |
litest_assert_notnull(tool); |
| 3555 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 3556 |
LIBINPUT_TABLET_TOOL_TYPE_PEN); |
| 3557 |
litest_assert(libinput_tablet_tool_has_rotation(tool)); |
| 3558 |
|
| 3559 |
libinput_event_destroy(event); |
| 3560 |
} |
| 3561 |
END_TEST |
| 3562 |
|
| 3563 |
START_TEST(artpen_rotation) |
| 3564 |
{ |
| 3565 |
struct litest_device *dev = litest_current_device(); |
| 3566 |
struct libinput *li = dev->libinput; |
| 3567 |
struct libinput_event *event; |
| 3568 |
struct libinput_event_tablet_tool *tev; |
| 3569 |
const struct input_absinfo *abs; |
| 3570 |
double val; |
| 3571 |
double scale; |
| 3572 |
int angle; |
| 3573 |
|
| 3574 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_Z)) |
| 3575 |
return LITEST_NOT_APPLICABLE; |
| 3576 |
|
| 3577 |
litest_drain_events(li); |
| 3578 |
|
| 3579 |
abs = libevdev_get_abs_info(dev->evdev, ABS_Z); |
| 3580 |
litest_assert_notnull(abs); |
| 3581 |
scale = absinfo_range(abs) / 360.0; |
| 3582 |
|
| 3583 |
litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1); |
| 3584 |
litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */ |
| 3585 |
litest_event(dev, EV_MSC, MSC_SERIAL, 1000); |
| 3586 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3587 |
|
| 3588 |
litest_event(dev, EV_ABS, ABS_Z, abs->minimum); |
| 3589 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3590 |
|
| 3591 |
litest_drain_events(li); |
| 3592 |
|
| 3593 |
for (angle = 8; angle < 360; angle += 8) { |
| 3594 |
int a = angle * scale + abs->minimum; |
| 3595 |
|
| 3596 |
litest_event(dev, EV_ABS, ABS_Z, a); |
| 3597 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 3598 |
litest_dispatch(li); |
| 3599 |
event = libinput_get_event(li); |
| 3600 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3601 |
litest_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); |
| 3602 |
val = libinput_event_tablet_tool_get_rotation(tev); |
| 3603 |
|
| 3604 |
/* artpen has a 90 deg offset cw */ |
| 3605 |
litest_assert_int_eq(round(val), (angle + 90) % 360); |
| 3606 |
|
| 3607 |
libinput_event_destroy(event); |
| 3608 |
litest_assert_empty_queue(li); |
| 3609 |
} |
| 3610 |
} |
| 3611 |
END_TEST |
| 3612 |
|
| 3613 |
START_TEST(tablet_time_usec) |
| 3614 |
{ |
| 3615 |
struct litest_device *dev = litest_current_device(); |
| 3616 |
struct libinput *li = dev->libinput; |
| 3617 |
struct libinput_event *event; |
| 3618 |
struct libinput_event_tablet_tool *tev; |
| 3619 |
struct axis_replacement axes[] = { |
| 3620 |
{ ABS_DISTANCE, 10 }, |
| 3621 |
{ ABS_PRESSURE, 0 }, |
| 3622 |
{ -1, -1 }, |
| 3623 |
}; |
| 3624 |
uint64_t time_usec; |
| 3625 |
|
| 3626 |
litest_drain_events(li); |
| 3627 |
|
| 3628 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 3629 |
litest_dispatch(li); |
| 3630 |
|
| 3631 |
event = libinput_get_event(li); |
| 3632 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3633 |
time_usec = libinput_event_tablet_tool_get_time_usec(tev); |
| 3634 |
litest_assert_int_eq(libinput_event_tablet_tool_get_time(tev), |
| 3635 |
(uint32_t)(time_usec / 1000)); |
| 3636 |
libinput_event_destroy(event); |
| 3637 |
} |
| 3638 |
END_TEST |
| 3639 |
|
| 3640 |
START_TEST(tablet_pressure_distance_exclusive) |
| 3641 |
{ |
| 3642 |
struct litest_device *dev = litest_current_device(); |
| 3643 |
struct libinput *li = dev->libinput; |
| 3644 |
struct libinput_event *event; |
| 3645 |
struct libinput_event_tablet_tool *tev; |
| 3646 |
struct axis_replacement axes[] = { |
| 3647 |
{ ABS_DISTANCE, 10 }, |
| 3648 |
{ ABS_PRESSURE, 0 }, |
| 3649 |
{ -1, -1 }, |
| 3650 |
}; |
| 3651 |
double pressure, distance; |
| 3652 |
|
| 3653 |
litest_tablet_proximity_in(dev, 5, 50, axes); |
| 3654 |
litest_drain_events(li); |
| 3655 |
|
| 3656 |
/* We have 0.1% pressure above minimum threshold but we're still below |
| 3657 |
* the tip threshold */ |
| 3658 |
litest_axis_set_value(axes, ABS_PRESSURE, 1.1); |
| 3659 |
litest_tablet_motion(dev, 70, 70, axes); |
| 3660 |
litest_dispatch(li); |
| 3661 |
|
| 3662 |
event = libinput_get_event(li); |
| 3663 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3664 |
|
| 3665 |
pressure = libinput_event_tablet_tool_get_pressure(tev); |
| 3666 |
distance = libinput_event_tablet_tool_get_distance(tev); |
| 3667 |
|
| 3668 |
litest_assert_double_eq(pressure, 0.001); |
| 3669 |
litest_assert_double_eq(distance, 0.0); |
| 3670 |
libinput_event_destroy(event); |
| 3671 |
|
| 3672 |
/* We have pressure and we're above the tip threshold now */ |
| 3673 |
litest_axis_set_value(axes, ABS_PRESSURE, 5.5); |
| 3674 |
litest_tablet_motion(dev, 70, 70, axes); |
| 3675 |
litest_dispatch(li); |
| 3676 |
|
| 3677 |
event = libinput_get_event(li); |
| 3678 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 3679 |
|
| 3680 |
pressure = libinput_event_tablet_tool_get_pressure(tev); |
| 3681 |
distance = libinput_event_tablet_tool_get_distance(tev); |
| 3682 |
|
| 3683 |
litest_assert_double_gt(pressure, 0.0); |
| 3684 |
litest_assert_double_eq(distance, 0.0); |
| 3685 |
|
| 3686 |
libinput_event_destroy(event); |
| 3687 |
} |
| 3688 |
END_TEST |
| 3689 |
|
| 3690 |
static bool |
| 3691 |
device_has_calibration(struct litest_device *dev) |
| 3692 |
{ |
| 3693 |
|
| 3694 |
if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) |
| 3695 |
return true; |
| 3696 |
|
| 3697 |
bool has_calibration = |
| 3698 |
libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_PEN) || |
| 3699 |
libevdev_has_event_code(dev->evdev, EV_KEY, BTN_STYLUS); |
| 3700 |
|
| 3701 |
#ifdef HAVE_LIBWACOM |
| 3702 |
WacomDeviceDatabase *db = libwacom_database_new(); |
| 3703 |
if (db) { |
| 3704 |
WacomDevice *d = |
| 3705 |
libwacom_new_from_path(db, |
| 3706 |
libevdev_uinput_get_devnode(dev->uinput), |
| 3707 |
WFALLBACK_NONE, |
| 3708 |
NULL); |
| 3709 |
if (d) { |
| 3710 |
has_calibration = !!(libwacom_get_integration_flags(d) & |
| 3711 |
(WACOM_DEVICE_INTEGRATED_SYSTEM | |
| 3712 |
WACOM_DEVICE_INTEGRATED_DISPLAY)); |
| 3713 |
libwacom_destroy(d); |
| 3714 |
} |
| 3715 |
libwacom_database_destroy(db); |
| 3716 |
} |
| 3717 |
#endif |
| 3718 |
|
| 3719 |
return has_calibration; |
| 3720 |
} |
| 3721 |
|
| 3722 |
START_TEST(tablet_calibration_has_matrix) |
| 3723 |
{ |
| 3724 |
struct litest_device *dev = litest_current_device(); |
| 3725 |
struct libinput_device *d = dev->libinput_device; |
| 3726 |
enum libinput_config_status status; |
| 3727 |
int rc; |
| 3728 |
float calibration[6] = { 1, 0, 0, 0, 1, 0 }; |
| 3729 |
int has_calibration; |
| 3730 |
|
| 3731 |
has_calibration = device_has_calibration(dev); |
| 3732 |
|
| 3733 |
rc = libinput_device_config_calibration_has_matrix(d); |
| 3734 |
litest_assert_int_eq(rc, has_calibration); |
| 3735 |
rc = libinput_device_config_calibration_get_matrix(d, calibration); |
| 3736 |
litest_assert_int_eq(rc, 0); |
| 3737 |
rc = libinput_device_config_calibration_get_default_matrix(d, calibration); |
| 3738 |
litest_assert_int_eq(rc, 0); |
| 3739 |
|
| 3740 |
status = libinput_device_config_calibration_set_matrix(d, calibration); |
| 3741 |
if (has_calibration) |
| 3742 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 3743 |
else |
| 3744 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); |
| 3745 |
} |
| 3746 |
END_TEST |
| 3747 |
|
| 3748 |
START_TEST(tablet_calibration_set_matrix_delta) |
| 3749 |
{ |
| 3750 |
struct litest_device *dev = litest_current_device(); |
| 3751 |
struct libinput *li = dev->libinput; |
| 3752 |
struct libinput_device *d = dev->libinput_device; |
| 3753 |
enum libinput_config_status status; |
| 3754 |
float calibration[6] = { 0.5, 0, 0, 0, 0.5, 0 }; |
| 3755 |
struct libinput_event *event; |
| 3756 |
struct libinput_event_tablet_tool *tablet_event; |
| 3757 |
struct axis_replacement axes[] = { |
| 3758 |
{ ABS_DISTANCE, 0 }, |
| 3759 |
{ ABS_PRESSURE, 10 }, |
| 3760 |
{ -1, -1 }, |
| 3761 |
}; |
| 3762 |
double x, y, dx, dy, mdx, mdy; |
| 3763 |
|
| 3764 |
if (!device_has_calibration(dev)) |
| 3765 |
return LITEST_NOT_APPLICABLE; |
| 3766 |
|
| 3767 |
litest_drain_events(li); |
| 3768 |
|
| 3769 |
litest_tablet_proximity_in(dev, 100, 100, axes); |
| 3770 |
litest_tablet_tip_down(dev, 100, 100, axes); |
| 3771 |
litest_dispatch(li); |
| 3772 |
event = libinput_get_event(li); |
| 3773 |
tablet_event = |
| 3774 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3775 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 3776 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 3777 |
libinput_event_destroy(event); |
| 3778 |
|
| 3779 |
event = libinput_get_event(li); |
| 3780 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 3781 |
libinput_event_destroy(event); |
| 3782 |
|
| 3783 |
litest_tablet_motion(dev, 80, 80, axes); |
| 3784 |
litest_dispatch(li); |
| 3785 |
|
| 3786 |
event = libinput_get_event(li); |
| 3787 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3788 |
|
| 3789 |
dx = libinput_event_tablet_tool_get_x(tablet_event) - x; |
| 3790 |
dy = libinput_event_tablet_tool_get_y(tablet_event) - y; |
| 3791 |
libinput_event_destroy(event); |
| 3792 |
litest_tablet_tip_up(dev, 80, 80, axes); |
| 3793 |
litest_tablet_proximity_out(dev); |
| 3794 |
litest_timeout_tablet_proxout(li); |
| 3795 |
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3796 |
litest_drain_events(li); |
| 3797 |
|
| 3798 |
status = libinput_device_config_calibration_set_matrix(d, calibration); |
| 3799 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 3800 |
|
| 3801 |
litest_tablet_proximity_in(dev, 100, 100, axes); |
| 3802 |
litest_tablet_tip_down(dev, 100, 100, axes); |
| 3803 |
litest_dispatch(li); |
| 3804 |
event = libinput_get_event(li); |
| 3805 |
tablet_event = |
| 3806 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3807 |
x = libinput_event_tablet_tool_get_x(tablet_event); |
| 3808 |
y = libinput_event_tablet_tool_get_y(tablet_event); |
| 3809 |
libinput_event_destroy(event); |
| 3810 |
|
| 3811 |
event = libinput_get_event(li); |
| 3812 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 3813 |
libinput_event_destroy(event); |
| 3814 |
|
| 3815 |
litest_tablet_motion(dev, 80, 80, axes); |
| 3816 |
litest_dispatch(li); |
| 3817 |
|
| 3818 |
event = libinput_get_event(li); |
| 3819 |
tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 3820 |
|
| 3821 |
mdx = libinput_event_tablet_tool_get_x(tablet_event) - x; |
| 3822 |
mdy = libinput_event_tablet_tool_get_y(tablet_event) - y; |
| 3823 |
libinput_event_destroy(event); |
| 3824 |
litest_drain_events(li); |
| 3825 |
|
| 3826 |
litest_assert_double_gt(dx, mdx * 2 - 1); |
| 3827 |
litest_assert_double_lt(dx, mdx * 2 + 1); |
| 3828 |
litest_assert_double_gt(dy, mdy * 2 - 1); |
| 3829 |
litest_assert_double_lt(dy, mdy * 2 + 1); |
| 3830 |
} |
| 3831 |
END_TEST |
| 3832 |
|
| 3833 |
START_TEST(tablet_calibration_set_matrix) |
| 3834 |
{ |
| 3835 |
struct litest_device *dev = litest_current_device(); |
| 3836 |
struct libinput *li = dev->libinput; |
| 3837 |
struct libinput_device *d = dev->libinput_device; |
| 3838 |
enum libinput_config_status status; |
| 3839 |
float calibration[6] = { 0.5, 0, 0, 0, 1, 0 }; |
| 3840 |
struct libinput_event *event; |
| 3841 |
struct libinput_event_tablet_tool *tablet_event; |
| 3842 |
struct axis_replacement axes[] = { |
| 3843 |
{ ABS_DISTANCE, 10 }, |
| 3844 |
{ ABS_PRESSURE, 0 }, |
| 3845 |
{ -1, -1 }, |
| 3846 |
}; |
| 3847 |
double x, y; |
| 3848 |
|
| 3849 |
if (!device_has_calibration(dev)) |
| 3850 |
return LITEST_NOT_APPLICABLE; |
| 3851 |
|
| 3852 |
litest_drain_events(li); |
| 3853 |
|
| 3854 |
status = libinput_device_config_calibration_set_matrix(d, calibration); |
| 3855 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 3856 |
|
| 3857 |
litest_tablet_proximity_in(dev, 100, 100, axes); |
| 3858 |
litest_dispatch(li); |
| 3859 |
|
| 3860 |
event = libinput_get_event(li); |
| 3861 |
tablet_event = |
| 3862 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3863 |
x = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); |
| 3864 |
y = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); |
| 3865 |
libinput_event_destroy(event); |
| 3866 |
|
| 3867 |
litest_assert_double_gt(x, 49.0); |
| 3868 |
litest_assert_double_lt(x, 51.0); |
| 3869 |
litest_assert_double_gt(y, 99.0); |
| 3870 |
litest_assert_double_lt(y, 100.0); |
| 3871 |
|
| 3872 |
litest_tablet_proximity_out(dev); |
| 3873 |
litest_timeout_tablet_proxout(li); |
| 3874 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 3875 |
litest_tablet_proximity_out(dev); |
| 3876 |
litest_timeout_tablet_proxout(li); |
| 3877 |
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3878 |
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3879 |
litest_drain_events(li); |
| 3880 |
|
| 3881 |
calibration[0] = 1; |
| 3882 |
calibration[4] = 0.5; |
| 3883 |
status = libinput_device_config_calibration_set_matrix(d, calibration); |
| 3884 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 3885 |
|
| 3886 |
litest_tablet_proximity_in(dev, 100, 100, axes); |
| 3887 |
litest_dispatch(li); |
| 3888 |
|
| 3889 |
event = libinput_get_event(li); |
| 3890 |
tablet_event = |
| 3891 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 3892 |
x = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); |
| 3893 |
y = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); |
| 3894 |
libinput_event_destroy(event); |
| 3895 |
|
| 3896 |
litest_assert(x > 99.0); |
| 3897 |
litest_assert(x < 100.0); |
| 3898 |
litest_assert(y > 49.0); |
| 3899 |
litest_assert(y < 51.0); |
| 3900 |
|
| 3901 |
litest_tablet_proximity_out(dev); |
| 3902 |
litest_timeout_tablet_proxout(li); |
| 3903 |
} |
| 3904 |
END_TEST |
| 3905 |
|
| 3906 |
START_TEST(tablet_area_has_rectangle) |
| 3907 |
{ |
| 3908 |
struct litest_device *dev = litest_current_device(); |
| 3909 |
struct libinput_device *d = dev->libinput_device; |
| 3910 |
enum libinput_config_status status; |
| 3911 |
int rc; |
| 3912 |
struct libinput_config_area_rectangle rect; |
| 3913 |
|
| 3914 |
int has_area = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); |
| 3915 |
|
| 3916 |
rc = libinput_device_config_area_has_rectangle(d); |
| 3917 |
litest_assert_int_eq(rc, has_area); |
| 3918 |
rect = libinput_device_config_area_get_rectangle(d); |
| 3919 |
litest_assert_double_eq(rect.x1, 0.0); |
| 3920 |
litest_assert_double_eq(rect.y1, 0.0); |
| 3921 |
litest_assert_double_eq(rect.x2, 1.0); |
| 3922 |
litest_assert_double_eq(rect.y2, 1.0); |
| 3923 |
|
| 3924 |
rect = libinput_device_config_area_get_default_rectangle(d); |
| 3925 |
litest_assert_double_eq(rect.x1, 0.0); |
| 3926 |
litest_assert_double_eq(rect.y1, 0.0); |
| 3927 |
litest_assert_double_eq(rect.x2, 1.0); |
| 3928 |
litest_assert_double_eq(rect.y2, 1.0); |
| 3929 |
|
| 3930 |
status = libinput_device_config_area_set_rectangle(d, &rect); |
| 3931 |
if (has_area) |
| 3932 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 3933 |
else |
| 3934 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); |
| 3935 |
} |
| 3936 |
END_TEST |
| 3937 |
|
| 3938 |
START_TEST(tablet_area_set_rectangle_invalid) |
| 3939 |
{ |
| 3940 |
struct litest_device *dev = litest_current_device(); |
| 3941 |
struct libinput_device *d = dev->libinput_device; |
| 3942 |
int rc; |
| 3943 |
struct libinput_config_area_rectangle rect; |
| 3944 |
|
| 3945 |
int has_area = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); |
| 3946 |
if (!has_area) |
| 3947 |
return LITEST_NOT_APPLICABLE; |
| 3948 |
|
| 3949 |
rect.x1 = 1.0; |
| 3950 |
rect.x2 = 0.9; |
| 3951 |
rect.y1 = 0.0; |
| 3952 |
rect.y2 = 1.0; |
| 3953 |
|
| 3954 |
rc = libinput_device_config_area_set_rectangle(d, &rect); |
| 3955 |
litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); |
| 3956 |
|
| 3957 |
rect.x1 = 0.9; |
| 3958 |
rect.x2 = 1.0; |
| 3959 |
rect.y1 = 1.0; |
| 3960 |
rect.y2 = 0.9; |
| 3961 |
|
| 3962 |
rc = libinput_device_config_area_set_rectangle(d, &rect); |
| 3963 |
litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); |
| 3964 |
|
| 3965 |
rect.x1 = 0.9; |
| 3966 |
rect.x2 = 0.9; |
| 3967 |
rect.y1 = 0.9; |
| 3968 |
rect.y2 = 1.0; |
| 3969 |
|
| 3970 |
rc = libinput_device_config_area_set_rectangle(d, &rect); |
| 3971 |
litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); |
| 3972 |
|
| 3973 |
rect.x1 = 0.9; |
| 3974 |
rect.x2 = 1.0; |
| 3975 |
rect.y1 = 0.9; |
| 3976 |
rect.y2 = 0.9; |
| 3977 |
|
| 3978 |
rc = libinput_device_config_area_set_rectangle(d, &rect); |
| 3979 |
litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); |
| 3980 |
|
| 3981 |
rect.x1 = 0.9; |
| 3982 |
rect.x2 = 1.5; |
| 3983 |
rect.y1 = 0.0; |
| 3984 |
rect.y2 = 1.0; |
| 3985 |
|
| 3986 |
rc = libinput_device_config_area_set_rectangle(d, &rect); |
| 3987 |
litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); |
| 3988 |
|
| 3989 |
rect.x1 = 0.0; |
| 3990 |
rect.x2 = 1.0; |
| 3991 |
rect.y1 = 0.9; |
| 3992 |
rect.y2 = 1.4; |
| 3993 |
|
| 3994 |
rc = libinput_device_config_area_set_rectangle(d, &rect); |
| 3995 |
litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); |
| 3996 |
} |
| 3997 |
END_TEST |
| 3998 |
|
| 3999 |
static void |
| 4000 |
get_tool_xy(struct libinput *li, double *x, double *y) |
| 4001 |
{ |
| 4002 |
struct libinput_event *event = libinput_get_event(li); |
| 4003 |
struct libinput_event_tablet_tool *tev; |
| 4004 |
|
| 4005 |
litest_assert_ptr_notnull(event); |
| 4006 |
|
| 4007 |
switch (libinput_event_get_type(event)) { |
| 4008 |
case LIBINPUT_EVENT_TABLET_TOOL_AXIS: |
| 4009 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4010 |
break; |
| 4011 |
case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: |
| 4012 |
tev = litest_is_tablet_event(event, |
| 4013 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 4014 |
break; |
| 4015 |
default: |
| 4016 |
litest_assert_not_reached(); |
| 4017 |
} |
| 4018 |
|
| 4019 |
*x = libinput_event_tablet_tool_get_x_transformed(tev, 100); |
| 4020 |
*y = libinput_event_tablet_tool_get_y_transformed(tev, 100); |
| 4021 |
libinput_event_destroy(event); |
| 4022 |
} |
| 4023 |
|
| 4024 |
START_TEST(tablet_area_set_rectangle) |
| 4025 |
{ |
| 4026 |
struct litest_device *dev = litest_current_device(); |
| 4027 |
struct libinput *li = dev->libinput; |
| 4028 |
struct libinput_device *d = dev->libinput_device; |
| 4029 |
struct axis_replacement axes[] = { |
| 4030 |
{ ABS_DISTANCE, 10 }, |
| 4031 |
{ ABS_PRESSURE, 0 }, |
| 4032 |
{ -1, -1 }, |
| 4033 |
}; |
| 4034 |
double x, y; |
| 4035 |
double *scaled, *unscaled; |
| 4036 |
|
| 4037 |
const char *param_axis = litest_test_param_get_string(test_env->params, "axis"); |
| 4038 |
const char *param_direction = |
| 4039 |
litest_test_param_get_string(test_env->params, "direction"); |
| 4040 |
|
| 4041 |
bool use_vertical = streq(param_axis, "vertical"); |
| 4042 |
int direction = streq(param_direction, "down") ? 1 : -1; |
| 4043 |
|
| 4044 |
if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) |
| 4045 |
return LITEST_NOT_APPLICABLE; |
| 4046 |
|
| 4047 |
struct libinput_config_area_rectangle rect; |
| 4048 |
if (use_vertical) { |
| 4049 |
rect = (struct libinput_config_area_rectangle){ |
| 4050 |
0.25, |
| 4051 |
0.0, |
| 4052 |
0.75, |
| 4053 |
1.0, |
| 4054 |
}; |
| 4055 |
scaled = &x; |
| 4056 |
unscaled = &y; |
| 4057 |
} else { |
| 4058 |
rect = (struct libinput_config_area_rectangle){ |
| 4059 |
0.0, |
| 4060 |
0.25, |
| 4061 |
1.0, |
| 4062 |
0.75, |
| 4063 |
}; |
| 4064 |
scaled = &y; |
| 4065 |
unscaled = &x; |
| 4066 |
} |
| 4067 |
|
| 4068 |
enum libinput_config_status status = |
| 4069 |
libinput_device_config_area_set_rectangle(d, &rect); |
| 4070 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4071 |
|
| 4072 |
litest_drain_events(li); |
| 4073 |
|
| 4074 |
/* move from the center out */ |
| 4075 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 4076 |
litest_dispatch(li); |
| 4077 |
get_tool_xy(li, &x, &y); |
| 4078 |
litest_assert_double_eq_epsilon(*scaled, 50.0, 2); |
| 4079 |
litest_assert_double_eq_epsilon(*unscaled, 50.0, 2); |
| 4080 |
|
| 4081 |
int i; |
| 4082 |
for (i = 50; i > 0 && i <= 100; i += 5 * direction) { |
| 4083 |
/* Negate any smoothing */ |
| 4084 |
litest_tablet_motion(dev, i, i, axes); |
| 4085 |
litest_tablet_motion(dev, i - 1, i, axes); |
| 4086 |
litest_tablet_motion(dev, i, i - 1, axes); |
| 4087 |
litest_drain_events(li); |
| 4088 |
|
| 4089 |
litest_tablet_motion(dev, i, i, axes); |
| 4090 |
litest_dispatch(li); |
| 4091 |
get_tool_xy(li, &x, &y); |
| 4092 |
if (i <= 25) |
| 4093 |
litest_assert_double_eq(*scaled, 0.0); |
| 4094 |
else if (i > 75) |
| 4095 |
litest_assert_double_eq_epsilon(*scaled, 100.0, 1); |
| 4096 |
else |
| 4097 |
litest_assert_double_eq_epsilon(*scaled, (i - 25) * 2, 1); |
| 4098 |
litest_assert_double_eq_epsilon(*unscaled, i, 2); |
| 4099 |
} |
| 4100 |
|
| 4101 |
double final_stop = max(0.0, min(100.0, i)); |
| 4102 |
/* Push through any smoothing */ |
| 4103 |
litest_tablet_motion(dev, final_stop, final_stop, axes); |
| 4104 |
litest_tablet_motion(dev, final_stop, final_stop, axes); |
| 4105 |
litest_dispatch(li); |
| 4106 |
litest_drain_events(li); |
| 4107 |
|
| 4108 |
litest_tablet_proximity_out(dev); |
| 4109 |
litest_timeout_tablet_proxout(li); |
| 4110 |
get_tool_xy(li, &x, &y); |
| 4111 |
litest_assert_double_eq_epsilon(x, final_stop, 1); |
| 4112 |
litest_assert_double_eq_epsilon(y, final_stop, 1); |
| 4113 |
} |
| 4114 |
END_TEST |
| 4115 |
|
| 4116 |
START_TEST(tablet_area_set_rectangle_move_outside) |
| 4117 |
{ |
| 4118 |
struct litest_device *dev = litest_current_device(); |
| 4119 |
struct libinput *li = dev->libinput; |
| 4120 |
struct libinput_device *d = dev->libinput_device; |
| 4121 |
struct axis_replacement axes[] = { |
| 4122 |
{ ABS_DISTANCE, 10 }, |
| 4123 |
{ ABS_PRESSURE, 0 }, |
| 4124 |
{ -1, -1 }, |
| 4125 |
}; |
| 4126 |
double x, y; |
| 4127 |
|
| 4128 |
if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) |
| 4129 |
return LITEST_NOT_APPLICABLE; |
| 4130 |
|
| 4131 |
struct libinput_config_area_rectangle rect = { |
| 4132 |
0.25, |
| 4133 |
0.25, |
| 4134 |
0.75, |
| 4135 |
0.75, |
| 4136 |
}; |
| 4137 |
|
| 4138 |
enum libinput_config_status status = |
| 4139 |
libinput_device_config_area_set_rectangle(d, &rect); |
| 4140 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4141 |
|
| 4142 |
litest_drain_events(li); |
| 4143 |
|
| 4144 |
/* move in/out of prox outside the area */ |
| 4145 |
litest_tablet_proximity_in(dev, 5, 5, axes); |
| 4146 |
litest_tablet_proximity_out(dev); |
| 4147 |
litest_timeout_tablet_proxout(li); |
| 4148 |
litest_assert_empty_queue(li); |
| 4149 |
|
| 4150 |
x = 5; |
| 4151 |
y = 5; |
| 4152 |
/* Move around the area - since we stay outside the area expect no events */ |
| 4153 |
litest_tablet_proximity_in(dev, x, y, axes); |
| 4154 |
litest_dispatch(li); |
| 4155 |
for (; x < 90; x += 5) { |
| 4156 |
litest_tablet_motion(dev, x, y, axes); |
| 4157 |
litest_dispatch(li); |
| 4158 |
litest_assert_empty_queue(li); |
| 4159 |
} |
| 4160 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 4161 |
litest_tablet_tip_down(dev, x, y, axes); |
| 4162 |
for (; y < 90; y += 5) { |
| 4163 |
litest_tablet_motion(dev, x, y, axes); |
| 4164 |
litest_dispatch(li); |
| 4165 |
litest_assert_empty_queue(li); |
| 4166 |
} |
| 4167 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 4168 |
litest_tablet_tip_up(dev, x, y, axes); |
| 4169 |
for (; x > 5; x -= 5) { |
| 4170 |
litest_tablet_motion(dev, x, y, axes); |
| 4171 |
litest_dispatch(li); |
| 4172 |
litest_assert_empty_queue(li); |
| 4173 |
} |
| 4174 |
litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); |
| 4175 |
litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); |
| 4176 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 4177 |
litest_tablet_tip_down(dev, x, y, axes); |
| 4178 |
for (; y > 5; y -= 5) { |
| 4179 |
litest_tablet_motion(dev, x, y, axes); |
| 4180 |
litest_dispatch(li); |
| 4181 |
litest_assert_empty_queue(li); |
| 4182 |
} |
| 4183 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 4184 |
litest_tablet_tip_up(dev, x, y, axes); |
| 4185 |
|
| 4186 |
litest_tablet_proximity_out(dev); |
| 4187 |
litest_timeout_tablet_proxout(li); |
| 4188 |
litest_assert_empty_queue(li); |
| 4189 |
} |
| 4190 |
END_TEST |
| 4191 |
|
| 4192 |
START_TEST(tablet_area_set_rectangle_move_outside_to_inside) |
| 4193 |
{ |
| 4194 |
struct litest_device *dev = litest_current_device(); |
| 4195 |
struct libinput *li = dev->libinput; |
| 4196 |
struct libinput_device *d = dev->libinput_device; |
| 4197 |
struct axis_replacement axes[] = { |
| 4198 |
{ ABS_DISTANCE, 10 }, |
| 4199 |
{ ABS_PRESSURE, 0 }, |
| 4200 |
{ -1, -1 }, |
| 4201 |
}; |
| 4202 |
double x, y; |
| 4203 |
|
| 4204 |
if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) |
| 4205 |
return LITEST_NOT_APPLICABLE; |
| 4206 |
|
| 4207 |
struct libinput_config_area_rectangle rect = { |
| 4208 |
0.25, |
| 4209 |
0.25, |
| 4210 |
0.75, |
| 4211 |
0.75, |
| 4212 |
}; |
| 4213 |
|
| 4214 |
enum libinput_config_status status = |
| 4215 |
libinput_device_config_area_set_rectangle(d, &rect); |
| 4216 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4217 |
|
| 4218 |
litest_drain_events(li); |
| 4219 |
|
| 4220 |
x = 5; |
| 4221 |
y = 50; |
| 4222 |
/* Move into the center of the area - since we started outside the area |
| 4223 |
* expect no events */ |
| 4224 |
litest_tablet_proximity_in(dev, x, y, axes); |
| 4225 |
litest_dispatch(li); |
| 4226 |
for (; x < 50; x += 5) { |
| 4227 |
litest_tablet_motion(dev, x, y, axes); |
| 4228 |
litest_dispatch(li); |
| 4229 |
litest_assert_empty_queue(li); |
| 4230 |
} |
| 4231 |
litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); |
| 4232 |
litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); |
| 4233 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 4234 |
litest_tablet_tip_down(dev, x, y, axes); |
| 4235 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 4236 |
litest_tablet_tip_up(dev, x, y, axes); |
| 4237 |
litest_tablet_proximity_out(dev); |
| 4238 |
litest_timeout_tablet_proxout(li); |
| 4239 |
litest_assert_empty_queue(li); |
| 4240 |
|
| 4241 |
y = 5; |
| 4242 |
x = 50; |
| 4243 |
litest_tablet_proximity_in(dev, x, y, axes); |
| 4244 |
for (; y < 50; y += 5) { |
| 4245 |
litest_tablet_motion(dev, x, y, axes); |
| 4246 |
litest_dispatch(li); |
| 4247 |
litest_assert_empty_queue(li); |
| 4248 |
} |
| 4249 |
litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); |
| 4250 |
litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); |
| 4251 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 4252 |
litest_tablet_tip_down(dev, x, y, axes); |
| 4253 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 4254 |
litest_tablet_tip_up(dev, x, y, axes); |
| 4255 |
litest_tablet_proximity_out(dev); |
| 4256 |
litest_timeout_tablet_proxout(li); |
| 4257 |
litest_assert_empty_queue(li); |
| 4258 |
} |
| 4259 |
END_TEST |
| 4260 |
|
| 4261 |
START_TEST(tablet_area_set_rectangle_move_in_margin) |
| 4262 |
{ |
| 4263 |
struct litest_device *dev = litest_current_device(); |
| 4264 |
struct libinput *li = dev->libinput; |
| 4265 |
struct libinput_device *d = dev->libinput_device; |
| 4266 |
struct libinput_event *ev; |
| 4267 |
struct libinput_event_tablet_tool *tev; |
| 4268 |
struct axis_replacement axes[] = { |
| 4269 |
{ ABS_DISTANCE, 10 }, |
| 4270 |
{ ABS_PRESSURE, 0 }, |
| 4271 |
{ -1, -1 }, |
| 4272 |
}; |
| 4273 |
double x, y; |
| 4274 |
|
| 4275 |
if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) |
| 4276 |
return LITEST_NOT_APPLICABLE; |
| 4277 |
|
| 4278 |
struct libinput_config_area_rectangle rect = { |
| 4279 |
0.25, |
| 4280 |
0.25, |
| 4281 |
0.75, |
| 4282 |
0.75, |
| 4283 |
}; |
| 4284 |
|
| 4285 |
enum libinput_config_status status = |
| 4286 |
libinput_device_config_area_set_rectangle(d, &rect); |
| 4287 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4288 |
|
| 4289 |
litest_drain_events(li); |
| 4290 |
|
| 4291 |
/* move in/out of prox outside the area but within the margin */ |
| 4292 |
litest_tablet_proximity_in(dev, 24, 24, axes); |
| 4293 |
litest_tablet_proximity_out(dev); |
| 4294 |
litest_timeout_tablet_proxout(li); |
| 4295 |
|
| 4296 |
ev = libinput_get_event(li); |
| 4297 |
tev = litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 4298 |
x = libinput_event_tablet_tool_get_x(tev); |
| 4299 |
y = libinput_event_tablet_tool_get_y(tev); |
| 4300 |
litest_assert_double_eq(x, 0.0); |
| 4301 |
litest_assert_double_eq(y, 0.0); |
| 4302 |
libinput_event_destroy(ev); |
| 4303 |
ev = libinput_get_event(li); |
| 4304 |
tev = litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 4305 |
x = libinput_event_tablet_tool_get_x(tev); |
| 4306 |
y = libinput_event_tablet_tool_get_y(tev); |
| 4307 |
litest_assert_double_eq(x, 0.0); |
| 4308 |
litest_assert_double_eq(y, 0.0); |
| 4309 |
libinput_event_destroy(ev); |
| 4310 |
} |
| 4311 |
END_TEST |
| 4312 |
|
| 4313 |
START_TEST(tablet_area_set_rectangle_while_outside) |
| 4314 |
{ |
| 4315 |
struct litest_device *dev = litest_current_device(); |
| 4316 |
struct libinput *li = dev->libinput; |
| 4317 |
struct libinput_device *d = dev->libinput_device; |
| 4318 |
struct libinput_event *ev; |
| 4319 |
struct libinput_event_tablet_tool *tev; |
| 4320 |
struct axis_replacement axes[] = { |
| 4321 |
{ ABS_DISTANCE, 10 }, |
| 4322 |
{ ABS_PRESSURE, 0 }, |
| 4323 |
{ -1, -1 }, |
| 4324 |
}; |
| 4325 |
double x, y; |
| 4326 |
|
| 4327 |
if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) |
| 4328 |
return LITEST_NOT_APPLICABLE; |
| 4329 |
|
| 4330 |
litest_checkpoint("Set tablet area"); |
| 4331 |
struct libinput_config_area_rectangle rect = { |
| 4332 |
0.25, |
| 4333 |
0.25, |
| 4334 |
0.75, |
| 4335 |
0.75, |
| 4336 |
}; |
| 4337 |
|
| 4338 |
enum libinput_config_status status = |
| 4339 |
libinput_device_config_area_set_rectangle(d, &rect); |
| 4340 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4341 |
|
| 4342 |
litest_drain_events(li); |
| 4343 |
|
| 4344 |
litest_checkpoint("Proximity in + out outside tablet area"); |
| 4345 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 4346 |
litest_tablet_proximity_out(dev); |
| 4347 |
litest_timeout_tablet_proxout(li); |
| 4348 |
litest_assert_empty_queue(li); |
| 4349 |
litest_dispatch(li); |
| 4350 |
|
| 4351 |
litest_checkpoint("Update tablet area"); |
| 4352 |
rect = (struct libinput_config_area_rectangle){ |
| 4353 |
0.05, |
| 4354 |
0.05, |
| 4355 |
0.95, |
| 4356 |
0.95, |
| 4357 |
}; |
| 4358 |
|
| 4359 |
status = libinput_device_config_area_set_rectangle(d, &rect); |
| 4360 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4361 |
|
| 4362 |
litest_checkpoint("Proximity in + out inside tablet area"); |
| 4363 |
litest_tablet_proximity_in(dev, 11, 11, axes); |
| 4364 |
litest_tablet_motion(dev, 12, 12, axes); |
| 4365 |
litest_tablet_proximity_out(dev); |
| 4366 |
litest_timeout_tablet_proxout(li); |
| 4367 |
|
| 4368 |
ev = libinput_get_event(li); |
| 4369 |
tev = litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 4370 |
x = libinput_event_tablet_tool_get_x_transformed(tev, 100.0); |
| 4371 |
y = libinput_event_tablet_tool_get_y_transformed(tev, 100.0); |
| 4372 |
litest_assert_double_gt( |
| 4373 |
x, |
| 4374 |
6); /* somewhere around 6%, precise number doesn't matter */ |
| 4375 |
litest_assert_double_gt(y, 6); |
| 4376 |
libinput_event_destroy(ev); |
| 4377 |
|
| 4378 |
ev = libinput_get_event(li); |
| 4379 |
tev = litest_is_tablet_event(ev, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4380 |
x = libinput_event_tablet_tool_get_x_transformed(tev, 100.0); |
| 4381 |
y = libinput_event_tablet_tool_get_y_transformed(tev, 100.0); |
| 4382 |
litest_assert_double_gt(x, 6); |
| 4383 |
litest_assert_double_gt(y, 6); |
| 4384 |
libinput_event_destroy(ev); |
| 4385 |
|
| 4386 |
ev = libinput_get_event(li); |
| 4387 |
tev = litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 4388 |
x = libinput_event_tablet_tool_get_x_transformed(tev, 100.0); |
| 4389 |
y = libinput_event_tablet_tool_get_y_transformed(tev, 100.0); |
| 4390 |
litest_assert_double_gt(x, 6); |
| 4391 |
litest_assert_double_gt(y, 6); |
| 4392 |
libinput_event_destroy(ev); |
| 4393 |
} |
| 4394 |
END_TEST |
| 4395 |
|
| 4396 |
static void |
| 4397 |
assert_pressure(struct libinput *li, |
| 4398 |
enum libinput_event_type type, |
| 4399 |
double expected_pressure) |
| 4400 |
{ |
| 4401 |
struct libinput_event *event = libinput_get_event(li); |
| 4402 |
struct libinput_event_tablet_tool *tev = litest_is_tablet_event(event, type); |
| 4403 |
double pressure = libinput_event_tablet_tool_get_pressure(tev); |
| 4404 |
litest_assert_double_eq_epsilon(pressure, expected_pressure, 0.01); |
| 4405 |
libinput_event_destroy(event); |
| 4406 |
} |
| 4407 |
|
| 4408 |
START_TEST(tablet_pressure_offset_set) |
| 4409 |
{ |
| 4410 |
struct litest_device *dev = litest_current_device(); |
| 4411 |
struct libinput *li = dev->libinput; |
| 4412 |
struct libinput_event *event; |
| 4413 |
struct axis_replacement axes[] = { |
| 4414 |
{ ABS_DISTANCE, 70 }, |
| 4415 |
{ ABS_PRESSURE, 20 }, |
| 4416 |
{ -1, -1 }, |
| 4417 |
}; |
| 4418 |
|
| 4419 |
litest_drain_events(li); |
| 4420 |
|
| 4421 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_DISTANCE)) { |
| 4422 |
/* First two prox ins won't do anything, coming with 10% should give |
| 4423 |
* us ~10% pressure */ |
| 4424 |
for (int i = 0; i < 2; i++) { |
| 4425 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4426 |
litest_dispatch(li); |
| 4427 |
|
| 4428 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.20); |
| 4429 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.20); |
| 4430 |
litest_tablet_proximity_out(dev); |
| 4431 |
litest_timeout_tablet_proxout(li); |
| 4432 |
litest_drain_events(li); |
| 4433 |
} |
| 4434 |
} |
| 4435 |
|
| 4436 |
/* This activates the pressure offset */ |
| 4437 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4438 |
litest_drain_events(li); |
| 4439 |
|
| 4440 |
/* Put the pen down, with a pressure high enough to meet the |
| 4441 |
* new offset */ |
| 4442 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 4443 |
litest_axis_set_value(axes, ABS_PRESSURE, 26); |
| 4444 |
|
| 4445 |
/* Tablet motion above threshold should trigger axis + tip down. Use |
| 4446 |
* the litest motion helper here to avoid false positives caused by |
| 4447 |
* BTN_TOUCH */ |
| 4448 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4449 |
litest_dispatch(li); |
| 4450 |
event = libinput_get_event(li); |
| 4451 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 4452 |
libinput_event_destroy(event); |
| 4453 |
|
| 4454 |
/* Reduce pressure to just a tick over the offset, otherwise we get |
| 4455 |
* the tip up event again */ |
| 4456 |
litest_axis_set_value(axes, ABS_PRESSURE, 20.1); |
| 4457 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4458 |
litest_dispatch(li); |
| 4459 |
|
| 4460 |
/* we can't actually get a real 0.0 because that would trigger a tip |
| 4461 |
up. but it's close enough to zero. */ |
| 4462 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.01); |
| 4463 |
litest_drain_events(li); |
| 4464 |
|
| 4465 |
litest_axis_set_value(axes, ABS_PRESSURE, 21); |
| 4466 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4467 |
|
| 4468 |
litest_dispatch(li); |
| 4469 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.015); |
| 4470 |
|
| 4471 |
/* Make sure we can reach the upper range too */ |
| 4472 |
litest_axis_set_value(axes, ABS_PRESSURE, 100); |
| 4473 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4474 |
|
| 4475 |
litest_dispatch(li); |
| 4476 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 1.0); |
| 4477 |
|
| 4478 |
/* Tablet motion at offset should trigger tip up. Use |
| 4479 |
* the litest motion helper here to avoid false positives caused by |
| 4480 |
* BTN_TOUCH */ |
| 4481 |
litest_axis_set_value(axes, ABS_PRESSURE, 20); |
| 4482 |
litest_tablet_motion(dev, 71, 71, axes); |
| 4483 |
litest_dispatch(li); |
| 4484 |
event = libinput_get_event(li); |
| 4485 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 4486 |
libinput_event_destroy(event); |
| 4487 |
} |
| 4488 |
END_TEST |
| 4489 |
|
| 4490 |
START_TEST(tablet_pressure_offset_decrease) |
| 4491 |
{ |
| 4492 |
struct litest_device *dev = litest_current_device(); |
| 4493 |
struct libinput *li = dev->libinput; |
| 4494 |
struct axis_replacement axes[] = { |
| 4495 |
{ ABS_DISTANCE, 70 }, |
| 4496 |
{ ABS_PRESSURE, 20 }, |
| 4497 |
{ -1, -1 }, |
| 4498 |
}; |
| 4499 |
|
| 4500 |
/* offset 20 on prox in */ |
| 4501 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4502 |
litest_tablet_proximity_out(dev); |
| 4503 |
litest_timeout_tablet_proxout(li); |
| 4504 |
litest_drain_events(li); |
| 4505 |
|
| 4506 |
/* offset 15 on prox in - this one is so we trigger on the next prox |
| 4507 |
* in for the no-distance tablets */ |
| 4508 |
litest_axis_set_value(axes, ABS_PRESSURE, 15); |
| 4509 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4510 |
litest_tablet_proximity_out(dev); |
| 4511 |
litest_timeout_tablet_proxout(li); |
| 4512 |
litest_drain_events(li); |
| 4513 |
|
| 4514 |
/* a reduced pressure value must reduce the offset */ |
| 4515 |
litest_axis_set_value(axes, ABS_PRESSURE, 10); |
| 4516 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4517 |
litest_tablet_proximity_out(dev); |
| 4518 |
litest_timeout_tablet_proxout(li); |
| 4519 |
litest_drain_events(li); |
| 4520 |
|
| 4521 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4522 |
litest_dispatch(li); |
| 4523 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.0); |
| 4524 |
litest_drain_events(li); |
| 4525 |
|
| 4526 |
/* trigger the pressure threshold */ |
| 4527 |
litest_axis_set_value(axes, ABS_PRESSURE, 15); |
| 4528 |
litest_tablet_tip_down(dev, 70, 70, axes); |
| 4529 |
litest_dispatch(li); |
| 4530 |
|
| 4531 |
/* offset 10 + lower threshold of ~1% of original range, |
| 4532 |
* value 15 is 5% over original range but with the above taken into |
| 4533 |
* account it's closer to 5% into the remaining effective 89% range |
| 4534 |
*/ |
| 4535 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.05); |
| 4536 |
|
| 4537 |
/* a reduced pressure value during motion events must reduce the offset |
| 4538 |
* - here back down to 5%. |
| 4539 |
* FIXME: this causes a tip up event which is a bug but working around |
| 4540 |
* this is more effort than it's worth for what should be quite a niche |
| 4541 |
* case. |
| 4542 |
*/ |
| 4543 |
litest_axis_set_value(axes, ABS_PRESSURE, 5); |
| 4544 |
litest_tablet_motion(dev, 75, 75, axes); |
| 4545 |
litest_dispatch(li); |
| 4546 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.0); |
| 4547 |
litest_drain_events(li); |
| 4548 |
|
| 4549 |
/* back to 10% should now give us 5% pressure because we reduced the |
| 4550 |
* offset */ |
| 4551 |
litest_axis_set_value(axes, ABS_PRESSURE, 10); |
| 4552 |
litest_tablet_motion(dev, 75, 75, axes); |
| 4553 |
litest_dispatch(li); |
| 4554 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.05); |
| 4555 |
litest_drain_events(li); |
| 4556 |
} |
| 4557 |
END_TEST |
| 4558 |
|
| 4559 |
START_TEST(tablet_pressure_offset_increase) |
| 4560 |
{ |
| 4561 |
struct litest_device *dev = litest_current_device(); |
| 4562 |
struct libinput *li = dev->libinput; |
| 4563 |
struct axis_replacement axes[] = { |
| 4564 |
{ ABS_DISTANCE, 70 }, |
| 4565 |
{ ABS_PRESSURE, 20 }, |
| 4566 |
{ -1, -1 }, |
| 4567 |
}; |
| 4568 |
|
| 4569 |
/* offset 20 on first prox in */ |
| 4570 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4571 |
litest_tablet_proximity_out(dev); |
| 4572 |
litest_dispatch(li); |
| 4573 |
litest_timeout_tablet_proxout(li); |
| 4574 |
litest_drain_events(li); |
| 4575 |
|
| 4576 |
/* offset 25 on second prox in - must not change the offset */ |
| 4577 |
litest_axis_set_value(axes, ABS_PRESSURE, 25); |
| 4578 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4579 |
litest_tablet_proximity_out(dev); |
| 4580 |
litest_timeout_tablet_proxout(li); |
| 4581 |
litest_drain_events(li); |
| 4582 |
|
| 4583 |
/* offset 30 on third prox in - must not change the offset */ |
| 4584 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 4585 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4586 |
litest_drain_events(li); |
| 4587 |
|
| 4588 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 4589 |
litest_axis_set_value(axes, ABS_PRESSURE, 31); |
| 4590 |
litest_tablet_tip_down(dev, 70, 70, axes); |
| 4591 |
litest_dispatch(li); |
| 4592 |
litest_drain_events(li); |
| 4593 |
|
| 4594 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 4595 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4596 |
litest_dispatch(li); |
| 4597 |
|
| 4598 |
/* offset 20 + lower threshold of 1% of original range, |
| 4599 |
* value 30 is 5% over original range but with the above taken into |
| 4600 |
* account it's closer to 12% into the remaining effective 79% range |
| 4601 |
*/ |
| 4602 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.12); |
| 4603 |
|
| 4604 |
litest_drain_events(li); |
| 4605 |
|
| 4606 |
litest_axis_set_value(axes, ABS_PRESSURE, 20); |
| 4607 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4608 |
litest_dispatch(li); |
| 4609 |
|
| 4610 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.0); |
| 4611 |
} |
| 4612 |
END_TEST |
| 4613 |
|
| 4614 |
START_TEST(tablet_pressure_min_max) |
| 4615 |
{ |
| 4616 |
struct litest_device *dev = litest_current_device(); |
| 4617 |
struct libinput *li = dev->libinput; |
| 4618 |
struct axis_replacement axes[] = { |
| 4619 |
{ ABS_DISTANCE, 10 }, |
| 4620 |
{ ABS_PRESSURE, 0 }, |
| 4621 |
{ -1, -1 }, |
| 4622 |
}; |
| 4623 |
|
| 4624 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) |
| 4625 |
return LITEST_NOT_APPLICABLE; |
| 4626 |
|
| 4627 |
litest_tablet_proximity_in(dev, 5, 50, axes); |
| 4628 |
litest_drain_events(li); |
| 4629 |
litest_dispatch(li); |
| 4630 |
|
| 4631 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 4632 |
/* Default pressure threshold is 1% of range */ |
| 4633 |
litest_axis_set_value(axes, ABS_PRESSURE, 1.1); |
| 4634 |
litest_tablet_motion(dev, 5, 50, axes); |
| 4635 |
litest_dispatch(li); |
| 4636 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.0); |
| 4637 |
|
| 4638 |
/* skip over pressure-based tip down */ |
| 4639 |
litest_axis_set_value(axes, ABS_PRESSURE, 90); |
| 4640 |
litest_tablet_motion(dev, 5, 50, axes); |
| 4641 |
litest_drain_events(li); |
| 4642 |
|
| 4643 |
/* need to fill the motion history */ |
| 4644 |
litest_axis_set_value(axes, ABS_PRESSURE, 100); |
| 4645 |
litest_tablet_motion(dev, 5, 50, axes); |
| 4646 |
litest_tablet_motion(dev, 6, 50, axes); |
| 4647 |
litest_tablet_motion(dev, 7, 50, axes); |
| 4648 |
litest_tablet_motion(dev, 8, 50, axes); |
| 4649 |
litest_drain_events(li); |
| 4650 |
|
| 4651 |
litest_tablet_motion(dev, 5, 50, axes); |
| 4652 |
litest_dispatch(li); |
| 4653 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 1.0); |
| 4654 |
} |
| 4655 |
END_TEST |
| 4656 |
|
| 4657 |
START_TEST(tablet_pressure_range) |
| 4658 |
{ |
| 4659 |
struct litest_device *dev = litest_current_device(); |
| 4660 |
struct libinput *li = dev->libinput; |
| 4661 |
struct libinput_event *event; |
| 4662 |
struct libinput_event_tablet_tool *tev; |
| 4663 |
struct axis_replacement axes[] = { |
| 4664 |
{ ABS_DISTANCE, 0 }, |
| 4665 |
{ ABS_PRESSURE, 10 }, |
| 4666 |
{ -1, -1 }, |
| 4667 |
}; |
| 4668 |
int pressure; |
| 4669 |
double p; |
| 4670 |
|
| 4671 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4672 |
litest_drain_events(li); |
| 4673 |
litest_dispatch(li); |
| 4674 |
|
| 4675 |
for (pressure = 10; pressure <= 100; pressure += 10) { |
| 4676 |
litest_axis_set_value(axes, ABS_PRESSURE, pressure); |
| 4677 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4678 |
litest_dispatch(li); |
| 4679 |
|
| 4680 |
event = libinput_get_event(li); |
| 4681 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4682 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4683 |
litest_assert_double_ge(p, 0.0); |
| 4684 |
litest_assert_double_le(p, 1.0); |
| 4685 |
libinput_event_destroy(event); |
| 4686 |
} |
| 4687 |
} |
| 4688 |
END_TEST |
| 4689 |
|
| 4690 |
START_TEST(tablet_pressure_config) |
| 4691 |
{ |
| 4692 |
struct litest_device *dev = litest_current_device(); |
| 4693 |
struct libinput *li = dev->libinput; |
| 4694 |
struct libinput_event_tablet_tool *tev; |
| 4695 |
struct axis_replacement axes[] = { |
| 4696 |
{ ABS_DISTANCE, 0 }, |
| 4697 |
{ ABS_PRESSURE, 10 }, |
| 4698 |
{ -1, -1 }, |
| 4699 |
}; |
| 4700 |
bool has_pressure = libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE); |
| 4701 |
|
| 4702 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4703 |
litest_drain_events(li); |
| 4704 |
litest_dispatch(li); |
| 4705 |
|
| 4706 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4707 |
litest_dispatch(li); |
| 4708 |
|
| 4709 |
_destroy_(libinput_event) *event = libinput_get_event(li); |
| 4710 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4711 |
struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(tev); |
| 4712 |
|
| 4713 |
litest_assert_int_eq( |
| 4714 |
has_pressure, |
| 4715 |
libinput_tablet_tool_config_pressure_range_is_available(tool)); |
| 4716 |
litest_assert_double_eq( |
| 4717 |
libinput_tablet_tool_config_pressure_range_get_minimum(tool), |
| 4718 |
0.0); |
| 4719 |
litest_assert_double_eq( |
| 4720 |
libinput_tablet_tool_config_pressure_range_get_maximum(tool), |
| 4721 |
1.0); |
| 4722 |
litest_assert_double_eq( |
| 4723 |
libinput_tablet_tool_config_pressure_range_get_default_minimum(tool), |
| 4724 |
0.0); |
| 4725 |
litest_assert_double_eq( |
| 4726 |
libinput_tablet_tool_config_pressure_range_get_default_maximum(tool), |
| 4727 |
1.0); |
| 4728 |
|
| 4729 |
if (!has_pressure) { |
| 4730 |
litest_assert_enum_eq( |
| 4731 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 1.0), |
| 4732 |
LIBINPUT_CONFIG_STATUS_UNSUPPORTED); |
| 4733 |
return LITEST_PASS; |
| 4734 |
} |
| 4735 |
|
| 4736 |
litest_assert_enum_eq( |
| 4737 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 1.0), |
| 4738 |
LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4739 |
litest_assert_enum_eq( |
| 4740 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.2, 0.5), |
| 4741 |
LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4742 |
litest_assert_enum_eq( |
| 4743 |
libinput_tablet_tool_config_pressure_range_set(tool, -0.1, 1.0), |
| 4744 |
LIBINPUT_CONFIG_STATUS_INVALID); |
| 4745 |
litest_assert_enum_eq( |
| 4746 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 0.0), |
| 4747 |
LIBINPUT_CONFIG_STATUS_INVALID); |
| 4748 |
litest_assert_enum_eq( |
| 4749 |
libinput_tablet_tool_config_pressure_range_set(tool, 1.0, 1.0), |
| 4750 |
LIBINPUT_CONFIG_STATUS_INVALID); |
| 4751 |
litest_assert_enum_eq( |
| 4752 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 1.1), |
| 4753 |
LIBINPUT_CONFIG_STATUS_INVALID); |
| 4754 |
|
| 4755 |
/* The last successful one */ |
| 4756 |
litest_assert_double_eq( |
| 4757 |
libinput_tablet_tool_config_pressure_range_get_minimum(tool), |
| 4758 |
0.2); |
| 4759 |
litest_assert_double_eq( |
| 4760 |
libinput_tablet_tool_config_pressure_range_get_maximum(tool), |
| 4761 |
0.5); |
| 4762 |
litest_assert_double_eq( |
| 4763 |
libinput_tablet_tool_config_pressure_range_get_default_minimum(tool), |
| 4764 |
0.0); |
| 4765 |
litest_assert_double_eq( |
| 4766 |
libinput_tablet_tool_config_pressure_range_get_default_maximum(tool), |
| 4767 |
1.0); |
| 4768 |
} |
| 4769 |
END_TEST |
| 4770 |
|
| 4771 |
START_TEST(tablet_pressure_config_set_minimum) |
| 4772 |
{ |
| 4773 |
struct litest_device *dev = litest_current_device(); |
| 4774 |
struct libinput *li = dev->libinput; |
| 4775 |
struct libinput_event *event; |
| 4776 |
struct libinput_event_tablet_tool *tev; |
| 4777 |
struct libinput_tablet_tool *tool; |
| 4778 |
struct axis_replacement axes[] = { |
| 4779 |
{ ABS_DISTANCE, 0 }, |
| 4780 |
{ ABS_PRESSURE, 10 }, |
| 4781 |
{ -1, -1 }, |
| 4782 |
}; |
| 4783 |
double p, old_pressure; |
| 4784 |
|
| 4785 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) |
| 4786 |
return LITEST_NOT_APPLICABLE; |
| 4787 |
|
| 4788 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4789 |
litest_drain_events(li); |
| 4790 |
litest_dispatch(li); |
| 4791 |
|
| 4792 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4793 |
litest_dispatch(li); |
| 4794 |
|
| 4795 |
event = libinput_get_event(li); |
| 4796 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4797 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 4798 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4799 |
litest_assert_double_gt(p, 0.0); |
| 4800 |
old_pressure = p; |
| 4801 |
|
| 4802 |
litest_assert(libinput_tablet_tool_config_pressure_range_is_available(tool)); |
| 4803 |
litest_assert_enum_eq( |
| 4804 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.4, 1.0), |
| 4805 |
LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4806 |
libinput_event_destroy(event); |
| 4807 |
|
| 4808 |
/* config doesn't take effect until we're out of prox */ |
| 4809 |
for (int pos = 71; pos < 80; pos++) { |
| 4810 |
litest_tablet_motion(dev, pos, pos, axes); |
| 4811 |
litest_dispatch(li); |
| 4812 |
event = libinput_get_event(li); |
| 4813 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4814 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4815 |
litest_assert_double_eq(p, old_pressure); |
| 4816 |
libinput_event_destroy(event); |
| 4817 |
} |
| 4818 |
|
| 4819 |
litest_tablet_proximity_out(dev); |
| 4820 |
litest_timeout_tablet_proxout(li); |
| 4821 |
litest_drain_events(li); |
| 4822 |
|
| 4823 |
/* 10% hw value is below our thresholds, so logical zero */ |
| 4824 |
litest_axis_set_value(axes, ABS_PRESSURE, 10); |
| 4825 |
litest_tablet_proximity_in(dev, 70, 70, axes); |
| 4826 |
litest_drain_events(li); |
| 4827 |
|
| 4828 |
for (int pos = 71; pos < 80; pos++) { |
| 4829 |
litest_tablet_motion(dev, pos, pos, axes); |
| 4830 |
litest_dispatch(li); |
| 4831 |
event = libinput_get_event(li); |
| 4832 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4833 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4834 |
litest_assert_double_eq(p, 0.00); |
| 4835 |
libinput_event_destroy(event); |
| 4836 |
} |
| 4837 |
|
| 4838 |
/* 50% hw value mapped into a reduced range of 60% from hw range, |
| 4839 |
plus the 1% minimum offset, so our output pressure is actually ~15% */ |
| 4840 |
litest_axis_set_value(axes, ABS_PRESSURE, 50); |
| 4841 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4842 |
litest_dispatch(li); |
| 4843 |
event = libinput_get_event(li); |
| 4844 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 4845 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4846 |
litest_assert_double_gt(p, 0.15); |
| 4847 |
litest_assert_double_le(p, 0.16); |
| 4848 |
libinput_event_destroy(event); |
| 4849 |
|
| 4850 |
for (int pos = 71; pos < 80; pos++) { |
| 4851 |
litest_tablet_motion(dev, pos, pos, axes); |
| 4852 |
litest_dispatch(li); |
| 4853 |
event = libinput_get_event(li); |
| 4854 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4855 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4856 |
litest_assert_double_ge(p, 0.15); |
| 4857 |
litest_assert_double_le(p, 0.16); |
| 4858 |
libinput_event_destroy(event); |
| 4859 |
} |
| 4860 |
} |
| 4861 |
END_TEST |
| 4862 |
|
| 4863 |
START_TEST(tablet_pressure_config_set_maximum) |
| 4864 |
{ |
| 4865 |
struct litest_device *dev = litest_current_device(); |
| 4866 |
struct libinput *li = dev->libinput; |
| 4867 |
struct libinput_event *event; |
| 4868 |
struct libinput_event_tablet_tool *tev; |
| 4869 |
struct libinput_tablet_tool *tool; |
| 4870 |
struct axis_replacement axes[] = { |
| 4871 |
{ ABS_DISTANCE, 0 }, |
| 4872 |
{ ABS_PRESSURE, 10 }, |
| 4873 |
{ -1, -1 }, |
| 4874 |
}; |
| 4875 |
double p, old_pressure; |
| 4876 |
|
| 4877 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) |
| 4878 |
return LITEST_NOT_APPLICABLE; |
| 4879 |
|
| 4880 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4881 |
litest_drain_events(li); |
| 4882 |
litest_dispatch(li); |
| 4883 |
|
| 4884 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4885 |
litest_dispatch(li); |
| 4886 |
|
| 4887 |
event = libinput_get_event(li); |
| 4888 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4889 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 4890 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4891 |
litest_assert_double_gt(p, 0.0); |
| 4892 |
old_pressure = p; |
| 4893 |
|
| 4894 |
litest_assert(libinput_tablet_tool_config_pressure_range_is_available(tool)); |
| 4895 |
litest_assert_enum_eq( |
| 4896 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 0.6), |
| 4897 |
LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4898 |
libinput_event_destroy(event); |
| 4899 |
|
| 4900 |
/* config doesn't take effect until we're out of prox */ |
| 4901 |
for (int pos = 71; pos < 80; pos++) { |
| 4902 |
litest_tablet_motion(dev, pos, pos, axes); |
| 4903 |
litest_dispatch(li); |
| 4904 |
event = libinput_get_event(li); |
| 4905 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4906 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4907 |
litest_assert_double_eq(p, old_pressure); |
| 4908 |
libinput_event_destroy(event); |
| 4909 |
} |
| 4910 |
|
| 4911 |
litest_tablet_proximity_out(dev); |
| 4912 |
litest_timeout_tablet_proxout(li); |
| 4913 |
|
| 4914 |
litest_axis_set_value(axes, ABS_PRESSURE, 10); |
| 4915 |
litest_tablet_proximity_in(dev, 70, 70, axes); |
| 4916 |
litest_drain_events(li); |
| 4917 |
|
| 4918 |
/* 10% hw value mapped into a reduced range of 60% from hw range, |
| 4919 |
plus the 1% minimum offset so our output pressure is actually ~15% */ |
| 4920 |
for (int pos = 71; pos < 80; pos++) { |
| 4921 |
litest_tablet_motion(dev, pos, pos, axes); |
| 4922 |
litest_dispatch(li); |
| 4923 |
event = libinput_get_event(li); |
| 4924 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4925 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4926 |
litest_assert_double_ge(p, 0.15); |
| 4927 |
litest_assert_double_le(p, 0.16); |
| 4928 |
litest_assert_double_gt(p, old_pressure); |
| 4929 |
libinput_event_destroy(event); |
| 4930 |
} |
| 4931 |
|
| 4932 |
/* 50% hw value mapped into a reduced range of 60% from hw range, |
| 4933 |
plus the 1% minimum offset, so our output pressure is actually ~83% */ |
| 4934 |
litest_axis_set_value(axes, ABS_PRESSURE, 50); |
| 4935 |
|
| 4936 |
for (int pos = 71; pos < 80; pos++) { |
| 4937 |
litest_tablet_motion(dev, pos, pos, axes); |
| 4938 |
litest_dispatch(li); |
| 4939 |
event = libinput_get_event(li); |
| 4940 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4941 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4942 |
litest_assert_double_ge(p, 0.82); |
| 4943 |
litest_assert_double_le(p, 0.84); |
| 4944 |
libinput_event_destroy(event); |
| 4945 |
} |
| 4946 |
|
| 4947 |
for (int hwp = 60; hwp < 100; hwp += 10) { |
| 4948 |
litest_axis_set_value(axes, ABS_PRESSURE, hwp); |
| 4949 |
|
| 4950 |
for (int pos = 71; pos < 80; pos++) { |
| 4951 |
litest_tablet_motion(dev, pos, pos, axes); |
| 4952 |
litest_dispatch(li); |
| 4953 |
event = libinput_get_event(li); |
| 4954 |
tev = litest_is_tablet_event(event, |
| 4955 |
LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4956 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4957 |
litest_assert_double_eq(p, 1.0); |
| 4958 |
libinput_event_destroy(event); |
| 4959 |
} |
| 4960 |
} |
| 4961 |
} |
| 4962 |
END_TEST |
| 4963 |
|
| 4964 |
START_TEST(tablet_pressure_config_set_range) |
| 4965 |
{ |
| 4966 |
struct litest_device *dev = litest_current_device(); |
| 4967 |
struct libinput *li = dev->libinput; |
| 4968 |
struct libinput_event *event; |
| 4969 |
struct libinput_event_tablet_tool *tev; |
| 4970 |
struct libinput_tablet_tool *tool; |
| 4971 |
struct axis_replacement axes[] = { |
| 4972 |
{ ABS_DISTANCE, 0 }, |
| 4973 |
{ ABS_PRESSURE, 10 }, |
| 4974 |
{ -1, -1 }, |
| 4975 |
}; |
| 4976 |
double p, old_pressure; |
| 4977 |
|
| 4978 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) |
| 4979 |
return LITEST_NOT_APPLICABLE; |
| 4980 |
|
| 4981 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 4982 |
litest_drain_events(li); |
| 4983 |
litest_dispatch(li); |
| 4984 |
|
| 4985 |
litest_tablet_motion(dev, 70, 70, axes); |
| 4986 |
litest_dispatch(li); |
| 4987 |
|
| 4988 |
event = libinput_get_event(li); |
| 4989 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 4990 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 4991 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 4992 |
litest_assert_double_gt(p, 0.0); |
| 4993 |
old_pressure = p; |
| 4994 |
|
| 4995 |
litest_assert(libinput_tablet_tool_config_pressure_range_is_available(tool)); |
| 4996 |
litest_assert_enum_eq( |
| 4997 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.4, 0.6), |
| 4998 |
LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 4999 |
libinput_event_destroy(event); |
| 5000 |
|
| 5001 |
/* config doesn't take effect until we're out of prox */ |
| 5002 |
for (int i = 71; i < 80; i++) { |
| 5003 |
litest_tablet_motion(dev, i, i, axes); |
| 5004 |
litest_dispatch(li); |
| 5005 |
event = libinput_get_event(li); |
| 5006 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5007 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 5008 |
litest_assert_double_eq(p, old_pressure); |
| 5009 |
libinput_event_destroy(event); |
| 5010 |
} |
| 5011 |
|
| 5012 |
litest_tablet_proximity_out(dev); |
| 5013 |
litest_timeout_tablet_proxout(li); |
| 5014 |
litest_drain_events(li); |
| 5015 |
|
| 5016 |
litest_tablet_proximity_in(dev, 70, 70, axes); |
| 5017 |
litest_drain_events(li); |
| 5018 |
|
| 5019 |
for (double pressure = 0.0, i = 71; pressure <= 100; pressure += 5, i += 0.2) { |
| 5020 |
litest_axis_set_value(axes, ABS_PRESSURE, pressure); |
| 5021 |
litest_tablet_motion(dev, i, i, axes); |
| 5022 |
litest_dispatch(li); |
| 5023 |
event = libinput_get_event(li); |
| 5024 |
if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) |
| 5025 |
tev = litest_is_tablet_event(event, |
| 5026 |
LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5027 |
else |
| 5028 |
tev = litest_is_tablet_event(event, |
| 5029 |
LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 5030 |
p = libinput_event_tablet_tool_get_pressure(tev); |
| 5031 |
if (pressure <= 40) { |
| 5032 |
litest_assert_double_eq(p, 0.0); |
| 5033 |
} else if (pressure >= 60) { |
| 5034 |
litest_assert_double_eq(p, 1.0); |
| 5035 |
} else { |
| 5036 |
litest_assert_double_ge(p, (pressure - 1 - 40) / 20.0); |
| 5037 |
litest_assert_double_le(p, (pressure - 40) / 20.0); |
| 5038 |
} |
| 5039 |
libinput_event_destroy(event); |
| 5040 |
} |
| 5041 |
} |
| 5042 |
END_TEST |
| 5043 |
|
| 5044 |
START_TEST(tablet_pressure_config_resets_offset) |
| 5045 |
{ |
| 5046 |
struct litest_device *dev = litest_current_device(); |
| 5047 |
struct libinput *li = dev->libinput; |
| 5048 |
struct axis_replacement axes[] = { |
| 5049 |
{ ABS_DISTANCE, 70 }, |
| 5050 |
{ ABS_PRESSURE, 70 }, /* high pressure offset */ |
| 5051 |
{ -1, -1 }, |
| 5052 |
}; |
| 5053 |
|
| 5054 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) |
| 5055 |
return LITEST_NOT_APPLICABLE; |
| 5056 |
|
| 5057 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 5058 |
litest_drain_events(li); |
| 5059 |
litest_dispatch(li); |
| 5060 |
|
| 5061 |
litest_tablet_motion(dev, 70, 70, axes); |
| 5062 |
litest_dispatch(li); |
| 5063 |
|
| 5064 |
{ |
| 5065 |
_destroy_(libinput_event) *event = libinput_get_event(li); |
| 5066 |
auto tev = |
| 5067 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5068 |
auto tool = libinput_event_tablet_tool_get_tool(tev); |
| 5069 |
|
| 5070 |
litest_assert( |
| 5071 |
libinput_tablet_tool_config_pressure_range_is_available(tool)); |
| 5072 |
litest_assert_enum_eq( |
| 5073 |
libinput_tablet_tool_config_pressure_range_set(tool, |
| 5074 |
0.01, |
| 5075 |
0.99), |
| 5076 |
LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 5077 |
} |
| 5078 |
|
| 5079 |
litest_tablet_proximity_out(dev); |
| 5080 |
litest_timeout_tablet_proxout(li); |
| 5081 |
litest_drain_events(li); |
| 5082 |
|
| 5083 |
/* Config should be applied on prox in */ |
| 5084 |
litest_axis_set_value(axes, ABS_PRESSURE, 71); |
| 5085 |
litest_tablet_proximity_in(dev, 72, 72, axes); |
| 5086 |
litest_drain_events(li); |
| 5087 |
litest_tablet_proximity_out(dev); |
| 5088 |
litest_timeout_tablet_proxout(li); |
| 5089 |
litest_drain_events(li); |
| 5090 |
|
| 5091 |
/* Two prox in/out cycles to get past the heuristics on devices without |
| 5092 |
* ABS_DISTANCE |
| 5093 |
*/ |
| 5094 |
litest_axis_set_value(axes, ABS_PRESSURE, 72); |
| 5095 |
litest_tablet_proximity_in(dev, 75, 75, axes); |
| 5096 |
litest_drain_events(li); |
| 5097 |
litest_tablet_proximity_out(dev); |
| 5098 |
litest_timeout_tablet_proxout(li); |
| 5099 |
litest_drain_events(li); |
| 5100 |
|
| 5101 |
for (double pressure = 10.0, i = 71; pressure <= 25; pressure += 5, i += 0.2) { |
| 5102 |
litest_log_group("Prox in/out with pressure %.f", pressure) { |
| 5103 |
litest_axis_set_value(axes, ABS_PRESSURE, pressure); |
| 5104 |
litest_tablet_proximity_in(dev, i, i, axes); |
| 5105 |
litest_dispatch(li); |
| 5106 |
|
| 5107 |
_destroy_(libinput_event) *event = libinput_get_event(li); |
| 5108 |
auto tev = litest_is_tablet_event( |
| 5109 |
event, |
| 5110 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5111 |
double p = libinput_event_tablet_tool_get_pressure(tev); |
| 5112 |
/* checking if >5% is good enough here, it'd be zero if the |
| 5113 |
* 70% threshold were locked in */ |
| 5114 |
litest_assert_double_gt(p, 0.05); |
| 5115 |
|
| 5116 |
litest_tablet_proximity_out(dev); |
| 5117 |
litest_timeout_tablet_proxout(li); |
| 5118 |
litest_drain_events(li); |
| 5119 |
} |
| 5120 |
} |
| 5121 |
} |
| 5122 |
END_TEST |
| 5123 |
|
| 5124 |
START_TEST(tablet_pressure_config_01_does_not_reset_offset) |
| 5125 |
{ |
| 5126 |
struct litest_device *dev = litest_current_device(); |
| 5127 |
struct libinput *li = dev->libinput; |
| 5128 |
struct axis_replacement axes[] = { |
| 5129 |
{ ABS_PRESSURE, 20 }, /* high pressure offset */ |
| 5130 |
{ -1, -1 }, |
| 5131 |
}; |
| 5132 |
|
| 5133 |
/* test is only run for specific devices because some of our test devices |
| 5134 |
* write ABS_PRESSURE 0 events on prox out and that changes the test outcomes. |
| 5135 |
*/ |
| 5136 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) |
| 5137 |
return LITEST_NOT_APPLICABLE; |
| 5138 |
|
| 5139 |
if (libevdev_has_event_code(dev->evdev, EV_ABS, ABS_DISTANCE)) |
| 5140 |
return LITEST_NOT_APPLICABLE; |
| 5141 |
|
| 5142 |
litest_drain_events(li); /* Drain potential tip event */ |
| 5143 |
|
| 5144 |
litest_tablet_proximity_in(dev, 68, 68, axes); |
| 5145 |
litest_dispatch(li); |
| 5146 |
{ |
| 5147 |
_destroy_(libinput_event) *event = libinput_get_event(li); |
| 5148 |
auto tev = litest_is_tablet_event(event, |
| 5149 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5150 |
auto tool = libinput_event_tablet_tool_get_tool(tev); |
| 5151 |
|
| 5152 |
litest_assert( |
| 5153 |
libinput_tablet_tool_config_pressure_range_is_available(tool)); |
| 5154 |
litest_assert_enum_eq( |
| 5155 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 1.0), |
| 5156 |
LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 5157 |
} |
| 5158 |
|
| 5159 |
/* Drain potential tip event. */ |
| 5160 |
litest_drain_events(li); |
| 5161 |
|
| 5162 |
/* No motion events here, that might change the offset! */ |
| 5163 |
|
| 5164 |
litest_tablet_proximity_out(dev); |
| 5165 |
litest_timeout_tablet_proxout(li); |
| 5166 |
litest_drain_events(li); |
| 5167 |
|
| 5168 |
litest_checkpoint("second prox in"); |
| 5169 |
/* Config should be applied on prox in */ |
| 5170 |
litest_axis_set_value(axes, ABS_PRESSURE, 31); |
| 5171 |
litest_tablet_proximity_in(dev, 72, 72, axes); |
| 5172 |
litest_drain_events(li); |
| 5173 |
litest_tablet_proximity_out(dev); |
| 5174 |
litest_timeout_tablet_proxout(li); |
| 5175 |
litest_drain_events(li); |
| 5176 |
|
| 5177 |
/* Two prox in/out cycles to finalize heuristics */ |
| 5178 |
litest_with_logcapture(li, capture) { |
| 5179 |
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_INFO); |
| 5180 |
litest_axis_set_value(axes, ABS_PRESSURE, 32); |
| 5181 |
litest_tablet_proximity_in(dev, 75, 75, axes); |
| 5182 |
litest_drain_events(li); |
| 5183 |
litest_tablet_proximity_out(dev); |
| 5184 |
litest_timeout_tablet_proxout(li); |
| 5185 |
litest_drain_events(li); |
| 5186 |
|
| 5187 |
/* Full message is "Pressure offset detected of n% detected on tool pen" |
| 5188 |
*/ |
| 5189 |
litest_assert_strv_substring(capture->infos, "detected on tool pen"); |
| 5190 |
} |
| 5191 |
|
| 5192 |
litest_log_group("Expecting pressure with offset factored in") { |
| 5193 |
litest_axis_set_value(axes, ABS_PRESSURE, 25); |
| 5194 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 5195 |
litest_dispatch(li); |
| 5196 |
|
| 5197 |
_destroy_(libinput_event) *event = libinput_get_event(li); |
| 5198 |
auto tev = litest_is_tablet_event(event, |
| 5199 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5200 |
double p = libinput_event_tablet_tool_get_pressure(tev); |
| 5201 |
/* Pressure 25%, base offset of 20% so we should get 5% plus the 1% we |
| 5202 |
* use anyway */ |
| 5203 |
litest_assert_double_ge(p, 0.05); |
| 5204 |
litest_assert_double_le(p, 0.07); |
| 5205 |
|
| 5206 |
litest_tablet_proximity_out(dev); |
| 5207 |
litest_timeout_tablet_proxout(li); |
| 5208 |
litest_drain_events(li); |
| 5209 |
} |
| 5210 |
|
| 5211 |
litest_log_group("Expecting low pressure to reduce offset") { |
| 5212 |
/* Because we didn't configure the range, we expect lower pressure to |
| 5213 |
* reduce the offset */ |
| 5214 |
litest_axis_set_value(axes, ABS_PRESSURE, 5); |
| 5215 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 5216 |
litest_dispatch(li); |
| 5217 |
|
| 5218 |
_destroy_(libinput_event) *event = libinput_get_event(li); |
| 5219 |
auto tev = litest_is_tablet_event(event, |
| 5220 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5221 |
double p = libinput_event_tablet_tool_get_pressure(tev); |
| 5222 |
litest_assert_double_eq(p, 0.00); |
| 5223 |
|
| 5224 |
litest_tablet_proximity_out(dev); |
| 5225 |
litest_timeout_tablet_proxout(li); |
| 5226 |
litest_drain_events(li); |
| 5227 |
} |
| 5228 |
} |
| 5229 |
END_TEST |
| 5230 |
|
| 5231 |
static void |
| 5232 |
pressure_threshold_warning(struct libinput *libinput, |
| 5233 |
enum libinput_log_priority priority, |
| 5234 |
const char *format, |
| 5235 |
va_list args) |
| 5236 |
{ |
| 5237 |
struct litest_user_data *user_data = libinput_get_user_data(libinput); |
| 5238 |
int *warning_triggered = user_data->private; |
| 5239 |
|
| 5240 |
if (priority == LIBINPUT_LOG_PRIORITY_ERROR && |
| 5241 |
strstr(format, "pressure offset greater")) |
| 5242 |
(*warning_triggered)++; |
| 5243 |
} |
| 5244 |
|
| 5245 |
START_TEST(tablet_pressure_offset_exceed_threshold) |
| 5246 |
{ |
| 5247 |
struct litest_device *dev = litest_current_device(); |
| 5248 |
struct libinput *li = dev->libinput; |
| 5249 |
struct axis_replacement axes[] = { |
| 5250 |
{ ABS_DISTANCE, 70 }, |
| 5251 |
{ ABS_PRESSURE, 60 }, |
| 5252 |
{ -1, -1 }, |
| 5253 |
}; |
| 5254 |
int warning_triggered = 0; |
| 5255 |
struct litest_user_data *user_data = libinput_get_user_data(li); |
| 5256 |
|
| 5257 |
/* Tablet without distance: offset takes effect on third prox-in */ |
| 5258 |
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_DISTANCE)) { |
| 5259 |
for (int i = 0; i < 2; i++) { |
| 5260 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 5261 |
litest_tablet_proximity_out(dev); |
| 5262 |
litest_timeout_tablet_proxout(li); |
| 5263 |
} |
| 5264 |
} |
| 5265 |
|
| 5266 |
litest_drain_events(li); |
| 5267 |
|
| 5268 |
user_data->private = &warning_triggered; |
| 5269 |
|
| 5270 |
libinput_log_set_handler(li, pressure_threshold_warning); |
| 5271 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 5272 |
litest_dispatch(li); |
| 5273 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.60); |
| 5274 |
|
| 5275 |
litest_assert_int_eq(warning_triggered, 1); |
| 5276 |
litest_restore_log_handler(li); |
| 5277 |
} |
| 5278 |
END_TEST |
| 5279 |
|
| 5280 |
START_TEST(tablet_pressure_offset_none_for_zero_distance) |
| 5281 |
{ |
| 5282 |
struct litest_device *dev = litest_current_device(); |
| 5283 |
struct libinput *li = dev->libinput; |
| 5284 |
struct axis_replacement axes[] = { |
| 5285 |
{ ABS_DISTANCE, 0 }, |
| 5286 |
{ ABS_PRESSURE, 20 }, |
| 5287 |
{ -1, -1 }, |
| 5288 |
}; |
| 5289 |
|
| 5290 |
litest_drain_events(li); |
| 5291 |
|
| 5292 |
/* we're going straight to touch on proximity, make sure we don't |
| 5293 |
* offset the pressure here */ |
| 5294 |
litest_with_event_frame(dev) { |
| 5295 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 5296 |
litest_tablet_tip_down(dev, 5, 100, axes); |
| 5297 |
} |
| 5298 |
litest_dispatch(li); |
| 5299 |
|
| 5300 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.20); |
| 5301 |
} |
| 5302 |
END_TEST |
| 5303 |
|
| 5304 |
START_TEST(tablet_pressure_offset_none_for_small_distance) |
| 5305 |
{ |
| 5306 |
struct litest_device *dev = litest_current_device(); |
| 5307 |
struct libinput *li = dev->libinput; |
| 5308 |
struct axis_replacement axes[] = { |
| 5309 |
{ ABS_DISTANCE, 20 }, |
| 5310 |
{ ABS_PRESSURE, 20 }, |
| 5311 |
{ -1, -1 }, |
| 5312 |
}; |
| 5313 |
|
| 5314 |
/* stylus too close to the tablet on the proximity in, ignore any |
| 5315 |
* pressure offset */ |
| 5316 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 5317 |
litest_drain_events(li); |
| 5318 |
litest_dispatch(li); |
| 5319 |
|
| 5320 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 5321 |
litest_axis_set_value(axes, ABS_PRESSURE, 21); |
| 5322 |
litest_tablet_tip_down(dev, 70, 70, axes); |
| 5323 |
litest_drain_events(li); |
| 5324 |
|
| 5325 |
litest_axis_set_value(axes, ABS_PRESSURE, 20); |
| 5326 |
litest_tablet_motion(dev, 70, 70, axes); |
| 5327 |
litest_dispatch(li); |
| 5328 |
|
| 5329 |
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.20); |
| 5330 |
} |
| 5331 |
END_TEST |
| 5332 |
|
| 5333 |
START_TEST(tablet_pressure_across_multiple_tablets) |
| 5334 |
{ |
| 5335 |
struct litest_device *cintiq12wx = litest_current_device(); |
| 5336 |
struct libinput *li = cintiq12wx->libinput; |
| 5337 |
|
| 5338 |
struct litest_device *mobilestudio = |
| 5339 |
litest_add_device(li, LITEST_WACOM_CINTIQ_PRO16_PEN); |
| 5340 |
|
| 5341 |
bool direction = litest_test_param_get_bool(test_env->params, "8k-to-1k"); |
| 5342 |
struct litest_device *first = direction ? mobilestudio : cintiq12wx; |
| 5343 |
struct litest_device *second = direction ? cintiq12wx : mobilestudio; |
| 5344 |
|
| 5345 |
bool with_range = litest_test_param_get_bool(test_env->params, "with-range"); |
| 5346 |
bool with_second_range = |
| 5347 |
litest_test_param_get_bool(test_env->params, "with-second-range"); |
| 5348 |
|
| 5349 |
struct axis_replacement axes[] = { |
| 5350 |
{ ABS_DISTANCE, 20 }, |
| 5351 |
{ ABS_PRESSURE, 0 }, |
| 5352 |
{ -1, -1 }, |
| 5353 |
}; |
| 5354 |
|
| 5355 |
bool have_cintiq12wx = false; |
| 5356 |
bool have_mobilestudio = false; |
| 5357 |
|
| 5358 |
litest_dispatch(li); |
| 5359 |
|
| 5360 |
while (!have_cintiq12wx || !have_mobilestudio) { |
| 5361 |
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); |
| 5362 |
_destroy_(libinput_event) *ev = libinput_get_event(li); |
| 5363 |
litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_ADDED); |
| 5364 |
if (libinput_event_get_device(ev) == cintiq12wx->libinput_device) |
| 5365 |
have_cintiq12wx = true; |
| 5366 |
if (libinput_event_get_device(ev) == mobilestudio->libinput_device) |
| 5367 |
have_mobilestudio = true; |
| 5368 |
litest_checkpoint("Have Cintiq 12WX: %s, MobileStudio: %s", |
| 5369 |
yesno(have_cintiq12wx), |
| 5370 |
yesno(have_mobilestudio)); |
| 5371 |
litest_dispatch(li); |
| 5372 |
} |
| 5373 |
|
| 5374 |
litest_drain_events(li); |
| 5375 |
|
| 5376 |
litest_mark_test_start(); |
| 5377 |
|
| 5378 |
_unref_(libinput_tablet_tool) *tool = NULL; |
| 5379 |
if (with_range) { |
| 5380 |
litest_log_group("Prox in/out on %s to apply pressure range to tool", |
| 5381 |
libinput_device_get_name(first->libinput_device)) { |
| 5382 |
litest_tablet_proximity_in(first, 50, 50, axes); |
| 5383 |
litest_dispatch(li); |
| 5384 |
|
| 5385 |
_destroy_(libinput_event) *ev = libinput_get_event(li); |
| 5386 |
struct libinput_event_tablet_tool *tev = litest_is_tablet_event( |
| 5387 |
ev, |
| 5388 |
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5389 |
tool = libinput_tablet_tool_ref( |
| 5390 |
libinput_event_tablet_tool_get_tool(tev)); |
| 5391 |
libinput_tablet_tool_config_pressure_range_set(tool, 0.2, 0.7); |
| 5392 |
litest_tablet_proximity_out(first); |
| 5393 |
litest_timeout_tablet_proxout(li); |
| 5394 |
litest_drain_events(li); |
| 5395 |
} |
| 5396 |
} |
| 5397 |
|
| 5398 |
/* Proximity in followed by pressure up to 70%, on the first |
| 5399 |
* device, then on the second one. They have different pressure |
| 5400 |
* ranges but we expect the normalized range to be the same |
| 5401 |
* proportionate range */ |
| 5402 |
struct litest_device *dev = first; |
| 5403 |
for (int i = 0; i < 2; i++, dev = second) { |
| 5404 |
litest_checkpoint("Putting pen into proximity on %s", |
| 5405 |
libinput_device_get_name(dev->libinput_device)); |
| 5406 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 5407 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 5408 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 5409 |
litest_dispatch(li); |
| 5410 |
|
| 5411 |
/* FIXME: this tests a bug in the code. The pressure range is updated |
| 5412 |
* on proximity out only, so if we update the range while the tool |
| 5413 |
* is in prox only the tablet the tool *leaves* from gets updated. |
| 5414 |
* If we move into a new tablet the pressure range there isn't updated |
| 5415 |
* until we leave proximity of that tablet. |
| 5416 |
* |
| 5417 |
* Since pressure ranges don't change often and the vast majority of |
| 5418 |
* users don't have more than one tablet anyway, this isn't worth |
| 5419 |
* fixing. |
| 5420 |
* |
| 5421 |
* For this test, if we have a second range and we're on the second |
| 5422 |
* device we add an extra prox out/in to get the pressure range applied |
| 5423 |
* correctly. |
| 5424 |
*/ |
| 5425 |
if (with_second_range && dev == second) { |
| 5426 |
litest_log_group("Updating pressure range") { |
| 5427 |
libinput_tablet_tool_config_pressure_range_set(tool, |
| 5428 |
0.5, |
| 5429 |
0.9); |
| 5430 |
litest_tablet_proximity_out(dev); |
| 5431 |
litest_timeout_tablet_proxout(li); |
| 5432 |
litest_drain_events(li); |
| 5433 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 5434 |
litest_dispatch(li); |
| 5435 |
} |
| 5436 |
} |
| 5437 |
litest_assert_tablet_proximity_event( |
| 5438 |
li, |
| 5439 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 5440 |
|
| 5441 |
for (int pressure = 10; pressure <= 70; pressure += 10) { |
| 5442 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 5443 |
litest_axis_set_value(axes, ABS_PRESSURE, pressure); |
| 5444 |
litest_tablet_motion(dev, 50, 50, axes); |
| 5445 |
litest_dispatch(li); |
| 5446 |
|
| 5447 |
_destroy_(libinput_event) *ev = libinput_get_event(li); |
| 5448 |
litest_assert_event_type_is_one_of( |
| 5449 |
ev, |
| 5450 |
LIBINPUT_EVENT_TABLET_TOOL_AXIS, |
| 5451 |
LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 5452 |
struct libinput_event_tablet_tool *tev = |
| 5453 |
libinput_event_get_tablet_tool_event(ev); |
| 5454 |
|
| 5455 |
double tool_pressure = |
| 5456 |
libinput_event_tablet_tool_get_pressure(tev); |
| 5457 |
if (with_second_range && dev == second) { |
| 5458 |
if (pressure < 50) { |
| 5459 |
litest_assert_double_eq(tool_pressure, 0.0); |
| 5460 |
} else if (pressure == 60) { |
| 5461 |
litest_assert_event_type( |
| 5462 |
ev, |
| 5463 |
LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 5464 |
litest_assert_double_ge(tool_pressure, 0.0); |
| 5465 |
} else { |
| 5466 |
litest_assert_double_lt(tool_pressure, 0.7); |
| 5467 |
} |
| 5468 |
} else if (with_range) { |
| 5469 |
/* with our range 30% device pressure should be around |
| 5470 |
* 10% actual pressure and trigger the tip down */ |
| 5471 |
if (pressure < 30) { |
| 5472 |
litest_assert_double_eq(tool_pressure, 0.0); |
| 5473 |
} else if (pressure == 30) { |
| 5474 |
litest_assert_event_type( |
| 5475 |
ev, |
| 5476 |
LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 5477 |
litest_assert_double_ge(tool_pressure, 0.0); |
| 5478 |
} else if (pressure < 70) { |
| 5479 |
litest_assert_double_ge(tool_pressure, 0.1); |
| 5480 |
litest_assert_double_lt(tool_pressure, 1.0); |
| 5481 |
} else { |
| 5482 |
litest_assert_double_eq(tool_pressure, 1.0); |
| 5483 |
} |
| 5484 |
} else { |
| 5485 |
if (pressure == 10) |
| 5486 |
litest_assert_event_type( |
| 5487 |
ev, |
| 5488 |
LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 5489 |
/* We start at device range 10% but we always have a |
| 5490 |
* small threshold */ |
| 5491 |
litest_assert_double_gt_epsilon(pressure, 0.09, 0); |
| 5492 |
litest_assert_double_le(tool_pressure, 0.7); |
| 5493 |
} |
| 5494 |
|
| 5495 |
if (!tool) |
| 5496 |
tool = libinput_tablet_tool_ref( |
| 5497 |
libinput_event_tablet_tool_get_tool(tev)); |
| 5498 |
} |
| 5499 |
|
| 5500 |
litest_checkpoint("Leaving proximity on %s", |
| 5501 |
libinput_device_get_name(dev->libinput_device)); |
| 5502 |
litest_tablet_proximity_out(dev); |
| 5503 |
litest_timeout_tablet_proxout(li); |
| 5504 |
|
| 5505 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5506 |
litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_UP); |
| 5507 |
litest_assert_tablet_proximity_event( |
| 5508 |
li, |
| 5509 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 5510 |
} |
| 5511 |
|
| 5512 |
litest_device_destroy(mobilestudio); |
| 5513 |
} |
| 5514 |
END_TEST |
| 5515 |
|
| 5516 |
START_TEST(tablet_pressure_after_unplug) |
| 5517 |
{ |
| 5518 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 5519 |
struct litest_device *dev = |
| 5520 |
litest_add_device(li, LITEST_WACOM_CINTIQ_PRO16_PEN); |
| 5521 |
|
| 5522 |
struct axis_replacement axes[] = { |
| 5523 |
{ ABS_DISTANCE, 20 }, |
| 5524 |
{ ABS_PRESSURE, 0 }, |
| 5525 |
{ -1, -1 }, |
| 5526 |
}; |
| 5527 |
|
| 5528 |
litest_drain_events(li); |
| 5529 |
litest_mark_test_start(); |
| 5530 |
|
| 5531 |
/* Unplug 10 times because that's more than however many tablets |
| 5532 |
* we keep track of internally */ |
| 5533 |
for (int iteration = 0; iteration < 10; iteration++) { |
| 5534 |
litest_checkpoint("Putting pen into proximity"); |
| 5535 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 5536 |
litest_tablet_motion(dev, 51, 51, axes); |
| 5537 |
litest_dispatch(li); |
| 5538 |
|
| 5539 |
litest_tablet_proximity_out(dev); |
| 5540 |
|
| 5541 |
litest_checkpoint("Unplugging/replugging device"); |
| 5542 |
litest_device_destroy(dev); |
| 5543 |
litest_dispatch(li); |
| 5544 |
litest_drain_events(li); |
| 5545 |
dev = litest_add_device(li, LITEST_WACOM_CINTIQ_PRO16_PEN); |
| 5546 |
litest_dispatch(li); |
| 5547 |
litest_drain_events(li); |
| 5548 |
} |
| 5549 |
|
| 5550 |
litest_checkpoint("Putting pen into proximity"); |
| 5551 |
|
| 5552 |
litest_tablet_proximity_in(dev, 49, 49, axes); |
| 5553 |
litest_dispatch(li); |
| 5554 |
litest_assert_tablet_proximity_event(li, |
| 5555 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 5556 |
|
| 5557 |
for (int i = 1; i < 5; i++) { |
| 5558 |
litest_tablet_motion(dev, 50 + i, 50 + i, axes); |
| 5559 |
litest_dispatch(li); |
| 5560 |
struct libinput_event *event = libinput_get_event(li); |
| 5561 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5562 |
libinput_event_destroy(event); |
| 5563 |
} |
| 5564 |
|
| 5565 |
litest_checkpoint("Putting pen tip down"); |
| 5566 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 5567 |
litest_axis_set_value(axes, ABS_PRESSURE, 10); |
| 5568 |
litest_tablet_tip_down(dev, 50, 50, axes); |
| 5569 |
litest_dispatch(li); |
| 5570 |
litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 5571 |
double old_pressure = 0; |
| 5572 |
for (int i = 1; i < 5; i++) { |
| 5573 |
litest_axis_set_value(axes, ABS_PRESSURE, 10 + i); |
| 5574 |
litest_tablet_motion(dev, 50 + i, 50 + i, axes); |
| 5575 |
litest_dispatch(li); |
| 5576 |
struct libinput_event *event = libinput_get_event(li); |
| 5577 |
struct libinput_event_tablet_tool *tev = |
| 5578 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5579 |
double pressure = libinput_event_tablet_tool_get_pressure(tev); |
| 5580 |
litest_assert_double_gt(pressure, old_pressure); |
| 5581 |
libinput_event_destroy(event); |
| 5582 |
} |
| 5583 |
|
| 5584 |
litest_checkpoint("Putting pen tip up"); |
| 5585 |
litest_axis_set_value(axes, ABS_DISTANCE, 20); |
| 5586 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 5587 |
litest_tablet_tip_up(dev, 50, 50, axes); |
| 5588 |
litest_dispatch(li); |
| 5589 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5590 |
litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_UP); |
| 5591 |
|
| 5592 |
litest_checkpoint("Putting out of proximity"); |
| 5593 |
litest_tablet_proximity_out(dev); |
| 5594 |
litest_timeout_tablet_proxout(li); |
| 5595 |
litest_assert_tablet_proximity_event(li, |
| 5596 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 5597 |
|
| 5598 |
litest_device_destroy(dev); |
| 5599 |
} |
| 5600 |
END_TEST |
| 5601 |
|
| 5602 |
START_TEST(tablet_distance_range) |
| 5603 |
{ |
| 5604 |
struct litest_device *dev = litest_current_device(); |
| 5605 |
struct libinput *li = dev->libinput; |
| 5606 |
struct libinput_event *event; |
| 5607 |
struct libinput_event_tablet_tool *tev; |
| 5608 |
struct axis_replacement axes[] = { |
| 5609 |
{ ABS_DISTANCE, 20 }, |
| 5610 |
{ ABS_PRESSURE, 0 }, |
| 5611 |
{ -1, -1 }, |
| 5612 |
}; |
| 5613 |
int distance; |
| 5614 |
double dist; |
| 5615 |
|
| 5616 |
litest_tablet_proximity_in(dev, 5, 100, axes); |
| 5617 |
litest_drain_events(li); |
| 5618 |
litest_dispatch(li); |
| 5619 |
|
| 5620 |
for (distance = 0; distance <= 100; distance += 10) { |
| 5621 |
litest_axis_set_value(axes, ABS_DISTANCE, distance); |
| 5622 |
litest_tablet_motion(dev, 70, 70, axes); |
| 5623 |
litest_dispatch(li); |
| 5624 |
|
| 5625 |
event = libinput_get_event(li); |
| 5626 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5627 |
dist = libinput_event_tablet_tool_get_distance(tev); |
| 5628 |
litest_assert_double_ge(dist, 0.0); |
| 5629 |
litest_assert_double_le(dist, 1.0); |
| 5630 |
libinput_event_destroy(event); |
| 5631 |
} |
| 5632 |
} |
| 5633 |
END_TEST |
| 5634 |
|
| 5635 |
START_TEST(tilt_available) |
| 5636 |
{ |
| 5637 |
struct litest_device *dev = litest_current_device(); |
| 5638 |
struct libinput *li = dev->libinput; |
| 5639 |
struct libinput_event *event; |
| 5640 |
struct libinput_event_tablet_tool *tev; |
| 5641 |
struct libinput_tablet_tool *tool; |
| 5642 |
struct axis_replacement axes[] = { |
| 5643 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 80 }, |
| 5644 |
{ ABS_TILT_Y, 20 }, { -1, -1 }, |
| 5645 |
}; |
| 5646 |
|
| 5647 |
litest_drain_events(li); |
| 5648 |
|
| 5649 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 5650 |
litest_dispatch(li); |
| 5651 |
event = libinput_get_event(li); |
| 5652 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5653 |
|
| 5654 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 5655 |
litest_assert(libinput_tablet_tool_has_tilt(tool)); |
| 5656 |
|
| 5657 |
libinput_event_destroy(event); |
| 5658 |
} |
| 5659 |
END_TEST |
| 5660 |
|
| 5661 |
START_TEST(tilt_not_available) |
| 5662 |
{ |
| 5663 |
struct litest_device *dev = litest_current_device(); |
| 5664 |
struct libinput *li = dev->libinput; |
| 5665 |
struct libinput_event *event; |
| 5666 |
struct libinput_event_tablet_tool *tev; |
| 5667 |
struct libinput_tablet_tool *tool; |
| 5668 |
struct axis_replacement axes[] = { |
| 5669 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 80 }, |
| 5670 |
{ ABS_TILT_Y, 20 }, { -1, -1 }, |
| 5671 |
}; |
| 5672 |
|
| 5673 |
litest_drain_events(li); |
| 5674 |
|
| 5675 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 5676 |
litest_dispatch(li); |
| 5677 |
event = libinput_get_event(li); |
| 5678 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5679 |
|
| 5680 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 5681 |
litest_assert(!libinput_tablet_tool_has_tilt(tool)); |
| 5682 |
|
| 5683 |
libinput_event_destroy(event); |
| 5684 |
} |
| 5685 |
END_TEST |
| 5686 |
|
| 5687 |
START_TEST(tilt_x) |
| 5688 |
{ |
| 5689 |
struct litest_device *dev = litest_current_device(); |
| 5690 |
struct libinput *li = dev->libinput; |
| 5691 |
struct libinput_event *event; |
| 5692 |
struct libinput_event_tablet_tool *tev; |
| 5693 |
struct axis_replacement axes[] = { |
| 5694 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 10 }, |
| 5695 |
{ ABS_TILT_Y, 0 }, { -1, -1 }, |
| 5696 |
}; |
| 5697 |
double tx, ty; |
| 5698 |
int tilt; |
| 5699 |
double expected_tx; |
| 5700 |
|
| 5701 |
litest_drain_events(li); |
| 5702 |
|
| 5703 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 5704 |
litest_dispatch(li); |
| 5705 |
event = libinput_get_event(li); |
| 5706 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5707 |
|
| 5708 |
/* 90% of the actual axis but mapped into a [-64, 64] tilt range, so |
| 5709 |
* we expect 51 degrees ± rounding errors */ |
| 5710 |
tx = libinput_event_tablet_tool_get_tilt_x(tev); |
| 5711 |
litest_assert_double_le(tx, -50); |
| 5712 |
litest_assert_double_ge(tx, -52); |
| 5713 |
|
| 5714 |
ty = libinput_event_tablet_tool_get_tilt_y(tev); |
| 5715 |
litest_assert_double_ge(ty, -65); |
| 5716 |
litest_assert_double_lt(ty, -63); |
| 5717 |
|
| 5718 |
libinput_event_destroy(event); |
| 5719 |
|
| 5720 |
expected_tx = -64.0; |
| 5721 |
|
| 5722 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 5723 |
litest_axis_set_value(axes, ABS_PRESSURE, 1); |
| 5724 |
|
| 5725 |
for (tilt = 0; tilt <= 100; tilt += 5) { |
| 5726 |
litest_axis_set_value(axes, ABS_TILT_X, tilt); |
| 5727 |
/* work around smoothing */ |
| 5728 |
litest_tablet_motion(dev, 10, 10, axes); |
| 5729 |
litest_tablet_motion(dev, 10, 11, axes); |
| 5730 |
litest_tablet_motion(dev, 10, 10, axes); |
| 5731 |
litest_drain_events(li); |
| 5732 |
litest_tablet_motion(dev, 10, 11, axes); |
| 5733 |
litest_dispatch(li); |
| 5734 |
event = libinput_get_event(li); |
| 5735 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5736 |
|
| 5737 |
tx = libinput_event_tablet_tool_get_tilt_x(tev); |
| 5738 |
litest_assert_double_ge(tx, expected_tx - 2); |
| 5739 |
litest_assert_double_le(tx, expected_tx + 2); |
| 5740 |
|
| 5741 |
ty = libinput_event_tablet_tool_get_tilt_y(tev); |
| 5742 |
litest_assert_double_ge(ty, -65); |
| 5743 |
litest_assert_double_lt(ty, -63); |
| 5744 |
|
| 5745 |
libinput_event_destroy(event); |
| 5746 |
|
| 5747 |
expected_tx = tx + 6.04; |
| 5748 |
} |
| 5749 |
|
| 5750 |
/* the last event must reach the max */ |
| 5751 |
litest_assert_double_ge(tx, 63.0); |
| 5752 |
litest_assert_double_le(tx, 64.0); |
| 5753 |
} |
| 5754 |
END_TEST |
| 5755 |
|
| 5756 |
START_TEST(tilt_y) |
| 5757 |
{ |
| 5758 |
struct litest_device *dev = litest_current_device(); |
| 5759 |
struct libinput *li = dev->libinput; |
| 5760 |
struct libinput_event *event; |
| 5761 |
struct libinput_event_tablet_tool *tev; |
| 5762 |
struct axis_replacement axes[] = { |
| 5763 |
{ ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, |
| 5764 |
{ ABS_TILT_Y, 10 }, { -1, -1 }, |
| 5765 |
}; |
| 5766 |
double tx, ty; |
| 5767 |
int tilt; |
| 5768 |
double expected_ty; |
| 5769 |
|
| 5770 |
litest_drain_events(li); |
| 5771 |
|
| 5772 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 5773 |
litest_dispatch(li); |
| 5774 |
event = libinput_get_event(li); |
| 5775 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5776 |
|
| 5777 |
/* 90% of the actual axis but mapped into a [-64, 64] tilt range, so |
| 5778 |
* we expect 50 degrees ± rounding errors */ |
| 5779 |
ty = libinput_event_tablet_tool_get_tilt_y(tev); |
| 5780 |
litest_assert_double_le(ty, -50); |
| 5781 |
litest_assert_double_ge(ty, -52); |
| 5782 |
|
| 5783 |
tx = libinput_event_tablet_tool_get_tilt_x(tev); |
| 5784 |
litest_assert_double_ge(tx, -65); |
| 5785 |
litest_assert_double_lt(tx, -63); |
| 5786 |
|
| 5787 |
libinput_event_destroy(event); |
| 5788 |
|
| 5789 |
expected_ty = -64; |
| 5790 |
|
| 5791 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 5792 |
litest_axis_set_value(axes, ABS_PRESSURE, 1); |
| 5793 |
|
| 5794 |
for (tilt = 0; tilt <= 100; tilt += 5) { |
| 5795 |
litest_axis_set_value(axes, ABS_TILT_Y, tilt); |
| 5796 |
/* work around smoothing */ |
| 5797 |
litest_tablet_motion(dev, 10, 11, axes); |
| 5798 |
litest_tablet_motion(dev, 10, 10, axes); |
| 5799 |
litest_tablet_motion(dev, 10, 11, axes); |
| 5800 |
litest_drain_events(li); |
| 5801 |
litest_tablet_motion(dev, 10, 10, axes); |
| 5802 |
litest_dispatch(li); |
| 5803 |
event = libinput_get_event(li); |
| 5804 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5805 |
|
| 5806 |
ty = libinput_event_tablet_tool_get_tilt_y(tev); |
| 5807 |
litest_assert_double_ge(ty, expected_ty - 2); |
| 5808 |
litest_assert_double_le(ty, expected_ty + 2); |
| 5809 |
|
| 5810 |
tx = libinput_event_tablet_tool_get_tilt_x(tev); |
| 5811 |
litest_assert_double_ge(tx, -65); |
| 5812 |
litest_assert_double_lt(tx, -63); |
| 5813 |
|
| 5814 |
libinput_event_destroy(event); |
| 5815 |
|
| 5816 |
expected_ty = ty + 6; |
| 5817 |
} |
| 5818 |
|
| 5819 |
/* the last event must reach the max */ |
| 5820 |
litest_assert_double_ge(ty, 63.0); |
| 5821 |
litest_assert_double_le(tx, 64.0); |
| 5822 |
} |
| 5823 |
END_TEST |
| 5824 |
|
| 5825 |
START_TEST(tilt_fixed_points) |
| 5826 |
{ |
| 5827 |
struct litest_device *dev = litest_current_device(); |
| 5828 |
struct libinput *li = dev->libinput; |
| 5829 |
struct libinput_event *event; |
| 5830 |
struct libinput_event_tablet_tool *tev; |
| 5831 |
struct axis_replacement axes[] = { |
| 5832 |
{ ABS_DISTANCE, 10 }, |
| 5833 |
{ ABS_PRESSURE, 0 }, |
| 5834 |
{ -1, -1 }, |
| 5835 |
}; |
| 5836 |
|
| 5837 |
/* On devices with a range of [-N, M], make sure we calculate the hw zero |
| 5838 |
* position as zero and that the respective min/max resolve to our (hardcoded) |
| 5839 |
* min/max degree values |
| 5840 |
*/ |
| 5841 |
const struct input_absinfo *abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_X); |
| 5842 |
if (abs->minimum >= 0) |
| 5843 |
return LITEST_NOT_APPLICABLE; |
| 5844 |
|
| 5845 |
/* If the tablet reports physical resolutions we don't need to test them */ |
| 5846 |
if (abs->resolution != 0) |
| 5847 |
return LITEST_NOT_APPLICABLE; |
| 5848 |
|
| 5849 |
/* see tablet_fix_tilt() */ |
| 5850 |
bool is_adjusted = (int)absinfo_range(abs) % 2 == 0; |
| 5851 |
|
| 5852 |
int axis_value; |
| 5853 |
double expected; |
| 5854 |
int testcase = litest_test_param_get_i32(test_env->params, "tilt"); |
| 5855 |
switch (testcase) { |
| 5856 |
case TILT_MINIMUM: |
| 5857 |
axis_value = abs->minimum; |
| 5858 |
expected = -64.0; |
| 5859 |
break; |
| 5860 |
case TILT_CENTER: |
| 5861 |
axis_value = 0; |
| 5862 |
expected = 0.0; |
| 5863 |
break; |
| 5864 |
case TILT_MAXIMUM: |
| 5865 |
axis_value = abs->maximum; |
| 5866 |
expected = 64.0; |
| 5867 |
break; |
| 5868 |
default: |
| 5869 |
litest_abort_msg("Invalid tilt testcase '%d'", testcase); |
| 5870 |
} |
| 5871 |
|
| 5872 |
litest_drain_events(li); |
| 5873 |
|
| 5874 |
litest_with_event_frame(dev) { |
| 5875 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 5876 |
litest_event(dev, EV_ABS, ABS_TILT_X, axis_value); |
| 5877 |
litest_event(dev, EV_ABS, ABS_TILT_Y, axis_value); |
| 5878 |
} |
| 5879 |
|
| 5880 |
litest_dispatch(li); |
| 5881 |
event = libinput_get_event(li); |
| 5882 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5883 |
|
| 5884 |
double tx = libinput_event_tablet_tool_get_tilt_x(tev); |
| 5885 |
double ty = libinput_event_tablet_tool_get_tilt_y(tev); |
| 5886 |
litest_assert_double_eq(tx, expected); |
| 5887 |
if (is_adjusted) { |
| 5888 |
litest_assert_double_ge(ty, expected - 1); |
| 5889 |
litest_assert_double_lt(ty, expected); |
| 5890 |
} else { |
| 5891 |
litest_assert_double_eq(ty, expected); |
| 5892 |
} |
| 5893 |
|
| 5894 |
libinput_event_destroy(event); |
| 5895 |
} |
| 5896 |
END_TEST |
| 5897 |
|
| 5898 |
START_TEST(relative_no_profile) |
| 5899 |
{ |
| 5900 |
struct litest_device *dev = litest_current_device(); |
| 5901 |
struct libinput_device *device = dev->libinput_device; |
| 5902 |
enum libinput_config_accel_profile profile; |
| 5903 |
enum libinput_config_status status; |
| 5904 |
uint32_t profiles; |
| 5905 |
|
| 5906 |
litest_assert(libinput_device_config_accel_is_available(device)); |
| 5907 |
|
| 5908 |
profile = libinput_device_config_accel_get_default_profile(device); |
| 5909 |
litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); |
| 5910 |
|
| 5911 |
profile = libinput_device_config_accel_get_profile(device); |
| 5912 |
litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); |
| 5913 |
|
| 5914 |
profiles = libinput_device_config_accel_get_profiles(device); |
| 5915 |
litest_assert_enum_eq(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, 0); |
| 5916 |
litest_assert_enum_eq(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, 0); |
| 5917 |
|
| 5918 |
status = libinput_device_config_accel_set_profile( |
| 5919 |
device, |
| 5920 |
LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); |
| 5921 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); |
| 5922 |
profile = libinput_device_config_accel_get_profile(device); |
| 5923 |
litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); |
| 5924 |
|
| 5925 |
status = libinput_device_config_accel_set_profile( |
| 5926 |
device, |
| 5927 |
LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); |
| 5928 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); |
| 5929 |
profile = libinput_device_config_accel_get_profile(device); |
| 5930 |
litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); |
| 5931 |
} |
| 5932 |
END_TEST |
| 5933 |
|
| 5934 |
START_TEST(relative_no_delta_prox_in) |
| 5935 |
{ |
| 5936 |
struct litest_device *dev = litest_current_device(); |
| 5937 |
struct libinput *li = dev->libinput; |
| 5938 |
struct libinput_event *event; |
| 5939 |
struct libinput_event_tablet_tool *tev; |
| 5940 |
struct axis_replacement axes[] = { |
| 5941 |
{ ABS_DISTANCE, 10 }, |
| 5942 |
{ ABS_PRESSURE, 0 }, |
| 5943 |
{ -1, -1 }, |
| 5944 |
}; |
| 5945 |
double dx, dy; |
| 5946 |
|
| 5947 |
litest_drain_events(li); |
| 5948 |
|
| 5949 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 5950 |
litest_dispatch(li); |
| 5951 |
event = libinput_get_event(li); |
| 5952 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 5953 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 5954 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 5955 |
litest_assert(dx == 0.0); |
| 5956 |
litest_assert(dy == 0.0); |
| 5957 |
|
| 5958 |
libinput_event_destroy(event); |
| 5959 |
} |
| 5960 |
END_TEST |
| 5961 |
|
| 5962 |
START_TEST(relative_delta) |
| 5963 |
{ |
| 5964 |
struct litest_device *dev = litest_current_device(); |
| 5965 |
struct libinput *li = dev->libinput; |
| 5966 |
struct libinput_event *event; |
| 5967 |
struct libinput_event_tablet_tool *tev; |
| 5968 |
struct axis_replacement axes[] = { |
| 5969 |
{ ABS_DISTANCE, 10 }, |
| 5970 |
{ ABS_PRESSURE, 0 }, |
| 5971 |
{ -1, -1 }, |
| 5972 |
}; |
| 5973 |
double dx, dy; |
| 5974 |
|
| 5975 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 5976 |
litest_drain_events(li); |
| 5977 |
|
| 5978 |
/* flush the motion history */ |
| 5979 |
for (int i = 0; i < 5; i++) |
| 5980 |
litest_tablet_motion(dev, 10 + i, 10, axes); |
| 5981 |
litest_drain_events(li); |
| 5982 |
|
| 5983 |
litest_tablet_motion(dev, 20, 10, axes); |
| 5984 |
litest_dispatch(li); |
| 5985 |
|
| 5986 |
event = libinput_get_event(li); |
| 5987 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 5988 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 5989 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 5990 |
litest_assert(dx > 0.0); |
| 5991 |
litest_assert(dy == 0.0); |
| 5992 |
libinput_event_destroy(event); |
| 5993 |
|
| 5994 |
/* flush the motion history */ |
| 5995 |
for (int i = 0; i < 5; i++) |
| 5996 |
litest_tablet_motion(dev, 20 - i, 10, axes); |
| 5997 |
litest_drain_events(li); |
| 5998 |
|
| 5999 |
litest_tablet_motion(dev, 5, 10, axes); |
| 6000 |
litest_dispatch(li); |
| 6001 |
event = libinput_get_event(li); |
| 6002 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6003 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6004 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6005 |
litest_assert(dx < 0.0); |
| 6006 |
litest_assert(dy == 0.0); |
| 6007 |
libinput_event_destroy(event); |
| 6008 |
|
| 6009 |
/* flush the motion history */ |
| 6010 |
for (int i = 0; i < 5; i++) |
| 6011 |
litest_tablet_motion(dev, 5, 10 + i, axes); |
| 6012 |
litest_drain_events(li); |
| 6013 |
|
| 6014 |
litest_tablet_motion(dev, 5, 20, axes); |
| 6015 |
litest_dispatch(li); |
| 6016 |
event = libinput_get_event(li); |
| 6017 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6018 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6019 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6020 |
litest_assert(dx == 0.0); |
| 6021 |
litest_assert(dy > 0.0); |
| 6022 |
libinput_event_destroy(event); |
| 6023 |
|
| 6024 |
/* flush the motion history */ |
| 6025 |
for (int i = 0; i < 5; i++) |
| 6026 |
litest_tablet_motion(dev, 5, 20 - i, axes); |
| 6027 |
litest_drain_events(li); |
| 6028 |
|
| 6029 |
litest_tablet_motion(dev, 5, 10, axes); |
| 6030 |
litest_dispatch(li); |
| 6031 |
event = libinput_get_event(li); |
| 6032 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6033 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6034 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6035 |
litest_assert(dx == 0.0); |
| 6036 |
litest_assert(dy < 0.0); |
| 6037 |
libinput_event_destroy(event); |
| 6038 |
} |
| 6039 |
END_TEST |
| 6040 |
|
| 6041 |
START_TEST(relative_no_delta_on_tip) |
| 6042 |
{ |
| 6043 |
struct litest_device *dev = litest_current_device(); |
| 6044 |
struct libinput *li = dev->libinput; |
| 6045 |
struct libinput_event *event; |
| 6046 |
struct libinput_event_tablet_tool *tev; |
| 6047 |
struct axis_replacement axes[] = { |
| 6048 |
{ ABS_DISTANCE, 10 }, |
| 6049 |
{ ABS_PRESSURE, 0 }, |
| 6050 |
{ -1, -1 }, |
| 6051 |
}; |
| 6052 |
double dx, dy; |
| 6053 |
|
| 6054 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 6055 |
litest_drain_events(li); |
| 6056 |
|
| 6057 |
litest_tablet_motion(dev, 20, 10, axes); |
| 6058 |
litest_drain_events(li); |
| 6059 |
|
| 6060 |
/* tip down */ |
| 6061 |
litest_axis_set_value(axes, ABS_DISTANCE, 0); |
| 6062 |
litest_axis_set_value(axes, ABS_PRESSURE, 30); |
| 6063 |
litest_tablet_tip_down(dev, 30, 20, axes); |
| 6064 |
|
| 6065 |
litest_dispatch(li); |
| 6066 |
event = libinput_get_event(li); |
| 6067 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 6068 |
litest_assert(libinput_event_tablet_tool_x_has_changed(tev)); |
| 6069 |
litest_assert(libinput_event_tablet_tool_y_has_changed(tev)); |
| 6070 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6071 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6072 |
litest_assert(dx == 0.0); |
| 6073 |
litest_assert(dy == 0.0); |
| 6074 |
libinput_event_destroy(event); |
| 6075 |
|
| 6076 |
/* normal motion */ |
| 6077 |
litest_tablet_motion(dev, 40, 30, axes); |
| 6078 |
litest_dispatch(li); |
| 6079 |
event = libinput_get_event(li); |
| 6080 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6081 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6082 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6083 |
litest_assert(dx > 0.0); |
| 6084 |
litest_assert(dy > 0.0); |
| 6085 |
libinput_event_destroy(event); |
| 6086 |
|
| 6087 |
/* tip up */ |
| 6088 |
litest_axis_set_value(axes, ABS_DISTANCE, 10); |
| 6089 |
litest_axis_set_value(axes, ABS_PRESSURE, 0); |
| 6090 |
litest_tablet_tip_up(dev, 50, 40, axes); |
| 6091 |
litest_dispatch(li); |
| 6092 |
event = libinput_get_event(li); |
| 6093 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); |
| 6094 |
litest_assert(libinput_event_tablet_tool_x_has_changed(tev)); |
| 6095 |
litest_assert(libinput_event_tablet_tool_y_has_changed(tev)); |
| 6096 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6097 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6098 |
litest_assert(dx == 0.0); |
| 6099 |
litest_assert(dy == 0.0); |
| 6100 |
libinput_event_destroy(event); |
| 6101 |
} |
| 6102 |
END_TEST |
| 6103 |
|
| 6104 |
START_TEST(relative_calibration) |
| 6105 |
{ |
| 6106 |
struct litest_device *dev = litest_current_device(); |
| 6107 |
struct libinput *li = dev->libinput; |
| 6108 |
struct libinput_event *event; |
| 6109 |
struct libinput_event_tablet_tool *tev; |
| 6110 |
struct axis_replacement axes[] = { |
| 6111 |
{ ABS_DISTANCE, 10 }, |
| 6112 |
{ ABS_PRESSURE, 0 }, |
| 6113 |
{ -1, -1 }, |
| 6114 |
}; |
| 6115 |
double dx, dy; |
| 6116 |
float calibration[] = { -1, 0, 1, 0, -1, 1 }; |
| 6117 |
enum libinput_config_status status; |
| 6118 |
|
| 6119 |
if (!libinput_device_config_calibration_has_matrix(dev->libinput_device)) |
| 6120 |
return LITEST_NOT_APPLICABLE; |
| 6121 |
|
| 6122 |
status = libinput_device_config_calibration_set_matrix(dev->libinput_device, |
| 6123 |
calibration); |
| 6124 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 6125 |
|
| 6126 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 6127 |
litest_drain_events(li); |
| 6128 |
|
| 6129 |
litest_tablet_motion(dev, 20, 10, axes); |
| 6130 |
litest_dispatch(li); |
| 6131 |
|
| 6132 |
event = libinput_get_event(li); |
| 6133 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6134 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6135 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6136 |
litest_assert(dx < 0.0); |
| 6137 |
litest_assert(dy == 0.0); |
| 6138 |
libinput_event_destroy(event); |
| 6139 |
|
| 6140 |
/* work around axis smoothing */ |
| 6141 |
litest_tablet_motion(dev, 19, 10, axes); |
| 6142 |
litest_tablet_motion(dev, 18, 10, axes); |
| 6143 |
litest_tablet_motion(dev, 17, 10, axes); |
| 6144 |
litest_drain_events(li); |
| 6145 |
|
| 6146 |
litest_tablet_motion(dev, 5, 10, axes); |
| 6147 |
litest_dispatch(li); |
| 6148 |
event = libinput_get_event(li); |
| 6149 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6150 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6151 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6152 |
litest_assert(dx > 0.0); |
| 6153 |
litest_assert(dy == 0.0); |
| 6154 |
libinput_event_destroy(event); |
| 6155 |
|
| 6156 |
/* work around axis smoothing */ |
| 6157 |
litest_tablet_motion(dev, 5, 11, axes); |
| 6158 |
litest_tablet_motion(dev, 5, 12, axes); |
| 6159 |
litest_tablet_motion(dev, 5, 13, axes); |
| 6160 |
litest_drain_events(li); |
| 6161 |
|
| 6162 |
litest_tablet_motion(dev, 5, 20, axes); |
| 6163 |
litest_dispatch(li); |
| 6164 |
event = libinput_get_event(li); |
| 6165 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6166 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6167 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6168 |
litest_assert(dx == 0.0); |
| 6169 |
litest_assert(dy < 0.0); |
| 6170 |
libinput_event_destroy(event); |
| 6171 |
|
| 6172 |
/* work around axis smoothing */ |
| 6173 |
litest_tablet_motion(dev, 5, 19, axes); |
| 6174 |
litest_tablet_motion(dev, 5, 18, axes); |
| 6175 |
litest_tablet_motion(dev, 5, 17, axes); |
| 6176 |
litest_drain_events(li); |
| 6177 |
|
| 6178 |
litest_tablet_motion(dev, 5, 5, axes); |
| 6179 |
litest_dispatch(li); |
| 6180 |
event = libinput_get_event(li); |
| 6181 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6182 |
dx = libinput_event_tablet_tool_get_dx(tev); |
| 6183 |
dy = libinput_event_tablet_tool_get_dy(tev); |
| 6184 |
litest_assert(dx == 0.0); |
| 6185 |
litest_assert(dy > 0.0); |
| 6186 |
libinput_event_destroy(event); |
| 6187 |
} |
| 6188 |
END_TEST |
| 6189 |
|
| 6190 |
static enum litest_device_type |
| 6191 |
paired_device(struct litest_device *dev) |
| 6192 |
{ |
| 6193 |
switch (dev->which) { |
| 6194 |
case LITEST_WACOM_INTUOS5_PEN: |
| 6195 |
return LITEST_WACOM_INTUOS5_FINGER; |
| 6196 |
case LITEST_WACOM_INTUOS5_FINGER: |
| 6197 |
return LITEST_WACOM_INTUOS5_PEN; |
| 6198 |
case LITEST_WACOM_CINTIQ_13HDT_PEN: |
| 6199 |
return LITEST_WACOM_CINTIQ_13HDT_FINGER; |
| 6200 |
case LITEST_WACOM_CINTIQ_13HDT_FINGER: |
| 6201 |
return LITEST_WACOM_CINTIQ_13HDT_PEN; |
| 6202 |
default: |
| 6203 |
return LITEST_NO_DEVICE; |
| 6204 |
} |
| 6205 |
} |
| 6206 |
|
| 6207 |
static void |
| 6208 |
assert_touch_is_arbitrated(struct litest_device *dev, struct litest_device *finger) |
| 6209 |
{ |
| 6210 |
struct libinput *li = dev->libinput; |
| 6211 |
bool is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); |
| 6212 |
struct axis_replacement axes[] = { |
| 6213 |
{ ABS_TILT_X, 80 }, { ABS_TILT_Y, 80 }, { ABS_DISTANCE, 10 }, |
| 6214 |
{ ABS_PRESSURE, 0 }, { -1, -1 }, |
| 6215 |
}; |
| 6216 |
|
| 6217 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 6218 |
litest_tablet_motion(dev, 10, 10, axes); |
| 6219 |
litest_tablet_motion(dev, 20, 40, axes); |
| 6220 |
litest_drain_events(li); |
| 6221 |
|
| 6222 |
double tx = 20; |
| 6223 |
double ty = 40; |
| 6224 |
double x = 21; |
| 6225 |
double y = 41; |
| 6226 |
litest_touch_down(finger, 0, x, y); |
| 6227 |
|
| 6228 |
/* We need to intersperce the touch events with tablets so we don't |
| 6229 |
trigger the tablet proximity timeout. */ |
| 6230 |
for (int i = 0; i < 60; i += 5) { |
| 6231 |
litest_touch_move(finger, 0, x + i, y + i); |
| 6232 |
litest_tablet_motion(dev, tx + 0.1 * i, ty + 0.1 * i, axes); |
| 6233 |
} |
| 6234 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6235 |
litest_tablet_proximity_out(dev); |
| 6236 |
litest_timeout_tablet_proxout(li); |
| 6237 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 6238 |
|
| 6239 |
litest_timeout_touch_arbitration(li); |
| 6240 |
|
| 6241 |
/* finger still down */ |
| 6242 |
litest_touch_move_to(finger, 0, 80, 80, 30, 30, 10); |
| 6243 |
litest_touch_up(finger, 0); |
| 6244 |
litest_assert_empty_queue(li); |
| 6245 |
|
| 6246 |
litest_timeout_touch_arbitration(li); |
| 6247 |
|
| 6248 |
/* lift finger, expect expect events */ |
| 6249 |
litest_touch_down(finger, 0, 30, 30); |
| 6250 |
litest_touch_move_to(finger, 0, 30, 30, 80, 80, 10); |
| 6251 |
litest_touch_up(finger, 0); |
| 6252 |
litest_dispatch(li); |
| 6253 |
|
| 6254 |
if (is_touchpad) |
| 6255 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); |
| 6256 |
else |
| 6257 |
litest_assert_touch_sequence(li); |
| 6258 |
} |
| 6259 |
|
| 6260 |
START_TEST(touch_arbitration) |
| 6261 |
{ |
| 6262 |
struct litest_device *dev = litest_current_device(); |
| 6263 |
enum litest_device_type other; |
| 6264 |
struct libinput *li = dev->libinput; |
| 6265 |
|
| 6266 |
other = paired_device(dev); |
| 6267 |
if (other == LITEST_NO_DEVICE) |
| 6268 |
return LITEST_NOT_APPLICABLE; |
| 6269 |
|
| 6270 |
struct litest_device *finger = litest_add_device(li, other); |
| 6271 |
litest_drain_events(li); |
| 6272 |
|
| 6273 |
bool is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); |
| 6274 |
if (is_touchpad) |
| 6275 |
litest_disable_hold_gestures(finger->libinput_device); |
| 6276 |
|
| 6277 |
assert_touch_is_arbitrated(dev, finger); |
| 6278 |
|
| 6279 |
litest_device_destroy(finger); |
| 6280 |
} |
| 6281 |
END_TEST |
| 6282 |
|
| 6283 |
START_TEST(touch_arbitration_outside_rect) |
| 6284 |
{ |
| 6285 |
struct litest_device *dev = litest_current_device(); |
| 6286 |
enum litest_device_type other; |
| 6287 |
struct litest_device *finger; |
| 6288 |
struct libinput *li = dev->libinput; |
| 6289 |
struct axis_replacement axes[] = { |
| 6290 |
{ ABS_TILT_X, 80 }, { ABS_TILT_Y, 80 }, { ABS_DISTANCE, 10 }, |
| 6291 |
{ ABS_PRESSURE, 0 }, { -1, -1 }, |
| 6292 |
}; |
| 6293 |
double x, y; |
| 6294 |
bool is_touchpad; |
| 6295 |
|
| 6296 |
other = paired_device(dev); |
| 6297 |
if (other == LITEST_NO_DEVICE) |
| 6298 |
return LITEST_NOT_APPLICABLE; |
| 6299 |
|
| 6300 |
finger = litest_add_device(li, other); |
| 6301 |
litest_drain_events(li); |
| 6302 |
|
| 6303 |
is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); |
| 6304 |
if (is_touchpad) |
| 6305 |
return LITEST_NOT_APPLICABLE; |
| 6306 |
|
| 6307 |
x = 20; |
| 6308 |
y = 70; |
| 6309 |
|
| 6310 |
/* disable prox-out timer quirk */ |
| 6311 |
litest_tablet_proximity_in(dev, x, y - 1, axes); |
| 6312 |
litest_tablet_proximity_out(dev); |
| 6313 |
litest_timeout_tablet_proxout(li); |
| 6314 |
|
| 6315 |
litest_tablet_proximity_in(dev, x, y - 1, axes); |
| 6316 |
litest_drain_events(li); |
| 6317 |
|
| 6318 |
/* these are in percent, but the pen/finger have different |
| 6319 |
* resolution and the rect works in mm, so the numbers below are |
| 6320 |
* hand-picked for the test device */ |
| 6321 |
litest_tablet_motion(dev, x, y, axes); |
| 6322 |
litest_drain_events(li); |
| 6323 |
|
| 6324 |
/* left of rect */ |
| 6325 |
litest_touch_sequence(finger, 0, x - 10, y + 2, x - 10, y + 20, 3); |
| 6326 |
litest_dispatch(li); |
| 6327 |
litest_assert_touch_sequence(li); |
| 6328 |
|
| 6329 |
/* above rect */ |
| 6330 |
litest_touch_sequence(finger, 0, x + 2, y - 65, x + 20, y - 40, 3); |
| 6331 |
litest_dispatch(li); |
| 6332 |
litest_assert_touch_sequence(li); |
| 6333 |
|
| 6334 |
/* right of rect */ |
| 6335 |
litest_touch_sequence(finger, 0, x + 80, y + 2, x + 20, y + 10, 3); |
| 6336 |
litest_dispatch(li); |
| 6337 |
litest_assert_touch_sequence(li); |
| 6338 |
|
| 6339 |
#if 0 |
| 6340 |
/* This *should* work but the Cintiq test devices is <200mm |
| 6341 |
high, so we can't test for anything below the tip */ |
| 6342 |
x = 20; |
| 6343 |
y = 10; |
| 6344 |
litest_tablet_proximity_out(dev); |
| 6345 |
litest_timeout_tablet_proxout(li); |
| 6346 |
litest_tablet_motion(dev, x, y, axes); |
| 6347 |
litest_tablet_proximity_in(dev, x, y - 1, axes); |
| 6348 |
litest_drain_events(li); |
| 6349 |
|
| 6350 |
/* below rect */ |
| 6351 |
litest_touch_sequence(finger, 0, x + 2, y + 80, x + 20, y + 20, 30); |
| 6352 |
litest_dispatch(li); |
| 6353 |
litest_assert_touch_sequence(li); |
| 6354 |
#endif |
| 6355 |
|
| 6356 |
litest_device_destroy(finger); |
| 6357 |
} |
| 6358 |
END_TEST |
| 6359 |
|
| 6360 |
START_TEST(touch_arbitration_remove_after) |
| 6361 |
{ |
| 6362 |
struct litest_device *dev = litest_current_device(); |
| 6363 |
enum litest_device_type other; |
| 6364 |
struct litest_device *finger; |
| 6365 |
struct libinput *li = dev->libinput; |
| 6366 |
struct axis_replacement axes[] = { |
| 6367 |
{ ABS_TILT_X, 80 }, { ABS_TILT_Y, 80 }, { ABS_DISTANCE, 10 }, |
| 6368 |
{ ABS_PRESSURE, 0 }, { -1, -1 }, |
| 6369 |
}; |
| 6370 |
bool is_touchpad; |
| 6371 |
|
| 6372 |
other = paired_device(dev); |
| 6373 |
if (other == LITEST_NO_DEVICE) |
| 6374 |
return LITEST_NOT_APPLICABLE; |
| 6375 |
|
| 6376 |
finger = litest_add_device(li, other); |
| 6377 |
litest_drain_events(li); |
| 6378 |
|
| 6379 |
is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); |
| 6380 |
if (is_touchpad) |
| 6381 |
return LITEST_NOT_APPLICABLE; |
| 6382 |
|
| 6383 |
litest_tablet_proximity_in(dev, 50, 50, axes); |
| 6384 |
litest_drain_events(li); |
| 6385 |
|
| 6386 |
litest_touch_down(finger, 0, 70, 70); |
| 6387 |
litest_drain_events(li); |
| 6388 |
litest_tablet_proximity_out(dev); |
| 6389 |
litest_timeout_tablet_proxout(li); |
| 6390 |
|
| 6391 |
/* Delete the device immediately after the tablet goes out of prox. |
| 6392 |
* This merely tests that the arbitration timer gets cleaned up */ |
| 6393 |
litest_device_destroy(finger); |
| 6394 |
} |
| 6395 |
END_TEST |
| 6396 |
|
| 6397 |
START_TEST(touch_arbitration_stop_touch) |
| 6398 |
{ |
| 6399 |
struct litest_device *dev = litest_current_device(); |
| 6400 |
enum litest_device_type other; |
| 6401 |
struct litest_device *finger; |
| 6402 |
struct libinput *li = dev->libinput; |
| 6403 |
struct axis_replacement axes[] = { |
| 6404 |
{ ABS_DISTANCE, 10 }, |
| 6405 |
{ ABS_PRESSURE, 0 }, |
| 6406 |
{ -1, -1 }, |
| 6407 |
}; |
| 6408 |
bool is_touchpad; |
| 6409 |
|
| 6410 |
other = paired_device(dev); |
| 6411 |
if (other == LITEST_NO_DEVICE) |
| 6412 |
return LITEST_NOT_APPLICABLE; |
| 6413 |
|
| 6414 |
finger = litest_add_device(li, other); |
| 6415 |
|
| 6416 |
is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); |
| 6417 |
|
| 6418 |
if (is_touchpad) |
| 6419 |
litest_disable_hold_gestures(finger->libinput_device); |
| 6420 |
|
| 6421 |
/* disable prox-out timer quirk */ |
| 6422 |
litest_tablet_proximity_in(dev, 30, 30, axes); |
| 6423 |
litest_tablet_proximity_out(dev); |
| 6424 |
litest_timeout_tablet_proxout(li); |
| 6425 |
litest_drain_events(li); |
| 6426 |
|
| 6427 |
litest_touch_down(finger, 0, 30, 30); |
| 6428 |
litest_touch_move_to(finger, 0, 30, 30, 80, 80, 10); |
| 6429 |
|
| 6430 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 6431 |
litest_tablet_motion(dev, 10, 10, axes); |
| 6432 |
litest_tablet_motion(dev, 20, 40, axes); |
| 6433 |
litest_drain_events(li); |
| 6434 |
|
| 6435 |
litest_touch_move_to(finger, 0, 80, 80, 30, 30, 10); |
| 6436 |
litest_assert_empty_queue(li); |
| 6437 |
|
| 6438 |
/* tablet event so we don't time out for proximity */ |
| 6439 |
litest_tablet_motion(dev, 30, 40, axes); |
| 6440 |
litest_drain_events(li); |
| 6441 |
|
| 6442 |
/* start another finger to make sure that one doesn't send events |
| 6443 |
either */ |
| 6444 |
litest_touch_down(finger, 1, 30, 30); |
| 6445 |
litest_touch_move_to(finger, 1, 30, 30, 80, 80, 3); |
| 6446 |
litest_assert_empty_queue(li); |
| 6447 |
|
| 6448 |
litest_tablet_motion(dev, 10, 10, axes); |
| 6449 |
litest_tablet_motion(dev, 20, 40, axes); |
| 6450 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6451 |
litest_tablet_proximity_out(dev); |
| 6452 |
litest_drain_events(li); |
| 6453 |
|
| 6454 |
litest_timeout_tablet_proxout(li); |
| 6455 |
litest_drain_events(li); |
| 6456 |
|
| 6457 |
/* Finger needs to be lifted for events to happen*/ |
| 6458 |
litest_touch_move_to(finger, 0, 30, 30, 80, 80, 3); |
| 6459 |
litest_assert_empty_queue(li); |
| 6460 |
litest_touch_move_to(finger, 1, 80, 80, 30, 30, 3); |
| 6461 |
litest_assert_empty_queue(li); |
| 6462 |
litest_touch_up(finger, 0); |
| 6463 |
litest_touch_move_to(finger, 1, 30, 30, 80, 80, 3); |
| 6464 |
litest_assert_empty_queue(li); |
| 6465 |
litest_touch_up(finger, 1); |
| 6466 |
litest_dispatch(li); |
| 6467 |
|
| 6468 |
litest_touch_down(finger, 0, 30, 30); |
| 6469 |
litest_touch_move_to(finger, 0, 30, 30, 80, 80, 3); |
| 6470 |
litest_touch_up(finger, 0); |
| 6471 |
litest_dispatch(li); |
| 6472 |
|
| 6473 |
if (is_touchpad) |
| 6474 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); |
| 6475 |
else |
| 6476 |
litest_assert_touch_sequence(li); |
| 6477 |
|
| 6478 |
litest_device_destroy(finger); |
| 6479 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); |
| 6480 |
} |
| 6481 |
END_TEST |
| 6482 |
|
| 6483 |
START_TEST(touch_arbitration_suspend_touch_device) |
| 6484 |
{ |
| 6485 |
struct litest_device *dev = litest_current_device(); |
| 6486 |
enum litest_device_type other; |
| 6487 |
struct litest_device *tablet; |
| 6488 |
struct libinput *li = dev->libinput; |
| 6489 |
enum libinput_config_status status; |
| 6490 |
struct axis_replacement axes[] = { |
| 6491 |
{ ABS_DISTANCE, 10 }, |
| 6492 |
{ ABS_PRESSURE, 0 }, |
| 6493 |
{ -1, -1 }, |
| 6494 |
}; |
| 6495 |
bool is_touchpad; |
| 6496 |
|
| 6497 |
other = paired_device(dev); |
| 6498 |
if (other == LITEST_NO_DEVICE) |
| 6499 |
return LITEST_NOT_APPLICABLE; |
| 6500 |
|
| 6501 |
tablet = litest_add_device(li, other); |
| 6502 |
|
| 6503 |
is_touchpad = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); |
| 6504 |
|
| 6505 |
if (is_touchpad) |
| 6506 |
litest_disable_hold_gestures(dev->libinput_device); |
| 6507 |
|
| 6508 |
/* we can't force a device suspend, but we can at least make sure |
| 6509 |
the device doesn't send events */ |
| 6510 |
status = libinput_device_config_send_events_set_mode( |
| 6511 |
dev->libinput_device, |
| 6512 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 6513 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 6514 |
|
| 6515 |
litest_drain_events(li); |
| 6516 |
|
| 6517 |
/* Disable the proximity timer */ |
| 6518 |
litest_tablet_proximity_in(tablet, 12, 12, axes); |
| 6519 |
litest_tablet_proximity_out(tablet); |
| 6520 |
litest_timeout_tablet_proxout(li); |
| 6521 |
litest_drain_events(li); |
| 6522 |
|
| 6523 |
litest_tablet_proximity_in(tablet, 10, 10, axes); |
| 6524 |
litest_tablet_motion(tablet, 10, 10, axes); |
| 6525 |
litest_tablet_motion(tablet, 20, 40, axes); |
| 6526 |
litest_drain_events(li); |
| 6527 |
|
| 6528 |
litest_touch_down(dev, 0, 30, 30); |
| 6529 |
litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); |
| 6530 |
litest_touch_up(dev, 0); |
| 6531 |
litest_assert_empty_queue(li); |
| 6532 |
|
| 6533 |
/* Remove tablet device to unpair, still disabled though */ |
| 6534 |
litest_device_destroy(tablet); |
| 6535 |
litest_assert_tablet_proximity_event(li, |
| 6536 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 6537 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); |
| 6538 |
|
| 6539 |
litest_timeout_touch_arbitration(li); |
| 6540 |
|
| 6541 |
litest_touch_down(dev, 0, 30, 30); |
| 6542 |
litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); |
| 6543 |
litest_touch_up(dev, 0); |
| 6544 |
litest_assert_empty_queue(li); |
| 6545 |
|
| 6546 |
/* Touch device is still disabled */ |
| 6547 |
litest_touch_down(dev, 0, 30, 30); |
| 6548 |
litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); |
| 6549 |
litest_touch_up(dev, 0); |
| 6550 |
litest_assert_empty_queue(li); |
| 6551 |
|
| 6552 |
status = libinput_device_config_send_events_set_mode( |
| 6553 |
dev->libinput_device, |
| 6554 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 6555 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 6556 |
|
| 6557 |
litest_touch_down(dev, 0, 30, 30); |
| 6558 |
litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); |
| 6559 |
litest_touch_up(dev, 0); |
| 6560 |
litest_dispatch(li); |
| 6561 |
|
| 6562 |
if (is_touchpad) |
| 6563 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); |
| 6564 |
else |
| 6565 |
litest_assert_touch_sequence(li); |
| 6566 |
} |
| 6567 |
END_TEST |
| 6568 |
|
| 6569 |
START_TEST(touch_arbitration_remove_touch) |
| 6570 |
{ |
| 6571 |
struct litest_device *dev = litest_current_device(); |
| 6572 |
enum litest_device_type other; |
| 6573 |
struct litest_device *finger; |
| 6574 |
struct libinput *li = dev->libinput; |
| 6575 |
struct axis_replacement axes[] = { |
| 6576 |
{ ABS_DISTANCE, 10 }, |
| 6577 |
{ ABS_PRESSURE, 0 }, |
| 6578 |
{ -1, -1 }, |
| 6579 |
}; |
| 6580 |
|
| 6581 |
other = paired_device(dev); |
| 6582 |
if (other == LITEST_NO_DEVICE) |
| 6583 |
return LITEST_NOT_APPLICABLE; |
| 6584 |
|
| 6585 |
/* Disable the proximity timer */ |
| 6586 |
litest_tablet_proximity_in(dev, 12, 12, axes); |
| 6587 |
litest_tablet_proximity_out(dev); |
| 6588 |
litest_timeout_tablet_proxout(li); |
| 6589 |
litest_drain_events(li); |
| 6590 |
|
| 6591 |
finger = litest_add_device(li, other); |
| 6592 |
litest_touch_down(finger, 0, 30, 30); |
| 6593 |
litest_touch_move_to(finger, 0, 30, 30, 80, 80, 10); |
| 6594 |
|
| 6595 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 6596 |
litest_drain_events(li); |
| 6597 |
|
| 6598 |
litest_device_destroy(finger); |
| 6599 |
litest_dispatch(li); |
| 6600 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); |
| 6601 |
litest_assert_empty_queue(li); |
| 6602 |
|
| 6603 |
litest_tablet_motion(dev, 10, 10, axes); |
| 6604 |
litest_tablet_motion(dev, 20, 40, axes); |
| 6605 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6606 |
} |
| 6607 |
END_TEST |
| 6608 |
|
| 6609 |
START_TEST(touch_arbitration_remove_tablet) |
| 6610 |
{ |
| 6611 |
struct litest_device *dev = litest_current_device(); |
| 6612 |
enum litest_device_type other; |
| 6613 |
struct litest_device *tablet; |
| 6614 |
struct libinput *li = dev->libinput; |
| 6615 |
struct axis_replacement axes[] = { |
| 6616 |
{ ABS_DISTANCE, 10 }, |
| 6617 |
{ ABS_PRESSURE, 0 }, |
| 6618 |
{ -1, -1 }, |
| 6619 |
}; |
| 6620 |
bool is_touchpad; |
| 6621 |
|
| 6622 |
other = paired_device(dev); |
| 6623 |
if (other == LITEST_NO_DEVICE) |
| 6624 |
return LITEST_NOT_APPLICABLE; |
| 6625 |
|
| 6626 |
tablet = litest_add_device(li, other); |
| 6627 |
|
| 6628 |
is_touchpad = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); |
| 6629 |
|
| 6630 |
if (is_touchpad) |
| 6631 |
litest_disable_hold_gestures(dev->libinput_device); |
| 6632 |
|
| 6633 |
/* Disable the proximity timer */ |
| 6634 |
litest_tablet_proximity_in(tablet, 12, 12, axes); |
| 6635 |
litest_tablet_proximity_out(tablet); |
| 6636 |
litest_timeout_tablet_proxout(li); |
| 6637 |
litest_drain_events(li); |
| 6638 |
|
| 6639 |
litest_dispatch(li); |
| 6640 |
litest_tablet_proximity_in(tablet, 10, 10, axes); |
| 6641 |
litest_tablet_motion(tablet, 10, 10, axes); |
| 6642 |
litest_tablet_motion(tablet, 20, 40, axes); |
| 6643 |
litest_drain_events(li); |
| 6644 |
|
| 6645 |
litest_touch_down(dev, 0, 30, 30); |
| 6646 |
litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); |
| 6647 |
litest_assert_empty_queue(li); |
| 6648 |
|
| 6649 |
litest_device_destroy(tablet); |
| 6650 |
litest_assert_tablet_proximity_event(li, |
| 6651 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 6652 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); |
| 6653 |
|
| 6654 |
litest_timeout_touch_arbitration(li); |
| 6655 |
|
| 6656 |
/* Touch is still down, don't enable */ |
| 6657 |
litest_touch_move_to(dev, 0, 80, 80, 30, 30, 10); |
| 6658 |
litest_touch_up(dev, 0); |
| 6659 |
litest_assert_empty_queue(li); |
| 6660 |
|
| 6661 |
litest_touch_down(dev, 0, 30, 30); |
| 6662 |
litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); |
| 6663 |
litest_touch_up(dev, 0); |
| 6664 |
litest_dispatch(li); |
| 6665 |
|
| 6666 |
if (is_touchpad) |
| 6667 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); |
| 6668 |
else |
| 6669 |
litest_assert_touch_sequence(li); |
| 6670 |
} |
| 6671 |
END_TEST |
| 6672 |
|
| 6673 |
START_TEST(touch_arbitration_keep_ignoring) |
| 6674 |
{ |
| 6675 |
struct litest_device *tablet = litest_current_device(); |
| 6676 |
enum litest_device_type other; |
| 6677 |
struct litest_device *finger; |
| 6678 |
struct libinput *li = tablet->libinput; |
| 6679 |
struct axis_replacement axes[] = { |
| 6680 |
{ ABS_DISTANCE, 10 }, |
| 6681 |
{ ABS_PRESSURE, 0 }, |
| 6682 |
{ -1, -1 }, |
| 6683 |
}; |
| 6684 |
|
| 6685 |
other = paired_device(tablet); |
| 6686 |
if (other == LITEST_NO_DEVICE) |
| 6687 |
return LITEST_NOT_APPLICABLE; |
| 6688 |
|
| 6689 |
/* Disable the proximity timer */ |
| 6690 |
litest_tablet_proximity_in(tablet, 12, 12, axes); |
| 6691 |
litest_tablet_proximity_out(tablet); |
| 6692 |
litest_timeout_tablet_proxout(li); |
| 6693 |
litest_drain_events(li); |
| 6694 |
|
| 6695 |
finger = litest_add_device(li, other); |
| 6696 |
litest_tablet_proximity_in(tablet, 10, 10, axes); |
| 6697 |
litest_tablet_motion(tablet, 10, 10, axes); |
| 6698 |
litest_tablet_motion(tablet, 20, 40, axes); |
| 6699 |
|
| 6700 |
litest_touch_down(finger, 0, 30, 30); |
| 6701 |
litest_drain_events(li); |
| 6702 |
|
| 6703 |
litest_tablet_proximity_out(tablet); |
| 6704 |
litest_dispatch(li); |
| 6705 |
litest_timeout_tablet_proxout(li); |
| 6706 |
litest_drain_events(li); |
| 6707 |
|
| 6708 |
/* a touch during pen interaction stays a palm after the pen lifts. |
| 6709 |
*/ |
| 6710 |
litest_touch_move_to(finger, 0, 30, 30, 80, 80, 10); |
| 6711 |
litest_touch_up(finger, 0); |
| 6712 |
litest_dispatch(li); |
| 6713 |
|
| 6714 |
litest_assert_empty_queue(li); |
| 6715 |
|
| 6716 |
litest_device_destroy(finger); |
| 6717 |
} |
| 6718 |
END_TEST |
| 6719 |
|
| 6720 |
START_TEST(touch_arbitration_late_touch_lift) |
| 6721 |
{ |
| 6722 |
struct litest_device *tablet = litest_current_device(); |
| 6723 |
enum litest_device_type other; |
| 6724 |
struct litest_device *finger; |
| 6725 |
struct libinput *li = tablet->libinput; |
| 6726 |
struct axis_replacement axes[] = { |
| 6727 |
{ ABS_DISTANCE, 10 }, |
| 6728 |
{ ABS_PRESSURE, 0 }, |
| 6729 |
{ -1, -1 }, |
| 6730 |
}; |
| 6731 |
bool is_touchpad; |
| 6732 |
|
| 6733 |
other = paired_device(tablet); |
| 6734 |
if (other == LITEST_NO_DEVICE) |
| 6735 |
return LITEST_NOT_APPLICABLE; |
| 6736 |
|
| 6737 |
/* Disable the proximity timer */ |
| 6738 |
litest_tablet_proximity_in(tablet, 12, 12, axes); |
| 6739 |
litest_tablet_proximity_out(tablet); |
| 6740 |
litest_timeout_tablet_proxout(li); |
| 6741 |
litest_drain_events(li); |
| 6742 |
|
| 6743 |
finger = litest_add_device(li, other); |
| 6744 |
is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); |
| 6745 |
if (is_touchpad) { |
| 6746 |
litest_enable_tap(finger->libinput_device); |
| 6747 |
litest_disable_hold_gestures(finger->libinput_device); |
| 6748 |
} |
| 6749 |
|
| 6750 |
litest_tablet_proximity_in(tablet, 10, 10, axes); |
| 6751 |
litest_tablet_motion(tablet, 10, 10, axes); |
| 6752 |
litest_tablet_motion(tablet, 20, 40, axes); |
| 6753 |
litest_drain_events(li); |
| 6754 |
|
| 6755 |
litest_tablet_proximity_out(tablet); |
| 6756 |
litest_drain_events(li); |
| 6757 |
|
| 6758 |
/* with kernel arbitration, a finger + stylus in prox only generates |
| 6759 |
* stylus events. When a user lifts the hand with the stylus, the |
| 6760 |
* stylus usually goes out of prox while the hand is still touching |
| 6761 |
* the surface. This causes a touch down event now that the stylus |
| 6762 |
* is out of proximity. A few ms later, the hand really lifts off |
| 6763 |
* the surface, causing a touch down and thus a fake tap event. |
| 6764 |
*/ |
| 6765 |
litest_touch_down(finger, 0, 30, 30); |
| 6766 |
litest_touch_up(finger, 0); |
| 6767 |
litest_timeout_tap(li); |
| 6768 |
|
| 6769 |
litest_assert_empty_queue(li); |
| 6770 |
|
| 6771 |
litest_device_destroy(finger); |
| 6772 |
} |
| 6773 |
END_TEST |
| 6774 |
|
| 6775 |
START_TEST(touch_arbitration_swap_device) |
| 6776 |
{ |
| 6777 |
struct litest_device *tablet = litest_current_device(); |
| 6778 |
struct libinput *li = tablet->libinput; |
| 6779 |
struct axis_replacement axes[] = { |
| 6780 |
{ ABS_DISTANCE, 10 }, |
| 6781 |
{ ABS_PRESSURE, 0 }, |
| 6782 |
{ -1, -1 }, |
| 6783 |
}; |
| 6784 |
|
| 6785 |
enum litest_device_type paired = paired_device(tablet); |
| 6786 |
if (paired == LITEST_NO_DEVICE) |
| 6787 |
return LITEST_NOT_APPLICABLE; |
| 6788 |
|
| 6789 |
/* Disable the proximity timer */ |
| 6790 |
litest_tablet_proximity_in(tablet, 12, 12, axes); |
| 6791 |
litest_tablet_proximity_out(tablet); |
| 6792 |
litest_timeout_tablet_proxout(li); |
| 6793 |
litest_drain_events(li); |
| 6794 |
|
| 6795 |
/* First, add a normal touchscreen */ |
| 6796 |
struct litest_device *touchscreen = |
| 6797 |
litest_add_device(li, LITEST_GENERIC_MULTITOUCH_SCREEN); |
| 6798 |
libinput_device_config_gesture_set_hold_enabled(touchscreen->libinput_device, |
| 6799 |
LIBINPUT_CONFIG_HOLD_DISABLED); |
| 6800 |
litest_drain_events(li); |
| 6801 |
assert_touch_is_arbitrated(tablet, touchscreen); |
| 6802 |
|
| 6803 |
/* Now add a better device to override the pairing */ |
| 6804 |
struct litest_device *finger = litest_add_device(li, paired); |
| 6805 |
libinput_device_config_gesture_set_hold_enabled(finger->libinput_device, |
| 6806 |
LIBINPUT_CONFIG_HOLD_DISABLED); |
| 6807 |
litest_drain_events(li); |
| 6808 |
assert_touch_is_arbitrated(tablet, finger); |
| 6809 |
|
| 6810 |
litest_device_destroy(touchscreen); |
| 6811 |
litest_device_destroy(finger); |
| 6812 |
} |
| 6813 |
END_TEST |
| 6814 |
|
| 6815 |
#ifdef HAVE_LIBWACOM |
| 6816 |
static void |
| 6817 |
verify_left_handed_tablet_motion(struct litest_device *tablet, |
| 6818 |
struct libinput *li, |
| 6819 |
double x, |
| 6820 |
double y, |
| 6821 |
bool left_handed) |
| 6822 |
{ |
| 6823 |
struct libinput_event *event; |
| 6824 |
struct libinput_event_tablet_tool *t; |
| 6825 |
|
| 6826 |
/* proximity in/out must be handled by caller */ |
| 6827 |
|
| 6828 |
for (int i = 5; i < 25; i += 5) { |
| 6829 |
litest_tablet_motion(tablet, x + i, y - i, NULL); |
| 6830 |
litest_dispatch(li); |
| 6831 |
} |
| 6832 |
|
| 6833 |
event = libinput_get_event(li); |
| 6834 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6835 |
x = libinput_event_tablet_tool_get_x(t); |
| 6836 |
y = libinput_event_tablet_tool_get_y(t); |
| 6837 |
libinput_event_destroy(event); |
| 6838 |
|
| 6839 |
event = libinput_get_event(li); |
| 6840 |
litest_assert_ptr_notnull(event); |
| 6841 |
|
| 6842 |
while (event) { |
| 6843 |
double last_x = x, last_y = y; |
| 6844 |
|
| 6845 |
t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 6846 |
x = libinput_event_tablet_tool_get_x(t); |
| 6847 |
y = libinput_event_tablet_tool_get_y(t); |
| 6848 |
|
| 6849 |
if (left_handed) { |
| 6850 |
litest_assert_double_lt(x, last_x); |
| 6851 |
litest_assert_double_gt(y, last_y); |
| 6852 |
} else { |
| 6853 |
litest_assert_double_gt(x, last_x); |
| 6854 |
litest_assert_double_lt(y, last_y); |
| 6855 |
} |
| 6856 |
|
| 6857 |
libinput_event_destroy(event); |
| 6858 |
event = libinput_get_event(li); |
| 6859 |
} |
| 6860 |
} |
| 6861 |
|
| 6862 |
static void |
| 6863 |
verify_left_handed_tablet_sequence(struct litest_device *tablet, |
| 6864 |
struct libinput *li, |
| 6865 |
bool left_handed) |
| 6866 |
{ |
| 6867 |
double x, y; |
| 6868 |
|
| 6869 |
/* verifies a whole sequence, including prox in/out and timeouts */ |
| 6870 |
x = 60; |
| 6871 |
y = 60; |
| 6872 |
litest_tablet_proximity_in(tablet, x, y, NULL); |
| 6873 |
litest_dispatch(li); |
| 6874 |
litest_drain_events(li); |
| 6875 |
verify_left_handed_tablet_motion(tablet, li, x, y, left_handed); |
| 6876 |
litest_tablet_proximity_out(tablet); |
| 6877 |
litest_timeout_tablet_proxout(li); |
| 6878 |
litest_drain_events(li); |
| 6879 |
} |
| 6880 |
|
| 6881 |
static void |
| 6882 |
verify_left_handed_touch_motion(struct litest_device *finger, |
| 6883 |
struct libinput *li, |
| 6884 |
double x, |
| 6885 |
double y, |
| 6886 |
bool left_handed) |
| 6887 |
{ |
| 6888 |
struct libinput_event *event; |
| 6889 |
struct libinput_event_pointer *p; |
| 6890 |
|
| 6891 |
/* touch down/up must be handled by caller */ |
| 6892 |
|
| 6893 |
litest_touch_move_to(finger, 0, x + 1, y - 1, x + 20, y - 20, 10); |
| 6894 |
litest_dispatch(li); |
| 6895 |
|
| 6896 |
event = libinput_get_event(li); |
| 6897 |
litest_assert_notnull(event); |
| 6898 |
|
| 6899 |
while (event) { |
| 6900 |
p = litest_is_motion_event(event); |
| 6901 |
x = libinput_event_pointer_get_dx(p); |
| 6902 |
y = libinput_event_pointer_get_dy(p); |
| 6903 |
|
| 6904 |
if (left_handed) { |
| 6905 |
litest_assert_double_lt(x, 0); |
| 6906 |
litest_assert_double_gt(y, 0); |
| 6907 |
} else { |
| 6908 |
litest_assert_double_gt(x, 0); |
| 6909 |
litest_assert_double_lt(y, 0); |
| 6910 |
} |
| 6911 |
|
| 6912 |
libinput_event_destroy(event); |
| 6913 |
event = libinput_get_event(li); |
| 6914 |
} |
| 6915 |
} |
| 6916 |
|
| 6917 |
static void |
| 6918 |
verify_left_handed_touch_sequence(struct litest_device *finger, |
| 6919 |
struct libinput *li, |
| 6920 |
bool left_handed) |
| 6921 |
{ |
| 6922 |
double x, y; |
| 6923 |
|
| 6924 |
/* verifies a whole sequence, including prox in/out and timeouts */ |
| 6925 |
|
| 6926 |
x = 10; |
| 6927 |
y = 30; |
| 6928 |
litest_touch_down(finger, 0, x, y); |
| 6929 |
litest_drain_events(li); |
| 6930 |
verify_left_handed_touch_motion(finger, li, x, y, left_handed); |
| 6931 |
litest_touch_up(finger, 0); |
| 6932 |
litest_dispatch(li); |
| 6933 |
} |
| 6934 |
#endif |
| 6935 |
|
| 6936 |
START_TEST(tablet_rotation_left_handed) |
| 6937 |
{ |
| 6938 |
#ifdef HAVE_LIBWACOM |
| 6939 |
struct litest_device *tablet = litest_current_device(); |
| 6940 |
enum litest_device_type other; |
| 6941 |
struct litest_device *finger; |
| 6942 |
struct libinput *li = tablet->libinput; |
| 6943 |
|
| 6944 |
other = paired_device(tablet); |
| 6945 |
if (other == LITEST_NO_DEVICE) |
| 6946 |
return LITEST_NOT_APPLICABLE; |
| 6947 |
|
| 6948 |
finger = litest_add_device(li, other); |
| 6949 |
litest_drain_events(li); |
| 6950 |
|
| 6951 |
if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) |
| 6952 |
goto out; |
| 6953 |
|
| 6954 |
bool tablet_from = litest_test_param_get_bool(test_env->params, "tablet_from"); |
| 6955 |
bool touch_from = litest_test_param_get_bool(test_env->params, "touch_from"); |
| 6956 |
bool tablet_to = litest_test_param_get_bool(test_env->params, "tablet_to"); |
| 6957 |
bool touch_to = litest_test_param_get_bool(test_env->params, "touch_to"); |
| 6958 |
|
| 6959 |
bool enabled_from = tablet_from || touch_from; |
| 6960 |
bool enabled_to = tablet_to || touch_to; |
| 6961 |
|
| 6962 |
litest_disable_hold_gestures(finger->libinput_device); |
| 6963 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); |
| 6964 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_from); |
| 6965 |
verify_left_handed_tablet_sequence(tablet, li, enabled_from); |
| 6966 |
verify_left_handed_touch_sequence(finger, li, enabled_from); |
| 6967 |
|
| 6968 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); |
| 6969 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_to); |
| 6970 |
verify_left_handed_tablet_sequence(tablet, li, enabled_to); |
| 6971 |
verify_left_handed_touch_sequence(finger, li, enabled_to); |
| 6972 |
|
| 6973 |
out: |
| 6974 |
litest_device_destroy(finger); |
| 6975 |
#endif |
| 6976 |
} |
| 6977 |
END_TEST |
| 6978 |
|
| 6979 |
START_TEST(tablet_rotation_left_handed_configuration) |
| 6980 |
{ |
| 6981 |
#ifdef HAVE_LIBWACOM |
| 6982 |
struct litest_device *tablet = litest_current_device(); |
| 6983 |
enum litest_device_type other; |
| 6984 |
struct litest_device *finger; |
| 6985 |
struct libinput *li = tablet->libinput; |
| 6986 |
bool tablet_enabled, touch_enabled; |
| 6987 |
struct libinput_device *tablet_dev, *touch_dev; |
| 6988 |
|
| 6989 |
other = paired_device(tablet); |
| 6990 |
if (other == LITEST_NO_DEVICE) |
| 6991 |
return LITEST_NOT_APPLICABLE; |
| 6992 |
|
| 6993 |
finger = litest_add_device(li, other); |
| 6994 |
litest_drain_events(li); |
| 6995 |
|
| 6996 |
if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) |
| 6997 |
goto out; |
| 6998 |
|
| 6999 |
bool tablet_from = litest_test_param_get_bool(test_env->params, "tablet_from"); |
| 7000 |
bool touch_from = litest_test_param_get_bool(test_env->params, "touch_from"); |
| 7001 |
bool tablet_to = litest_test_param_get_bool(test_env->params, "tablet_to"); |
| 7002 |
bool touch_to = litest_test_param_get_bool(test_env->params, "touch_to"); |
| 7003 |
|
| 7004 |
tablet_dev = tablet->libinput_device; |
| 7005 |
touch_dev = finger->libinput_device; |
| 7006 |
|
| 7007 |
/* Make sure that toggling one device doesn't toggle the other one */ |
| 7008 |
|
| 7009 |
libinput_device_config_left_handed_set(tablet_dev, tablet_from); |
| 7010 |
libinput_device_config_left_handed_set(touch_dev, touch_from); |
| 7011 |
litest_dispatch(li); |
| 7012 |
tablet_enabled = libinput_device_config_left_handed_get(tablet_dev); |
| 7013 |
touch_enabled = libinput_device_config_left_handed_get(touch_dev); |
| 7014 |
litest_assert_int_eq(tablet_enabled, tablet_from); |
| 7015 |
litest_assert_int_eq(touch_enabled, touch_from); |
| 7016 |
|
| 7017 |
libinput_device_config_left_handed_set(tablet_dev, tablet_to); |
| 7018 |
libinput_device_config_left_handed_set(touch_dev, touch_to); |
| 7019 |
litest_dispatch(li); |
| 7020 |
tablet_enabled = libinput_device_config_left_handed_get(tablet_dev); |
| 7021 |
touch_enabled = libinput_device_config_left_handed_get(touch_dev); |
| 7022 |
litest_assert_int_eq(tablet_enabled, tablet_to); |
| 7023 |
litest_assert_int_eq(touch_enabled, touch_to); |
| 7024 |
|
| 7025 |
out: |
| 7026 |
litest_device_destroy(finger); |
| 7027 |
#endif |
| 7028 |
} |
| 7029 |
END_TEST |
| 7030 |
|
| 7031 |
START_TEST(tablet_rotation_left_handed_while_in_prox) |
| 7032 |
{ |
| 7033 |
#ifdef HAVE_LIBWACOM |
| 7034 |
struct litest_device *tablet = litest_current_device(); |
| 7035 |
enum litest_device_type other; |
| 7036 |
struct litest_device *finger; |
| 7037 |
struct libinput *li = tablet->libinput; |
| 7038 |
double x, y; |
| 7039 |
double tx, ty; |
| 7040 |
|
| 7041 |
other = paired_device(tablet); |
| 7042 |
if (other == LITEST_NO_DEVICE) |
| 7043 |
return LITEST_NOT_APPLICABLE; |
| 7044 |
|
| 7045 |
finger = litest_add_device(li, other); |
| 7046 |
litest_drain_events(li); |
| 7047 |
|
| 7048 |
if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) |
| 7049 |
goto out; |
| 7050 |
|
| 7051 |
bool tablet_from = litest_test_param_get_bool(test_env->params, "tablet_from"); |
| 7052 |
bool touch_from = litest_test_param_get_bool(test_env->params, "touch_from"); |
| 7053 |
bool tablet_to = litest_test_param_get_bool(test_env->params, "tablet_to"); |
| 7054 |
bool touch_to = litest_test_param_get_bool(test_env->params, "touch_to"); |
| 7055 |
|
| 7056 |
bool enabled_from = tablet_from || touch_from; |
| 7057 |
bool enabled_to = tablet_to || touch_to; |
| 7058 |
|
| 7059 |
litest_disable_hold_gestures(finger->libinput_device); |
| 7060 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_from); |
| 7061 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); |
| 7062 |
|
| 7063 |
litest_checkpoint("Moving into proximity"); |
| 7064 |
tx = 60; |
| 7065 |
ty = 60; |
| 7066 |
litest_tablet_proximity_in(tablet, tx, ty, NULL); |
| 7067 |
litest_dispatch(li); |
| 7068 |
litest_drain_events(li); |
| 7069 |
|
| 7070 |
litest_checkpoint("Changing tablet to left-handed: %s", truefalse(tablet_to)); |
| 7071 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); |
| 7072 |
litest_checkpoint("Changing touch to left-handed: %s", truefalse(touch_to)); |
| 7073 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_to); |
| 7074 |
|
| 7075 |
/* not yet neutral, so still whatever the original was */ |
| 7076 |
litest_checkpoint("Expecting tablet motion with left-handed: %s", |
| 7077 |
truefalse(enabled_from)); |
| 7078 |
verify_left_handed_tablet_motion(tablet, li, tx, ty, enabled_from); |
| 7079 |
litest_drain_events(li); |
| 7080 |
|
| 7081 |
/* test pointer, should be left-handed already */ |
| 7082 |
#if 0 |
| 7083 |
/* Touch arbitration discards events, so we can't check for the |
| 7084 |
right behaviour here. */ |
| 7085 |
verify_left_handed_touch_sequence(finger, li, enabled_to); |
| 7086 |
#else |
| 7087 |
x = 10; |
| 7088 |
y = 30; |
| 7089 |
litest_touch_down(finger, 0, x, y); |
| 7090 |
|
| 7091 |
/* We need to intersperse the touch events with tablets so we don't |
| 7092 |
trigger the tablet proximity timeout. */ |
| 7093 |
for (int i = 0; i < 10; i++) { |
| 7094 |
litest_touch_move(finger, 0, x + i, y - i); |
| 7095 |
litest_tablet_motion(tablet, tx + 0.1 * i, ty + 0.1 * i, NULL); |
| 7096 |
} |
| 7097 |
|
| 7098 |
litest_touch_up(finger, 0); |
| 7099 |
litest_dispatch(li); |
| 7100 |
/* this will fail once we have location-based touch arbitration on |
| 7101 |
* touchpads */ |
| 7102 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7103 |
#endif |
| 7104 |
litest_checkpoint("Moving out of proximity"); |
| 7105 |
litest_tablet_proximity_out(tablet); |
| 7106 |
litest_timeout_tablet_proxout(li); |
| 7107 |
litest_drain_events(li); |
| 7108 |
|
| 7109 |
litest_assert_empty_queue(li); |
| 7110 |
|
| 7111 |
/* now both should've switched */ |
| 7112 |
litest_checkpoint("Expecting tablet motion with left-handed: %s", |
| 7113 |
truefalse(enabled_to)); |
| 7114 |
verify_left_handed_tablet_sequence(tablet, li, enabled_to); |
| 7115 |
litest_checkpoint("Expecting touch motion with left-handed: %s", |
| 7116 |
truefalse(enabled_to)); |
| 7117 |
verify_left_handed_touch_sequence(finger, li, enabled_to); |
| 7118 |
|
| 7119 |
out: |
| 7120 |
litest_device_destroy(finger); |
| 7121 |
#endif |
| 7122 |
} |
| 7123 |
END_TEST |
| 7124 |
|
| 7125 |
START_TEST(tablet_rotation_left_handed_while_touch_down) |
| 7126 |
{ |
| 7127 |
#ifdef HAVE_LIBWACOM |
| 7128 |
struct litest_device *tablet = litest_current_device(); |
| 7129 |
enum litest_device_type other; |
| 7130 |
struct litest_device *finger; |
| 7131 |
struct libinput *li = tablet->libinput; |
| 7132 |
double x, y; |
| 7133 |
|
| 7134 |
other = paired_device(tablet); |
| 7135 |
if (other == LITEST_NO_DEVICE) |
| 7136 |
return LITEST_NOT_APPLICABLE; |
| 7137 |
|
| 7138 |
finger = litest_add_device(li, other); |
| 7139 |
litest_drain_events(li); |
| 7140 |
|
| 7141 |
if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) |
| 7142 |
goto out; |
| 7143 |
|
| 7144 |
bool tablet_from = litest_test_param_get_bool(test_env->params, "tablet_from"); |
| 7145 |
bool touch_from = litest_test_param_get_bool(test_env->params, "touch_from"); |
| 7146 |
bool tablet_to = litest_test_param_get_bool(test_env->params, "tablet_to"); |
| 7147 |
bool touch_to = litest_test_param_get_bool(test_env->params, "touch_to"); |
| 7148 |
|
| 7149 |
bool enabled_from = tablet_from || touch_from; |
| 7150 |
bool enabled_to = tablet_to || touch_to; |
| 7151 |
|
| 7152 |
litest_disable_hold_gestures(finger->libinput_device); |
| 7153 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_from); |
| 7154 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); |
| 7155 |
|
| 7156 |
/* Touch down when setting to left-handed */ |
| 7157 |
x = 10; |
| 7158 |
y = 30; |
| 7159 |
litest_touch_down(finger, 0, x, y); |
| 7160 |
litest_dispatch(li); |
| 7161 |
litest_drain_events(li); |
| 7162 |
|
| 7163 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); |
| 7164 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_to); |
| 7165 |
|
| 7166 |
/* not yet neutral, so still whatever the original was */ |
| 7167 |
verify_left_handed_touch_motion(finger, li, x, y, enabled_from); |
| 7168 |
litest_assert_empty_queue(li); |
| 7169 |
|
| 7170 |
/* test tablet, should be left-handed already */ |
| 7171 |
verify_left_handed_tablet_sequence(tablet, li, enabled_to); |
| 7172 |
|
| 7173 |
litest_touch_up(finger, 0); |
| 7174 |
litest_drain_events(li); |
| 7175 |
|
| 7176 |
/* now both should've switched */ |
| 7177 |
verify_left_handed_tablet_sequence(tablet, li, enabled_to); |
| 7178 |
verify_left_handed_touch_sequence(finger, li, enabled_to); |
| 7179 |
|
| 7180 |
out: |
| 7181 |
litest_device_destroy(finger); |
| 7182 |
#endif |
| 7183 |
} |
| 7184 |
END_TEST |
| 7185 |
|
| 7186 |
START_TEST(tablet_rotation_left_handed_add_touchpad) |
| 7187 |
{ |
| 7188 |
#ifdef HAVE_LIBWACOM |
| 7189 |
struct litest_device *tablet = litest_current_device(); |
| 7190 |
enum litest_device_type other; |
| 7191 |
struct litest_device *finger; |
| 7192 |
struct libinput *li = tablet->libinput; |
| 7193 |
|
| 7194 |
other = paired_device(tablet); |
| 7195 |
if (other == LITEST_NO_DEVICE) |
| 7196 |
return LITEST_NOT_APPLICABLE; |
| 7197 |
|
| 7198 |
bool tablet_from = litest_test_param_get_bool(test_env->params, "tablet_from"); |
| 7199 |
bool touch_from = litest_test_param_get_bool(test_env->params, "touch_from"); |
| 7200 |
bool tablet_to = litest_test_param_get_bool(test_env->params, "tablet_to"); |
| 7201 |
bool touch_to = litest_test_param_get_bool(test_env->params, "touch_to"); |
| 7202 |
|
| 7203 |
bool enabled_from = tablet_from || touch_from; |
| 7204 |
bool enabled_to = tablet_to || touch_to; |
| 7205 |
|
| 7206 |
/* change left-handed before touchpad appears */ |
| 7207 |
|
| 7208 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); |
| 7209 |
|
| 7210 |
finger = litest_add_device(li, other); |
| 7211 |
litest_drain_events(li); |
| 7212 |
|
| 7213 |
if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) |
| 7214 |
goto out; |
| 7215 |
|
| 7216 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_from); |
| 7217 |
litest_disable_hold_gestures(finger->libinput_device); |
| 7218 |
|
| 7219 |
verify_left_handed_touch_sequence(finger, li, enabled_from); |
| 7220 |
verify_left_handed_tablet_sequence(tablet, li, enabled_from); |
| 7221 |
|
| 7222 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); |
| 7223 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_to); |
| 7224 |
|
| 7225 |
verify_left_handed_touch_sequence(finger, li, enabled_to); |
| 7226 |
verify_left_handed_tablet_sequence(tablet, li, enabled_to); |
| 7227 |
|
| 7228 |
out: |
| 7229 |
litest_device_destroy(finger); |
| 7230 |
#endif |
| 7231 |
} |
| 7232 |
END_TEST |
| 7233 |
|
| 7234 |
START_TEST(tablet_rotation_left_handed_add_tablet) |
| 7235 |
{ |
| 7236 |
#ifdef HAVE_LIBWACOM |
| 7237 |
struct litest_device *finger = litest_current_device(); |
| 7238 |
enum litest_device_type other; |
| 7239 |
struct litest_device *tablet; |
| 7240 |
struct libinput *li = finger->libinput; |
| 7241 |
unsigned int transition = _i; /* ranged test */ |
| 7242 |
bool tablet_from, touch_from, tablet_to, touch_to; |
| 7243 |
bool enabled_from, enabled_to; |
| 7244 |
|
| 7245 |
if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) |
| 7246 |
return LITEST_NOT_APPLICABLE; |
| 7247 |
|
| 7248 |
other = paired_device(finger); |
| 7249 |
if (other == LITEST_NO_DEVICE) |
| 7250 |
return LITEST_NOT_APPLICABLE; |
| 7251 |
|
| 7252 |
tablet_from = !!(transition & bit(0)); |
| 7253 |
touch_from = !!(transition & bit(1)); |
| 7254 |
tablet_to = !!(transition & bit(2)); |
| 7255 |
touch_to = !!(transition & bit(3)); |
| 7256 |
|
| 7257 |
enabled_from = tablet_from || touch_from; |
| 7258 |
enabled_to = tablet_to || touch_to; |
| 7259 |
|
| 7260 |
/* change left-handed before tablet appears */ |
| 7261 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_from); |
| 7262 |
litest_disable_hold_gestures(finger->libinput_device); |
| 7263 |
|
| 7264 |
tablet = litest_add_device(li, other); |
| 7265 |
litest_drain_events(li); |
| 7266 |
|
| 7267 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); |
| 7268 |
|
| 7269 |
verify_left_handed_touch_sequence(finger, li, enabled_from); |
| 7270 |
verify_left_handed_tablet_sequence(tablet, li, enabled_from); |
| 7271 |
|
| 7272 |
libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); |
| 7273 |
libinput_device_config_left_handed_set(finger->libinput_device, touch_to); |
| 7274 |
|
| 7275 |
verify_left_handed_touch_sequence(finger, li, enabled_to); |
| 7276 |
verify_left_handed_tablet_sequence(tablet, li, enabled_to); |
| 7277 |
|
| 7278 |
litest_device_destroy(tablet); |
| 7279 |
#endif |
| 7280 |
} |
| 7281 |
END_TEST |
| 7282 |
|
| 7283 |
START_TEST(huion_static_btn_tool_pen) |
| 7284 |
{ |
| 7285 |
struct litest_device *dev = litest_current_device(); |
| 7286 |
struct libinput *li = dev->libinput; |
| 7287 |
int i; |
| 7288 |
bool send_btn_tool = |
| 7289 |
litest_test_param_get_bool(test_env->params, "send-btn-tool"); |
| 7290 |
|
| 7291 |
litest_drain_events(li); |
| 7292 |
|
| 7293 |
litest_event(dev, EV_ABS, ABS_X, 20000); |
| 7294 |
litest_event(dev, EV_ABS, ABS_Y, 20000); |
| 7295 |
litest_event(dev, EV_ABS, ABS_PRESSURE, 100); |
| 7296 |
if (send_btn_tool) |
| 7297 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 7298 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7299 |
litest_drain_events(li); |
| 7300 |
|
| 7301 |
for (i = 0; i < 10; i++) { |
| 7302 |
litest_event(dev, EV_ABS, ABS_X, 20000 + 10 * i); |
| 7303 |
litest_event(dev, EV_ABS, ABS_Y, 20000 - 10 * i); |
| 7304 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7305 |
litest_dispatch(li); |
| 7306 |
} |
| 7307 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7308 |
|
| 7309 |
/* Wait past the timeout to expect a proximity out */ |
| 7310 |
litest_timeout_tablet_proxout(li); |
| 7311 |
litest_assert_tablet_proximity_event(li, |
| 7312 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 7313 |
litest_dispatch(li); |
| 7314 |
|
| 7315 |
/* New events should fake a proximity in again */ |
| 7316 |
litest_event(dev, EV_ABS, ABS_X, 20000); |
| 7317 |
litest_event(dev, EV_ABS, ABS_Y, 20000); |
| 7318 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7319 |
litest_dispatch(li); |
| 7320 |
litest_assert_tablet_proximity_event(li, |
| 7321 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 7322 |
litest_dispatch(li); |
| 7323 |
|
| 7324 |
for (i = 0; i < 10; i++) { |
| 7325 |
litest_event(dev, EV_ABS, ABS_X, 20000 + 10 * i); |
| 7326 |
litest_event(dev, EV_ABS, ABS_Y, 20000 - 10 * i); |
| 7327 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7328 |
litest_dispatch(li); |
| 7329 |
} |
| 7330 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7331 |
litest_timeout_tablet_proxout(li); |
| 7332 |
litest_assert_tablet_proximity_event(li, |
| 7333 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 7334 |
litest_dispatch(li); |
| 7335 |
|
| 7336 |
/* New events, just to ensure cleanup paths are correct */ |
| 7337 |
litest_event(dev, EV_ABS, ABS_X, 20000); |
| 7338 |
litest_event(dev, EV_ABS, ABS_Y, 20000); |
| 7339 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7340 |
litest_dispatch(li); |
| 7341 |
} |
| 7342 |
END_TEST |
| 7343 |
|
| 7344 |
START_TEST(huion_static_btn_tool_pen_no_timeout_during_usage) |
| 7345 |
{ |
| 7346 |
struct litest_device *dev = litest_current_device(); |
| 7347 |
struct libinput *li = dev->libinput; |
| 7348 |
int i; |
| 7349 |
bool send_btn_tool = |
| 7350 |
litest_test_param_get_bool(test_env->params, "send-btn-tool"); |
| 7351 |
|
| 7352 |
litest_drain_events(li); |
| 7353 |
|
| 7354 |
litest_event(dev, EV_ABS, ABS_X, 20000); |
| 7355 |
litest_event(dev, EV_ABS, ABS_Y, 20000); |
| 7356 |
litest_event(dev, EV_ABS, ABS_PRESSURE, 100); |
| 7357 |
if (send_btn_tool) |
| 7358 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 7359 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7360 |
litest_drain_events(li); |
| 7361 |
|
| 7362 |
/* take longer than the no-activity timeout */ |
| 7363 |
for (i = 0; i < 50; i++) { |
| 7364 |
litest_event(dev, EV_ABS, ABS_X, 20000 + 10 * i); |
| 7365 |
litest_event(dev, EV_ABS, ABS_Y, 20000 - 10 * i); |
| 7366 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7367 |
litest_dispatch(li); |
| 7368 |
msleep(5); |
| 7369 |
} |
| 7370 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7371 |
litest_timeout_tablet_proxout(li); |
| 7372 |
litest_dispatch(li); |
| 7373 |
litest_assert_tablet_proximity_event(li, |
| 7374 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 7375 |
litest_dispatch(li); |
| 7376 |
} |
| 7377 |
END_TEST |
| 7378 |
|
| 7379 |
START_TEST(huion_static_btn_tool_pen_disable_quirk_on_prox_out) |
| 7380 |
{ |
| 7381 |
struct litest_device *dev = litest_current_device(); |
| 7382 |
struct libinput *li = dev->libinput; |
| 7383 |
int i; |
| 7384 |
|
| 7385 |
/* test is run twice, once where the real BTN_TOOL_PEN is triggered |
| 7386 |
* during proximity out, one where the real BTN_TOOL_PEN is |
| 7387 |
* triggered after we already triggered the quirk timeout |
| 7388 |
*/ |
| 7389 |
bool with_timeout = |
| 7390 |
litest_test_param_get_bool(test_env->params, "btn_tool_pen_timeout"); |
| 7391 |
|
| 7392 |
litest_drain_events(li); |
| 7393 |
|
| 7394 |
litest_event(dev, EV_ABS, ABS_X, 20000); |
| 7395 |
litest_event(dev, EV_ABS, ABS_Y, 20000); |
| 7396 |
litest_event(dev, EV_ABS, ABS_PRESSURE, 100); |
| 7397 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); |
| 7398 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7399 |
litest_drain_events(li); |
| 7400 |
|
| 7401 |
for (i = 0; i < 3; i++) { |
| 7402 |
litest_event(dev, EV_ABS, ABS_X, 20000 + 10 * i); |
| 7403 |
litest_event(dev, EV_ABS, ABS_Y, 20000 - 10 * i); |
| 7404 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7405 |
litest_dispatch(li); |
| 7406 |
} |
| 7407 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7408 |
|
| 7409 |
/* Wait past the timeout to expect a proximity out */ |
| 7410 |
if (with_timeout) { |
| 7411 |
litest_timeout_tablet_proxout(li); |
| 7412 |
litest_assert_tablet_proximity_event( |
| 7413 |
li, |
| 7414 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 7415 |
} |
| 7416 |
|
| 7417 |
litest_checkpoint("Sending BTN_TOOL_PEN 0 "); |
| 7418 |
/* Send a real prox out, expect quirk to be disabled */ |
| 7419 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); |
| 7420 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7421 |
litest_dispatch(li); |
| 7422 |
|
| 7423 |
if (with_timeout) { |
| 7424 |
/* we got the proximity event above already */ |
| 7425 |
litest_assert_empty_queue(li); |
| 7426 |
} else { |
| 7427 |
litest_assert_tablet_proximity_event( |
| 7428 |
li, |
| 7429 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 7430 |
} |
| 7431 |
|
| 7432 |
litest_tablet_proximity_in(dev, 50, 50, NULL); |
| 7433 |
litest_dispatch(li); |
| 7434 |
litest_assert_tablet_proximity_event(li, |
| 7435 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 7436 |
|
| 7437 |
for (i = 0; i < 3; i++) { |
| 7438 |
litest_tablet_motion(dev, 50 + i, 50 + i, NULL); |
| 7439 |
litest_dispatch(li); |
| 7440 |
} |
| 7441 |
|
| 7442 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7443 |
|
| 7444 |
/* Expect the timeout quirk to be disabled */ |
| 7445 |
litest_timeout_tablet_proxout(li); |
| 7446 |
|
| 7447 |
litest_assert_empty_queue(li); |
| 7448 |
|
| 7449 |
litest_with_event_frame(dev) { |
| 7450 |
litest_tablet_proximity_out(dev); |
| 7451 |
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); |
| 7452 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7453 |
} |
| 7454 |
litest_dispatch(li); |
| 7455 |
|
| 7456 |
litest_assert_tablet_proximity_event(li, |
| 7457 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 7458 |
litest_assert_empty_queue(li); |
| 7459 |
} |
| 7460 |
END_TEST |
| 7461 |
|
| 7462 |
START_TEST(tablet_smoothing) |
| 7463 |
{ |
| 7464 |
#ifdef HAVE_LIBWACOM |
| 7465 |
struct litest_device *dev = litest_current_device(); |
| 7466 |
struct libinput *li = dev->libinput; |
| 7467 |
double x, y; |
| 7468 |
struct point { |
| 7469 |
double x, y; |
| 7470 |
} coordinates[100] = { 0 }; |
| 7471 |
size_t npoints = 0; |
| 7472 |
size_t idx = 0; |
| 7473 |
struct axis_replacement axes[] = { |
| 7474 |
{ ABS_DISTANCE, 10 }, |
| 7475 |
{ ABS_PRESSURE, 0 }, |
| 7476 |
{ -1, -1 }, |
| 7477 |
}; |
| 7478 |
|
| 7479 |
litest_drain_events(li); |
| 7480 |
|
| 7481 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 7482 |
litest_dispatch(li); |
| 7483 |
litest_drain_events(li); |
| 7484 |
|
| 7485 |
/* Move in a straight line, collect the resulting points */ |
| 7486 |
for (x = 11, y = 11; x < 50; x++, y++) { |
| 7487 |
struct libinput_event *event; |
| 7488 |
struct libinput_event_tablet_tool *tev; |
| 7489 |
struct point *p = &coordinates[npoints++]; |
| 7490 |
|
| 7491 |
litest_assert(npoints <= ARRAY_LENGTH(coordinates)); |
| 7492 |
|
| 7493 |
litest_tablet_motion(dev, x, y, axes); |
| 7494 |
litest_dispatch(li); |
| 7495 |
|
| 7496 |
event = libinput_get_event(li); |
| 7497 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7498 |
p->x = libinput_event_tablet_tool_get_x(tev); |
| 7499 |
p->y = libinput_event_tablet_tool_get_y(tev); |
| 7500 |
|
| 7501 |
libinput_event_destroy(event); |
| 7502 |
} |
| 7503 |
|
| 7504 |
litest_tablet_proximity_out(dev); |
| 7505 |
litest_timeout_tablet_proxout(li); |
| 7506 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 7507 |
litest_dispatch(li); |
| 7508 |
litest_drain_events(li); |
| 7509 |
|
| 7510 |
/* Move in a wobbly line, collect every second point */ |
| 7511 |
for (x = 11, y = 11; x < 50; x++, y++) { |
| 7512 |
struct libinput_event *event; |
| 7513 |
struct libinput_event_tablet_tool *tev; |
| 7514 |
double ex, ey; |
| 7515 |
struct point *p = &coordinates[idx++]; |
| 7516 |
|
| 7517 |
litest_assert(idx <= npoints); |
| 7518 |
|
| 7519 |
/* point off position */ |
| 7520 |
litest_tablet_motion(dev, x - 2, y + 1, axes); |
| 7521 |
litest_dispatch(li); |
| 7522 |
event = libinput_get_event(li); |
| 7523 |
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7524 |
libinput_event_destroy(event); |
| 7525 |
|
| 7526 |
/* same position as before */ |
| 7527 |
litest_tablet_motion(dev, x, y, axes); |
| 7528 |
litest_dispatch(li); |
| 7529 |
event = libinput_get_event(li); |
| 7530 |
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7531 |
ex = libinput_event_tablet_tool_get_x(tev); |
| 7532 |
ey = libinput_event_tablet_tool_get_y(tev); |
| 7533 |
|
| 7534 |
litest_assert_double_eq(ex, p->x); |
| 7535 |
litest_assert_double_eq(ey, p->y); |
| 7536 |
|
| 7537 |
libinput_event_destroy(event); |
| 7538 |
} |
| 7539 |
#endif |
| 7540 |
} |
| 7541 |
END_TEST |
| 7542 |
|
| 7543 |
START_TEST(tablet_eraser_button_disabled) |
| 7544 |
{ |
| 7545 |
struct litest_device *dev = litest_current_device(); |
| 7546 |
struct libinput *li = dev->libinput; |
| 7547 |
struct axis_replacement axes[] = { |
| 7548 |
{ ABS_DISTANCE, 10 }, |
| 7549 |
{ ABS_PRESSURE, 0 }, |
| 7550 |
{ -1, -1 }, |
| 7551 |
}; |
| 7552 |
struct axis_replacement tip_down_axes[] = { |
| 7553 |
{ ABS_DISTANCE, 0 }, |
| 7554 |
{ ABS_PRESSURE, 30 }, |
| 7555 |
{ -1, -1 }, |
| 7556 |
}; |
| 7557 |
struct libinput_event *ev; |
| 7558 |
struct libinput_event_tablet_tool *tev; |
| 7559 |
struct libinput_tablet_tool *tool, *pen; |
| 7560 |
bool with_tip_down = |
| 7561 |
litest_test_param_get_bool(test_env->params, "with-tip-down"); |
| 7562 |
bool configure_while_out_of_prox = |
| 7563 |
litest_test_param_get_bool(test_env->params, |
| 7564 |
"configure-while-out-of-prox"); |
| 7565 |
bool down_when_in_prox = |
| 7566 |
litest_test_param_get_bool(test_env->params, "down-when-in-prox"); |
| 7567 |
bool down_when_out_of_prox = |
| 7568 |
litest_test_param_get_bool(test_env->params, "down-when-out-of-prox"); |
| 7569 |
bool with_motion_events = |
| 7570 |
litest_test_param_get_bool(test_env->params, "with-motion-events"); |
| 7571 |
|
| 7572 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) |
| 7573 |
return LITEST_NOT_APPLICABLE; |
| 7574 |
|
| 7575 |
/* Device forces BTN_TOOL_PEN on tip */ |
| 7576 |
if (with_tip_down && dev->which == LITEST_WACOM_ISDV4_524C_PEN) |
| 7577 |
return LITEST_NOT_APPLICABLE; |
| 7578 |
|
| 7579 |
litest_log_group("Prox in/out to disable proximity timer") { |
| 7580 |
litest_tablet_proximity_in(dev, 25, 25, axes); |
| 7581 |
litest_tablet_proximity_out(dev); |
| 7582 |
litest_timeout_tablet_proxout(li); |
| 7583 |
|
| 7584 |
litest_checkpoint( |
| 7585 |
"Eraser prox in/out to force-disable config on broken tablets"); |
| 7586 |
litest_tablet_set_tool_type(dev, BTN_TOOL_RUBBER); |
| 7587 |
litest_tablet_proximity_in(dev, 25, 25, axes); |
| 7588 |
litest_tablet_proximity_out(dev); |
| 7589 |
litest_timeout_tablet_proxout(li); |
| 7590 |
} |
| 7591 |
|
| 7592 |
litest_drain_events(li); |
| 7593 |
|
| 7594 |
litest_log_group("Proximity in for pen") { |
| 7595 |
litest_tablet_set_tool_type(dev, BTN_TOOL_PEN); |
| 7596 |
litest_tablet_proximity_in(dev, 20, 20, axes); |
| 7597 |
litest_dispatch(li); |
| 7598 |
_destroy_(libinput_event) *ev = libinput_get_event(li); |
| 7599 |
tev = litest_is_proximity_event( |
| 7600 |
ev, |
| 7601 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 7602 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 7603 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), |
| 7604 |
LIBINPUT_TABLET_TOOL_TYPE_PEN); |
| 7605 |
pen = libinput_tablet_tool_ref(tool); |
| 7606 |
} |
| 7607 |
|
| 7608 |
if (!libinput_tablet_tool_config_eraser_button_get_modes(tool)) { |
| 7609 |
libinput_tablet_tool_unref(tool); |
| 7610 |
return LITEST_NOT_APPLICABLE; |
| 7611 |
} |
| 7612 |
|
| 7613 |
unsigned int expected_button = BTN_STYLUS3; |
| 7614 |
if (!libinput_tablet_tool_has_button(pen, BTN_STYLUS)) |
| 7615 |
expected_button = BTN_STYLUS; |
| 7616 |
else if (!libinput_tablet_tool_has_button(pen, BTN_STYLUS2)) |
| 7617 |
expected_button = BTN_STYLUS2; |
| 7618 |
else if (!libinput_tablet_tool_has_button(pen, BTN_STYLUS3)) |
| 7619 |
expected_button = BTN_STYLUS3; |
| 7620 |
litest_checkpoint("expected button from now on: %s (%d)", |
| 7621 |
libevdev_event_code_get_name(EV_KEY, expected_button), |
| 7622 |
expected_button); |
| 7623 |
|
| 7624 |
if (!configure_while_out_of_prox) { |
| 7625 |
litest_log_group("Configuring eraser button while in of proximity") { |
| 7626 |
auto status = |
| 7627 |
libinput_tablet_tool_config_eraser_button_set_mode( |
| 7628 |
tool, |
| 7629 |
LIBINPUT_CONFIG_ERASER_BUTTON_BUTTON); |
| 7630 |
if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) |
| 7631 |
return LITEST_NOT_APPLICABLE; |
| 7632 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 7633 |
} |
| 7634 |
} |
| 7635 |
|
| 7636 |
litest_log_group("Prox out to apply changed settings") { |
| 7637 |
litest_tablet_proximity_out(dev); |
| 7638 |
litest_timeout_tablet_proxout(li); |
| 7639 |
litest_drain_events(li); |
| 7640 |
} |
| 7641 |
|
| 7642 |
if (configure_while_out_of_prox) { |
| 7643 |
litest_log_group("Configuring eraser button while out of proximity") { |
| 7644 |
auto status = |
| 7645 |
libinput_tablet_tool_config_eraser_button_set_mode( |
| 7646 |
tool, |
| 7647 |
LIBINPUT_CONFIG_ERASER_BUTTON_BUTTON); |
| 7648 |
if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) |
| 7649 |
return LITEST_NOT_APPLICABLE; |
| 7650 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 7651 |
} |
| 7652 |
} |
| 7653 |
|
| 7654 |
litest_mark_test_start(); |
| 7655 |
|
| 7656 |
if (down_when_in_prox) { |
| 7657 |
litest_log_group("Prox in with eraser, expecting eraser button event") { |
| 7658 |
litest_tablet_set_tool_type(dev, BTN_TOOL_RUBBER); |
| 7659 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 7660 |
litest_wait_for_event(li); |
| 7661 |
ev = libinput_get_event(li); |
| 7662 |
tev = litest_is_proximity_event( |
| 7663 |
ev, |
| 7664 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 7665 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), |
| 7666 |
pen); |
| 7667 |
libinput_event_destroy(ev); |
| 7668 |
litest_drain_events_of_type(li, |
| 7669 |
LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7670 |
ev = libinput_get_event(li); |
| 7671 |
tev = litest_is_tablet_event(ev, |
| 7672 |
LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 7673 |
litest_assert_enum_eq( |
| 7674 |
libinput_event_tablet_tool_get_button_state(tev), |
| 7675 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 7676 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), |
| 7677 |
expected_button); |
| 7678 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), |
| 7679 |
pen); |
| 7680 |
libinput_event_destroy(ev); |
| 7681 |
} |
| 7682 |
} else { |
| 7683 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 7684 |
} |
| 7685 |
|
| 7686 |
litest_drain_events(li); |
| 7687 |
|
| 7688 |
if (with_motion_events) { |
| 7689 |
for (int i = 0; i < 3; i++) { |
| 7690 |
litest_tablet_motion(dev, 11 + i, 11 + i, axes); |
| 7691 |
litest_dispatch(li); |
| 7692 |
} |
| 7693 |
ev = libinput_get_event(li); |
| 7694 |
do { |
| 7695 |
tev = litest_is_tablet_event(ev, |
| 7696 |
LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7697 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), |
| 7698 |
pen); |
| 7699 |
libinput_event_destroy(ev); |
| 7700 |
ev = libinput_get_event(li); |
| 7701 |
} while (ev); |
| 7702 |
} |
| 7703 |
|
| 7704 |
if (with_tip_down) { |
| 7705 |
litest_tablet_tip_down(dev, 11, 11, tip_down_axes); |
| 7706 |
litest_dispatch(li); |
| 7707 |
litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_DOWN); |
| 7708 |
|
| 7709 |
if (with_motion_events) { |
| 7710 |
for (int i = 0; i < 3; i++) { |
| 7711 |
litest_tablet_motion(dev, |
| 7712 |
11 + i, |
| 7713 |
11 + i, |
| 7714 |
tip_down_axes); |
| 7715 |
litest_dispatch(li); |
| 7716 |
} |
| 7717 |
ev = libinput_get_event(li); |
| 7718 |
do { |
| 7719 |
tev = litest_is_tablet_event( |
| 7720 |
ev, |
| 7721 |
LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7722 |
litest_assert_ptr_eq( |
| 7723 |
libinput_event_tablet_tool_get_tool(tev), |
| 7724 |
pen); |
| 7725 |
libinput_event_destroy(ev); |
| 7726 |
ev = libinput_get_event(li); |
| 7727 |
} while (ev); |
| 7728 |
} |
| 7729 |
} |
| 7730 |
|
| 7731 |
/* Make sure the button still works as-is */ |
| 7732 |
if (libinput_tablet_tool_has_button(pen, BTN_STYLUS)) { |
| 7733 |
litest_log_group("Testing BTN_STYLUS") { |
| 7734 |
litest_event(dev, EV_KEY, BTN_STYLUS, 1); |
| 7735 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7736 |
litest_dispatch(li); |
| 7737 |
litest_event(dev, EV_KEY, BTN_STYLUS, 0); |
| 7738 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7739 |
litest_dispatch(li); |
| 7740 |
litest_assert_tablet_button_event( |
| 7741 |
li, |
| 7742 |
BTN_STYLUS, |
| 7743 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 7744 |
litest_assert_tablet_button_event( |
| 7745 |
li, |
| 7746 |
BTN_STYLUS, |
| 7747 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 7748 |
} |
| 7749 |
} |
| 7750 |
|
| 7751 |
litest_dispatch(li); |
| 7752 |
|
| 7753 |
if (!down_when_in_prox) { |
| 7754 |
litest_log_group("Prox out for the pen ...") { |
| 7755 |
litest_with_event_frame(dev) { |
| 7756 |
litest_tablet_set_tool_type(dev, BTN_TOOL_PEN); |
| 7757 |
if (with_tip_down) |
| 7758 |
litest_tablet_tip_up(dev, 11, 11, axes); |
| 7759 |
litest_tablet_proximity_out(dev); |
| 7760 |
} |
| 7761 |
litest_dispatch(li); |
| 7762 |
} |
| 7763 |
|
| 7764 |
litest_log_group("...and prox in for the eraser") { |
| 7765 |
litest_with_event_frame(dev) { |
| 7766 |
litest_tablet_set_tool_type(dev, BTN_TOOL_RUBBER); |
| 7767 |
if (with_tip_down) { |
| 7768 |
litest_tablet_tip_down(dev, |
| 7769 |
12, |
| 7770 |
12, |
| 7771 |
tip_down_axes); |
| 7772 |
litest_tablet_proximity_in(dev, |
| 7773 |
12, |
| 7774 |
12, |
| 7775 |
tip_down_axes); |
| 7776 |
} else { |
| 7777 |
litest_tablet_proximity_in(dev, 12, 12, axes); |
| 7778 |
} |
| 7779 |
} |
| 7780 |
litest_dispatch(li); |
| 7781 |
} |
| 7782 |
|
| 7783 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7784 |
|
| 7785 |
litest_log_group("Expect button event") { |
| 7786 |
ev = libinput_get_event(li); |
| 7787 |
tev = litest_is_tablet_event(ev, |
| 7788 |
LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 7789 |
litest_assert_enum_eq( |
| 7790 |
libinput_event_tablet_tool_get_button_state(tev), |
| 7791 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 7792 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), |
| 7793 |
expected_button); |
| 7794 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), |
| 7795 |
pen); |
| 7796 |
libinput_event_destroy(ev); |
| 7797 |
} |
| 7798 |
} |
| 7799 |
|
| 7800 |
if (!down_when_out_of_prox) { |
| 7801 |
litest_log_group("Prox out for the eraser...") { |
| 7802 |
litest_with_event_frame(dev) { |
| 7803 |
if (with_tip_down) |
| 7804 |
litest_tablet_tip_up(dev, 11, 11, axes); |
| 7805 |
litest_tablet_proximity_out(dev); |
| 7806 |
} |
| 7807 |
litest_dispatch(li); |
| 7808 |
} |
| 7809 |
|
| 7810 |
litest_log_group("...and prox in for the pen") { |
| 7811 |
litest_with_event_frame(dev) { |
| 7812 |
litest_tablet_set_tool_type(dev, BTN_TOOL_PEN); |
| 7813 |
if (with_tip_down) { |
| 7814 |
litest_tablet_tip_down(dev, |
| 7815 |
12, |
| 7816 |
12, |
| 7817 |
tip_down_axes); |
| 7818 |
litest_tablet_proximity_in(dev, |
| 7819 |
12, |
| 7820 |
12, |
| 7821 |
tip_down_axes); |
| 7822 |
} else { |
| 7823 |
litest_tablet_proximity_in(dev, 12, 12, axes); |
| 7824 |
} |
| 7825 |
} |
| 7826 |
litest_dispatch(li); |
| 7827 |
} |
| 7828 |
|
| 7829 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7830 |
|
| 7831 |
litest_log_group("Expect button event") { |
| 7832 |
ev = libinput_get_event(li); |
| 7833 |
tev = litest_is_tablet_event(ev, |
| 7834 |
LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 7835 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), |
| 7836 |
expected_button); |
| 7837 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), |
| 7838 |
pen); |
| 7839 |
libinput_event_destroy(ev); |
| 7840 |
} |
| 7841 |
} |
| 7842 |
|
| 7843 |
litest_log_group("Real prox out for the %s", |
| 7844 |
down_when_out_of_prox ? "eraser" : "pen") { |
| 7845 |
litest_with_event_frame(dev) { |
| 7846 |
if (with_tip_down) |
| 7847 |
litest_tablet_tip_up(dev, 12, 12, axes); |
| 7848 |
litest_tablet_proximity_out(dev); |
| 7849 |
} |
| 7850 |
litest_dispatch(li); |
| 7851 |
litest_timeout_tablet_proxout(li); |
| 7852 |
} |
| 7853 |
|
| 7854 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7855 |
|
| 7856 |
if (down_when_out_of_prox) { |
| 7857 |
litest_log_group("Expect button release") { |
| 7858 |
ev = libinput_get_event(li); |
| 7859 |
tev = litest_is_tablet_event(ev, |
| 7860 |
LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 7861 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), |
| 7862 |
expected_button); |
| 7863 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), |
| 7864 |
pen); |
| 7865 |
libinput_event_destroy(ev); |
| 7866 |
} |
| 7867 |
} |
| 7868 |
|
| 7869 |
if (with_tip_down) |
| 7870 |
litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_UP); |
| 7871 |
|
| 7872 |
litest_log_group("Expect final prox out for the pen") { |
| 7873 |
ev = libinput_get_event(li); |
| 7874 |
tev = litest_is_proximity_event( |
| 7875 |
ev, |
| 7876 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); |
| 7877 |
tool = libinput_event_tablet_tool_get_tool(tev); |
| 7878 |
litest_assert_ptr_eq(pen, tool); |
| 7879 |
libinput_event_destroy(ev); |
| 7880 |
} |
| 7881 |
|
| 7882 |
libinput_tablet_tool_unref(pen); |
| 7883 |
} |
| 7884 |
END_TEST |
| 7885 |
|
| 7886 |
START_TEST(tablet_eraser_button_different_buttons) |
| 7887 |
{ |
| 7888 |
struct litest_device *dev = litest_current_device(); |
| 7889 |
struct libinput *li = dev->libinput; |
| 7890 |
struct axis_replacement axes[] = { |
| 7891 |
{ ABS_DISTANCE, 10 }, |
| 7892 |
{ ABS_PRESSURE, 0 }, |
| 7893 |
{ -1, -1 }, |
| 7894 |
}; |
| 7895 |
_unref_(libinput_tablet_tool) *pen = NULL; |
| 7896 |
|
| 7897 |
uint32_t eraser_button_mapping = |
| 7898 |
litest_test_param_get_i32(test_env->params, "eraser-button-mapping"); |
| 7899 |
|
| 7900 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) |
| 7901 |
return LITEST_NOT_APPLICABLE; |
| 7902 |
|
| 7903 |
litest_log_group("Prox in/out to disable proximity timer") { |
| 7904 |
litest_tablet_proximity_in(dev, 25, 25, axes); |
| 7905 |
litest_tablet_proximity_out(dev); |
| 7906 |
litest_timeout_tablet_proxout(li); |
| 7907 |
|
| 7908 |
litest_checkpoint( |
| 7909 |
"Eraser prox in/out to force-disable config on broken tablets"); |
| 7910 |
litest_tablet_set_tool_type(dev, BTN_TOOL_RUBBER); |
| 7911 |
litest_tablet_proximity_in(dev, 25, 25, axes); |
| 7912 |
litest_tablet_proximity_out(dev); |
| 7913 |
litest_timeout_tablet_proxout(li); |
| 7914 |
} |
| 7915 |
|
| 7916 |
litest_drain_events(li); |
| 7917 |
|
| 7918 |
litest_log_group("Proximity in for pen") { |
| 7919 |
litest_tablet_set_tool_type(dev, BTN_TOOL_PEN); |
| 7920 |
litest_tablet_proximity_in(dev, 20, 20, axes); |
| 7921 |
litest_dispatch(li); |
| 7922 |
_destroy_(libinput_event) *ev = libinput_get_event(li); |
| 7923 |
auto tev = litest_is_proximity_event( |
| 7924 |
ev, |
| 7925 |
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 7926 |
pen = libinput_event_tablet_tool_get_tool(tev); |
| 7927 |
litest_assert_enum_eq(libinput_tablet_tool_get_type(pen), |
| 7928 |
LIBINPUT_TABLET_TOOL_TYPE_PEN); |
| 7929 |
pen = libinput_tablet_tool_ref(pen); |
| 7930 |
} |
| 7931 |
|
| 7932 |
if (!libinput_tablet_tool_config_eraser_button_get_modes(pen)) |
| 7933 |
return LITEST_NOT_APPLICABLE; |
| 7934 |
|
| 7935 |
auto status = libinput_tablet_tool_config_eraser_button_set_mode( |
| 7936 |
pen, |
| 7937 |
LIBINPUT_CONFIG_ERASER_BUTTON_BUTTON); |
| 7938 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 7939 |
status = libinput_tablet_tool_config_eraser_button_set_button( |
| 7940 |
pen, |
| 7941 |
eraser_button_mapping); |
| 7942 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 7943 |
|
| 7944 |
litest_log_group("Prox out to apply changed settings") { |
| 7945 |
litest_tablet_proximity_out(dev); |
| 7946 |
litest_timeout_tablet_proxout(li); |
| 7947 |
litest_drain_events(li); |
| 7948 |
} |
| 7949 |
|
| 7950 |
litest_mark_test_start(); |
| 7951 |
|
| 7952 |
litest_tablet_proximity_in(dev, 10, 10, axes); |
| 7953 |
litest_drain_events(li); |
| 7954 |
|
| 7955 |
/* Make sure the button still works as-is */ |
| 7956 |
if (libinput_tablet_tool_has_button(pen, eraser_button_mapping)) { |
| 7957 |
litest_log_group("Testing button on pen") { |
| 7958 |
litest_event(dev, EV_KEY, eraser_button_mapping, 1); |
| 7959 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7960 |
litest_dispatch(li); |
| 7961 |
litest_event(dev, EV_KEY, eraser_button_mapping, 0); |
| 7962 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 7963 |
litest_dispatch(li); |
| 7964 |
litest_assert_tablet_button_event( |
| 7965 |
li, |
| 7966 |
eraser_button_mapping, |
| 7967 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 7968 |
litest_assert_tablet_button_event( |
| 7969 |
li, |
| 7970 |
eraser_button_mapping, |
| 7971 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 7972 |
} |
| 7973 |
} |
| 7974 |
|
| 7975 |
litest_dispatch(li); |
| 7976 |
|
| 7977 |
litest_log_group("Prox out for the pen ...") { |
| 7978 |
litest_with_event_frame(dev) { |
| 7979 |
litest_tablet_set_tool_type(dev, BTN_TOOL_PEN); |
| 7980 |
litest_tablet_proximity_out(dev); |
| 7981 |
} |
| 7982 |
litest_dispatch(li); |
| 7983 |
} |
| 7984 |
|
| 7985 |
litest_log_group("...and prox in for the eraser") { |
| 7986 |
litest_with_event_frame(dev) { |
| 7987 |
litest_tablet_set_tool_type(dev, BTN_TOOL_RUBBER); |
| 7988 |
litest_tablet_proximity_in(dev, 12, 12, axes); |
| 7989 |
} |
| 7990 |
litest_dispatch(li); |
| 7991 |
} |
| 7992 |
|
| 7993 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 7994 |
|
| 7995 |
litest_log_group("Expect button event") { |
| 7996 |
_destroy_(libinput_event) *ev = libinput_get_event(li); |
| 7997 |
auto tev = |
| 7998 |
litest_is_tablet_event(ev, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 7999 |
litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), |
| 8000 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 8001 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), |
| 8002 |
eraser_button_mapping); |
| 8003 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), pen); |
| 8004 |
} |
| 8005 |
|
| 8006 |
litest_log_group("Prox out for the eraser...") { |
| 8007 |
litest_with_event_frame(dev) { |
| 8008 |
litest_tablet_proximity_out(dev); |
| 8009 |
} |
| 8010 |
litest_dispatch(li); |
| 8011 |
} |
| 8012 |
|
| 8013 |
litest_log_group("...and prox in for the pen") { |
| 8014 |
litest_with_event_frame(dev) { |
| 8015 |
litest_tablet_set_tool_type(dev, BTN_TOOL_PEN); |
| 8016 |
litest_tablet_proximity_in(dev, 12, 12, axes); |
| 8017 |
} |
| 8018 |
litest_dispatch(li); |
| 8019 |
} |
| 8020 |
|
| 8021 |
litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); |
| 8022 |
|
| 8023 |
litest_log_group("Expect button event") { |
| 8024 |
_destroy_(libinput_event) *ev = libinput_get_event(li); |
| 8025 |
auto tev = |
| 8026 |
litest_is_tablet_event(ev, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); |
| 8027 |
litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), |
| 8028 |
eraser_button_mapping); |
| 8029 |
litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), pen); |
| 8030 |
} |
| 8031 |
} |
| 8032 |
END_TEST |
| 8033 |
|
| 8034 |
START_TEST(tablet_eraser_button_invalid_buttons) |
| 8035 |
{ |
| 8036 |
struct litest_device *dev = litest_current_device(); |
| 8037 |
struct libinput *li = dev->libinput; |
| 8038 |
struct axis_replacement axes[] = { |
| 8039 |
{ ABS_DISTANCE, 10 }, |
| 8040 |
{ ABS_PRESSURE, 0 }, |
| 8041 |
{ -1, -1 }, |
| 8042 |
}; |
| 8043 |
|
| 8044 |
uint32_t eraser_button_mapping = |
| 8045 |
litest_test_param_get_i32(test_env->params, "eraser-button-mapping"); |
| 8046 |
|
| 8047 |
if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) |
| 8048 |
return LITEST_NOT_APPLICABLE; |
| 8049 |
|
| 8050 |
litest_drain_events(li); |
| 8051 |
litest_tablet_proximity_in(dev, 20, 20, axes); |
| 8052 |
litest_dispatch(li); |
| 8053 |
|
| 8054 |
_destroy_(libinput_event) *ev = libinput_get_event(li); |
| 8055 |
auto tev = |
| 8056 |
litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); |
| 8057 |
auto tool = libinput_event_tablet_tool_get_tool(tev); |
| 8058 |
|
| 8059 |
if (!libinput_tablet_tool_config_eraser_button_get_modes(tool)) |
| 8060 |
return LITEST_NOT_APPLICABLE; |
| 8061 |
|
| 8062 |
auto status = libinput_tablet_tool_config_eraser_button_set_button( |
| 8063 |
tool, |
| 8064 |
eraser_button_mapping); |
| 8065 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); |
| 8066 |
} |
| 8067 |
END_TEST |
| 8068 |
|
| 8069 |
START_TEST(tablet_eraser_button_config_after_device_removal) |
| 8070 |
{ |
| 8071 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 8072 |
struct litest_device *tablet = litest_add_device(li, LITEST_ELAN_TABLET); |
| 8073 |
struct axis_replacement axes[] = { |
| 8074 |
{ ABS_DISTANCE, 10 }, |
| 8075 |
{ ABS_PRESSURE, 0 }, |
| 8076 |
{ -1, -1 }, |
| 8077 |
}; |
| 8078 |
|
| 8079 |
litest_drain_events(li); |
| 8080 |
|
| 8081 |
litest_tablet_set_tool_type(tablet, BTN_TOOL_RUBBER); |
| 8082 |
litest_tablet_proximity_in(tablet, 10, 10, axes); |
| 8083 |
|
| 8084 |
litest_dispatch(li); |
| 8085 |
auto event = libinput_get_event(li); |
| 8086 |
auto tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); |
| 8087 |
auto tool = libinput_event_tablet_tool_get_tool(tev); |
| 8088 |
libinput_tablet_tool_ref(tool); |
| 8089 |
libinput_event_destroy(event); |
| 8090 |
|
| 8091 |
litest_device_destroy(tablet); |
| 8092 |
litest_drain_events(li); |
| 8093 |
|
| 8094 |
/* Tool isn't associated with a device but config should take effect anyway */ |
| 8095 |
auto status = libinput_tablet_tool_config_eraser_button_set_mode( |
| 8096 |
tool, |
| 8097 |
LIBINPUT_CONFIG_ERASER_BUTTON_BUTTON); |
| 8098 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 8099 |
status = |
| 8100 |
libinput_tablet_tool_config_eraser_button_set_button(tool, BTN_STYLUS2); |
| 8101 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 8102 |
|
| 8103 |
litest_assert_enum_eq(libinput_tablet_tool_config_eraser_button_get_mode(tool), |
| 8104 |
LIBINPUT_CONFIG_ERASER_BUTTON_BUTTON); |
| 8105 |
litest_assert_int_eq(libinput_tablet_tool_config_eraser_button_get_button(tool), |
| 8106 |
(unsigned)BTN_STYLUS2); |
| 8107 |
|
| 8108 |
litest_drain_events(li); |
| 8109 |
|
| 8110 |
libinput_tablet_tool_unref(tool); |
| 8111 |
} |
| 8112 |
END_TEST |
| 8113 |
|
| 8114 |
TEST_COLLECTION(tablet) |
| 8115 |
{ |
| 8116 |
/* clang-format off */ |
| 8117 |
litest_add(tool_ref, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); |
| 8118 |
litest_add(tool_user_data, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); |
| 8119 |
litest_add(tool_capability, LITEST_TABLET, LITEST_ANY); |
| 8120 |
litest_add_no_device(tool_capabilities); |
| 8121 |
litest_add(tool_type, LITEST_TABLET, LITEST_FORCED_PROXOUT); |
| 8122 |
litest_add(tool_in_prox_before_start, LITEST_TABLET, LITEST_TOTEM); |
| 8123 |
litest_add(tool_direct_switch_skip_tool_update, LITEST_TABLET, LITEST_ANY); |
| 8124 |
litest_add(tool_direct_switch_with_forced_proxout, LITEST_TABLET, LITEST_ANY); |
| 8125 |
|
| 8126 |
/* Tablets hold back the proximity until the first event from the |
| 8127 |
* kernel, the totem sends it immediately */ |
| 8128 |
litest_add(tool_in_prox_before_start, LITEST_TABLET, LITEST_TOTEM); |
| 8129 |
litest_add(tool_unique, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); |
| 8130 |
litest_add(tool_serial, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); |
| 8131 |
litest_add(tool_id, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); |
| 8132 |
litest_with_parameters(params, "tool_id", 'I', 3, |
| 8133 |
litest_named_i32(0x823, "GripPen"), |
| 8134 |
litest_named_i32(0x4802, "ClassicPen"), |
| 8135 |
litest_named_i32(0x100902, "AirbrushPen")) { |
| 8136 |
litest_add_parametrized_for_device(tool_name, LITEST_WACOM_CINTIQ_PRO16_PEN, params); |
| 8137 |
} |
| 8138 |
litest_add_for_device(tool_no_name, LITEST_HUION_TABLET); |
| 8139 |
litest_add(serial_changes_tool, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); |
| 8140 |
litest_add(invalid_serials, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); |
| 8141 |
litest_add_no_device(tools_with_serials); |
| 8142 |
litest_add_no_device(tools_without_serials); |
| 8143 |
litest_add_for_device(tool_delayed_serial, LITEST_WACOM_HID4800_PEN); |
| 8144 |
litest_add_no_device(proximity_out_on_delete); |
| 8145 |
litest_add(button_down_up, LITEST_TABLET, LITEST_ANY); |
| 8146 |
litest_add(button_seat_count, LITEST_TABLET, LITEST_ANY); |
| 8147 |
litest_add_no_device(button_up_on_delete); |
| 8148 |
litest_add(motion, LITEST_TABLET, LITEST_ANY); |
| 8149 |
litest_add(motion_event_state, LITEST_TABLET, LITEST_ANY); |
| 8150 |
litest_add_for_device(motion_outside_bounds, LITEST_WACOM_CINTIQ_24HD_PEN); |
| 8151 |
litest_add(tilt_available, LITEST_TABLET|LITEST_TILT, LITEST_ANY); |
| 8152 |
litest_add(tilt_not_available, LITEST_TABLET, LITEST_TILT); |
| 8153 |
litest_add(tilt_x, LITEST_TABLET|LITEST_TILT, LITEST_ANY); |
| 8154 |
litest_add(tilt_y, LITEST_TABLET|LITEST_TILT, LITEST_ANY); |
| 8155 |
litest_with_parameters(params, "tilt", 'I', 3, litest_named_i32(TILT_MINIMUM, "minimum"), |
| 8156 |
litest_named_i32(TILT_CENTER, "center"), |
| 8157 |
litest_named_i32(TILT_MAXIMUM, "maximum")) { |
| 8158 |
litest_add_parametrized(tilt_fixed_points, LITEST_TABLET|LITEST_TILT, LITEST_ANY, params); |
| 8159 |
} |
| 8160 |
litest_add(pad_buttons_ignored, LITEST_TABLET, LITEST_TOTEM); |
| 8161 |
litest_add_for_device(stylus_buttons, LITEST_WACOM_CINTIQ_PRO16_PEN); |
| 8162 |
litest_add(mouse_tool, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); |
| 8163 |
litest_add(mouse_buttons, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); |
| 8164 |
litest_add(mouse_rotation, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); |
| 8165 |
litest_add(mouse_wheel, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_WHEEL); |
| 8166 |
|
| 8167 |
litest_add(airbrush_tool, LITEST_TABLET, LITEST_ANY); |
| 8168 |
litest_add(airbrush_slider, LITEST_TABLET, LITEST_ANY); |
| 8169 |
litest_add(artpen_tool, LITEST_TABLET, LITEST_ANY); |
| 8170 |
litest_add(artpen_rotation, LITEST_TABLET, LITEST_ANY); |
| 8171 |
|
| 8172 |
litest_add(tablet_time_usec, LITEST_TABLET, LITEST_ANY); |
| 8173 |
litest_add(tablet_pressure_distance_exclusive, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); |
| 8174 |
|
| 8175 |
/* The totem doesn't need calibration */ |
| 8176 |
litest_add(tablet_calibration_has_matrix, LITEST_TABLET, LITEST_TOTEM|LITEST_PRECALIBRATED); |
| 8177 |
litest_add(tablet_calibration_set_matrix, LITEST_TABLET, LITEST_TOTEM|LITEST_PRECALIBRATED); |
| 8178 |
litest_add(tablet_calibration_set_matrix_delta, LITEST_TABLET, LITEST_TOTEM|LITEST_PRECALIBRATED); |
| 8179 |
|
| 8180 |
litest_add(tablet_area_has_rectangle, LITEST_TABLET, LITEST_ANY); |
| 8181 |
litest_add(tablet_area_set_rectangle_invalid, LITEST_TABLET, LITEST_ANY); |
| 8182 |
litest_with_parameters(params, |
| 8183 |
"axis", 's', 2, "vertical", "horizontal", |
| 8184 |
"direction", 's', 2, "down", "up") { |
| 8185 |
litest_add_parametrized(tablet_area_set_rectangle, LITEST_TABLET, LITEST_ANY, params); |
| 8186 |
} |
| 8187 |
litest_add(tablet_area_set_rectangle_move_outside, LITEST_TABLET, LITEST_ANY); |
| 8188 |
litest_add(tablet_area_set_rectangle_move_outside_to_inside, LITEST_TABLET, LITEST_ANY); |
| 8189 |
litest_add(tablet_area_set_rectangle_move_in_margin, LITEST_TABLET, LITEST_ANY); |
| 8190 |
litest_add(tablet_area_set_rectangle_while_outside, LITEST_TABLET, LITEST_ANY); |
| 8191 |
|
| 8192 |
litest_add(tablet_pressure_min_max, LITEST_TABLET, LITEST_ANY); |
| 8193 |
/* Tests for pressure offset with distance */ |
| 8194 |
litest_add_for_device(tablet_pressure_range, LITEST_WACOM_INTUOS5_PEN); |
| 8195 |
litest_add_for_device(tablet_pressure_offset_set, LITEST_WACOM_INTUOS5_PEN); |
| 8196 |
litest_add_for_device(tablet_pressure_offset_decrease, LITEST_WACOM_INTUOS5_PEN); |
| 8197 |
litest_add_for_device(tablet_pressure_offset_increase, LITEST_WACOM_INTUOS5_PEN); |
| 8198 |
litest_add_for_device(tablet_pressure_offset_exceed_threshold, LITEST_WACOM_INTUOS5_PEN); |
| 8199 |
litest_add_for_device(tablet_pressure_offset_none_for_zero_distance, LITEST_WACOM_INTUOS5_PEN); |
| 8200 |
litest_add_for_device(tablet_pressure_offset_none_for_small_distance, LITEST_WACOM_INTUOS5_PEN); |
| 8201 |
/* Tests for pressure offset without distance */ |
| 8202 |
litest_add_for_device(tablet_pressure_range, LITEST_WACOM_HID4800_PEN); |
| 8203 |
litest_add_for_device(tablet_pressure_offset_set, LITEST_WACOM_HID4800_PEN); |
| 8204 |
litest_add_for_device(tablet_pressure_offset_decrease, LITEST_WACOM_HID4800_PEN); |
| 8205 |
litest_add_for_device(tablet_pressure_offset_increase, LITEST_WACOM_HID4800_PEN); |
| 8206 |
litest_add_for_device(tablet_pressure_offset_exceed_threshold, LITEST_WACOM_HID4800_PEN); |
| 8207 |
litest_with_parameters(params, "8k-to-1k", 'b', "with-range", 'b', "with-second-range", 'b') |
| 8208 |
litest_add_parametrized_for_device(tablet_pressure_across_multiple_tablets, LITEST_WACOM_CINTIQ_12WX_PEN, params); |
| 8209 |
litest_add_no_device(tablet_pressure_after_unplug); |
| 8210 |
|
| 8211 |
litest_add(tablet_pressure_config, LITEST_TABLET, LITEST_TOTEM); |
| 8212 |
litest_add(tablet_pressure_config_set_minimum, LITEST_TABLET, LITEST_TOTEM); |
| 8213 |
litest_add(tablet_pressure_config_set_maximum, LITEST_TABLET, LITEST_TOTEM); |
| 8214 |
litest_add(tablet_pressure_config_set_range, LITEST_TABLET, LITEST_TOTEM); |
| 8215 |
litest_add(tablet_pressure_config_resets_offset, LITEST_TABLET, LITEST_TOTEM); |
| 8216 |
litest_add_for_device(tablet_pressure_config_01_does_not_reset_offset, LITEST_WACOM_HID4800_PEN); |
| 8217 |
|
| 8218 |
litest_add_for_device(tablet_distance_range, LITEST_WACOM_INTUOS5_PEN); |
| 8219 |
|
| 8220 |
litest_add(relative_no_profile, LITEST_TABLET, LITEST_ANY); |
| 8221 |
litest_add(relative_no_delta_prox_in, LITEST_TABLET, LITEST_ANY); |
| 8222 |
litest_add(relative_delta, LITEST_TABLET, LITEST_ANY); |
| 8223 |
litest_add(relative_no_delta_on_tip, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8224 |
litest_add(relative_calibration, LITEST_TABLET, LITEST_PRECALIBRATED); |
| 8225 |
|
| 8226 |
litest_add(touch_arbitration, LITEST_TABLET, LITEST_ANY); |
| 8227 |
litest_add(touch_arbitration_stop_touch, LITEST_TABLET, LITEST_ANY); |
| 8228 |
litest_add(touch_arbitration_suspend_touch_device, LITEST_TOUCH, LITEST_ANY); |
| 8229 |
litest_add(touch_arbitration_remove_touch, LITEST_TABLET, LITEST_ANY); |
| 8230 |
litest_add(touch_arbitration_remove_tablet, LITEST_TOUCH, LITEST_ANY); |
| 8231 |
litest_add(touch_arbitration_keep_ignoring, LITEST_TABLET, LITEST_ANY); |
| 8232 |
litest_add(touch_arbitration_late_touch_lift, LITEST_TABLET, LITEST_ANY); |
| 8233 |
litest_add(touch_arbitration_outside_rect, LITEST_TABLET | LITEST_DIRECT, LITEST_ANY); |
| 8234 |
litest_add(touch_arbitration_remove_after, LITEST_TABLET | LITEST_DIRECT, LITEST_ANY); |
| 8235 |
litest_add(touch_arbitration_swap_device, LITEST_TABLET, LITEST_ANY); |
| 8236 |
|
| 8237 |
litest_with_parameters(params, "send-btn-tool", 'b') { |
| 8238 |
litest_add_parametrized_for_device(huion_static_btn_tool_pen, LITEST_HUION_TABLET, params); |
| 8239 |
litest_add_parametrized_for_device(huion_static_btn_tool_pen_no_timeout_during_usage, LITEST_HUION_TABLET, params); |
| 8240 |
} |
| 8241 |
|
| 8242 |
litest_with_parameters(params, "btn_tool_pen_timeout", 'b') { |
| 8243 |
litest_add_parametrized_for_device(huion_static_btn_tool_pen_disable_quirk_on_prox_out, LITEST_HUION_TABLET, params); |
| 8244 |
} |
| 8245 |
|
| 8246 |
litest_add_for_device(tablet_smoothing, LITEST_WACOM_HID4800_PEN); |
| 8247 |
/* clang-format on */ |
| 8248 |
} |
| 8249 |
|
| 8250 |
TEST_COLLECTION(tablet_left_handed) |
| 8251 |
{ |
| 8252 |
/* clang-format off */ |
| 8253 |
litest_add_for_device(left_handed, LITEST_WACOM_INTUOS5_PEN); |
| 8254 |
litest_add_for_device(left_handed_tilt, LITEST_WACOM_INTUOS5_PEN); |
| 8255 |
litest_add_for_device(left_handed_mouse_rotation, LITEST_WACOM_INTUOS5_PEN); |
| 8256 |
litest_add_for_device(left_handed_artpen_rotation, LITEST_WACOM_INTUOS5_PEN); |
| 8257 |
litest_add_for_device(no_left_handed, LITEST_WACOM_CINTIQ_12WX_PEN); |
| 8258 |
|
| 8259 |
litest_with_parameters(params, |
| 8260 |
"tablet_from", 'b', |
| 8261 |
"touch_from", 'b', |
| 8262 |
"tablet_to", 'b', |
| 8263 |
"touch_to", 'b') { |
| 8264 |
litest_add_parametrized(tablet_rotation_left_handed, LITEST_TABLET, LITEST_ANY, params); |
| 8265 |
litest_add_parametrized(tablet_rotation_left_handed_configuration, LITEST_TABLET, LITEST_ANY, params); |
| 8266 |
litest_add_parametrized(tablet_rotation_left_handed_while_in_prox, LITEST_TABLET, LITEST_ANY, params); |
| 8267 |
litest_add_parametrized(tablet_rotation_left_handed_while_touch_down, LITEST_TABLET, LITEST_ANY, params); |
| 8268 |
litest_add_parametrized(tablet_rotation_left_handed_add_touchpad, LITEST_TABLET, LITEST_ANY, params); |
| 8269 |
litest_add_parametrized(tablet_rotation_left_handed_add_tablet, LITEST_TOUCHPAD, LITEST_ANY, params); |
| 8270 |
} |
| 8271 |
/* clang-format on */ |
| 8272 |
} |
| 8273 |
|
| 8274 |
TEST_COLLECTION(tablet_eraser) |
| 8275 |
{ |
| 8276 |
/* clang-format off */ |
| 8277 |
litest_with_parameters(params, |
| 8278 |
"with-tip-down", 'b', |
| 8279 |
"configure-while-out-of-prox", 'b', |
| 8280 |
"down-when-in-prox", 'b', |
| 8281 |
"down-when-out-of-prox", 'b', |
| 8282 |
"with-motion-events", 'b') { |
| 8283 |
litest_add_parametrized(tablet_eraser_button_disabled, LITEST_TABLET, LITEST_TOTEM|LITEST_FORCED_PROXOUT, params); |
| 8284 |
} |
| 8285 |
litest_with_parameters(params, |
| 8286 |
"eraser-button-mapping", 'I', 4, |
| 8287 |
litest_named_i32(BTN_STYLUS), |
| 8288 |
litest_named_i32(BTN_STYLUS3), |
| 8289 |
litest_named_i32(BTN_LEFT), |
| 8290 |
litest_named_i32(BTN_BACK)){ |
| 8291 |
litest_add_parametrized(tablet_eraser_button_different_buttons, LITEST_TABLET, LITEST_TOTEM|LITEST_FORCED_PROXOUT, params); |
| 8292 |
} |
| 8293 |
litest_with_parameters(params, |
| 8294 |
"eraser-button-mapping", 'I', 3, |
| 8295 |
litest_named_i32(BTN_TOUCH), |
| 8296 |
litest_named_i32(BTN_TOOL_FINGER), |
| 8297 |
litest_named_i32(KEY_A)) { |
| 8298 |
litest_add_parametrized(tablet_eraser_button_invalid_buttons, LITEST_TABLET, LITEST_TOTEM|LITEST_FORCED_PROXOUT, params); |
| 8299 |
} |
| 8300 |
litest_add_no_device(tablet_eraser_button_config_after_device_removal); |
| 8301 |
/* clang-format on */ |
| 8302 |
} |
| 8303 |
|
| 8304 |
TEST_COLLECTION(tablet_proximity) |
| 8305 |
{ |
| 8306 |
/* clang-format off */ |
| 8307 |
litest_add(proximity_out_clear_buttons, LITEST_TABLET, LITEST_FORCED_PROXOUT); |
| 8308 |
litest_add(proximity_in_out, LITEST_TABLET, LITEST_ANY); |
| 8309 |
litest_add(proximity_in_button_down, LITEST_TABLET, LITEST_ANY); |
| 8310 |
litest_add(proximity_out_button_up, LITEST_TABLET, LITEST_ANY); |
| 8311 |
litest_add(proximity_has_axes, LITEST_TABLET, LITEST_ANY); |
| 8312 |
litest_add(bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); |
| 8313 |
litest_add(proximity_range_enter, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); |
| 8314 |
litest_add(proximity_range_in_out, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); |
| 8315 |
litest_add(proximity_range_button_click, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); |
| 8316 |
litest_add(proximity_range_button_press, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); |
| 8317 |
litest_add(proximity_range_button_release, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); |
| 8318 |
litest_add(proximity_out_slow_event, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); |
| 8319 |
litest_add(proximity_out_not_during_contact, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); |
| 8320 |
litest_add(proximity_out_not_during_buttonpress, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); |
| 8321 |
litest_add(proximity_out_disables_forced, LITEST_TABLET, LITEST_FORCED_PROXOUT|LITEST_TOTEM); |
| 8322 |
litest_add(proximity_out_disables_forced_after_forced, LITEST_TABLET, LITEST_FORCED_PROXOUT|LITEST_TOTEM); |
| 8323 |
litest_add(proximity_forced_in_with_eraser_swap, LITEST_TABLET, LITEST_FORCED_PROXOUT|LITEST_TOTEM); |
| 8324 |
/* clang-format on */ |
| 8325 |
} |
| 8326 |
|
| 8327 |
TEST_COLLECTION(tablet_tip) |
| 8328 |
{ |
| 8329 |
/* clang-format off */ |
| 8330 |
litest_add(tip_down_up, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8331 |
litest_add(tip_down_prox_in, LITEST_TABLET, LITEST_ANY); |
| 8332 |
litest_add(tip_up_prox_out, LITEST_TABLET, LITEST_ANY); |
| 8333 |
litest_add(tip_down_btn_change, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8334 |
litest_add(tip_up_btn_change, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8335 |
litest_add(tip_down_motion, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8336 |
litest_add(tip_up_motion, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8337 |
litest_add(tip_down_up_eraser, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8338 |
litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(ABS_X), litest_named_i32(ABS_Y)) { |
| 8339 |
litest_add_parametrized(tip_up_motion_one_axis, LITEST_TABLET|LITEST_HOVER, LITEST_ANY, params); |
| 8340 |
} |
| 8341 |
litest_add(tip_state_proximity, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8342 |
litest_add(tip_state_axis, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8343 |
litest_add(tip_state_button, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); |
| 8344 |
litest_add_no_device(tip_up_on_delete); |
| 8345 |
/* clang-format on */ |
| 8346 |
} |