(XInput/DirectInput) Show device disconnect messages when unplugging a gamepad

This commit is contained in:
twinaphex 2019-07-28 06:42:03 +02:00
parent b3915e8d22
commit eb3753ee3c
2 changed files with 14 additions and 7 deletions

View File

@ -553,6 +553,7 @@ static void dinput_joypad_poll(void)
unsigned i; unsigned i;
for (i = 0; i < MAX_USERS; i++) for (i = 0; i < MAX_USERS; i++)
{ {
HRESULT ret;
struct dinput_joypad_data *pad = &g_pads[i]; struct dinput_joypad_data *pad = &g_pads[i];
bool polled = g_xinput_pad_indexes[i] < 0; bool polled = g_xinput_pad_indexes[i] < 0;
@ -577,8 +578,11 @@ static void dinput_joypad_poll(void)
} }
} }
IDirectInputDevice8_GetDeviceState(pad->joypad, ret = IDirectInputDevice8_GetDeviceState(pad->joypad,
sizeof(DIJOYSTATE2), &pad->joy_state); sizeof(DIJOYSTATE2), &pad->joy_state);
if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED)
input_autoconfigure_disconnect(i, g_pads[i].joy_friendly_name);
} }
} }

View File

@ -540,10 +540,13 @@ static void xinput_joypad_poll(void)
#ifdef HAVE_DINPUT #ifdef HAVE_DINPUT
if (g_xinput_states[i].connected) if (g_xinput_states[i].connected)
{ {
if (g_XInputGetStateEx && g_XInputGetStateEx(i, if (g_XInputGetStateEx(i,
&(g_xinput_states[i].xstate)) &(g_xinput_states[i].xstate))
== ERROR_DEVICE_NOT_CONNECTED) == ERROR_DEVICE_NOT_CONNECTED)
{
g_xinput_states[i].connected = false; g_xinput_states[i].connected = false;
input_autoconfigure_disconnect(i, xinput_joypad_name(i));
}
} }
#else #else
/* Normally, dinput handles device insertion/removal for us, but /* Normally, dinput handles device insertion/removal for us, but
@ -551,7 +554,7 @@ static void xinput_joypad_poll(void)
/* Also note that on UWP, the controllers are not available on startup /* Also note that on UWP, the controllers are not available on startup
* and are instead 'plugged in' a moment later because Microsoft reasons */ * and are instead 'plugged in' a moment later because Microsoft reasons */
/* TODO: This may be bad for performance? */ /* TODO: This may be bad for performance? */
bool new_connected = g_XInputGetStateEx && g_XInputGetStateEx(i, &(g_xinput_states[i].xstate)) != ERROR_DEVICE_NOT_CONNECTED; bool new_connected = g_XInputGetStateEx(i, &(g_xinput_states[i].xstate)) != ERROR_DEVICE_NOT_CONNECTED;
if (new_connected != g_xinput_states[i].connected) if (new_connected != g_xinput_states[i].connected)
{ {
if (new_connected) if (new_connected)
@ -561,10 +564,10 @@ static void xinput_joypad_poll(void)
xinput_joypad_init(NULL); xinput_joypad_init(NULL);
return; return;
} }
else
{ g_xinput_states[i].connected = new_connected;
g_xinput_states[i].connected = new_connected; if (!g_xinput_states[i].connected)
} input_autoconfigure_disconnect(i, xinput_joypad_name(i));
} }
#endif #endif
} }