diff options
author | emersion <contact@emersion.fr> | 2018-11-28 09:44:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-28 09:44:26 +0100 |
commit | c931a13af962f3c0effd567d1fb0f78fe5f21b90 (patch) | |
tree | c9efca8e598a62c88514e3d971a4005eab35e958 | |
parent | Merge pull request #3204 from RedSoxFan/cmd-res-list (diff) | |
parent | Implement swaynag -B/--button-no-terminal (diff) | |
download | sway-c931a13af962f3c0effd567d1fb0f78fe5f21b90.tar.gz sway-c931a13af962f3c0effd567d1fb0f78fe5f21b90.tar.zst sway-c931a13af962f3c0effd567d1fb0f78fe5f21b90.zip |
Merge pull request #3207 from RedSoxFan/swaynag-no-term-buttons
Implement swaynag -B/--button-no-terminal
-rw-r--r-- | include/swaynag/swaynag.h | 1 | ||||
-rw-r--r-- | swaynag/config.c | 10 | ||||
-rw-r--r-- | swaynag/swaynag.1.scd | 9 | ||||
-rw-r--r-- | swaynag/swaynag.c | 7 |
4 files changed, 22 insertions, 5 deletions
diff --git a/include/swaynag/swaynag.h b/include/swaynag/swaynag.h index a32d1503..0fd1eb50 100644 --- a/include/swaynag/swaynag.h +++ b/include/swaynag/swaynag.h | |||
@@ -44,6 +44,7 @@ struct swaynag_button { | |||
44 | int y; | 44 | int y; |
45 | int width; | 45 | int width; |
46 | int height; | 46 | int height; |
47 | bool terminal; | ||
47 | }; | 48 | }; |
48 | 49 | ||
49 | struct swaynag_details { | 50 | struct swaynag_details { |
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 | } |