mirror of
https://github.com/swaywm/sway.git
synced 2025-10-29 05:40:18 -04:00
Reuse parsed PangoFontDescription
Avoids parsing the configured font each time text is rendered.
This commit is contained in:
parent
75605491a5
commit
80e386fd97
11 changed files with 52 additions and 49 deletions
|
|
@ -26,7 +26,7 @@ struct swaybar_config *init_config(void) {
|
|||
config->status_command = NULL;
|
||||
config->pango_markup = false;
|
||||
config->position = parse_position("bottom");
|
||||
config->font = strdup("monospace 10");
|
||||
config->font_description = pango_font_description_from_string("monospace 10");
|
||||
config->mode = strdup("dock");
|
||||
config->hidden_state = strdup("hide");
|
||||
config->sep_symbol = NULL;
|
||||
|
|
@ -105,7 +105,7 @@ void free_tray_binding(struct tray_binding *binding) {
|
|||
|
||||
void free_config(struct swaybar_config *config) {
|
||||
free(config->status_command);
|
||||
free(config->font);
|
||||
pango_font_description_free(config->font_description);
|
||||
free(config->mode);
|
||||
free(config->hidden_state);
|
||||
free(config->sep_symbol);
|
||||
|
|
|
|||
|
|
@ -147,8 +147,10 @@ static bool ipc_parse_config(
|
|||
|
||||
json_object *font = json_object_object_get(bar_config, "font");
|
||||
if (font) {
|
||||
free(config->font);
|
||||
config->font = parse_font(json_object_get_string(font));
|
||||
pango_font_description_free(config->font_description);
|
||||
char *font_value = parse_font(json_object_get_string(font));
|
||||
config->font_description = pango_font_description_from_string(font_value);
|
||||
free(font_value);
|
||||
}
|
||||
|
||||
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,
|
|||
destroy_layer_surface(output);
|
||||
wl_list_remove(&output->link);
|
||||
wl_list_insert(&bar->unused_outputs, &output->link);
|
||||
} else if (!oldcfg->font || !newcfg->font ||
|
||||
strcmp(oldcfg->font, newcfg->font) != 0) {
|
||||
} else if (!pango_font_description_equal(oldcfg->font_description, newcfg->font_description)) {
|
||||
output->height = 0; // force update height
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ static uint32_t render_status_line_error(struct render_context *ctx, double *x)
|
|||
int margin = 3;
|
||||
double ws_vertical_padding = output->bar->config->status_padding;
|
||||
|
||||
char *font = output->bar->config->font;
|
||||
PangoFontDescription *font = output->bar->config->font_description;
|
||||
int text_width, text_height;
|
||||
get_text_size(cairo, font, &text_width, &text_height, NULL,
|
||||
1, false, "%s", error);
|
||||
|
|
@ -97,7 +97,7 @@ static uint32_t render_status_line_text(struct render_context *ctx, double *x) {
|
|||
cairo_set_source_u32(cairo, fontcolor);
|
||||
|
||||
int text_width, text_height;
|
||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
||||
get_text_size(cairo, config->font_description, &text_width, &text_height, NULL,
|
||||
1, config->pango_markup, "%s", text);
|
||||
|
||||
double ws_vertical_padding = config->status_padding;
|
||||
|
|
@ -115,7 +115,7 @@ static uint32_t render_status_line_text(struct render_context *ctx, double *x) {
|
|||
double text_y = height / 2.0 - text_height / 2.0;
|
||||
cairo_move_to(cairo, *x, (int)floor(text_y));
|
||||
choose_text_aa_mode(ctx, fontcolor);
|
||||
render_text(cairo, config->font, 1, config->pango_markup, "%s", text);
|
||||
render_text(cairo, config->font_description, 1, config->pango_markup, "%s", text);
|
||||
*x -= margin;
|
||||
return output->height;
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ static uint32_t render_status_block(struct render_context *ctx,
|
|||
struct swaybar_output *output = ctx->output;
|
||||
struct swaybar_config *config = output->bar->config;
|
||||
int text_width, text_height;
|
||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL, 1,
|
||||
get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, 1,
|
||||
block->markup, "%s", text);
|
||||
|
||||
int margin = 3;
|
||||
|
|
@ -199,7 +199,7 @@ static uint32_t render_status_block(struct render_context *ctx,
|
|||
int width = text_width;
|
||||
if (block->min_width_str) {
|
||||
int w;
|
||||
get_text_size(cairo, config->font, &w, NULL, NULL, 1, block->markup,
|
||||
get_text_size(cairo, config->font_description, &w, NULL, NULL, 1, block->markup,
|
||||
"%s", block->min_width_str);
|
||||
block->min_width = w;
|
||||
}
|
||||
|
|
@ -229,7 +229,7 @@ static uint32_t render_status_block(struct render_context *ctx,
|
|||
int sep_block_width = block->separator_block_width;
|
||||
if (!edge) {
|
||||
if (config->sep_symbol) {
|
||||
get_text_size(cairo, config->font, &sep_width, &sep_height, NULL,
|
||||
get_text_size(cairo, config->font_description, &sep_width, &sep_height, NULL,
|
||||
1, false, "%s", config->sep_symbol);
|
||||
uint32_t _ideal_height = sep_height + ws_vertical_padding * 2;
|
||||
uint32_t _ideal_surface_height = _ideal_height;
|
||||
|
|
@ -307,7 +307,7 @@ static uint32_t render_status_block(struct render_context *ctx,
|
|||
color = block->urgent ? config->colors.urgent_workspace.text : color;
|
||||
cairo_set_source_u32(cairo, color);
|
||||
choose_text_aa_mode(ctx, color);
|
||||
render_text(cairo, config->font, 1, block->markup, "%s", text);
|
||||
render_text(cairo, config->font_description, 1, block->markup, "%s", text);
|
||||
x_pos += width;
|
||||
|
||||
if (block->border_set || block->urgent) {
|
||||
|
|
@ -331,7 +331,7 @@ static uint32_t render_status_block(struct render_context *ctx,
|
|||
double sep_y = height / 2.0 - sep_height / 2.0;
|
||||
cairo_move_to(cairo, offset, (int)floor(sep_y));
|
||||
choose_text_aa_mode(ctx, color);
|
||||
render_text(cairo, config->font, 1, false,
|
||||
render_text(cairo, config->font_description, 1, false,
|
||||
"%s", config->sep_symbol);
|
||||
} else {
|
||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||
|
|
@ -354,7 +354,7 @@ static void predict_status_block_pos(cairo_t *cairo,
|
|||
struct swaybar_config *config = output->bar->config;
|
||||
|
||||
int text_width, text_height;
|
||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL, 1,
|
||||
get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, 1,
|
||||
block->markup, "%s", block->full_text);
|
||||
|
||||
int margin = 3;
|
||||
|
|
@ -364,7 +364,7 @@ static void predict_status_block_pos(cairo_t *cairo,
|
|||
|
||||
if (block->min_width_str) {
|
||||
int w;
|
||||
get_text_size(cairo, config->font, &w, NULL, NULL,
|
||||
get_text_size(cairo, config->font_description, &w, NULL, NULL,
|
||||
1, block->markup, "%s", block->min_width_str);
|
||||
block->min_width = w;
|
||||
}
|
||||
|
|
@ -391,7 +391,7 @@ static void predict_status_block_pos(cairo_t *cairo,
|
|||
int sep_block_width = block->separator_block_width;
|
||||
if (!edge) {
|
||||
if (config->sep_symbol) {
|
||||
get_text_size(cairo, config->font, &sep_width, &sep_height, NULL,
|
||||
get_text_size(cairo, config->font_description, &sep_width, &sep_height, NULL,
|
||||
1, false, "%s", config->sep_symbol);
|
||||
uint32_t _ideal_height = sep_height + ws_vertical_padding * 2;
|
||||
uint32_t _ideal_surface_height = _ideal_height;
|
||||
|
|
@ -426,7 +426,7 @@ static uint32_t predict_workspace_button_length(cairo_t *cairo,
|
|||
struct swaybar_config *config = output->bar->config;
|
||||
|
||||
int text_width, text_height;
|
||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL, 1,
|
||||
get_text_size(cairo, config->font_description, &text_width, &text_height, NULL, 1,
|
||||
config->pango_markup, "%s", ws->label);
|
||||
|
||||
int ws_vertical_padding = WS_VERTICAL_PADDING;
|
||||
|
|
@ -474,7 +474,7 @@ static uint32_t predict_binding_mode_indicator_length(cairo_t *cairo,
|
|||
}
|
||||
|
||||
int text_width, text_height;
|
||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
||||
get_text_size(cairo, config->font_description, &text_width, &text_height, NULL,
|
||||
1, output->bar->mode_pango_markup,
|
||||
"%s", mode);
|
||||
|
||||
|
|
@ -551,7 +551,7 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx,
|
|||
cairo_t *cairo = ctx->cairo;
|
||||
struct swaybar_config *config = output->bar->config;
|
||||
int text_width, text_height;
|
||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
||||
get_text_size(cairo, config->font_description, &text_width, &text_height, NULL,
|
||||
1, output->bar->mode_pango_markup,
|
||||
"%s", mode);
|
||||
|
||||
|
|
@ -592,7 +592,7 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx,
|
|||
cairo_set_source_u32(cairo, config->colors.binding_mode.text);
|
||||
cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
|
||||
choose_text_aa_mode(ctx, config->colors.binding_mode.text);
|
||||
render_text(cairo, config->font, 1, output->bar->mode_pango_markup,
|
||||
render_text(cairo, config->font_description, 1, output->bar->mode_pango_markup,
|
||||
"%s", mode);
|
||||
return output->height;
|
||||
}
|
||||
|
|
@ -626,7 +626,7 @@ static uint32_t render_workspace_button(struct render_context *ctx,
|
|||
|
||||
cairo_t *cairo = ctx->cairo;
|
||||
int text_width, text_height;
|
||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
||||
get_text_size(cairo, config->font_description, &text_width, &text_height, NULL,
|
||||
1, config->pango_markup, "%s", ws->label);
|
||||
|
||||
int ws_vertical_padding = WS_VERTICAL_PADDING;
|
||||
|
|
@ -666,7 +666,7 @@ static uint32_t render_workspace_button(struct render_context *ctx,
|
|||
cairo_set_source_u32(cairo, box_colors.text);
|
||||
cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y));
|
||||
choose_text_aa_mode(ctx, box_colors.text);
|
||||
render_text(cairo, config->font, 1, config->pango_markup,
|
||||
render_text(cairo, config->font_description, 1, config->pango_markup,
|
||||
"%s", ws->label);
|
||||
|
||||
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
||||
|
|
@ -699,7 +699,7 @@ static uint32_t render_to_cairo(struct render_context *ctx) {
|
|||
cairo_paint(cairo);
|
||||
|
||||
int th;
|
||||
get_text_size(cairo, config->font, NULL, &th, NULL, 1, false, "");
|
||||
get_text_size(cairo, config->font_description, NULL, &th, NULL, 1, false, "");
|
||||
uint32_t max_height = (th + WS_VERTICAL_PADDING * 4);
|
||||
/*
|
||||
* Each render_* function takes the actual height of the bar, and returns
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue