osc: kitty notifications: implement focus|report

This patch adds support for window focusing, and sending events back
to the client application when a notification is closed.

* Refactor notification related configuration options:
    - add desktop-notifications sub-section
    - deprecate 'notify' in favor of 'desktop-notifications.command'
    - deprecate 'notify-focus-inhibit' in favor of
      'desktop-notifications.inhibit-when-focused'
* Refactor: rename 'struct kitty_notification' to 'struct
  notification'
* Pass a 'struct notification' to notify_notify(), instead of many
  arguments.
* notify_notify() now registers a reaper callback. When the notifier
  process has terminated, the notification is considered closed, and we
  either try to focus (activate) the window, or send an event to the
  client application, depending on the notification setting.
* For the window activation, we need an XDG activation token. For now,
  assume *everything* written on stdout is part of the token.
* Refactor: remove much of the warnings from OSC-99; we don't
  typically log anything when an OSC/CSI has invalid values.
* Add icon support to OSC-99. This isn't part of the upstream
  spec. Foot's implementation:
    - uses the 'I' parameter
    - the value is expected to be a symbolic icon name
    - a quick check for absolute paths is done, and such icon requests
      are ignored.
* Added ${icon} to the 'desktop-notifications.command' template. Uses
  the icon specified in the notification, or ${app-id} if not set.
This commit is contained in:
Daniel Eklöf 2024-07-23 06:59:46 +02:00
parent 12152a8ae4
commit 5905ea0d84
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
11 changed files with 410 additions and 137 deletions

View file

@ -1,30 +1,41 @@
#pragma once
#include <stdbool.h>
#include <unistd.h>
struct terminal;
enum notify_when {
/* First, so that it can be left out of initializer and still be
the default */
NOTIFY_ALWAYS,
NOTIFY_UNFOCUSED,
NOTIFY_INVISIBLE
};
enum notify_urgency {
NOTIFY_URGENCY_LOW,
/* First, so that it can be left out of initializer and still be
the default */
NOTIFY_URGENCY_NORMAL,
NOTIFY_URGENCY_LOW,
NOTIFY_URGENCY_CRITICAL,
};
struct kitty_notification {
struct notification {
char *id;
char *title;
char *body;
char *icon;
char *xdg_token;
enum notify_when when;
enum notify_urgency urgency;
bool focus;
bool report;
pid_t pid;
int stdout_fd;
};
void notify_notify(
const struct terminal *term, const char *title, const char *body,
enum notify_when when, enum notify_urgency urgency);
bool notify_notify(const struct terminal *term, struct notification *notif);
void notify_free(struct terminal *term, struct notification *notif);