|
@@ -105,6 +105,35 @@ struct _SDL_GameController
|
|
int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value);
|
|
int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value);
|
|
int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);
|
|
int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * If there is an existing add event in the queue, it needs to be modified
|
|
|
|
+ * to have the right value for which, because the number of controllers in
|
|
|
|
+ * the system is now one less.
|
|
|
|
+ */
|
|
|
|
+static void UpdateEventsForDeviceRemoval()
|
|
|
|
+{
|
|
|
|
+ int i, num_events;
|
|
|
|
+ SDL_Event *events;
|
|
|
|
+
|
|
|
|
+ num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
|
|
|
|
+ if (num_events <= 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ events = SDL_stack_alloc(SDL_Event, num_events);
|
|
|
|
+ if (!events) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
|
|
|
|
+ for (i = 0; i < num_events; ++i) {
|
|
|
|
+ --events[i].cdevice.which;
|
|
|
|
+ }
|
|
|
|
+ SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
|
|
|
|
+
|
|
|
|
+ SDL_stack_free(events);
|
|
|
|
+}
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Event filter to fire controller events from joystick ones
|
|
* Event filter to fire controller events from joystick ones
|
|
*/
|
|
*/
|
|
@@ -222,22 +251,13 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
|
|
SDL_GameController *controllerlist = SDL_gamecontrollers;
|
|
SDL_GameController *controllerlist = SDL_gamecontrollers;
|
|
while (controllerlist) {
|
|
while (controllerlist) {
|
|
if (controllerlist->joystick->instance_id == event->jdevice.which) {
|
|
if (controllerlist->joystick->instance_id == event->jdevice.which) {
|
|
- SDL_Event peeped;
|
|
|
|
SDL_Event deviceevent;
|
|
SDL_Event deviceevent;
|
|
|
|
|
|
- /* If there is an existing add event in the queue, it
|
|
|
|
- * needs to be modified to have the right value for which,
|
|
|
|
- * because the number of controllers in the system is now
|
|
|
|
- * one less.
|
|
|
|
- */
|
|
|
|
- if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED) > 0) {
|
|
|
|
- peeped.jdevice.which--;
|
|
|
|
- SDL_PushEvent(&peeped);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
|
|
deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
|
|
deviceevent.cdevice.which = event->jdevice.which;
|
|
deviceevent.cdevice.which = event->jdevice.which;
|
|
SDL_PushEvent(&deviceevent);
|
|
SDL_PushEvent(&deviceevent);
|
|
|
|
+
|
|
|
|
+ UpdateEventsForDeviceRemoval();
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
controllerlist = controllerlist->next;
|
|
controllerlist = controllerlist->next;
|