mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
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
59 lines
1.4 KiB
C
59 lines
1.4 KiB
C
#include "notify.h"
|
||
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include <unistd.h>
|
||
|
||
#include <sys/stat.h>
|
||
#include <fcntl.h>
|
||
|
||
#define LOG_MODULE "notify"
|
||
#define LOG_ENABLE_DBG 0
|
||
#include "log.h"
|
||
#include "config.h"
|
||
#include "spawn.h"
|
||
#include "xmalloc.h"
|
||
|
||
void
|
||
notify_notify(const struct terminal *term, const char *title, const char *body)
|
||
{
|
||
LOG_DBG("notify: title=\"%s\", msg=\"%s\"", title, body);
|
||
|
||
if (term->conf->notify_focus_inhibit && term->kbd_focus) {
|
||
/* No notifications while we’re focused */
|
||
return;
|
||
}
|
||
|
||
if (title == NULL || body == NULL)
|
||
return;
|
||
|
||
if (term->conf->notify.argv.args == NULL)
|
||
return;
|
||
|
||
char **argv = NULL;
|
||
size_t argc = 0;
|
||
|
||
if (!spawn_expand_template(
|
||
&term->conf->notify, 4,
|
||
(const char *[]){"app-id", "window-title", "title", "body"},
|
||
(const char *[]){term->conf->app_id, term->window_title, title, body},
|
||
&argc, &argv))
|
||
{
|
||
return;
|
||
}
|
||
|
||
LOG_DBG("notify command:");
|
||
for (size_t i = 0; i < argc; i++)
|
||
LOG_DBG(" argv[%zu] = \"%s\"", i, argv[i]);
|
||
|
||
/* Redirect stdin to /dev/null, but ignore failure to open */
|
||
int devnull = open("/dev/null", O_RDONLY);
|
||
spawn(term->reaper, NULL, argv, devnull, -1, -1, NULL);
|
||
|
||
if (devnull >= 0)
|
||
close(devnull);
|
||
|
||
for (size_t i = 0; i < argc; i++)
|
||
free(argv[i]);
|
||
free(argv);
|
||
}
|