xbmc
KeyHandler.h
1 /*
2  * Copyright (C) 2017-2018 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"
13 #include "input/joysticks/interfaces/IKeyHandler.h"
14 
15 #include <map>
16 #include <string>
17 #include <vector>
18 
19 class CAction;
20 class IActionListener;
21 class IKeymap;
22 
23 namespace KODI
24 {
25 namespace JOYSTICK
26 {
27 class IKeymapHandler;
28 
33 class CKeyHandler : public IKeyHandler
34 {
35 public:
36  CKeyHandler(const std::string& keyName,
37  IActionListener* actionHandler,
38  const IKeymap* keymap,
39  IKeymapHandler* keymapHandler);
40 
41  ~CKeyHandler() override = default;
42 
43  // implementation of IKeyHandler
44  bool IsPressed() const override { return m_bHeld; }
45  bool OnDigitalMotion(bool bPressed, unsigned int holdTimeMs) override;
46  bool OnAnalogMotion(float magnitude, unsigned int motionTimeMs) override;
47 
48 private:
49  void Reset();
50 
61  CAction ProcessActions(std::vector<const KeymapAction*> actions,
62  int windowId,
63  float magnitude,
64  unsigned int holdTimeMs);
65 
74  CAction ProcessRelease(std::vector<const KeymapAction*> actions, int windowId);
75 
86  CAction ProcessAction(const KeymapAction& action,
87  int windowId,
88  float magnitude,
89  unsigned int holdTimeMs);
90 
91  // Check criteria for sending a repeat action
92  bool SendRepeatAction(unsigned int holdTimeMs);
93 
94  // Helper function
95  static bool IsPressed(float magnitude);
96 
97  // Construction parameters
98  const std::string m_keyName;
99  IActionListener* const m_actionHandler;
100  const IKeymap* const m_keymap;
101  IKeymapHandler* const m_keymapHandler;
102 
103  // State variables
104  bool m_bHeld;
105  float m_magnitude;
106  unsigned int m_holdStartTimeMs;
107  unsigned int m_lastHoldTimeMs;
108  bool m_bActionSent;
109  unsigned int m_lastActionMs;
110  int m_activeWindowId = -1; // Window that activated the key
111  CAction m_lastAction;
112 };
113 } // namespace JOYSTICK
114 } // namespace KODI
Interface for handling keymap keys.
Definition: IKeyHandler.h:22
bool OnDigitalMotion(bool bPressed, unsigned int holdTimeMs) override
A key mapped to a digital feature has been pressed or released.
Definition: KeyHandler.cpp:57
Definition: KeyHandler.h:33
Interface for mapping buttons to Kodi actions.
Definition: IKeymap.h:22
Action entry in joystick.xml.
Definition: JoystickTypes.h:166
Interface for a class working with a keymap.
Definition: IKeymapHandler.h:22
bool IsPressed() const override
Return true if the key is "pressed" (has a magnitude greater than 0.5)
Definition: KeyHandler.h:44
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Controller configuration window.
Definition: AudioDecoder.h:18
Definition: IActionListener.h:13
bool OnAnalogMotion(float magnitude, unsigned int motionTimeMs) override
Callback for keys mapped to analog features.
Definition: KeyHandler.cpp:62
Definition: actions.py:1