]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: add window.button.height
authorJohan Malm <jgm323@gmail.com>
Fri, 20 Sep 2024 19:59:01 +0000 (20:59 +0100)
committerJohan Malm <jgm323@gmail.com>
Tue, 8 Oct 2024 19:04:05 +0000 (20:04 +0100)
window.button.{height,width} determine the space allocated for buttons.
Buttons can be smaller than this size and will then just be center aligned
within the allocated space. However, buttons will be clamped at this size
to prevent them from going outside of the allocated space.

include/ssd-internal.h
include/theme.h
src/ssd/ssd-part.c
src/ssd/ssd-titlebar.c
src/theme.c

index 5c5aa8e87fe0e1c4210b0478f709091668d2c889..d34543355ea054338f7e973d468afd05cadb09bb 100644 (file)
@@ -146,7 +146,7 @@ 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,
-       struct lab_data_buffer *buffers[LAB_BS_ALL + 1], int x,
+       struct lab_data_buffer *buffers[LAB_BS_ALL + 1], int x, int y,
        struct view *view);
 void update_window_icon_buffer(struct wlr_scene_node *button_node,
        struct lab_data_buffer *buffer);
index 3fbe44047f9cdb721f44cdd1b130b391a61c6c93..d3ffbf05b405050839d74a3aa5887d208c09d856 100644 (file)
@@ -67,10 +67,11 @@ struct theme {
        enum lab_justification window_label_text_justify;
        enum lab_justification menu_title_text_justify;
 
-       /* button width */
+       /* buttons */
        int window_button_width;
-       /* the space between buttons */
+       int window_button_height;
        int window_button_spacing;
+
        /* the shape of the hover effect */
        enum lab_shape window_button_hover_bg_shape;
 
index 58305e0c3d95048796305a77329fb15bbddb0db4..af09df2468fee28fded2ecfe6ee63f5fb26d17fd 100644 (file)
@@ -97,7 +97,7 @@ update_window_icon_buffer(struct wlr_scene_node *button_node,
 
        struct wlr_box icon_geo = get_scale_box(buffer,
                rc.theme->window_button_width,
-               rc.theme->title_height);
+               rc.theme->window_button_height);
 
        wlr_scene_buffer_set_buffer(scene_buffer, &buffer->base);
        wlr_scene_buffer_set_dest_size(scene_buffer,
@@ -109,17 +109,17 @@ struct ssd_part *
 add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
                struct wlr_scene_tree *parent,
                struct lab_data_buffer *buffers[LAB_BS_ALL + 1],
-               int x, struct view *view)
+               int x, int y, 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);
+       wlr_scene_node_set_position(button_root->node, x, y);
 
        /* 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,
+               rc.theme->window_button_width, rc.theme->window_button_height, 0, 0,
                invisible);
 
        /* Icons */
@@ -130,7 +130,7 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
                }
                struct lab_data_buffer *icon_buffer = buffers[state_set];
                struct wlr_box icon_geo = get_scale_box(icon_buffer,
-                       rc.theme->window_button_width, rc.theme->title_height);
+                       rc.theme->window_button_width, rc.theme->window_button_height);
                struct ssd_part *icon_part = add_scene_buffer(part_list, type,
                        parent, &icon_buffer->base, icon_geo.x, icon_geo.y);
                /* Make sure big icons are scaled down if necessary */
index 5e5b9769751ea5bc61a7f75f219e81468f455071..9937896df001e4ec923c35ba1cc63410126c376c 100644 (file)
@@ -75,11 +75,15 @@ ssd_titlebar_create(struct ssd *ssd)
                /* Buttons */
                struct title_button *b;
                int x = theme->padding_width;
+
+               /* Center vertically within titlebar */
+               int y = (theme->title_height - theme->window_button_height) / 2;
+
                wl_list_for_each(b, &rc.title_buttons_left, link) {
                        struct lab_data_buffer **buffers =
                                theme->window[active].buttons[b->type];
                        add_scene_button(&subtree->parts, b->type, parent,
-                               buffers, x, view);
+                               buffers, x, y, view);
                        x += theme->window_button_width + theme->window_button_spacing;
                }
 
