diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2020-04-11 14:24:20 +0200 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2020-04-11 14:24:20 +0200 |
| commit | ff833a07d3ffc5916fdfb814f2896e82a97e91d9 (patch) | |
| tree | a2e5e5176e901420787bb67f97707e64908ed133 /src/root.zig | |
| parent | ad8e13df412cc2b6d813644ecdb04c3bc22880ff (diff) | |
| download | river-ff833a07d3ffc5916fdfb814f2896e82a97e91d9.tar.gz river-ff833a07d3ffc5916fdfb814f2896e82a97e91d9.tar.xz | |
Move output specific code out of root
This is in preperation of proper output event handling and eventual
multi output support.
Diffstat (limited to 'src/root.zig')
| -rw-r--r-- | src/root.zig | 244 |
1 files changed, 87 insertions, 157 deletions
diff --git a/src/root.zig b/src/root.zig index 6dccf42..2ac8074 100644 --- a/src/root.zig +++ b/src/root.zig @@ -19,22 +19,10 @@ pub const Root = struct { wlr_output_layout: *c.wlr_output_layout, outputs: std.TailQueue(Output), - /// The top of the stack is the "most important" view. - views: ViewStack, - /// The view that has seat focus, if any. + /// TODO: move this to Seat focused_view: ?*View, - /// A bit field of focused tags - current_focused_tags: u32, - pending_focused_tags: ?u32, - - /// Number of views in "master" section of the screen. - master_count: u32, - - /// Percentage of the total screen that the master section takes up. - master_factor: f64, - /// Number of pending configures sent in the current transaction. /// A value of 0 means there is no current transaction. pending_configures: u32, @@ -53,17 +41,8 @@ pub const Root = struct { self.outputs = std.TailQueue(Output).init(); - self.views.init(); - self.focused_view = null; - self.current_focused_tags = 1 << 0; - self.pending_focused_tags = null; - - self.master_count = 1; - - self.master_factor = 0.6; - self.pending_configures = 0; self.transaction_timer = null; @@ -80,19 +59,23 @@ pub const Root = struct { self.outputs.append(node); } - pub fn addView(self: *Self, wlr_xdg_surface: *c.wlr_xdg_surface) void { - const node = self.server.allocator.create(ViewStack.Node) catch unreachable; - node.view.init(self, wlr_xdg_surface, self.current_focused_tags); - self.views.push(node); + /// TODO: move this to seat, it's just a stop gap hack + pub fn focusedOutput(self: Self) *Output { + return &self.outputs.first.?.data; } /// Finds the topmost view under the output layout coordinates lx, ly /// returns the view if found, and a pointer to the wlr_surface as well as the surface coordinates pub fn viewAt(self: Self, lx: f64, ly: f64, surface: *?*c.wlr_surface, sx: *f64, sy: *f64) ?*View { - var it = ViewStack.iterator(self.views.first, 0xFFFFFFFF); - while (it.next()) |view| { - if (view.isAt(lx, ly, surface, sx, sy)) { - return view; + // Iterate over all views of all outputs + var output_it = self.outputs.first; + while (output_it) |node| : (output_it = node.next) { + const output = &node.data; + var view_it = ViewStack.iterator(output.views.first, 0xFFFFFFFF); + while (view_it.next()) |view| { + if (view.isAt(lx, ly, surface, sx, sy)) { + return view; + } } } return null; @@ -109,10 +92,11 @@ pub const Root = struct { /// Focus the next visible view in the stack, wrapping if needed. Does /// nothing if there is only one view in the stack. pub fn focusNextView(self: *Self) void { + const output = self.focusedOutput(); if (self.focused_view) |current_focus| { // If there is a currently focused view, focus the next visible view in the stack. const current_node = @fieldParentPtr(ViewStack.Node, "view", current_focus); - var it = ViewStack.iterator(current_node, self.current_focused_tags); + var it = ViewStack.iterator(current_node, output.current_focused_tags); // Skip past the current node _ = it.next(); // Focus the next visible node if there is one @@ -124,7 +108,7 @@ pub const Root = struct { // There is either no currently focused view or the last visible view in the // stack is focused and we need to wrap. - var it = ViewStack.iterator(self.views.first, self.current_focused_tags); + var it = ViewStack.iterator(output.views.first, output.current_focused_tags); if (it.next()) |view| { view.focus(view.wlr_xdg_surface.surface); } else { @@ -136,10 +120,11 @@ pub const Root = struct { /// Focus the previous view in the stack, wrapping if needed. Does nothing /// if there is only one view in the stack. pub fn focusPrevView(self: *Self) void { + const output = self.focusedOutput(); if (self.focused_view) |current_focus| { // If there is a currently focused view, focus the previous visible view in the stack. const current_node = @fieldParentPtr(ViewStack.Node, "view", current_focus); - var it = ViewStack.reverseIterator(current_node, self.current_focused_tags); + var it = ViewStack.reverseIterator(current_node, output.current_focused_tags); // Skip past the current node _ = it.next(); // Focus the previous visible node if there is one @@ -151,7 +136,7 @@ pub const Root = struct { // There is either no currently focused view or the first visible view in the // stack is focused and we need to wrap. - var it = ViewStack.reverseIterator(self.views.last, self.current_focused_tags); + var it = ViewStack.reverseIterator(output.views.last, output.current_focused_tags); if (it.next()) |view| { view.focus(view.wlr_xdg_surface.surface); } else { @@ -160,79 +145,13 @@ pub const Root = struct { } } + /// Arrange all outputs and then a transaction. pub fn arrange(self: *Self) void { - const root_tags = if (self.pending_focused_tags) |tags| - tags - else - self.current_focused_tags; - - const visible_count = blk: { - var count: u32 = 0; - var it = ViewStack.pendingIterator(self.views.first, root_tags); - while (it.next() != null) count += 1; - break :blk count; - }; - - const master_count = util.min(u32, self.master_count, visible_count); - const slave_count = if (master_count >= visible_count) 0 else visible_count - master_count; - - // This can't return null if we pass null as the reference - const output_box: *c.wlr_box = c.wlr_output_layout_get_box(self.wlr_output_layout, null); - - const outer_padding = self.server.config.outer_padding; - - const layout_width = @intCast(u32, output_box.width) - outer_padding * 2; - const layout_height = @intCast(u32, output_box.height) - outer_padding * 2; - - var master_column_width: u32 = undefined; - var slave_column_width: 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; - } else if (master_count > 0) { - master_column_width = layout_width; - slave_column_width = 0; - } else { - slave_column_width = layout_width; - master_column_width = 0; - } - - var i: u32 = 0; - var it = ViewStack.pendingIterator(self.views.first, root_tags); - while (it.next()) |view| { - if (i < master_count) { - // Add the remainder to the first master to ensure every pixel of height is used - const master_height = @divTrunc(layout_height, master_count); - const master_height_rem = layout_height % master_count; - - view.pending_box = Box{ - .x = @intCast(i32, outer_padding), - .y = @intCast(i32, outer_padding + 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, - }; - } else { - // Add the remainder to the first slave to ensure every pixel of height is used - const slave_height = @divTrunc(layout_height, slave_count); - const slave_height_rem = layout_height % slave_count; - - view.pending_box = Box{ - .x = @intCast(i32, outer_padding + master_column_width), - .y = @intCast(i32, outer_padding + (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, - }; - } - - i += 1; + var it = self.outputs.first; + while (it) |node| : (it = node.next) { + const output = &node.data; + output.arrange(); } - self.startTransaction(); } @@ -243,25 +162,30 @@ pub const Root = struct { // to reset the pending count to 0 and clear serials from the views self.pending_configures = 0; - var it = ViewStack.iterator(self.views.first, 0xFFFFFFFF); - while (it.next()) |view| { - // Clear the serial in case this transaction is interrupting a prior one. - view.pending_serial = null; - - if (view.needsConfigure()) { - view.configurePending(); - self.pending_configures += 1; - - // We save the current buffer, so we can send an early - // frame done event to give the client a head start on - // redrawing. - view.sendFrameDone(); - } + // Iterate over all views of all outputs + var output_it = self.outputs.first; + while (output_it) |node| : (output_it = node.next) { + const output = &node.data; + var view_it = ViewStack.iterator(output.views.first, 0xFFFFFFFF); + while (view_it.next()) |view| { + // Clear the serial in case this transaction is interrupting a prior one. + view.pending_serial = null; + + if (view.needsConfigure()) { + view.configurePending(); + self.pending_configures += 1; + + // We save the current buffer, so we can send an early + // frame done event to give the client a head start on + // redrawing. + view.sendFrameDone(); + } - // If there is a saved buffer present, then this transaction is interrupting - // a previous transaction and we should keep the old buffer. - if (view.stashed_buffer == null) { - view.stashBuffer(); + // If there is a saved buffer present, then this transaction is interrupting + // a previous transaction and we should keep the old buffer. + if (view.stashed_buffer == null) { + view.stashBuffer(); + } } } @@ -317,45 +241,51 @@ pub const Root = struct { // Ensure this is set to 0 to avoid entering invalid state (e.g. if called due to timeout) self.pending_configures = 0; - // If there were pending focused tags, make them the current focus - if (self.pending_focused_tags) |tags| { - Log.Debug.log( - "changing current focus: {b:0>10} to {b:0>10}", - .{ self.current_focused_tags, tags }, - ); - self.current_focused_tags = tags; - self.pending_focused_tags = null; - - self.focused_view = null; - self.focusNextView(); - } - - var it = ViewStack.iterator(self.views.first, 0xFFFFFFFF); - while (it.next()) |view| { - // Ensure that all pending state is cleared - view.pending_serial = null; - if (view.pending_box) |state| { - view.current_box = state; - view.pending_box = null; + // Iterate over all views of all outputs + var output_it = self.outputs.first; + while (output_it) |node| : (output_it = node.next) { + const output = &node.data; + + // If there were pending focused tags, make them the current focus + if (output.pending_focused_tags) |tags| { + Log.Debug.log( + "changing current focus: {b:0>10} to {b:0>10}", + .{ output.current_focused_tags, tags }, + ); + output.current_focused_tags = tags; + output.pending_focused_tags = null; + + self.focused_view = null; + self.focusNextView(); } - // Apply possible pending tags - if (view.pending_tags) |tags| { - view.current_tags = tags; - view.pending_tags = null; - - // If the pending tags caused the currently focused view to no - // longer be visible, focus the next view. - if (self.focused_view) |focus| { - if (focus == view and - view.current_tags & self.current_focused_tags == 0) - { - self.focusNextView(); + var view_it = ViewStack.iterator(output.views.first, 0xFFFFFFFF); + while (view_it.next()) |view| { + // Ensure that all pending state is cleared + view.pending_serial = null; + if (view.pending_box) |state| { + view.current_box = state; + view.pending_box = null; + } + + // Apply possible pending tags + if (view.pending_tags) |tags| { + view.current_tags = tags; + view.pending_tags = null; + + // If the pending tags caused the currently focused view to no + // longer be visible, focus the next view. + if (self.focused_view) |focus| { + if (focus == view and + view.current_tags & output.current_focused_tags == 0) + { + self.focusNextView(); + } } } - } - view.dropStashedBuffer(); + view.dropStashedBuffer(); + } } } }; |
