aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-11-27 23:27:44 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-11-27 23:34:51 -0500
commit673da8326038e0deb9837fd90d9e02351783b564 (patch)
tree1546629686b2afe4c7dbae18eb4233cbf0f0b4c6 /swaynag
parentMerge pull request #3175 from emersion/rename-gtk-primary-selection (diff)
downloadsway-673da8326038e0deb9837fd90d9e02351783b564.tar.gz
sway-673da8326038e0deb9837fd90d9e02351783b564.tar.zst
sway-673da8326038e0deb9837fd90d9e02351783b564.zip
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.
Diffstat (limited to 'swaynag')
-rw-r--r--swaynag/config.c10
-rw-r--r--swaynag/swaynag.1.scd9
-rw-r--r--swaynag/swaynag.c7
3 files changed, 21 insertions, 5 deletions
diff --git a/swaynag/config.c b/swaynag/config.c
index 63808ce4..e724aa0c 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -52,6 +52,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
52 52
53 static struct option opts[] = { 53 static struct option opts[] = {
54 {"button", required_argument, NULL, 'b'}, 54 {"button", required_argument, NULL, 'b'},
55 {"button-no-terminal", required_argument, NULL, 'B'},
55 {"config", required_argument, NULL, 'c'}, 56 {"config", required_argument, NULL, 'c'},
56 {"debug", no_argument, NULL, 'd'}, 57 {"debug", no_argument, NULL, 'd'},
57 {"edge", required_argument, NULL, 'e'}, 58 {"edge", required_argument, NULL, 'e'},
@@ -86,7 +87,10 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
86 "Usage: swaynag [options...]\n" 87 "Usage: swaynag [options...]\n"
87 "\n" 88 "\n"
88 " -b, --button <text> <action> Create a button with text that " 89 " -b, --button <text> <action> Create a button with text that "
89 "executes action when pressed. Multiple buttons can be defined.\n" 90 "executes action in a terminal when pressed. Multiple buttons can "
91 "be defined.\n"
92 " -B, --button-no-terminal <text> <action> Like --button, but does"
93 "not run the action in a terminal.\n"
90 " -c, --config <path> Path to config file.\n" 94 " -c, --config <path> Path to config file.\n"
91 " -d, --debug Enable debugging.\n" 95 " -d, --debug Enable debugging.\n"
92 " -e, --edge top|bottom Set the edge to use.\n" 96 " -e, --edge top|bottom Set the edge to use.\n"
@@ -117,12 +121,13 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
117 121
118 optind = 1; 122 optind = 1;
119 while (1) { 123 while (1) {
120 int c = getopt_long(argc, argv, "b:c:de:f:hlL:m:o:s:t:v", opts, NULL); 124 int c = getopt_long(argc, argv, "b:B:c:de:f:hlL:m:o:s:t:v", opts, NULL);
121 if (c == -1) { 125 if (c == -1) {
122 break; 126 break;
123 } 127 }
124 switch (c) { 128 switch (c) {
125 case 'b': // Button 129 case 'b': // Button
130 case 'B': // Button (No Terminal)
126 if (swaynag) { 131 if (swaynag) {
127 if (optind >= argc) { 132 if (optind >= argc) {
128 fprintf(stderr, "Missing action for button %s\n", optarg); 133 fprintf(stderr, "Missing action for button %s\n", optarg);
@@ -133,6 +138,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
133 button->text = strdup(optarg); 138 button->text = strdup(optarg);
134 button->type = SWAYNAG_ACTION_COMMAND; 139 button->type = SWAYNAG_ACTION_COMMAND;
135 button->action = strdup(argv[optind]); 140 button->action = strdup(argv[optind]);
141 button->terminal = c == 'b';
136 list_add(swaynag->buttons, button); 142 list_add(swaynag->buttons, button);
137 } 143 }
138 optind++; 144 optind++;
diff --git a/swaynag/swaynag.1.scd b/swaynag/swaynag.1.scd
index bb69e47d..b25568a0 100644
--- a/swaynag/swaynag.1.scd
+++ b/swaynag/swaynag.1.scd
@@ -12,7 +12,14 @@ _swaynag_ [options...]
12 12
13*-b, --button* <text> <action> 13*-b, --button* <text> <action>
14 Create a button with the text _text_ that executes _action_ when pressed. 14 Create a button with the text _text_ that executes _action_ when pressed.
15 Multiple buttons can be defined by providing the flag multiple times. 15 If the environment variable `TERMINAL` is set, _action_ will be run inside
16 the terminal. Otherwise, it will fallback to running directly. Multiple
17 buttons can be defined by providing the flag multiple times.
18
19*-B, --button-no-terminal* <text> <action>
20 Create a button with the text _text_ that executes _action_ when pressed.
21 _action_ will be run directly instead of in a terminal. Multiple buttons
22 can be defined by providing the flag multiple times.
16 23
17*-c, --config* <path> 24*-c, --config* <path>
18 The config file to use. By default, the following paths are checked: 25 The config file to use. By default, the following paths are checked:
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c
index 74e127b6..a2a0b412 100644
--- a/swaynag/swaynag.c
+++ b/swaynag/swaynag.c
@@ -49,14 +49,17 @@ static void swaynag_button_execute(struct swaynag *swaynag,
49 if (fork() == 0) { 49 if (fork() == 0) {
50 // Child of the child. Will be reparented to the init process 50 // Child of the child. Will be reparented to the init process
51 char *terminal = getenv("TERMINAL"); 51 char *terminal = getenv("TERMINAL");
52 if (terminal && strlen(terminal)) { 52 if (button->terminal && terminal && strlen(terminal)) {
53 wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal); 53 wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal);
54 if (!terminal_execute(terminal, button->action)) { 54 if (!terminal_execute(terminal, button->action)) {
55 swaynag_destroy(swaynag); 55 swaynag_destroy(swaynag);
56 exit(EXIT_FAILURE); 56 exit(EXIT_FAILURE);
57 } 57 }
58 } else { 58 } else {
59 wlr_log(WLR_DEBUG, "$TERMINAL not found. Running directly"); 59 if (button->terminal) {
60 wlr_log(WLR_DEBUG,
61 "$TERMINAL not found. Running directly");
62 }
60 execl("/bin/sh", "/bin/sh", "-c", button->action, NULL); 63 execl("/bin/sh", "/bin/sh", "-c", button->action, NULL);
61 } 64 }
62 } 65 }