]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Chase wlroots: prep work: ssd to tree
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sun, 5 Jun 2022 13:17:15 +0000 (15:17 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 7 Jun 2022 06:13:37 +0000 (07:13 +0100)
src/ssd/ssd_part.c
src/ssd/ssd_titlebar.c

index ec754697983d0e5236853b266f45600f84ec2bd7..f7c4c51daaa02e0a57f250c3558eaf0445076f79 100644 (file)
@@ -52,22 +52,14 @@ finish_scene_button(struct wl_list *part_list, enum ssd_part_type type,
        float hover_bg[4] = {0.15f, 0.15f, 0.15f, 0.3f};
 
        /* Icon */
-       int offset_y = 0;
-       int offset_x = 0;
-       if (type == LAB_SSD_BUTTON_WINDOW_MENU) {
-               offset_y = rc.theme->border_width;
-               offset_x = rc.theme->border_width;
-       } else if (type == LAB_SSD_BUTTON_CLOSE) {
-               offset_y = rc.theme->border_width;
-       }
        add_scene_buffer(part_list, type, parent, icon_buffer,
-               offset_x + (BUTTON_WIDTH - icon_buffer->width) / 2,
-               offset_y + (rc.theme->title_height - icon_buffer->height) / 2);
+               (BUTTON_WIDTH - icon_buffer->width) / 2,
+               (rc.theme->title_height - icon_buffer->height) / 2);
 
        /* Hover overlay */
        struct ssd_part *hover_part;
        hover_part = add_scene_rect(part_list, type, parent, BUTTON_WIDTH,
-               rc.theme->title_height, offset_x, offset_y, hover_bg);
+               rc.theme->title_height, 0, 0, hover_bg);
        wlr_scene_node_set_enabled(hover_part->node, false);
 }
 
@@ -76,14 +68,28 @@ add_scene_button_corner(struct wl_list *part_list, enum ssd_part_type type,
        struct wlr_scene_node *parent, struct wlr_buffer *corner_buffer,
        struct wlr_buffer *icon_buffer, int x)
 {
+       struct ssd_part *button_root = add_scene_part(part_list, type);
+       parent = &wlr_scene_tree_create(parent)->node;
+       button_root->node = parent;
+       wlr_scene_node_set_position(button_root->node, x, 0);
+
+       int offset_x;
+       if (type == LAB_SSD_BUTTON_WINDOW_MENU) {
+               offset_x = rc.theme->border_width;
+       } else if (type == LAB_SSD_BUTTON_CLOSE) {
+               offset_x = 0;
+       } else {
+               assert(false && "invalid corner button type");
+       }
+
        struct ssd_part *part;
        /*
         * Background, y adjusted for border_width which is
         * already included in rendered theme.c / corner_buffer
         */
        part = add_scene_buffer(part_list, type, parent, corner_buffer,
-               x, -rc.theme->border_width);
-       finish_scene_button(part_list, type, part->node, icon_buffer);
+               -offset_x, -rc.theme->border_width);
+       finish_scene_button(part_list, type, parent, icon_buffer);
        return part;
 }
 
@@ -92,11 +98,16 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
        struct wlr_scene_node *parent, float *bg_color,
        struct wlr_buffer *icon_buffer, int x)
 {
+       struct ssd_part *button_root = add_scene_part(part_list, type);
+       parent = &wlr_scene_tree_create(parent)->node;
+       button_root->node = parent;
+       wlr_scene_node_set_position(button_root->node, x, 0);
+
        struct ssd_part *part;
        /* Background */
        part = add_scene_rect(part_list, type, parent,
-               BUTTON_WIDTH, rc.theme->title_height, x, 0, bg_color);
-       finish_scene_button(part_list, type, part->node, icon_buffer);
+               BUTTON_WIDTH, rc.theme->title_height, 0, 0, bg_color);
+       finish_scene_button(part_list, type, parent, icon_buffer);
        return part;
 }
 
index 7a80a0a79d62019388d0dabf13fe72ff965da15b..d9931372f5b4df791c6f52213cd971db6c7aab3c 100644 (file)
@@ -48,7 +48,7 @@ ssd_titlebar_create(struct view *view)
                /* Buttons */
                add_scene_button_corner(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU,
                        parent, corner_top_left,
-                       &theme->xbm_menu_active_unpressed->base, -theme->border_width);
+                       &theme->xbm_menu_active_unpressed->base, 0);
                add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
                        color, &theme->xbm_iconify_active_unpressed->base,
                        width - BUTTON_WIDTH * 3);
@@ -103,8 +103,7 @@ ssd_titlebar_update(struct view *view)
                        case LAB_SSD_BUTTON_CLOSE:
                                if (is_direct_child(part->node, subtree)) {
                                        wlr_scene_node_set_position(part->node,
-                                               width - BUTTON_WIDTH * 1,
-                                               -theme->border_width);
+                                               width - BUTTON_WIDTH * 1, 0);
                                }
                                continue;
                        default:
