From b0bf8ca5f7034f6d95bc3b58082e719a81d99859 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 19 Jul 2024 15:04:28 +0200 Subject: osc/notify: add support for OSC-99, kitty desktop notifications This adds limited support for OSC-99, kitty desktop notifications[^1]. We support everything defined by the "protocol", except: * 'a': action to perform on notification activation. Since we don't trigger the notification ourselves (over D-Bus), we don't know a) which ID the notification got, or b) when it is clicked. * ... and that's it. Everything else is supported To be explicit, we *do* support: * Chunked notifications (d=0|1), allowing the application to append data to a notification in chunks, before it's finally displayed. * Plain UTF-8, or base64-encoded UTF-8 payload (e=0|1). * Notification identifier (i=xyz). * Payload type (p=title|body). * When to honor the notification (o=always|unfocused|invisible), with the following quirks: - we don't know when the window is invisible, thus it's treated as 'unfocused'. - the foot option 'notify-focus-inhibit' overrides 'always' * Urgency (u=0|1|2) [^1]: https://sw.kovidgoyal.net/kitty/desktop-notifications/ --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index dfa2b9ad..057924fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,8 @@ * Support for [in-band window resize notifications](https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83), private mode `2048`. +* Support for OSC-99 [_"Kitty desktop + notifications"_](https://sw.kovidgoyal.net/kitty/desktop-notifications/). [1707]: https://codeberg.org/dnkl/foot/issues/1707 [1738]: https://codeberg.org/dnkl/foot/issues/1738 -- cgit v1.3 From 0209458cc0b4fc502492253d3a9e9338e590a97e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 23 Jul 2024 07:09:54 +0200 Subject: changelog: new desktop-notifications config section --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 057924fa..861245b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,11 @@ private mode `2048`. * Support for OSC-99 [_"Kitty desktop notifications"_](https://sw.kovidgoyal.net/kitty/desktop-notifications/). +* `desktop-notifications.command` option, replaces `notify`. +* `desktop-notifications.inhibit-when-focused` option, replaces + `notify-focus-inhibit`. +* `${icon}` and `${urgency}` added to the + `desktop-notifications.command` template. [1707]: https://codeberg.org/dnkl/foot/issues/1707 [1738]: https://codeberg.org/dnkl/foot/issues/1738 @@ -118,6 +123,12 @@ ### Deprecated + +* `notify` option; replaced by `desktop-notifications.command`. +* `notify-focus-inhibit` option; replaced by + `desktop-notifications.inhibit-when-focused`. + + ### Removed ### Fixed -- cgit v1.3 From 045ead985c1e320f289704b6a995d48a5eccf59e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 23 Jul 2024 16:41:52 +0200 Subject: 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. --- CHANGELOG.md | 2 +- config.c | 2 +- doc/foot.ini.5.scd | 31 ++++++++++++++++++++++++++----- foot.ini | 2 +- notify.c | 27 ++++++++++++++++----------- notify.h | 1 + 6 files changed, 46 insertions(+), 19 deletions(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 861245b2..fe27afc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,7 +75,7 @@ * `desktop-notifications.command` option, replaces `notify`. * `desktop-notifications.inhibit-when-focused` option, replaces `notify-focus-inhibit`. -* `${icon}` and `${urgency}` added to the +* `${icon}`, `${urgency}` and `${action}` added to the `desktop-notifications.command` template. [1707]: https://codeberg.org/dnkl/foot/issues/1707 diff --git a/config.c b/config.c index a624f95c..be465abf 100644 --- a/config.c +++ b/config.c @@ -3225,7 +3225,7 @@ config_load(struct config *conf, const char *conf_path, parse_modifiers(XKB_MOD_NAME_SHIFT, 5, &conf->mouse.selection_override_modifiers); tokenize_cmdline( - "notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} -- ${title} ${body}", + "notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action} -- ${title} ${body}", &conf->desktop_notifications.command.argv.args); tokenize_cmdline("xdg-open ${url}", &conf->url.launch.argv.args); diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 5135e080..8e388107 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -462,11 +462,32 @@ Note: do not set *TERM* here; use the *term* option in the main behavior depends on the notification daemon in use, and how it has been configured. - For this to work, foot needs an XDG activation token. To this - end, foot will read the command's stdout; a line prefixed with - *xdgtoken=* will be recognized as containing the XDG - activation token: + For this to work, foot needs to know when the notification was + activated (as opposed to just dismissed), and it needs an XDG + activation token. + There are two parts to handle this. First, the notification + must define an action. For this purpose, foot definse the + template parameter *${action}*. It is intended to be used with + e.g. notify-send's *-A,--action* option. The contents of + *${action}* is not configurable, but will be on the form + 'name=label', where name is a notification internal reference + to the action, and label is what is displayed in the + notification. + + Second, foot needs to know when the notification activated, + and it needs to get hold of the XDG activation token. + + Both are expected to be printed on stdout. + + Foot expects the action name (not label) to be printed on a + single line. No prefix, no postfix. + + Foot expects the activation token to be printed on a single + line, prefixed with *xdgtoken=*. + + Example: + activate-foot xdgtoken=18179adf579a7a904ce73754964b1ec3 The expected format of stdout may change at any time. Please @@ -491,7 +512,7 @@ Note: do not set *TERM* here; use the *term* option in the main For *notify-send*, this can be achieved with the *--wait* option. - Default: _notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} -- ${title} ${body}_. + Default: _notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action} -- ${title} ${body}_. *inhibit-when-focused* Boolean. If enabled, foot will not display notifications if the diff --git a/foot.ini b/foot.ini index 33727dd3..707f09a2 100644 --- a/foot.ini +++ b/foot.ini @@ -47,7 +47,7 @@ # command-focused=no [desktop-notifications] -# command=notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} -- ${title} ${body} +# command=notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action} -- ${title} ${body} # inhibit-when-focused=yes diff --git a/notify.c b/notify.c index 4261268d..d12c3081 100644 --- a/notify.c +++ b/notify.c @@ -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; } diff --git a/notify.h b/notify.h index 90fbf9fc..ba017276 100644 --- a/notify.h +++ b/notify.h @@ -45,6 +45,7 @@ struct notification { * Used internally by notify */ + bool activated; /* User 'activated' the notification */ char *xdg_token; /* XDG activation token, from daemon */ pid_t pid; /* Notifier command PID */ -- cgit v1.3 From ecbec57a4749cc4162d2bb55dd14e1890b6dff31 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 23 Jul 2024 19:08:21 +0200 Subject: notify: split up the ${action} template parameter Split it up into two, ${action-name} and ${action-label}. Dunstify, for example, has a different syntax compared to notify-send: notify-send: default=foobar dunstify: default,foobar --- CHANGELOG.md | 4 ++-- config.c | 2 +- doc/foot.ini.5.scd | 14 ++++++-------- foot.ini | 2 +- notify.c | 10 ++++------ 5 files changed, 14 insertions(+), 18 deletions(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index fe27afc5..65ddfc3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,8 +75,8 @@ * `desktop-notifications.command` option, replaces `notify`. * `desktop-notifications.inhibit-when-focused` option, replaces `notify-focus-inhibit`. -* `${icon}`, `${urgency}` and `${action}` added to the - `desktop-notifications.command` template. +* `${icon}`, `${urgency}`,`${action-name}` and `${action-label}` added + to the `desktop-notifications.command` template. [1707]: https://codeberg.org/dnkl/foot/issues/1707 [1738]: https://codeberg.org/dnkl/foot/issues/1738 diff --git a/config.c b/config.c index be465abf..307d348d 100644 --- a/config.c +++ b/config.c @@ -3225,7 +3225,7 @@ config_load(struct config *conf, const char *conf_path, parse_modifiers(XKB_MOD_NAME_SHIFT, 5, &conf->mouse.selection_override_modifiers); tokenize_cmdline( - "notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action} -- ${title} ${body}", + "notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action-name},${action-label} --print-id -- ${title} ${body}", &conf->desktop_notifications.command.argv.args); tokenize_cmdline("xdg-open ${url}", &conf->url.launch.argv.args); diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 40106223..a6c20e6e 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -470,12 +470,9 @@ Note: do not set *TERM* here; use the *term* option in the main There are two parts to handle this. First, the notification must define an action. For this purpose, foot definse the - template parameter *${action}*. It is intended to be used with - e.g. notify-send's *-A,--action* option. The contents of - *${action}* is not configurable, but will be on the form - 'name=label', where name is a notification internal reference - to the action, and label is what is displayed in the - notification. + template parameters *${action-name}* and + *${action-label}*. They are intended to be used with + e.g. notify-send's *-A,--action* option. Second, foot needs to know when the notification activated, and it needs to get hold of the XDG activation token. @@ -489,7 +486,7 @@ Note: do not set *TERM* here; use the *term* option in the main line, prefixed with *xdgtoken=*. Example: - activate-foot + default xdgtoken=18179adf579a7a904ce73754964b1ec3 The expected format of stdout may change at any time. Please @@ -499,7 +496,8 @@ Note: do not set *TERM* here; use the *term* option in the main reporting the XDG activation token in any way. This means window activation will not work by default. - Default: _notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action} -- ${title} ${body}_. + Default: _notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action-name},${action-label} --print-id -- ${title} ${body}_. + *inhibit-when-focused* Boolean. If enabled, foot will not display notifications if the diff --git a/foot.ini b/foot.ini index 707f09a2..c743182c 100644 --- a/foot.ini +++ b/foot.ini @@ -47,7 +47,7 @@ # command-focused=no [desktop-notifications] -# command=notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action} -- ${title} ${body} +# command=notify-send --wait --app-name ${app-id} --icon ${icon} --urgency ${urgency} --action ${action-name},${action-label} --print-id -- ${title} ${body} # inhibit-when-focused=yes diff --git a/notify.c b/notify.c index 2dd303db..71852c6a 100644 --- a/notify.c +++ b/notify.c @@ -78,7 +78,6 @@ fdm_notify_stdout(struct fdm *fdm, int fd, int events, void *data) const struct terminal *term = data; struct notification *notif = NULL; - /* Find notification */ tll_foreach(term->active_notifications, it) { if (it->item.stdout_fd == fd) { @@ -225,13 +224,13 @@ notify_notify(struct terminal *term, struct notification *notif) ? "normal" : "critical"; if (!spawn_expand_template( - &term->conf->desktop_notifications.command, 7, + &term->conf->desktop_notifications.command, 8, (const char *[]){ - "app-id", "window-title", "icon", "title", "body", "urgency", "action"}, + "app-id", "window-title", "icon", "title", "body", "urgency", "action-name", "action-label"}, (const char *[]){ term->app_id ? term->app_id : term->conf->app_id, term->window_title, icon_name_or_path, title, body, urgency_str, - "default=Click to activate"}, + "default", "Click to activate"}, &argc, &argv)) { return false; @@ -253,7 +252,7 @@ notify_notify(struct terminal *term, struct notification *notif) notif->title = NULL; notif->body = NULL; notif->icon_id = NULL; - notif->icon_symbolic_name= NULL; + notif->icon_symbolic_name = NULL; notif->icon_data = NULL; notif->icon_data_sz = 0; notif = &tll_back(term->active_notifications); @@ -262,7 +261,6 @@ notify_notify(struct terminal *term, struct notification *notif) if (stdout_fds[0] >= 0) { - xassert(notif->xdg_token == NULL); fdm_add(term->fdm, stdout_fds[0], EPOLLIN, &fdm_notify_stdout, (void *)term); } -- cgit v1.3