Fix updating SDL_update_joysticks and SDL_update_sensors in response to hint changes Hint callbacks are called before the actual value in the hint is changed, so the functions SDL_AutoUpdateJoysticksChanged and SDL_AutoUpdateSensorsChanged were not actually properly updating their respective variables in repsonse to their auto update hint changing. Instead, we pull the new hint value out of the value passed into the callback and use that to update the variables. Assume true on a null value as that was the previous behavior and it matches with the default values of SDL_update_joysticks/SDL_update_sensors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 6e5ee31..fa58ed1 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -102,9 +102,9 @@ static struct
static SDL_bool SDL_update_joysticks = SDL_TRUE;
static void
-SDL_CalculateShouldUpdateJoysticks()
+SDL_CalculateShouldUpdateJoysticks(SDL_bool hint_value)
{
- if (SDL_GetHintBoolean(SDL_HINT_AUTO_UPDATE_JOYSTICKS, SDL_TRUE) &&
+ if (hint_value &&
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
SDL_update_joysticks = SDL_TRUE;
} else {
@@ -115,7 +115,7 @@ SDL_CalculateShouldUpdateJoysticks()
static void SDLCALL
SDL_AutoUpdateJoysticksChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
- SDL_CalculateShouldUpdateJoysticks();
+ SDL_CalculateShouldUpdateJoysticks(SDL_GetStringBoolean(hint, SDL_TRUE));
}
#endif /* !SDL_JOYSTICK_DISABLED */
@@ -126,9 +126,9 @@ SDL_AutoUpdateJoysticksChanged(void *userdata, const char *name, const char *old
static SDL_bool SDL_update_sensors = SDL_TRUE;
static void
-SDL_CalculateShouldUpdateSensors()
+SDL_CalculateShouldUpdateSensors(SDL_bool hint_value)
{
- if (SDL_GetHintBoolean(SDL_HINT_AUTO_UPDATE_SENSORS, SDL_TRUE) &&
+ if (hint_value &&
!SDL_disabled_events[SDL_SENSORUPDATE >> 8]) {
SDL_update_sensors = SDL_TRUE;
} else {
@@ -139,7 +139,7 @@ SDL_CalculateShouldUpdateSensors()
static void SDLCALL
SDL_AutoUpdateSensorsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
- SDL_CalculateShouldUpdateSensors();
+ SDL_CalculateShouldUpdateSensors(SDL_GetStringBoolean(hint, SDL_TRUE));
}
#endif /* !SDL_SENSOR_DISABLED */
@@ -1306,10 +1306,10 @@ SDL_EventState(Uint32 type, int state)
}
#if !SDL_JOYSTICK_DISABLED
- SDL_CalculateShouldUpdateJoysticks();
+ SDL_CalculateShouldUpdateJoysticks(SDL_GetHintBoolean(SDL_HINT_AUTO_UPDATE_JOYSTICKS, SDL_TRUE));
#endif
#if !SDL_SENSOR_DISABLED
- SDL_CalculateShouldUpdateSensors();
+ SDL_CalculateShouldUpdateSensors(SDL_GetHintBoolean(SDL_HINT_AUTO_UPDATE_SENSORS, SDL_TRUE));
#endif
}