From c5694b3013ff6c5038f58eba5ef9f62ec43112be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 31 Jan 2017 00:17:08 +0100 Subject: [PATCH] Linux: Fix joystick disconnection detection Joystick disconnection was not dectected by the event processing functions and required calling a joystick function. Fixes #932. --- README.md | 1 + src/linux_joystick.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f43bf6c0..e71125c9 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ information on what to include when reporting a bug. - [Win32] Bugfix: Bitness test in `FindVulkan.cmake` was VS specific (#928) - [X11] Replaced `_GLFW_HAS_XF86VM` compile-time option with dynamic loading - [X11] Bugfix: `glfwGetVideoMode` would segfault on Cygwin/X +- [Linux] Bugfix: Event processing did not detect joystick disconnection (#932) - [Cocoa] Added support for Vulkan window surface creation via [MoltenVK](https://moltengl.com/moltenvk/) (#870) - [Cocoa] Bugfix: Disabling window aspect ratio would assert (#852) diff --git a/src/linux_joystick.c b/src/linux_joystick.c index 7a7b4561..cfc15a49 100644 --- a/src/linux_joystick.c +++ b/src/linux_joystick.c @@ -146,7 +146,7 @@ GLFWbool _glfwInitJoysticksLinux(void) _glfw.linjs.watch = inotify_add_watch(_glfw.linjs.inotify, dirname, - IN_CREATE | IN_ATTRIB); + IN_CREATE | IN_ATTRIB | IN_DELETE); if (_glfw.linjs.watch == -1) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -240,7 +240,22 @@ void _glfwDetectJoystickConnectionLinux(void) { char path[20]; snprintf(path, sizeof(path), "/dev/input/%s", e->name); - openJoystickDevice(path); + + if (e->mask & (IN_CREATE | IN_ATTRIB)) + openJoystickDevice(path); + else if (e->mask & IN_DELETE) + { + int jid; + + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) + { + if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) + { + closeJoystick(_glfw.joysticks + jid); + break; + } + } + } } offset += sizeof(struct inotify_event) + e->len;