Enable mouse toggle buttons

This commit is contained in:
german77 2021-03-06 13:27:02 -06:00
parent 4bcc5bacff
commit 41e94b7b99
5 changed files with 65 additions and 11 deletions

View file

@ -19,16 +19,18 @@ public:
bool GetStatus() const override {
if (toggle) {
return toggled_status.load();
return toggled_status.load(std::memory_order_relaxed);
}
return status.load();
}
void ToggleButton() {
if (!lock) {
lock = true;
toggled_status.store(!toggled_status.load());
if (lock) {
return;
}
lock = true;
const bool old_toggle_status = toggled_status.load();
toggled_status.store(!old_toggle_status);
}
void UnlockButton() {
@ -41,7 +43,7 @@ private:
std::shared_ptr<KeyButtonList> key_button_list;
std::atomic<bool> status{false};
std::atomic<bool> toggled_status{false};
bool lock = {};
bool lock{false};
const bool toggle;
};