diff options
author | Garrett Brown <themagnificentmrb@gmail.com> | 2017-07-23 06:23:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-23 06:23:14 -0700 |
commit | e7b7ebe9126beaa80cd9ffce96a4d94c22efe7df (patch) | |
tree | d1f6397a40ed683d7b930387c4ea0ca62223a6cc | |
parent | dece7533286f114e19056875ef6101223d055f5c (diff) | |
parent | 5dedbabb07375520d9835498e32ae43e3d321b3d (diff) |
Merge pull request #12547 from garbear/controller-fixes
Controller window: Bug fixes
20 files changed, 310 insertions, 64 deletions
diff --git a/xbmc/games/controllers/ControllerFeature.cpp b/xbmc/games/controllers/ControllerFeature.cpp index 3b517ee432..9e25a4320d 100644 --- a/xbmc/games/controllers/ControllerFeature.cpp +++ b/xbmc/games/controllers/ControllerFeature.cpp @@ -39,7 +39,7 @@ void CControllerFeature::Reset(void) m_strCategory.clear(); m_strName.clear(); m_strLabel.clear(); - m_labelId = 0; + m_labelId = -1; m_inputType = INPUT_TYPE::UNKNOWN; } @@ -74,7 +74,7 @@ bool CControllerFeature::Deserialize(const TiXmlElement* pElement, m_type = CControllerTranslator::TranslateFeatureType(strType); if (m_type == FEATURE_TYPE::UNKNOWN) { - CLog::Log(LOGERROR, "Invalid feature: <%s> ", pElement->Value()); + CLog::Log(LOGDEBUG, "Invalid feature: <%s> ", pElement->Value()); return false; } @@ -90,21 +90,16 @@ bool CControllerFeature::Deserialize(const TiXmlElement* pElement, return false; } - // Label (not used for motors) - if (m_type != FEATURE_TYPE::MOTOR) - { - // Label ID - std::string strLabel = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_FEATURE_LABEL); - if (strLabel.empty()) - { - CLog::Log(LOGERROR, "<%s> tag has no \"%s\" attribute", strType.c_str(), LAYOUT_XML_ATTR_FEATURE_LABEL); - return false; - } + // Label ID + std::string strLabel = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_FEATURE_LABEL); + if (strLabel.empty()) + CLog::Log(LOGDEBUG, "<%s> tag has no \"%s\" attribute", strType.c_str(), LAYOUT_XML_ATTR_FEATURE_LABEL); + else std::istringstream(strLabel) >> m_labelId; - // Label (string) + // Label (string) + if (m_labelId >= 0) m_strLabel = g_localizeStrings.GetAddonString(controller->ID(), m_labelId); - } // Input type if (m_type == FEATURE_TYPE::SCALAR) diff --git a/xbmc/games/controllers/ControllerFeature.h b/xbmc/games/controllers/ControllerFeature.h index c9aad8339c..f6d8e4c6ea 100644 --- a/xbmc/games/controllers/ControllerFeature.h +++ b/xbmc/games/controllers/ControllerFeature.h @@ -46,7 +46,7 @@ public: const std::string& CategoryLabel(void) const { return m_strCategory; } const std::string& Name(void) const { return m_strName; } const std::string& Label(void) const { return m_strLabel; } - unsigned int LabelID(void) const { return m_labelId; } + int LabelID(void) const { return m_labelId; } JOYSTICK::INPUT_TYPE InputType(void) const { return m_inputType; } bool Deserialize(const TiXmlElement* pElement, @@ -60,7 +60,7 @@ private: std::string m_strCategory; std::string m_strName; std::string m_strLabel; - unsigned int m_labelId; + int m_labelId; JOYSTICK::INPUT_TYPE m_inputType; }; diff --git a/xbmc/games/controllers/ControllerLayout.cpp b/xbmc/games/controllers/ControllerLayout.cpp index 2e29421aa6..f5fa280df8 100644 --- a/xbmc/games/controllers/ControllerLayout.cpp +++ b/xbmc/games/controllers/ControllerLayout.cpp @@ -103,7 +103,7 @@ bool CControllerLayout::Deserialize(const TiXmlElement* pElement, const CControl { if (pCategory->ValueStr() != LAYOUT_XML_ELM_CATEGORY) { - CLog::Log(LOGERROR, "<%s> tag is misnamed: <%s>", LAYOUT_XML_ELM_CATEGORY, pCategory->Value() ? pCategory->Value() : ""); + CLog::Log(LOGDEBUG, "Ignoring <%s> tag", pCategory->ValueStr().c_str()); continue; } @@ -128,10 +128,8 @@ bool CControllerLayout::Deserialize(const TiXmlElement* pElement, const CControl { CControllerFeature feature; - if (!feature.Deserialize(pFeature, controller, category, strCategoryLabel)) - return false; - - m_features.push_back(feature); + if (feature.Deserialize(pFeature, controller, category, strCategoryLabel)) + m_features.push_back(feature); } } diff --git a/xbmc/games/controllers/guicontrols/CMakeLists.txt b/xbmc/games/controllers/guicontrols/CMakeLists.txt index c719a88fd0..07df27a8a9 100644 --- a/xbmc/games/controllers/guicontrols/CMakeLists.txt +++ b/xbmc/games/controllers/guicontrols/CMakeLists.txt @@ -2,13 +2,18 @@ set(SOURCES GUIAnalogStickButton.cpp GUIControllerButton.cpp GUIFeatureButton.cpp GUIFeatureControls.cpp + GUIFeatureFactory.cpp + GUIFeatureTranslator.cpp GUIGameController.cpp GUIScalarFeatureButton.cpp) set(HEADERS GUIAnalogStickButton.h GUIControllerButton.h + GUIControlTypes.h GUIFeatureButton.h GUIFeatureControls.h + GUIFeatureFactory.h + GUIFeatureTranslator.h GUIGameController.h GUIScalarFeatureButton.h) diff --git a/xbmc/games/controllers/guicontrols/GUIControlTypes.h b/xbmc/games/controllers/guicontrols/GUIControlTypes.h new file mode 100644 index 0000000000..bdb2ff2852 --- /dev/null +++ b/xbmc/games/controllers/guicontrols/GUIControlTypes.h @@ -0,0 +1,36 @@ +/* +* Copyright (C) 2017 Team Kodi +* http://kodi.tv +* +* This Program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2, or (at your option) +* any later version. +* +* This Program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this Program; see the file COPYING. If not, see +* <http://www.gnu.org/licenses/>. +* +*/ +#pragma once + +namespace KODI +{ +namespace GAME +{ + /*! + * \brief Types of button controls that can populate the feature list + */ + enum class BUTTON_TYPE + { + UNKNOWN, + BUTTON, + ANALOG_STICK, + }; +} +} diff --git a/xbmc/games/controllers/guicontrols/GUIFeatureFactory.cpp b/xbmc/games/controllers/guicontrols/GUIFeatureFactory.cpp new file mode 100644 index 0000000000..d7eb89bf1b --- /dev/null +++ b/xbmc/games/controllers/guicontrols/GUIFeatureFactory.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2017 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this Program; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "GUIFeatureFactory.h" +#include "GUIAnalogStickButton.h" +#include "GUIScalarFeatureButton.h" + +using namespace KODI; +using namespace GAME; + +CGUIButtonControl* CGUIFeatureFactory::CreateButton(BUTTON_TYPE type, + const CGUIButtonControl& buttonTemplate, + IConfigurationWizard* wizard, + const CControllerFeature& feature, + unsigned int index) +{ + switch (type) + { + case BUTTON_TYPE::BUTTON: + return new CGUIScalarFeatureButton(buttonTemplate, wizard, feature, index); + + case BUTTON_TYPE::ANALOG_STICK: + return new CGUIAnalogStickButton(buttonTemplate, wizard, feature, index); + + default: + break; + } + + return nullptr; +} diff --git a/xbmc/games/controllers/guicontrols/GUIFeatureFactory.h b/xbmc/games/controllers/guicontrols/GUIFeatureFactory.h new file mode 100644 index 0000000000..3564e3159b --- /dev/null +++ b/xbmc/games/controllers/guicontrols/GUIFeatureFactory.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2017 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this Program; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "GUIControlTypes.h" + +class CGUIButtonControl; + +namespace KODI +{ +namespace GAME +{ + class CControllerFeature; + class IConfigurationWizard; + + class CGUIFeatureFactory + { + public: + /*! + * \brief Create a button of the specified type + * \param type The type of button control being created + * \return A button control, or nullptr if type is invalid + */ + static CGUIButtonControl* CreateButton(BUTTON_TYPE type, + const CGUIButtonControl& buttonTemplate, + IConfigurationWizard* wizard, + const CControllerFeature& feature, + unsigned int index); + }; +} +} diff --git a/xbmc/games/controllers/guicontrols/GUIFeatureTranslator.cpp b/xbmc/games/controllers/guicontrols/GUIFeatureTranslator.cpp new file mode 100644 index 0000000000..8ef1ec9b91 --- /dev/null +++ b/xbmc/games/controllers/guicontrols/GUIFeatureTranslator.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2017 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this Program; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "GUIFeatureTranslator.h" + +using namespace KODI; +using namespace GAME; + +BUTTON_TYPE CGUIFeatureTranslator::GetButtonType(JOYSTICK::FEATURE_TYPE featureType) +{ + switch (featureType) + { + case JOYSTICK::FEATURE_TYPE::SCALAR: + return BUTTON_TYPE::BUTTON; + + case JOYSTICK::FEATURE_TYPE::ANALOG_STICK: + return BUTTON_TYPE::ANALOG_STICK; + + default: + break; + } + + return BUTTON_TYPE::UNKNOWN; +} diff --git a/xbmc/games/controllers/guicontrols/GUIFeatureTranslator.h b/xbmc/games/controllers/guicontrols/GUIFeatureTranslator.h new file mode 100644 index 0000000000..4f841305ba --- /dev/null +++ b/xbmc/games/controllers/guicontrols/GUIFeatureTranslator.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2017 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this Program; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "GUIControlTypes.h" +#include "input/joysticks/JoystickTypes.h" + +namespace KODI +{ +namespace GAME +{ + class CGUIFeatureTranslator + { + public: + /*! + * \brief Get the type of button control used to map the feature + */ + static BUTTON_TYPE GetButtonType(JOYSTICK::FEATURE_TYPE featureType); + }; +} +} diff --git a/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp b/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp index 00acaa07dd..199dd6b680 100644 --- a/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp +++ b/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp @@ -60,6 +60,7 @@ void CGUIConfigurationWizard::InitializeState(void) m_currentDirection = JOYSTICK::ANALOG_STICK_DIRECTION::UNKNOWN; m_history.clear(); m_lateAxisDetected = false; + m_deviceName.clear(); } void CGUIConfigurationWizard::Run(const std::string& strControllerId, const std::vector<IFeatureButton*>& buttons) @@ -196,8 +197,7 @@ bool CGUIConfigurationWizard::MapPrimitive(JOYSTICK::IButtonMap* buttonMap, bool bHandled = false; // Handle esc key separately - if (primitive.Type() == PRIMITIVE_TYPE::BUTTON && - primitive.Index() == ESC_KEY_CODE) + if (!m_deviceName.empty() && m_deviceName != buttonMap->DeviceName()) { bool bIsCancelAction = false; @@ -293,6 +293,7 @@ bool CGUIConfigurationWizard::MapPrimitive(JOYSTICK::IButtonMap* buttonMap, OnMotion(buttonMap); m_inputEvent.Set(); + m_deviceName = buttonMap->DeviceName(); } } } diff --git a/xbmc/games/controllers/windows/GUIConfigurationWizard.h b/xbmc/games/controllers/windows/GUIConfigurationWizard.h index 8f27009bc4..512c1602e0 100644 --- a/xbmc/games/controllers/windows/GUIConfigurationWizard.h +++ b/xbmc/games/controllers/windows/GUIConfigurationWizard.h @@ -109,6 +109,7 @@ namespace GAME JOYSTICK::ANALOG_STICK_DIRECTION m_currentDirection; std::set<JOYSTICK::CDriverPrimitive> m_history; // History to avoid repeated features bool m_lateAxisDetected; // Set to true if an axis is detected during button mapping + std::string m_deviceName; CCriticalSection m_stateMutex; // Synchronization events diff --git a/xbmc/games/controllers/windows/GUIControllerList.cpp b/xbmc/games/controllers/windows/GUIControllerList.cpp index d5f4814236..9ff128d8b7 100644 --- a/xbmc/games/controllers/windows/GUIControllerList.cpp +++ b/xbmc/games/controllers/windows/GUIControllerList.cpp @@ -30,6 +30,7 @@ #include "addons/AddonManager.h" #include "dialogs/GUIDialogYesNo.h" #include "games/controllers/Controller.h" +#include "games/controllers/ControllerFeature.h" #include "games/controllers/ControllerLayout.h" #include "games/controllers/guicontrols/GUIControllerButton.h" #include "games/controllers/guicontrols/GUIGameController.h" @@ -162,6 +163,21 @@ bool CGUIControllerList::RefreshControllers(void) CGameServices& gameServices = CServiceBroker::GetGameServices(); ControllerVector newControllers = gameServices.GetControllers(); + // Don't show an empty list in the GUI + auto HasButtonForFeature = [this](const CControllerFeature &feature) + { + return m_featureList->HasButton(feature.Type()); + }; + + auto HasButtonForController = [&](const ControllerPtr &controller) + { + const auto &features = controller->Layout().Features(); + auto it = std::find_if(features.begin(), features.end(), HasButtonForFeature); + return it == features.end(); + }; + + newControllers.erase(std::remove_if(newControllers.begin(), newControllers.end(), HasButtonForController), newControllers.end()); + // Check for changes std::set<std::string> oldControllerIds; std::set<std::string> newControllerIds; diff --git a/xbmc/games/controllers/windows/GUIFeatureList.cpp b/xbmc/games/controllers/windows/GUIFeatureList.cpp index 518a6d2af7..9c152a6f28 100644 --- a/xbmc/games/controllers/windows/GUIFeatureList.cpp +++ b/xbmc/games/controllers/windows/GUIFeatureList.cpp @@ -19,12 +19,12 @@ */ #include "GUIFeatureList.h" - #include "GUIConfigurationWizard.h" #include "GUIControllerDefines.h" -#include "games/controllers/guicontrols/GUIAnalogStickButton.h" #include "games/controllers/guicontrols/GUIFeatureControls.h" -#include "games/controllers/guicontrols/GUIScalarFeatureButton.h" +#include "games/controllers/guicontrols/GUIFeatureButton.h" +#include "games/controllers/guicontrols/GUIFeatureFactory.h" +#include "games/controllers/guicontrols/GUIFeatureTranslator.h" #include "games/controllers/Controller.h" #include "games/controllers/ControllerLayout.h" #include "guilib/GUIButtonControl.h" @@ -169,7 +169,7 @@ IFeatureButton* CGUIFeatureList::GetButtonControl(unsigned int featureIndex) { CGUIControl* control = m_guiList->GetControl(CONTROL_FEATURE_BUTTONS_START + featureIndex); - return dynamic_cast<CGUIFeatureButton*>(control); + return static_cast<IFeatureButton*>(dynamic_cast<CGUIFeatureButton*>(control)); } void CGUIFeatureList::CleanupButtons(void) @@ -182,31 +182,44 @@ void CGUIFeatureList::CleanupButtons(void) std::vector<CGUIFeatureList::FeatureGroup> CGUIFeatureList::GetFeatureGroups(const std::vector<CControllerFeature>& features) { - std::vector<CGUIFeatureList::FeatureGroup> groups; + std::vector<FeatureGroup> groups; // Get group names std::vector<std::string> groupNames; for (const CControllerFeature& feature : features) { - if (std::find(groupNames.begin(), groupNames.end(), feature.CategoryLabel()) == groupNames.end()) - groupNames.push_back(feature.CategoryLabel()); - } + bool bAdded = false; - // Divide features into groups - for (std::string& groupName : groupNames) - { - FeatureGroup group = { groupName }; - for (const CControllerFeature& feature : features) + if (!groups.empty()) { - if (feature.CategoryLabel() == groupName) - group.features.push_back(feature); + FeatureGroup &previousGroup = *groups.rbegin(); + if (feature.CategoryLabel() == previousGroup.groupName) + { + // Add feature to previous group + previousGroup.features.emplace_back(feature); + bAdded = true; + } + } + + if (!bAdded) + { + // Create new group and add feature + FeatureGroup group; + group.groupName = feature.CategoryLabel(); + group.category = feature.Category(); + group.features.emplace_back(feature); + groups.emplace_back(std::move(group)); } - groups.emplace_back(std::move(group)); } return groups; } +bool CGUIFeatureList::HasButton(JOYSTICK::FEATURE_TYPE type) const +{ + return CGUIFeatureTranslator::GetButtonType(type) != BUTTON_TYPE::UNKNOWN; +} + std::vector<CGUIButtonControl*> CGUIFeatureList::GetButtons(const std::vector<CControllerFeature>& features, unsigned int startIndex) { std::vector<CGUIButtonControl*> buttons; @@ -215,27 +228,12 @@ std::vector<CGUIButtonControl*> CGUIFeatureList::GetButtons(const std::vector<CC unsigned int featureIndex = startIndex; for (const CControllerFeature& feature : features) { - CGUIButtonControl* pButton = nullptr; + BUTTON_TYPE buttonType = CGUIFeatureTranslator::GetButtonType(feature.Type()); - // Create button - switch (feature.Type()) - { - case JOYSTICK::FEATURE_TYPE::SCALAR: - { - pButton = new CGUIScalarFeatureButton(*m_guiButtonTemplate, m_wizard, feature, featureIndex); - break; - } - case JOYSTICK::FEATURE_TYPE::ANALOG_STICK: - { - pButton = new CGUIAnalogStickButton(*m_guiButtonTemplate, m_wizard, feature, featureIndex); - break; - } - default: - break; - } + CGUIButtonControl* pButton = CGUIFeatureFactory::CreateButton(buttonType, *m_guiButtonTemplate, m_wizard, feature, featureIndex); // If successful, add button to result - if (pButton) + if (pButton != nullptr) buttons.push_back(pButton); featureIndex++; diff --git a/xbmc/games/controllers/windows/GUIFeatureList.h b/xbmc/games/controllers/windows/GUIFeatureList.h index 6528c14b1e..226c0589d3 100644 --- a/xbmc/games/controllers/windows/GUIFeatureList.h +++ b/xbmc/games/controllers/windows/GUIFeatureList.h @@ -22,6 +22,7 @@ #include "IConfigurationWindow.h" #include "games/controllers/ControllerFeature.h" #include "games/controllers/ControllerTypes.h" +#include "input/joysticks/JoystickTypes.h" class CGUIButtonControl; class CGUIControlGroupList; @@ -42,6 +43,7 @@ namespace GAME // implementation of IFeatureList virtual bool Initialize(void) override; virtual void Deinitialize(void) override; + virtual bool HasButton(JOYSTICK::FEATURE_TYPE type) const override; virtual void Load(const ControllerPtr& controller) override; virtual void OnFocus(unsigned int index) override { } virtual void OnSelect(unsigned int index) override; @@ -55,6 +57,7 @@ namespace GAME struct FeatureGroup { std::string groupName; + JOYSTICK::FEATURE_CATEGORY category = JOYSTICK::FEATURE_CATEGORY::UNKNOWN; std::vector<CControllerFeature> features; }; static std::vector<FeatureGroup> GetFeatureGroups(const std::vector<CControllerFeature>& features); diff --git a/xbmc/games/controllers/windows/IConfigurationWindow.h b/xbmc/games/controllers/windows/IConfigurationWindow.h index f7fd05ea20..378779f23f 100644 --- a/xbmc/games/controllers/windows/IConfigurationWindow.h +++ b/xbmc/games/controllers/windows/IConfigurationWindow.h @@ -46,6 +46,8 @@ class CEvent; * and the prompt for input ends. */ +#include "input/joysticks/JoystickTypes.h" + namespace KODI { namespace GAME @@ -124,6 +126,13 @@ namespace GAME virtual void Deinitialize(void) = 0; /*! + * \brief Check if the feature type has any buttons in the GUI + * \param The type of the feature being added to the GUI + * \return True if the type is support, false otherwise + */ + virtual bool HasButton(JOYSTICK::FEATURE_TYPE type) const = 0; + + /*! * \brief Load the features for the specified controller * \param controller The controller to load */ diff --git a/xbmc/games/ports/Port.h b/xbmc/games/ports/Port.h index e957a0bed8..1f38147c04 100644 --- a/xbmc/games/ports/Port.h +++ b/xbmc/games/ports/Port.h @@ -60,6 +60,7 @@ namespace GAME // Implementation of IKeymapEnvironment virtual int GetWindowID() const override; + virtual void SetWindowID(int windowId) override { } virtual int GetFallthrough(int windowId) const override { return -1; } virtual bool UseGlobalFallthrough() const override { return false; } diff --git a/xbmc/input/IKeymapEnvironment.h b/xbmc/input/IKeymapEnvironment.h index 1eaf7f82ac..8c0604c21d 100644 --- a/xbmc/input/IKeymapEnvironment.h +++ b/xbmc/input/IKeymapEnvironment.h @@ -42,6 +42,13 @@ public: virtual int GetWindowID() const = 0; /*! + * \brief Set the window ID + * + * \param The window ID, used for translating actions + */ + virtual void SetWindowID(int windowId) = 0; + + /*! * \brief Get the fallthrough window to when a key definition is missing * * \param windowId The window ID diff --git a/xbmc/input/InputManager.cpp b/xbmc/input/InputManager.cpp index 81caa73ccc..f0dadd83e3 100644 --- a/xbmc/input/InputManager.cpp +++ b/xbmc/input/InputManager.cpp @@ -379,7 +379,10 @@ bool CInputManager::Process(int windowId, float frameTime) ProcessEventServer(windowId, frameTime); ProcessPeripherals(frameTime); ProcessQueuedActions(); - + + // Inform the environment of the new active window ID + m_keymapEnvironment->SetWindowID(windowId); + return true; } diff --git a/xbmc/input/KeymapEnvironment.cpp b/xbmc/input/KeymapEnvironment.cpp index 5c80243b68..412f4f107b 100644 --- a/xbmc/input/KeymapEnvironment.cpp +++ b/xbmc/input/KeymapEnvironment.cpp @@ -23,11 +23,6 @@ #include "guilib/GUIWindowManager.h" #include "Application.h" -int CKeymapEnvironment::GetWindowID() const -{ - return g_windowManager.GetActiveWindowID(); -} - int CKeymapEnvironment::GetFallthrough(int windowId) const { return CWindowTranslator::GetFallbackWindow(windowId); diff --git a/xbmc/input/KeymapEnvironment.h b/xbmc/input/KeymapEnvironment.h index 78e7437a02..019ebafdc9 100644 --- a/xbmc/input/KeymapEnvironment.h +++ b/xbmc/input/KeymapEnvironment.h @@ -27,7 +27,11 @@ public: virtual ~CKeymapEnvironment() = default; // implementation of IKeymapEnvironment - virtual int GetWindowID() const override; + virtual int GetWindowID() const override { return m_windowId; } + virtual void SetWindowID(int windowId) override { m_windowId = windowId; } virtual int GetFallthrough(int windowId) const override; virtual bool UseGlobalFallthrough() const override { return true; } + +private: + int m_windowId = -1; }; |