test-trackpoint.c 13.6 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 35 36 37 38
 */

#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"

START_TEST(trackpoint_middlebutton)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
39 40 41
	struct libinput_event *event;
	struct libinput_event_pointer *ptrev;
	uint64_t ptime, rtime;
42 43 44 45

	litest_drain_events(li);

	/* A quick middle button click should get reported normally */
46
	litest_button_click_debounced(dev, li, BTN_MIDDLE, 1);
47
	msleep(2);
48
	litest_button_click_debounced(dev, li, BTN_MIDDLE, 0);
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
	litest_wait_for_event(li);

	event = libinput_get_event(li);
	ptrev = litest_is_button_event(event,
				       BTN_MIDDLE,
				       LIBINPUT_BUTTON_STATE_PRESSED);
	ptime = libinput_event_pointer_get_time(ptrev);
	libinput_event_destroy(event);

	event = libinput_get_event(li);
	ptrev = litest_is_button_event(event,
				       BTN_MIDDLE,
				       LIBINPUT_BUTTON_STATE_RELEASED);
	rtime = libinput_event_pointer_get_time(ptrev);
	libinput_event_destroy(event);

	ck_assert_int_lt(ptime, rtime);
67 68 69 70 71 72 73 74 75 76 77 78

	litest_assert_empty_queue(li);
}
END_TEST

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

	litest_drain_events(li);

79
	litest_button_scroll(dev, BTN_MIDDLE, 1, 6);
80
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6);
81
	litest_button_scroll(dev, BTN_MIDDLE, 1, -7);
82
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7);
83
	litest_button_scroll(dev, BTN_MIDDLE, 8, 1);
84
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 8);
85
	litest_button_scroll(dev, BTN_MIDDLE, -9, 1);
86 87
	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9);

88
	/* scroll smaller than the threshold should not generate axis events */
89
	litest_button_scroll(dev, BTN_MIDDLE, 1, 1);
90

91
	litest_button_scroll(dev, BTN_MIDDLE, 0, 0);
92 93 94 95 96
	litest_assert_button_event(li, BTN_MIDDLE,
				   LIBINPUT_BUTTON_STATE_PRESSED);
	litest_assert_button_event(li,
				   BTN_MIDDLE,
				   LIBINPUT_BUTTON_STATE_RELEASED);
97 98 99 100 101

	litest_assert_empty_queue(li);
}
END_TEST

102 103 104 105 106 107 108
START_TEST(trackpoint_middlebutton_noscroll)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	struct libinput_event *event;

	/* Disable middle button scrolling */
109
	libinput_device_config_scroll_set_method(dev->libinput_device,
110 111 112 113 114
					LIBINPUT_CONFIG_SCROLL_NO_SCROLL);

	litest_drain_events(li);

	/* A long middle button click + motion should get reported normally now */
115
	litest_button_scroll(dev, BTN_MIDDLE, 0, 10);
116 117 118 119 120 121 122 123 124 125 126 127 128

	litest_assert_button_event(li, BTN_MIDDLE, 1);

	event = libinput_get_event(li);
	ck_assert(event != NULL);
	ck_assert_int_eq(libinput_event_get_type(event), LIBINPUT_EVENT_POINTER_MOTION);
	libinput_event_destroy(event);

	litest_assert_button_event(li, BTN_MIDDLE, 0);

	litest_assert_empty_queue(li);

	/* Restore default scroll behavior */
129 130
	libinput_device_config_scroll_set_method(dev->libinput_device,
		libinput_device_config_scroll_get_default_method(
131 132 133 134
			dev->libinput_device));
}
END_TEST

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
START_TEST(trackpoint_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);

	litest_button_scroll(dev, BTN_MIDDLE, 0, 6);
	litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);

	while ((event = libinput_get_event(li))) {
		ptrev = libinput_event_get_pointer_event(event);

		ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev),
				 LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS);

		libinput_event_destroy(event);
	}
}
END_TEST

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
START_TEST(trackpoint_topsoftbuttons_left_handed_trackpoint)
{
	struct litest_device *touchpad = litest_current_device();
	struct litest_device *trackpoint;
	struct libinput *li = touchpad->libinput;
	enum libinput_config_status status;
	struct libinput_event *event;
	struct libinput_device *device;

	trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
	litest_drain_events(li);
	/* touchpad right-handed, trackpoint left-handed */
	status = libinput_device_config_left_handed_set(
					trackpoint->libinput_device, 1);
	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);

	litest_touch_down(touchpad, 0, 5, 5);
	libinput_dispatch(li);
176
	litest_button_click_debounced(touchpad, li, BTN_LEFT, true);
177 178 179 180 181 182 183 184 185 186
	libinput_dispatch(li);

	event = libinput_get_event(li);
	litest_is_button_event(event,
			       BTN_RIGHT,
			       LIBINPUT_BUTTON_STATE_PRESSED);
	device = libinput_event_get_device(event);
	ck_assert(device == trackpoint->libinput_device);
	libinput_event_destroy(event);

187
	litest_button_click_debounced(touchpad, li, BTN_LEFT, false);
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
	libinput_dispatch(li);
	event = libinput_get_event(li);
	litest_is_button_event(event,
			       BTN_RIGHT,
			       LIBINPUT_BUTTON_STATE_RELEASED);
	device = libinput_event_get_device(event);
	ck_assert(device == trackpoint->libinput_device);
	libinput_event_destroy(event);

	litest_delete_device(trackpoint);
}
END_TEST

START_TEST(trackpoint_topsoftbuttons_left_handed_touchpad)
{
	struct litest_device *touchpad = litest_current_device();
	struct litest_device *trackpoint;
	struct libinput *li = touchpad->libinput;
	enum libinput_config_status status;
	struct libinput_event *event;
	struct libinput_device *device;

	trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
	litest_drain_events(li);
	/* touchpad left-handed, trackpoint right-handed */
	status = libinput_device_config_left_handed_set(
					touchpad->libinput_device, 1);
	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);

	litest_touch_down(touchpad, 0, 5, 5);
	libinput_dispatch(li);
219
	litest_button_click_debounced(touchpad, li, BTN_LEFT, true);
220 221 222 223 224 225 226 227
	libinput_dispatch(li);

	event = libinput_get_event(li);
	litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
	device = libinput_event_get_device(event);
	ck_assert(device == trackpoint->libinput_device);
	libinput_event_destroy(event);

228
	litest_button_click_debounced(touchpad, li, BTN_LEFT, false);
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
	libinput_dispatch(li);
	event = libinput_get_event(li);
	litest_is_button_event(event,
			       BTN_LEFT,
			       LIBINPUT_BUTTON_STATE_RELEASED);
	device = libinput_event_get_device(event);
	ck_assert(device == trackpoint->libinput_device);
	libinput_event_destroy(event);

	litest_delete_device(trackpoint);
}
END_TEST

START_TEST(trackpoint_topsoftbuttons_left_handed_both)
{
	struct litest_device *touchpad = litest_current_device();
	struct litest_device *trackpoint;
	struct libinput *li = touchpad->libinput;
	enum libinput_config_status status;
	struct libinput_event *event;
	struct libinput_device *device;

	trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
	litest_drain_events(li);
	/* touchpad left-handed, trackpoint left-handed */
	status = libinput_device_config_left_handed_set(
					touchpad->libinput_device, 1);
	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
	status = libinput_device_config_left_handed_set(
					trackpoint->libinput_device, 1);
	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);

	litest_touch_down(touchpad, 0, 5, 5);
	libinput_dispatch(li);
263
	litest_button_click_debounced(touchpad, li, BTN_LEFT, true);
264 265 266 267 268 269 270 271 272 273
	libinput_dispatch(li);

	event = libinput_get_event(li);
	litest_is_button_event(event,
			       BTN_RIGHT,
			       LIBINPUT_BUTTON_STATE_PRESSED);
	device = libinput_event_get_device(event);
	ck_assert(device == trackpoint->libinput_device);
	libinput_event_destroy(event);

274
	litest_button_click_debounced(touchpad, li, BTN_LEFT, false);
275 276 277 278 279 280 281 282 283 284 285 286
	libinput_dispatch(li);
	event = libinput_get_event(li);
	litest_is_button_event(event,
			       BTN_RIGHT,
			       LIBINPUT_BUTTON_STATE_RELEASED);
	device = libinput_event_get_device(event);
	ck_assert(device == trackpoint->libinput_device);
	libinput_event_destroy(event);

	litest_delete_device(trackpoint);
}
END_TEST
287

288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
START_TEST(trackpoint_palmdetect)
{
	struct litest_device *trackpoint = litest_current_device();
	struct litest_device *touchpad;
	struct libinput *li = trackpoint->libinput;
	int i;

	touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
	litest_drain_events(li);

	for (i = 0; i < 10; i++) {
		litest_event(trackpoint, EV_REL, REL_X, 1);
		litest_event(trackpoint, EV_REL, REL_Y, 1);
		litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
		libinput_dispatch(li);
	}
	litest_drain_events(li);

	litest_touch_down(touchpad, 0, 30, 30);
307
	litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
308 309 310 311 312 313 314
	litest_touch_up(touchpad, 0);
	litest_assert_empty_queue(li);

	litest_timeout_trackpoint();
	libinput_dispatch(li);

	litest_touch_down(touchpad, 0, 30, 30);
315
	litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
	litest_touch_up(touchpad, 0);
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	litest_delete_device(touchpad);
}
END_TEST

