2014-07-08 15:47:28 -05:00
|
|
|
// 8 july 2014
|
|
|
|
|
|
|
|
#import "objc_darwin.h"
|
|
|
|
#import "_cgo_export.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2014-07-20 16:27:56 -05:00
|
|
|
@interface appDelegateClass : NSObject <NSApplicationDelegate>
|
2014-07-08 15:47:28 -05:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation appDelegateClass
|
|
|
|
@end
|
|
|
|
|
|
|
|
appDelegateClass *appDelegate;
|
|
|
|
|
|
|
|
id getAppDelegate(void)
|
|
|
|
{
|
|
|
|
return appDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL uiinit(void)
|
|
|
|
{
|
|
|
|
appDelegate = [appDelegateClass new];
|
|
|
|
[NSApplication sharedApplication];
|
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
[NSApp activateIgnoringOtherApps:YES]; // TODO rsc does this; finder says NO?
|
|
|
|
[NSApp setDelegate:appDelegate];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uimsgloop(void)
|
|
|
|
{
|
|
|
|
[NSApp run];
|
|
|
|
}
|
|
|
|
|
2014-07-13 20:31:13 -05:00
|
|
|
// don't use [NSApp terminate:]; that quits the program
|
|
|
|
void uistop(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
|
|
|
|
}
|
|
|
|
|
|
|
|
// thanks to mikeash in irc.freenode.net/#macdev for suggesting the use of Grand Central Dispatch and blocks for this
|
2014-07-08 15:47:28 -05:00
|
|
|
void issue(void *what)
|
|
|
|
{
|
2014-07-08 15:50:52 -05:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
doissue(what);
|
|
|
|
});
|
2014-07-08 15:47:28 -05:00
|
|
|
}
|