Added uiMainSteps(), which sets things up to use uiMainStep() for the main loop. Implemented on OS X.
This commit is contained in:
parent
b4d0e08a22
commit
da4b396aaf
|
@ -3,8 +3,11 @@
|
||||||
|
|
||||||
static BOOL canQuit = NO;
|
static BOOL canQuit = NO;
|
||||||
static NSAutoreleasePool *globalPool;
|
static NSAutoreleasePool *globalPool;
|
||||||
static applicationClass* app;
|
static applicationClass *app;
|
||||||
static appDelegate* delegate;
|
static appDelegate *delegate;
|
||||||
|
|
||||||
|
static BOOL (^isRunning)(void);
|
||||||
|
static BOOL stepsIsRunning;
|
||||||
|
|
||||||
@implementation applicationClass
|
@implementation applicationClass
|
||||||
|
|
||||||
|
@ -67,6 +70,9 @@ static appDelegate* delegate;
|
||||||
data1:0
|
data1:0
|
||||||
data2: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)
|
[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
|
@end
|
||||||
|
@ -147,9 +153,20 @@ void uiFreeInitError(const char *err)
|
||||||
|
|
||||||
void uiMain(void)
|
void uiMain(void)
|
||||||
{
|
{
|
||||||
|
isRunning = ^{
|
||||||
|
return [realNSApp() isRunning];
|
||||||
|
};
|
||||||
[realNSApp() run];
|
[realNSApp() run];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiMainSteps(void)
|
||||||
|
{
|
||||||
|
isRunning = ^{
|
||||||
|
return stepsIsRunning;
|
||||||
|
};
|
||||||
|
stepsIsRunning = YES;
|
||||||
|
}
|
||||||
|
|
||||||
// see also:
|
// see also:
|
||||||
// - http://www.cocoawithlove.com/2009/01/demystifying-nsapplication-by.html
|
// - http://www.cocoawithlove.com/2009/01/demystifying-nsapplication-by.html
|
||||||
// - https://github.com/gnustep/gui/blob/master/Source/NSApplication.m
|
// - 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
|
if (wait) // but this is normal so it will work
|
||||||
expire = [NSDate distantFuture];
|
expire = [NSDate distantFuture];
|
||||||
|
|
||||||
if (![realNSApp() isRunning])
|
if (!isRunning())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
e = [realNSApp() nextEventMatchingMask:NSAnyEventMask
|
e = [realNSApp() nextEventMatchingMask:NSAnyEventMask
|
||||||
|
|
|
@ -161,9 +161,11 @@ int main(int argc, char *argv[])
|
||||||
uiControlShow(uiControl(w));
|
uiControlShow(uiControl(w));
|
||||||
if (!steps)
|
if (!steps)
|
||||||
uiMain();
|
uiMain();
|
||||||
else
|
else {
|
||||||
|
uiMainSteps();
|
||||||
while (uiMainStep(1))
|
while (uiMainStep(1))
|
||||||
;
|
;
|
||||||
|
}
|
||||||
printf("after uiMain()\n");
|
printf("after uiMain()\n");
|
||||||
uiUninit();
|
uiUninit();
|
||||||
printf("after uiUninit()\n");
|
printf("after uiUninit()\n");
|
||||||
|
|
1
ui.h
1
ui.h
|
@ -45,6 +45,7 @@ _UI_EXTERN void uiUninit(void);
|
||||||
_UI_EXTERN void uiFreeInitError(const char *err);
|
_UI_EXTERN void uiFreeInitError(const char *err);
|
||||||
|
|
||||||
_UI_EXTERN void uiMain(void);
|
_UI_EXTERN void uiMain(void);
|
||||||
|
_UI_EXTERN void uiMainSteps(void);
|
||||||
_UI_EXTERN int uiMainStep(int wait);
|
_UI_EXTERN int uiMainStep(int wait);
|
||||||
_UI_EXTERN void uiQuit(void);
|
_UI_EXTERN void uiQuit(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue