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.
This commit is contained in:
Cameron Gutman 2021-11-07 16:00:47 -06:00
parent 74f35a7cbd
commit f6dc47caef
2 changed files with 12 additions and 2 deletions

View file

@ -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;
}

View file

@ -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;
}