From 39c56613539ff4de3c077c270686c3f6ccc8f9d5 Mon Sep 17 00:00:00 2001 From: arucard21 Date: Thu, 22 Aug 2019 11:14:02 +0200 Subject: [PATCH] Override joystick controls per-keyname (fixes userdata config override) --- xbmc/input/JoystickMapper.cpp | 18 +++++++++--------- xbmc/input/WindowKeymap.cpp | 8 ++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/xbmc/input/JoystickMapper.cpp b/xbmc/input/JoystickMapper.cpp index 5bcbbbbace0e2..36cdc610961a4 100644 --- a/xbmc/input/JoystickMapper.cpp +++ b/xbmc/input/JoystickMapper.cpp @@ -37,6 +37,15 @@ void CJoystickMapper::MapActions(int windowID, const TiXmlNode *pDevice) if (controllerId.empty()) return; + // Update Controller IDs + if (std::find(m_controllerIds.begin(), m_controllerIds.end(), controllerId) == m_controllerIds.end()) + m_controllerIds.emplace_back(controllerId); + + // Create/overwrite keymap + auto& keymap = m_joystickKeymaps[controllerId]; + if (!keymap) + keymap.reset(new CWindowKeymap(controllerId)); + const TiXmlElement *pButton = pDevice->FirstChildElement(); while (pButton != nullptr) { @@ -47,15 +56,6 @@ void CJoystickMapper::MapActions(int windowID, const TiXmlNode *pDevice) std::string actionString; if (DeserializeButton(pButton, feature, dir, holdtimeMs, hotkeys, actionString)) { - // Update Controller IDs - if (std::find(m_controllerIds.begin(), m_controllerIds.end(), controllerId) == m_controllerIds.end()) - m_controllerIds.emplace_back(controllerId); - - // Find/create keymap - auto &keymap = m_joystickKeymaps[controllerId]; - if (!keymap) - keymap.reset(new CWindowKeymap(controllerId)); - // Update keymap unsigned int actionId = ACTION_NONE; if (CActionTranslator::TranslateString(actionString, actionId)) diff --git a/xbmc/input/WindowKeymap.cpp b/xbmc/input/WindowKeymap.cpp index 89bafda34be33..d927045398840 100644 --- a/xbmc/input/WindowKeymap.cpp +++ b/xbmc/input/WindowKeymap.cpp @@ -21,6 +21,14 @@ void CWindowKeymap::MapAction(int windowId, const std::string &keyName, JOYSTICK auto &actionGroup = m_windowKeymap[windowId][keyName]; actionGroup.windowId = windowId; + auto it = actionGroup.actions.begin(); + while (it != actionGroup.actions.end()) + { + if (it->holdTimeMs == action.holdTimeMs && it->hotkeys == action.hotkeys) + it = actionGroup.actions.erase(it); + else + it++; + } actionGroup.actions.insert(std::move(action)); }