]> git.mdlowis.com Git - proto/labwc.git/commitdiff
ssd: do not draw background for individual buttons
authorTobias Bengfort <tobias.bengfort@posteo.de>
Sat, 17 Aug 2024 12:46:35 +0000 (14:46 +0200)
committerTobias Bengfort <tobias.bengfort@posteo.de>
Sun, 18 Aug 2024 08:50:27 +0000 (10:50 +0200)
include/ssd-internal.h
src/ssd/ssd-part.c
src/ssd/ssd-titlebar.c

index fda196e6aaf7b952349709ea66bde612b1b23de6..c6e3ba770d0e9c8ac303e0db39b3c6423e03873e 100644 (file)
@@ -22,7 +22,6 @@ struct ssd_button {
        struct wlr_scene_node *hover;
        struct wlr_scene_node *toggled;
        struct wlr_scene_node *toggled_hover;
-       struct wlr_scene_node *background;
        struct wlr_scene_tree *icon_tree;
        struct wlr_scene_tree *hover_tree;
 
@@ -127,17 +126,11 @@ struct ssd_part *add_scene_buffer(
        struct wlr_scene_tree *parent, struct wlr_buffer *buffer, int x, int y);
 struct ssd_part *add_scene_button(
        struct wl_list *part_list, enum ssd_part_type type,
-       struct wlr_scene_tree *parent, float *bg_color,
-       struct wlr_buffer *icon_buffer, struct wlr_buffer *hover_buffer,
-       int x, struct view *view);
+       struct wlr_scene_tree *parent, struct wlr_buffer *icon_buffer,
+       struct wlr_buffer *hover_buffer, int x, struct view *view);
 void add_toggled_icon(struct ssd_button *button, struct wl_list *part_list,
        enum ssd_part_type type, struct wlr_buffer *icon_buffer,
        struct wlr_buffer *hover_buffer);
-struct ssd_part *add_scene_button_corner(
-       struct wl_list *part_list, enum ssd_part_type type,
-       enum ssd_part_type corner_type, struct wlr_scene_tree *parent,
-       struct wlr_buffer *corner_buffer, struct wlr_buffer *icon_buffer,
-       struct wlr_buffer *hover_buffer, int x, struct view *view);
 
 /* SSD internal helpers */
 struct ssd_part *ssd_get_part(
index 5c9036096fe4f70a050bd90e84c6068ff8162ed2..9c3294e2ef0d977eae09ca412c2a1de0723eec28 100644 (file)
@@ -78,42 +78,6 @@ add_scene_buffer(struct wl_list *list, enum ssd_part_type type,
        return part;
 }
 
-struct ssd_part *
-add_scene_button_corner(struct wl_list *part_list, enum ssd_part_type type,
-               enum ssd_part_type corner_type, struct wlr_scene_tree *parent,
-               struct wlr_buffer *corner_buffer, struct wlr_buffer *icon_buffer,
-               struct wlr_buffer *hover_buffer, int x, struct view *view)
-{
-       int offset_x;
-       float invisible[4] = { 0, 0, 0, 0 };
-
-       if (corner_type == LAB_SSD_PART_CORNER_TOP_LEFT) {
-               offset_x = rc.theme->border_width;
-       } else if (corner_type == LAB_SSD_PART_CORNER_TOP_RIGHT) {
-               offset_x = 0;
-       } else {
-               assert(false && "invalid corner button type");
-               wlr_log(WLR_ERROR, "invalid corner button type");
-               abort();
-       }
-
-       struct ssd_part *button_root = add_scene_part(part_list, corner_type);
-       parent = wlr_scene_tree_create(parent);
-       button_root->node = &parent->node;
-       wlr_scene_node_set_position(button_root->node, x, 0);
-
-       /*
-        * Background, x and y adjusted for border_width which is
-        * already included in rendered theme.c / corner_buffer
-        */
-       add_scene_buffer(part_list, corner_type, parent, corner_buffer,
-               -offset_x, -rc.theme->border_width);
-
-       /* Finally just put a usual theme button on top, using an invisible hitbox */
-       add_scene_button(part_list, type, parent, invisible, icon_buffer, hover_buffer, 0, view);
-       return button_root;
-}
-
 static struct wlr_box
 get_scale_box(struct wlr_buffer *buffer, double container_width,
                double container_height)
@@ -142,19 +106,19 @@ get_scale_box(struct wlr_buffer *buffer, double container_width,
 
 struct ssd_part *
 add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
-               struct wlr_scene_tree *parent, float *bg_color,
-               struct wlr_buffer *icon_buffer, struct wlr_buffer *hover_buffer,
-               int x, struct view *view)
+               struct wlr_scene_tree *parent, struct wlr_buffer *icon_buffer,
+               struct wlr_buffer *hover_buffer, int x, struct view *view)
 {
        struct ssd_part *button_root = add_scene_part(part_list, type);
        parent = wlr_scene_tree_create(parent);
        button_root->node = &parent->node;
        wlr_scene_node_set_position(button_root->node, x, 0);
 
-       /* Background */
-       struct ssd_part *bg_rect = add_scene_rect(part_list, type, parent,
+       /* Hitbox */
+       float invisible[4] = { 0, 0, 0, 0 };
+       add_scene_rect(part_list, type, parent,
                rc.theme->window_button_width, rc.theme->title_height, 0, 0,
-               bg_color);
+               invisible);
 
        /* Icon */
        struct wlr_scene_tree *icon_tree = wlr_scene_tree_create(parent);
@@ -186,7 +150,6 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
        button->view = view;
        button->normal = icon_part->node;
        button->hover = hover_part->node;
-       button->background = bg_rect->node;
        button->toggled = NULL;
        button->toggled_hover = NULL;
        button->icon_tree = icon_tree;
index 70d9ca6bf837a714045a671a6e00766d6e41a656..ba4dc2bfca98758a936efb9c3e03676ac85ca24d 100644 (file)
@@ -88,30 +88,34 @@ ssd_titlebar_create(struct ssd *ssd)
                }
                wl_list_init(&subtree->parts);
 
