swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 2814349c0270f1b4235e37d5965ae362f3416d4f
parent 06a268660cb3f191015707da097c0c60631a5b6b
Author: Michael Forney <mforney@mforney.org>
Date:   Fri, 13 Sep 2013 20:37:08 -0700

evdev_device: Don't use libudev

Diffstat:
Mlibswc/evdev_device.c | 24+++++++-----------------
Mlibswc/evdev_device.h | 4+---
Mlibswc/seat.c | 5++++-
3 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/libswc/evdev_device.c b/libswc/evdev_device.c @@ -154,19 +154,10 @@ static int handle_data(int fd, uint32_t mask, void * data) } bool swc_evdev_device_initialize(struct swc_evdev_device * device, - struct udev_device * udev_device) + const char * path) { - const char * path, * model, * vendor; uint32_t index; - path = udev_device_get_devnode(udev_device); - model = udev_device_get_property_value(udev_device, "ID_MODEL") - ?: "unknown"; - vendor = udev_device_get_property_value(udev_device, "ID_VENDOR") - ?: "unknown"; - - device->model = strdup(model); - device->vendor = strdup(vendor); device->fd = open(path, O_RDWR | O_NONBLOCK | O_CLOEXEC); memset(&device->motion, 0, sizeof device->motion); @@ -184,19 +175,20 @@ bool swc_evdev_device_initialize(struct swc_evdev_device * device, goto error_fd; } - printf("adding device %s %s\n", device->vendor, device->model); + printf("Adding device %s\n", libevdev_get_name(device->dev)); device->capabilities = 0; /* XXX: touch devices */ - if (udev_device_get_property_value(udev_device, "ID_INPUT_KEYBOARD")) + if (libevdev_has_event_code(device->dev, EV_KEY, KEY_ENTER)) { device->capabilities |= WL_SEAT_CAPABILITY_KEYBOARD; printf("\tthis device is a keyboard\n"); } - if (udev_device_get_property_value(udev_device, "ID_INPUT_MOUSE") - || udev_device_get_property_value(udev_device, "ID_INPUT_TOUCHPAD")) + if (libevdev_has_event_code(device->dev, EV_REL, REL_X) + && libevdev_has_event_code(device->dev, EV_REL, REL_Y) + && libevdev_has_event_code(device->dev, EV_KEY, BTN_MOUSE)) { device->capabilities |= WL_SEAT_CAPABILITY_POINTER; printf("\tthis device is a pointer\n"); @@ -214,15 +206,13 @@ void swc_evdev_device_finish(struct swc_evdev_device * device) { wl_event_source_remove(device->source); libevdev_free(device->dev); - free(device->model); - free(device->vendor); close(device->fd); } void swc_evdev_device_add_event_sources(struct swc_evdev_device * device, struct wl_event_loop * event_loop) { - printf("adding event source for %s %s\n", device->vendor, device->model); + printf("Adding event source for %s\n", libevdev_get_name(device->dev)); device->source = wl_event_loop_add_fd(event_loop, device->fd, WL_EVENT_READABLE, handle_data, device); diff --git a/libswc/evdev_device.h b/libswc/evdev_device.h @@ -2,7 +2,6 @@ #define SWC_EVDEV_DEVICE_H 1 #include <stdbool.h> -#include <libudev.h> #include <linux/input.h> #include <wayland-server.h> @@ -51,7 +50,6 @@ struct swc_evdev_device { int fd; struct libevdev * dev; - char * model, * vendor; struct { @@ -81,7 +79,7 @@ struct swc_evdev_device }; bool swc_evdev_device_initialize(struct swc_evdev_device * device, - struct udev_device * udev_device); + const char * path); void swc_evdev_device_finish(struct swc_evdev_device * device); diff --git a/libswc/seat.c b/libswc/seat.c @@ -179,6 +179,7 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device) { const char * device_seat; const char * device_path; + struct swc_evdev_device * device; struct evdev_device_entry * entry; device_seat = udev_device_get_property_value(udev_device, "ID_SEAT"); @@ -190,6 +191,8 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device) if (strcmp(device_seat, seat->name) != 0) return; + device_path = udev_device_get_devnode(udev_device); + entry = malloc(sizeof *entry); if (!entry) @@ -201,7 +204,7 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device) entry->seat = seat; entry->event_listener.notify = &handle_evdev_event; - if (!swc_evdev_device_initialize(&entry->device, udev_device)) + if (!swc_evdev_device_initialize(&entry->device, device_path)) { free(entry); return;