Skip to content

Commit

Permalink
Implemented trigger rumble for raw input controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 26, 2020
1 parent 517be80 commit 845b903
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
20 changes: 17 additions & 3 deletions include/SDL_config_windows.h
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
21 changes: 18 additions & 3 deletions src/joystick/windows/SDL_rawinputjoystick.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 845b903

Please sign in to comment.