Poll SDL device list to recover missing hotplug events
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 02:06:12 -07:00
commit b03a4341e3
3 changed files with 30 additions and 0 deletions

View file

@ -97,6 +97,33 @@ SdlInputHandler::ensureStateForGamepad(SDL_JoystickID id)
return findStateForGamepad(id);
}
void SdlInputHandler::pollForMissingGamepads()
{
cleanupDetachedGamepads();
const int joystickCount = SDL_NumJoysticks();
for (int deviceIndex = 0; deviceIndex < joystickCount; deviceIndex++) {
if (!SDL_IsGameController(deviceIndex)) {
continue;
}
SDL_JoystickID jsId = SDL_JoystickGetDeviceInstanceID(deviceIndex);
if (jsId < 0 || findStateForGamepad(jsId) != nullptr) {
continue;
}
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Polling recovered missing gamepad add event (device index: %d, instance ID: %d)",
deviceIndex,
jsId);
SDL_ControllerDeviceEvent controllerEvent = {};
controllerEvent.type = SDL_CONTROLLERDEVICEADDED;
controllerEvent.which = deviceIndex;
handleControllerDeviceEvent(&controllerEvent);
}
}
void SdlInputHandler::cleanupDetachedGamepads()
{
for (int i = 0; i < MAX_GAMEPADS; i++) {

View file

@ -118,6 +118,8 @@ public:
void handleJoystickRemovalEvent(SDL_JoyDeviceEvent* event);
void pollForMissingGamepads();
void sendText(QString& string);
void rumble(uint16_t controllerNumber, uint16_t lowFreqMotor, uint16_t highFreqMotor);

View file

@ -2206,6 +2206,7 @@ void Session::exec()
// issues that could cause indefinite timeouts, delayed joystick detection,
// and other problems.
if (!SDL_WaitEventTimeout(&event, 1000)) {
m_InputHandler->pollForMissingGamepads();
updateEffectiveAudioMuteState();
presence.runCallbacks();
continue;