Poll SDL device list to recover missing hotplug events
This commit is contained in:
parent
e005587806
commit
b03a4341e3
3 changed files with 30 additions and 0 deletions
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue