diff --git a/common/pango.c b/common/pango.c index e52b52b93..288569b30 100644 --- a/common/pango.c +++ b/common/pango.c @@ -53,8 +53,6 @@ size_t escape_markup_text(const char *src, char *dest) { PangoLayout *get_pango_layout(cairo_t *cairo, const PangoFontDescription *desc, const char *text, double scale, bool markup) { PangoLayout *layout = pango_cairo_create_layout(cairo); - pango_context_set_round_glyph_positions(pango_layout_get_context(layout), false); - PangoAttrList *attrs; if (markup) { char *buf; @@ -106,7 +104,6 @@ void get_text_size(cairo_t *cairo, const PangoFontDescription *desc, int *width, void get_text_metrics(const PangoFontDescription *description, int *height, int *baseline) { cairo_t *cairo = cairo_create(NULL); PangoContext *pango = pango_cairo_create_context(cairo); - pango_context_set_round_glyph_positions(pango, false); // When passing NULL as a language, pango uses the current locale. PangoFontMetrics *metrics = pango_context_get_metrics(pango, description, NULL); diff --git a/include/sway/sway_text_node.h b/include/sway/sway_text_node.h index 0d4209bb6..83123aab2 100644 --- a/include/sway/sway_text_node.h +++ b/include/sway/sway_text_node.h @@ -6,7 +6,7 @@ struct sway_text_node { int width; int max_width; int height; - int baseline; + float baseline; bool pango_markup; float color[4]; float background[4]; diff --git a/sway/sway_text_node.c b/sway/sway_text_node.c index 7c7813559..fbd338e5a 100644 --- a/sway/sway_text_node.c +++ b/sway/sway_text_node.c @@ -9,6 +9,7 @@ #include "pango.h" #include "sway/config.h" #include "sway/sway_text_node.h" +#include "sway/output.h" struct cairo_buffer { struct wlr_buffer base; @@ -163,6 +164,39 @@ err: cairo_font_options_destroy(fo); } +static void text_calc_size(struct text_buffer *buffer) { + struct sway_text_node *props = &buffer->props; + props->width = 0; + + cairo_t *c = cairo_create(NULL); + if (!c) { + sway_log(SWAY_ERROR, "cairo_t allocation failed"); + return; + } + + cairo_set_antialias(c, CAIRO_ANTIALIAS_BEST); + for (int i = 0; i < root->outputs->length; ++i) { + struct sway_output *output = root->outputs->items[i]; + if (!output->wlr_output->enabled) { + continue; + } + + int size, baseline; + get_text_size(c, config->font_description, &size, NULL, + &baseline, output->wlr_output->scale, props->pango_markup, "%s", buffer->text); + + size = ceil((float)size / output->wlr_output->scale); + if (props->width < size) { + props->width = size; + props->baseline = (float)baseline / output->wlr_output->scale; + } + } + cairo_destroy(c); + + wlr_scene_buffer_set_dest_size(buffer->buffer_node, + get_text_width(props), props->height); +} + static void handle_outputs_update(struct wl_listener *listener, void *data) { struct text_buffer *buffer = wl_container_of(listener, buffer, outputs_update); struct wlr_scene_outputs_update_event *event = data; @@ -194,6 +228,7 @@ static void handle_outputs_update(struct wl_listener *listener, void *data) { if (scale != buffer->scale || subpixel != buffer->subpixel) { buffer->scale = scale; buffer->subpixel = subpixel; + text_calc_size(buffer); render_backing_buffer(buffer); } } @@ -208,24 +243,6 @@ static void handle_destroy(struct wl_listener *listener, void *data) { free(buffer); } -static void text_calc_size(struct text_buffer *buffer) { - struct sway_text_node *props = &buffer->props; - - cairo_t *c = cairo_create(NULL); - if (!c) { - sway_log(SWAY_ERROR, "cairo_t allocation failed"); - return; - } - - cairo_set_antialias(c, CAIRO_ANTIALIAS_BEST); - get_text_size(c, config->font_description, &props->width, NULL, - &props->baseline, 1, props->pango_markup, "%s", buffer->text); - cairo_destroy(c); - - wlr_scene_buffer_set_dest_size(buffer->buffer_node, - get_text_width(props), props->height); -} - struct sway_text_node *sway_text_node_create(struct wlr_scene_tree *parent, char *text, float color[4], bool pango_markup) { struct text_buffer *buffer = calloc(1, sizeof(*buffer));