]> git.mdlowis.com Git - proto/labwc.git/commitdiff
ssd: refactor and position title nearer left hand edge
authorJohan Malm <jgm323@gmail.com>
Sun, 22 Aug 2021 13:06:11 +0000 (14:06 +0100)
committerJohan Malm <jgm323@gmail.com>
Sun, 22 Aug 2021 13:06:11 +0000 (14:06 +0100)
Put title deco at the end of linked list to render it on top of corner
edges.

include/ssd.h
src/output.c
src/server.c
src/ssd.c

index c38caa59df59241a0fac490d69b74562df3a0f75..040cc3afa267912161f45b6fd87a23af1d39d329 100644 (file)
@@ -54,7 +54,7 @@ struct view;
 
 struct border ssd_thickness(struct view *view);
 struct wlr_box ssd_max_extents(struct view *view);
-struct wlr_box ssd_box(struct view *view, enum ssd_part_type type);
+struct wlr_box ssd_visible_box(struct view *view, enum ssd_part_type type);
 enum ssd_part_type ssd_at(struct view *view, double lx, double ly);
 uint32_t ssd_resize_edges(enum ssd_part_type type);
 void ssd_update_title(struct view *view);
index 0fd28ca0cd8616640c507d71c455bcfa9ab900d9..a0c8379c06d80facef3edcc1b7db30ed80f82a6f 100644 (file)
@@ -521,7 +521,7 @@ render_deco(struct view *view, struct output *output,
        /* button background */
        struct wlr_cursor *cur = view->server->seat.cursor;
        enum ssd_part_type type = ssd_at(view, cur->x, cur->y);
-       struct wlr_box box = ssd_box(view, type);
+       struct wlr_box box = ssd_visible_box(view, type);
        if (isbutton(type) &&
                        wlr_box_contains_point(&box, cur->x, cur->y)) {
                float *color = (float[4]){ 0.5, 0.5, 0.5, 0.5 };
@@ -531,23 +531,23 @@ render_deco(struct view *view, struct output *output,
        /* buttons */
        struct theme *theme = view->server->theme;
        if (view->surface == seat->keyboard_state.focused_surface) {
-               box = ssd_box(view, LAB_SSD_BUTTON_CLOSE);
+               box = ssd_visible_box(view, LAB_SSD_BUTTON_CLOSE);
                render_icon(output, output_damage, &box,
                        theme->xbm_close_active_unpressed);
-               box = ssd_box(view, LAB_SSD_BUTTON_MAXIMIZE);
+               box = ssd_visible_box(view, LAB_SSD_BUTTON_MAXIMIZE);
                render_icon(output, output_damage, &box,
                        theme->xbm_maximize_active_unpressed);
-               box = ssd_box(view, LAB_SSD_BUTTON_ICONIFY);
+               box = ssd_visible_box(view, LAB_SSD_BUTTON_ICONIFY);
                render_icon(output, output_damage, &box,
                        theme->xbm_iconify_active_unpressed);
        } else {
-               box = ssd_box(view, LAB_SSD_BUTTON_CLOSE);
+               box = ssd_visible_box(view, LAB_SSD_BUTTON_CLOSE);
                render_icon(output, output_damage, &box,
                        theme->xbm_close_inactive_unpressed);
-               box = ssd_box(view, LAB_SSD_BUTTON_MAXIMIZE);
+               box = ssd_visible_box(view, LAB_SSD_BUTTON_MAXIMIZE);
                render_icon(output, output_damage, &box,
                        theme->xbm_maximize_inactive_unpressed);
-               box = ssd_box(view, LAB_SSD_BUTTON_ICONIFY);
+               box = ssd_visible_box(view, LAB_SSD_BUTTON_ICONIFY);
                render_icon(output, output_damage, &box,
                        theme->xbm_iconify_inactive_unpressed);
        }
index 6ffac31dabad11ebfb646634aa88f95dad4b0472..cfcac22fa0ab5787767c562eda31907783cf9856 100644 (file)
@@ -38,7 +38,7 @@ reload_config_and_theme(void)
                view->margin = ssd_thickness(view);
                struct ssd_part *part;
                wl_list_for_each(part, &view->ssd.parts, link) {
-                       part->box = ssd_box(view, part->type);
+                       part->box = ssd_visible_box(view, part->type);
                }
        }
 
index 3b8fbb84aa34a748a587521eae677f37f68c3bc1..ac90642e1769a4cad08c9febbec84e7b276e044b 100644 (file)
--- a/src/ssd.c
+++ b/src/ssd.c
@@ -39,8 +39,15 @@ ssd_max_extents(struct view *view)
        return box;
 }
 
+#define NR_BUTTONS (3)
+
+/**
+ * ssd_box - the 'full' decoration geometry which includes both visible
+ * and invisible parts. It typically includes an invisible margin outside
+ * the decoration.
+ */
 static struct wlr_box
-ssd_interactive_box(struct view *view, enum ssd_part_type type)
+ssd_box(struct view *view, enum ssd_part_type type)
 {
        struct theme *theme = view->server->theme;
        struct wlr_box box = { 0 };
@@ -70,6 +77,12 @@ ssd_interactive_box(struct view *view, enum ssd_part_type type)
                box.width = view->w;
                box.height = theme->title_height;
                break;
+       case LAB_SSD_PART_TITLE:
+               box.x = view->x + corner_square / 2;
+               box.y = view->y - theme->title_height;
+               box.width = view->w - NR_BUTTONS * corner_square;
+               box.height = theme->title_height;
+               break;
        case LAB_SSD_PART_CORNER_TOP_LEFT:
                box.x = view->x - theme->border_width - INVISIBLE_MARGIN;
                box.y = view->y - corner_square - INVISIBLE_MARGIN;
@@ -125,62 +138,62 @@ ssd_interactive_box(struct view *view, enum ssd_part_type type)
 }
 
 struct wlr_box
-ssd_box(struct view *view, enum ssd_part_type type)
+ssd_visible_box(struct view *view, enum ssd_part_type type)
 {
        struct theme *theme = view->server->theme;
        struct wlr_box box = { 0 };
        switch (type) {
        case LAB_SSD_BUTTON_CLOSE:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                break;
        case LAB_SSD_BUTTON_MAXIMIZE:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                break;
        case LAB_SSD_BUTTON_ICONIFY:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                break;
        case LAB_SSD_PART_TITLEBAR:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                box.x += theme->title_height;
                box.width -= 2 * theme->title_height;
                break;
        case LAB_SSD_PART_TITLE:
-               box = ssd_box(view, LAB_SSD_PART_TITLEBAR);
+               box = ssd_box(view, type);
                if (view->title) {
-                       /* center align title vertically within allocated box */
+                       /* center align title vertically */
                        box.y += (box.height - view->title->height) / 2;
                        box.width = view->title->width;
                        box.height = view->title->height;
                }
                break;
        case LAB_SSD_PART_CORNER_TOP_LEFT:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                box.x += INVISIBLE_MARGIN;
                box.y += INVISIBLE_MARGIN;
                box.width -= INVISIBLE_MARGIN;
                box.height -= INVISIBLE_MARGIN;
                break;
        case LAB_SSD_PART_CORNER_TOP_RIGHT:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                box.y += INVISIBLE_MARGIN;
                box.width -= INVISIBLE_MARGIN;
                box.height -= INVISIBLE_MARGIN;
                break;
        case LAB_SSD_PART_TOP:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                box.y += INVISIBLE_MARGIN;
                box.height -= INVISIBLE_MARGIN;
                break;
        case LAB_SSD_PART_RIGHT:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                box.width -= INVISIBLE_MARGIN;
                break;
        case LAB_SSD_PART_BOTTOM:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                box.height -= INVISIBLE_MARGIN;
                break;
        case LAB_SSD_PART_LEFT:
-               box = ssd_interactive_box(view, type);
+               box = ssd_box(view, type);
                box.x += INVISIBLE_MARGIN;
                box.width -= INVISIBLE_MARGIN;
                break;
@@ -197,7 +210,7 @@ ssd_at(struct view *view, double lx, double ly)
 {
        enum ssd_part_type type;
        for (type = 0; type < LAB_SSD_END_MARKER; ++type) {
-               struct wlr_box box = ssd_interactive_box(view, type);
+               struct wlr_box box = ssd_box(view, type);
                if (wlr_box_contains_point(&box, lx, ly)) {
                        return type;
                }
@@ -254,10 +267,13 @@ ssd_update_title(struct view *view)
        struct ssd_part *part;
        wl_list_for_each(part, &view->ssd.parts, link) {
                if (part->type == LAB_SSD_PART_TITLE) {
-                       part->box = ssd_box(view, LAB_SSD_PART_TITLEBAR);
+                       part->box = ssd_box(view, part->type);
                        break;
                }
        }
+       if (part->type != LAB_SSD_PART_TITLE) {
+               return;
+       }
 
        int max_width = part->box.width > 0 ? part->box.width : 1000;
 
@@ -266,7 +282,7 @@ ssd_update_title(struct view *view)
                view->impl->get_string_prop(view, "title"),
                &font, theme->menu_items_active_text_color);
 
-       part->box = ssd_box(view, LAB_SSD_PART_TITLE);
+       part->box = ssd_visible_box(view, part->type);
 }
 
 void
@@ -289,34 +305,34 @@ ssd_create(struct view *view)
        };
        for (int i = 0; i < 4; i++) {
                part = add_part(view, border[i]);
-               part->box = ssd_box(view, border[i]);
+               part->box = ssd_visible_box(view, border[i]);
                part->color.active = theme->window_active_border_color;
                part->color.inactive = theme->window_inactive_border_color;
        }
 
        /* titlebar */
        part = add_part(view, LAB_SSD_PART_TITLEBAR);
-       part->box = ssd_box(view, LAB_SSD_PART_TITLEBAR);
+       part->box = ssd_visible_box(view, LAB_SSD_PART_TITLEBAR);
        part->color.active = theme->window_active_title_bg_color;
        part->color.inactive = theme->window_inactive_title_bg_color;
 
-       /* title text */
-       part = add_part(view, LAB_SSD_PART_TITLE);
-       ssd_update_title(view);
-       part->texture.active = &view->title;
-       part->texture.inactive = &view->title;
-
        /* titlebar top-left corner */
        part = add_part(view, LAB_SSD_PART_CORNER_TOP_LEFT);
-       part->box = ssd_box(view, part->type);
+       part->box = ssd_visible_box(view, part->type);
        part->texture.active = &theme->corner_top_left_active_normal;
        part->texture.inactive = &theme->corner_top_left_inactive_normal;
 
        /* titlebar top-right corner */
        part = add_part(view, LAB_SSD_PART_CORNER_TOP_RIGHT);
-       part->box = ssd_box(view, part->type);
+       part->box = ssd_visible_box(view, part->type);
        part->texture.active = &theme->corner_top_right_active_normal;
        part->texture.inactive = &theme->corner_top_right_inactive_normal;
+
+       /* title text */
+       part = add_part(view, LAB_SSD_PART_TITLE);
+       ssd_update_title(view);
+       part->texture.active = &view->title;
+       part->texture.inactive = &view->title;
 }
 
 void
@@ -345,7 +361,7 @@ ssd_update_geometry(struct view *view)
        }
        struct ssd_part *part;
        wl_list_for_each(part, &view->ssd.parts, link) {
-               part->box = ssd_box(view, part->type);
+               part->box = ssd_visible_box(view, part->type);
        }
        view->ssd.box.x = view->x;
        view->ssd.box.y = view->y;