ladybird/Libraries/LibGUI/Notification.cpp
Andreas Kling 9f54ea9bcd NotificationServer: Add a system service for desktop notifications
This patch adds NotificationServer, which runs as the "notify" user
and provides an IPC API for desktop notifications.

LibGUI gains the GUI::Notification class for showing notifications.

NotificationServer is spawned on demand and will unspawn after
dimissing all visible notifications. :^)

Finally, this also comes with a small /bin/notify utility.
2020-02-16 21:58:17 +01:00

48 lines
1.3 KiB
C++

#include <LibGUI/Notification.h>
#include <LibIPC/ServerConnection.h>
#include <NotificationServer/NotificationClientEndpoint.h>
#include <NotificationServer/NotificationServerEndpoint.h>
namespace GUI {
class NotificationServerConnection : public IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>
, public NotificationClientEndpoint {
C_OBJECT(NotificationServerConnection)
public:
virtual void handshake() override
{
auto response = send_sync<Messages::NotificationServer::Greet>();
set_my_client_id(response->client_id());
}
private:
NotificationServerConnection()
: IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify")
{
}
virtual void handle(const Messages::NotificationClient::Dummy&) override {}
};
Notification::Notification()
{
}
Notification::~Notification()
{
}
static NotificationServerConnection& notification_server_connection()
{
static NotificationServerConnection* connection;
if (!connection)
connection = &NotificationServerConnection::construct().leak_ref();
return *connection;
}
void Notification::show()
{
notification_server_connection().post_message(Messages::NotificationServer::ShowNotification(m_text, m_title));
}
}