Find out if a controller is wireless using WGI (thanks @DJm00n!) Confirmed using an Xbox Series X controller over USB and Bluetooth Fixes https://github.com/libsdl-org/SDL/issues/6322
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c
index 863b3f5..deec84b 100644
--- a/src/joystick/windows/SDL_windows_gaming_input.c
+++ b/src/joystick/windows/SDL_windows_gaming_input.c
@@ -265,6 +265,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
if (SUCCEEDED(hr)) {
char *name = NULL;
SDL_JoystickGUID guid;
+ Uint16 bus = SDL_HARDWARE_BUS_USB;
Uint16 vendor = 0;
Uint16 product = 0;
Uint16 version = 0;
@@ -315,6 +316,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
__x_ABI_CWindows_CGaming_CInput_CIFlightStick *flight_stick = NULL;
__x_ABI_CWindows_CGaming_CInput_CIGamepad *gamepad = NULL;
__x_ABI_CWindows_CGaming_CInput_CIRacingWheel *racing_wheel = NULL;
+ boolean wireless;
if (wgi.gamepad_statics2 && SUCCEEDED(__x_ABI_CWindows_CGaming_CInput_CIGamepadStatics2_FromGameController(wgi.gamepad_statics2, gamecontroller, &gamepad)) && gamepad) {
type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
@@ -329,11 +331,16 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
type = SDL_JOYSTICK_TYPE_WHEEL;
__x_ABI_CWindows_CGaming_CInput_CIRacingWheel_Release(racing_wheel);
}
+
+ hr = __x_ABI_CWindows_CGaming_CInput_CIGameController_get_IsWireless(gamecontroller, &wireless);
+ if (SUCCEEDED(hr) && wireless) {
+ bus = SDL_HARDWARE_BUS_BLUETOOTH;
+ }
+
__x_ABI_CWindows_CGaming_CInput_CIGameController_Release(gamecontroller);
}
- /* FIXME: Is there any way to tell whether this is a Bluetooth device? */
- guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_USB, vendor, product, version, name, 'w', (Uint8)type);
+ guid = SDL_CreateJoystickGUID(bus, vendor, product, version, name, 'w', (Uint8) type);
#ifdef SDL_JOYSTICK_HIDAPI
if (!ignore_joystick && HIDAPI_IsDevicePresent(vendor, product, version, name)) {