@@ -11,6 +11,7 @@ const fizzy = @import("fizzy.zig");
1111const auto_update = @import ("auto_update.zig" );
1212const update_notify = @import ("update_notify.zig" );
1313const singleton = @import ("singleton.zig" );
14+ const paths = @import ("paths.zig" );
1415
1516const App = @This ();
1617const Editor = fizzy .Editor ;
@@ -41,27 +42,45 @@ fn appAllocator() std.mem.Allocator {
4142// reach argv through this zig's `process.Init` API.
4243var main_init_global : ? std.process.Init = null ;
4344
45+ var pref_path_buf : [std .fs .max_path_bytes ]u8 = undefined ;
46+ var pref_path_len : usize = 0 ;
47+
48+ const start_options_base : dvui.App.StartOptions = .{
49+ .size = .{ .w = 1200.0 , .h = 800.0 },
50+ .min_size = .{ .w = 640.0 , .h = 480.0 },
51+ .title = "fizzy" ,
52+ .icon = icon ,
53+ .transparent = if (builtin .os .tag == .macos or builtin .os .tag == .windows ) true else false ,
54+ // macOS: Cancel-leading dialog/footer order; other platforms: OK-leading (matches dialog header close vs icon).
55+ .window_init_options = .{
56+ .button_order = if (builtin .os .tag .isDarwin ()) .cancel_ok else .ok_cancel ,
57+ },
58+ };
59+
60+ fn startOptions () dvui.App.StartOptions {
61+ var opts = start_options_base ;
62+ if (comptime builtin .target .cpu .arch != .wasm32 ) {
63+ const main_init = dvui .App .main_init orelse return opts ;
64+ if (paths .configFolderZ (& pref_path_buf , main_init .io , fizzy .processEnviron (), "." )) | pref_path | {
65+ pref_path_len = pref_path .len ;
66+ opts .pref_path = pref_path_buf [0.. pref_path_len :0 ];
67+ }
68+ }
69+ return opts ;
70+ }
71+
4472// To be a dvui App:
4573// * declare "dvui_app"
4674// * expose the backend's main function
4775// * use the backend's log function
4876pub const dvui_app : dvui.App = .{
49- .config = .{
50- .options = .{
51- .size = .{ .w = 1200.0 , .h = 800.0 },
52- .min_size = .{ .w = 640.0 , .h = 480.0 },
53- .title = "fizzy" ,
54- .icon = icon ,
55- .transparent = if (builtin .os .tag == .macos or builtin .os .tag == .windows ) true else false ,
56- // macOS: Cancel-leading dialog/footer order; other platforms: OK-leading (matches dialog header close vs icon).
57- .window_init_options = .{
58- .button_order = if (builtin .os .tag .isDarwin ()) .cancel_ok else .ok_cancel ,
59- },
60- },
61- },
77+ .config = .{ .startFn = & startOptions },
6278 .frameFn = AppFrame ,
6379 .initFn = AppInit ,
6480 .deinitFn = AppDeinit ,
81+ // Applies macOS window chrome and restores a saved fullscreen Space
82+ // before the first frame (no-op elsewhere).
83+ .restoreFn = fizzy .backend .restoreWindowState ,
6584};
6685
6786pub fn main (main_init : std.process.Init ) ! u8 {
@@ -160,7 +179,18 @@ pub fn AppInit(win: *dvui.Window) !void {
160179 // No-op on Windows/Linux/web.
161180 fizzy .backend .installTrackpadGestureMonitor ();
162181
182+ // macOS window chrome was already applied in restoreWindowState (dvui
183+ // restoreFn) before this first frame; zoom restore is handled by the dvui
184+ // backend once the window is shown/focused. Windows chrome goes here.
185+ if (builtin .os .tag != .macos ) {
186+ fizzy .backend .setWindowStyle (win );
187+ }
188+
163189 update_notify .startLaunchCheck (dvui .io , fizzy .editor .settings .debug_simulate_update_available );
190+
191+ // From here on the monitor's pump timer may drive frames during macOS
192+ // window animations.
193+ fizzy .backend .macosLaunchComplete ();
164194}
165195
166196// Run as app is shutting down before dvui.Window.deinit()
0 commit comments