Clean up stale detached gamepads before hotplug reattach
Some checks are pending
Build / setup (push) Waiting to run
Build / build-appimage (push) Blocked by required conditions
Build / build-steamlink (push) Blocked by required conditions
Build / build-windows-macos (push) Blocked by required conditions

This commit is contained in:
Joey Yakimowich-Payne 2026-02-12 01:44:04 -07:00
commit ca41cf32cc
2 changed files with 23 additions and 0 deletions

View file

@ -63,6 +63,25 @@ SdlInputHandler::findStateForGamepad(SDL_JoystickID id)
return nullptr;
}
void SdlInputHandler::cleanupDetachedGamepads()
{
for (int i = 0; i < MAX_GAMEPADS; i++) {
if (m_GamepadState[i].controller == nullptr ||
SDL_GameControllerGetAttached(m_GamepadState[i].controller)) {
continue;
}
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Found detached gamepad in slot %d without removal event; cleaning up",
i);
SDL_ControllerDeviceEvent controllerEvent = {};
controllerEvent.type = SDL_CONTROLLERDEVICEREMOVED;
controllerEvent.which = m_GamepadState[i].jsId;
handleControllerDeviceEvent(&controllerEvent);
}
}
void SdlInputHandler::sendGamepadState(GamepadState* state)
{
SDL_assert(m_GamepadMask == 0x1 || m_MultiController);
@ -582,6 +601,8 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
GamepadState* state;
if (event->type == SDL_CONTROLLERDEVICEADDED) {
cleanupDetachedGamepads();
int i;
const char* name;
SDL_GameController* controller;