aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag
diff options
context:
space:
mode:
authorLibravatar Graham Christensen <graham@grahamc.com>2020-06-07 10:47:56 -0400
committerLibravatar Simon Ser <contact@emersion.fr>2020-06-09 00:00:14 +0200
commita974300652fc5cea72db60e1e39b0f7da7e9f334 (patch)
treebb976b50668afd3d700b8f7738a193a025870324 /swaynag
parentinput/tablet: allow moving tiling tablet v2 surfaces by pen input (diff)
downloadsway-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.
Diffstat (limited to 'swaynag')
-rw-r--r--swaynag/config.c12
-rw-r--r--swaynag/swaynag.1.scd13
-rw-r--r--swaynag/swaynag.c5
3 files changed, 29 insertions, 1 deletions
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 }