aboutsummaryrefslogtreecommitdiff
path: root/notify.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-07-23 09:53:30 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-07-23 09:53:30 +0000
commitb3108e1ad23387327d6cc7ebfdb20307878dd5c3 (patch)
tree650525b6f06eff41a62a3895a4580a699a374be5 /notify.c
parentosc: kitty notifications: updated support for icons (diff)
notify: separate active notifications from unfinished kitty notifications
This fixes an issue where it wasn't possible to trigger multiple notifications with the same kitty notification ID. This is something that works in kitty, and there's no reason why it shouldn't work. The issue was that we track stdout, and the notification helper's PID in the notification struct. Thus, when a notification is being displayed, we can't re-use the same notification struct instance for another notification. This patch fixes this by adding a new notification list, 'active_notifications'. Whenever we detect that we need to track the helper (notification want's to either focus the window on activation, or send an event to the application), we add a copy of the notification to the 'active' list. The notification can then be removed from the 'kitty' list, allowing kitty notifications to re-use the same ID over and over again, even if old notifications are still being displayed.
Diffstat (limited to 'notify.c')
-rw-r--r--notify.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/notify.c b/notify.c
index 67cf5bd1..af89838b 100644
--- a/notify.c
+++ b/notify.c
@@ -75,7 +75,7 @@ fdm_notify_stdout(struct fdm *fdm, int fd, int events, void *data)
/* Find notification */
- tll_foreach(term->notifications, it) {
+ tll_foreach(term->active_notifications, it) {
if (it->item.stdout_fd == fd) {
notif = &it->item;
break;
@@ -124,7 +124,7 @@ notif_done(struct reaper *reaper, pid_t pid, int status, void *data)
{
struct terminal *term = data;
- tll_foreach(term->notifications, it) {
+ tll_foreach(term->active_notifications, it) {
struct notification *notif = &it->item;
if (notif->pid != pid)
continue;
@@ -148,17 +148,17 @@ notif_done(struct reaper *reaper, pid_t pid, int status, void *data)
}
notify_free(term, notif);
- tll_remove(term->notifications, it);
+ tll_remove(term->active_notifications, it);
return;
}
}
bool
-notify_notify(const struct terminal *term, struct notification *notif)
+notify_notify(struct terminal *term, struct notification *notif)
{
xassert(notif->xdg_token == NULL);
xassert(notif->pid == 0);
- xassert(notif->stdout_fd == 0);
+ xassert(notif->stdout_fd <= 0);
xassert(notif->stdout_data == NULL);
notif->pid = -1;
@@ -187,6 +187,8 @@ notify_notify(const struct terminal *term, struct notification *notif)
}
}
+ bool track_notification = notif->focus || notif->report;
+
LOG_DBG("notify: title=\"%s\", body=\"%s\"", title, body);
xassert(title != NULL);
@@ -230,13 +232,25 @@ notify_notify(const struct terminal *term, struct notification *notif)
LOG_DBG(" argv[%zu] = \"%s\"", i, argv[i]);
int stdout_fds[2] = {-1, -1};
- if ((notif->focus || notif->report) &&
- pipe2(stdout_fds, O_CLOEXEC | O_NONBLOCK) < 0)
- {
- LOG_WARN("failed to create stdout pipe");
- /* Non-fatal */
+ if (track_notification) {
+ if (pipe2(stdout_fds, O_CLOEXEC | O_NONBLOCK) < 0) {
+ LOG_WARN("failed to create stdout pipe");
+ track_notification = false;
+ /* Non-fatal */
+ } else {
+ tll_push_back(term->active_notifications, *notif);
+ notif->id = NULL;
+ notif->title = NULL;
+ notif->body = NULL;
+ notif->icon_id = NULL;
+ notif->icon_symbolic_name= NULL;
+ notif->icon_data = NULL;
+ notif->icon_data_sz = 0;
+ notif = &tll_back(term->active_notifications);
+ }
}
+
if (stdout_fds[0] >= 0) {
xassert(notif->xdg_token == NULL);
fdm_add(term->fdm, stdout_fds[0], EPOLLIN,
@@ -247,7 +261,7 @@ notify_notify(const struct terminal *term, struct notification *notif)
int devnull = open("/dev/null", O_RDONLY);
pid_t pid = spawn(
term->reaper, NULL, argv, devnull, stdout_fds[1], -1,
- &notif_done, (void *)term, NULL);
+ track_notification ? &notif_done : NULL, (void *)term, NULL);
if (stdout_fds[1] >= 0) {
/* Close write-end of stdout pipe */