Debian Codegraph @

xbmc/input/keymaps/generic/KeyHandler.h

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 #pragma once
10
11 #include "input/actions/Action.h"
12 #include "input/keymaps/KeymapTypes.h"
13 #include "input/keymaps/interfaces/IKeyHandler.h"
14
15 #include <map>
16 #include <string>
17 #include <vector>
18
19 class CAction;
20
21 namespace KODI
22 {
23 namespace ACTION
24 {
25 class IActionListener;
26 } // namespace ACTION
27
28 namespace KEYMAP
29 {
30 class IKeymapHandler;
31 class IKeymap;
32
33 /*!
34 * \ingroup keymap
35 */
36 class CKeyHandler : public IKeyHandler
37 {
38 public:
39 CKeyHandler(const std::string& keyName,
40 ACTION::IActionListener* actionHandler,
41 const IKeymap* keymap,
42 IKeymapHandler* keymapHandler);
43
44 ~CKeyHandler() override = default;
45
46 // implementation of IKeyHandler
47 bool IsPressed() const override { return m_bHeld; }
48 bool OnDigitalMotion(bool bPressed, unsigned int holdTimeMs) override;
49 bool OnAnalogMotion(float magnitude, unsigned int motionTimeMs) override;
50
51 private:
52 void Reset();
53
54 /*!
55 * \brief Process actions to see if an action should be dispatched
56 *
57 * \param actions All actions from the keymap defined for the current window
58 * \param windowId The current window ID
59 * \param magnitude The magnitude or distance of the feature being handled
60 * \param holdTimeMs The time which the feature has been past the hold threshold
61 *
62 * \return The action to dispatch, or action with ID ACTION_NONE if no action should be dispatched
63 */
64 CAction ProcessActions(std::vector<const KeymapAction*> actions,
65 int windowId,
66 float magnitude,
67 unsigned int holdTimeMs);
68
69 /*!
70 * \brief Process actions after release event to see if an action should be dispatched
71 *
72 * \param actions All actions from the keymap defined for the current window
73 * \param windowId The current window ID
74 *
75 * \return The action to dispatch, or action with ID ACTION_NONE if no action should be dispatched
76 */
77 CAction ProcessRelease(std::vector<const KeymapAction*> actions, int windowId);
78
79 /*!
80 * \brief Process an action to see if it should be dispatched
81 *
82 * \param action The action chosen to be dispatched
83 * \param windowId The current window ID
84 * \param magnitude The magnitude or distance of the feature being handled
85 * \param holdTimeMs The time which the feature has been past the hold threshold
86 *
87 * \return The action to dispatch, or action with ID ACTION_NONE if no action should be dispatched
88 */
89 CAction ProcessAction(const KeymapAction& action,
90 int windowId,
91 float magnitude,
92 unsigned int holdTimeMs);
93
94 // Check criteria for sending a repeat action
95 bool SendRepeatAction(unsigned int holdTimeMs);
96
97 // Helper function
98 static bool IsPressed(float magnitude);
99
100 // Construction parameters
101 const std::string m_keyName;
102 ACTION::IActionListener* const m_actionHandler;
103 const IKeymap* const m_keymap;
104 IKeymapHandler* const m_keymapHandler;
105
106 // State variables
107 bool m_bHeld;
108 float m_magnitude;
109 unsigned int m_holdStartTimeMs;
110 unsigned int m_lastHoldTimeMs;
111 bool m_bActionSent;
112 unsigned int m_lastActionMs;
113 int m_activeWindowId = -1; // Window that activated the key
114 CAction m_lastAction;
115 };
116 } // namespace KEYMAP
117 } // namespace KODI