aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarten Ringwelski <git@maringuu.de>2020-11-16 09:11:08 +0100
committerIsaac Freund <ifreund@ifreund.xyz>2020-12-07 11:47:55 +0100
commitfc549d6249d3708bc5729b94e572685b2190c8f3 (patch)
tree0e6dc67b3f286d7a2352a5840a9b3c56785f4b39
parent0dd8197f0340706705aca0ee3d8857e038431203 (diff)
downloadriver-fc549d6249d3708bc5729b94e572685b2190c8f3.tar.gz
river-fc549d6249d3708bc5729b94e572685b2190c8f3.tar.xz
code: Refactor Root.addOutput
-rw-r--r--river/OutputManager.zig13
-rw-r--r--river/Root.zig14
2 files changed, 16 insertions, 11 deletions
diff --git a/river/OutputManager.zig b/river/OutputManager.zig
index c11acd9..4415352 100644
--- a/river/OutputManager.zig
+++ b/river/OutputManager.zig
@@ -24,6 +24,7 @@ const c = @import("c.zig");
const log = @import("log.zig");
const util = @import("util.zig");
+const Output = @import("Output.zig");
const Root = @import("Root.zig");
const Server = @import("Server.zig");
@@ -56,7 +57,17 @@ fn handleNewOutput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void
const self = @fieldParentPtr(Self, "listen_new_output", listener.?);
const wlr_output = util.voidCast(c.wlr_output, data.?);
log.debug(.output_manager, "new output {}", .{wlr_output.name});
- self.root.addOutput(wlr_output);
+
+ const node = util.gpa.create(std.TailQueue(Output).Node) catch {
+ c.wlr_output_destroy(wlr_output);
+ return;
+ };
+ node.data.init(self.root, wlr_output) catch {
+ c.wlr_output_destroy(wlr_output);
+ return;
+ };
+
+ self.root.addOutput(node);
}
fn handleOutputPowerManagementSetMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
diff --git a/river/Root.zig b/river/Root.zig
index 4029992..0c6f6e8 100644
--- a/river/Root.zig
+++ b/river/Root.zig
@@ -91,22 +91,16 @@ pub fn deinit(self: *Self) void {
if (c.wl_event_source_remove(self.transaction_timer) < 0) unreachable;
}
-pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void {
- const node = util.gpa.create(std.TailQueue(Output).Node) catch {
- c.wlr_output_destroy(wlr_output);
- return;
- };
- node.data.init(self, wlr_output) catch {
- c.wlr_output_destroy(wlr_output);
- return;
- };
+/// Adds the output in node.data to self.outputs
+/// The Output in node.data must be initalized
+pub fn addOutput(self: *Self, node: *std.TailQueue(Output).Node) void {
self.outputs.append(node);
// Add the new output to the layout. The add_auto function arranges outputs
// from left-to-right in the order they appear. A more sophisticated
// compositor would let the user configure the arrangement of outputs in the
// layout. This automatically creates an output global on the wl_display.
- c.wlr_output_layout_add_auto(self.wlr_output_layout, wlr_output);
+ c.wlr_output_layout_add_auto(self.wlr_output_layout, node.data.wlr_output);
// if we previously had no real outputs, move focus from the noop output
// to the new one.