Implement swaynag -B/--button-no-terminal

In `i3 4.16`, `i3-nagbar` introduces the flags `-B/--button-no-terminal`
to run the action directly instead of inside a terminal. This implements
the flags for swaynag for compatibility.

Since swaynag does not use an equivalent to `i3-sensible-terminal`, the
flags `-b/--button` only uses a terminal when the environment variable
`TERMINAL` is set, otherwise it acts the same as these new flags.
This commit is contained in:
Brian Ashworth 2018-11-27 23:27:44 -05:00
parent dbf8e1cead
commit 673da83260
4 changed files with 22 additions and 5 deletions

View file

@ -49,14 +49,17 @@ static void swaynag_button_execute(struct swaynag *swaynag,
if (fork() == 0) {
// Child of the child. Will be reparented to the init process
char *terminal = getenv("TERMINAL");
if (terminal && strlen(terminal)) {
if (button->terminal && terminal && strlen(terminal)) {
wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal);
if (!terminal_execute(terminal, button->action)) {
swaynag_destroy(swaynag);
exit(EXIT_FAILURE);
}
} else {
wlr_log(WLR_DEBUG, "$TERMINAL not found. Running directly");
if (button->terminal) {
wlr_log(WLR_DEBUG,
"$TERMINAL not found. Running directly");
}
execl("/bin/sh", "/bin/sh", "-c", button->action, NULL);
}
}