Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
authorSam Lantinga <slouken@libsdl.org>
Fri, 26 Aug 2016 12:18:08 -0700
changeset 10226cb13d22b7f09
parent 10225 3134026517cb
child 10227 9bbe05f2612a
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Updated the removal code to iterate over all joystick add messages instead of just the first one.
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_joystick.c
src/joystick/SDL_joystick_c.h
src/joystick/android/SDL_sysjoystick.c
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/emscripten/SDL_sysjoystick.c
src/joystick/iphoneos/SDL_sysjoystick.m
src/joystick/linux/SDL_sysjoystick.c
src/joystick/windows/SDL_windowsjoystick.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Fri Aug 26 11:16:44 2016 -0700
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Fri Aug 26 12:18:08 2016 -0700
     1.3 @@ -106,6 +106,35 @@
     1.4  int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);
     1.5  
     1.6  /*
     1.7 + * If there is an existing add event in the queue, it needs to be modified
     1.8 + * to have the right value for which, because the number of controllers in
     1.9 + * the system is now one less.
    1.10 + */
    1.11 +static void UpdateEventsForDeviceRemoval()
    1.12 +{
    1.13 +    int i, num_events;
    1.14 +    SDL_Event *events;
    1.15 +
    1.16 +    num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
    1.17 +    if (num_events <= 0) {
    1.18 +        return;
    1.19 +    }
    1.20 +
    1.21 +    events = SDL_stack_alloc(SDL_Event, num_events);
    1.22 +    if (!events) {
    1.23 +        return;
    1.24 +    }
    1.25 +
    1.26 +    num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
    1.27 +    for (i = 0; i < num_events; ++i) {
    1.28 +        --events[i].cdevice.which;
    1.29 +    }
    1.30 +    SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
    1.31 +
    1.32 +    SDL_stack_free(events);
    1.33 +}
    1.34 +
    1.35 +/*
    1.36   * Event filter to fire controller events from joystick ones
    1.37   */
    1.38  int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
    1.39 @@ -222,22 +251,13 @@
    1.40              SDL_GameController *controllerlist = SDL_gamecontrollers;
    1.41              while (controllerlist) {
    1.42                  if (controllerlist->joystick->instance_id == event->jdevice.which) {
    1.43 -					SDL_Event peeped;
    1.44                      SDL_Event deviceevent;
    1.45  
    1.46 -					/* If there is an existing add event in the queue, it
    1.47 -					 * needs to be modified to have the right value for which,
    1.48 -					 * because the number of controllers in the system is now
    1.49 -					 * one less.
    1.50 -					 */
    1.51 -					if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED) > 0) {
    1.52 -						peeped.jdevice.which--;
    1.53 -						SDL_PushEvent(&peeped);
    1.54 -					}
    1.55 -
    1.56                      deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
    1.57                      deviceevent.cdevice.which = event->jdevice.which;
    1.58                      SDL_PushEvent(&deviceevent);
    1.59 +
    1.60 +                    UpdateEventsForDeviceRemoval();
    1.61                      break;
    1.62                  }
    1.63                  controllerlist = controllerlist->next;
     2.1 --- a/src/joystick/SDL_joystick.c	Fri Aug 26 11:16:44 2016 -0700
     2.2 +++ b/src/joystick/SDL_joystick.c	Fri Aug 26 12:18:08 2016 -0700
     2.3 @@ -497,6 +497,71 @@
     2.4  
     2.5  /* These are global for SDL_sysjoystick.c and SDL_events.c */
     2.6  
     2.7 +void SDL_PrivateJoystickAdded(int device_index)
     2.8 +{
     2.9 +#if !SDL_EVENTS_DISABLED
    2.10 +    SDL_Event event;
    2.11 +
    2.12 +    event.type = SDL_JOYDEVICEADDED;
    2.13 +
    2.14 +    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    2.15 +        event.jdevice.which = device_index;
    2.16 +        if ( (SDL_EventOK == NULL) ||
    2.17 +             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    2.18 +            SDL_PushEvent(&event);
    2.19 +        }
    2.20 +    }
    2.21 +#endif /* !SDL_EVENTS_DISABLED */
    2.22 +}
    2.23 +
    2.24 +/*
    2.25 + * If there is an existing add event in the queue, it needs to be modified
    2.26 + * to have the right value for which, because the number of controllers in
    2.27 + * the system is now one less.
    2.28 + */
    2.29 +static void UpdateEventsForDeviceRemoval()
    2.30 +{
    2.31 +    int i, num_events;
    2.32 +    SDL_Event *events;
    2.33 +
    2.34 +    num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
    2.35 +    if (num_events <= 0) {
    2.36 +        return;
    2.37 +    }
    2.38 +
    2.39 +    events = SDL_stack_alloc(SDL_Event, num_events);
    2.40 +    if (!events) {
    2.41 +        return;
    2.42 +    }
    2.43 +
    2.44 +    num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
    2.45 +    for (i = 0; i < num_events; ++i) {
    2.46 +        --events[i].jdevice.which;
    2.47 +    }
    2.48 +    SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
    2.49 +
    2.50 +    SDL_stack_free(events);
    2.51 +}
    2.52 +
    2.53 +void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
    2.54 +{
    2.55 +#if !SDL_EVENTS_DISABLED
    2.56 +    SDL_Event event;
    2.57 +
    2.58 +    event.type = SDL_JOYDEVICEREMOVED;
    2.59 +
    2.60 +    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    2.61 +        event.jdevice.which = device_instance;
    2.62 +        if ( (SDL_EventOK == NULL) ||
    2.63 +             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    2.64 +            SDL_PushEvent(&event);
    2.65 +        }
    2.66 +    }
    2.67 +
    2.68 +    UpdateEventsForDeviceRemoval();
    2.69 +#endif /* !SDL_EVENTS_DISABLED */
    2.70 +}
    2.71 +
    2.72  int
    2.73  SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
    2.74  {
     3.1 --- a/src/joystick/SDL_joystick_c.h	Fri Aug 26 11:16:44 2016 -0700
     3.2 +++ b/src/joystick/SDL_joystick_c.h	Fri Aug 26 12:18:08 2016 -0700
     3.3 @@ -33,6 +33,8 @@
     3.4  
     3.5  
     3.6  /* Internal event queueing functions */
     3.7 +extern void SDL_PrivateJoystickAdded(int device_index);
     3.8 +extern void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance);
     3.9  extern int SDL_PrivateJoystickAxis(SDL_Joystick * joystick,
    3.10                                     Uint8 axis, Sint16 value);
    3.11  extern int SDL_PrivateJoystickBall(SDL_Joystick * joystick,
    3.12 @@ -41,8 +43,8 @@
    3.13                                    Uint8 hat, Uint8 value);
    3.14  extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
    3.15                                       Uint8 button, Uint8 state);
    3.16 -extern void SDL_PrivateJoystickBatteryLevel( SDL_Joystick * joystick,
    3.17 -    SDL_JoystickPowerLevel ePowerLevel );
    3.18 +extern void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick,
    3.19 +                                            SDL_JoystickPowerLevel ePowerLevel);
    3.20  
    3.21  /* Internal sanity checking functions */
    3.22  extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick);
     4.1 --- a/src/joystick/android/SDL_sysjoystick.c	Fri Aug 26 11:16:44 2016 -0700
     4.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Fri Aug 26 12:18:08 2016 -0700
     4.3 @@ -27,10 +27,6 @@
     4.4  #include "SDL_error.h"
     4.5  #include "SDL_events.h"
     4.6  
     4.7 -#if !SDL_EVENTS_DISABLED
     4.8 -#include "../../events/SDL_events_c.h"
     4.9 -#endif
    4.10 -
    4.11  #include "SDL_joystick.h"
    4.12  #include "SDL_hints.h"
    4.13  #include "SDL_assert.h"
    4.14 @@ -252,9 +248,6 @@
    4.15  {
    4.16      SDL_JoystickGUID guid;
    4.17      SDL_joylist_item *item;
    4.18 -#if !SDL_EVENTS_DISABLED
    4.19 -    SDL_Event event;
    4.20 -#endif
    4.21      
    4.22      if(JoystickByDeviceId(device_id) != NULL || name == NULL) {
    4.23          return -1;
    4.24 @@ -299,17 +292,7 @@
    4.25      /* Need to increment the joystick count before we post the event */
    4.26      ++numjoysticks;
    4.27  
    4.28 -#if !SDL_EVENTS_DISABLED
    4.29 -    event.type = SDL_JOYDEVICEADDED;
    4.30 -
    4.31 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    4.32 -        event.jdevice.which = (numjoysticks - 1);
    4.33 -        if ( (SDL_EventOK == NULL) ||
    4.34 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    4.35 -            SDL_PushEvent(&event);
    4.36 -        }
    4.37 -    }
    4.38 -#endif /* !SDL_EVENTS_DISABLED */
    4.39 +    SDL_PrivateJoystickAdded(numjoysticks - 1);
    4.40  
    4.41  #ifdef DEBUG_JOYSTICK
    4.42      SDL_Log("Added joystick %s with device_id %d", name, device_id);
    4.43 @@ -323,9 +306,6 @@
    4.44  {
    4.45      SDL_joylist_item *item = SDL_joylist;
    4.46      SDL_joylist_item *prev = NULL;
    4.47 -#if !SDL_EVENTS_DISABLED
    4.48 -    SDL_Event event;
    4.49 -#endif
    4.50      
    4.51      /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */
    4.52      while (item != NULL) {
    4.53 @@ -357,17 +337,7 @@
    4.54      /* Need to decrement the joystick count before we post the event */
    4.55      --numjoysticks;
    4.56  
    4.57 -#if !SDL_EVENTS_DISABLED
    4.58 -    event.type = SDL_JOYDEVICEREMOVED;
    4.59 -
    4.60 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    4.61 -        event.jdevice.which = item->device_instance;
    4.62 -        if ( (SDL_EventOK == NULL) ||
    4.63 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    4.64 -            SDL_PushEvent(&event);
    4.65 -        }
    4.66 -    }
    4.67 -#endif /* !SDL_EVENTS_DISABLED */
    4.68 +    SDL_PrivateJoystickRemoved(item->device_instance);
    4.69  
    4.70  #ifdef DEBUG_JOYSTICK
    4.71      SDL_Log("Removed joystick with device_id %d", device_id);
     5.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Fri Aug 26 11:16:44 2016 -0700
     5.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Fri Aug 26 12:18:08 2016 -0700
     5.3 @@ -34,9 +34,6 @@
     5.4  #include "SDL_sysjoystick_c.h"
     5.5  #include "SDL_events.h"
     5.6  #include "../../haptic/darwin/SDL_syshaptic_c.h"    /* For haptic hot plugging */
     5.7 -#if !SDL_EVENTS_DISABLED
     5.8 -#include "../../events/SDL_events_c.h"
     5.9 -#endif
    5.10  
    5.11  #define SDL_JOYSTICK_RUNLOOP_MODE CFSTR("SDLJoystick")
    5.12  
    5.13 @@ -154,21 +151,7 @@
    5.14      MacHaptic_MaybeRemoveDevice(device->ffservice);
    5.15  #endif
    5.16  
    5.17 -/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceRemoved()? */
    5.18 -#if !SDL_EVENTS_DISABLED
    5.19 -    {
    5.20 -        SDL_Event event;
    5.21 -        event.type = SDL_JOYDEVICEREMOVED;
    5.22 -
    5.23 -        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    5.24 -            event.jdevice.which = device->instance_id;
    5.25 -            if ((SDL_EventOK == NULL)
    5.26 -                || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    5.27 -                SDL_PushEvent(&event);
    5.28 -            }
    5.29 -        }
    5.30 -    }
    5.31 -#endif /* !SDL_EVENTS_DISABLED */
    5.32 +    SDL_PrivateJoystickRemoved(device->instance_id);
    5.33  }
    5.34  
    5.35  
    5.36 @@ -476,21 +459,7 @@
    5.37          ++device_index;  /* bump by one since we counted by pNext. */
    5.38      }
    5.39  
    5.40 -/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceAdded()? */
    5.41 -#if !SDL_EVENTS_DISABLED
    5.42 -    {
    5.43 -        SDL_Event event;
    5.44 -        event.type = SDL_JOYDEVICEADDED;
    5.45 -
    5.46 -        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    5.47 -            event.jdevice.which = device_index;
    5.48 -            if ((SDL_EventOK == NULL)
    5.49 -                || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    5.50 -                SDL_PushEvent(&event);
    5.51 -            }
    5.52 -        }
    5.53 -    }
    5.54 -#endif /* !SDL_EVENTS_DISABLED */
    5.55 +    SDL_PrivateJoystickAdded(device_index);
    5.56  }
    5.57  
    5.58  static SDL_bool
     6.1 --- a/src/joystick/emscripten/SDL_sysjoystick.c	Fri Aug 26 11:16:44 2016 -0700
     6.2 +++ b/src/joystick/emscripten/SDL_sysjoystick.c	Fri Aug 26 12:18:08 2016 -0700
     6.3 @@ -27,10 +27,6 @@
     6.4  #include "SDL_error.h"
     6.5  #include "SDL_events.h"
     6.6  
     6.7 -#if !SDL_EVENTS_DISABLED
     6.8 -#include "../../events/SDL_events_c.h"
     6.9 -#endif
    6.10 -
    6.11  #include "SDL_joystick.h"
    6.12  #include "SDL_hints.h"
    6.13  #include "SDL_assert.h"
    6.14 @@ -57,10 +53,6 @@
    6.15        return 1;
    6.16      }
    6.17  
    6.18 -#if !SDL_EVENTS_DISABLED
    6.19 -    SDL_Event event;
    6.20 -#endif
    6.21 -
    6.22      item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
    6.23      if (item == NULL) {
    6.24          return 1;
    6.25 @@ -105,20 +97,12 @@
    6.26      }
    6.27  
    6.28      ++numjoysticks;
    6.29 +
    6.30 +    SDL_PrivateJoystickAdded(numjoysticks - 1);
    6.31 +
    6.32  #ifdef DEBUG_JOYSTICK
    6.33      SDL_Log("Number of joysticks is %d", numjoysticks);
    6.34  #endif
    6.35 -#if !SDL_EVENTS_DISABLED
    6.36 -    event.type = SDL_JOYDEVICEADDED;
    6.37 -
    6.38 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    6.39 -        event.jdevice.which = numjoysticks - 1;
    6.40 -        if ( (SDL_EventOK == NULL) ||
    6.41 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    6.42 -            SDL_PushEvent(&event);
    6.43 -        }
    6.44 -    }
    6.45 -#endif /* !SDL_EVENTS_DISABLED */
    6.46  
    6.47  #ifdef DEBUG_JOYSTICK
    6.48      SDL_Log("Added joystick with index %d", item->index);
    6.49 @@ -132,9 +116,6 @@
    6.50  {
    6.51      SDL_joylist_item *item = SDL_joylist;
    6.52      SDL_joylist_item *prev = NULL;
    6.53 -#if !SDL_EVENTS_DISABLED
    6.54 -    SDL_Event event;
    6.55 -#endif
    6.56  
    6.57      while (item != NULL) {
    6.58          if (item->index == gamepadEvent->index) {
    6.59 @@ -165,17 +146,7 @@
    6.60      /* Need to decrement the joystick count before we post the event */
    6.61      --numjoysticks;
    6.62  
    6.63 -#if !SDL_EVENTS_DISABLED
    6.64 -    event.type = SDL_JOYDEVICEREMOVED;
    6.65 -
    6.66 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    6.67 -        event.jdevice.which = item->device_instance;
    6.68 -        if ( (SDL_EventOK == NULL) ||
    6.69 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    6.70 -            SDL_PushEvent(&event);
    6.71 -        }
    6.72 -    }
    6.73 -#endif /* !SDL_EVENTS_DISABLED */
    6.74 +	SDL_PrivateJoystickRemoved(item->device_instance);
    6.75  
    6.76  #ifdef DEBUG_JOYSTICK
    6.77      SDL_Log("Removed joystick with id %d", item->device_instance);
     7.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Fri Aug 26 11:16:44 2016 -0700
     7.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Fri Aug 26 12:18:08 2016 -0700
     7.3 @@ -32,10 +32,6 @@
     7.4  #include "../SDL_sysjoystick.h"
     7.5  #include "../SDL_joystick_c.h"
     7.6  
     7.7 -#if !SDL_EVENTS_DISABLED
     7.8 -#include "../../events/SDL_events_c.h"
     7.9 -#endif
    7.10 -
    7.11  #import <CoreMotion/CoreMotion.h>
    7.12  
    7.13  #ifdef SDL_JOYSTICK_MFI
    7.14 @@ -127,9 +123,6 @@
    7.15  SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
    7.16  {
    7.17      SDL_JoystickDeviceItem *device = deviceList;
    7.18 -#if !SDL_EVENTS_DISABLED
    7.19 -    SDL_Event event;
    7.20 -#endif
    7.21  
    7.22      while (device != NULL) {
    7.23          if (device->controller == controller) {
    7.24 @@ -172,17 +165,7 @@
    7.25  
    7.26      ++numjoysticks;
    7.27  
    7.28 -#if !SDL_EVENTS_DISABLED
    7.29 -    event.type = SDL_JOYDEVICEADDED;
    7.30 -
    7.31 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    7.32 -        event.jdevice.which = numjoysticks - 1;
    7.33 -        if ((SDL_EventOK == NULL) ||
    7.34 -            (*SDL_EventOK)(SDL_EventOKParam, &event)) {
    7.35 -            SDL_PushEvent(&event);
    7.36 -        }
    7.37 -    }
    7.38 -#endif /* !SDL_EVENTS_DISABLED */
    7.39 +    SDL_PrivateJoystickAdded(numjoysticks - 1);
    7.40  }
    7.41  
    7.42  static SDL_JoystickDeviceItem *
    7.43 @@ -191,9 +174,6 @@
    7.44      SDL_JoystickDeviceItem *prev = NULL;
    7.45      SDL_JoystickDeviceItem *next = NULL;
    7.46      SDL_JoystickDeviceItem *item = deviceList;
    7.47 -#if !SDL_EVENTS_DISABLED
    7.48 -    SDL_Event event;
    7.49 -#endif
    7.50  
    7.51      if (device == NULL) {
    7.52          return NULL;
    7.53 @@ -234,17 +214,7 @@
    7.54  
    7.55      --numjoysticks;
    7.56  
    7.57 -#if !SDL_EVENTS_DISABLED
    7.58 -    event.type = SDL_JOYDEVICEREMOVED;
    7.59 -
    7.60 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    7.61 -        event.jdevice.which = device->instance_id;
    7.62 -        if ((SDL_EventOK == NULL) ||
    7.63 -            (*SDL_EventOK)(SDL_EventOKParam, &event)) {
    7.64 -            SDL_PushEvent(&event);
    7.65 -        }
    7.66 -    }
    7.67 -#endif /* !SDL_EVENTS_DISABLED */
    7.68 +	SDL_PrivateJoystickRemoved(device->instance_id);
    7.69  
    7.70      SDL_free(device->name);
    7.71      SDL_free(device);
     8.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Fri Aug 26 11:16:44 2016 -0700
     8.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Fri Aug 26 12:18:08 2016 -0700
     8.3 @@ -42,11 +42,6 @@
     8.4  #include "../SDL_joystick_c.h"
     8.5  #include "SDL_sysjoystick_c.h"
     8.6  
     8.7 -/* !!! FIXME: move this somewhere else. */
     8.8 -#if !SDL_EVENTS_DISABLED
     8.9 -#include "../../events/SDL_events_c.h"
    8.10 -#endif
    8.11 -
    8.12  /* This isn't defined in older Linux kernel headers */
    8.13  #ifndef SYN_DROPPED
    8.14  #define SYN_DROPPED 3
    8.15 @@ -176,9 +171,6 @@
    8.16      char namebuf[128];
    8.17      SDL_JoystickGUID guid;
    8.18      SDL_joylist_item *item;
    8.19 -#if !SDL_EVENTS_DISABLED
    8.20 -    SDL_Event event;
    8.21 -#endif
    8.22  
    8.23      if (path == NULL) {
    8.24          return -1;
    8.25 @@ -239,18 +231,7 @@
    8.26      /* Need to increment the joystick count before we post the event */
    8.27      ++numjoysticks;
    8.28  
    8.29 -    /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
    8.30 -#if !SDL_EVENTS_DISABLED
    8.31 -    event.type = SDL_JOYDEVICEADDED;
    8.32 -
    8.33 -    if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    8.34 -        event.jdevice.which = (numjoysticks - 1);
    8.35 -        if ( (SDL_EventOK == NULL) ||
    8.36 -             (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    8.37 -            SDL_PushEvent(&event);
    8.38 -        }
    8.39 -    }
    8.40 -#endif /* !SDL_EVENTS_DISABLED */
    8.41 +    SDL_PrivateJoystickAdded(numjoysticks - 1);
    8.42  
    8.43      return numjoysticks;
    8.44  }
    8.45 @@ -262,9 +243,6 @@
    8.46  {
    8.47      SDL_joylist_item *item;
    8.48      SDL_joylist_item *prev = NULL;
    8.49 -#if !SDL_EVENTS_DISABLED
    8.50 -    SDL_Event event;
    8.51 -#endif
    8.52  
    8.53      if (path == NULL) {
    8.54          return -1;
    8.55 @@ -290,30 +268,7 @@
    8.56              /* Need to decrement the joystick count before we post the event */
    8.57              --numjoysticks;
    8.58  
    8.59 -            /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
    8.60 -#if !SDL_EVENTS_DISABLED
    8.61 -            event.type = SDL_JOYDEVICEREMOVED;
    8.62 -
    8.63 -            if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    8.64 -				SDL_Event peeped;
    8.65 -
    8.66 -				/* If there is an existing add event in the queue, it
    8.67 -				 * needs to be modified to have the right value for which,
    8.68 -				 * because the number of controllers in the system is now
    8.69 -				 * one less.
    8.70 -				 */
    8.71 -				if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED) > 0) {
    8.72 -					peeped.jdevice.which--;
    8.73 -					SDL_PushEvent(&peeped);
    8.74 -				}
    8.75 -
    8.76 -                event.jdevice.which = item->device_instance;
    8.77 -                if ( (SDL_EventOK == NULL) ||
    8.78 -                     (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
    8.79 -                    SDL_PushEvent(&event);
    8.80 -                }
    8.81 -            }
    8.82 -#endif /* !SDL_EVENTS_DISABLED */
    8.83 +            SDL_PrivateJoystickRemoved(item->device_instance);
    8.84  
    8.85              SDL_free(item->path);
    8.86              SDL_free(item->name);
     9.1 --- a/src/joystick/windows/SDL_windowsjoystick.c	Fri Aug 26 11:16:44 2016 -0700
     9.2 +++ b/src/joystick/windows/SDL_windowsjoystick.c	Fri Aug 26 12:18:08 2016 -0700
     9.3 @@ -42,9 +42,6 @@
     9.4  #include "SDL_joystick.h"
     9.5  #include "../SDL_sysjoystick.h"
     9.6  #include "../../thread/SDL_systhread.h"
     9.7 -#if !SDL_EVENTS_DISABLED
     9.8 -#include "../../events/SDL_events_c.h"
     9.9 -#endif
    9.10  #include "../../core/windows/SDL_windows.h"
    9.11  #if !defined(__WINRT__)
    9.12  #include <dbt.h>
    9.13 @@ -327,9 +324,6 @@
    9.14  SDL_SYS_JoystickDetect()
    9.15  {
    9.16      JoyStick_DeviceData *pCurList = NULL;
    9.17 -#if !SDL_EVENTS_DISABLED
    9.18 -    SDL_Event event;
    9.19 -#endif
    9.20  
    9.21      /* only enum the devices if the joystick thread told us something changed */
    9.22      if (!s_bDeviceAdded && !s_bDeviceRemoved) {
    9.23 @@ -361,17 +355,7 @@
    9.24              SDL_DINPUT_MaybeRemoveDevice(&pCurList->dxdevice);
    9.25          }
    9.26  
    9.27 -#if !SDL_EVENTS_DISABLED
    9.28 -        SDL_zero(event);
    9.29 -        event.type = SDL_JOYDEVICEREMOVED;
    9.30 -
    9.31 -        if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    9.32 -            event.jdevice.which = pCurList->nInstanceID;
    9.33 -            if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    9.34 -                SDL_PushEvent(&event);
    9.35 -            }
    9.36 -        }
    9.37 -#endif /* !SDL_EVENTS_DISABLED */
    9.38 +        SDL_PrivateJoystickRemoved(pCurList->nInstanceID);
    9.39  
    9.40          pListNext = pCurList->pNext;
    9.41          SDL_free(pCurList->joystickname);
    9.42 @@ -392,17 +376,8 @@
    9.43                      SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice);
    9.44                  }
    9.45  
    9.46 -#if !SDL_EVENTS_DISABLED
    9.47 -                SDL_zero(event);
    9.48 -                event.type = SDL_JOYDEVICEADDED;
    9.49 +                SDL_PrivateJoystickAdded(device_index);
    9.50  
    9.51 -                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    9.52 -                    event.jdevice.which = device_index;
    9.53 -                    if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    9.54 -                        SDL_PushEvent(&event);
    9.55 -                    }
    9.56 -                }
    9.57 -#endif /* !SDL_EVENTS_DISABLED */
    9.58                  pNewJoystick->send_add_event = SDL_FALSE;
    9.59              }
    9.60              device_index++;