mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
Notification: Give a unique internal ID
This will allow us to later query the notifications from a connection and safely update it without exposing it to any other applications, as it is session based.
This commit is contained in:
parent
7351c77a42
commit
a437430294
3 changed files with 13 additions and 8 deletions
|
@ -55,7 +55,7 @@ OwnPtr<Messages::NotificationServer::GreetResponse> ClientConnection::handle(con
|
||||||
|
|
||||||
OwnPtr<Messages::NotificationServer::ShowNotificationResponse> ClientConnection::handle(const Messages::NotificationServer::ShowNotification& message)
|
OwnPtr<Messages::NotificationServer::ShowNotificationResponse> ClientConnection::handle(const Messages::NotificationServer::ShowNotification& message)
|
||||||
{
|
{
|
||||||
auto window = NotificationWindow::construct(message.text(), message.title(), message.icon());
|
auto window = NotificationWindow::construct(client_id(), message.text(), message.title(), message.icon());
|
||||||
window->show();
|
window->show();
|
||||||
return make<Messages::NotificationServer::ShowNotificationResponse>();
|
return make<Messages::NotificationServer::ShowNotificationResponse>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "NotificationWindow.h"
|
#include "NotificationWindow.h"
|
||||||
|
#include <AK/HashMap.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
|
@ -39,12 +40,13 @@
|
||||||
|
|
||||||
namespace NotificationServer {
|
namespace NotificationServer {
|
||||||
|
|
||||||
static Vector<RefPtr<NotificationWindow>> s_windows;
|
static HashMap<u32, RefPtr<NotificationWindow>> s_windows;
|
||||||
|
|
||||||
void update_notification_window_locations()
|
void update_notification_window_locations()
|
||||||
{
|
{
|
||||||
Gfx::IntRect last_window_rect;
|
Gfx::IntRect last_window_rect;
|
||||||
for (auto& window : s_windows) {
|
for (auto& window_entry : s_windows) {
|
||||||
|
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 = GUI::Desktop::the().rect().top_right().translated(-window->rect().width() - 24, 26);
|
||||||
|
@ -58,16 +60,18 @@ void update_notification_window_locations()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationWindow::NotificationWindow(const String& text, const String& title, const Gfx::ShareableBitmap& icon)
|
NotificationWindow::NotificationWindow(i32 client_id, const String& text, const String& title, const Gfx::ShareableBitmap& icon)
|
||||||
{
|
{
|
||||||
s_windows.append(this);
|
m_id = client_id;
|
||||||
|
s_windows.set(m_id, this);
|
||||||
|
|
||||||
set_window_type(GUI::WindowType::Notification);
|
set_window_type(GUI::WindowType::Notification);
|
||||||
set_resizable(false);
|
set_resizable(false);
|
||||||
set_minimizable(false);
|
set_minimizable(false);
|
||||||
|
|
||||||
Gfx::IntRect lowest_notification_rect_on_screen;
|
Gfx::IntRect lowest_notification_rect_on_screen;
|
||||||
for (auto& window : s_windows) {
|
for (auto& window_entry : s_windows) {
|
||||||
|
auto& window = window_entry.value;
|
||||||
if (window->m_original_rect.y() > lowest_notification_rect_on_screen.y())
|
if (window->m_original_rect.y() > lowest_notification_rect_on_screen.y())
|
||||||
lowest_notification_rect_on_screen = window->m_original_rect;
|
lowest_notification_rect_on_screen = window->m_original_rect;
|
||||||
}
|
}
|
||||||
|
@ -114,7 +118,7 @@ NotificationWindow::NotificationWindow(const String& text, const String& title,
|
||||||
right_container.set_layout<GUI::HorizontalBoxLayout>();
|
right_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||||
|
|
||||||
on_close_request = [this] {
|
on_close_request = [this] {
|
||||||
s_windows.remove_first_matching([this](auto& entry) { return entry == this; });
|
s_windows.remove(m_id);
|
||||||
update_notification_window_locations();
|
update_notification_window_locations();
|
||||||
return CloseRequestDecision::Close;
|
return CloseRequestDecision::Close;
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,9 +40,10 @@ public:
|
||||||
void set_original_rect(Gfx::IntRect original_rect) { m_original_rect = original_rect; };
|
void set_original_rect(Gfx::IntRect original_rect) { m_original_rect = original_rect; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NotificationWindow(const String& text, const String& title, const Gfx::ShareableBitmap&);
|
NotificationWindow(i32 client_id, const String& text, const String& title, const Gfx::ShareableBitmap&);
|
||||||
|
|
||||||
Gfx::IntRect m_original_rect;
|
Gfx::IntRect m_original_rect;
|
||||||
|
i32 m_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue