macos: menu bar to split

This commit is contained in:
Mitchell Hashimoto
2023-03-10 15:24:45 -08:00
parent 0aadd19282
commit f85c1c256c
4 changed files with 25 additions and 0 deletions

View File

@ -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_mouse_scroll(ghostty_surface_t, double, double);
void ghostty_surface_ime_point(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_request_close(ghostty_surface_t);
void ghostty_surface_split(ghostty_surface_t, ghostty_split_direction_e);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -88,6 +88,10 @@ extension Ghostty {
ghostty_surface_request_close(surface) ghostty_surface_request_close(surface)
} }
func split(surface: ghostty_surface_t, direction: ghostty_split_direction_e) {
ghostty_surface_split(surface, direction)
}
// MARK: Ghostty Callbacks // MARK: Ghostty Callbacks
static func newSplit(_ userdata: UnsafeMutableRawPointer?, direction: ghostty_split_direction_e) { static func newSplit(_ userdata: UnsafeMutableRawPointer?, direction: ghostty_split_direction_e) {

View File

@ -31,6 +31,9 @@ struct GhosttyApp: App {
CommandGroup(after: .newItem) { CommandGroup(after: .newItem) {
Button("New Tab", action: Self.newTab).keyboardShortcut("t", modifiers: [.command]) Button("New Tab", action: Self.newTab).keyboardShortcut("t", modifiers: [.command])
Divider() 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", action: close).keyboardShortcut("w", modifiers: [.command])
Button("Close Window", action: Self.closeWindow).keyboardShortcut("w", modifiers: [.command, .shift]) 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 } guard let surface = surfaceView.surface else { return }
ghostty.requestClose(surface: surface) 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 { class AppDelegate: NSObject, NSApplicationDelegate {

View File

@ -476,4 +476,9 @@ pub const CAPI = struct {
export fn ghostty_surface_request_close(ptr: *Surface) void { export fn ghostty_surface_request_close(ptr: *Surface) void {
ptr.closeSurface() catch {}; 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 {};
}
}; };