Implemented the quitting logic on OS X. Now I can get rid of darwin/main.m and move darwin/init.m in its place.

This commit is contained in:
Pietro Gagliardi 2015-05-09 10:18:19 -04:00
parent 4e9fa46aec
commit 2b83300e0b
3 changed files with 29 additions and 28 deletions

View File

@ -17,15 +17,27 @@ static BOOL canQuit = NO;
// yes that's right folks: DO ABSOLUTELY NOTHING.
// the magic is [NSApp run] will just... stop.
// well let's not do nothing; let's actually quit our graceful way
NSEvent *e;
// for debugging
NSLog(@"in terminate:");
if (!canQuit)
complain("call to [NSApp terminate:] when not ready to terminate");
// TODO move the body of uiQuit() here
// TODO make uiQuit() just call terminate:
// TODO update the above comment
[NSApp stop:NSApp];
// stop: won't register until another event has passed; let's synthesize one
e = [NSEvent otherEventWithType:NSApplicationDefined
location:NSZeroPoint
modifierFlags:0
timestamp:[[NSProcessInfo processInfo] systemUptime]
windowNumber:0
context:[NSGraphicsContext currentContext]
subtype:0
data1:0
data2:0];
[NSApp 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)
}
@end
@ -88,3 +100,14 @@ void uiUninit(void)
void uiFreeInitError(const char *err)
{
}
void uiMain(void)
{
[NSApp run];
}
void uiQuit(void)
{
canQuit = YES;
[NSApp terminate:NSApp];
}

View File

@ -1,25 +1,2 @@
// 6 april 2015
#import "uipriv_darwin.h"
void uiMain(void)
{
[NSApp run];
}
void uiQuit(void)
{
NSEvent *e;
[NSApp stop:NSApp];
// stop: won't register until another event has passed; let's synthesize one
e = [NSEvent otherEventWithType:NSApplicationDefined
location:NSZeroPoint
modifierFlags:0
timestamp:[[NSProcessInfo processInfo] systemUptime]
windowNumber:0
context:[NSGraphicsContext currentContext]
subtype:0
data1:0
data2:0];
[NSApp 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)
}

View File

@ -23,6 +23,7 @@ int onClosing(uiWindow *w, void *data)
int onShouldQuit(void *data)
{
printf("in onShouldQuit()\n");
uiControlDestroy(uiControl(data));
return uiMenuItemChecked(shouldQuitItem);
}
@ -57,12 +58,12 @@ int main(int argc, char *argv[])
if (!nomenus)
initMenus();
uiOnShouldQuit(onShouldQuit, NULL);
w = newWindow("Main Window", 320, 240, 1);
uiWindowOnClosing(w, onClosing, NULL);
printf("main window %p\n", w);
uiOnShouldQuit(onShouldQuit, w);
mainBox = newHorizontalBox();
uiWindowSetChild(w, uiControl(mainBox));