From 535e1c91526924c3a67c2125e08986550a743b56 Mon Sep 17 00:00:00 2001 From: networkException Date: Thu, 16 Jun 2022 14:16:31 +0200 Subject: LibGUI: Add on_theme_change callback to Application This allows an Application without a window to listen for theme changes. --- Userland/Libraries/LibGUI/Application.cpp | 4 ++++ Userland/Libraries/LibGUI/Application.h | 1 + Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp | 2 ++ 3 files changed, 7 insertions(+) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index c5d0f670fe..ded131f1cc 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -311,6 +311,10 @@ void Application::event(Core::Event& event) on_action_leave(action); } } + if (event.type() == GUI::Event::ThemeChange) { + if (on_theme_change) + on_theme_change(); + } Object::event(event); } diff --git a/Userland/Libraries/LibGUI/Application.h b/Userland/Libraries/LibGUI/Application.h index e74fc6abca..0f224f41a6 100644 --- a/Userland/Libraries/LibGUI/Application.h +++ b/Userland/Libraries/LibGUI/Application.h @@ -83,6 +83,7 @@ public: Function on_action_enter; Function on_action_leave; + Function on_theme_change; auto const& global_shortcut_actions(Badge) const { return m_global_shortcut_actions; } diff --git a/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp b/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp index 61e997d57c..11637bf2a1 100644 --- a/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp +++ b/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp @@ -67,6 +67,8 @@ void ConnectionToWindowServer::update_system_theme(Core::AnonymousBuffer const& Window::for_each_window({}, [](auto& window) { Core::EventLoop::current().post_event(window, make()); }); + + Application::the()->dispatch_event(*make()); } void ConnectionToWindowServer::update_system_fonts(String const& default_font_query, String const& fixed_width_font_query) -- cgit v1.2.3