darwin: windowWillResize_toSize -> windowDidResize, fixes a bug where window size didn't include titlebar height. Depends on https://github.com/hexops/mach-objc/pull/30

This commit is contained in:
foxnne 2024-12-06 13:02:39 -06:00 committed by Emi Gutekanst
parent 14dee01b43
commit 059a271b3b

View file

@ -135,9 +135,7 @@ fn initWindow(
const layer = objc.quartz_core.MetalLayer.new(); const layer = objc.quartz_core.MetalLayer.new();
defer layer.release(); defer layer.release();
if (core_window.color == .transparent) { if (core_window.color == .transparent) layer.setOpaque(false);
layer.setOpaque(false);
}
metal_descriptor.* = .{ metal_descriptor.* = .{
.layer = layer, .layer = layer,
@ -228,13 +226,13 @@ fn initWindow(
const delegate = objc.mach.WindowDelegate.allocInit(); const delegate = objc.mach.WindowDelegate.allocInit();
defer native_window.setDelegate(@ptrCast(delegate)); defer native_window.setDelegate(@ptrCast(delegate));
{ {
var windowWillResize_toSize = objc.foundation.stackBlockLiteral( var windowDidResize = objc.foundation.stackBlockLiteral(
WindowDelegateCallbacks.windowWillResize_toSize, WindowDelegateCallbacks.windowDidResize,
context, context,
null, null,
null, null,
); );
delegate.setBlock_windowWillResize_toSize(windowWillResize_toSize.asBlock().copy()); delegate.setBlock_windowDidResize(windowDidResize.asBlock().copy());
var windowShouldClose = objc.foundation.stackBlockLiteral( var windowShouldClose = objc.foundation.stackBlockLiteral(
WindowDelegateCallbacks.windowShouldClose, WindowDelegateCallbacks.windowShouldClose,
@ -254,19 +252,28 @@ fn initWindow(
} }
const WindowDelegateCallbacks = struct { const WindowDelegateCallbacks = struct {
pub fn windowWillResize_toSize(block: *objc.foundation.BlockLiteral(*Context), size: objc.app_kit.Size) callconv(.C) void { pub fn windowDidResize(block: *objc.foundation.BlockLiteral(*Context)) callconv(.C) void {
const core: *Core = block.context.core; const core: *Core = block.context.core;
const s: Size = .{ .width = @intFromFloat(size.width), .height = @intFromFloat(size.height) };
var window = core.windows.getValue(block.context.window_id); var core_window = core.windows.getValue(block.context.window_id);
window.width = s.width;
window.height = s.height; if (core_window.native) |native| {
window.swap_chain_update.set(); const native_window: *objc.app_kit.Window = native.window;
core.windows.setValueRaw(block.context.window_id, window);
const frame = native_window.frame();
const content_rect = native_window.contentRectForFrameRect(frame);
core_window.width = @intFromFloat(content_rect.size.width);
core_window.height = @intFromFloat(content_rect.size.height);
core_window.swap_chain_update.set();
}
core.windows.setValueRaw(block.context.window_id, core_window);
core.pushEvent(.{ .window_resize = .{ core.pushEvent(.{ .window_resize = .{
.window_id = block.context.window_id, .window_id = block.context.window_id,
.size = s, .size = .{ .width = core_window.width, .height = core_window.height },
} }); } });
} }