gtk: wire up close-tab button

This commit is contained in:
Thorsten Ball
2023-10-20 09:16:11 +02:00
committed by Mitchell Hashimoto
parent 98a5016598
commit 8afcce666a
2 changed files with 9 additions and 16 deletions

View File

@ -181,7 +181,6 @@ pub fn setChild(self: *Tab, newChild: Child) void {
fn gtkTabCloseClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void { fn gtkTabCloseClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
const tab: *Tab = @ptrCast(@alignCast(ud)); const tab: *Tab = @ptrCast(@alignCast(ud));
_ = tab; const window = tab.window;
// TODO: Fix tab closing logic window.closeTab(tab);
log.info("tab close click\n", .{});
} }

View File

@ -219,13 +219,11 @@ pub fn removeTab(self: *Window, tab: *Tab) !void {
/// Close the tab for the given notebook page. This will automatically /// Close the tab for the given notebook page. This will automatically
/// handle closing the window if there are no more tabs. /// handle closing the window if there are no more tabs.
fn closeTab(self: *Window, page: *c.GtkNotebookPage) void { pub fn closeTab(self: *Window, tab: *Tab) void {
const page = c.gtk_notebook_get_page(self.notebook, @ptrCast(tab.box)) orelse return;
// Find page and tab which we're closing // Find page and tab which we're closing
const page_idx = getNotebookPageIndex(page); const page_idx = getNotebookPageIndex(page);
const page_widget = c.gtk_notebook_get_nth_page(self.notebook, page_idx);
const tab: *Tab = @ptrCast(@alignCast(
c.g_object_get_data(@ptrCast(page_widget), Tab.GHOSTTY_TAB) orelse return,
));
// Remove the tab from our stored tabs. // Remove the tab from our stored tabs.
self.removeTab(tab) catch |err| { self.removeTab(tab) catch |err| {
@ -233,7 +231,6 @@ fn closeTab(self: *Window, page: *c.GtkNotebookPage) void {
return; return;
}; };
// Now remove the page
c.gtk_notebook_remove_page(self.notebook, page_idx); c.gtk_notebook_remove_page(self.notebook, page_idx);
const remaining = c.gtk_notebook_get_n_pages(self.notebook); const remaining = c.gtk_notebook_get_n_pages(self.notebook);
@ -258,17 +255,11 @@ pub fn closeSurface(self: *Window, surface: *Surface) void {
const alloc = surface.app.core_app.alloc; const alloc = surface.app.core_app.alloc;
switch (surface.parent) { switch (surface.parent) {
.tab => { .tab => |tab| self.closeTab(tab),
const page = c.gtk_notebook_get_page(self.notebook, @ptrCast(surface.tab.box)) orelse return;
self.closeTab(page);
},
.paned => |paned_tuple| { .paned => |paned_tuple| {
const paned = paned_tuple[0]; const paned = paned_tuple[0];
const position = paned_tuple[1]; const position = paned_tuple[1];
// TODO: Do we need this?
surface.setParent(.none);
const sibling = switch (position) { const sibling = switch (position) {
.start => .{ .start => .{
switch (paned.child2) { switch (paned.child2) {
@ -295,6 +286,9 @@ pub fn closeSurface(self: *Window, surface: *Surface) void {
_ = c.g_object_ref(sibling_object); _ = c.g_object_ref(sibling_object);
defer c.g_object_unref(sibling_object); defer c.g_object_unref(sibling_object);
// Remove reference on the surface we're closing
surface.setParent(.none);
// Remove children and kill Paned. // Remove children and kill Paned.
paned.removeChildren(); paned.removeChildren();
defer alloc.destroy(paned); defer alloc.destroy(paned);