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.h152
1 files changed, 120 insertions, 32 deletions
diff --git a/src/input_common/main.h b/src/input_common/main.h
index 0e32856f6..dded3f1ef 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -6,45 +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#include "input_common/gcadapter/gc_poller.h"
11 11
12namespace Common { 12namespace Common {
13class ParamPackage; 13class ParamPackage;
14} 14}
15 15
16namespace InputCommon { 16namespace Settings::NativeAnalog {
17 17enum Values : int;
18/// Initializes and registers all built-in input device factories. 18}
19void Init();
20
21/// Deregisters all built-in input device factories and shuts them down.
22void Shutdown();
23
24class Keyboard;
25
26/// Gets the keyboard button device factory.
27Keyboard* GetKeyboard();
28
29class MotionEmu;
30
31/// Gets the motion emulation factory.
32MotionEmu* GetMotionEmu();
33
34GCButtonFactory* GetGCButtons();
35
36GCAnalogFactory* GetGCAnalogs();
37 19
38/// Generates a serialized param package for creating a keyboard button device 20namespace Settings::NativeButton {
39std::string GenerateKeyboardParam(int key_code); 21enum Values : int;
22}
40 23
41/// Generates a serialized param package for creating an analog device taking input from keyboard 24namespace Settings::NativeMotion {
42std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, 25enum Values : int;
43 int key_modifier, float modifier_scale); 26}
44 27
28namespace InputCommon {
45namespace Polling { 29namespace Polling {
46 30
47enum class DeviceType { Button, Analog }; 31enum class DeviceType { Button, AnalogPreferred, Motion };
48 32
49/** 33/**
50 * 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
@@ -54,7 +38,9 @@ class DevicePoller {
54public: 38public:
55 virtual ~DevicePoller() = default; 39 virtual ~DevicePoller() = default;
56 /// Setup and start polling for inputs, should be called before GetNextInput 40 /// Setup and start polling for inputs, should be called before GetNextInput
57 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;
58 /// Stop polling 44 /// Stop polling
59 virtual void Stop() = 0; 45 virtual void Stop() = 0;
60 /** 46 /**
@@ -64,8 +50,110 @@ public:
64 */ 50 */
65 virtual Common::ParamPackage GetNextInput() = 0; 51 virtual Common::ParamPackage GetNextInput() = 0;
66}; 52};
67
68// Get all DevicePoller from all backends for a specific device type
69std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type);
70} // 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
71} // namespace InputCommon 159} // namespace InputCommon