macos: add key binding for equalizing split sizes

This commit is contained in:
Gregory Anders
2023-11-07 16:15:46 -06:00
parent 36dd5ef4ee
commit cd01340cce
12 changed files with 103 additions and 4 deletions

View File

@@ -2458,6 +2458,12 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
} else log.warn("runtime doesn't implement resizeSplit", .{});
},
.equalize_splits => {
if (@hasDecl(apprt.Surface, "equalizeSplits")) {
self.rt_surface.equalizeSplits();
} else log.warn("runtime doesn't implement equalizeSplits", .{});
},
.toggle_split_zoom => {
if (@hasDecl(apprt.Surface, "toggleSplitZoom")) {
self.rt_surface.toggleSplitZoom();

View File

@@ -95,6 +95,9 @@ pub const App = struct {
/// Resize the current split.
resize_split: ?*const fn (SurfaceUD, input.SplitResizeDirection, u16) callconv(.C) void = null,
/// Equalize all splits in the current window
equalize_splits: ?*const fn (SurfaceUD) callconv(.C) void = null,
/// Zoom the current split.
toggle_split_zoom: ?*const fn (SurfaceUD) callconv(.C) void = null,
@@ -396,6 +399,15 @@ pub const Surface = struct {
func(self.opts.userdata, direction, amount);
}
pub fn equalizeSplits(self: *const Surface) void {
const func = self.app.opts.equalize_splits orelse {
log.info("runtime embedder does not support equalize splits", .{});
return;
};
func(self.opts.userdata);
}
pub fn toggleSplitZoom(self: *const Surface) void {
const func = self.app.opts.toggle_split_zoom orelse {
log.info("runtime embedder does not support split zoom", .{});
@@ -1388,6 +1400,11 @@ pub const CAPI = struct {
ptr.resizeSplit(direction, amount);
}
/// Equalize the size of all splits in the current window.
export fn ghostty_surface_split_equalize(ptr: *Surface) void {
ptr.equalizeSplits();
}
/// Invoke an action on the surface.
export fn ghostty_surface_binding_action(
ptr: *Surface,

View File

@@ -1016,6 +1016,11 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
.{ .key = .right, .mods = .{ .super = true, .ctrl = true } },
.{ .resize_split = .{ .right, 10 } },
);
try result.keybind.set.put(
alloc,
.{ .key = .equal, .mods = .{ .shift = true, .alt = true } },
.{ .equalize_splits = {} },
);
// Inspector, matching Chromium
try result.keybind.set.put(

View File

@@ -197,6 +197,9 @@ pub const Action = union(enum) {
/// direction
resize_split: SplitResizeParameter,
/// Equalize all splits in the current window
equalize_splits: void,
/// Show, hide, or toggle the terminal inspector for the currently
/// focused terminal.
inspector: InspectorMode,