-               /* Title */
+               /* Background */
                add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
-                       width - theme->window_button_width * SSD_BUTTON_COUNT,
-                       theme->title_height, theme->window_button_width, 0, color);
+                       width - theme->window_button_width * 2, theme->title_height,
+                       theme->window_button_width, 0, color);
+               add_scene_buffer(&subtree->parts, LAB_SSD_PART_CORNER_TOP_LEFT, parent,
+                       corner_top_left, -rc.theme->border_width, -rc.theme->border_width);
+               add_scene_buffer(&subtree->parts, LAB_SSD_PART_CORNER_TOP_RIGHT, parent,
+                       corner_top_right, width - theme->window_button_width,
+                       -rc.theme->border_width);
+
                /* Buttons */
-               add_scene_button_corner(&subtree->parts,
-                       LAB_SSD_BUTTON_WINDOW_MENU, LAB_SSD_PART_CORNER_TOP_LEFT, parent,
-                       corner_top_left, menu_button_unpressed, menu_button_hover, 0, view);
+               add_scene_button(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU, parent,
+                       menu_button_unpressed, menu_button_hover, 0, view);
                add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
-                       color, iconify_button_unpressed, iconify_button_hover,
+                       iconify_button_unpressed, iconify_button_hover,
                        width - theme->window_button_width * 3, view);
 
                /* Maximize button has an alternate state when maximized */
                struct ssd_part *btn_max_root = add_scene_button(
                        &subtree->parts, LAB_SSD_BUTTON_MAXIMIZE, parent,
-                       color, maximize_button_unpressed, maximize_button_hover,
+                       maximize_button_unpressed, maximize_button_hover,
                        width - theme->window_button_width * 2, view);
                struct ssd_button *btn_max = node_ssd_button_from_node(btn_max_root->node);
                add_toggled_icon(btn_max, &subtree->parts, LAB_SSD_BUTTON_MAXIMIZE,
                        restore_button_unpressed, restore_button_hover);
 
-               add_scene_button_corner(&subtree->parts,
-                       LAB_SSD_BUTTON_CLOSE, LAB_SSD_PART_CORNER_TOP_RIGHT, parent,
-                       corner_top_right, close_button_unpressed, close_button_hover,
+               add_scene_button(&subtree->parts, LAB_SSD_BUTTON_CLOSE, parent,
+                       close_button_unpressed, close_button_hover,
                        width - theme->window_button_width * 1, view);
        } FOR_EACH_END
 
