summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorOriko <oriko1010@protonmail.com>2020-03-16 13:36:21 +0200
committerAndreas Kling <kling@serenityos.org>2020-03-16 13:39:34 +0100
commit2a32330257b96922d9ed274baf6fc96abca957f0 (patch)
tree4eba5f05e4729305d56c4ca383c24127cf6c038b /Libraries
parent2b162ef79459d4b4961c25809ef98da4ca5cefd5 (diff)
downloadserenity-2a32330257b96922d9ed274baf6fc96abca957f0.zip
LibGUI: Add a ThemeChange event
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/Event.h11
-rw-r--r--Libraries/LibGUI/TextEditor.cpp7
-rw-r--r--Libraries/LibGUI/TextEditor.h1
-rw-r--r--Libraries/LibGUI/Widget.cpp6
-rw-r--r--Libraries/LibGUI/Widget.h1
-rw-r--r--Libraries/LibGUI/Window.cpp24
-rw-r--r--Libraries/LibGUI/Window.h1
-rw-r--r--Libraries/LibGUI/WindowServerConnection.cpp3
8 files changed, 53 insertions, 1 deletions
diff --git a/Libraries/LibGUI/Event.h b/Libraries/LibGUI/Event.h
index fd378b5200..a2240a1659 100644
--- a/Libraries/LibGUI/Event.h
+++ b/Libraries/LibGUI/Event.h
@@ -28,9 +28,9 @@
#include <Kernel/KeyCode.h>
#include <LibCore/Event.h>
+#include <LibGUI/WindowType.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
-#include <LibGUI/WindowType.h>
namespace GUI {
@@ -62,6 +62,7 @@ public:
EnabledChange,
DragMove,
Drop,
+ ThemeChange,
__Begin_WM_Events,
WM_WindowRemoved,
@@ -340,4 +341,12 @@ private:
NonnullRefPtr<Core::MimeData> m_mime_data;
};
+class ThemeChangeEvent final : public Event {
+public:
+ ThemeChangeEvent()
+ : Event(Type::ThemeChange)
+ {
+ }
+};
+
}
diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp
index a8bd6118bb..f16d170ba1 100644
--- a/Libraries/LibGUI/TextEditor.cpp
+++ b/Libraries/LibGUI/TextEditor.cpp
@@ -1279,6 +1279,13 @@ void TextEditor::resize_event(ResizeEvent& event)
recompute_all_visual_lines();
}
+void TextEditor::theme_change_event(ThemeChangeEvent& event)
+{
+ ScrollableWidget::theme_change_event(event);
+ if (m_highlighter)
+ m_highlighter->rehighlight(palette());
+}
+
void TextEditor::set_selection(const TextRange& selection)
{
if (m_selection == selection)
diff --git a/Libraries/LibGUI/TextEditor.h b/Libraries/LibGUI/TextEditor.h
index 8aec1a66b7..7d70474cdd 100644
--- a/Libraries/LibGUI/TextEditor.h
+++ b/Libraries/LibGUI/TextEditor.h
@@ -148,6 +148,7 @@ protected:
virtual void leave_event(Core::Event&) override;
virtual void context_menu_event(ContextMenuEvent&) override;
virtual void resize_event(ResizeEvent&) override;
+ virtual void theme_change_event(ThemeChangeEvent&) override;
virtual void cursor_did_change() {}
TextPosition text_position_at(const Gfx::Point&) const;
diff --git a/Libraries/LibGUI/Widget.cpp b/Libraries/LibGUI/Widget.cpp
index 7e5d719633..0f9036fd69 100644
--- a/Libraries/LibGUI/Widget.cpp
+++ b/Libraries/LibGUI/Widget.cpp
@@ -206,6 +206,8 @@ void Widget::event(Core::Event& event)
return drag_move_event(static_cast<DragEvent&>(event));
case Event::Drop:
return drop_event(static_cast<DropEvent&>(event));
+ case Event::ThemeChange:
+ return theme_change_event(static_cast<ThemeChangeEvent&>(event));
case Event::Enter:
return handle_enter_event(event);
case Event::Leave:
@@ -417,6 +419,10 @@ void Widget::drop_event(DropEvent& event)
event.ignore();
}
+void Widget::theme_change_event(ThemeChangeEvent&)
+{
+}
+
void Widget::update()
{
if (rect().is_empty())
diff --git a/Libraries/LibGUI/Widget.h b/Libraries/LibGUI/Widget.h
index 52f41fdd4a..5206290e58 100644
--- a/Libraries/LibGUI/Widget.h
+++ b/Libraries/LibGUI/Widget.h
@@ -292,6 +292,7 @@ protected:
virtual void change_event(Event&);
virtual void drag_move_event(DragEvent&);
virtual void drop_event(DropEvent&);
+ virtual void theme_change_event(ThemeChangeEvent&);
virtual void did_begin_inspection() override;
virtual void did_end_inspection() override;
diff --git a/Libraries/LibGUI/Window.cpp b/Libraries/LibGUI/Window.cpp
index 60c583802b..9cb37b02c5 100644
--- a/Libraries/LibGUI/Window.cpp
+++ b/Libraries/LibGUI/Window.cpp
@@ -334,6 +334,22 @@ void Window::event(Core::Event& event)
return result.widget->dispatch_event(*local_event, this);
}
+ if (event.type() == Event::ThemeChange) {
+ if (!m_main_widget)
+ return;
+ auto theme_event = static_cast<ThemeChangeEvent&>(event);
+ auto dispatch_theme_change = [&](auto& widget, auto recursive) {
+ widget.dispatch_event(theme_event, this);
+ widget.for_each_child_widget([&](auto& widget) -> IterationDecision {
+ widget.dispatch_event(theme_event, this);
+ recursive(widget, recursive);
+ return IterationDecision::Continue;
+ });
+ };
+ dispatch_theme_change(*m_main_widget.ptr(), dispatch_theme_change);
+ return;
+ }
+
Core::Object::event(event);
}
@@ -635,6 +651,14 @@ void Window::schedule_relayout()
});
}
+void Window::for_each_window(Badge<WindowServerConnection>, Function<void(Window&)> callback)
+{
+ for (auto& e : *reified_windows) {
+ ASSERT(e.value);
+ callback(*e.value);
+ }
+}
+
void Window::update_all_windows(Badge<WindowServerConnection>)
{
for (auto& e : *reified_windows) {
diff --git a/Libraries/LibGUI/Window.h b/Libraries/LibGUI/Window.h
index c9b8633faa..10527fed6d 100644
--- a/Libraries/LibGUI/Window.h
+++ b/Libraries/LibGUI/Window.h
@@ -172,6 +172,7 @@ public:
void schedule_relayout();
+ static void for_each_window(Badge<WindowServerConnection>, Function<void(Window&)>);
static void update_all_windows(Badge<WindowServerConnection>);
void notify_state_changed(Badge<WindowServerConnection>, bool minimized, bool occluded);
diff --git a/Libraries/LibGUI/WindowServerConnection.cpp b/Libraries/LibGUI/WindowServerConnection.cpp
index 35c9c154e6..343699a208 100644
--- a/Libraries/LibGUI/WindowServerConnection.cpp
+++ b/Libraries/LibGUI/WindowServerConnection.cpp
@@ -73,6 +73,9 @@ void WindowServerConnection::handle(const Messages::WindowClient::UpdateSystemTh
{
set_system_theme_from_shbuf_id(message.system_theme_buffer_id());
Window::update_all_windows({});
+ Window::for_each_window({}, [](auto& window) {
+ Core::EventLoop::current().post_event(window, make<ThemeChangeEvent>());
+ });
}
void WindowServerConnection::handle(const Messages::WindowClient::Paint& message)