Compare commits

...

4 Commits

Author SHA1 Message Date
dc325834c7 nice spotify notification 2026-02-01 01:53:47 +01:00
caca94bc6a vibed a cached downloader for images 2026-02-01 00:57:16 +01:00
13278d518a add notifications 2026-01-31 22:46:19 +01:00
8283531748 fix six seven 2026-01-31 20:08:29 +01:00
17 changed files with 674 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -DNDEBUG -Wall -Wextra -Wpedantic -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic")
find_package(PkgConfig REQUIRED)
@@ -28,11 +28,16 @@ target_sources(bar_lib
src/widgets/clock.cpp
src/widgets/date.cpp
src/widgets/notification.cpp
src/widgets/volumeWidget.cpp
src/widgets/webWidget.cpp
src/services/hyprland.cpp
src/services/notificationController.cpp
src/services/textureCache.cpp
src/services/tray.cpp
src/services/dbus/notification.cpp
src/services/dbus/mpris.cpp
src/widgets/tray.cpp
src/widgets/controlCenter.cpp

View File

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

View File

@@ -37,4 +37,11 @@ public:
tokens.push_back(input.substr(start));
return tokens;
}
static std::string trimToSize(const std::string &input, size_t maxSize) {
if (input.length() <= maxSize) {
return input;
}
return input.substr(0, maxSize) + "...";
}
};

View File

@@ -0,0 +1,35 @@
#pragma once
#include <giomm.h>
#include <string>
#include <vector>
class MprisController {
public:
struct MprisPlayer2Message {
std::string title;
std::string artist;
std::string artwork_url;
std::function<void()> play_pause;
std::function<void()> next;
std::function<void()> previous;
};
MprisController();
void toggle_play();
void next_song();
void previous_song();
private:
Glib::RefPtr<Gio::DBus::Connection> m_connection;
Glib::RefPtr<Gio::DBus::Proxy> m_proxy;
void on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result);
void launchNotification();
// Called when the song changes
void on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
const std::vector<Glib::ustring> &invalidated_properties);
};

View File

@@ -0,0 +1,74 @@
#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,27 @@
#pragma once
#include <memory>
#include <vector>
#include "services/dbus/mpris.hpp"
#include "gdkmm/monitor.h"
#include "gtkmm/window.h"
class NotificationController {
static std::shared_ptr<NotificationController> instance;
public:
static std::shared_ptr<NotificationController> getInstance() {
if (!NotificationController::instance) {
NotificationController::instance = std::shared_ptr<NotificationController>(new NotificationController());
}
return NotificationController::instance;
}
void showSpotifyNotification(MprisController::MprisPlayer2Message mpris);
void showNotificationOnAllMonitors(const std::string &title, const std::string &message);
private:
NotificationController();
std::vector<std::shared_ptr<Gdk::Monitor>> activeMonitors;
void baseWindowSetup(std::shared_ptr<Gtk::Window> win, std::shared_ptr<Gdk::Monitor> monitor);
};

View File

@@ -0,0 +1,19 @@
#pragma once
#include <string>
#include <unordered_map>
#include "gdkmm/texture.h"
#include "glibmm/refptr.h"
class TextureCacheService {
public:
static TextureCacheService *getInstance();
Glib::RefPtr<Gdk::Texture> getTexture(const std::string &url);
private:
TextureCacheService() = default;
std::unordered_map<std::string, Glib::RefPtr<Gdk::Texture>> cache;
};

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);
};

View File

@@ -58,6 +58,13 @@ button {
background-color: #111111;
}
.flat-button {
background-color: #333333;
color: #ffffff;
padding: 2px 4px;
border-radius: 10px;
}
.workspace-pill {
padding: 2px 5px;
margin-right: 6px;
@@ -142,3 +149,15 @@ button {
opacity: 1;
}
}
.notification-popup {
border-radius: 8px;
padding: 8px 12px;
background: rgba(30, 30, 30, 0.948);
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
border: 1px solid rgba(80, 80, 80, 0.8);
font-size: 14px;
}
.notification-button-box {
}

View File

