From 05ae654547b9bffd8cdcc915f863ad8564b2a2a7 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Sun, 12 Jun 2022 21:22:49 +0200 Subject: [PATCH] Convert SSD title to scaled font buffer --- include/ssd.h | 3 ++- src/ssd/ssd_part.c | 7 +++---- src/ssd/ssd_titlebar.c | 32 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/ssd.h b/include/ssd.h index 027dcc21..302d78d8 100644 --- a/include/ssd.h +++ b/include/ssd.h @@ -53,6 +53,7 @@ struct view; struct wl_list; struct wlr_box; struct wlr_scene_tree; +struct scaled_font_buffer; struct ssd_button { struct view *view; @@ -115,7 +116,7 @@ struct ssd_part { enum ssd_part_type type; /* Buffer pointer. May be NULL */ - struct lab_data_buffer *buffer; + struct scaled_font_buffer *buffer; /* This part represented in scene graph */ struct wlr_scene_node *node; diff --git a/src/ssd/ssd_part.c b/src/ssd/ssd_part.c index d060f08f..f08af948 100644 --- a/src/ssd/ssd_part.c +++ b/src/ssd/ssd_part.c @@ -4,6 +4,7 @@ #include "labwc.h" #include "ssd.h" #include "node.h" +#include "common/font.h" /* Internal helpers */ static void @@ -165,10 +166,8 @@ ssd_destroy_parts(struct wl_list *list) wlr_scene_node_destroy(part->node); part->node = NULL; } - if (part->buffer) { - wlr_buffer_drop(&part->buffer->base); - part->buffer = NULL; - } + /* part->buffer will free itself along the scene_buffer node */ + part->buffer = NULL; if (part->geometry) { free(part->geometry); part->geometry = NULL; diff --git a/src/ssd/ssd_titlebar.c b/src/ssd/ssd_titlebar.c index f8f3c9c4..bac4c7ed 100644 --- a/src/ssd/ssd_titlebar.c +++ b/src/ssd/ssd_titlebar.c @@ -7,6 +7,7 @@ #include "ssd.h" #include "theme.h" #include "common/font.h" +#include "common/scaled_font_buffer.h" #include "common/scene-helpers.h" #include "node.h" @@ -156,13 +157,14 @@ ssd_update_title_positions(struct view *view) struct ssd_sub_tree *subtree; FOR_EACH_STATE(view, subtree) { part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE); - if (!part) { + if (!part || !part->node) { /* view->surface never been mapped */ + /* Or we somehow failed to allocate a scaled titlebar buffer */ continue; } - buffer_width = part->buffer ? part->buffer->base.width : 0; - buffer_height = part->buffer ? part->buffer->base.height : 0; + buffer_width = part->buffer ? part->buffer->width : 0; + buffer_height = part->buffer ? part->buffer->height : 0; x = BUTTON_WIDTH; y = (theme->title_height - buffer_height) / 2; if (title_bg_width <= 0) { @@ -243,25 +245,23 @@ ssd_update_title(struct view *view) if (!part) { /* Initialize part and wlr_scene_buffer without attaching a buffer */ part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE); - part->node = &wlr_scene_buffer_create(subtree->tree, NULL)->node; + part->buffer = scaled_font_buffer_create(subtree->tree); + if (part->buffer) { + part->node = &part->buffer->scene_buffer->node; + } else { + wlr_log(WLR_ERROR, "Failed to create title node"); + } } - /* Generate and update the lab_data_buffer, drops the old buffer */ - font_buffer_update(&part->buffer, title_bg_width, title, &font, - text_color, 1); - if (!part->buffer) { - /* This can happen for example by defining a font size of 0 */ - wlr_log(WLR_ERROR, "Failed to create title buffer"); + if (part->buffer) { + scaled_font_buffer_update(part->buffer, + title, title_bg_width, &font, text_color); } - /* (Re)set the buffer */ - wlr_scene_buffer_set_buffer( - wlr_scene_buffer_from_node(part->node), - part->buffer ? &part->buffer->base : NULL); - /* And finally update the cache */ - dstate->width = part->buffer ? part->buffer->base.width : 0; + dstate->width = part->buffer ? part->buffer->width : 0; dstate->truncated = title_bg_width <= dstate->width; + } FOR_EACH_END if (!title_unchanged) { -- 2.52.0