diff options
-rw-r--r-- | common/pango.c | 12 | ||||
-rw-r--r-- | include/pango.h | 8 | ||||
-rw-r--r-- | include/sway/config.h | 2 | ||||
-rw-r--r-- | include/swaybar/config.h | 3 | ||||
-rw-r--r-- | include/swaynag/types.h | 3 | ||||
-rw-r--r-- | sway/tree/container.c | 4 | ||||
-rw-r--r-- | swaybar/config.c | 4 | ||||
-rw-r--r-- | swaybar/ipc.c | 9 | ||||
-rw-r--r-- | swaybar/render.c | 36 | ||||
-rw-r--r-- | swaynag/config.c | 2 | ||||
-rw-r--r-- | swaynag/render.c | 18 |
11 files changed, 52 insertions, 49 deletions
diff --git a/common/pango.c b/common/pango.c index e8e2678d..e04bf80f 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -50,7 +50,7 @@ size_t escape_markup_text(const char *src, char *dest) { | |||
50 | return length; | 50 | return length; |
51 | } | 51 | } |
52 | 52 | ||
53 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | 53 | PangoLayout *get_pango_layout(cairo_t *cairo, const PangoFontDescription *desc, |
54 | const char *text, double scale, bool markup) { | 54 | const char *text, double scale, bool markup) { |
55 | PangoLayout *layout = pango_cairo_create_layout(cairo); | 55 | PangoLayout *layout = pango_cairo_create_layout(cairo); |
56 | PangoAttrList *attrs; | 56 | PangoAttrList *attrs; |
@@ -73,16 +73,14 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | |||
73 | } | 73 | } |
74 | 74 | ||
75 | pango_attr_list_insert(attrs, pango_attr_scale_new(scale)); | 75 | pango_attr_list_insert(attrs, pango_attr_scale_new(scale)); |
76 | PangoFontDescription *desc = pango_font_description_from_string(font); | ||
77 | pango_layout_set_font_description(layout, desc); | 76 | pango_layout_set_font_description(layout, desc); |
78 | pango_layout_set_single_paragraph_mode(layout, 1); | 77 | pango_layout_set_single_paragraph_mode(layout, 1); |
79 | pango_layout_set_attributes(layout, attrs); | 78 | pango_layout_set_attributes(layout, attrs); |
80 | pango_attr_list_unref(attrs); | 79 | pango_attr_list_unref(attrs); |
81 | pango_font_description_free(desc); | ||
82 | return layout; | 80 | return layout; |
83 | } | 81 | } |
84 | 82 | ||
85 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | 83 | void get_text_size(cairo_t *cairo, const PangoFontDescription *desc, int *width, int *height, |
86 | int *baseline, double scale, bool markup, const char *fmt, ...) { | 84 | int *baseline, double scale, bool markup, const char *fmt, ...) { |
87 | va_list args; | 85 | va_list args; |
88 | va_start(args, fmt); | 86 | va_start(args, fmt); |
@@ -99,7 +97,7 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | |||
99 | vsnprintf(buf, length, fmt, args); | 97 | vsnprintf(buf, length, fmt, args); |
100 | va_end(args); | 98 | va_end(args); |
101 | 99 | ||
102 | PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); | 100 | PangoLayout *layout = get_pango_layout(cairo, desc, buf, scale, markup); |
103 | pango_cairo_update_layout(cairo, layout); | 101 | pango_cairo_update_layout(cairo, layout); |
104 | pango_layout_get_pixel_size(layout, width, height); | 102 | pango_layout_get_pixel_size(layout, width, height); |
105 | if (baseline) { | 103 | if (baseline) { |
@@ -123,7 +121,7 @@ void get_text_metrics(const PangoFontDescription *description, int *height, int | |||
123 | cairo_destroy(cairo); | 121 | cairo_destroy(cairo); |
124 | } | 122 | } |
125 | 123 | ||
126 | void render_text(cairo_t *cairo, const char *font, | 124 | void render_text(cairo_t *cairo, const PangoFontDescription *desc, |
127 | double scale, bool markup, const char *fmt, ...) { | 125 | double scale, bool markup, const char *fmt, ...) { |
128 | va_list args; | 126 | va_list args; |
129 | va_start(args, fmt); | 127 | va_start(args, fmt); |
@@ -140,7 +138,7 @@ void render_text(cairo_t *cairo, const char *font, | |||
140 | vsnprintf(buf, length, fmt, args); | 138 | vsnprintf(buf, length, fmt, args); |
141 | va_end(args); | 139 | va_end(args); |
142 | 140 | ||
143 | PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); | 141 | PangoLayout *layout = get_pango_layout(cairo, desc, buf, scale, markup); |
144 | cairo_font_options_t *fo = cairo_font_options_create(); | 142 | cairo_font_options_t *fo = cairo_font_options_create(); |
145 | cairo_get_font_options(cairo, fo); | 143 | cairo_get_font_options(cairo, fo); |
146 | pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo); | 144 | pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo); |
diff --git a/include/pango.h b/include/pango.h index 2f14d2bb..1db113c2 100644 --- a/include/pango.h +++ b/include/pango.h | |||
@@ -13,12 +13,12 @@ | |||
13 | * escaped string to dest if provided. | 13 | * escaped string to dest if provided. |
14 | */ | 14 | */ |
15 | size_t escape_markup_text(const char *src, char *dest); | 15 | size_t escape_markup_text(const char *src, char *dest); |
16 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | 16 | PangoLayout *get_pango_layout(cairo_t *cairo, const PangoFontDescription *desc, |
17 | const char *text, double scale, bool markup); | 17 | const char *text, double scale, bool markup); |
18 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | 18 | void get_text_size(cairo_t *cairo, const PangoFontDescription *desc, int *width, int *height, |
19 | int *baseline, double scale, bool markup, const char *fmt, ...); | 19 | int *baseline, double scale, bool markup, const char *fmt, ...); |
20 | void get_text_metrics(const PangoFontDescription *font, int *height, int *baseline); | 20 | void get_text_metrics(const PangoFontDescription *desc, int *height, int *baseline); |
21 | void render_text(cairo_t *cairo, const char *font, | 21 | void render_text(cairo_t *cairo, PangoFontDescription *desc, |
22 | double scale, bool markup, const char *fmt, ...); | 22 | double scale, bool markup, const char *fmt, ...); |
23 | 23 | ||
24 | #endif | 24 | #endif |
diff --git a/include/sway/config.h b/include/sway/config.h index 8939af00..2b4aa972 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -505,7 +505,7 @@ struct sway_config { | |||
505 | char *floating_scroll_right_cmd; | 505 | char *floating_scroll_right_cmd; |
506 | enum sway_container_layout default_orientation; | 506 | enum sway_container_layout default_orientation; |
507 | enum sway_container_layout default_layout; | 507 | enum sway_container_layout default_layout; |
508 | char *font; // Use mostly for IPC. | 508 | char *font; // Used for IPC. |
509 | PangoFontDescription *font_description; // Used internally for rendering and validating. | 509 | PangoFontDescription *font_description; // Used internally for rendering and validating. |
510 | int font_height; | 510 | int font_height; |
511 | int font_baseline; | 511 | int font_baseline; |
diff --git a/include/swaybar/config.h b/include/swaybar/config.h index 4cacd21a..361acd99 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h | |||
@@ -6,6 +6,7 @@ | |||
6 | #include "../include/config.h" | 6 | #include "../include/config.h" |
7 | #include "list.h" | 7 | #include "list.h" |
8 | #include "util.h" | 8 | #include "util.h" |
9 | #include <pango/pangocairo.h> | ||
9 | 10 | ||
10 | struct box_colors { | 11 | struct box_colors { |
11 | uint32_t border; | 12 | uint32_t border; |
@@ -28,7 +29,7 @@ struct swaybar_config { | |||
28 | char *status_command; | 29 | char *status_command; |
29 | bool pango_markup; | 30 | bool pango_markup; |
30 | uint32_t position; // zwlr_layer_surface_v1_anchor | 31 | uint32_t position; // zwlr_layer_surface_v1_anchor |
31 | char *font; | 32 | PangoFontDescription *font_description; |
32 | char *sep_symbol; | 33 | char *sep_symbol; |
33 | char *mode; | 34 | char *mode; |
34 | char *hidden_state; | 35 | char *hidden_state; |
diff --git a/include/swaynag/types.h b/include/swaynag/types.h index 3c3b2754..18f218e0 100644 --- a/include/swaynag/types.h +++ b/include/swaynag/types.h | |||
@@ -4,7 +4,8 @@ | |||
4 | struct swaynag_type { | 4 | struct swaynag_type { |
5 | char *name; | 5 | char *name; |
6 | 6 | ||
7 | char *font; | 7 | char *font; // Used for debugging. |
8 | PangoFontDescription *font_description; | ||
8 | char *output; | 9 | char *output; |
9 | uint32_t anchors; | 10 | uint32_t anchors; |
10 | int32_t layer; // enum zwlr_layer_shell_v1_layer or -1 if unset | 11 | int32_t layer; // enum zwlr_layer_shell_v1_layer or -1 if unset |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 09766ce5..04ef965f 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -520,7 +520,7 @@ static void render_titlebar_text_texture(struct sway_output *output, | |||
520 | to_cairo_subpixel_order(output->wlr_output->subpixel)); | 520 | to_cairo_subpixel_order(output->wlr_output->subpixel)); |
521 | } | 521 | } |
522 | cairo_set_font_options(c, fo); | 522 | cairo_set_font_options(c, fo); |
523 | get_text_size(c, config->font, &width, NULL, &baseline, scale, | 523 | get_text_size(c, config->font_description, &width, NULL, &baseline, scale, |
524 | config->pango_markup, "%s", text); | 524 | config->pango_markup, "%s", text); |
525 | cairo_surface_destroy(dummy_surface); | 525 | cairo_surface_destroy(dummy_surface); |
526 | cairo_destroy(c); | 526 | cairo_destroy(c); |
@@ -554,7 +554,7 @@ static void render_titlebar_text_texture(struct sway_output *output, | |||
554 | class->text[2], class->text[3]); | 554 | class->text[2], class->text[3]); |
555 | cairo_move_to(cairo, 0, config->font_baseline * scale - baseline); | 555 | cairo_move_to(cairo, 0, config->font_baseline * scale - baseline); |
556 | 556 | ||
557 | render_text(cairo, config->font, scale, pango_markup, "%s", text); | 557 | render_text(cairo, config->font_description, scale, pango_markup, "%s", text); |
558 | 558 | ||
559 | cairo_surface_flush(surface); | 559 | cairo_surface_flush(surface); |
560 | unsigned char *data = cairo_image_surface_get_data(surface); | 560 | unsigned char *data = cairo_image_surface_get_data(surface); |
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 |
diff --git a/swaynag/config.c b/swaynag/config.c index 9aeec3c2..a0bf3197 100644 --- a/swaynag/config.c +++ b/swaynag/config.c | |||
@@ -227,7 +227,9 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, | |||
227 | case 'f': // Font | 227 | case 'f': // Font |
228 | if (type) { | 228 | if (type) { |
229 | free(type->font); | 229 | free(type->font); |
230 | pango_font_description_free(type->font_description); | ||
230 | type->font = strdup(optarg); | 231 | type->font = strdup(optarg); |
232 | type->font_description = pango_font_description_from_string(type->font); | ||
231 | } | 233 | } |
232 | break; | 234 | break; |
233 | case 'l': // Detailed Message | 235 | case 'l': // Detailed Message |
diff --git a/swaynag/render.c b/swaynag/render.c index d72f42c2..21b03289 100644 --- a/swaynag/render.c +++ b/swaynag/render.c | |||
@@ -9,7 +9,7 @@ | |||
9 | 9 | ||
10 | static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) { | 10 | static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) { |
11 | int text_width, text_height; | 11 | int text_width, text_height; |
12 | get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL, | 12 | get_text_size(cairo, swaynag->type->font_description, &text_width, &text_height, NULL, |
13 | 1, true, "%s", swaynag->message); | 13 | 1, true, "%s", swaynag->message); |
14 | 14 | ||
15 | int padding = swaynag->type->message_padding; | 15 | int padding = swaynag->type->message_padding; |
@@ -22,7 +22,7 @@ static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) { | |||
22 | 22 | ||
23 | cairo_set_source_u32(cairo, swaynag->type->text); | 23 | cairo_set_source_u32(cairo, swaynag->type->text); |
24 | cairo_move_to(cairo, padding, (int)(ideal_height - text_height) / 2); | 24 | cairo_move_to(cairo, padding, (int)(ideal_height - text_height) / 2); |
25 | render_text(cairo, swaynag->type->font, 1, false, | 25 | render_text(cairo, swaynag->type->font_description, 1, false, |
26 | "%s", swaynag->message); | 26 | "%s", swaynag->message); |
27 | 27 | ||
28 | return ideal_surface_height; | 28 | return ideal_surface_height; |
@@ -31,7 +31,7 @@ static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) { | |||
31 | static void render_details_scroll_button(cairo_t *cairo, | 31 | static void render_details_scroll_button(cairo_t *cairo, |
32 | struct swaynag *swaynag, struct swaynag_button *button) { | 32 | struct swaynag *swaynag, struct swaynag_button *button) { |
33 | int text_width, text_height; | 33 | int text_width, text_height; |
34 | get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL, | 34 | get_text_size(cairo, swaynag->type->font_description, &text_width, &text_height, NULL, |
35 | 1, true, "%s", button->text); | 35 | 1, true, "%s", button->text); |
36 | 36 | ||
37 | int border = swaynag->type->button_border_thickness; | 37 | int border = swaynag->type->button_border_thickness; |
@@ -50,17 +50,17 @@ static void render_details_scroll_button(cairo_t *cairo, | |||
50 | cairo_set_source_u32(cairo, swaynag->type->button_text); | 50 | cairo_set_source_u32(cairo, swaynag->type->button_text); |
51 | cairo_move_to(cairo, button->x + border + padding, | 51 | cairo_move_to(cairo, button->x + border + padding, |
52 | button->y + border + (button->height - text_height) / 2); | 52 | button->y + border + (button->height - text_height) / 2); |
53 | render_text(cairo, swaynag->type->font, 1, true, | 53 | render_text(cairo, swaynag->type->font_description, 1, true, |
54 | "%s", button->text); | 54 | "%s", button->text); |
55 | } | 55 | } |
56 | 56 | ||
57 | static int get_detailed_scroll_button_width(cairo_t *cairo, | 57 | static int get_detailed_scroll_button_width(cairo_t *cairo, |
58 | struct swaynag *swaynag) { | 58 | struct swaynag *swaynag) { |
59 | int up_width, down_width, temp_height; | 59 | int up_width, down_width, temp_height; |
60 | get_text_size(cairo, swaynag->type->font, &up_width, &temp_height, NULL, | 60 | get_text_size(cairo, swaynag->type->font_description, &up_width, &temp_height, NULL, |
61 | 1, true, | 61 | 1, true, |
62 | "%s", swaynag->details.button_up.text); | 62 | "%s", swaynag->details.button_up.text); |
63 | get_text_size(cairo, swaynag->type->font, &down_width, &temp_height, NULL, | 63 | get_text_size(cairo, swaynag->type->font_description, &down_width, &temp_height, NULL, |
64 | 1, true, | 64 | 1, true, |
65 | "%s", swaynag->details.button_down.text); | 65 | "%s", swaynag->details.button_down.text); |
66 | 66 | ||
@@ -83,7 +83,7 @@ static uint32_t render_detailed(cairo_t *cairo, struct swaynag *swaynag, | |||
83 | swaynag->details.y = y + decor; | 83 | swaynag->details.y = y + decor; |
84 | swaynag->details.width = width - decor * 2; | 84 | swaynag->details.width = width - decor * 2; |
85 | 85 | ||
86 | PangoLayout *layout = get_pango_layout(cairo, swaynag->type->font, | 86 | PangoLayout *layout = get_pango_layout(cairo, swaynag->type->font_description, |
87 | swaynag->details.message, 1, false); | 87 | swaynag->details.message, 1, false); |
88 | pango_layout_set_width(layout, | 88 | pango_layout_set_width(layout, |
89 | (swaynag->details.width - padding * 2) * PANGO_SCALE); | 89 | (swaynag->details.width - padding * 2) * PANGO_SCALE); |
@@ -172,7 +172,7 @@ static uint32_t render_button(cairo_t *cairo, struct swaynag *swaynag, | |||
172 | struct swaynag_button *button = swaynag->buttons->items[button_index]; | 172 | struct swaynag_button *button = swaynag->buttons->items[button_index]; |
173 | 173 | ||
174 | int text_width, text_height; | 174 | int text_width, text_height; |
175 | get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL, | 175 | get_text_size(cairo, swaynag->type->font_description, &text_width, &text_height, NULL, |
176 | 1, true, "%s", button->text); | 176 | 1, true, "%s", button->text); |
177 | 177 | ||
178 | int border = swaynag->type->button_border_thickness; | 178 | int border = swaynag->type->button_border_thickness; |
@@ -201,7 +201,7 @@ static uint32_t render_button(cairo_t *cairo, struct swaynag *swaynag, | |||
201 | 201 | ||
202 | cairo_set_source_u32(cairo, swaynag->type->button_text); | 202 | cairo_set_source_u32(cairo, swaynag->type->button_text); |
203 | cairo_move_to(cairo, button->x + padding, button->y + padding); | 203 | cairo_move_to(cairo, button->x + padding, button->y + padding); |
204 | render_text(cairo, swaynag->type->font, 1, true, | 204 | render_text(cairo, swaynag->type->font_description, 1, true, |
205 | "%s", button->text); | 205 | "%s", button->text); |
206 | 206 | ||
207 | *x = button->x - border; | 207 | *x = button->x - border; |