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