From ce8411c5877537a49aa1ca1f38e2a89c174c0993 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 20 Nov 2019 08:43:24 -0800 Subject: [PATCH] Fixed Xbox One Elite Series 2 showing up as 2 devices in Bluetooth mode on Windows --- src/joystick/windows/SDL_dinputjoystick.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c index f03c80096..2e651c15a 100644 --- a/src/joystick/windows/SDL_dinputjoystick.c +++ b/src/joystick/windows/SDL_dinputjoystick.c @@ -504,8 +504,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) return DIENUM_CONTINUE; /* better luck next time? */ } - SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance, - sizeof(DIDEVICEINSTANCE)); + SDL_memcpy(&pNewJoystick->dxdevice, pdidInstance, sizeof(DIDEVICEINSTANCE)); SDL_memset(pNewJoystick->guid.data, 0, sizeof(pNewJoystick->guid.data)); @@ -529,7 +528,17 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) SDL_strlcpy((char*)guid16, pNewJoystick->joystickname, sizeof(pNewJoystick->guid.data) - 4); } + if (SDL_strstr(pNewJoystick->joystickname, " XINPUT ") != NULL) { + /* This is a duplicate interface for a controller that will show up with XInput, + e.g. Xbox One Elite Series 2 in Bluetooth mode. + */ + SDL_free(pNewJoystick->joystickname); + SDL_free(pNewJoystick); + return DIENUM_CONTINUE; + } + if (SDL_ShouldIgnoreJoystick(pNewJoystick->joystickname, pNewJoystick->guid)) { + SDL_free(pNewJoystick->joystickname); SDL_free(pNewJoystick); return DIENUM_CONTINUE; } @@ -537,6 +546,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) #ifdef SDL_JOYSTICK_HIDAPI if (HIDAPI_IsDevicePresent(vendor, product, 0, pNewJoystick->joystickname)) { /* The HIDAPI driver is taking care of this device */ + SDL_free(pNewJoystick->joystickname); SDL_free(pNewJoystick); return DIENUM_CONTINUE; }