From cd005e15f8bcb6852b35fd3d89248e72611a5d5f Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 21 Jan 2021 10:43:18 +0100 Subject: [PATCH] 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. --- river/Option.zig | 1 + river/OptionsManager.zig | 7 +++++++ river/Output.zig | 2 ++ 3 files changed, 10 insertions(+) diff --git a/river/Option.zig b/river/Option.zig index 1008d5f..a6366bc 100644 --- a/river/Option.zig +++ b/river/Option.zig @@ -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); } diff --git a/river/OptionsManager.zig b/river/OptionsManager.zig index a3e2876..9d895dd 100644 --- a/river/OptionsManager.zig +++ b/river/OptionsManager.zig @@ -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(); diff --git a/river/Output.zig b/river/Output.zig index c8cd6c3..1b599ef 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -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);