Linux: Fix joystick disconnection detection

Joystick disconnection was not dectected by the event processing
functions and required calling a joystick function.

Fixes #932.
This commit is contained in:
Camilla Löwy 2017-01-31 00:17:08 +01:00
parent 466347a335
commit c5694b3013
2 changed files with 18 additions and 2 deletions

View File

@ -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)

View File

@ -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);
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;