Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
i3-nagbar: add option for button that runs commands without a termina…
…l (#3258)

Fixes #2199.
  • Loading branch information
orestisfl authored and stapelberg committed Oct 7, 2018
1 parent c583f81 commit dfe89cc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion etc/config
Expand Up @@ -147,7 +147,7 @@ bindsym Mod1+Shift+c reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym Mod1+Shift+r restart
# exit i3 (logs you out of your X session)
bindsym Mod1+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"
bindsym Mod1+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'"

# resize window (you can also use the mouse for that)
mode "resize" {
Expand Down
2 changes: 1 addition & 1 deletion etc/config.keycodes
Expand Up @@ -133,7 +133,7 @@ bindcode $mod+Shift+54 reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindcode $mod+Shift+27 restart
# exit i3 (logs you out of your X session)
bindcode $mod+Shift+26 exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"
bindcode $mod+Shift+26 exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'"

# resize window (you can also use the mouse for that)
mode "resize" {
Expand Down
14 changes: 11 additions & 3 deletions i3-nagbar/main.c
Expand Up @@ -55,6 +55,7 @@ typedef struct {
char *action;
int16_t x;
uint16_t width;
bool terminal;
} button_t;

static xcb_window_t win;
Expand Down Expand Up @@ -187,7 +188,11 @@ static void handle_button_release(xcb_connection_t *conn, xcb_button_release_eve
}

char *terminal_cmd;
sasprintf(&terminal_cmd, "i3-sensible-terminal -e %s", link_path);
if (button->terminal) {
sasprintf(&terminal_cmd, "i3-sensible-terminal -e %s", link_path);
} else {
terminal_cmd = sstrdup(link_path);
}
printf("argv0 = %s\n", argv0);
printf("terminal_cmd = %s\n", terminal_cmd);

Expand Down Expand Up @@ -361,12 +366,13 @@ int main(int argc, char *argv[]) {
{"version", no_argument, 0, 'v'},
{"font", required_argument, 0, 'f'},
{"button", required_argument, 0, 'b'},
{"button-no-terminal", required_argument, 0, 'B'},
{"help", no_argument, 0, 'h'},
{"message", required_argument, 0, 'm'},
{"type", required_argument, 0, 't'},
{0, 0, 0, 0}};

char *options_string = "b:f:m:t:vh";
char *options_string = "b:B:f:m:t:vh";

prompt = i3string_from_utf8("Please do not run this program.");

Expand All @@ -388,12 +394,14 @@ int main(int argc, char *argv[]) {
break;
case 'h':
printf("i3-nagbar " I3_VERSION "\n");
printf("i3-nagbar [-m <message>] [-b <button> <action>] [-t warning|error] [-f <font>] [-v]\n");
printf("i3-nagbar [-m <message>] [-b <button> <action>] [-B <button> <action>] [-t warning|error] [-f <font>] [-v]\n");
return 0;
case 'b':
case 'B':
buttons = srealloc(buttons, sizeof(button_t) * (buttoncnt + 1));
buttons[buttoncnt].label = i3string_from_utf8(optarg);
buttons[buttoncnt].action = argv[optind];
buttons[buttoncnt].terminal = (o == 'b');
printf("button with label *%s* and action *%s*\n",
i3string_as_utf8(buttons[buttoncnt].label),
buttons[buttoncnt].action);
Expand Down
8 changes: 7 additions & 1 deletion man/i3-nagbar.man
Expand Up @@ -9,7 +9,7 @@ i3-nagbar - displays an error bar on top of your screen

== SYNOPSIS

i3-nagbar [-m <message>] [-b <button> <action>] [-t warning|error] [-f <font>] [-v]
i3-nagbar [-m <message>] [-b <button> <action>] [-B <button> <action>] [-t warning|error] [-f <font>] [-v]

== OPTIONS

Expand All @@ -32,6 +32,12 @@ Select font that is being used.
*-b, --button* 'button' 'action'::
Create a button with text 'button'. The 'action' are the shell commands that
will be executed by this button. Multiple buttons can be defined.
Will launch the shell commands inside a terminal emulator, using
i3-sensible-terminal.

*-B, --button-no-terminal* 'button' 'action'::
Same as above, but will execute the shell commands directly, without launching a
terminal emulator.

== DESCRIPTION

Expand Down

0 comments on commit dfe89cc

Please sign in to comment.