Improved RAWINPUT <-> XInput/WGI device correlation

If there is only one controller slot available, assume that's the one matching new RAWINPUt devices. This will be right most of the time, and uncorrelation will fix any bad guesses.
main
Sam Lantinga 2023-07-11 07:56:07 -07:00
parent dfc5e6964e
commit 41882a1acb
1 changed files with 36 additions and 2 deletions

View File

@ -74,7 +74,9 @@ typedef struct WindowsGamingInputGamepadState WindowsGamingInputGamepadState;
#endif
#endif
/*#define DEBUG_RAWINPUT*/
#if 0
#define DEBUG_RAWINPUT
#endif
#ifndef RIDEV_EXINPUTSINK
#define RIDEV_EXINPUTSINK 0x00001000
@ -397,6 +399,21 @@ static SDL_bool RAWINPUT_GuessXInputSlot(const WindowsMatchState *state, Uint8 *
Uint8 user_index;
int match_count;
/* If there is only one available slot, let's use that
* That will be right most of the time, and uncorrelation will fix any bad guesses
*/
match_count = 0;
for (user_index = 0; user_index < XUSER_MAX_COUNT; ++user_index) {
if (xinput_state[user_index].connected && !xinput_state[user_index].used) {
*slot_idx = user_index;
++match_count;
}
}
if (match_count == 1) {
*correlation_id = ++xinput_state[*slot_idx].correlation_id;
return SDL_TRUE;
}
*slot_idx = 0;
match_count = 0;
@ -720,10 +737,27 @@ static SDL_bool RAWINPUT_WindowsGamingInputSlotMatches(const WindowsMatchState *
static SDL_bool RAWINPUT_GuessWindowsGamingInputSlot(const WindowsMatchState *state, Uint8 *correlation_id, WindowsGamingInputGamepadState **slot, SDL_bool xinput_correlated)
{
int match_count, user_index;
WindowsGamingInputGamepadState *gamepad_state = NULL;
/* If there is only one available slot, let's use that
* That will be right most of the time, and uncorrelation will fix any bad guesses
*/
match_count = 0;
for (user_index = 0; user_index < wgi_state.per_gamepad_count; ++user_index) {
gamepad_state = wgi_state.per_gamepad[user_index];
if (gamepad_state->connected && !gamepad_state->used) {
*slot = gamepad_state;
++match_count;
}
}
if (match_count == 1) {
*correlation_id = ++gamepad_state->correlation_id;
return SDL_TRUE;
}
match_count = 0;
for (user_index = 0; user_index < wgi_state.per_gamepad_count; ++user_index) {
WindowsGamingInputGamepadState *gamepad_state = wgi_state.per_gamepad[user_index];
gamepad_state = wgi_state.per_gamepad[user_index];
if (RAWINPUT_WindowsGamingInputSlotMatches(state, gamepad_state, xinput_correlated)) {
++match_count;
*slot = gamepad_state;