kodi
GUIConfigurationWizard.h
1 /*
2  * Copyright (C) 2014-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 "IConfigurationWindow.h"
12 #include "games/controllers/input/PhysicalFeature.h"
13 #include "input/joysticks/DriverPrimitive.h"
14 #include "input/joysticks/interfaces/IButtonMapper.h"
15 #include "input/keyboard/XBMC_keysym.h"
16 #include "input/keyboard/interfaces/IKeyboardDriverHandler.h"
17 #include "threads/CriticalSection.h"
18 #include "threads/Event.h"
19 #include "threads/Thread.h"
20 #include "utils/Observer.h"
21 
22 #include <map>
23 #include <memory>
24 #include <set>
25 #include <string>
26 #include <vector>
27 
28 namespace KODI
29 {
30 namespace KEYMAP
31 {
32 class IKeyboardActionMap;
33 class IKeymap;
34 } // namespace KEYMAP
35 
36 namespace GAME
37 {
44  public Observer,
45  protected CThread
46 {
47 public:
49 
50  ~CGUIConfigurationWizard() override;
51 
52  // implementation of IConfigurationWizard
53  void Run(const std::string& strControllerId,
54  const std::vector<IFeatureButton*>& buttons) override;
55  void OnUnfocus(IFeatureButton* button) override;
56  bool Abort(bool bWait = true) override;
57  void RegisterKey(const CPhysicalFeature& key) override;
58  void UnregisterKeys() override;
59 
60  // implementation of IButtonMapper
61  std::string ControllerID() const override { return m_strControllerId; }
62  bool NeedsCooldown() const override { return true; }
63  bool AcceptsPrimitive(JOYSTICK::PRIMITIVE_TYPE type) const override { return true; }
64  bool MapPrimitive(JOYSTICK::IButtonMap* buttonMap,
65  KEYMAP::IKeymap* keymap,
66  const JOYSTICK::CDriverPrimitive& primitive) override;
67  void OnEventFrame(const JOYSTICK::IButtonMap* buttonMap, bool bMotion) override;
68  void OnLateAxis(const JOYSTICK::IButtonMap* buttonMap, unsigned int axisIndex) override;
69 
70  // implementation of IKeyboardDriverHandler
71  bool OnKeyPress(const CKey& key) override;
72  void OnKeyRelease(const CKey& key) override {}
73 
74  // implementation of Observer
75  void Notify(const Observable& obs, const ObservableMessage msg) override;
76 
77 protected:
78  // implementation of CThread
79  void Process() override;
80 
81 private:
82  void InitializeState(void);
83 
84  bool IsMapping() const;
85  bool IsMapping(const std::string& location) const;
86 
87  void InstallHooks(void);
88  void RemoveHooks(void);
89 
90  void OnMotion(const JOYSTICK::IButtonMap* buttonMap);
91  void OnMotionless(const JOYSTICK::IButtonMap* buttonMap);
92 
93  bool OnAction(unsigned int actionId);
94 
95  // Run() parameters
96  std::string m_strControllerId;
97  std::vector<IFeatureButton*> m_buttons;
98 
99  // State variables and mutex
100  IFeatureButton* m_currentButton;
101  INPUT::CARDINAL_DIRECTION m_cardinalDirection;
102  JOYSTICK::WHEEL_DIRECTION m_wheelDirection;
103  JOYSTICK::THROTTLE_DIRECTION m_throttleDirection;
104  std::set<JOYSTICK::CDriverPrimitive> m_history; // History to avoid repeated features
105  bool m_lateAxisDetected; // Set to true if an axis is detected during button mapping
106  std::string m_location; // Peripheral location of device that we're mapping
107  bool m_bIsKeyboard = false; // True if we're mapping keyboard keys
108  CCriticalSection m_stateMutex;
109 
110  // Synchronization events
111  CEvent m_inputEvent;
112  CEvent m_motionlessEvent;
113  CCriticalSection m_motionMutex;
114  std::set<const JOYSTICK::IButtonMap*> m_bInMotion;
115 
116  // Keyboard handling
117  std::unique_ptr<KEYMAP::IKeyboardActionMap> m_actionMap;
118  std::map<std::string, CPhysicalFeature> m_keyMap; // Key symbol -> feature
119 };
120 } // namespace GAME
121 } // namespace KODI
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: Thread.h:44
A wizard to direct user input.
Definition: IConfigurationWindow.h:240
Button map interface to translate between the driver&#39;s raw button/hat/axis elements and physical joys...
Definition: IButtonMap.h:29
Definition: GUIConfigurationWizard.h:41
A GUI button in a feature list (IFeatureList)
Definition: IConfigurationWindow.h:159
bool NeedsCooldown() const override
Return true if the button mapper wants a cooldown between button mapping commands.
Definition: GUIConfigurationWizard.h:62
Definition: AudioDecoder.h:18
Definition: Observer.h:31
Basic driver element associated with input events.
Definition: DriverPrimitive.h:70
std::string ControllerID() const override
The add-on ID of the game controller associated with this button mapper.
Definition: GUIConfigurationWizard.h:61
Button mapper interface to assign the driver&#39;s raw button/hat/axis elements to physical joystick feat...
Definition: IButtonMapper.h:37
Interface for handling keyboard events.
Definition: IKeyboardDriverHandler.h:22
Definition: PhysicalFeature.h:30
Definition: Observer.h:44
bool AcceptsPrimitive(JOYSTICK::PRIMITIVE_TYPE type) const override
Return true if the button mapper accepts primitives of the given type.
Definition: GUIConfigurationWizard.h:63
Definition: Key.h:17
Interface for mapping buttons to Kodi actions.
Definition: IKeymap.h:28
void OnKeyRelease(const CKey &key) override
A key has been released.
Definition: GUIConfigurationWizard.h:72