Clean up stale detached gamepads before hotplug reattach
This commit is contained in:
parent
e88be5dce2
commit
ca41cf32cc
2 changed files with 23 additions and 0 deletions
|
|
@ -63,6 +63,25 @@ SdlInputHandler::findStateForGamepad(SDL_JoystickID id)
|
||||||
return nullptr;
|
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)
|
void SdlInputHandler::sendGamepadState(GamepadState* state)
|
||||||
{
|
{
|
||||||
SDL_assert(m_GamepadMask == 0x1 || m_MultiController);
|
SDL_assert(m_GamepadMask == 0x1 || m_MultiController);
|
||||||
|
|
@ -582,6 +601,8 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
|
||||||
GamepadState* state;
|
GamepadState* state;
|
||||||
|
|
||||||
if (event->type == SDL_CONTROLLERDEVICEADDED) {
|
if (event->type == SDL_CONTROLLERDEVICEADDED) {
|
||||||
|
cleanupDetachedGamepads();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
const char* name;
|
const char* name;
|
||||||
SDL_GameController* controller;
|
SDL_GameController* controller;
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,8 @@ private:
|
||||||
GamepadState*
|
GamepadState*
|
||||||
findStateForGamepad(SDL_JoystickID id);
|
findStateForGamepad(SDL_JoystickID id);
|
||||||
|
|
||||||
|
void cleanupDetachedGamepads();
|
||||||
|
|
||||||
void sendGamepadState(GamepadState* state);
|
void sendGamepadState(GamepadState* state);
|
||||||
|
|
||||||
void sendGamepadBatteryState(GamepadState* state, SDL_JoystickPowerLevel level);
|
void sendGamepadBatteryState(GamepadState* state, SDL_JoystickPowerLevel level);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue