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/ --- terminal.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 35cfe8aa..712b9d4e 100644 --- a/terminal.c +++ b/terminal.c @@ -1313,6 +1313,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED .ime_enabled = true, #endif + .kitty_notifications = tll_init(), }; pixman_region32_init(&term->render.last_overlay_clip); @@ -1817,6 +1818,13 @@ term_destroy(struct terminal *term) tll_remove(term->ptmx_paste_buffers, it); } + tll_foreach(term->kitty_notifications, it) { + free(it->item.id); + free(it->item.body); + free(it->item.title); + tll_remove(term->kitty_notifications, it); + } + sixel_fini(term); term_ime_reset(term); @@ -2022,6 +2030,13 @@ term_reset(struct terminal *term, bool hard) tll_remove(term->alt.sixel_images, it); } + tll_foreach(term->kitty_notifications, it) { + free(it->item.id); + free(it->item.title); + free(it->item.body); + tll_remove(term->kitty_notifications, it); + } + term->grapheme_shaping = term->conf->tweak.grapheme_shaping; #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED @@ -3566,8 +3581,10 @@ term_bell(struct terminal *term) } } - if (term->conf->bell.notify) - notify_notify(term, "Bell", "Bell in terminal"); + if (term->conf->bell.notify) { + notify_notify(term, "Bell", "Bell in terminal", + NOTIFY_ALWAYS, NOTIFY_URGENCY_NORMAL); + } if (term->conf->bell.flash) term_flash(term, 100); -- cgit v1.3