| 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 |
{ |
| 38 |
/*! |
| 39 |
* \ingroup games |
| 40 |
*/ |
| 41 |
class CGUIConfigurationWizard : public IConfigurationWizard, |
| 42 |
public JOYSTICK::IButtonMapper, |
| 43 |
public KEYBOARD::IKeyboardDriverHandler, |
| 44 |
public Observer, |
| 45 |
protected CThread |
| 46 |
{ |
| 47 |
public: |
| 48 |
CGUIConfigurationWizard(); |
| 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 |