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

@@ -0,0 +1,34 @@
#include "widgets/notification.hpp"
#include "gtk4-layer-shell.h"
NotificationWidget::NotificationWidget(std::shared_ptr<Gdk::Monitor> monitor, const Glib::ustring &title, const Glib::ustring &message) {
if (!monitor) return;
auto win = new Gtk::Window();
win->set_title(title);
win->set_default_size(300, 100);
auto label = Gtk::make_managed<Gtk::Label>(message);
label->set_use_markup(true);
win->set_child(*label);
gtk_layer_init_for_window(win->gobj());
gtk_layer_set_monitor(win->gobj(), monitor->gobj());
gtk_layer_set_layer(win->gobj(), GTK_LAYER_SHELL_LAYER_OVERLAY);
gtk_layer_set_anchor(win->gobj(), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
gtk_layer_set_anchor(win->gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
gtk_layer_set_margin(win->gobj(), GTK_LAYER_SHELL_EDGE_TOP, 2);
win->add_css_class("notification-popup");
win->show();
// Auto close after 3 seconds for demo purposes
Glib::signal_timeout().connect([win]() {
win->close();
delete win;
return false; // Don't repeat
},
3000);
}