diff --git a/Userland/Libraries/LibGUI/Notification.cpp b/Userland/Libraries/LibGUI/Notification.cpp index 34e06345c9..13a4820d6b 100644 --- a/Userland/Libraries/LibGUI/Notification.cpp +++ b/Userland/Libraries/LibGUI/Notification.cpp @@ -59,8 +59,16 @@ Notification::~Notification() void Notification::show() { + VERIFY(!m_showing); auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap(); m_connection->send_sync(m_text, m_title, icon); + m_showing = true; +} +void Notification::close() +{ + VERIFY(m_showing); + m_connection->send_sync(); + m_showing = false; } } diff --git a/Userland/Libraries/LibGUI/Notification.h b/Userland/Libraries/LibGUI/Notification.h index b26c5aa0fa..44f1479b74 100644 --- a/Userland/Libraries/LibGUI/Notification.h +++ b/Userland/Libraries/LibGUI/Notification.h @@ -30,7 +30,8 @@ #include namespace GUI { - class NotificationServerConnection; + +class NotificationServerConnection; class Notification : public Core::Object { C_OBJECT(Notification); @@ -48,6 +49,7 @@ public: void set_icon(const Gfx::Bitmap* icon) { m_icon = icon; } void show(); + void close(); private: Notification(); @@ -57,6 +59,7 @@ private: RefPtr m_icon; NonnullRefPtr m_connection; + bool m_showing { false }; }; } diff --git a/Userland/Services/NotificationServer/ClientConnection.cpp b/Userland/Services/NotificationServer/ClientConnection.cpp index 59b9dcf968..b2f52c31e3 100644 --- a/Userland/Services/NotificationServer/ClientConnection.cpp +++ b/Userland/Services/NotificationServer/ClientConnection.cpp @@ -60,4 +60,13 @@ OwnPtr ClientConnection: return make(); } +OwnPtr ClientConnection::handle([[maybe_unused]] const Messages::NotificationServer::CloseNotification& message) +{ + auto window = NotificationWindow::get_window_by_id(client_id()); + if (window) { + window->close(); + } + return make(); +} + } diff --git a/Userland/Services/NotificationServer/ClientConnection.h b/Userland/Services/NotificationServer/ClientConnection.h index af4e36d0aa..c32bd415b6 100644 --- a/Userland/Services/NotificationServer/ClientConnection.h +++ b/Userland/Services/NotificationServer/ClientConnection.h @@ -45,6 +45,7 @@ private: virtual OwnPtr handle(const Messages::NotificationServer::Greet&) override; virtual OwnPtr handle(const Messages::NotificationServer::ShowNotification&) override; + virtual OwnPtr handle(const Messages::NotificationServer::CloseNotification& message) override; }; } diff --git a/Userland/Services/NotificationServer/NotificationServer.ipc b/Userland/Services/NotificationServer/NotificationServer.ipc index a4f7e64a6b..bfc02879fb 100644 --- a/Userland/Services/NotificationServer/NotificationServer.ipc +++ b/Userland/Services/NotificationServer/NotificationServer.ipc @@ -4,4 +4,6 @@ endpoint NotificationServer = 95 Greet() => () ShowNotification([UTF8] String text, [UTF8] String title, Gfx::ShareableBitmap icon) => () + + CloseNotification() => () }