From e94f0c59908db5ee6562f3b0709a76a6b656c421 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Thu, 12 Feb 2026 07:40:45 -0700 Subject: [PATCH] Throttle hotplug re-enumeration retries and reduce log noise --- app/streaming/input/gamepad.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/app/streaming/input/gamepad.cpp b/app/streaming/input/gamepad.cpp index deb8b4e1..b1391755 100644 --- a/app/streaming/input/gamepad.cpp +++ b/app/streaming/input/gamepad.cpp @@ -25,6 +25,7 @@ static bool isKeyboardMouseInputAllowed() #define MOUSE_EMULATION_POLLING_INTERVAL 50 #define HOTPLUG_REENUMERATION_INTERVAL_MS 2000 +#define HOTPLUG_REENUMERATION_MAX_INTERVAL_MS 8000 // Determines how fast the mouse will move each interval #define MOUSE_EMULATION_MOTION_MULTIPLIER 4 @@ -102,6 +103,8 @@ SdlInputHandler::ensureStateForGamepad(SDL_JoystickID id) void SdlInputHandler::pollForMissingGamepads() { static uint32_t s_LastForcedReenumerationTick = 0; + static uint32_t s_ReenumerationIntervalMs = HOTPLUG_REENUMERATION_INTERVAL_MS; + static uint32_t s_ReenumerationAttempts = 0; SDL_JoystickUpdate(); SDL_GameControllerUpdate(); @@ -138,6 +141,11 @@ void SdlInputHandler::pollForMissingGamepads() m_LastJoystickCount = joystickCount; } + if (joystickCount > 0) { + s_ReenumerationAttempts = 0; + s_ReenumerationIntervalMs = HOTPLUG_REENUMERATION_INTERVAL_MS; + } + for (int i = 0; i < MAX_GAMEPADS; i++) { GamepadState* state = &m_GamepadState[i]; if (state->controller == nullptr) { @@ -156,7 +164,7 @@ void SdlInputHandler::pollForMissingGamepads() continue; } - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Polling detected disconnected gamepad instance %d in slot %d; cleaning up", state->jsId, i); @@ -171,11 +179,14 @@ void SdlInputHandler::pollForMissingGamepads() if (joystickCount == 0) { uint32_t now = SDL_GetTicks(); - if (SDL_TICKS_PASSED(now, s_LastForcedReenumerationTick + HOTPLUG_REENUMERATION_INTERVAL_MS)) { + if (SDL_TICKS_PASSED(now, s_LastForcedReenumerationTick + s_ReenumerationIntervalMs)) { s_LastForcedReenumerationTick = now; + s_ReenumerationAttempts++; - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "No joysticks visible; forcing SDL joystick/gamecontroller re-enumeration"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, + "No joysticks visible; forcing SDL joystick/gamecontroller re-enumeration (attempt %u, interval %u ms)", + s_ReenumerationAttempts, + s_ReenumerationIntervalMs); SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); SDL_QuitSubSystem(SDL_INIT_JOYSTICK); @@ -210,6 +221,15 @@ void SdlInputHandler::pollForMissingGamepads() } recoverUntrackedGamepads(joystickCount); + + if (joystickCount > 0) { + s_ReenumerationAttempts = 0; + s_ReenumerationIntervalMs = HOTPLUG_REENUMERATION_INTERVAL_MS; + } + else { + s_ReenumerationIntervalMs = qMin(s_ReenumerationIntervalMs * 2, + static_cast(HOTPLUG_REENUMERATION_MAX_INTERVAL_MS)); + } } } } @@ -777,7 +797,7 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve // before we've processed the add event. for (int i = 0; i < MAX_GAMEPADS; i++) { if (m_GamepadState[i].controller != nullptr && m_GamepadState[i].jsId == jsId) { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Received duplicate add event for joystick instance ID: %d", jsId); SDL_GameControllerClose(controller);