ssd: guard against negative sizes

We always create a SSD for 0x0 window since decorations are usually
requested before a window is mapped. Thus the sizes of some buffers/rects
like edge shadows could be negative, which is asserted in wlroots 0.19.
This commit is contained in:
tokyo4j 2025-05-04 22:33:12 +09:00 committed by Hiroaki Yamamoto
parent defa1d1a98
commit 93d77801c5
4 changed files with 16 additions and 23 deletions

View file

@ -49,7 +49,7 @@ ssd_border_create(struct ssd *ssd)
add_scene_rect(&subtree->parts, LAB_SSD_PART_BOTTOM, parent,
full_width, theme->border_width, 0, height, color);
add_scene_rect(&subtree->parts, LAB_SSD_PART_TOP, parent,
width - 2 * corner_width, theme->border_width,
MAX(width - 2 * corner_width, 0), theme->border_width,
theme->border_width + corner_width,
-(ssd->titlebar.height + theme->border_width), color);
} FOR_EACH_END
@ -123,7 +123,7 @@ ssd_border_update(struct ssd *ssd)
: 0;
int top_width = ssd->titlebar.height <= 0 || ssd->state.was_squared
? full_width
: width - 2 * corner_width;
: MAX(width - 2 * corner_width, 0);
int top_x = ssd->titlebar.height <= 0 || ssd->state.was_squared
? 0
: theme->border_width + corner_width;

View file

@ -55,15 +55,7 @@ add_scene_rect(struct wl_list *list, enum ssd_part_type type,
struct wlr_scene_tree *parent, int width, int height,
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;
assert(width >= 0 && height >= 0);
struct ssd_part *part = add_scene_part(list, type);
part->node = &wlr_scene_rect_create(
parent, width, height, color)->node;

View file

@ -32,8 +32,8 @@ static void
corner_scale_crop(struct wlr_scene_buffer *buffer, int horizontal_overlap,
int vertical_overlap, int corner_size)
{
int width = corner_size - horizontal_overlap;
int height = corner_size - vertical_overlap;
int width = MAX(corner_size - horizontal_overlap, 0);
int height = MAX(corner_size - vertical_overlap, 0);
struct wlr_fbox src_box = {
.x = horizontal_overlap,
.y = vertical_overlap,
@ -127,7 +127,7 @@ set_shadow_part_geometry(struct ssd_part *part, int width, int height,
y = -titlebar_height + inset;
wlr_scene_node_set_position(part->node, x, y);
wlr_scene_buffer_set_dest_size(
scene_buf, visible_shadow_width, height - 2 * inset);
scene_buf, visible_shadow_width, MAX(height - 2 * inset, 0));
wlr_scene_node_set_enabled(part->node, show_sides);
break;
case LAB_SSD_PART_BOTTOM:
@ -135,7 +135,7 @@ set_shadow_part_geometry(struct ssd_part *part, int width, int height,
y = -titlebar_height + height;
wlr_scene_node_set_position(part->node, x, y);
wlr_scene_buffer_set_dest_size(
scene_buf, width - 2 * inset, visible_shadow_width);
scene_buf, MAX(width - 2 * inset, 0), visible_shadow_width);
wlr_scene_node_set_enabled(part->node, show_topbottom);
break;
case LAB_SSD_PART_LEFT:
@ -143,7 +143,7 @@ set_shadow_part_geometry(struct ssd_part *part, int width, int height,
y = -titlebar_height + inset;
wlr_scene_node_set_position(part->node, x, y);
wlr_scene_buffer_set_dest_size(
scene_buf, visible_shadow_width, height - 2 * inset);
scene_buf, visible_shadow_width, MAX(height - 2 * inset, 0));
wlr_scene_node_set_enabled(part->node, show_sides);
break;
case LAB_SSD_PART_TOP:
@ -151,7 +151,7 @@ set_shadow_part_geometry(struct ssd_part *part, int width, int height,
y = -titlebar_height - visible_shadow_width;
wlr_scene_node_set_position(part->node, x, y);
wlr_scene_buffer_set_dest_size(
scene_buf, width - 2 * inset, visible_shadow_width);
scene_buf, MAX(width - 2 * inset, 0), visible_shadow_width);
wlr_scene_node_set_enabled(part->node, show_topbottom);
break;
default:

View file

@ -58,7 +58,7 @@ ssd_titlebar_create(struct ssd *ssd)
/* Background */
add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
width - corner_width * 2, theme->titlebar_height,
MAX(width - corner_width * 2, 0), theme->titlebar_height,
corner_width, 0, color);
add_scene_buffer(&subtree->parts, LAB_SSD_PART_TITLEBAR_CORNER_LEFT, parent,
corner_top_left, -rc.theme->border_width, -rc.theme->border_width);
@ -153,7 +153,7 @@ set_squared_corners(struct ssd *ssd, bool enable)
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
wlr_scene_node_set_position(part->node, x, 0);
wlr_scene_rect_set_size(wlr_scene_rect_from_node(part->node),
width - 2 * x, theme->titlebar_height);
MAX(width - 2 * x, 0), theme->titlebar_height);
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR_CORNER_LEFT);
wlr_scene_node_set_enabled(part->node, !enable);
@ -204,9 +204,10 @@ static void
update_visible_buttons(struct ssd *ssd)
{
struct view *view = ssd->view;
int width = view->current.width - (2 * view->server->theme->window_titlebar_padding_width);
int button_width = view->server->theme->window_button_width;
int button_spacing = view->server->theme->window_button_spacing;
struct theme *theme = view->server->theme;
int width = MAX(view->current.width - 2 * theme->window_titlebar_padding_width, 0);
int button_width = theme->window_button_width;
int button_spacing = theme->window_button_spacing;
int button_count_left = wl_list_length(&rc.title_buttons_left);
int button_count_right = wl_list_length(&rc.title_buttons_right);
@ -301,7 +302,7 @@ ssd_titlebar_update(struct ssd *ssd)
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLEBAR);
wlr_scene_rect_set_size(
wlr_scene_rect_from_node(part->node),
width - bg_offset * 2, theme->titlebar_height);
MAX(width - bg_offset * 2, 0), theme->titlebar_height);
x = theme->window_titlebar_padding_width;
wl_list_for_each(b, &rc.title_buttons_left, link) {