Chase wlroots: prep work: ssd to tree

This commit is contained in:
Consolatis 2022-06-05 15:17:15 +02:00 committed by Johan Malm
parent 65a5315e42
commit b7c9d0e055
2 changed files with 43 additions and 40 deletions

View file

@ -52,22 +52,14 @@ finish_scene_button(struct wl_list *part_list, enum ssd_part_type type,
float hover_bg[4] = {0.15f, 0.15f, 0.15f, 0.3f}; float hover_bg[4] = {0.15f, 0.15f, 0.15f, 0.3f};
/* Icon */ /* Icon */
int offset_y = 0;
int offset_x = 0;
if (type == LAB_SSD_BUTTON_WINDOW_MENU) {
offset_y = rc.theme->border_width;
offset_x = rc.theme->border_width;
} else if (type == LAB_SSD_BUTTON_CLOSE) {
offset_y = rc.theme->border_width;
}
add_scene_buffer(part_list, type, parent, icon_buffer, add_scene_buffer(part_list, type, parent, icon_buffer,
offset_x + (BUTTON_WIDTH - icon_buffer->width) / 2, (BUTTON_WIDTH - icon_buffer->width) / 2,
offset_y + (rc.theme->title_height - icon_buffer->height) / 2); (rc.theme->title_height - icon_buffer->height) / 2);
/* Hover overlay */ /* Hover overlay */
struct ssd_part *hover_part; struct ssd_part *hover_part;
hover_part = add_scene_rect(part_list, type, parent, BUTTON_WIDTH, hover_part = add_scene_rect(part_list, type, parent, BUTTON_WIDTH,
rc.theme->title_height, offset_x, offset_y, hover_bg); rc.theme->title_height, 0, 0, hover_bg);
wlr_scene_node_set_enabled(hover_part->node, false); wlr_scene_node_set_enabled(hover_part->node, false);
} }
@ -76,14 +68,28 @@ add_scene_button_corner(struct wl_list *part_list, enum ssd_part_type type,
struct wlr_scene_node *parent, struct wlr_buffer *corner_buffer, struct wlr_scene_node *parent, struct wlr_buffer *corner_buffer,
struct wlr_buffer *icon_buffer, int x) struct wlr_buffer *icon_buffer, int x)
{ {
struct ssd_part *button_root = add_scene_part(part_list, type);
parent = &wlr_scene_tree_create(parent)->node;
button_root->node = parent;
wlr_scene_node_set_position(button_root->node, x, 0);
int offset_x;
if (type == LAB_SSD_BUTTON_WINDOW_MENU) {
offset_x = rc.theme->border_width;
} else if (type == LAB_SSD_BUTTON_CLOSE) {
offset_x = 0;
} else {
assert(false && "invalid corner button type");
}
struct ssd_part *part; struct ssd_part *part;
/* /*
* Background, y adjusted for border_width which is * Background, y adjusted for border_width which is
* already included in rendered theme.c / corner_buffer * already included in rendered theme.c / corner_buffer
*/ */
part = add_scene_buffer(part_list, type, parent, corner_buffer, part = add_scene_buffer(part_list, type, parent, corner_buffer,
x, -rc.theme->border_width); -offset_x, -rc.theme->border_width);
finish_scene_button(part_list, type, part->node, icon_buffer); finish_scene_button(part_list, type, parent, icon_buffer);
return part; return part;
} }
@ -92,11 +98,16 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
struct wlr_scene_node *parent, float *bg_color, struct wlr_scene_node *parent, float *bg_color,
struct wlr_buffer *icon_buffer, int x) struct wlr_buffer *icon_buffer, int x)
{ {
struct ssd_part *button_root = add_scene_part(part_list, type);
parent = &wlr_scene_tree_create(parent)->node;
button_root->node = parent;
wlr_scene_node_set_position(button_root->node, x, 0);
struct ssd_part *part; struct ssd_part *part;
/* Background */ /* Background */
part = add_scene_rect(part_list, type, parent, part = add_scene_rect(part_list, type, parent,
BUTTON_WIDTH, rc.theme->title_height, x, 0, bg_color); BUTTON_WIDTH, rc.theme->title_height, 0, 0, bg_color);
finish_scene_button(part_list, type, part->node, icon_buffer); finish_scene_button(part_list, type, parent, icon_buffer);
return part; return part;
} }

