Made the background controller setting not require a restart

This commit is contained in:
MysterD 2023-03-31 22:05:09 -07:00
parent 92d9c1edab
commit 4839adf289
1 changed files with 9 additions and 0 deletions

View File

@ -43,6 +43,8 @@ static bool haptics_enabled;
static SDL_GameController *sdl_cntrl; static SDL_GameController *sdl_cntrl;
static SDL_Haptic *sdl_haptic; static SDL_Haptic *sdl_haptic;
static bool sBackgroundGamepad = false;
static u32 num_joy_binds = 0; static u32 num_joy_binds = 0;
static u32 num_mouse_binds = 0; static u32 num_mouse_binds = 0;
static u32 joy_binds[MAX_JOYBINDS][2]; static u32 joy_binds[MAX_JOYBINDS][2];
@ -103,6 +105,7 @@ static void controller_sdl_init(void) {
if (configBackgroundGamepad) { if (configBackgroundGamepad) {
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
} }
sBackgroundGamepad = configBackgroundGamepad;
if (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS) != 0) { if (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS) != 0) {
fprintf(stderr, "SDL init error: %s\n", SDL_GetError()); fprintf(stderr, "SDL init error: %s\n", SDL_GetError());
@ -213,6 +216,12 @@ static void controller_sdl_read(OSContPad *pad) {
#endif #endif
} }
if (configBackgroundGamepad != sBackgroundGamepad) {
sBackgroundGamepad = configBackgroundGamepad;
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, sBackgroundGamepad ? "1" : "0");
}
SDL_GameControllerUpdate(); SDL_GameControllerUpdate();
if (sdl_cntrl != NULL && !SDL_GameControllerGetAttached(sdl_cntrl)) { if (sdl_cntrl != NULL && !SDL_GameControllerGetAttached(sdl_cntrl)) {