root: simplify noop output handling

Instead of removing the listeners of the noop output early, simply never
add them.
This commit is contained in:
Isaac Freund 2021-06-14 21:29:23 +00:00
parent 1fd8d4d828
commit 20eb94317a
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
2 changed files with 27 additions and 39 deletions

View file

@ -95,6 +95,8 @@ mode: wl.Listener(*wlr.Output) = wl.Listener(*wlr.Output).init(handleMode),
frame: wl.Listener(*wlr.OutputDamage) = wl.Listener(*wlr.OutputDamage).init(handleFrame), frame: wl.Listener(*wlr.OutputDamage) = wl.Listener(*wlr.OutputDamage).init(handleFrame),
pub fn init(self: *Self, wlr_output: *wlr.Output) !void { pub fn init(self: *Self, wlr_output: *wlr.Output) !void {
assert(!wlr_output.isNoop());
// Some backends don't have modes. DRM+KMS does, and we need to set a mode // Some backends don't have modes. DRM+KMS does, and we need to set a mode
// before we can use the output. The mode is a tuple of (width, height, // before we can use the output. The mode is a tuple of (width, height,
// refresh rate), and each monitor supports only a specific set of modes. We // refresh rate), and each monitor supports only a specific set of modes. We
@ -119,15 +121,6 @@ pub fn init(self: *Self, wlr_output: *wlr.Output) !void {
self.damage.events.frame.add(&self.frame); self.damage.events.frame.add(&self.frame);
if (wlr_output.isNoop()) {
// A noop output is always 0 x 0
self.usable_box = .{
.x = 0,
.y = 0,
.width = 0,
.height = 0,
};
} else {
// Ensure that a cursor image at the output's scale factor is loaded // Ensure that a cursor image at the output's scale factor is loaded
// for each seat. // for each seat.
var it = server.input_manager.seats.first; var it = server.input_manager.seats.first;
@ -146,7 +139,6 @@ pub fn init(self: *Self, wlr_output: *wlr.Output) !void {
}; };
self.setTitle(); self.setTitle();
}
} }
pub fn getLayer(self: *Self, layer: zwlr.LayerShellV1.Layer) *std.TailQueue(LayerSurface) { pub fn getLayer(self: *Self, layer: zwlr.LayerShellV1.Layer) *std.TailQueue(LayerSurface) {

View file

@ -94,16 +94,20 @@ pub fn init(self: *Self) !void {
const transaction_timer = try event_loop.addTimer(*Self, handleTransactionTimeout, self); const transaction_timer = try event_loop.addTimer(*Self, handleTransactionTimeout, self);
errdefer transaction_timer.remove(); errdefer transaction_timer.remove();
const noop_wlr_output = try server.noop_backend.noopAddOutput();
self.* = .{ self.* = .{
.output_layout = output_layout, .output_layout = output_layout,
.output_manager = try wlr.OutputManagerV1.create(server.wl_server), .output_manager = try wlr.OutputManagerV1.create(server.wl_server),
.power_manager = try wlr.OutputPowerManagerV1.create(server.wl_server), .power_manager = try wlr.OutputPowerManagerV1.create(server.wl_server),
.transaction_timer = transaction_timer, .transaction_timer = transaction_timer,
.noop_output = undefined, .noop_output = .{
.wlr_output = noop_wlr_output,
// TODO: find a good way to not create a wlr.OutputDamage for the noop output
.damage = try wlr.OutputDamage.create(noop_wlr_output),
.usable_box = .{ .x = 0, .y = 0, .width = 0, .height = 0 },
},
}; };
noop_wlr_output.data = @ptrToInt(&self.noop_output);
const noop_wlr_output = try server.noop_backend.noopAddOutput();
try self.noop_output.init(noop_wlr_output);
server.backend.events.new_output.add(&self.new_output); server.backend.events.new_output.add(&self.new_output);
self.output_manager.events.apply.add(&self.manager_apply); self.output_manager.events.apply.add(&self.manager_apply);
@ -113,14 +117,6 @@ pub fn init(self: *Self) !void {
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
// Need to remove these listeners as the noop output will be destroyed with
// the noop backend triggering the destroy event. However,
// Output.handleDestroy is not intended to handle the noop output being
// destroyed.
self.noop_output.destroy.link.remove();
self.noop_output.frame.link.remove();
self.noop_output.mode.link.remove();
self.output_layout.destroy(); self.output_layout.destroy();
self.transaction_timer.remove(); self.transaction_timer.remove();
} }