commit 76db202
uint
·
2026-02-15 14:24:18 +0000 UTC
parent 89634c3
add min/max window width/height fixes swc wm dying if resize value is too large (unsigned wrapping back)
2 files changed,
+41,
-0
+4,
-0
1@@ -250,6 +250,10 @@ struct swc_window {
2
3 struct swc_window *parent;
4 uint32_t motion_throttle_ms;
5+ uint32_t min_width;
6+ uint32_t min_height;
7+ uint32_t max_width;
8+ uint32_t max_height;
9 };
10
11 /**
+37,
-0
1@@ -55,6 +55,36 @@ should_throttle_motion(uint32_t throttle_ms, uint32_t *last_time, uint32_t time)
2 return false;
3 }
4
5+static uint32_t
6+clamp_dimension(int32_t value, uint32_t min, uint32_t max)
7+{
8+ if (value < 0)
9+ value = 0;
10+
11+ if (min && value < min)
12+ value = min;
13+
14+ if (max) {
15+ if (min && max < min)
16+ max = min;
17+
18+ if (value > max)
19+ value = max;
20+ }
21+
22+ if (value > UINT32_MAX)
23+ value = UINT32_MAX;
24+
25+ return value;
26+}
27+
28+static void
29+clamp_window_size(const struct window *window, uint32_t *width, uint32_t *height)
30+{
31+ *width = clamp_dimension(*width, window->base.min_width, window->base.max_width);
32+ *height = clamp_dimension(*height, window->base.min_height, window->base.max_height);
33+}
34+
35 static void
36 handle_window_enter(struct wl_listener *listener, void *data)
37 {
38@@ -255,6 +285,8 @@ swc_window_set_size(struct swc_window *base, uint32_t width, uint32_t height)
39 struct window *window = INTERNAL(base);
40 struct swc_rectangle *geom = &window->view->base.geometry;
41
42+ clamp_window_size(window, &width, &height);
43+
44 if ((window->configure.pending && width == window->configure.width && height == window->configure.height)
45 || (!window->configure.pending && width == geom->width && height == geom->height))
46 {
47@@ -359,6 +391,7 @@ resize_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t fx, wl_
48 else if (window->resize.edges & SWC_WINDOW_EDGE_BOTTOM)
49 height = wl_fixed_to_int(fy) + window->resize.offset.y - geometry->y;
50
51+ clamp_window_size(window, &width, &height);
52 window->impl->configure(window, width, height);
53
54 return true;
55@@ -432,6 +465,10 @@ window_initialize(struct window *window, const struct window_impl *impl, struct
56 window->view_handler.impl = &view_handler_impl;
57 window->view->window = window;
58 window->base.motion_throttle_ms = def_motion_throttle_ms;
59+ window->base.min_width = 0;
60+ window->base.min_height = 0;
61+ window->base.max_width = 0;
62+ window->base.max_height = 0;
63 window->managed = false;
64 window->mode = WINDOW_MODE_STACKED;
65 window->move.pending = false;