diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 09:29:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 09:29:25 +0000 |
commit | 5d9aef0d431d3207b82abb0fdb813c94ae0a2a42 (patch) | |
tree | e9eafbbb3fecfeb0863a15195b92a0d0576e450f /xbmc/peripherals | |
parent | Adding debian version 2:20.4+dfsg-1. (diff) | |
download | kodi-5d9aef0d431d3207b82abb0fdb813c94ae0a2a42.tar.xz kodi-5d9aef0d431d3207b82abb0fdb813c94ae0a2a42.zip |
Merging upstream version 2:20.5+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/peripherals')
-rw-r--r-- | xbmc/peripherals/Peripherals.cpp | 2 | ||||
-rw-r--r-- | xbmc/peripherals/addons/AddonButtonMap.cpp | 28 | ||||
-rw-r--r-- | xbmc/peripherals/addons/AddonButtonMap.h | 5 | ||||
-rw-r--r-- | xbmc/peripherals/addons/AddonButtonMapping.cpp | 2 | ||||
-rw-r--r-- | xbmc/peripherals/addons/AddonInputHandling.cpp | 167 | ||||
-rw-r--r-- | xbmc/peripherals/addons/AddonInputHandling.h | 24 | ||||
-rw-r--r-- | xbmc/peripherals/bus/PeripheralBus.h | 17 | ||||
-rw-r--r-- | xbmc/peripherals/devices/Peripheral.cpp | 67 | ||||
-rw-r--r-- | xbmc/peripherals/devices/PeripheralJoystick.cpp | 3 |
9 files changed, 105 insertions, 210 deletions
diff --git a/xbmc/peripherals/Peripherals.cpp b/xbmc/peripherals/Peripherals.cpp index c178158..3dc5ca6 100644 --- a/xbmc/peripherals/Peripherals.cpp +++ b/xbmc/peripherals/Peripherals.cpp @@ -915,7 +915,7 @@ void CPeripherals::ResetButtonMaps(const std::string& controllerId) PeripheralAddonPtr addon; if (addonBus->GetAddonWithButtonMap(peripheral.get(), addon)) { - CAddonButtonMap buttonMap(peripheral.get(), addon, controllerId, *this); + CAddonButtonMap buttonMap(peripheral.get(), addon, controllerId); buttonMap.Reset(); } } diff --git a/xbmc/peripherals/addons/AddonButtonMap.cpp b/xbmc/peripherals/addons/AddonButtonMap.cpp index 0d76ec9..f2c894c 100644 --- a/xbmc/peripherals/addons/AddonButtonMap.cpp +++ b/xbmc/peripherals/addons/AddonButtonMap.cpp @@ -10,7 +10,6 @@ #include "PeripheralAddonTranslator.h" #include "input/joysticks/JoystickUtils.h" -#include "peripherals/Peripherals.h" #include "peripherals/devices/Peripheral.h" #include "utils/log.h" @@ -25,9 +24,8 @@ using namespace PERIPHERALS; CAddonButtonMap::CAddonButtonMap(CPeripheral* device, const std::weak_ptr<CPeripheralAddon>& addon, - const std::string& strControllerId, - CPeripherals& manager) - : m_device(device), m_addon(addon), m_strControllerId(strControllerId), m_manager(manager) + const std::string& strControllerId) + : m_device(device), m_addon(addon), m_strControllerId(strControllerId) { auto peripheralAddon = m_addon.lock(); assert(peripheralAddon != nullptr); @@ -60,28 +58,6 @@ bool CAddonButtonMap::Load(void) bSuccess |= addon->GetIgnoredPrimitives(m_device, ignoredPrimitives); } - if (features.empty()) - { - // Check if we can initialize a buttonmap from the peripheral bus - PeripheralBusPtr peripheralBus = m_manager.GetBusByType(m_device->GetBusType()); - if (peripheralBus) - { - CLog::Log(LOGDEBUG, - "Buttonmap not found for {}, attempting to initialize from peripheral bus", - m_device->Location()); - if (peripheralBus->InitializeButtonMap(*m_device, *this)) - { - bSuccess = true; - - if (auto addon = m_addon.lock()) - { - addon->GetFeatures(m_device, m_strControllerId, features); - addon->GetIgnoredPrimitives(m_device, ignoredPrimitives); - } - } - } - } - // GetFeatures() was changed to always return false if no features were // retrieved. Check here, just in case its contract is changed or violated in // the future. diff --git a/xbmc/peripherals/addons/AddonButtonMap.h b/xbmc/peripherals/addons/AddonButtonMap.h index cade54b..b6a629f 100644 --- a/xbmc/peripherals/addons/AddonButtonMap.h +++ b/xbmc/peripherals/addons/AddonButtonMap.h @@ -18,15 +18,13 @@ namespace PERIPHERALS { class CPeripheral; -class CPeripherals; class CAddonButtonMap : public KODI::JOYSTICK::IButtonMap { public: CAddonButtonMap(CPeripheral* device, const std::weak_ptr<CPeripheralAddon>& addon, - const std::string& strControllerId, - CPeripherals& manager); + const std::string& strControllerId); ~CAddonButtonMap(void) override; @@ -132,7 +130,6 @@ private: CPeripheral* const m_device; const std::weak_ptr<CPeripheralAddon> m_addon; const std::string m_strControllerId; - CPeripherals& m_manager; // Button map state std::string m_controllerAppearance; diff --git a/xbmc/peripherals/addons/AddonButtonMapping.cpp b/xbmc/peripherals/addons/AddonButtonMapping.cpp index abf981f..af838aa 100644 --- a/xbmc/peripherals/addons/AddonButtonMapping.cpp +++ b/xbmc/peripherals/addons/AddonButtonMapping.cpp @@ -31,7 +31,7 @@ CAddonButtonMapping::CAddonButtonMapping(CPeripherals& manager, else { const std::string controllerId = mapper->ControllerID(); - m_buttonMap = std::make_unique<CAddonButtonMap>(peripheral, addon, controllerId, manager); + m_buttonMap.reset(new CAddonButtonMap(peripheral, addon, controllerId)); if (m_buttonMap->Load()) { IKeymap* keymap = peripheral->GetKeymap(controllerId); diff --git a/xbmc/peripherals/addons/AddonInputHandling.cpp b/xbmc/peripherals/addons/AddonInputHandling.cpp index 7490b96..644c33e 100644 --- a/xbmc/peripherals/addons/AddonInputHandling.cpp +++ b/xbmc/peripherals/addons/AddonInputHandling.cpp @@ -16,8 +16,8 @@ #include "input/keyboard/interfaces/IKeyboardInputHandler.h" #include "input/mouse/generic/MouseInputHandling.h" #include "input/mouse/interfaces/IMouseInputHandler.h" +#include "peripherals/Peripherals.h" #include "peripherals/addons/AddonButtonMap.h" -#include "peripherals/devices/Peripheral.h" #include "utils/log.h" using namespace KODI; @@ -26,106 +26,105 @@ using namespace PERIPHERALS; CAddonInputHandling::CAddonInputHandling(CPeripherals& manager, CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, IInputHandler* handler, IDriverReceiver* receiver) - : m_manager(manager), - m_peripheral(peripheral), - m_addon(std::move(addon)), - m_joystickInputHandler(handler), - m_joystickDriverReceiver(receiver) { + PeripheralAddonPtr addon = manager.GetAddonWithButtonMap(peripheral); + + if (!addon) + { + CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", peripheral->DeviceName()); + } + else + { + m_buttonMap.reset(new CAddonButtonMap(peripheral, addon, handler->ControllerID())); + if (m_buttonMap->Load()) + { + m_driverHandler.reset(new CInputHandling(handler, m_buttonMap.get())); + + if (receiver) + { + m_inputReceiver.reset(new CDriverReceiving(receiver, m_buttonMap.get())); + + // Interfaces are connected here because they share button map as a common resource + handler->SetInputReceiver(m_inputReceiver.get()); + } + } + else + { + m_buttonMap.reset(); + } + } } CAddonInputHandling::CAddonInputHandling(CPeripherals& manager, CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, KEYBOARD::IKeyboardInputHandler* handler) - : m_manager(manager), - m_peripheral(peripheral), - m_addon(std::move(addon)), - m_keyboardInputHandler(handler) { + PeripheralAddonPtr addon = manager.GetAddonWithButtonMap(peripheral); + + if (!addon) + { + CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", peripheral->DeviceName()); + } + else + { + m_buttonMap.reset(new CAddonButtonMap(peripheral, addon, handler->ControllerID())); + if (m_buttonMap->Load()) + { + m_keyboardHandler.reset(new KEYBOARD::CKeyboardInputHandling(handler, m_buttonMap.get())); + } + else + { + m_buttonMap.reset(); + } + } } CAddonInputHandling::CAddonInputHandling(CPeripherals& manager, CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, MOUSE::IMouseInputHandler* handler) - : m_manager(manager), - m_peripheral(peripheral), - m_addon(std::move(addon)), - m_mouseInputHandler(handler) { -} + PeripheralAddonPtr addon = manager.GetAddonWithButtonMap(peripheral); -CAddonInputHandling::~CAddonInputHandling(void) -{ - m_joystickDriverHandler.reset(); - m_joystickInputReceiver.reset(); - m_keyboardDriverHandler.reset(); - m_mouseDriverHandler.reset(); - m_buttonMap.reset(); -} - -bool CAddonInputHandling::Load() -{ - std::string controllerId; - if (m_joystickInputHandler != nullptr) - controllerId = m_joystickInputHandler->ControllerID(); - else if (m_keyboardInputHandler != nullptr) - controllerId = m_keyboardInputHandler->ControllerID(); - else if (m_mouseInputHandler != nullptr) - controllerId = m_mouseInputHandler->ControllerID(); - - if (!controllerId.empty()) - m_buttonMap = std::make_unique<CAddonButtonMap>(m_peripheral, m_addon, controllerId, m_manager); - - if (m_buttonMap && m_buttonMap->Load()) + if (!addon) { - if (m_joystickInputHandler != nullptr) - { - m_joystickDriverHandler = - std::make_unique<CInputHandling>(m_joystickInputHandler, m_buttonMap.get()); - if (m_joystickDriverReceiver != nullptr) - { - m_joystickInputReceiver = - std::make_unique<CDriverReceiving>(m_joystickDriverReceiver, m_buttonMap.get()); - - // Interfaces are connected here because they share button map as a common resource - m_joystickInputHandler->SetInputReceiver(m_joystickInputReceiver.get()); - } - return true; - } - else if (m_keyboardInputHandler != nullptr) + CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", peripheral->DeviceName()); + } + else + { + m_buttonMap.reset(new CAddonButtonMap(peripheral, addon, handler->ControllerID())); + if (m_buttonMap->Load()) { - m_keyboardDriverHandler = std::make_unique<KEYBOARD::CKeyboardInputHandling>( - m_keyboardInputHandler, m_buttonMap.get()); - return true; + m_mouseHandler.reset(new MOUSE::CMouseInputHandling(handler, m_buttonMap.get())); } - else if (m_mouseInputHandler != nullptr) + else { - m_mouseDriverHandler = - std::make_unique<MOUSE::CMouseInputHandling>(m_mouseInputHandler, m_buttonMap.get()); - return true; + m_buttonMap.reset(); } } +} - return false; +CAddonInputHandling::~CAddonInputHandling(void) +{ + m_driverHandler.reset(); + m_inputReceiver.reset(); + m_keyboardHandler.reset(); + m_buttonMap.reset(); } bool CAddonInputHandling::OnButtonMotion(unsigned int buttonIndex, bool bPressed) { - if (m_joystickDriverHandler) - return m_joystickDriverHandler->OnButtonMotion(buttonIndex, bPressed); + if (m_driverHandler) + return m_driverHandler->OnButtonMotion(buttonIndex, bPressed); return false; } bool CAddonInputHandling::OnHatMotion(unsigned int hatIndex, HAT_STATE state) { - if (m_joystickDriverHandler) - return m_joystickDriverHandler->OnHatMotion(hatIndex, state); + if (m_driverHandler) + return m_driverHandler->OnHatMotion(hatIndex, state); return false; } @@ -135,58 +134,58 @@ bool CAddonInputHandling::OnAxisMotion(unsigned int axisIndex, int center, unsigned int range) { - if (m_joystickDriverHandler) - return m_joystickDriverHandler->OnAxisMotion(axisIndex, position, center, range); + if (m_driverHandler) + return m_driverHandler->OnAxisMotion(axisIndex, position, center, range); return false; } void CAddonInputHandling::OnInputFrame(void) { - if (m_joystickDriverHandler) - m_joystickDriverHandler->OnInputFrame(); + if (m_driverHandler) + m_driverHandler->OnInputFrame(); } bool CAddonInputHandling::OnKeyPress(const CKey& key) { - if (m_keyboardDriverHandler) - return m_keyboardDriverHandler->OnKeyPress(key); + if (m_keyboardHandler) + return m_keyboardHandler->OnKeyPress(key); return false; } void CAddonInputHandling::OnKeyRelease(const CKey& key) { - if (m_keyboardDriverHandler) - m_keyboardDriverHandler->OnKeyRelease(key); + if (m_keyboardHandler) + m_keyboardHandler->OnKeyRelease(key); } bool CAddonInputHandling::OnPosition(int x, int y) { - if (m_mouseDriverHandler) - return m_mouseDriverHandler->OnPosition(x, y); + if (m_mouseHandler) + return m_mouseHandler->OnPosition(x, y); return false; } bool CAddonInputHandling::OnButtonPress(MOUSE::BUTTON_ID button) { - if (m_mouseDriverHandler) - return m_mouseDriverHandler->OnButtonPress(button); + if (m_mouseHandler) + return m_mouseHandler->OnButtonPress(button); return false; } void CAddonInputHandling::OnButtonRelease(MOUSE::BUTTON_ID button) { - if (m_mouseDriverHandler) - m_mouseDriverHandler->OnButtonRelease(button); + if (m_mouseHandler) + m_mouseHandler->OnButtonRelease(button); } bool CAddonInputHandling::SetRumbleState(const JOYSTICK::FeatureName& feature, float magnitude) { - if (m_joystickInputReceiver) - return m_joystickInputReceiver->SetRumbleState(feature, magnitude); + if (m_inputReceiver) + return m_inputReceiver->SetRumbleState(feature, magnitude); return false; } diff --git a/xbmc/peripherals/addons/AddonInputHandling.h b/xbmc/peripherals/addons/AddonInputHandling.h index 295e6d4..2a59162 100644 --- a/xbmc/peripherals/addons/AddonInputHandling.h +++ b/xbmc/peripherals/addons/AddonInputHandling.h @@ -39,7 +39,6 @@ namespace PERIPHERALS { class CPeripheral; class CPeripherals; -class CPeripheralAddon; class CAddonInputHandling : public KODI::JOYSTICK::IDriverHandler, public KODI::JOYSTICK::IInputReceiver, @@ -49,24 +48,19 @@ class CAddonInputHandling : public KODI::JOYSTICK::IDriverHandler, public: CAddonInputHandling(CPeripherals& manager, CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, KODI::JOYSTICK::IInputHandler* handler, KODI::JOYSTICK::IDriverReceiver* receiver); CAddonInputHandling(CPeripherals& manager, CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, KODI::KEYBOARD::IKeyboardInputHandler* handler); CAddonInputHandling(CPeripherals& manager, CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, KODI::MOUSE::IMouseInputHandler* handler); ~CAddonInputHandling(void) override; - bool Load(); - // implementation of IDriverHandler bool OnButtonMotion(unsigned int buttonIndex, bool bPressed) override; bool OnHatMotion(unsigned int hatIndex, KODI::JOYSTICK::HAT_STATE state) override; @@ -89,20 +83,10 @@ public: bool SetRumbleState(const KODI::JOYSTICK::FeatureName& feature, float magnitude) override; private: - // Construction parameters - CPeripherals& m_manager; - CPeripheral* const m_peripheral; - const std::shared_ptr<CPeripheralAddon> m_addon; - KODI::JOYSTICK::IInputHandler* const m_joystickInputHandler{nullptr}; - KODI::JOYSTICK::IDriverReceiver* const m_joystickDriverReceiver{nullptr}; - KODI::KEYBOARD::IKeyboardInputHandler* m_keyboardInputHandler{nullptr}; - KODI::MOUSE::IMouseInputHandler* const m_mouseInputHandler{nullptr}; - - // Input parameters - std::unique_ptr<KODI::JOYSTICK::IDriverHandler> m_joystickDriverHandler; - std::unique_ptr<KODI::JOYSTICK::IInputReceiver> m_joystickInputReceiver; - std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler> m_keyboardDriverHandler; - std::unique_ptr<KODI::MOUSE::IMouseDriverHandler> m_mouseDriverHandler; + std::unique_ptr<KODI::JOYSTICK::IDriverHandler> m_driverHandler; + std::unique_ptr<KODI::JOYSTICK::IInputReceiver> m_inputReceiver; + std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler> m_keyboardHandler; + std::unique_ptr<KODI::MOUSE::IMouseDriverHandler> m_mouseHandler; std::unique_ptr<KODI::JOYSTICK::IButtonMap> m_buttonMap; }; } // namespace PERIPHERALS diff --git a/xbmc/peripherals/bus/PeripheralBus.h b/xbmc/peripherals/bus/PeripheralBus.h index 6b67a7f..c23abff 100644 --- a/xbmc/peripherals/bus/PeripheralBus.h +++ b/xbmc/peripherals/bus/PeripheralBus.h @@ -17,14 +17,6 @@ class CFileItemList; -namespace KODI -{ -namespace JOYSTICK -{ -class IButtonMap; -} // namespace JOYSTICK -} // namespace KODI - namespace PERIPHERALS { class CPeripheral; @@ -66,15 +58,6 @@ public: virtual bool InitializeProperties(CPeripheral& peripheral); /*! - * \brief Initialize a joystick buttonmap, if possible - */ - virtual bool InitializeButtonMap(const CPeripheral& peripheral, - KODI::JOYSTICK::IButtonMap& buttonMap) const - { - return false; - } - - /*! * @brief Get the instance of the peripheral at the given location. * @param strLocation The location. * @return The peripheral or NULL if it wasn't found. diff --git a/xbmc/peripherals/devices/Peripheral.cpp b/xbmc/peripherals/devices/Peripheral.cpp index 6c3f779..2c656a3 100644 --- a/xbmc/peripherals/devices/Peripheral.cpp +++ b/xbmc/peripherals/devices/Peripheral.cpp @@ -588,21 +588,10 @@ void CPeripheral::RegisterInputHandler(IInputHandler* handler, bool bPromiscuous auto it = m_inputHandlers.find(handler); if (it == m_inputHandlers.end()) { - PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this); - if (addon) - { - std::unique_ptr<CAddonInputHandling> addonInput = std::make_unique<CAddonInputHandling>( - m_manager, this, std::move(addon), handler, GetDriverReceiver()); - if (addonInput->Load()) - { - RegisterJoystickDriverHandler(addonInput.get(), bPromiscuous); - m_inputHandlers[handler] = std::move(addonInput); - } - } - else - { - CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation); - } + CAddonInputHandling* addonInput = + new CAddonInputHandling(m_manager, this, handler, GetDriverReceiver()); + RegisterJoystickDriverHandler(addonInput, bPromiscuous); + m_inputHandlers[handler].reset(addonInput); } } @@ -624,26 +613,10 @@ void CPeripheral::RegisterKeyboardHandler(KEYBOARD::IKeyboardInputHandler* handl 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 - { - CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation); - } - - if (keyboardDriverHandler) - { - RegisterKeyboardDriverHandler(keyboardDriverHandler.get(), bPromiscuous); - m_keyboardHandlers[handler] = std::move(keyboardDriverHandler); - } + std::unique_ptr<CAddonInputHandling> addonInput( + new CAddonInputHandling(m_manager, this, handler)); + RegisterKeyboardDriverHandler(addonInput.get(), bPromiscuous); + m_keyboardHandlers[handler] = std::move(addonInput); } } @@ -662,26 +635,10 @@ void CPeripheral::RegisterMouseHandler(MOUSE::IMouseInputHandler* handler, bool 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 - { - CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation); - } - - if (mouseDriverHandler) - { - RegisterMouseDriverHandler(mouseDriverHandler.get(), bPromiscuous); - m_mouseHandlers[handler] = std::move(mouseDriverHandler); - } + std::unique_ptr<CAddonInputHandling> addonInput( + new CAddonInputHandling(m_manager, this, handler)); + RegisterMouseDriverHandler(addonInput.get(), bPromiscuous); + m_mouseHandlers[handler] = std::move(addonInput); } } diff --git a/xbmc/peripherals/devices/PeripheralJoystick.cpp b/xbmc/peripherals/devices/PeripheralJoystick.cpp index bccad91..e2087a7 100644 --- a/xbmc/peripherals/devices/PeripheralJoystick.cpp +++ b/xbmc/peripherals/devices/PeripheralJoystick.cpp @@ -98,8 +98,7 @@ bool CPeripheralJoystick::InitialiseFeature(const PeripheralFeature feature) if (bSuccess) { - m_buttonMap = - std::make_unique<CAddonButtonMap>(this, addon, DEFAULT_CONTROLLER_ID, m_manager); + m_buttonMap = std::make_unique<CAddonButtonMap>(this, addon, DEFAULT_CONTROLLER_ID); if (m_buttonMap->Load()) { InitializeDeadzoneFiltering(*m_buttonMap); |