From 0a2d435481fec499a6a416cb91d90db5785bbba6 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Sun, 5 Nov 2023 19:50:58 -0600 Subject: [PATCH] core: add resize_split binding with default keys On macOS, use Cmd+Ctrl+Arrow keys as default bindings for resizing by 10 points in the given direction. --- src/Surface.zig | 8 ++++++++ src/config/Config.zig | 20 ++++++++++++++++++++ src/input.zig | 1 + src/input/Binding.zig | 17 +++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/src/Surface.zig b/src/Surface.zig index 7032ec8ae..aa5d89000 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2426,6 +2426,14 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool } else log.warn("runtime doesn't implement gotoSplit", .{}); }, + .resize_split => |param| { + if (@hasDecl(apprt.Surface, "resizeSplit")) { + const direction = param[0]; + const amount = param[1]; + self.rt_surface.resizeSplit(direction, amount); + } else log.warn("runtime doesn't implement resizeSplit", .{}); + }, + .toggle_split_zoom => { if (@hasDecl(apprt.Surface, "toggleSplitZoom")) { self.rt_surface.toggleSplitZoom(); diff --git a/src/config/Config.zig b/src/config/Config.zig index a091191d4..23eed68f4 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -956,6 +956,26 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config { .{ .key = .right, .mods = .{ .super = true, .alt = true } }, .{ .goto_split = .right }, ); + try result.keybind.set.put( + alloc, + .{ .key = .up, .mods = .{ .super = true, .ctrl = true } }, + .{ .resize_split = .{ .up, 10 } }, + ); + try result.keybind.set.put( + alloc, + .{ .key = .down, .mods = .{ .super = true, .ctrl = true } }, + .{ .resize_split = .{ .down, 10 } }, + ); + try result.keybind.set.put( + alloc, + .{ .key = .left, .mods = .{ .super = true, .ctrl = true } }, + .{ .resize_split = .{ .left, 10 } }, + ); + try result.keybind.set.put( + alloc, + .{ .key = .right, .mods = .{ .super = true, .ctrl = true } }, + .{ .resize_split = .{ .right, 10 } }, + ); // Inspector, matching Chromium try result.keybind.set.put( diff --git a/src/input.zig b/src/input.zig index c90226b39..f3afce97d 100644 --- a/src/input.zig +++ b/src/input.zig @@ -11,6 +11,7 @@ pub const KeyEncoder = @import("input/KeyEncoder.zig"); pub const InspectorMode = Binding.Action.InspectorMode; pub const SplitDirection = Binding.Action.SplitDirection; pub const SplitFocusDirection = Binding.Action.SplitFocusDirection; +pub const SplitResizeDirection = Binding.Action.SplitResizeDirection; // Keymap is only available on macOS right now. We could implement it // in theory for XKB too on Linux but we don't need it right now. diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 5bd9299b6..dcce76b01 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -179,6 +179,10 @@ pub const Action = union(enum) { /// zoom/unzoom the current split. toggle_split_zoom: void, + /// Resize the current split by moving the split divider in the given + /// direction + resize_split: SplitResizeParameter, + /// Show, hide, or toggle the terminal inspector for the currently /// focused terminal. inspector: InspectorMode, @@ -227,6 +231,19 @@ pub const Action = union(enum) { right, }; + // Extern because it is used in the embedded runtime ABI. + pub const SplitResizeDirection = enum(c_int) { + up, + down, + left, + right, + }; + + pub const SplitResizeParameter = struct { + SplitResizeDirection, + u16, + }; + // Extern because it is used in the embedded runtime ABI. pub const InspectorMode = enum(c_int) { toggle,