osc: kitty notification: implement 'close' events

Application can now request to receive a 'close' event when the
notification is closed (but not necessarily activated), by adding
'c=1' to the notification request.
This commit is contained in:
Daniel Eklöf 2024-07-25 18:47:23 +02:00
parent d53f0aea75
commit c797222930
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 30 additions and 6 deletions

View file

@ -181,7 +181,7 @@ notif_done(struct reaper *reaper, pid_t pid, int status, void *data)
if (notif->activated && notif->report_activated) {
xassert(notif->id != NULL);
LOG_DBG("sending notification report to client");
LOG_DBG("sending notification activation event to client");
char reply[7 + strlen(notif->id) + 1 + 2 + 1];
int n = xsnprintf(
@ -189,6 +189,15 @@ notif_done(struct reaper *reaper, pid_t pid, int status, void *data)
term_to_slave(term, reply, n);
}
if (notif->report_closed) {
LOG_DBG("sending notification close event to client");
char reply[7 + strlen(notif->id) + 1 + 7 + 1 + 2 + 1];
int n = xsnprintf(
reply, sizeof(reply), "\033]99;i=%s:p=close;\033\\", notif->id);
term_to_slave(term, reply, n);
}
notify_free(term, notif);
tll_remove(term->active_notifications, it);
return;

View file

@ -40,6 +40,7 @@ struct notification {
enum notify_urgency urgency;
bool focus;
bool report_activated;
bool report_closed;
/*
* Used internally by notify

24
osc.c
View file

@ -581,7 +581,8 @@ kitty_notification(struct terminal *term, char *string)
char *payload = NULL;
bool focus = true; /* The 'a' parameter */
bool report = false; /* The 'a' parameter */
bool report_activated = false; /* The 'a' parameter */
bool report_closed = false; /* The 'c' parameter */
bool done = true; /* The 'd' parameter */
bool base64 = false; /* The 'e' parameter */
@ -596,6 +597,7 @@ kitty_notification(struct terminal *term, char *string)
enum notify_urgency urgency = NOTIFY_URGENCY_NORMAL;
bool have_a = false;
bool have_c = false;
bool have_o = false;
bool have_u = false;
@ -628,12 +630,20 @@ kitty_notification(struct terminal *term, char *string)
if (streq(v, "focus"))
focus = !reverse;
else if (streq(v, "report"))
report = !reverse;
report_activated = !reverse;
}
break;
}
case 'c':
if (value[0] == '1' && value[1] == '\0')
report_closed = true;
else if (value[0] == '0' && value[1] == '\0')
report_closed = false;
have_c = true;
break;
case 'd':
/* done: 0|1 */
if (value[0] == '0' && value[1] == '\0')
@ -677,7 +687,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%s",
"\033]99;i=%s:p=?;p=title,body,icon:a=focus,report:o=%s:u=0,1,2:c=1%s",
id, when_str, terminator);
term_to_slave(term, reply, n);
@ -746,7 +756,8 @@ kitty_notification(struct terminal *term, char *string)
.when = when,
.urgency = urgency,
.focus = focus,
.report_activated = report,
.report_activated = report_activated,
.report_closed = report_closed,
.stdout_fd = -1,
}));
@ -762,9 +773,12 @@ kitty_notification(struct terminal *term, char *string)
/* Update notification metadata */
if (have_a) {
notif->focus = focus;
notif->report_activated = report;
notif->report_activated = report_activated;
}
if (have_c)
notif->report_closed = report_closed;
if (have_o)
notif->when = when;
if (have_u)