From 81b48de3f54150310cbf4c887fba756de5668be4 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 7 Oct 2024 16:14:57 -0700
Subject: [PATCH] Fixed VID/PID list parsing of
SDL_HINT_GAMECONTROLLER_SENSOR_FUSION
Fixes https://github.com/libsdl-org/SDL/issues/11118
---
src/joystick/SDL_joystick.c | 47 ++++++++++++++++---------------------
1 file changed, 20 insertions(+), 27 deletions(-)
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index fcc6565ec11ce..e8cd6fd9e665e 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -888,9 +888,6 @@ static bool IsROGAlly(SDL_Joystick *joystick)
static bool ShouldAttemptSensorFusion(SDL_Joystick *joystick, bool *invert_sensors)
{
- const char *hint;
- int hint_value;
-
SDL_AssertJoysticksLocked();
*invert_sensors = false;
@@ -905,30 +902,26 @@ static bool ShouldAttemptSensorFusion(SDL_Joystick *joystick, bool *invert_senso
return false;
}
- hint = SDL_GetHint(SDL_HINT_GAMECONTROLLER_SENSOR_FUSION);
- hint_value = SDL_GetStringInteger(hint, -1);
- if (hint_value > 0) {
- return true;
- }
- if (hint_value == 0) {
- return false;
- }
-
- if (hint) {
- SDL_vidpid_list gamepads;
- SDL_GUID guid;
- Uint16 vendor, product;
- bool enabled;
- SDL_zero(gamepads);
-
- // See if the gamepad is in our list of devices to enable
- guid = SDL_GetJoystickGUID(joystick);
- SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL, NULL);
- SDL_LoadVIDPIDListFromHints(&gamepads, hint, NULL);
- enabled = SDL_VIDPIDInList(vendor, product, &gamepads);
- SDL_FreeVIDPIDList(&gamepads);
- if (enabled) {
- return true;
+ const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLER_SENSOR_FUSION);
+ if (hint && *hint) {
+ if (*hint == '@' || SDL_strncmp(hint, "0x", 2) == 0) {
+ SDL_vidpid_list gamepads;
+ SDL_GUID guid;
+ Uint16 vendor, product;
+ bool enabled;
+ SDL_zero(gamepads);
+
+ // See if the gamepad is in our list of devices to enable
+ guid = SDL_GetJoystickGUID(joystick);
+ SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL, NULL);
+ SDL_LoadVIDPIDListFromHints(&gamepads, hint, NULL);
+ enabled = SDL_VIDPIDInList(vendor, product, &gamepads);
+ SDL_FreeVIDPIDList(&gamepads);
+ if (enabled) {
+ return true;
+ }
+ } else {
+ return SDL_GetStringBoolean(hint, false);
}
}