From 96b26ec125340b7a0b29754215dc24f372b6d737 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 4 Apr 2021 00:07:27 +0200 Subject: [PATCH] Everywhere: Replace uses of GUI::Desktop's on_rect_change and remove it --- Userland/Libraries/LibGUI/Desktop.cpp | 2 -- Userland/Libraries/LibGUI/Desktop.h | 2 -- .../NotificationServer/NotificationWindow.cpp | 11 ++++++++--- .../Services/NotificationServer/NotificationWindow.h | 4 ++-- Userland/Services/NotificationServer/main.cpp | 5 ----- Userland/Services/Taskbar/TaskbarWindow.cpp | 7 +++++-- Userland/Services/Taskbar/TaskbarWindow.h | 1 + 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibGUI/Desktop.cpp b/Userland/Libraries/LibGUI/Desktop.cpp index f0bb7b4759..4f10254155 100644 --- a/Userland/Libraries/LibGUI/Desktop.cpp +++ b/Userland/Libraries/LibGUI/Desktop.cpp @@ -50,8 +50,6 @@ void Desktop::did_receive_screen_rect(Badge, const Gfx:: if (m_rect == rect) return; m_rect = rect; - if (on_rect_change) - on_rect_change(rect); } void Desktop::set_background_color(const StringView& background_color) diff --git a/Userland/Libraries/LibGUI/Desktop.h b/Userland/Libraries/LibGUI/Desktop.h index 3de64a7571..ad002ac9ca 100644 --- a/Userland/Libraries/LibGUI/Desktop.h +++ b/Userland/Libraries/LibGUI/Desktop.h @@ -51,8 +51,6 @@ public: void did_receive_screen_rect(Badge, const Gfx::IntRect&); - Function on_rect_change; - private: Gfx::IntRect m_rect; }; diff --git a/Userland/Services/NotificationServer/NotificationWindow.cpp b/Userland/Services/NotificationServer/NotificationWindow.cpp index 96eb65cc07..2cfc391304 100644 --- a/Userland/Services/NotificationServer/NotificationWindow.cpp +++ b/Userland/Services/NotificationServer/NotificationWindow.cpp @@ -39,14 +39,14 @@ namespace NotificationServer { static HashMap> s_windows; -void update_notification_window_locations() +static void update_notification_window_locations(const Gfx::IntRect& screen_rect) { Gfx::IntRect last_window_rect; for (auto& window_entry : s_windows) { auto& window = window_entry.value; Gfx::IntPoint new_window_location; if (last_window_rect.is_null()) - new_window_location = GUI::Desktop::the().rect().top_right().translated(-window->rect().width() - 24, 26); + new_window_location = screen_rect.top_right().translated(-window->rect().width() - 24, 26); else new_window_location = last_window_rect.bottom_left().translated(0, 10); if (window->rect().location() != new_window_location) { @@ -117,7 +117,7 @@ NotificationWindow::NotificationWindow(i32 client_id, const String& text, const on_close = [this] { s_windows.remove(m_id); - update_notification_window_locations(); + update_notification_window_locations(GUI::Desktop::the().rect()); }; } @@ -149,4 +149,9 @@ void NotificationWindow::set_image(const Gfx::ShareableBitmap& image) } } +void NotificationWindow::screen_rect_change_event(GUI::ScreenRectChangeEvent& event) +{ + update_notification_window_locations(event.rect()); +} + } diff --git a/Userland/Services/NotificationServer/NotificationWindow.h b/Userland/Services/NotificationServer/NotificationWindow.h index a02894e2cb..7798b59635 100644 --- a/Userland/Services/NotificationServer/NotificationWindow.h +++ b/Userland/Services/NotificationServer/NotificationWindow.h @@ -31,8 +31,6 @@ namespace NotificationServer { -void update_notification_window_locations(); - class NotificationWindow final : public GUI::Window { C_OBJECT(NotificationWindow); @@ -49,6 +47,8 @@ public: private: NotificationWindow(i32 client_id, const String& text, const String& title, const Gfx::ShareableBitmap&); + virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override; + Gfx::IntRect m_original_rect; i32 m_id; diff --git a/Userland/Services/NotificationServer/main.cpp b/Userland/Services/NotificationServer/main.cpp index 9bf0e11ab1..d0a8c220e8 100644 --- a/Userland/Services/NotificationServer/main.cpp +++ b/Userland/Services/NotificationServer/main.cpp @@ -25,12 +25,9 @@ */ #include "ClientConnection.h" -#include "NotificationWindow.h" #include #include -#include #include -#include #include int main(int argc, char** argv) @@ -68,7 +65,5 @@ int main(int argc, char** argv) return 1; } - GUI::Desktop::the().on_rect_change = [](auto&) { NotificationServer::update_notification_window_locations(); }; - return app->exec(); } diff --git a/Userland/Services/Taskbar/TaskbarWindow.cpp b/Userland/Services/Taskbar/TaskbarWindow.cpp index 1c3747b358..4b5032d243 100644 --- a/Userland/Services/Taskbar/TaskbarWindow.cpp +++ b/Userland/Services/Taskbar/TaskbarWindow.cpp @@ -79,8 +79,6 @@ TaskbarWindow::TaskbarWindow(NonnullRefPtr start_menu) on_screen_rect_change(GUI::Desktop::the().rect()); - GUI::Desktop::the().on_rect_change = [this](const Gfx::IntRect& rect) { on_screen_rect_change(rect); }; - auto& main_widget = set_main_widget(); main_widget.set_layout(); main_widget.layout()->set_margins({ 3, 3, 3, 1 }); @@ -346,3 +344,8 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) break; } } + +void TaskbarWindow::screen_rect_change_event(GUI::ScreenRectChangeEvent& event) +{ + on_screen_rect_change(event.rect()); +} diff --git a/Userland/Services/Taskbar/TaskbarWindow.h b/Userland/Services/Taskbar/TaskbarWindow.h index 2c0f9941ea..e3eebd753e 100644 --- a/Userland/Services/Taskbar/TaskbarWindow.h +++ b/Userland/Services/Taskbar/TaskbarWindow.h @@ -49,6 +49,7 @@ private: ::Window* find_window_owner(::Window&) const; virtual void wm_event(GUI::WMEvent&) override; + virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override; void update_applet_area();