| 1 |
/* |
| 2 |
* Copyright © 2015 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 <fcntl.h> |
| 27 |
#include <libevdev/libevdev.h> |
| 28 |
#include <libudev.h> |
| 29 |
#include <linux/input.h> |
| 30 |
#include <stdint.h> |
| 31 |
#include <stdio.h> |
| 32 |
#include <unistd.h> |
| 33 |
|
| 34 |
#include "util-macros.h" |
| 35 |
#include "util-prop-parsers.h" |
| 36 |
|
| 37 |
/** |
| 38 |
* For a non-zero fuzz on the x/y axes, print that fuzz as property and |
| 39 |
* reset the kernel's fuzz to 0. |
| 40 |
* https://bugs.freedesktop.org/show_bug.cgi?id=105202 |
| 41 |
*/ |
| 42 |
static void |
| 43 |
handle_absfuzz(struct udev_device *device) |
| 44 |
{ |
| 45 |
const char *devnode; |
| 46 |
struct libevdev *evdev = NULL; |
| 47 |
int fd = -1; |
| 48 |
int rc; |
| 49 |
unsigned int axes[] = { |
| 50 |
ABS_X, |
| 51 |
ABS_Y, |
| 52 |
ABS_MT_POSITION_X, |
| 53 |
ABS_MT_POSITION_Y, |
| 54 |
}; |
| 55 |
|
| 56 |
devnode = udev_device_get_devnode(device); |
| 57 |
if (!devnode) |
| 58 |
goto out; |
| 59 |
|
| 60 |
fd = open(devnode, O_RDONLY); |
| 61 |
if (fd < 0) |
| 62 |
goto out; |
| 63 |
|
| 64 |
rc = libevdev_new_from_fd(fd, &evdev); |
| 65 |
if (rc != 0) |
| 66 |
goto out; |
| 67 |
|
| 68 |
if (!libevdev_has_event_type(evdev, EV_ABS)) |
| 69 |
goto out; |
| 70 |
|
| 71 |
ARRAY_FOR_EACH(axes, code) { |
| 72 |
int fuzz; |
| 73 |
|
| 74 |
fuzz = libevdev_get_abs_fuzz(evdev, *code); |
| 75 |
if (fuzz) |
| 76 |
printf("LIBINPUT_FUZZ_%02x=%d\n", *code, fuzz); |
| 77 |
} |
| 78 |
|
| 79 |
out: |
| 80 |
close(fd); |
| 81 |
libevdev_free(evdev); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Where a device has EVDEV_ABS_... set with a fuzz, that fuzz hasn't been |
| 86 |
* applied to the kernel yet. So we need to extract it ourselves **and** |
| 87 |
* update the property so the kernel won't actually set it later. |
| 88 |
*/ |
| 89 |
static void |
| 90 |
handle_evdev_abs(struct udev_device *device) |
| 91 |
{ |
| 92 |
unsigned int axes[] = { |
| 93 |
ABS_X, |
| 94 |
ABS_Y, |
| 95 |
ABS_MT_POSITION_X, |
| 96 |
ABS_MT_POSITION_Y, |
| 97 |
}; |
| 98 |
|
| 99 |
ARRAY_FOR_EACH(axes, code) { |
| 100 |
const char *prop; |
| 101 |
char name[64]; |
| 102 |
uint32_t mask; |
| 103 |
struct input_absinfo abs; |
| 104 |
|
| 105 |
snprintf(name, sizeof(name), "EVDEV_ABS_%02X", *code); |
| 106 |
prop = udev_device_get_property_value(device, name); |
| 107 |
if (!prop) |
| 108 |
continue; |
| 109 |
|
| 110 |
mask = parse_evdev_abs_prop(prop, &abs); |
| 111 |
if (mask & ABS_MASK_FUZZ) |
| 112 |
printf("LIBINPUT_FUZZ_%02x=%d\n", *code, abs.fuzz); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
int |
| 117 |
main(int argc, char **argv) |
| 118 |
{ |
| 119 |
int rc = 1; |
| 120 |
struct udev *udev = NULL; |
| 121 |
struct udev_device *device = NULL; |
| 122 |
const char *syspath; |
| 123 |
|
| 124 |
if (argc != 2) |
| 125 |
return 1; |
| 126 |
|
| 127 |
syspath = argv[1]; |
| 128 |
|
| 129 |
udev = udev_new(); |
| 130 |
if (!udev) |
| 131 |
goto out; |
| 132 |
|
| 133 |
device = udev_device_new_from_syspath(udev, syspath); |
| 134 |
if (!device) |
| 135 |
goto out; |
| 136 |
|
| 137 |
handle_absfuzz(device); |
| 138 |
handle_evdev_abs(device); |
| 139 |
|
| 140 |
rc = 0; |
| 141 |
|
| 142 |
out: |
| 143 |
if (device) |
| 144 |
udev_device_unref(device); |
| 145 |
if (udev) |
| 146 |
udev_unref(udev); |
| 147 |
|
| 148 |
return rc; |
| 149 |
} |