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:
parent
4e9fa46aec
commit
2b83300e0b
|
@ -17,15 +17,27 @@ static BOOL canQuit = NO;
|
||||||
// yes that's right folks: DO ABSOLUTELY NOTHING.
|
// yes that's right folks: DO ABSOLUTELY NOTHING.
|
||||||
// the magic is [NSApp run] will just... stop.
|
// 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
|
// for debugging
|
||||||
NSLog(@"in terminate:");
|
NSLog(@"in terminate:");
|
||||||
|
|
||||||
if (!canQuit)
|
if (!canQuit)
|
||||||
complain("call to [NSApp terminate:] when not ready to terminate");
|
complain("call to [NSApp terminate:] when not ready to terminate");
|
||||||
|
|
||||||
// TODO move the body of uiQuit() here
|
[NSApp stop:NSApp];
|
||||||
// TODO make uiQuit() just call terminate:
|
// stop: won't register until another event has passed; let's synthesize one
|
||||||
// TODO update the above comment
|
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
|
@end
|
||||||
|
@ -88,3 +100,14 @@ void uiUninit(void)
|
||||||
void uiFreeInitError(const char *err)
|
void uiFreeInitError(const char *err)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiMain(void)
|
||||||
|
{
|
||||||
|
[NSApp run];
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiQuit(void)
|
||||||
|
{
|
||||||
|
canQuit = YES;
|
||||||
|
[NSApp terminate:NSApp];
|
||||||
|
}
|
||||||
|
|
|
@ -1,25 +1,2 @@
|
||||||
// 6 april 2015
|
// 6 april 2015
|
||||||
#import "uipriv_darwin.h"
|
#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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ int onClosing(uiWindow *w, void *data)
|
||||||
int onShouldQuit(void *data)
|
int onShouldQuit(void *data)
|
||||||
{
|
{
|
||||||
printf("in onShouldQuit()\n");
|
printf("in onShouldQuit()\n");
|
||||||
|
uiControlDestroy(uiControl(data));
|
||||||
return uiMenuItemChecked(shouldQuitItem);
|
return uiMenuItemChecked(shouldQuitItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,12 +58,12 @@ int main(int argc, char *argv[])
|
||||||
if (!nomenus)
|
if (!nomenus)
|
||||||
initMenus();
|
initMenus();
|
||||||
|
|
||||||
uiOnShouldQuit(onShouldQuit, NULL);
|
|
||||||
|
|
||||||
w = newWindow("Main Window", 320, 240, 1);
|
w = newWindow("Main Window", 320, 240, 1);
|
||||||
uiWindowOnClosing(w, onClosing, NULL);
|
uiWindowOnClosing(w, onClosing, NULL);
|
||||||
printf("main window %p\n", w);
|
printf("main window %p\n", w);
|
||||||
|
|
||||||
|
uiOnShouldQuit(onShouldQuit, w);
|
||||||
|
|
||||||
mainBox = newHorizontalBox();
|
mainBox = newHorizontalBox();
|
||||||
uiWindowSetChild(w, uiControl(mainBox));
|
uiWindowSetChild(w, uiControl(mainBox));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue