Fixed Xbox One Elite Series 2 showing up as 2 devices in Bluetooth mode on Windows
authorSam Lantinga
Wed, 20 Nov 2019 08:43:24 -0800
changeset 1326133390f96674c
parent 13260 688fd43988a5
child 13262 d6decc5d2464
Fixed Xbox One Elite Series 2 showing up as 2 devices in Bluetooth mode on Windows
src/joystick/windows/SDL_dinputjoystick.c
     1.1 --- a/src/joystick/windows/SDL_dinputjoystick.c	Wed Nov 20 02:47:40 2019 +0300
     1.2 +++ b/src/joystick/windows/SDL_dinputjoystick.c	Wed Nov 20 08:43:24 2019 -0800
     1.3 @@ -504,8 +504,7 @@
     1.4          return DIENUM_CONTINUE; /* better luck next time? */
     1.5      }
     1.6  
     1.7 -    SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance,
     1.8 -        sizeof(DIDEVICEINSTANCE));
     1.9 +    SDL_memcpy(&pNewJoystick->dxdevice, pdidInstance, sizeof(DIDEVICEINSTANCE));
    1.10  
    1.11      SDL_memset(pNewJoystick->guid.data, 0, sizeof(pNewJoystick->guid.data));
    1.12  
    1.13 @@ -529,7 +528,17 @@
    1.14          SDL_strlcpy((char*)guid16, pNewJoystick->joystickname, sizeof(pNewJoystick->guid.data) - 4);
    1.15      }
    1.16  
    1.17 +    if (SDL_strstr(pNewJoystick->joystickname, " XINPUT ") != NULL) {
    1.18 +        /* This is a duplicate interface for a controller that will show up with XInput,
    1.19 +           e.g. Xbox One Elite Series 2 in Bluetooth mode.
    1.20 +         */
    1.21 +        SDL_free(pNewJoystick->joystickname);
    1.22 +        SDL_free(pNewJoystick);
    1.23 +        return DIENUM_CONTINUE;
    1.24 +    }
    1.25 +
    1.26      if (SDL_ShouldIgnoreJoystick(pNewJoystick->joystickname, pNewJoystick->guid)) {
    1.27 +        SDL_free(pNewJoystick->joystickname);
    1.28          SDL_free(pNewJoystick);
    1.29          return DIENUM_CONTINUE;
    1.30      }
    1.31 @@ -537,6 +546,7 @@
    1.32  #ifdef SDL_JOYSTICK_HIDAPI
    1.33      if (HIDAPI_IsDevicePresent(vendor, product, 0, pNewJoystick->joystickname)) {
    1.34          /* The HIDAPI driver is taking care of this device */
    1.35 +        SDL_free(pNewJoystick->joystickname);
    1.36          SDL_free(pNewJoystick);
    1.37          return DIENUM_CONTINUE;
    1.38      }