aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/ipc.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/ipc.c')
-rw-r--r--swaybar/ipc.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 6bbe9408..33ae6544 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -147,8 +147,10 @@ static bool ipc_parse_config(
147 147
148 json_object *font = json_object_object_get(bar_config, "font"); 148 json_object *font = json_object_object_get(bar_config, "font");
149 if (font) { 149 if (font) {
150 free(config->font); 150 pango_font_description_free(config->font_description);
151 config->font = parse_font(json_object_get_string(font)); 151 char *font_value = parse_font(json_object_get_string(font));
152 config->font_description = pango_font_description_from_string(font_value);
153 free(font_value);
152 } 154 }
153 155
154 json_object *gaps = json_object_object_get(bar_config, "gaps"); 156 json_object *gaps = json_object_object_get(bar_config, "gaps");
@@ -424,12 +426,9 @@ bool ipc_initialize(struct swaybar *bar) {
424 } 426 }
425 free(res); 427 free(res);
426 428
427 struct swaybar_config *config = bar->config; 429 char *subscribe =
428 char subscribe[128]; // suitably large buffer 430 "[ \"barconfig_update\", \"bar_state_update\", \"mode\", \"workspace\" ]";
429 len = snprintf(subscribe, 128, 431 len = strlen(subscribe);
430 "[ \"barconfig_update\" , \"bar_state_update\" %s %s ]",
431 config->binding_mode_indicator ? ", \"mode\"" : "",
432 config->workspace_buttons ? ", \"workspace\"" : "");
433 free(ipc_single_command(bar->ipc_event_socketfd, 432 free(ipc_single_command(bar->ipc_event_socketfd,
434 IPC_SUBSCRIBE, subscribe, &len)); 433 IPC_SUBSCRIBE, subscribe, &len));
435 return true; 434 return true;
@@ -485,8 +484,7 @@ static bool handle_barconfig_update(struct swaybar *bar, const char *payload,
485 destroy_layer_surface(output); 484 destroy_layer_surface(output);
486 wl_list_remove(&output->link); 485 wl_list_remove(&output->link);
487 wl_list_insert(&bar->unused_outputs, &output->link); 486 wl_list_insert(&bar->unused_outputs, &output->link);
488 } else if (!oldcfg->font || !newcfg->font || 487 } else if (!pango_font_description_equal(oldcfg->font_description, newcfg->font_description)) {
489 strcmp(oldcfg->font, newcfg->font) != 0) {
490 output->height = 0; // force update height 488 output->height = 0; // force update height
491 } 489 }
492 } 490 }
@@ -547,9 +545,23 @@ bool handle_ipc_readable(struct swaybar *bar) {
547 return false; 545 return false;
548 } 546 }
549 547
550 json_object *result = json_tokener_parse(resp->payload); 548 // The default depth of 32 is too small to represent some nested layouts, but
551 if (!result) { 549 // we can't pass INT_MAX here because json-c (as of this writing) prefaults
552 sway_log(SWAY_ERROR, "failed to parse payload as json"); 550 // all the memory for its stack.
551 json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH);
552 if (!tok) {
553 sway_log_errno(SWAY_ERROR, "failed to create tokener");
554 free_ipc_response(resp);
555 return false;
556 }
557
558 json_object *result = json_tokener_parse_ex(tok, resp->payload, -1);
559 enum json_tokener_error err = json_tokener_get_error(tok);
560 json_tokener_free(tok);
561
562 if (err != json_tokener_success) {
563 sway_log(SWAY_ERROR, "failed to parse payload as json: %s",
564 json_tokener_error_desc(err));
553 free_ipc_response(resp); 565 free_ipc_response(resp);
554 return false; 566 return false;
555 } 567 }