consolidated enums

This commit is contained in:
Peter Guy
2025-10-13 19:12:03 -07:00
parent d660799723
commit b119bc6089
3 changed files with 12 additions and 48 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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 {