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);