src/joystick/linux/SDL_sysjoystick.c
changeset 7916 8f16728ce87b
parent 7909 4434ab25abf3
child 8053 495f4a047be1
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Fri Nov 08 14:04:51 2013 -0800
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Fri Nov 08 14:04:59 2013 -0800
     1.3 @@ -234,12 +234,15 @@
     1.4          SDL_joylist_tail = item;
     1.5      }
     1.6  
     1.7 +    /* Need to increment the joystick count before we post the event */
     1.8 +    ++numjoysticks;
     1.9 +
    1.10      /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
    1.11  #if !SDL_EVENTS_DISABLED
    1.12      event.type = SDL_JOYDEVICEADDED;
    1.13  
    1.14      if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    1.15 -        event.jdevice.which = numjoysticks;
    1.16 +        event.jdevice.which = (numjoysticks - 1);
    1.17          if ( (SDL_EventOK == NULL) ||
    1.18               (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    1.19              SDL_PushEvent(&event);
    1.20 @@ -247,7 +250,7 @@
    1.21      }
    1.22  #endif /* !SDL_EVENTS_DISABLED */
    1.23  
    1.24 -    return numjoysticks++;
    1.25 +    return numjoysticks;
    1.26  }
    1.27  
    1.28  #if SDL_USE_LIBUDEV
    1.29 @@ -282,6 +285,9 @@
    1.30                  SDL_joylist_tail = prev;
    1.31              }
    1.32  
    1.33 +            /* Need to decrement the joystick count before we post the event */
    1.34 +            --numjoysticks;
    1.35 +
    1.36              /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
    1.37  #if !SDL_EVENTS_DISABLED
    1.38              event.type = SDL_JOYDEVICEREMOVED;
    1.39 @@ -298,7 +304,6 @@
    1.40              SDL_free(item->path);
    1.41              SDL_free(item->name);
    1.42              SDL_free(item);
    1.43 -            numjoysticks--;
    1.44              return retval;
    1.45          }
    1.46          prev = item;