config: change quick terminal size C layout to tagged union

pull/8402/head
Mitchell Hashimoto 2025-08-26 09:47:03 -07:00
parent 6a78f9c0c0
commit a90bf58080
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
4 changed files with 37 additions and 24 deletions

View File

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

View File

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

View File

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

View File

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