apprt/gtk-ng: hook up win split actions

pull/8207/head
Mitchell Hashimoto 2025-08-09 14:26:57 -07:00
parent aed6a3a343
commit e682e99bf5
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 60 additions and 2 deletions

View File

@ -562,6 +562,8 @@ pub const Application = extern struct {
.move_tab => return Action.moveTab(target, value),
.new_split => return Action.newSplit(target, value),
.new_tab => return Action.newTab(target),
.new_window => try Action.newWindow(
@ -611,7 +613,6 @@ pub const Application = extern struct {
.prompt_title,
.inspector,
// TODO: splits
.new_split,
.resize_split,
.equalize_splits,
.goto_split,
@ -1747,6 +1748,28 @@ const Action = struct {
}
}
pub fn newSplit(
target: apprt.Target,
direction: apprt.action.SplitDirection,
) bool {
switch (target) {
.app => {
log.warn("new split to app is unexpected", .{});
return false;
},
.surface => |core| {
const surface = core.rt_surface.surface;
return surface.as(gtk.Widget).activateAction(switch (direction) {
.right => "split-tree.new-right",
.left => "split-tree.new-left",
.down => "split-tree.new-down",
.up => "split-tree.new-up",
}, null) != 0;
},
}
}
pub fn newTab(target: apprt.Target) bool {
switch (target) {
.app => {

View File

@ -490,7 +490,6 @@ pub const SplitTree = extern struct {
// Remove the surface from the tree.
.surface => {
// TODO: close confirmation
// TODO: invalid free on final close
// Find the surface in the tree.
const tree = self.getTree() orelse return;

View File

@ -335,6 +335,10 @@ pub const Window = extern struct {
.{ "close-tab", actionCloseTab, null },
.{ "new-tab", actionNewTab, null },
.{ "new-window", actionNewWindow, null },
.{ "split-right", actionSplitRight, null },
.{ "split-left", actionSplitLeft, null },
.{ "split-up", actionSplitUp, null },
.{ "split-down", actionSplitDown, null },
.{ "copy", actionCopy, null },
.{ "paste", actionPaste, null },
.{ "reset", actionReset, null },
@ -1650,6 +1654,38 @@ pub const Window = extern struct {
self.performBindingAction(.new_tab);
}
fn actionSplitRight(
_: *gio.SimpleAction,
_: ?*glib.Variant,
self: *Window,
) callconv(.c) void {
self.performBindingAction(.{ .new_split = .right });
}
fn actionSplitLeft(
_: *gio.SimpleAction,
_: ?*glib.Variant,
self: *Window,
) callconv(.c) void {
self.performBindingAction(.{ .new_split = .left });
}
fn actionSplitUp(
_: *gio.SimpleAction,
_: ?*glib.Variant,
self: *Window,
) callconv(.c) void {
self.performBindingAction(.{ .new_split = .up });
}
fn actionSplitDown(
_: *gio.SimpleAction,
_: ?*glib.Variant,
self: *Window,
) callconv(.c) void {
self.performBindingAction(.{ .new_split = .down });
}
fn actionCopy(
_: *gio.SimpleAction,
_: ?*glib.Variant,