aboutsummaryrefslogtreecommitdiff
path: root/src/Output.zig
diff options
context:
space:
mode:
authorLeon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de>2020-05-18 19:22:48 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2020-05-20 23:02:28 +0200
commitb40c5d912e1ea566aa4847d86df4464ac025dd4a (patch)
tree42f39050ee15cfc0fdfc17f1524546126178755f /src/Output.zig
parentcee41e925dc0a9d7460806c9f8386512b207edf3 (diff)
downloadriver-b40c5d912e1ea566aa4847d86df4464ac025dd4a.tar.gz
river-b40c5d912e1ea566aa4847d86df4464ac025dd4a.tar.xz
Modify default layout to allow master area on all four sides
Also move it into a separate function
Diffstat (limited to 'src/Output.zig')
-rw-r--r--src/Output.zig218
1 files changed, 160 insertions, 58 deletions
diff --git a/src/Output.zig b/src/Output.zig
index 67dedbf..9937fb6 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -147,33 +147,15 @@ pub fn getRenderer(self: Self) *c.wlr_renderer {
return c.river_wlr_backend_get_renderer(self.wlr_output.backend);
}
-/// Arrange all views on the output for the current layout. Modifies only
-/// pending state, the changes are not appplied until a transaction is started
-/// and completed.
-pub fn arrangeViews(self: *Self) void {
- // If the output has a zero dimension, trying to arrange would cause
- // underflow and is pointless anyway
- if (self.usable_box.width == 0 or self.usable_box.height == 0) {
- return;
- }
-
- const output_tags = if (self.pending_focused_tags) |tags|
- tags
- else
- self.current_focused_tags;
-
- const visible_count = blk: {
- var count: u32 = 0;
- var it = ViewStack(View).pendingIterator(self.views.first, output_tags);
- while (it.next()) |node| {
- if (node.view.floating) {
- continue;
- }
- count += 1;
- }
- break :blk count;
- };
-
+const MasterPosition = enum {
+ Top,
+ Right,
+ Bottom,
+ Left,
+};
+
+/// Default layout of master-stack and slave-stack.
+pub fn layoutMasterStack(self: *Self, visible_count: u32, output_tags: u32, position: MasterPosition) void {
const master_count = std.math.min(self.master_count, visible_count);
const slave_count = if (master_count >= visible_count) 0 else visible_count - master_count;
@@ -184,18 +166,33 @@ pub fn arrangeViews(self: *Self) void {
const layout_width = @intCast(u32, self.usable_box.width) - outer_padding * 2;
const layout_height = @intCast(u32, self.usable_box.height) - outer_padding * 2;
- var master_column_width: u32 = undefined;
- var slave_column_width: u32 = undefined;
+ // Depending on position of the master area,
+ // the *_stack_size is either width or height
+ var master_stack_size: u32 = undefined;
+ var slave_stack_size: u32 = undefined;
if (master_count > 0 and slave_count > 0) {
// If both master and slave views are present
- master_column_width = @floatToInt(u32, @round(@intToFloat(f64, layout_width) * self.master_factor));
- slave_column_width = layout_width - master_column_width;
+ if (position == MasterPosition.Right or position == MasterPosition.Left) {
+ master_stack_size = @floatToInt(u32, @round(@intToFloat(f64, layout_width) * self.master_factor));
+ slave_stack_size = layout_width - master_stack_size;
+ } else {
+ master_stack_size = @floatToInt(u32, @round(@intToFloat(f64, layout_height) * self.master_factor));
+ slave_stack_size = layout_height - master_stack_size;
+ }
} else if (master_count > 0) {
- master_column_width = layout_width;
- slave_column_width = 0;
+ if (position == MasterPosition.Right or position == MasterPosition.Left) {
+ master_stack_size = layout_width;
+ } else {
+ master_stack_size = layout_height;
+ }
+ slave_stack_size = 0;
} else {
- slave_column_width = layout_width;
- master_column_width = 0;
+ if (position == MasterPosition.Right or position == MasterPosition.Left) {
+ slave_stack_size = layout_width;
+ } else {
+ slave_stack_size = layout_width;
+ }
+ master_stack_size = 0;
}
var i: u32 = 0;
@@ -212,30 +209,81 @@ pub fn arrangeViews(self: *Self) void {
// Add the remainder to the first master/slave to ensure every
// pixel of height is used
if (i < master_count) {
- const master_height = @divTrunc(layout_height, master_count);
- const master_height_rem = layout_height % master_count;
-
- new_box = .{
- .x = 0,
- .y = @intCast(i32, i * master_height +
- if (i > 0) master_height_rem else 0),
-
- .width = master_column_width,
- .height = master_height + if (i == 0) master_height_rem else 0,
- };
+ if (position == MasterPosition.Top) { // Top master
+ const master_width = @divTrunc(layout_width, master_count);
+ const master_width_rem = layout_width % master_count;
+ new_box = .{
+ .x = @intCast(i32, i * master_width + if (i > 0) master_width_rem else 0),
+ .y = 0,
+ .width = master_width + if (i == 0) master_width_rem else 0,
+ .height = master_stack_size,
+ };
+ } else if (position == MasterPosition.Right) { // Right master
+ const master_height = @divTrunc(layout_height, master_count);
+ const master_height_rem = layout_height % master_count;
+ new_box = .{
+ .x = @intCast(i32, slave_stack_size),
+ .y = @intCast(i32, i * master_height + if (i > 0) master_height_rem else 0),
+ .width = master_stack_size,
+ .height = master_height + if (i == 0) master_height_rem else 0,
+ };
+ } else if (position == MasterPosition.Bottom) { // Bottom master
+ const master_width = @divTrunc(layout_width, master_count);
+ const master_width_rem = layout_width % master_count;
+ new_box = .{
+ .x = @intCast(i32, i * master_width + if (i > 0) master_width_rem else 0),
+ .y = @intCast(i32, slave_stack_size),
+ .width = master_width + if (i == 0) master_width_rem else 0,
+ .height = master_stack_size,
+ };
+ } else { // Left master
+ const master_height = @divTrunc(layout_height, master_count);
+ const master_height_rem = layout_height % master_count;
+ new_box = .{
+ .x = 0,
+ .y = @intCast(i32, i * master_height + if (i > 0) master_height_rem else 0),
+ .width = master_stack_size,
+ .height = master_height + if (i == 0) master_height_rem else 0,
+ };
+ }
} else {
- const slave_height = @divTrunc(layout_height, slave_count);
- const slave_height_rem = layout_height % slave_count;
-
- new_box = .{
- .x = @intCast(i32, master_column_width),
- .y = @intCast(i32, (i - master_count) * slave_height +
- if (i > master_count) slave_height_rem else 0),
-
- .width = slave_column_width,
- .height = slave_height +
- if (i == master_count) slave_height_rem else 0,
- };
+ if (position == MasterPosition.Top) { // Top master
+ const slave_width = @divTrunc(layout_width, slave_count);
+ const slave_width_rem = layout_width % slave_count;
+ new_box = .{
+ .x = @intCast(i32, (i - master_count) * slave_width + if (i > master_count) slave_width_rem else 0),
+ .y = @intCast(i32, master_stack_size),
+ .width = slave_width + if (i == master_count) slave_width_rem else 0,
+ .height = slave_stack_size,
+ };
+ } else if (position == MasterPosition.Right) { // Right master
+ const slave_height = @divTrunc(layout_height, slave_count);
+ const slave_height_rem = layout_height % slave_count;
+ new_box = .{
+ .x = 0,
+ .y = @intCast(i32, (i - master_count) * slave_height + if (i > master_count) slave_height_rem else 0),
+ .width = slave_stack_size,
+ .height = slave_height + if (i == master_count) slave_height_rem else 0,
+ };
+ } else if (position == MasterPosition.Bottom) { // Bottom master
+ const slave_width = @divTrunc(layout_width, slave_count);
+ const slave_width_rem = layout_width % slave_count;
+ new_box = .{
+ .x = @intCast(i32, (i - master_count) * slave_width + if (i > master_count) slave_width_rem else 0),
+ .y = 0,
+ .width = slave_width + if (i == master_count) slave_width_rem else 0,
+ .height = slave_stack_size,
+ };
+ } else { // Left master
+ const slave_height = @divTrunc(layout_height, slave_count);
+ const slave_height_rem = layout_height % slave_count;
+ new_box = .{
+ .x = @intCast(i32, master_stack_size),
+ .y = @intCast(i32, (i - master_count) * slave_height + if (i > master_count) slave_height_rem else 0),
+ .width = slave_stack_size,
+ .height = slave_height + if (i == master_count) slave_height_rem else 0,
+ };
+ }
}
// Apply offsets from borders and padding
@@ -255,6 +303,60 @@ pub fn arrangeViews(self: *Self) void {
}
}
+/// Wrapper for default layout with master area on the top
+pub fn layoutTopMaster(self: *Self, visible_count: u32, output_tags: u32) void {
+ layoutMasterStack(self, visible_count, output_tags, MasterPosition.Top);
+}
+
+/// Wrapper for default layout with master area on the right
+pub fn layoutRightMaster(self: *Self, visible_count: u32, output_tags: u32) void {
+ layoutMasterStack(self, visible_count, output_tags, MasterPosition.Right);
+}
+
+/// Wrapper for default layout with master area on the bottom
+pub fn layoutBottomMaster(self: *Self, visible_count: u32, output_tags: u32) void {
+ layoutMasterStack(self, visible_count, output_tags, MasterPosition.Bottom);
+}
+
+/// Wrapper for default layout with master area on the left
+pub fn layoutLeftMaster(self: *Self, visible_count: u32, output_tags: u32) void {
+ layoutMasterStack(self, visible_count, output_tags, MasterPosition.Left);
+}
+
+/// Arrange all views on the output for the current layout. Modifies only
+/// pending state, the changes are not appplied until a transaction is started
+/// and completed.
+pub fn arrangeViews(self: *Self) void {
+ // If the output has a zero dimension, trying to arrange would cause
+ // underflow and is pointless anyway
+ if (self.usable_box.width == 0 or self.usable_box.height == 0) {
+ return;
+ }
+
+ const output_tags = if (self.pending_focused_tags) |tags|
+ tags
+ else
+ self.current_focused_tags;
+
+ const visible_count = blk: {
+ var count: u32 = 0;
+ var it = ViewStack(View).pendingIterator(self.views.first, output_tags);
+ while (it.next()) |node| {
+ if (node.view.floating) {
+ continue;
+ }
+ count += 1;
+ }
+ break :blk count;
+ };
+
+ //layoutFull(self, visible_count, output_tags);
+ //layoutTopMaster(self, visible_count, output_tags);
+ //layoutRightMaster(self, visible_count, output_tags);
+ //layoutBottomMaster(self, visible_count, output_tags);
+ layoutLeftMaster(self, visible_count, output_tags);
+}
+
/// Arrange all layer surfaces of this output and addjust the usable aread
pub fn arrangeLayers(self: *Self) void {
const full_box = blk: {