Debian Codegraph @

xbmc/input/keymaps/Keymap.cpp

raw
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 "Keymap.h"
10
11 #include "input/keymaps/interfaces/IKeymapEnvironment.h"
12
13 using namespace KODI;
14 using namespace KEYMAP;
15
16 CKeymap::CKeymap(std::shared_ptr<const IWindowKeymap> keymap, const IKeymapEnvironment* environment)
17 : m_keymap(std::move(keymap)), m_environment(environment)
18 {
19 }
20
21 std::string CKeymap::ControllerID() const
22 {
23 return m_keymap->ControllerID();
24 }
25
26 const KeymapActionGroup& CKeymap::GetActions(const std::string& keyName) const
27 {
28 const int windowId = m_environment->GetWindowID();
29 const auto& actions = m_keymap->GetActions(windowId, keyName);
30 if (!actions.actions.empty())
31 return actions;
32
33 const int fallbackWindowId = m_environment->GetFallthrough(windowId);
34 if (fallbackWindowId >= 0)
35 {
36 const auto& fallbackActions = m_keymap->GetActions(fallbackWindowId, keyName);
37 if (!fallbackActions.actions.empty())
38 return fallbackActions;
39 }
40
41 if (m_environment->UseGlobalFallthrough())
42 {
43 const auto& globalActions = m_keymap->GetActions(-1, keyName);
44 if (!globalActions.actions.empty())
45 return globalActions;
46 }
47
48 static const KeymapActionGroup empty{};
49 return empty;
50 }