From 14ef6fb2f9e0db71a4012b4a1830ccc5519f2541 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 1 Dec 2023 09:07:37 -0800 Subject: [PATCH] apprt/gtk: add comments, rename some funcs --- src/apprt/gtk/Split.zig | 13 +++++++++---- src/apprt/gtk/Surface.zig | 4 ++-- src/apprt/gtk/Tab.zig | 6 ++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/apprt/gtk/Split.zig b/src/apprt/gtk/Split.zig index fce3f74ed..01562bcc5 100644 --- a/src/apprt/gtk/Split.zig +++ b/src/apprt/gtk/Split.zig @@ -47,7 +47,7 @@ pub fn init( sibling: *Surface, direction: input.SplitDirection, ) !void { - // Create the new child surface + // Create the new child surface for the other direction. const alloc = sibling.app.core_app.alloc; var surface = try Surface.create(alloc, sibling.app, .{ .parent = &sibling.core_surface, @@ -97,7 +97,8 @@ pub fn destroy(self: *Split, alloc: Allocator) void { self.top_left.deinit(alloc); self.bottom_right.deinit(alloc); - // Clean up our GTK reference. + // Clean up our GTK reference. This will trigger all the destroy callbacks + // that are necessary for the surfaces to clean up. c.g_object_unref(self.paned); alloc.destroy(self); @@ -114,7 +115,11 @@ 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 { +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; @@ -128,7 +133,7 @@ inline fn removeChild(self: *Split, remove: Surface.Container.Elem, keep: Surfac // Grab focus of the left-over side keep.grabFocus(); - // TODO: is this correct? + // When a child is removed we are no longer a split, so destroy ourself remove.deinit(alloc); alloc.destroy(self); } diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index dfffdef0a..dfcf663bf 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -147,12 +147,12 @@ pub const Container = union(enum) { } /// Remove ourselves from the container. This is used by - /// children to effectively notify they're containing that + /// children to effectively notify they're container that /// all children at this level are exiting. pub fn remove(self: Container) void { switch (self) { .none => {}, - .tab_ => |t| t.closeElem(), + .tab_ => |t| t.remove(), .split_tl => self.split().?.removeTopLeft(), .split_br => self.split().?.removeBottomRight(), } diff --git a/src/apprt/gtk/Tab.zig b/src/apprt/gtk/Tab.zig index e6a417792..fff5b9519 100644 --- a/src/apprt/gtk/Tab.zig +++ b/src/apprt/gtk/Tab.zig @@ -166,10 +166,8 @@ pub fn replaceElem(self: *Tab, elem: Surface.Container.Elem) void { self.elem = elem; } -// TODO: move this -/// The surface element is closing. If we're the direct parent -/// then that means our tab is also closing. -pub fn closeElem(self: *Tab) void { +/// Remove this tab from the window. +pub fn remove(self: *Tab) void { self.window.closeTab(self); }