| 1 |
/* |
| 2 |
* Copyright (C) 2017-2024 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "WindowKeymap.h" |
| 10 |
|
| 11 |
#include "input/WindowTranslator.h" |
| 12 |
|
| 13 |
using namespace KODI; |
| 14 |
using namespace KEYMAP; |
| 15 |
|
| 16 |
CWindowKeymap::CWindowKeymap(const std::string& controllerId) : m_controllerId(controllerId) |
| 17 |
{ |
| 18 |
} |
| 19 |
|
| 20 |
void CWindowKeymap::MapAction(int windowId, const std::string& keyName, KeymapAction action) |
| 21 |
{ |
| 22 |
auto& actionGroup = m_windowKeymap[windowId][keyName]; |
| 23 |
|
| 24 |
actionGroup.windowId = windowId; |
| 25 |
auto it = actionGroup.actions.begin(); |
| 26 |
while (it != actionGroup.actions.end()) |
| 27 |
{ |
| 28 |
if (it->holdTimeMs == action.holdTimeMs && it->hotkeys == action.hotkeys) |
| 29 |
it = actionGroup.actions.erase(it); |
| 30 |
else |
| 31 |
it++; |
| 32 |
} |
| 33 |
actionGroup.actions.insert(std::move(action)); |
| 34 |
} |
| 35 |
|
| 36 |
const KeymapActionGroup& CWindowKeymap::GetActions(int windowId, const std::string& keyName) const |
| 37 |
{ |
| 38 |
// handle virtual windows |
| 39 |
windowId = CWindowTranslator::GetVirtualWindow(windowId); |
| 40 |
|
| 41 |
auto it = m_windowKeymap.find(windowId); |
| 42 |
if (it != m_windowKeymap.end()) |
| 43 |
{ |
| 44 |
auto& keymap = it->second; |
| 45 |
auto it2 = keymap.find(keyName); |
| 46 |
if (it2 != keymap.end()) |
| 47 |
return it2->second; |
| 48 |
} |
| 49 |
|
| 50 |
static const KeymapActionGroup empty{}; |
| 51 |
return empty; |
| 52 |
} |