diff options
| author | 2023-02-22 22:08:35 -0500 | |
|---|---|---|
| committer | 2023-02-22 22:08:35 -0500 | |
| commit | ca8a804a3c28f53bba9d1f9080ae15c13f60ce9c (patch) | |
| tree | ac8c6c62c2f43c41e887b269520c6d2482cf95a2 /src/core/hid/emulated_devices.cpp | |
| parent | Merge pull request #9847 from german77/timeout (diff) | |
| parent | settings: Add more input settings to the log (diff) | |
| download | yuzu-ca8a804a3c28f53bba9d1f9080ae15c13f60ce9c.tar.gz yuzu-ca8a804a3c28f53bba9d1f9080ae15c13f60ce9c.tar.xz yuzu-ca8a804a3c28f53bba9d1f9080ae15c13f60ce9c.zip | |
Merge pull request #9842 from german77/proper_real_mouse
core: hid: Fix native mouse mapping
Diffstat (limited to 'src/core/hid/emulated_devices.cpp')
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index 578a6ff61..8e165dded 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp | |||
| @@ -19,52 +19,53 @@ void EmulatedDevices::ReloadFromSettings() { | |||
| 19 | 19 | ||
| 20 | void EmulatedDevices::ReloadInput() { | 20 | void EmulatedDevices::ReloadInput() { |
| 21 | // If you load any device here add the equivalent to the UnloadInput() function | 21 | // If you load any device here add the equivalent to the UnloadInput() function |
| 22 | |||
| 23 | // Native Mouse is mapped on port 1, pad 0 | ||
| 24 | const Common::ParamPackage mouse_params{"engine:mouse,port:1,pad:0"}; | ||
| 25 | |||
| 26 | // Keyboard keys is mapped on port 1, pad 0 for normal keys, pad 1 for moddifier keys | ||
| 27 | const Common::ParamPackage keyboard_params{"engine:keyboard,port:1"}; | ||
| 28 | |||
| 22 | std::size_t key_index = 0; | 29 | std::size_t key_index = 0; |
| 23 | for (auto& mouse_device : mouse_button_devices) { | 30 | for (auto& mouse_device : mouse_button_devices) { |
| 24 | Common::ParamPackage mouse_params; | 31 | Common::ParamPackage mouse_button_params = mouse_params; |
| 25 | mouse_params.Set("engine", "mouse"); | 32 | mouse_button_params.Set("button", static_cast<int>(key_index)); |
| 26 | mouse_params.Set("button", static_cast<int>(key_index)); | 33 | mouse_device = Common::Input::CreateInputDevice(mouse_button_params); |
| 27 | mouse_device = Common::Input::CreateInputDevice(mouse_params); | ||
| 28 | key_index++; | 34 | key_index++; |
| 29 | } | 35 | } |
| 30 | 36 | ||
| 31 | mouse_stick_device = | 37 | Common::ParamPackage mouse_position_params = mouse_params; |
| 32 | Common::Input::CreateInputDeviceFromString("engine:mouse,axis_x:0,axis_y:1"); | 38 | mouse_position_params.Set("axis_x", 0); |
| 39 | mouse_position_params.Set("axis_y", 1); | ||
| 40 | mouse_position_params.Set("deadzone", 0.0f); | ||
| 41 | mouse_position_params.Set("range", 1.0f); | ||
| 42 | mouse_position_params.Set("threshold", 0.0f); | ||
| 43 | mouse_stick_device = Common::Input::CreateInputDevice(mouse_position_params); | ||
| 33 | 44 | ||
| 34 | // First two axis are reserved for mouse position | 45 | // First two axis are reserved for mouse position |
| 35 | key_index = 2; | 46 | key_index = 2; |
| 36 | for (auto& mouse_device : mouse_analog_devices) { | 47 | for (auto& mouse_device : mouse_wheel_devices) { |
| 37 | // Mouse axis are only mapped on port 1, pad 0 | 48 | Common::ParamPackage mouse_wheel_params = mouse_params; |
| 38 | Common::ParamPackage mouse_params; | 49 | mouse_wheel_params.Set("axis", static_cast<int>(key_index)); |
| 39 | mouse_params.Set("engine", "mouse"); | 50 | mouse_device = Common::Input::CreateInputDevice(mouse_wheel_params); |
| 40 | mouse_params.Set("axis", static_cast<int>(key_index)); | ||
| 41 | mouse_params.Set("port", 1); | ||
| 42 | mouse_params.Set("pad", 0); | ||
| 43 | mouse_device = Common::Input::CreateInputDevice(mouse_params); | ||
| 44 | key_index++; | 51 | key_index++; |
| 45 | } | 52 | } |
| 46 | 53 | ||
| 47 | key_index = 0; | 54 | key_index = 0; |
| 48 | for (auto& keyboard_device : keyboard_devices) { | 55 | for (auto& keyboard_device : keyboard_devices) { |
| 49 | // Keyboard keys are only mapped on port 1, pad 0 | 56 | Common::ParamPackage keyboard_key_params = keyboard_params; |
| 50 | Common::ParamPackage keyboard_params; | 57 | keyboard_key_params.Set("button", static_cast<int>(key_index)); |
| 51 | keyboard_params.Set("engine", "keyboard"); | 58 | keyboard_key_params.Set("pad", 0); |
| 52 | keyboard_params.Set("button", static_cast<int>(key_index)); | 59 | keyboard_device = Common::Input::CreateInputDevice(keyboard_key_params); |
| 53 | keyboard_params.Set("port", 1); | ||
| 54 | keyboard_params.Set("pad", 0); | ||
| 55 | keyboard_device = Common::Input::CreateInputDevice(keyboard_params); | ||
| 56 | key_index++; | 60 | key_index++; |
| 57 | } | 61 | } |
| 58 | 62 | ||
| 59 | key_index = 0; | 63 | key_index = 0; |
| 60 | for (auto& keyboard_device : keyboard_modifier_devices) { | 64 | for (auto& keyboard_device : keyboard_modifier_devices) { |
| 61 | // Keyboard moddifiers are only mapped on port 1, pad 1 | 65 | Common::ParamPackage keyboard_moddifier_params = keyboard_params; |
| 62 | Common::ParamPackage keyboard_params; | 66 | keyboard_moddifier_params.Set("button", static_cast<int>(key_index)); |
| 63 | keyboard_params.Set("engine", "keyboard"); | 67 | keyboard_moddifier_params.Set("pad", 1); |
| 64 | keyboard_params.Set("button", static_cast<int>(key_index)); | 68 | keyboard_device = Common::Input::CreateInputDevice(keyboard_moddifier_params); |
| 65 | keyboard_params.Set("port", 1); | ||
| 66 | keyboard_params.Set("pad", 1); | ||
| 67 | keyboard_device = Common::Input::CreateInputDevice(keyboard_params); | ||
| 68 | key_index++; | 69 | key_index++; |
| 69 | } | 70 | } |
| 70 | 71 | ||
| @@ -80,14 +81,14 @@ void EmulatedDevices::ReloadInput() { | |||
| 80 | }); | 81 | }); |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | for (std::size_t index = 0; index < mouse_analog_devices.size(); ++index) { | 84 | for (std::size_t index = 0; index < mouse_wheel_devices.size(); ++index) { |
| 84 | if (!mouse_analog_devices[index]) { | 85 | if (!mouse_wheel_devices[index]) { |
| 85 | continue; | 86 | continue; |
| 86 | } | 87 | } |
| 87 | mouse_analog_devices[index]->SetCallback({ | 88 | mouse_wheel_devices[index]->SetCallback({ |
| 88 | .on_change = | 89 | .on_change = |
| 89 | [this, index](const Common::Input::CallbackStatus& callback) { | 90 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 90 | SetMouseAnalog(callback, index); | 91 | SetMouseWheel(callback, index); |
| 91 | }, | 92 | }, |
| 92 | }); | 93 | }); |
| 93 | } | 94 | } |
| @@ -95,7 +96,9 @@ void EmulatedDevices::ReloadInput() { | |||
| 95 | if (mouse_stick_device) { | 96 | if (mouse_stick_device) { |
| 96 | mouse_stick_device->SetCallback({ | 97 | mouse_stick_device->SetCallback({ |
| 97 | .on_change = | 98 | .on_change = |
| 98 | [this](const Common::Input::CallbackStatus& callback) { SetMouseStick(callback); }, | 99 | [this](const Common::Input::CallbackStatus& callback) { |
| 100 | SetMousePosition(callback); | ||
| 101 | }, | ||
| 99 | }); | 102 | }); |
| 100 | } | 103 | } |
| 101 | 104 | ||
| @@ -128,7 +131,7 @@ void EmulatedDevices::UnloadInput() { | |||
| 128 | for (auto& button : mouse_button_devices) { | 131 | for (auto& button : mouse_button_devices) { |
| 129 | button.reset(); | 132 | button.reset(); |
| 130 | } | 133 | } |
| 131 | for (auto& analog : mouse_analog_devices) { | 134 | for (auto& analog : mouse_wheel_devices) { |
| 132 | analog.reset(); | 135 | analog.reset(); |
| 133 | } | 136 | } |
| 134 | mouse_stick_device.reset(); | 137 | mouse_stick_device.reset(); |
| @@ -362,18 +365,18 @@ void EmulatedDevices::SetMouseButton(const Common::Input::CallbackStatus& callba | |||
| 362 | TriggerOnChange(DeviceTriggerType::Mouse); | 365 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 363 | } | 366 | } |
| 364 | 367 | ||
| 365 | void EmulatedDevices::SetMouseAnalog(const Common::Input::CallbackStatus& callback, | 368 | void EmulatedDevices::SetMouseWheel(const Common::Input::CallbackStatus& callback, |
| 366 | std::size_t index) { | 369 | std::size_t index) { |
| 367 | if (index >= device_status.mouse_analog_values.size()) { | 370 | if (index >= device_status.mouse_wheel_values.size()) { |
| 368 | return; | 371 | return; |
| 369 | } | 372 | } |
| 370 | std::unique_lock lock{mutex}; | 373 | std::unique_lock lock{mutex}; |
| 371 | const auto analog_value = TransformToAnalog(callback); | 374 | const auto analog_value = TransformToAnalog(callback); |
| 372 | 375 | ||
| 373 | device_status.mouse_analog_values[index] = analog_value; | 376 | device_status.mouse_wheel_values[index] = analog_value; |
| 374 | 377 | ||
| 375 | if (is_configuring) { | 378 | if (is_configuring) { |
| 376 | device_status.mouse_position_state = {}; | 379 | device_status.mouse_wheel_state = {}; |
| 377 | lock.unlock(); | 380 | lock.unlock(); |
| 378 | TriggerOnChange(DeviceTriggerType::Mouse); | 381 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 379 | return; | 382 | return; |
| @@ -392,7 +395,7 @@ void EmulatedDevices::SetMouseAnalog(const Common::Input::CallbackStatus& callba | |||
| 392 | TriggerOnChange(DeviceTriggerType::Mouse); | 395 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 393 | } | 396 | } |
| 394 | 397 | ||
| 395 | void EmulatedDevices::SetMouseStick(const Common::Input::CallbackStatus& callback) { | 398 | void EmulatedDevices::SetMousePosition(const Common::Input::CallbackStatus& callback) { |
| 396 | std::unique_lock lock{mutex}; | 399 | std::unique_lock lock{mutex}; |
| 397 | const auto touch_value = TransformToTouch(callback); | 400 | const auto touch_value = TransformToTouch(callback); |
| 398 | 401 | ||