Add proper adding and removal of subdeviceNames in SDL2Manager after startup

This commit is contained in:
Ryan Huffman 2016-11-03 14:02:53 -07:00
parent 413199459b
commit 687605ad38
2 changed files with 7 additions and 1 deletions

View file

@ -31,6 +31,8 @@ public:
const QString& getName() const { return _name; }
SDL_GameController* getGameController() { return _sdlGameController; }
// Device functions
virtual controller::Input::NamedVector getAvailableInputs() const override;
virtual QString getDefaultMappingConfig() const override;

View file

@ -163,15 +163,19 @@ void SDL2Manager::pluginUpdate(float deltaTime, const controller::InputCalibrati
Joystick::Pointer joystick = std::make_shared<Joystick>(id, controller);
_openJoysticks[id] = joystick;
userInputMapper->registerDevice(joystick);
QString name = SDL_GameControllerName(controller);
emit joystickAdded(joystick.get());
emit subdeviceConnected(getName(), SDL_GameControllerName(controller));
emit subdeviceConnected(getName(), name);
_subdeviceNames << name;
}
} else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
if (_openJoysticks.contains(event.cdevice.which)) {
Joystick::Pointer joystick = _openJoysticks[event.cdevice.which];
_openJoysticks.remove(event.cdevice.which);
userInputMapper->removeDevice(joystick->getDeviceID());
QString name = SDL_GameControllerName(joystick->getGameController());
emit joystickRemoved(joystick.get());
_subdeviceNames.removeOne(name);
}
}
}