Skip to content

Instantly share code, notes, and snippets.

@marcs-feh
Created March 13, 2023 14:17
Show Gist options
  • Save marcs-feh/387ac6968adc8c6102d92347658069d4 to your computer and use it in GitHub Desktop.
Save marcs-feh/387ac6968adc8c6102d92347658069d4 to your computer and use it in GitHub Desktop.
Rivertile pertag behavior
diff --git a/rivertile/main.zig b/rivertile/main.zig
index 6b9c458..cbef542 100644
--- a/rivertile/main.zig
+++ b/rivertile/main.zig
@@ -1,5 +1,4 @@
// This file is part of river, a dynamic tiling wayland compositor.
-//
// Copyright 2020-2021 The River Developers
//
// This program is free software: you can redistribute it and/or modify
@@ -104,13 +103,18 @@ const Context = struct {
};
const Output = struct {
- wl_output: *wl.Output,
name: u32,
+ wl_output: *wl.Output,
main_location: Location,
main_count: u31,
main_ratio: f64,
+ tag_ratios: [10]f64,
+ tag_locs: [10]Location,
+ tag_counts: [10]u31,
+ cur_tag: u31,
+
layout: *river.LayoutV3 = undefined,
fn init(output: *Output, context: *Context, wl_output: *wl.Output, name: u32) !void {
@@ -120,6 +124,10 @@ const Output = struct {
.main_location = default_main_location,
.main_count = default_main_count,
.main_ratio = default_main_ratio,
+ .tag_ratios = [_]f64{default_main_ratio} ** 10,
+ .tag_locs = [_]Location{default_main_location} ** 10,
+ .tag_counts = [_]u31{default_main_count} ** 10,
+ .cur_tag = 9,
};
if (context.initialized) try output.getLayout(context);
}
@@ -130,6 +138,7 @@ const Output = struct {
output.layout.setListener(*Output, layoutListener, output);
}
+
fn deinit(output: *Output) void {
output.wl_output.release();
output.layout.destroy();
@@ -159,7 +168,7 @@ const Output = struct {
};
switch (cmd) {
.@"main-location" => {
- output.main_location = std.meta.stringToEnum(Location, raw_arg) orelse {
+ output.tag_locs[output.cur_tag] = std.meta.stringToEnum(Location, raw_arg) orelse {
std.log.err("unknown location: {s}", .{raw_arg});
return;
};
@@ -169,14 +178,15 @@ const Output = struct {
std.log.err("failed to parse argument: {}", .{err});
return;
};
+
switch (raw_arg[0]) {
- '+' => output.main_count +|= @intCast(u31, arg),
+ '+' => output.tag_counts[output.cur_tag] +|= @intCast(u31, arg),
'-' => {
- const result = output.main_count +| arg;
- if (result >= 1) output.main_count = @intCast(u31, result);
+ const result = output.tag_counts[output.cur_tag] +| arg;
+ if (result >= 1) output.tag_counts[output.cur_tag] = @intCast(u31, result);
},
else => {
- if (arg >= 1) output.main_count = @intCast(u31, arg);
+ if (arg >= 1) output.tag_counts[output.cur_tag] = @intCast(u31, arg);
},
}
},
@@ -187,9 +197,9 @@ const Output = struct {
};
switch (raw_arg[0]) {
'+', '-' => {
- output.main_ratio = math.clamp(output.main_ratio + arg, 0.1, 0.9);
+ output.tag_ratios[output.cur_tag] = math.clamp(output.tag_ratios[output.cur_tag] + arg, 0.1, 0.9);
},
- else => output.main_ratio = math.clamp(arg, 0.1, 0.9),
+ else => output.tag_ratios[output.cur_tag] = math.clamp(arg, 0.1, 0.9),
}
},
}
@@ -198,6 +208,29 @@ const Output = struct {
.layout_demand => |ev| {
assert(ev.view_count > 0);
+ const tag = ev.tags;
+ output.cur_tag = switch(tag){
+ 1 => 0,
+ 2 => 1,
+ 4 => 2,
+ 8 => 3,
+ 16 => 4,
+ 32 => 5,
+ 64 => 6,
+ 128 => 7,
+ 256 => 8,
+ else => 9,
+ };
+
+ output.main_count = output.tag_counts[output.cur_tag];
+ output.tag_counts[9] = output.tag_counts[output.cur_tag];
+
+ output.main_ratio = output.tag_ratios[output.cur_tag];
+ output.tag_ratios[9] = output.tag_ratios[output.cur_tag];
+
+ output.main_location = output.tag_locs[output.cur_tag];
+ output.tag_locs[9] = output.tag_locs[output.cur_tag];
+
const main_count = math.min(output.main_count, @truncate(u31, ev.view_count));
const secondary_count = @truncate(u31, ev.view_count) -| main_count;
@marcs-feh
Copy link
Author

This patch follows the same terms as the river license (GPLv3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment