mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
gtk: implement splitting leftwards and upwards
This commit is contained in:

committed by
Mitchell Hashimoto

parent
1b5a4433c8
commit
fbc621a7d8
@ -3835,7 +3835,9 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
|||||||
.new_split,
|
.new_split,
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
.right => .right,
|
.right => .right,
|
||||||
|
.left => .left,
|
||||||
.down => .down,
|
.down => .down,
|
||||||
|
.up => .up,
|
||||||
.auto => if (self.screen_size.width > self.screen_size.height)
|
.auto => if (self.screen_size.width > self.screen_size.height)
|
||||||
.right
|
.right
|
||||||
else
|
else
|
||||||
|
@ -272,6 +272,8 @@ pub const Action = union(Key) {
|
|||||||
pub const SplitDirection = enum(c_int) {
|
pub const SplitDirection = enum(c_int) {
|
||||||
right,
|
right,
|
||||||
down,
|
down,
|
||||||
|
left,
|
||||||
|
up,
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is made extern (c_int) to make interop easier with our embedded
|
// This is made extern (c_int) to make interop easier with our embedded
|
||||||
|
@ -768,6 +768,8 @@ fn syncActionAccelerators(self: *App) !void {
|
|||||||
try self.syncActionAccelerator("win.new_tab", .{ .new_tab = {} });
|
try self.syncActionAccelerator("win.new_tab", .{ .new_tab = {} });
|
||||||
try self.syncActionAccelerator("win.split_right", .{ .new_split = .right });
|
try self.syncActionAccelerator("win.split_right", .{ .new_split = .right });
|
||||||
try self.syncActionAccelerator("win.split_down", .{ .new_split = .down });
|
try self.syncActionAccelerator("win.split_down", .{ .new_split = .down });
|
||||||
|
try self.syncActionAccelerator("win.split_left", .{ .new_split = .left });
|
||||||
|
try self.syncActionAccelerator("win.split_up", .{ .new_split = .up });
|
||||||
try self.syncActionAccelerator("win.copy", .{ .copy_to_clipboard = {} });
|
try self.syncActionAccelerator("win.copy", .{ .copy_to_clipboard = {} });
|
||||||
try self.syncActionAccelerator("win.paste", .{ .paste_from_clipboard = {} });
|
try self.syncActionAccelerator("win.paste", .{ .paste_from_clipboard = {} });
|
||||||
try self.syncActionAccelerator("win.reset", .{ .reset = {} });
|
try self.syncActionAccelerator("win.reset", .{ .reset = {} });
|
||||||
|
@ -22,8 +22,8 @@ pub const Orientation = enum {
|
|||||||
|
|
||||||
pub fn fromDirection(direction: apprt.action.SplitDirection) Orientation {
|
pub fn fromDirection(direction: apprt.action.SplitDirection) Orientation {
|
||||||
return switch (direction) {
|
return switch (direction) {
|
||||||
.right => .horizontal,
|
.right, .left => .horizontal,
|
||||||
.down => .vertical,
|
.down, .up => .vertical,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +80,8 @@ pub fn init(
|
|||||||
|
|
||||||
// Create the actual GTKPaned, attach the proper children.
|
// Create the actual GTKPaned, attach the proper children.
|
||||||
const orientation: c_uint = switch (direction) {
|
const orientation: c_uint = switch (direction) {
|
||||||
.right => c.GTK_ORIENTATION_HORIZONTAL,
|
.right, .left => c.GTK_ORIENTATION_HORIZONTAL,
|
||||||
.down => c.GTK_ORIENTATION_VERTICAL,
|
.down, .up => c.GTK_ORIENTATION_VERTICAL,
|
||||||
};
|
};
|
||||||
const paned = c.gtk_paned_new(orientation);
|
const paned = c.gtk_paned_new(orientation);
|
||||||
errdefer c.g_object_unref(paned);
|
errdefer c.g_object_unref(paned);
|
||||||
@ -94,14 +94,25 @@ pub fn init(
|
|||||||
// we're inheriting its parent. The sibling points to its location
|
// we're inheriting its parent. The sibling points to its location
|
||||||
// in the split, and the surface points to the other location.
|
// in the split, and the surface points to the other location.
|
||||||
const container = sibling.container;
|
const container = sibling.container;
|
||||||
sibling.container = .{ .split_tl = &self.top_left };
|
const tl: *Surface, const br: *Surface = switch (direction) {
|
||||||
surface.container = .{ .split_br = &self.bottom_right };
|
.right, .down => right_down: {
|
||||||
|
sibling.container = .{ .split_tl = &self.top_left };
|
||||||
|
surface.container = .{ .split_br = &self.bottom_right };
|
||||||
|
break :right_down .{ sibling, surface };
|
||||||
|
},
|
||||||
|
|
||||||
|
.left, .up => left_up: {
|
||||||
|
sibling.container = .{ .split_br = &self.bottom_right };
|
||||||
|
surface.container = .{ .split_tl = &self.top_left };
|
||||||
|
break :left_up .{ surface, sibling };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.paned = @ptrCast(paned),
|
.paned = @ptrCast(paned),
|
||||||
.container = container,
|
.container = container,
|
||||||
.top_left = .{ .surface = sibling },
|
.top_left = .{ .surface = tl },
|
||||||
.bottom_right = .{ .surface = surface },
|
.bottom_right = .{ .surface = br },
|
||||||
.orientation = Orientation.fromDirection(direction),
|
.orientation = Orientation.fromDirection(direction),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -373,6 +373,8 @@ fn initActions(self: *Window) void {
|
|||||||
.{ "new_tab", >kActionNewTab },
|
.{ "new_tab", >kActionNewTab },
|
||||||
.{ "split_right", >kActionSplitRight },
|
.{ "split_right", >kActionSplitRight },
|
||||||
.{ "split_down", >kActionSplitDown },
|
.{ "split_down", >kActionSplitDown },
|
||||||
|
.{ "split_left", >kActionSplitLeft },
|
||||||
|
.{ "split_up", >kActionSplitUp },
|
||||||
.{ "toggle_inspector", >kActionToggleInspector },
|
.{ "toggle_inspector", >kActionToggleInspector },
|
||||||
.{ "copy", >kActionCopy },
|
.{ "copy", >kActionCopy },
|
||||||
.{ "paste", >kActionPaste },
|
.{ "paste", >kActionPaste },
|
||||||
@ -812,6 +814,32 @@ fn gtkActionSplitDown(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gtkActionSplitLeft(
|
||||||
|
_: *c.GSimpleAction,
|
||||||
|
_: *c.GVariant,
|
||||||
|
ud: ?*anyopaque,
|
||||||
|
) callconv(.C) void {
|
||||||
|
const self: *Window = @ptrCast(@alignCast(ud orelse return));
|
||||||
|
const surface = self.actionSurface() orelse return;
|
||||||
|
_ = surface.performBindingAction(.{ .new_split = .left }) catch |err| {
|
||||||
|
log.warn("error performing binding action error={}", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gtkActionSplitUp(
|
||||||
|
_: *c.GSimpleAction,
|
||||||
|
_: *c.GVariant,
|
||||||
|
ud: ?*anyopaque,
|
||||||
|
) callconv(.C) void {
|
||||||
|
const self: *Window = @ptrCast(@alignCast(ud orelse return));
|
||||||
|
const surface = self.actionSurface() orelse return;
|
||||||
|
_ = surface.performBindingAction(.{ .new_split = .up }) catch |err| {
|
||||||
|
log.warn("error performing binding action error={}", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn gtkActionToggleInspector(
|
fn gtkActionToggleInspector(
|
||||||
_: *c.GSimpleAction,
|
_: *c.GSimpleAction,
|
||||||
_: *c.GVariant,
|
_: *c.GVariant,
|
||||||
|
@ -440,9 +440,9 @@ pub const Action = union(enum) {
|
|||||||
pub const SplitDirection = enum {
|
pub const SplitDirection = enum {
|
||||||
right,
|
right,
|
||||||
down,
|
down,
|
||||||
|
left,
|
||||||
|
up,
|
||||||
auto, // splits along the larger direction
|
auto, // splits along the larger direction
|
||||||
|
|
||||||
// Note: we don't support top or left yet
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const SplitFocusDirection = enum {
|
pub const SplitFocusDirection = enum {
|
||||||
|
Reference in New Issue
Block a user