apprt/gtk: closing tabs works again

This commit is contained in:
Mitchell Hashimoto
2023-11-02 11:15:25 -07:00
parent cdd76a3b0b
commit 06b40a8b89
2 changed files with 27 additions and 8 deletions

View File

@ -121,6 +121,17 @@ pub const Container = union(enum) {
}, },
} }
} }
/// Remove ourselves from the container. This is used by
/// children to effectively notify they're containing that
/// all children at this level are exiting.
pub fn remove(self: Container) void {
switch (self) {
.none => {},
.tab_ => |t| t.closeElem(),
else => @panic("TOOD"),
}
}
}; };
/// Whether the surface has been realized or not yet. When a surface is /// Whether the surface has been realized or not yet. When a surface is
@ -388,14 +399,16 @@ pub fn redraw(self: *Surface) void {
/// Close this surface. /// Close this surface.
pub fn close(self: *Surface, processActive: bool) void { pub fn close(self: *Surface, processActive: bool) void {
// If we are not currently in a window, then we don't need to do any // If we're not part of a window hierarchy, we never confirm
// cleanup. If we are in a window, we need to potentially confirm, // so we can just directly remove ourselves and exit.
// remove ourselves from the view hierarchy, etc. const window = self.container.window() orelse {
const window = self.container.window() orelse return; self.container.remove();
return;
};
// If we have no process active we can just exit immediately.
if (!processActive) { if (!processActive) {
// TODO: change to container doing this directly self.container.remove();
window.closeSurface(self);
return; return;
} }
@ -1472,8 +1485,7 @@ fn gtkCloseConfirmation(
c.gtk_window_destroy(@ptrCast(alert)); c.gtk_window_destroy(@ptrCast(alert));
if (response == c.GTK_RESPONSE_YES) { if (response == c.GTK_RESPONSE_YES) {
const self = userdataSelf(ud.?); const self = userdataSelf(ud.?);
const window = self.container.window() orelse return; self.container.remove();
window.closeSurface(self);
} }
} }

View File

@ -178,6 +178,13 @@ pub fn replaceElem(self: *Tab, elem: Surface.Container.Elem) void {
self.elem = elem; 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 {
self.window.closeTab(self);
}
/// Sets child to given child and sets parent on child. /// Sets child to given child and sets parent on child.
pub fn setChild(self: *Tab, child: Child) void { pub fn setChild(self: *Tab, child: Child) void {
const widget = child.widget() orelse return; const widget = child.widget() orelse return;