swc

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

commit 439168087493c3296d5be729360834166c3893e5
parent 1893d9226d80bf68326df91e9ce1fe2925c7bc90
Author: Michael Forney <mforney@mforney.org>
Date:   Fri, 13 Sep 2013 20:54:42 -0700

evdev_device: Use new/destroy instead of initialize/finish

Diffstat:
Mlibswc/evdev_device.c | 29+++++++++++++++++------------
Mlibswc/evdev_device.h | 7+++----
Mlibswc/seat.c | 44++++++++++++--------------------------------
3 files changed, 32 insertions(+), 48 deletions(-)

diff --git a/libswc/evdev_device.c b/libswc/evdev_device.c @@ -133,32 +133,34 @@ static int handle_data(int fd, uint32_t mask, void * data) return 1; } -bool swc_evdev_device_initialize(struct swc_evdev_device * device, - const char * path, - const struct swc_evdev_device_handler * handler) +struct swc_evdev_device * swc_evdev_device_new + (const char * path, const struct swc_evdev_device_handler * handler) { + struct swc_evdev_device * device; uint32_t index; + if (!(device = malloc(sizeof *device))) + goto error0; + device->fd = open(path, O_RDWR | O_NONBLOCK | O_CLOEXEC); - memset(&device->motion, 0, sizeof device->motion); if (device->fd == -1) { printf("couldn't open input device at %s\n", path); - goto error_base; + goto error0; } if (libevdev_new_from_fd(device->fd, &device->dev) != 0) { fprintf(stderr, "Could not create libevdev device\n"); - goto error_fd; + goto error1; } printf("Adding device %s\n", libevdev_get_name(device->dev)); device->handler = handler; device->capabilities = 0; - /* XXX: touch devices */ + memset(&device->motion, 0, sizeof device->motion); if (libevdev_has_event_code(device->dev, EV_KEY, KEY_ENTER)) { @@ -174,19 +176,22 @@ bool swc_evdev_device_initialize(struct swc_evdev_device * device, printf("\tthis device is a pointer\n"); } - return true; + /* XXX: touch devices */ + + return device; - error_fd: + error1: close(device->fd); - error_base: - return false; + error0: + return NULL; } -void swc_evdev_device_finish(struct swc_evdev_device * device) +void swc_evdev_device_destroy(struct swc_evdev_device * device) { wl_event_source_remove(device->source); libevdev_free(device->dev); close(device->fd); + free(device); } void swc_evdev_device_add_event_sources(struct swc_evdev_device * device, diff --git a/libswc/evdev_device.h b/libswc/evdev_device.h @@ -53,11 +53,10 @@ struct swc_evdev_device struct wl_list link; }; -bool swc_evdev_device_initialize - (struct swc_evdev_device * device, const char * path, - const struct swc_evdev_device_handler * handler); +struct swc_evdev_device * swc_evdev_device_new + (const char * path, const struct swc_evdev_device_handler * handler); -void swc_evdev_device_finish(struct swc_evdev_device * device); +void swc_evdev_device_destroy(struct swc_evdev_device * device); void swc_evdev_device_add_event_sources(struct swc_evdev_device * device, struct wl_event_loop * event_loop); diff --git a/libswc/seat.c b/libswc/seat.c @@ -9,14 +9,6 @@ #include <stdio.h> #include <string.h> -struct evdev_device_entry -{ - struct swc_evdev_device device; - struct wl_listener event_listener; - struct swc_seat * seat; - struct wl_list link; -}; - static void handle_key(const struct swc_evdev_device_handler * handler, uint32_t time, uint32_t key, uint32_t state) { @@ -160,7 +152,6 @@ 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"); @@ -172,31 +163,21 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device) return; device_path = udev_device_get_devnode(udev_device); + device = swc_evdev_device_new(device_path, &seat->evdev_handler); - entry = malloc(sizeof *entry); - - if (!entry) - { - printf("could not allocate evdev device\n"); - return; - } - - entry->seat = seat; - - if (!swc_evdev_device_initialize(&entry->device, device_path, - &seat->evdev_handler)) + if (!device) { - free(entry); + fprintf(stderr, "Could not create evdev device\n"); return; } - if (~seat->capabilities & entry->device.capabilities) + if (~seat->capabilities & device->capabilities) { - seat->capabilities |= entry->device.capabilities; + seat->capabilities |= device->capabilities; update_capabilities(seat); } - wl_list_insert(&seat->devices, &entry->link); + wl_list_insert(&seat->devices, &device->link); } bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev, @@ -253,7 +234,7 @@ bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev, void swc_seat_finish(struct swc_seat * seat) { - struct evdev_device_entry * entry, * tmp; + struct swc_evdev_device * device, * tmp; wl_signal_emit(&seat->destroy_signal, seat); @@ -262,10 +243,9 @@ void swc_seat_finish(struct swc_seat * seat) free(seat->name); - wl_list_for_each_safe(entry, tmp, &seat->devices, link) + wl_list_for_each_safe(device, tmp, &seat->devices, link) { - swc_evdev_device_finish(&entry->device); - free(entry); + swc_evdev_device_destroy(device); } } @@ -277,11 +257,11 @@ void swc_seat_add_globals(struct swc_seat * seat, struct wl_display * display) void swc_seat_add_event_sources(struct swc_seat * seat, struct wl_event_loop * event_loop) { - struct evdev_device_entry * entry; + struct swc_evdev_device * device; - wl_list_for_each(entry, &seat->devices, link) + wl_list_for_each(device, &seat->devices, link) { - swc_evdev_device_add_event_sources(&entry->device, event_loop); + swc_evdev_device_add_event_sources(device, event_loop); } }