START_TEST(trackpoint_palmdetect_resume_touch)
{
	struct litest_device *trackpoint = litest_current_device();
	struct litest_device *touchpad;
	struct libinput *li = trackpoint->libinput;
	int i;

	touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
	litest_drain_events(li);

	for (i = 0; i < 10; i++) {
		litest_event(trackpoint, EV_REL, REL_X, 1);
		litest_event(trackpoint, EV_REL, REL_Y, 1);
		litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
		libinput_dispatch(li);
	}
	litest_drain_events(li);

	litest_touch_down(touchpad, 0, 30, 30);
342
	litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
343 344 345 346 347 348
	litest_assert_empty_queue(li);

	litest_timeout_trackpoint();
	libinput_dispatch(li);

	/* touch started after last tp event, expect resume */
349
	litest_touch_move_to(touchpad, 0, 80, 80, 30, 30, 10);
350 351 352 353 354 355 356
	litest_touch_up(touchpad, 0);
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	litest_delete_device(touchpad);
}
END_TEST

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
START_TEST(trackpoint_palmdetect_require_min_events)
{
	struct litest_device *trackpoint = litest_current_device();
	struct litest_device *touchpad;
	struct libinput *li = trackpoint->libinput;

	touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
	litest_drain_events(li);

	/* A single event does not trigger palm detection */
	litest_event(trackpoint, EV_REL, REL_X, 1);
	litest_event(trackpoint, EV_REL, REL_Y, 1);
	litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
	libinput_dispatch(li);
	litest_drain_events(li);

	litest_touch_down(touchpad, 0, 30, 30);
374
	litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
375 376 377 378 379 380 381
	litest_touch_up(touchpad, 0);
	litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

	litest_delete_device(touchpad);
}
END_TEST

382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
START_TEST(trackpoint_palmdetect_require_min_events_timeout)
{
	struct litest_device *trackpoint = litest_current_device();
	struct litest_device *touchpad;
	struct libinput *li = trackpoint->libinput;

	touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
	litest_drain_events(li);

	for (int i = 0; i < 10; i++) {
		/* A single event does not trigger palm detection */
		litest_event(trackpoint, EV_REL, REL_X, 1);
		litest_event(trackpoint, EV_REL, REL_Y, 1);
		litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
		libinput_dispatch(li);
		litest_drain_events(li);

		litest_touch_down(touchpad, 0, 30, 30);
400
		litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
401 402 403 404 405 406 407 408 409 410
		litest_touch_up(touchpad, 0);
		litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);

		litest_timeout_trackpoint();
	}

	litest_delete_device(touchpad);
}
END_TEST

411
TEST_COLLECTION(trackpoint)
412
{
413
	litest_add("trackpoint:middlebutton", trackpoint_middlebutton, LITEST_POINTINGSTICK, LITEST_ANY);
414
	litest_add("trackpoint:middlebutton", trackpoint_middlebutton_noscroll, LITEST_POINTINGSTICK, LITEST_ANY);
415
	litest_add("trackpoint:scroll", trackpoint_scroll, LITEST_POINTINGSTICK, LITEST_ANY);
416
	litest_add("trackpoint:scroll", trackpoint_scroll_source, LITEST_POINTINGSTICK, LITEST_ANY);
417 418 419
	litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_trackpoint, LITEST_TOPBUTTONPAD, LITEST_ANY);
	litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_touchpad, LITEST_TOPBUTTONPAD, LITEST_ANY);
	litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_both, LITEST_TOPBUTTONPAD, LITEST_ANY);
420 421 422

	litest_add("trackpoint:palmdetect", trackpoint_palmdetect, LITEST_POINTINGSTICK, LITEST_ANY);
	litest_add("trackpoint:palmdetect", trackpoint_palmdetect_resume_touch, LITEST_POINTINGSTICK, LITEST_ANY);
423
	litest_add("trackpoint:palmdetect", trackpoint_palmdetect_require_min_events, LITEST_POINTINGSTICK, LITEST_ANY);
424
	litest_add("trackpoint:palmdetect", trackpoint_palmdetect_require_min_events_timeout, LITEST_POINTINGSTICK, LITEST_ANY);
425
}