test-touchpad.c 193 KB
Newer Older
1 2 3
/*
 * Copyright © 2014 Red Hat, Inc.
 *
4 5 6 7 8 9
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
10
 *
11 12 13 14 15 16 17 18 19 20 21
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
22 23 24 25 26 27 28 29 30 31 32 33 34
 */

#include <config.h>

#include <check.h>
#include <errno.h>
#include <fcntl.h>
#include <libinput.h>
#include <unistd.h>

#include "libinput-util.h"
#include "litest.h"

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
static inline bool
has_disable_while_typing(struct litest_device *device)
{
	return libinput_device_config_dwt_is_available(device->libinput_device);
}

static inline struct litest_device *
dwt_init_paired_keyboard(struct libinput *li,
			 struct litest_device *touchpad)
{
	enum litest_device_type which = LITEST_KEYBOARD;

	if (libevdev_get_id_vendor(touchpad->evdev) == VENDOR_ID_APPLE)
		which = LITEST_APPLE_KEYBOARD;

	if (libevdev_get_id_vendor(touchpad->evdev) == VENDOR_ID_CHICONY)
		which = LITEST_ACER_HAWAII_KEYBOARD;

	return litest_add_device(li, which);
}

56 57 58 59 60 61 62
START_TEST(touchpad_1fg_motion)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;

63
	litest_disable_tap(dev->libinput_device);
64

65 66 67
	litest_drain_events(li);

	litest_touch_down(dev, 0, 50, 50);
68
	litest_touch_move_to(dev, 0, 50, 50, 80, 50, 20, 0);
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	litest_touch_up(dev, 0);

	libinput_dispatch(li);

	event = libinput_get_event(li);
	ck_assert(event != NULL);

	while (event) {
		ck_assert_int_eq(libinput_event_get_type(event),
				 LIBINPUT_EVENT_POINTER_MOTION);

		ptrev = libinput_event_get_pointer_event(event);
		ck_assert_int_ge(libinput_event_pointer_get_dx(ptrev), 0);
		ck_assert_int_eq(libinput_event_pointer_get_dy(ptrev), 0);
		libinput_event_destroy(event);
		event = libinput_get_event(li);
	}
}
END_TEST

START_TEST(touchpad_2fg_no_motion)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;

95 96 97
	libinput_device_config_tap_set_enabled(dev->libinput_device,
					       LIBINPUT_CONFIG_TAP_DISABLED);

98 99
	litest_drain_events(li);

100 101
	litest_touch_down(dev, 0, 20, 20);
	litest_touch_down(dev, 1, 70, 20);
102 103
	litest_touch_move_to(dev, 0, 20, 20, 80, 80, 20, 0);
	litest_touch_move_to(dev, 1, 70, 20, 80, 50, 20, 0);
104
	litest_touch_up(dev, 1);
105
	litest_touch_up(dev, 0);
106 107 108 109 110 111 112 113 114 115 116 117 118

	libinput_dispatch(li);

	event = libinput_get_event(li);
	while (event) {
		ck_assert_int_ne(libinput_event_get_type(event),
				 LIBINPUT_EVENT_POINTER_MOTION);
		libinput_event_destroy(event);
		event = libinput_get_event(li);
	}
}
END_TEST

119
static void
120
test_2fg_scroll(struct litest_device *dev, double dx, double dy, bool want_sleep)
121
{
122 123
	struct libinput *li = dev->libinput;

124 125
	litest_touch_down(dev, 0, 49, 50);
	litest_touch_down(dev, 1, 51, 50);
126

127
	litest_touch_move_two_touches(dev, 49, 50, 51, 50, dx, dy, 10, 10);
128

129
	/* Avoid a small scroll being seen as a tap */
130
	if (want_sleep) {
131
		libinput_dispatch(li);
132
		litest_timeout_tap();
133 134 135
		libinput_dispatch(li);
	}

136 137
	litest_touch_up(dev, 1);
	litest_touch_up(dev, 0);
138 139

	libinput_dispatch(li);
140 141 142 143 144 145 146
}

START_TEST(touchpad_2fg_scroll)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

147
	if (!litest_has_2fg_scroll(dev))
148 149
		return;

150
	litest_enable_2fg_scroll(dev);
151 152
	litest_drain_events(li);

153
	test_2fg_scroll(dev, 0.1, 40, false);
154
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
155
	test_2fg_scroll(dev, 0.1, -40, false);
156
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
157
	test_2fg_scroll(dev, 40, 0.1, false);
158
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
159
	test_2fg_scroll(dev, -40, 0.1, false);
160
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
161 162

	/* 2fg scroll smaller than the threshold should not generate events */
163
	test_2fg_scroll(dev, 0.1, 0.1, true);
164
	litest_assert_empty_queue(li);
165 166 167
}
END_TEST

168
START_TEST(touchpad_2fg_scroll_initially_diagonal)
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;
	int i;

	if (!litest_has_2fg_scroll(dev))
		return;

	litest_enable_2fg_scroll(dev);
	litest_drain_events(li);

	litest_touch_down(dev, 0, 45, 30);
	litest_touch_down(dev, 1, 55, 30);

185
	/* start diagonally */
186 187 188 189 190 191 192 193 194 195 196 197
	litest_touch_move_two_touches(dev, 45, 30, 55, 30, 10, 10, 10, 0);
	libinput_dispatch(li);
	litest_wait_for_event_of_type(li,
				      LIBINPUT_EVENT_POINTER_AXIS,
				      -1);
	litest_drain_events(li);

	/* get rid of any touch history still adding x deltas sideways */
	for (i = 0; i < 5; i++)
		litest_touch_move(dev, 0, 55, 41 + i);
	litest_drain_events(li);

