osc: kitty notifications: cleanup and update to latest version of spec

* Don't store a list of unfinished notifications. Use a single one. If
  the notification ID of the 'current' notification doesn't match the
  previous, unfinished one, the 'current' notification replaces the
  previous one, instead of updating it.

* Update xstrjoin() to take an optional delimiter (for example ','),
  and use that when joining categories and 'alive IDs'.

* Rename ${action-arg} to ${action-argument}

* Update handling of the 'n' parameter (symbolic icon name); the spec
  allows it to be used multiple times, and the terminal is supposed to
  pick the first one it can resolve. Foot can't resolve icons at all,
  neither can 'notify-send' or 'fyi' (which is what foot typically
  executes to display a notification); it's the notification daemon that
  resolves icons.

  The spec _could_ be interpreted to mean the terminal should lookup
  .desktop files, and use the value of the 'Icon' key from the first
  matching .desktop files. But foot doesn't read .desktop files, and I
  don't intend to implement XDG directory scanning and parsing of
  .desktop files just to figure out which icon to use.

  Instead, use a simple heuristics; use the *shortest* symbolic
  names. The idea is pretty simple: plain icon names are typically
  shorter than .desktop file IDs.
This commit is contained in:
Daniel Eklöf 2024-08-02 08:07:13 +02:00
parent 18b87b2e20
commit ea2f0e7c3f
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
12 changed files with 296 additions and 247 deletions

23
main.c
View file

@ -261,7 +261,7 @@ main(int argc, char *const *argv)
break;
case 't':
tll_push_back(overrides, xstrjoin("term=", optarg));
tll_push_back(overrides, xstrjoin("term=", optarg, 0));
break;
case 'L':
@ -269,11 +269,11 @@ main(int argc, char *const *argv)
break;
case 'T':
tll_push_back(overrides, xstrjoin("title=", optarg));
tll_push_back(overrides, xstrjoin("title=", optarg, 0));
break;
case 'a':
tll_push_back(overrides, xstrjoin("app-id=", optarg));
tll_push_back(overrides, xstrjoin("app-id=", optarg, 0));
break;
case 'D': {
@ -287,7 +287,7 @@ main(int argc, char *const *argv)
}
case 'f': {
char *font_override = xstrjoin("font=", optarg);
char *font_override = xstrjoin("font=", optarg, 0);
tll_push_back(overrides, font_override);
break;
}
@ -658,3 +658,18 @@ out:
log_deinit();
return ret == EXIT_SUCCESS && !as_server ? shutdown_ctx.exit_code : ret;
}
UNITTEST
{
char *s = xstrjoin("foo", "bar", 0);
xassert(streq(s, "foobar"));
free(s);
s = xstrjoin("foo", "bar", ' ');
xassert(streq(s, "foo bar"));
free(s);
s = xstrjoin("foo", "bar", ',');
xassert(streq(s, "foo,bar"));
free(s);
}