diff options
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/config.c | 4 | ||||
-rw-r--r-- | swaybar/ipc.c | 9 | ||||
-rw-r--r-- | swaybar/render.c | 36 |
3 files changed, 25 insertions, 24 deletions
diff --git a/swaybar/config.c b/swaybar/config.c index abedaec0..5e828773 100644 --- a/swaybar/config.c +++ b/swaybar/config.c | |||
@@ -26,7 +26,7 @@ struct swaybar_config *init_config(void) { | |||
26 | config->status_command = NULL; | 26 | config->status_command = NULL; |
27 | config->pango_markup = false; | 27 | config->pango_markup = false; |
28 | config->position = parse_position("bottom"); | 28 | config->position = parse_position("bottom"); |
29 | config->font = strdup("monospace 10"); | 29 | config->font_description = pango_font_description_from_string("monospace 10"); |
30 | config->mode = strdup("dock"); | 30 | config->mode = strdup("dock"); |
31 | config->hidden_state = strdup("hide"); | 31 | config->hidden_state = strdup("hide"); |
32 | config->sep_symbol = NULL; | 32 | config->sep_symbol = NULL; |
@@ -105,7 +105,7 @@ void free_tray_binding(struct tray_binding *binding) { | |||
105 | 105 | ||
106 | void free_config(struct swaybar_config *config) { | 106 | void free_config(struct swaybar_config *config) { |
107 | free(config->status_command); | 107 | free(config->status_command); |
108 | free(config->font); | 108 | pango_font_description_free(config->font_description); |
109 | free(config->mode); | 109 | free(config->mode); |
110 | free(config->hidden_state); | 110 | free(config->hidden_state); |
111 | free(config->sep_symbol); | 111 | free(config->sep_symbol); |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 2cb235bf..9d81a9fb 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"); |
@@ -485,8 +487,7 @@ static bool handle_barconfig_update(struct swaybar *bar, const char *payload, | |||
485 | destroy_layer_surface(output); | 487 | destroy_layer_surface(output); |
486 | wl_list_remove(&output->link); | 488 | wl_list_remove(&output->link); |
487 | wl_list_insert(&bar->unused_outputs, &output->link); | 489 | wl_list_insert(&bar->unused_outputs, &output->link); |
488 | } else if (!oldcfg->font || !newcfg->font || | 490 | } 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 | 491 | output->height = 0; // force update height |
491 | } | 492 | } |
492 | } | 493 | } |
diff --git a/swaybar/render.c b/swaybar/render.c index 7e2f97b7..a878805e 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -62,7 +62,7 @@ static uint32_t render_status_line_error(struct render_context *ctx, double *x) | |||
62 | int margin = 3; | 62 | int margin = 3; |
63 | double ws_vertical_padding = output->bar->config->status_padding; | 63 | double ws_vertical_padding = output->bar->config->status_padding; |
64 | 64 | ||
65 | char *font = output->bar->config->font; | 65 | PangoFontDescription *font = output->bar->config->font_description; |
66 | int text_width, text_height; | 66 | int text_width, text_height; |
67 | get_text_size(cairo, font, &text_width, &text_height, NULL, | 67 | get_text_size(cairo, font, &text_width, &text_height, NULL, |
68 | 1, false, "%s", error); | 68 | 1, false, "%s", error); |
@@ -97,7 +97,7 @@ static uint32_t render_status_line_text(struct render_context *ctx, double *x) { | |||
97 | cairo_set_source_u32(cairo, fontcolor); | 97 | cairo_set_source_u32(cairo, fontcolor); |
98 | 98 | ||
99 | int text_width, text_height; | 99 | int text_width, text_height; |
100 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, | 100 | get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, |
101 | 1, config->pango_markup, "%s", text); | 101 | 1, config->pango_markup, "%s", text); |
102 | 102 | ||
103 | double ws_vertical_padding = config->status_padding; | 103 | double ws_vertical_padding = config->status_padding; |
@@ -115,7 +115,7 @@ static uint32_t render_status_line_text(struct render_context *ctx, double *x) { | |||
115 | double text_y = height / 2.0 - text_height / 2.0; | 115 | double text_y = height / 2.0 - text_height / 2.0; |
116 | cairo_move_to(cairo, *x, (int)floor(text_y)); | 116 | cairo_move_to(cairo, *x, (int)floor(text_y)); |
117 | choose_text_aa_mode(ctx, fontcolor); | 117 | choose_text_aa_mode(ctx, fontcolor); |
118 | render_text(cairo, config->font, 1, config->pango_markup, "%s", text); | 118 | render_text(cairo, config->font_description, 1, config->pango_markup, "%s", text); |
119 | *x -= margin; | 119 | *x -= margin; |
120 | return output->height; | 120 | return output->height; |
121 | } | 121 | } |
@@ -190,7 +190,7 @@ static uint32_t render_status_block(struct render_context *ctx, | |||
190 | struct swaybar_output *output = ctx->output; | 190 | struct swaybar_output *output = ctx->output; |
191 | struct swaybar_config *config = output->bar->config; | 191 | struct swaybar_config *config = output->bar->config; |
192 | int text_width, text_height; | 192 | int text_width, text_height; |
193 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, 1, | 193 | get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, 1, |
194 | block->markup, "%s", text); | 194 | block->markup, "%s", text); |
195 | 195 | ||
196 | int margin = 3; | 196 | int margin = 3; |
@@ -199,7 +199,7 @@ static uint32_t render_status_block(struct render_context *ctx, | |||
199 | int width = text_width; | 199 | int width = text_width; |
200 | if (block->min_width_str) { | 200 | if (block->min_width_str) { |
201 | int w; | 201 | int w; |
202 | get_text_size(cairo, config->font, &w, NULL, NULL, 1, block->markup, | 202 | get_text_size(cairo, config->font_description, &w, NULL, NULL, 1, block->markup, |
203 | "%s", block->min_width_str); | 203 | "%s", block->min_width_str); |
204 | block->min_width = w; | 204 | block->min_width = w; |
205 | } | 205 | } |
@@ -229,7 +229,7 @@ static uint32_t render_status_block(struct render_context *ctx, | |||
229 | int sep_block_width = block->separator_block_width; | 229 | int sep_block_width = block->separator_block_width; |
230 | if (!edge) { | 230 | if (!edge) { |
231 | if (config->sep_symbol) { | 231 | if (config->sep_symbol) { |
232 | get_text_size(cairo, config->font, &sep_width, &sep_height, NULL, | 232 | get_text_size(cairo, config->font_description, &sep_width, &sep_height, NULL, |
233 | 1, false, "%s", config->sep_symbol); | 233 | 1, false, "%s", config->sep_symbol); |
234 | uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; | 234 | uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; |
235 | uint32_t _ideal_surface_height = _ideal_height; | 235 | uint32_t _ideal_surface_height = _ideal_height; |
@@ -307,7 +307,7 @@ static uint32_t render_status_block(struct render_context *ctx, | |||
307 | color = block->urgent ? config->colors.urgent_workspace.text : color; | 307 | color = block->urgent ? config->colors.urgent_workspace.text : color; |
308 | cairo_set_source_u32(cairo, color); | 308 | cairo_set_source_u32(cairo, color); |
309 | choose_text_aa_mode(ctx, color); | 309 | choose_text_aa_mode(ctx, color); |
310 | render_text(cairo, config->font, 1, block->markup, "%s", text); | 310 | render_text(cairo, config->font_description, 1, block->markup, "%s", text); |
311 | x_pos += width; | 311 | x_pos += width; |
312 | 312 | ||
313 | if (block->border_set || block->urgent) { | 313 | if (block->border_set || block->urgent) { |
@@ -331,7 +331,7 @@ static uint32_t render_status_block(struct render_context *ctx, | |||
331 | double sep_y = height / 2.0 - sep_height / 2.0; | 331 | double sep_y = height / 2.0 - sep_height / 2.0; |
332 | cairo_move_to(cairo, offset, (int)floor(sep_y)); | 332 | cairo_move_to(cairo, offset, (int)floor(sep_y)); |
333 | choose_text_aa_mode(ctx, color); | 333 | choose_text_aa_mode(ctx, color); |
334 | render_text(cairo, config->font, 1, false, | 334 | render_text(cairo, config->font_description, 1, false, |
335 | "%s", config->sep_symbol); | 335 | "%s", config->sep_symbol); |
336 | } else { | 336 | } else { |
337 | cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); | 337 | cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); |
@@ -354,7 +354,7 @@ static void predict_status_block_pos(cairo_t *cairo, | |||
354 | struct swaybar_config *config = output->bar->config; | 354 | struct swaybar_config *config = output->bar->config; |
355 | 355 | ||
356 | int text_width, text_height; | 356 | int text_width, text_height; |
357 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, 1, | 357 | get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, 1, |
358 | block->markup, "%s", block->full_text); | 358 | block->markup, "%s", block->full_text); |
359 | 359 | ||
360 | int margin = 3; | 360 | int margin = 3; |
@@ -364,7 +364,7 @@ static void predict_status_block_pos(cairo_t *cairo, | |||
364 | 364 | ||
365 | if (block->min_width_str) { | 365 | if (block->min_width_str) { |
366 | int w; | 366 | int w; |
367 | get_text_size(cairo, config->font, &w, NULL, NULL, | 367 | get_text_size(cairo, config->font_description, &w, NULL, NULL, |
368 | 1, block->markup, "%s", block->min_width_str); | 368 | 1, block->markup, "%s", block->min_width_str); |
369 | block->min_width = w; | 369 | block->min_width = w; |
370 | } | 370 | } |
@@ -391,7 +391,7 @@ static void predict_status_block_pos(cairo_t *cairo, | |||
391 | int sep_block_width = block->separator_block_width; | 391 | int sep_block_width = block->separator_block_width; |
392 | if (!edge) { | 392 | if (!edge) { |
393 | if (config->sep_symbol) { | 393 | if (config->sep_symbol) { |
394 | get_text_size(cairo, config->font, &sep_width, &sep_height, NULL, | 394 | get_text_size(cairo, config->font_description, &sep_width, &sep_height, NULL, |
395 | 1, false, "%s", config->sep_symbol); | 395 | 1, false, "%s", config->sep_symbol); |
396 | uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; | 396 | uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; |
397 | uint32_t _ideal_surface_height = _ideal_height; | 397 | uint32_t _ideal_surface_height = _ideal_height; |
@@ -426,7 +426,7 @@ static uint32_t predict_workspace_button_length(cairo_t *cairo, | |||
426 | struct swaybar_config *config = output->bar->config; | 426 | struct swaybar_config *config = output->bar->config; |
427 | 427 | ||
428 | int text_width, text_height; | 428 | int text_width, text_height; |
429 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, 1, | 429 | get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, 1, |
430 | config->pango_markup, "%s", ws->label); | 430 | config->pango_markup, "%s", ws->label); |
431 | 431 | ||
432 | int ws_vertical_padding = WS_VERTICAL_PADDING; | 432 | int ws_vertical_padding = WS_VERTICAL_PADDING; |
@@ -474,7 +474,7 @@ static uint32_t predict_binding_mode_indicator_length(cairo_t *cairo, | |||
474 | } | 474 | } |
475 | 475 | ||
476 | int text_width, text_height; | 476 | int text_width, text_height; |
477 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, | 477 | get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, |
478 | 1, output->bar->mode_pango_markup, | 478 | 1, output->bar->mode_pango_markup, |
479 | "%s", mode); | 479 | "%s", mode); |
480 | 480 | ||
@@ -551,7 +551,7 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx, | |||
551 | cairo_t *cairo = ctx->cairo; | 551 | cairo_t *cairo = ctx->cairo; |
552 | struct swaybar_config *config = output->bar->config; | 552 | struct swaybar_config *config = output->bar->config; |
553 | int text_width, text_height; | 553 | int text_width, text_height; |
554 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, | 554 | get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, |
555 | 1, output->bar->mode_pango_markup, | 555 | 1, output->bar->mode_pango_markup, |
556 | "%s", mode); | 556 | "%s", mode); |
557 | 557 | ||
@@ -592,7 +592,7 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx, | |||
592 | cairo_set_source_u32(cairo, config->colors.binding_mode.text); | 592 | cairo_set_source_u32(cairo, config->colors.binding_mode.text); |
593 | cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); | 593 | cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); |
594 | choose_text_aa_mode(ctx, config->colors.binding_mode.text); | 594 | choose_text_aa_mode(ctx, config->colors.binding_mode.text); |
595 | render_text(cairo, config->font, 1, output->bar->mode_pango_markup, | 595 | render_text(cairo, config->font_description, 1, output->bar->mode_pango_markup, |
596 | "%s", mode); | 596 | "%s", mode); |
597 | return output->height; | 597 | return output->height; |
598 | } | 598 | } |
@@ -626,7 +626,7 @@ static uint32_t render_workspace_button(struct render_context *ctx, | |||
626 | 626 | ||
627 | cairo_t *cairo = ctx->cairo; | 627 | cairo_t *cairo = ctx->cairo; |
628 | int text_width, text_height; | 628 | int text_width, text_height; |
629 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, | 629 | get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, |
630 | 1, config->pango_markup, "%s", ws->label); | 630 | 1, config->pango_markup, "%s", ws->label); |
631 | 631 | ||
632 | int ws_vertical_padding = WS_VERTICAL_PADDING; | 632 | int ws_vertical_padding = WS_VERTICAL_PADDING; |
@@ -666,7 +666,7 @@ static uint32_t render_workspace_button(struct render_context *ctx, | |||
666 | cairo_set_source_u32(cairo, box_colors.text); | 666 | cairo_set_source_u32(cairo, box_colors.text); |
667 | cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); | 667 | cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); |
668 | choose_text_aa_mode(ctx, box_colors.text); | 668 | choose_text_aa_mode(ctx, box_colors.text); |
669 | render_text(cairo, config->font, 1, config->pango_markup, | 669 | render_text(cairo, config->font_description, 1, config->pango_markup, |
670 | "%s", ws->label); | 670 | "%s", ws->label); |
671 | 671 | ||
672 | struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); | 672 | struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); |
@@ -699,7 +699,7 @@ static uint32_t render_to_cairo(struct render_context *ctx) { | |||
699 | cairo_paint(cairo); | 699 | cairo_paint(cairo); |
700 | 700 | ||
701 | int th; | 701 | int th; |
702 | get_text_size(cairo, config->font, NULL, &th, NULL, 1, false, ""); | 702 | get_text_size(cairo, config->font_description, NULL, &th, NULL, 1, false, ""); |
703 | uint32_t max_height = (th + WS_VERTICAL_PADDING * 4); | 703 | uint32_t max_height = (th + WS_VERTICAL_PADDING * 4); |
704 | /* | 704 | /* |
705 | * Each render_* function takes the actual height of the bar, and returns | 705 | * Each render_* function takes the actual height of the bar, and returns |