From 21d5625ec70fc4a76376b9727c13ee1f0c8bca4f Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Sun, 8 Mar 2026 20:03:47 -0700 Subject: [PATCH] fix forceRender, at the cost of breaking the rotate example --- src/backend/cocoa.m | 28 +++++++++++++++------------- src/widget/opengl_cocoa.m | 25 ++++++++----------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index 3e30503..169cb1c 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -140,6 +140,7 @@ static NSPoint pointFlip(NSPoint point) { c->rect.origin.y -= [p->window frame].origin.y - offset; c->rect.origin.y -= offset; } else { + [c->application setActivationPolicy:NSApplicationActivationPolicyRegular]; [c->application activateIgnoringOtherApps:true]; [c->window makeFirstResponder:c->view]; } @@ -279,7 +280,7 @@ static NSPoint pointFlip(NSPoint point) { }; - (void)getNextEvent { - + [self eventProcess:self->lastEvent]; while (true) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSEvent *ev = [self->window nextEventMatchingMask:NSAnyEventMask @@ -595,18 +596,19 @@ static NSPoint pointFlip(NSPoint point) { (void)pixmap; }; - (void)forceRender { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined - location:NSMakePoint(0, 0) - modifierFlags:0 - timestamp:0 - windowNumber:0 - context:nil - subtype:0 - data1:0 - data2:0]; - [NSApp postEvent:event atStart:YES]; - [pool release]; + self->_forceRender = MwTRUE; + // NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + // NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined + // location:NSMakePoint(0, 0) + // modifierFlags:0 + // timestamp:0 + // windowNumber:0 + // context:nil + // subtype:0 + // data1:0 + // data2:0]; + // [NSApp postEvent:event atStart:YES]; + // [pool release]; }; - (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask { (void)image; diff --git a/src/widget/opengl_cocoa.m b/src/widget/opengl_cocoa.m index c33e375..15c1198 100644 --- a/src/widget/opengl_cocoa.m +++ b/src/widget/opengl_cocoa.m @@ -1,5 +1,6 @@ #include "Mw/BaseTypes.h" #include "Mw/Core.h" +#include "Mw/LowLevel/Cocoa.h" #include "Mw/StringDefs.h" #include #include @@ -8,9 +9,10 @@ @interface MacOpenGLWidget : NSObject { NSOpenGLPixelFormat *pixelFormat; NSOpenGLContext *glc; + MilskoCocoa * _win; } -- (MacOpenGLWidget *)initWithView:(NSView *)view; +- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w; - (void)destroy; - (void)makeCurrent; - (void)swapBuffer; @@ -30,7 +32,7 @@ static int create(MwWidget handle) { printf("%d %d\n", width, height); handle->internal = [[MacOpenGLWidget alloc] - initWithView:[handle->lowlevel->cocoa.real getView]]; + initWithWindow:handle->lowlevel->cocoa.real]; handle->lowlevel->common.copy_buffer = 0; MwSetDefault(handle); @@ -75,7 +77,7 @@ static void func_handler(MwWidget handle, const char *name, void *out, @implementation MacOpenGLWidget -- (MacOpenGLWidget *)initWithView:(NSView *)view { +- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w { NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { NSOpenGLPFAColorSize, 24, NSOpenGLPFAStencilSize, 8, @@ -86,7 +88,8 @@ static void func_handler(MwWidget handle, const char *name, void *out, [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; self->glc = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil]; - [self->glc setView:view]; + [self->glc setView:[w getView]]; + self->_win = w; return self; }; - (void)destroy { @@ -95,19 +98,7 @@ static void func_handler(MwWidget handle, const char *name, void *out, [self->glc makeCurrentContext]; }; - (void)swapBuffer { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSEvent *event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined - location:NSMakePoint(0, 0) - modifierFlags:0 - timestamp:0 - windowNumber:0 - context:nil - subtype:0 - data1:0 - data2:0]; - [NSApp postEvent:event atStart:YES]; - [pool release]; - + [self->_win forceRender]; [self->glc flushBuffer]; }; - (void *)getProcAddressWithName:(const char *)name {