Skip to content

Commit 9300f36

Browse files
committed
darwin: windowWillResize_toSize -> windowDidResize, fixes a bug where window size didn't include titlebar height. Depends on hexops/mach-objc#30
1 parent 0f6f4f6 commit 9300f36

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/core/Darwin.zig

+21-14
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ fn initWindow(
135135
const layer = objc.quartz_core.MetalLayer.new();
136136
defer layer.release();
137137

138-
if (core_window.color == .transparent) {
139-
layer.setOpaque(false);
140-
}
138+
if (core_window.color == .transparent) layer.setOpaque(false);
141139

142140
metal_descriptor.* = .{
143141
.layer = layer,
@@ -228,13 +226,13 @@ fn initWindow(
228226
const delegate = objc.mach.WindowDelegate.allocInit();
229227
defer native_window.setDelegate(@ptrCast(delegate));
230228
{
231-
var windowWillResize_toSize = objc.foundation.stackBlockLiteral(
232-
WindowDelegateCallbacks.windowWillResize_toSize,
229+
var windowDidResize = objc.foundation.stackBlockLiteral(
230+
WindowDelegateCallbacks.windowDidResize,
233231
context,
234232
null,
235233
null,
236234
);
237-
delegate.setBlock_windowWillResize_toSize(windowWillResize_toSize.asBlock().copy());
235+
delegate.setBlock_windowDidResize(windowDidResize.asBlock().copy());
238236

239237
var windowShouldClose = objc.foundation.stackBlockLiteral(
240238
WindowDelegateCallbacks.windowShouldClose,
@@ -254,19 +252,28 @@ fn initWindow(
254252
}
255253

256254
const WindowDelegateCallbacks = struct {
257-
pub fn windowWillResize_toSize(block: *objc.foundation.BlockLiteral(*Context), size: objc.app_kit.Size) callconv(.C) void {
255+
pub fn windowDidResize(block: *objc.foundation.BlockLiteral(*Context)) callconv(.C) void {
258256
const core: *Core = block.context.core;
259-
const s: Size = .{ .width = @intFromFloat(size.width), .height = @intFromFloat(size.height) };
260257

261-
var window = core.windows.getValue(block.context.window_id);
262-
window.width = s.width;
263-
window.height = s.height;
264-
window.swap_chain_update.set();
265-
core.windows.setValueRaw(block.context.window_id, window);
258+
var core_window = core.windows.getValue(block.context.window_id);
259+
260+
if (core_window.native) |native| {
261+
const native_window: *objc.app_kit.Window = native.window;
262+
263+
const frame = native_window.frame();
264+
265+
const content_rect = native_window.contentRectForFrameRect(frame);
266+
267+
core_window.width = @intFromFloat(content_rect.size.width);
268+
core_window.height = @intFromFloat(content_rect.size.height);
269+
core_window.swap_chain_update.set();
270+
}
271+
272+
core.windows.setValueRaw(block.context.window_id, core_window);
266273

267274
core.pushEvent(.{ .window_resize = .{
268275
.window_id = block.context.window_id,
269-
.size = s,
276+
.size = .{ .width = core_window.width, .height = core_window.height },
270277
} });
271278
}
272279

0 commit comments

Comments
 (0)