198
	/* scroll vertical only and make sure the horiz axis is never set */
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
	for (i = 6; i < 10; i++) {
		litest_touch_move(dev, 0, 55, 41 + i);
		libinput_dispatch(li);

		event = libinput_get_event(li);
		ptrev = litest_is_axis_event(event,
				LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
				LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
		ck_assert(!libinput_event_pointer_has_axis(ptrev,
				LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL));
		libinput_event_destroy(event);
	}

	litest_touch_up(dev, 1);
	litest_touch_up(dev, 0);
	libinput_dispatch(li);
}
END_TEST

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
static bool
is_single_axis_2fg_scroll(struct litest_device *dev,
			   enum libinput_pointer_axis axis)
{
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;
	enum libinput_pointer_axis on_axis = axis;
	enum libinput_pointer_axis off_axis =
		(axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL) ?
		LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL :
		LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
	bool has_on_axis, has_off_axis;
	bool val = true;

	event = libinput_get_event(li);
	while (event) {
		litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_AXIS);
		ptrev = litest_is_axis_event(event, on_axis,
				LIBINPUT_POINTER_AXIS_SOURCE_FINGER);

		has_on_axis = libinput_event_pointer_has_axis(ptrev, on_axis);
		has_off_axis = libinput_event_pointer_has_axis(ptrev, off_axis);

		if (has_on_axis && has_off_axis) {
			val = (libinput_event_pointer_get_axis_value(ptrev, off_axis) == 0.0);
			break;
		}

		ck_assert(has_on_axis);
		ck_assert(!has_off_axis);

		libinput_event_destroy(event);
		event = libinput_get_event(li);
	}

	libinput_event_destroy(event);
	return val;
}

START_TEST(touchpad_2fg_scroll_axis_lock)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	enum libinput_pointer_axis axis;
	double delta[4][2] = {
		{ 7,  40},
		{ 7, -40},
		{-7,  40},
		{-7, -40}
	};
	/* 10 degrees off from horiz/vert should count as straight */

	if (!litest_has_2fg_scroll(dev))
		return;

	litest_enable_2fg_scroll(dev);
	litest_drain_events(li);

	axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
	for (int i = 0; i < 4; i++) {
		test_2fg_scroll(dev, delta[i][0], delta[i][1], false);
		ck_assert(is_single_axis_2fg_scroll(dev, axis));
		litest_assert_empty_queue(li);
	}

	axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
	for (int i = 0; i < 4; i++) {
		test_2fg_scroll(dev, delta[i][1], delta[i][0], false);
		ck_assert(is_single_axis_2fg_scroll(dev, axis));
		litest_assert_empty_queue(li);
	}
}
END_TEST

START_TEST(touchpad_2fg_scroll_axis_lock_switch)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	enum libinput_pointer_axis axis;

	if (!litest_has_2fg_scroll(dev))
		return;

	litest_enable_2fg_scroll(dev);
	litest_drain_events(li);

	litest_touch_down(dev, 0, 20, 20);
	litest_touch_down(dev, 1, 25, 20);

	/* Move roughly straight horizontally for >100ms to set axis lock */
309
	litest_touch_move_two_touches(dev, 20, 20, 25, 20, 55, 10, 15, 10);
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
	libinput_dispatch(li);
	litest_wait_for_event_of_type(li,
				      LIBINPUT_EVENT_POINTER_AXIS,
				      -1);

	axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
	ck_assert(is_single_axis_2fg_scroll(dev, axis));
	litest_drain_events(li);

	msleep(200);
	libinput_dispatch(li);

	/* Move roughly vertically for >100ms to switch axis lock. This will
	 * contain some horizontal movement while the lock changes; don't
	 * check for single-axis yet
	 */
326
	litest_touch_move_two_touches(dev, 75, 30, 80, 30, 2, 20, 15, 10);
327 328 329 330 331 332 333
	libinput_dispatch(li);
	litest_wait_for_event_of_type(li,
				      LIBINPUT_EVENT_POINTER_AXIS,
				      -1);
	litest_drain_events(li);

	/* Move some more, roughly vertically, and check new axis lock */
334
	litest_touch_move_two_touches(dev, 77, 50, 82, 50, 1, 40, 15, 10);
335 336 337 338 339 340 341 342 343 344
	libinput_dispatch(li);
	litest_wait_for_event_of_type(li,
				      LIBINPUT_EVENT_POINTER_AXIS,
				      -1);

	axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
	ck_assert(is_single_axis_2fg_scroll(dev, axis));
	litest_drain_events(li);

	/* Move in a clear diagonal direction to ensure the lock releases */
345
	litest_touch_move_two_touches(dev, 78, 90, 83, 90, -60, -60, 20, 10);
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
	libinput_dispatch(li);
	litest_wait_for_event_of_type(li,
				      LIBINPUT_EVENT_POINTER_AXIS,
				      -1);

	axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
	ck_assert(!is_single_axis_2fg_scroll(dev, axis));

	litest_touch_up(dev, 1);
	litest_touch_up(dev, 0);
	libinput_dispatch(li);
	litest_drain_events(li);
}
END_TEST

361 362 363 364 365 366
START_TEST(touchpad_2fg_scroll_slow_distance)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;
367 368
	double width, height;
	double y_move = 100;
369

370
	if (!litest_has_2fg_scroll(dev))
371 372
		return;

373
	/* We want to move > 5 mm. */
374 375 376 377
	ck_assert_int_eq(libinput_device_get_size(dev->libinput_device,
						  &width,
						  &height), 0);
	y_move = 100.0/height * 7;
378

379
	litest_enable_2fg_scroll(dev);
380 381
	litest_drain_events(li);

382 383
	litest_touch_down(dev, 0, 49, 50);
	litest_touch_down(dev, 1, 51, 50);
384
	litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, y_move, 100, 10);
