aboutsummaryrefslogtreecommitdiff
path: root/rivertile/main.zig
diff options
context:
space:
mode:
authorIsaac Freund <mail@isaacfreund.com>2023-01-06 17:47:54 +0100
committerIsaac Freund <mail@isaacfreund.com>2023-01-06 17:47:54 +0100
commitc479525ab8f54cbaf5f63e83267ca6d1ef23296f (patch)
tree3e383c82a00b7c8c2a3e4e8e746fac7be0538212 /rivertile/main.zig
parent030f7efd4f8ea362434f9826a5e7acae99f7e448 (diff)
downloadriver-c479525ab8f54cbaf5f63e83267ca6d1ef23296f.tar.gz
river-c479525ab8f54cbaf5f63e83267ca6d1ef23296f.tar.xz
rivertile: fix code to disallow 0 main count
Also document this limit
Diffstat (limited to 'rivertile/main.zig')
-rw-r--r--rivertile/main.zig19
1 files changed, 9 insertions, 10 deletions
diff --git a/rivertile/main.zig b/rivertile/main.zig
index dee3892..293ffeb 100644
--- a/rivertile/main.zig
+++ b/rivertile/main.zig
@@ -173,9 +173,11 @@ const Output = struct {
'+' => output.main_count +|= @intCast(u31, arg),
'-' => {
const result = output.main_count +| arg;
- if (result >= 0) output.main_count = @intCast(u31, result);
+ if (result >= 1) output.main_count = @intCast(u31, result);
+ },
+ else => {
+ if (arg >= 1) output.main_count = @intCast(u31, arg);
},
- else => output.main_count = @intCast(u31, arg),
}
},
.@"main-ratio" => {
@@ -194,7 +196,9 @@ const Output = struct {
},
.layout_demand => |ev| {
- const main_count = math.clamp(output.main_count, 1, @truncate(u31, ev.view_count));
+ assert(ev.view_count > 0);
+
+ const main_count = math.min(output.main_count, @truncate(u31, ev.view_count));
const secondary_count = @truncate(u31, ev.view_count) -| main_count;
const usable_width = switch (output.main_location) {
@@ -216,7 +220,7 @@ const Output = struct {
var secondary_height: u31 = undefined;
var secondary_height_rem: u31 = undefined;
- if (main_count > 0 and secondary_count > 0) {
+ if (secondary_count > 0) {
main_width = @floatToInt(u31, output.main_ratio * @intToFloat(f64, usable_width));
main_height = usable_height / main_count;
main_height_rem = usable_height % main_count;
@@ -224,15 +228,10 @@ const Output = struct {
secondary_width = usable_width - main_width;
secondary_height = usable_height / secondary_count;
secondary_height_rem = usable_height % secondary_count;
- } else if (main_count > 0) {
+ } else {
main_width = usable_width;
main_height = usable_height / main_count;
main_height_rem = usable_height % main_count;
- } else if (secondary_width > 0) {
- main_width = 0;
- secondary_width = usable_width;
- secondary_height = usable_height / secondary_count;
- secondary_height_rem = usable_height % secondary_count;
}
var i: u31 = 0;