swc

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

commit 9b58165ef971855b7915f32200c18a9c9f0f692e
parent 80e62f633fa6fd54829c5666ce6a4eac3638a12e
Author: Michael Forney <mforney@mforney.org>
Date:   Tue,  3 Dec 2013 21:49:42 -0800

evdev_device: Add reopen function

Diffstat:
Mlibswc/evdev_device.c | 31+++++++++++++++++++++++++++++++
Mlibswc/evdev_device.h | 3+++
Mlibswc/seat.c | 8++++++++
Mlibswc/seat.h | 1+
4 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/libswc/evdev_device.c b/libswc/evdev_device.c @@ -160,6 +160,9 @@ struct swc_evdev_device * swc_evdev_device_new goto error1; } + if (!(device->path = strdup(path))) + goto error2; + DEBUG("Adding device %s\n", libevdev_get_name(device->dev)); device->handler = handler; @@ -184,6 +187,8 @@ struct swc_evdev_device * swc_evdev_device_new return device; + error2: + libevdev_free(device->dev); error1: close(device->fd); error0: @@ -195,6 +200,7 @@ 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->path); free(device); } @@ -207,3 +213,28 @@ void swc_evdev_device_add_event_sources(struct swc_evdev_device * device, handle_data, device); } +bool swc_evdev_device_reopen(struct swc_evdev_device * device) +{ + close(device->fd); + + device->fd = swc_launch_open_device(device->path, + O_RDWR | O_NONBLOCK | O_CLOEXEC); + + if (device->fd == -1) + { + ERROR("Failed to open input device at %s\n", device->path); + goto error0; + } + + if (libevdev_change_fd(device->dev, device->fd) == -1) + { + ERROR("Failed to update libevdev fd\n"); + goto error1; + } + + error1: + close(device->fd); + error0: + return false; +} + diff --git a/libswc/evdev_device.h b/libswc/evdev_device.h @@ -18,6 +18,7 @@ struct swc_evdev_device_handler struct swc_evdev_device { + char * path; int fd; struct libevdev * dev; @@ -57,5 +58,7 @@ 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); +bool swc_evdev_device_reopen(struct swc_evdev_device * device); + #endif diff --git a/libswc/seat.c b/libswc/seat.c @@ -274,3 +274,11 @@ void swc_seat_finalize() wl_global_destroy(seat.global); } +void swc_seat_reopen_devices() +{ + struct swc_evdev_device * device; + + wl_list_for_each(device, &seat.devices, link) + swc_evdev_device_reopen(device); +} + diff --git a/libswc/seat.h b/libswc/seat.h @@ -35,6 +35,7 @@ struct swc_seat_global bool swc_seat_initialize(); void swc_seat_finalize(); +void swc_seat_reopen_devices(); #endif