core: darwin: Add ability to detect and fire magnify event which is triggered by pinch to zoom on a trackpad

This commit is contained in:
foxnne 2024-12-12 09:43:12 -06:00 committed by Emi Gutekanst
parent 98c303aefc
commit ff11fd6d4c
2 changed files with 23 additions and 0 deletions

View file

@ -522,6 +522,10 @@ pub const Event = union(enum) {
window_open: struct { window_open: struct {
window_id: mach.ObjectID, window_id: mach.ObjectID,
}, },
magnify: struct {
window_id: mach.ObjectID,
magnification: f32,
},
focus_gained: struct { focus_gained: struct {
window_id: mach.ObjectID, window_id: mach.ObjectID,
}, },

View file

@ -209,6 +209,14 @@ fn initWindow(
); );
view.setBlock_flagsChanged(flagsChanged.asBlock().copy()); view.setBlock_flagsChanged(flagsChanged.asBlock().copy());
var magnify = objc.foundation.stackBlockLiteral(
ViewCallbacks.magnify,
context,
null,
null,
);
view.setBlock_magnify(magnify.asBlock().copy());
var mouseMoved = objc.foundation.stackBlockLiteral( var mouseMoved = objc.foundation.stackBlockLiteral(
ViewCallbacks.mouseMoved, ViewCallbacks.mouseMoved,
context, context,
@ -405,6 +413,17 @@ const ViewCallbacks = struct {
} }); } });
} }
// This is currently only supported on macOS using a trackpad
pub fn magnify(block: *objc.foundation.BlockLiteral(*Context), event: *objc.app_kit.Event) callconv(.C) void {
const core: *Core = block.context.core;
const window_id = block.context.window_id;
core.pushEvent(.{ .magnify = .{
.window_id = window_id,
.magnification = @floatCast(event.magnification()),
} });
}
pub fn keyDown(block: *objc.foundation.BlockLiteral(*Context), event: *objc.app_kit.Event) callconv(.C) void { pub fn keyDown(block: *objc.foundation.BlockLiteral(*Context), event: *objc.app_kit.Event) callconv(.C) void {
const core: *Core = block.context.core; const core: *Core = block.context.core;
const window_id = block.context.window_id; const window_id = block.context.window_id;