]> git.mdlowis.com Git - proto/labwc.git/commitdiff
ssd: use dynamic titlebar height based on font size and padding
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Wed, 9 Mar 2022 04:40:54 +0000 (05:40 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 12 Mar 2022 15:32:44 +0000 (15:32 +0000)
include/config/rcxml.h
include/ssd.h
src/main.c
src/ssd/ssd.c
src/ssd/ssd_border.c
src/ssd/ssd_extents.c
src/ssd/ssd_part.c
src/ssd/ssd_titlebar.c
src/theme.c

index 934f742fbb9907a281fda2757e967f4ce6187aae..0c57e16784414f442a7efabe1f77252a2f5321ce 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "common/buf.h"
 #include "config/libinput.h"
+#include "theme.h"
 
 struct rcxml {
 
@@ -29,6 +30,8 @@ struct rcxml {
        int font_size_activewindow;
        int font_size_menuitem;
        int font_size_osd;
+       /* Pointer to current theme */
+       struct theme *theme;
 
        /* keyboard */
        int repeat_rate;
index 74bc535c4a82c23130f24d502cb08e9ba1ee97df..a87df8df1f0636f36418e6773691c84a495de178 100644 (file)
@@ -5,7 +5,6 @@
 #include "buffer.h"
 #include <wlr/util/box.h>
 
-#define SSD_HEIGHT 26    /* TODO: use theme->title_height */
 #define BUTTON_COUNT 4
 #define BUTTON_WIDTH 26
 #define EXTENDED_AREA 8
index e3662f26314e5fd6782d1c80ebbc14466245d358..9a486397cf96e31bb92f57514c28b2539df5cfbd 100644 (file)
@@ -69,6 +69,7 @@ main(int argc, char *argv[])
 
        struct theme theme = { 0 };
        theme_init(&theme, rc.theme_name);
+       rc.theme = &theme;
        server.theme = &theme;
 
        menu_init_rootmenu(&server);
index bc86ca61d3bd9e9e67dfc6f552305aa293353d59..f42f06ecb7b541c90ebdc0292c3c18c1d27802fc 100644 (file)
 #include "theme.h"
 #include "ssd.h"
 
-/* TODO: use theme->title_height instead of SSD_HEIGHT */
 struct border
 ssd_thickness(struct view *view)
 {
        struct theme *theme = view->server->theme;
        struct border border = {
-               .top = SSD_HEIGHT,
+               .top = theme->title_height,
                .bottom = theme->border_width,
                .left = theme->border_width,
                .right = theme->border_width,
index 104b5c5c4bfea53f3bd4f51f8affecd7296e02dd..7425eff0918cee78930115f04448b8245b87df23 100644 (file)
@@ -42,7 +42,7 @@ ssd_border_create(struct view *view)
                        0, height, color);
                add_scene_rect(&subtree->parts, LAB_SSD_PART_TOP, parent,
                        full_width - 2 * BUTTON_WIDTH, theme->border_width,
-                       BUTTON_WIDTH, -SSD_HEIGHT, color);
+                       BUTTON_WIDTH, -theme->title_height, color);
        } FOR_EACH_END
 }
 
@@ -79,7 +79,7 @@ ssd_border_update(struct view *view)
                                        full_width - 2 * BUTTON_WIDTH,
                                        theme->border_width);
                                wlr_scene_node_set_position(part->node,
-                                       BUTTON_WIDTH, -SSD_HEIGHT);
+                                       BUTTON_WIDTH, -theme->title_height);
                                continue;
                        default:
                                continue;
index fcff88510a405fba4af837a4a6d960835be08de6..13d55fedd2bf92e5aeccc42523045e4f13b8339e 100644 (file)
@@ -13,7 +13,7 @@ ssd_extents_create(struct view *view)
        struct wl_list *part_list = &view->ssd.extents.parts;
        int width = view->w;
        int height = view->h;
-       int full_height = height + theme->border_width + SSD_HEIGHT;
+       int full_height = height + theme->border_width + theme->title_height;
        int full_width = width + 2 * theme->border_width;
        int extended_area = EXTENDED_AREA;
        int corner_size = extended_area + theme->border_width + BUTTON_WIDTH / 2;
@@ -26,8 +26,8 @@ ssd_extents_create(struct view *view)
                wlr_scene_node_set_enabled(parent, false);
        }
        wl_list_init(&view->ssd.extents.parts);