View file

@ -48,7 +48,7 @@ ssd_titlebar_create(struct view *view)
/* Buttons */ /* Buttons */
add_scene_button_corner(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU, add_scene_button_corner(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU,
parent, corner_top_left, parent, corner_top_left,
&theme->xbm_menu_active_unpressed->base, -theme->border_width); &theme->xbm_menu_active_unpressed->base, 0);
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent, add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
color, &theme->xbm_iconify_active_unpressed->base, color, &theme->xbm_iconify_active_unpressed->base,
width - BUTTON_WIDTH * 3); width - BUTTON_WIDTH * 3);
@ -103,8 +103,7 @@ ssd_titlebar_update(struct view *view)
case LAB_SSD_BUTTON_CLOSE: case LAB_SSD_BUTTON_CLOSE:
if (is_direct_child(part->node, subtree)) { if (is_direct_child(part->node, subtree)) {
wlr_scene_node_set_position(part->node, wlr_scene_node_set_position(part->node,
width - BUTTON_WIDTH * 1, width - BUTTON_WIDTH * 1, 0);
-theme->border_width);
} }
continue; continue;
default: default:
@ -147,11 +146,10 @@ ssd_update_title_positions(struct view *view)
{ {
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->w; int width = view->w;
int full_width = width + 2 * view->server->theme->border_width; int title_bg_width = width - BUTTON_WIDTH * BUTTON_COUNT;
int x, y; int x, y;
int buffer_height, buffer_width; int buffer_height, buffer_width;
struct wlr_scene_rect *rect;
struct ssd_part *part; struct ssd_part *part;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(view, subtree) {
@ -163,29 +161,27 @@ ssd_update_title_positions(struct view *view)
buffer_width = part->buffer ? part->buffer->base.width : 0; buffer_width = part->buffer ? part->buffer->base.width : 0;
buffer_height = part->buffer ? part->buffer->base.height : 0; buffer_height = part->buffer ? part->buffer->base.height : 0;
x = 0; x = BUTTON_WIDTH;
y = (theme->title_height - buffer_height) / 2; y = (theme->title_height - buffer_height) / 2;
rect = lab_wlr_scene_get_rect(part->node->parent); if (title_bg_width <= 0) {
if (rect->width <= 0) {
wlr_scene_node_set_position(part->node, x, y); wlr_scene_node_set_position(part->node, x, y);
continue; continue;
} }
if (theme->window_label_text_justify == LAB_JUSTIFY_CENTER) { if (theme->window_label_text_justify == LAB_JUSTIFY_CENTER) {
if (buffer_width + BUTTON_WIDTH * 2 <= rect->width) { if (buffer_width + BUTTON_WIDTH * 2 <= title_bg_width) {
/* Center based on the full width */ /* Center based on the full width */
x = (full_width - buffer_width) / 2; x = (width - buffer_width) / 2;
x -= BUTTON_WIDTH;
} else { } else {
/* /*
* Center based on the width between the buttons. * Center based on the width between the buttons.
* Title jumps around once this is hit but its still * Title jumps around once this is hit but its still
* better than to hide behind the buttons on the right. * better than to hide behind the buttons on the right.
*/ */
x = (rect->width - buffer_width) / 2; x += (title_bg_width - buffer_width) / 2;
} }
} else if (theme->window_label_text_justify == LAB_JUSTIFY_RIGHT) { } else if (theme->window_label_text_justify == LAB_JUSTIFY_RIGHT) {
x = rect->width - buffer_width; x += title_bg_width - buffer_width;
} else if (theme->window_label_text_justify == LAB_JUSTIFY_LEFT) { } else if (theme->window_label_text_justify == LAB_JUSTIFY_LEFT) {
/* TODO: maybe add some theme x padding here? */ /* TODO: maybe add some theme x padding here? */
} }
@ -216,15 +212,12 @@ ssd_update_title(struct view *view)
}; };
float *text_color; float *text_color;
struct wlr_scene_rect *rect;
struct ssd_part *part; struct ssd_part *part;
struct ssd_part *parent_part;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
struct ssd_state_title_width *dstate; struct ssd_state_title_width *dstate;
FOR_EACH_STATE(view, subtree) { int title_bg_width = view->w - BUTTON_WIDTH * BUTTON_COUNT;
parent_part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
assert(parent_part);
FOR_EACH_STATE(view, subtree) {
if (subtree == &view->ssd.titlebar.active) { if (subtree == &view->ssd.titlebar.active) {
dstate = &state->active; dstate = &state->active;
text_color = theme->window_active_label_text_color; text_color = theme->window_active_label_text_color;
@ -233,14 +226,13 @@ ssd_update_title(struct view *view)
text_color = theme->window_inactive_label_text_color; text_color = theme->window_inactive_label_text_color;
} }
rect = lab_wlr_scene_get_rect(parent_part->node); if (title_bg_width <= 0) {
if (rect->width <= 0) {
dstate->truncated = true; dstate->truncated = true;
continue; continue;
} }
if (title_unchanged if (title_unchanged
&& !dstate->truncated && dstate->width < rect->width) { && !dstate->truncated && dstate->width < title_bg_width) {
/* title the same + we don't need to resize title */ /* title the same + we don't need to resize title */
continue; continue;
} }
@ -249,11 +241,11 @@ ssd_update_title(struct view *view)
if (!part) { if (!part) {
/* Initialize part and wlr_scene_buffer without attaching a buffer */ /* Initialize part and wlr_scene_buffer without attaching a buffer */
part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE); part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE);
part->node = &wlr_scene_buffer_create(parent_part->node, NULL)->node; part->node = &wlr_scene_buffer_create(&subtree->tree->node, NULL)->node;
} }
/* Generate and update the lab_data_buffer, drops the old buffer */ /* Generate and update the lab_data_buffer, drops the old buffer */
font_buffer_update(&part->buffer, rect->width, title, &font, text_color); font_buffer_update(&part->buffer, title_bg_width, title, &font, text_color);
if (!part->buffer) { if (!part->buffer) {
/* This can happen for example by defining a font size of 0 */ /* This can happen for example by defining a font size of 0 */
wlr_log(WLR_ERROR, "Failed to create title buffer"); wlr_log(WLR_ERROR, "Failed to create title buffer");
@ -266,7 +258,7 @@ ssd_update_title(struct view *view)
/* And finally update the cache */ /* And finally update the cache */
dstate->width = part->buffer ? part->buffer->base.width : 0; dstate->width = part->buffer ? part->buffer->base.width : 0;
dstate->truncated = rect->width <= dstate->width; dstate->truncated = title_bg_width <= dstate->width;
} FOR_EACH_END } FOR_EACH_END
if (!title_unchanged) { if (!title_unchanged) {
@ -302,7 +294,7 @@ ssd_button_hover_enable(struct view *view, enum ssd_part_type type)
return NULL; return NULL;
} }
struct wlr_scene_node *child; struct wlr_scene_node *child;
wl_list_for_each(child, &part->node->state.children, state.link) { wl_list_for_each_reverse(child, &part->node->state.children, state.link) {
if (child->type == WLR_SCENE_NODE_RECT) { if (child->type == WLR_SCENE_NODE_RECT) {
wlr_scene_node_set_enabled(child, true); wlr_scene_node_set_enabled(child, true);
return child; return child;