• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2014 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 <assert.h>
27 #include <errno.h>
28 #include <fcntl.h>
29 #include <fnmatch.h>
30 #include <getopt.h>
31 #include <limits.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <sys/stat.h>
36 #include <libudev.h>
37 #include <unistd.h>
38 
39 #include <libevdev/libevdev.h>
40 
41 #include "builddir.h"
42 #include "shared.h"
43 #include "util-macros.h"
44 #include "util-strings.h"
45 
46 static uint32_t dispatch_counter = 0;
47 
48 void
tools_dispatch(struct libinput * libinput)49 tools_dispatch(struct libinput *libinput)
50 {
51 	dispatch_counter++;
52 	libinput_dispatch(libinput);
53 }
54 
55 LIBINPUT_ATTRIBUTE_PRINTF(3, 0)
56 static void
log_handler(struct libinput * li,enum libinput_log_priority priority,const char * format,va_list args)57 log_handler(struct libinput *li,
58 	    enum libinput_log_priority priority,
59 	    const char *format,
60 	    va_list args)
61 {
62 	static int is_tty = -1;
63 	static uint32_t last_dispatch_no = 0;
64 	static bool color_toggle = false;
65 
66 	if (is_tty == -1)
67 		is_tty = isatty(STDOUT_FILENO);
68 
69 	if (is_tty) {
70 		if (priority >= LIBINPUT_LOG_PRIORITY_ERROR) {
71 			printf(ANSI_RED);
72 		} else if (priority >= LIBINPUT_LOG_PRIORITY_INFO) {
73 			printf(ANSI_HIGHLIGHT);
74 		} else if (priority == LIBINPUT_LOG_PRIORITY_DEBUG) {
75 			if (dispatch_counter != last_dispatch_no)
76 				color_toggle = !color_toggle;
77 			uint8_t r = 0,
78 				g = 135,
79 				b = 95 + (color_toggle ? 80 :0);
80 			printf("\x1B[38;2;%u;%u;%um", r, g, b);
81 		}
82 	}
83 
84 	if (priority < LIBINPUT_LOG_PRIORITY_INFO) {
85 		if (dispatch_counter != last_dispatch_no) {
86 			last_dispatch_no = dispatch_counter;
87 			printf("%4u: ", dispatch_counter);
88 		} else {
89 			printf(" %4s ", "...");
90 		}
91 	}
92 	vprintf(format, args);
93 
94 	if (is_tty)
95 		printf(ANSI_NORMAL);
96 }
97 
98 void
tools_init_options(struct tools_options * options)99 tools_init_options(struct tools_options *options)
100 {
101 	memset(options, 0, sizeof(*options));
102 	options->tapping = -1;
103 	options->tap_map = -1;
104 	options->drag = -1;
105 	options->drag_lock = -1;
106 	options->natural_scroll = -1;
107 	options->left_handed = -1;
108 	options->middlebutton = -1;
109 	options->dwt = -1;
110 	options->click_method = -1;
111 	options->scroll_method = -1;
112 	options->scroll_button = -1;
113 	options->scroll_button_lock = -1;
114 	options->speed = 0.0;
115 	options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
116 }
117 
118 int
tools_parse_option(int option,const char * optarg,struct tools_options * options)119 tools_parse_option(int option,
120 		   const char *optarg,
121 		   struct tools_options *options)
122 {
123 	switch(option) {
124 	case OPT_TAP_ENABLE:
125 		options->tapping = 1;
126 		break;
127 	case OPT_TAP_DISABLE:
128 		options->tapping = 0;
129 		break;
130 	case OPT_TAP_MAP:
131 		if (!optarg)
132 			return 1;
133 
134 		if (streq(optarg, "lrm")) {
135 			options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
136 		} else if (streq(optarg, "lmr")) {
137 			options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LMR;
138 		} else {
139 			return 1;
140 		}
141 		break;
142 	case OPT_DRAG_ENABLE:
143 		options->drag = 1;
144 		break;
145 	case OPT_DRAG_DISABLE:
146 		options->drag = 0;
147 		break;
148 	case OPT_DRAG_LOCK_ENABLE:
149 		options->drag_lock = 1;
150 		break;
151 	case OPT_DRAG_LOCK_DISABLE:
152 		options->drag_lock = 0;
153 		break;
154 	case OPT_NATURAL_SCROLL_ENABLE:
155 		options->natural_scroll = 1;
156 		break;
157 	case OPT_NATURAL_SCROLL_DISABLE:
158 		options->natural_scroll = 0;
159 		break;
160 	case OPT_LEFT_HANDED_ENABLE:
161 		options->left_handed = 1;
162 		break;
163 	case OPT_LEFT_HANDED_DISABLE:
164 		options->left_handed = 0;
165 		break;
166 	case OPT_MIDDLEBUTTON_ENABLE:
167 		options->middlebutton = 1;
168 		break;
169 	case OPT_MIDDLEBUTTON_DISABLE:
170 		options->middlebutton = 0;
171 		break;
172 	case OPT_DWT_ENABLE:
173 		options->dwt = LIBINPUT_CONFIG_DWT_ENABLED;
174 		break;
175 	case OPT_DWT_DISABLE:
176 		options->dwt = LIBINPUT_CONFIG_DWT_DISABLED;
177 		break;
178 	case OPT_CLICK_METHOD:
179 		if (!optarg)
180 			return 1;
181 
182 		if (streq(optarg, "none")) {
183 			options->click_method =
184 			LIBINPUT_CONFIG_CLICK_METHOD_NONE;
185 		} else if (streq(optarg, "clickfinger")) {
186 			options->click_method =
187 			LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
188 		} else if (streq(optarg, "buttonareas")) {
189 			options->click_method =
190 			LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
191 		} else {
192 			return 1;
193 		}
194 		break;
195 	case OPT_SCROLL_METHOD:
196 		if (!optarg)
197 			return 1;
198 
199 		if (streq(optarg, "none")) {
200 			options->scroll_method =
201 			LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
202 		} else if (streq(optarg, "twofinger")) {
203 			options->scroll_method =
204 			LIBINPUT_CONFIG_SCROLL_2FG;
205 		} else if (streq(optarg, "edge")) {
206 			options->scroll_method =
207 			LIBINPUT_CONFIG_SCROLL_EDGE;
208 		} else if (streq(optarg, "button")) {
209 			options->scroll_method =
210 			LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
211 		} else {
212 			return 1;
213 		}
214 		break;
215 	case OPT_SCROLL_BUTTON:
216 		if (!optarg) {
217 			return 1;
218 		}
219 		options->scroll_button =
220 		libevdev_event_code_from_name(EV_KEY,
221 					      optarg);
222 		if (options->scroll_button == -1) {
223 			fprintf(stderr,
224 				"Invalid button %s\n",
225 				optarg);
226 			return 1;
227 		}
228 		break;
229 	case OPT_SCROLL_BUTTON_LOCK_ENABLE:
230 		options->scroll_button_lock = true;
231 		break;
232 	case OPT_SCROLL_BUTTON_LOCK_DISABLE:
233 		options->scroll_button_lock = false;
234 		break;
235 	case OPT_SPEED:
236 		if (!optarg)
237 			return 1;
238 		options->speed = atof(optarg);
239 		break;
240 	case OPT_PROFILE:
241 		if (!optarg)
242 			return 1;
243 
244 		if (streq(optarg, "adaptive"))
245 			options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
246 		else if (streq(optarg, "flat"))
247 		      options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
248 		else
249 		      return 1;
250 		break;
251 	case OPT_DISABLE_SENDEVENTS:
252 		if (!optarg)
253 			return 1;
254 
255 		snprintf(options->disable_pattern,
256 			 sizeof(options->disable_pattern),
257 			 "%s",
258 			 optarg);
259 		break;
260 	case OPT_APPLY_TO:
261 		if (!optarg)
262 			return 1;
263 
264 		snprintf(options->match,
265 			 sizeof(options->match),
266 			 "%s",
267 			 optarg);
268 		break;
269 	}
270 
271 	return 0;
272 }
273 
274 static int
open_restricted(const char * path,int flags,void * user_data)275 open_restricted(const char *path, int flags, void *user_data)
276 {
277 	bool *grab = user_data;
278 	int fd = open(path, flags);
279 
280 	if (fd < 0)
281 		fprintf(stderr, "Failed to open %s (%s)\n",
282 			path, strerror(errno));
283 	else if (grab && *grab && ioctl(fd, EVIOCGRAB, (void*)1) == -1)
284 		fprintf(stderr, "Grab requested, but failed for %s (%s)\n",
285 			path, strerror(errno));
286 
287 	return fd < 0 ? -errno : fd;
288 }
289 
290 static void
close_restricted(int fd,void * user_data)291 close_restricted(int fd, void *user_data)
292 {
293 	close(fd);
294 }
295 
296 static const struct libinput_interface interface = {
297 	.open_restricted = open_restricted,
298 	.close_restricted = close_restricted,
299 };
300 
301 static struct libinput *
tools_open_udev(const char * seat,bool verbose,bool * grab)302 tools_open_udev(const char *seat, bool verbose, bool *grab)
303 {
304 	struct libinput *li;
305 	struct udev *udev = udev_new();
306 
307 	if (!udev) {
308 		fprintf(stderr, "Failed to initialize udev\n");
309 		return NULL;
310 	}
311 
312 	li = libinput_udev_create_context(&interface, grab, udev);
313 	if (!li) {
314 		fprintf(stderr, "Failed to initialize context from udev\n");
315 		goto out;
316 	}
317 
318 	libinput_log_set_handler(li, log_handler);
319 	if (verbose)
320 		libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
321 
322 	if (libinput_udev_assign_seat(li, seat)) {
323 		fprintf(stderr, "Failed to set seat\n");
324 		libinput_unref(li);
325 		li = NULL;
326 		goto out;
327 	}
328 
329 out:
330 	udev_unref(udev);
331 	return li;
332 }
333 
334 static struct libinput *
tools_open_device(const char ** paths,bool verbose,bool * grab)335 tools_open_device(const char **paths, bool verbose, bool *grab)
336 {
337 	struct libinput_device *device;
338 	struct libinput *li;
339 	const char **p = paths;
340 
341 	li = libinput_path_create_context(&interface, grab);
342 	if (!li) {
343 		fprintf(stderr, "Failed to initialize path context\n");
344 		return NULL;
345 	}
346 
347 	if (verbose) {
348 		libinput_log_set_handler(li, log_handler);
349 		libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
350 	}
351 
352 	while (*p) {
353 		device = libinput_path_add_device(li, *p);
354 		if (!device) {
355 			fprintf(stderr, "Failed to initialize device %s\n", *p);
356 			libinput_unref(li);
357 			li = NULL;
358 			break;
359 		}
360 		p++;
361 	}
362 
363 	return li;
364 }
365 
366 static void
tools_setenv_quirks_dir(void)367 tools_setenv_quirks_dir(void)
368 {
369 	char *builddir = builddir_lookup();
370 	if (builddir) {
371 		setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0);
372 		free(builddir);
373 	}
374 }
375 
376 struct libinput *
tools_open_backend(enum tools_backend which,const char ** seat_or_device,bool verbose,bool * grab)377 tools_open_backend(enum tools_backend which,
378 		   const char **seat_or_device,
379 		   bool verbose,
380 		   bool *grab)
381 {
382 	struct libinput *li;
383 
384 	tools_setenv_quirks_dir();
385 
386 	switch (which) {
387 	case BACKEND_UDEV:
388 		li = tools_open_udev(seat_or_device[0], verbose, grab);
389 		break;
390 	case BACKEND_DEVICE:
391 		li = tools_open_device(seat_or_device, verbose, grab);
392 		break;
393 	default:
394 		abort();
395 	}
396 
397 	return li;
398 }
399 
400 void
tools_device_apply_config(struct libinput_device * device,struct tools_options * options)401 tools_device_apply_config(struct libinput_device *device,
402 			  struct tools_options *options)
403 {
404 	const char *name = libinput_device_get_name(device);
405 
406 	if (libinput_device_config_send_events_get_modes(device) &
407 	      LIBINPUT_CONFIG_SEND_EVENTS_DISABLED &&
408 	    fnmatch(options->disable_pattern, name, 0) != FNM_NOMATCH) {
409 		libinput_device_config_send_events_set_mode(device,
410 					    LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
411 	}
412 
413 	if (strlen(options->match) > 0 &&
414 	    fnmatch(options->match, name, 0) == FNM_NOMATCH)
415 		return;
416 
417 	if (options->tapping != -1)
418 		libinput_device_config_tap_set_enabled(device, options->tapping);
419 	if (options->tap_map != (enum libinput_config_tap_button_map)-1)
420 		libinput_device_config_tap_set_button_map(device,
421 							  options->tap_map);
422 	if (options->drag != -1)
423 		libinput_device_config_tap_set_drag_enabled(device,
424 							    options->drag);
425 	if (options->drag_lock != -1)
426 		libinput_device_config_tap_set_drag_lock_enabled(device,
427 								 options->drag_lock);
428 	if (options->natural_scroll != -1)
429 		libinput_device_config_scroll_set_natural_scroll_enabled(device,
430 									 options->natural_scroll);
431 	if (options->left_handed != -1)
432 		libinput_device_config_left_handed_set(device, options->left_handed);
433 	if (options->middlebutton != -1)
434 		libinput_device_config_middle_emulation_set_enabled(device,
435 								    options->middlebutton);
436 
437 	if (options->dwt != -1)
438 		libinput_device_config_dwt_set_enabled(device, options->dwt);
439 
440 	if (options->click_method != (enum libinput_config_click_method)-1)
441 		libinput_device_config_click_set_method(device, options->click_method);
442 
443 	if (options->scroll_method != (enum libinput_config_scroll_method)-1)
444 		libinput_device_config_scroll_set_method(device,
445 							 options->scroll_method);
446 	if (options->scroll_button != -1)
447 		libinput_device_config_scroll_set_button(device,
448 							 options->scroll_button);
449 	if (options->scroll_button_lock != -1)
450 		libinput_device_config_scroll_set_button_lock(device,
451 							      options->scroll_button_lock);
452 
453 
454 	if (libinput_device_config_accel_is_available(device)) {
455 		libinput_device_config_accel_set_speed(device,
456 						       options->speed);
457 		if (options->profile != LIBINPUT_CONFIG_ACCEL_PROFILE_NONE)
458 			libinput_device_config_accel_set_profile(device,
459 								 options->profile);
460 	}
461 }
462 
463 static char*
find_device(const char * udev_tag)464 find_device(const char *udev_tag)
465 {
466 	struct udev *udev;
467 	struct udev_enumerate *e = NULL;
468 	struct udev_list_entry *entry = NULL;
469 	struct udev_device *device;
470 	const char *path, *sysname;
471 	char *device_node = NULL;
472 
473 	udev = udev_new();
474 	if (!udev)
475 		goto out;
476 
477 	e = udev_enumerate_new(udev);
478 	udev_enumerate_add_match_subsystem(e, "input");
479 	udev_enumerate_scan_devices(e);
480 
481 	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
482 		path = udev_list_entry_get_name(entry);
483 		device = udev_device_new_from_syspath(udev, path);
484 		if (!device)
485 			continue;
486 
487 		sysname = udev_device_get_sysname(device);
488 		if (!strneq("event", sysname, 5)) {
489 			udev_device_unref(device);
490 			continue;
491 		}
492 
493 		if (udev_device_get_property_value(device, udev_tag))
494 			device_node = safe_strdup(udev_device_get_devnode(device));
495 
496 		udev_device_unref(device);
497 
498 		if (device_node)
499 			break;
500 	}
501 out:
502 	udev_enumerate_unref(e);
503 	udev_unref(udev);
504 
505 	return device_node;
506 }
507 
508 bool
find_touchpad_device(char * path,size_t path_len)509 find_touchpad_device(char *path, size_t path_len)
510 {
511 	char *devnode = find_device("ID_INPUT_TOUCHPAD");
512 
513 	if (devnode) {
514 		snprintf(path, path_len, "%s", devnode);
515 		free(devnode);
516 	}
517 
518 	return devnode != NULL;
519 }
520 
521 bool
is_touchpad_device(const char * devnode)522 is_touchpad_device(const char *devnode)
523 {
524 	struct udev *udev;
525 	struct udev_device *dev = NULL;
526 	struct stat st;
527 	bool is_touchpad = false;
528 
529 	if (stat(devnode, &st) < 0)
530 		return false;
531 
532 	udev = udev_new();
533 	if (!udev)
534 		goto out;
535 
536 	dev = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
537 	if (!dev)
538 		goto out;
539 
540 	is_touchpad = udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
541 out:
542 	if (dev)
543 		udev_device_unref(dev);
544 	udev_unref(udev);
545 
546 	return is_touchpad;
547 }
548 
549 static inline void
setup_path(void)550 setup_path(void)
551 {
552 	const char *path = getenv("PATH");
553 	char new_path[PATH_MAX];
554 	const char *extra_path = LIBINPUT_TOOL_PATH;
555 	char *builddir = builddir_lookup();
556 
557 	snprintf(new_path,
558 		 sizeof(new_path),
559 		 "%s:%s",
560 		 builddir ? builddir : extra_path,
561 		 path ? path : "");
562 	setenv("PATH", new_path, 1);
563 	free(builddir);
564 }
565 
566 int
tools_exec_command(const char * prefix,int real_argc,char ** real_argv)567 tools_exec_command(const char *prefix, int real_argc, char **real_argv)
568 {
569 	char *argv[64] = {NULL};
570 	char executable[128];
571 	const char *command;
572 	int rc;
573 
574 	assert((size_t)real_argc < ARRAY_LENGTH(argv));
575 
576 	command = real_argv[0];
577 
578 	rc = snprintf(executable,
579 		      sizeof(executable),
580 		      "%s-%s",
581 		      prefix,
582 		      command);
583 	if (rc >= (int)sizeof(executable)) {
584 		fprintf(stderr, "Failed to assemble command.\n");
585 		return EXIT_FAILURE;
586 	}
587 
588 	argv[0] = executable;
589 	for (int i = 1; i < real_argc; i++)
590 		argv[i] = real_argv[i];
591 
592 	setup_path();
593 
594 	rc = execvp(executable, argv);
595 	if (rc) {
596 		if (errno == ENOENT) {
597 			fprintf(stderr,
598 				"libinput: %s is not installed\n",
599 				command);
600 			return EXIT_INVALID_USAGE;
601 		}
602 		fprintf(stderr,
603 			"Failed to execute '%s' (%s)\n",
604 			command,
605 			strerror(errno));
606 	}
607 
608 	return EXIT_FAILURE;
609 }
610 
611 static void
sprintf_event_codes(char * buf,size_t sz,struct quirks * quirks,enum quirk q)612 sprintf_event_codes(char *buf, size_t sz, struct quirks *quirks, enum quirk q)
613 {
614 	const struct quirk_tuples *t;
615 	size_t off = 0;
616 	int printed;
617 	const char *name;
618 
619 	quirks_get_tuples(quirks, q, &t);
620 	name = quirk_get_name(q);
621 	printed = snprintf(buf, sz, "%s=", name);
622 	assert(printed != -1);
623 	off += printed;
624 
625 	for (size_t i = 0; off < sz && i < t->ntuples; i++) {
626 		const char *name = libevdev_event_code_get_name(
627 						t->tuples[i].first,
628 						t->tuples[i].second);
629 
630 		printed = snprintf(buf + off, sz - off, "%s;", name);
631 		assert(printed != -1);
632 		off += printed;
633 	}
634 }
635 
636 static void
sprintf_input_props(char * buf,size_t sz,struct quirks * quirks,enum quirk q)637 sprintf_input_props(char *buf, size_t sz, struct quirks *quirks, enum quirk q)
638 {
639 	const uint32_t *properties;
640 	size_t nprops = 0;
641 	size_t off = 0;
642 	int printed;
643 	const char *name;
644 
645 	quirks_get_uint32_array(quirks, q, &properties, &nprops);
646 	name = quirk_get_name(q);
647 	printed = snprintf(buf, sz, "%s=", name);
648 	assert(printed != -1);
649 	off += printed;
650 
651 	for (size_t i = 0; off < sz && i < nprops; i++) {
652 		const char *name = libevdev_property_get_name(properties[i]);
653 		printed = snprintf(buf + off, sz - off, "%s;", name);
654 		assert(printed != -1);
655 		off += printed;
656 	}
657 }
658 
659 void
tools_list_device_quirks(struct quirks_context * ctx,struct udev_device * device,void (* callback)(void * data,const char * str),void * userdata)660 tools_list_device_quirks(struct quirks_context *ctx,
661 			 struct udev_device *device,
662 			 void (*callback)(void *data, const char *str),
663 			 void *userdata)
664 {
665 	char buf[256];
666 
667 	struct quirks *quirks;
668 	enum quirk q;
669 
670 	quirks = quirks_fetch_for_device(ctx, device);
671 	if (!quirks)
672 		return;
673 
674 	q = QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD;
675 	do {
676 		if (quirks_has_quirk(quirks, q)) {
677 			const char *name;
678 			bool b;
679 
680 			name = quirk_get_name(q);
681 			quirks_get_bool(quirks, q, &b);
682 			snprintf(buf, sizeof(buf), "%s=%d", name, b ? 1 : 0);
683 			callback(userdata, buf);
684 		}
685 	} while(++q < _QUIRK_LAST_MODEL_QUIRK_);
686 
687 	q = QUIRK_ATTR_SIZE_HINT;
688 	do {
689 		if (quirks_has_quirk(quirks, q)) {
690 			const char *name;
691 			struct quirk_dimensions dim;
692 			struct quirk_range r;
693 			uint32_t v;
694 			char *s;
695 			double d;
696 
697 			name = quirk_get_name(q);
698 
699 			switch (q) {
700 			case QUIRK_ATTR_SIZE_HINT:
701 			case QUIRK_ATTR_RESOLUTION_HINT:
702 				quirks_get_dimensions(quirks, q, &dim);
703 				snprintf(buf, sizeof(buf), "%s=%zdx%zd", name, dim.x, dim.y);
704 				callback(userdata, buf);
705 				break;
706 			case QUIRK_ATTR_TOUCH_SIZE_RANGE:
707 			case QUIRK_ATTR_PRESSURE_RANGE:
708 				quirks_get_range(quirks, q, &r);
709 				snprintf(buf, sizeof(buf), "%s=%d:%d", name, r.upper, r.lower);
710 				callback(userdata, buf);
711 				break;
712 			case QUIRK_ATTR_PALM_SIZE_THRESHOLD:
713 			case QUIRK_ATTR_PALM_PRESSURE_THRESHOLD:
714 			case QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD:
715 			case QUIRK_ATTR_THUMB_SIZE_THRESHOLD:
716 				quirks_get_uint32(quirks, q, &v);
717 				snprintf(buf, sizeof(buf), "%s=%u", name, v);
718 				callback(userdata, buf);
719 				break;
720 			case QUIRK_ATTR_LID_SWITCH_RELIABILITY:
721 			case QUIRK_ATTR_KEYBOARD_INTEGRATION:
722 			case QUIRK_ATTR_TRACKPOINT_INTEGRATION:
723 			case QUIRK_ATTR_TPKBCOMBO_LAYOUT:
724 			case QUIRK_ATTR_MSC_TIMESTAMP:
725 				quirks_get_string(quirks, q, &s);
726 				snprintf(buf, sizeof(buf), "%s=%s", name, s);
727 				callback(userdata, buf);
728 				break;
729 			case QUIRK_ATTR_TRACKPOINT_MULTIPLIER:
730 				quirks_get_double(quirks, q, &d);
731 				snprintf(buf, sizeof(buf), "%s=%0.2f", name, d);
732 				callback(userdata, buf);
733 				break;
734 			case QUIRK_ATTR_USE_VELOCITY_AVERAGING:
735 			case QUIRK_ATTR_TABLET_SMOOTHING:
736 				snprintf(buf, sizeof(buf), "%s=1", name);
737 				callback(userdata, buf);
738 				break;
739 			case QUIRK_ATTR_EVENT_CODE_DISABLE:
740 			case QUIRK_ATTR_EVENT_CODE_ENABLE:
741 				sprintf_event_codes(buf, sizeof(buf), quirks, q);
742 				callback(userdata, buf);
743 				break;
744 			case QUIRK_ATTR_INPUT_PROP_DISABLE:
745 			case QUIRK_ATTR_INPUT_PROP_ENABLE:
746 				sprintf_input_props(buf, sizeof(buf), quirks, q);
747 				callback(userdata, buf);
748 				break;
749 			default:
750 				abort();
751 				break;
752 			}
753 		}
754 	} while(++q < _QUIRK_LAST_ATTR_QUIRK_);
755 
756 	quirks_unref(quirks);
757 }
758