diff --git a/include/ghostty.h b/include/ghostty.h index c7f4b549e..ea62ca74b 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -253,6 +253,7 @@ void ghostty_surface_mouse_pos(ghostty_surface_t, double, double); void ghostty_surface_mouse_scroll(ghostty_surface_t, double, double); void ghostty_surface_ime_point(ghostty_surface_t, double *, double *); void ghostty_surface_request_close(ghostty_surface_t); +void ghostty_surface_split(ghostty_surface_t, ghostty_split_direction_e); #ifdef __cplusplus } diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index 819c9a378..59f68785b 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -88,6 +88,10 @@ extension Ghostty { ghostty_surface_request_close(surface) } + func split(surface: ghostty_surface_t, direction: ghostty_split_direction_e) { + ghostty_surface_split(surface, direction) + } + // MARK: Ghostty Callbacks static func newSplit(_ userdata: UnsafeMutableRawPointer?, direction: ghostty_split_direction_e) { diff --git a/macos/Sources/GhosttyApp.swift b/macos/Sources/GhosttyApp.swift index f096f1028..4a14e6fe6 100644 --- a/macos/Sources/GhosttyApp.swift +++ b/macos/Sources/GhosttyApp.swift @@ -31,6 +31,9 @@ struct GhosttyApp: App { CommandGroup(after: .newItem) { Button("New Tab", action: Self.newTab).keyboardShortcut("t", modifiers: [.command]) Divider() + Button("Split Horizontally", action: splitHorizontally).keyboardShortcut("d", modifiers: [.command]) + Button("Split Vertically", action: splitVertically).keyboardShortcut("d", modifiers: [.command, .shift]) + Divider() Button("Close", action: close).keyboardShortcut("w", modifiers: [.command]) Button("Close Window", action: Self.closeWindow).keyboardShortcut("w", modifiers: [.command, .shift]) } @@ -61,6 +64,18 @@ struct GhosttyApp: App { guard let surface = surfaceView.surface else { return } ghostty.requestClose(surface: surface) } + + func splitHorizontally() { + guard let surfaceView = focusedSurface else { return } + guard let surface = surfaceView.surface else { return } + ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_RIGHT) + } + + func splitVertically() { + guard let surfaceView = focusedSurface else { return } + guard let surface = surfaceView.surface else { return } + ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_DOWN) + } } class AppDelegate: NSObject, NSApplicationDelegate { diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 8cf5d6d30..7ed69a514 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -476,4 +476,9 @@ pub const CAPI = struct { export fn ghostty_surface_request_close(ptr: *Surface) void { ptr.closeSurface() catch {}; } + + /// Request that the surface split in the given direction. + export fn ghostty_surface_split(ptr: *Surface, direction: input.SplitDirection) void { + ptr.newSplit(direction) catch {}; + } };