aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag/config.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-28 23:15:12 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-08-01 22:47:54 -0400
commita6145914c60351d8e541192c7fe35556f8e02507 (patch)
tree8bb5cacc6e91ed4483c8a4fd0b903aacb76abf15 /swaynag/config.c
parentswaynag: split config into own file and fix optind (diff)
downloadsway-a6145914c60351d8e541192c7fe35556f8e02507.tar.gz
sway-a6145914c60351d8e541192c7fe35556f8e02507.tar.zst
sway-a6145914c60351d8e541192c7fe35556f8e02507.zip
swaynag: refactor {sway_,}nagbar to swaynag
Diffstat (limited to 'swaynag/config.c')
-rw-r--r--swaynag/config.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/swaynag/config.c b/swaynag/config.c
index 4e7edf2e..289fc82a 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -6,7 +6,7 @@
6#include "log.h" 6#include "log.h"
7#include "list.h" 7#include "list.h"
8#include "readline.h" 8#include "readline.h"
9#include "swaynag/nagbar.h" 9#include "swaynag/swaynag.h"
10#include "swaynag/types.h" 10#include "swaynag/types.h"
11#include "wlr-layer-shell-unstable-v1-client-protocol.h" 11#include "wlr-layer-shell-unstable-v1-client-protocol.h"
12 12
@@ -36,7 +36,7 @@ static char *read_from_stdin() {
36 return buffer; 36 return buffer;
37} 37}
38 38
39int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar, 39int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
40 list_t *types, char **config, bool *debug) { 40 list_t *types, char **config, bool *debug) {
41 static struct option opts[] = { 41 static struct option opts[] = {
42 {"button", required_argument, NULL, 'b'}, 42 {"button", required_argument, NULL, 'b'},
@@ -81,17 +81,17 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar,
81 } 81 }
82 switch (c) { 82 switch (c) {
83 case 'b': // Button 83 case 'b': // Button
84 if (nagbar) { 84 if (swaynag) {
85 if (optind >= argc) { 85 if (optind >= argc) {
86 fprintf(stderr, "Missing action for button %s\n", optarg); 86 fprintf(stderr, "Missing action for button %s\n", optarg);
87 return EXIT_FAILURE; 87 return EXIT_FAILURE;
88 } 88 }
89 struct sway_nagbar_button *button; 89 struct swaynag_button *button;
90 button = calloc(sizeof(struct sway_nagbar_button), 1); 90 button = calloc(sizeof(struct swaynag_button), 1);
91 button->text = strdup(optarg); 91 button->text = strdup(optarg);
92 button->type = NAGBAR_ACTION_COMMAND; 92 button->type = SWAYNAG_ACTION_COMMAND;
93 button->action = strdup(argv[optind]); 93 button->action = strdup(argv[optind]);
94 list_add(nagbar->buttons, button); 94 list_add(swaynag->buttons, button);
95 } 95 }
96 optind++; 96 optind++;
97 break; 97 break;
@@ -106,13 +106,13 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar,
106 } 106 }
107 break; 107 break;
108 case 'e': // Edge 108 case 'e': // Edge
109 if (nagbar) { 109 if (swaynag) {
110 if (strcmp(optarg, "top") == 0) { 110 if (strcmp(optarg, "top") == 0) {
111 nagbar->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP 111 swaynag->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
112 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT 112 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
113 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; 113 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
114 } else if (strcmp(optarg, "bottom") == 0) { 114 } else if (strcmp(optarg, "bottom") == 0) {
115 nagbar->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM 115 swaynag->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
116 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT 116 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
117 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; 117 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
118 } else { 118 } else {
@@ -122,49 +122,49 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar,
122 } 122 }
123 break; 123 break;
124 case 'f': // Font 124 case 'f': // Font
125 if (nagbar) { 125 if (swaynag) {
126 free(nagbar->font); 126 free(swaynag->font);
127 nagbar->font = strdup(optarg); 127 swaynag->font = strdup(optarg);
128 } 128 }
129 break; 129 break;
130 case 'l': // Detailed Message 130 case 'l': // Detailed Message
131 if (nagbar) { 131 if (swaynag) {
132 free(nagbar->details.message); 132 free(swaynag->details.message);
133 nagbar->details.message = read_from_stdin(); 133 swaynag->details.message = read_from_stdin();
134 nagbar->details.button_up.text = strdup("▲"); 134 swaynag->details.button_up.text = strdup("▲");
135 nagbar->details.button_down.text = strdup("▼"); 135 swaynag->details.button_down.text = strdup("▼");
136 } 136 }
137 break; 137 break;
138 case 'L': // Detailed Button Text 138 case 'L': // Detailed Button Text
139 if (nagbar) { 139 if (swaynag) {
140 free(nagbar->details.button_details.text); 140 free(swaynag->details.button_details.text);
141 nagbar->details.button_details.text = strdup(optarg); 141 swaynag->details.button_details.text = strdup(optarg);
142 } 142 }
143 break; 143 break;
144 case 'm': // Message 144 case 'm': // Message
145 if (nagbar) { 145 if (swaynag) {
146 free(nagbar->message); 146 free(swaynag->message);
147 nagbar->message = strdup(optarg); 147 swaynag->message = strdup(optarg);
148 } 148 }
149 break; 149 break;
150 case 'o': // Output 150 case 'o': // Output
151 if (nagbar) { 151 if (swaynag) {
152 free(nagbar->output.name); 152 free(swaynag->output.name);
153 nagbar->output.name = strdup(optarg); 153 swaynag->output.name = strdup(optarg);
154 } 154 }
155 break; 155 break;
156 case 's': // Dismiss Button Text 156 case 's': // Dismiss Button Text
157 if (nagbar) { 157 if (swaynag) {
158 struct sway_nagbar_button *button_close; 158 struct swaynag_button *button_close;
159 button_close = nagbar->buttons->items[0]; 159 button_close = swaynag->buttons->items[0];
160 free(button_close->text); 160 free(button_close->text);
161 button_close->text = strdup(optarg); 161 button_close->text = strdup(optarg);
162 } 162 }
163 break; 163 break;
164 case 't': // Type 164 case 't': // Type
165 if (nagbar) { 165 if (swaynag) {
166 nagbar->type = nagbar_type_get(types, optarg); 166 swaynag->type = swaynag_type_get(types, optarg);
167 if (!nagbar->type) { 167 if (!swaynag->type) {
168 fprintf(stderr, "Unknown type %s\n", optarg); 168 fprintf(stderr, "Unknown type %s\n", optarg);
169 return EXIT_FAILURE; 169 return EXIT_FAILURE;
170 } 170 }
@@ -186,7 +186,7 @@ static bool file_exists(const char *path) {
186 return path && access(path, R_OK) != -1; 186 return path && access(path, R_OK) != -1;
187} 187}
188 188
189char *nagbar_get_config_path(void) { 189char *swaynag_get_config_path(void) {
190 static const char *config_paths[] = { 190 static const char *config_paths[] = {
191 "$HOME/.swaynag/config", 191 "$HOME/.swaynag/config",
192 "$XDG_CONFIG_HOME/swaynag/config", 192 "$XDG_CONFIG_HOME/swaynag/config",
@@ -223,13 +223,13 @@ char *nagbar_get_config_path(void) {
223 return NULL; 223 return NULL;
224} 224}
225 225
226int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) { 226int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
227 FILE *config = fopen(path, "r"); 227 FILE *config = fopen(path, "r");
228 if (!config) { 228 if (!config) {
229 fprintf(stderr, "Failed to read config. Running without it.\n"); 229 fprintf(stderr, "Failed to read config. Running without it.\n");
230 return 0; 230 return 0;
231 } 231 }
232 struct sway_nagbar_type *type = NULL; 232 struct swaynag_type *type = NULL;
233 char *line; 233 char *line;
234 int line_number = 0; 234 int line_number = 0;
235 while (!feof(config)) { 235 while (!feof(config)) {
@@ -259,9 +259,9 @@ int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) {
259 } 259 }
260 char *name = calloc(1, close - line); 260 char *name = calloc(1, close - line);
261 strncat(name, line + 1, close - line - 1); 261 strncat(name, line + 1, close - line - 1);
262 type = nagbar_type_get(types, name); 262 type = swaynag_type_get(types, name);
263 if (!type) { 263 if (!type) {
264 type = calloc(1, sizeof(struct sway_nagbar_type)); 264 type = calloc(1, sizeof(struct swaynag_type));
265 type->name = strdup(name); 265 type->name = strdup(name);
266 list_add(types, type); 266 list_add(types, type);
267 } 267 }
@@ -272,9 +272,9 @@ int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) {
272 char *argv[] = {"swaynag", flag}; 272 char *argv[] = {"swaynag", flag};
273 int result; 273 int result;
274 if (type) { 274 if (type) {
275 result = nagbar_parse_type(2, argv, type); 275 result = swaynag_parse_type(2, argv, type);
276 } else { 276 } else {
277 result = nagbar_parse_options(2, argv, nagbar, types, 277 result = swaynag_parse_options(2, argv, swaynag, types,
278 NULL, NULL); 278 NULL, NULL);
279 } 279 }
280 if (result != 0) { 280 if (result != 0) {