Make Root a toplevel struct
This commit is contained in:
parent
9ea26d2a30
commit
a73343c92f
@ -8,7 +8,7 @@ const render = @import("render.zig");
|
||||
const Box = @import("box.zig");
|
||||
const LayerSurface = @import("layer_surface.zig");
|
||||
const Log = @import("log.zig").Log;
|
||||
const Root = @import("root.zig").Root;
|
||||
const Root = @import("root.zig");
|
||||
const View = @import("view.zig");
|
||||
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||
|
||||
|
92
src/root.zig
92
src/root.zig
@ -1,36 +1,33 @@
|
||||
const std = @import("std");
|
||||
const c = @import("c.zig");
|
||||
const util = @import("util.zig");
|
||||
const Self = @This();
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("c.zig");
|
||||
|
||||
const Box = @import("box.zig").Box;
|
||||
const Log = @import("log.zig").Log;
|
||||
const Output = @import("output.zig");
|
||||
const Server = @import("server.zig");
|
||||
const Seat = @import("seat.zig").Seat;
|
||||
const View = @import("view.zig");
|
||||
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||
|
||||
/// Responsible for all windowing operations
|
||||
pub const Root = struct {
|
||||
const Self = @This();
|
||||
server: *Server,
|
||||
|
||||
server: *Server,
|
||||
wlr_output_layout: *c.wlr_output_layout,
|
||||
outputs: std.TailQueue(Output),
|
||||
|
||||
wlr_output_layout: *c.wlr_output_layout,
|
||||
outputs: std.TailQueue(Output),
|
||||
/// This output is used internally when no real outputs are available.
|
||||
/// It is not advertised to clients.
|
||||
noop_output: Output,
|
||||
|
||||
/// This output is used internally when no real outputs are available.
|
||||
/// It is not advertised to clients.
|
||||
noop_output: Output,
|
||||
/// Number of pending configures sent in the current transaction.
|
||||
/// A value of 0 means there is no current transaction.
|
||||
pending_configures: u32,
|
||||
|
||||
/// Number of pending configures sent in the current transaction.
|
||||
/// A value of 0 means there is no current transaction.
|
||||
pending_configures: u32,
|
||||
/// Handles timeout of transactions
|
||||
transaction_timer: ?*c.wl_event_source,
|
||||
|
||||
/// Handles timeout of transactions
|
||||
transaction_timer: ?*c.wl_event_source,
|
||||
|
||||
pub fn init(self: *Self, server: *Server) !void {
|
||||
pub fn init(self: *Self, server: *Server) !void {
|
||||
self.server = server;
|
||||
|
||||
// Create an output layout, which a wlroots utility for working with an
|
||||
@ -48,17 +45,17 @@ pub const Root = struct {
|
||||
self.pending_configures = 0;
|
||||
|
||||
self.transaction_timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
pub fn deinit(self: *Self) void {
|
||||
while (self.outputs.pop()) |output_node| {
|
||||
output_node.data.deinit();
|
||||
self.server.allocator.destroy(output_node);
|
||||
}
|
||||
c.wlr_output_layout_destroy(self.wlr_output_layout);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void {
|
||||
pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void {
|
||||
// TODO: Handle failure
|
||||
const node = self.outputs.allocateNode(self.server.allocator) catch unreachable;
|
||||
node.data.init(self, wlr_output) catch unreachable;
|
||||
@ -73,28 +70,28 @@ pub const Root = struct {
|
||||
seat_node.data.focused_output = &self.outputs.first.?.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear the current focus.
|
||||
pub fn clearFocus(self: *Self) void {
|
||||
/// Clear the current focus.
|
||||
pub fn clearFocus(self: *Self) void {
|
||||
if (self.focused_view) |view| {
|
||||
_ = c.wlr_xdg_toplevel_set_activated(view.wlr_xdg_surface, false);
|
||||
}
|
||||
self.focused_view = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Arrange all views on all outputs and then start a transaction.
|
||||
pub fn arrange(self: *Self) void {
|
||||
/// Arrange all views on all outputs and then start a transaction.
|
||||
pub fn arrange(self: *Self) void {
|
||||
var it = self.outputs.first;
|
||||
while (it) |output_node| : (it = output_node.next) {
|
||||
output_node.data.arrangeViews();
|
||||
}
|
||||
self.startTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
/// Initiate an atomic change to the layout. This change will not be
|
||||
/// applied until all affected clients ack a configure and commit a buffer.
|
||||
fn startTransaction(self: *Self) void {
|
||||
/// Initiate an atomic change to the layout. This change will not be
|
||||
/// applied until all affected clients ack a configure and commit a buffer.
|
||||
fn startTransaction(self: *Self) void {
|
||||
// If a new transaction is started while another is in progress, we need
|
||||
// to reset the pending count to 0 and clear serials from the views
|
||||
self.pending_configures = 0;
|
||||
@ -147,19 +144,19 @@ pub const Root = struct {
|
||||
} else {
|
||||
self.commitTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handleTimeout(data: ?*c_void) callconv(.C) c_int {
|
||||
const root = @ptrCast(*Root, @alignCast(@alignOf(*Root), data));
|
||||
fn handleTimeout(data: ?*c_void) callconv(.C) c_int {
|
||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), data));
|
||||
|
||||
Log.Error.log("Transaction timed out. Some imperfect frames may be shown.", .{});
|
||||
|
||||
root.commitTransaction();
|
||||
self.commitTransaction();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notifyConfigured(self: *Self) void {
|
||||
pub fn notifyConfigured(self: *Self) void {
|
||||
self.pending_configures -= 1;
|
||||
if (self.pending_configures == 0) {
|
||||
// Stop the timer, as we didn't timeout
|
||||
@ -168,13 +165,13 @@ pub const Root = struct {
|
||||
}
|
||||
self.commitTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply the pending state and drop stashed buffers. This means that
|
||||
/// the next frame drawn will be the post-transaction state of the
|
||||
/// layout. Should only be called after all clients have configured for
|
||||
/// the new layout. If called early imperfect frames may be drawn.
|
||||
fn commitTransaction(self: *Self) void {
|
||||
/// Apply the pending state and drop stashed buffers. This means that
|
||||
/// the next frame drawn will be the post-transaction state of the
|
||||
/// layout. Should only be called after all clients have configured for
|
||||
/// the new layout. If called early imperfect frames may be drawn.
|
||||
fn commitTransaction(self: *Self) void {
|
||||
// TODO: apply damage properly
|
||||
|
||||
// Ensure this is set to 0 to avoid entering invalid state (e.g. if called due to timeout)
|
||||
@ -220,5 +217,4 @@ pub const Root = struct {
|
||||
while (it) |seat_node| : (it = seat_node.next) {
|
||||
seat_node.data.focus(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ const DecorationManager = @import("decoration_manager.zig");
|
||||
const InputManager = @import("input_manager.zig");
|
||||
const Log = @import("log.zig").Log;
|
||||
const Output = @import("output.zig");
|
||||
const Root = @import("root.zig").Root;
|
||||
const Root = @import("root.zig");
|
||||
const View = @import("view.zig");
|
||||
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||
|
||||
|
@ -7,7 +7,7 @@ const c = @import("c.zig");
|
||||
const Box = @import("box.zig");
|
||||
const Log = @import("log.zig").Log;
|
||||
const Output = @import("output.zig");
|
||||
const Root = @import("root.zig").Root;
|
||||
const Root = @import("root.zig");
|
||||
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||
const XdgToplevel = @import("xdg_toplevel.zig");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user