@@ -1,13 +1,16 @@
#include "app.hpp"
#include <exception>
#include <iostream>
#include <sigc++/sigc++.h>
#include <vector>
#include "services/dbus/notification.hpp"
#include "services/dbus/mpris.hpp"
App::App() {
this->app = Gtk::Application::create("org.example.mybar");
this->setupServices();
this->hyprlandService = HyprlandService::getInstance();
this->notificationService = std::make_shared<NotificationService>();
this->mprisController = std::make_shared<MprisController>();
app->signal_activate().connect([&]() {
auto display = Gdk::Display::get_default();

View File

@@ -1,5 +1,4 @@
#include "components/workspaceIndicator.hpp"
#include <iostream>
#include "gtkmm/gestureclick.h"
#include "gtkmm/label.h"
@@ -14,7 +13,7 @@ WorkspaceIndicator::WorkspaceIndicator(int id, std::string label, sigc::slot<voi
auto gesture = Gtk::GestureClick::create();
gesture->set_button(GDK_BUTTON_PRIMARY);
gesture->signal_released().connect([this, id, onClick](int, double, double) {
gesture->signal_released().connect([id, onClick](int, double, double) {
onClick(
id);
});
@@ -22,9 +21,11 @@ WorkspaceIndicator::WorkspaceIndicator(int id, std::string label, sigc::slot<voi
overlay->add_controller(gesture);
overlay->add_css_class("workspace-pill");
if (id == 6 || id == 7) {
auto indicator = Gtk::make_managed<Gtk::Label>(id == 6 ? "🫱🏻" : "🫲🏻");
indicator->add_css_class(id == 6 ? "workspace-pill-six" : "workspace-pill-seven");
int sixSevenCheck = std::stoi(label);
if (sixSevenCheck == 6 || sixSevenCheck == 7) {
auto indicator = Gtk::make_managed<Gtk::Label>(sixSevenCheck == 6 ? "🫱🏻" : "🫲🏻");
indicator->add_css_class(sixSevenCheck == 6 ? "workspace-pill-six" : "workspace-pill-seven");
indicator->set_valign(Gtk::Align::END);
overlay->set_child(*indicator);
overlay->add_overlay(*numLabel);

132
src/services/dbus/mpris.cpp Normal file
View File

@@ -0,0 +1,132 @@
#include "services/dbus/mpris.hpp"
#include <iostream>
#include <map>
#include "helpers/string.hpp"
#include "services/notificationController.hpp"
#include "giomm/dbusconnection.h"
#include "giomm/dbusproxy.h"
MprisController::MprisController() {
// 1. Connect to the Session Bus
Gio::DBus::Connection::get(
Gio::DBus::BusType::SESSION,
sigc::mem_fun(*this, &MprisController::on_bus_connected));
}
void MprisController::on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result) {
if (!result) {
std::cerr << "DBus Connection Error: null async result" << std::endl;
return;
}
try {
m_connection = Gio::DBus::Connection::get_finish(result);
std::string player_bus_name = "org.mpris.MediaPlayer2.spotify";
m_proxy = Gio::DBus::Proxy::create_sync(
m_connection,
player_bus_name, // The Bus Name
"/org/mpris/MediaPlayer2", // The Object Path
"org.mpris.MediaPlayer2.Player" // The Interface
);
if (m_proxy) {
std::cout << "Connected to: " << player_bus_name << std::endl;
// uncomment if launch notification on start
launchNotification();
m_proxy->signal_properties_changed().connect(
sigc::mem_fun(*this, &MprisController::on_properties_changed));
}
} catch (const Glib::Error &ex) {
std::cerr << "DBus Connection Error: " << ex.what() << std::endl;
}
}
void MprisController::launchNotification() {
if (!m_proxy) {
return;
}
Glib::VariantBase metadata_var;
m_proxy->get_cached_property(metadata_var, "Metadata");
if (!metadata_var) {
std::cout << "No metadata available." << std::endl;
return;
}
using MetadataMap = std::map<Glib::ustring, Glib::VariantBase>;
MetadataMap metadata_map;
Glib::Variant<MetadataMap> variant_dict =
Glib::VariantBase::cast_dynamic<Glib::Variant<MetadataMap>>(metadata_var);
metadata_map = variant_dict.get();
std::string title, artist, artwork_url;
if (metadata_map.count("xesam:title")) {
auto title_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(metadata_map["xesam:title"]);
title = title_var.get();
}
if (metadata_map.count("xesam:artist")) {
auto artist_var = metadata_map["xesam:artist"];
if (artist_var.is_of_type(Glib::VariantType("as"))) {
auto artists = Glib::VariantBase::cast_dynamic<Glib::Variant<std::vector<Glib::ustring>>>(artist_var).get();
if (!artists.empty()) {
artist = artists[0]; // Take the first artist
}
}
}
if (metadata_map.count("mpris:artUrl")) {
auto art_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(metadata_map["mpris:artUrl"]);
artwork_url = art_var.get();
}
auto notifactionController = NotificationController::getInstance();
MprisController::MprisPlayer2Message mpris;
mpris.title = StringHelper::trimToSize(title, 30);
mpris.artist = StringHelper::trimToSize(artist, 30);
mpris.artwork_url = artwork_url;
mpris.play_pause = [this]() { this->toggle_play(); };
mpris.next = [this]() { this->next_song(); };
mpris.previous = [this]() { this->previous_song(); };
notifactionController->showSpotifyNotification(mpris);
}
void MprisController::on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
const std::vector<Glib::ustring> &) {
if (changed_properties.find("Metadata") != changed_properties.end()) {
launchNotification();
}
}
void MprisController::previous_song() {
if (m_proxy) {
m_proxy->call("Previous");
}
}
void MprisController::toggle_play() {
if (m_proxy) {
m_proxy->call("PlayPause");
}
}
void MprisController::next_song() {
if (m_proxy) {
m_proxy->call("Next");
}
}

View File

@@ -0,0 +1,74 @@
#include "services/dbus/notification.hpp"
#include <iostream>
#include "services/notificationController.hpp"
#include "widgets/notification.hpp"
void NotificationService::onBusAcquired(const Glib::RefPtr<Gio::DBus::Connection> &connection, const Glib::ustring &name) {
std::cout << "Acquired bus name: " << name << std::endl;
auto introspection_data = Gio::DBus::NodeInfo::create_for_xml(introspection_xml);
// Register the object at the standard path
connection->register_object(
"/org/freedesktop/Notifications",
introspection_data->lookup_interface("org.freedesktop.Notifications"),
getMessageInterfaceVTable());
}
const Gio::DBus::InterfaceVTable &NotificationService::getMessageInterfaceVTable() {
static Gio::DBus::InterfaceVTable vtable(
sigc::mem_fun(*this, &NotificationService::on_method_call));
return vtable;
}
void NotificationService::on_method_call(const Glib::RefPtr<Gio::DBus::Connection> &,
const Glib::ustring &,
const Glib::ustring &,
const Glib::ustring &,
const Glib::ustring &method_name,
const Glib::VariantContainerBase &parameters,
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation) {
if (method_name == "Notify") {
handle_notify(parameters, invocation);
} else if (method_name == "GetCapabilities") {
auto caps = std::vector<Glib::ustring>{"body"};
invocation->return_value(Glib::VariantContainerBase::create_tuple(
Glib::Variant<std::vector<Glib::ustring>>::create(caps)));
} else if (method_name == "GetServerInformation") {
invocation->return_value(Glib::VariantContainerBase::create_tuple({Glib::Variant<Glib::ustring>::create("MyGtkmmNotifier"),
Glib::Variant<Glib::ustring>::create("Custom"),
Glib::Variant<Glib::ustring>::create("1.0"),
Glib::Variant<Glib::ustring>::create("1.2")}));
} else {
// Handle other methods or return error
invocation->return_value(Glib::VariantContainerBase());
}
}
void NotificationService::handle_notify(const Glib::VariantContainerBase &parameters,
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation) {
Glib::VariantBase app_name_var, replaces_id_var, app_icon_var, summary_var, body_var, actions_var, hints_var, timeout_var;
parameters.get_child(app_name_var, 0);
parameters.get_child(summary_var, 3);
parameters.get_child(body_var, 4);
Glib::ustring summary = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(summary_var).get();
Glib::ustring body = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(body_var).get();
std::cout << "Notification Received: " << summary << " - " << body << std::endl;
createNotificationPopup(summary, body);
guint id = notificationIdCounter++;
invocation->return_value(Glib::VariantContainerBase::create_tuple(
Glib::Variant<guint>::create(id)));
}
void NotificationService::createNotificationPopup(const Glib::ustring &title, const Glib::ustring &message) {
auto controller = NotificationController::getInstance();
controller->showNotificationOnAllMonitors(title, message);
}

View File

@@ -1,6 +1,5 @@
#include "services/hyprland.hpp"
#include <cstdlib>
#include <cstring>
#include <glib-unix.h>
#include <glib.h>

View File

@@ -0,0 +1,152 @@
#include "services/notificationController.hpp"
#include <memory>
#include "services/dbus/mpris.hpp"
#include "services/textureCache.hpp"
#include "gdkmm/display.h"
#include "giomm/listmodel.h"
#include "glibmm/main.h"
#include "gtk4-layer-shell.h"
#include "gtkmm/box.h"
#include "gtkmm/button.h"
#include "gtkmm/centerbox.h"
#include "gtkmm/image.h"
#include "gtkmm/label.h"
#include "gtkmm/window.h"
std::shared_ptr<NotificationController> NotificationController::instance = nullptr;
NotificationController::NotificationController() {
if (NotificationController::instance) {
throw std::runtime_error("use getInstance()!");
}
auto display = Gdk::Display::get_default();
if (!display) {
return;
}
auto monitors = display->get_monitors();
if (!monitors) {
return;
}
for (guint i = 0; i < monitors->get_n_items(); ++i) {
auto monitor = std::dynamic_pointer_cast<Gdk::Monitor>(
monitors->get_object(i));
this->activeMonitors.push_back(monitor);
}
}
void NotificationController::showSpotifyNotification(MprisController::MprisPlayer2Message mpris) {
for (const auto &monitor : this->activeMonitors) {
auto win = std::make_shared<Gtk::Window>();
win->set_title(mpris.title);
this->baseWindowSetup(win, monitor);
auto container = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 10);
if (auto texture = TextureCacheService::getInstance()->getTexture(mpris.artwork_url)) {
auto img = Gtk::make_managed<Gtk::Image>(texture);
img->set_pixel_size(64);
container->append(*img);
}
auto rightArea = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 5);
rightArea->set_halign(Gtk::Align::CENTER);
rightArea->set_valign(Gtk::Align::CENTER);
// make sure rigfht area takes the remaining space
rightArea->set_hexpand(true);
// also set a max width
auto title_label = Gtk::make_managed<Gtk::Label>("<b>" + mpris.title + "</b>");
title_label->set_use_markup(true);
title_label->set_halign(Gtk::Align::START);
rightArea->append(*title_label);
auto artistLabel = Gtk::make_managed<Gtk::Label>(mpris.artist);
artistLabel->set_halign(Gtk::Align::CENTER);
rightArea->append(*artistLabel);
auto buttonBox = Gtk::make_managed<Gtk::CenterBox>();
buttonBox->add_css_class("notification-button-box");
buttonBox->set_hexpand(true);
auto backButton = Gtk::make_managed<Gtk::Button>("<");
backButton->add_css_class("flat-button");
auto playPauseButton = Gtk::make_managed<Gtk::Button>("=<");
playPauseButton->add_css_class("flat-button");
auto nextButton = Gtk::make_managed<Gtk::Button>(">");
nextButton->add_css_class("flat-button");
backButton->signal_clicked().connect([mpris]() {
if (mpris.previous) {
mpris.previous();
}
});
playPauseButton->signal_clicked().connect([mpris]() {
if (mpris.play_pause) {
mpris.play_pause();
}
});
nextButton->signal_clicked().connect([mpris]() {
if (mpris.next) {
mpris.next();
}
});
buttonBox->set_start_widget(*backButton);
buttonBox->set_center_widget(*playPauseButton);
buttonBox->set_end_widget(*nextButton);
// rightArea->append(*buttonBox);
container->append(*rightArea);
win->set_child(*container);
win->show();
Glib::signal_timeout().connect([win]() {
win->close();
return false; // Don't repeat
},
3000);
}
}
void NotificationController::baseWindowSetup(std::shared_ptr<Gtk::Window> win, std::shared_ptr<Gdk::Monitor> monitor) {
win->set_default_size(300, 100);
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");
}
void NotificationController::showNotificationOnAllMonitors(const std::string &title, const std::string &message) {
for (const auto &monitor : this->activeMonitors) {
auto win = std::make_shared<Gtk::Window>();
win->set_title(title);
this->baseWindowSetup(win, monitor);
auto label = Gtk::make_managed<Gtk::Label>(message);
label->set_use_markup(true);
win->set_child(*label);
win->show();
Glib::signal_timeout().connect([win]() {
win->close();
return false; // Don't repeat
},
3000);
}
}

View File

@@ -0,0 +1,67 @@
#include "services/textureCache.hpp"
#include <curl/curl.h>
#include <vector>
#include "glibmm/bytes.h"
namespace {
size_t write_to_buffer(void *contents, size_t size, size_t nmemb, void *userp) {
auto *buffer = static_cast<std::vector<unsigned char> *>(userp);
auto total = size * nmemb;
auto *bytes = static_cast<unsigned char *>(contents);
buffer->insert(buffer->end(), bytes, bytes + total);
return total;
}
Glib::RefPtr<Gdk::Texture> download_texture_from_url(const std::string &url) {
if (url.empty()) {
return {};
}
CURL *curl = curl_easy_init();
if (!curl) {
return {};
}
std::vector<unsigned char> buffer;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_buffer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "bar/1.0");
auto res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK || buffer.empty()) {
return {};
}
auto bytes = Glib::Bytes::create(buffer.data(), buffer.size());
return Gdk::Texture::create_from_bytes(bytes);
}
} // namespace
TextureCacheService *TextureCacheService::getInstance() {
static TextureCacheService instance;
return &instance;
}
Glib::RefPtr<Gdk::Texture> TextureCacheService::getTexture(const std::string &url) {
if (url.empty()) {
return {};
}
auto it = cache.find(url);
if (it != cache.end()) {
return it->second;
}
auto texture = download_texture_from_url(url);
if (texture) {
cache.emplace(url, texture);
}
return texture;
}

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);
}