| 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 <stdio.h> |
| 31 |
#include <unistd.h> |
| 32 |
|
| 33 |
#include "util-macros.h" |
| 34 |
|
| 35 |
static void |
| 36 |
reset_absfuzz_to_zero(struct udev_device *device) |
| 37 |
{ |
| 38 |
const char *devnode; |
| 39 |
struct libevdev *evdev = NULL; |
| 40 |
int fd = -1; |
| 41 |
int rc; |
| 42 |
unsigned int axes[] = { |
| 43 |
ABS_X, |
| 44 |
ABS_Y, |
| 45 |
ABS_MT_POSITION_X, |
| 46 |
ABS_MT_POSITION_Y, |
| 47 |
}; |
| 48 |
|
| 49 |
devnode = udev_device_get_devnode(device); |
| 50 |
if (!devnode) |
| 51 |
goto out; |
| 52 |
|
| 53 |
fd = open(devnode, O_RDWR); |
| 54 |
if (fd < 0) |
| 55 |
goto out; |
| 56 |
|
| 57 |
rc = libevdev_new_from_fd(fd, &evdev); |
| 58 |
if (rc != 0) |
| 59 |
goto out; |
| 60 |
|
| 61 |
if (!libevdev_has_event_type(evdev, EV_ABS)) |
| 62 |
goto out; |
| 63 |
|
| 64 |
ARRAY_FOR_EACH(axes, code) { |
| 65 |
struct input_absinfo abs; |
| 66 |
int fuzz; |
| 67 |
|
| 68 |
fuzz = libevdev_get_abs_fuzz(evdev, *code); |
| 69 |
if (!fuzz) |
| 70 |
continue; |
| 71 |
|
| 72 |
abs = *libevdev_get_abs_info(evdev, *code); |
| 73 |
abs.fuzz = 0; |
| 74 |
libevdev_kernel_set_abs_info(evdev, *code, &abs); |
| 75 |
} |
| 76 |
|
| 77 |
out: |
| 78 |
close(fd); |
| 79 |
libevdev_free(evdev); |
| 80 |
} |
| 81 |
|
| 82 |
int |
| 83 |
main(int argc, char **argv) |
| 84 |
{ |
| 85 |
int rc = 1; |
| 86 |
struct udev *udev = NULL; |
| 87 |
struct udev_device *device = NULL; |
| 88 |
const char *syspath; |
| 89 |
|
| 90 |
if (argc != 2) |
| 91 |
return 1; |
| 92 |
|
| 93 |
syspath = argv[1]; |
| 94 |
|
| 95 |
udev = udev_new(); |
| 96 |
if (!udev) |
| 97 |
goto out; |
| 98 |
|
| 99 |
device = udev_device_new_from_syspath(udev, syspath); |
| 100 |
if (!device) |
| 101 |
goto out; |
| 102 |
|
| 103 |
reset_absfuzz_to_zero(device); |
| 104 |
|
| 105 |
rc = 0; |
| 106 |
|
| 107 |
out: |
| 108 |
if (device) |
| 109 |
udev_device_unref(device); |
| 110 |
if (udev) |
| 111 |
udev_unref(udev); |
| 112 |
|
| 113 |
return rc; |
| 114 |
} |