summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorJoe Bentley <jbentley@star.sr.bham.ac.uk>2021-08-24 13:01:01 +0100
committerAndreas Kling <kling@serenityos.org>2021-08-31 16:49:22 +0200
commit9df79a77da3feed551ed6211af5b7980e6de3932 (patch)
treebbf610f07dbdba9fa01c996a86fafd7c8d13b50b /Userland/Libraries
parent1179d5d921cf82513098239bbf05b526263d3f2e (diff)
downloadserenity-9df79a77da3feed551ed6211af5b7980e6de3932.zip
WindowServer: Add message to notify clients of applet area resize
Applets and windows would like to be able to know when the applet area has been resized. For example, this happens asynchronously after an applet has been resized, so we cannot then rely on the applet area position synchronously after resizing. This adds a new message applet_area_rect_changed and associated Event AppletAreaRectChange, and the appropriate virtual functions.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/Event.h15
-rw-r--r--Userland/Libraries/LibGUI/Forward.h1
-rw-r--r--Userland/Libraries/LibGUI/Widget.cpp6
-rw-r--r--Userland/Libraries/LibGUI/Widget.h1
-rw-r--r--Userland/Libraries/LibGUI/Window.cpp23
-rw-r--r--Userland/Libraries/LibGUI/Window.h2
-rw-r--r--Userland/Libraries/LibGUI/WindowServerConnection.cpp7
-rw-r--r--Userland/Libraries/LibGUI/WindowServerConnection.h1
8 files changed, 56 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Event.h b/Userland/Libraries/LibGUI/Event.h
index e2a0cd520b..8a2b732773 100644
--- a/Userland/Libraries/LibGUI/Event.h
+++ b/Userland/Libraries/LibGUI/Event.h
@@ -56,6 +56,7 @@ public:
ScreenRectsChange,
ActionEnter,
ActionLeave,
+ AppletAreaRectChange,
__Begin_WM_Events,
WM_WindowRemoved,
@@ -451,6 +452,20 @@ private:
size_t m_main_screen_index;
};
+class AppletAreaRectChangeEvent final : public Event {
+public:
+ explicit AppletAreaRectChangeEvent(Gfx::IntRect rect)
+ : Event(Type::AppletAreaRectChange)
+ , m_rect(rect)
+ {
+ }
+
+ Gfx::IntRect rect() const { return m_rect; }
+
+private:
+ Gfx::IntRect const m_rect;
+};
+
class FocusEvent final : public Event {
public:
explicit FocusEvent(Type type, FocusSource source)
diff --git a/Userland/Libraries/LibGUI/Forward.h b/Userland/Libraries/LibGUI/Forward.h
index 21e0c77f06..ac629e035f 100644
--- a/Userland/Libraries/LibGUI/Forward.h
+++ b/Userland/Libraries/LibGUI/Forward.h
@@ -13,6 +13,7 @@ class AbstractTableView;
class AbstractView;
class Action;
class ActionGroup;
+class AppletAreaRectChangeEvent;
class Application;
class AutocompleteBox;
class AutocompleteProvider;
diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp
index 52bb229f5c..71362ff939 100644
--- a/Userland/Libraries/LibGUI/Widget.cpp
+++ b/Userland/Libraries/LibGUI/Widget.cpp
@@ -305,6 +305,8 @@ void Widget::event(Core::Event& event)
return change_event(static_cast<Event&>(event));
case Event::ContextMenu:
return context_menu_event(static_cast<ContextMenuEvent&>(event));
+ case Event::AppletAreaRectChange:
+ return applet_area_rect_change_event(static_cast<AppletAreaRectChangeEvent&>(event));
default:
return Core::Object::event(event);
}
@@ -579,6 +581,10 @@ void Widget::screen_rects_change_event(ScreenRectsChangeEvent&)
{
}
+void Widget::applet_area_rect_change_event(AppletAreaRectChangeEvent&)
+{
+}
+
void Widget::update()
{
if (rect().is_empty())
diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h
index 86b353b5a0..d88a70dfec 100644
--- a/Userland/Libraries/LibGUI/Widget.h
+++ b/Userland/Libraries/LibGUI/Widget.h
@@ -319,6 +319,7 @@ protected:
virtual void theme_change_event(ThemeChangeEvent&);
virtual void fonts_change_event(FontsChangeEvent&);
virtual void screen_rects_change_event(ScreenRectsChangeEvent&);
+ virtual void applet_area_rect_change_event(AppletAreaRectChangeEvent&);
virtual void did_begin_inspection() override;
virtual void did_end_inspection() override;
diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp
index 3156e0f04f..3d926eabd1 100644
--- a/Userland/Libraries/LibGUI/Window.cpp
+++ b/Userland/Libraries/LibGUI/Window.cpp
@@ -550,6 +550,22 @@ void Window::handle_screen_rects_change_event(ScreenRectsChangeEvent& event)
screen_rects_change_event(event);
}
+void Window::handle_applet_area_rect_change_event(AppletAreaRectChangeEvent& event)
+{
+ if (!m_main_widget)
+ return;
+ auto dispatch_applet_area_rect_change = [&](auto& widget, auto recursive) {
+ widget.dispatch_event(event, this);
+ widget.for_each_child_widget([&](auto& widget) -> IterationDecision {
+ widget.dispatch_event(event, this);
+ recursive(widget, recursive);
+ return IterationDecision::Continue;
+ });
+ };
+ dispatch_applet_area_rect_change(*m_main_widget.ptr(), dispatch_applet_area_rect_change);
+ applet_area_rect_change_event(event);
+}
+
void Window::handle_drag_move_event(DragEvent& event)
{
if (!m_main_widget)
@@ -640,6 +656,9 @@ void Window::event(Core::Event& event)
if (event.type() == Event::ScreenRectsChange)
return handle_screen_rects_change_event(static_cast<ScreenRectsChangeEvent&>(event));
+ if (event.type() == Event::AppletAreaRectChange)
+ return handle_applet_area_rect_change_event(static_cast<AppletAreaRectChangeEvent&>(event));
+
Core::Object::event(event);
}
@@ -878,6 +897,10 @@ void Window::screen_rects_change_event(ScreenRectsChangeEvent&)
{
}
+void Window::applet_area_rect_change_event(AppletAreaRectChangeEvent&)
+{
+}
+
void Window::set_icon(const Gfx::Bitmap* icon)
{
if (m_icon == icon)
diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h
index a6d5b3db8b..013bb4fbe3 100644
--- a/Userland/Libraries/LibGUI/Window.h
+++ b/Userland/Libraries/LibGUI/Window.h
@@ -207,6 +207,7 @@ protected:
Window(Core::Object* parent = nullptr);
virtual void wm_event(WMEvent&);
virtual void screen_rects_change_event(ScreenRectsChangeEvent&);
+ virtual void applet_area_rect_change_event(AppletAreaRectChangeEvent&);
virtual void enter_event(Core::Event&);
virtual void leave_event(Core::Event&);
@@ -226,6 +227,7 @@ private:
void handle_theme_change_event(ThemeChangeEvent&);
void handle_fonts_change_event(FontsChangeEvent&);
void handle_screen_rects_change_event(ScreenRectsChangeEvent&);
+ void handle_applet_area_rect_change_event(AppletAreaRectChangeEvent&);
void handle_drag_move_event(DragEvent&);
void handle_entered_event(Core::Event&);
void handle_left_event(Core::Event&);
diff --git a/Userland/Libraries/LibGUI/WindowServerConnection.cpp b/Userland/Libraries/LibGUI/WindowServerConnection.cpp
index 7462e0cc8c..a06f9bde20 100644
--- a/Userland/Libraries/LibGUI/WindowServerConnection.cpp
+++ b/Userland/Libraries/LibGUI/WindowServerConnection.cpp
@@ -321,6 +321,13 @@ void WindowServerConnection::screen_rects_changed(Vector<Gfx::IntRect> const& re
});
}
+void WindowServerConnection::applet_area_rect_changed(Gfx::IntRect const& rect)
+{
+ Window::for_each_window({}, [&](auto& window) {
+ Core::EventLoop::current().post_event(window, make<AppletAreaRectChangeEvent>(rect));
+ });
+}
+
void WindowServerConnection::set_wallpaper_finished(bool)
{
// This is handled manually by Desktop::set_wallpaper().
diff --git a/Userland/Libraries/LibGUI/WindowServerConnection.h b/Userland/Libraries/LibGUI/WindowServerConnection.h
index 91a5bbc195..f9d4b92751 100644
--- a/Userland/Libraries/LibGUI/WindowServerConnection.h
+++ b/Userland/Libraries/LibGUI/WindowServerConnection.h
@@ -46,6 +46,7 @@ private:
virtual void menu_item_left(i32, u32) override;
virtual void menu_visibility_did_change(i32, bool) override;
virtual void screen_rects_changed(Vector<Gfx::IntRect> const&, u32, u32, u32) override;
+ virtual void applet_area_rect_changed(Gfx::IntRect const&) override;
virtual void set_wallpaper_finished(bool) override;
virtual void drag_dropped(i32, Gfx::IntPoint const&, String const&, HashMap<String, ByteBuffer> const&) override;
virtual void drag_accepted() override;