mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
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.
This commit is contained in:
parent
14de45296e
commit
401becb922
Notes:
sideshowbarker
2024-07-19 08:05:52 +09:00
Author: https://github.com/QuantumDancer 🔰 Commit: https://github.com/SerenityOS/serenity/commit/401becb9226 Pull-request: https://github.com/SerenityOS/serenity/pull/1520
@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "NotificationWindow.h"
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Desktop.h>
|
||||
@ -36,11 +36,28 @@
|
||||
|
||||
namespace NotificationServer {
|
||||
|
||||
static HashTable<RefPtr<NotificationWindow>> s_windows;
|
||||
static Vector<RefPtr<NotificationWindow>> 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<GUI::Button>("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();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user