summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorRob Ryan <rob@affclicks.com>2022-04-03 15:50:32 +1000
committerAndreas Kling <kling@serenityos.org>2022-04-03 12:21:50 +0200
commit554709fec6d4e3dedc858b49b193d68df228c016 (patch)
treec5a91bda2e5a5ee22da074e33cc99ccaa47f42f4 /Userland/Libraries/LibGUI
parent7af87e8e6ba5fee7fe486cf97f9a5e8d40b3d483 (diff)
downloadserenity-554709fec6d4e3dedc858b49b193d68df228c016.zip
LibGUI: Extend mimic pressed across keyboard shortcuts for buttons
Primary motivation for this was to get a visual indication in the browser for Ctrl-R refresh. This extends what ForLoveOfCats had done for calculator button shortcuts across all buttons with shortcuts. When an action is triggered without an activator each associated button will be set as mimic pressed.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/Action.cpp6
-rw-r--r--Userland/Libraries/LibGUI/Button.cpp19
-rw-r--r--Userland/Libraries/LibGUI/Button.h2
3 files changed, 25 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/Action.cpp b/Userland/Libraries/LibGUI/Action.cpp
index 4eceaa6fbd..29c9b9b199 100644
--- a/Userland/Libraries/LibGUI/Action.cpp
+++ b/Userland/Libraries/LibGUI/Action.cpp
@@ -131,6 +131,12 @@ void Action::activate(Core::Object* activator)
}
}
+ if (activator == nullptr) {
+ for_each_toolbar_button([](auto& button) {
+ button.set_mimic_pressed(true);
+ });
+ }
+
on_activation(*this);
m_activator = nullptr;
}
diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp
index e75b041364..15759fa697 100644
--- a/Userland/Libraries/LibGUI/Button.cpp
+++ b/Userland/Libraries/LibGUI/Button.cpp
@@ -224,8 +224,23 @@ void Button::set_default(bool default_button)
void Button::set_mimic_pressed(bool mimic_pressed)
{
- m_mimic_pressed = mimic_pressed;
- update();
+ if (!is_being_pressed()) {
+ m_mimic_pressed = mimic_pressed;
+
+ stop_timer();
+ start_timer(80, Core::TimerShouldFireWhenNotVisible::Yes);
+
+ update();
+ }
+}
+
+void Button::timer_event(Core::TimerEvent&)
+{
+ if (is_mimic_pressed()) {
+ m_mimic_pressed = false;
+
+ update();
+ }
}
}
diff --git a/Userland/Libraries/LibGUI/Button.h b/Userland/Libraries/LibGUI/Button.h
index 5e1cb76a84..4fe29f5572 100644
--- a/Userland/Libraries/LibGUI/Button.h
+++ b/Userland/Libraries/LibGUI/Button.h
@@ -64,6 +64,8 @@ protected:
virtual void paint_event(PaintEvent&) override;
private:
+ virtual void timer_event(Core::TimerEvent&) override;
+
RefPtr<Gfx::Bitmap> m_icon;
RefPtr<GUI::Menu> m_menu;
Gfx::ButtonStyle m_button_style { Gfx::ButtonStyle::Normal };