diff --git a/src/apprt/gtk/Split.zig b/src/apprt/gtk/Split.zig index 9d21eb7a9..792968e4a 100644 --- a/src/apprt/gtk/Split.zig +++ b/src/apprt/gtk/Split.zig @@ -90,16 +90,11 @@ pub fn init( surface.grabFocus(); } -pub fn destroy(self: *Split) void { - const window = self.container.window() orelse return; +pub fn destroy(self: *Split, alloc: Allocator) void { + self.top_left.deinit(alloc); + self.bottom_right.deinit(alloc); - self.top_left.destroy(); - self.bottom_right.destroy(); - - self.removeChildren(); - - // TODO: this is the same as in removeChild? - window.app.core_app.alloc.destroy(self); + alloc.destroy(self); } /// Remove the top left child. @@ -115,6 +110,7 @@ pub fn removeBottomRight(self: *Split) void { // TODO: Is this Zig-y? inline fn removeChild(self: *Split, remove: Surface.Container.Elem, keep: Surface.Container.Elem) void { const window = self.container.window() orelse return; + const alloc = window.app.core_app.alloc; // TODO: Grab focus @@ -132,8 +128,8 @@ inline fn removeChild(self: *Split, remove: Surface.Container.Elem, keep: Surfac self.container.replace(keep); // TODO: is this correct? - remove.destroy(); - window.app.core_app.alloc.destroy(self); + remove.deinit(alloc); + alloc.destroy(self); } // TODO: ehhhhhh diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 1d8721f07..21fe86a37 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -79,10 +79,10 @@ pub const Container = union(enum) { }; } - pub fn destroy(self: Elem) void { + pub fn deinit(self: Elem, alloc: Allocator) void { switch (self) { .surface => |s| s.unref(), - .split => |s| s.destroy(), + .split => |s| s.destroy(alloc), } } diff --git a/src/apprt/gtk/Tab.zig b/src/apprt/gtk/Tab.zig index fc16c8e37..867956d0e 100644 --- a/src/apprt/gtk/Tab.zig +++ b/src/apprt/gtk/Tab.zig @@ -141,15 +141,13 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void { } /// Deinits tab by deiniting child elem. -pub fn deinit(self: *Tab) void { - self.elem.destroy(); +pub fn deinit(self: *Tab, alloc: Allocator) void { + self.elem.deinit(alloc); } // TODO: move this /// Replace the surface element that this tab is showing. pub fn replaceElem(self: *Tab, elem: Surface.Container.Elem) void { - // _ = c.g_object_ref_sink(self.elem.widget()); - // Remove our previous widget c.gtk_box_remove(self.box, self.elem.widget()); diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index 7129599d6..923f23c53 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -193,7 +193,7 @@ fn initActions(self: *Window) void { pub fn deinit(self: *Window) void { self.icon.deinit(self.app); for (self.tabs.items) |tab| { - tab.deinit(); + tab.deinit(self.app.core_app.alloc); self.app.core_app.alloc.destroy(tab); } self.tabs.deinit(self.app.core_app.alloc); @@ -219,7 +219,7 @@ pub fn removeTab(self: *Window, tab: *Tab) !void { if (tab_idx) |idx| _ = self.tabs.orderedRemove(idx) else return error.TabNotFound; // Deallocate the tab - tab.deinit(); + tab.deinit(self.app.core_app.alloc); self.app.core_app.alloc.destroy(tab); }