mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
LibGUI+Notification: Add notification closing
Closing a notification will now allow it to be shown again, as m_showing being false means it can be re-shown.
This commit is contained in:
parent
ef4144c183
commit
0fd1e6f062
5 changed files with 24 additions and 1 deletions
|
@ -59,8 +59,16 @@ Notification::~Notification()
|
||||||
|
|
||||||
void Notification::show()
|
void Notification::show()
|
||||||
{
|
{
|
||||||
|
VERIFY(!m_showing);
|
||||||
auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
||||||
m_connection->send_sync<Messages::NotificationServer::ShowNotification>(m_text, m_title, icon);
|
m_connection->send_sync<Messages::NotificationServer::ShowNotification>(m_text, m_title, icon);
|
||||||
|
m_showing = true;
|
||||||
|
}
|
||||||
|
void Notification::close()
|
||||||
|
{
|
||||||
|
VERIFY(m_showing);
|
||||||
|
m_connection->send_sync<Messages::NotificationServer::CloseNotification>();
|
||||||
|
m_showing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
class NotificationServerConnection;
|
|
||||||
|
class NotificationServerConnection;
|
||||||
|
|
||||||
class Notification : public Core::Object {
|
class Notification : public Core::Object {
|
||||||
C_OBJECT(Notification);
|
C_OBJECT(Notification);
|
||||||
|
@ -48,6 +49,7 @@ public:
|
||||||
void set_icon(const Gfx::Bitmap* icon) { m_icon = icon; }
|
void set_icon(const Gfx::Bitmap* icon) { m_icon = icon; }
|
||||||
|
|
||||||
void show();
|
void show();
|
||||||
|
void close();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Notification();
|
Notification();
|
||||||
|
@ -57,6 +59,7 @@ private:
|
||||||
RefPtr<Gfx::Bitmap> m_icon;
|
RefPtr<Gfx::Bitmap> m_icon;
|
||||||
|
|
||||||
NonnullRefPtr<NotificationServerConnection> m_connection;
|
NonnullRefPtr<NotificationServerConnection> m_connection;
|
||||||
|
bool m_showing { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,4 +60,13 @@ OwnPtr<Messages::NotificationServer::ShowNotificationResponse> ClientConnection:
|
||||||
return make<Messages::NotificationServer::ShowNotificationResponse>();
|
return make<Messages::NotificationServer::ShowNotificationResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OwnPtr<Messages::NotificationServer::CloseNotificationResponse> ClientConnection::handle([[maybe_unused]] const Messages::NotificationServer::CloseNotification& message)
|
||||||
|
{
|
||||||
|
auto window = NotificationWindow::get_window_by_id(client_id());
|
||||||
|
if (window) {
|
||||||
|
window->close();
|
||||||
|
}
|
||||||
|
return make<Messages::NotificationServer::CloseNotificationResponse>();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ private:
|
||||||
|
|
||||||
virtual OwnPtr<Messages::NotificationServer::GreetResponse> handle(const Messages::NotificationServer::Greet&) override;
|
virtual OwnPtr<Messages::NotificationServer::GreetResponse> handle(const Messages::NotificationServer::Greet&) override;
|
||||||
virtual OwnPtr<Messages::NotificationServer::ShowNotificationResponse> handle(const Messages::NotificationServer::ShowNotification&) override;
|
virtual OwnPtr<Messages::NotificationServer::ShowNotificationResponse> handle(const Messages::NotificationServer::ShowNotification&) override;
|
||||||
|
virtual OwnPtr<Messages::NotificationServer::CloseNotificationResponse> handle(const Messages::NotificationServer::CloseNotification& message) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,4 +4,6 @@ endpoint NotificationServer = 95
|
||||||
Greet() => ()
|
Greet() => ()
|
||||||
|
|
||||||
ShowNotification([UTF8] String text, [UTF8] String title, Gfx::ShareableBitmap icon) => ()
|
ShowNotification([UTF8] String text, [UTF8] String title, Gfx::ShareableBitmap icon) => ()
|
||||||
|
|
||||||
|
CloseNotification() => ()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue