From bf31d6f43e5ce04891a96b226a975379e2e2ba71 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 11 Aug 2016 12:34:54 -0700 Subject: [PATCH] os: Allow re-registering fd with InputThreadRegisterDev Calling InputThreadRegisterDev twice with the same fd should replace the existing function and args instead of creating a new entry with the same fd. Signed-off-by: Keith Packard Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- os/inputthread.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/os/inputthread.c b/os/inputthread.c index cb3af0661..1cd1c2af4 100644 --- a/os/inputthread.c +++ b/os/inputthread.c @@ -188,24 +188,38 @@ InputThreadRegisterDev(int fd, NotifyFdProcPtr readInputProc, void *readInputArgs) { - InputThreadDevice *dev; + InputThreadDevice *dev, *old; if (!inputThreadInfo) return SetNotifyFd(fd, readInputProc, X_NOTIFY_READ, readInputArgs); - dev = calloc(1, sizeof(InputThreadDevice)); - if (dev == NULL) { - DebugF("input-thread: could not register device\n"); - return 0; + input_lock(); + + dev = NULL; + xorg_list_for_each_entry(old, &inputThreadInfo->devs, node) { + if (old->fd == fd) { + dev = old; + break; + } } - dev->fd = fd; - dev->readInputProc = readInputProc; - dev->readInputArgs = readInputArgs; - dev->state = device_state_added; + if (dev) { + dev->readInputProc = readInputProc; + dev->readInputArgs = readInputArgs; + } else { + dev = calloc(1, sizeof(InputThreadDevice)); + if (dev == NULL) { + DebugF("input-thread: could not register device\n"); + input_unlock(); + return 0; + } - input_lock(); - xorg_list_append(&dev->node, &inputThreadInfo->devs); + dev->fd = fd; + dev->readInputProc = readInputProc; + dev->readInputArgs = readInputArgs; + dev->state = device_state_added; + xorg_list_append(&dev->node, &inputThreadInfo->devs); + } inputThreadInfo->changed = TRUE;