foot/notify.c
Mitja Horvat 729f7466ae notify: add the notify-focus-inhibit config option
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.
2021-10-06 23:33:17 +02:00

59 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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 were 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);
if (devnull >= 0)
close(devnull);
for (size_t i = 0; i < argc; i++)
free(argv[i]);
free(argv);
}