Skip to content

Commit

Permalink
Added the hint SDL_HINT_JOYSTICK_WGI to control whether to use Window…
Browse files Browse the repository at this point in the history
…s.Gaming.Input for controllers

(cherry picked from commit a6228e7)
  • Loading branch information
slouken committed Jul 8, 2023
1 parent 46927b1 commit b858242
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
7 changes: 7 additions & 0 deletions WhatsNew.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

This is a list of major changes in SDL's version history.

---------------------------------------------------------------------------
2.28.2:
---------------------------------------------------------------------------
General:
* Added the hint SDL_HINT_JOYSTICK_WGI to control whether to use Windows.Gaming.Input for controllers


---------------------------------------------------------------------------
2.28.0:
---------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions include/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,15 @@ extern "C" {
*/
#define SDL_HINT_JOYSTICK_THREAD "SDL_JOYSTICK_THREAD"

/**
* \brief A variable controlling whether Windows.Gaming.Input should be used for controller handling.
*
* This variable can be set to the following values:
* "0" - WGI is not used
* "1" - WGI is used (the default)
*/
#define SDL_HINT_JOYSTICK_WGI "SDL_JOYSTICK_WGI"

/**
* \brief Determines whether SDL enforces that DRM master is required in order
* to initialize the KMSDRM video backend.
Expand Down
12 changes: 8 additions & 4 deletions src/joystick/windows/SDL_rawinputjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ static void RAWINPUT_UpdateWindowsGamingInput()
}
static void RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
{
if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_WGI, SDL_TRUE)) {
return;
}

wgi_state.need_device_list_update = SDL_TRUE;
wgi_state.ref_count++;
if (!wgi_state.initialized) {
Expand Down Expand Up @@ -879,12 +883,12 @@ static int RAWINPUT_JoystickInit(void)
{
SDL_assert(!SDL_RAWINPUT_inited);

if (!WIN_IsWindowsVistaOrGreater()) {
/* According to bug 6400, this doesn't work on Windows XP */
return -1;
if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_RAWINPUT, SDL_TRUE)) {
return 0;
}

if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_RAWINPUT, SDL_TRUE)) {
if (!WIN_IsWindowsVistaOrGreater()) {
/* According to bug 6400, this doesn't work on Windows XP */
return -1;
}

Expand Down
4 changes: 4 additions & 0 deletions src/joystick/windows/SDL_windows_gaming_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ static int WGI_JoystickInit(void)
RoGetActivationFactory_t RoGetActivationFactoryFunc = NULL;
HRESULT hr;

if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_WGI, SDL_TRUE)) {
return 0;
}

if (FAILED(WIN_RoInitialize())) {
return SDL_SetError("RoInitialize() failed");
}
Expand Down

2 comments on commit b858242

@sezero
Copy link
Contributor

@sezero sezero commented on b858242 Jul 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not needed in SDL2 branch itself?

@slouken
Copy link
Collaborator Author

@slouken slouken commented on b858242 Jul 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, I just hadn't pushed yet.

Please sign in to comment.