diff options
| author | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2022-02-19 13:53:42 +0100 |
|---|---|---|
| committer | Isaac Freund <mail@isaacfreund.com> | 2022-02-26 16:19:15 +0100 |
| commit | e857631936df8a2b818c73ba0e6f860bcd068248 (patch) | |
| tree | 9f71985cb029ae9abebcae2159e31c9d88fb2a2d | |
| parent | e67a9423a81359bd9d3bc33215b24222a0c85775 (diff) | |
| download | river-e857631936df8a2b818c73ba0e6f860bcd068248.tar.gz river-e857631936df8a2b818c73ba0e6f860bcd068248.tar.xz | |
rivertile: Use saturating arithmetics to prevent over-/underflow when using user defined values
| -rw-r--r-- | rivertile/main.zig | 28 |
1 files 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, |
