move SplitDirection to apprt

This commit is contained in:
Mitchell Hashimoto
2024-02-04 20:42:42 -08:00
parent 1824a0fe87
commit f414787779
7 changed files with 22 additions and 25 deletions

View File

@ -3195,17 +3195,14 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.new_split => |direction| { .new_split => |direction| {
if (@hasDecl(apprt.Surface, "newSplit")) { if (@hasDecl(apprt.Surface, "newSplit")) {
const resolved_direction: input.SplitDirection = switch (direction) { try self.rt_surface.newSplit(switch (direction) {
.right => .right, .right => .right,
.down => .down, .down => .down,
.auto => auto: { .auto => if (self.screen_size.width > self.screen_size.height)
const size = self.screen_size; .right
if (size.width > size.height) { else
break :auto .right; .down,
} else break :auto .down; });
},
};
try self.rt_surface.newSplit(resolved_direction);
} else log.warn("runtime doesn't implement newSplit", .{}); } else log.warn("runtime doesn't implement newSplit", .{});
}, },

View File

@ -80,7 +80,7 @@ pub const App = struct {
/// Create a new split view. If the embedder doesn't support split /// Create a new split view. If the embedder doesn't support split
/// views then this can be null. /// views then this can be null.
new_split: ?*const fn (SurfaceUD, input.SplitDirection, apprt.Surface.Options) callconv(.C) void = null, new_split: ?*const fn (SurfaceUD, apprt.SplitDirection, apprt.Surface.Options) callconv(.C) void = null,
/// New tab with options. /// New tab with options.
new_tab: ?*const fn (SurfaceUD, apprt.Surface.Options) callconv(.C) void = null, new_tab: ?*const fn (SurfaceUD, apprt.Surface.Options) callconv(.C) void = null,
@ -460,7 +460,7 @@ pub const Surface = struct {
func(self.opts.userdata, mode); func(self.opts.userdata, mode);
} }
pub fn newSplit(self: *const Surface, direction: input.SplitDirection) !void { pub fn newSplit(self: *const Surface, direction: apprt.SplitDirection) !void {
const func = self.app.opts.new_split orelse { const func = self.app.opts.new_split orelse {
log.info("runtime embedder does not support splits", .{}); log.info("runtime embedder does not support splits", .{});
return; return;
@ -1640,7 +1640,7 @@ pub const CAPI = struct {
} }
/// Request that the surface split in the given direction. /// Request that the surface split in the given direction.
export fn ghostty_surface_split(ptr: *Surface, direction: input.SplitDirection) void { export fn ghostty_surface_split(ptr: *Surface, direction: apprt.SplitDirection) void {
ptr.newSplit(direction) catch {}; ptr.newSplit(direction) catch {};
} }

View File

@ -5,6 +5,7 @@ const Split = @This();
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const assert = std.debug.assert; const assert = std.debug.assert;
const apprt = @import("../../apprt.zig");
const font = @import("../../font/main.zig"); const font = @import("../../font/main.zig");
const input = @import("../../input.zig"); const input = @import("../../input.zig");
const CoreSurface = @import("../../Surface.zig"); const CoreSurface = @import("../../Surface.zig");
@ -20,7 +21,7 @@ pub const Orientation = enum {
horizontal, horizontal,
vertical, vertical,
pub fn fromDirection(direction: input.SplitDirection) Orientation { pub fn fromDirection(direction: apprt.SplitDirection) Orientation {
return switch (direction) { return switch (direction) {
.right => .horizontal, .right => .horizontal,
.down => .vertical, .down => .vertical,
@ -57,7 +58,7 @@ bottom_right: Surface.Container.Elem,
pub fn create( pub fn create(
alloc: Allocator, alloc: Allocator,
sibling: *Surface, sibling: *Surface,
direction: input.SplitDirection, direction: apprt.SplitDirection,
) !*Split { ) !*Split {
var split = try alloc.create(Split); var split = try alloc.create(Split);
errdefer alloc.destroy(split); errdefer alloc.destroy(split);
@ -68,7 +69,7 @@ pub fn create(
pub fn init( pub fn init(
self: *Split, self: *Split,
sibling: *Surface, sibling: *Surface,
direction: input.SplitDirection, direction: apprt.SplitDirection,
) !void { ) !void {
// Create the new child surface for the other direction. // Create the new child surface for the other direction.
const alloc = sibling.app.core_app.alloc; const alloc = sibling.app.core_app.alloc;

View File

@ -570,7 +570,7 @@ pub fn getTitleLabel(self: *Surface) ?*c.GtkWidget {
} }
} }
pub fn newSplit(self: *Surface, direction: input.SplitDirection) !void { pub fn newSplit(self: *Surface, direction: apprt.SplitDirection) !void {
const alloc = self.app.core_app.alloc; const alloc = self.app.core_app.alloc;
_ = try Split.create(alloc, self, direction); _ = try Split.create(alloc, self, direction);
} }

View File

@ -62,6 +62,13 @@ pub const DesktopNotification = struct {
body: []const u8, body: []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) {
right,
down,
};
/// The color scheme in use (light vs dark). /// The color scheme in use (light vs dark).
pub const ColorScheme = enum(u2) { pub const ColorScheme = enum(u2) {
light = 0, light = 0,

View File

@ -13,13 +13,6 @@ pub const InspectorMode = Binding.Action.InspectorMode;
pub const SplitFocusDirection = Binding.Action.SplitFocusDirection; pub const SplitFocusDirection = Binding.Action.SplitFocusDirection;
pub const SplitResizeDirection = Binding.Action.SplitResizeDirection; 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 // 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. // in theory for XKB too on Linux but we don't need it right now.
pub const Keymap = switch (builtin.os.tag) { pub const Keymap = switch (builtin.os.tag) {

View File

@ -259,8 +259,7 @@ pub const Action = union(enum) {
pub const SplitDirection = enum { pub const SplitDirection = enum {
right, right,
down, down,
// splits along the larger direction auto, // splits along the larger direction
auto,
// Note: we don't support top or left yet // Note: we don't support top or left yet
}; };