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++) {