From 687605ad38425eee9825e9581e3f8ec6ae7892b1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 3 Nov 2016 14:02:53 -0700 Subject: [PATCH] Add proper adding and removal of subdeviceNames in SDL2Manager after startup --- plugins/hifiSdl2/src/Joystick.h | 2 ++ plugins/hifiSdl2/src/SDL2Manager.cpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/hifiSdl2/src/Joystick.h b/plugins/hifiSdl2/src/Joystick.h index 25381d545a..a10e02d325 100644 --- a/plugins/hifiSdl2/src/Joystick.h +++ b/plugins/hifiSdl2/src/Joystick.h @@ -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; diff --git a/plugins/hifiSdl2/src/SDL2Manager.cpp b/plugins/hifiSdl2/src/SDL2Manager.cpp index 91a693cc09..b6fa567aee 100644 --- a/plugins/hifiSdl2/src/SDL2Manager.cpp +++ b/plugins/hifiSdl2/src/SDL2Manager.cpp @@ -163,15 +163,19 @@ void SDL2Manager::pluginUpdate(float deltaTime, const controller::InputCalibrati Joystick::Pointer joystick = std::make_shared(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); } } }