code: Refactor Root.addOutput

This commit is contained in:
Marten Ringwelski 2020-11-16 09:11:08 +01:00 committed by Isaac Freund
parent 0dd8197f03
commit fc549d6249
2 changed files with 16 additions and 11 deletions

View file

@ -24,6 +24,7 @@ const c = @import("c.zig");
const log = @import("log.zig"); const log = @import("log.zig");
const util = @import("util.zig"); const util = @import("util.zig");
const Output = @import("Output.zig");
const Root = @import("Root.zig"); const Root = @import("Root.zig");
const Server = @import("Server.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 self = @fieldParentPtr(Self, "listen_new_output", listener.?);
const wlr_output = util.voidCast(c.wlr_output, data.?); const wlr_output = util.voidCast(c.wlr_output, data.?);
log.debug(.output_manager, "new output {}", .{wlr_output.name}); 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 { fn handleOutputPowerManagementSetMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {

View file

@ -91,22 +91,16 @@ pub fn deinit(self: *Self) void {
if (c.wl_event_source_remove(self.transaction_timer) < 0) unreachable; if (c.wl_event_source_remove(self.transaction_timer) < 0) unreachable;
} }
pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void { /// Adds the output in node.data to self.outputs
const node = util.gpa.create(std.TailQueue(Output).Node) catch { /// The Output in node.data must be initalized
c.wlr_output_destroy(wlr_output); pub fn addOutput(self: *Self, node: *std.TailQueue(Output).Node) void {
return;
};
node.data.init(self, wlr_output) catch {
c.wlr_output_destroy(wlr_output);
return;
};
self.outputs.append(node); self.outputs.append(node);
// Add the new output to the layout. The add_auto function arranges outputs // 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 // from left-to-right in the order they appear. A more sophisticated
// compositor would let the user configure the arrangement of outputs in the // compositor would let the user configure the arrangement of outputs in the
// layout. This automatically creates an output global on the wl_display. // 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 // if we previously had no real outputs, move focus from the noop output
// to the new one. // to the new one.