From b9952b4938da95de07bff748cfd6d2c7e8471796 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 27 Dec 2019 20:14:49 +0100 Subject: Remembering what was happening in this program... *Maybe* I should document it more. Who knows... I do seem to get one feature request every two years, and pretty much forget all about it inbetween. --- src/device/physical/physical_device.c | 40 ++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'src/device/physical/physical_device.c') diff --git a/src/device/physical/physical_device.c b/src/device/physical/physical_device.c index 7023791..4582c2d 100644 --- a/src/device/physical/physical_device.c +++ b/src/device/physical/physical_device.c @@ -187,12 +187,28 @@ int relabsd_physical_device_read libevdev_next_event ( device->libevdev, - device->is_late ? LIBEVDEV_READ_FLAG_SYNC : LIBEVDEV_READ_FLAG_NORMAL, + ( + ( + /* + * If we were already late, reading in NORMAL mode discards all + * the outdated input events, whereas reading in SYNC mode goes + * through them in order. + * TODO: add an option to allow users to drop events when late. + */ + device->is_late ? + LIBEVDEV_READ_FLAG_SYNC + : LIBEVDEV_READ_FLAG_NORMAL + ) + /* "The fd is not in O_NONBLOCK and a read may block." */ + | LIBEVDEV_READ_FLAG_BLOCKING + ) + , &event ); switch (returned_code) { + /* Read an actual input. */ case LIBEVDEV_READ_STATUS_SUCCESS: RELABSD_DEBUG ( @@ -207,14 +223,28 @@ int relabsd_physical_device_read *input_code = event.code; *input_value = event.value; - return 1; + return 0; + /* Code indicating that we are late. */ case LIBEVDEV_READ_STATUS_SYNC: - /* There are old events waiting to be read. */ + /* There are old input events waiting to be read. */ device->is_late = 1; + /* + * From the documentation, the event we just read was an EV_SYN one, + * so we don't actually have any input event in hand. + */ + + /* FIXME: Really make sure this cannot recurse a second time. */ + return + relabsd_physical_device_read + ( + device, + input_type, + input_code, + input_value + ); - return 0; - + /* No event to read. */ case -EAGAIN: device->is_late = 0; -- cgit v1.2.3-70-g09d2