From 496f5b3ed72751727a26b363692ad3c82cd2995d Mon Sep 17 00:00:00 2001 From: Peter Guy Date: Sat, 11 Oct 2025 22:17:38 -0700 Subject: [PATCH] Add the context to the Swift layer. - Define NewSurfaceContext to match the Zig enum name and avoid magic numbers. --- .../Sources/Ghostty/Surface View/SurfaceView.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView.swift b/macos/Sources/Ghostty/Surface View/SurfaceView.swift index c224d373e..3fa98837f 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView.swift @@ -625,6 +625,13 @@ extension Ghostty { #endif } + /// Context for surface creation, matching the Zig NewSurfaceContext enum + enum NewSurfaceContext: Int32 { + case window = 0 + case tab = 1 + case split = 2 + } + /// The configuration for a surface. For any configuration not set, defaults will be chosen from /// libghostty, usually from the Ghostty configuration. struct SurfaceConfiguration { @@ -646,6 +653,9 @@ extension Ghostty { /// Wait after the command var waitAfterCommand: Bool = false + /// Context for surface creation + var context: NewSurfaceContext = .window + init() {} init(from config: ghostty_surface_config_s) { @@ -667,6 +677,7 @@ extension Ghostty { } } } + self.context = NewSurfaceContext(rawValue: config.context) ?? .window } /// Provides a C-compatible ghostty configuration within a closure. The configuration @@ -700,6 +711,9 @@ extension Ghostty { // Set wait after command config.wait_after_command = waitAfterCommand + // Set context + config.context = context.rawValue + // Use withCString to ensure strings remain valid for the duration of the closure return try workingDirectory.withCString { cWorkingDir in config.working_directory = cWorkingDir