diff options
| author | 2021-03-05 19:21:04 -0600 | |
|---|---|---|
| committer | 2021-03-05 19:21:04 -0600 | |
| commit | 1f228c51ca2c510622f4204937f90c7f2bbc7bf6 (patch) | |
| tree | bb29a416ef52d308c38adb16b4ee7d0fe55fe391 | |
| parent | Merge pull request #6034 from Morph1984/mbedtls (diff) | |
| download | yuzu-1f228c51ca2c510622f4204937f90c7f2bbc7bf6.tar.gz yuzu-1f228c51ca2c510622f4204937f90c7f2bbc7bf6.tar.xz yuzu-1f228c51ca2c510622f4204937f90c7f2bbc7bf6.zip | |
Enable button toggle for keyboard in the modifier button
| -rw-r--r-- | src/input_common/keyboard.cpp | 29 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 8 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 13 |
3 files changed, 44 insertions, 6 deletions
diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp index 24a6f7a33..fa0e60ac1 100644 --- a/src/input_common/keyboard.cpp +++ b/src/input_common/keyboard.cpp | |||
| @@ -12,20 +12,37 @@ namespace InputCommon { | |||
| 12 | 12 | ||
| 13 | class KeyButton final : public Input::ButtonDevice { | 13 | class KeyButton final : public Input::ButtonDevice { |
| 14 | public: | 14 | public: |
| 15 | explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_) | 15 | explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_, bool toggle_) |
| 16 | : key_button_list(std::move(key_button_list_)) {} | 16 | : key_button_list(std::move(key_button_list_)), toggle(toggle_) {} |
| 17 | 17 | ||
| 18 | ~KeyButton() override; | 18 | ~KeyButton() override; |
| 19 | 19 | ||
| 20 | bool GetStatus() const override { | 20 | bool GetStatus() const override { |
| 21 | if (toggle) { | ||
| 22 | return toggled_status.load(); | ||
| 23 | } | ||
| 21 | return status.load(); | 24 | return status.load(); |
| 22 | } | 25 | } |
| 23 | 26 | ||
| 27 | void ToggleButton() { | ||
| 28 | if (!lock) { | ||
| 29 | lock = true; | ||
| 30 | toggled_status.store(!toggled_status.load()); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | void UnlockButton() { | ||
| 35 | lock = false; | ||
| 36 | } | ||
| 37 | |||
| 24 | friend class KeyButtonList; | 38 | friend class KeyButtonList; |
| 25 | 39 | ||
| 26 | private: | 40 | private: |
| 27 | std::shared_ptr<KeyButtonList> key_button_list; | 41 | std::shared_ptr<KeyButtonList> key_button_list; |
| 28 | std::atomic<bool> status{false}; | 42 | std::atomic<bool> status{false}; |
| 43 | std::atomic<bool> toggled_status{false}; | ||
| 44 | bool lock = {}; | ||
| 45 | const bool toggle; | ||
| 29 | }; | 46 | }; |
| 30 | 47 | ||
| 31 | struct KeyButtonPair { | 48 | struct KeyButtonPair { |
| @@ -51,6 +68,11 @@ public: | |||
| 51 | for (const KeyButtonPair& pair : list) { | 68 | for (const KeyButtonPair& pair : list) { |
| 52 | if (pair.key_code == key_code) { | 69 | if (pair.key_code == key_code) { |
| 53 | pair.key_button->status.store(pressed); | 70 | pair.key_button->status.store(pressed); |
| 71 | if (pressed) { | ||
| 72 | pair.key_button->ToggleButton(); | ||
| 73 | } else { | ||
| 74 | pair.key_button->UnlockButton(); | ||
| 75 | } | ||
| 54 | } | 76 | } |
| 55 | } | 77 | } |
| 56 | } | 78 | } |
| @@ -75,7 +97,8 @@ KeyButton::~KeyButton() { | |||
| 75 | 97 | ||
| 76 | std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { | 98 | std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { |
| 77 | const int key_code = params.Get("code", 0); | 99 | const int key_code = params.Get("code", 0); |
| 78 | std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list); | 100 | const bool toggle = params.Get("toggle", false); |
| 101 | std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list, toggle); | ||
| 79 | key_button_list->AddKeyButton(key_code, button.get()); | 102 | key_button_list->AddKeyButton(key_code, button.get()); |
| 80 | return button; | 103 | return button; |
| 81 | } | 104 | } |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 1c61d419d..50938fb04 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -376,11 +376,15 @@ void GRenderWindow::closeEvent(QCloseEvent* event) { | |||
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | void GRenderWindow::keyPressEvent(QKeyEvent* event) { | 378 | void GRenderWindow::keyPressEvent(QKeyEvent* event) { |
| 379 | input_subsystem->GetKeyboard()->PressKey(event->key()); | 379 | if (!event->isAutoRepeat()) { |
| 380 | input_subsystem->GetKeyboard()->PressKey(event->key()); | ||
| 381 | } | ||
| 380 | } | 382 | } |
| 381 | 383 | ||
| 382 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { | 384 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { |
| 383 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); | 385 | if (!event->isAutoRepeat()) { |
| 386 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); | ||
| 387 | } | ||
| 384 | } | 388 | } |
| 385 | 389 | ||
| 386 | void GRenderWindow::mousePressEvent(QMouseEvent* event) { | 390 | void GRenderWindow::mousePressEvent(QMouseEvent* event) { |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 21d0d3449..e297eeffd 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -104,7 +104,9 @@ QString ButtonToText(const Common::ParamPackage& param) { | |||
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | if (param.Get("engine", "") == "keyboard") { | 106 | if (param.Get("engine", "") == "keyboard") { |
| 107 | return GetKeyName(param.Get("code", 0)); | 107 | const QString button_str = GetKeyName(param.Get("code", 0)); |
| 108 | const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : ""); | ||
| 109 | return QObject::tr("%1%2").arg(toggle, button_str); | ||
| 108 | } | 110 | } |
| 109 | 111 | ||
| 110 | if (param.Get("engine", "") == "gcpad") { | 112 | if (param.Get("engine", "") == "gcpad") { |
| @@ -412,6 +414,15 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 412 | analogs_param[analog_id].Set("modifier", ""); | 414 | analogs_param[analog_id].Set("modifier", ""); |
| 413 | analog_map_modifier_button[analog_id]->setText(tr("[not set]")); | 415 | analog_map_modifier_button[analog_id]->setText(tr("[not set]")); |
| 414 | }); | 416 | }); |
| 417 | context_menu.addAction(tr("Toggle button"), [&] { | ||
| 418 | Common::ParamPackage modifier_param = | ||
| 419 | Common::ParamPackage{analogs_param[analog_id].Get("modifier", "")}; | ||
| 420 | const bool toggle_value = !modifier_param.Get("toggle", false); | ||
| 421 | modifier_param.Set("toggle", toggle_value); | ||
| 422 | analogs_param[analog_id].Set("modifier", modifier_param.Serialize()); | ||
| 423 | analog_map_modifier_button[analog_id]->setText( | ||
| 424 | ButtonToText(modifier_param)); | ||
| 425 | }); | ||
| 415 | context_menu.exec( | 426 | context_menu.exec( |
| 416 | analog_map_modifier_button[analog_id]->mapToGlobal(menu_location)); | 427 | analog_map_modifier_button[analog_id]->mapToGlobal(menu_location)); |
| 417 | }); | 428 | }); |