WGI/DInput: Fix SDL_IsXInputDevice() checks when RawInput is enabled Enabling the RawInput backend causes SDL_XINPUT_Enabled() to return false. That causes WGI and DInput backends to take ownership of XInput-compatible controllers, because they think there's no XInput-specific backend enabled. In WGI's case, it will actually race with RawInput to open the device. By properly excluding XInput devices from WGI, we can ensure that the sets of devices managed by WGI and RawInput don't intersect. This makes the race harmless, since they'll never both go after the same device.
diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c
index f334c00..8f01474 100644
--- a/src/joystick/windows/SDL_dinputjoystick.c
+++ b/src/joystick/windows/SDL_dinputjoystick.c
@@ -238,7 +238,12 @@ SDL_IsXInputDevice(Uint16 vendor_id, Uint16 product_id, const char* hidPath)
{
SDL_GameControllerType type;
- if (!SDL_XINPUT_Enabled()) {
+ /* XInput and RawInput backends will pick up XInput-compatible devices */
+ if (!SDL_XINPUT_Enabled()
+#ifdef SDL_JOYSTICK_RAWINPUT
+ && !RAWINPUT_IsEnabled()
+#endif
+ ) {
return SDL_FALSE;
}
diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c
index af623c8..6d7e1d7 100644
--- a/src/joystick/windows/SDL_windows_gaming_input.c
+++ b/src/joystick/windows/SDL_windows_gaming_input.c
@@ -98,7 +98,12 @@ SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
UINT i, raw_device_count = 0;
LONG vidpid = MAKELONG(vendor, product);
- if (!SDL_XINPUT_Enabled()) {
+ /* XInput and RawInput backends will pick up XInput-compatible devices */
+ if (!SDL_XINPUT_Enabled()
+#ifdef SDL_JOYSTICK_RAWINPUT
+ && !RAWINPUT_IsEnabled()
+#endif
+ ) {
return SDL_FALSE;
}