From ed6dc1cc055f4b93a9d16e03eae5eb361488c702 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 7 Jul 2023 09:47:03 -0700 Subject: [PATCH] Prefer using XInput for rumble over WGI, as it allows rumble in the background (cherry picked from commit e16a83d393ae1784040519f42c482e2641b971a2) --- src/joystick/windows/SDL_rawinputjoystick.c | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c index 44aad79f6..a026f607b 100644 --- a/src/joystick/windows/SDL_rawinputjoystick.c +++ b/src/joystick/windows/SDL_rawinputjoystick.c @@ -1276,20 +1276,8 @@ static int RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_ #endif SDL_bool rumbled = SDL_FALSE; -#ifdef SDL_JOYSTICK_RAWINPUT_WGI - if (!rumbled && ctx->wgi_correlated) { - WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot; - HRESULT hr; - gamepad_state->vibration.LeftMotor = (DOUBLE)low_frequency_rumble / SDL_MAX_UINT16; - gamepad_state->vibration.RightMotor = (DOUBLE)high_frequency_rumble / SDL_MAX_UINT16; - hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, gamepad_state->vibration); - if (SUCCEEDED(hr)) { - rumbled = SDL_TRUE; - } - } -#endif - #ifdef SDL_JOYSTICK_RAWINPUT_XINPUT + /* Prefer XInput over WGI because it allows rumble in the background */ if (!rumbled && ctx->xinput_correlated) { XINPUT_VIBRATION XVibration; @@ -1307,6 +1295,19 @@ static int RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_ } #endif /* SDL_JOYSTICK_RAWINPUT_XINPUT */ +#ifdef SDL_JOYSTICK_RAWINPUT_WGI + if (!rumbled && ctx->wgi_correlated) { + WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot; + HRESULT hr; + gamepad_state->vibration.LeftMotor = (DOUBLE)low_frequency_rumble / SDL_MAX_UINT16; + gamepad_state->vibration.RightMotor = (DOUBLE)high_frequency_rumble / SDL_MAX_UINT16; + hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, gamepad_state->vibration); + if (SUCCEEDED(hr)) { + rumbled = SDL_TRUE; + } + } +#endif + if (!rumbled) { #if defined(SDL_JOYSTICK_RAWINPUT_WGI) || defined(SDL_JOYSTICK_RAWINPUT_XINPUT) return SDL_SetError("Controller isn't correlated yet, try hitting a button first");