@@ -89,7 +93,7 @@ ssd_titlebar_create(struct ssd *ssd)
                        struct lab_data_buffer **buffers =
                                theme->window[active].buttons[b->type];
                        add_scene_button(&subtree->parts, b->type, parent,
-                               buffers, x, view);
+                               buffers, x, y, view);
                }
        } FOR_EACH_END
 
@@ -293,6 +297,8 @@ ssd_titlebar_update(struct ssd *ssd)
 
        update_visible_buttons(ssd);
 
+       /* Center buttons vertically within titlebar */
+       int y = (theme->title_height - theme->window_button_height) / 2;
        int x;
        struct ssd_part *part;
        struct ssd_sub_tree *subtree;
@@ -307,7 +313,7 @@ ssd_titlebar_update(struct ssd *ssd)
                x = theme->padding_width;
                wl_list_for_each(b, &rc.title_buttons_left, link) {
                        part = ssd_get_part(&subtree->parts, b->type);
-                       wlr_scene_node_set_position(part->node, x, 0);
+                       wlr_scene_node_set_position(part->node, x, y);
                        x += theme->window_button_width + theme->window_button_spacing;
                }
 
@@ -319,7 +325,7 @@ ssd_titlebar_update(struct ssd *ssd)
                wl_list_for_each_reverse(b, &rc.title_buttons_right, link) {
                        part = ssd_get_part(&subtree->parts, b->type);
                        x -= theme->window_button_width + theme->window_button_spacing;
-                       wlr_scene_node_set_position(part->node, x, 0);
+                       wlr_scene_node_set_position(part->node, x, y);
                }
        } FOR_EACH_END
 
index ac7794a2bdbe1dd8570b0a43ee9cd54155bb673c..2926b80bd75e3f0bc2fe6f31435caab50cd8aeea 100644 (file)
@@ -91,7 +91,7 @@ copy_icon_buffer(struct theme *theme, struct lab_data_buffer *icon_buffer)
        int icon_height = cairo_image_surface_get_height(icon.surface);
 
        int width = theme->window_button_width;
-       int height = theme->title_height;
+       int height = theme->window_button_height;
 
        /*
         * Proportionately increase size of hover_buffer if the non-hover
@@ -139,7 +139,7 @@ create_hover_fallback(struct theme *theme,
        assert(!*hover_buffer);
 
        int width = theme->window_button_width;
-       int height = theme->title_height;
+       int height = theme->window_button_height;
 
        *hover_buffer = copy_icon_buffer(theme, icon_buffer);
        cairo_t *cairo = (*hover_buffer)->cairo;
@@ -171,7 +171,7 @@ create_rounded_buffer(struct theme *theme, enum corner corner,
        cairo_t *cairo = (*rounded_buffer)->cairo;
 
        int width = theme->window_button_width;
-       int height = theme->title_height;
+       int height = theme->window_button_height;
 
        /*
         * Round the hover overlay of corner buttons by
@@ -246,7 +246,7 @@ load_button(struct theme *theme, struct button *b, int active)
 
        zdrop(buffer);
 
-       int size = theme->title_height - 2 * theme->padding_height;
+       int size = theme->window_button_height;
        float scale = 1; /* TODO: account for output scale */
 
        /* PNG */
@@ -593,6 +593,7 @@ theme_builtin(struct theme *theme, struct server *server)
 
        theme->padding_width = 0;
        theme->window_button_width = 26;
+       theme->window_button_height = 26;
        theme->window_button_spacing = 0;
        theme->window_button_hover_bg_shape = LAB_RECTANGLE;
 
@@ -779,6 +780,14 @@ entry(struct theme *theme, const char *key, const char *value)
                        theme->window_button_width = 1;
                }
        }
+       if (match_glob(key, "window.button.height")) {
+               theme->window_button_height = atoi(value);
+               if (theme->window_button_height < 1) {
+                       wlr_log(WLR_ERROR, "window.button.height cannot "
+                               "be less than 1, clamping it to 1.");
+                       theme->window_button_height = 1;
+               }
+       }
        if (match_glob(key, "window.button.spacing")) {
                theme->window_button_spacing = get_int_if_positive(
                        value, "window.button.spacing");