| 1 |
/* |
| 2 |
* Copyright © 2013 Red Hat, Inc. |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice (including the next |
| 12 |
* paragraph) shall be included in all copies or substantial portions of the |
| 13 |
* Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 |
* DEALINGS IN THE SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include <config.h> |
| 25 |
|
| 26 |
#include <errno.h> |
| 27 |
#include <fcntl.h> |
| 28 |
#include <libevdev/libevdev.h> |
| 29 |
#include <libinput.h> |
| 30 |
#include <unistd.h> |
| 31 |
|
| 32 |
#include "libinput-util.h" |
| 33 |
#include "litest.h" |
| 34 |
|
| 35 |
START_TEST(touch_frame_events) |
| 36 |
{ |
| 37 |
struct litest_device *dev = litest_current_device(); |
| 38 |
struct libinput *li = dev->libinput; |
| 39 |
struct libinput_event *event; |
| 40 |
int have_frame_event = 0; |
| 41 |
|
| 42 |
litest_drain_events(dev->libinput); |
| 43 |
|
| 44 |
litest_touch_down(dev, 0, 10, 10); |
| 45 |
litest_dispatch(li); |
| 46 |
|
| 47 |
while ((event = libinput_get_event(li))) { |
| 48 |
if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME) |
| 49 |
have_frame_event++; |
| 50 |
libinput_event_destroy(event); |
| 51 |
} |
| 52 |
litest_assert_int_eq(have_frame_event, 1); |
| 53 |
|
| 54 |
litest_touch_down(dev, 1, 10, 10); |
| 55 |
litest_dispatch(li); |
| 56 |
|
| 57 |
while ((event = libinput_get_event(li))) { |
| 58 |
if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME) |
| 59 |
have_frame_event++; |
| 60 |
libinput_event_destroy(event); |
| 61 |
} |
| 62 |
litest_assert_int_eq(have_frame_event, 2); |
| 63 |
} |
| 64 |
END_TEST |
| 65 |
|
| 66 |
START_TEST(touch_downup_no_motion) |
| 67 |
{ |
| 68 |
struct litest_device *dev = litest_current_device(); |
| 69 |
struct libinput *li = dev->libinput; |
| 70 |
|
| 71 |
litest_drain_events(li); |
| 72 |
|
| 73 |
litest_touch_down(dev, 0, 10, 10); |
| 74 |
litest_dispatch(li); |
| 75 |
|
| 76 |
litest_assert_touch_down_frame(li); |
| 77 |
|
| 78 |
litest_touch_up(dev, 0); |
| 79 |
litest_dispatch(li); |
| 80 |
|
| 81 |
litest_assert_touch_up_frame(li); |
| 82 |
} |
| 83 |
END_TEST |
| 84 |
|
| 85 |
START_TEST(touch_abs_transform) |
| 86 |
{ |
| 87 |
struct litest_device *dev; |
| 88 |
struct libinput *libinput; |
| 89 |
struct libinput_event *ev; |
| 90 |
struct libinput_event_touch *tev; |
| 91 |
double fx, fy; |
| 92 |
bool tested = false; |
| 93 |
|
| 94 |
struct input_absinfo abs[] = { |
| 95 |
{ ABS_X, 0, 32767, 75, 0, 10 }, |
| 96 |
{ ABS_Y, 0, 32767, 129, 0, 9 }, |
| 97 |
{ ABS_MT_POSITION_X, 0, 32767, 0, 0, 10 }, |
| 98 |
{ ABS_MT_POSITION_Y, 0, 32767, 0, 0, 9 }, |
| 99 |
{ .value = -1 }, |
| 100 |
}; |
| 101 |
|
| 102 |
dev = litest_create_device_with_overrides(LITEST_WACOM_ISDV4_E6_FINGER, |
| 103 |
"litest Highres touch device", |
| 104 |
NULL, |
| 105 |
abs, |
| 106 |
NULL); |
| 107 |
|
| 108 |
libinput = dev->libinput; |
| 109 |
|
| 110 |
litest_touch_down(dev, 0, 100, 100); |
| 111 |
|
| 112 |
litest_dispatch(libinput); |
| 113 |
|
| 114 |
while ((ev = libinput_get_event(libinput))) { |
| 115 |
if (libinput_event_get_type(ev) != LIBINPUT_EVENT_TOUCH_DOWN) { |
| 116 |
libinput_event_destroy(ev); |
| 117 |
continue; |
| 118 |
} |
| 119 |
|
| 120 |
tev = libinput_event_get_touch_event(ev); |
| 121 |
fx = libinput_event_touch_get_x_transformed(tev, 1920); |
| 122 |
litest_assert_double_eq_epsilon(fx, 1920.0, 0.1); |
| 123 |
litest_assert_double_lt(fx, 1920.0); |
| 124 |
fy = libinput_event_touch_get_y_transformed(tev, 720); |
| 125 |
litest_assert_double_eq_epsilon(fy, 720.0, 0.1); |
| 126 |
litest_assert_double_lt(fy, 720.0); |
| 127 |
|
| 128 |
tested = true; |
| 129 |
|
| 130 |
libinput_event_destroy(ev); |
| 131 |
} |
| 132 |
|
| 133 |
litest_assert(tested); |
| 134 |
|
| 135 |
litest_device_destroy(dev); |
| 136 |
} |
| 137 |
END_TEST |
| 138 |
|
| 139 |
static inline void |
| 140 |
touch_assert_seat_slot(struct libinput *li, |
| 141 |
enum libinput_event_type type, |
| 142 |
unsigned int slot, |
| 143 |
unsigned int seat_slot) |
| 144 |
{ |
| 145 |
struct libinput_event *ev; |
| 146 |
struct libinput_event_touch *tev; |
| 147 |
|
| 148 |
litest_dispatch(li); |
| 149 |
ev = libinput_get_event(li); |
| 150 |
tev = litest_is_touch_event(ev, type); |
| 151 |
slot = libinput_event_touch_get_slot(tev); |
| 152 |
litest_assert_int_eq(slot, slot); |
| 153 |
slot = libinput_event_touch_get_seat_slot(tev); |
| 154 |
litest_assert_int_eq(slot, seat_slot); |
| 155 |
libinput_event_destroy(ev); |
| 156 |
|
| 157 |
ev = libinput_get_event(li); |
| 158 |
litest_assert_event_type(ev, LIBINPUT_EVENT_TOUCH_FRAME); |
| 159 |
libinput_event_destroy(ev); |
| 160 |
} |
| 161 |
|
| 162 |
START_TEST(touch_seat_slot) |
| 163 |
{ |
| 164 |
struct litest_device *dev1 = litest_current_device(); |
| 165 |
struct litest_device *dev2; |
| 166 |
struct libinput *li = dev1->libinput; |
| 167 |
|
| 168 |
dev2 = litest_add_device(li, LITEST_WACOM_ISDV4_E6_FINGER); |
| 169 |
|
| 170 |
litest_drain_events(li); |
| 171 |
|
| 172 |
litest_touch_down(dev1, 0, 50, 50); |
| 173 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 0, 0); |
| 174 |
|
| 175 |
litest_touch_down(dev2, 0, 50, 50); |
| 176 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 0, 1); |
| 177 |
|
| 178 |
litest_touch_down(dev2, 1, 60, 50); |
| 179 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 1, 2); |
| 180 |
|
| 181 |
litest_touch_down(dev1, 1, 60, 50); |
| 182 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 1, 3); |
| 183 |
|
| 184 |
litest_touch_move_to(dev1, 0, 50, 50, 60, 70, 10); |
| 185 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_MOTION, 0, 0); |
| 186 |
litest_drain_events(li); |
| 187 |
|
| 188 |
litest_touch_move_to(dev2, 1, 50, 50, 60, 70, 10); |
| 189 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_MOTION, 1, 2); |
| 190 |
litest_drain_events(li); |
| 191 |
|
| 192 |
litest_touch_up(dev1, 0); |
| 193 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 0, 0); |
| 194 |
|
| 195 |
litest_touch_up(dev2, 0); |
| 196 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 0, 1); |
| 197 |
|
| 198 |
litest_touch_up(dev2, 1); |
| 199 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 1, 2); |
| 200 |
|
| 201 |
litest_touch_up(dev1, 1); |
| 202 |
touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 1, 3); |
| 203 |
|
| 204 |
litest_device_destroy(dev2); |
| 205 |
} |
| 206 |
END_TEST |
| 207 |
|
| 208 |
START_TEST(touch_many_slots) |
| 209 |
{ |
| 210 |
struct libinput *libinput; |
| 211 |
struct litest_device *dev; |
| 212 |
struct libinput_event *ev; |
| 213 |
int slot; |
| 214 |
const int num_tps = 100; |
| 215 |
int slot_count = 0; |
| 216 |
enum libinput_event_type type; |
| 217 |
|
| 218 |
struct input_absinfo abs[] = { |
| 219 |
{ ABS_MT_SLOT, 0, num_tps - 1, 0, 0, 0 }, |
| 220 |
{ .value = -1 }, |
| 221 |
}; |
| 222 |
|
| 223 |
dev = litest_create_device_with_overrides(LITEST_WACOM_ISDV4_E6_FINGER, |
| 224 |
"litest Multi-touch device", |
| 225 |
NULL, |
| 226 |
abs, |
| 227 |
NULL); |
| 228 |
libinput = dev->libinput; |
| 229 |
|
| 230 |
for (slot = 0; slot < num_tps; ++slot) |
| 231 |
litest_touch_down(dev, slot, 0, 0); |
| 232 |
for (slot = 0; slot < num_tps; ++slot) |
| 233 |
litest_touch_up(dev, slot); |
| 234 |
|
| 235 |
litest_dispatch(libinput); |
| 236 |
while ((ev = libinput_get_event(libinput))) { |
| 237 |
type = libinput_event_get_type(ev); |
| 238 |
|
| 239 |
if (type == LIBINPUT_EVENT_TOUCH_DOWN) |
| 240 |
slot_count++; |
| 241 |
else if (type == LIBINPUT_EVENT_TOUCH_UP) |
| 242 |
break; |
| 243 |
|
| 244 |
libinput_event_destroy(ev); |
| 245 |
litest_dispatch(libinput); |
| 246 |
} |
| 247 |
|
| 248 |
litest_assert_notnull(ev); |
| 249 |
litest_assert_int_gt(slot_count, 0); |
| 250 |
|
| 251 |
litest_dispatch(libinput); |
| 252 |
do { |
| 253 |
type = libinput_event_get_type(ev); |
| 254 |
litest_assert_enum_ne(type, LIBINPUT_EVENT_TOUCH_DOWN); |
| 255 |
if (type == LIBINPUT_EVENT_TOUCH_UP) |
| 256 |
slot_count--; |
| 257 |
|
| 258 |
libinput_event_destroy(ev); |
| 259 |
litest_dispatch(libinput); |
| 260 |
} while ((ev = libinput_get_event(libinput))); |
| 261 |
|
| 262 |
litest_assert_int_eq(slot_count, 0); |
| 263 |
|
| 264 |
litest_device_destroy(dev); |
| 265 |
} |
| 266 |
END_TEST |
| 267 |
|
| 268 |
START_TEST(touch_double_touch_down_up) |
| 269 |
{ |
| 270 |
struct libinput *libinput; |
| 271 |
struct litest_device *dev; |
| 272 |
struct libinput_event *ev; |
| 273 |
bool got_down = false; |
| 274 |
bool got_up = false; |
| 275 |
|
| 276 |
dev = litest_current_device(); |
| 277 |
libinput = dev->libinput; |
| 278 |
|
| 279 |
litest_disable_log_handler(libinput); |
| 280 |
/* note: this test is a false negative, libevdev will filter |
| 281 |
* tracking IDs re-used in the same slot. */ |
| 282 |
litest_touch_down(dev, 0, 0, 0); |
| 283 |
litest_touch_down(dev, 0, 0, 0); |
| 284 |
litest_touch_up(dev, 0); |
| 285 |
litest_touch_up(dev, 0); |
| 286 |
litest_dispatch(libinput); |
| 287 |
litest_restore_log_handler(libinput); |
| 288 |
|
| 289 |
while ((ev = libinput_get_event(libinput))) { |
| 290 |
switch (libinput_event_get_type(ev)) { |
| 291 |
case LIBINPUT_EVENT_TOUCH_DOWN: |
| 292 |
litest_assert(!got_down); |
| 293 |
got_down = true; |
| 294 |
break; |
| 295 |
case LIBINPUT_EVENT_TOUCH_UP: |
| 296 |
litest_assert(got_down); |
| 297 |
litest_assert(!got_up); |
| 298 |
got_up = true; |
| 299 |
break; |
| 300 |
default: |
| 301 |
break; |
| 302 |
} |
| 303 |
|
| 304 |
libinput_event_destroy(ev); |
| 305 |
litest_dispatch(libinput); |
| 306 |
} |
| 307 |
|
| 308 |
litest_assert(got_down); |
| 309 |
litest_assert(got_up); |
| 310 |
} |
| 311 |
END_TEST |
| 312 |
|
| 313 |
START_TEST(touch_calibration_scale) |
| 314 |
{ |
| 315 |
struct libinput *li; |
| 316 |
struct litest_device *dev; |
| 317 |
struct libinput_event *ev; |
| 318 |
struct libinput_event_touch *tev; |
| 319 |
float matrix[6] = { 1, 0, 0, 0, 1, 0 }; |
| 320 |
|
| 321 |
float calibration; |
| 322 |
double x, y; |
| 323 |
const int width = 640, height = 480; |
| 324 |
|
| 325 |
dev = litest_current_device(); |
| 326 |
li = dev->libinput; |
| 327 |
|
| 328 |
for (calibration = 0.1; calibration < 1; calibration += 0.1) { |
| 329 |
libinput_device_config_calibration_set_matrix(dev->libinput_device, |
| 330 |
matrix); |
| 331 |
litest_drain_events(li); |
| 332 |
|
| 333 |
litest_touch_down(dev, 0, 100, 100); |
| 334 |
litest_touch_up(dev, 0); |
| 335 |
litest_dispatch(li); |
| 336 |
|
| 337 |
ev = libinput_get_event(li); |
| 338 |
tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); |
| 339 |
|
| 340 |
x = libinput_event_touch_get_x_transformed(tev, width); |
| 341 |
y = libinput_event_touch_get_y_transformed(tev, height); |
| 342 |
|
| 343 |
litest_assert_int_eq(round(x), round(width * matrix[0])); |
| 344 |
litest_assert_int_eq(round(y), round(height * matrix[4])); |
| 345 |
|
| 346 |
libinput_event_destroy(ev); |
| 347 |
litest_drain_events(li); |
| 348 |
|
| 349 |
matrix[0] = calibration; |
| 350 |
matrix[4] = 1 - calibration; |
| 351 |
} |
| 352 |
} |
| 353 |
END_TEST |
| 354 |
|
| 355 |
START_TEST(touch_calibration_rotation) |
| 356 |
{ |
| 357 |
struct libinput *li; |
| 358 |
struct litest_device *dev; |
| 359 |
struct libinput_event *ev; |
| 360 |
struct libinput_event_touch *tev; |
| 361 |
float matrix[6]; |
| 362 |
int i; |
| 363 |
double x, y; |
| 364 |
int width = 1024, height = 480; |
| 365 |
|
| 366 |
dev = litest_current_device(); |
| 367 |
li = dev->libinput; |
| 368 |
|
| 369 |
for (i = 0; i < 4; i++) { |
| 370 |
float angle = i * M_PI / 2; |
| 371 |
|
| 372 |
/* [ cos -sin tx ] |
| 373 |
[ sin cos ty ] |
| 374 |
[ 0 0 1 ] */ |
| 375 |
matrix[0] = cos(angle); |
| 376 |
matrix[1] = -sin(angle); |
| 377 |
matrix[3] = sin(angle); |
| 378 |
matrix[4] = cos(angle); |
| 379 |
|
| 380 |
switch (i) { |
| 381 |
case 0: /* 0 deg */ |
| 382 |
matrix[2] = 0; |
| 383 |
matrix[5] = 0; |
| 384 |
break; |
| 385 |
case 1: /* 90 deg cw */ |
| 386 |
matrix[2] = 1; |
| 387 |
matrix[5] = 0; |
| 388 |
break; |
| 389 |
case 2: /* 180 deg cw */ |
| 390 |
matrix[2] = 1; |
| 391 |
matrix[5] = 1; |
| 392 |
break; |
| 393 |
case 3: /* 270 deg cw */ |
| 394 |
matrix[2] = 0; |
| 395 |
matrix[5] = 1; |
| 396 |
break; |
| 397 |
} |
| 398 |
|
| 399 |
libinput_device_config_calibration_set_matrix(dev->libinput_device, |
| 400 |
matrix); |
| 401 |
litest_drain_events(li); |
| 402 |
|
| 403 |
litest_touch_down(dev, 0, 80, 20); |
| 404 |
litest_touch_up(dev, 0); |
| 405 |
litest_dispatch(li); |
| 406 |
ev = libinput_get_event(li); |
| 407 |
tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); |
| 408 |
|
| 409 |
x = libinput_event_touch_get_x_transformed(tev, width); |
| 410 |
y = libinput_event_touch_get_y_transformed(tev, height); |
| 411 |
|
| 412 |
/* rounding errors... */ |
| 413 |
switch (i) { |
| 414 |
case 0: /* 0 deg */ |
| 415 |
litest_assert_double_eq_epsilon(x, width * 0.8, 1.0); |
| 416 |
litest_assert_double_eq_epsilon(y, height * 0.2, 1.0); |
| 417 |
break; |
| 418 |
case 1: /* 90 deg cw */ |
| 419 |
litest_assert_double_eq_epsilon(x, width * 0.8, 1.0); |
| 420 |
litest_assert_double_eq_epsilon(y, height * 0.8, 1.0); |
| 421 |
break; |
| 422 |
case 2: /* 180 deg cw */ |
| 423 |
litest_assert_double_eq_epsilon(x, width * 0.2, 1.0); |
| 424 |
litest_assert_double_eq_epsilon(y, height * 0.8, 1.0); |
| 425 |
break; |
| 426 |
case 3: /* 270 deg cw */ |
| 427 |
litest_assert_double_eq_epsilon(x, width * 0.2, 1.0); |
| 428 |
litest_assert_double_eq_epsilon(y, height * 0.2, 1.0); |
| 429 |
break; |
| 430 |
} |
| 431 |
|
| 432 |
libinput_event_destroy(ev); |
| 433 |
litest_drain_events(li); |
| 434 |
} |
| 435 |
} |
| 436 |
END_TEST |
| 437 |
|
| 438 |
START_TEST(touch_calibration_translation) |
| 439 |
{ |
| 440 |
struct libinput *li; |
| 441 |
struct litest_device *dev; |
| 442 |
struct libinput_event *ev; |
| 443 |
struct libinput_event_touch *tev; |
| 444 |
float matrix[6] = { 1, 0, 0, 0, 1, 0 }; |
| 445 |
|
| 446 |
float translate; |
| 447 |
double x, y; |
| 448 |
const int width = 640, height = 480; |
| 449 |
|
| 450 |
dev = litest_current_device(); |
| 451 |
li = dev->libinput; |
| 452 |
|
| 453 |
/* translating from 0 up to 1 device width/height */ |
| 454 |
for (translate = 0.1; translate <= 1; translate += 0.1) { |
| 455 |
libinput_device_config_calibration_set_matrix(dev->libinput_device, |
| 456 |
matrix); |
| 457 |
litest_drain_events(li); |
| 458 |
|
| 459 |
litest_touch_down(dev, 0, 100, 100); |
| 460 |
litest_touch_up(dev, 0); |
| 461 |
|
| 462 |
litest_dispatch(li); |
| 463 |
ev = libinput_get_event(li); |
| 464 |
tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); |
| 465 |
|
| 466 |
x = libinput_event_touch_get_x_transformed(tev, width); |
| 467 |
y = libinput_event_touch_get_y_transformed(tev, height); |
| 468 |
|
| 469 |
/* sigh. rounding errors */ |
| 470 |
litest_assert_int_ge(round(x), width + round(width * matrix[2]) - 1); |
| 471 |
litest_assert_int_ge(round(y), height + round(height * matrix[5]) - 1); |
| 472 |
litest_assert_int_le(round(x), width + round(width * matrix[2]) + 1); |
| 473 |
litest_assert_int_le(round(y), height + round(height * matrix[5]) + 1); |
| 474 |
|
| 475 |
libinput_event_destroy(ev); |
| 476 |
litest_drain_events(li); |
| 477 |
|
| 478 |
matrix[2] = translate; |
| 479 |
matrix[5] = 1 - translate; |
| 480 |
} |
| 481 |
} |
| 482 |
END_TEST |
| 483 |
|
| 484 |
START_TEST(touch_calibrated_screen_path) |
| 485 |
{ |
| 486 |
struct litest_device *dev = litest_current_device(); |
| 487 |
float matrix[6]; |
| 488 |
int rc; |
| 489 |
|
| 490 |
rc = libinput_device_config_calibration_has_matrix(dev->libinput_device); |
| 491 |
litest_assert_int_eq(rc, 1); |
| 492 |
|
| 493 |
rc = libinput_device_config_calibration_get_matrix(dev->libinput_device, |
| 494 |
matrix); |
| 495 |
litest_assert_int_eq(rc, 1); |
| 496 |
|
| 497 |
litest_assert_double_eq(matrix[0], 1.2); |
| 498 |
litest_assert_double_eq(matrix[1], 3.4); |
| 499 |
litest_assert_double_eq(matrix[2], 5.6); |
| 500 |
litest_assert_double_eq(matrix[3], 7.8); |
| 501 |
litest_assert_double_eq(matrix[4], 9.10); |
| 502 |
litest_assert_double_eq(matrix[5], 11.12); |
| 503 |
} |
| 504 |
END_TEST |
| 505 |
|
| 506 |
START_TEST(touch_calibration_config) |
| 507 |
{ |
| 508 |
struct litest_device *dev = litest_current_device(); |
| 509 |
float identity[6] = { 1, 0, 0, 0, 1, 0 }; |
| 510 |
float nonidentity[6] = { 1, 2, 3, 4, 5, 6 }; |
| 511 |
float matrix[6]; |
| 512 |
enum libinput_config_status status; |
| 513 |
int rc; |
| 514 |
|
| 515 |
rc = libinput_device_config_calibration_has_matrix(dev->libinput_device); |
| 516 |
litest_assert_int_eq(rc, 1); |
| 517 |
|
| 518 |
/* Twice so we have every to-fro combination */ |
| 519 |
for (int i = 0; i < 2; i++) { |
| 520 |
status = libinput_device_config_calibration_set_matrix( |
| 521 |
dev->libinput_device, |
| 522 |
identity); |
| 523 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 524 |
libinput_device_config_calibration_get_matrix(dev->libinput_device, |
| 525 |
matrix); |
| 526 |
litest_assert_int_eq(memcmp(matrix, identity, sizeof(matrix)), 0); |
| 527 |
|
| 528 |
status = libinput_device_config_calibration_set_matrix( |
| 529 |
dev->libinput_device, |
| 530 |
nonidentity); |
| 531 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 532 |
libinput_device_config_calibration_get_matrix(dev->libinput_device, |
| 533 |
matrix); |
| 534 |
litest_assert_int_eq(memcmp(matrix, nonidentity, sizeof(matrix)), 0); |
| 535 |
} |
| 536 |
} |
| 537 |
END_TEST |
| 538 |
|
| 539 |
static int |
| 540 |
open_restricted(const char *path, int flags, void *data) |
| 541 |
{ |
| 542 |
int fd; |
| 543 |
fd = open(path, flags); |
| 544 |
return fd < 0 ? -errno : fd; |
| 545 |
} |
| 546 |
static void |
| 547 |
close_restricted(int fd, void *data) |
| 548 |
{ |
| 549 |
close(fd); |
| 550 |
} |
| 551 |
|
| 552 |
static const struct libinput_interface simple_interface = { |
| 553 |
.open_restricted = open_restricted, |
| 554 |
.close_restricted = close_restricted, |
| 555 |
}; |
| 556 |
|
| 557 |
START_TEST(touch_calibrated_screen_udev) |
| 558 |
{ |
| 559 |
struct libinput *li; |
| 560 |
struct libinput_event *ev; |
| 561 |
struct libinput_device *device = NULL; |
| 562 |
struct udev *udev; |
| 563 |
float matrix[6]; |
| 564 |
int rc; |
| 565 |
|
| 566 |
udev = udev_new(); |
| 567 |
litest_assert_notnull(udev); |
| 568 |
|
| 569 |
li = libinput_udev_create_context(&simple_interface, NULL, udev); |
| 570 |
litest_assert_notnull(li); |
| 571 |
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); |
| 572 |
|
| 573 |
litest_dispatch(li); |
| 574 |
|
| 575 |
while ((ev = libinput_get_event(li))) { |
| 576 |
struct libinput_device *d; |
| 577 |
|
| 578 |
if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED) { |
| 579 |
libinput_event_destroy(ev); |
| 580 |
continue; |
| 581 |
} |
| 582 |
|
| 583 |
d = libinput_event_get_device(ev); |
| 584 |
|
| 585 |
if (libinput_device_get_id_vendor(d) == 0x22 && |
| 586 |
libinput_device_get_id_product(d) == 0x33) { |
| 587 |
device = libinput_device_ref(d); |
| 588 |
litest_drain_events(li); |
| 589 |
} |
| 590 |
libinput_event_destroy(ev); |
| 591 |
} |
| 592 |
|
| 593 |
litest_drain_events(li); |
| 594 |
|
| 595 |
litest_assert_notnull(device); |
| 596 |
rc = libinput_device_config_calibration_has_matrix(device); |
| 597 |
litest_assert_int_eq(rc, 1); |
| 598 |
|
| 599 |
rc = libinput_device_config_calibration_get_matrix(device, matrix); |
| 600 |
litest_assert_int_eq(rc, 1); |
| 601 |
|
| 602 |
litest_assert_double_eq(matrix[0], 1.2); |
| 603 |
litest_assert_double_eq(matrix[1], 3.4); |
| 604 |
litest_assert_double_eq(matrix[2], 5.6); |
| 605 |
litest_assert_double_eq(matrix[3], 7.8); |
| 606 |
litest_assert_double_eq(matrix[4], 9.10); |
| 607 |
litest_assert_double_eq(matrix[5], 11.12); |
| 608 |
|
| 609 |
libinput_device_unref(device); |
| 610 |
|
| 611 |
libinput_unref(li); |
| 612 |
udev_unref(udev); |
| 613 |
} |
| 614 |
END_TEST |
| 615 |
|
| 616 |
START_TEST(touch_no_left_handed) |
| 617 |
{ |
| 618 |
struct litest_device *dev = litest_current_device(); |
| 619 |
struct libinput_device *d = dev->libinput_device; |
| 620 |
enum libinput_config_status status; |
| 621 |
int rc; |
| 622 |
|
| 623 |
rc = libinput_device_config_left_handed_is_available(d); |
| 624 |
litest_assert_int_eq(rc, 0); |
| 625 |
|
| 626 |
rc = libinput_device_config_left_handed_get(d); |
| 627 |
litest_assert_int_eq(rc, 0); |
| 628 |
|
| 629 |
rc = libinput_device_config_left_handed_get_default(d); |
| 630 |
litest_assert_int_eq(rc, 0); |
| 631 |
|
| 632 |
status = libinput_device_config_left_handed_set(d, 0); |
| 633 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); |
| 634 |
} |
| 635 |
END_TEST |
| 636 |
|
| 637 |
START_TEST(fake_mt_exists) |
| 638 |
{ |
| 639 |
struct litest_device *dev = litest_current_device(); |
| 640 |
struct libinput *li = dev->libinput; |
| 641 |
struct libinput_event *event; |
| 642 |
struct libinput_device *device; |
| 643 |
|
| 644 |
litest_dispatch(li); |
| 645 |
|
| 646 |
event = libinput_get_event(li); |
| 647 |
device = libinput_event_get_device(event); |
| 648 |
|
| 649 |
litest_assert( |
| 650 |
!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)); |
| 651 |
|
| 652 |
/* This test may need fixing if we add other fake-mt devices that |
| 653 |
* have different capabilities */ |
| 654 |
litest_assert( |
| 655 |
libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)); |
| 656 |
|
| 657 |
libinput_event_destroy(event); |
| 658 |
} |
| 659 |
END_TEST |
| 660 |
|
| 661 |
START_TEST(fake_mt_no_touch_events) |
| 662 |
{ |
| 663 |
struct litest_device *dev = litest_current_device(); |
| 664 |
struct libinput *li = dev->libinput; |
| 665 |
|
| 666 |
litest_drain_events(li); |
| 667 |
|
| 668 |
litest_touch_down(dev, 0, 50, 50); |
| 669 |
litest_touch_move_to(dev, 0, 50, 50, 70, 70, 5); |
| 670 |
litest_touch_up(dev, 0); |
| 671 |
|
| 672 |
litest_touch_down(dev, 0, 50, 50); |
| 673 |
litest_touch_down(dev, 1, 70, 70); |
| 674 |
litest_touch_move_to(dev, 0, 50, 50, 90, 40, 10); |
| 675 |
litest_touch_move_to(dev, 0, 70, 70, 40, 50, 10); |
| 676 |
litest_touch_up(dev, 0); |
| 677 |
litest_touch_up(dev, 1); |
| 678 |
|
| 679 |
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); |
| 680 |
} |
| 681 |
END_TEST |
| 682 |
|
| 683 |
START_TEST(touch_protocol_a_init) |
| 684 |
{ |
| 685 |
struct litest_device *dev = litest_current_device(); |
| 686 |
struct libinput *li = dev->libinput; |
| 687 |
struct libinput_device *device = dev->libinput_device; |
| 688 |
|
| 689 |
litest_wait_for_event(li); |
| 690 |
|
| 691 |
litest_assert( |
| 692 |
libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)); |
| 693 |
} |
| 694 |
END_TEST |
| 695 |
|
| 696 |
START_TEST(touch_protocol_a_touch) |
| 697 |
{ |
| 698 |
struct litest_device *dev = litest_current_device(); |
| 699 |
struct libinput *li = dev->libinput; |
| 700 |
struct libinput_event *ev; |
| 701 |
struct libinput_event_touch *tev; |
| 702 |
double x, y, oldx, oldy; |
| 703 |
|
| 704 |
litest_drain_events(li); |
| 705 |
|
| 706 |
litest_touch_down(dev, 0, 5, 95); |
| 707 |
litest_dispatch(li); |
| 708 |
|
| 709 |
ev = libinput_get_event(li); |
| 710 |
tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); |
| 711 |
|
| 712 |
oldx = libinput_event_touch_get_x(tev); |
| 713 |
oldy = libinput_event_touch_get_y(tev); |
| 714 |
|
| 715 |
libinput_event_destroy(ev); |
| 716 |
|
| 717 |
ev = libinput_get_event(li); |
| 718 |
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); |
| 719 |
libinput_event_destroy(ev); |
| 720 |
|
| 721 |
litest_touch_move_to(dev, 0, 10, 90, 90, 10, 20); |
| 722 |
litest_dispatch(li); |
| 723 |
|
| 724 |
while ((ev = libinput_get_event(li))) { |
| 725 |
if (libinput_event_get_type(ev) == LIBINPUT_EVENT_TOUCH_FRAME) { |
| 726 |
libinput_event_destroy(ev); |
| 727 |
continue; |
| 728 |
} |
| 729 |
|
| 730 |
litest_assert_event_type(ev, LIBINPUT_EVENT_TOUCH_MOTION); |
| 731 |
|
| 732 |
tev = libinput_event_get_touch_event(ev); |
| 733 |
x = libinput_event_touch_get_x(tev); |
| 734 |
y = libinput_event_touch_get_y(tev); |
| 735 |
|
| 736 |
litest_assert_int_gt(x, oldx); |
| 737 |
litest_assert_int_lt(y, oldy); |
| 738 |
|
| 739 |
oldx = x; |
| 740 |
oldy = y; |
| 741 |
|
| 742 |
libinput_event_destroy(ev); |
| 743 |
} |
| 744 |
|
| 745 |
litest_touch_up(dev, 0); |
| 746 |
litest_dispatch(li); |
| 747 |
ev = libinput_get_event(li); |
| 748 |
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_UP); |
| 749 |
libinput_event_destroy(ev); |
| 750 |
} |
| 751 |
END_TEST |
| 752 |
|
| 753 |
START_TEST(touch_protocol_a_2fg_touch) |
| 754 |
{ |
| 755 |
struct litest_device *dev = litest_current_device(); |
| 756 |
struct libinput *li = dev->libinput; |
| 757 |
struct libinput_event *ev; |
| 758 |
struct libinput_event_touch *tev; |
| 759 |
int pos; |
| 760 |
|
| 761 |
litest_drain_events(li); |
| 762 |
|
| 763 |
litest_touch_down(dev, 0, 5, 95); |
| 764 |
litest_touch_down(dev, 1, 95, 5); |
| 765 |
|
| 766 |
litest_dispatch(li); |
| 767 |
litest_assert_touch_down_frame(li); |
| 768 |
|
| 769 |
ev = libinput_get_event(li); |
| 770 |
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); |
| 771 |
libinput_event_destroy(ev); |
| 772 |
|
| 773 |
ev = libinput_get_event(li); |
| 774 |
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); |
| 775 |
libinput_event_destroy(ev); |
| 776 |
|
| 777 |
for (pos = 10; pos < 100; pos += 10) { |
| 778 |
litest_touch_move(dev, 0, pos, 100 - pos); |
| 779 |
litest_touch_move(dev, 1, 100 - pos, pos); |
| 780 |
litest_dispatch(li); |
| 781 |
|
| 782 |
ev = libinput_get_event(li); |
| 783 |
tev = libinput_event_get_touch_event(ev); |
| 784 |
litest_assert_int_eq(libinput_event_touch_get_slot(tev), 0); |
| 785 |
libinput_event_destroy(ev); |
| 786 |
|
| 787 |
ev = libinput_get_event(li); |
| 788 |
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); |
| 789 |
libinput_event_destroy(ev); |
| 790 |
|
| 791 |
ev = libinput_get_event(li); |
| 792 |
tev = libinput_event_get_touch_event(ev); |
| 793 |
litest_assert_int_eq(libinput_event_touch_get_slot(tev), 1); |
| 794 |
libinput_event_destroy(ev); |
| 795 |
|
| 796 |
ev = libinput_get_event(li); |
| 797 |
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); |
| 798 |
libinput_event_destroy(ev); |
| 799 |
} |
| 800 |
|
| 801 |
litest_touch_up(dev, 0); |
| 802 |
litest_dispatch(li); |
| 803 |
litest_assert_touch_up_frame(li); |
| 804 |
|
| 805 |
litest_touch_up(dev, 1); |
| 806 |
litest_dispatch(li); |
| 807 |
litest_assert_touch_up_frame(li); |
| 808 |
} |
| 809 |
END_TEST |
| 810 |
|
| 811 |
START_TEST(touch_initial_state) |
| 812 |
{ |
| 813 |
struct litest_device *dev; |
| 814 |
struct libinput *libinput1; |
| 815 |
struct libinput_event *ev1 = NULL; |
| 816 |
struct libinput_event *ev2 = NULL; |
| 817 |
struct libinput_event_touch *t1, *t2; |
| 818 |
struct libinput_device *device1, *device2; |
| 819 |
int axis = litest_test_param_get_i32(test_env->params, "axis"); |
| 820 |
|
| 821 |
dev = litest_current_device(); |
| 822 |
device1 = dev->libinput_device; |
| 823 |
libinput_device_config_tap_set_enabled(device1, LIBINPUT_CONFIG_TAP_DISABLED); |
| 824 |
|
| 825 |
libinput1 = dev->libinput; |
| 826 |
litest_touch_down(dev, 0, 40, 60); |
| 827 |
litest_touch_up(dev, 0); |
| 828 |
|
| 829 |
/* device is now on some x/y value */ |
| 830 |
litest_drain_events(libinput1); |
| 831 |
|
| 832 |
_litest_context_destroy_ struct libinput *libinput2 = litest_create_context(); |
| 833 |
device2 = libinput_path_add_device(libinput2, |
| 834 |
libevdev_uinput_get_devnode(dev->uinput)); |
| 835 |
libinput_device_config_tap_set_enabled(device2, LIBINPUT_CONFIG_TAP_DISABLED); |
| 836 |
litest_drain_events(libinput2); |
| 837 |
|
| 838 |
if (axis == ABS_X) |
| 839 |
litest_touch_down(dev, 0, 40, 70); |
| 840 |
else |
| 841 |
litest_touch_down(dev, 0, 70, 60); |
| 842 |
litest_touch_up(dev, 0); |
| 843 |
|
| 844 |
litest_dispatch(libinput1); |
| 845 |
litest_dispatch(libinput2); |
| 846 |
|
| 847 |
while (libinput_next_event_type(libinput1)) { |
| 848 |
ev1 = libinput_get_event(libinput1); |
| 849 |
ev2 = libinput_get_event(libinput2); |
| 850 |
|
| 851 |
t1 = litest_is_touch_event(ev1, 0); |
| 852 |
t2 = litest_is_touch_event(ev2, 0); |
| 853 |
|
| 854 |
litest_assert_int_eq(libinput_event_get_type(ev1), |
| 855 |
libinput_event_get_type(ev2)); |
| 856 |
|
| 857 |
if (libinput_event_get_type(ev1) == LIBINPUT_EVENT_TOUCH_UP || |
| 858 |
libinput_event_get_type(ev1) == LIBINPUT_EVENT_TOUCH_FRAME) |
| 859 |
break; |
| 860 |
|
| 861 |
litest_assert_double_eq(libinput_event_touch_get_x(t1), |
| 862 |
libinput_event_touch_get_x(t2)); |
| 863 |
litest_assert_double_eq(libinput_event_touch_get_y(t1), |
| 864 |
libinput_event_touch_get_y(t2)); |
| 865 |
|
| 866 |
libinput_event_destroy(ev1); |
| 867 |
libinput_event_destroy(ev2); |
| 868 |
ev1 = NULL; |
| 869 |
ev2 = NULL; |
| 870 |
} |
| 871 |
|
| 872 |
libinput_event_destroy(ev1); |
| 873 |
libinput_event_destroy(ev2); |
| 874 |
} |
| 875 |
END_TEST |
| 876 |
|
| 877 |
START_TEST(touch_time_usec) |
| 878 |
{ |
| 879 |
struct litest_device *dev = litest_current_device(); |
| 880 |
struct libinput *li = dev->libinput; |
| 881 |
struct libinput_event *event; |
| 882 |
struct libinput_event_touch *tev; |
| 883 |
uint64_t time_usec; |
| 884 |
|
| 885 |
litest_drain_events(dev->libinput); |
| 886 |
|
| 887 |
litest_touch_down(dev, 0, 10, 10); |
| 888 |
litest_dispatch(li); |
| 889 |
|
| 890 |
event = libinput_get_event(li); |
| 891 |
tev = litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_DOWN); |
| 892 |
time_usec = libinput_event_touch_get_time_usec(tev); |
| 893 |
litest_assert_int_eq(libinput_event_touch_get_time(tev), |
| 894 |
(uint32_t)(time_usec / 1000)); |
| 895 |
libinput_event_destroy(event); |
| 896 |
} |
| 897 |
END_TEST |
| 898 |
|
| 899 |
START_TEST(touch_fuzz) |
| 900 |
{ |
| 901 |
struct litest_device *dev = litest_current_device(); |
| 902 |
struct libinput *li = dev->libinput; |
| 903 |
struct libinput_event *event; |
| 904 |
int i; |
| 905 |
int x = 700, y = 300; |
| 906 |
|
| 907 |
litest_drain_events(dev->libinput); |
| 908 |
|
| 909 |
litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 30); |
| 910 |
litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); |
| 911 |
litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); |
| 912 |
litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); |
| 913 |
litest_event(dev, EV_KEY, BTN_TOUCH, 1); |
| 914 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 915 |
litest_dispatch(li); |
| 916 |
|
| 917 |
event = libinput_get_event(li); |
| 918 |
litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_DOWN); |
| 919 |
libinput_event_destroy(event); |
| 920 |
event = libinput_get_event(li); |
| 921 |
litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); |
| 922 |
libinput_event_destroy(event); |
| 923 |
|
| 924 |
litest_drain_events(li); |
| 925 |
|
| 926 |
for (i = 0; i < 50; i++) { |
| 927 |
if (i % 2) { |
| 928 |
x++; |
| 929 |
y--; |
| 930 |
} else { |
| 931 |
x--; |
| 932 |
y++; |
| 933 |
} |
| 934 |
litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); |
| 935 |
litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); |
| 936 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 937 |
litest_dispatch(li); |
| 938 |
litest_assert_empty_queue(li); |
| 939 |
} |
| 940 |
} |
| 941 |
END_TEST |
| 942 |
|
| 943 |
START_TEST(touch_fuzz_property) |
| 944 |
{ |
| 945 |
struct litest_device *dev = litest_current_device(); |
| 946 |
struct udev_device *d; |
| 947 |
const char *prop; |
| 948 |
int fuzz = 0; |
| 949 |
|
| 950 |
litest_assert_int_eq(libevdev_get_abs_fuzz(dev->evdev, ABS_X), 0); |
| 951 |
litest_assert_int_eq(libevdev_get_abs_fuzz(dev->evdev, ABS_Y), 0); |
| 952 |
|
| 953 |
d = libinput_device_get_udev_device(dev->libinput_device); |
| 954 |
prop = udev_device_get_property_value(d, "LIBINPUT_FUZZ_00"); |
| 955 |
litest_assert_notnull(prop); |
| 956 |
litest_assert(safe_atoi(prop, &fuzz)); |
| 957 |
litest_assert_int_eq(fuzz, 10); /* device-specific */ |
| 958 |
|
| 959 |
prop = udev_device_get_property_value(d, "LIBINPUT_FUZZ_01"); |
| 960 |
litest_assert_notnull(prop); |
| 961 |
litest_assert(safe_atoi(prop, &fuzz)); |
| 962 |
litest_assert_int_eq(fuzz, 12); /* device-specific */ |
| 963 |
|
| 964 |
udev_device_unref(d); |
| 965 |
} |
| 966 |
END_TEST |
| 967 |
|
| 968 |
START_TEST(touch_release_on_unplug) |
| 969 |
{ |
| 970 |
struct litest_device *dev; |
| 971 |
struct libinput_event *ev; |
| 972 |
|
| 973 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 974 |
dev = litest_add_device(li, LITEST_GENERIC_MULTITOUCH_SCREEN); |
| 975 |
litest_drain_events(li); |
| 976 |
|
| 977 |
litest_touch_down(dev, 0, 50, 50); |
| 978 |
litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); |
| 979 |
litest_drain_events(li); |
| 980 |
|
| 981 |
/* Touch is still down when device is removed, expect a release */ |
| 982 |
litest_device_destroy(dev); |
| 983 |
litest_dispatch(li); |
| 984 |
|
| 985 |
ev = libinput_get_event(li); |
| 986 |
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_CANCEL); |
| 987 |
libinput_event_destroy(ev); |
| 988 |
|
| 989 |
ev = libinput_get_event(li); |
| 990 |
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); |
| 991 |
libinput_event_destroy(ev); |
| 992 |
|
| 993 |
ev = libinput_get_event(li); |
| 994 |
litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_REMOVED); |
| 995 |
libinput_event_destroy(ev); |
| 996 |
} |
| 997 |
END_TEST |
| 998 |
|
| 999 |
START_TEST(touch_invalid_range_over) |
| 1000 |
{ |
| 1001 |
struct litest_device *dev = litest_current_device(); |
| 1002 |
struct libinput *li = dev->libinput; |
| 1003 |
struct libinput_event *ev; |
| 1004 |
struct libinput_event_touch *t; |
| 1005 |
double x, y; |
| 1006 |
|
| 1007 |
litest_drain_events(li); |
| 1008 |
|
| 1009 |
/* Touch outside the valid area */ |
| 1010 |
litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); |
| 1011 |
litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); |
| 1012 |
litest_event(dev, EV_ABS, ABS_X, 4000); |
| 1013 |
litest_event(dev, EV_ABS, ABS_Y, 5000); |
| 1014 |
litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000); |
| 1015 |
litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 5000); |
| 1016 |
litest_event(dev, EV_KEY, BTN_TOUCH, 1); |
| 1017 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1018 |
litest_dispatch(li); |
| 1019 |
|
| 1020 |
/* Expect the mm to be correct regardless */ |
| 1021 |
ev = libinput_get_event(li); |
| 1022 |
t = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); |
| 1023 |
x = libinput_event_touch_get_x(t); |
| 1024 |
y = libinput_event_touch_get_y(t); |
| 1025 |
litest_assert_double_eq(x, 300); /* device has resolution 10 */ |
| 1026 |
litest_assert_double_eq(y, 300); /* device has resolution 10 */ |
| 1027 |
|
| 1028 |
/* Expect the percentage to be correct too, even if > 100% */ |
| 1029 |
x = libinput_event_touch_get_x_transformed(t, 100); |
| 1030 |
y = libinput_event_touch_get_y_transformed(t, 100); |
| 1031 |
litest_assert_double_eq(round(x), 200); |
| 1032 |
litest_assert_double_eq(round(y), 120); |
| 1033 |
|
| 1034 |
libinput_event_destroy(ev); |
| 1035 |
} |
| 1036 |
END_TEST |
| 1037 |
|
| 1038 |
START_TEST(touch_invalid_range_under) |
| 1039 |
{ |
| 1040 |
struct litest_device *dev = litest_current_device(); |
| 1041 |
struct libinput *li = dev->libinput; |
| 1042 |
struct libinput_event *ev; |
| 1043 |
struct libinput_event_touch *t; |
| 1044 |
double x, y; |
| 1045 |
|
| 1046 |
litest_drain_events(li); |
| 1047 |
|
| 1048 |
/* Touch outside the valid area */ |
| 1049 |
litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); |
| 1050 |
litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); |
| 1051 |
litest_event(dev, EV_ABS, ABS_X, -500); |
| 1052 |
litest_event(dev, EV_ABS, ABS_Y, 1000); |
| 1053 |
litest_event(dev, EV_ABS, ABS_MT_POSITION_X, -500); |
| 1054 |
litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 1000); |
| 1055 |
litest_event(dev, EV_KEY, BTN_TOUCH, 1); |
| 1056 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1057 |
litest_dispatch(li); |
| 1058 |
|
| 1059 |
/* Expect the mm to be correct regardless */ |
| 1060 |
ev = libinput_get_event(li); |
| 1061 |
t = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); |
| 1062 |
x = libinput_event_touch_get_x(t); |
| 1063 |
y = libinput_event_touch_get_y(t); |
| 1064 |
litest_assert_double_eq(x, -150); /* device has resolution 10 */ |
| 1065 |
litest_assert_double_eq(y, -100); /* device has resolution 10 */ |
| 1066 |
|
| 1067 |
/* Expect the percentage to be correct too, even if > 100% */ |
| 1068 |
x = libinput_event_touch_get_x_transformed(t, 100); |
| 1069 |
y = libinput_event_touch_get_y_transformed(t, 100); |
| 1070 |
litest_assert_double_eq(round(x), -100); |
| 1071 |
litest_assert_double_eq(round(y), -40); |
| 1072 |
|
| 1073 |
libinput_event_destroy(ev); |
| 1074 |
} |
| 1075 |
END_TEST |
| 1076 |
|
| 1077 |
START_TEST(touch_count_st) |
| 1078 |
{ |
| 1079 |
struct litest_device *dev = litest_current_device(); |
| 1080 |
struct libinput_device *device = dev->libinput_device; |
| 1081 |
|
| 1082 |
litest_assert_int_eq(libinput_device_touch_get_touch_count(device), 1); |
| 1083 |
} |
| 1084 |
END_TEST |
| 1085 |
|
| 1086 |
START_TEST(touch_count_mt) |
| 1087 |
{ |
| 1088 |
struct litest_device *dev = litest_current_device(); |
| 1089 |
struct libinput_device *device = dev->libinput_device; |
| 1090 |
struct libevdev *evdev = dev->evdev; |
| 1091 |
|
| 1092 |
litest_assert_int_eq(libinput_device_touch_get_touch_count(device), |
| 1093 |
libevdev_get_num_slots(evdev)); |
| 1094 |
} |
| 1095 |
END_TEST |
| 1096 |
|
| 1097 |
START_TEST(touch_count_mtdev) |
| 1098 |
{ |
| 1099 |
struct litest_device *dev = litest_current_device(); |
| 1100 |
struct libinput_device *device = dev->libinput_device; |
| 1101 |
|
| 1102 |
/* We hardcode this to 10 */ |
| 1103 |
litest_assert_int_eq(libinput_device_touch_get_touch_count(device), 10); |
| 1104 |
} |
| 1105 |
END_TEST |
| 1106 |
|
| 1107 |
START_TEST(touch_count_invalid) |
| 1108 |
{ |
| 1109 |
struct litest_device *dev = litest_current_device(); |
| 1110 |
struct libinput_device *device = dev->libinput_device; |
| 1111 |
|
| 1112 |
litest_assert_int_eq(libinput_device_touch_get_touch_count(device), -1); |
| 1113 |
} |
| 1114 |
END_TEST |
| 1115 |
|
| 1116 |
static inline bool |
| 1117 |
touch_has_tool_palm(struct litest_device *dev) |
| 1118 |
{ |
| 1119 |
return libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_TOOL_TYPE); |
| 1120 |
} |
| 1121 |
|
| 1122 |
START_TEST(touch_palm_detect_tool_palm) |
| 1123 |
{ |
| 1124 |
struct litest_device *dev = litest_current_device(); |
| 1125 |
struct libinput *li = dev->libinput; |
| 1126 |
struct axis_replacement axes[] = { |
| 1127 |
{ ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, |
| 1128 |
{ -1, 0 }, |
| 1129 |
}; |
| 1130 |
|
| 1131 |
if (!touch_has_tool_palm(dev)) |
| 1132 |
return LITEST_NOT_APPLICABLE; |
| 1133 |
|
| 1134 |
litest_touch_down(dev, 0, 50, 50); |
| 1135 |
litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); |
| 1136 |
litest_drain_events(li); |
| 1137 |
|
| 1138 |
litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); |
| 1139 |
litest_dispatch(li); |
| 1140 |
litest_assert_touch_cancel(li); |
| 1141 |
|
| 1142 |
litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); |
| 1143 |
litest_touch_up(dev, 0); |
| 1144 |
|
| 1145 |
litest_assert_empty_queue(li); |
| 1146 |
} |
| 1147 |
END_TEST |
| 1148 |
|
| 1149 |
START_TEST(touch_palm_detect_tool_palm_on_off) |
| 1150 |
{ |
| 1151 |
struct litest_device *dev = litest_current_device(); |
| 1152 |
struct libinput *li = dev->libinput; |
| 1153 |
struct axis_replacement axes[] = { |
| 1154 |
{ ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, |
| 1155 |
{ -1, 0 }, |
| 1156 |
}; |
| 1157 |
|
| 1158 |
if (!touch_has_tool_palm(dev)) |
| 1159 |
return LITEST_NOT_APPLICABLE; |
| 1160 |
|
| 1161 |
litest_touch_down(dev, 0, 50, 50); |
| 1162 |
litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); |
| 1163 |
litest_drain_events(li); |
| 1164 |
|
| 1165 |
litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); |
| 1166 |
litest_dispatch(li); |
| 1167 |
litest_assert_touch_cancel(li); |
| 1168 |
|
| 1169 |
litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); |
| 1170 |
litest_assert_empty_queue(li); |
| 1171 |
|
| 1172 |
litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); |
| 1173 |
litest_touch_move_to_extended(dev, 0, 50, 40, 70, 70, axes, 10); |
| 1174 |
litest_touch_up(dev, 0); |
| 1175 |
|
| 1176 |
litest_assert_empty_queue(li); |
| 1177 |
} |
| 1178 |
END_TEST |
| 1179 |
|
| 1180 |
START_TEST(touch_palm_detect_tool_palm_keep_type) |
| 1181 |
{ |
| 1182 |
struct litest_device *dev = litest_current_device(); |
| 1183 |
struct libinput *li = dev->libinput; |
| 1184 |
struct axis_replacement axes[] = { |
| 1185 |
{ ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, |
| 1186 |
{ -1, 0 }, |
| 1187 |
}; |
| 1188 |
|
| 1189 |
if (!touch_has_tool_palm(dev)) |
| 1190 |
return LITEST_NOT_APPLICABLE; |
| 1191 |
|
| 1192 |
litest_touch_down(dev, 0, 50, 50); |
| 1193 |
litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); |
| 1194 |
litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); |
| 1195 |
litest_touch_up(dev, 0); |
| 1196 |
litest_drain_events(li); |
| 1197 |
|
| 1198 |
/* ABS_MT_TOOL_TYPE never reset to finger, so a new touch |
| 1199 |
should be ignored outright */ |
| 1200 |
litest_touch_down_extended(dev, 0, 50, 50, axes); |
| 1201 |
|
| 1202 |
/* Test the revert to finger case too */ |
| 1203 |
litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); |
| 1204 |
litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); |
| 1205 |
litest_touch_up(dev, 0); |
| 1206 |
|
| 1207 |
litest_assert_empty_queue(li); |
| 1208 |
} |
| 1209 |
END_TEST |
| 1210 |
|
| 1211 |
START_TEST(touch_palm_detect_tool_palm_2fg) |
| 1212 |
{ |
| 1213 |
struct litest_device *dev = litest_current_device(); |
| 1214 |
struct libinput *li = dev->libinput; |
| 1215 |
struct axis_replacement axes[] = { |
| 1216 |
{ ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, |
| 1217 |
{ -1, 0 }, |
| 1218 |
}; |
| 1219 |
|
| 1220 |
if (!touch_has_tool_palm(dev)) |
| 1221 |
return LITEST_NOT_APPLICABLE; |
| 1222 |
|
| 1223 |
litest_touch_down(dev, 0, 50, 50); |
| 1224 |
litest_touch_down(dev, 1, 50, 50); |
| 1225 |
litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); |
| 1226 |
litest_drain_events(li); |
| 1227 |
|
| 1228 |
litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); |
| 1229 |
litest_dispatch(li); |
| 1230 |
litest_assert_touch_cancel(li); |
| 1231 |
|
| 1232 |
litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10); |
| 1233 |
litest_dispatch(li); |
| 1234 |
litest_assert_touch_motion_frame(li); |
| 1235 |
|
| 1236 |
litest_touch_up(dev, 1); |
| 1237 |
litest_dispatch(li); |
| 1238 |
litest_assert_touch_up_frame(li); |
| 1239 |
|
| 1240 |
litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); |
| 1241 |
litest_touch_up(dev, 0); |
| 1242 |
|
| 1243 |
litest_assert_empty_queue(li); |
| 1244 |
} |
| 1245 |
END_TEST |
| 1246 |
|
| 1247 |
START_TEST(touch_palm_detect_tool_palm_on_off_2fg) |
| 1248 |
{ |
| 1249 |
struct litest_device *dev = litest_current_device(); |
| 1250 |
struct libinput *li = dev->libinput; |
| 1251 |
struct axis_replacement axes[] = { |
| 1252 |
{ ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, |
| 1253 |
{ -1, 0 }, |
| 1254 |
}; |
| 1255 |
|
| 1256 |
if (!touch_has_tool_palm(dev)) |
| 1257 |
return LITEST_NOT_APPLICABLE; |
| 1258 |
|
| 1259 |
litest_touch_down(dev, 0, 50, 50); |
| 1260 |
litest_touch_down(dev, 1, 50, 50); |
| 1261 |
litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); |
| 1262 |
litest_drain_events(li); |
| 1263 |
|
| 1264 |
litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); |
| 1265 |
litest_dispatch(li); |
| 1266 |
litest_assert_touch_cancel(li); |
| 1267 |
|
| 1268 |
litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10); |
| 1269 |
litest_dispatch(li); |
| 1270 |
litest_assert_touch_motion_frame(li); |
| 1271 |
|
| 1272 |
litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); |
| 1273 |
litest_touch_move_to_extended(dev, 0, 50, 40, 70, 70, axes, 10); |
| 1274 |
litest_assert_empty_queue(li); |
| 1275 |
|
| 1276 |
litest_touch_move_to(dev, 1, 70, 70, 50, 40, 10); |
| 1277 |
litest_dispatch(li); |
| 1278 |
litest_assert_touch_motion_frame(li); |
| 1279 |
|
| 1280 |
litest_touch_up(dev, 1); |
| 1281 |
litest_dispatch(li); |
| 1282 |
litest_assert_touch_up_frame(li); |
| 1283 |
|
| 1284 |
litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); |
| 1285 |
litest_touch_up(dev, 0); |
| 1286 |
|
| 1287 |
litest_assert_empty_queue(li); |
| 1288 |
} |
| 1289 |
END_TEST |
| 1290 |
|
| 1291 |
START_TEST(touch_palm_detect_tool_palm_keep_type_2fg) |
| 1292 |
{ |
| 1293 |
struct litest_device *dev = litest_current_device(); |
| 1294 |
struct libinput *li = dev->libinput; |
| 1295 |
struct axis_replacement axes[] = { |
| 1296 |
{ ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, |
| 1297 |
{ -1, 0 }, |
| 1298 |
}; |
| 1299 |
|
| 1300 |
if (!touch_has_tool_palm(dev)) |
| 1301 |
return LITEST_NOT_APPLICABLE; |
| 1302 |
|
| 1303 |
litest_touch_down(dev, 0, 50, 50); |
| 1304 |
litest_touch_down(dev, 1, 50, 50); |
| 1305 |
litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); |
| 1306 |
litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); |
| 1307 |
litest_touch_up(dev, 0); |
| 1308 |
litest_drain_events(li); |
| 1309 |
|
| 1310 |
litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10); |
| 1311 |
litest_dispatch(li); |
| 1312 |
litest_assert_touch_motion_frame(li); |
| 1313 |
|
| 1314 |
/* ABS_MT_TOOL_TYPE never reset to finger, so a new touch |
| 1315 |
should be ignored outright */ |
| 1316 |
litest_touch_down_extended(dev, 0, 50, 50, axes); |
| 1317 |
|
| 1318 |
/* Test the revert to finger case too */ |
| 1319 |
litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); |
| 1320 |
litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); |
| 1321 |
litest_touch_up(dev, 0); |
| 1322 |
|
| 1323 |
litest_assert_empty_queue(li); |
| 1324 |
|
| 1325 |
litest_touch_up(dev, 1); |
| 1326 |
litest_dispatch(li); |
| 1327 |
litest_assert_touch_up_frame(li); |
| 1328 |
} |
| 1329 |
END_TEST |
| 1330 |
|
| 1331 |
TEST_COLLECTION(touch) |
| 1332 |
{ |
| 1333 |
/* clang-format off */ |
| 1334 |
litest_add(touch_frame_events, LITEST_TOUCH, LITEST_ANY); |
| 1335 |
litest_add(touch_downup_no_motion, LITEST_TOUCH, LITEST_ANY); |
| 1336 |
litest_add(touch_downup_no_motion, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); |
| 1337 |
litest_add_no_device(touch_abs_transform); |
| 1338 |
litest_add(touch_seat_slot, LITEST_TOUCH, LITEST_TOUCHPAD); |
| 1339 |
litest_add_no_device(touch_many_slots); |
| 1340 |
litest_add(touch_double_touch_down_up, LITEST_TOUCH, LITEST_PROTOCOL_A); |
| 1341 |
litest_add(touch_calibration_scale, LITEST_TOUCH, LITEST_TOUCHPAD); |
| 1342 |
litest_add(touch_calibration_scale, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); |
| 1343 |
litest_add(touch_calibration_rotation, LITEST_TOUCH, LITEST_TOUCHPAD); |
| 1344 |
litest_add(touch_calibration_rotation, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); |
| 1345 |
litest_add(touch_calibration_translation, LITEST_TOUCH, LITEST_TOUCHPAD); |
| 1346 |
litest_add(touch_calibration_translation, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); |
| 1347 |
litest_add_for_device(touch_calibrated_screen_path, LITEST_CALIBRATED_TOUCHSCREEN); |
| 1348 |
litest_add_for_device(touch_calibrated_screen_udev, LITEST_CALIBRATED_TOUCHSCREEN); |
| 1349 |
litest_add(touch_calibration_config, LITEST_TOUCH, LITEST_ANY); |
| 1350 |
|
| 1351 |
litest_add(touch_no_left_handed, LITEST_TOUCH, LITEST_ANY); |
| 1352 |
|
| 1353 |
litest_add(fake_mt_exists, LITEST_FAKE_MT, LITEST_ANY); |
| 1354 |
litest_add(fake_mt_no_touch_events, LITEST_FAKE_MT, LITEST_ANY); |
| 1355 |
|
| 1356 |
#ifdef HAVE_MTDEV |
| 1357 |
litest_add(touch_protocol_a_init, LITEST_PROTOCOL_A, LITEST_ANY); |
| 1358 |
litest_add(touch_protocol_a_touch, LITEST_PROTOCOL_A, LITEST_ANY); |
| 1359 |
litest_add(touch_protocol_a_2fg_touch, LITEST_PROTOCOL_A, LITEST_ANY); |
| 1360 |
#endif |
| 1361 |
|
| 1362 |
litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(ABS_X), litest_named_i32(ABS_Y)) { |
| 1363 |
litest_add_parametrized(touch_initial_state, LITEST_TOUCH, LITEST_PROTOCOL_A, params); |
| 1364 |
} |
| 1365 |
|
| 1366 |
litest_add(touch_time_usec, LITEST_TOUCH, LITEST_TOUCHPAD); |
| 1367 |
|
| 1368 |
litest_add_for_device(touch_fuzz, LITEST_MULTITOUCH_FUZZ_SCREEN); |
| 1369 |
litest_add_for_device(touch_fuzz_property, LITEST_MULTITOUCH_FUZZ_SCREEN); |
| 1370 |
|
| 1371 |
litest_add_no_device(touch_release_on_unplug); |
| 1372 |
|
| 1373 |
litest_add_for_device(touch_invalid_range_over, LITEST_TOUCHSCREEN_INVALID_RANGE); |
| 1374 |
litest_add_for_device(touch_invalid_range_under, LITEST_TOUCHSCREEN_INVALID_RANGE); |
| 1375 |
|
| 1376 |
litest_add(touch_count_st, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); |
| 1377 |
litest_add(touch_count_mt, LITEST_TOUCH, LITEST_SINGLE_TOUCH|LITEST_PROTOCOL_A); |
| 1378 |
#ifdef HAVE_MTDEV |
| 1379 |
litest_add(touch_count_mtdev, LITEST_PROTOCOL_A, LITEST_ANY); |
| 1380 |
litest_add(touch_count_invalid, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_PROTOCOL_A); |
| 1381 |
#endif |
| 1382 |
|
| 1383 |
litest_add(touch_palm_detect_tool_palm, LITEST_TOUCH, LITEST_ANY); |
| 1384 |
litest_add(touch_palm_detect_tool_palm_on_off, LITEST_TOUCH, LITEST_ANY); |
| 1385 |
litest_add(touch_palm_detect_tool_palm_keep_type, LITEST_TOUCH, LITEST_ANY); |
| 1386 |
litest_add(touch_palm_detect_tool_palm_2fg, LITEST_TOUCH, LITEST_SINGLE_TOUCH); |
| 1387 |
litest_add(touch_palm_detect_tool_palm_on_off_2fg, LITEST_TOUCH, LITEST_SINGLE_TOUCH); |
| 1388 |
litest_add(touch_palm_detect_tool_palm_keep_type_2fg, LITEST_TOUCH, LITEST_ANY); |
| 1389 |
/* clang-format on */ |
| 1390 |
} |