diff --git a/include/ghostty.h b/include/ghostty.h index 7758423fe..6fd218e9e 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -455,11 +455,16 @@ typedef enum { GHOSTTY_QUICK_TERMINAL_SIZE_NONE, GHOSTTY_QUICK_TERMINAL_SIZE_PERCENTAGE, GHOSTTY_QUICK_TERMINAL_SIZE_PIXELS, -} ghostty_quick_terminal_size_e; +} ghostty_quick_terminal_size_tag_e; + +typedef union { + float percentage; + uint32_t pixels; +} ghostty_quick_terminal_size_value_u; typedef struct { - ghostty_quick_terminal_size_e type; - uint32_t value; + ghostty_quick_terminal_size_tag_e tag; + ghostty_quick_terminal_size_value_u value; } ghostty_quick_terminal_size_s; typedef struct { diff --git a/macos/Ghostty.xcodeproj/project.pbxproj b/macos/Ghostty.xcodeproj/project.pbxproj index d9fa44f08..e3fb92fa4 100644 --- a/macos/Ghostty.xcodeproj/project.pbxproj +++ b/macos/Ghostty.xcodeproj/project.pbxproj @@ -490,7 +490,6 @@ A55B7BB429B6F4410055DE60 /* Ghostty */ = { isa = PBXGroup; children = ( - A5BB78B82DF9D8CE009AC3FA /* QuickTerminalSize.swift */, A55B7BB729B6F53A0055DE60 /* Package.swift */, A55B7BBB29B6FC330055DE60 /* SurfaceView.swift */, A5333E212B5A2128008AEFF7 /* SurfaceView_AppKit.swift */, @@ -640,6 +639,7 @@ CFBB5FE92D231E5000FD62EE /* QuickTerminalSpaceBehavior.swift */, A5CBD0632CA122E70017A1AE /* QuickTerminalPosition.swift */, A52FFF562CA90481000C6A5B /* QuickTerminalScreen.swift */, + A5BB78B82DF9D8CE009AC3FA /* QuickTerminalSize.swift */, A5CBD05F2CA0C9080017A1AE /* QuickTerminalWindow.swift */, ); path = QuickTerminal; diff --git a/macos/Sources/Ghostty/QuickTerminalSize.swift b/macos/Sources/Features/QuickTerminal/QuickTerminalSize.swift similarity index 88% rename from macos/Sources/Ghostty/QuickTerminalSize.swift rename to macos/Sources/Features/QuickTerminal/QuickTerminalSize.swift index 194407014..cb3cc6fd6 100644 --- a/macos/Sources/Ghostty/QuickTerminalSize.swift +++ b/macos/Sources/Features/QuickTerminal/QuickTerminalSize.swift @@ -19,16 +19,13 @@ struct QuickTerminalSize { case pixels(UInt32) init?(from cStruct: ghostty_quick_terminal_size_s) { - switch cStruct.type { + switch cStruct.tag { case GHOSTTY_QUICK_TERMINAL_SIZE_NONE: return nil case GHOSTTY_QUICK_TERMINAL_SIZE_PERCENTAGE: - let floatValue = withUnsafePointer(to: cStruct.value) { ptr in - ptr.withMemoryRebound(to: Float.self, capacity: 1) { $0.pointee } - } - self = .percentage(floatValue) + self = .percentage(cStruct.value.percentage) case GHOSTTY_QUICK_TERMINAL_SIZE_PIXELS: - self = .pixels(cStruct.value) + self = .pixels(cStruct.value.pixels) default: return nil } diff --git a/src/config/Config.zig b/src/config/Config.zig index 498f59bfb..1156c5fef 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -7200,25 +7200,36 @@ pub const QuickTerminalSize = struct { /// C API structure for QuickTerminalSize pub const C = extern struct { - primary: CSize, - secondary: CSize, - }; + primary: C.Size, + secondary: C.Size, - pub const CSize = extern struct { - type: Type, - value: u32, + pub const Size = extern struct { + tag: Tag, + value: Value, - pub const Type = enum(u8) { none, percentage, pixels }; + pub const Tag = enum(u8) { none, percentage, pixels }; - pub const none: CSize = .{ .type = .none, .value = 0 }; + pub const Value = extern union { + percentage: f32, + pixels: u32, + }; - fn percentage(v: f32) CSize { - return .{ .type = .percentage, .value = @bitCast(v) }; - } + pub const none: C.Size = .{ .tag = .none, .value = undefined }; - fn pixels(v: u32) CSize { - return .{ .type = .pixels, .value = v }; - } + pub fn percentage(v: f32) C.Size { + return .{ + .tag = .percentage, + .value = .{ .percentage = v }, + }; + } + + pub fn pixels(v: u32) C.Size { + return .{ + .tag = .pixels, + .value = .{ .pixels = v }, + }; + } + }; }; pub fn cval(self: QuickTerminalSize) C {