From 17826b06dc72cbc897e0f4bbd8d3ef02e23f8a24 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 4 Feb 2014 08:45:18 +1000 Subject: [PATCH] Keep track of the enabled devices All libinput devices share the same file descriptor so make sure we don't remove from the server's select loop until the last device is disabled. Signed-off-by: Peter Hutterer --- src/libinput.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 070de30..b19492b 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -54,6 +54,7 @@ struct xf86libinput_driver { struct libinput *libinput; int device_count; + int device_enabled_count; }; static struct xf86libinput_driver driver_context; @@ -91,8 +92,13 @@ xf86libinput_on(DeviceIntPtr dev) driver_data->device = device; pInfo->fd = libinput_get_fd(libinput); - /* Can't use xf86AddEnabledDevice on an epollfd */ - AddEnabledDevice(pInfo->fd); + + if (driver_context.device_enabled_count == 0) { + /* Can't use xf86AddEnabledDevice on an epollfd */ + AddEnabledDevice(pInfo->fd); + } + + driver_context.device_enabled_count++; dev->public.on = TRUE; return Success; @@ -104,7 +110,10 @@ xf86libinput_off(DeviceIntPtr dev) InputInfoPtr pInfo = dev->public.devicePrivate; struct xf86libinput *driver_data = pInfo->private; - RemoveEnabledDevice(pInfo->fd); + if (--driver_context.device_enabled_count == 0) { + RemoveEnabledDevice(pInfo->fd); + } + pInfo->fd = -1; dev->public.on = FALSE; @@ -433,6 +442,9 @@ xf86libinput_handle_event(struct libinput_event *event) device = libinput_event_get_device(event); pInfo = libinput_device_get_user_data(device); + if (pInfo && !pInfo->dev->public.on) + return; + switch (libinput_event_get_type(event)) { case LIBINPUT_EVENT_NONE: case LIBINPUT_EVENT_DEVICE_ADDED: