diff --git a/include/ghostty.h b/include/ghostty.h index ea7fd07aa..7258c8838 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -416,6 +416,12 @@ typedef union { ghostty_platform_ios_s ios; } ghostty_platform_u; +typedef enum { + GHOSTTY_SURFACE_CONTEXT_WINDOW = 0, + GHOSTTY_SURFACE_CONTEXT_TAB = 1, + GHOSTTY_SURFACE_CONTEXT_SPLIT = 2, +} ghostty_surface_context_e; + typedef struct { ghostty_platform_e platform_tag; ghostty_platform_u platform; @@ -428,7 +434,7 @@ typedef struct { size_t env_var_count; const char* initial_input; bool wait_after_command; - int context; // 0=window, 1=tab, 2=split + ghostty_surface_context_e context; } ghostty_surface_config_s; typedef struct { diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView.swift b/macos/Sources/Ghostty/Surface View/SurfaceView.swift index 3fa98837f..095441192 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView.swift @@ -625,11 +625,19 @@ extension Ghostty { #endif } - /// Context for surface creation, matching the Zig NewSurfaceContext enum - enum NewSurfaceContext: Int32 { - case window = 0 - case tab = 1 - case split = 2 + /// Context for surface creation, matching ghostty_surface_context_e + enum NewSurfaceContext: ghostty_surface_context_e.RawValue { + case window = 0 // GHOSTTY_SURFACE_CONTEXT_WINDOW + case tab = 1 // GHOSTTY_SURFACE_CONTEXT_TAB + case split = 2 // GHOSTTY_SURFACE_CONTEXT_SPLIT + + init(_ cValue: ghostty_surface_context_e) { + self.init(rawValue: cValue.rawValue)! + } + + var cValue: ghostty_surface_context_e { + ghostty_surface_context_e(rawValue: self.rawValue) + } } /// The configuration for a surface. For any configuration not set, defaults will be chosen from @@ -677,7 +685,7 @@ extension Ghostty { } } } - self.context = NewSurfaceContext(rawValue: config.context) ?? .window + self.context = NewSurfaceContext(config.context) } /// Provides a C-compatible ghostty configuration within a closure. The configuration @@ -712,7 +720,7 @@ extension Ghostty { config.wait_after_command = waitAfterCommand // Set context - config.context = context.rawValue + config.context = context.cValue // Use withCString to ensure strings remain valid for the duration of the closure return try workingDirectory.withCString { cWorkingDir in