summaryrefslogtreecommitdiff
path: root/src/input_common/main.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/main.h')
-rw-r--r--src/input_common/main.h147
1 files changed, 120 insertions, 27 deletions
diff --git a/src/input_common/main.h b/src/input_common/main.h
index 77a0ce90b..dded3f1ef 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -6,40 +6,29 @@
6 6
7#include <memory> 7#include <memory>
8#include <string> 8#include <string>
9#include <unordered_map>
9#include <vector> 10#include <vector>
10 11
11namespace Common { 12namespace Common {
12class ParamPackage; 13class ParamPackage;
13} 14}
14 15
15namespace InputCommon { 16namespace Settings::NativeAnalog {
16 17enum Values : int;
17/// Initializes and registers all built-in input device factories. 18}
18void Init();
19
20/// Deregisters all built-in input device factories and shuts them down.
21void Shutdown();
22
23class Keyboard;
24
25/// Gets the keyboard button device factory.
26Keyboard* GetKeyboard();
27
28class MotionEmu;
29
30/// Gets the motion emulation factory.
31MotionEmu* GetMotionEmu();
32 19
33/// Generates a serialized param package for creating a keyboard button device 20namespace Settings::NativeButton {
34std::string GenerateKeyboardParam(int key_code); 21enum Values : int;
22}
35 23
36/// Generates a serialized param package for creating an analog device taking input from keyboard 24namespace Settings::NativeMotion {
37std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, 25enum Values : int;
38 int key_modifier, float modifier_scale); 26}
39 27
28namespace InputCommon {
40namespace Polling { 29namespace Polling {
41 30
42enum class DeviceType { Button, Analog }; 31enum class DeviceType { Button, AnalogPreferred, Motion };
43 32
44/** 33/**
45 * A class that can be used to get inputs from an input device like controllers without having to 34 * A class that can be used to get inputs from an input device like controllers without having to
@@ -49,7 +38,9 @@ class DevicePoller {
49public: 38public:
50 virtual ~DevicePoller() = default; 39 virtual ~DevicePoller() = default;
51 /// Setup and start polling for inputs, should be called before GetNextInput 40 /// Setup and start polling for inputs, should be called before GetNextInput
52 virtual void Start() = 0; 41 /// If a device_id is provided, events should be filtered to only include events from this
42 /// device id
43 virtual void Start(const std::string& device_id = "") = 0;
53 /// Stop polling 44 /// Stop polling
54 virtual void Stop() = 0; 45 virtual void Stop() = 0;
55 /** 46 /**
@@ -59,8 +50,110 @@ public:
59 */ 50 */
60 virtual Common::ParamPackage GetNextInput() = 0; 51 virtual Common::ParamPackage GetNextInput() = 0;
61}; 52};
62
63// Get all DevicePoller from all backends for a specific device type
64std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type);
65} // namespace Polling 53} // namespace Polling
54
55class GCAnalogFactory;
56class GCButtonFactory;
57class UDPMotionFactory;
58class UDPTouchFactory;
59class Keyboard;
60class MotionEmu;
61
62/**
63 * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default
64 * mapping for the device. This is currently only implemented for the SDL backend devices.
65 */
66using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>;
67using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>;
68using MotionMapping = std::unordered_map<Settings::NativeMotion::Values, Common::ParamPackage>;
69
70class InputSubsystem {
71public:
72 explicit InputSubsystem();
73 ~InputSubsystem();
74
75 InputSubsystem(const InputSubsystem&) = delete;
76 InputSubsystem& operator=(const InputSubsystem&) = delete;
77
78 InputSubsystem(InputSubsystem&&) = delete;
79 InputSubsystem& operator=(InputSubsystem&&) = delete;
80
81 /// Initializes and registers all built-in input device factories.
82 void Initialize();
83
84 /// Unregisters all built-in input device factories and shuts them down.
85 void Shutdown();
86
87 /// Retrieves the underlying keyboard device.
88 [[nodiscard]] Keyboard* GetKeyboard();
89
90 /// Retrieves the underlying keyboard device.
91 [[nodiscard]] const Keyboard* GetKeyboard() const;
92
93 /// Retrieves the underlying motion emulation factory.
94 [[nodiscard]] MotionEmu* GetMotionEmu();
95
96 /// Retrieves the underlying motion emulation factory.
97 [[nodiscard]] const MotionEmu* GetMotionEmu() const;
98
99 /**
100 * Returns all available input devices that this Factory can create a new device with.
101 * Each returned ParamPackage should have a `display` field used for display, a class field for
102 * backends to determine if this backend is meant to service the request and any other
103 * information needed to identify this in the backend later.
104 */
105 [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const;
106
107 /// Retrieves the analog mappings for the given device.
108 [[nodiscard]] AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& device) const;
109
110 /// Retrieves the button mappings for the given device.
111 [[nodiscard]] ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& device) const;
112
113 /// Retrieves the motion mappings for the given device.
114 [[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const;
115
116 /// Retrieves the underlying GameCube analog handler.
117 [[nodiscard]] GCAnalogFactory* GetGCAnalogs();
118
119 /// Retrieves the underlying GameCube analog handler.
120 [[nodiscard]] const GCAnalogFactory* GetGCAnalogs() const;
121
122 /// Retrieves the underlying GameCube button handler.
123 [[nodiscard]] GCButtonFactory* GetGCButtons();
124
125 /// Retrieves the underlying GameCube button handler.
126 [[nodiscard]] const GCButtonFactory* GetGCButtons() const;
127
128 /// Retrieves the underlying udp motion handler.
129 [[nodiscard]] UDPMotionFactory* GetUDPMotions();
130
131 /// Retrieves the underlying udp motion handler.
132 [[nodiscard]] const UDPMotionFactory* GetUDPMotions() const;
133
134 /// Retrieves the underlying udp touch handler.
135 [[nodiscard]] UDPTouchFactory* GetUDPTouch();
136
137 /// Retrieves the underlying udp touch handler.
138 [[nodiscard]] const UDPTouchFactory* GetUDPTouch() const;
139
140 /// Reloads the input devices
141 void ReloadInputDevices();
142
143 /// Get all DevicePoller from all backends for a specific device type
144 [[nodiscard]] std::vector<std::unique_ptr<Polling::DevicePoller>> GetPollers(
145 Polling::DeviceType type) const;
146
147private:
148 struct Impl;
149 std::unique_ptr<Impl> impl;
150};
151
152/// Generates a serialized param package for creating a keyboard button device
153std::string GenerateKeyboardParam(int key_code);
154
155/// Generates a serialized param package for creating an analog device taking input from keyboard
156std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right,
157 int key_modifier, float modifier_scale);
158
66} // namespace InputCommon 159} // namespace InputCommon