ReXGlue SDK
Loading...
Searching...
No Matches
input_system.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <memory>
14#include <span>
15#include <string>
16#include <string_view>
17
18#include <rex/hid/binding.h>
19#include <rex/input_keys.h>
20#include <rex/hid/pad.h>
21#include <rex/module.h>
22#include <rex/platform.h>
23#include <rex/result.h>
24#include <rex/setting.h>
26#include <rex/types.h>
27#include <rex/utility.h>
28
29namespace rex::hid {
30
31class REX_HID_API InputSettings final : public SettingOwner {
32 public:
33 InputSettings();
34
35 REX_SETTING(std::string, drivers, "sdl3", "Input drivers in priority order, comma separated",
36 kStartupOnly);
37 REX_SETTING(bool, shared_pads, false, "Every pad feeds user 0", kStartupOnly);
38 REX_SETTING(bool, vibration, true, "Allow vibration");
39 REX_SETTING(bool, guide_button, false, "Pass the guide button to the title");
40 REX_SETTING(f64, left_stick_deadzone, 0.0, "Left stick deadzone", Range{0.0, 1.0});
41 REX_SETTING(f64, right_stick_deadzone, 0.0, "Right stick deadzone", Range{0.0, 1.0});
42 REX_SETTING(bool, mnk_mode, false, "Keyboard and mouse act as a pad");
43 REX_SETTING(bool, mnk_mouse, false, "The mouse moves the right stick");
44 REX_SETTING(f64, mnk_sensitivity, 1.0, "Mouse to stick sensitivity", Range{0.01, 100.0});
45 REX_SETTING(bool, mnk_passthrough, false, "Keys reach the title as keystrokes");
46};
47
55 static constexpr u32 kMaxUsers = 4;
56
58 static constexpr u32 kAnyUser = 0xFF;
59
60 struct PadReading {
61 u32 packet = 0;
62 PadState state;
63 };
64
65 virtual InputSettings& GetSettings() = 0;
66
73 [[nodiscard]] virtual Result<PadReading> GetState(u32 user) = 0;
74
81 [[nodiscard]] virtual Result<PadCapabilities> GetCapabilities(u32 user) = 0;
82
89 [[nodiscard]] virtual Result<void> SetVibration(u32 user, const PadVibration& motors) = 0;
90
99 [[nodiscard]] virtual Result<PadKeystroke> GetKeystroke(u32 user, KeystrokeSource sources) = 0;
100
106 [[nodiscard]] virtual Result<PadInfo> GetPadInfo(u32 user) = 0;
107
115 [[nodiscard]] virtual ScopeGuard OnConnectionChange(
116 MoveOnlyFunction<void(u32 user, bool connected)> fn) = 0;
117
121 virtual void AcquireUIBlock() = 0;
122
123 virtual void ReleaseUIBlock() = 0;
124
125 virtual bool IsKeyDown(VirtualKey key) const = 0;
126
127 virtual bool IsAnyKeyDown() const = 0;
128
129 virtual KeyModifiers GetModifiers() const = 0;
130
134 virtual PointerState GetPointer() const = 0;
135
136 virtual bool IsButtonDown(MouseButton button) const = 0;
137
138 virtual bool IsAnyButtonDown() const = 0;
139
141 virtual bool TakePointerMoved() = 0;
142
146 virtual PointerDelta TakeMotion() = 0;
147
151 virtual PointerDelta PeekMotion() const = 0;
152
156 virtual i32 TakeWheel() = 0;
157
158 virtual i32 GetWheel() const = 0;
159
163 virtual void SetPointerMode(PointerMode mode) = 0;
164
170 virtual void OnInputEvent(InputEvent& event) = 0;
171
172 virtual void SetInputCaptured(bool captured) = 0;
173
177 virtual PointerMode GetPointerModeToApply() const = 0;
178
185 [[nodiscard]] virtual ScopeGuard SetPointerModeListener(MoveOnlyFunction<void()> listener) = 0;
186
191 virtual hid::IBindingSet& GetKeyBindings() = 0;
192
200 [[nodiscard]] virtual std::unique_ptr<hid::IBindingSet> CreateBindingSet(
201 std::span<const hid::BindingConfig> configs, std::string_view scope) = 0;
202
209 [[nodiscard]] virtual std::unique_ptr<hid::IKeyCapture> CreateKeyCapture(
210 hid::KeyCaptureConfig config) = 0;
211
217 [[nodiscard]] virtual Result<KeyChord> ParseKeyChord(std::string_view text) const = 0;
218
224 [[nodiscard]] virtual std::string FormatKeyChord(KeyChord chord) const = 0;
225
232 [[nodiscard]] virtual VirtualKey ParseVirtualKey(std::string_view name) const = 0;
233
237 [[nodiscard]] virtual std::string VirtualKeyToString(VirtualKey key) const = 0;
238
246 [[nodiscard]] virtual Result<InputSource> ParseInputSource(std::string_view text) const = 0;
247
253 [[nodiscard]] virtual std::string InputSourceToString(const InputSource& source) const = 0;
254};
255
256} // namespace rex::hid
Input bindings and key capture.
Definition utility.h:305
SettingOwner(std::string_view scope)
Definition binding.h:75
Definition input_system.h:54
Definition input_system.h:31
Interfaces, factory and module declaration.
#define REX_DECLARE_INTERFACE(Name, version)
Definition module.h:114
Result< InputSource > ParseInputSource(std::string_view text)
VirtualKey
Definition input_keys.h:35
std::string VirtualKeyToString(VirtualKey key)
MouseButton
Definition input_keys.h:377
Result< KeyChord > ParseKeyChord(std::string_view text)
std::string InputSourceToString(const InputSource &source)
PointerMode
Definition input_keys.h:371
typename detail::MoveOnlyFunctionFor< Signature >::type MoveOnlyFunction
Definition utility.h:254
std::expected< T, Error > Result
Definition result.h:98
VirtualKey ParseVirtualKey(std::string_view name)
KeystrokeSource
Definition pad.h:83
Platform flags, packing macros and export markers.
#define REX_HID_API
Definition platform.h:228
Typed settings and the owners that declare them.
The registry of every registered setting.
Definition input_keys.h:417
Definition input_keys.h:509
Definition input_keys.h:554
Definition input_keys.h:406
Definition input_keys.h:393
Definition setting.h:78
Definition binding.h:180
Definition pad.h:50
Definition pad.h:61
Integer types, byte order wrappers and size literals.
Move only function, const propagating pointer and scope guard.