diff options
author | Garrett Brown <themagnificentmrb@gmail.com> | 2024-02-05 06:31:24 -0800 |
---|---|---|
committer | Garrett Brown <themagnificentmrb@gmail.com> | 2024-02-05 07:13:47 -0800 |
commit | f8b6a620c863e19df75d74ea573f102503669d17 (patch) | |
tree | e385a2cab1b9921d0113e4173e658131021c2ee2 | |
parent | 6256993bb6991815377fcaa5ab6814b65135abc1 (diff) |
[Input] Allow input handlers to bypass add-on buttonmaps
-rw-r--r-- | xbmc/games/addons/input/GameClientKeyboard.cpp | 2 | ||||
-rw-r--r-- | xbmc/games/addons/input/GameClientMouse.cpp | 2 | ||||
-rw-r--r-- | xbmc/games/agents/input/AgentJoystick.cpp | 3 | ||||
-rw-r--r-- | xbmc/games/agents/input/AgentKeyboard.cpp | 8 | ||||
-rw-r--r-- | xbmc/games/agents/input/AgentMouse.cpp | 8 | ||||
-rw-r--r-- | xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h | 6 | ||||
-rw-r--r-- | xbmc/input/mouse/interfaces/IMouseInputProvider.h | 6 | ||||
-rw-r--r-- | xbmc/peripherals/devices/Peripheral.cpp | 53 | ||||
-rw-r--r-- | xbmc/peripherals/devices/Peripheral.h | 7 |
9 files changed, 56 insertions, 39 deletions
diff --git a/xbmc/games/addons/input/GameClientKeyboard.cpp b/xbmc/games/addons/input/GameClientKeyboard.cpp index 8a21f99ad4..33c0ba5a10 100644 --- a/xbmc/games/addons/input/GameClientKeyboard.cpp +++ b/xbmc/games/addons/input/GameClientKeyboard.cpp @@ -31,7 +31,7 @@ CGameClientKeyboard::CGameClientKeyboard(CGameClient& gameClient, m_inputProvider(inputProvider), m_keyboardActivity(std::make_unique<CControllerActivity>()) { - m_inputProvider->RegisterKeyboardHandler(this, false); + m_inputProvider->RegisterKeyboardHandler(this, false, false); } CGameClientKeyboard::~CGameClientKeyboard() diff --git a/xbmc/games/addons/input/GameClientMouse.cpp b/xbmc/games/addons/input/GameClientMouse.cpp index 904c71b0cb..995cff68a1 100644 --- a/xbmc/games/addons/input/GameClientMouse.cpp +++ b/xbmc/games/addons/input/GameClientMouse.cpp @@ -27,7 +27,7 @@ CGameClientMouse::CGameClientMouse(CGameClient& gameClient, m_inputProvider(inputProvider), m_mouseActivity(std::make_unique<CControllerActivity>()) { - inputProvider->RegisterMouseHandler(this, false); + inputProvider->RegisterMouseHandler(this, false, false); } CGameClientMouse::~CGameClientMouse() diff --git a/xbmc/games/agents/input/AgentJoystick.cpp b/xbmc/games/agents/input/AgentJoystick.cpp index 5fa3527b74..95247fa3cd 100644 --- a/xbmc/games/agents/input/AgentJoystick.cpp +++ b/xbmc/games/agents/input/AgentJoystick.cpp @@ -9,6 +9,7 @@ #include "AgentJoystick.h" #include "games/controllers/Controller.h" +#include "games/controllers/ControllerIDs.h" #include "games/controllers/input/ControllerActivity.h" #include "input/joysticks/interfaces/IInputProvider.h" #include "peripherals/devices/Peripheral.h" @@ -63,7 +64,7 @@ std::string CAgentJoystick::ControllerID(void) const if (m_controllerAppearance) return m_controllerAppearance->ID(); - return ""; + return DEFAULT_CONTROLLER_ID; } bool CAgentJoystick::HasFeature(const std::string& feature) const diff --git a/xbmc/games/agents/input/AgentKeyboard.cpp b/xbmc/games/agents/input/AgentKeyboard.cpp index 0213c08e3f..9deaf78caf 100644 --- a/xbmc/games/agents/input/AgentKeyboard.cpp +++ b/xbmc/games/agents/input/AgentKeyboard.cpp @@ -9,6 +9,7 @@ #include "AgentKeyboard.h" #include "games/controllers/Controller.h" +#include "games/controllers/ControllerIDs.h" #include "games/controllers/input/ControllerActivity.h" #include "input/keyboard/interfaces/IKeyboardInputProvider.h" #include "peripherals/devices/Peripheral.h" @@ -32,7 +33,7 @@ void CAgentKeyboard::Initialize() KEYBOARD::IKeyboardInputProvider* inputProvider = m_peripheral.get(); // Register input handler to silently observe all input - inputProvider->RegisterKeyboardHandler(this, true); + inputProvider->RegisterKeyboardHandler(this, true, true); } void CAgentKeyboard::Deinitialize() @@ -59,10 +60,7 @@ float CAgentKeyboard::GetActivation() const std::string CAgentKeyboard::ControllerID(void) const { - if (m_controllerAppearance) - return m_controllerAppearance->ID(); - - return ""; + return DEFAULT_KEYBOARD_ID; } bool CAgentKeyboard::HasKey(const KEYBOARD::KeyName& key) const diff --git a/xbmc/games/agents/input/AgentMouse.cpp b/xbmc/games/agents/input/AgentMouse.cpp index 1e0ffa737e..7c94f0205f 100644 --- a/xbmc/games/agents/input/AgentMouse.cpp +++ b/xbmc/games/agents/input/AgentMouse.cpp @@ -9,6 +9,7 @@ #include "AgentMouse.h" #include "games/controllers/Controller.h" +#include "games/controllers/ControllerIDs.h" #include "games/controllers/input/ControllerActivity.h" #include "input/mouse/interfaces/IMouseInputProvider.h" #include "peripherals/devices/Peripheral.h" @@ -32,7 +33,7 @@ void CAgentMouse::Initialize() MOUSE::IMouseInputProvider* inputProvider = m_peripheral.get(); // Register input handler to silently observe all input - inputProvider->RegisterMouseHandler(this, true); + inputProvider->RegisterMouseHandler(this, true, true); } void CAgentMouse::Deinitialize() @@ -59,10 +60,7 @@ float CAgentMouse::GetActivation() const std::string CAgentMouse::ControllerID(void) const { - if (m_controllerAppearance) - return m_controllerAppearance->ID(); - - return ""; + return DEFAULT_MOUSE_ID; } bool CAgentMouse::OnMotion(const MOUSE::PointerName& relpointer, int differenceX, int differenceY) diff --git a/xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h b/xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h index 23799e8181..6f72c4f44b 100644 --- a/xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h +++ b/xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h @@ -30,8 +30,12 @@ public: * \param handler The handler to receive keyboard input provided by this class * \param bPromiscuous True to observe all events without affecting the * input's destination + * \param forceDefaultMap Always use the default keyboard buttonmap, avoiding + * buttonmaps provided by add-ons */ - virtual void RegisterKeyboardHandler(IKeyboardInputHandler* handler, bool bPromiscuous) = 0; + virtual void RegisterKeyboardHandler(IKeyboardInputHandler* handler, + bool bPromiscuous, + bool forceDefaultMap) = 0; /*! * \brief Unregisters handler from keyboard input diff --git a/xbmc/input/mouse/interfaces/IMouseInputProvider.h b/xbmc/input/mouse/interfaces/IMouseInputProvider.h index 6048aaaca3..6bc3a18497 100644 --- a/xbmc/input/mouse/interfaces/IMouseInputProvider.h +++ b/xbmc/input/mouse/interfaces/IMouseInputProvider.h @@ -30,8 +30,12 @@ public: * \param handler The handler to receive mouse input provided by this class * \param bPromiscuous True to observe all events without affecting * subsequent handlers + * \param forceDefaultMap Always use the default keyboard buttonmap, avoiding + * buttonmaps provided by add-ons */ - virtual void RegisterMouseHandler(IMouseInputHandler* handler, bool bPromiscuous) = 0; + virtual void RegisterMouseHandler(IMouseInputHandler* handler, + bool bPromiscuous, + bool forceDefaultMap) = 0; /*! * \brief Unregisters handler from mouse input diff --git a/xbmc/peripherals/devices/Peripheral.cpp b/xbmc/peripherals/devices/Peripheral.cpp index 671f8d4f52..18ea89b77a 100644 --- a/xbmc/peripherals/devices/Peripheral.cpp +++ b/xbmc/peripherals/devices/Peripheral.cpp @@ -624,24 +624,28 @@ void CPeripheral::UnregisterInputHandler(IInputHandler* handler) } void CPeripheral::RegisterKeyboardHandler(KEYBOARD::IKeyboardInputHandler* handler, - bool bPromiscuous) + bool bPromiscuous, + bool forceDefaultMap) { auto it = m_keyboardHandlers.find(handler); if (it == m_keyboardHandlers.end()) { std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler> keyboardDriverHandler; - PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this); - if (addon) - { - std::unique_ptr<CAddonInputHandling> addonInput = - std::make_unique<CAddonInputHandling>(m_manager, this, std::move(addon), handler); - if (addonInput->Load()) - keyboardDriverHandler = std::move(addonInput); - } - else + if (!forceDefaultMap) { - CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation); + PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this); + if (addon) + { + std::unique_ptr<CAddonInputHandling> addonInput = + std::make_unique<CAddonInputHandling>(m_manager, this, std::move(addon), handler); + if (addonInput->Load()) + keyboardDriverHandler = std::move(addonInput); + } + else + { + CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation); + } } if (!keyboardDriverHandler) @@ -670,24 +674,29 @@ void CPeripheral::UnregisterKeyboardHandler(KEYBOARD::IKeyboardInputHandler* han } } -void CPeripheral::RegisterMouseHandler(MOUSE::IMouseInputHandler* handler, bool bPromiscuous) +void CPeripheral::RegisterMouseHandler(MOUSE::IMouseInputHandler* handler, + bool bPromiscuous, + bool forceDefaultMap) { auto it = m_mouseHandlers.find(handler); if (it == m_mouseHandlers.end()) { std::unique_ptr<KODI::MOUSE::IMouseDriverHandler> mouseDriverHandler; - PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this); - if (addon) - { - std::unique_ptr<CAddonInputHandling> addonInput = - std::make_unique<CAddonInputHandling>(m_manager, this, std::move(addon), handler); - if (addonInput->Load()) - mouseDriverHandler = std::move(addonInput); - } - else + if (!forceDefaultMap) { - CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation); + PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this); + if (addon) + { + std::unique_ptr<CAddonInputHandling> addonInput = + std::make_unique<CAddonInputHandling>(m_manager, this, std::move(addon), handler); + if (addonInput->Load()) + mouseDriverHandler = std::move(addonInput); + } + else + { + CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation); + } } if (!mouseDriverHandler) diff --git a/xbmc/peripherals/devices/Peripheral.h b/xbmc/peripherals/devices/Peripheral.h index 3e7bb99d6e..95acef1344 100644 --- a/xbmc/peripherals/devices/Peripheral.h +++ b/xbmc/peripherals/devices/Peripheral.h @@ -240,11 +240,14 @@ public: // implementation of IKeyboardInputProvider void RegisterKeyboardHandler(KODI::KEYBOARD::IKeyboardInputHandler* handler, - bool bPromiscuous) override; + bool bPromiscuous, + bool forceDefaultMap) override; void UnregisterKeyboardHandler(KODI::KEYBOARD::IKeyboardInputHandler* handler) override; // implementation of IMouseInputProvider - void RegisterMouseHandler(KODI::MOUSE::IMouseInputHandler* handler, bool bPromiscuous) override; + void RegisterMouseHandler(KODI::MOUSE::IMouseInputHandler* handler, + bool bPromiscuous, + bool forceDefaultMap) override; void UnregisterMouseHandler(KODI::MOUSE::IMouseInputHandler* handler) override; virtual void RegisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper); |