diff --git a/darwin/main.m b/darwin/main.m index 97821201..2c934330 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -3,8 +3,11 @@ static BOOL canQuit = NO; static NSAutoreleasePool *globalPool; -static applicationClass* app; -static appDelegate* delegate; +static applicationClass *app; +static appDelegate *delegate; + +static BOOL (^isRunning)(void); +static BOOL stepsIsRunning; @implementation applicationClass @@ -67,6 +70,9 @@ static appDelegate* delegate; data1:0 data2:0]; [realNSApp() postEvent:e atStart:NO]; // let pending events take priority (this is what PostQuitMessage() on Windows does so we have to do it here too for parity; thanks to mikeash in irc.freenode.net/#macdev for confirming that this parameter should indeed be NO) + + // and in case uiMainSteps() was called + stepsIsRunning = NO; } @end @@ -147,9 +153,20 @@ void uiFreeInitError(const char *err) void uiMain(void) { + isRunning = ^{ + return [realNSApp() isRunning]; + }; [realNSApp() run]; } +void uiMainSteps(void) +{ + isRunning = ^{ + return stepsIsRunning; + }; + stepsIsRunning = YES; +} + // see also: // - http://www.cocoawithlove.com/2009/01/demystifying-nsapplication-by.html // - https://github.com/gnustep/gui/blob/master/Source/NSApplication.m @@ -166,7 +183,7 @@ int uiMainStep(int wait) if (wait) // but this is normal so it will work expire = [NSDate distantFuture]; - if (![realNSApp() isRunning]) + if (!isRunning()) return 0; e = [realNSApp() nextEventMatchingMask:NSAnyEventMask diff --git a/test/main.c b/test/main.c index d5e31bf6..803326b5 100644 --- a/test/main.c +++ b/test/main.c @@ -161,9 +161,11 @@ int main(int argc, char *argv[]) uiControlShow(uiControl(w)); if (!steps) uiMain(); - else + else { + uiMainSteps(); while (uiMainStep(1)) ; + } printf("after uiMain()\n"); uiUninit(); printf("after uiUninit()\n"); diff --git a/ui.h b/ui.h index f6d6dd83..6b7a1e8b 100644 --- a/ui.h +++ b/ui.h @@ -45,6 +45,7 @@ _UI_EXTERN void uiUninit(void); _UI_EXTERN void uiFreeInitError(const char *err); _UI_EXTERN void uiMain(void); +_UI_EXTERN void uiMainSteps(void); _UI_EXTERN int uiMainStep(int wait); _UI_EXTERN void uiQuit(void);