gtk: implement move_tab_to_new_window

This commit is contained in:
Leah Amelia Chen
2026-08-05 17:18:26 +08:00
parent 25b2d8a385
commit f6fca9aabf
2 changed files with 44 additions and 1 deletions

View File

@@ -717,6 +717,7 @@ pub const Application = extern struct {
.mouse_visibility => Action.mouseVisibility(target, value),
.move_tab => return Action.moveTab(target, value),
.move_tab_to_new_window => return Action.moveTabToNewWindow(target),
.new_split => return Action.newSplit(target, value),
@@ -799,7 +800,6 @@ pub const Application = extern struct {
.check_for_updates,
.undo,
.redo,
.move_tab_to_new_window,
=> {
log.warn("unimplemented action={}", .{action});
return false;
@@ -2359,6 +2359,26 @@ const Action = struct {
}
}
pub fn moveTabToNewWindow(
target: apprt.Target,
) bool {
switch (target) {
.app => return false,
.surface => |core| {
const surface = core.rt_surface.surface;
const window = ext.getAncestor(
Window,
surface.as(gtk.Widget),
) orelse {
log.warn("surface is not in a window, ignoring new_tab_to_new_window", .{});
return false;
};
return window.moveTabToNewWindow(surface);
},
}
}
pub fn newSplit(
target: apprt.Target,
direction: apprt.action.SplitDirection,

View File

@@ -604,6 +604,29 @@ pub const Window = extern struct {
return tab_view.reorderPage(page, desired_pos) != 0;
}
pub fn moveTabToNewWindow(self: *Self, surface: *Surface) bool {
const tab_view = self.private().tab_view;
const tab = ext.getAncestor(
Tab,
surface.as(gtk.Widget),
) orelse return false;
const page = tab_view.getPage(tab.as(gtk.Widget));
// Skip if this is the only tab in the existing window
if (tab_view.getNPages() <= 1) return false;
const app = Application.default();
const window = Window.new(app, .none);
tab_view.transferPage(
page,
window.private().tab_view,
0,
);
window.as(gtk.Window).present();
return true;
}
pub fn toggleTabOverview(self: *Self) void {
const priv = self.private();
const tab_overview = priv.tab_overview;