commit 1170112da3776fdb06425f62d57b63144c33dc51
authorSam Lantinga <slouken@libsdl.org>
Fri, 26 Aug 2016 11:16:44 -0700
changeset 102253134026517cb
parent 10224 d1c27f616999
child 10226 cb13d22b7f09
commit 1170112da3776fdb06425f62d57b63144c33dc51
Author: James Zipperer <james.zipperer@synapse.com>
Date: Sun Aug 21 01:19:19 2016 -0700

bugfix for controller / joystick add / remove being in the event queue at the same time
src/joystick/SDL_gamecontroller.c
src/joystick/linux/SDL_sysjoystick.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Thu Aug 25 22:31:44 2016 +0200
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Fri Aug 26 11:16:44 2016 -0700
     1.3 @@ -222,7 +222,19 @@
     1.4              SDL_GameController *controllerlist = SDL_gamecontrollers;
     1.5              while (controllerlist) {
     1.6                  if (controllerlist->joystick->instance_id == event->jdevice.which) {
     1.7 +					SDL_Event peeped;
     1.8                      SDL_Event deviceevent;
     1.9 +
    1.10 +					/* If there is an existing add event in the queue, it
    1.11 +					 * needs to be modified to have the right value for which,
    1.12 +					 * because the number of controllers in the system is now
    1.13 +					 * one less.
    1.14 +					 */
    1.15 +					if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED) > 0) {
    1.16 +						peeped.jdevice.which--;
    1.17 +						SDL_PushEvent(&peeped);
    1.18 +					}
    1.19 +
    1.20                      deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
    1.21                      deviceevent.cdevice.which = event->jdevice.which;
    1.22                      SDL_PushEvent(&deviceevent);
     2.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Thu Aug 25 22:31:44 2016 +0200
     2.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Fri Aug 26 11:16:44 2016 -0700
     2.3 @@ -295,6 +295,18 @@
     2.4              event.type = SDL_JOYDEVICEREMOVED;
     2.5  
     2.6              if (SDL_GetEventState(event.type) == SDL_ENABLE) {
     2.7 +				SDL_Event peeped;
     2.8 +
     2.9 +				/* If there is an existing add event in the queue, it
    2.10 +				 * needs to be modified to have the right value for which,
    2.11 +				 * because the number of controllers in the system is now
    2.12 +				 * one less.
    2.13 +				 */
    2.14 +				if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED) > 0) {
    2.15 +					peeped.jdevice.which--;
    2.16 +					SDL_PushEvent(&peeped);
    2.17 +				}
    2.18 +
    2.19                  event.jdevice.which = item->device_instance;
    2.20                  if ( (SDL_EventOK == NULL) ||
    2.21                       (*SDL_EventOK) (SDL_EventOKParam, &event) ) {