1a46c0ec8Sopenharmony_ci/* 2a46c0ec8Sopenharmony_ci * Copyright © 2015 Red Hat, Inc. 3a46c0ec8Sopenharmony_ci * 4a46c0ec8Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5a46c0ec8Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6a46c0ec8Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7a46c0ec8Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8a46c0ec8Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9a46c0ec8Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10a46c0ec8Sopenharmony_ci * 11a46c0ec8Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12a46c0ec8Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13a46c0ec8Sopenharmony_ci * Software. 14a46c0ec8Sopenharmony_ci * 15a46c0ec8Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16a46c0ec8Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17a46c0ec8Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18a46c0ec8Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19a46c0ec8Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20a46c0ec8Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21a46c0ec8Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 22a46c0ec8Sopenharmony_ci */ 23a46c0ec8Sopenharmony_ci 24a46c0ec8Sopenharmony_ci#include "config.h" 25a46c0ec8Sopenharmony_ci 26a46c0ec8Sopenharmony_ci#include <fcntl.h> 27a46c0ec8Sopenharmony_ci#include <stdio.h> 28a46c0ec8Sopenharmony_ci#include <unistd.h> 29a46c0ec8Sopenharmony_ci#include <libudev.h> 30a46c0ec8Sopenharmony_ci#include <linux/input.h> 31a46c0ec8Sopenharmony_ci#include <libevdev/libevdev.h> 32a46c0ec8Sopenharmony_ci 33a46c0ec8Sopenharmony_ci#include "util-macros.h" 34a46c0ec8Sopenharmony_ci 35a46c0ec8Sopenharmony_cistatic void 36a46c0ec8Sopenharmony_cireset_absfuzz_to_zero(struct udev_device *device) 37a46c0ec8Sopenharmony_ci{ 38a46c0ec8Sopenharmony_ci const char *devnode; 39a46c0ec8Sopenharmony_ci struct libevdev *evdev = NULL; 40a46c0ec8Sopenharmony_ci int fd = -1; 41a46c0ec8Sopenharmony_ci int rc; 42a46c0ec8Sopenharmony_ci unsigned int axes[] = {ABS_X, 43a46c0ec8Sopenharmony_ci ABS_Y, 44a46c0ec8Sopenharmony_ci ABS_MT_POSITION_X, 45a46c0ec8Sopenharmony_ci ABS_MT_POSITION_Y}; 46a46c0ec8Sopenharmony_ci 47a46c0ec8Sopenharmony_ci devnode = udev_device_get_devnode(device); 48a46c0ec8Sopenharmony_ci if (!devnode) 49a46c0ec8Sopenharmony_ci goto out; 50a46c0ec8Sopenharmony_ci 51a46c0ec8Sopenharmony_ci fd = open(devnode, O_RDWR); 52a46c0ec8Sopenharmony_ci if (fd < 0) 53a46c0ec8Sopenharmony_ci goto out; 54a46c0ec8Sopenharmony_ci 55a46c0ec8Sopenharmony_ci rc = libevdev_new_from_fd(fd, &evdev); 56a46c0ec8Sopenharmony_ci if (rc != 0) 57a46c0ec8Sopenharmony_ci goto out; 58a46c0ec8Sopenharmony_ci 59a46c0ec8Sopenharmony_ci if (!libevdev_has_event_type(evdev, EV_ABS)) 60a46c0ec8Sopenharmony_ci goto out; 61a46c0ec8Sopenharmony_ci 62a46c0ec8Sopenharmony_ci ARRAY_FOR_EACH(axes, code) { 63a46c0ec8Sopenharmony_ci struct input_absinfo abs; 64a46c0ec8Sopenharmony_ci int fuzz; 65a46c0ec8Sopenharmony_ci 66a46c0ec8Sopenharmony_ci fuzz = libevdev_get_abs_fuzz(evdev, *code); 67a46c0ec8Sopenharmony_ci if (!fuzz) 68a46c0ec8Sopenharmony_ci continue; 69a46c0ec8Sopenharmony_ci 70a46c0ec8Sopenharmony_ci abs = *libevdev_get_abs_info(evdev, *code); 71a46c0ec8Sopenharmony_ci abs.fuzz = 0; 72a46c0ec8Sopenharmony_ci libevdev_kernel_set_abs_info(evdev, *code, &abs); 73a46c0ec8Sopenharmony_ci } 74a46c0ec8Sopenharmony_ci 75a46c0ec8Sopenharmony_ciout: 76a46c0ec8Sopenharmony_ci close(fd); 77a46c0ec8Sopenharmony_ci libevdev_free(evdev); 78a46c0ec8Sopenharmony_ci} 79a46c0ec8Sopenharmony_ci 80a46c0ec8Sopenharmony_ciint main(int argc, char **argv) 81a46c0ec8Sopenharmony_ci{ 82a46c0ec8Sopenharmony_ci int rc = 1; 83a46c0ec8Sopenharmony_ci struct udev *udev = NULL; 84a46c0ec8Sopenharmony_ci struct udev_device *device = NULL; 85a46c0ec8Sopenharmony_ci const char *syspath; 86a46c0ec8Sopenharmony_ci 87a46c0ec8Sopenharmony_ci if (argc != 2) 88a46c0ec8Sopenharmony_ci return 1; 89a46c0ec8Sopenharmony_ci 90a46c0ec8Sopenharmony_ci syspath = argv[1]; 91a46c0ec8Sopenharmony_ci 92a46c0ec8Sopenharmony_ci udev = udev_new(); 93a46c0ec8Sopenharmony_ci if (!udev) 94a46c0ec8Sopenharmony_ci goto out; 95a46c0ec8Sopenharmony_ci 96a46c0ec8Sopenharmony_ci device = udev_device_new_from_syspath(udev, syspath); 97a46c0ec8Sopenharmony_ci if (!device) 98a46c0ec8Sopenharmony_ci goto out; 99a46c0ec8Sopenharmony_ci 100a46c0ec8Sopenharmony_ci reset_absfuzz_to_zero(device); 101a46c0ec8Sopenharmony_ci 102a46c0ec8Sopenharmony_ci rc = 0; 103a46c0ec8Sopenharmony_ci 104a46c0ec8Sopenharmony_ciout: 105a46c0ec8Sopenharmony_ci if (device) 106a46c0ec8Sopenharmony_ci udev_device_unref(device); 107a46c0ec8Sopenharmony_ci if (udev) 108a46c0ec8Sopenharmony_ci udev_unref(udev); 109a46c0ec8Sopenharmony_ci 110a46c0ec8Sopenharmony_ci return rc; 111a46c0ec8Sopenharmony_ci} 112