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/
This commit is contained in:
Daniel Eklöf 2024-07-19 15:04:28 +02:00
parent 45c7cd3f74
commit b0bf8ca5f7
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
10 changed files with 322 additions and 15 deletions

View file

@ -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);