-       wlr_scene_node_set_position(parent,
-               -(theme->border_width + extended_area), -(SSD_HEIGHT + extended_area));
+       wlr_scene_node_set_position(parent, -(theme->border_width + extended_area),
+               -(theme->title_height + extended_area));
 
        /* Top */
        add_scene_rect(part_list, LAB_SSD_PART_CORNER_TOP_LEFT, parent,
@@ -75,7 +75,7 @@ ssd_extents_update(struct view *view)
 
        int width = view->w;
        int height = view->h;
-       int full_height = height + theme->border_width + SSD_HEIGHT;
+       int full_height = height + theme->border_width + theme->title_height;
        int full_width = width + 2 * theme->border_width;
        int extended_area = EXTENDED_AREA;
        int corner_size = extended_area + theme->border_width + BUTTON_WIDTH / 2;
index f6e55ba105fa759822d8224c151e205235f29356..1dce341a94413c7a028f596cfb1b0a16cc3b1f64 100644 (file)
@@ -54,12 +54,12 @@ finish_scene_button(struct wl_list *part_list, enum ssd_part_type type,
        /* Icon */
        add_scene_buffer(part_list, type, parent, icon_buffer,
                (BUTTON_WIDTH - icon_buffer->width) / 2,
-               (SSD_HEIGHT - icon_buffer->height) / 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, SSD_HEIGHT, 0, 0, hover_bg);
+               BUTTON_WIDTH, rc.theme->title_height, 0, 0, hover_bg);
        wlr_scene_node_set_enabled(hover_part->node, false);
 }
 
@@ -83,7 +83,7 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
        struct ssd_part *part;
        /* Background */
        part = add_scene_rect(part_list, type, parent,
-               BUTTON_WIDTH, SSD_HEIGHT, x, 0, bg_color);
+               BUTTON_WIDTH, rc.theme->title_height, x, 0, bg_color);
        finish_scene_button(part_list, type, part->node, icon_buffer);
        return part;
 }
index 1c7d9876551b98ff011a3bac2f54091baee48e48..b59e6f8492ba28eb6d1676d4b7d29a0bf3734512 100644 (file)
@@ -29,7 +29,8 @@ ssd_titlebar_create(struct view *view)
        FOR_EACH_STATE(view, subtree) {
                subtree->tree = wlr_scene_tree_create(&view->ssd.tree->node);
                parent = &subtree->tree->node;
-               wlr_scene_node_set_position(parent, -theme->border_width, -SSD_HEIGHT);
+               wlr_scene_node_set_position(parent,
+                       -theme->border_width, -theme->title_height);
                if (subtree == &view->ssd.titlebar.active) {
                        color = theme->window_active_title_bg_color;
                        corner_top_left = &theme->corner_top_left_active_normal->base;
@@ -44,7 +45,7 @@ ssd_titlebar_create(struct view *view)
 
                /* Title */
                add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
-                       full_width - BUTTON_WIDTH * BUTTON_COUNT, SSD_HEIGHT,
+                       full_width - BUTTON_WIDTH * BUTTON_COUNT, theme->title_height,
                        BUTTON_WIDTH, 0, color);
                /* Buttons */
                add_scene_button_corner(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU,
@@ -76,7 +77,8 @@ ssd_titlebar_update(struct view *view)
        if (width == view->ssd.state.width) {
                return;
        }
-       int full_width = width + 2 * view->server->theme->border_width;
+       struct theme *theme = view->server->theme;
+       int full_width = width + 2 * theme->border_width;
 
        struct ssd_part *part;
        struct ssd_sub_tree *subtree;
@@ -85,7 +87,8 @@ ssd_titlebar_update(struct view *view)
                        switch (part->type) {
                        case LAB_SSD_PART_TITLEBAR:
                                wlr_scene_rect_set_size(lab_wlr_scene_get_rect(part->node),
-                                       full_width - BUTTON_WIDTH * BUTTON_COUNT, SSD_HEIGHT);
+                                       full_width - BUTTON_WIDTH * BUTTON_COUNT,
+                                       theme->title_height);
                                continue;
                        case LAB_SSD_BUTTON_ICONIFY:
                                if (is_direct_child(part->node, subtree)) {
@@ -159,7 +162,7 @@ ssd_update_title_positions(struct view *view)
                }
 
                x = 0;
-               y = (SSD_HEIGHT - part->buffer->base.height) / 2;
+               y = (theme->title_height - part->buffer->base.height) / 2;
                rect = lab_wlr_scene_get_rect(part->node->parent);
                if (rect->width <= 0) {
                        wlr_scene_node_set_position(part->node, x, y);
index 5a4a6e5f514cb6f6f69448472f771ef9df8f3c06..1bf6dba00e010ef8ebd27d13ff2a8a2a0e72ee1f 100644 (file)
@@ -422,7 +422,7 @@ create_corners(struct theme *theme)
                .x = 0,
                .y = 0,
                .width = BUTTON_WIDTH,
-               .height = SSD_HEIGHT,
+               .height = theme->title_height,
        };
 
        struct rounded_corner_ctx ctx = {