summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/input.h18
-rw-r--r--src/common/x64/cpu_detect.cpp12
-rw-r--r--src/core/hid/emulated_console.cpp21
-rw-r--r--src/core/hid/emulated_console.h4
-rw-r--r--src/core/hid/emulated_controller.cpp99
-rw-r--r--src/core/hid/emulated_controller.h13
-rw-r--r--src/core/hid/emulated_devices.cpp66
-rw-r--r--src/core/hid/emulated_devices.h11
-rw-r--r--src/input_common/drivers/gc_adapter.cpp6
-rw-r--r--src/input_common/drivers/gc_adapter.h8
-rw-r--r--src/input_common/drivers/keyboard.cpp2
-rw-r--r--src/input_common/drivers/keyboard.h4
-rw-r--r--src/input_common/drivers/mouse.cpp2
-rw-r--r--src/input_common/drivers/mouse.h4
-rw-r--r--src/input_common/drivers/sdl_driver.cpp19
-rw-r--r--src/input_common/drivers/sdl_driver.h14
-rw-r--r--src/input_common/drivers/tas_input.cpp2
-rw-r--r--src/input_common/drivers/tas_input.h6
-rw-r--r--src/input_common/drivers/touch_screen.cpp2
-rw-r--r--src/input_common/drivers/touch_screen.h4
-rw-r--r--src/input_common/drivers/udp_client.cpp2
-rw-r--r--src/input_common/drivers/udp_client.h6
-rw-r--r--src/input_common/helpers/stick_from_buttons.cpp75
-rw-r--r--src/input_common/helpers/touch_from_buttons.cpp11
-rw-r--r--src/input_common/input_engine.cpp86
-rw-r--r--src/input_common/input_engine.h53
-rw-r--r--src/input_common/input_mapping.h28
-rw-r--r--src/input_common/input_poller.cpp39
-rw-r--r--src/input_common/input_poller.h212
-rw-r--r--src/video_core/renderer_vulkan/maxwell_to_vk.cpp4
-rw-r--r--src/yuzu/applets/qt_software_keyboard.cpp23
31 files changed, 446 insertions, 410 deletions
diff --git a/src/common/input.h b/src/common/input.h
index eaee0bdea..f775a4c01 100644
--- a/src/common/input.h
+++ b/src/common/input.h
@@ -227,7 +227,7 @@ struct CallbackStatus {
227 227
228// Triggered once every input change 228// Triggered once every input change
229struct InputCallback { 229struct InputCallback {
230 std::function<void(CallbackStatus)> on_change; 230 std::function<void(const CallbackStatus&)> on_change;
231}; 231};
232 232
233/// An abstract class template for an input device (a button, an analog input, etc.). 233/// An abstract class template for an input device (a button, an analog input, etc.).
@@ -236,14 +236,10 @@ public:
236 virtual ~InputDevice() = default; 236 virtual ~InputDevice() = default;
237 237
238 // Request input device to update if necessary 238 // Request input device to update if necessary
239 virtual void SoftUpdate() { 239 virtual void SoftUpdate() {}
240 return;
241 }
242 240
243 // Force input device to update data regardless of the current state 241 // Force input device to update data regardless of the current state
244 virtual void ForceUpdate() { 242 virtual void ForceUpdate() {}
245 return;
246 }
247 243
248 // Sets the function to be triggered when input changes 244 // Sets the function to be triggered when input changes
249 void SetCallback(InputCallback callback_) { 245 void SetCallback(InputCallback callback_) {
@@ -251,7 +247,7 @@ public:
251 } 247 }
252 248
253 // Triggers the function set in the callback 249 // Triggers the function set in the callback
254 void TriggerOnChange(CallbackStatus status) { 250 void TriggerOnChange(const CallbackStatus& status) {
255 if (callback.on_change) { 251 if (callback.on_change) {
256 callback.on_change(status); 252 callback.on_change(status);
257 } 253 }
@@ -266,11 +262,9 @@ class OutputDevice {
266public: 262public:
267 virtual ~OutputDevice() = default; 263 virtual ~OutputDevice() = default;
268 264
269 virtual void SetLED([[maybe_unused]] LedStatus led_status) { 265 virtual void SetLED([[maybe_unused]] const LedStatus& led_status) {}
270 return;
271 }
272 266
273 virtual VibrationError SetVibration([[maybe_unused]] VibrationStatus vibration_status) { 267 virtual VibrationError SetVibration([[maybe_unused]] const VibrationStatus& vibration_status) {
274 return VibrationError::NotSupported; 268 return VibrationError::NotSupported;
275 } 269 }
276 270
diff --git a/src/common/x64/cpu_detect.cpp b/src/common/x64/cpu_detect.cpp
index fccd2eee5..fbeacc7e2 100644
--- a/src/common/x64/cpu_detect.cpp
+++ b/src/common/x64/cpu_detect.cpp
@@ -71,9 +71,6 @@ static CPUCaps Detect() {
71 else 71 else
72 caps.manufacturer = Manufacturer::Unknown; 72 caps.manufacturer = Manufacturer::Unknown;
73 73
74 u32 family = {};
75 u32 model = {};
76
77 __cpuid(cpu_id, 0x80000000); 74 __cpuid(cpu_id, 0x80000000);
78 75
79 u32 max_ex_fn = cpu_id[0]; 76 u32 max_ex_fn = cpu_id[0];
@@ -84,15 +81,6 @@ static CPUCaps Detect() {
84 // Detect family and other miscellaneous features 81 // Detect family and other miscellaneous features
85 if (max_std_fn >= 1) { 82 if (max_std_fn >= 1) {
86 __cpuid(cpu_id, 0x00000001); 83 __cpuid(cpu_id, 0x00000001);
87 family = (cpu_id[0] >> 8) & 0xf;
88 model = (cpu_id[0] >> 4) & 0xf;
89 if (family == 0xf) {
90 family += (cpu_id[0] >> 20) & 0xff;
91 }
92 if (family >= 6) {
93 model += ((cpu_id[0] >> 16) & 0xf) << 4;
94 }
95
96 if ((cpu_id[3] >> 25) & 1) 84 if ((cpu_id[3] >> 25) & 1)
97 caps.sse = true; 85 caps.sse = true;
98 if ((cpu_id[3] >> 26) & 1) 86 if ((cpu_id[3] >> 26) & 1)
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp
index 80db8e9c6..685ec080c 100644
--- a/src/core/hid/emulated_console.cpp
+++ b/src/core/hid/emulated_console.cpp
@@ -66,9 +66,10 @@ void EmulatedConsole::ReloadInput() {
66 66
67 motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params); 67 motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params);
68 if (motion_devices) { 68 if (motion_devices) {
69 Common::Input::InputCallback motion_callback{ 69 motion_devices->SetCallback({
70 [this](Common::Input::CallbackStatus callback) { SetMotion(callback); }}; 70 .on_change =
71 motion_devices->SetCallback(motion_callback); 71 [this](const Common::Input::CallbackStatus& callback) { SetMotion(callback); },
72 });
72 } 73 }
73 74
74 // Unique index for identifying touch device source 75 // Unique index for identifying touch device source
@@ -78,9 +79,12 @@ void EmulatedConsole::ReloadInput() {
78 if (!touch_device) { 79 if (!touch_device) {
79 continue; 80 continue;
80 } 81 }
81 Common::Input::InputCallback touch_callback{ 82 touch_device->SetCallback({
82 [this, index](Common::Input::CallbackStatus callback) { SetTouch(callback, index); }}; 83 .on_change =
83 touch_device->SetCallback(touch_callback); 84 [this, index](const Common::Input::CallbackStatus& callback) {
85 SetTouch(callback, index);
86 },
87 });
84 index++; 88 index++;
85 } 89 }
86} 90}
@@ -127,7 +131,7 @@ void EmulatedConsole::SetMotionParam(Common::ParamPackage param) {
127 ReloadInput(); 131 ReloadInput();
128} 132}
129 133
130void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) { 134void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) {
131 std::lock_guard lock{mutex}; 135 std::lock_guard lock{mutex};
132 auto& raw_status = console.motion_values.raw_status; 136 auto& raw_status = console.motion_values.raw_status;
133 auto& emulated = console.motion_values.emulated; 137 auto& emulated = console.motion_values.emulated;
@@ -162,8 +166,7 @@ void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) {
162 TriggerOnChange(ConsoleTriggerType::Motion); 166 TriggerOnChange(ConsoleTriggerType::Motion);
163} 167}
164 168
165void EmulatedConsole::SetTouch(Common::Input::CallbackStatus callback, 169void EmulatedConsole::SetTouch(const Common::Input::CallbackStatus& callback, std::size_t index) {
166 [[maybe_unused]] std::size_t index) {
167 if (index >= console.touch_values.size()) { 170 if (index >= console.touch_values.size()) {
168 return; 171 return;
169 } 172 }
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h
index bb3d7ab90..3afd284d5 100644
--- a/src/core/hid/emulated_console.h
+++ b/src/core/hid/emulated_console.h
@@ -155,14 +155,14 @@ private:
155 * Updates the motion status of the console 155 * Updates the motion status of the console
156 * @param callback A CallbackStatus containing gyro and accelerometer data 156 * @param callback A CallbackStatus containing gyro and accelerometer data
157 */ 157 */
158 void SetMotion(Common::Input::CallbackStatus callback); 158 void SetMotion(const Common::Input::CallbackStatus& callback);
159 159
160 /** 160 /**
161 * Updates the touch status of the console 161 * Updates the touch status of the console
162 * @param callback A CallbackStatus containing the touch position 162 * @param callback A CallbackStatus containing the touch position
163 * @param index Finger ID to be updated 163 * @param index Finger ID to be updated
164 */ 164 */
165 void SetTouch(Common::Input::CallbackStatus callback, std::size_t index); 165 void SetTouch(const Common::Input::CallbackStatus& callback, std::size_t index);
166 166
167 /** 167 /**
168 * Triggers a callback that something has changed on the console status 168 * Triggers a callback that something has changed on the console status
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index fbb19f230..93372445b 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -205,11 +205,12 @@ void EmulatedController::ReloadInput() {
205 continue; 205 continue;
206 } 206 }
207 const auto uuid = Common::UUID{button_params[index].Get("guid", "")}; 207 const auto uuid = Common::UUID{button_params[index].Get("guid", "")};
208 Common::Input::InputCallback button_callback{ 208 button_devices[index]->SetCallback({
209 [this, index, uuid](Common::Input::CallbackStatus callback) { 209 .on_change =
210 SetButton(callback, index, uuid); 210 [this, index, uuid](const Common::Input::CallbackStatus& callback) {
211 }}; 211 SetButton(callback, index, uuid);
212 button_devices[index]->SetCallback(button_callback); 212 },
213 });
213 button_devices[index]->ForceUpdate(); 214 button_devices[index]->ForceUpdate();
214 } 215 }
215 216
@@ -218,11 +219,12 @@ void EmulatedController::ReloadInput() {
218 continue; 219 continue;
219 } 220 }
220 const auto uuid = Common::UUID{stick_params[index].Get("guid", "")}; 221 const auto uuid = Common::UUID{stick_params[index].Get("guid", "")};
221 Common::Input::InputCallback stick_callback{ 222 stick_devices[index]->SetCallback({
222 [this, index, uuid](Common::Input::CallbackStatus callback) { 223 .on_change =
223 SetStick(callback, index, uuid); 224 [this, index, uuid](const Common::Input::CallbackStatus& callback) {
224 }}; 225 SetStick(callback, index, uuid);
225 stick_devices[index]->SetCallback(stick_callback); 226 },
227 });
226 stick_devices[index]->ForceUpdate(); 228 stick_devices[index]->ForceUpdate();
227 } 229 }
228 230
@@ -231,11 +233,12 @@ void EmulatedController::ReloadInput() {
231 continue; 233 continue;
232 } 234 }
233 const auto uuid = Common::UUID{trigger_params[index].Get("guid", "")}; 235 const auto uuid = Common::UUID{trigger_params[index].Get("guid", "")};
234 Common::Input::InputCallback trigger_callback{ 236 trigger_devices[index]->SetCallback({
235 [this, index, uuid](Common::Input::CallbackStatus callback) { 237 .on_change =
236 SetTrigger(callback, index, uuid); 238 [this, index, uuid](const Common::Input::CallbackStatus& callback) {
237 }}; 239 SetTrigger(callback, index, uuid);
238 trigger_devices[index]->SetCallback(trigger_callback); 240 },
241 });
239 trigger_devices[index]->ForceUpdate(); 242 trigger_devices[index]->ForceUpdate();
240 } 243 }
241 244
@@ -243,9 +246,12 @@ void EmulatedController::ReloadInput() {
243 if (!battery_devices[index]) { 246 if (!battery_devices[index]) {
244 continue; 247 continue;
245 } 248 }
246 Common::Input::InputCallback battery_callback{ 249 battery_devices[index]->SetCallback({
247 [this, index](Common::Input::CallbackStatus callback) { SetBattery(callback, index); }}; 250 .on_change =
248 battery_devices[index]->SetCallback(battery_callback); 251 [this, index](const Common::Input::CallbackStatus& callback) {
252 SetBattery(callback, index);
253 },
254 });
249 battery_devices[index]->ForceUpdate(); 255 battery_devices[index]->ForceUpdate();
250 } 256 }
251 257
@@ -253,9 +259,12 @@ void EmulatedController::ReloadInput() {
253 if (!motion_devices[index]) { 259 if (!motion_devices[index]) {
254 continue; 260 continue;
255 } 261 }
256 Common::Input::InputCallback motion_callback{ 262 motion_devices[index]->SetCallback({
257 [this, index](Common::Input::CallbackStatus callback) { SetMotion(callback, index); }}; 263 .on_change =
258 motion_devices[index]->SetCallback(motion_callback); 264 [this, index](const Common::Input::CallbackStatus& callback) {
265 SetMotion(callback, index);
266 },
267 });
259 motion_devices[index]->ForceUpdate(); 268 motion_devices[index]->ForceUpdate();
260 } 269 }
261 270
@@ -267,22 +276,24 @@ void EmulatedController::ReloadInput() {
267 if (!tas_button_devices[index]) { 276 if (!tas_button_devices[index]) {
268 continue; 277 continue;
269 } 278 }
270 Common::Input::InputCallback button_callback{ 279 tas_button_devices[index]->SetCallback({
271 [this, index, tas_uuid](Common::Input::CallbackStatus callback) { 280 .on_change =
272 SetButton(callback, index, tas_uuid); 281 [this, index, tas_uuid](const Common::Input::CallbackStatus& callback) {
273 }}; 282 SetButton(callback, index, tas_uuid);
274 tas_button_devices[index]->SetCallback(button_callback); 283 },
284 });
275 } 285 }
276 286
277 for (std::size_t index = 0; index < tas_stick_devices.size(); ++index) { 287 for (std::size_t index = 0; index < tas_stick_devices.size(); ++index) {
278 if (!tas_stick_devices[index]) { 288 if (!tas_stick_devices[index]) {
279 continue; 289 continue;
280 } 290 }
281 Common::Input::InputCallback stick_callback{ 291 tas_stick_devices[index]->SetCallback({
282 [this, index, tas_uuid](Common::Input::CallbackStatus callback) { 292 .on_change =
283 SetStick(callback, index, tas_uuid); 293 [this, index, tas_uuid](const Common::Input::CallbackStatus& callback) {
284 }}; 294 SetStick(callback, index, tas_uuid);
285 tas_stick_devices[index]->SetCallback(stick_callback); 295 },
296 });
286 } 297 }
287} 298}
288 299
@@ -440,7 +451,7 @@ void EmulatedController::SetButtonParam(std::size_t index, Common::ParamPackage
440 if (index >= button_params.size()) { 451 if (index >= button_params.size()) {
441 return; 452 return;
442 } 453 }
443 button_params[index] = param; 454 button_params[index] = std::move(param);
444 ReloadInput(); 455 ReloadInput();
445} 456}
446 457
@@ -448,7 +459,7 @@ void EmulatedController::SetStickParam(std::size_t index, Common::ParamPackage p
448 if (index >= stick_params.size()) { 459 if (index >= stick_params.size()) {
449 return; 460 return;
450 } 461 }
451 stick_params[index] = param; 462 stick_params[index] = std::move(param);
452 ReloadInput(); 463 ReloadInput();
453} 464}
454 465
@@ -456,11 +467,11 @@ void EmulatedController::SetMotionParam(std::size_t index, Common::ParamPackage
456 if (index >= motion_params.size()) { 467 if (index >= motion_params.size()) {
457 return; 468 return;
458 } 469 }
459 motion_params[index] = param; 470 motion_params[index] = std::move(param);
460 ReloadInput(); 471 ReloadInput();
461} 472}
462 473
463void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::size_t index, 474void EmulatedController::SetButton(const Common::Input::CallbackStatus& callback, std::size_t index,
464 Common::UUID uuid) { 475 Common::UUID uuid) {
465 if (index >= controller.button_values.size()) { 476 if (index >= controller.button_values.size()) {
466 return; 477 return;
@@ -600,7 +611,7 @@ void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::
600 TriggerOnChange(ControllerTriggerType::Button, true); 611 TriggerOnChange(ControllerTriggerType::Button, true);
601} 612}
602 613
603void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::size_t index, 614void EmulatedController::SetStick(const Common::Input::CallbackStatus& callback, std::size_t index,
604 Common::UUID uuid) { 615 Common::UUID uuid) {
605 if (index >= controller.stick_values.size()) { 616 if (index >= controller.stick_values.size()) {
606 return; 617 return;
@@ -650,8 +661,8 @@ void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::s
650 TriggerOnChange(ControllerTriggerType::Stick, true); 661 TriggerOnChange(ControllerTriggerType::Stick, true);
651} 662}
652 663
653void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std::size_t index, 664void EmulatedController::SetTrigger(const Common::Input::CallbackStatus& callback,
654 Common::UUID uuid) { 665 std::size_t index, Common::UUID uuid) {
655 if (index >= controller.trigger_values.size()) { 666 if (index >= controller.trigger_values.size()) {
656 return; 667 return;
657 } 668 }
@@ -659,7 +670,7 @@ void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std:
659 const auto trigger_value = TransformToTrigger(callback); 670 const auto trigger_value = TransformToTrigger(callback);
660 671
661 // Only read trigger values that have the same uuid or are pressed once 672 // Only read trigger values that have the same uuid or are pressed once
662 if (controller.stick_values[index].uuid != uuid) { 673 if (controller.trigger_values[index].uuid != uuid) {
663 if (!trigger_value.pressed.value) { 674 if (!trigger_value.pressed.value) {
664 return; 675 return;
665 } 676 }
@@ -675,7 +686,7 @@ void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std:
675 return; 686 return;
676 } 687 }
677 688
678 const auto trigger = controller.trigger_values[index]; 689 const auto& trigger = controller.trigger_values[index];
679 690
680 switch (index) { 691 switch (index) {
681 case Settings::NativeTrigger::LTrigger: 692 case Settings::NativeTrigger::LTrigger:
@@ -692,7 +703,8 @@ void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std:
692 TriggerOnChange(ControllerTriggerType::Trigger, true); 703 TriggerOnChange(ControllerTriggerType::Trigger, true);
693} 704}
694 705
695void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::size_t index) { 706void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback,
707 std::size_t index) {
696 if (index >= controller.motion_values.size()) { 708 if (index >= controller.motion_values.size()) {
697 return; 709 return;
698 } 710 }
@@ -730,7 +742,8 @@ void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::
730 TriggerOnChange(ControllerTriggerType::Motion, true); 742 TriggerOnChange(ControllerTriggerType::Motion, true);
731} 743}
732 744
733void EmulatedController::SetBattery(Common::Input::CallbackStatus callback, std::size_t index) { 745void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callback,
746 std::size_t index) {
734 if (index >= controller.battery_values.size()) { 747 if (index >= controller.battery_values.size()) {
735 return; 748 return;
736 } 749 }
@@ -1110,7 +1123,7 @@ void EmulatedController::TriggerOnChange(ControllerTriggerType type, bool is_npa
1110 1123
1111int EmulatedController::SetCallback(ControllerUpdateCallback update_callback) { 1124int EmulatedController::SetCallback(ControllerUpdateCallback update_callback) {
1112 std::lock_guard lock{mutex}; 1125 std::lock_guard lock{mutex};
1113 callback_list.insert_or_assign(last_callback_key, update_callback); 1126 callback_list.insert_or_assign(last_callback_key, std::move(update_callback));
1114 return last_callback_key++; 1127 return last_callback_key++;
1115} 1128}
1116 1129
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 425b3e7c4..e42aafebc 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -328,35 +328,38 @@ private:
328 * @param callback A CallbackStatus containing the button status 328 * @param callback A CallbackStatus containing the button status
329 * @param index Button ID of the to be updated 329 * @param index Button ID of the to be updated
330 */ 330 */
331 void SetButton(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid); 331 void SetButton(const Common::Input::CallbackStatus& callback, std::size_t index,
332 Common::UUID uuid);
332 333
333 /** 334 /**
334 * Updates the analog stick status of the controller 335 * Updates the analog stick status of the controller
335 * @param callback A CallbackStatus containing the analog stick status 336 * @param callback A CallbackStatus containing the analog stick status
336 * @param index stick ID of the to be updated 337 * @param index stick ID of the to be updated
337 */ 338 */
338 void SetStick(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid); 339 void SetStick(const Common::Input::CallbackStatus& callback, std::size_t index,
340 Common::UUID uuid);
339 341
340 /** 342 /**
341 * Updates the trigger status of the controller 343 * Updates the trigger status of the controller
342 * @param callback A CallbackStatus containing the trigger status 344 * @param callback A CallbackStatus containing the trigger status
343 * @param index trigger ID of the to be updated 345 * @param index trigger ID of the to be updated
344 */ 346 */
345 void SetTrigger(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid); 347 void SetTrigger(const Common::Input::CallbackStatus& callback, std::size_t index,
348 Common::UUID uuid);
346 349
347 /** 350 /**
348 * Updates the motion status of the controller 351 * Updates the motion status of the controller
349 * @param callback A CallbackStatus containing gyro and accelerometer data 352 * @param callback A CallbackStatus containing gyro and accelerometer data
350 * @param index motion ID of the to be updated 353 * @param index motion ID of the to be updated
351 */ 354 */
352 void SetMotion(Common::Input::CallbackStatus callback, std::size_t index); 355 void SetMotion(const Common::Input::CallbackStatus& callback, std::size_t index);
353 356
354 /** 357 /**
355 * Updates the battery status of the controller 358 * Updates the battery status of the controller
356 * @param callback A CallbackStatus containing the battery status 359 * @param callback A CallbackStatus containing the battery status
357 * @param index Button ID of the to be updated 360 * @param index Button ID of the to be updated
358 */ 361 */
359 void SetBattery(Common::Input::CallbackStatus callback, std::size_t index); 362 void SetBattery(const Common::Input::CallbackStatus& callback, std::size_t index);
360 363
361 /** 364 /**
362 * Triggers a callback that something has changed on the controller status 365 * Triggers a callback that something has changed on the controller status
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
162void EmulatedDevices::SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index) { 167void 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
219void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback, 225void 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
289void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index) { 295void 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
350void EmulatedDevices::SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index) { 357void 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
377void EmulatedDevices::SetMouseStick(Common::Input::CallbackStatus callback) { 385void 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
436int EmulatedDevices::SetCallback(InterfaceUpdateCallback update_callback) { 444int 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
diff --git a/src/core/hid/emulated_devices.h b/src/core/hid/emulated_devices.h
index c72327681..790d3b411 100644
--- a/src/core/hid/emulated_devices.h
+++ b/src/core/hid/emulated_devices.h
@@ -156,35 +156,34 @@ private:
156 * @param callback A CallbackStatus containing the key status 156 * @param callback A CallbackStatus containing the key status
157 * @param index key ID to be updated 157 * @param index key ID to be updated
158 */ 158 */
159 void SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index); 159 void SetKeyboardButton(const Common::Input::CallbackStatus& callback, std::size_t index);
160 160
161 /** 161 /**
162 * Updates the keyboard status of the keyboard device 162 * Updates the keyboard status of the keyboard device
163 * @param callback A CallbackStatus containing the modifier key status 163 * @param callback A CallbackStatus containing the modifier key status
164 * @param index modifier key ID to be updated 164 * @param index modifier key ID to be updated
165 */ 165 */
166 void SetKeyboardModifier(Common::Input::CallbackStatus callback, std::size_t index); 166 void SetKeyboardModifier(const Common::Input::CallbackStatus& callback, std::size_t index);
167 167
168 /** 168 /**
169 * Updates the mouse button status of the mouse device 169 * Updates the mouse button status of the mouse device
170 * @param callback A CallbackStatus containing the button status 170 * @param callback A CallbackStatus containing the button status
171 * @param index Button ID to be updated 171 * @param index Button ID to be updated
172 */ 172 */
173 void SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index); 173 void SetMouseButton(const Common::Input::CallbackStatus& callback, std::size_t index);
174 174
175 /** 175 /**
176 * Updates the mouse wheel status of the mouse device 176 * Updates the mouse wheel status of the mouse device
177 * @param callback A CallbackStatus containing the wheel status 177 * @param callback A CallbackStatus containing the wheel status
178 * @param index wheel ID to be updated 178 * @param index wheel ID to be updated
179 */ 179 */
180 void SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index); 180 void SetMouseAnalog(const Common::Input::CallbackStatus& callback, std::size_t index);
181 181
182 /** 182 /**
183 * Updates the mouse position status of the mouse device 183 * Updates the mouse position status of the mouse device
184 * @param callback A CallbackStatus containing the position status 184 * @param callback A CallbackStatus containing the position status
185 * @param index stick ID to be updated
186 */ 185 */
187 void SetMouseStick(Common::Input::CallbackStatus callback); 186 void SetMouseStick(const Common::Input::CallbackStatus& callback);
188 187
189 /** 188 /**
190 * Triggers a callback that something has changed on the device status 189 * Triggers a callback that something has changed on the device status
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp
index 8b6574223..7ab4540a8 100644
--- a/src/input_common/drivers/gc_adapter.cpp
+++ b/src/input_common/drivers/gc_adapter.cpp
@@ -69,7 +69,7 @@ private:
69 libusb_device_handle* handle{}; 69 libusb_device_handle* handle{};
70}; 70};
71 71
72GCAdapter::GCAdapter(const std::string& input_engine_) : InputEngine(input_engine_) { 72GCAdapter::GCAdapter(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
73 if (usb_adapter_handle) { 73 if (usb_adapter_handle) {
74 return; 74 return;
75 } 75 }
@@ -325,8 +325,8 @@ bool GCAdapter::GetGCEndpoint(libusb_device* device) {
325 return true; 325 return true;
326} 326}
327 327
328Common::Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier, 328Common::Input::VibrationError GCAdapter::SetRumble(
329 const Common::Input::VibrationStatus vibration) { 329 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) {
330 const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f; 330 const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f;
331 const auto processed_amplitude = 331 const auto processed_amplitude =
332 static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8); 332 static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8);
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h
index 8dc51d2e5..7ce1912a3 100644
--- a/src/input_common/drivers/gc_adapter.h
+++ b/src/input_common/drivers/gc_adapter.h
@@ -22,13 +22,13 @@ namespace InputCommon {
22class LibUSBContext; 22class LibUSBContext;
23class LibUSBDeviceHandle; 23class LibUSBDeviceHandle;
24 24
25class GCAdapter : public InputCommon::InputEngine { 25class GCAdapter : public InputEngine {
26public: 26public:
27 explicit GCAdapter(const std::string& input_engine_); 27 explicit GCAdapter(std::string input_engine_);
28 ~GCAdapter(); 28 ~GCAdapter() override;
29 29
30 Common::Input::VibrationError SetRumble( 30 Common::Input::VibrationError SetRumble(
31 const PadIdentifier& identifier, const Common::Input::VibrationStatus vibration) override; 31 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
32 32
33 /// Used for automapping features 33 /// Used for automapping features
34 std::vector<Common::ParamPackage> GetInputDevices() const override; 34 std::vector<Common::ParamPackage> GetInputDevices() const override;
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp
index 23b0c0ccf..4c1e5bbec 100644
--- a/src/input_common/drivers/keyboard.cpp
+++ b/src/input_common/drivers/keyboard.cpp
@@ -24,7 +24,7 @@ constexpr PadIdentifier keyboard_modifier_identifier = {
24 .pad = 1, 24 .pad = 1,
25}; 25};
26 26
27Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { 27Keyboard::Keyboard(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
28 // Keyboard is broken into 3 diferent sets: 28 // Keyboard is broken into 3 diferent sets:
29 // key: Unfiltered intended for controllers. 29 // key: Unfiltered intended for controllers.
30 // keyboard_key: Allows only Settings::NativeKeyboard::Keys intended for keyboard emulation. 30 // keyboard_key: Allows only Settings::NativeKeyboard::Keys intended for keyboard emulation.
diff --git a/src/input_common/drivers/keyboard.h b/src/input_common/drivers/keyboard.h
index ad123b136..3856c882c 100644
--- a/src/input_common/drivers/keyboard.h
+++ b/src/input_common/drivers/keyboard.h
@@ -12,9 +12,9 @@ namespace InputCommon {
12 * A button device factory representing a keyboard. It receives keyboard events and forward them 12 * A button device factory representing a keyboard. It receives keyboard events and forward them
13 * to all button devices it created. 13 * to all button devices it created.
14 */ 14 */
15class Keyboard final : public InputCommon::InputEngine { 15class Keyboard final : public InputEngine {
16public: 16public:
17 explicit Keyboard(const std::string& input_engine_); 17 explicit Keyboard(std::string input_engine_);
18 18
19 /** 19 /**
20 * Sets the status of all buttons bound with the key to pressed 20 * Sets the status of all buttons bound with the key to pressed
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index 752118e97..aa69216c8 100644
--- a/src/input_common/drivers/mouse.cpp
+++ b/src/input_common/drivers/mouse.cpp
@@ -24,7 +24,7 @@ constexpr PadIdentifier identifier = {
24 .pad = 0, 24 .pad = 0,
25}; 25};
26 26
27Mouse::Mouse(const std::string& input_engine_) : InputEngine(input_engine_) { 27Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
28 PreSetController(identifier); 28 PreSetController(identifier);
29 PreSetAxis(identifier, mouse_axis_x); 29 PreSetAxis(identifier, mouse_axis_x);
30 PreSetAxis(identifier, mouse_axis_y); 30 PreSetAxis(identifier, mouse_axis_y);
diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h
index 4a1fd2fd9..040446178 100644
--- a/src/input_common/drivers/mouse.h
+++ b/src/input_common/drivers/mouse.h
@@ -27,9 +27,9 @@ enum class MouseButton {
27 * A button device factory representing a keyboard. It receives keyboard events and forward them 27 * A button device factory representing a keyboard. It receives keyboard events and forward them
28 * to all button devices it created. 28 * to all button devices it created.
29 */ 29 */
30class Mouse final : public InputCommon::InputEngine { 30class Mouse final : public InputEngine {
31public: 31public:
32 explicit Mouse(const std::string& input_engine_); 32 explicit Mouse(std::string input_engine_);
33 33
34 /** 34 /**
35 * Signals that mouse has moved. 35 * Signals that mouse has moved.
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index 1052ed394..0cda9df62 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -88,7 +88,7 @@ public:
88 return true; 88 return true;
89 } 89 }
90 90
91 BasicMotion GetMotion() { 91 const BasicMotion& GetMotion() const {
92 return motion; 92 return motion;
93 } 93 }
94 94
@@ -367,7 +367,7 @@ void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) {
367 if (joystick->UpdateMotion(event.csensor)) { 367 if (joystick->UpdateMotion(event.csensor)) {
368 const PadIdentifier identifier = joystick->GetPadIdentifier(); 368 const PadIdentifier identifier = joystick->GetPadIdentifier();
369 SetMotion(identifier, 0, joystick->GetMotion()); 369 SetMotion(identifier, 0, joystick->GetMotion());
370 }; 370 }
371 } 371 }
372 break; 372 break;
373 } 373 }
@@ -387,7 +387,7 @@ void SDLDriver::CloseJoysticks() {
387 joystick_map.clear(); 387 joystick_map.clear();
388} 388}
389 389
390SDLDriver::SDLDriver(const std::string& input_engine_) : InputEngine(input_engine_) { 390SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
391 if (!Settings::values.enable_raw_input) { 391 if (!Settings::values.enable_raw_input) {
392 // Disable raw input. When enabled this setting causes SDL to die when a web applet opens 392 // Disable raw input. When enabled this setting causes SDL to die when a web applet opens
393 SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); 393 SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
@@ -403,10 +403,11 @@ SDLDriver::SDLDriver(const std::string& input_engine_) : InputEngine(input_engin
403 403
404 // Use hidapi driver for joycons. This will allow joycons to be detected as a GameController and 404 // Use hidapi driver for joycons. This will allow joycons to be detected as a GameController and
405 // not a generic one 405 // not a generic one
406 SDL_SetHint("SDL_JOYSTICK_HIDAPI_JOY_CONS", "1"); 406 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
407 407
408 // Turn off Pro controller home led 408 // Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native
409 SDL_SetHint("SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED", "0"); 409 // driver on Linux.
410 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_XBOX, "0");
410 411
411 // If the frontend is going to manage the event loop, then we don't start one here 412 // If the frontend is going to manage the event loop, then we don't start one here
412 start_thread = SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == 0; 413 start_thread = SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == 0;
@@ -491,8 +492,9 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
491 } 492 }
492 return devices; 493 return devices;
493} 494}
494Common::Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier, 495
495 const Common::Input::VibrationStatus vibration) { 496Common::Input::VibrationError SDLDriver::SetRumble(
497 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) {
496 const auto joystick = 498 const auto joystick =
497 GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); 499 GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port));
498 const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { 500 const auto process_amplitude_exp = [](f32 amplitude, f32 factor) {
@@ -526,6 +528,7 @@ Common::Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifi
526 528
527 return Common::Input::VibrationError::None; 529 return Common::Input::VibrationError::None;
528} 530}
531
529Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid, 532Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
530 s32 axis, float value) const { 533 s32 axis, float value) const {
531 Common::ParamPackage params{}; 534 Common::ParamPackage params{};
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index d03ff4b84..e9a5d2e26 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -19,19 +19,19 @@ using SDL_GameController = struct _SDL_GameController;
19using SDL_Joystick = struct _SDL_Joystick; 19using SDL_Joystick = struct _SDL_Joystick;
20using SDL_JoystickID = s32; 20using SDL_JoystickID = s32;
21 21
22namespace InputCommon {
23
24class SDLJoystick;
25
22using ButtonBindings = 26using ButtonBindings =
23 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; 27 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>;
24using ZButtonBindings = 28using ZButtonBindings =
25 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>; 29 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>;
26 30
27namespace InputCommon { 31class SDLDriver : public InputEngine {
28
29class SDLJoystick;
30
31class SDLDriver : public InputCommon::InputEngine {
32public: 32public:
33 /// Initializes and registers SDL device factories 33 /// Initializes and registers SDL device factories
34 SDLDriver(const std::string& input_engine_); 34 explicit SDLDriver(std::string input_engine_);
35 35
36 /// Unregisters SDL device factories and shut them down. 36 /// Unregisters SDL device factories and shut them down.
37 ~SDLDriver() override; 37 ~SDLDriver() override;
@@ -59,7 +59,7 @@ public:
59 u8 GetHatButtonId(const std::string& direction_name) const override; 59 u8 GetHatButtonId(const std::string& direction_name) const override;
60 60
61 Common::Input::VibrationError SetRumble( 61 Common::Input::VibrationError SetRumble(
62 const PadIdentifier& identifier, const Common::Input::VibrationStatus vibration) override; 62 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
63 63
64private: 64private:
65 void InitJoystick(int joystick_index); 65 void InitJoystick(int joystick_index);
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index 2094c1feb..5bdd5dac3 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -46,7 +46,7 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but
46 {"KEY_ZR", TasButton::TRIGGER_ZR}, 46 {"KEY_ZR", TasButton::TRIGGER_ZR},
47}; 47};
48 48
49Tas::Tas(const std::string& input_engine_) : InputCommon::InputEngine(input_engine_) { 49Tas::Tas(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
50 for (size_t player_index = 0; player_index < PLAYER_NUMBER; player_index++) { 50 for (size_t player_index = 0; player_index < PLAYER_NUMBER; player_index++) {
51 PadIdentifier identifier{ 51 PadIdentifier identifier{
52 .guid = Common::UUID{}, 52 .guid = Common::UUID{},
diff --git a/src/input_common/drivers/tas_input.h b/src/input_common/drivers/tas_input.h
index 3996fe3a8..4b4e6c417 100644
--- a/src/input_common/drivers/tas_input.h
+++ b/src/input_common/drivers/tas_input.h
@@ -81,10 +81,10 @@ enum class TasState {
81 Stopped, 81 Stopped,
82}; 82};
83 83
84class Tas final : public InputCommon::InputEngine { 84class Tas final : public InputEngine {
85public: 85public:
86 explicit Tas(const std::string& input_engine_); 86 explicit Tas(std::string input_engine_);
87 ~Tas(); 87 ~Tas() override;
88 88
89 /** 89 /**
90 * Changes the input status that will be stored in each frame 90 * Changes the input status that will be stored in each frame
diff --git a/src/input_common/drivers/touch_screen.cpp b/src/input_common/drivers/touch_screen.cpp
index 45b3086f6..880781825 100644
--- a/src/input_common/drivers/touch_screen.cpp
+++ b/src/input_common/drivers/touch_screen.cpp
@@ -13,7 +13,7 @@ constexpr PadIdentifier identifier = {
13 .pad = 0, 13 .pad = 0,
14}; 14};
15 15
16TouchScreen::TouchScreen(const std::string& input_engine_) : InputEngine(input_engine_) { 16TouchScreen::TouchScreen(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
17 PreSetController(identifier); 17 PreSetController(identifier);
18} 18}
19 19
diff --git a/src/input_common/drivers/touch_screen.h b/src/input_common/drivers/touch_screen.h
index 25c11e8bf..bf395c40b 100644
--- a/src/input_common/drivers/touch_screen.h
+++ b/src/input_common/drivers/touch_screen.h
@@ -12,9 +12,9 @@ namespace InputCommon {
12 * A button device factory representing a keyboard. It receives keyboard events and forward them 12 * A button device factory representing a keyboard. It receives keyboard events and forward them
13 * to all button devices it created. 13 * to all button devices it created.
14 */ 14 */
15class TouchScreen final : public InputCommon::InputEngine { 15class TouchScreen final : public InputEngine {
16public: 16public:
17 explicit TouchScreen(const std::string& input_engine_); 17 explicit TouchScreen(std::string input_engine_);
18 18
19 /** 19 /**
20 * Signals that mouse has moved. 20 * Signals that mouse has moved.
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp
index fdee0f2d5..4ab991a7d 100644
--- a/src/input_common/drivers/udp_client.cpp
+++ b/src/input_common/drivers/udp_client.cpp
@@ -136,7 +136,7 @@ static void SocketLoop(Socket* socket) {
136 socket->Loop(); 136 socket->Loop();
137} 137}
138 138
139UDPClient::UDPClient(const std::string& input_engine_) : InputEngine(input_engine_) { 139UDPClient::UDPClient(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
140 LOG_INFO(Input, "Udp Initialization started"); 140 LOG_INFO(Input, "Udp Initialization started");
141 ReloadSockets(); 141 ReloadSockets();
142} 142}
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h
index 5d483f26b..1adc947c4 100644
--- a/src/input_common/drivers/udp_client.h
+++ b/src/input_common/drivers/udp_client.h
@@ -49,10 +49,10 @@ struct DeviceStatus {
49 * A button device factory representing a keyboard. It receives keyboard events and forward them 49 * A button device factory representing a keyboard. It receives keyboard events and forward them
50 * to all button devices it created. 50 * to all button devices it created.
51 */ 51 */
52class UDPClient final : public InputCommon::InputEngine { 52class UDPClient final : public InputEngine {
53public: 53public:
54 explicit UDPClient(const std::string& input_engine_); 54 explicit UDPClient(std::string input_engine_);
55 ~UDPClient(); 55 ~UDPClient() override;
56 56
57 void ReloadSockets(); 57 void ReloadSockets();
58 58
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp
index 77fcd655e..e23394f5f 100644
--- a/src/input_common/helpers/stick_from_buttons.cpp
+++ b/src/input_common/helpers/stick_from_buttons.cpp
@@ -19,23 +19,36 @@ public:
19 : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), 19 : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
20 right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), 20 right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_),
21 modifier_angle(modifier_angle_) { 21 modifier_angle(modifier_angle_) {
22 Common::Input::InputCallback button_up_callback{ 22 up->SetCallback({
23 [this](Common::Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }}; 23 .on_change =
24 Common::Input::InputCallback button_down_callback{ 24 [this](const Common::Input::CallbackStatus& callback_) {
25 [this](Common::Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }}; 25 UpdateUpButtonStatus(callback_);
26 Common::Input::InputCallback button_left_callback{ 26 },
27 [this](Common::Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }}; 27 });
28 Common::Input::InputCallback button_right_callback{ 28 down->SetCallback({
29 [this](Common::Input::CallbackStatus callback_) { 29 .on_change =
30 UpdateRightButtonStatus(callback_); 30 [this](const Common::Input::CallbackStatus& callback_) {
31 }}; 31 UpdateDownButtonStatus(callback_);
32 Common::Input::InputCallback button_modifier_callback{ 32 },
33 [this](Common::Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }}; 33 });
34 up->SetCallback(button_up_callback); 34 left->SetCallback({
35 down->SetCallback(button_down_callback); 35 .on_change =
36 left->SetCallback(button_left_callback); 36 [this](const Common::Input::CallbackStatus& callback_) {
37 right->SetCallback(button_right_callback); 37 UpdateLeftButtonStatus(callback_);
38 modifier->SetCallback(button_modifier_callback); 38 },
39 });
40 right->SetCallback({
41 .on_change =
42 [this](const Common::Input::CallbackStatus& callback_) {
43 UpdateRightButtonStatus(callback_);
44 },
45 });
46 modifier->SetCallback({
47 .on_change =
48 [this](const Common::Input::CallbackStatus& callback_) {
49 UpdateModButtonStatus(callback_);
50 },
51 });
39 last_x_axis_value = 0.0f; 52 last_x_axis_value = 0.0f;
40 last_y_axis_value = 0.0f; 53 last_y_axis_value = 0.0f;
41 } 54 }
@@ -133,27 +146,27 @@ public:
133 } 146 }
134 } 147 }
135 148
136 void UpdateUpButtonStatus(Common::Input::CallbackStatus button_callback) { 149 void UpdateUpButtonStatus(const Common::Input::CallbackStatus& button_callback) {
137 up_status = button_callback.button_status.value; 150 up_status = button_callback.button_status.value;
138 UpdateStatus(); 151 UpdateStatus();
139 } 152 }
140 153
141 void UpdateDownButtonStatus(Common::Input::CallbackStatus button_callback) { 154 void UpdateDownButtonStatus(const Common::Input::CallbackStatus& button_callback) {
142 down_status = button_callback.button_status.value; 155 down_status = button_callback.button_status.value;
143 UpdateStatus(); 156 UpdateStatus();
144 } 157 }
145 158
146 void UpdateLeftButtonStatus(Common::Input::CallbackStatus button_callback) { 159 void UpdateLeftButtonStatus(const Common::Input::CallbackStatus& button_callback) {
147 left_status = button_callback.button_status.value; 160 left_status = button_callback.button_status.value;
148 UpdateStatus(); 161 UpdateStatus();
149 } 162 }
150 163
151 void UpdateRightButtonStatus(Common::Input::CallbackStatus button_callback) { 164 void UpdateRightButtonStatus(const Common::Input::CallbackStatus& button_callback) {
152 right_status = button_callback.button_status.value; 165 right_status = button_callback.button_status.value;
153 UpdateStatus(); 166 UpdateStatus();
154 } 167 }
155 168
156 void UpdateModButtonStatus(Common::Input::CallbackStatus button_callback) { 169 void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) {
157 modifier_status = button_callback.button_status.value; 170 modifier_status = button_callback.button_status.value;
158 UpdateStatus(); 171 UpdateStatus();
159 } 172 }
@@ -265,18 +278,18 @@ private:
265 Button left; 278 Button left;
266 Button right; 279 Button right;
267 Button modifier; 280 Button modifier;
268 float modifier_scale; 281 float modifier_scale{};
269 float modifier_angle; 282 float modifier_angle{};
270 float angle{}; 283 float angle{};
271 float goal_angle{}; 284 float goal_angle{};
272 float amplitude{}; 285 float amplitude{};
273 bool up_status; 286 bool up_status{};
274 bool down_status; 287 bool down_status{};
275 bool left_status; 288 bool left_status{};
276 bool right_status; 289 bool right_status{};
277 bool modifier_status; 290 bool modifier_status{};
278 float last_x_axis_value; 291 float last_x_axis_value{};
279 float last_y_axis_value; 292 float last_y_axis_value{};
280 const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; 293 const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
281 std::chrono::time_point<std::chrono::steady_clock> last_update; 294 std::chrono::time_point<std::chrono::steady_clock> last_update;
282}; 295};
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp
index 35d60bc90..ece1e3b32 100644
--- a/src/input_common/helpers/touch_from_buttons.cpp
+++ b/src/input_common/helpers/touch_from_buttons.cpp
@@ -14,10 +14,13 @@ public:
14 using Button = std::unique_ptr<Common::Input::InputDevice>; 14 using Button = std::unique_ptr<Common::Input::InputDevice>;
15 TouchFromButtonDevice(Button button_, int touch_id_, float x_, float y_) 15 TouchFromButtonDevice(Button button_, int touch_id_, float x_, float y_)
16 : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) { 16 : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) {
17 Common::Input::InputCallback button_up_callback{
18 [this](Common::Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }};
19 last_button_value = false; 17 last_button_value = false;
20 button->SetCallback(button_up_callback); 18 button->SetCallback({
19 .on_change =
20 [this](const Common::Input::CallbackStatus& callback_) {
21 UpdateButtonStatus(callback_);
22 },
23 });
21 button->ForceUpdate(); 24 button->ForceUpdate();
22 } 25 }
23 26
@@ -47,7 +50,7 @@ public:
47 return status; 50 return status;
48 } 51 }
49 52
50 void UpdateButtonStatus(Common::Input::CallbackStatus button_callback) { 53 void UpdateButtonStatus(const Common::Input::CallbackStatus& button_callback) {
51 const Common::Input::CallbackStatus status{ 54 const Common::Input::CallbackStatus status{
52 .type = Common::Input::InputType::Touch, 55 .type = Common::Input::InputType::Touch,
53 .touch_status = GetStatus(button_callback.button_status.value), 56 .touch_status = GetStatus(button_callback.button_status.value),
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp
index 2b2105376..9c17ca4f7 100644
--- a/src/input_common/input_engine.cpp
+++ b/src/input_common/input_engine.cpp
@@ -10,41 +10,31 @@ namespace InputCommon {
10 10
11void InputEngine::PreSetController(const PadIdentifier& identifier) { 11void InputEngine::PreSetController(const PadIdentifier& identifier) {
12 std::lock_guard lock{mutex}; 12 std::lock_guard lock{mutex};
13 if (!controller_list.contains(identifier)) { 13 controller_list.try_emplace(identifier);
14 controller_list.insert_or_assign(identifier, ControllerData{});
15 }
16} 14}
17 15
18void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) { 16void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) {
19 std::lock_guard lock{mutex}; 17 std::lock_guard lock{mutex};
20 ControllerData& controller = controller_list.at(identifier); 18 ControllerData& controller = controller_list.at(identifier);
21 if (!controller.buttons.contains(button)) { 19 controller.buttons.try_emplace(button, false);
22 controller.buttons.insert_or_assign(button, false);
23 }
24} 20}
25 21
26void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) { 22void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) {
27 std::lock_guard lock{mutex}; 23 std::lock_guard lock{mutex};
28 ControllerData& controller = controller_list.at(identifier); 24 ControllerData& controller = controller_list.at(identifier);
29 if (!controller.hat_buttons.contains(button)) { 25 controller.hat_buttons.try_emplace(button, u8{0});
30 controller.hat_buttons.insert_or_assign(button, u8{0});
31 }
32} 26}
33 27
34void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) { 28void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) {
35 std::lock_guard lock{mutex}; 29 std::lock_guard lock{mutex};
36 ControllerData& controller = controller_list.at(identifier); 30 ControllerData& controller = controller_list.at(identifier);
37 if (!controller.axes.contains(axis)) { 31 controller.axes.try_emplace(axis, 0.0f);
38 controller.axes.insert_or_assign(axis, 0.0f);
39 }
40} 32}
41 33
42void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) { 34void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) {
43 std::lock_guard lock{mutex}; 35 std::lock_guard lock{mutex};
44 ControllerData& controller = controller_list.at(identifier); 36 ControllerData& controller = controller_list.at(identifier);
45 if (!controller.motions.contains(motion)) { 37 controller.motions.try_emplace(motion);
46 controller.motions.insert_or_assign(motion, BasicMotion{});
47 }
48} 38}
49 39
50void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) { 40void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) {
@@ -91,7 +81,7 @@ void InputEngine::SetBattery(const PadIdentifier& identifier, BatteryLevel value
91 TriggerOnBatteryChange(identifier, value); 81 TriggerOnBatteryChange(identifier, value);
92} 82}
93 83
94void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, BasicMotion value) { 84void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) {
95 { 85 {
96 std::lock_guard lock{mutex}; 86 std::lock_guard lock{mutex};
97 ControllerData& controller = controller_list.at(identifier); 87 ControllerData& controller = controller_list.at(identifier);
@@ -104,85 +94,93 @@ void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, BasicMo
104 94
105bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const { 95bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const {
106 std::lock_guard lock{mutex}; 96 std::lock_guard lock{mutex};
107 if (!controller_list.contains(identifier)) { 97 const auto controller_iter = controller_list.find(identifier);
98 if (controller_iter == controller_list.cend()) {
108 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 99 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
109 identifier.pad, identifier.port); 100 identifier.pad, identifier.port);
110 return false; 101 return false;
111 } 102 }
112 ControllerData controller = controller_list.at(identifier); 103 const ControllerData& controller = controller_iter->second;
113 if (!controller.buttons.contains(button)) { 104 const auto button_iter = controller.buttons.find(button);
105 if (button_iter == controller.buttons.cend()) {
114 LOG_ERROR(Input, "Invalid button {}", button); 106 LOG_ERROR(Input, "Invalid button {}", button);
115 return false; 107 return false;
116 } 108 }
117 return controller.buttons.at(button); 109 return button_iter->second;
118} 110}
119 111
120bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const { 112bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const {
121 std::lock_guard lock{mutex}; 113 std::lock_guard lock{mutex};
122 if (!controller_list.contains(identifier)) { 114 const auto controller_iter = controller_list.find(identifier);
115 if (controller_iter == controller_list.cend()) {
123 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 116 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
124 identifier.pad, identifier.port); 117 identifier.pad, identifier.port);
125 return false; 118 return false;
126 } 119 }
127 ControllerData controller = controller_list.at(identifier); 120 const ControllerData& controller = controller_iter->second;
128 if (!controller.hat_buttons.contains(button)) { 121 const auto hat_iter = controller.hat_buttons.find(button);
122 if (hat_iter == controller.hat_buttons.cend()) {
129 LOG_ERROR(Input, "Invalid hat button {}", button); 123 LOG_ERROR(Input, "Invalid hat button {}", button);
130 return false; 124 return false;
131 } 125 }
132 return (controller.hat_buttons.at(button) & direction) != 0; 126 return (hat_iter->second & direction) != 0;
133} 127}
134 128
135f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const { 129f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const {
136 std::lock_guard lock{mutex}; 130 std::lock_guard lock{mutex};
137 if (!controller_list.contains(identifier)) { 131 const auto controller_iter = controller_list.find(identifier);
132 if (controller_iter == controller_list.cend()) {
138 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 133 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
139 identifier.pad, identifier.port); 134 identifier.pad, identifier.port);
140 return 0.0f; 135 return 0.0f;
141 } 136 }
142 ControllerData controller = controller_list.at(identifier); 137 const ControllerData& controller = controller_iter->second;
143 if (!controller.axes.contains(axis)) { 138 const auto axis_iter = controller.axes.find(axis);
139 if (axis_iter == controller.axes.cend()) {
144 LOG_ERROR(Input, "Invalid axis {}", axis); 140 LOG_ERROR(Input, "Invalid axis {}", axis);
145 return 0.0f; 141 return 0.0f;
146 } 142 }
147 return controller.axes.at(axis); 143 return axis_iter->second;
148} 144}
149 145
150BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const { 146BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const {
151 std::lock_guard lock{mutex}; 147 std::lock_guard lock{mutex};
152 if (!controller_list.contains(identifier)) { 148 const auto controller_iter = controller_list.find(identifier);
149 if (controller_iter == controller_list.cend()) {
153 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 150 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
154 identifier.pad, identifier.port); 151 identifier.pad, identifier.port);
155 return BatteryLevel::Charging; 152 return BatteryLevel::Charging;
156 } 153 }
157 ControllerData controller = controller_list.at(identifier); 154 const ControllerData& controller = controller_iter->second;
158 return controller.battery; 155 return controller.battery;
159} 156}
160 157
161BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const { 158BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const {
162 std::lock_guard lock{mutex}; 159 std::lock_guard lock{mutex};
163 if (!controller_list.contains(identifier)) { 160 const auto controller_iter = controller_list.find(identifier);
161 if (controller_iter == controller_list.cend()) {
164 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 162 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
165 identifier.pad, identifier.port); 163 identifier.pad, identifier.port);
166 return {}; 164 return {};
167 } 165 }
168 ControllerData controller = controller_list.at(identifier); 166 const ControllerData& controller = controller_iter->second;
169 return controller.motions.at(motion); 167 return controller.motions.at(motion);
170} 168}
171 169
172void InputEngine::ResetButtonState() { 170void InputEngine::ResetButtonState() {
173 for (std::pair<PadIdentifier, ControllerData> controller : controller_list) { 171 for (const auto& controller : controller_list) {
174 for (std::pair<int, bool> button : controller.second.buttons) { 172 for (const auto& button : controller.second.buttons) {
175 SetButton(controller.first, button.first, false); 173 SetButton(controller.first, button.first, false);
176 } 174 }
177 for (std::pair<int, bool> button : controller.second.hat_buttons) { 175 for (const auto& button : controller.second.hat_buttons) {
178 SetHatButton(controller.first, button.first, false); 176 SetHatButton(controller.first, button.first, false);
179 } 177 }
180 } 178 }
181} 179}
182 180
183void InputEngine::ResetAnalogState() { 181void InputEngine::ResetAnalogState() {
184 for (std::pair<PadIdentifier, ControllerData> controller : controller_list) { 182 for (const auto& controller : controller_list) {
185 for (std::pair<int, float> axis : controller.second.axes) { 183 for (const auto& axis : controller.second.axes) {
186 SetAxis(controller.first, axis.first, 0.0); 184 SetAxis(controller.first, axis.first, 0.0);
187 } 185 }
188 } 186 }
@@ -190,7 +188,7 @@ void InputEngine::ResetAnalogState() {
190 188
191void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) { 189void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) {
192 std::lock_guard lock{mutex_callback}; 190 std::lock_guard lock{mutex_callback};
193 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 191 for (const auto& poller_pair : callback_list) {
194 const InputIdentifier& poller = poller_pair.second; 192 const InputIdentifier& poller = poller_pair.second;
195 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) { 193 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) {
196 continue; 194 continue;
@@ -218,7 +216,7 @@ void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int but
218 216
219void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) { 217void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) {
220 std::lock_guard lock{mutex_callback}; 218 std::lock_guard lock{mutex_callback};
221 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 219 for (const auto& poller_pair : callback_list) {
222 const InputIdentifier& poller = poller_pair.second; 220 const InputIdentifier& poller = poller_pair.second;
223 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) { 221 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) {
224 continue; 222 continue;
@@ -247,7 +245,7 @@ void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int
247 245
248void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) { 246void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) {
249 std::lock_guard lock{mutex_callback}; 247 std::lock_guard lock{mutex_callback};
250 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 248 for (const auto& poller_pair : callback_list) {
251 const InputIdentifier& poller = poller_pair.second; 249 const InputIdentifier& poller = poller_pair.second;
252 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) { 250 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) {
253 continue; 251 continue;
@@ -274,7 +272,7 @@ void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis,
274void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, 272void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
275 [[maybe_unused]] BatteryLevel value) { 273 [[maybe_unused]] BatteryLevel value) {
276 std::lock_guard lock{mutex_callback}; 274 std::lock_guard lock{mutex_callback};
277 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 275 for (const auto& poller_pair : callback_list) {
278 const InputIdentifier& poller = poller_pair.second; 276 const InputIdentifier& poller = poller_pair.second;
279 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) { 277 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) {
280 continue; 278 continue;
@@ -286,9 +284,9 @@ void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
286} 284}
287 285
288void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, 286void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
289 BasicMotion value) { 287 const BasicMotion& value) {
290 std::lock_guard lock{mutex_callback}; 288 std::lock_guard lock{mutex_callback};
291 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 289 for (const auto& poller_pair : callback_list) {
292 const InputIdentifier& poller = poller_pair.second; 290 const InputIdentifier& poller = poller_pair.second;
293 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) { 291 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) {
294 continue; 292 continue;
@@ -342,7 +340,7 @@ const std::string& InputEngine::GetEngineName() const {
342 340
343int InputEngine::SetCallback(InputIdentifier input_identifier) { 341int InputEngine::SetCallback(InputIdentifier input_identifier) {
344 std::lock_guard lock{mutex_callback}; 342 std::lock_guard lock{mutex_callback};
345 callback_list.insert_or_assign(last_callback_key, input_identifier); 343 callback_list.insert_or_assign(last_callback_key, std::move(input_identifier));
346 return last_callback_key++; 344 return last_callback_key++;
347} 345}
348 346
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h
index 02272b3f8..390581c94 100644
--- a/src/input_common/input_engine.h
+++ b/src/input_common/input_engine.h
@@ -23,15 +23,15 @@ struct PadIdentifier {
23 friend constexpr bool operator==(const PadIdentifier&, const PadIdentifier&) = default; 23 friend constexpr bool operator==(const PadIdentifier&, const PadIdentifier&) = default;
24}; 24};
25 25
26// Basic motion data containing data from the sensors and a timestamp in microsecons 26// Basic motion data containing data from the sensors and a timestamp in microseconds
27struct BasicMotion { 27struct BasicMotion {
28 float gyro_x; 28 float gyro_x{};
29 float gyro_y; 29 float gyro_y{};
30 float gyro_z; 30 float gyro_z{};
31 float accel_x; 31 float accel_x{};
32 float accel_y; 32 float accel_y{};
33 float accel_z; 33 float accel_z{};
34 u64 delta_timestamp; 34 u64 delta_timestamp{};
35}; 35};
36 36
37// Stages of a battery charge 37// Stages of a battery charge
@@ -102,9 +102,7 @@ struct InputIdentifier {
102 102
103class InputEngine { 103class InputEngine {
104public: 104public:
105 explicit InputEngine(const std::string& input_engine_) : input_engine(input_engine_) { 105 explicit InputEngine(std::string input_engine_) : input_engine{std::move(input_engine_)} {}
106 callback_list.clear();
107 }
108 106
109 virtual ~InputEngine() = default; 107 virtual ~InputEngine() = default;
110 108
@@ -116,14 +114,12 @@ public:
116 114
117 // Sets a led pattern for a controller 115 // Sets a led pattern for a controller
118 virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier, 116 virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier,
119 [[maybe_unused]] const Common::Input::LedStatus led_status) { 117 [[maybe_unused]] const Common::Input::LedStatus& led_status) {}
120 return;
121 }
122 118
123 // Sets rumble to a controller 119 // Sets rumble to a controller
124 virtual Common::Input::VibrationError SetRumble( 120 virtual Common::Input::VibrationError SetRumble(
125 [[maybe_unused]] const PadIdentifier& identifier, 121 [[maybe_unused]] const PadIdentifier& identifier,
126 [[maybe_unused]] const Common::Input::VibrationStatus vibration) { 122 [[maybe_unused]] const Common::Input::VibrationStatus& vibration) {
127 return Common::Input::VibrationError::NotSupported; 123 return Common::Input::VibrationError::NotSupported;
128 } 124 }
129 125
@@ -140,36 +136,36 @@ public:
140 /// Used for automapping features 136 /// Used for automapping features
141 virtual std::vector<Common::ParamPackage> GetInputDevices() const { 137 virtual std::vector<Common::ParamPackage> GetInputDevices() const {
142 return {}; 138 return {};
143 }; 139 }
144 140
145 /// Retrieves the button mappings for the given device 141 /// Retrieves the button mappings for the given device
146 virtual InputCommon::ButtonMapping GetButtonMappingForDevice( 142 virtual ButtonMapping GetButtonMappingForDevice(
147 [[maybe_unused]] const Common::ParamPackage& params) { 143 [[maybe_unused]] const Common::ParamPackage& params) {
148 return {}; 144 return {};
149 }; 145 }
150 146
151 /// Retrieves the analog mappings for the given device 147 /// Retrieves the analog mappings for the given device
152 virtual InputCommon::AnalogMapping GetAnalogMappingForDevice( 148 virtual AnalogMapping GetAnalogMappingForDevice(
153 [[maybe_unused]] const Common::ParamPackage& params) { 149 [[maybe_unused]] const Common::ParamPackage& params) {
154 return {}; 150 return {};
155 }; 151 }
156 152
157 /// Retrieves the motion mappings for the given device 153 /// Retrieves the motion mappings for the given device
158 virtual InputCommon::MotionMapping GetMotionMappingForDevice( 154 virtual MotionMapping GetMotionMappingForDevice(
159 [[maybe_unused]] const Common::ParamPackage& params) { 155 [[maybe_unused]] const Common::ParamPackage& params) {
160 return {}; 156 return {};
161 }; 157 }
162 158
163 /// Retrieves the name of the given input. 159 /// Retrieves the name of the given input.
164 virtual Common::Input::ButtonNames GetUIName( 160 virtual Common::Input::ButtonNames GetUIName(
165 [[maybe_unused]] const Common::ParamPackage& params) const { 161 [[maybe_unused]] const Common::ParamPackage& params) const {
166 return Common::Input::ButtonNames::Engine; 162 return Common::Input::ButtonNames::Engine;
167 }; 163 }
168 164
169 /// Retrieves the index number of the given hat button direction 165 /// Retrieves the index number of the given hat button direction
170 virtual u8 GetHatButtonId([[maybe_unused]] const std::string& direction_name) const { 166 virtual u8 GetHatButtonId([[maybe_unused]] const std::string& direction_name) const {
171 return 0; 167 return 0;
172 }; 168 }
173 169
174 void PreSetController(const PadIdentifier& identifier); 170 void PreSetController(const PadIdentifier& identifier);
175 void PreSetButton(const PadIdentifier& identifier, int button); 171 void PreSetButton(const PadIdentifier& identifier, int button);
@@ -194,7 +190,7 @@ protected:
194 void SetHatButton(const PadIdentifier& identifier, int button, u8 value); 190 void SetHatButton(const PadIdentifier& identifier, int button, u8 value);
195 void SetAxis(const PadIdentifier& identifier, int axis, f32 value); 191 void SetAxis(const PadIdentifier& identifier, int axis, f32 value);
196 void SetBattery(const PadIdentifier& identifier, BatteryLevel value); 192 void SetBattery(const PadIdentifier& identifier, BatteryLevel value);
197 void SetMotion(const PadIdentifier& identifier, int motion, BasicMotion value); 193 void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value);
198 194
199 virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const { 195 virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const {
200 return "Unknown"; 196 return "Unknown";
@@ -206,14 +202,15 @@ private:
206 std::unordered_map<int, u8> hat_buttons; 202 std::unordered_map<int, u8> hat_buttons;
207 std::unordered_map<int, float> axes; 203 std::unordered_map<int, float> axes;
208 std::unordered_map<int, BasicMotion> motions; 204 std::unordered_map<int, BasicMotion> motions;
209 BatteryLevel battery; 205 BatteryLevel battery{};
210 }; 206 };
211 207
212 void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value); 208 void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value);
213 void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); 209 void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value);
214 void TriggerOnAxisChange(const PadIdentifier& identifier, int button, f32 value); 210 void TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value);
215 void TriggerOnBatteryChange(const PadIdentifier& identifier, BatteryLevel value); 211 void TriggerOnBatteryChange(const PadIdentifier& identifier, BatteryLevel value);
216 void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, BasicMotion value); 212 void TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
213 const BasicMotion& value);
217 214
218 bool IsInputIdentifierEqual(const InputIdentifier& input_identifier, 215 bool IsInputIdentifierEqual(const InputIdentifier& input_identifier,
219 const PadIdentifier& identifier, EngineInputType type, 216 const PadIdentifier& identifier, EngineInputType type,
diff --git a/src/input_common/input_mapping.h b/src/input_common/input_mapping.h
index 44eb8ad9a..93564b5f8 100644
--- a/src/input_common/input_mapping.h
+++ b/src/input_common/input_mapping.h
@@ -14,8 +14,8 @@ public:
14 MappingFactory(); 14 MappingFactory();
15 15
16 /** 16 /**
17 * Resets all varables to beggin the mapping process 17 * Resets all variables to begin the mapping process
18 * @param "type": type of input desired to be returned 18 * @param type type of input desired to be returned
19 */ 19 */
20 void BeginMapping(Polling::InputType type); 20 void BeginMapping(Polling::InputType type);
21 21
@@ -24,8 +24,8 @@ public:
24 24
25 /** 25 /**
26 * Registers mapping input data from the driver 26 * Registers mapping input data from the driver
27 * @param "data": An struct containing all the information needed to create a proper 27 * @param data A struct containing all the information needed to create a proper
28 * ParamPackage 28 * ParamPackage
29 */ 29 */
30 void RegisterInput(const MappingData& data); 30 void RegisterInput(const MappingData& data);
31 31
@@ -34,42 +34,42 @@ public:
34 34
35private: 35private:
36 /** 36 /**
37 * If provided data satisfies the requeriments it will push an element to the input_queue 37 * If provided data satisfies the requirements it will push an element to the input_queue
38 * Supported input: 38 * Supported input:
39 * - Button: Creates a basic button ParamPackage 39 * - Button: Creates a basic button ParamPackage
40 * - HatButton: Creates a basic hat button ParamPackage 40 * - HatButton: Creates a basic hat button ParamPackage
41 * - Analog: Creates a basic analog ParamPackage 41 * - Analog: Creates a basic analog ParamPackage
42 * @param "data": An struct containing all the information needed to create a proper 42 * @param data A struct containing all the information needed to create a proper
43 * ParamPackage 43 * ParamPackage
44 */ 44 */
45 void RegisterButton(const MappingData& data); 45 void RegisterButton(const MappingData& data);
46 46
47 /** 47 /**
48 * If provided data satisfies the requeriments it will push an element to the input_queue 48 * If provided data satisfies the requirements it will push an element to the input_queue
49 * Supported input: 49 * Supported input:
50 * - Button, HatButton: Pass the data to RegisterButton 50 * - Button, HatButton: Pass the data to RegisterButton
51 * - Analog: Stores the first axis and on the second axis creates a basic stick ParamPackage 51 * - Analog: Stores the first axis and on the second axis creates a basic stick ParamPackage
52 * @param "data": An struct containing all the information needed to create a proper 52 * @param data A struct containing all the information needed to create a proper
53 * ParamPackage 53 * ParamPackage
54 */ 54 */
55 void RegisterStick(const MappingData& data); 55 void RegisterStick(const MappingData& data);
56 56
57 /** 57 /**
58 * If provided data satisfies the requeriments it will push an element to the input_queue 58 * If provided data satisfies the requirements it will push an element to the input_queue
59 * Supported input: 59 * Supported input:
60 * - Button, HatButton: Pass the data to RegisterButton 60 * - Button, HatButton: Pass the data to RegisterButton
61 * - Analog: Stores the first two axis and on the third axis creates a basic Motion 61 * - Analog: Stores the first two axis and on the third axis creates a basic Motion
62 * ParamPackage 62 * ParamPackage
63 * - Motion: Creates a basic Motion ParamPackage 63 * - Motion: Creates a basic Motion ParamPackage
64 * @param "data": An struct containing all the information needed to create a proper 64 * @param data A struct containing all the information needed to create a proper
65 * ParamPackage 65 * ParamPackage
66 */ 66 */
67 void RegisterMotion(const MappingData& data); 67 void RegisterMotion(const MappingData& data);
68 68
69 /** 69 /**
70 * Returns true if driver can be mapped 70 * Returns true if driver can be mapped
71 * @param "data": An struct containing all the information needed to create a proper 71 * @param data A struct containing all the information needed to create a proper
72 * ParamPackage 72 * ParamPackage
73 */ 73 */
74 bool IsDriverValid(const MappingData& data) const; 74 bool IsDriverValid(const MappingData& data) const;
75 75
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp
index 7e4eafded..7b370335f 100644
--- a/src/input_common/input_poller.cpp
+++ b/src/input_common/input_poller.cpp
@@ -12,8 +12,7 @@ namespace InputCommon {
12 12
13class DummyInput final : public Common::Input::InputDevice { 13class DummyInput final : public Common::Input::InputDevice {
14public: 14public:
15 explicit DummyInput() {} 15 explicit DummyInput() = default;
16 ~DummyInput() {}
17}; 16};
18 17
19class InputFromButton final : public Common::Input::InputDevice { 18class InputFromButton final : public Common::Input::InputDevice {
@@ -33,7 +32,7 @@ public:
33 callback_key = input_engine->SetCallback(input_identifier); 32 callback_key = input_engine->SetCallback(input_identifier);
34 } 33 }
35 34
36 ~InputFromButton() { 35 ~InputFromButton() override {
37 input_engine->DeleteCallback(callback_key); 36 input_engine->DeleteCallback(callback_key);
38 } 37 }
39 38
@@ -45,7 +44,7 @@ public:
45 }; 44 };
46 } 45 }
47 46
48 void ForceUpdate() { 47 void ForceUpdate() override {
49 const Common::Input::CallbackStatus status{ 48 const Common::Input::CallbackStatus status{
50 .type = Common::Input::InputType::Button, 49 .type = Common::Input::InputType::Button,
51 .button_status = GetStatus(), 50 .button_status = GetStatus(),
@@ -94,7 +93,7 @@ public:
94 callback_key = input_engine->SetCallback(input_identifier); 93 callback_key = input_engine->SetCallback(input_identifier);
95 } 94 }
96 95
97 ~InputFromHatButton() { 96 ~InputFromHatButton() override {
98 input_engine->DeleteCallback(callback_key); 97 input_engine->DeleteCallback(callback_key);
99 } 98 }
100 99
@@ -106,7 +105,7 @@ public:
106 }; 105 };
107 } 106 }
108 107
109 void ForceUpdate() { 108 void ForceUpdate() override {
110 const Common::Input::CallbackStatus status{ 109 const Common::Input::CallbackStatus status{
111 .type = Common::Input::InputType::Button, 110 .type = Common::Input::InputType::Button,
112 .button_status = GetStatus(), 111 .button_status = GetStatus(),
@@ -167,7 +166,7 @@ public:
167 callback_key_y = input_engine->SetCallback(y_input_identifier); 166 callback_key_y = input_engine->SetCallback(y_input_identifier);
168 } 167 }
169 168
170 ~InputFromStick() { 169 ~InputFromStick() override {
171 input_engine->DeleteCallback(callback_key_x); 170 input_engine->DeleteCallback(callback_key_x);
172 input_engine->DeleteCallback(callback_key_y); 171 input_engine->DeleteCallback(callback_key_y);
173 } 172 }
@@ -190,7 +189,7 @@ public:
190 return status; 189 return status;
191 } 190 }
192 191
193 void ForceUpdate() { 192 void ForceUpdate() override {
194 const Common::Input::CallbackStatus status{ 193 const Common::Input::CallbackStatus status{
195 .type = Common::Input::InputType::Stick, 194 .type = Common::Input::InputType::Stick,
196 .stick_status = GetStatus(), 195 .stick_status = GetStatus(),
@@ -266,7 +265,7 @@ public:
266 callback_key_y = input_engine->SetCallback(y_input_identifier); 265 callback_key_y = input_engine->SetCallback(y_input_identifier);
267 } 266 }
268 267
269 ~InputFromTouch() { 268 ~InputFromTouch() override {
270 input_engine->DeleteCallback(callback_key_button); 269 input_engine->DeleteCallback(callback_key_button);
271 input_engine->DeleteCallback(callback_key_x); 270 input_engine->DeleteCallback(callback_key_x);
272 input_engine->DeleteCallback(callback_key_y); 271 input_engine->DeleteCallback(callback_key_y);
@@ -352,7 +351,7 @@ public:
352 axis_callback_key = input_engine->SetCallback(axis_input_identifier); 351 axis_callback_key = input_engine->SetCallback(axis_input_identifier);
353 } 352 }
354 353
355 ~InputFromTrigger() { 354 ~InputFromTrigger() override {
356 input_engine->DeleteCallback(callback_key_button); 355 input_engine->DeleteCallback(callback_key_button);
357 input_engine->DeleteCallback(axis_callback_key); 356 input_engine->DeleteCallback(axis_callback_key);
358 } 357 }
@@ -419,7 +418,7 @@ public:
419 callback_key = input_engine->SetCallback(input_identifier); 418 callback_key = input_engine->SetCallback(input_identifier);
420 } 419 }
421 420
422 ~InputFromAnalog() { 421 ~InputFromAnalog() override {
423 input_engine->DeleteCallback(callback_key); 422 input_engine->DeleteCallback(callback_key);
424 } 423 }
425 424
@@ -466,7 +465,7 @@ public:
466 callback_key = input_engine->SetCallback(input_identifier); 465 callback_key = input_engine->SetCallback(input_identifier);
467 } 466 }
468 467
469 ~InputFromBattery() { 468 ~InputFromBattery() override {
470 input_engine->DeleteCallback(callback_key); 469 input_engine->DeleteCallback(callback_key);
471 } 470 }
472 471
@@ -474,7 +473,7 @@ public:
474 return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier)); 473 return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier));
475 } 474 }
476 475
477 void ForceUpdate() { 476 void ForceUpdate() override {
478 const Common::Input::CallbackStatus status{ 477 const Common::Input::CallbackStatus status{
479 .type = Common::Input::InputType::Battery, 478 .type = Common::Input::InputType::Battery,
480 .battery_status = GetStatus(), 479 .battery_status = GetStatus(),
@@ -518,7 +517,7 @@ public:
518 callback_key = input_engine->SetCallback(input_identifier); 517 callback_key = input_engine->SetCallback(input_identifier);
519 } 518 }
520 519
521 ~InputFromMotion() { 520 ~InputFromMotion() override {
522 input_engine->DeleteCallback(callback_key); 521 input_engine->DeleteCallback(callback_key);
523 } 522 }
524 523
@@ -593,7 +592,7 @@ public:
593 callback_key_z = input_engine->SetCallback(z_input_identifier); 592 callback_key_z = input_engine->SetCallback(z_input_identifier);
594 } 593 }
595 594
596 ~InputFromAxisMotion() { 595 ~InputFromAxisMotion() override {
597 input_engine->DeleteCallback(callback_key_x); 596 input_engine->DeleteCallback(callback_key_x);
598 input_engine->DeleteCallback(callback_key_y); 597 input_engine->DeleteCallback(callback_key_y);
599 input_engine->DeleteCallback(callback_key_z); 598 input_engine->DeleteCallback(callback_key_z);
@@ -618,7 +617,7 @@ public:
618 return status; 617 return status;
619 } 618 }
620 619
621 void ForceUpdate() { 620 void ForceUpdate() override {
622 const Common::Input::CallbackStatus status{ 621 const Common::Input::CallbackStatus status{
623 .type = Common::Input::InputType::Motion, 622 .type = Common::Input::InputType::Motion,
624 .motion_status = GetStatus(), 623 .motion_status = GetStatus(),
@@ -668,16 +667,16 @@ public:
668 explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) 667 explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
669 : identifier(identifier_), input_engine(input_engine_) {} 668 : identifier(identifier_), input_engine(input_engine_) {}
670 669
671 virtual void SetLED(Common::Input::LedStatus led_status) { 670 void SetLED(const Common::Input::LedStatus& led_status) override {
672 input_engine->SetLeds(identifier, led_status); 671 input_engine->SetLeds(identifier, led_status);
673 } 672 }
674 673
675 virtual Common::Input::VibrationError SetVibration( 674 Common::Input::VibrationError SetVibration(
676 Common::Input::VibrationStatus vibration_status) { 675 const Common::Input::VibrationStatus& vibration_status) override {
677 return input_engine->SetRumble(identifier, vibration_status); 676 return input_engine->SetRumble(identifier, vibration_status);
678 } 677 }
679 678
680 virtual Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) { 679 Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override {
681 return input_engine->SetPollingMode(identifier, polling_mode); 680 return input_engine->SetPollingMode(identifier, polling_mode);
682 } 681 }
683 682
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h
index 573f09fde..8a0977d58 100644
--- a/src/input_common/input_poller.h
+++ b/src/input_common/input_poller.h
@@ -13,9 +13,6 @@ class Factory;
13 13
14namespace InputCommon { 14namespace InputCommon {
15class InputEngine; 15class InputEngine;
16/**
17 * An Input factory. It receives input events and forward them to all input devices it created.
18 */
19 16
20class OutputFactory final : public Common::Input::Factory<Common::Input::OutputDevice> { 17class OutputFactory final : public Common::Input::Factory<Common::Input::OutputDevice> {
21public: 18public:
@@ -24,10 +21,10 @@ public:
24 /** 21 /**
25 * Creates an output device from the parameters given. 22 * Creates an output device from the parameters given.
26 * @param params contains parameters for creating the device: 23 * @param params contains parameters for creating the device:
27 * @param - "guid": text string for identifing controllers 24 * - "guid" text string for identifying controllers
28 * @param - "port": port of the connected device 25 * - "port": port of the connected device
29 * @param - "pad": slot of the connected controller 26 * - "pad": slot of the connected controller
30 * @return an unique ouput device with the parameters specified 27 * @returns a unique output device with the parameters specified
31 */ 28 */
32 std::unique_ptr<Common::Input::OutputDevice> Create( 29 std::unique_ptr<Common::Input::OutputDevice> Create(
33 const Common::ParamPackage& params) override; 30 const Common::ParamPackage& params) override;
@@ -36,6 +33,9 @@ private:
36 std::shared_ptr<InputEngine> input_engine; 33 std::shared_ptr<InputEngine> input_engine;
37}; 34};
38 35
36/**
37 * An Input factory. It receives input events and forward them to all input devices it created.
38 */
39class InputFactory final : public Common::Input::Factory<Common::Input::InputDevice> { 39class InputFactory final : public Common::Input::Factory<Common::Input::InputDevice> {
40public: 40public:
41 explicit InputFactory(std::shared_ptr<InputEngine> input_engine_); 41 explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);
@@ -54,16 +54,16 @@ public:
54 * - battery: Contains "battery" 54 * - battery: Contains "battery"
55 * - output: Contains "output" 55 * - output: Contains "output"
56 * @param params contains parameters for creating the device: 56 * @param params contains parameters for creating the device:
57 * @param - "code": the code of the keyboard key to bind with the input 57 * - "code": the code of the keyboard key to bind with the input
58 * @param - "button": same as "code" but for controller buttons 58 * - "button": same as "code" but for controller buttons
59 * @param - "hat": similar as "button" but it's a group of hat buttons from SDL 59 * - "hat": similar as "button" but it's a group of hat buttons from SDL
60 * @param - "axis": the axis number of the axis to bind with the input 60 * - "axis": the axis number of the axis to bind with the input
61 * @param - "motion": the motion number of the motion to bind with the input 61 * - "motion": the motion number of the motion to bind with the input
62 * @param - "axis_x": same as axis but specifing horizontal direction 62 * - "axis_x": same as axis but specifying horizontal direction
63 * @param - "axis_y": same as axis but specifing vertical direction 63 * - "axis_y": same as axis but specifying vertical direction
64 * @param - "axis_z": same as axis but specifing forward direction 64 * - "axis_z": same as axis but specifying forward direction
65 * @param - "battery": Only used as a placeholder to set the input type 65 * - "battery": Only used as a placeholder to set the input type
66 * @return an unique input device with the parameters specified 66 * @returns a unique input device with the parameters specified
67 */ 67 */
68 std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override; 68 std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override;
69 69
@@ -71,14 +71,14 @@ private:
71 /** 71 /**
72 * Creates a button device from the parameters given. 72 * Creates a button device from the parameters given.
73 * @param params contains parameters for creating the device: 73 * @param params contains parameters for creating the device:
74 * @param - "code": the code of the keyboard key to bind with the input 74 * - "code": the code of the keyboard key to bind with the input
75 * @param - "button": same as "code" but for controller buttons 75 * - "button": same as "code" but for controller buttons
76 * @param - "toggle": press once to enable, press again to disable 76 * - "toggle": press once to enable, press again to disable
77 * @param - "inverted": inverts the output of the button 77 * - "inverted": inverts the output of the button
78 * @param - "guid": text string for identifing controllers 78 * - "guid": text string for identifying controllers
79 * @param - "port": port of the connected device 79 * - "port": port of the connected device
80 * @param - "pad": slot of the connected controller 80 * - "pad": slot of the connected controller
81 * @return an unique input device with the parameters specified 81 * @returns a unique input device with the parameters specified
82 */ 82 */
83 std::unique_ptr<Common::Input::InputDevice> CreateButtonDevice( 83 std::unique_ptr<Common::Input::InputDevice> CreateButtonDevice(
84 const Common::ParamPackage& params); 84 const Common::ParamPackage& params);
@@ -86,14 +86,14 @@ private:
86 /** 86 /**
87 * Creates a hat button device from the parameters given. 87 * Creates a hat button device from the parameters given.
88 * @param params contains parameters for creating the device: 88 * @param params contains parameters for creating the device:
89 * @param - "button": the controller hat id to bind with the input 89 * - "button": the controller hat id to bind with the input
90 * @param - "direction": the direction id to be detected 90 * - "direction": the direction id to be detected
91 * @param - "toggle": press once to enable, press again to disable 91 * - "toggle": press once to enable, press again to disable
92 * @param - "inverted": inverts the output of the button 92 * - "inverted": inverts the output of the button
93 * @param - "guid": text string for identifing controllers 93 * - "guid": text string for identifying controllers
94 * @param - "port": port of the connected device 94 * - "port": port of the connected device
95 * @param - "pad": slot of the connected controller 95 * - "pad": slot of the connected controller
96 * @return an unique input device with the parameters specified 96 * @returns a unique input device with the parameters specified
97 */ 97 */
98 std::unique_ptr<Common::Input::InputDevice> CreateHatButtonDevice( 98 std::unique_ptr<Common::Input::InputDevice> CreateHatButtonDevice(
99 const Common::ParamPackage& params); 99 const Common::ParamPackage& params);
@@ -101,19 +101,19 @@ private:
101 /** 101 /**
102 * Creates a stick device from the parameters given. 102 * Creates a stick device from the parameters given.
103 * @param params contains parameters for creating the device: 103 * @param params contains parameters for creating the device:
104 * @param - "axis_x": the controller horizontal axis id to bind with the input 104 * - "axis_x": the controller horizontal axis id to bind with the input
105 * @param - "axis_y": the controller vertical axis id to bind with the input 105 * - "axis_y": the controller vertical axis id to bind with the input
106 * @param - "deadzone": the mimimum required value to be detected 106 * - "deadzone": the minimum required value to be detected
107 * @param - "range": the maximum value required to reach 100% 107 * - "range": the maximum value required to reach 100%
108 * @param - "threshold": the mimimum required value to considered pressed 108 * - "threshold": the minimum required value to considered pressed
109 * @param - "offset_x": the amount of offset in the x axis 109 * - "offset_x": the amount of offset in the x axis
110 * @param - "offset_y": the amount of offset in the y axis 110 * - "offset_y": the amount of offset in the y axis
111 * @param - "invert_x": inverts the sign of the horizontal axis 111 * - "invert_x": inverts the sign of the horizontal axis
112 * @param - "invert_y": inverts the sign of the vertical axis 112 * - "invert_y": inverts the sign of the vertical axis
113 * @param - "guid": text string for identifing controllers 113 * - "guid": text string for identifying controllers
114 * @param - "port": port of the connected device 114 * - "port": port of the connected device
115 * @param - "pad": slot of the connected controller 115 * - "pad": slot of the connected controller
116 * @return an unique input device with the parameters specified 116 * @returns a unique input device with the parameters specified
117 */ 117 */
118 std::unique_ptr<Common::Input::InputDevice> CreateStickDevice( 118 std::unique_ptr<Common::Input::InputDevice> CreateStickDevice(
119 const Common::ParamPackage& params); 119 const Common::ParamPackage& params);
@@ -121,16 +121,16 @@ private:
121 /** 121 /**
122 * Creates an analog device from the parameters given. 122 * Creates an analog device from the parameters given.
123 * @param params contains parameters for creating the device: 123 * @param params contains parameters for creating the device:
124 * @param - "axis": the controller axis id to bind with the input 124 * - "axis": the controller axis id to bind with the input
125 * @param - "deadzone": the mimimum required value to be detected 125 * - "deadzone": the minimum required value to be detected
126 * @param - "range": the maximum value required to reach 100% 126 * - "range": the maximum value required to reach 100%
127 * @param - "threshold": the mimimum required value to considered pressed 127 * - "threshold": the minimum required value to considered pressed
128 * @param - "offset": the amount of offset in the axis 128 * - "offset": the amount of offset in the axis
129 * @param - "invert": inverts the sign of the axis 129 * - "invert": inverts the sign of the axis
130 * @param - "guid": text string for identifing controllers 130 * - "guid": text string for identifying controllers
131 * @param - "port": port of the connected device 131 * - "port": port of the connected device
132 * @param - "pad": slot of the connected controller 132 * - "pad": slot of the connected controller
133 * @return an unique input device with the parameters specified 133 * @returns a unique input device with the parameters specified
134 */ 134 */
135 std::unique_ptr<Common::Input::InputDevice> CreateAnalogDevice( 135 std::unique_ptr<Common::Input::InputDevice> CreateAnalogDevice(
136 const Common::ParamPackage& params); 136 const Common::ParamPackage& params);
@@ -138,20 +138,20 @@ private:
138 /** 138 /**
139 * Creates a trigger device from the parameters given. 139 * Creates a trigger device from the parameters given.
140 * @param params contains parameters for creating the device: 140 * @param params contains parameters for creating the device:
141 * @param - "button": the controller hat id to bind with the input 141 * - "button": the controller hat id to bind with the input
142 * @param - "direction": the direction id to be detected 142 * - "direction": the direction id to be detected
143 * @param - "toggle": press once to enable, press again to disable 143 * - "toggle": press once to enable, press again to disable
144 * @param - "inverted": inverts the output of the button 144 * - "inverted": inverts the output of the button
145 * @param - "axis": the controller axis id to bind with the input 145 * - "axis": the controller axis id to bind with the input
146 * @param - "deadzone": the mimimum required value to be detected 146 * - "deadzone": the minimum required value to be detected
147 * @param - "range": the maximum value required to reach 100% 147 * - "range": the maximum value required to reach 100%
148 * @param - "threshold": the mimimum required value to considered pressed 148 * - "threshold": the minimum required value to considered pressed
149 * @param - "offset": the amount of offset in the axis 149 * - "offset": the amount of offset in the axis
150 * @param - "invert": inverts the sign of the axis 150 * - "invert": inverts the sign of the axis
151 * @param - "guid": text string for identifing controllers 151 * - "guid": text string for identifying controllers
152 * @param - "port": port of the connected device 152 * - "port": port of the connected device
153 * @param - "pad": slot of the connected controller 153 * - "pad": slot of the connected controller
154 * @return an unique input device with the parameters specified 154 * @returns a unique input device with the parameters specified
155 */ 155 */
156 std::unique_ptr<Common::Input::InputDevice> CreateTriggerDevice( 156 std::unique_ptr<Common::Input::InputDevice> CreateTriggerDevice(
157 const Common::ParamPackage& params); 157 const Common::ParamPackage& params);
@@ -159,23 +159,23 @@ private:
159 /** 159 /**
160 * Creates a touch device from the parameters given. 160 * Creates a touch device from the parameters given.
161 * @param params contains parameters for creating the device: 161 * @param params contains parameters for creating the device:
162 * @param - "button": the controller hat id to bind with the input 162 * - "button": the controller hat id to bind with the input
163 * @param - "direction": the direction id to be detected 163 * - "direction": the direction id to be detected
164 * @param - "toggle": press once to enable, press again to disable 164 * - "toggle": press once to enable, press again to disable
165 * @param - "inverted": inverts the output of the button 165 * - "inverted": inverts the output of the button
166 * @param - "axis_x": the controller horizontal axis id to bind with the input 166 * - "axis_x": the controller horizontal axis id to bind with the input
167 * @param - "axis_y": the controller vertical axis id to bind with the input 167 * - "axis_y": the controller vertical axis id to bind with the input
168 * @param - "deadzone": the mimimum required value to be detected 168 * - "deadzone": the minimum required value to be detected
169 * @param - "range": the maximum value required to reach 100% 169 * - "range": the maximum value required to reach 100%
170 * @param - "threshold": the mimimum required value to considered pressed 170 * - "threshold": the minimum required value to considered pressed
171 * @param - "offset_x": the amount of offset in the x axis 171 * - "offset_x": the amount of offset in the x axis
172 * @param - "offset_y": the amount of offset in the y axis 172 * - "offset_y": the amount of offset in the y axis
173 * @param - "invert_x": inverts the sign of the horizontal axis 173 * - "invert_x": inverts the sign of the horizontal axis
174 * @param - "invert_y": inverts the sign of the vertical axis 174 * - "invert_y": inverts the sign of the vertical axis
175 * @param - "guid": text string for identifing controllers 175 * - "guid": text string for identifying controllers
176 * @param - "port": port of the connected device 176 * - "port": port of the connected device
177 * @param - "pad": slot of the connected controller 177 * - "pad": slot of the connected controller
178 * @return an unique input device with the parameters specified 178 * @returns a unique input device with the parameters specified
179 */ 179 */
180 std::unique_ptr<Common::Input::InputDevice> CreateTouchDevice( 180 std::unique_ptr<Common::Input::InputDevice> CreateTouchDevice(
181 const Common::ParamPackage& params); 181 const Common::ParamPackage& params);
@@ -183,10 +183,10 @@ private:
183 /** 183 /**
184 * Creates a battery device from the parameters given. 184 * Creates a battery device from the parameters given.
185 * @param params contains parameters for creating the device: 185 * @param params contains parameters for creating the device:
186 * @param - "guid": text string for identifing controllers 186 * - "guid": text string for identifying controllers
187 * @param - "port": port of the connected device 187 * - "port": port of the connected device
188 * @param - "pad": slot of the connected controller 188 * - "pad": slot of the connected controller
189 * @return an unique input device with the parameters specified 189 * @returns a unique input device with the parameters specified
190 */ 190 */
191 std::unique_ptr<Common::Input::InputDevice> CreateBatteryDevice( 191 std::unique_ptr<Common::Input::InputDevice> CreateBatteryDevice(
192 const Common::ParamPackage& params); 192 const Common::ParamPackage& params);
@@ -194,21 +194,21 @@ private:
194 /** 194 /**
195 * Creates a motion device from the parameters given. 195 * Creates a motion device from the parameters given.
196 * @param params contains parameters for creating the device: 196 * @param params contains parameters for creating the device:
197 * @param - "axis_x": the controller horizontal axis id to bind with the input 197 * - "axis_x": the controller horizontal axis id to bind with the input
198 * @param - "axis_y": the controller vertical axis id to bind with the input 198 * - "axis_y": the controller vertical axis id to bind with the input
199 * @param - "axis_z": the controller fordward axis id to bind with the input 199 * - "axis_z": the controller forward axis id to bind with the input
200 * @param - "deadzone": the mimimum required value to be detected 200 * - "deadzone": the minimum required value to be detected
201 * @param - "range": the maximum value required to reach 100% 201 * - "range": the maximum value required to reach 100%
202 * @param - "offset_x": the amount of offset in the x axis 202 * - "offset_x": the amount of offset in the x axis
203 * @param - "offset_y": the amount of offset in the y axis 203 * - "offset_y": the amount of offset in the y axis
204 * @param - "offset_z": the amount of offset in the z axis 204 * - "offset_z": the amount of offset in the z axis
205 * @param - "invert_x": inverts the sign of the horizontal axis 205 * - "invert_x": inverts the sign of the horizontal axis
206 * @param - "invert_y": inverts the sign of the vertical axis 206 * - "invert_y": inverts the sign of the vertical axis
207 * @param - "invert_z": inverts the sign of the fordward axis 207 * - "invert_z": inverts the sign of the forward axis
208 * @param - "guid": text string for identifing controllers 208 * - "guid": text string for identifying controllers
209 * @param - "port": port of the connected device 209 * - "port": port of the connected device
210 * @param - "pad": slot of the connected controller 210 * - "pad": slot of the connected controller
211 * @return an unique input device with the parameters specified 211 * @returns a unique input device with the parameters specified
212 */ 212 */
213 std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params); 213 std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params);
214 214
diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
index e38cfbc6c..751e4792b 100644
--- a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
+++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
@@ -176,8 +176,8 @@ struct FormatTuple {
176 {VK_FORMAT_R32_UINT, Attachable | Storage}, // R32_UINT 176 {VK_FORMAT_R32_UINT, Attachable | Storage}, // R32_UINT
177 {VK_FORMAT_R32_SINT, Attachable | Storage}, // R32_SINT 177 {VK_FORMAT_R32_SINT, Attachable | Storage}, // R32_SINT
178 {VK_FORMAT_ASTC_8x8_UNORM_BLOCK}, // ASTC_2D_8X8_UNORM 178 {VK_FORMAT_ASTC_8x8_UNORM_BLOCK}, // ASTC_2D_8X8_UNORM
179 {VK_FORMAT_UNDEFINED}, // ASTC_2D_8X5_UNORM 179 {VK_FORMAT_ASTC_8x5_UNORM_BLOCK}, // ASTC_2D_8X5_UNORM
180 {VK_FORMAT_UNDEFINED}, // ASTC_2D_5X4_UNORM 180 {VK_FORMAT_ASTC_5x4_UNORM_BLOCK}, // ASTC_2D_5X4_UNORM
181 {VK_FORMAT_B8G8R8A8_SRGB, Attachable}, // B8G8R8A8_SRGB 181 {VK_FORMAT_B8G8R8A8_SRGB, Attachable}, // B8G8R8A8_SRGB
182 {VK_FORMAT_BC1_RGBA_SRGB_BLOCK}, // BC1_RGBA_SRGB 182 {VK_FORMAT_BC1_RGBA_SRGB_BLOCK}, // BC1_RGBA_SRGB
183 {VK_FORMAT_BC2_SRGB_BLOCK}, // BC2_SRGB 183 {VK_FORMAT_BC2_SRGB_BLOCK}, // BC2_SRGB
diff --git a/src/yuzu/applets/qt_software_keyboard.cpp b/src/yuzu/applets/qt_software_keyboard.cpp
index de7f98c4f..c3857fc98 100644
--- a/src/yuzu/applets/qt_software_keyboard.cpp
+++ b/src/yuzu/applets/qt_software_keyboard.cpp
@@ -475,11 +475,26 @@ void QtSoftwareKeyboardDialog::open() {
475 row = 0; 475 row = 0;
476 column = 0; 476 column = 0;
477 477
478 const auto* const curr_button = 478 switch (bottom_osk_index) {
479 keyboard_buttons[static_cast<int>(bottom_osk_index)][row][column]; 479 case BottomOSKIndex::LowerCase:
480 case BottomOSKIndex::UpperCase: {
481 const auto* const curr_button =
482 keyboard_buttons[static_cast<std::size_t>(bottom_osk_index)][row][column];
483
484 // This is a workaround for setFocus() randomly not showing focus in the UI
485 QCursor::setPos(curr_button->mapToGlobal(curr_button->rect().center()));
486 break;
487 }
488 case BottomOSKIndex::NumberPad: {
489 const auto* const curr_button = numberpad_buttons[row][column];
480 490
481 // This is a workaround for setFocus() randomly not showing focus in the UI 491 // This is a workaround for setFocus() randomly not showing focus in the UI
482 QCursor::setPos(curr_button->mapToGlobal(curr_button->rect().center())); 492 QCursor::setPos(curr_button->mapToGlobal(curr_button->rect().center()));
493 break;
494 }
495 default:
496 break;
497 }
483 498
484 StartInputThread(); 499 StartInputThread();
485} 500}