]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/ssd/: Don't access view->surface->current directly
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Thu, 24 Feb 2022 00:27:29 +0000 (01:27 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 24 Feb 2022 06:56:25 +0000 (06:56 +0000)
Instead use view->{w,h} which are set on client commit

src/ssd/ssd.c
src/ssd/ssd_border.c
src/ssd/ssd_extents.c
src/ssd/ssd_part.c
src/ssd/ssd_titlebar.c

index 677c2017f3945e391130bd0f24f030cf8e904472..72f563068a6839df3c77e870fb37a09979b67cbd 100644 (file)
@@ -164,7 +164,7 @@ void
 ssd_update_geometry(struct view *view)
 {
        /* TODO: verify we are not called without reason. like in commit handlers */
-       if (!view->ssd.tree || !view->surface) {
+       if (!view->ssd.tree || !view->scene_node) {
                return;
        }
 
@@ -175,8 +175,8 @@ ssd_update_geometry(struct view *view)
                wlr_scene_node_set_enabled(&view->ssd.tree->node, false);
        }
 
-       int width = view->surface->current.width;
-       int height = view->surface->current.height;
+       int width = view->w;
+       int height = view->h;
        if (width == view->ssd.state.width && height == view->ssd.state.height) {
                return;
        }
index 399d2c8cdb1f753bcba55c63978efb6e1d0c3cdb..aa289e21130132653984d942ad55372ff44ce8c3 100644 (file)
@@ -13,8 +13,8 @@ void
 ssd_border_create(struct view *view)
 {
        struct theme *theme = view->server->theme;
-       int width = view->surface->current.width;
-       int height = view->surface->current.height;
+       int width = view->w;
+       int height = view->h;
        int full_width = width + 2 * theme->border_width;
 
        float *color;
@@ -48,8 +48,8 @@ ssd_border_update(struct view *view)
 {
        struct theme *theme = view->server->theme;
 
-       int width = view->surface->current.width;
-       int height = view->surface->current.height;
+       int width = view->w;
+       int height = view->h;
        int full_width = width + 2 * theme->border_width;
 
        struct ssd_part *part;
index 0175d76771d5148e99e2c773e98ae32db1890838..d72b5df0161a9ac7414383f38e2cf410acc9dd40 100644 (file)
@@ -11,8 +11,8 @@ ssd_extents_create(struct view *view)
        struct theme *theme = view->server->theme;
        float invisible[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
        struct wl_list *part_list = &view->ssd.extents.parts;
-       int width = view->surface->current.width;
-       int height = view->surface->current.height;
+       int width = view->w;
+       int height = view->h;
        int full_height = height + theme->border_width + SSD_HEIGHT;
        int full_width = width + 2 * theme->border_width;
        int extended_area = EXTENDED_AREA;
@@ -61,8 +61,8 @@ ssd_extents_update(struct view *view)
 {
        struct theme *theme = view->server->theme;
 
-       int width = view->surface->current.width;
-       int height = view->surface->current.height;
+       int width = view->w;
+       int height = view->h;
        int full_height = height + theme->border_width + SSD_HEIGHT;
        int full_width = width + 2 * theme->border_width;
        int extended_area = EXTENDED_AREA;
index ab718637f575b409eede0e7d2069c64154c4746b..f6e55ba105fa759822d8224c151e205235f29356 100644 (file)
@@ -18,6 +18,15 @@ add_scene_rect(struct wl_list *list, enum ssd_part_type type,
        struct wlr_scene_node *parent, int width, int height,
        int x, int y, float color[4])
 {
+       /*
+        * When initialized without surface being mapped,
+        * size may be negative. Just set to 0, next call
+        * to ssd_*_update() will update the rect to use
+        * its correct size.
+        */
+       width = width >= 0 ? width : 0;
+       height = height >= 0 ? height : 0;
+
        struct ssd_part *part = add_scene_part(list, type);
        part->node = &wlr_scene_rect_create(
                parent, width, height, color)->node;
index 16e1785bd5d306afb45d8e80c080dec9245663ba..968bd1443152d861f091f5beba3bf0359e53f863 100644 (file)
@@ -17,7 +17,7 @@ void
 ssd_titlebar_create(struct view *view)
 {
        struct theme *theme = view->server->theme;
-       int width = view->surface->current.width;
+       int width = view->w;
        int full_width = width + 2 * theme->border_width;
 
        float *color;
@@ -72,7 +72,7 @@ is_direct_child(struct wlr_scene_node *node, struct ssd_sub_tree *subtree)
 void
 ssd_titlebar_update(struct view *view)
 {
-       int width = view->surface->current.width;
+       int width = view->w;
        if (width == view->ssd.state.width) {
                return;
        }
@@ -144,7 +144,7 @@ static void
 ssd_update_title_positions(struct view *view)
 {
        struct theme *theme = view->server->theme;
-       int width = view->surface->current.width;
+       int width = view->w;
        int full_width = width + 2 * view->server->theme->border_width;
 
        int x, y;
@@ -154,8 +154,7 @@ ssd_update_title_positions(struct view *view)
        FOR_EACH_STATE(view, subtree) {
                part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE);
                if (!part) {
-                       wlr_log(WLR_ERROR,
-                               "Failed to position SSD title: title node not found");
+                       /* view->surface never been mapped */
                        continue;
                }
 
@@ -163,8 +162,6 @@ ssd_update_title_positions(struct view *view)
                y = (SSD_HEIGHT - part->buffer->base.height) / 2;
                rect = lab_wlr_scene_get_rect(part->node->parent);
                if (rect->width <= 0) {
-                       wlr_log(WLR_ERROR,
-                               "Failed to position SSD title: not enough screen space");
                        wlr_scene_node_set_position(part->node, x, y);
                        continue;
                }
@@ -221,17 +218,8 @@ ssd_update_title(struct view *view)
        struct ssd_state_title_width *dstate;
        FOR_EACH_STATE(view, subtree) {
                parent_part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
-               if (!parent_part) {
-                       wlr_log(WLR_ERROR,
-                               "Failed to update SSD title: parent node not found");
-                       continue;
-               }
-               rect = lab_wlr_scene_get_rect(parent_part->node);
-               if (rect->width <= 0) {
-                       wlr_log(WLR_ERROR,
-                               "Failed to update SSD title: not enough screen space");
-                       continue;
-               }
+               assert(parent_part);
+
                if (subtree == &view->ssd.titlebar.active) {
                        dstate = &state->active;
                        text_color = theme->window_active_label_text_color;
@@ -239,11 +227,19 @@ ssd_update_title(struct view *view)
                        dstate = &state->inactive;
                        text_color = theme->window_inactive_label_text_color;
                }
+
+               rect = lab_wlr_scene_get_rect(parent_part->node);
+               if (rect->width <= 0) {
+                       dstate->truncated = true;
+                       continue;
+               }
+
                if (title_unchanged
                                && !dstate->truncated && dstate->width < rect->width) {
                        /* title the same + we don't need to resize title */
                        continue;
                }
+
                part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE);
                if (!part) {
                        part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE);