hover pauses notification

This commit is contained in:
2026-02-02 23:42:08 +01:00
parent 6d9f016350
commit 9898c48c67
6 changed files with 199 additions and 58 deletions

View File

@@ -7,8 +7,9 @@
#include "widgets/notification/notificationWindow.hpp"
#include "widgets/notification/spotifyNotification.hpp"
#include <algorithm>
#include "gdkmm/display.h"
#include "glibmm/main.h"
#include "sigc++/adaptors/bind.h"
std::shared_ptr<NotificationController> NotificationController::instance = nullptr;
@@ -36,32 +37,6 @@ 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>(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();
return false; // Don't repeat
},
DEFAULT_NOTIFICATION_TIMEOUT);
}
this->activeNotifications[id] = notifications;
}
void NotificationController::showNotificationOnAllMonitors(NotifyMessage notify) {
uint64_t id = this->globalNotificationId++;
@@ -74,27 +49,79 @@ void NotificationController::showNotificationOnAllMonitors(NotifyMessage notify)
auto timeout = notify.expire_timeout;
notification->show();
// -1 means use default timeout, 0 means never expire
if (timeout <= 0) {
if (timeout < 0) {
timeout = DEFAULT_NOTIFICATION_TIMEOUT;
}
notification->signal_close.connect(
[this, id = notification->getNotificationId()](int) {
closeNotification(id);
});
notification->signal_close.connect([this, id = notification->getNotificationId()](int) {
closeNotification(id);
});
notification->signal_hover_changed.connect([this, id = notification->getNotificationId()](bool hovered) {
updateHoverState(id, hovered);
});
if (timeout == 0) {
continue;
}
Glib::signal_timeout().connect([notification]() {
notification->close();
return false; // Don't repeat
},
timeout);
notification->startAutoClose(timeout);
}
this->activeNotifications[id] = notifications;
}
void NotificationController::showSpotifyNotification(MprisPlayer2Message mpris) {
std::vector<std::shared_ptr<BaseNotification>> notifications;
uint64_t id = this->globalNotificationId++;
for (const auto &monitor : this->activeMonitors) {
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);
});
notification->signal_hover_changed.connect([this, id = notification->getNotificationId()](bool hovered) {
updateHoverState(id, hovered);
});
notification->startAutoClose(10000);
}
this->activeNotifications[id] = notifications;
}
void NotificationController::updateHoverState(uint64_t notificationId, bool isHovered) {
if (this->activeNotifications.find(notificationId) == this->activeNotifications.end()) {
return;
}
int &count = this->hoverCounts[notificationId];
if (isHovered) {
count += 1;
} else {
count = std::max(0, count - 1);
}
auto &notifications = this->activeNotifications[notificationId];
if (count > 0) {
for (const auto &notification : notifications) {
notification->pauseAutoClose();
}
} else {
for (const auto &notification : notifications) {
notification->resumeAutoClose();
}
}
}
void NotificationController::closeNotification(uint64_t notificationId) {
@@ -108,4 +135,5 @@ void NotificationController::closeNotification(uint64_t notificationId) {
}
this->activeNotifications.erase(notificationId);
}
this->hoverCounts.erase(notificationId);
}