From 0065bae0d43959ed973092b6c50dfa86c6b0977d Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Sat, 25 Nov 2023 13:46:48 +0100 Subject: [PATCH] gtk: get closing of tabs working again (closing windows still broken) --- src/apprt/gtk/Split.zig | 14 +++++++++++++- src/apprt/gtk/Surface.zig | 12 +++++------- src/apprt/gtk/Tab.zig | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/apprt/gtk/Split.zig b/src/apprt/gtk/Split.zig index ab7580f17..9d21eb7a9 100644 --- a/src/apprt/gtk/Split.zig +++ b/src/apprt/gtk/Split.zig @@ -90,6 +90,18 @@ pub fn init( surface.grabFocus(); } +pub fn destroy(self: *Split) void { + const window = self.container.window() orelse return; + + 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); +} + /// Remove the top left child. pub fn removeTopLeft(self: *Split) void { self.removeChild(self.top_left, self.bottom_right); @@ -120,7 +132,7 @@ inline fn removeChild(self: *Split, remove: Surface.Container.Elem, keep: Surfac self.container.replace(keep); // TODO: is this correct? - remove.shutdown(); + remove.destroy(); window.app.core_app.alloc.destroy(self); } diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 7695224cd..1d8721f07 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -79,12 +79,10 @@ pub const Container = union(enum) { }; } - pub fn shutdown(self: Elem) void { + pub fn destroy(self: Elem) void { switch (self) { - .surface => |s| s.shutdown(), - .split => { - @panic("TODO: shutdownsplit"); - }, + .surface => |s| s.unref(), + .split => |s| s.destroy(), } } @@ -416,9 +414,9 @@ pub fn deinit(self: *Surface) void { if (self.cursor) |cursor| c.g_object_unref(cursor); } -// shutdown removes the long-held reference to the gl_area and kicks off the +// unref removes the long-held reference to the gl_area and kicks off the // deinit/destroy process for this surface. -pub fn shutdown(self: *Surface) void { +pub fn unref(self: *Surface) void { c.g_object_unref(self.gl_area); } diff --git a/src/apprt/gtk/Tab.zig b/src/apprt/gtk/Tab.zig index afa3383b1..fc16c8e37 100644 --- a/src/apprt/gtk/Tab.zig +++ b/src/apprt/gtk/Tab.zig @@ -142,7 +142,7 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void { /// Deinits tab by deiniting child elem. pub fn deinit(self: *Tab) void { - self.elem.shutdown(); + self.elem.destroy(); } // TODO: move this