385 386 387 388 389 390 391 392 393
	litest_touch_up(dev, 1);
	litest_touch_up(dev, 0);
	libinput_dispatch(li);

	event = libinput_get_event(li);
	ck_assert_notnull(event);

	/* last event is value 0, tested elsewhere */
	while (libinput_next_event_type(li) != LIBINPUT_EVENT_NONE) {
394
		double axisval;
395 396 397 398
		ck_assert_int_eq(libinput_event_get_type(event),
				 LIBINPUT_EVENT_POINTER_AXIS);
		ptrev = libinput_event_get_pointer_event(event);

399 400 401
		axisval = libinput_event_pointer_get_axis_value(ptrev,
				LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
		ck_assert(axisval > 0.0);
402 403 404 405

		/* this is to verify we test the right thing, if the value
		   is greater than scroll.threshold we triggered the wrong
		   condition */
406
		ck_assert(axisval < 5.0);
407 408 409 410 411 412 413 414 415 416

		libinput_event_destroy(event);
		event = libinput_get_event(li);
	}

	litest_assert_empty_queue(li);
	libinput_event_destroy(event);
}
END_TEST

417 418 419 420 421 422 423
START_TEST(touchpad_2fg_scroll_source)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;

424
	if (!litest_has_2fg_scroll(dev))
425 426
		return;

427
	litest_enable_2fg_scroll(dev);
428 429
	litest_drain_events(li);

430
	test_2fg_scroll(dev, 0, 30, false);
431 432 433 434 435 436 437 438 439 440 441 442 443
	litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);

	while ((event = libinput_get_event(li))) {
		ck_assert_int_eq(libinput_event_get_type(event),
				 LIBINPUT_EVENT_POINTER_AXIS);
		ptrev = libinput_event_get_pointer_event(event);
		ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev),
				 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
		libinput_event_destroy(event);
	}
}
END_TEST

444 445 446 447 448
START_TEST(touchpad_2fg_scroll_semi_mt)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

449
	if (!litest_has_2fg_scroll(dev))
450 451
		return;

452
	litest_enable_2fg_scroll(dev);
453 454 455 456 457
	litest_drain_events(li);

	litest_touch_down(dev, 0, 20, 20);
	litest_touch_down(dev, 1, 30, 20);
	libinput_dispatch(li);
458 459 460 461 462
	litest_touch_move_two_touches(dev,
				      20, 20,
				      30, 20,
				      30, 40,
				      10, 1);
463 464 465 466 467

	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
}
END_TEST

468 469 470 471 472
START_TEST(touchpad_2fg_scroll_return_to_motion)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

473
	if (!litest_has_2fg_scroll(dev))
474 475
		return;

476
	litest_enable_2fg_scroll(dev);
477 478 479 480
	litest_drain_events(li);

	/* start with motion */
	litest_touch_down(dev, 0, 70, 70);
481
	litest_touch_move_to(dev, 0, 70, 70, 49, 50, 10, 0);
482 483 484
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	/* 2fg scroll */
485 486
	litest_touch_down(dev, 1, 51, 50);
	litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, 20, 5, 0);
487
	litest_touch_up(dev, 1);
488 489 490
	libinput_dispatch(li);
	litest_timeout_finger_switch();
	libinput_dispatch(li);
491 492
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);

493
	litest_touch_move_to(dev, 0, 49, 70, 49, 50, 10, 0);
494 495 496
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	/* back to 2fg scroll, lifting the other finger */
497 498
	litest_touch_down(dev, 1, 51, 50);
	litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, 20, 5, 0);
499
	litest_touch_up(dev, 0);
500 501 502
	libinput_dispatch(li);
	litest_timeout_finger_switch();
	libinput_dispatch(li);
503 504 505
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);

	/* move with second finger */
506
	litest_touch_move_to(dev, 1, 51, 70, 51, 50, 10, 0);
507 508 509 510 511 512 513
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	litest_touch_up(dev, 1);
	litest_assert_empty_queue(li);
}
END_TEST

514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
START_TEST(touchpad_scroll_natural_defaults)
{
	struct litest_device *dev = litest_current_device();

	ck_assert_int_ge(libinput_device_config_scroll_has_natural_scroll(dev->libinput_device), 1);
	ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0);
	ck_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), 0);
}
END_TEST

START_TEST(touchpad_scroll_natural_enable_config)
{
	struct litest_device *dev = litest_current_device();
	enum libinput_config_status status;

	status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1);
	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
	ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 1);

	status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 0);
	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
	ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0);
}
END_TEST

539
START_TEST(touchpad_scroll_natural_2fg)
540 541 542 543
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

544
	if (!litest_has_2fg_scroll(dev))
545 546
		return;

547
	litest_enable_2fg_scroll(dev);
548 549 550 551
	litest_drain_events(li);

	libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1);

552
	test_2fg_scroll(dev, 0.1, 40, false);
553
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
554
	test_2fg_scroll(dev, 0.1, -40, false);
555
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
556
	test_2fg_scroll(dev, 40, 0.1, false);
557
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
558
	test_2fg_scroll(dev, -40, 0.1, false);
559 560 561 562 563
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);

}
END_TEST

564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
START_TEST(touchpad_scroll_natural_edge)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	litest_enable_edge_scroll(dev);
	litest_drain_events(li);

	libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1);

	litest_touch_down(dev, 0, 99, 20);
	litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -4);
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 99, 80);
	litest_touch_move_to(dev, 0, 99, 80, 99, 20, 10, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4);
	litest_assert_empty_queue(li);

}
END_TEST

593
START_TEST(touchpad_edge_scroll_vert)
594 595 596 597
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

598 599 600 601
	litest_touch_down(dev, 0, 99, 20);
	litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10, 0);
	litest_touch_up(dev, 0);

602
	litest_drain_events(li);
603
	litest_enable_edge_scroll(dev);
604 605 606 607 608 609

	litest_touch_down(dev, 0, 99, 20);
	litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);
610
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4);
611 612 613 614 615 616 617
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 99, 80);
	litest_touch_move_to(dev, 0, 99, 80, 99, 20, 10, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);
618
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -4);
619
	litest_assert_empty_queue(li);
620 621 622
}
END_TEST

623 624 625 626 627 628 629 630
static int
touchpad_has_horiz_edge_scroll_size(struct litest_device *dev)
{
	double width, height;
	int rc;

	rc = libinput_device_get_size(dev->libinput_device, &width, &height);

631
	return rc == 0 && height >= 40;
632 633
}

