Fixed bug 2477 - [PATCH] Joysticks do not work on RHEL6/CentOS6 systems
authorSam Lantinga <slouken@libsdl.org>
Thu, 17 Apr 2014 20:18:50 -0700
changeset 8709a4346af9eec4
parent 8708 2a76a78f7723
child 8710 403c95143f8a
Fixed bug 2477 - [PATCH] Joysticks do not work on RHEL6/CentOS6 systems

Ashley Whetter

RHEL6 and CentOS6 systems still use an old version of udev (147). It wasn't until udev 148 (Yep. 1 version off!) that the input class system changed from "ID_CLASS" to "ID_INPUT_{JOYSTICK,KEYBOARD,MOUSE,etc}" (http://lwn.net/Articles/364728/). Because SDL2 looks for the ID_INPUT_X field this means that it never detects any input devices on RHEL6 systems.

I've attached a patch which fixes the problem. If no input devices are detected with "ID_INPUT_X" then SDL will fallback to looking for the old style "ID_CLASS" udev field instead.
Because of the "big change" between udev versions I doubt it'll ever get upgraded on RHEL6, but because RHEL7 is on the way I don't know if this patch is worth merging. Hopefully it'll help anyone out that's having this problem though.
src/core/linux/SDL_udev.c
     1.1 --- a/src/core/linux/SDL_udev.c	Thu Apr 17 20:15:44 2014 -0700
     1.2 +++ b/src/core/linux/SDL_udev.c	Thu Apr 17 20:18:50 2014 -0700
     1.3 @@ -308,7 +308,21 @@
     1.4          }
     1.5  
     1.6          if (devclass == 0) {
     1.7 -            return;
     1.8 +            // Fall back to old style input classes
     1.9 +            val = _this->udev_device_get_property_value(dev, "ID_CLASS");
    1.10 +            if (val != NULL) {
    1.11 +                if (SDL_strcmp(val, "joystick") == 0) {
    1.12 +                    devclass = SDL_UDEV_DEVICE_JOYSTICK;
    1.13 +                } else if (SDL_strcmp(val, "mouse") == 0) {
    1.14 +                    devclass = SDL_UDEV_DEVICE_MOUSE;
    1.15 +                } else if (SDL_strcmp(val, "kbd") == 0) {
    1.16 +                    devclass = SDL_UDEV_DEVICE_KEYBOARD;
    1.17 +                } else {
    1.18 +                    return;
    1.19 +                }
    1.20 +            } else {
    1.21 +                return;
    1.22 +            }
    1.23          }
    1.24      } else {
    1.25          return;