@@ -138,27 +142,25 @@ is_direct_child(struct wlr_scene_node *node, struct ssd_sub_tree *subtree)
 static void
 set_squared_corners(struct ssd *ssd, bool enable)
 {
+       struct view *view = ssd->view;
+       int width = view->current.width;
+       struct theme *theme = view->server->theme;
+
        struct ssd_part *part;
        struct ssd_sub_tree *subtree;
-       enum ssd_part_type ssd_type[2] = { LAB_SSD_BUTTON_WINDOW_MENU, LAB_SSD_BUTTON_CLOSE };
+       int x = enable ? 0 : theme->window_button_width;
 
        FOR_EACH_STATE(ssd, subtree) {
-               for (size_t i = 0; i < ARRAY_SIZE(ssd_type); i++) {
-                       part = ssd_get_part(&subtree->parts, ssd_type[i]);
-                       struct ssd_button *button = node_ssd_button_from_node(part->node);
-
-                       /* Toggle background between invisible and titlebar background color */
-                       struct wlr_scene_rect *rect = wlr_scene_rect_from_node(button->background);
-                       wlr_scene_rect_set_color(rect, !enable ? (float[4]) {0, 0, 0, 0} : (
-                               subtree == &ssd->titlebar.active
-                                       ? rc.theme->window_active_title_bg_color
-                                       : rc.theme->window_inactive_title_bg_color));
-
-                       /* Toggle rounded corner image itself */
-                       struct wlr_scene_node *rounded_corner =
-                               wl_container_of(part->node->link.prev, rounded_corner, link);
-                       wlr_scene_node_set_enabled(rounded_corner, !enable);
-               }
+               part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
+               wlr_scene_node_set_position(part->node, x, 0);
+               wlr_scene_rect_set_size(
+                       wlr_scene_rect_from_node(part->node), width - 2 * x, theme->title_height);
+
+               part = ssd_get_part(&subtree->parts, LAB_SSD_PART_CORNER_TOP_LEFT);
+               wlr_scene_node_set_enabled(part->node, !enable);
+
+               part = ssd_get_part(&subtree->parts, LAB_SSD_PART_CORNER_TOP_RIGHT);
+               wlr_scene_node_set_enabled(part->node, !enable);
        } FOR_EACH_END
 }
 
@@ -212,14 +214,14 @@ ssd_titlebar_update(struct ssd *ssd)
 
        struct ssd_part *part;
        struct ssd_sub_tree *subtree;
+       int bg_offset = maximized || tiled_not_maximized ? 0 : theme->window_button_width;
        FOR_EACH_STATE(ssd, subtree) {
                wl_list_for_each(part, &subtree->parts, link) {
                        switch (part->type) {
                        case LAB_SSD_PART_TITLEBAR:
                                wlr_scene_rect_set_size(
                                        wlr_scene_rect_from_node(part->node),
-                                       width - theme->window_button_width * SSD_BUTTON_COUNT,
-                                       theme->title_height);
+                                       width - bg_offset * 2, theme->title_height);
                                continue;
                        case LAB_SSD_BUTTON_ICONIFY:
                                if (is_direct_child(part->node, subtree)) {
@@ -233,12 +235,19 @@ ssd_titlebar_update(struct ssd *ssd)
                                                width - theme->window_button_width * 2, 0);
                                }
                                continue;
-                       case LAB_SSD_PART_CORNER_TOP_RIGHT:
+                       case LAB_SSD_BUTTON_CLOSE:
                                if (is_direct_child(part->node, subtree)) {
                                        wlr_scene_node_set_position(part->node,
                                                width - theme->window_button_width * 1, 0);
                                }
                                continue;
+                       case LAB_SSD_PART_CORNER_TOP_RIGHT:
+                               if (is_direct_child(part->node, subtree)) {
+                                       wlr_scene_node_set_position(part->node,
+                                               width - theme->window_button_width * 1,
+                                               -rc.theme->border_width);
+                               }
+                               continue;
                        default:
                                continue;
                        }