634 635 636 637 638
START_TEST(touchpad_edge_scroll_horiz)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

639 640 641 642
	litest_touch_down(dev, 0, 99, 20);
	litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10, 0);
	litest_touch_up(dev, 0);

643 644 645
	if (!touchpad_has_horiz_edge_scroll_size(dev))
		return;

646 647
	litest_drain_events(li);
	litest_enable_edge_scroll(dev);
648 649 650 651 652 653

	litest_touch_down(dev, 0, 20, 99);
	litest_touch_move_to(dev, 0, 20, 99, 70, 99, 10, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);
654
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 4);
655 656 657 658 659 660 661
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 70, 99);
	litest_touch_move_to(dev, 0, 70, 99, 20, 99, 10, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);
662
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -4);
663 664 665 666
	litest_assert_empty_queue(li);
}
END_TEST

667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
START_TEST(touchpad_edge_scroll_horiz_clickpad)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	litest_drain_events(li);
	litest_enable_edge_scroll(dev);

	litest_touch_down(dev, 0, 20, 99);
	litest_touch_move_to(dev, 0, 20, 99, 70, 99, 10, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 4);
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 70, 99);
	litest_touch_move_to(dev, 0, 70, 99, 20, 99, 10, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -4);
	litest_assert_empty_queue(li);
}
END_TEST

START_TEST(touchpad_edge_scroll_no_horiz)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	if (touchpad_has_horiz_edge_scroll_size(dev))
		return;

	litest_drain_events(li);
	litest_enable_edge_scroll(dev);

	litest_touch_down(dev, 0, 20, 99);
	litest_touch_move_to(dev, 0, 20, 99, 70, 99, 10, 0);
	litest_touch_up(dev, 0);

	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	litest_touch_down(dev, 0, 70, 99);
	litest_touch_move_to(dev, 0, 70, 99, 20, 99, 10, 0);
	litest_touch_up(dev, 0);

	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
}
END_TEST

718 719 720 721 722 723 724
START_TEST(touchpad_scroll_defaults)
{
	struct litest_device *dev = litest_current_device();
	struct libinput_device *device = dev->libinput_device;
	struct libevdev *evdev = dev->evdev;
	enum libinput_config_scroll_method method, expected;
	enum libinput_config_status status;
725 726 727 728 729 730
	bool should_have_2fg = false;

	if (libevdev_get_num_slots(evdev) > 1 ||
	    (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE &&
	     libevdev_get_id_product(dev->evdev) == PRODUCT_ID_APPLE_APPLETOUCH))
		should_have_2fg = true;
731 732 733

	method = libinput_device_config_scroll_get_methods(device);
	ck_assert(method & LIBINPUT_CONFIG_SCROLL_EDGE);
734
	if (should_have_2fg)
735
		ck_assert(method & LIBINPUT_CONFIG_SCROLL_2FG);
736 737
	else
		ck_assert((method & LIBINPUT_CONFIG_SCROLL_2FG) == 0);
738

739
	if (should_have_2fg)
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
		expected = LIBINPUT_CONFIG_SCROLL_2FG;
	else
		expected = LIBINPUT_CONFIG_SCROLL_EDGE;

	method = libinput_device_config_scroll_get_method(device);
	ck_assert_int_eq(method, expected);
	method = libinput_device_config_scroll_get_default_method(device);
	ck_assert_int_eq(method, expected);

	status = libinput_device_config_scroll_set_method(device,
					  LIBINPUT_CONFIG_SCROLL_EDGE);
	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
	status = libinput_device_config_scroll_set_method(device,
					  LIBINPUT_CONFIG_SCROLL_2FG);

755
	if (should_have_2fg)
756 757 758 759 760 761
		ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
	else
		ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
}
END_TEST

762
START_TEST(touchpad_edge_scroll_timeout)
763 764 765 766 767
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;
768
	double width = 0, height = 0;
769 770 771 772 773 774 775 776 777 778 779 780 781 782
	int nevents = 0;
	double mm; /* one mm in percent of the device */

	ck_assert_int_eq(libinput_device_get_size(dev->libinput_device,
						  &width,
						  &height), 0);
	mm = 100.0/height;

	/* timeout-based scrolling is disabled when software buttons are
	 * active, so switch to clickfinger. Not all test devices support
	 * that, hence the extra check. */
	if (libinput_device_config_click_get_methods(dev->libinput_device) &
	    LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER)
		litest_enable_clickfinger(dev);
783 784

	litest_drain_events(li);
785
	litest_enable_edge_scroll(dev);
786

787 788
	/* move 0.5mm, enough to load up the motion history, but less than
	 * the scroll threshold of 2mm */
789
	litest_touch_down(dev, 0, 99, 20);
790 791 792 793
	libinput_dispatch(li);
	litest_timeout_hysteresis();
	libinput_dispatch(li);

794
	litest_touch_move_to(dev, 0, 99, 20, 99, 20 + mm/2, 8, 0);
795
	libinput_dispatch(li);
796 797
	litest_assert_empty_queue(li);

798 799 800
	litest_timeout_edgescroll();
	libinput_dispatch(li);

801 802 803 804
	litest_assert_empty_queue(li);

	/* now move slowly up to the 2mm scroll threshold. we expect events */
	litest_touch_move_to(dev, 0, 99, 20 + mm/2, 99, 20 + mm * 2, 20, 0);
805 806 807
	litest_touch_up(dev, 0);
	libinput_dispatch(li);

808 809
	litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);

810 811 812 813 814 815 816 817 818
	while ((event = libinput_get_event(li))) {
		double value;

		ptrev = litest_is_axis_event(event,
					     LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
					     0);
		value = libinput_event_pointer_get_axis_value(ptrev,
							      LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
		ck_assert_double_lt(value, 5.0);
819
		libinput_event_destroy(event);
820
		nevents++;
821 822
	}

823 824 825 826
	/* we sent 20 events but allow for some to be swallowed by rounding
	 * errors, the hysteresis, etc. */
	ck_assert_int_ge(nevents, 10);

827 828 829 830 831 832 833 834 835 836 837
	litest_assert_empty_queue(li);
	libinput_event_destroy(event);
}
END_TEST

START_TEST(touchpad_edge_scroll_no_motion)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	litest_drain_events(li);
838
	litest_enable_edge_scroll(dev);
839

840
	litest_touch_down(dev, 0, 99, 10);
841
	litest_touch_move_to(dev, 0, 99, 10, 99, 70, 12, 0);
842
	/* moving outside -> no motion event */
843
	litest_touch_move_to(dev, 0, 99, 70, 20, 70, 12, 0);
844
	/* moving down outside edge once scrolling had started -> scroll */
845
	litest_touch_move_to(dev, 0, 20, 70, 40, 99, 12, 0);
846 847 848
	litest_touch_up(dev, 0);
	libinput_dispatch(li);

849
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4);
850 851 852 853 854 855 856 857 858 859
	litest_assert_empty_queue(li);
}
END_TEST

START_TEST(touchpad_edge_scroll_no_edge_after_motion)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	litest_drain_events(li);
860
	litest_enable_edge_scroll(dev);
861 862 863

	/* moving into the edge zone must not trigger scroll events */
	litest_touch_down(dev, 0, 20, 20);
864 865
	litest_touch_move_to(dev, 0, 20, 20, 99, 20, 22, 10);
	litest_touch_move_to(dev, 0, 99, 20, 99, 80, 22, 10);
866 867 868 869 870 871 872 873
	litest_touch_up(dev, 0);
	libinput_dispatch(li);

	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
	litest_assert_empty_queue(li);
}
END_TEST

874 875 876 877 878 879 880 881
START_TEST(touchpad_edge_scroll_source)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;

	litest_drain_events(li);
882
	litest_enable_edge_scroll(dev);
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900

	litest_touch_down(dev, 0, 99, 20);
	litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10, 0);
	litest_touch_up(dev, 0);

	litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);

	while ((event = libinput_get_event(li))) {
		ck_assert_int_eq(libinput_event_get_type(event),
				 LIBINPUT_EVENT_POINTER_AXIS);
		ptrev = libinput_event_get_pointer_event(event);
		ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev),
				 LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
		libinput_event_destroy(event);
	}
}
END_TEST

901 902 903 904 905 906
START_TEST(touchpad_edge_scroll_no_2fg)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	litest_drain_events(li);
907
	litest_enable_edge_scroll(dev);
908

909 910
	litest_touch_down(dev, 0, 49, 50);
	litest_touch_down(dev, 1, 51, 50);
911
	litest_touch_move_two_touches(dev, 49, 50, 51, 50, 20, 30, 10, 10);
912 913 914 915 916 917 918 919 920
	libinput_dispatch(li);
	litest_touch_up(dev, 0);
	litest_touch_up(dev, 1);
	libinput_dispatch(li);

	litest_assert_empty_queue(li);
}
END_TEST

921 922 923 924 925
START_TEST(touchpad_edge_scroll_into_buttonareas)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

926 927
	litest_enable_buttonareas(dev);
	litest_enable_edge_scroll(dev);
928 929 930 931
	litest_drain_events(li);

	litest_touch_down(dev, 0, 99, 40);
	litest_touch_move_to(dev, 0, 99, 40, 99, 95, 10, 0);
932
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
933 934
	/* in the button zone now, make sure we still get events */
	litest_touch_move_to(dev, 0, 99, 95, 99, 100, 10, 0);
935
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
936 937 938

	/* and out of the zone again */
	litest_touch_move_to(dev, 0, 99, 100, 99, 70, 10, 0);
939
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
940 941 942

	/* still out of the zone */
	litest_touch_move_to(dev, 0, 99, 70, 99, 50, 10, 0);
943
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
944 945 946 947 948 949 950 951
}
END_TEST

START_TEST(touchpad_edge_scroll_within_buttonareas)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

952 953 954
	if (!touchpad_has_horiz_edge_scroll_size(dev))
		return;

955 956
	litest_enable_buttonareas(dev);
	litest_enable_edge_scroll(dev);
957 958 959 960 961 962
	litest_drain_events(li);

	litest_touch_down(dev, 0, 20, 99);

	/* within left button */
	litest_touch_move_to(dev, 0, 20, 99, 40, 99, 10, 0);
963
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
964 965 966

	/* over to right button */
	litest_touch_move_to(dev, 0, 40, 99, 60, 99, 10, 0);
967
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
968 969 970

	/* within right button */
	litest_touch_move_to(dev, 0, 60, 99, 80, 99, 10, 0);
971
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
972 973 974 975 976 977 978 979 980 981 982
}
END_TEST

START_TEST(touchpad_edge_scroll_buttonareas_click_stops_scroll)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;
	double val;

983 984 985
	if (!touchpad_has_horiz_edge_scroll_size(dev))
		return;

986 987
	litest_enable_buttonareas(dev);
	litest_enable_edge_scroll(dev);
988 989 990 991
	litest_drain_events(li);

	litest_touch_down(dev, 0, 20, 95);
	litest_touch_move_to(dev, 0, 20, 95, 70, 95, 10, 5);
992
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
993

