Skip to content

Commit 364abb8

Browse files
committed
Improved XInput controller detection
Sometimes we'll get a Windows.Gaming.Input callback before the raw input device is even in the list, so try some other methods to better detect XInput devices. (cherry picked from commit 55a7587)
1 parent 1650c02 commit 364abb8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/joystick/windows/SDL_windows_gaming_input.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extern SDL_bool SDL_XINPUT_Enabled(void);
110110
extern SDL_bool SDL_DINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version);
111111

112112

113-
static SDL_bool SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
113+
static SDL_bool SDL_IsXInputDevice(Uint16 vendor, Uint16 product, const char* name)
114114
{
115115
#if defined(SDL_JOYSTICK_XINPUT) || defined(SDL_JOYSTICK_RAWINPUT)
116116
PRAWINPUTDEVICELIST raw_devices = NULL;
@@ -126,6 +126,13 @@ static SDL_bool SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
126126
return SDL_FALSE;
127127
}
128128

129+
/* Sometimes we'll get a Windows.Gaming.Input callback before the raw input device is even in the list,
130+
* so try to do some checks up front to catch these cases. */
131+
if (SDL_IsJoystickXboxOne(vendor, product) ||
132+
(name && SDL_strncmp(name, "Xbox ", 5) == 0)) {
133+
return SDL_TRUE;
134+
}
135+
129136
/* Go through RAWINPUT (WinXP and later) to find HID devices. */
130137
if ((GetRawInputDeviceList(NULL, &raw_device_count, sizeof(RAWINPUTDEVICELIST)) == -1) || (!raw_device_count)) {
131138
return SDL_FALSE; /* oh well. */
@@ -508,7 +515,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
508515
ignore_joystick = SDL_TRUE;
509516
}
510517

511-
if (!ignore_joystick && SDL_IsXInputDevice(vendor, product)) {
518+
if (!ignore_joystick && SDL_IsXInputDevice(vendor, product, name)) {
512519
ignore_joystick = SDL_TRUE;
513520
}
514521

0 commit comments

Comments
 (0)