diff options
author | 2020-06-07 10:47:56 -0400 | |
---|---|---|
committer | 2020-06-09 00:00:14 +0200 | |
commit | a974300652fc5cea72db60e1e39b0f7da7e9f334 (patch) | |
tree | bb976b50668afd3d700b8f7738a193a025870324 | |
parent | input/tablet: allow moving tiling tablet v2 surfaces by pen input (diff) | |
download | sway-a974300652fc5cea72db60e1e39b0f7da7e9f334.tar.gz sway-a974300652fc5cea72db60e1e39b0f7da7e9f334.tar.zst sway-a974300652fc5cea72db60e1e39b0f7da7e9f334.zip |
swaynag: allow specifying more buttons which execute and dismiss
I don't love -z / -Z, but I figure this patch is far from being
accepted for other reasons too.
-rw-r--r-- | include/swaynag/swaynag.h | 1 | ||||
-rw-r--r-- | swaynag/config.c | 12 | ||||
-rw-r--r-- | swaynag/swaynag.1.scd | 13 | ||||
-rw-r--r-- | swaynag/swaynag.c | 5 |
4 files changed, 30 insertions, 1 deletions
diff --git a/include/swaynag/swaynag.h b/include/swaynag/swaynag.h index 496e883a..9e39e716 100644 --- a/include/swaynag/swaynag.h +++ b/include/swaynag/swaynag.h | |||
@@ -53,6 +53,7 @@ struct swaynag_button { | |||
53 | int width; | 53 | int width; |
54 | int height; | 54 | int height; |
55 | bool terminal; | 55 | bool terminal; |
56 | bool dismiss; | ||
56 | }; | 57 | }; |
57 | 58 | ||
58 | struct swaynag_details { | 59 | struct swaynag_details { |
diff --git a/swaynag/config.c b/swaynag/config.c index f1161b39..d702cc95 100644 --- a/swaynag/config.c +++ b/swaynag/config.c | |||
@@ -52,6 +52,8 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, | |||
52 | static struct option opts[] = { | 52 | static struct option opts[] = { |
53 | {"button", required_argument, NULL, 'b'}, | 53 | {"button", required_argument, NULL, 'b'}, |
54 | {"button-no-terminal", required_argument, NULL, 'B'}, | 54 | {"button-no-terminal", required_argument, NULL, 'B'}, |
55 | {"button-dismiss", required_argument, NULL, 'z'}, | ||
56 | {"button-dismiss-no-terminal", required_argument, NULL, 'Z'}, | ||
55 | {"config", required_argument, NULL, 'c'}, | 57 | {"config", required_argument, NULL, 'c'}, |
56 | {"debug", no_argument, NULL, 'd'}, | 58 | {"debug", no_argument, NULL, 'd'}, |
57 | {"edge", required_argument, NULL, 'e'}, | 59 | {"edge", required_argument, NULL, 'e'}, |
@@ -90,6 +92,11 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, | |||
90 | "be defined.\n" | 92 | "be defined.\n" |
91 | " -B, --button-no-terminal <text> <action> Like --button, but does" | 93 | " -B, --button-no-terminal <text> <action> Like --button, but does" |
92 | "not run the action in a terminal.\n" | 94 | "not run the action in a terminal.\n" |
95 | " -z, --button-dismiss <text> <action> Create a button with text that " | ||
96 | "dismisses swaynag, and executes action in a terminal when pressed. " | ||
97 | "Multiple buttons can be defined.\n" | ||
98 | " -Z, --button-dismiss-no-terminal <text> <action> Like " | ||
99 | "--button-dismiss, but does not run the action in a terminal.\n" | ||
93 | " -c, --config <path> Path to config file.\n" | 100 | " -c, --config <path> Path to config file.\n" |
94 | " -d, --debug Enable debugging.\n" | 101 | " -d, --debug Enable debugging.\n" |
95 | " -e, --edge top|bottom Set the edge to use.\n" | 102 | " -e, --edge top|bottom Set the edge to use.\n" |
@@ -120,13 +127,15 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, | |||
120 | 127 | ||
121 | optind = 1; | 128 | optind = 1; |
122 | while (1) { | 129 | while (1) { |
123 | int c = getopt_long(argc, argv, "b:B:c:de:f:hlL:m:o:s:t:v", opts, NULL); | 130 | int c = getopt_long(argc, argv, "b:B:z:Z:c:de:f:hlL:m:o:s:t:v", opts, NULL); |
124 | if (c == -1) { | 131 | if (c == -1) { |
125 | break; | 132 | break; |
126 | } | 133 | } |
127 | switch (c) { | 134 | switch (c) { |
128 | case 'b': // Button | 135 | case 'b': // Button |
129 | case 'B': // Button (No Terminal) | 136 | case 'B': // Button (No Terminal) |
137 | case 'z': // Button (Dismiss) | ||
138 | case 'Z': // Button (Dismiss, No Terminal) | ||
130 | if (swaynag) { | 139 | if (swaynag) { |
131 | if (optind >= argc) { | 140 | if (optind >= argc) { |
132 | fprintf(stderr, "Missing action for button %s\n", optarg); | 141 | fprintf(stderr, "Missing action for button %s\n", optarg); |
@@ -138,6 +147,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, | |||
138 | button->type = SWAYNAG_ACTION_COMMAND; | 147 | button->type = SWAYNAG_ACTION_COMMAND; |
139 | button->action = strdup(argv[optind]); | 148 | button->action = strdup(argv[optind]); |
140 | button->terminal = c == 'b'; | 149 | button->terminal = c == 'b'; |
150 | button->dismiss = c == 'z' || c == 'Z'; | ||
141 | list_add(swaynag->buttons, button); | 151 | list_add(swaynag->buttons, button); |
142 | } | 152 | } |
143 | optind++; | 153 | optind++; |
diff --git a/swaynag/swaynag.1.scd b/swaynag/swaynag.1.scd index fc839b96..2ce7f330 100644 --- a/swaynag/swaynag.1.scd +++ b/swaynag/swaynag.1.scd | |||
@@ -21,6 +21,19 @@ _swaynag_ [options...] | |||
21 | _action_ will be run directly instead of in a terminal. Multiple buttons | 21 | _action_ will be run directly instead of in a terminal. Multiple buttons |
22 | can be defined by providing the flag multiple times. | 22 | can be defined by providing the flag multiple times. |
23 | 23 | ||
24 | *-z, --button-dismiss* <text> <action> | ||
25 | Create a button with the text _text_ that executes _action_ when pressed, | ||
26 | and dismisses swaynag. If the environment variable _TERMINAL_ is set, | ||
27 | _action_ will be run inside the terminal. Otherwise, it will fallback to | ||
28 | running directly. Multiple buttons can be defined by providing the flag | ||
29 | multiple times. | ||
30 | |||
31 | *-Z, --button-dismiss-no-terminal* <text> <action> | ||
32 | Create a button with the text _text_ that executes _action_ when pressed, | ||
33 | and dismisses swaynag. _action_ will be run directly instead of in a | ||
34 | terminal. Multiple buttons can be defined by providing the flag multiple | ||
35 | times. | ||
36 | |||
24 | *-c, --config* <path> | 37 | *-c, --config* <path> |
25 | The config file to use. By default, the following paths are checked: | 38 | The config file to use. By default, the following paths are checked: |
26 | _$HOME/.swaynag/config_, _$XDG\_CONFIG\_HOME/swaynag/config_, and | 39 | _$HOME/.swaynag/config_, _$XDG\_CONFIG\_HOME/swaynag/config_, and |
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 4e692b14..6c326ca8 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c | |||
@@ -76,6 +76,11 @@ static void swaynag_button_execute(struct swaynag *swaynag, | |||
76 | } | 76 | } |
77 | _exit(EXIT_SUCCESS); | 77 | _exit(EXIT_SUCCESS); |
78 | } | 78 | } |
79 | |||
80 | if (button->dismiss) { | ||
81 | swaynag->run_display = false; | ||
82 | } | ||
83 | |||
79 | if (waitpid(pid, NULL, 0) < 0) { | 84 | if (waitpid(pid, NULL, 0) < 0) { |
80 | sway_log_errno(SWAY_DEBUG, "waitpid failed"); | 85 | sway_log_errno(SWAY_DEBUG, "waitpid failed"); |
81 | } | 86 | } |