notify: don't focus/report on notification dismissal

Only do it when the notification was activated.

Here, activated means the 'click to activate' notification action was
triggered.

How do we tie everything together?

First, we add a new template parameter, ${action}. It's intended to be
used with e.g. notify-send's --action option.

When the action is triggered, notify-send prints its name on stdout,
on a separate line. Look for this in stdout. Only if we've seen it do
we focus/report the notification.
This commit is contained in:
Daniel Eklöf 2024-07-23 16:41:52 +02:00
parent 55a4e59ef9
commit 045ead985c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
6 changed files with 46 additions and 19 deletions

View file

@ -54,8 +54,11 @@ consume_stdout(struct notification *notif, bool eof)
} else if (!eof)
break;
if (strcmp(line, "activate-foot") == 0)
notif->activated = true;
/* Check for 'xdgtoken=xyz' */
if (len > 9 && memcmp(line, "xdgtoken=", 9) == 0) {
else if (len > 9 && memcmp(line, "xdgtoken=", 9) == 0) {
notif->xdg_token = xstrndup(&line[9], len - 9);
LOG_DBG("XDG token: \"%s\"", notif->xdg_token);
}
@ -133,12 +136,13 @@ notif_done(struct reaper *reaper, pid_t pid, int status, void *data)
LOG_DBG("notification %s dismissed", notif->id);
if (notif->focus) {
LOG_DBG("focus window on notification activation: \"%s\"", notif->xdg_token);
if (notif->activated && notif->focus) {
LOG_DBG("focus window on notification activation: \"%s\"",
notif->xdg_token);
wayl_activate(term->wl, term->window, notif->xdg_token);
}
if (notif->report) {
if (notif->activated && notif->report) {
xassert(notif->id != NULL);
LOG_DBG("sending notification report to client");
@ -221,13 +225,14 @@ notify_notify(struct terminal *term, struct notification *notif)
? "normal" : "critical";
if (!spawn_expand_template(
&term->conf->desktop_notifications.command, 6,
(const char *[]){
"app-id", "window-title", "icon", "title", "body", "urgency"},
(const char *[]){
term->app_id ? term->app_id : term->conf->app_id,
term->window_title, icon_name_or_path, title, body, urgency_str},
&argc, &argv))
&term->conf->desktop_notifications.command, 7,
(const char *[]){
"app-id", "window-title", "icon", "title", "body", "urgency", "action"},
(const char *[]){
term->app_id ? term->app_id : term->conf->app_id,
term->window_title, icon_name_or_path, title, body, urgency_str,
"activate-foot=Click to activate"},
&argc, &argv))
{
return false;
}