@@ -147,11 +146,10 @@ ssd_update_title_positions(struct view *view)
 {
        struct theme *theme = view->server->theme;
        int width = view->w;
-       int full_width = width + 2 * view->server->theme->border_width;
+       int title_bg_width = width - BUTTON_WIDTH * BUTTON_COUNT;
 
        int x, y;
        int buffer_height, buffer_width;
-       struct wlr_scene_rect *rect;
        struct ssd_part *part;
        struct ssd_sub_tree *subtree;
        FOR_EACH_STATE(view, subtree) {
@@ -163,29 +161,27 @@ ssd_update_title_positions(struct view *view)
 
                buffer_width = part->buffer ? part->buffer->base.width : 0;
                buffer_height = part->buffer ? part->buffer->base.height : 0;
-               x = 0;
+               x = BUTTON_WIDTH;
                y = (theme->title_height - buffer_height) / 2;
-               rect = lab_wlr_scene_get_rect(part->node->parent);
-               if (rect->width <= 0) {
+               if (title_bg_width <= 0) {
                        wlr_scene_node_set_position(part->node, x, y);
                        continue;
                }
 
                if (theme->window_label_text_justify == LAB_JUSTIFY_CENTER) {
-                       if (buffer_width + BUTTON_WIDTH * 2 <= rect->width) {
+                       if (buffer_width + BUTTON_WIDTH * 2 <= title_bg_width) {
                                /* Center based on the full width */
-                               x = (full_width - buffer_width) / 2;
-                               x -= BUTTON_WIDTH;
+                               x = (width - buffer_width) / 2;
                        } else {
                                /*
                                 * Center based on the width between the buttons.
                                 * Title jumps around once this is hit but its still
                                 * better than to hide behind the buttons on the right.
                                 */
-                               x = (rect->width - buffer_width) / 2;
+                               x += (title_bg_width - buffer_width) / 2;
                        }
                } else if (theme->window_label_text_justify == LAB_JUSTIFY_RIGHT) {
-                       x = rect->width - buffer_width;
+                       x += title_bg_width - buffer_width;
                } else if (theme->window_label_text_justify == LAB_JUSTIFY_LEFT) {
                        /* TODO: maybe add some theme x padding here? */
                }
@@ -216,15 +212,12 @@ ssd_update_title(struct view *view)
        };
 
        float *text_color;
-       struct wlr_scene_rect *rect;
        struct ssd_part *part;
-       struct ssd_part *parent_part;
        struct ssd_sub_tree *subtree;
        struct ssd_state_title_width *dstate;
-       FOR_EACH_STATE(view, subtree) {
-               parent_part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
-               assert(parent_part);
+       int title_bg_width = view->w - BUTTON_WIDTH * BUTTON_COUNT;
 
+       FOR_EACH_STATE(view, subtree) {
                if (subtree == &view->ssd.titlebar.active) {
                        dstate = &state->active;
                        text_color = theme->window_active_label_text_color;
@@ -233,14 +226,13 @@ ssd_update_title(struct view *view)
                        text_color = theme->window_inactive_label_text_color;
                }
 
-               rect = lab_wlr_scene_get_rect(parent_part->node);
-               if (rect->width <= 0) {
+               if (title_bg_width <= 0) {
                        dstate->truncated = true;
                        continue;
                }
 
                if (title_unchanged
-                               && !dstate->truncated && dstate->width < rect->width) {
+                               && !dstate->truncated && dstate->width < title_bg_width) {
                        /* title the same + we don't need to resize title */
                        continue;
                }
@@ -249,11 +241,11 @@ 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(parent_part->node, NULL)->node;
+                       part->node = &wlr_scene_buffer_create(&subtree->tree->node, NULL)->node;
                }
 
                /* Generate and update the lab_data_buffer, drops the old buffer */
-               font_buffer_update(&part->buffer, rect->width, title, &font, text_color);
+               font_buffer_update(&part->buffer, title_bg_width, title, &font, text_color);
                if (!part->buffer) {
                        /* This can happen for example by defining a font size of 0 */
                        wlr_log(WLR_ERROR, "Failed to create title buffer");
@@ -266,7 +258,7 @@ ssd_update_title(struct view *view)
 
                /* And finally update the cache */
                dstate->width = part->buffer ? part->buffer->base.width : 0;
-               dstate->truncated = rect->width <= dstate->width;
+               dstate->truncated = title_bg_width <= dstate->width;
        } FOR_EACH_END
 
        if (!title_unchanged) {
@@ -302,7 +294,7 @@ ssd_button_hover_enable(struct view *view, enum ssd_part_type type)
                                return NULL;
                        }
                        struct wlr_scene_node *child;
-                       wl_list_for_each(child, &part->node->state.children, state.link) {
+                       wl_list_for_each_reverse(child, &part->node->state.children, state.link) {
                                if (child->type == WLR_SCENE_NODE_RECT) {
                                        wlr_scene_node_set_enabled(child, true);
                                        return child;