From 401becb922646b7096ee3d16a9aace43c9831f98 Mon Sep 17 00:00:00 2001 From: Benjamin Rottler Date: Sat, 28 Mar 2020 15:06:19 +0100 Subject: [PATCH] NotificationServer: Update locations of notifications after closing one When multiple notifications are open and one notification in the beginning or in the middle is closed the location of the remaining notification windows are updated so that there is no gap between them. --- .../NotificationServer/NotificationWindow.cpp | 28 ++++++++++++++++--- .../NotificationServer/NotificationWindow.h | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Servers/NotificationServer/NotificationWindow.cpp b/Servers/NotificationServer/NotificationWindow.cpp index 0c249f6846..42915f65f9 100644 --- a/Servers/NotificationServer/NotificationWindow.cpp +++ b/Servers/NotificationServer/NotificationWindow.cpp @@ -25,7 +25,7 @@ */ #include "NotificationWindow.h" -#include +#include #include #include #include @@ -36,11 +36,28 @@ namespace NotificationServer { -static HashTable> s_windows; +static Vector> s_windows; + +void update_notification_window_locations() +{ + Gfx::Rect last_window_rect; + for (auto& window : s_windows) { + Gfx::Point new_window_location; + if (last_window_rect.is_null()) + new_window_location = GUI::Desktop::the().rect().top_right().translated(-window->rect().width() - 8, 26); + else + new_window_location = last_window_rect.bottom_left().translated(0, 8); + if (window->rect().location() != new_window_location) { + window->move_to(new_window_location); + window->set_original_rect(window->rect()); + } + last_window_rect = window->rect(); + } +} NotificationWindow::NotificationWindow(const String& text, const String& title, const String& icon_path) { - s_windows.set(this); + s_windows.append(this); set_window_type(GUI::WindowType::Tooltip); @@ -92,8 +109,11 @@ NotificationWindow::NotificationWindow(const String& text, const String& title, auto& button = right_container.add("Okay"); button.on_click = [this] { - s_windows.remove(this); + auto this_window_index = s_windows.find_first_index(this); + if (this_window_index.has_value()) + s_windows.remove(this_window_index.value()); close(); + update_notification_window_locations(); }; } diff --git a/Servers/NotificationServer/NotificationWindow.h b/Servers/NotificationServer/NotificationWindow.h index 589c70848d..232588ff60 100644 --- a/Servers/NotificationServer/NotificationWindow.h +++ b/Servers/NotificationServer/NotificationWindow.h @@ -35,6 +35,7 @@ class NotificationWindow final : public GUI::Window { public: virtual ~NotificationWindow() override; + void set_original_rect(Gfx::Rect original_rect) { m_original_rect = original_rect; }; private: NotificationWindow(const String& text, const String& title, const String& icon_path);