aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag/config.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-29 22:42:03 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-08-01 22:47:54 -0400
commite01acb6097b583fcf2f6d0e0afe1bd878dd9b683 (patch)
treecf3e715870bb22d9ef7d5bee9457fdcc70e31ee2 /swaynag/config.c
parentswaynag: add math to meson.build (diff)
downloadsway-e01acb6097b583fcf2f6d0e0afe1bd878dd9b683.tar.gz
sway-e01acb6097b583fcf2f6d0e0afe1bd878dd9b683.tar.zst
sway-e01acb6097b583fcf2f6d0e0afe1bd878dd9b683.zip
swaynag: allow more config options
Diffstat (limited to 'swaynag/config.c')
-rw-r--r--swaynag/config.c149
1 files changed, 131 insertions, 18 deletions
diff --git a/swaynag/config.c b/swaynag/config.c
index 289fc82a..80c5ad88 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -8,6 +8,7 @@
8#include "readline.h" 8#include "readline.h"
9#include "swaynag/swaynag.h" 9#include "swaynag/swaynag.h"
10#include "swaynag/types.h" 10#include "swaynag/types.h"
11#include "util.h"
11#include "wlr-layer-shell-unstable-v1-client-protocol.h" 12#include "wlr-layer-shell-unstable-v1-client-protocol.h"
12 13
13static char *read_from_stdin() { 14static char *read_from_stdin() {
@@ -37,7 +38,23 @@ static char *read_from_stdin() {
37} 38}
38 39
39int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, 40int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
40 list_t *types, char **config, bool *debug) { 41 list_t *types, struct swaynag_type *type, char **config, bool *debug) {
42 enum type_options {
43 TO_COLOR_BACKGROUND = 256,
44 TO_COLOR_BORDER,
45 TO_COLOR_BORDER_BOTTOM,
46 TO_COLOR_BUTTON,
47 TO_COLOR_TEXT,
48 TO_THICK_BAR_BORDER,
49 TO_PADDING_MESSAGE,
50 TO_THICK_DET_BORDER,
51 TO_THICK_BTN_BORDER,
52 TO_GAP_BTN,
53 TO_GAP_BTN_DISMISS,
54 TO_MARGIN_BTN_RIGHT,
55 TO_PADDING_BTN,
56 };
57
41 static struct option opts[] = { 58 static struct option opts[] = {
42 {"button", required_argument, NULL, 'b'}, 59 {"button", required_argument, NULL, 'b'},
43 {"config", required_argument, NULL, 'c'}, 60 {"config", required_argument, NULL, 'c'},
@@ -52,6 +69,21 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
52 {"dismiss-button", required_argument, NULL, 's'}, 69 {"dismiss-button", required_argument, NULL, 's'},
53 {"type", required_argument, NULL, 't'}, 70 {"type", required_argument, NULL, 't'},
54 {"version", no_argument, NULL, 'v'}, 71 {"version", no_argument, NULL, 'v'},
72
73 {"background", required_argument, NULL, TO_COLOR_BACKGROUND},
74 {"border", required_argument, NULL, TO_COLOR_BORDER},
75 {"border-bottom", required_argument, NULL, TO_COLOR_BORDER_BOTTOM},
76 {"button-background", required_argument, NULL, TO_COLOR_BUTTON},
77 {"text", required_argument, NULL, TO_COLOR_TEXT},
78 {"border-bottom-size", required_argument, NULL, TO_THICK_BAR_BORDER},
79 {"message-padding", required_argument, NULL, TO_PADDING_MESSAGE},
80 {"details-border-size", required_argument, NULL, TO_THICK_DET_BORDER},
81 {"button-border-size", required_argument, NULL, TO_THICK_BTN_BORDER},
82 {"button-gap", required_argument, NULL, TO_GAP_BTN},
83 {"button-dismiss-gap", required_argument, NULL, TO_GAP_BTN_DISMISS},
84 {"button-margin-right", required_argument, NULL, TO_MARGIN_BTN_RIGHT},
85 {"button-padding", required_argument, NULL, TO_PADDING_BTN},
86
55 {0, 0, 0, 0} 87 {0, 0, 0, 0}
56 }; 88 };
57 89
@@ -71,7 +103,22 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
71 " -o, --output <output> Set the output to use.\n" 103 " -o, --output <output> Set the output to use.\n"
72 " -s, --dismiss-button <text> Set the dismiss button text.\n" 104 " -s, --dismiss-button <text> Set the dismiss button text.\n"
73 " -t, --type <type> Set the message type.\n" 105 " -t, --type <type> Set the message type.\n"
74 " -v, --version Show the version number and quit.\n"; 106 " -v, --version Show the version number and quit.\n"
107 "\n"
108 "The following appearance options can also be given:\n"
109 " --background RRGGBB[AA] Background color.\n"
110 " --border RRGGBB[AA] Border color.\n"
111 " --border-bottom RRGGBB[AA] Bottom border color.\n"
112 " --button-background RRGGBB[AA] Button background color.\n"
113 " --text RRGGBB[AA] Text color.\n"
114 " --border-bottom-size size Thickness of the bar border.\n"
115 " --message-padding padding Padding for the message.\n"
116 " --details-border-size size Thickness for the details border.\n"
117 " --button-border-size size Thickness for the button border.\n"
118 " --button-gap gap Size of the gap between buttons\n"
119 " --button-dismiss-gap gap Size of the gap for dismiss button.\n"
120 " --button-margin-right margin Margin from dismiss button to edge.\n"
121 " --button-padding padding Padding for the button text.\n";
75 122
76 optind = 1; 123 optind = 1;
77 while (1) { 124 while (1) {
@@ -106,13 +153,13 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
106 } 153 }
107 break; 154 break;
108 case 'e': // Edge 155 case 'e': // Edge
109 if (swaynag) { 156 if (type) {
110 if (strcmp(optarg, "top") == 0) { 157 if (strcmp(optarg, "top") == 0) {
111 swaynag->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP 158 type->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
112 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT 159 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
113 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; 160 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
114 } else if (strcmp(optarg, "bottom") == 0) { 161 } else if (strcmp(optarg, "bottom") == 0) {
115 swaynag->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM 162 type->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
116 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT 163 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
117 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; 164 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
118 } else { 165 } else {
@@ -122,9 +169,9 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
122 } 169 }
123 break; 170 break;
124 case 'f': // Font 171 case 'f': // Font
125 if (swaynag) { 172 if (type) {
126 free(swaynag->font); 173 free(type->font);
127 swaynag->font = strdup(optarg); 174 type->font = strdup(optarg);
128 } 175 }
129 break; 176 break;
130 case 'l': // Detailed Message 177 case 'l': // Detailed Message
@@ -148,9 +195,9 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
148 } 195 }
149 break; 196 break;
150 case 'o': // Output 197 case 'o': // Output
151 if (swaynag) { 198 if (type) {
152 free(swaynag->output.name); 199 free(type->output);
153 swaynag->output.name = strdup(optarg); 200 type->output = strdup(optarg);
154 } 201 }
155 break; 202 break;
156 case 's': // Dismiss Button Text 203 case 's': // Dismiss Button Text
@@ -173,6 +220,71 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
173 case 'v': // Version 220 case 'v': // Version
174 fprintf(stdout, "swaynag version " SWAY_VERSION "\n"); 221 fprintf(stdout, "swaynag version " SWAY_VERSION "\n");
175 return -1; 222 return -1;
223 case TO_COLOR_BACKGROUND: // Background color
224 if (type) {
225 type->background = parse_color(optarg);
226 }
227 break;
228 case TO_COLOR_BORDER: // Border color
229 if (type) {
230 type->border = parse_color(optarg);
231 }
232 break;
233 case TO_COLOR_BORDER_BOTTOM: // Bottom border color
234 if (type) {
235 type->border_bottom = parse_color(optarg);
236 }
237 break;
238 case TO_COLOR_BUTTON: // Button background color
239 if (type) {
240 type->button_background = parse_color(optarg);
241 }
242 break;
243 case TO_COLOR_TEXT: // Text color
244 if (type) {
245 type->text = parse_color(optarg);
246 }
247 break;
248 case TO_THICK_BAR_BORDER: // Bottom border thickness
249 if (type) {
250 type->bar_border_thickness = strtol(optarg, NULL, 0);
251 }
252 break;
253 case TO_PADDING_MESSAGE: // Message padding
254 if (type) {
255 type->message_padding = strtol(optarg, NULL, 0);
256 }
257 break;
258 case TO_THICK_DET_BORDER: // Details border thickness
259 if (type) {
260 type->details_border_thickness = strtol(optarg, NULL, 0);
261 }
262 break;
263 case TO_THICK_BTN_BORDER: // Button border thickness
264 if (type) {
265 type->button_border_thickness = strtol(optarg, NULL, 0);
266 }
267 break;
268 case TO_GAP_BTN: // Gap between buttons
269 if (type) {
270 type->button_gap = strtol(optarg, NULL, 0);
271 }
272 break;
273 case TO_GAP_BTN_DISMISS: // Gap between dismiss button
274 if (type) {
275 type->button_gap_close = strtol(optarg, NULL, 0);
276 }
277 break;
278 case TO_MARGIN_BTN_RIGHT: // Margin on the right side of button area
279 if (type) {
280 type->button_margin_right = strtol(optarg, NULL, 0);
281 }
282 break;
283 case TO_PADDING_BTN: // Padding for the button text
284 if (type) {
285 type->button_padding = strtol(optarg, NULL, 0);
286 }
287 break;
176 default: // Help or unknown flag 288 default: // Help or unknown flag
177 fprintf(c == 'h' ? stdout : stderr, "%s", usage); 289 fprintf(c == 'h' ? stdout : stderr, "%s", usage);
178 return -1; 290 return -1;
@@ -229,7 +341,12 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
229 fprintf(stderr, "Failed to read config. Running without it.\n"); 341 fprintf(stderr, "Failed to read config. Running without it.\n");
230 return 0; 342 return 0;
231 } 343 }
232 struct swaynag_type *type = NULL; 344
345 struct swaynag_type *type;
346 type = calloc(1, sizeof(struct swaynag_type));
347 type->name = strdup("<config>");
348 list_add(types, type);
349
233 char *line; 350 char *line;
234 int line_number = 0; 351 int line_number = 0;
235 while (!feof(config)) { 352 while (!feof(config)) {
@@ -271,12 +388,8 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
271 sprintf(flag, "--%s", line); 388 sprintf(flag, "--%s", line);
272 char *argv[] = {"swaynag", flag}; 389 char *argv[] = {"swaynag", flag};
273 int result; 390 int result;
274 if (type) { 391 result = swaynag_parse_options(2, argv, swaynag, types, type,
275 result = swaynag_parse_type(2, argv, type); 392 NULL, NULL);
276 } else {
277 result = swaynag_parse_options(2, argv, swaynag, types,
278 NULL, NULL);
279 }
280 if (result != 0) { 393 if (result != 0) {
281 free(line); 394 free(line);
282 fclose(config); 395 fclose(config);