Fixed game controller hotplug support for some embedded Linux devices
authorSam Lantinga <slouken@libsdl.org>
Thu, 29 Jan 2015 13:33:53 -0800
changeset 9321 01966f6feadc
parent 9320 38f5bcc808a9
child 9322 a45110bca65e
Fixed game controller hotplug support for some embedded Linux devices When guessing the device class, it ends up being 0 for devices that have been removed (because the device node no longer exists)
src/joystick/linux/SDL_sysjoystick.c
--- a/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 29 13:33:20 2015 -0800
+++ b/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 29 13:33:53 2015 -0800
@@ -142,13 +142,15 @@
 #if SDL_USE_LIBUDEV
 void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
 {
-    if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
+    if (devpath == NULL) {
         return;
     }
-    
-    switch( udev_type )
-    {
+
+    switch (udev_type) {
         case SDL_UDEV_DEVICEADDED:
+            if (!(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
+                return;
+            }
             MaybeAddDevice(devpath);
             break;
             
@@ -335,13 +337,12 @@
 static int
 JoystickInitWithUdev(void)
 {
-
     if (SDL_UDEV_Init() < 0) {
         return SDL_SetError("Could not initialize UDEV");
     }
 
     /* Set up the udev callback */
-    if ( SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
+    if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
         SDL_UDEV_Quit();
         return SDL_SetError("Could not set up joystick <-> udev callback");
     }