diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/settings.h | 2 | ||||
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 28 | ||||
| -rw-r--r-- | src/input_common/drivers/keyboard.cpp | 52 | ||||
| -rw-r--r-- | src/input_common/drivers/keyboard.h | 14 | ||||
| -rw-r--r-- | src/input_common/input_mapping.cpp | 25 | ||||
| -rw-r--r-- | src/input_common/input_mapping.h | 7 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 9 | ||||
| -rw-r--r-- | src/input_common/main.h | 3 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 14 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 9 |
10 files changed, 115 insertions, 48 deletions
diff --git a/src/common/settings.h b/src/common/settings.h index b52d0d1d0..ee9e0b5a1 100644 --- a/src/common/settings.h +++ b/src/common/settings.h | |||
| @@ -572,8 +572,6 @@ struct Values { | |||
| 572 | 572 | ||
| 573 | BasicSetting<bool> emulate_analog_keyboard{false, "emulate_analog_keyboard"}; | 573 | BasicSetting<bool> emulate_analog_keyboard{false, "emulate_analog_keyboard"}; |
| 574 | BasicSetting<bool> keyboard_enabled{false, "keyboard_enabled"}; | 574 | BasicSetting<bool> keyboard_enabled{false, "keyboard_enabled"}; |
| 575 | KeyboardKeysRaw keyboard_keys; | ||
| 576 | KeyboardModsRaw keyboard_mods; | ||
| 577 | 575 | ||
| 578 | BasicSetting<bool> debug_pad_enabled{false, "debug_pad_enabled"}; | 576 | BasicSetting<bool> debug_pad_enabled{false, "debug_pad_enabled"}; |
| 579 | ButtonsRaw debug_pad_buttons; | 577 | ButtonsRaw debug_pad_buttons; |
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index 0d840a003..45e0bd80d 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp | |||
| @@ -29,13 +29,29 @@ void EmulatedDevices::ReloadInput() { | |||
| 29 | mouse_button_devices.begin(), | 29 | mouse_button_devices.begin(), |
| 30 | Common::Input::CreateDevice<Common::Input::InputDevice>); | 30 | Common::Input::CreateDevice<Common::Input::InputDevice>); |
| 31 | 31 | ||
| 32 | std::transform(Settings::values.keyboard_keys.begin(), Settings::values.keyboard_keys.end(), | 32 | std::size_t key_index = 0; |
| 33 | keyboard_devices.begin(), | 33 | for (auto& keyboard_device : keyboard_devices) { |
| 34 | Common::Input::CreateDeviceFromString<Common::Input::InputDevice>); | 34 | // Keyboard keys are only mapped on port 1, pad 0 |
| 35 | Common::ParamPackage keyboard_params; | ||
| 36 | keyboard_params.Set("engine", "keyboard"); | ||
| 37 | keyboard_params.Set("button", static_cast<int>(key_index)); | ||
| 38 | keyboard_params.Set("port", 1); | ||
| 39 | keyboard_params.Set("pad", 0); | ||
| 40 | keyboard_device = Common::Input::CreateDevice<Common::Input::InputDevice>(keyboard_params); | ||
| 41 | key_index++; | ||
| 42 | } | ||
| 35 | 43 | ||
| 36 | std::transform(Settings::values.keyboard_mods.begin(), Settings::values.keyboard_mods.end(), | 44 | key_index = 0; |
| 37 | keyboard_modifier_devices.begin(), | 45 | for (auto& keyboard_device : keyboard_modifier_devices) { |
| 38 | Common::Input::CreateDeviceFromString<Common::Input::InputDevice>); | 46 | // Keyboard moddifiers are only mapped on port 1, pad 1 |
| 47 | Common::ParamPackage keyboard_params; | ||
| 48 | keyboard_params.Set("engine", "keyboard"); | ||
| 49 | keyboard_params.Set("button", static_cast<int>(key_index)); | ||
| 50 | keyboard_params.Set("port", 1); | ||
| 51 | keyboard_params.Set("pad", 1); | ||
| 52 | keyboard_device = Common::Input::CreateDevice<Common::Input::InputDevice>(keyboard_params); | ||
| 53 | key_index++; | ||
| 54 | } | ||
| 39 | 55 | ||
| 40 | for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { | 56 | for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { |
| 41 | if (!mouse_button_devices[index]) { | 57 | if (!mouse_button_devices[index]) { |
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp index 328fe1ac1..23b0c0ccf 100644 --- a/src/input_common/drivers/keyboard.cpp +++ b/src/input_common/drivers/keyboard.cpp | |||
| @@ -13,15 +13,26 @@ constexpr PadIdentifier key_identifier = { | |||
| 13 | .port = 0, | 13 | .port = 0, |
| 14 | .pad = 0, | 14 | .pad = 0, |
| 15 | }; | 15 | }; |
| 16 | constexpr PadIdentifier modifier_identifier = { | 16 | constexpr PadIdentifier keyboard_key_identifier = { |
| 17 | .guid = Common::UUID{Common::INVALID_UUID}, | 17 | .guid = Common::UUID{Common::INVALID_UUID}, |
| 18 | .port = 0, | 18 | .port = 1, |
| 19 | .pad = 0, | ||
| 20 | }; | ||
| 21 | constexpr PadIdentifier keyboard_modifier_identifier = { | ||
| 22 | .guid = Common::UUID{Common::INVALID_UUID}, | ||
| 23 | .port = 1, | ||
| 19 | .pad = 1, | 24 | .pad = 1, |
| 20 | }; | 25 | }; |
| 21 | 26 | ||
| 22 | Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { | 27 | Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { |
| 28 | // Keyboard is broken into 3 diferent sets: | ||
| 29 | // key: Unfiltered intended for controllers. | ||
| 30 | // keyboard_key: Allows only Settings::NativeKeyboard::Keys intended for keyboard emulation. | ||
| 31 | // keyboard_modifier: Allows only Settings::NativeKeyboard::Modifiers intended for keyboard | ||
| 32 | // emulation. | ||
| 23 | PreSetController(key_identifier); | 33 | PreSetController(key_identifier); |
| 24 | PreSetController(modifier_identifier); | 34 | PreSetController(keyboard_key_identifier); |
| 35 | PreSetController(keyboard_modifier_identifier); | ||
| 25 | } | 36 | } |
| 26 | 37 | ||
| 27 | void Keyboard::PressKey(int key_code) { | 38 | void Keyboard::PressKey(int key_code) { |
| @@ -32,35 +43,50 @@ void Keyboard::ReleaseKey(int key_code) { | |||
| 32 | SetButton(key_identifier, key_code, false); | 43 | SetButton(key_identifier, key_code, false); |
| 33 | } | 44 | } |
| 34 | 45 | ||
| 35 | void Keyboard::SetModifiers(int key_modifiers) { | 46 | void Keyboard::PressKeyboardKey(int key_index) { |
| 47 | if (key_index == Settings::NativeKeyboard::None) { | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | SetButton(keyboard_key_identifier, key_index, true); | ||
| 51 | } | ||
| 52 | |||
| 53 | void Keyboard::ReleaseKeyboardKey(int key_index) { | ||
| 54 | if (key_index == Settings::NativeKeyboard::None) { | ||
| 55 | return; | ||
| 56 | } | ||
| 57 | SetButton(keyboard_key_identifier, key_index, false); | ||
| 58 | } | ||
| 59 | |||
| 60 | void Keyboard::SetKeyboardModifiers(int key_modifiers) { | ||
| 36 | for (int i = 0; i < 32; ++i) { | 61 | for (int i = 0; i < 32; ++i) { |
| 37 | bool key_value = ((key_modifiers >> i) & 0x1) != 0; | 62 | bool key_value = ((key_modifiers >> i) & 0x1) != 0; |
| 38 | SetButton(modifier_identifier, i, key_value); | 63 | SetButton(keyboard_modifier_identifier, i, key_value); |
| 39 | // Use the modifier to press the key button equivalent | 64 | // Use the modifier to press the key button equivalent |
| 40 | switch (i) { | 65 | switch (i) { |
| 41 | case Settings::NativeKeyboard::LeftControl: | 66 | case Settings::NativeKeyboard::LeftControl: |
| 42 | SetButton(key_identifier, Settings::NativeKeyboard::LeftControlKey, key_value); | 67 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftControlKey, key_value); |
| 43 | break; | 68 | break; |
| 44 | case Settings::NativeKeyboard::LeftShift: | 69 | case Settings::NativeKeyboard::LeftShift: |
| 45 | SetButton(key_identifier, Settings::NativeKeyboard::LeftShiftKey, key_value); | 70 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftShiftKey, key_value); |
| 46 | break; | 71 | break; |
| 47 | case Settings::NativeKeyboard::LeftAlt: | 72 | case Settings::NativeKeyboard::LeftAlt: |
| 48 | SetButton(key_identifier, Settings::NativeKeyboard::LeftAltKey, key_value); | 73 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftAltKey, key_value); |
| 49 | break; | 74 | break; |
| 50 | case Settings::NativeKeyboard::LeftMeta: | 75 | case Settings::NativeKeyboard::LeftMeta: |
| 51 | SetButton(key_identifier, Settings::NativeKeyboard::LeftMetaKey, key_value); | 76 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftMetaKey, key_value); |
| 52 | break; | 77 | break; |
| 53 | case Settings::NativeKeyboard::RightControl: | 78 | case Settings::NativeKeyboard::RightControl: |
| 54 | SetButton(key_identifier, Settings::NativeKeyboard::RightControlKey, key_value); | 79 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightControlKey, |
| 80 | key_value); | ||
| 55 | break; | 81 | break; |
| 56 | case Settings::NativeKeyboard::RightShift: | 82 | case Settings::NativeKeyboard::RightShift: |
| 57 | SetButton(key_identifier, Settings::NativeKeyboard::RightShiftKey, key_value); | 83 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightShiftKey, key_value); |
| 58 | break; | 84 | break; |
| 59 | case Settings::NativeKeyboard::RightAlt: | 85 | case Settings::NativeKeyboard::RightAlt: |
| 60 | SetButton(key_identifier, Settings::NativeKeyboard::RightAltKey, key_value); | 86 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightAltKey, key_value); |
| 61 | break; | 87 | break; |
| 62 | case Settings::NativeKeyboard::RightMeta: | 88 | case Settings::NativeKeyboard::RightMeta: |
| 63 | SetButton(key_identifier, Settings::NativeKeyboard::RightMetaKey, key_value); | 89 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightMetaKey, key_value); |
| 64 | break; | 90 | break; |
| 65 | default: | 91 | default: |
| 66 | // Other modifier keys should be pressed with PressKey since they stay enabled until | 92 | // Other modifier keys should be pressed with PressKey since they stay enabled until |
diff --git a/src/input_common/drivers/keyboard.h b/src/input_common/drivers/keyboard.h index 2ab92fd6c..ad123b136 100644 --- a/src/input_common/drivers/keyboard.h +++ b/src/input_common/drivers/keyboard.h | |||
| @@ -29,10 +29,22 @@ public: | |||
| 29 | void ReleaseKey(int key_code); | 29 | void ReleaseKey(int key_code); |
| 30 | 30 | ||
| 31 | /** | 31 | /** |
| 32 | * Sets the status of the keyboard key to pressed | ||
| 33 | * @param key_index index of the key to press | ||
| 34 | */ | ||
| 35 | void PressKeyboardKey(int key_index); | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Sets the status of the keyboard key to released | ||
| 39 | * @param key_index index of the key to release | ||
| 40 | */ | ||
| 41 | void ReleaseKeyboardKey(int key_index); | ||
| 42 | |||
| 43 | /** | ||
| 32 | * Sets the status of all keyboard modifier keys | 44 | * Sets the status of all keyboard modifier keys |
| 33 | * @param key_modifiers the code of the key to release | 45 | * @param key_modifiers the code of the key to release |
| 34 | */ | 46 | */ |
| 35 | void SetModifiers(int key_modifiers); | 47 | void SetKeyboardModifiers(int key_modifiers); |
| 36 | 48 | ||
| 37 | /// Sets all keys to the non pressed state | 49 | /// Sets all keys to the non pressed state |
| 38 | void ReleaseAllKeys(); | 50 | void ReleaseAllKeys(); |
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index 0ffc71028..0eeeff372 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp | |||
| @@ -28,6 +28,10 @@ void MappingFactory::RegisterInput(const MappingData& data) { | |||
| 28 | if (!is_enabled) { | 28 | if (!is_enabled) { |
| 29 | return; | 29 | return; |
| 30 | } | 30 | } |
| 31 | if (!IsDriverValid(data)) { | ||
| 32 | return; | ||
| 33 | } | ||
| 34 | |||
| 31 | switch (input_type) { | 35 | switch (input_type) { |
| 32 | case Polling::InputType::Button: | 36 | case Polling::InputType::Button: |
| 33 | RegisterButton(data); | 37 | RegisterButton(data); |
| @@ -168,4 +172,25 @@ void MappingFactory::RegisterMotion(const MappingData& data) { | |||
| 168 | input_queue.Push(new_input); | 172 | input_queue.Push(new_input); |
| 169 | } | 173 | } |
| 170 | 174 | ||
| 175 | bool MappingFactory::IsDriverValid(const MappingData& data) const { | ||
| 176 | // Only port 0 can be mapped on the keyboard | ||
| 177 | if (data.engine == "keyboard" && data.pad.port != 0) { | ||
| 178 | return false; | ||
| 179 | } | ||
| 180 | // The following drivers don't need to be mapped | ||
| 181 | if (data.engine == "tas") { | ||
| 182 | return false; | ||
| 183 | } | ||
| 184 | if (data.engine == "touch") { | ||
| 185 | return false; | ||
| 186 | } | ||
| 187 | if (data.engine == "touch_from_button") { | ||
| 188 | return false; | ||
| 189 | } | ||
| 190 | if (data.engine == "analog_from_button") { | ||
| 191 | return false; | ||
| 192 | } | ||
| 193 | return true; | ||
| 194 | } | ||
| 195 | |||
| 171 | } // namespace InputCommon | 196 | } // namespace InputCommon |
diff --git a/src/input_common/input_mapping.h b/src/input_common/input_mapping.h index 2622dba70..44eb8ad9a 100644 --- a/src/input_common/input_mapping.h +++ b/src/input_common/input_mapping.h | |||
| @@ -66,6 +66,13 @@ private: | |||
| 66 | */ | 66 | */ |
| 67 | void RegisterMotion(const MappingData& data); | 67 | void RegisterMotion(const MappingData& data); |
| 68 | 68 | ||
| 69 | /** | ||
| 70 | * Returns true if driver can be mapped | ||
| 71 | * @param "data": An struct containing all the information needed to create a proper | ||
| 72 | * ParamPackage | ||
| 73 | */ | ||
| 74 | bool IsDriverValid(const MappingData& data) const; | ||
| 75 | |||
| 69 | Common::SPSCQueue<Common::ParamPackage> input_queue; | 76 | Common::SPSCQueue<Common::ParamPackage> input_queue; |
| 70 | Polling::InputType input_type{Polling::InputType::None}; | 77 | Polling::InputType input_type{Polling::InputType::None}; |
| 71 | bool is_enabled{}; | 78 | bool is_enabled{}; |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index ae2518f53..df36a337c 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -402,15 +402,6 @@ std::string GenerateKeyboardParam(int key_code) { | |||
| 402 | return param.Serialize(); | 402 | return param.Serialize(); |
| 403 | } | 403 | } |
| 404 | 404 | ||
| 405 | std::string GenerateModdifierKeyboardParam(int key_code) { | ||
| 406 | Common::ParamPackage param; | ||
| 407 | param.Set("engine", "keyboard"); | ||
| 408 | param.Set("code", key_code); | ||
| 409 | param.Set("toggle", false); | ||
| 410 | param.Set("pad", 1); | ||
| 411 | return param.Serialize(); | ||
| 412 | } | ||
| 413 | |||
| 414 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | 405 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, |
| 415 | int key_modifier, float modifier_scale) { | 406 | int key_modifier, float modifier_scale) { |
| 416 | Common::ParamPackage circle_pad_param{ | 407 | Common::ParamPackage circle_pad_param{ |
diff --git a/src/input_common/main.h b/src/input_common/main.h index 9ea395465..a4a24d076 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -134,9 +134,6 @@ private: | |||
| 134 | /// Generates a serialized param package for creating a keyboard button device. | 134 | /// Generates a serialized param package for creating a keyboard button device. |
| 135 | std::string GenerateKeyboardParam(int key_code); | 135 | std::string GenerateKeyboardParam(int key_code); |
| 136 | 136 | ||
| 137 | /// Generates a serialized param package for creating a moddifier keyboard button device. | ||
| 138 | std::string GenerateModdifierKeyboardParam(int key_code); | ||
| 139 | |||
| 140 | /// Generates a serialized param package for creating an analog device taking input from keyboard. | 137 | /// Generates a serialized param package for creating an analog device taking input from keyboard. |
| 141 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | 138 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, |
| 142 | int key_modifier, float modifier_scale); | 139 | int key_modifier, float modifier_scale); |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 61513a5b4..9f4d1aac3 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -609,7 +609,7 @@ int GRenderWindow::QtKeyToSwitchKey(Qt::Key qt_key) { | |||
| 609 | return Settings::NativeKeyboard::ZenkakuHankaku; | 609 | return Settings::NativeKeyboard::ZenkakuHankaku; |
| 610 | // Modifier keys are handled by the modifier property | 610 | // Modifier keys are handled by the modifier property |
| 611 | default: | 611 | default: |
| 612 | return 0; | 612 | return Settings::NativeKeyboard::None; |
| 613 | } | 613 | } |
| 614 | } | 614 | } |
| 615 | 615 | ||
| @@ -662,8 +662,10 @@ void GRenderWindow::keyPressEvent(QKeyEvent* event) { | |||
| 662 | // Replace event->key() with event->nativeVirtualKey() since the second one provides raw key | 662 | // Replace event->key() with event->nativeVirtualKey() since the second one provides raw key |
| 663 | // buttons | 663 | // buttons |
| 664 | const auto key = QtKeyToSwitchKey(Qt::Key(event->key())); | 664 | const auto key = QtKeyToSwitchKey(Qt::Key(event->key())); |
| 665 | input_subsystem->GetKeyboard()->SetModifiers(moddifier); | 665 | input_subsystem->GetKeyboard()->SetKeyboardModifiers(moddifier); |
| 666 | input_subsystem->GetKeyboard()->PressKey(key); | 666 | input_subsystem->GetKeyboard()->PressKeyboardKey(key); |
| 667 | // This is used for gamepads | ||
| 668 | input_subsystem->GetKeyboard()->PressKey(event->key()); | ||
| 667 | } | 669 | } |
| 668 | } | 670 | } |
| 669 | 671 | ||
| @@ -671,8 +673,10 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { | |||
| 671 | if (!event->isAutoRepeat()) { | 673 | if (!event->isAutoRepeat()) { |
| 672 | const auto moddifier = QtModifierToSwitchModdifier(event->nativeModifiers()); | 674 | const auto moddifier = QtModifierToSwitchModdifier(event->nativeModifiers()); |
| 673 | const auto key = QtKeyToSwitchKey(Qt::Key(event->key())); | 675 | const auto key = QtKeyToSwitchKey(Qt::Key(event->key())); |
| 674 | input_subsystem->GetKeyboard()->SetModifiers(moddifier); | 676 | input_subsystem->GetKeyboard()->SetKeyboardModifiers(moddifier); |
| 675 | input_subsystem->GetKeyboard()->ReleaseKey(key); | 677 | input_subsystem->GetKeyboard()->ReleaseKeyboardKey(key); |
| 678 | // This is used for gamepads | ||
| 679 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); | ||
| 676 | } | 680 | } |
| 677 | } | 681 | } |
| 678 | 682 | ||
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index ccf274895..5865359fe 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -344,15 +344,6 @@ void Config::ReadDebugValues() { | |||
| 344 | 344 | ||
| 345 | void Config::ReadKeyboardValues() { | 345 | void Config::ReadKeyboardValues() { |
| 346 | ReadBasicSetting(Settings::values.keyboard_enabled); | 346 | ReadBasicSetting(Settings::values.keyboard_enabled); |
| 347 | |||
| 348 | for (std::size_t i = 0; i < Settings::values.keyboard_keys.size(); ++i) { | ||
| 349 | Settings::values.keyboard_keys[i] = InputCommon::GenerateKeyboardParam(static_cast<int>(i)); | ||
| 350 | } | ||
| 351 | |||
| 352 | for (std::size_t i = 0; i < Settings::values.keyboard_mods.size(); ++i) { | ||
| 353 | Settings::values.keyboard_mods[i] = | ||
| 354 | InputCommon::GenerateModdifierKeyboardParam(static_cast<int>(i)); | ||
| 355 | } | ||
| 356 | } | 347 | } |
| 357 | 348 | ||
| 358 | void Config::ReadMouseValues() { | 349 | void Config::ReadMouseValues() { |