apprt/gtk: add comments, rename some funcs

This commit is contained in:
Mitchell Hashimoto
2023-12-01 09:07:37 -08:00
parent e40b79906e
commit 14ef6fb2f9
3 changed files with 13 additions and 10 deletions

View File

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

View File

@ -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(),
}

View File

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