From b503e48623c1797d7a1c227a8ec09a87e615798a Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Mon, 5 May 2025 02:02:59 +0900 Subject: [PATCH] graphic-helper: properly handle very small multi_rects Before this patch, the multi_rect for a window switcher preview could be broken with a very small window (e.g. alacritty resized to 1x1). --- src/common/graphic-helpers.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/common/graphic-helpers.c b/src/common/graphic-helpers.c index ba1dda4a..6351083d 100644 --- a/src/common/graphic-helpers.c +++ b/src/common/graphic-helpers.c @@ -45,6 +45,7 @@ border_rect_set_size(struct border_rect *rect, int width, int height) { assert(rect); int border_width = rect->border_width; + assert(MIN(width, height) >= rect->border_width * 2); /* * The border is drawn like below: @@ -118,8 +119,14 @@ multi_rect_set_size(struct multi_rect *multi_rect, int width, int height) assert(multi_rect); int line_width = multi_rect->border_rects[0]->border_width; for (size_t i = 0; i < 3; i++) { - border_rect_set_size(multi_rect->border_rects[i], - width - i * line_width * 2, height - i * line_width * 2); + int w = width - i * line_width * 2; + int h = height - i * line_width * 2; + bool is_valid_size = (w >= line_width * 2) && (h >= line_width * 2); + wlr_scene_node_set_enabled(&multi_rect->border_rects[i]->tree->node, + is_valid_size); + if (is_valid_size) { + border_rect_set_size(multi_rect->border_rects[i], w, h); + } } }