From 845b903324b19e863fd026436ef9b2016ecb0626 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 25 Nov 2020 16:46:42 -0800 Subject: [PATCH] Implemented trigger rumble for raw input controllers --- include/SDL_config_windows.h | 20 +++++++++++++++++--- src/joystick/windows/SDL_rawinputjoystick.c | 21 ++++++++++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index d43c90ac5..fcc33e3ea 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -191,6 +191,20 @@ typedef unsigned int uintptr_t; #define HAVE_STDDEF_H 1 #endif +/* Check to see if we have Windows 10 build environment */ +#if _MSC_VER >= 1911 /* Visual Studio 15.3 */ +#include +#if _WIN32_WINNT >= 0x0601 /* Windows 7 */ +#define SDL_WINDOWS7_SDK +#endif +#if _WIN32_WINNT >= 0x0602 /* Windows 8 */ +#define SDL_WINDOWS8_SDK +#endif +#if _WIN32_WINNT >= 0x0A00 /* Windows 10 */ +#define SDL_WINDOWS10_SDK +#endif +#endif /* _MSC_VER >= 1911 */ + /* Enable various audio drivers */ #define SDL_AUDIO_DRIVER_WASAPI 1 #define SDL_AUDIO_DRIVER_DSOUND 1 @@ -203,8 +217,8 @@ typedef unsigned int uintptr_t; #define SDL_JOYSTICK_HIDAPI 1 #define SDL_JOYSTICK_RAWINPUT 1 #define SDL_JOYSTICK_VIRTUAL 1 -#if _MSC_VER >= 1911 -#define SDL_JOYSTICK_WGI 1 /* This requires Windows SDK 10.0.16299.0 or newer */ +#ifdef SDL_WINDOWS10_SDK +#define SDL_JOYSTICK_WGI 1 #endif #define SDL_JOYSTICK_XINPUT 1 #define SDL_HAPTIC_DINPUT 1 @@ -229,7 +243,7 @@ typedef unsigned int uintptr_t; #ifndef SDL_VIDEO_RENDER_D3D #define SDL_VIDEO_RENDER_D3D 1 #endif -#if _MSC_VER >= 1911 +#ifdef SDL_WINDOWS7_SDK #define SDL_VIDEO_RENDER_D3D11 1 #endif diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c index 23b764e8f..d525c7667 100644 --- a/src/joystick/windows/SDL_rawinputjoystick.c +++ b/src/joystick/windows/SDL_rawinputjoystick.c @@ -44,10 +44,9 @@ #include "../../core/windows/SDL_hid.h" #include "../hidapi/SDL_hidapijoystick_c.h" -#ifdef __WIN32__ #define SDL_JOYSTICK_RAWINPUT_XINPUT -/* This requires the Windows 10 SDK to build */ -/*#define SDL_JOYSTICK_RAWINPUT_GAMING_INPUT*/ +#ifdef SDL_WINDOWS10_SDK +#define SDL_JOYSTICK_RAWINPUT_GAMING_INPUT #endif #ifdef SDL_JOYSTICK_RAWINPUT_XINPUT @@ -1232,7 +1231,23 @@ RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uin static int RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { +#if defined(SDL_JOYSTICK_RAWINPUT_GAMING_INPUT) + RAWINPUT_DeviceContext *ctx = joystick->hwdata; + + if (ctx->wgi_correlated) { + WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot; + HRESULT hr; + gamepad_state->vibration.LeftTrigger = (DOUBLE)left_rumble / SDL_MAX_UINT16; + gamepad_state->vibration.RightTrigger = (DOUBLE)right_rumble / SDL_MAX_UINT16; + hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, gamepad_state->vibration); + if (!SUCCEEDED(hr)) { + return SDL_SetError("Setting vibration failed: 0x%x\n", hr); + } + } + return 0; +#else return SDL_Unsupported(); +#endif } static SDL_bool