Move output specific code out of root
This is in preperation of proper output event handling and eventual multi output support.
This commit is contained in:
parent
ad8e13df41
commit
ff833a07d3
@ -33,22 +33,24 @@ pub fn focusPrevView(server: *Server, arg: Arg) void {
|
|||||||
/// Modify the number of master views
|
/// Modify the number of master views
|
||||||
pub fn modifyMasterCount(server: *Server, arg: Arg) void {
|
pub fn modifyMasterCount(server: *Server, arg: Arg) void {
|
||||||
const delta = arg.int;
|
const delta = arg.int;
|
||||||
server.root.master_count = @intCast(u32, std.math.max(
|
const output = server.root.focusedOutput();
|
||||||
0,
|
output.master_count = @intCast(
|
||||||
@intCast(i32, server.root.master_count) + delta,
|
u32,
|
||||||
));
|
std.math.max(0, @intCast(i32, output.master_count) + delta),
|
||||||
|
);
|
||||||
server.root.arrange();
|
server.root.arrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modify the percent of the width of the screen that the master views occupy.
|
/// Modify the percent of the width of the screen that the master views occupy.
|
||||||
pub fn modifyMasterFactor(server: *Server, arg: Arg) void {
|
pub fn modifyMasterFactor(server: *Server, arg: Arg) void {
|
||||||
const delta = arg.float;
|
const delta = arg.float;
|
||||||
|
const output = server.root.focusedOutput();
|
||||||
const new_master_factor = std.math.min(
|
const new_master_factor = std.math.min(
|
||||||
std.math.max(server.root.master_factor + delta, 0.05),
|
std.math.max(output.master_factor + delta, 0.05),
|
||||||
0.95,
|
0.95,
|
||||||
);
|
);
|
||||||
if (new_master_factor != server.root.master_factor) {
|
if (new_master_factor != output.master_factor) {
|
||||||
server.root.master_factor = new_master_factor;
|
output.master_factor = new_master_factor;
|
||||||
server.root.arrange();
|
server.root.arrange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,10 +59,11 @@ pub fn modifyMasterFactor(server: *Server, arg: Arg) void {
|
|||||||
/// TODO: if the top of the stack is focused, bump the next visible view.
|
/// TODO: if the top of the stack is focused, bump the next visible view.
|
||||||
pub fn zoom(server: *Server, arg: Arg) void {
|
pub fn zoom(server: *Server, arg: Arg) void {
|
||||||
if (server.root.focused_view) |current_focus| {
|
if (server.root.focused_view) |current_focus| {
|
||||||
|
const output = server.root.focusedOutput();
|
||||||
const node = @fieldParentPtr(ViewStack.Node, "view", current_focus);
|
const node = @fieldParentPtr(ViewStack.Node, "view", current_focus);
|
||||||
if (node != server.root.views.first) {
|
if (node != output.views.first) {
|
||||||
server.root.views.remove(node);
|
output.views.remove(node);
|
||||||
server.root.views.push(node);
|
output.views.push(node);
|
||||||
server.root.arrange();
|
server.root.arrange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,16 +72,18 @@ pub fn zoom(server: *Server, arg: Arg) void {
|
|||||||
/// Switch focus to the passed tags.
|
/// Switch focus to the passed tags.
|
||||||
pub fn focusTags(server: *Server, arg: Arg) void {
|
pub fn focusTags(server: *Server, arg: Arg) void {
|
||||||
const tags = arg.uint;
|
const tags = arg.uint;
|
||||||
server.root.pending_focused_tags = tags;
|
const output = server.root.focusedOutput();
|
||||||
|
output.pending_focused_tags = tags;
|
||||||
server.root.arrange();
|
server.root.arrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Toggle focus of the passsed tags.
|
/// Toggle focus of the passsed tags.
|
||||||
pub fn toggleTags(server: *Server, arg: Arg) void {
|
pub fn toggleTags(server: *Server, arg: Arg) void {
|
||||||
const tags = arg.uint;
|
const tags = arg.uint;
|
||||||
const new_focused_tags = server.root.current_focused_tags ^ tags;
|
const output = server.root.focusedOutput();
|
||||||
|
const new_focused_tags = output.current_focused_tags ^ tags;
|
||||||
if (new_focused_tags != 0) {
|
if (new_focused_tags != 0) {
|
||||||
server.root.pending_focused_tags = new_focused_tags;
|
output.pending_focused_tags = new_focused_tags;
|
||||||
server.root.arrange();
|
server.root.arrange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
121
src/output.zig
121
src/output.zig
@ -4,7 +4,9 @@ const render = @import("render.zig");
|
|||||||
|
|
||||||
const Box = @import("box.zig").Box;
|
const Box = @import("box.zig").Box;
|
||||||
const LayerSurface = @import("layer_surface.zig").LayerSurface;
|
const LayerSurface = @import("layer_surface.zig").LayerSurface;
|
||||||
|
const Log = @import("log.zig").Log;
|
||||||
const Root = @import("root.zig").Root;
|
const Root = @import("root.zig").Root;
|
||||||
|
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||||
|
|
||||||
pub const Output = struct {
|
pub const Output = struct {
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
@ -12,8 +14,26 @@ pub const Output = struct {
|
|||||||
root: *Root,
|
root: *Root,
|
||||||
wlr_output: *c.wlr_output,
|
wlr_output: *c.wlr_output,
|
||||||
|
|
||||||
|
/// All layer surfaces on the output, indexed by the layer enum.
|
||||||
layers: [4]std.TailQueue(LayerSurface),
|
layers: [4]std.TailQueue(LayerSurface),
|
||||||
|
|
||||||
|
/// The area left for views and other layer surfaces after applying the
|
||||||
|
/// exclusive zones of exclusive layer surfaces.
|
||||||
|
usable_box: Box,
|
||||||
|
|
||||||
|
/// The top of the stack is the "most important" view.
|
||||||
|
views: ViewStack,
|
||||||
|
|
||||||
|
/// 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,
|
||||||
|
|
||||||
listen_frame: c.wl_listener,
|
listen_frame: c.wl_listener,
|
||||||
|
|
||||||
pub fn init(self: *Self, root: *Root, wlr_output: *c.wlr_output) !void {
|
pub fn init(self: *Self, root: *Root, wlr_output: *c.wlr_output) !void {
|
||||||
@ -41,6 +61,17 @@ pub const Output = struct {
|
|||||||
layer.* = std.TailQueue(LayerSurface).init();
|
layer.* = std.TailQueue(LayerSurface).init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.usable_box = undefined;
|
||||||
|
|
||||||
|
self.views.init();
|
||||||
|
|
||||||
|
self.current_focused_tags = 1 << 0;
|
||||||
|
self.pending_focused_tags = null;
|
||||||
|
|
||||||
|
self.master_count = 1;
|
||||||
|
|
||||||
|
self.master_factor = 0.6;
|
||||||
|
|
||||||
// Sets up a listener for the frame notify event.
|
// Sets up a listener for the frame notify event.
|
||||||
self.listen_frame.notify = handleFrame;
|
self.listen_frame.notify = handleFrame;
|
||||||
c.wl_signal_add(&wlr_output.events.frame, &self.listen_frame);
|
c.wl_signal_add(&wlr_output.events.frame, &self.listen_frame);
|
||||||
@ -57,6 +88,14 @@ pub const Output = struct {
|
|||||||
c.wlr_output_create_global(wlr_output);
|
c.wlr_output_create_global(wlr_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a new view to the output. arrangeViews() will be called by the view
|
||||||
|
/// when it is mapped.
|
||||||
|
pub fn addView(self: *Self, wlr_xdg_surface: *c.wlr_xdg_surface) void {
|
||||||
|
const node = self.root.server.allocator.create(ViewStack.Node) catch unreachable;
|
||||||
|
node.view.init(self, wlr_xdg_surface, self.current_focused_tags);
|
||||||
|
self.views.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a newly created layer surface to the output.
|
/// Add a newly created layer surface to the output.
|
||||||
pub fn addLayerSurface(self: *Self, wlr_layer_surface: *c.wlr_layer_surface_v1) !void {
|
pub fn addLayerSurface(self: *Self, wlr_layer_surface: *c.wlr_layer_surface_v1) !void {
|
||||||
const layer = wlr_layer_surface.client_pending.layer;
|
const layer = wlr_layer_surface.client_pending.layer;
|
||||||
@ -66,6 +105,86 @@ pub const Output = struct {
|
|||||||
self.arrangeLayers();
|
self.arrangeLayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn arrange(self: *Self) void {
|
||||||
|
// TODO: properly handle output events instead of calling arrangeLayers() here
|
||||||
|
self.arrangeLayers();
|
||||||
|
self.arrangeViews();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
fn arrangeViews(self: *Self) void {
|
||||||
|
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.pendingIterator(self.views.first, output_tags);
|
||||||
|
while (it.next() != null) count += 1;
|
||||||
|
break :blk count;
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
const outer_padding = self.root.server.config.outer_padding;
|
||||||
|
|
||||||
|
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;
|
||||||
|
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, output_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Arrange all layer surfaces of this output and addjust the usable aread
|
/// Arrange all layer surfaces of this output and addjust the usable aread
|
||||||
pub fn arrangeLayers(self: *Self) void {
|
pub fn arrangeLayers(self: *Self) void {
|
||||||
// TODO: handle exclusive zones
|
// TODO: handle exclusive zones
|
||||||
@ -85,6 +204,8 @@ pub const Output = struct {
|
|||||||
self.arrangeLayer(layer, bounds);
|
self.arrangeLayer(layer, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.usable_box = bounds;
|
||||||
|
|
||||||
// TODO: handle seat focus
|
// TODO: handle seat focus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,10 +44,7 @@ pub fn renderOutput(output: *Output) void {
|
|||||||
renderLayer(output.*, output.layers[c.ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &now, ox, oy);
|
renderLayer(output.*, output.layers[c.ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &now, ox, oy);
|
||||||
|
|
||||||
// The first view in the list is "on top" so iterate in reverse.
|
// The first view in the list is "on top" so iterate in reverse.
|
||||||
var it = ViewStack.reverseIterator(
|
var it = ViewStack.reverseIterator(output.views.last, output.current_focused_tags);
|
||||||
output.root.views.last,
|
|
||||||
output.root.current_focused_tags,
|
|
||||||
);
|
|
||||||
while (it.next()) |view| {
|
while (it.next()) |view| {
|
||||||
// This check prevents a race condition when a frame is requested
|
// This check prevents a race condition when a frame is requested
|
||||||
// between mapping of a view and the first configure being handled.
|
// between mapping of a view and the first configure being handled.
|
||||||
@ -166,8 +163,8 @@ fn renderView(output: Output, view: *View, now: *c.struct_timespec, ox: f64, oy:
|
|||||||
// If we have a stashed buffer, we are in the middle of a transaction
|
// If we have a stashed buffer, we are in the middle of a transaction
|
||||||
// and need to render that buffer until the transaction is complete.
|
// and need to render that buffer until the transaction is complete.
|
||||||
if (view.stashed_buffer) |buffer| {
|
if (view.stashed_buffer) |buffer| {
|
||||||
const border_width = view.root.server.config.border_width;
|
const border_width = view.output.root.server.config.border_width;
|
||||||
const view_padding = view.root.server.config.view_padding;
|
const view_padding = view.output.root.server.config.view_padding;
|
||||||
var box = c.wlr_box{
|
var box = c.wlr_box{
|
||||||
.x = view.current_box.x + @intCast(i32, border_width + view_padding),
|
.x = view.current_box.x + @intCast(i32, border_width + view_padding),
|
||||||
.y = view.current_box.y + @intCast(i32, border_width + view_padding),
|
.y = view.current_box.y + @intCast(i32, border_width + view_padding),
|
||||||
@ -231,8 +228,8 @@ fn renderSurface(_surface: ?*c.wlr_surface, sx: c_int, sy: c_int, data: ?*c_void
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const border_width = view.root.server.config.border_width;
|
const border_width = view.output.root.server.config.border_width;
|
||||||
const view_padding = view.root.server.config.view_padding;
|
const view_padding = view.output.root.server.config.view_padding;
|
||||||
var box = c.wlr_box{
|
var box = c.wlr_box{
|
||||||
.x = @floatToInt(c_int, rdata.ox) + view.current_box.x + sx +
|
.x = @floatToInt(c_int, rdata.ox) + view.current_box.x + sx +
|
||||||
@intCast(c_int, border_width + view_padding),
|
@intCast(c_int, border_width + view_padding),
|
||||||
|
154
src/root.zig
154
src/root.zig
@ -19,22 +19,10 @@ pub const Root = struct {
|
|||||||
wlr_output_layout: *c.wlr_output_layout,
|
wlr_output_layout: *c.wlr_output_layout,
|
||||||
outputs: std.TailQueue(Output),
|
outputs: std.TailQueue(Output),
|
||||||
|
|
||||||
/// The top of the stack is the "most important" view.
|
|
||||||
views: ViewStack,
|
|
||||||
|
|
||||||
/// The view that has seat focus, if any.
|
/// The view that has seat focus, if any.
|
||||||
|
/// TODO: move this to Seat
|
||||||
focused_view: ?*View,
|
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.
|
/// Number of pending configures sent in the current transaction.
|
||||||
/// A value of 0 means there is no current transaction.
|
/// A value of 0 means there is no current transaction.
|
||||||
pending_configures: u32,
|
pending_configures: u32,
|
||||||
@ -53,17 +41,8 @@ pub const Root = struct {
|
|||||||
|
|
||||||
self.outputs = std.TailQueue(Output).init();
|
self.outputs = std.TailQueue(Output).init();
|
||||||
|
|
||||||
self.views.init();
|
|
||||||
|
|
||||||
self.focused_view = null;
|
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.pending_configures = 0;
|
||||||
|
|
||||||
self.transaction_timer = null;
|
self.transaction_timer = null;
|
||||||
@ -80,21 +59,25 @@ pub const Root = struct {
|
|||||||
self.outputs.append(node);
|
self.outputs.append(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addView(self: *Self, wlr_xdg_surface: *c.wlr_xdg_surface) void {
|
/// TODO: move this to seat, it's just a stop gap hack
|
||||||
const node = self.server.allocator.create(ViewStack.Node) catch unreachable;
|
pub fn focusedOutput(self: Self) *Output {
|
||||||
node.view.init(self, wlr_xdg_surface, self.current_focused_tags);
|
return &self.outputs.first.?.data;
|
||||||
self.views.push(node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the topmost view under the output layout coordinates lx, ly
|
/// 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
|
/// 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 {
|
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);
|
// Iterate over all views of all outputs
|
||||||
while (it.next()) |view| {
|
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)) {
|
if (view.isAt(lx, ly, surface, sx, sy)) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,10 +92,11 @@ pub const Root = struct {
|
|||||||
/// Focus the next visible view in the stack, wrapping if needed. Does
|
/// Focus the next visible view in the stack, wrapping if needed. Does
|
||||||
/// nothing if there is only one view in the stack.
|
/// nothing if there is only one view in the stack.
|
||||||
pub fn focusNextView(self: *Self) void {
|
pub fn focusNextView(self: *Self) void {
|
||||||
|
const output = self.focusedOutput();
|
||||||
if (self.focused_view) |current_focus| {
|
if (self.focused_view) |current_focus| {
|
||||||
// If there is a currently focused view, focus the next visible view in the stack.
|
// If there is a currently focused view, focus the next visible view in the stack.
|
||||||
const current_node = @fieldParentPtr(ViewStack.Node, "view", current_focus);
|
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
|
// Skip past the current node
|
||||||
_ = it.next();
|
_ = it.next();
|
||||||
// Focus the next visible node if there is one
|
// 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
|
// There is either no currently focused view or the last visible view in the
|
||||||
// stack is focused and we need to wrap.
|
// 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| {
|
if (it.next()) |view| {
|
||||||
view.focus(view.wlr_xdg_surface.surface);
|
view.focus(view.wlr_xdg_surface.surface);
|
||||||
} else {
|
} else {
|
||||||
@ -136,10 +120,11 @@ pub const Root = struct {
|
|||||||
/// Focus the previous view in the stack, wrapping if needed. Does nothing
|
/// Focus the previous view in the stack, wrapping if needed. Does nothing
|
||||||
/// if there is only one view in the stack.
|
/// if there is only one view in the stack.
|
||||||
pub fn focusPrevView(self: *Self) void {
|
pub fn focusPrevView(self: *Self) void {
|
||||||
|
const output = self.focusedOutput();
|
||||||
if (self.focused_view) |current_focus| {
|
if (self.focused_view) |current_focus| {
|
||||||
// If there is a currently focused view, focus the previous visible view in the stack.
|
// If there is a currently focused view, focus the previous visible view in the stack.
|
||||||
const current_node = @fieldParentPtr(ViewStack.Node, "view", current_focus);
|
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
|
// Skip past the current node
|
||||||
_ = it.next();
|
_ = it.next();
|
||||||
// Focus the previous visible node if there is one
|
// 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
|
// There is either no currently focused view or the first visible view in the
|
||||||
// stack is focused and we need to wrap.
|
// 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| {
|
if (it.next()) |view| {
|
||||||
view.focus(view.wlr_xdg_surface.surface);
|
view.focus(view.wlr_xdg_surface.surface);
|
||||||
} else {
|
} else {
|
||||||
@ -160,79 +145,13 @@ pub const Root = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Arrange all outputs and then a transaction.
|
||||||
pub fn arrange(self: *Self) void {
|
pub fn arrange(self: *Self) void {
|
||||||
const root_tags = if (self.pending_focused_tags) |tags|
|
var it = self.outputs.first;
|
||||||
tags
|
while (it) |node| : (it = node.next) {
|
||||||
else
|
const output = &node.data;
|
||||||
self.current_focused_tags;
|
output.arrange();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.startTransaction();
|
self.startTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,8 +162,12 @@ pub const Root = struct {
|
|||||||
// to reset the pending count to 0 and clear serials from the views
|
// to reset the pending count to 0 and clear serials from the views
|
||||||
self.pending_configures = 0;
|
self.pending_configures = 0;
|
||||||
|
|
||||||
var it = ViewStack.iterator(self.views.first, 0xFFFFFFFF);
|
// Iterate over all views of all outputs
|
||||||
while (it.next()) |view| {
|
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.
|
// Clear the serial in case this transaction is interrupting a prior one.
|
||||||
view.pending_serial = null;
|
view.pending_serial = null;
|
||||||
|
|
||||||
@ -264,6 +187,7 @@ pub const Root = struct {
|
|||||||
view.stashBuffer();
|
view.stashBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log.Debug.log(
|
Log.Debug.log(
|
||||||
"Started transaction with {} pending configures.",
|
"Started transaction with {} pending configures.",
|
||||||
@ -317,21 +241,26 @@ pub const Root = struct {
|
|||||||
// Ensure this is set to 0 to avoid entering invalid state (e.g. if called due to timeout)
|
// Ensure this is set to 0 to avoid entering invalid state (e.g. if called due to timeout)
|
||||||
self.pending_configures = 0;
|
self.pending_configures = 0;
|
||||||
|
|
||||||
|
// 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 there were pending focused tags, make them the current focus
|
||||||
if (self.pending_focused_tags) |tags| {
|
if (output.pending_focused_tags) |tags| {
|
||||||
Log.Debug.log(
|
Log.Debug.log(
|
||||||
"changing current focus: {b:0>10} to {b:0>10}",
|
"changing current focus: {b:0>10} to {b:0>10}",
|
||||||
.{ self.current_focused_tags, tags },
|
.{ output.current_focused_tags, tags },
|
||||||
);
|
);
|
||||||
self.current_focused_tags = tags;
|
output.current_focused_tags = tags;
|
||||||
self.pending_focused_tags = null;
|
output.pending_focused_tags = null;
|
||||||
|
|
||||||
self.focused_view = null;
|
self.focused_view = null;
|
||||||
self.focusNextView();
|
self.focusNextView();
|
||||||
}
|
}
|
||||||
|
|
||||||
var it = ViewStack.iterator(self.views.first, 0xFFFFFFFF);
|
var view_it = ViewStack.iterator(output.views.first, 0xFFFFFFFF);
|
||||||
while (it.next()) |view| {
|
while (view_it.next()) |view| {
|
||||||
// Ensure that all pending state is cleared
|
// Ensure that all pending state is cleared
|
||||||
view.pending_serial = null;
|
view.pending_serial = null;
|
||||||
if (view.pending_box) |state| {
|
if (view.pending_box) |state| {
|
||||||
@ -348,7 +277,7 @@ pub const Root = struct {
|
|||||||
// longer be visible, focus the next view.
|
// longer be visible, focus the next view.
|
||||||
if (self.focused_view) |focus| {
|
if (self.focused_view) |focus| {
|
||||||
if (focus == view and
|
if (focus == view and
|
||||||
view.current_tags & self.current_focused_tags == 0)
|
view.current_tags & output.current_focused_tags == 0)
|
||||||
{
|
{
|
||||||
self.focusNextView();
|
self.focusNextView();
|
||||||
}
|
}
|
||||||
@ -358,4 +287,5 @@ pub const Root = struct {
|
|||||||
view.dropStashedBuffer();
|
view.dropStashedBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -144,8 +144,7 @@ pub const Server = struct {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// toplevel surfaces are tracked and managed by the root
|
server.root.focusedOutput().addView(wlr_xdg_surface);
|
||||||
server.root.addView(wlr_xdg_surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This event is raised when the layer_shell recieves a new surface from a client.
|
/// This event is raised when the layer_shell recieves a new surface from a client.
|
||||||
|
25
src/view.zig
25
src/view.zig
@ -2,13 +2,14 @@ const std = @import("std");
|
|||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
const Box = @import("box.zig").Box;
|
const Box = @import("box.zig").Box;
|
||||||
|
const Output = @import("output.zig").Output;
|
||||||
const Root = @import("root.zig").Root;
|
const Root = @import("root.zig").Root;
|
||||||
const ViewStack = @import("view_stack.zig").ViewStack;
|
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||||
|
|
||||||
pub const View = struct {
|
pub const View = struct {
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
root: *Root,
|
output: *Output,
|
||||||
wlr_xdg_surface: *c.wlr_xdg_surface,
|
wlr_xdg_surface: *c.wlr_xdg_surface,
|
||||||
|
|
||||||
mapped: bool,
|
mapped: bool,
|
||||||
@ -31,8 +32,8 @@ pub const View = struct {
|
|||||||
// listen_request_move: c.wl_listener,
|
// listen_request_move: c.wl_listener,
|
||||||
// listen_request_resize: c.wl_listener,
|
// listen_request_resize: c.wl_listener,
|
||||||
|
|
||||||
pub fn init(self: *Self, root: *Root, wlr_xdg_surface: *c.wlr_xdg_surface, tags: u32) void {
|
pub fn init(self: *Self, output: *Output, wlr_xdg_surface: *c.wlr_xdg_surface, tags: u32) void {
|
||||||
self.root = root;
|
self.output = output;
|
||||||
self.wlr_xdg_surface = wlr_xdg_surface;
|
self.wlr_xdg_surface = wlr_xdg_surface;
|
||||||
|
|
||||||
// Inform the xdg toplevel that it is tiled.
|
// Inform the xdg toplevel that it is tiled.
|
||||||
@ -85,8 +86,8 @@ pub const View = struct {
|
|||||||
|
|
||||||
pub fn configurePending(self: *Self) void {
|
pub fn configurePending(self: *Self) void {
|
||||||
if (self.pending_box) |pending_box| {
|
if (self.pending_box) |pending_box| {
|
||||||
const border_width = self.root.server.config.border_width;
|
const border_width = self.output.root.server.config.border_width;
|
||||||
const view_padding = self.root.server.config.view_padding;
|
const view_padding = self.output.root.server.config.view_padding;
|
||||||
self.pending_serial = c.wlr_xdg_toplevel_set_size(
|
self.pending_serial = c.wlr_xdg_toplevel_set_size(
|
||||||
self.wlr_xdg_surface,
|
self.wlr_xdg_surface,
|
||||||
pending_box.width - border_width * 2 - view_padding * 2,
|
pending_box.width - border_width * 2 - view_padding * 2,
|
||||||
@ -132,12 +133,12 @@ pub const View = struct {
|
|||||||
const view = @fieldParentPtr(View, "listen_map", listener.?);
|
const view = @fieldParentPtr(View, "listen_map", listener.?);
|
||||||
view.mapped = true;
|
view.mapped = true;
|
||||||
view.focus(view.wlr_xdg_surface.surface);
|
view.focus(view.wlr_xdg_surface.surface);
|
||||||
view.root.arrange();
|
view.output.root.arrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const view = @fieldParentPtr(View, "listen_unmap", listener.?);
|
const view = @fieldParentPtr(View, "listen_unmap", listener.?);
|
||||||
const root = view.root;
|
const root = view.output.root;
|
||||||
view.mapped = false;
|
view.mapped = false;
|
||||||
|
|
||||||
if (root.focused_view) |current_focus| {
|
if (root.focused_view) |current_focus| {
|
||||||
@ -153,18 +154,18 @@ pub const View = struct {
|
|||||||
|
|
||||||
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const view = @fieldParentPtr(View, "listen_destroy", listener.?);
|
const view = @fieldParentPtr(View, "listen_destroy", listener.?);
|
||||||
const root = view.root;
|
const output = view.output;
|
||||||
|
|
||||||
const node = @fieldParentPtr(ViewStack.Node, "view", view);
|
const node = @fieldParentPtr(ViewStack.Node, "view", view);
|
||||||
root.views.remove(node);
|
output.views.remove(node);
|
||||||
root.server.allocator.destroy(node);
|
output.root.server.allocator.destroy(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const view = @fieldParentPtr(View, "listen_commit", listener.?);
|
const view = @fieldParentPtr(View, "listen_commit", listener.?);
|
||||||
if (view.pending_serial) |s| {
|
if (view.pending_serial) |s| {
|
||||||
if (s == view.wlr_xdg_surface.configure_serial) {
|
if (s == view.wlr_xdg_surface.configure_serial) {
|
||||||
view.root.notifyConfigured();
|
view.output.root.notifyConfigured();
|
||||||
view.pending_serial = null;
|
view.pending_serial = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,7 +181,7 @@ pub const View = struct {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
fn focus(self: *Self, surface: *c.wlr_surface) void {
|
fn focus(self: *Self, surface: *c.wlr_surface) void {
|
||||||
const root = self.root;
|
const root = self.output.root;
|
||||||
const wlr_seat = root.server.seat.wlr_seat;
|
const wlr_seat = root.server.seat.wlr_seat;
|
||||||
const prev_surface = wlr_seat.keyboard_state.focused_surface;
|
const prev_surface = wlr_seat.keyboard_state.focused_surface;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user