river-options: free options of destroyed outputs

This is done when river's internal Output struct is destroyed, not when
the advertised wl_output global is removed. This means that options will
persist when an output is disabled and re-enabled.
This commit is contained in:
Isaac Freund 2021-01-21 10:43:18 +01:00
parent 18bab45d4c
commit cd005e15f8
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
3 changed files with 10 additions and 0 deletions

View file

@ -67,6 +67,7 @@ pub fn destroy(self: *Self) void {
var it = self.handles.safeIterator(.forward);
while (it.next()) |handle| handle.destroy();
if (self.value == .string) if (self.value.string) |s| util.gpa.free(mem.span(s));
self.link.remove();
util.gpa.destroy(self);
}

View file

@ -44,6 +44,13 @@ pub fn init(self: *Self, server: *Server) !void {
server.wl_server.addDestroyListener(&self.server_destroy);
}
pub fn handleOutputDestroy(self: *Self, output: *Output) void {
var it = self.options.safeIterator(.forward);
while (it.next()) |option| {
if (option.output == output) option.destroy();
}
}
fn handleServerDestroy(listener: *wl.Listener(*wl.Server), wl_server: *wl.Server) void {
const self = @fieldParentPtr(Self, "server_destroy", listener);
self.global.destroy();

View file

@ -487,6 +487,8 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) v
log.debug(.server, "output '{}' destroyed", .{self.wlr_output.name});
root.server.options_manager.handleOutputDestroy(self);
// Remove the destroyed output from root if it wasn't already removed
root.removeOutput(self);