Skip to content

Commit

Permalink
Fixed bug 2950 - wrong axes values are set on joystick initialization
Browse files Browse the repository at this point in the history
Edward Rudd

Device: Logitech Rumble Gamepad F510 in Xinput mode.

Upon opening the joystick the values of the axes are queried via PollAllValues are not actually set on the device all the time.

This can easily be seen in the testjoystick or testgamecontroller test programs,as the testjoystick shows all axes in the center until one 'tickles' the triggers., and the testgamecontroller will show the triggers as 'on' until on 'tickles' the triggers.

Upon further research the culprit is the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint. In the default value events are ignored until there is an active window, Thus in cases where the joystick system is initialized and controllers opened before the initial window is created & focuses, the initial values will be incorrect.

Here is my current workaround in the game I'm working on porting..

SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
SDL_GameController* gamepad = SDL_GameControllerOpen(index);
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "0");
  • Loading branch information
slouken committed Aug 13, 2017
1 parent 7bab291 commit 059d9e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/joystick/SDL_joystick.c
Expand Up @@ -31,6 +31,7 @@
#if !SDL_EVENTS_DISABLED
#include "../events/SDL_events_c.h"
#endif
#include "../video/SDL_sysvideo.h"


static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE;
Expand Down Expand Up @@ -582,16 +583,10 @@ SDL_PrivateJoystickShouldIgnoreEvent()
return SDL_FALSE;
}

if (SDL_WasInit(SDL_INIT_VIDEO)) {
if (SDL_GetKeyboardFocus() == NULL) {
/* Video is initialized and we don't have focus, ignore the event. */
return SDL_TRUE;
} else {
return SDL_FALSE;
}
if (SDL_HasWindows() && SDL_GetKeyboardFocus() == NULL) {
/* We have windows but we don't have focus, ignore the event. */
return SDL_TRUE;
}

/* Video subsystem wasn't initialized, always allow the event */
return SDL_FALSE;
}

Expand Down
1 change: 1 addition & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -403,6 +403,7 @@ extern void *SDL_GetDisplayDriverData( int displayIndex );
extern void SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor);

extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
extern SDL_bool SDL_HasWindows();

extern void SDL_OnWindowShown(SDL_Window * window);
extern void SDL_OnWindowHidden(SDL_Window * window);
Expand Down
6 changes: 6 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -1606,6 +1606,12 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
return 0;
}

SDL_bool
SDL_HasWindows()
{
return (_this && _this->windows != NULL);
}

Uint32
SDL_GetWindowID(SDL_Window * window)
{
Expand Down

0 comments on commit 059d9e4

Please sign in to comment.