diff options
| author | 2021-03-05 19:21:04 -0600 | |
|---|---|---|
| committer | 2021-03-05 19:21:04 -0600 | |
| commit | 1f228c51ca2c510622f4204937f90c7f2bbc7bf6 (patch) | |
| tree | bb29a416ef52d308c38adb16b4ee7d0fe55fe391 /src/input_common/keyboard.cpp | |
| 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
Diffstat (limited to 'src/input_common/keyboard.cpp')
| -rw-r--r-- | src/input_common/keyboard.cpp | 29 |
1 files changed, 26 insertions, 3 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 | } |