diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2023-05-13 05:10:39 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-15 12:15:39 +0200 |
commit | c87c4f6d9456ae142359ef98b8768055d5de8306 (patch) | |
tree | 032d63b10fe19e939e2dba66e810cbe35fe91875 /Userland | |
parent | 7323a54e59ccb23e82d9629c123f88d717bfe460 (diff) | |
download | serenity-c87c4f6d9456ae142359ef98b8768055d5de8306.zip |
LibGUI: Put a governor on Action activation
Many actions affect Window modality, so let's put a temporary change
governor on activation to stop race conditions.
Fixes being able to spam open/close shortcuts and spawn multiple
FilePickers, among other things.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/Action.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Action.h | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/Action.cpp b/Userland/Libraries/LibGUI/Action.cpp index e55dddc1cf..07de87bccb 100644 --- a/Userland/Libraries/LibGUI/Action.cpp +++ b/Userland/Libraries/LibGUI/Action.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/TemporaryChange.h> #include <LibGUI/Action.h> #include <LibGUI/ActionGroup.h> #include <LibGUI/Application.h> @@ -132,7 +133,7 @@ Action::~Action() void Action::process_event(Window& window, Event& event) { - if (is_enabled() && is_visible()) { + if (is_enabled() && is_visible() && !is_activating()) { flash_menubar_menu(window); activate(); event.accept(); @@ -148,6 +149,10 @@ void Action::process_event(Window& window, Event& event) void Action::activate(Core::Object* activator) { + if (is_activating()) + return; + TemporaryChange change { m_activating, true }; + if (!on_activation) return; diff --git a/Userland/Libraries/LibGUI/Action.h b/Userland/Libraries/LibGUI/Action.h index f876f0371f..a61c765d05 100644 --- a/Userland/Libraries/LibGUI/Action.h +++ b/Userland/Libraries/LibGUI/Action.h @@ -121,6 +121,8 @@ public: } void set_checked(bool); + bool is_activating() const { return m_activating; } + bool swallow_key_event_when_disabled() const { return m_swallow_key_event_when_disabled; } void set_swallow_key_event_when_disabled(bool swallow) { m_swallow_key_event_when_disabled = swallow; } @@ -157,6 +159,7 @@ private: bool m_checkable { false }; bool m_checked { false }; bool m_swallow_key_event_when_disabled { false }; + bool m_activating { false }; ShortcutScope m_scope { ShortcutScope::None }; HashTable<Button*> m_buttons; |