diff options
Diffstat (limited to 'swaybar/ipc.c')
-rw-r--r-- | swaybar/ipc.c | 115 |
1 files changed, 111 insertions, 4 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 706f968d..097f9161 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <wlr/util/log.h> | 6 | #include <wlr/util/log.h> |
7 | #include "swaybar/config.h" | 7 | #include "swaybar/config.h" |
8 | #include "swaybar/ipc.h" | 8 | #include "swaybar/ipc.h" |
9 | #include "config.h" | ||
9 | #include "ipc-client.h" | 10 | #include "ipc-client.h" |
10 | #include "list.h" | 11 | #include "list.h" |
11 | 12 | ||
@@ -153,18 +154,21 @@ static bool ipc_parse_config( | |||
153 | return false; | 154 | return false; |
154 | } | 155 | } |
155 | json_object *markup, *mode, *hidden_state, *position, *status_command; | 156 | json_object *markup, *mode, *hidden_state, *position, *status_command; |
156 | json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers; | 157 | json_object *font, *gaps, *bar_height, *wrap_scroll, *workspace_buttons; |
157 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; | 158 | json_object *strip_workspace_numbers, *strip_workspace_name; |
158 | json_object *bindings; | 159 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol; |
160 | json_object *outputs, *bindings, *status_padding, *status_edge_padding; | ||
159 | json_object_object_get_ex(bar_config, "mode", &mode); | 161 | json_object_object_get_ex(bar_config, "mode", &mode); |
160 | json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); | 162 | json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); |
161 | json_object_object_get_ex(bar_config, "position", &position); | 163 | json_object_object_get_ex(bar_config, "position", &position); |
162 | json_object_object_get_ex(bar_config, "status_command", &status_command); | 164 | json_object_object_get_ex(bar_config, "status_command", &status_command); |
163 | json_object_object_get_ex(bar_config, "font", &font); | 165 | json_object_object_get_ex(bar_config, "font", &font); |
166 | json_object_object_get_ex(bar_config, "gaps", &gaps); | ||
164 | json_object_object_get_ex(bar_config, "bar_height", &bar_height); | 167 | json_object_object_get_ex(bar_config, "bar_height", &bar_height); |
165 | json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll); | 168 | json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll); |
166 | json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons); | 169 | json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons); |
167 | json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); | 170 | json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); |
171 | json_object_object_get_ex(bar_config, "strip_workspace_name", &strip_workspace_name); | ||
168 | json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); | 172 | json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); |
169 | json_object_object_get_ex(bar_config, "verbose", &verbose); | 173 | json_object_object_get_ex(bar_config, "verbose", &verbose); |
170 | json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol); | 174 | json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol); |
@@ -172,6 +176,9 @@ static bool ipc_parse_config( | |||
172 | json_object_object_get_ex(bar_config, "outputs", &outputs); | 176 | json_object_object_get_ex(bar_config, "outputs", &outputs); |
173 | json_object_object_get_ex(bar_config, "pango_markup", &markup); | 177 | json_object_object_get_ex(bar_config, "pango_markup", &markup); |
174 | json_object_object_get_ex(bar_config, "bindings", &bindings); | 178 | json_object_object_get_ex(bar_config, "bindings", &bindings); |
179 | json_object_object_get_ex(bar_config, "status_padding", &status_padding); | ||
180 | json_object_object_get_ex(bar_config, "status_edge_padding", | ||
181 | &status_edge_padding); | ||
175 | if (status_command) { | 182 | if (status_command) { |
176 | free(config->status_command); | 183 | free(config->status_command); |
177 | config->status_command = strdup(json_object_get_string(status_command)); | 184 | config->status_command = strdup(json_object_get_string(status_command)); |
@@ -190,6 +197,9 @@ static bool ipc_parse_config( | |||
190 | if (strip_workspace_numbers) { | 197 | if (strip_workspace_numbers) { |
191 | config->strip_workspace_numbers = json_object_get_boolean(strip_workspace_numbers); | 198 | config->strip_workspace_numbers = json_object_get_boolean(strip_workspace_numbers); |
192 | } | 199 | } |
200 | if (strip_workspace_name) { | ||
201 | config->strip_workspace_name = json_object_get_boolean(strip_workspace_name); | ||
202 | } | ||
193 | if (binding_mode_indicator) { | 203 | if (binding_mode_indicator) { |
194 | config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator); | 204 | config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator); |
195 | } | 205 | } |
@@ -202,6 +212,30 @@ static bool ipc_parse_config( | |||
202 | if (bar_height) { | 212 | if (bar_height) { |
203 | config->height = json_object_get_int(bar_height); | 213 | config->height = json_object_get_int(bar_height); |
204 | } | 214 | } |
215 | if (status_padding) { | ||
216 | config->status_padding = json_object_get_int(status_padding); | ||
217 | } | ||
218 | if (status_edge_padding) { | ||
219 | config->status_edge_padding = json_object_get_int(status_edge_padding); | ||
220 | } | ||
221 | if (gaps) { | ||
222 | json_object *top = json_object_object_get(gaps, "top"); | ||
223 | if (top) { | ||
224 | config->gaps.top = json_object_get_int(top); | ||
225 | } | ||
226 | json_object *right = json_object_object_get(gaps, "right"); | ||
227 | if (right) { | ||
228 | config->gaps.right = json_object_get_int(right); | ||
229 | } | ||
230 | json_object *bottom = json_object_object_get(gaps, "bottom"); | ||
231 | if (bottom) { | ||
232 | config->gaps.bottom = json_object_get_int(bottom); | ||
233 | } | ||
234 | json_object *left = json_object_object_get(gaps, "left"); | ||
235 | if (left) { | ||
236 | config->gaps.left = json_object_get_int(left); | ||
237 | } | ||
238 | } | ||
205 | if (markup) { | 239 | if (markup) { |
206 | config->pango_markup = json_object_get_boolean(markup); | 240 | config->pango_markup = json_object_get_boolean(markup); |
207 | } | 241 | } |
@@ -212,7 +246,7 @@ static bool ipc_parse_config( | |||
212 | struct swaybar_binding *binding = | 246 | struct swaybar_binding *binding = |
213 | calloc(1, sizeof(struct swaybar_binding)); | 247 | calloc(1, sizeof(struct swaybar_binding)); |
214 | binding->button = json_object_get_int( | 248 | binding->button = json_object_get_int( |
215 | json_object_object_get(bindobj, "input_code")); | 249 | json_object_object_get(bindobj, "event_code")); |
216 | binding->command = strdup(json_object_get_string( | 250 | binding->command = strdup(json_object_get_string( |
217 | json_object_object_get(bindobj, "command"))); | 251 | json_object_object_get(bindobj, "command"))); |
218 | binding->release = json_object_get_boolean( | 252 | binding->release = json_object_get_boolean( |
@@ -258,6 +292,40 @@ static bool ipc_parse_config( | |||
258 | ipc_parse_colors(config, colors); | 292 | ipc_parse_colors(config, colors); |
259 | } | 293 | } |
260 | 294 | ||
295 | #if HAVE_TRAY | ||
296 | json_object *tray_outputs, *tray_padding, *tray_bindings, *icon_theme; | ||
297 | |||
298 | if ((json_object_object_get_ex(bar_config, "tray_outputs", &tray_outputs))) { | ||
299 | config->tray_outputs = create_list(); | ||
300 | int length = json_object_array_length(tray_outputs); | ||
301 | for (int i = 0; i < length; ++i) { | ||
302 | json_object *o = json_object_array_get_idx(tray_outputs, i); | ||
303 | list_add(config->tray_outputs, strdup(json_object_get_string(o))); | ||
304 | } | ||
305 | config->tray_hidden = strcmp(config->tray_outputs->items[0], "none") == 0; | ||
306 | } | ||
307 | |||
308 | if ((json_object_object_get_ex(bar_config, "tray_padding", &tray_padding))) { | ||
309 | config->tray_padding = json_object_get_int(tray_padding); | ||
310 | } | ||
311 | |||
312 | if ((json_object_object_get_ex(bar_config, "tray_bindings", &tray_bindings))) { | ||
313 | int length = json_object_array_length(tray_bindings); | ||
314 | for (int i = 0; i < length; ++i) { | ||
315 | json_object *bind = json_object_array_get_idx(tray_bindings, i); | ||
316 | json_object *button, *command; | ||
317 | json_object_object_get_ex(bind, "input_code", &button); | ||
318 | json_object_object_get_ex(bind, "command", &command); | ||
319 | config->tray_bindings[json_object_get_int(button)] = | ||
320 | strdup(json_object_get_string(command)); | ||
321 | } | ||
322 | } | ||
323 | |||
324 | if ((json_object_object_get_ex(bar_config, "icon_theme", &icon_theme))) { | ||
325 | config->icon_theme = strdup(json_object_get_string(icon_theme)); | ||
326 | } | ||
327 | #endif | ||
328 | |||
261 | json_object_put(bar_config); | 329 | json_object_put(bar_config); |
262 | return true; | 330 | return true; |
263 | } | 331 | } |
@@ -298,6 +366,24 @@ bool ipc_get_workspaces(struct swaybar *bar) { | |||
298 | calloc(1, sizeof(struct swaybar_workspace)); | 366 | calloc(1, sizeof(struct swaybar_workspace)); |
299 | ws->num = json_object_get_int(num); | 367 | ws->num = json_object_get_int(num); |
300 | ws->name = strdup(json_object_get_string(name)); | 368 | ws->name = strdup(json_object_get_string(name)); |
369 | ws->label = strdup(ws->name); | ||
370 | // ws->num will be -1 if workspace name doesn't begin with int. | ||
371 | if (ws->num != -1) { | ||
372 | size_t len_offset = numlen(ws->num); | ||
373 | if (bar->config->strip_workspace_name) { | ||
374 | free(ws->label); | ||
375 | ws->label = malloc(len_offset + 1 * sizeof(char)); | ||
376 | ws->label[len_offset] = '\0'; | ||
377 | strncpy(ws->label, ws->name, len_offset); | ||
378 | } else if (bar->config->strip_workspace_numbers) { | ||
379 | len_offset += ws->label[len_offset] == ':'; | ||
380 | if (strlen(ws->name) > len_offset) { | ||
381 | free(ws->label); | ||
382 | // Strip number prefix [1-?:] using len_offset. | ||
383 | ws->label = strdup(ws->name + len_offset); | ||
384 | } | ||
385 | } | ||
386 | } | ||
301 | ws->visible = json_object_get_boolean(visible); | 387 | ws->visible = json_object_get_boolean(visible); |
302 | ws->focused = json_object_get_boolean(focused); | 388 | ws->focused = json_object_get_boolean(focused); |
303 | if (ws->focused) { | 389 | if (ws->focused) { |
@@ -423,6 +509,27 @@ static bool handle_barconfig_update(struct swaybar *bar, | |||
423 | config->mode = strdup(json_object_get_string(json_mode)); | 509 | config->mode = strdup(json_object_get_string(json_mode)); |
424 | wlr_log(WLR_DEBUG, "Changing bar mode to %s", config->mode); | 510 | wlr_log(WLR_DEBUG, "Changing bar mode to %s", config->mode); |
425 | 511 | ||
512 | json_object *gaps; | ||
513 | json_object_object_get_ex(json_config, "gaps", &gaps); | ||
514 | if (gaps) { | ||
515 | json_object *top = json_object_object_get(gaps, "top"); | ||
516 | if (top) { | ||
517 | config->gaps.top = json_object_get_int(top); | ||
518 | } | ||
519 | json_object *right = json_object_object_get(gaps, "right"); | ||
520 | if (right) { | ||
521 | config->gaps.right = json_object_get_int(right); | ||
522 | } | ||
523 | json_object *bottom = json_object_object_get(gaps, "bottom"); | ||
524 | if (bottom) { | ||
525 | config->gaps.bottom = json_object_get_int(bottom); | ||
526 | } | ||
527 | json_object *left = json_object_object_get(gaps, "left"); | ||
528 | if (left) { | ||
529 | config->gaps.left = json_object_get_int(left); | ||
530 | } | ||
531 | } | ||
532 | |||
426 | return determine_bar_visibility(bar, true); | 533 | return determine_bar_visibility(bar, true); |
427 | } | 534 | } |
428 | 535 | ||