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