Everywhere: Replace uses of GUI::Desktop's on_rect_change and remove it

This commit is contained in:
Linus Groh 2021-04-04 00:07:27 +02:00 committed by Andreas Kling
parent 5367bbb82c
commit 96b26ec125
Notes: sideshowbarker 2024-07-18 20:51:10 +09:00
7 changed files with 16 additions and 16 deletions

View File

@ -50,8 +50,6 @@ void Desktop::did_receive_screen_rect(Badge<WindowServerConnection>, const Gfx::
if (m_rect == rect) if (m_rect == rect)
return; return;
m_rect = rect; m_rect = rect;
if (on_rect_change)
on_rect_change(rect);
} }
void Desktop::set_background_color(const StringView& background_color) void Desktop::set_background_color(const StringView& background_color)

View File

@ -51,8 +51,6 @@ public:
void did_receive_screen_rect(Badge<WindowServerConnection>, const Gfx::IntRect&); void did_receive_screen_rect(Badge<WindowServerConnection>, const Gfx::IntRect&);
Function<void(const Gfx::IntRect&)> on_rect_change;
private: private:
Gfx::IntRect m_rect; Gfx::IntRect m_rect;
}; };

View File

@ -39,14 +39,14 @@ namespace NotificationServer {
static HashMap<u32, RefPtr<NotificationWindow>> s_windows; static HashMap<u32, RefPtr<NotificationWindow>> s_windows;
void update_notification_window_locations() static void update_notification_window_locations(const Gfx::IntRect& screen_rect)
{ {
Gfx::IntRect last_window_rect; Gfx::IntRect last_window_rect;
for (auto& window_entry : s_windows) { for (auto& window_entry : s_windows) {
auto& window = window_entry.value; auto& window = window_entry.value;
Gfx::IntPoint new_window_location; Gfx::IntPoint new_window_location;
if (last_window_rect.is_null()) 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 else
new_window_location = last_window_rect.bottom_left().translated(0, 10); new_window_location = last_window_rect.bottom_left().translated(0, 10);
if (window->rect().location() != new_window_location) { if (window->rect().location() != new_window_location) {
@ -117,7 +117,7 @@ NotificationWindow::NotificationWindow(i32 client_id, const String& text, const
on_close = [this] { on_close = [this] {
s_windows.remove(m_id); 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());
}
} }

View File

@ -31,8 +31,6 @@
namespace NotificationServer { namespace NotificationServer {
void update_notification_window_locations();
class NotificationWindow final : public GUI::Window { class NotificationWindow final : public GUI::Window {
C_OBJECT(NotificationWindow); C_OBJECT(NotificationWindow);
@ -49,6 +47,8 @@ public:
private: private:
NotificationWindow(i32 client_id, const String& text, const String& title, const Gfx::ShareableBitmap&); 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; Gfx::IntRect m_original_rect;
i32 m_id; i32 m_id;

View File

@ -25,12 +25,9 @@
*/ */
#include "ClientConnection.h" #include "ClientConnection.h"
#include "NotificationWindow.h"
#include <LibCore/LocalServer.h> #include <LibCore/LocalServer.h>
#include <LibGUI/Application.h> #include <LibGUI/Application.h>
#include <LibGUI/Desktop.h>
#include <LibGUI/WindowServerConnection.h> #include <LibGUI/WindowServerConnection.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
@ -68,7 +65,5 @@ int main(int argc, char** argv)
return 1; return 1;
} }
GUI::Desktop::the().on_rect_change = [](auto&) { NotificationServer::update_notification_window_locations(); };
return app->exec(); return app->exec();
} }

View File

@ -79,8 +79,6 @@ TaskbarWindow::TaskbarWindow(NonnullRefPtr<GUI::Menu> start_menu)
on_screen_rect_change(GUI::Desktop::the().rect()); 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<TaskbarWidget>(); auto& main_widget = set_main_widget<TaskbarWidget>();
main_widget.set_layout<GUI::HorizontalBoxLayout>(); main_widget.set_layout<GUI::HorizontalBoxLayout>();
main_widget.layout()->set_margins({ 3, 3, 3, 1 }); main_widget.layout()->set_margins({ 3, 3, 3, 1 });
@ -346,3 +344,8 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event)
break; break;
} }
} }
void TaskbarWindow::screen_rect_change_event(GUI::ScreenRectChangeEvent& event)
{
on_screen_rect_change(event.rect());
}

View File

@ -49,6 +49,7 @@ private:
::Window* find_window_owner(::Window&) const; ::Window* find_window_owner(::Window&) const;
virtual void wm_event(GUI::WMEvent&) override; virtual void wm_event(GUI::WMEvent&) override;
virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override;
void update_applet_area(); void update_applet_area();