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