mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
gtk: restore detachable-tabs feature after adding splits
This commit is contained in:

committed by
Mitchell Hashimoto

parent
3fef4fce56
commit
ba65b61fa9
@ -210,6 +210,13 @@ pub fn newTab(self: *Window, parentSurface: ?*CoreSurface) !void {
|
|||||||
// does not (cursor doesn't blink) unless reactivated by refocusing.
|
// does not (cursor doesn't blink) unless reactivated by refocusing.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addTab adds a tab to the windows list of tabs.
|
||||||
|
// This does *not* manage the underlying GtkNotebook pages.
|
||||||
|
pub fn addTab(self: *Window, tab: *Tab) !void {
|
||||||
|
tab.window = self;
|
||||||
|
try self.tabs.append(self.app.core_app.alloc, tab);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn removeTab(self: *Window, tab: *Tab) !void {
|
pub fn removeTab(self: *Window, tab: *Tab) !void {
|
||||||
// Remove the tab from our stored tabs.
|
// Remove the tab from our stored tabs.
|
||||||
const tab_idx = for (self.tabs.items, 0..) |t, i| {
|
const tab_idx = for (self.tabs.items, 0..) |t, i| {
|
||||||
@ -217,10 +224,6 @@ pub fn removeTab(self: *Window, tab: *Tab) !void {
|
|||||||
} else null;
|
} else null;
|
||||||
|
|
||||||
if (tab_idx) |idx| _ = self.tabs.orderedRemove(idx) else return error.TabNotFound;
|
if (tab_idx) |idx| _ = self.tabs.orderedRemove(idx) else return error.TabNotFound;
|
||||||
|
|
||||||
// Deallocate the tab
|
|
||||||
tab.deinit(self.app.core_app.alloc);
|
|
||||||
self.app.core_app.alloc.destroy(tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close the tab for the given notebook page. This will automatically
|
/// Close the tab for the given notebook page. This will automatically
|
||||||
@ -236,6 +239,9 @@ pub fn closeTab(self: *Window, tab: *Tab) void {
|
|||||||
log.warn("tab {} not removable: {}", .{ page_idx, err });
|
log.warn("tab {} not removable: {}", .{ page_idx, err });
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
// Deallocate the tab
|
||||||
|
tab.deinit(self.app.core_app.alloc);
|
||||||
|
self.app.core_app.alloc.destroy(tab);
|
||||||
|
|
||||||
c.gtk_notebook_remove_page(self.notebook, page_idx);
|
c.gtk_notebook_remove_page(self.notebook, page_idx);
|
||||||
|
|
||||||
@ -381,31 +387,35 @@ fn gtkNotebookCreateWindow(
|
|||||||
page: *c.GtkWidget,
|
page: *c.GtkWidget,
|
||||||
ud: ?*anyopaque,
|
ud: ?*anyopaque,
|
||||||
) callconv(.C) ?*c.GtkNotebook {
|
) callconv(.C) ?*c.GtkNotebook {
|
||||||
_ = ud;
|
|
||||||
_ = page;
|
|
||||||
log.warn("feature needs to be re-implemented after adding gtk splits", .{});
|
|
||||||
return null;
|
|
||||||
// The tab for the page is stored in the widget data.
|
// The tab for the page is stored in the widget data.
|
||||||
// const tab: *Tab = @ptrCast(@alignCast(
|
const tab: *Tab = @ptrCast(@alignCast(
|
||||||
// c.g_object_get_data(@ptrCast(page), Tab.GHOSTTY_TAB) orelse return null,
|
c.g_object_get_data(@ptrCast(page), Tab.GHOSTTY_TAB) orelse return null,
|
||||||
// ));
|
));
|
||||||
// const surface: *Surface = tab.focus_child;
|
|
||||||
|
|
||||||
// const self = userdataSelf(ud.?);
|
const currentWindow = userdataSelf(ud.?);
|
||||||
// const alloc = self.app.core_app.alloc;
|
const alloc = currentWindow.app.core_app.alloc;
|
||||||
|
const app = currentWindow.app;
|
||||||
|
|
||||||
// // Create a new window
|
// Create a new window
|
||||||
// const window = Window.create(alloc, self.app) catch |err| {
|
const window = Window.create(alloc, app) catch |err| {
|
||||||
// log.warn("error creating new window error={}", .{err});
|
log.warn("error creating new window error={}", .{err});
|
||||||
// return null;
|
return null;
|
||||||
// };
|
};
|
||||||
|
|
||||||
// // We need to update our surface to point to the new window and tab so that
|
// Now remove the tab from the old window.
|
||||||
// // events such as new tab go to the right window.
|
currentWindow.removeTab(tab) catch |err| {
|
||||||
// surface.window = window;
|
log.warn("error removing tab error={}", .{err});
|
||||||
// surface.tab = window.tabs.items[window.tabs.items.len - 1];
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
// return window.notebook;
|
// And add it to the new window.
|
||||||
|
tab.window = window;
|
||||||
|
window.addTab(tab) catch |err| {
|
||||||
|
log.warn("error adding tab to new window error={}", .{err});
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
return window.notebook;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkCloseRequest(v: *c.GtkWindow, ud: ?*anyopaque) callconv(.C) bool {
|
fn gtkCloseRequest(v: *c.GtkWindow, ud: ?*anyopaque) callconv(.C) bool {
|
||||||
|
Reference in New Issue
Block a user