ssd: refactor and position title nearer left hand edge

Put title deco at the end of linked list to render it on top of corner
edges.
This commit is contained in:
Johan Malm 2021-08-22 14:06:11 +01:00
parent ec5603dbd0
commit 5f01c49b72
4 changed files with 57 additions and 41 deletions

View 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);
}

View 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);
}
}

View file

@ -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;
/* titlebar top-left corner */
part = add_part(view, LAB_SSD_PART_CORNER_TOP_LEFT);
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_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;
/* titlebar top-left corner */
part = add_part(view, LAB_SSD_PART_CORNER_TOP_LEFT);
part->box = ssd_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->texture.active = &theme->corner_top_right_active_normal;
part->texture.inactive = &theme->corner_top_right_inactive_normal;
}
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;