Added uiMainSteps(), which sets things up to use uiMainStep() for the main loop. Implemented on OS X.

This commit is contained in:
Pietro Gagliardi 2016-06-16 13:45:24 -04:00
parent b4d0e08a22
commit da4b396aaf
3 changed files with 24 additions and 4 deletions

View File

@ -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

View File

@ -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");

1
ui.h
View File

@ -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);