libinput-fuzz-to-zero.c 2.5 KB

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