summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/drivers/mouse.cpp35
-rw-r--r--src/input_common/drivers/mouse.h2
-rw-r--r--src/input_common/drivers/sdl_driver.cpp12
-rw-r--r--src/input_common/drivers/sdl_driver.h2
-rw-r--r--src/input_common/drivers/tas_input.cpp7
-rw-r--r--src/input_common/input_engine.cpp2
-rw-r--r--src/input_common/input_mapping.cpp13
7 files changed, 64 insertions, 9 deletions
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index aa69216c8..d8ae7f0c1 100644
--- a/src/input_common/drivers/mouse.cpp
+++ b/src/input_common/drivers/mouse.cpp
@@ -16,6 +16,7 @@ constexpr int mouse_axis_x = 0;
16constexpr int mouse_axis_y = 1; 16constexpr int mouse_axis_y = 1;
17constexpr int wheel_axis_x = 2; 17constexpr int wheel_axis_x = 2;
18constexpr int wheel_axis_y = 3; 18constexpr int wheel_axis_y = 3;
19constexpr int motion_wheel_y = 4;
19constexpr int touch_axis_x = 10; 20constexpr int touch_axis_x = 10;
20constexpr int touch_axis_y = 11; 21constexpr int touch_axis_y = 11;
21constexpr PadIdentifier identifier = { 22constexpr PadIdentifier identifier = {
@@ -30,8 +31,9 @@ Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_))
30 PreSetAxis(identifier, mouse_axis_y); 31 PreSetAxis(identifier, mouse_axis_y);
31 PreSetAxis(identifier, wheel_axis_x); 32 PreSetAxis(identifier, wheel_axis_x);
32 PreSetAxis(identifier, wheel_axis_y); 33 PreSetAxis(identifier, wheel_axis_y);
34 PreSetAxis(identifier, motion_wheel_y);
33 PreSetAxis(identifier, touch_axis_x); 35 PreSetAxis(identifier, touch_axis_x);
34 PreSetAxis(identifier, touch_axis_x); 36 PreSetAxis(identifier, touch_axis_y);
35 update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); }); 37 update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); });
36} 38}
37 39
@@ -48,6 +50,8 @@ void Mouse::UpdateThread(std::stop_token stop_token) {
48 SetAxis(identifier, mouse_axis_y, -last_mouse_change.y * sensitivity); 50 SetAxis(identifier, mouse_axis_y, -last_mouse_change.y * sensitivity);
49 } 51 }
50 52
53 SetAxis(identifier, motion_wheel_y, 0.0f);
54
51 if (mouse_panning_timout++ > 20) { 55 if (mouse_panning_timout++ > 20) {
52 StopPanning(); 56 StopPanning();
53 } 57 }
@@ -136,6 +140,7 @@ void Mouse::MouseWheelChange(int x, int y) {
136 wheel_position.y += y; 140 wheel_position.y += y;
137 SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position.x)); 141 SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position.x));
138 SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position.y)); 142 SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position.y));
143 SetAxis(identifier, motion_wheel_y, static_cast<f32>(y) / 100.0f);
139} 144}
140 145
141void Mouse::ReleaseAllButtons() { 146void Mouse::ReleaseAllButtons() {
@@ -171,13 +176,39 @@ AnalogMapping Mouse::GetAnalogMappingForDevice(
171 return mapping; 176 return mapping;
172} 177}
173 178
179Common::Input::ButtonNames Mouse::GetUIButtonName(const Common::ParamPackage& params) const {
180 const auto button = static_cast<MouseButton>(params.Get("button", 0));
181 switch (button) {
182 case MouseButton::Left:
183 return Common::Input::ButtonNames::ButtonLeft;
184 case MouseButton::Right:
185 return Common::Input::ButtonNames::ButtonRight;
186 case MouseButton::Wheel:
187 return Common::Input::ButtonNames::ButtonMouseWheel;
188 case MouseButton::Backward:
189 return Common::Input::ButtonNames::ButtonBackward;
190 case MouseButton::Forward:
191 return Common::Input::ButtonNames::ButtonForward;
192 case MouseButton::Task:
193 return Common::Input::ButtonNames::ButtonTask;
194 case MouseButton::Extra:
195 return Common::Input::ButtonNames::ButtonExtra;
196 case MouseButton::Undefined:
197 default:
198 return Common::Input::ButtonNames::Undefined;
199 }
200}
201
174Common::Input::ButtonNames Mouse::GetUIName(const Common::ParamPackage& params) const { 202Common::Input::ButtonNames Mouse::GetUIName(const Common::ParamPackage& params) const {
175 if (params.Has("button")) { 203 if (params.Has("button")) {
176 return Common::Input::ButtonNames::Value; 204 return GetUIButtonName(params);
177 } 205 }
178 if (params.Has("axis")) { 206 if (params.Has("axis")) {
179 return Common::Input::ButtonNames::Value; 207 return Common::Input::ButtonNames::Value;
180 } 208 }
209 if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) {
210 return Common::Input::ButtonNames::Engine;
211 }
181 212
182 return Common::Input::ButtonNames::Invalid; 213 return Common::Input::ButtonNames::Invalid;
183} 214}
diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h
index 040446178..c5833b8ed 100644
--- a/src/input_common/drivers/mouse.h
+++ b/src/input_common/drivers/mouse.h
@@ -69,6 +69,8 @@ private:
69 void UpdateThread(std::stop_token stop_token); 69 void UpdateThread(std::stop_token stop_token);
70 void StopPanning(); 70 void StopPanning();
71 71
72 Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
73
72 Common::Vec2<int> mouse_origin; 74 Common::Vec2<int> mouse_origin;
73 Common::Vec2<int> last_mouse_position; 75 Common::Vec2<int> last_mouse_position;
74 Common::Vec2<float> last_mouse_change; 76 Common::Vec2<float> last_mouse_change;
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index 0cda9df62..ed6281772 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -198,9 +198,15 @@ public:
198 if (sdl_controller) { 198 if (sdl_controller) {
199 switch (SDL_GameControllerGetType(sdl_controller.get())) { 199 switch (SDL_GameControllerGetType(sdl_controller.get())) {
200 case SDL_CONTROLLER_TYPE_XBOX360: 200 case SDL_CONTROLLER_TYPE_XBOX360:
201 return "XBox 360 Controller"; 201 return "Xbox 360 Controller";
202 case SDL_CONTROLLER_TYPE_XBOXONE: 202 case SDL_CONTROLLER_TYPE_XBOXONE:
203 return "XBox One Controller"; 203 return "Xbox One Controller";
204 case SDL_CONTROLLER_TYPE_PS3:
205 return "DualShock 3 Controller";
206 case SDL_CONTROLLER_TYPE_PS4:
207 return "DualShock 4 Controller";
208 case SDL_CONTROLLER_TYPE_PS5:
209 return "DualSense Controller";
204 default: 210 default:
205 break; 211 break;
206 } 212 }
@@ -663,6 +669,7 @@ ButtonBindings SDLDriver::GetDefaultButtonBinding() const {
663 {Settings::NativeButton::SL, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, 669 {Settings::NativeButton::SL, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
664 {Settings::NativeButton::SR, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, 670 {Settings::NativeButton::SR, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
665 {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE}, 671 {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE},
672 {Settings::NativeButton::Screenshot, SDL_CONTROLLER_BUTTON_MISC1},
666 }; 673 };
667} 674}
668 675
@@ -699,6 +706,7 @@ ButtonBindings SDLDriver::GetNintendoButtonBinding(
699 {Settings::NativeButton::SL, sl_button}, 706 {Settings::NativeButton::SL, sl_button},
700 {Settings::NativeButton::SR, sr_button}, 707 {Settings::NativeButton::SR, sr_button},
701 {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE}, 708 {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE},
709 {Settings::NativeButton::Screenshot, SDL_CONTROLLER_BUTTON_MISC1},
702 }; 710 };
703} 711}
704 712
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index e9a5d2e26..4cde3606f 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -24,7 +24,7 @@ namespace InputCommon {
24class SDLJoystick; 24class SDLJoystick;
25 25
26using ButtonBindings = 26using ButtonBindings =
27 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; 27 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 18>;
28using ZButtonBindings = 28using ZButtonBindings =
29 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>; 29 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>;
30 30
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index d78228b50..944e141bf 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -23,7 +23,7 @@ enum class Tas::TasAxis : u8 {
23}; 23};
24 24
25// Supported keywords and buttons from a TAS file 25// Supported keywords and buttons from a TAS file
26constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_button = { 26constexpr std::array<std::pair<std::string_view, TasButton>, 18> text_to_tas_button = {
27 std::pair{"KEY_A", TasButton::BUTTON_A}, 27 std::pair{"KEY_A", TasButton::BUTTON_A},
28 {"KEY_B", TasButton::BUTTON_B}, 28 {"KEY_B", TasButton::BUTTON_B},
29 {"KEY_X", TasButton::BUTTON_X}, 29 {"KEY_X", TasButton::BUTTON_X},
@@ -40,8 +40,9 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but
40 {"KEY_DDOWN", TasButton::BUTTON_DOWN}, 40 {"KEY_DDOWN", TasButton::BUTTON_DOWN},
41 {"KEY_SL", TasButton::BUTTON_SL}, 41 {"KEY_SL", TasButton::BUTTON_SL},
42 {"KEY_SR", TasButton::BUTTON_SR}, 42 {"KEY_SR", TasButton::BUTTON_SR},
43 {"KEY_CAPTURE", TasButton::BUTTON_CAPTURE}, 43 // These buttons are disabled to avoid TAS input from activating hotkeys
44 {"KEY_HOME", TasButton::BUTTON_HOME}, 44 // {"KEY_CAPTURE", TasButton::BUTTON_CAPTURE},
45 // {"KEY_HOME", TasButton::BUTTON_HOME},
45 {"KEY_ZL", TasButton::TRIGGER_ZL}, 46 {"KEY_ZL", TasButton::TRIGGER_ZL},
46 {"KEY_ZR", TasButton::TRIGGER_ZR}, 47 {"KEY_ZR", TasButton::TRIGGER_ZR},
47}; 48};
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp
index b57330e51..0508b408d 100644
--- a/src/input_common/input_engine.cpp
+++ b/src/input_common/input_engine.cpp
@@ -173,7 +173,7 @@ void InputEngine::ResetButtonState() {
173 SetButton(controller.first, button.first, false); 173 SetButton(controller.first, button.first, false);
174 } 174 }
175 for (const auto& button : controller.second.hat_buttons) { 175 for (const auto& button : controller.second.hat_buttons) {
176 SetHatButton(controller.first, button.first, false); 176 SetHatButton(controller.first, button.first, 0);
177 } 177 }
178 } 178 }
179} 179}
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp
index 6e0024b2d..475257f42 100644
--- a/src/input_common/input_mapping.cpp
+++ b/src/input_common/input_mapping.cpp
@@ -143,6 +143,19 @@ void MappingFactory::RegisterMotion(const MappingData& data) {
143 } 143 }
144 new_input.Set("port", static_cast<int>(data.pad.port)); 144 new_input.Set("port", static_cast<int>(data.pad.port));
145 new_input.Set("pad", static_cast<int>(data.pad.pad)); 145 new_input.Set("pad", static_cast<int>(data.pad.pad));
146
147 // If engine is mouse map the mouse position as 3 axis motion
148 if (data.engine == "mouse") {
149 new_input.Set("axis_x", 1);
150 new_input.Set("invert_x", "-");
151 new_input.Set("axis_y", 0);
152 new_input.Set("axis_z", 4);
153 new_input.Set("range", 1.0f);
154 new_input.Set("deadzone", 0.0f);
155 input_queue.Push(new_input);
156 return;
157 }
158
146 switch (data.type) { 159 switch (data.type) {
147 case EngineInputType::Button: 160 case EngineInputType::Button:
148 case EngineInputType::HatButton: 161 case EngineInputType::HatButton: