From 9f1b455341de321a146c6ba797d5c592b89e95e4 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Tue, 10 Mar 2026 15:33:20 -0700 Subject: [PATCH] mac: new event pumping architecture that sucks and i hate it but apple is happy with it so we're happy with it --- include/Mw/LowLevel/Cocoa.h | 1 + src/backend/cocoa.m | 47 ++++++++++--------------------------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index 5543d7e..445af0e 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -156,6 +156,7 @@ - (NSView *)getView; - (MilskoCocoaWindow *)getWindow; - (MilskoFakePointer *)getHandle; ++ (void)eventCanceller:(MilskoCocoa *)this; @end #define OBJC(x) x diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index fdf12c3..edf5cfd 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -142,9 +142,9 @@ static NSPoint pointFlip(NSPoint point) { [c->application setActivationPolicy:0 /* NSApplicationActivationPolicyRegular */]; } + [c->window makeKeyAndOrderFront:nil]; [c->application activateIgnoringOtherApps:true]; [c->window makeFirstResponder:c->view]; - [c->window makeKeyAndOrderFront:nil]; } [c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc] initWithAppl:c->application]]; @@ -172,6 +172,13 @@ static NSPoint pointFlip(NSPoint point) { return c; } ++ (void)eventCanceller:(MilskoCocoa *)this { + this->lastEvent = [this->application currentEvent]; + [this eventProcess:this->lastEvent]; + + [[NSApplication sharedApplication] stop:nil]; +} + - (void)polygonWithPoints:(MwPoint *)points points_count:(int)points_count color:(MwLLColor)color { @@ -269,42 +276,14 @@ static NSPoint pointFlip(NSPoint point) { [self forceRender]; }; - (int)pending { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - MwBool isPending = MwFALSE; - if (_forceRender) { - _forceRender = MwFALSE; - [pool release]; - return 1; - } - self->lastEvent = [self->window nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantPast] - inMode:NSDefaultRunLoopMode - dequeue:YES]; - - isPending = self->lastEvent != NULL; - [pool release]; - return isPending; + [MilskoCocoa performSelectorOnMainThread:@selector(eventCanceller:) + withObject:self + waitUntilDone:NO]; + [self->application run]; + return 1; }; - (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]; if (self->pointerLocked && [self->window isMainWindow]) {