From 1824a0fe87f6a9fc2531b3ef21d053de733367c8 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sun, 4 Feb 2024 21:08:44 -0600 Subject: [PATCH] split: add `auto` as split option Add an `auto` split direction which splits along the larger direction. --- src/Surface.zig | 12 +++++++++++- src/input.zig | 8 +++++++- src/input/Binding.zig | 6 +++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index e15bc342c..c6aa5e9aa 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -3195,7 +3195,17 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool .new_split => |direction| { if (@hasDecl(apprt.Surface, "newSplit")) { - try self.rt_surface.newSplit(direction); + const resolved_direction: input.SplitDirection = switch (direction) { + .right => .right, + .down => .down, + .auto => auto: { + const size = self.screen_size; + if (size.width > size.height) { + break :auto .right; + } else break :auto .down; + }, + }; + try self.rt_surface.newSplit(resolved_direction); } else log.warn("runtime doesn't implement newSplit", .{}); }, diff --git a/src/input.zig b/src/input.zig index 814415fcb..1c457455e 100644 --- a/src/input.zig +++ b/src/input.zig @@ -10,10 +10,16 @@ pub const Binding = @import("input/Binding.zig"); pub const Link = @import("input/Link.zig"); 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; +// This is made extern (c_int) to make interop easier with our embedded +// runtime. The small size cost doesn't make a difference in our union. +pub const SplitDirection = enum(c_int) { + right, + down, +}; + // 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. pub const Keymap = switch (builtin.os.tag) { diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 00fed488f..51d23a3aa 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -256,11 +256,11 @@ pub const Action = union(enum) { application: []const u8, }; - // This is made extern (c_int) to make interop easier with our embedded - // runtime. The small size cost doesn't make a difference in our union. - pub const SplitDirection = enum(c_int) { + pub const SplitDirection = enum { right, down, + // splits along the larger direction + auto, // Note: we don't support top or left yet };