]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Convert SSD title to scaled font buffer
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sun, 12 Jun 2022 19:22:49 +0000 (21:22 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 14 Jun 2022 21:03:08 +0000 (22:03 +0100)
include/ssd.h
src/ssd/ssd_part.c
src/ssd/ssd_titlebar.c

index 027dcc211f5437cf00572213219bf6976f9c0705..302d78d836c1b06dd2b320da7fcf6764e8a510f2 100644 (file)
@@ -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;
index d060f08fbf1c4034bb155e64bc2ccec39b03b1a5..f08af948a2c1796ca4afd013686d4ebf79151542 100644 (file)
@@ -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;
index f8f3c9c4912e3d5d580c4b56cf2922cb2a9aec78..bac4c7edb387ad9242faf7c14232719545670f3c 100644 (file)
@@ -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) {