Implement Long-Press-to-Right-Click on Touchscreen Linux Device with Xorg or Wayland
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uinput.c 1002B

1234567891011121314151617181920212223242526
  1. #include "uinput.h"
  2. #include <stddef.h>
  3. struct libevdev_uinput *uinput_initialize() {
  4. // Create a evdev first to describe the features
  5. struct libevdev *evdev = libevdev_new();
  6. libevdev_set_name(evdev, "Simulated Right Button");
  7. libevdev_enable_event_type(evdev, EV_KEY);
  8. libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
  9. // Initialize uinput device from the evdev descriptor
  10. struct libevdev_uinput *uinput = NULL;
  11. if (libevdev_uinput_create_from_device(evdev,
  12. LIBEVDEV_UINPUT_OPEN_MANAGED, &uinput) != 0) {
  13. uinput = NULL;
  14. }
  15. // We don't need the fake evdev anymore.
  16. libevdev_free(evdev);
  17. return uinput;
  18. }
  19. void uinput_send_right_click(struct libevdev_uinput *uinput) {
  20. libevdev_uinput_write_event(uinput, EV_KEY, BTN_RIGHT, 1);
  21. libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
  22. libevdev_uinput_write_event(uinput, EV_KEY, BTN_RIGHT, 0);
  23. libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
  24. }