2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "input/actions/Action.h"
12 #include "network/EventClient.h"
20 class CCustomControllerTranslator
;
21 class CTouchTranslator
;
25 /// singleton class to map from buttons to actions
26 /// Warning: _not_ threadsafe!
27 class CButtonTranslator
29 friend class EVENTCLIENT::CEventButtonState
;
32 CButtonTranslator() = default;
33 CButtonTranslator(const CButtonTranslator
&) = delete;
34 CButtonTranslator
const& operator=(CButtonTranslator
const&) = delete;
35 virtual ~CButtonTranslator() = default;
37 // Add/remove a HID device with custom mappings
38 bool AddDevice(const std::string
& strDevice
);
39 bool RemoveDevice(const std::string
& strDevice
);
47 /*! \brief Finds out if a longpress mapping exists for this key
48 \param window id of the current window
49 \param key to search a mapping for
50 \return true if a longpress mapping exists
52 bool HasLongpressMapping(int window
, const CKey
& key
);
54 /*! \brief Obtain the action configured for a given window and key
55 \param window the window id
56 \param key the key to query the action for
57 \param fallback if no action is directly configured for the given window, obtain the action from
58 fallback window, if exists or from global config as last resort
59 \return the action matching the key
61 CAction
GetAction(int window
, const CKey
& key
, bool fallback
= true);
63 void RegisterMapper(const std::string
& device
, IButtonMapper
* mapper
);
64 void UnregisterMapper(const IButtonMapper
* mapper
);
66 static uint32_t TranslateString(const std::string
& strMap
, const std::string
& strButton
);
72 std::string strID
; // needed for "ActivateWindow()" type actions
75 typedef std::multimap
<uint32_t, CButtonAction
> buttonMap
; // our button map to fill in
77 // m_translatorMap contains all mappings i.e. m_BaseMap + HID device mappings
78 std::map
<int, buttonMap
> m_translatorMap
;
80 // m_deviceList contains the list of connected HID devices
81 std::set
<std::string
> m_deviceList
;
83 unsigned int GetActionCode(int window
, const CKey
& key
, std::string
& strAction
) const;
85 void MapWindowActions(const TiXmlNode
* pWindow
, int wWindowID
);
86 void MapAction(uint32_t buttonCode
, const std::string
& szAction
, buttonMap
& map
);
88 bool LoadKeymap(const std::string
& keymapPath
);
90 bool HasLongpressMapping_Internal(int window
, const CKey
& key
);
92 std::map
<std::string
, IButtonMapper
*> m_buttonMappers
;