WIP: gtk: handle split surfaces when closing tab/window

This commit is contained in:
Thorsten Ball
2023-10-26 20:24:32 +02:00
committed by Mitchell Hashimoto
parent a7717289eb
commit dc0f6e3a5b
3 changed files with 37 additions and 1 deletions

View File

@ -219,3 +219,21 @@ fn addChild2(self: *Paned, child: Child) void {
self.child2 = child;
child.setParent(.{ .paned = .{ self, .end } });
}
pub fn deinit(self: *Paned, alloc: Allocator) void {
switch (self.child1) {
.none, .surface => {},
.paned => |paned| {
paned.deinit(alloc);
alloc.destroy(paned);
},
}
switch (self.child2) {
.none, .surface => {},
.paned => |paned| {
paned.deinit(alloc);
alloc.destroy(paned);
},
}
}

View File

@ -163,3 +163,17 @@ fn gtkTabCloseClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
const window = tab.window;
window.closeTab(tab);
}
pub fn close(self: *Tab) void {
switch (self.child) {
.none => return,
.surface => {
// TODO: I'm not 100% but I don't think we have to do something
return;
},
.paned => |paned| {
paned.deinit(self.window.app.core_app.alloc);
self.window.app.core_app.alloc.destroy(paned);
},
}
}

View File

@ -189,7 +189,10 @@ fn initActions(self: *Window) void {
pub fn deinit(self: *Window) void {
self.icon.deinit(self.app);
for (self.tabs.items) |tab| self.app.core_app.alloc.destroy(tab);
for (self.tabs.items) |tab| {
tab.close();
self.app.core_app.alloc.destroy(tab);
}
self.tabs.deinit(self.app.core_app.alloc);
}
@ -214,6 +217,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.close();
self.app.core_app.alloc.destroy(tab);
}