From fc549d6249d3708bc5729b94e572685b2190c8f3 Mon Sep 17 00:00:00 2001 From: Marten Ringwelski Date: Mon, 16 Nov 2020 09:11:08 +0100 Subject: [PATCH] code: Refactor Root.addOutput --- river/OutputManager.zig | 13 ++++++++++++- river/Root.zig | 14 ++++---------- 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.