diff options
Diffstat (limited to 'src/core/hid/emulated_devices.cpp')
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index 874780ec2..708480f2d 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp | |||
| @@ -70,50 +70,55 @@ void EmulatedDevices::ReloadInput() { | |||
| 70 | if (!mouse_button_devices[index]) { | 70 | if (!mouse_button_devices[index]) { |
| 71 | continue; | 71 | continue; |
| 72 | } | 72 | } |
| 73 | Common::Input::InputCallback button_callback{ | 73 | mouse_button_devices[index]->SetCallback({ |
| 74 | [this, index](Common::Input::CallbackStatus callback) { | 74 | .on_change = |
| 75 | SetMouseButton(callback, index); | 75 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 76 | }}; | 76 | SetMouseButton(callback, index); |
| 77 | mouse_button_devices[index]->SetCallback(button_callback); | 77 | }, |
| 78 | }); | ||
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | for (std::size_t index = 0; index < mouse_analog_devices.size(); ++index) { | 81 | for (std::size_t index = 0; index < mouse_analog_devices.size(); ++index) { |
| 81 | if (!mouse_analog_devices[index]) { | 82 | if (!mouse_analog_devices[index]) { |
| 82 | continue; | 83 | continue; |
| 83 | } | 84 | } |
| 84 | Common::Input::InputCallback button_callback{ | 85 | mouse_analog_devices[index]->SetCallback({ |
| 85 | [this, index](Common::Input::CallbackStatus callback) { | 86 | .on_change = |
| 86 | SetMouseAnalog(callback, index); | 87 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 87 | }}; | 88 | SetMouseAnalog(callback, index); |
| 88 | mouse_analog_devices[index]->SetCallback(button_callback); | 89 | }, |
| 90 | }); | ||
| 89 | } | 91 | } |
| 90 | 92 | ||
| 91 | if (mouse_stick_device) { | 93 | if (mouse_stick_device) { |
| 92 | Common::Input::InputCallback button_callback{ | 94 | mouse_stick_device->SetCallback({ |
| 93 | [this](Common::Input::CallbackStatus callback) { SetMouseStick(callback); }}; | 95 | .on_change = |
| 94 | mouse_stick_device->SetCallback(button_callback); | 96 | [this](const Common::Input::CallbackStatus& callback) { SetMouseStick(callback); }, |
| 97 | }); | ||
| 95 | } | 98 | } |
| 96 | 99 | ||
| 97 | for (std::size_t index = 0; index < keyboard_devices.size(); ++index) { | 100 | for (std::size_t index = 0; index < keyboard_devices.size(); ++index) { |
| 98 | if (!keyboard_devices[index]) { | 101 | if (!keyboard_devices[index]) { |
| 99 | continue; | 102 | continue; |
| 100 | } | 103 | } |
| 101 | Common::Input::InputCallback button_callback{ | 104 | keyboard_devices[index]->SetCallback({ |
| 102 | [this, index](Common::Input::CallbackStatus callback) { | 105 | .on_change = |
| 103 | SetKeyboardButton(callback, index); | 106 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 104 | }}; | 107 | SetKeyboardButton(callback, index); |
| 105 | keyboard_devices[index]->SetCallback(button_callback); | 108 | }, |
| 109 | }); | ||
| 106 | } | 110 | } |
| 107 | 111 | ||
| 108 | for (std::size_t index = 0; index < keyboard_modifier_devices.size(); ++index) { | 112 | for (std::size_t index = 0; index < keyboard_modifier_devices.size(); ++index) { |
| 109 | if (!keyboard_modifier_devices[index]) { | 113 | if (!keyboard_modifier_devices[index]) { |
| 110 | continue; | 114 | continue; |
| 111 | } | 115 | } |
| 112 | Common::Input::InputCallback button_callback{ | 116 | keyboard_modifier_devices[index]->SetCallback({ |
| 113 | [this, index](Common::Input::CallbackStatus callback) { | 117 | .on_change = |
| 114 | SetKeyboardModifier(callback, index); | 118 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 115 | }}; | 119 | SetKeyboardModifier(callback, index); |
| 116 | keyboard_modifier_devices[index]->SetCallback(button_callback); | 120 | }, |
| 121 | }); | ||
| 117 | } | 122 | } |
| 118 | } | 123 | } |
| 119 | 124 | ||
| @@ -159,7 +164,8 @@ void EmulatedDevices::RestoreConfig() { | |||
| 159 | ReloadFromSettings(); | 164 | ReloadFromSettings(); |
| 160 | } | 165 | } |
| 161 | 166 | ||
| 162 | void EmulatedDevices::SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index) { | 167 | void EmulatedDevices::SetKeyboardButton(const Common::Input::CallbackStatus& callback, |
| 168 | std::size_t index) { | ||
| 163 | if (index >= device_status.keyboard_values.size()) { | 169 | if (index >= device_status.keyboard_values.size()) { |
| 164 | return; | 170 | return; |
| 165 | } | 171 | } |
| @@ -216,7 +222,7 @@ void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) { | |||
| 216 | } | 222 | } |
| 217 | } | 223 | } |
| 218 | 224 | ||
| 219 | void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback, | 225 | void EmulatedDevices::SetKeyboardModifier(const Common::Input::CallbackStatus& callback, |
| 220 | std::size_t index) { | 226 | std::size_t index) { |
| 221 | if (index >= device_status.keyboard_moddifier_values.size()) { | 227 | if (index >= device_status.keyboard_moddifier_values.size()) { |
| 222 | return; | 228 | return; |
| @@ -286,7 +292,8 @@ void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback | |||
| 286 | TriggerOnChange(DeviceTriggerType::KeyboardModdifier); | 292 | TriggerOnChange(DeviceTriggerType::KeyboardModdifier); |
| 287 | } | 293 | } |
| 288 | 294 | ||
| 289 | void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index) { | 295 | void EmulatedDevices::SetMouseButton(const Common::Input::CallbackStatus& callback, |
| 296 | std::size_t index) { | ||
| 290 | if (index >= device_status.mouse_button_values.size()) { | 297 | if (index >= device_status.mouse_button_values.size()) { |
| 291 | return; | 298 | return; |
| 292 | } | 299 | } |
| @@ -347,7 +354,8 @@ void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std | |||
| 347 | TriggerOnChange(DeviceTriggerType::Mouse); | 354 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 348 | } | 355 | } |
| 349 | 356 | ||
| 350 | void EmulatedDevices::SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index) { | 357 | void EmulatedDevices::SetMouseAnalog(const Common::Input::CallbackStatus& callback, |
| 358 | std::size_t index) { | ||
| 351 | if (index >= device_status.mouse_analog_values.size()) { | 359 | if (index >= device_status.mouse_analog_values.size()) { |
| 352 | return; | 360 | return; |
| 353 | } | 361 | } |
| @@ -374,7 +382,7 @@ void EmulatedDevices::SetMouseAnalog(Common::Input::CallbackStatus callback, std | |||
| 374 | TriggerOnChange(DeviceTriggerType::Mouse); | 382 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 375 | } | 383 | } |
| 376 | 384 | ||
| 377 | void EmulatedDevices::SetMouseStick(Common::Input::CallbackStatus callback) { | 385 | void EmulatedDevices::SetMouseStick(const Common::Input::CallbackStatus& callback) { |
| 378 | std::lock_guard lock{mutex}; | 386 | std::lock_guard lock{mutex}; |
| 379 | const auto touch_value = TransformToTouch(callback); | 387 | const auto touch_value = TransformToTouch(callback); |
| 380 | 388 | ||
| @@ -435,7 +443,7 @@ void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) { | |||
| 435 | 443 | ||
| 436 | int EmulatedDevices::SetCallback(InterfaceUpdateCallback update_callback) { | 444 | int EmulatedDevices::SetCallback(InterfaceUpdateCallback update_callback) { |
| 437 | std::lock_guard lock{mutex}; | 445 | std::lock_guard lock{mutex}; |
| 438 | callback_list.insert_or_assign(last_callback_key, update_callback); | 446 | callback_list.insert_or_assign(last_callback_key, std::move(update_callback)); |
| 439 | return last_callback_key++; | 447 | return last_callback_key++; |
| 440 | } | 448 | } |
| 441 | 449 | ||