Skip to content

Commit 860cfb5

Browse files
foxnneemidoots
authored andcommitted
Add necessary generation to fix cursors and workaround for command key blocking keyUp
1 parent 1e5b394 commit 860cfb5

File tree

2 files changed

+97
-63
lines changed

2 files changed

+97
-63
lines changed

generator.zig

+28-3
Original file line numberDiff line numberDiff line change
@@ -1929,12 +1929,35 @@ fn generateAppKit(generator: anytype) !void {
19291929
[2][]const u8{ "NSWindow", "backgroundColor" },
19301930
[2][]const u8{ "NSWindow", "setBackgroundColor" },
19311931
[2][]const u8{ "NSWindow", "backingScaleFactor" },
1932+
[2][]const u8{ "NSWindow", "setAppearance" },
1933+
[2][]const u8{ "NSWindow", "sendEvent" },
1934+
1935+
[2][]const u8{ "NSCursor", "hide" },
1936+
[2][]const u8{ "NSCursor", "unhide" },
1937+
[2][]const u8{ "NSCursor", "pop" },
1938+
[2][]const u8{ "NSCursor", "push" },
1939+
[2][]const u8{ "NSCursor", "arrowCursor" },
1940+
[2][]const u8{ "NSCursor", "IBeamCursor" },
1941+
[2][]const u8{ "NSCursor", "pointingHandCursor" },
1942+
[2][]const u8{ "NSCursor", "closedHandCursor" },
1943+
[2][]const u8{ "NSCursor", "openHandCursor" },
1944+
[2][]const u8{ "NSCursor", "resizeLeftCursor" },
1945+
[2][]const u8{ "NSCursor", "resizeRightCursor" },
1946+
[2][]const u8{ "NSCursor", "resizeLeftRightCursor" },
1947+
[2][]const u8{ "NSCursor", "resizeUpCursor" },
1948+
[2][]const u8{ "NSCursor", "resizeDownCursor" },
1949+
[2][]const u8{ "NSCursor", "resizeUpDownCursor" },
1950+
[2][]const u8{ "NSCursor", "crosshairCursor" },
1951+
[2][]const u8{ "NSCursor", "operationNotAllowedCursor" },
1952+
1953+
[2][]const u8{ "NSAppearance", "appearanceNamed" },
19321954

19331955
[2][]const u8{ "NSWindowDelegate", "windowWillResize:toSize" },
19341956

19351957
[2][]const u8{ "NSView", "layer" },
19361958
[2][]const u8{ "NSView", "setLayer" },
19371959
[2][]const u8{ "NSView", "initWithFrame" },
1960+
[2][]const u8{ "NSView", "sendEvent" },
19381961

19391962
[2][]const u8{ "NSColor", "colorWithRed:green:blue:alpha" },
19401963

@@ -1950,6 +1973,8 @@ fn generateAppKit(generator: anytype) !void {
19501973
[2][]const u8{ "NSEvent", "scrollingDeltaY" },
19511974
[2][]const u8{ "NSEvent", "hasPreciseScrollingDeltas" },
19521975
[2][]const u8{ "NSEvent", "magnification" },
1976+
[2][]const u8{ "NSEvent", "phase" },
1977+
[2][]const u8{ "NSEvent", "addLocalMonitorForEventsMatchingMask:handler" },
19531978

19541979
[2][]const u8{ "NSDictionary", "" },
19551980

@@ -1985,7 +2010,7 @@ fn generateAppKit(generator: anytype) !void {
19852010
// try generator.addInterface("NSException");
19862011
// try generator.addInterface("NSImage");
19872012
// try generator.addInterface("NSDockTile");
1988-
// try generator.addInterface("NSAppearance");
2013+
try generator.addInterface("NSAppearance");
19892014
try generator.addInterface("NSEvent");
19902015
// try generator.addInterface("NSDate");
19912016
// try generator.addInterface("NSGraphicsContext");
@@ -2084,7 +2109,7 @@ fn generateAppKit(generator: anytype) !void {
20842109
// try generator.addEnum("NSApplicationDelegateReply");
20852110
// try generator.addEnum("NSApplicationPresentationOptions");
20862111
// try generator.addEnum("NSApplicationOcclusionState");
2087-
// try generator.addEnum("NSEventMask");
2112+
try generator.addEnum("NSEventMask");
20882113
// try generator.addEnum("NSRemoteNotificationType");
20892114
// try generator.addEnum("NSUserInterfaceLayoutDirection");
20902115
// try generator.addEnum("NSSaveOperationType");
@@ -2118,7 +2143,7 @@ fn generateAppKit(generator: anytype) !void {
21182143
// try generator.addEnum("NSEventButtonMask");
21192144
// try generator.addEnum("NSEventGestureAxis");
21202145
try generator.addEnum("NSEventModifierFlags");
2121-
// try generator.addEnum("NSEventPhase");
2146+
try generator.addEnum("NSEventPhase");
21222147
// try generator.addEnum("NSEventSubtype");
21232148
// try generator.addEnum("NSEventSwipeTrackingOptions");
21242149
// try generator.addEnum("NSEventType");

src/app_kit.zig

+69-60
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,42 @@ pub const ApplicationActivationPolicyRegular: ApplicationActivationPolicy = 0;
7171
pub const ApplicationActivationPolicyAccessory: ApplicationActivationPolicy = 0;
7272
pub const ApplicationActivationPolicyProhibited: ApplicationActivationPolicy = 0;
7373

74+
pub const EventMask = c_ulonglong;
75+
pub const EventMaskLeftMouseDown: EventMask = 2;
76+
pub const EventMaskLeftMouseUp: EventMask = 4;
77+
pub const EventMaskRightMouseDown: EventMask = 8;
78+
pub const EventMaskRightMouseUp: EventMask = 16;
79+
pub const EventMaskMouseMoved: EventMask = 32;
80+
pub const EventMaskLeftMouseDragged: EventMask = 64;
81+
pub const EventMaskRightMouseDragged: EventMask = 128;
82+
pub const EventMaskMouseEntered: EventMask = 256;
83+
pub const EventMaskMouseExited: EventMask = 512;
84+
pub const EventMaskKeyDown: EventMask = 1024;
85+
pub const EventMaskKeyUp: EventMask = 2048;
86+
pub const EventMaskFlagsChanged: EventMask = 4096;
87+
pub const EventMaskAppKitDefined: EventMask = 8192;
88+
pub const EventMaskSystemDefined: EventMask = 16384;
89+
pub const EventMaskApplicationDefined: EventMask = 32768;
90+
pub const EventMaskPeriodic: EventMask = 65536;
91+
pub const EventMaskCursorUpdate: EventMask = 131072;
92+
pub const EventMaskScrollWheel: EventMask = 4194304;
93+
pub const EventMaskTabletPoint: EventMask = 8388608;
94+
pub const EventMaskTabletProximity: EventMask = 16777216;
95+
pub const EventMaskOtherMouseDown: EventMask = 33554432;
96+
pub const EventMaskOtherMouseUp: EventMask = 67108864;
97+
pub const EventMaskOtherMouseDragged: EventMask = 134217728;
98+
pub const EventMaskGesture: EventMask = 536870912;
99+
pub const EventMaskMagnify: EventMask = 1073741824;
100+
pub const EventMaskSwipe: EventMask = 2147483648;
101+
pub const EventMaskRotate: EventMask = 262144;
102+
pub const EventMaskBeginGesture: EventMask = 524288;
103+
pub const EventMaskEndGesture: EventMask = 1048576;
104+
pub const EventMaskSmartMagnify: EventMask = 4294967296;
105+
pub const EventMaskPressure: EventMask = 17179869184;
106+
pub const EventMaskDirectTouch: EventMask = 137438953472;
107+
pub const EventMaskChangeMode: EventMask = 274877906944;
108+
pub const EventMaskAny: EventMask = 0;
109+
74110
pub const BackingStoreType = UInteger;
75111
pub const BackingStoreRetained: BackingStoreType = 0;
76112
pub const BackingStoreNonretained: BackingStoreType = 1;
@@ -87,6 +123,15 @@ pub const EventModifierFlagHelp: EventModifierFlags = 4194304;
87123
pub const EventModifierFlagFunction: EventModifierFlags = 8388608;
88124
pub const EventModifierFlagDeviceIndependentFlagsMask: EventModifierFlags = 4294901760;
89125

126+
pub const EventPhase = UInteger;
127+
pub const EventPhaseNone: EventPhase = 0;
128+
pub const EventPhaseBegan: EventPhase = 1;
129+
pub const EventPhaseStationary: EventPhase = 2;
130+
pub const EventPhaseChanged: EventPhase = 4;
131+
pub const EventPhaseEnded: EventPhase = 8;
132+
pub const EventPhaseCancelled: EventPhase = 16;
133+
pub const EventPhaseMayBegin: EventPhase = 32;
134+
90135
pub const WindowStyleMask = UInteger;
91136
pub const WindowStyleMaskBorderless: WindowStyleMask = 0;
92137
pub const WindowStyleMaskTitled: WindowStyleMask = 1;
@@ -216,6 +261,9 @@ pub const Window = opaque {
216261
pub fn setMinSize(self_: *@This(), minSize_: Size) void {
217262
return objc.msgSend(self_, "setMinSize:", void, .{minSize_});
218263
}
264+
pub fn sendEvent(self_: *@This(), event_: *Event) void {
265+
return objc.msgSend(self_, "sendEvent:", void, .{event_});
266+
}
219267
pub fn setIsVisible(self_: *@This(), flag_: bool) void {
220268
return objc.msgSend(self_, "setIsVisible:", void, .{flag_});
221269
}
@@ -265,6 +313,21 @@ pub const ObjectInterface = opaque {
265313
}
266314
};
267315

316+
pub const Appearance = opaque {
317+
pub const InternalInfo = objc.ExternClass("NSAppearance", @This(), ObjectInterface, &.{});
318+
pub const as = InternalInfo.as;
319+
pub const retain = InternalInfo.retain;
320+
pub const release = InternalInfo.release;
321+
pub const autorelease = InternalInfo.autorelease;
322+
pub const new = InternalInfo.new;
323+
pub const alloc = InternalInfo.alloc;
324+
pub const allocInit = InternalInfo.allocInit;
325+
326+
pub fn appearanceNamed(name_: *String) ?*Appearance {
327+
return objc.msgSend(@This().InternalInfo.class(), "appearanceNamed:", ?*Appearance, .{name_});
328+
}
329+
};
330+
268331
pub const Event = opaque {
269332
pub const InternalInfo = objc.ExternClass("NSEvent", @This(), ObjectInterface, &.{});
270333
pub const as = InternalInfo.as;
@@ -275,6 +338,9 @@ pub const Event = opaque {
275338
pub const alloc = InternalInfo.alloc;
276339
pub const allocInit = InternalInfo.allocInit;
277340

341+
pub fn addLocalMonitorForEventsMatchingMask_handler(mask_: EventMask, block_: *ns.Block(fn (*Event) ?*Event)) ?*objc.Id {
342+
return objc.msgSend(@This().InternalInfo.class(), "addLocalMonitorForEventsMatchingMask:handler:", ?*objc.Id, .{ mask_, block_ });
343+
}
278344
pub fn modifierFlags(self_: *@This()) EventModifierFlags {
279345
return objc.msgSend(self_, "modifierFlags", EventModifierFlags, .{});
280346
}
@@ -302,6 +368,9 @@ pub const Event = opaque {
302368
pub fn magnification(self_: *@This()) cg.Float {
303369
return objc.msgSend(self_, "magnification", cg.Float, .{});
304370
}
371+
pub fn phase(self_: *@This()) EventPhase {
372+
return objc.msgSend(self_, "phase", EventPhase, .{});
373+
}
305374
// pub fn modifierFlags() EventModifierFlags {
306375
// return objc.msgSend(@This().InternalInfo.class(), "modifierFlags", EventModifierFlags, .{});
307376
// }
@@ -356,21 +425,12 @@ pub const Cursor = opaque {
356425
pub const alloc = InternalInfo.alloc;
357426
pub const allocInit = InternalInfo.allocInit;
358427

359-
// pub fn initWithImage_hotSpot(self_: *@This(), newImage_: *Image, point_: Point) *@This() {
360-
// return objc.msgSend(self_, "initWithImage:hotSpot:", *@This(), .{ newImage_, point_ });
361-
// }
362-
// pub fn initWithCoder(self_: *@This(), coder_: *Coder) *@This() {
363-
// return objc.msgSend(self_, "initWithCoder:", *@This(), .{coder_});
364-
// }
365428
pub fn hide() void {
366429
return objc.msgSend(@This().InternalInfo.class(), "hide", void, .{});
367430
}
368431
pub fn unhide() void {
369432
return objc.msgSend(@This().InternalInfo.class(), "unhide", void, .{});
370433
}
371-
pub fn setHiddenUntilMouseMoves(flag_: bool) void {
372-
return objc.msgSend(@This().InternalInfo.class(), "setHiddenUntilMouseMoves:", void, .{flag_});
373-
}
374434
pub fn pop() void {
375435
return objc.msgSend(@This().InternalInfo.class(), "pop", void, .{});
376436
}
@@ -380,15 +440,6 @@ pub const Cursor = opaque {
380440
// pub fn pop(self_: *@This()) void {
381441
// return objc.msgSend(self_, "pop", void, .{});
382442
// }
383-
pub fn set(self_: *@This()) void {
384-
return objc.msgSend(self_, "set", void, .{});
385-
}
386-
pub fn currentCursor() *Cursor {
387-
return objc.msgSend(@This().InternalInfo.class(), "currentCursor", *Cursor, .{});
388-
}
389-
pub fn currentSystemCursor() *Cursor {
390-
return objc.msgSend(@This().InternalInfo.class(), "currentSystemCursor", *Cursor, .{});
391-
}
392443
pub fn arrowCursor() *Cursor {
393444
return objc.msgSend(@This().InternalInfo.class(), "arrowCursor", *Cursor, .{});
394445
}
@@ -425,51 +476,9 @@ pub const Cursor = opaque {
425476
pub fn crosshairCursor() *Cursor {
426477
return objc.msgSend(@This().InternalInfo.class(), "crosshairCursor", *Cursor, .{});
427478
}
428-
pub fn disappearingItemCursor() *Cursor {
429-
return objc.msgSend(@This().InternalInfo.class(), "disappearingItemCursor", *Cursor, .{});
430-
}
431479
pub fn operationNotAllowedCursor() *Cursor {
432480
return objc.msgSend(@This().InternalInfo.class(), "operationNotAllowedCursor", *Cursor, .{});
433481
}
434-
pub fn dragLinkCursor() *Cursor {
435-
return objc.msgSend(@This().InternalInfo.class(), "dragLinkCursor", *Cursor, .{});
436-
}
437-
pub fn dragCopyCursor() *Cursor {
438-
return objc.msgSend(@This().InternalInfo.class(), "dragCopyCursor", *Cursor, .{});
439-
}
440-
pub fn contextualMenuCursor() *Cursor {
441-
return objc.msgSend(@This().InternalInfo.class(), "contextualMenuCursor", *Cursor, .{});
442-
}
443-
pub fn IBeamCursorForVerticalLayout() *Cursor {
444-
return objc.msgSend(@This().InternalInfo.class(), "IBeamCursorForVerticalLayout", *Cursor, .{});
445-
}
446-
// pub fn image(self_: *@This()) *Image {
447-
// return objc.msgSend(self_, "image", *Image, .{});
448-
// }
449-
pub fn hotSpot(self_: *@This()) Point {
450-
return objc.msgSend(self_, "hotSpot", Point, .{});
451-
}
452-
// pub fn initWithImage_foregroundColorHint_backgroundColorHint_hotSpot(self_: *@This(), newImage_: *Image, fg_: ?*Color, bg_: ?*Color, hotSpot_: Point) *@This() {
453-
// return objc.msgSend(self_, "initWithImage:foregroundColorHint:backgroundColorHint:hotSpot:", *@This(), .{ newImage_, fg_, bg_, hotSpot_ });
454-
// }
455-
pub fn setOnMouseExited(self_: *@This(), flag_: bool) void {
456-
return objc.msgSend(self_, "setOnMouseExited:", void, .{flag_});
457-
}
458-
pub fn setOnMouseEntered(self_: *@This(), flag_: bool) void {
459-
return objc.msgSend(self_, "setOnMouseEntered:", void, .{flag_});
460-
}
461-
pub fn mouseEntered(self_: *@This(), event_: *Event) void {
462-
return objc.msgSend(self_, "mouseEntered:", void, .{event_});
463-
}
464-
pub fn mouseExited(self_: *@This(), event_: *Event) void {
465-
return objc.msgSend(self_, "mouseExited:", void, .{event_});
466-
}
467-
pub fn isSetOnMouseExited(self_: *@This()) bool {
468-
return objc.msgSend(self_, "isSetOnMouseExited", bool, .{});
469-
}
470-
pub fn isSetOnMouseEntered(self_: *@This()) bool {
471-
return objc.msgSend(self_, "isSetOnMouseEntered", bool, .{});
472-
}
473482
};
474483

475484
pub const Screen = opaque {

0 commit comments

Comments
 (0)