From 6305cc0f78f1901b7ca06a271c99d0010e664906 Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Sun, 4 May 2025 23:40:25 +0900 Subject: [PATCH] graphic-helper: properly handle very small multi_rects For example, alacritty can be resized to 1x1 and the size of the scene-rects inside the multi_rect for the window switcher preview could be negative. --- src/common/graphic-helpers.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common/graphic-helpers.c b/src/common/graphic-helpers.c index aed4564f..4739b899 100644 --- a/src/common/graphic-helpers.c +++ b/src/common/graphic-helpers.c @@ -8,6 +8,7 @@ #include #include "buffer.h" #include "common/graphic-helpers.h" +#include "common/macros.h" #include "common/mem.h" static void @@ -57,7 +58,7 @@ multi_rect_set_size(struct multi_rect *rect, int width, int height) * +-+-----+-+ | * +---------+ --- */ - for (size_t i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { /* Reposition, top and left don't ever change */ wlr_scene_node_set_position(&rect->right[i]->node, width - (i + 1) * line_width, (i + 1) * line_width); @@ -66,13 +67,17 @@ multi_rect_set_size(struct multi_rect *rect, int width, int height) /* Update sizes */ wlr_scene_rect_set_size(rect->top[i], - width - i * line_width * 2, line_width); + MAX(width - i * line_width * 2, 0), + line_width); wlr_scene_rect_set_size(rect->bottom[i], - width - i * line_width * 2, line_width); + MAX(width - i * line_width * 2, 0), + line_width); wlr_scene_rect_set_size(rect->left[i], - line_width, height - (i + 1) * line_width * 2); + line_width, + MAX(height - (i + 1) * line_width * 2, 0)); wlr_scene_rect_set_size(rect->right[i], - line_width, height - (i + 1) * line_width * 2); + line_width, + MAX(height - (i + 1) * line_width * 2, 0)); } }