994
	litest_button_click(dev, BTN_LEFT, true);
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
	libinput_dispatch(li);

	event = libinput_get_event(li);
	ptrev = litest_is_axis_event(event,
				     LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
				     LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
	val = libinput_event_pointer_get_axis_value(ptrev,
				    LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
	ck_assert(val == 0.0);
	libinput_event_destroy(event);

	event = libinput_get_event(li);
1007 1008 1009
	litest_is_button_event(event,
			       BTN_RIGHT,
			       LIBINPUT_BUTTON_STATE_PRESSED);
1010 1011 1012

	libinput_event_destroy(event);

1013 1014 1015 1016 1017 1018 1019
	/* move within button areas but we cancelled the scroll so now we
	 * get pointer motion events when moving.
	 *
	 * This is not ideal behavior, but the use-case of horizontal
	 * edge scrolling, click, then scrolling without lifting the finger
	 * is so small we'll let it pass.
	 */
1020
	litest_touch_move_to(dev, 0, 70, 95, 90, 95, 10, 0);
1021
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1022

1023
	litest_button_click(dev, BTN_LEFT, false);
1024

1025
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038

	litest_touch_up(dev, 0);
}
END_TEST

START_TEST(touchpad_edge_scroll_clickfinger_click_stops_scroll)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;
	double val;

1039 1040 1041
	if (!touchpad_has_horiz_edge_scroll_size(dev))
		return;

1042 1043
	litest_enable_clickfinger(dev);
	litest_enable_edge_scroll(dev);
1044 1045 1046 1047
	litest_drain_events(li);

	litest_touch_down(dev, 0, 20, 95);
	litest_touch_move_to(dev, 0, 20, 95, 70, 95, 10, 5);
1048
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
1049

1050
	litest_button_click(dev, BTN_LEFT, true);
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
	libinput_dispatch(li);

	event = libinput_get_event(li);
	ptrev = litest_is_axis_event(event,
				     LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
				     LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
	val = libinput_event_pointer_get_axis_value(ptrev,
				    LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
	ck_assert(val == 0.0);
	libinput_event_destroy(event);

	event = libinput_get_event(li);
1063 1064 1065
	litest_is_button_event(event,
			       BTN_LEFT,
			       LIBINPUT_BUTTON_STATE_PRESSED);
1066 1067 1068 1069 1070

	libinput_event_destroy(event);

	/* clickfinger releases pointer -> expect movement */
	litest_touch_move_to(dev, 0, 70, 95, 90, 95, 10, 0);
1071
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1072 1073
	litest_assert_empty_queue(li);

1074
	litest_button_click(dev, BTN_LEFT, false);
1075

1076
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON);
1077 1078 1079 1080 1081

	litest_touch_up(dev, 0);
}
END_TEST

1082 1083 1084 1085 1086
START_TEST(touchpad_edge_scroll_into_area)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1087
	litest_enable_edge_scroll(dev);
1088 1089 1090 1091 1092
	litest_drain_events(li);

	/* move into area, move vertically, move back to edge */

	litest_touch_down(dev, 0, 99, 20);
1093 1094
	litest_touch_move_to(dev, 0, 99, 20, 99, 50, 15, 2);
	litest_touch_move_to(dev, 0, 99, 50, 20, 50, 15, 2);
1095 1096
	litest_assert_only_typed_events(li,
					LIBINPUT_EVENT_POINTER_AXIS);
1097 1098
	litest_touch_move_to(dev, 0, 20, 50, 20, 20, 15, 2);
	litest_touch_move_to(dev, 0, 20, 20, 99, 20, 15, 2);
1099 1100
	litest_assert_empty_queue(li);

1101
	litest_touch_move_to(dev, 0, 99, 20, 99, 50, 15, 2);
1102 1103 1104 1105 1106
	litest_assert_only_typed_events(li,
					LIBINPUT_EVENT_POINTER_AXIS);
}
END_TEST

1107
static bool
1108 1109 1110
touchpad_has_palm_detect_size(struct litest_device *dev)
{
	double width, height;
1111
	unsigned int vendor;
1112
	unsigned int bustype;
1113
	int rc;
1114

1115
	vendor = libinput_device_get_id_vendor(dev->libinput_device);
1116
	bustype = libevdev_get_id_bustype(dev->evdev);
1117 1118
	if (vendor == VENDOR_ID_WACOM)
		return 0;
1119 1120
	if (bustype == BUS_BLUETOOTH)
		return 0;
1121
	if (vendor == VENDOR_ID_APPLE)
1122 1123
		return 1;

1124
	rc = libinput_device_get_size(dev->libinput_device, &width, &height);
1125

1126
	return rc == 0 && width >= 70;
1127 1128
}

1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
static bool
touchpad_has_top_palm_detect_size(struct litest_device *dev)
{
	double width, height;
	int rc;

	if (!touchpad_has_palm_detect_size(dev))
		return false;

	rc = libinput_device_get_size(dev->libinput_device, &width, &height);

	return rc == 0 && height > 55;
}

1143 1144 1145 1146 1147
START_TEST(touchpad_palm_detect_at_edge)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1148
	if (!touchpad_has_palm_detect_size(dev) ||
1149
	    !litest_has_2fg_scroll(dev))
1150 1151
		return;

1152
	litest_enable_2fg_scroll(dev);
1153

1154
	litest_disable_tap(dev->libinput_device);
1155

1156 1157 1158
	litest_drain_events(li);

	litest_touch_down(dev, 0, 99, 50);
1159
	litest_touch_move_to(dev, 0, 99, 50, 99, 70, 5, 0);
1160 1161 1162 1163 1164
	litest_touch_up(dev, 0);

	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 5, 50);
1165
	litest_touch_move_to(dev, 0, 5, 50, 5, 70, 5, 0);
1166
	litest_touch_up(dev, 0);
1167 1168

	litest_assert_empty_queue(li);
1169 1170 1171
}
END_TEST

1172 1173 1174 1175 1176
START_TEST(touchpad_palm_detect_at_top)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1177
	if (!touchpad_has_top_palm_detect_size(dev))
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
		return;

	litest_disable_tap(dev->libinput_device);

	litest_drain_events(li);

	litest_touch_down(dev, 0, 20, 1);
	litest_touch_move_to(dev, 0, 20, 1, 70, 1, 10, 0);
	litest_touch_up(dev, 0);

	litest_assert_empty_queue(li);
}
END_TEST

1192 1193 1194 1195 1196 1197 1198 1199
START_TEST(touchpad_no_palm_detect_at_edge_for_edge_scrolling)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	if (!touchpad_has_palm_detect_size(dev))
		return;

