summaryrefslogtreecommitdiff
path: root/src/core/hid/emulated_devices.cpp
diff options
context:
space:
mode:
authorGravatar german772021-10-30 22:23:10 -0500
committerGravatar Narr the Reg2021-11-24 20:30:26 -0600
commit2b1b0c2a30e242b08ec120e09803ec54d5445703 (patch)
tree9a10400a7e4403b288eee3aae8a52f1d5be912de /src/core/hid/emulated_devices.cpp
parentinput_common: Revert deleted TAS functions (diff)
downloadyuzu-2b1b0c2a30e242b08ec120e09803ec54d5445703.tar.gz
yuzu-2b1b0c2a30e242b08ec120e09803ec54d5445703.tar.xz
yuzu-2b1b0c2a30e242b08ec120e09803ec54d5445703.zip
kraken: Address comments from review
start lion review
Diffstat (limited to 'src/core/hid/emulated_devices.cpp')
-rw-r--r--src/core/hid/emulated_devices.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp
index eb59c310c..c76a86b6c 100644
--- a/src/core/hid/emulated_devices.cpp
+++ b/src/core/hid/emulated_devices.cpp
@@ -2,6 +2,7 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included 3// Refer to the license.txt file included
4 4
5#include <algorithm>
5#include <fmt/format.h> 6#include <fmt/format.h>
6 7
7#include "core/hid/emulated_devices.h" 8#include "core/hid/emulated_devices.h"
@@ -25,21 +26,25 @@ void EmulatedDevices::ReloadFromSettings() {
25void EmulatedDevices::ReloadInput() { 26void EmulatedDevices::ReloadInput() {
26 std::transform(mouse_button_params.begin() + Settings::NativeMouseButton::MOUSE_HID_BEGIN, 27 std::transform(mouse_button_params.begin() + Settings::NativeMouseButton::MOUSE_HID_BEGIN,
27 mouse_button_params.begin() + Settings::NativeMouseButton::MOUSE_HID_END, 28 mouse_button_params.begin() + Settings::NativeMouseButton::MOUSE_HID_END,
28 mouse_button_devices.begin(), Input::CreateDevice<Input::InputDevice>); 29 mouse_button_devices.begin(),
30 Common::Input::CreateDevice<Common::Input::InputDevice>);
29 31
30 std::transform(Settings::values.keyboard_keys.begin(), Settings::values.keyboard_keys.end(), 32 std::transform(Settings::values.keyboard_keys.begin(), Settings::values.keyboard_keys.end(),
31 keyboard_devices.begin(), Input::CreateDeviceFromString<Input::InputDevice>); 33 keyboard_devices.begin(),
34 Common::Input::CreateDeviceFromString<Common::Input::InputDevice>);
32 35
33 std::transform(Settings::values.keyboard_mods.begin(), Settings::values.keyboard_mods.end(), 36 std::transform(Settings::values.keyboard_mods.begin(), Settings::values.keyboard_mods.end(),
34 keyboard_modifier_devices.begin(), 37 keyboard_modifier_devices.begin(),
35 Input::CreateDeviceFromString<Input::InputDevice>); 38 Common::Input::CreateDeviceFromString<Common::Input::InputDevice>);
36 39
37 for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { 40 for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) {
38 if (!mouse_button_devices[index]) { 41 if (!mouse_button_devices[index]) {
39 continue; 42 continue;
40 } 43 }
41 Input::InputCallback button_callback{ 44 Common::Input::InputCallback button_callback{
42 [this, index](Input::CallbackStatus callback) { SetMouseButton(callback, index); }}; 45 [this, index](Common::Input::CallbackStatus callback) {
46 SetMouseButton(callback, index);
47 }};
43 mouse_button_devices[index]->SetCallback(button_callback); 48 mouse_button_devices[index]->SetCallback(button_callback);
44 } 49 }
45 50
@@ -47,8 +52,10 @@ void EmulatedDevices::ReloadInput() {
47 if (!keyboard_devices[index]) { 52 if (!keyboard_devices[index]) {
48 continue; 53 continue;
49 } 54 }
50 Input::InputCallback button_callback{ 55 Common::Input::InputCallback button_callback{
51 [this, index](Input::CallbackStatus callback) { SetKeyboardButton(callback, index); }}; 56 [this, index](Common::Input::CallbackStatus callback) {
57 SetKeyboardButton(callback, index);
58 }};
52 keyboard_devices[index]->SetCallback(button_callback); 59 keyboard_devices[index]->SetCallback(button_callback);
53 } 60 }
54 61
@@ -56,9 +63,10 @@ void EmulatedDevices::ReloadInput() {
56 if (!keyboard_modifier_devices[index]) { 63 if (!keyboard_modifier_devices[index]) {
57 continue; 64 continue;
58 } 65 }
59 Input::InputCallback button_callback{[this, index](Input::CallbackStatus callback) { 66 Common::Input::InputCallback button_callback{
60 SetKeyboardModifier(callback, index); 67 [this, index](Common::Input::CallbackStatus callback) {
61 }}; 68 SetKeyboardModifier(callback, index);
69 }};
62 keyboard_modifier_devices[index]->SetCallback(button_callback); 70 keyboard_modifier_devices[index]->SetCallback(button_callback);
63 } 71 }
64} 72}
@@ -122,7 +130,7 @@ void EmulatedDevices::SetMouseButtonParam(std::size_t index, Common::ParamPackag
122 ReloadInput(); 130 ReloadInput();
123} 131}
124 132
125void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::size_t index) { 133void EmulatedDevices::SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index) {
126 if (index >= device_status.keyboard_values.size()) { 134 if (index >= device_status.keyboard_values.size()) {
127 return; 135 return;
128 } 136 }
@@ -170,7 +178,7 @@ void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::siz
170void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) { 178void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) {
171 constexpr u8 KEYS_PER_BYTE = 8; 179 constexpr u8 KEYS_PER_BYTE = 8;
172 auto& entry = device_status.keyboard_state.key[key_index / KEYS_PER_BYTE]; 180 auto& entry = device_status.keyboard_state.key[key_index / KEYS_PER_BYTE];
173 const u8 mask = 1 << (key_index % KEYS_PER_BYTE); 181 const u8 mask = static_cast<u8>(1 << (key_index % KEYS_PER_BYTE));
174 if (status) { 182 if (status) {
175 entry = entry | mask; 183 entry = entry | mask;
176 } else { 184 } else {
@@ -178,7 +186,8 @@ void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) {
178 } 186 }
179} 187}
180 188
181void EmulatedDevices::SetKeyboardModifier(Input::CallbackStatus callback, std::size_t index) { 189void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback,
190 std::size_t index) {
182 if (index >= device_status.keyboard_moddifier_values.size()) { 191 if (index >= device_status.keyboard_moddifier_values.size()) {
183 return; 192 return;
184 } 193 }
@@ -247,7 +256,7 @@ void EmulatedDevices::SetKeyboardModifier(Input::CallbackStatus callback, std::s
247 TriggerOnChange(DeviceTriggerType::KeyboardModdifier); 256 TriggerOnChange(DeviceTriggerType::KeyboardModdifier);
248} 257}
249 258
250void EmulatedDevices::SetMouseButton(Input::CallbackStatus callback, std::size_t index) { 259void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index) {
251 if (index >= device_status.mouse_button_values.size()) { 260 if (index >= device_status.mouse_button_values.size()) {
252 return; 261 return;
253 } 262 }