core: darwin: Document the command key fix

This commit is contained in:
foxnne 2024-12-13 09:43:19 -06:00 committed by Emi Gutekanst
parent 4a6101241c
commit 4ada021a15

View file

@ -134,11 +134,17 @@ fn initWindow(
window_id: mach.ObjectID,
) !void {
var core_window = core.windows.getValue(window_id);
const context = try core.allocator.create(Context);
context.* = .{ .core = core, .window_id = window_id };
// If the application is not headless, we need to make the application a genuine UI application
// by setting the activation policy, this moves the process to foreground
// TODO: Only call this on the first window creation
_ = objc.app_kit.Application.sharedApplication().setActivationPolicy(objc.app_kit.ApplicationActivationPolicyRegular);
{
// On macos, the command key in particular seems to be handled a bit differently and tends to block the `keyUp` event
// from firing. To remedy this, we borrow the same fix GLFW uses and add a monitor.
const commandFn = struct {
pub fn commandFn(block: *objc.foundation.BlockLiteral(*Context), event: *objc.app_kit.Event) callconv(.C) ?*objc.app_kit.Event {
const core_: *Core = block.context.core;
@ -154,9 +160,6 @@ fn initWindow(
}
}.commandFn;
const context = try core.allocator.create(Context);
context.* = .{ .core = core, .window_id = window_id };
var commandBlock = objc.foundation.stackBlockLiteral(
commandFn,
context,
@ -165,6 +168,7 @@ fn initWindow(
);
_ = objc.app_kit.Event.addLocalMonitorForEventsMatchingMask_handler(objc.app_kit.EventMaskKeyUp, commandBlock.asBlock().copy());
}
const metal_descriptor = try core.allocator.create(gpu.Surface.DescriptorFromMetalLayer);
const layer = objc.quartz_core.MetalLayer.new();