summaryrefslogtreecommitdiff
path: root/src/input_common/keyboard.cpp
diff options
context:
space:
mode:
authorGravatar german2021-03-05 19:21:04 -0600
committerGravatar german2021-03-05 19:21:04 -0600
commit1f228c51ca2c510622f4204937f90c7f2bbc7bf6 (patch)
treebb29a416ef52d308c38adb16b4ee7d0fe55fe391 /src/input_common/keyboard.cpp
parentMerge pull request #6034 from Morph1984/mbedtls (diff)
downloadyuzu-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.cpp29
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
13class KeyButton final : public Input::ButtonDevice { 13class KeyButton final : public Input::ButtonDevice {
14public: 14public:
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
26private: 40private:
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
31struct KeyButtonPair { 48struct 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
76std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { 98std::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}