xbmc
ButtonTranslator.h
1 /*
2  * Copyright (C) 2005-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 #pragma once
10 
11 #include "input/actions/Action.h"
12 #include "network/EventClient.h"
13 
14 #include <map>
15 #include <set>
16 #include <string>
17 
18 class CKey;
19 
20 namespace tinyxml2
21 {
22 class XMLNode;
23 }
24 
25 namespace KODI
26 {
27 namespace KEYMAP
28 {
29 class CCustomControllerTranslator;
30 class CTouchTranslator;
31 class IKeyMapper;
32 class IWindowKeymap;
33 
42 {
43  friend class EVENTCLIENT::CEventButtonState;
44 
45 public:
46  CButtonTranslator() = default;
47  CButtonTranslator(const CButtonTranslator&) = delete;
48  CButtonTranslator const& operator=(CButtonTranslator const&) = delete;
49  virtual ~CButtonTranslator() = default;
50 
51  // Add/remove a HID device with custom mappings
52  bool AddDevice(const std::string& strDevice);
53  bool RemoveDevice(const std::string& strDevice);
54 
56  bool Load();
57 
59  void Clear();
60 
66  bool HasLongpressMapping(int window, const CKey& key);
67 
75  CAction GetAction(int window, const CKey& key, bool fallback = true);
76 
77  void RegisterMapper(const std::string& device, IKeyMapper* mapper);
78  void UnregisterMapper(const IKeyMapper* mapper);
79 
80  static uint32_t TranslateString(const std::string& strMap, const std::string& strButton);
81 
82 private:
83  struct CButtonAction
84  {
85  unsigned int id;
86  std::string strID; // needed for "ActivateWindow()" type actions
87  };
88 
89  typedef std::multimap<uint32_t, CButtonAction> buttonMap; // our button map to fill in
90 
91  // m_translatorMap contains all mappings i.e. m_BaseMap + HID device mappings
92  std::map<int, buttonMap> m_translatorMap;
93 
94  // m_deviceList contains the list of connected HID devices
95  std::set<std::string> m_deviceList;
96 
97  unsigned int GetActionCode(int window, const CKey& key, std::string& strAction) const;
98 
99  void MapWindowActions(const tinyxml2::XMLNode* pWindow, int wWindowID);
100  void MapAction(uint32_t buttonCode, const std::string& szAction, buttonMap& map);
101 
102  bool LoadKeymap(const std::string& keymapPath);
103 
104  bool HasLongpressMapping_Internal(int window, const CKey& key);
105 
106  std::map<std::string, IKeyMapper*> m_buttonMappers;
107 };
108 } // namespace KEYMAP
109 } // namespace KODI
Singleton class to map from buttons to actions.
Definition: ButtonTranslator.h:41
Definition: EventClient.h:47
Definition: AddonInfoBuilder.h:21
Interface for classes that can map buttons to Kodi actions.
Definition: IKeyMapper.h:25
Class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:21
Definition: AudioDecoder.h:18
Definition: Key.h:17