From 8f46cb771c7c5e8aa4193b01f14f63e3ab7b4d8f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 6 Sep 2024 11:19:19 -0700
Subject: [PATCH] SDL_XINPUT_Enabled() returns false until XInput DLL is
successfully loaded
We make sure we initialize XInput first, so that anything checking whether it's enabled gets a valid result based on whether we were able to load it or not.
---
src/joystick/SDL_joystick.c | 2 +-
src/joystick/windows/SDL_windowsjoystick.c | 7 +++----
src/joystick/windows/SDL_xinputjoystick.c | 2 +-
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 1e37ea4c84bd5..d7b20b2d80a0b 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -61,7 +61,7 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
&SDL_WINDOWS_JoystickDriver,
#endif
-#ifdef SDL_JOYSTICK_WGI
+#ifdef SDL_JOYSTICK_WGI // Lower priority than other Windows drivers
&SDL_WGI_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_WINMM
diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c
index 1d724618b5347..b01d7a038bc3c 100644
--- a/src/joystick/windows/SDL_windowsjoystick.c
+++ b/src/joystick/windows/SDL_windowsjoystick.c
@@ -241,7 +241,7 @@ static int SDLCALL SDL_JoystickThread(void *_data)
#ifdef SDL_JOYSTICK_XINPUT
// WM_DEVICECHANGE not working, poll for new XINPUT controllers
SDL_WaitConditionTimeout(s_condJoystickThread, s_mutexJoyStickEnum, 1000);
- if (SDL_XINPUT_Enabled() && XINPUTGETCAPABILITIES) {
+ if (SDL_XINPUT_Enabled()) {
// scan for any change in XInput devices
Uint8 userId;
for (userId = 0; userId < XUSER_MAX_COUNT; userId++) {
@@ -329,15 +329,14 @@ void WINDOWS_AddJoystickDevice(JoyStick_DeviceData *device)
void WINDOWS_JoystickDetect(void);
void WINDOWS_JoystickQuit(void);
-// Function to scan the system for joysticks.
static bool WINDOWS_JoystickInit(void)
{
- if (!SDL_DINPUT_JoystickInit()) {
+ if (!SDL_XINPUT_JoystickInit()) {
WINDOWS_JoystickQuit();
return false;
}
- if (!SDL_XINPUT_JoystickInit()) {
+ if (!SDL_DINPUT_JoystickInit()) {
WINDOWS_JoystickQuit();
return false;
}
diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c
index 7486a135ec9ac..6e2f475f29e09 100644
--- a/src/joystick/windows/SDL_xinputjoystick.c
+++ b/src/joystick/windows/SDL_xinputjoystick.c
@@ -37,7 +37,7 @@ extern "C" {
/*
* Internal stuff.
*/
-static bool s_bXInputEnabled = true;
+static bool s_bXInputEnabled = false;
bool SDL_XINPUT_Enabled(void)
{