File tree Expand file tree Collapse file tree 8 files changed +53
-1
lines changed Expand file tree Collapse file tree 8 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 28
28
29
29
#include < Kernel/KeyCode.h>
30
30
#include < LibCore/Event.h>
31
+ #include < LibGUI/WindowType.h>
31
32
#include < LibGfx/Point.h>
32
33
#include < LibGfx/Rect.h>
33
- #include < LibGUI/WindowType.h>
34
34
35
35
namespace GUI {
36
36
@@ -62,6 +62,7 @@ class Event : public Core::Event {
62
62
EnabledChange,
63
63
DragMove,
64
64
Drop,
65
+ ThemeChange,
65
66
66
67
__Begin_WM_Events,
67
68
WM_WindowRemoved,
@@ -340,4 +341,12 @@ class DropEvent final : public Event {
340
341
NonnullRefPtr<Core::MimeData> m_mime_data;
341
342
};
342
343
344
+ class ThemeChangeEvent final : public Event {
345
+ public:
346
+ ThemeChangeEvent ()
347
+ : Event(Type::ThemeChange)
348
+ {
349
+ }
350
+ };
351
+
343
352
}
Original file line number Diff line number Diff line change @@ -1279,6 +1279,13 @@ void TextEditor::resize_event(ResizeEvent& event)
1279
1279
recompute_all_visual_lines ();
1280
1280
}
1281
1281
1282
+ void TextEditor::theme_change_event (ThemeChangeEvent& event)
1283
+ {
1284
+ ScrollableWidget::theme_change_event (event);
1285
+ if (m_highlighter)
1286
+ m_highlighter->rehighlight (palette ());
1287
+ }
1288
+
1282
1289
void TextEditor::set_selection (const TextRange& selection)
1283
1290
{
1284
1291
if (m_selection == selection)
Original file line number Diff line number Diff line change @@ -148,6 +148,7 @@ class TextEditor
148
148
virtual void leave_event (Core::Event&) override ;
149
149
virtual void context_menu_event (ContextMenuEvent&) override ;
150
150
virtual void resize_event (ResizeEvent&) override ;
151
+ virtual void theme_change_event (ThemeChangeEvent&) override ;
151
152
virtual void cursor_did_change () {}
152
153
153
154
TextPosition text_position_at (const Gfx::Point&) const ;
Original file line number Diff line number Diff line change @@ -206,6 +206,8 @@ void Widget::event(Core::Event& event)
206
206
return drag_move_event (static_cast <DragEvent&>(event));
207
207
case Event::Drop:
208
208
return drop_event (static_cast <DropEvent&>(event));
209
+ case Event::ThemeChange:
210
+ return theme_change_event (static_cast <ThemeChangeEvent&>(event));
209
211
case Event::Enter:
210
212
return handle_enter_event (event);
211
213
case Event::Leave:
@@ -417,6 +419,10 @@ void Widget::drop_event(DropEvent& event)
417
419
event.ignore ();
418
420
}
419
421
422
+ void Widget::theme_change_event (ThemeChangeEvent&)
423
+ {
424
+ }
425
+
420
426
void Widget::update ()
421
427
{
422
428
if (rect ().is_empty ())
Original file line number Diff line number Diff line change @@ -292,6 +292,7 @@ class Widget : public Core::Object {
292
292
virtual void change_event (Event&);
293
293
virtual void drag_move_event (DragEvent&);
294
294
virtual void drop_event (DropEvent&);
295
+ virtual void theme_change_event (ThemeChangeEvent&);
295
296
296
297
virtual void did_begin_inspection () override ;
297
298
virtual void did_end_inspection () override ;
Original file line number Diff line number Diff line change @@ -334,6 +334,22 @@ void Window::event(Core::Event& event)
334
334
return result.widget ->dispatch_event (*local_event, this );
335
335
}
336
336
337
+ if (event.type () == Event::ThemeChange) {
338
+ if (!m_main_widget)
339
+ return ;
340
+ auto theme_event = static_cast <ThemeChangeEvent&>(event);
341
+ auto dispatch_theme_change = [&](auto & widget, auto recursive) {
342
+ widget.dispatch_event (theme_event, this );
343
+ widget.for_each_child_widget ([&](auto & widget) -> IterationDecision {
344
+ widget.dispatch_event (theme_event, this );
345
+ recursive (widget, recursive);
346
+ return IterationDecision::Continue;
347
+ });
348
+ };
349
+ dispatch_theme_change (*m_main_widget.ptr (), dispatch_theme_change);
350
+ return ;
351
+ }
352
+
337
353
Core::Object::event (event);
338
354
}
339
355
@@ -635,6 +651,14 @@ void Window::schedule_relayout()
635
651
});
636
652
}
637
653
654
+ void Window::for_each_window (Badge<WindowServerConnection>, Function<void (Window&)> callback)
655
+ {
656
+ for (auto & e : *reified_windows) {
657
+ ASSERT (e.value );
658
+ callback (*e.value );
659
+ }
660
+ }
661
+
638
662
void Window::update_all_windows (Badge<WindowServerConnection>)
639
663
{
640
664
for (auto & e : *reified_windows) {
Original file line number Diff line number Diff line change @@ -172,6 +172,7 @@ class Window : public Core::Object {
172
172
173
173
void schedule_relayout ();
174
174
175
+ static void for_each_window (Badge<WindowServerConnection>, Function<void (Window&)>);
175
176
static void update_all_windows (Badge<WindowServerConnection>);
176
177
void notify_state_changed (Badge<WindowServerConnection>, bool minimized, bool occluded);
177
178
Original file line number Diff line number Diff line change @@ -73,6 +73,9 @@ void WindowServerConnection::handle(const Messages::WindowClient::UpdateSystemTh
73
73
{
74
74
set_system_theme_from_shbuf_id (message.system_theme_buffer_id ());
75
75
Window::update_all_windows ({});
76
+ Window::for_each_window ({}, [](auto & window) {
77
+ Core::EventLoop::current ().post_event (window, make<ThemeChangeEvent>());
78
+ });
76
79
}
77
80
78
81
void WindowServerConnection::handle (const Messages::WindowClient::Paint& message)
You can’t perform that action at this time.
0 commit comments