macos: support initial window size

This commit is contained in:
Mitchell Hashimoto
2023-09-30 20:47:31 -07:00
parent 8cb96a28c1
commit cc8e1cd936
6 changed files with 88 additions and 3 deletions

View File

@@ -757,6 +757,16 @@ pub const Surface = struct {
pub const CAPI = struct {
const global = &@import("../main.zig").state;
/// ghostty_rect_s
const Rect = extern struct {
origin: bool = false,
size: bool = false,
x: u32 = 0,
y: u32 = 0,
w: u32 = 0,
h: u32 = 0,
};
/// Create a new app.
export fn ghostty_app_new(
opts: *const apprt.runtime.App.Options,
@@ -864,6 +874,21 @@ pub const CAPI = struct {
return surface.app.config.@"background-opacity" < 1.0;
}
/// The desired window frame for a new window.
export fn ghostty_surface_window_frame(surface: *Surface) Rect {
const config = surface.app.config;
// If the desired height/width isn't configured, return 0.
if (config.@"window-height" == 0 or config.@"window-width" == 0) return .{};
// Return the desired rect
return .{
.size = true,
.h = @max(config.@"window-height" * surface.core_surface.cell_size.height, 480),
.w = @max(config.@"window-width" * surface.core_surface.cell_size.width, 640),
};
}
/// Tell the surface that it needs to schedule a render
export fn ghostty_surface_refresh(surface: *Surface) void {
surface.refresh();