1200
	litest_enable_edge_scroll(dev);
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211

	litest_drain_events(li);

	litest_touch_down(dev, 0, 99, 50);
	litest_touch_move_to(dev, 0, 99, 50, 99, 70, 5, 0);
	litest_touch_up(dev, 0);

	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
}
END_TEST

1212 1213 1214 1215 1216
START_TEST(touchpad_palm_detect_at_bottom_corners)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1217
	if (!touchpad_has_palm_detect_size(dev) ||
1218
	    !litest_has_2fg_scroll(dev))
1219 1220
		return;

1221
	litest_enable_2fg_scroll(dev);
1222

1223
	litest_disable_tap(dev->libinput_device);
1224

1225 1226 1227 1228 1229
	/* Run for non-clickpads only: make sure the bottom corners trigger
	   palm detection too */
	litest_drain_events(li);

	litest_touch_down(dev, 0, 99, 95);
1230
	litest_touch_move_to(dev, 0, 99, 95, 99, 99, 10, 0);
1231 1232 1233 1234 1235
	litest_touch_up(dev, 0);

	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 5, 95);
1236
	litest_touch_move_to(dev, 0, 5, 95, 5, 99, 5, 0);
1237 1238 1239 1240 1241 1242 1243 1244 1245
	litest_touch_up(dev, 0);
}
END_TEST

START_TEST(touchpad_palm_detect_at_top_corners)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1246
	if (!touchpad_has_palm_detect_size(dev) ||
1247
	    !litest_has_2fg_scroll(dev))
1248 1249
		return;

1250
	litest_enable_2fg_scroll(dev);
1251

1252
	litest_disable_tap(dev->libinput_device);
1253

1254 1255 1256 1257 1258
	/* Run for non-clickpads only: make sure the bottom corners trigger
	   palm detection too */
	litest_drain_events(li);

	litest_touch_down(dev, 0, 99, 5);
1259
	litest_touch_move_to(dev, 0, 99, 5, 99, 9, 10, 0);
1260 1261 1262 1263 1264
	litest_touch_up(dev, 0);

	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 5, 5);
1265
	litest_touch_move_to(dev, 0, 5, 5, 5, 9, 5, 0);
1266
	litest_touch_up(dev, 0);
1267 1268

	litest_assert_empty_queue(li);
1269 1270 1271
}
END_TEST

1272 1273 1274 1275 1276
START_TEST(touchpad_palm_detect_palm_stays_palm)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1277
	if (!touchpad_has_palm_detect_size(dev) ||
1278
	    !litest_has_2fg_scroll(dev))
1279 1280
		return;

1281
	litest_enable_2fg_scroll(dev);
1282

1283
	litest_disable_tap(dev->libinput_device);
1284

1285 1286 1287
	litest_drain_events(li);

	litest_touch_down(dev, 0, 99, 20);
1288
	litest_touch_move_to(dev, 0, 99, 20, 75, 99, 20, 10);
1289 1290 1291 1292 1293
	litest_touch_up(dev, 0);
	litest_assert_empty_queue(li);
}
END_TEST

1294 1295 1296 1297 1298
START_TEST(touchpad_palm_detect_top_palm_stays_palm)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1299
	if (!touchpad_has_top_palm_detect_size(dev))
1300 1301 1302 1303 1304 1305 1306
		return;

	litest_disable_tap(dev->libinput_device);

	litest_drain_events(li);

	litest_touch_down(dev, 0, 20, 1);
1307
	litest_touch_move_to(dev, 0, 20, 1, 50, 30, 20, 10);
1308 1309 1310 1311 1312 1313
	litest_touch_up(dev, 0);

	litest_assert_empty_queue(li);
}
END_TEST

1314
START_TEST(touchpad_palm_detect_palm_becomes_pointer)
1315 1316 1317 1318
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1319
	if (!touchpad_has_palm_detect_size(dev) ||
1320
	    !litest_has_2fg_scroll(dev))
1321 1322
		return;

1323
	litest_enable_2fg_scroll(dev);
1324

1325
	litest_disable_tap(dev->libinput_device);
1326

1327 1328 1329
	litest_drain_events(li);

	litest_touch_down(dev, 0, 99, 50);
1330
	litest_touch_move_to(dev, 0, 99, 50, 0, 70, 20, 0);
1331 1332
	litest_touch_up(dev, 0);

1333 1334
	libinput_dispatch(li);

1335
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1336

1337 1338 1339 1340
	litest_assert_empty_queue(li);
}
END_TEST

1341 1342 1343 1344 1345
START_TEST(touchpad_palm_detect_top_palm_becomes_pointer)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1346
	if (!touchpad_has_top_palm_detect_size(dev))
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
		return;

	litest_disable_tap(dev->libinput_device);

	litest_drain_events(li);

	litest_touch_down(dev, 0, 50, 1);
	litest_touch_move_to(dev, 0, 50, 1, 50, 60, 20, 0);
	litest_touch_up(dev, 0);

	libinput_dispatch(li);

	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	litest_assert_empty_queue(li);
}
END_TEST

1365 1366 1367 1368 1369
START_TEST(touchpad_palm_detect_no_palm_moving_into_edges)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1370 1371 1372
	if (!touchpad_has_palm_detect_size(dev))
		return;

1373
	litest_disable_tap(dev->libinput_device);
1374

1375 1376 1377 1378
	/* moving non-palm into the edge does not label it as palm */
	litest_drain_events(li);

	litest_touch_down(dev, 0, 50, 50);
1379
	litest_touch_move_to(dev, 0, 50, 50, 99, 50, 10, 0);
1380 1381 1382

	litest_drain_events(li);

1383
	litest_touch_move_to(dev, 0, 99, 50, 99, 90, 10, 0);
1384 1385
	libinput_dispatch(li);

1386
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
1387 1388 1389 1390 1391 1392 1393

	litest_touch_up(dev, 0);
	libinput_dispatch(li);
	litest_assert_empty_queue(li);
}
END_TEST

