From 06ea88ef92da878547fd5fa8a896a0577c4d7585 Mon Sep 17 00:00:00 2001 From: SternXD Date: Wed, 24 Sep 2025 09:29:04 -0400 Subject: [PATCH] UWP/WinRT: Fix XInput controller detection for late-arriving controllers Signed-off-by: SternXD --- input/drivers_joypad/xinput_hybrid_joypad.c | 16 ++++++++++++++++ input/drivers_joypad/xinput_joypad.c | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/input/drivers_joypad/xinput_hybrid_joypad.c b/input/drivers_joypad/xinput_hybrid_joypad.c index 4fc634336ad6..45358d52ddef 100644 --- a/input/drivers_joypad/xinput_hybrid_joypad.c +++ b/input/drivers_joypad/xinput_hybrid_joypad.c @@ -582,6 +582,8 @@ static int16_t xinput_joypad_state_func( static void xinput_joypad_poll(void) { int i; + bool has_active_ports = false; + /* Hotplugging detection: scanning one port at a time every few frames, * to avoid polling overload and framerate drops. */ xinput_poll_counter++; @@ -611,13 +613,27 @@ static void xinput_joypad_poll(void) xinput_hotplug_index = (xinput_hotplug_index + 1) % 4; } + for (i = 0; i < 4; ++i) + { + if (xinput_active_port[i]) + has_active_ports = true; + } + for (i = 0; i < 4; ++i) { DWORD status; bool success, new_connected; xinput_joypad_state *state; + /* On UWP, controllers may become available after initialization. + * If no ports are currently active, we need to poll all ports + * to catch any late arriving controllers. */ +#ifdef __WINRT__ + if (!xinput_active_port[i] && has_active_ports) + continue; +#else if (!xinput_active_port[i]) continue; +#endif state = &g_xinput_states[i]; status = g_XInputGetStateEx(i, &state->xstate); diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index 0589a1c8b766..83bf9540d498 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -351,6 +351,7 @@ static int16_t xinput_joypad_state_func( static void xinput_joypad_poll(void) { int i; + bool has_active_ports = false; /* Hotplugging detection: scanning one port at a time every few frames, * to avoid polling overload and framerate drops. */ @@ -381,13 +382,27 @@ static void xinput_joypad_poll(void) xinput_hotplug_index = (xinput_hotplug_index + 1) % 4; } + for (i = 0; i < 4; ++i) + { + if (xinput_active_port[i]) + has_active_ports = true; + } + for (i = 0; i < 4; ++i) { DWORD status; bool success, new_connected; xinput_joypad_state *state; + /* On UWP, controllers may become available after initialization. + * If no ports are currently active, we need to poll all ports + * to catch any late arriving controllers. */ +#ifdef __WINRT__ +if (!xinput_active_port[i] && has_active_ports) + continue; +#else if (!xinput_active_port[i]) continue; +#endif state = &g_xinput_states[i]; status = g_XInputGetStateEx(i, &state->xstate);