mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
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:
parent
ec5603dbd0
commit
5f01c49b72
4 changed files with 57 additions and 41 deletions
|
|
@ -54,7 +54,7 @@ struct view;
|
||||||
|
|
||||||
struct border ssd_thickness(struct view *view);
|
struct border ssd_thickness(struct view *view);
|
||||||
struct wlr_box ssd_max_extents(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);
|
enum ssd_part_type ssd_at(struct view *view, double lx, double ly);
|
||||||
uint32_t ssd_resize_edges(enum ssd_part_type type);
|
uint32_t ssd_resize_edges(enum ssd_part_type type);
|
||||||
void ssd_update_title(struct view *view);
|
void ssd_update_title(struct view *view);
|
||||||
|
|
|
||||||
14
src/output.c
14
src/output.c
|
|
@ -521,7 +521,7 @@ render_deco(struct view *view, struct output *output,
|
||||||
/* button background */
|
/* button background */
|
||||||
struct wlr_cursor *cur = view->server->seat.cursor;
|
struct wlr_cursor *cur = view->server->seat.cursor;
|
||||||
enum ssd_part_type type = ssd_at(view, cur->x, cur->y);
|
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) &&
|
if (isbutton(type) &&
|
||||||
wlr_box_contains_point(&box, cur->x, cur->y)) {
|
wlr_box_contains_point(&box, cur->x, cur->y)) {
|
||||||
float *color = (float[4]){ 0.5, 0.5, 0.5, 0.5 };
|
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 */
|
/* buttons */
|
||||||
struct theme *theme = view->server->theme;
|
struct theme *theme = view->server->theme;
|
||||||
if (view->surface == seat->keyboard_state.focused_surface) {
|
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,
|
render_icon(output, output_damage, &box,
|
||||||
theme->xbm_close_active_unpressed);
|
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,
|
render_icon(output, output_damage, &box,
|
||||||
theme->xbm_maximize_active_unpressed);
|
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,
|
render_icon(output, output_damage, &box,
|
||||||
theme->xbm_iconify_active_unpressed);
|
theme->xbm_iconify_active_unpressed);
|
||||||
} else {
|
} else {
|
||||||
box = ssd_box(view, LAB_SSD_BUTTON_CLOSE);
|
box = ssd_visible_box(view, LAB_SSD_BUTTON_CLOSE);
|
||||||
render_icon(output, output_damage, &box,
|
render_icon(output, output_damage, &box,
|
||||||
theme->xbm_close_inactive_unpressed);
|
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,
|
render_icon(output, output_damage, &box,
|
||||||
theme->xbm_maximize_inactive_unpressed);
|
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,
|
render_icon(output, output_damage, &box,
|
||||||
theme->xbm_iconify_inactive_unpressed);
|
theme->xbm_iconify_inactive_unpressed);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ reload_config_and_theme(void)
|
||||||
view->margin = ssd_thickness(view);
|
view->margin = ssd_thickness(view);
|
||||||
struct ssd_part *part;
|
struct ssd_part *part;
|
||||||
wl_list_for_each(part, &view->ssd.parts, link) {
|
wl_list_for_each(part, &view->ssd.parts, link) {
|
||||||
part->box = ssd_box(view, part->type);
|
part->box = ssd_visible_box(view, part->type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
80
src/ssd.c
80
src/ssd.c
|
|
@ -39,8 +39,15 @@ ssd_max_extents(struct view *view)
|
||||||
return box;
|
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
|
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 theme *theme = view->server->theme;
|
||||||
struct wlr_box box = { 0 };
|
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.width = view->w;
|
||||||
box.height = theme->title_height;
|
box.height = theme->title_height;
|
||||||
break;
|
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:
|
case LAB_SSD_PART_CORNER_TOP_LEFT:
|
||||||
box.x = view->x - theme->border_width - INVISIBLE_MARGIN;
|
box.x = view->x - theme->border_width - INVISIBLE_MARGIN;
|
||||||
box.y = view->y - corner_square - 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
|
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 theme *theme = view->server->theme;
|
||||||
struct wlr_box box = { 0 };
|
struct wlr_box box = { 0 };
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LAB_SSD_BUTTON_CLOSE:
|
case LAB_SSD_BUTTON_CLOSE:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_BUTTON_MAXIMIZE:
|
case LAB_SSD_BUTTON_MAXIMIZE:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_BUTTON_ICONIFY:
|
case LAB_SSD_BUTTON_ICONIFY:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_PART_TITLEBAR:
|
case LAB_SSD_PART_TITLEBAR:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
box.x += theme->title_height;
|
box.x += theme->title_height;
|
||||||
box.width -= 2 * theme->title_height;
|
box.width -= 2 * theme->title_height;
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_PART_TITLE:
|
case LAB_SSD_PART_TITLE:
|
||||||
box = ssd_box(view, LAB_SSD_PART_TITLEBAR);
|
box = ssd_box(view, type);
|
||||||
if (view->title) {
|
if (view->title) {
|
||||||
/* center align title vertically within allocated box */
|
/* center align title vertically */
|
||||||
box.y += (box.height - view->title->height) / 2;
|
box.y += (box.height - view->title->height) / 2;
|
||||||
box.width = view->title->width;
|
box.width = view->title->width;
|
||||||
box.height = view->title->height;
|
box.height = view->title->height;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_PART_CORNER_TOP_LEFT:
|
case LAB_SSD_PART_CORNER_TOP_LEFT:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
box.x += INVISIBLE_MARGIN;
|
box.x += INVISIBLE_MARGIN;
|
||||||
box.y += INVISIBLE_MARGIN;
|
box.y += INVISIBLE_MARGIN;
|
||||||
box.width -= INVISIBLE_MARGIN;
|
box.width -= INVISIBLE_MARGIN;
|
||||||
box.height -= INVISIBLE_MARGIN;
|
box.height -= INVISIBLE_MARGIN;
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_PART_CORNER_TOP_RIGHT:
|
case LAB_SSD_PART_CORNER_TOP_RIGHT:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
box.y += INVISIBLE_MARGIN;
|
box.y += INVISIBLE_MARGIN;
|
||||||
box.width -= INVISIBLE_MARGIN;
|
box.width -= INVISIBLE_MARGIN;
|
||||||
box.height -= INVISIBLE_MARGIN;
|
box.height -= INVISIBLE_MARGIN;
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_PART_TOP:
|
case LAB_SSD_PART_TOP:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
box.y += INVISIBLE_MARGIN;
|
box.y += INVISIBLE_MARGIN;
|
||||||
box.height -= INVISIBLE_MARGIN;
|
box.height -= INVISIBLE_MARGIN;
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_PART_RIGHT:
|
case LAB_SSD_PART_RIGHT:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
box.width -= INVISIBLE_MARGIN;
|
box.width -= INVISIBLE_MARGIN;
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_PART_BOTTOM:
|
case LAB_SSD_PART_BOTTOM:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
box.height -= INVISIBLE_MARGIN;
|
box.height -= INVISIBLE_MARGIN;
|
||||||
break;
|
break;
|
||||||
case LAB_SSD_PART_LEFT:
|
case LAB_SSD_PART_LEFT:
|
||||||
box = ssd_interactive_box(view, type);
|
box = ssd_box(view, type);
|
||||||
box.x += INVISIBLE_MARGIN;
|
box.x += INVISIBLE_MARGIN;
|
||||||
box.width -= INVISIBLE_MARGIN;
|
box.width -= INVISIBLE_MARGIN;
|
||||||
break;
|
break;
|
||||||
|
|
@ -197,7 +210,7 @@ ssd_at(struct view *view, double lx, double ly)
|
||||||
{
|
{
|
||||||
enum ssd_part_type type;
|
enum ssd_part_type type;
|
||||||
for (type = 0; type < LAB_SSD_END_MARKER; ++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)) {
|
if (wlr_box_contains_point(&box, lx, ly)) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
@ -254,10 +267,13 @@ ssd_update_title(struct view *view)
|
||||||
struct ssd_part *part;
|
struct ssd_part *part;
|
||||||
wl_list_for_each(part, &view->ssd.parts, link) {
|
wl_list_for_each(part, &view->ssd.parts, link) {
|
||||||
if (part->type == LAB_SSD_PART_TITLE) {
|
if (part->type == LAB_SSD_PART_TITLE) {
|
||||||
part->box = ssd_box(view, LAB_SSD_PART_TITLEBAR);
|
part->box = ssd_box(view, part->type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (part->type != LAB_SSD_PART_TITLE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int max_width = part->box.width > 0 ? part->box.width : 1000;
|
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"),
|
view->impl->get_string_prop(view, "title"),
|
||||||
&font, theme->menu_items_active_text_color);
|
&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
|
void
|
||||||
|
|
@ -289,34 +305,34 @@ ssd_create(struct view *view)
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
part = add_part(view, border[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.active = theme->window_active_border_color;
|
||||||
part->color.inactive = theme->window_inactive_border_color;
|
part->color.inactive = theme->window_inactive_border_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* titlebar */
|
/* titlebar */
|
||||||
part = add_part(view, LAB_SSD_PART_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.active = theme->window_active_title_bg_color;
|
||||||
part->color.inactive = theme->window_inactive_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 */
|
/* title text */
|
||||||
part = add_part(view, LAB_SSD_PART_TITLE);
|
part = add_part(view, LAB_SSD_PART_TITLE);
|
||||||
ssd_update_title(view);
|
ssd_update_title(view);
|
||||||
part->texture.active = &view->title;
|
part->texture.active = &view->title;
|
||||||
part->texture.inactive = &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
|
void
|
||||||
|
|
@ -345,7 +361,7 @@ ssd_update_geometry(struct view *view)
|
||||||
}
|
}
|
||||||
struct ssd_part *part;
|
struct ssd_part *part;
|
||||||
wl_list_for_each(part, &view->ssd.parts, link) {
|
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.x = view->x;
|
||||||
view->ssd.box.y = view->y;
|
view->ssd.box.y = view->y;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue