mac: new event pumping architecture that sucks and i hate it but apple is happy with it so we're happy with it

This commit is contained in:
IoI_xD 2026-03-10 15:33:20 -07:00
commit 9f1b455341
2 changed files with 14 additions and 34 deletions

View file

@ -156,6 +156,7 @@
- (NSView *)getView; - (NSView *)getView;
- (MilskoCocoaWindow *)getWindow; - (MilskoCocoaWindow *)getWindow;
- (MilskoFakePointer *)getHandle; - (MilskoFakePointer *)getHandle;
+ (void)eventCanceller:(MilskoCocoa *)this;
@end @end
#define OBJC(x) x #define OBJC(x) x

View file

@ -142,9 +142,9 @@ static NSPoint pointFlip(NSPoint point) {
[c->application [c->application
setActivationPolicy:0 /* NSApplicationActivationPolicyRegular */]; setActivationPolicy:0 /* NSApplicationActivationPolicyRegular */];
} }
[c->window makeKeyAndOrderFront:nil];
[c->application activateIgnoringOtherApps:true]; [c->application activateIgnoringOtherApps:true];
[c->window makeFirstResponder:c->view]; [c->window makeFirstResponder:c->view];
[c->window makeKeyAndOrderFront:nil];
} }
[c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc] [c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc]
initWithAppl:c->application]]; initWithAppl:c->application]];
@ -172,6 +172,13 @@ static NSPoint pointFlip(NSPoint point) {
return c; return c;
} }
+ (void)eventCanceller:(MilskoCocoa *)this {
this->lastEvent = [this->application currentEvent];
[this eventProcess:this->lastEvent];
[[NSApplication sharedApplication] stop:nil];
}
- (void)polygonWithPoints:(MwPoint *)points - (void)polygonWithPoints:(MwPoint *)points
points_count:(int)points_count points_count:(int)points_count
color:(MwLLColor)color { color:(MwLLColor)color {
@ -269,42 +276,14 @@ static NSPoint pointFlip(NSPoint point) {
[self forceRender]; [self forceRender];
}; };
- (int)pending { - (int)pending {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [MilskoCocoa performSelectorOnMainThread:@selector(eventCanceller:)
MwBool isPending = MwFALSE; withObject:self
if (_forceRender) { waitUntilDone:NO];
_forceRender = MwFALSE; [self->application run];
[pool release]; return 1;
return 1;
}
self->lastEvent = [self->window nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode
dequeue:YES];
isPending = self->lastEvent != NULL;
[pool release];
return isPending;
}; };
- (void)getNextEvent { - (void)getNextEvent {
[self eventProcess:self->lastEvent];
while (true) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSEvent *ev = [self->window nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode
dequeue:YES];
if (!ev) {
[pool release];
break;
}
/* run through the switch case on ev.type, before calling sendEvent on any
* events we handle */
[self eventProcess:ev];
[pool release];
[self->application updateWindows];
}
[self sendClipboardEvent]; [self sendClipboardEvent];
if (self->pointerLocked && [self->window isMainWindow]) { if (self->pointerLocked && [self->window isMainWindow]) {