close one notification to close all

This commit is contained in:
2026-02-02 21:47:47 +01:00
parent ed1a9a8605
commit 6d9f016350
9 changed files with 137 additions and 33 deletions

View File

@@ -3,12 +3,13 @@
#include <memory>
#include "services/dbus/messages.hpp"
#include "widgets/notification/baseNotification.hpp"
#include "widgets/notification/notificationWindow.hpp"
#include "widgets/notification/spotifyNotification.hpp"
#include "gdkmm/display.h"
#include "glibmm/main.h"
#include "sigc++/adaptors/bind.h"
std::shared_ptr<NotificationController> NotificationController::instance = nullptr;
@@ -37,10 +38,20 @@ NotificationController::NotificationController() {
void NotificationController::showSpotifyNotification(MprisPlayer2Message mpris) {
return;
std::vector<std::shared_ptr<BaseNotification>> notifications;
uint64_t id = this->globalNotificationId++;
for (const auto &monitor : this->activeMonitors) {
auto notification = std::make_shared<SpotifyNotification>(monitor, mpris);
auto notification = std::make_shared<SpotifyNotification>(id, monitor, mpris);
notification->show();
notifications.push_back(notification);
notification->signal_close.connect([this, id = notification->getNotificationId()](int) {
closeNotification(id);
});
this->activeNotifications[id] = notifications;
Glib::signal_timeout().connect([notification]() {
notification->close();
@@ -48,19 +59,30 @@ void NotificationController::showSpotifyNotification(MprisPlayer2Message mpris)
},
DEFAULT_NOTIFICATION_TIMEOUT);
}
this->activeNotifications[id] = notifications;
}
void NotificationController::showNotificationOnAllMonitors(NotifyMessage notify) {
uint64_t id = this->globalNotificationId++;
std::vector<std::shared_ptr<BaseNotification>> notifications;
for (const auto &monitor : this->activeMonitors) {
auto notification = std::make_shared<NotificationWindow>(monitor, notify);
auto notification = std::make_shared<NotificationWindow>(id, monitor, notify);
notifications.push_back(notification);
auto timeout = notify.expire_timeout;
notification->show();
// -1 means use default timeout, 0 means never expire
if (timeout <= 0) {
timeout = DEFAULT_NOTIFICATION_TIMEOUT;
timeout = DEFAULT_NOTIFICATION_TIMEOUT;
}
notification->signal_close.connect(
[this, id = notification->getNotificationId()](int) {
closeNotification(id);
});
if (timeout == 0) {
continue;
}
@@ -71,4 +93,19 @@ void NotificationController::showNotificationOnAllMonitors(NotifyMessage notify)
},
timeout);
}
}
this->activeNotifications[id] = notifications;
}
void NotificationController::closeNotification(uint64_t notificationId) {
if (this->activeNotifications.find(notificationId) == this->activeNotifications.end()) {
return;
}
auto notifications = this->activeNotifications[notificationId];
for (const auto &notification : notifications) {
notification->close();
}
this->activeNotifications.erase(notificationId);
}