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
main
Sam Lantinga 2022-10-03 11:00:50 -07:00
parent 321ca1091d
commit 3607f8316f
1 changed files with 9 additions and 2 deletions

View File

@ -265,6 +265,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
char *name = NULL; char *name = NULL;
SDL_JoystickGUID guid; SDL_JoystickGUID guid;
Uint16 bus = SDL_HARDWARE_BUS_USB;
Uint16 vendor = 0; Uint16 vendor = 0;
Uint16 product = 0; Uint16 product = 0;
Uint16 version = 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_CIFlightStick *flight_stick = NULL;
__x_ABI_CWindows_CGaming_CInput_CIGamepad *gamepad = NULL; __x_ABI_CWindows_CGaming_CInput_CIGamepad *gamepad = NULL;
__x_ABI_CWindows_CGaming_CInput_CIRacingWheel *racing_wheel = 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) { if (wgi.gamepad_statics2 && SUCCEEDED(__x_ABI_CWindows_CGaming_CInput_CIGamepadStatics2_FromGameController(wgi.gamepad_statics2, gamecontroller, &gamepad)) && gamepad) {
type = SDL_JOYSTICK_TYPE_GAMECONTROLLER; type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
@ -329,11 +331,16 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
type = SDL_JOYSTICK_TYPE_WHEEL; type = SDL_JOYSTICK_TYPE_WHEEL;
__x_ABI_CWindows_CGaming_CInput_CIRacingWheel_Release(racing_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); __x_ABI_CWindows_CGaming_CInput_CIGameController_Release(gamecontroller);
} }
/* FIXME: Is there any way to tell whether this is a Bluetooth device? */ guid = SDL_CreateJoystickGUID(bus, vendor, product, version, name, 'w', (Uint8) type);
guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_USB, vendor, product, version, name, 'w', (Uint8)type);
#ifdef SDL_JOYSTICK_HIDAPI #ifdef SDL_JOYSTICK_HIDAPI
if (!ignore_joystick && HIDAPI_IsDevicePresent(vendor, product, version, name)) { if (!ignore_joystick && HIDAPI_IsDevicePresent(vendor, product, version, name)) {