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 {
40  public Observer,
41  protected CThread
42 {
43 public:
45 
46  ~CGUIConfigurationWizard() override;
47 
48  // implementation of IConfigurationWizard
49  void Run(const std::string& strControllerId,
50  const std::vector<IFeatureButton*>& buttons) override;
51  void OnUnfocus(IFeatureButton* button) override;
52  bool Abort(bool bWait = true) override;
53  void RegisterKey(const CPhysicalFeature& key) override;
54  void UnregisterKeys() override;
55 
56  // implementation of IButtonMapper
57  std::string ControllerID() const override { return m_strControllerId; }
58  bool NeedsCooldown() const override { return true; }
59  bool AcceptsPrimitive(JOYSTICK::PRIMITIVE_TYPE type) const override { return true; }
60  bool MapPrimitive(JOYSTICK::IButtonMap* buttonMap,
61  IKeymap* keymap,
62  const JOYSTICK::CDriverPrimitive& primitive) override;
63  void OnEventFrame(const JOYSTICK::IButtonMap* buttonMap, bool bMotion) override;
64  void OnLateAxis(const JOYSTICK::IButtonMap* buttonMap, unsigned int axisIndex) override;
65 
66  // implementation of IKeyboardDriverHandler
67  bool OnKeyPress(const CKey& key) override;
68  void OnKeyRelease(const CKey& key) override {}
69 
70  // implementation of Observer
71  void Notify(const Observable& obs, const ObservableMessage msg) override;
72 
73 protected:
74  // implementation of CThread
75  void Process() override;
76 
77 private:
78  void InitializeState(void);
79 
80  bool IsMapping() const;
81  bool IsMapping(const std::string& location) const;
82 
83  void InstallHooks(void);
84  void RemoveHooks(void);
85 
86  void OnMotion(const JOYSTICK::IButtonMap* buttonMap);
87  void OnMotionless(const JOYSTICK::IButtonMap* buttonMap);
88 
89  bool OnAction(unsigned int actionId);
90 
91  // Run() parameters
92  std::string m_strControllerId;
93  std::vector<IFeatureButton*> m_buttons;
94 
95  // State variables and mutex
96  IFeatureButton* m_currentButton;
97  INPUT::CARDINAL_DIRECTION m_cardinalDirection;
98  JOYSTICK::WHEEL_DIRECTION m_wheelDirection;
99  JOYSTICK::THROTTLE_DIRECTION m_throttleDirection;
100  std::set<JOYSTICK::CDriverPrimitive> m_history; // History to avoid repeated features
101  bool m_lateAxisDetected; // Set to true if an axis is detected during button mapping
102  std::string m_location; // Peripheral location of device that we're mapping
103  bool m_bIsKeyboard = false; // True if we're mapping keyboard keys
104  CCriticalSection m_stateMutex;
105 
106  // Synchronization events
107  CEvent m_inputEvent;
108  CEvent m_motionlessEvent;
109  CCriticalSection m_motionMutex;
110  std::set<const JOYSTICK::IButtonMap*> m_bInMotion;
111 
112  // Keyboard handling
113  std::unique_ptr<KEYBOARD::IActionMap> m_actionMap;
114  std::map<XBMCKey, CPhysicalFeature> m_keyMap; // Keycode -> feature
115 };
116 } // namespace GAME
117 } // 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:221
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:37
A GUI button in a feature list.
Definition: IConfigurationWindow.h:146
bool NeedsCooldown() const override
Return true if the button mapper wants a cooldown between button mapping commands.
Definition: GUIConfigurationWizard.h:58
PRIMITIVE_TYPE
Type of driver primitive.
Definition: JoystickTypes.h:150
WHEEL_DIRECTION
Directions on a wheel.
Definition: JoystickTypes.h:120
Controller configuration window.
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:57
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:24
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:59
Definition: Key.h:135
void OnKeyRelease(const CKey &key) override
A key has been released.
Definition: GUIConfigurationWizard.h:68