aboutsummaryrefslogtreecommitdiff
path: root/notify.c (follow)
Commit message (Collapse)AuthorAgeLines
* notify: disable debug loggingDaniel Eklöf2025-01-02-1/+1
|
* osc: notify: fix crash with no messageJack Wilsdon2024-10-31-1/+2
| | | | Closes #1866
* xsnprintf: various improvements related to xvsnprintf() and xsnprintf()Craig Barnes2024-09-13-2/+2
| | | | | | | | | | | | | | | | | | | | | | Summary of changes: * Make xvsnprintf() static * restrict-qualify pointer arguments (as done by the libc equivalents) * Make comments and spec references more thorough * Remove pointless `n <= INT_MAX` assertion (see comment) * Use FATAL_ERROR() instead of xassert() (since the assertion is inside a shared util function but the caller is responsible for ensuring the condition holds true) * Change some callers to use size_t instead of int for the return value (negative returns are impossible and all subsequent uses are size_t) The updated comments and code were taken (and adapted) from: https://gitlab.com/craigbarnes/dte/-/blob/49260bb154bca0434462a41c061e512540ec2e49/src/util/xsnprintf.c#L6-50 This work was entirely authored by me and I hereby license this contribution under the MIT license (stated explicitly, so that there's no ambiguity w.r.t. the original license).
* osc: kitty notifications: add support for XDG sound namesDaniel Eklöf2024-08-04-6/+11
|
* osc: kitty notifications: implement s=silentDaniel Eklöf2024-08-04-5/+8
| | | | | | | | This implements part of the new 's' (sound) parameter; the 'silent' value. When s=silent, we set the ${muted} template argument to "true". It is intended to set the 'suppress-sound' hint: notify-send --hint BOOLEAN:suppress-sound:${muted}
* xmalloc: remove delim param from xstrjoin() and add separate xstrjoin3()Craig Barnes2024-08-03-1/+1
| | | | | | | | | | | This avoids the need for an unused third argument for most xstrjoin() calls and replaces the cases where it's needed with a more flexible function. Code generation is the same in both cases, when there are 2 string params and a compile-time known delimiter. This commit also converts 4 uses of xasprintf() to use xstrjoin*(). See also: https://godbolt.org/z/xsjrhv9b6
* notify: codespell: notificaton -> notificationDaniel Eklöf2024-08-02-1/+1
|
* osc: kitty notifications: cleanup and update to latest version of specDaniel Eklöf2024-08-02-60/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* notify: don't forget terminating NULL when patching notify helper's argvDaniel Eklöf2024-07-31-6/+10
|
* osc: kitty notifications: buttons, icons, app-name, categories etcDaniel Eklöf2024-07-31-52/+270
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | First, icons have been finalized in the specification. There were only three things we needed to adjust: * symbolic names are base64 encoded * there are a couple of OSC-99 defined symbolic names that need to be translated to the corresponding XDG icon name. * allow in-band icons without a cache ID (that is, allow applications to use p=icon without having to cache the icon first). Second, add support for the following new additions to the protocol: * 'f': custom app-name, overrides the terminal's app-id * 't': categories * 'p=alive': lets applications poll for currently active notifications * 'id' is now 'unset' by default, rather than "0" * 'w': expire time (i.e. notification timeout) * "buttons": aka actions. This lets applications add additional (to the terminal defined "default" action) actions. The 'activated' event has been updated to report which button/action was used to activate the notification. To support button/actions, desktop-notifications.command had to be reworked a bit. There's now a new config option: desktop-notifications.command-action-arg. It has two template arguments ${action-name} and ${action-label}. command-action-arg gets expanded for *each* action. ${action-name} and ${action-label} has been replaced by ${action-arg} in command. This is a somewhat special template, in that it gets replaced by *all* instances of the expanded actions.
* notify: disable debug loggingDaniel Eklöf2024-07-30-1/+1
|
* notify: remove debug assertionDaniel Eklöf2024-07-30-3/+1
| | | | (FD 0 _is_ valid, after all)
* notify: ${icon}: don't fallback to app-idDaniel Eklöf2024-07-30-5/+2
| | | | | | * Revert --icon to ${app-id} * Use --hint STRING:image-path:${icon} instead * ${icon} no longer expands to ${app-id} if notification has no icon
* notify: don't close FD 0Daniel Eklöf2024-07-30-3/+6
| | | | | | | | | | | | | | | This fixes a regression where closing a terminal instance, or hard- or soft-resetting a terminal caused FD 0 to be closed. This meant it became re-usable. Usually, by memfd_create() when allocating a new surface buffer. So far nothing _really_ bad has happened. But what if FD 0 is now used by a memfd, and we close _another_ terminal instance? This causes our memfd to be closed. And then, when e.g. trying to scroll the terminal content: fallocate() fails with bad FD.
* notify: close notification by sending SIGINT to helperDaniel Eklöf2024-07-26-29/+58
| | | | | | | | | | | | | If the user hasn't configured a custom 'desktop-notifications.close' command, try to close the notification by sending SIGINT to the notification helper. This is best-effort: * If there's no helper running, we do nothing (except warn) * We don't verify, in any way, the notification is actually closed * We don't send any other signals, under any circumstances. That is, no SIGTERM, no SIGKILL. Ever.
* osc: kitty notifications: implement the 'close' requestDaniel Eklöf2024-07-25-0/+45
| | | | | | | | | | | | | | | | 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\\'
* osc: kitty notification: implement 'close' eventsDaniel Eklöf2024-07-25-1/+10
| | | | | | 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.
* notify: rename 'report' -> 'report_activated'Daniel Eklöf2024-07-25-2/+2
|
* notify: kitty notifications: fix ID string in activation eventDaniel Eklöf2024-07-25-2/+2
| | | | We forgot to prefix the notification ID with 'i='
* osc+notify: strcmp() -> streq()Daniel Eklöf2024-07-24-3/+3
|
* notify: try to read the daemon assigned notification ID from stdoutDaniel Eklöf2024-07-24-2/+39
| | | | | And document the things we recognize in the notification helper's stdout.
* notify: don't create icon file on disk when we're not going to use itDaniel Eklöf2024-07-24-12/+25
| | | | | | | We always prefer the symbolic name. Thus, there's no need to write raw PNG data to disk if we have a symbolic name. Furthermore, keep the file open until the cache entry is evicted.
* notify: split up the ${action} template parameterDaniel Eklöf2024-07-23-6/+4
| | | | | | | | | Split it up into two, ${action-name} and ${action-label}. Dunstify, for example, has a different syntax compared to notify-send: notify-send: default=foobar dunstify: default,foobar
* notify: bug: always adjust amount of data left in stdout bufferDaniel Eklöf2024-07-23-3/+3
|
* notify: name the activation action 'default'Daniel Eklöf2024-07-23-2/+2
| | | | | This is less unique, but also works better with notification daemons that trigger the 'default' action when e.g. clicked.
* notify: don't focus/report on notification dismissalDaniel Eklöf2024-07-23-11/+16
| | | | | | | | | | | | | | | | Only do it when the notification was activated. Here, activated means the 'click to activate' notification action was triggered. How do we tie everything together? First, we add a new template parameter, ${action}. It's intended to be used with e.g. notify-send's --action option. When the action is triggered, notify-send prints its name on stdout, on a separate line. Look for this in stdout. Only if we've seen it do we focus/report the notification.
* notify: if there's a symbolic icon name, use itDaniel Eklöf2024-07-23-0/+2
| | | | | | | | | | | | | | | | | | | even if there's no graphical ID set. In other words, if there *is* a graphical ID, use the icon cache. Only if there is no graphical ID in the notification request do we fallback to the symbolic name. This means no icon will be displayed if there's no matching icon in the cache. Some examples. You can either pre-load the cache (with inline PNG data, a symbolic name, or both): printf '\e]99;g=123:n=firefox:p=icon:e=1;<PNG data>\e\\' printf '\e]99;g=123;this is a notification\e\\' or printf '\e]99;n=firefox;this is a notification\e\\'
* notify: consume_stdout(): fix ASAN warningDaniel Eklöf2024-07-23-2/+4
| | | | | | | | This is an ASAN false positive; size is always 0 when we're passing a NULL pointer. Still, the warning is easy to avoid, so let's do that to reduce the noise level.
* notify: add_icon(): check return value of write()Daniel Eklöf2024-07-23-4/+7
|
* notify: clean up logging messagesDaniel Eklöf2024-07-23-2/+4
|
* notify: separate active notifications from unfinished kitty notificationsDaniel Eklöf2024-07-23-11/+25
| | | | | | | | | | | | | | | | | | | | | This fixes an issue where it wasn't possible to trigger multiple notifications with the same kitty notification ID. This is something that works in kitty, and there's no reason why it shouldn't work. The issue was that we track stdout, and the notification helper's PID in the notification struct. Thus, when a notification is being displayed, we can't re-use the same notification struct instance for another notification. This patch fixes this by adding a new notification list, 'active_notifications'. Whenever we detect that we need to track the helper (notification want's to either focus the window on activation, or send an event to the application), we add a copy of the notification to the 'active' list. The notification can then be removed from the 'kitty' list, allowing kitty notifications to re-use the same ID over and over again, even if old notifications are still being displayed.
* osc: kitty notifications: updated support for iconsDaniel Eklöf2024-07-23-10/+116
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements the suggested protocol discussed in https://github.com/kovidgoyal/kitty/issues/7657. Icons are handled by loading a cache. Both in-band PNG data, and symbolic names are allowed. Applications use a graphical ID to reference the icon both when loading the cache, and when showing a notification. * 'g' is the graphical ID * 'n' is optional, and assigns a symbolic name to the icon * 'p=icon' - the payload is icon PNG data. It needs to be base64 encoded, but this is *not* implied. I.e. the application *must* use e=1 explicitly. To load an icon (in-band PNG data): printf '\e]99;g=123:p=icon;<base64-encoded-png-data>\e\\' or (symbolic name) printf '\e]99;g=123:n=firefox:p=icon;\e\\' Of course, we can combine the two, assigning *both* a symbolic name, *and* PNG data: printf '\e]99;g=123:n=firefox:p=icon;<base64-encoded-png>\e\\' Then, to use the icon in a notification: printf '\e]99;g=123;this is a notification\e\\' Foot also allows a *symbolic* icon to be defined and used at the same time: printf '\e]99;g=123:n=firefox;this is a notification\e\\' This obviously won't work with PNG data, since it uses the payload portion of the escape sequence.
* notify: stdout is a bad nameDaniel Eklöf2024-07-23-8/+8
|
* notify: XDG token is now expected to be prefixed with xdgtoken=Daniel Eklöf2024-07-23-22/+51
| | | | | | | | | | | | | | | | This patch modifies our stdout reader to consume input as we go, instead of all at once when stdout is closed. This will make it easier to add support for reading e.g. the daemon assigned notification ID in the future, and also ensures we see the XDG activation token "as soon as possible". Furthermore, to be more future proof, require the XDG activation token to be prefixed with 'xdgtoken=', and ignore other lines. Thus, instead of treating *all* of stdout as the XDG activation token, parse stdout line-by-line, and ignore everything that does not begin with 'xdgtoken='. Everything (on that line) following 'xdgtoken=' is treated as the activation token.
* osc: kitty notifications: implement focus|reportDaniel Eklöf2024-07-23-16/+169
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* spawn: add optional reaper callback, return pid_tDaniel Eklöf2024-07-23-1/+5
| | | | | This will allow spawn() callers to do things when the spawned process has terminated.
* osc/notify: add support for OSC-99, kitty desktop notificationsDaniel Eklöf2024-07-23-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | This adds limited support for OSC-99, kitty desktop notifications[^1]. We support everything defined by the "protocol", except: * 'a': action to perform on notification activation. Since we don't trigger the notification ourselves (over D-Bus), we don't know a) which ID the notification got, or b) when it is clicked. * ... and that's it. Everything else is supported To be explicit, we *do* support: * Chunked notifications (d=0|1), allowing the application to append data to a notification in chunks, before it's finally displayed. * Plain UTF-8, or base64-encoded UTF-8 payload (e=0|1). * Notification identifier (i=xyz). * Payload type (p=title|body). * When to honor the notification (o=always|unfocused|invisible), with the following quirks: - we don't know when the window is invisible, thus it's treated as 'unfocused'. - the foot option 'notify-focus-inhibit' overrides 'always' * Urgency (u=0|1|2) [^1]: https://sw.kovidgoyal.net/kitty/desktop-notifications/
* osc: add support for osc 176 (app ID)delthas2024-02-06-1/+1
| | | | | | | | | | This adds support for a new OSC escape sequence: OSC 176, that lets terminal programs tell the terminal the name of the app that is running. foot then sets the app ID of the toplevel to that ID, which lets the compositor know which app is running, and typically sets the appropriate icon, window grouping, ... See: https://gist.github.com/delthas/d451e2cc1573bb2364839849c7117239
* Don't use fancy Unicode quotes, stick to ASCIIDaniel Eklöf2024-02-06-1/+1
|
* url-mode: add support for XDG activation when opening URLsDaniel Eklöf2022-05-05-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | First, add a ‘token’ argument to spawn(). When non-NULL, spawn() will set the ‘XDG_ACTIVATION_TOKEN’ environment variable in the forked process. If DISPLAY is non-NULL, we also set DESKTOP_STARTUP_ID, for compatibility with X11 applications. Note that failing to set either of these environment variables are considered non-fatal - i.e. we ignore failures. Next, add a helper function, wayl_get_activation_token(), to generate an XDG activation token, and call a user-provided callback when it’s ‘done (since token generation is asynchronous). This function takes an optional ‘seat’ and ‘serial’ arguments - when both are non-NULL/zero, we set the serial on the token. ‘win’ is a required argument, used to set the surface on the token. Re-write wayl_win_set_urgent() to use the new helper function. Finally, rewrite activate_url() to first try to get an activation token (and spawn the URL launcher in the token callback). If that fails, or if we don’t have XDG activation support, spawn the URL launcher immediately (like before this patch). Closes #1058
* notify: add the notify-focus-inhibit config optionMitja Horvat2021-10-06-1/+1
| | | | | | | | | | | | | | | foot doesn't show desktop notifications (via OSC777) if the current terminal has keyboard focus. This is probably a sane default, but there are use cases where showing a notification regardless of the focus status may be desired. For example, a completion notification of a long running task inside a non-focused tmux window. This PR adds the notify-focus-inhibit option which can be used to disable inhibition of notifications when the window has focus. The default value is `yes`, which retains the old behavior.
* config: add new function config_clone()Daniel Eklöf2021-06-23-1/+1
|
* notify: add ${window-title}Daniel Eklöf2021-05-27-3/+3
|
* config: notify: change default value to use ${app-id}Daniel Eklöf2021-05-27-3/+3
| | | | | Make the default value of ‘notify’ use ${app-id} for icon and application name.
* notify: break out command template expansion to spawn_expand_template()Daniel Eklöf2021-02-07-60/+11
|
* notify: repair debug log: the parameter has been renamed: msg -> bodyDaniel Eklöf2021-01-31-1/+1
|
* notify: don’t emit notification when we’re focusedDaniel Eklöf2020-12-10-0/+5
|
* notify: break out desktop notifications from osc.cDaniel Eklöf2020-12-10-0/+103