mirror of
https://github.com/swaywm/sway.git
synced 2024-11-12 21:43:59 +01:00
Merge 1f765b86ec
into 4cfcb3643b
This commit is contained in:
commit
a935432e8a
@ -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);
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user