]> git.mdlowis.com Git - proto/labwc.git/commitdiff
graphic-helper: properly handle very small multi_rects
authortokyo4j <hrak1529@gmail.com>
Sun, 4 May 2025 14:40:25 +0000 (23:40 +0900)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Sun, 18 May 2025 21:51:42 +0000 (06:51 +0900)
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

index aed4564fd619b30a76b0e30371a8e555fd5d6216..4739b899778bc48c55669043b3576bbc731d1667 100644 (file)
@@ -8,6 +8,7 @@
 #include <wlr/util/box.h>
 #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));
        }
 }