Skip to content

Commit 4929434

Browse files
committed
UWP/WinRT: Fix XInput controller detection for late-arriving controllers
Signed-off-by: SternXD <[email protected]>
1 parent 3f19b2a commit 4929434

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

input/drivers_joypad/xinput_hybrid_joypad.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,28 @@ static void xinput_joypad_poll(void)
611611
xinput_hotplug_index = (xinput_hotplug_index + 1) % 4;
612612
}
613613

614+
bool has_active_ports = false;
615+
for (i = 0; i < 4; ++i)
616+
{
617+
if (xinput_active_port[i])
618+
has_active_ports = true;
619+
}
620+
614621
for (i = 0; i < 4; ++i)
615622
{
616623
DWORD status;
617624
bool success, new_connected;
618625
xinput_joypad_state *state;
626+
/* On UWP, controllers may become available after initialization.
627+
* If no ports are currently active, we need to poll all ports
628+
* to catch any late arriving controllers. */
629+
#ifdef __WINRT__
630+
if (!xinput_active_port[i] && has_active_ports)
631+
continue;
632+
#else
619633
if (!xinput_active_port[i])
620634
continue;
635+
#endif
621636

622637
state = &g_xinput_states[i];
623638
status = g_XInputGetStateEx(i, &state->xstate);

input/drivers_joypad/xinput_joypad.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,28 @@ static void xinput_joypad_poll(void)
381381
xinput_hotplug_index = (xinput_hotplug_index + 1) % 4;
382382
}
383383

384+
bool has_active_ports = false;
385+
for (i = 0; i < 4; ++i)
386+
{
387+
if (xinput_active_port[i])
388+
has_active_ports = true;
389+
}
390+
384391
for (i = 0; i < 4; ++i)
385392
{
386393
DWORD status;
387394
bool success, new_connected;
388395
xinput_joypad_state *state;
396+
/* On UWP, controllers may become available after initialization.
397+
* If no ports are currently active, we need to poll all ports
398+
* to catch any late arriving controllers. */
399+
#ifdef __WINRT__
400+
if (!xinput_active_port[i] && has_active_ports)
401+
continue;
402+
#else
389403
if (!xinput_active_port[i])
390404
continue;
405+
#endif
391406

392407
state = &g_xinput_states[i];
393408
status = g_XInputGetStateEx(i, &state->xstate);

0 commit comments

Comments
 (0)