1394 1395 1396 1397 1398
START_TEST(touchpad_palm_detect_no_palm_moving_into_top)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1399
	if (!touchpad_has_top_palm_detect_size(dev))
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
		return;

	litest_disable_tap(dev->libinput_device);

	/* moving non-palm into the edge does not label it as palm */
	litest_drain_events(li);

	litest_touch_down(dev, 0, 50, 50);
	litest_touch_move_to(dev, 0, 50, 50, 0, 2, 10, 0);

	litest_drain_events(li);

	litest_touch_move_to(dev, 0, 0, 2, 50, 50, 10, 0);
	libinput_dispatch(li);

	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	litest_touch_up(dev, 0);
	libinput_dispatch(li);
	litest_assert_empty_queue(li);
}
END_TEST

START_TEST(touchpad_palm_detect_no_tap_top_edge)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

1428
	if (!touchpad_has_top_palm_detect_size(dev))
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
		return;

	litest_enable_tap(dev->libinput_device);

	litest_drain_events(li);

	litest_touch_down(dev, 0, 50, 1);
	litest_touch_up(dev, 0);
	libinput_dispatch(li);

	litest_timeout_tap();
	litest_assert_empty_queue(li);
}
END_TEST

1444
START_TEST(touchpad_palm_detect_tap_hardbuttons)
1445 1446 1447 1448 1449 1450 1451
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	if (!touchpad_has_palm_detect_size(dev))
		return;

1452
	litest_enable_tap(dev->libinput_device);
1453 1454 1455 1456 1457

	litest_drain_events(li);

	litest_touch_down(dev, 0, 95, 5);
	litest_touch_up(dev, 0);
1458 1459 1460
	libinput_dispatch(li);

	litest_timeout_tap();
1461 1462 1463 1464
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 5, 5);
	litest_touch_up(dev, 0);
1465 1466 1467
	libinput_dispatch(li);

	litest_timeout_tap();
1468 1469
	litest_assert_empty_queue(li);

1470 1471
	litest_touch_down(dev, 0, 5, 99);
	litest_touch_up(dev, 0);
1472 1473 1474
	libinput_dispatch(li);

	litest_timeout_tap();
1475 1476 1477 1478
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 95, 99);
	litest_touch_up(dev, 0);
1479 1480 1481
	libinput_dispatch(li);

	litest_timeout_tap();
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498
	litest_assert_empty_queue(li);
}
END_TEST

START_TEST(touchpad_palm_detect_tap_softbuttons)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	if (!touchpad_has_palm_detect_size(dev))
		return;

	litest_enable_tap(dev->libinput_device);
	litest_enable_buttonareas(dev);

	litest_drain_events(li);

1499
	litest_touch_down(dev, 0, 99, 99);
1500
	litest_touch_up(dev, 0);
1501 1502 1503
	libinput_dispatch(li);

	litest_timeout_tap();
1504 1505
	litest_assert_empty_queue(li);

1506
	litest_touch_down(dev, 0, 1, 99);
1507
	litest_touch_up(dev, 0);
1508 1509 1510
	libinput_dispatch(li);

	litest_timeout_tap();
1511 1512
	litest_assert_empty_queue(li);

1513
	litest_touch_down(dev, 0, 10, 99);
1514
	litest_touch_up(dev, 0);
1515 1516 1517
	libinput_dispatch(li);

	litest_timeout_tap();
1518 1519 1520 1521 1522 1523 1524 1525
	litest_assert_button_event(li,
				   BTN_LEFT,
				   LIBINPUT_BUTTON_STATE_PRESSED);
	litest_assert_button_event(li,
				   BTN_LEFT,
				   LIBINPUT_BUTTON_STATE_RELEASED);
	litest_assert_empty_queue(li);

1526
	litest_touch_down(dev, 0, 90, 99);
1527
	litest_touch_up(dev, 0);
1528 1529 1530
	libinput_dispatch(li);

	litest_timeout_tap();
1531 1532 1533 1534 1535 1536 1537 1538 1539 1540
	litest_assert_button_event(li,
				   BTN_LEFT,
				   LIBINPUT_BUTTON_STATE_PRESSED);
	litest_assert_button_event(li,
				   BTN_LEFT,
				   LIBINPUT_BUTTON_STATE_RELEASED);
	litest_assert_empty_queue(li);
}
END_TEST

1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
START_TEST(touchpad_palm_detect_tap_clickfinger)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	if (!touchpad_has_palm_detect_size(dev))
		return;

	litest_enable_tap(dev->libinput_device);
	litest_enable_clickfinger(dev);

	litest_drain_events(li);

	litest_touch_down(dev, 0, 95, 5);
	litest_touch_up(dev, 0);
1556 1557 1558
	libinput_dispatch(li);

	litest_timeout_tap();
1559 1560 1561 1562
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 5, 5);
	litest_touch_up(dev, 0);
1563 1564 1565
	libinput_dispatch(li);

	litest_timeout_tap();
1566 1567 1568 1569
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 5, 99);
	litest_touch_up(dev, 0);
1570 1571 1572
	libinput_dispatch(li);

	litest_timeout_tap();
1573 1574 1575 1576
	litest_assert_empty_queue(li);

	litest_touch_down(dev, 0, 95, 99);
	litest_touch_up(dev, 0);
1577 1578 1579
	libinput_dispatch(li);

	litest_timeout_tap();
1580 1581 1582 1583
	litest_assert_empty_queue(li);
}
END_TEST

1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
START_TEST(touchpad_no_palm_detect_2fg_scroll)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;

	if (!touchpad_has_palm_detect_size(dev) ||
	    !litest_has_2fg_scroll(dev))
		return;

	litest_enable_2fg_scroll(dev);

	litest_drain_events(li);

	/* first finger is palm, second finger isn't so we trigger 2fg
	 * scrolling */
	litest_touch_down(dev, 0, 99, 50);
1600 1601
	litest_touch_move_to(dev, 0, 99, 50, 99, 40, 35, 12);
	litest_touch_move_to(dev, 0, 99, 40, 99, 50, 35, 12);
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625