diff options
Diffstat (limited to 'rcm-server-evdev.c')
-rw-r--r-- | rcm-server-evdev.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/rcm-server-evdev.c b/rcm-server-evdev.c index 74cae10..afd89f7 100644 --- a/rcm-server-evdev.c +++ b/rcm-server-evdev.c @@ -9,6 +9,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <libevdev/libevdev.h> #include "utils.h" #include "shared.h" @@ -150,6 +151,7 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) static uint32_t scancode; static bool scancode_recv = false; unsigned i; + int r; if (fd != device->evdev_fd) fprintf(stderr, "evdev fd mismatch: %i != %i\n", device->evdev_fd, fd); @@ -166,7 +168,16 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) return 0; } - while (read(fd, &ev, sizeof(ev)) == sizeof(ev)) { + do { + r = libevdev_next_event(device->evdev_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); + if (r != LIBEVDEV_READ_STATUS_SUCCESS) + continue; + + printf("Event: %s %s %d\n", + libevdev_event_type_get_name(ev.type), + libevdev_event_code_get_name(ev.type, ev.code), + ev.value); + switch (ev.type) { case EV_KEY: if (keycode) @@ -242,13 +253,14 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata) default: break; } - } + + } while (r == LIBEVDEV_READ_STATUS_SUCCESS || r == LIBEVDEV_READ_STATUS_SYNC); return 0; } int -evdev_setup(struct manager *mgr, struct device *device, const char *path) +evdev_setup(struct device *device, const char *path) { int r; struct keymap *keymap; @@ -262,13 +274,15 @@ evdev_setup(struct manager *mgr, struct device *device, const char *path) } device->evdev_fd = open(path, O_RDONLY | O_NONBLOCK); - if (device->evdev_fd < 0) { - printf("Failed to open evdev device %s: %s\n", - path, strerror(errno)); - return -errno; + r = libevdev_new_from_fd(device->evdev_fd, &device->evdev_dev); + if (r < 0) { + printf("Failed to open evdev device %s: %s\n", path, strerror(-r)); + close(device->evdev_fd); + return r; } - printf("Performing evdev setup for device %s\n", device->path); + printf("Performing evdev setup for device %s (%s)\n", + device->path, libevdev_get_name(device->evdev_dev)); r = evdev_clear_keymap(device); if (r < 0) return r; @@ -276,7 +290,7 @@ evdev_setup(struct manager *mgr, struct device *device, const char *path) list_for_each_entry(keymap, &device->keymaps, list) r = evdev_set_keymap(device, keymap); - if (sd_event_add_io(mgr->event, &device->evdev_ev, + if (sd_event_add_io(device->mgr->event, &device->evdev_ev, device->evdev_fd, EPOLLIN, evdev_read, device) < 0) { printf("Failed to add event source for evdev device %s: %s\n", path, strerror(errno)); |