Fixed game controller hotplug support for some embedded Linux devices
authorSam Lantinga <slouken@libsdl.org>
Thu, 29 Jan 2015 13:33:53 -0800
changeset 932101966f6feadc
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
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 29 13:33:20 2015 -0800
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 29 13:33:53 2015 -0800
     1.3 @@ -142,13 +142,15 @@
     1.4  #if SDL_USE_LIBUDEV
     1.5  void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
     1.6  {
     1.7 -    if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
     1.8 +    if (devpath == NULL) {
     1.9          return;
    1.10      }
    1.11 -    
    1.12 -    switch( udev_type )
    1.13 -    {
    1.14 +
    1.15 +    switch (udev_type) {
    1.16          case SDL_UDEV_DEVICEADDED:
    1.17 +            if (!(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
    1.18 +                return;
    1.19 +            }
    1.20              MaybeAddDevice(devpath);
    1.21              break;
    1.22              
    1.23 @@ -335,13 +337,12 @@
    1.24  static int
    1.25  JoystickInitWithUdev(void)
    1.26  {
    1.27 -
    1.28      if (SDL_UDEV_Init() < 0) {
    1.29          return SDL_SetError("Could not initialize UDEV");
    1.30      }
    1.31  
    1.32      /* Set up the udev callback */
    1.33 -    if ( SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
    1.34 +    if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
    1.35          SDL_UDEV_Quit();
    1.36          return SDL_SetError("Could not set up joystick <-> udev callback");
    1.37      }