core: darwin: Document the command key fix
This commit is contained in:
parent
4a6101241c
commit
4ada021a15
1 changed files with 25 additions and 21 deletions
|
|
@ -134,11 +134,17 @@ fn initWindow(
|
||||||
window_id: mach.ObjectID,
|
window_id: mach.ObjectID,
|
||||||
) !void {
|
) !void {
|
||||||
var core_window = core.windows.getValue(window_id);
|
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
|
// 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
|
// by setting the activation policy, this moves the process to foreground
|
||||||
// TODO: Only call this on the first window creation
|
// TODO: Only call this on the first window creation
|
||||||
_ = objc.app_kit.Application.sharedApplication().setActivationPolicy(objc.app_kit.ApplicationActivationPolicyRegular);
|
_ = 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 {
|
const commandFn = struct {
|
||||||
pub fn commandFn(block: *objc.foundation.BlockLiteral(*Context), event: *objc.app_kit.Event) callconv(.C) ?*objc.app_kit.Event {
|
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;
|
const core_: *Core = block.context.core;
|
||||||
|
|
@ -154,9 +160,6 @@ fn initWindow(
|
||||||
}
|
}
|
||||||
}.commandFn;
|
}.commandFn;
|
||||||
|
|
||||||
const context = try core.allocator.create(Context);
|
|
||||||
context.* = .{ .core = core, .window_id = window_id };
|
|
||||||
|
|
||||||
var commandBlock = objc.foundation.stackBlockLiteral(
|
var commandBlock = objc.foundation.stackBlockLiteral(
|
||||||
commandFn,
|
commandFn,
|
||||||
context,
|
context,
|
||||||
|
|
@ -165,6 +168,7 @@ fn initWindow(
|
||||||
);
|
);
|
||||||
|
|
||||||
_ = objc.app_kit.Event.addLocalMonitorForEventsMatchingMask_handler(objc.app_kit.EventMaskKeyUp, commandBlock.asBlock().copy());
|
_ = objc.app_kit.Event.addLocalMonitorForEventsMatchingMask_handler(objc.app_kit.EventMaskKeyUp, commandBlock.asBlock().copy());
|
||||||
|
}
|
||||||
|
|
||||||
const metal_descriptor = try core.allocator.create(gpu.Surface.DescriptorFromMetalLayer);
|
const metal_descriptor = try core.allocator.create(gpu.Surface.DescriptorFromMetalLayer);
|
||||||
const layer = objc.quartz_core.MetalLayer.new();
|
const layer = objc.quartz_core.MetalLayer.new();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue