From 74e7a44da3d51dfe2be27961eca651cc3a9e05f8 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 22 Jan 2023 20:01:45 -0800 Subject: [PATCH] Qt: More API cleanup --- src/platform/qt/InputController.cpp | 25 ++++++++++-------------- src/platform/qt/InputController.h | 8 ++++---- src/platform/qt/input/InputDriver.cpp | 22 +++++++++++++++++++-- src/platform/qt/input/InputDriver.h | 7 +++++-- src/platform/qt/input/SDLInputDriver.cpp | 2 +- src/platform/qt/input/SDLInputDriver.h | 2 +- 6 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/platform/qt/InputController.cpp b/src/platform/qt/InputController.cpp index 0c94e7511..e6e741a56 100644 --- a/src/platform/qt/InputController.cpp +++ b/src/platform/qt/InputController.cpp @@ -240,7 +240,7 @@ int InputController::gamepadIndex(uint32_t type) const { if (!driver) { return -1; } - return driver->activeGamepad(); + return driver->activeGamepadIndex(); } void InputController::setGamepad(uint32_t type, int index) { @@ -361,13 +361,9 @@ Gamepad* InputController::gamepad(uint32_t type) { } if (!driver->supportsGamepads()) { return nullptr; -} - QList driverPads(driver->connectedGamepads()); - int activeGamepad = driver->activeGamepad(); - if (activeGamepad < 0 || activeGamepad >= driverPads.count()) { - return nullptr; } - return driverPads[activeGamepad]; + + return driver->activeGamepad(); } QList InputController::gamepads() { @@ -376,16 +372,15 @@ QList InputController::gamepads() { if (!driver->supportsGamepads()) { continue; } - QList driverPads(driver->connectedGamepads()); - int activeGamepad = driver->activeGamepad(); - if (activeGamepad >= 0 && activeGamepad < driverPads.count()) { - pads.append(driverPads[activeGamepad]); + Gamepad* pad = driver->activeGamepad(); + if (pad) { + pads.append(pad); } } return pads; } -QSet InputController::activeGamepadButtons(int type) { +QSet InputController::activeGamepadButtons(uint32_t type) { QSet activeButtons; Gamepad* pad = gamepad(type); if (!pad) { @@ -400,7 +395,7 @@ QSet InputController::activeGamepadButtons(int type) { return activeButtons; } -QSet> InputController::activeGamepadAxes(int type) { +QSet> InputController::activeGamepadAxes(uint32_t type) { QSet> activeAxes; Gamepad* pad = gamepad(type); if (!pad) { @@ -421,7 +416,7 @@ QSet> InputController::activeGamepadAxes return activeAxes; } -QSet> InputController::activeGamepadHats(int type) { +QSet> InputController::activeGamepadHats(uint32_t type) { QSet> activeHats; Gamepad* pad = gamepad(type); if (!pad) { @@ -436,7 +431,7 @@ QSet> InputController::activeGamepadHats( return activeHats; } -void InputController::testGamepad(int type) { +void InputController::testGamepad(uint32_t type) { QWriteLocker l(&m_eventsLock); auto activeAxes = activeGamepadAxes(type); auto oldAxes = m_activeAxes; diff --git a/src/platform/qt/InputController.h b/src/platform/qt/InputController.h index ab6590e7c..e974c1aaa 100644 --- a/src/platform/qt/InputController.h +++ b/src/platform/qt/InputController.h @@ -107,7 +107,7 @@ signals: void luminanceValueChanged(int value); public slots: - void testGamepad(int type); + void testGamepad(uint32_t type); void update(); void increaseLuminanceLevel(); @@ -136,9 +136,9 @@ private: Gamepad* gamepad(uint32_t type); QList gamepads(); - QSet activeGamepadButtons(int type); - QSet> activeGamepadAxes(int type); - QSet> activeGamepadHats(int type); + QSet activeGamepadButtons(uint32_t type); + QSet> activeGamepadAxes(uint32_t type); + QSet> activeGamepadHats(uint32_t type); struct InputControllerLux : GBALuminanceSource { InputController* p; diff --git a/src/platform/qt/input/InputDriver.cpp b/src/platform/qt/input/InputDriver.cpp index 912395e0d..f76649bd8 100644 --- a/src/platform/qt/input/InputDriver.cpp +++ b/src/platform/qt/input/InputDriver.cpp @@ -40,14 +40,32 @@ QList InputDriver::connectedGamepads() const { return {}; } -int InputDriver::activeKeySource() const { +int InputDriver::activeKeySourceIndex() const { return -1; } -int InputDriver::activeGamepad() const { +int InputDriver::activeGamepadIndex() const { return -1; } +KeySource* InputDriver::activeKeySource() { + QList ks(connectedKeySources()); + int activeKeySource = activeKeySourceIndex(); + if (activeKeySource < 0 || activeKeySource >= ks.count()) { + return nullptr; + } + return ks[activeKeySource]; +} + +Gamepad* InputDriver::activeGamepad() { + QList pads(connectedGamepads()); + int activeGamepad = activeGamepadIndex(); + if (activeGamepad < 0 || activeGamepad >= pads.count()) { + return nullptr; + } + return pads[activeGamepad]; +} + void InputDriver::setActiveKeySource(int) { } diff --git a/src/platform/qt/input/InputDriver.h b/src/platform/qt/input/InputDriver.h index f344b271b..cc0a6e0cd 100644 --- a/src/platform/qt/input/InputDriver.h +++ b/src/platform/qt/input/InputDriver.h @@ -44,8 +44,11 @@ public: virtual QList connectedKeySources() const; virtual QList connectedGamepads() const; - virtual int activeKeySource() const; - virtual int activeGamepad() const; + virtual int activeKeySourceIndex() const; + virtual int activeGamepadIndex() const; + + KeySource* activeKeySource(); + Gamepad* activeGamepad(); virtual void setActiveKeySource(int); virtual void setActiveGamepad(int); diff --git a/src/platform/qt/input/SDLInputDriver.cpp b/src/platform/qt/input/SDLInputDriver.cpp index 2eda6a4f0..ca9e30b25 100644 --- a/src/platform/qt/input/SDLInputDriver.cpp +++ b/src/platform/qt/input/SDLInputDriver.cpp @@ -173,7 +173,7 @@ void SDLInputDriver::updateGamepads() { } #endif -int SDLInputDriver::activeGamepad() const { +int SDLInputDriver::activeGamepadIndex() const { return m_sdlPlayer.joystick ? m_sdlPlayer.joystick->index : 0; } diff --git a/src/platform/qt/input/SDLInputDriver.h b/src/platform/qt/input/SDLInputDriver.h index 79deac22c..09f4b9555 100644 --- a/src/platform/qt/input/SDLInputDriver.h +++ b/src/platform/qt/input/SDLInputDriver.h @@ -46,7 +46,7 @@ public: QList connectedGamepads() const override; - int activeGamepad() const override; + int activeGamepadIndex() const override; void setActiveGamepad(int) override; void registerTiltAxisX(int axis) override;