Skip to content

Commit aa30173

Browse files
committed
Fix enter/exit fullscreen transition, save and load window geometry
1 parent b99f453 commit aa30173

9 files changed

Lines changed: 1045 additions & 42 deletions

File tree

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ fn addFizzyExecutableForTarget(
11581158
exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/objc/FizzyVisualEffectView.m") });
11591159
exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/objc/FizzyMenuTarget.m") });
11601160
exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/objc/FizzyTrackpadGesture.m") });
1161+
exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/objc/FizzyWindowMonitor.m") });
11611162
} else if (resolved_target.result.os.tag == .windows) {
11621163
if (b.lazyDependency("zigwin32", .{})) |dep| {
11631164
exe.root_module.addImport("win32", dep.module("win32"));

build.zig.zon

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
.lazy = true,
1818
},
1919
.zigwin32 = .{
20-
.url = "https://github.com/kristoff-it/zigwin32/archive/1102e9b82e8bd50913b6a78035bfb399ebd8cf97.tar.gz",
21-
.hash = "zigwin32-25.0.28-preview-6BfVhYKN5AOvXPVJq4bGZ7C5dM3PbUra4xhKAKOFJGcF",
20+
.url = "https://github.com/marlersoft/zigwin32/archive/ec98bb4d9eea532320a8551720a9e3ec6de64994.tar.gz",
21+
.hash = "win32-25.0.28-preview-mX5pFWMt5QPTVIGh3r2-OpPunpcCCjApyRbA6Zn6WALH",
2222
.lazy = true,
2323
},
2424
.icons = .{
@@ -27,9 +27,8 @@
2727
.lazy = true,
2828
},
2929
.dvui = .{
30-
.url = "https://github.com/foxnne/dvui-dev/archive/b0213e89635f9fc020728101cb106a5404884934.tar.gz",
31-
.hash = "dvui-0.5.0-dev-AQFJmTXo9gBEcaOJrsSaM_yT4--HViiNIsyYZNfFnvdW",
32-
//.hash = "dvui-0.5.0-dev-AQFJmWbD9gDRbS5aDjZxoh1RG-zUgeSYz9aeFF4QcaaF",
30+
.url = "https://github.com/foxnne/dvui-dev/archive/0c9a596fa4362f8cb2cd27b653942ddf3fd7a668.tar.gz",
31+
.hash = "dvui-0.5.0-dev-AQFJmahe9wA8Cg9l8-mnlIhigaUqsWEtO3f3X8x3Ei62",
3332
//.path = "../dvui-dev",
3433
},
3534
.assetpack = .{
@@ -43,7 +42,6 @@
4342
.velopack_zig = .{
4443
.url = "https://github.com/graphl-tech/velopack-zig/archive/0c2f20635a97fde38cc8000e9fb1a75f891cf37d.tar.gz",
4544
.hash = "velopack_zig-0.0.1-LzeGcengAACU1f33uDAuLKlWXtek0KCC6i_b3XWeJMjd",
46-
//.hash = "velopack_zig-0.0.1-LzeGccHTAAAYj2eidbi80qHljonogPnwU-uHCMYBa1ag",
4745
//.path = "../velopack-zig",
4846
},
4947
.dvui_singleton_app = .{

src/App.zig

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const fizzy = @import("fizzy.zig");
1111
const auto_update = @import("auto_update.zig");
1212
const update_notify = @import("update_notify.zig");
1313
const singleton = @import("singleton.zig");
14+
const paths = @import("paths.zig");
1415

1516
const App = @This();
1617
const Editor = fizzy.Editor;
@@ -41,27 +42,45 @@ fn appAllocator() std.mem.Allocator {
4142
// reach argv through this zig's `process.Init` API.
4243
var 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
4876
pub 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

6786
pub 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

Comments
 (0)