src/ssd/: Don't access view->surface->current directly

Instead use view->{w,h} which are set on client commit
This commit is contained in:
Consolatis 2022-02-24 01:27:29 +01:00 committed by Johan Malm
parent f4c9d1ba9f
commit c033667716
5 changed files with 34 additions and 29 deletions

View file

@ -164,7 +164,7 @@ void
ssd_update_geometry(struct view *view) ssd_update_geometry(struct view *view)
{ {
/* TODO: verify we are not called without reason. like in commit handlers */ /* TODO: verify we are not called without reason. like in commit handlers */
if (!view->ssd.tree || !view->surface) { if (!view->ssd.tree || !view->scene_node) {
return; return;
} }
@ -175,8 +175,8 @@ ssd_update_geometry(struct view *view)
wlr_scene_node_set_enabled(&view->ssd.tree->node, false); wlr_scene_node_set_enabled(&view->ssd.tree->node, false);
} }
int width = view->surface->current.width; int width = view->w;
int height = view->surface->current.height; int height = view->h;
if (width == view->ssd.state.width && height == view->ssd.state.height) { if (width == view->ssd.state.width && height == view->ssd.state.height) {
return; return;
} }

View file

@ -13,8 +13,8 @@ void
ssd_border_create(struct view *view) ssd_border_create(struct view *view)
{ {
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->surface->current.width; int width = view->w;
int height = view->surface->current.height; int height = view->h;
int full_width = width + 2 * theme->border_width; int full_width = width + 2 * theme->border_width;
float *color; float *color;
@ -48,8 +48,8 @@ ssd_border_update(struct view *view)
{ {
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->surface->current.width; int width = view->w;
int height = view->surface->current.height; int height = view->h;
int full_width = width + 2 * theme->border_width; int full_width = width + 2 * theme->border_width;
struct ssd_part *part; struct ssd_part *part;

View file

@ -11,8 +11,8 @@ ssd_extents_create(struct view *view)
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
float invisible[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; float invisible[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
struct wl_list *part_list = &view->ssd.extents.parts; struct wl_list *part_list = &view->ssd.extents.parts;
int width = view->surface->current.width; int width = view->w;
int height = view->surface->current.height; int height = view->h;
int full_height = height + theme->border_width + SSD_HEIGHT; int full_height = height + theme->border_width + SSD_HEIGHT;
int full_width = width + 2 * theme->border_width; int full_width = width + 2 * theme->border_width;
int extended_area = EXTENDED_AREA; int extended_area = EXTENDED_AREA;
@ -61,8 +61,8 @@ ssd_extents_update(struct view *view)
{ {
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->surface->current.width; int width = view->w;
int height = view->surface->current.height; int height = view->h;
int full_height = height + theme->border_width + SSD_HEIGHT; int full_height = height + theme->border_width + SSD_HEIGHT;
int full_width = width + 2 * theme->border_width; int full_width = width + 2 * theme->border_width;
int extended_area = EXTENDED_AREA; int extended_area = EXTENDED_AREA;

View file

@ -18,6 +18,15 @@ add_scene_rect(struct wl_list *list, enum ssd_part_type type,
struct wlr_scene_node *parent, int width, int height, struct wlr_scene_node *parent, int width, int height,
int x, int y, float color[4]) int x, int y, float color[4])
{ {
/*
* When initialized without surface being mapped,
* size may be negative. Just set to 0, next call
* to ssd_*_update() will update the rect to use
* its correct size.
*/
width = width >= 0 ? width : 0;
height = height >= 0 ? height : 0;
struct ssd_part *part = add_scene_part(list, type); struct ssd_part *part = add_scene_part(list, type);
part->node = &wlr_scene_rect_create( part->node = &wlr_scene_rect_create(
parent, width, height, color)->node; parent, width, height, color)->node;

View file

@ -17,7 +17,7 @@ void
ssd_titlebar_create(struct view *view) ssd_titlebar_create(struct view *view)
{ {
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->surface->current.width; int width = view->w;
int full_width = width + 2 * theme->border_width; int full_width = width + 2 * theme->border_width;
float *color; float *color;
@ -72,7 +72,7 @@ is_direct_child(struct wlr_scene_node *node, struct ssd_sub_tree *subtree)
void void
ssd_titlebar_update(struct view *view) ssd_titlebar_update(struct view *view)
{ {
int width = view->surface->current.width; int width = view->w;
if (width == view->ssd.state.width) { if (width == view->ssd.state.width) {
return; return;
} }
@ -144,7 +144,7 @@ static void
ssd_update_title_positions(struct view *view) ssd_update_title_positions(struct view *view)
{ {
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
int width = view->surface->current.width; int width = view->w;
int full_width = width + 2 * view->server->theme->border_width; int full_width = width + 2 * view->server->theme->border_width;
int x, y; int x, y;
@ -154,8 +154,7 @@ ssd_update_title_positions(struct view *view)
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(view, subtree) {
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE); part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE);
if (!part) { if (!part) {
wlr_log(WLR_ERROR, /* view->surface never been mapped */
"Failed to position SSD title: title node not found");
continue; continue;
} }
@ -163,8 +162,6 @@ ssd_update_title_positions(struct view *view)
y = (SSD_HEIGHT - part->buffer->base.height) / 2; y = (SSD_HEIGHT - part->buffer->base.height) / 2;
rect = lab_wlr_scene_get_rect(part->node->parent); rect = lab_wlr_scene_get_rect(part->node->parent);
if (rect->width <= 0) { if (rect->width <= 0) {
wlr_log(WLR_ERROR,
"Failed to position SSD title: not enough screen space");
wlr_scene_node_set_position(part->node, x, y); wlr_scene_node_set_position(part->node, x, y);
continue; continue;
} }
@ -221,17 +218,8 @@ ssd_update_title(struct view *view)
struct ssd_state_title_width *dstate; struct ssd_state_title_width *dstate;
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(view, subtree) {
parent_part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR); parent_part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
if (!parent_part) { assert(parent_part);
wlr_log(WLR_ERROR,
"Failed to update SSD title: parent node not found");
continue;
}
rect = lab_wlr_scene_get_rect(parent_part->node);
if (rect->width <= 0) {
wlr_log(WLR_ERROR,
"Failed to update SSD title: not enough screen space");
continue;
}
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;
@ -239,11 +227,19 @@ ssd_update_title(struct view *view)
dstate = &state->inactive; dstate = &state->inactive;
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 (rect->width <= 0) {
dstate->truncated = true;
continue;
}
if (title_unchanged if (title_unchanged
&& !dstate->truncated && dstate->width < rect->width) { && !dstate->truncated && dstate->width < rect->width) {
/* title the same + we don't need to resize title */ /* title the same + we don't need to resize title */
continue; continue;
} }
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE); part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE);
if (!part) { if (!part) {
part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE); part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE);