Merge pull request #109819 from Nintorch/fix-get-connected-joypads

Fix DirectInput controllers on game startup
This commit is contained in:
Thaddeus Crews
2025-08-25 09:54:17 -05:00
3 changed files with 18 additions and 18 deletions

View File

@ -58,6 +58,19 @@ JoypadSDL::JoypadSDL() {
singleton = this;
}
#ifdef WINDOWS_ENABLED
extern "C" {
HWND SDL_HelperWindow;
}
// Required for DInput joypads to work
// TODO: remove this workaround when we update to newer version of SDL
JoypadSDL::JoypadSDL(HWND p_helper_window) :
JoypadSDL() {
SDL_HelperWindow = p_helper_window;
}
#endif
JoypadSDL::~JoypadSDL() {
// Process any remaining input events
process_events();
@ -247,17 +260,6 @@ void JoypadSDL::process_events() {
}
}
#ifdef WINDOWS_ENABLED
extern "C" {
HWND SDL_HelperWindow;
}
// Required for DInput joypads to work
void JoypadSDL::setup_sdl_helper_window(HWND p_hwnd) {
SDL_HelperWindow = p_hwnd;
}
#endif
void JoypadSDL::close_joypad(int p_pad_idx) {
int sdl_instance_idx = joypads[p_pad_idx].sdl_instance_idx;

View File

@ -39,15 +39,15 @@ typedef struct HWND__ *HWND;
class JoypadSDL {
public:
JoypadSDL();
#ifdef WINDOWS_ENABLED
JoypadSDL(HWND p_helper_window);
#endif
~JoypadSDL();
static JoypadSDL *get_singleton();
Error initialize();
void process_events();
#ifdef WINDOWS_ENABLED
void setup_sdl_helper_window(HWND p_hwnd);
#endif
private:
struct Joypad {

View File

@ -7188,10 +7188,8 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
}
#ifdef SDL_ENABLED
joypad_sdl = memnew(JoypadSDL());
if (joypad_sdl->initialize() == OK) {
joypad_sdl->setup_sdl_helper_window(windows[MAIN_WINDOW_ID].hWnd);
} else {
joypad_sdl = memnew(JoypadSDL(windows[MAIN_WINDOW_ID].hWnd));
if (joypad_sdl->initialize() != OK) {
ERR_PRINT("Couldn't initialize SDL joypad input driver.");
memdelete(joypad_sdl);
joypad_sdl = nullptr;