add notifications

This commit is contained in:
2026-01-31 22:46:19 +01:00
parent 8283531748
commit 13278d518a
10 changed files with 226 additions and 7 deletions

View File

@@ -4,6 +4,7 @@
#include "bar/bar.hpp"
#include "services/hyprland.hpp"
#include "services/notification.hpp"
#include "glibmm/refptr.h"
#include "gtkmm/application.h"
@@ -17,8 +18,9 @@ class App {
private:
Glib::RefPtr<Gtk::Application> app;
std::vector<std::shared_ptr<Bar>> bars;
std::shared_ptr<NotificationService> notificationService = nullptr;
HyprlandService *hyprlandService = nullptr;
TrayService *trayService = TrayService::getInstance();
TrayService *trayService = TrayService::getInstance();
void setupServices();
};

View File

@@ -0,0 +1,75 @@
#pragma once
#include <fcntl.h>
#include <giomm.h>
#include <gtkmm.h>
#include <memory>
#include <sigc++/sigc++.h>
#include <vector>
#include "gdkmm/monitor.h"
#include "giomm/dbusconnection.h"
#include "giomm/dbusownname.h"
#include "glib.h"
const Glib::ustring introspection_xml = R"(
<node>
<interface name="org.freedesktop.Notifications">
<method name="GetCapabilities">
<arg name="capabilities" type="as" direction="out"/>
</method>
<method name="Notify">
<arg name="app_name" type="s" direction="in"/>
<arg name="replaces_id" type="u" direction="in"/>
<arg name="app_icon" type="s" direction="in"/>
<arg name="summary" type="s" direction="in"/>
<arg name="body" type="s" direction="in"/>
<arg name="actions" type="as" direction="in"/>
<arg name="hints" type="a{sv}" direction="in"/>
<arg name="expire_timeout" type="i" direction="in"/>
<arg name="id" type="u" direction="out"/>
</method>
<method name="CloseNotification">
<arg name="id" type="u" direction="in"/>
</method>
<method name="GetServerInformation">
<arg name="name" type="s" direction="out"/>
<arg name="vendor" type="s" direction="out"/>
<arg name="version" type="s" direction="out"/>
<arg name="spec_version" type="s" direction="out"/>
</method>
</interface>
</node>
)";
class NotificationService {
public:
NotificationService() : notificationIdCounter(1) {
Gio::DBus::own_name(
Gio::DBus::BusType::SESSION,
"org.freedesktop.Notifications",
sigc::mem_fun(*this, &NotificationService::onBusAcquired),
{}, // Name acquired slot (optional)
{}, // Name lost slot (optional)
Gio::DBus::BusNameOwnerFlags::REPLACE);
}
void onBusAcquired(const Glib::RefPtr<Gio::DBus::Connection> &connection, const Glib::ustring &name);
private:
guint notificationIdCounter;
const Gio::DBus::InterfaceVTable &getMessageInterfaceVTable();
void on_method_call(const Glib::RefPtr<Gio::DBus::Connection> &connection,
const Glib::ustring &sender,
const Glib::ustring &object_path,
const Glib::ustring &interface_name,
const Glib::ustring &method_name,
const Glib::VariantContainerBase &parameters,
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation);
void handle_notify(const Glib::VariantContainerBase &parameters,
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation);
void createNotificationPopup(const Glib::ustring &title, const Glib::ustring &message);
};

View File

@@ -0,0 +1,10 @@
#pragma once
#include <giomm.h>
#include <gtkmm.h>
#include <memory>
#include "gdkmm/monitor.h"
class NotificationWidget {
public:
NotificationWidget(std::shared_ptr<Gdk::Monitor> monitor, const Glib::ustring &title, const Glib::ustring &message);
};