git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commitb1f24a072af27cb3a7735671f384516af94a34de
parent42eafdf118
authorLeon Henrik Plickat <[email protected]>
date2022-02-19 13:53
rivertile: Use saturating arithmetics to prevent over-/underflow when using user defined values

 rivertile/main.zig | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/rivertile/main.zig b/rivertile/main.zig
index 3c88843..4661fd2 100644
--- a/rivertile/main.zig
+++ b/rivertile/main.zig
@@ -201,12 +201,12 @@ const Output = struct {
                     0;
 
                 const usable_width = switch (output.main_location) {
-                    .left, .right => ev.usable_width - 2 * outer_padding,
-                    .top, .bottom => ev.usable_height - 2 * outer_padding,
+                    .left, .right => ev.usable_width -| (2 *| outer_padding),
+                    .top, .bottom => ev.usable_height -| (2 *| outer_padding),
                 };
                 const usable_height = switch (output.main_location) {
-                    .left, .right => ev.usable_height - 2 * outer_padding,
-                    .top, .bottom => ev.usable_width - 2 * outer_padding,
+                    .left, .right => ev.usable_height -| (2 *| outer_padding),
+                    .top, .bottom => ev.usable_width -| (2 *| outer_padding),
                 };
 
                 // to make things pixel-perfect, we make the first main and first secondary
@@ -258,10 +258,10 @@ const Output = struct {
                         height = secondary_height + if (i == main_count) secondary_height_rem else 0;
                     }
 
-                    x += @intCast(i32, view_padding);
-                    y += @intCast(i32, view_padding);
-                    width -= 2 * view_padding;
-                    height -= 2 * view_padding;
+                    x +|= @intCast(i32, view_padding);
+                    y +|= @intCast(i32, view_padding);
+                    width -|= 2 *| view_padding;
+                    height -|= 2 *| view_padding;
 
                     switch (output.main_location) {
                         .left => layout.pushViewDimensions(
@@ -272,22 +272,22 @@ const Output = struct {
                             ev.serial,
                         ),
                         .right => layout.pushViewDimensions(
-                            @intCast(i32, usable_width - width) - x + @intCast(i32, outer_padding),
-                            y + @intCast(i32, outer_padding),
+                            @intCast(i32, usable_width - width) - x +| @intCast(i32, outer_padding),
+                            y +| @intCast(i32, outer_padding),
                             width,
                             height,
                             ev.serial,
                         ),
                         .top => layout.pushViewDimensions(
-                            y + @intCast(i32, outer_padding),
-                            x + @intCast(i32, outer_padding),
+                            y +| @intCast(i32, outer_padding),
+                            x +| @intCast(i32, outer_padding),
                             height,
                             width,
                             ev.serial,
                         ),
                         .bottom => layout.pushViewDimensions(
-                            y + @intCast(i32, outer_padding),
-                            @intCast(i32, usable_width - width) - x + @intCast(i32, outer_padding),
+                            y +| @intCast(i32, outer_padding),
+                            @intCast(i32, usable_width - width) - x +| @intCast(i32, outer_padding),
                             height,
                             width,
                             ev.serial,