src/joystick/linux/SDL_sysjoystick.c
changeset 7802 d239ba573818
parent 7788 25355ecf10aa
child 7860 2b0bcdea3a79
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Mon Oct 07 16:01:40 2013 -0700
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Thu Oct 10 20:58:20 2013 -0700
     1.3 @@ -138,8 +138,6 @@
     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 -    int instance;
     1.8 -    
     1.9      if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
    1.10          return;
    1.11      }
    1.12 @@ -147,41 +145,11 @@
    1.13      switch( udev_type )
    1.14      {
    1.15          case SDL_UDEV_DEVICEADDED:
    1.16 -            instance = MaybeAddDevice(devpath);
    1.17 -            if (instance != -1) {
    1.18 -                /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
    1.19 -                #if !SDL_EVENTS_DISABLED
    1.20 -                SDL_Event event;
    1.21 -                event.type = SDL_JOYDEVICEADDED;
    1.22 -
    1.23 -                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    1.24 -                    event.jdevice.which = instance;
    1.25 -                    if ( (SDL_EventOK == NULL) ||
    1.26 -                         (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    1.27 -                        SDL_PushEvent(&event);
    1.28 -                    }
    1.29 -                }
    1.30 -                #endif /* !SDL_EVENTS_DISABLED */
    1.31 -            }
    1.32 +            MaybeAddDevice(devpath);
    1.33              break;
    1.34              
    1.35          case SDL_UDEV_DEVICEREMOVED:
    1.36 -            instance = MaybeRemoveDevice(devpath);
    1.37 -            if (instance != -1) {
    1.38 -                /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
    1.39 -                #if !SDL_EVENTS_DISABLED
    1.40 -                SDL_Event event;
    1.41 -                event.type = SDL_JOYDEVICEREMOVED;
    1.42 -
    1.43 -                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    1.44 -                    event.jdevice.which = instance;
    1.45 -                    if ( (SDL_EventOK == NULL) ||
    1.46 -                         (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    1.47 -                        SDL_PushEvent(&event);
    1.48 -                    }
    1.49 -                }
    1.50 -                #endif /* !SDL_EVENTS_DISABLED */
    1.51 -            }
    1.52 +            MaybeRemoveDevice(devpath);
    1.53              break;
    1.54              
    1.55          default:
    1.56 @@ -202,6 +170,9 @@
    1.57      char namebuf[128];
    1.58      SDL_JoystickGUID guid;
    1.59      SDL_joylist_item *item;
    1.60 +#if !SDL_EVENTS_DISABLED
    1.61 +    SDL_Event event;
    1.62 +#endif
    1.63  
    1.64      if (path == NULL) {
    1.65          return -1;
    1.66 @@ -259,6 +230,19 @@
    1.67          SDL_joylist_tail = item;
    1.68      }
    1.69  
    1.70 +    /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
    1.71 +#if !SDL_EVENTS_DISABLED
    1.72 +    event.type = SDL_JOYDEVICEADDED;
    1.73 +
    1.74 +    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    1.75 +        event.jdevice.which = numjoysticks;
    1.76 +        if ( (SDL_EventOK == NULL) ||
    1.77 +             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    1.78 +            SDL_PushEvent(&event);
    1.79 +        }
    1.80 +    }
    1.81 +#endif /* !SDL_EVENTS_DISABLED */
    1.82 +
    1.83      return numjoysticks++;
    1.84  }
    1.85  
    1.86 @@ -269,6 +253,9 @@
    1.87  {
    1.88      SDL_joylist_item *item;
    1.89      SDL_joylist_item *prev = NULL;
    1.90 +#if !SDL_EVENTS_DISABLED
    1.91 +    SDL_Event event;
    1.92 +#endif
    1.93  
    1.94      if (path == NULL) {
    1.95          return -1;
    1.96 @@ -290,6 +277,20 @@
    1.97              if (item == SDL_joylist_tail) {
    1.98                  SDL_joylist_tail = prev;
    1.99              }
   1.100 +
   1.101 +            /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
   1.102 +#if !SDL_EVENTS_DISABLED
   1.103 +            event.type = SDL_JOYDEVICEREMOVED;
   1.104 +
   1.105 +            if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   1.106 +                event.jdevice.which = item->device_instance;
   1.107 +                if ( (SDL_EventOK == NULL) ||
   1.108 +                     (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
   1.109 +                    SDL_PushEvent(&event);
   1.110 +                }
   1.111 +            }
   1.112 +#endif /* !SDL_EVENTS_DISABLED */
   1.113 +
   1.114              SDL_free(item->path);
   1.115              SDL_free(item->name);
   1.116              SDL_free(item);