aboutsummaryrefslogtreecommitdiff
path: root/osc.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-07-25 17:24:28 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-07-25 17:24:28 +0000
commitc4d9f8a8ff4d65b43defb8d63e775e8b91f82bed (patch)
tree3d83f7b953c8efe2a3b2b5732831f4dca9925171 /osc.c
parentosc: kitty notification: implement 'close' events (diff)
osc: kitty notifications: implement the 'close' request
Add a new config option, desktop-notifications.close, defining what to execute to close a notification. It has a single template parameter, ${id}, that is expanded to the external notification ID foot may have picked up from the notification helper. notify-send does not support closing notifications, and it appears impossible to pass an *unsigned* integer as argument to gdbus. Hence no default value for the new 'close' option. Example: printf '\e]99;i=123;this is a notification\e\\' printf '\e]99;i=123:p=close;\e\\'
Diffstat (limited to 'osc.c')
-rw-r--r--osc.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/osc.c b/osc.c
index 1da32447..2eaed869 100644
--- a/osc.c
+++ b/osc.c
@@ -590,6 +590,7 @@ kitty_notification(struct terminal *term, char *string)
enum {
PAYLOAD_TITLE,
PAYLOAD_BODY,
+ PAYLOAD_CLOSE,
PAYLOAD_ICON,
} payload_type = PAYLOAD_TITLE; /* The 'p' parameter */
@@ -672,6 +673,8 @@ kitty_notification(struct terminal *term, char *string)
payload_type = PAYLOAD_TITLE;
else if (streq(value, "body"))
payload_type = PAYLOAD_BODY;
+ else if (streq(value, "close"))
+ payload_type = PAYLOAD_CLOSE;
else if (streq(value, "icon"))
payload_type = PAYLOAD_ICON;
else if (streq(value, "?")) {
@@ -687,7 +690,7 @@ kitty_notification(struct terminal *term, char *string)
char reply[128];
int n = xsnprintf(
reply, sizeof(reply),
- "\033]99;i=%s:p=?;p=title,body,icon:a=focus,report:o=%s:u=0,1,2:c=1%s",
+ "\033]99;i=%s:p=?;p=title,body,close,icon:a=focus,report:o=%s:u=0,1,2:c=1%s",
id, when_str, terminator);
term_to_slave(term, reply, n);
@@ -815,6 +818,10 @@ kitty_notification(struct terminal *term, char *string)
break;
}
+ case PAYLOAD_CLOSE:
+ /* Ignore payload */
+ break;
+
case PAYLOAD_ICON:
if (notif->icon_data == NULL) {
notif->icon_data = (uint8_t *)payload;
@@ -847,14 +854,18 @@ kitty_notification(struct terminal *term, char *string)
notif->icon_data_sz = 0;
}
- /*
- * Show notification.
- *
- * The checks for title|body is to handle notifications that
- * only load icon data into the icon cache
- */
- if (notif->title != NULL || notif->body != NULL) {
- notify_notify(term, notif);
+ if (payload_type == PAYLOAD_CLOSE) {
+ notify_close(term, notif->id);
+ } else {
+ /*
+ * Show notification.
+ *
+ * The checks for title|body is to handle notifications that
+ * only load icon data into the icon cache
+ */
+ if (notif->title != NULL || notif->body != NULL) {
+ notify_notify(term, notif);
+ }
}
tll_foreach(term->kitty_notifications, it) {