From 70b4638a754048eeffc877405222d4750c3ea548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 23 Jul 2024 18:32:23 +0200 Subject: [PATCH] osc: kitty notifications: implement query --- osc.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/osc.c b/osc.c index 0e092a9f..6a04386c 100644 --- a/osc.c +++ b/osc.c @@ -567,17 +567,19 @@ kitty_notification(struct terminal *term, char *string) { /* https://sw.kovidgoyal.net/kitty/desktop-notifications */ - char *payload = strchr(string, ';'); - if (payload == NULL) + char *payload_raw = strchr(string, ';'); + if (payload_raw == NULL) return; char *parameters = string; - *payload = '\0'; - payload++; + *payload_raw = '\0'; + payload_raw++; char *id = xstrdup("0"); /* The 'i' parameter */ char *icon_id = NULL; /* The 'g' parameter */ char *symbolic_icon = NULL; /* The 'n' parameter */ + char *payload = NULL; + bool focus = true; /* The 'a' parameter */ bool report = false; /* The 'a' parameter */ bool done = true; /* The 'd' parameter */ @@ -662,6 +664,25 @@ kitty_notification(struct terminal *term, char *string) payload_type = PAYLOAD_BODY; else if (strcmp(value, "icon") == 0) payload_type = PAYLOAD_ICON; + else if (strcmp(value, "?") == 0) { + /* Query capabilities */ + + char when_str[64]; + strcpy(when_str, "unfocused"); + if (!term->conf->desktop_notifications.inhibit_when_focused) + strcat(when_str, ",always"); + + const char *terminator = term->vt.osc.bel ? "\a" : "\033\\"; + + char reply[128]; + int n = xsnprintf( + reply, sizeof(reply), + "\033]99;i=%s:p=?;p=title,body,?:a=focus,report:o=%s:u=0,1,2%s", + id, when_str, terminator); + + term_to_slave(term, reply, n); + goto out; + } break; case 'o': @@ -701,11 +722,11 @@ kitty_notification(struct terminal *term, char *string) } if (base64) { - payload = base64_decode(payload, &payload_size); + payload = base64_decode(payload_raw, &payload_size); if (payload == NULL) goto out; } else { - payload = xstrdup(payload); + payload = xstrdup(payload_raw); payload_size = strlen(payload); }