Implemented trigger rumble for raw input controllers
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h
index d43c90a..fcc33e3 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 <sdkddkver.h>
+#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 23b764e..d525c76 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