From b119bc6089f5a7e672ab8672f9de25b46a017ac0 Mon Sep 17 00:00:00 2001 From: Peter Guy Date: Mon, 13 Oct 2025 19:12:03 -0700 Subject: [PATCH] consolidated enums --- .../Ghostty/Surface View/SurfaceView.swift | 21 ++----------- src/apprt/embedded.zig | 31 +++---------------- src/apprt/surface.zig | 8 ++--- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView.swift b/macos/Sources/Ghostty/Surface View/SurfaceView.swift index 095441192..357e82a19 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView.swift @@ -625,21 +625,6 @@ extension Ghostty { #endif } - /// 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 /// libghostty, usually from the Ghostty configuration. struct SurfaceConfiguration { @@ -662,7 +647,7 @@ extension Ghostty { var waitAfterCommand: Bool = false /// Context for surface creation - var context: NewSurfaceContext = .window + var context: ghostty_surface_context_e = GHOSTTY_SURFACE_CONTEXT_WINDOW init() {} @@ -685,7 +670,7 @@ extension Ghostty { } } } - self.context = NewSurfaceContext(config.context) + self.context = config.context } /// Provides a C-compatible ghostty configuration within a closure. The configuration @@ -720,7 +705,7 @@ extension Ghostty { config.wait_after_command = waitAfterCommand // Set context - config.context = context.cValue + config.context = context // Use withCString to ensure strings remain valid for the duration of the closure return try workingDirectory.withCString { cWorkingDir in diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 186b0c2e4..d1d38c24d 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -458,13 +458,7 @@ pub const Surface = struct { wait_after_command: bool = false, /// Context for the new surface - context: Context = .c_window, - - pub const Context = enum(c_int) { - c_window = 0, - c_tab = 1, - c_split = 2, - }; + context: apprt.surface.NewSurfaceContext = .window, }; pub fn init(self: *Surface, app: *App, opts: Options) !void { @@ -486,13 +480,7 @@ pub const Surface = struct { errdefer app.core_app.deleteSurface(self); // Shallow copy the config so that we can modify it. - const surface_context: apprt.surface.NewSurfaceContext = switch (opts.context) { - .c_window => .window, - .c_tab => .tab, - .c_split => .split, - }; - - var config = try apprt.surface.newConfig(app.core_app, &app.config, surface_context); + var config = try apprt.surface.newConfig(app.core_app, &app.config, opts.context); defer config.deinit(); // If we have a working directory from the options then we set it. @@ -925,11 +913,7 @@ pub const Surface = struct { return .{ .font_size = font_size, .working_directory = working_directory, - .context = switch (context) { - .window => .c_window, - .tab => .c_tab, - .split => .c_split, - }, + .context = context, }; } @@ -1553,14 +1537,9 @@ pub const CAPI = struct { /// Returns the config to use for surfaces that inherit from this one. export fn ghostty_surface_inherited_config( surface: *Surface, - source: Surface.Options.Context, + source: apprt.surface.NewSurfaceContext, ) Surface.Options { - const context: apprt.surface.NewSurfaceContext = switch (source) { - .c_window => .window, - .c_tab => .tab, - .c_split => .split, - }; - return surface.newSurfaceOptions(context); + return surface.newSurfaceOptions(source); } /// Update the configuration to the provided config for only this surface. diff --git a/src/apprt/surface.zig b/src/apprt/surface.zig index 56dfae31b..be2f59149 100644 --- a/src/apprt/surface.zig +++ b/src/apprt/surface.zig @@ -160,10 +160,10 @@ pub const Mailbox = struct { }; /// Context for new surface creation to determine inheritance behavior -pub const NewSurfaceContext = enum { - window, - tab, - split, +pub const NewSurfaceContext = enum(c_int) { + window = 0, + tab = 1, + split = 2, }; pub fn shouldInheritWorkingDirectory(context: NewSurfaceContext, config: *const Config) bool {