From 0e7589af4718d8f90bbc007306c75c2a39386d2f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 13 Jul 2014 21:31:13 -0400 Subject: [PATCH] Implemented Stop() on Mac OS X. --- redo/objc_darwin.h | 1 + redo/uitask_darwin.go | 4 ++++ redo/uitask_darwin.m | 21 ++++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h index 3b33e26..3de8a29 100644 --- a/redo/objc_darwin.h +++ b/redo/objc_darwin.h @@ -14,6 +14,7 @@ extern id getAppDelegate(void); /* used by the other .m files */ extern BOOL uiinit(void); extern void uimsgloop(void); +extern void uistop(void); extern void issue(void *); /* window_darwin.m */ diff --git a/redo/uitask_darwin.go b/redo/uitask_darwin.go index da9a47b..45fa8d1 100644 --- a/redo/uitask_darwin.go +++ b/redo/uitask_darwin.go @@ -21,6 +21,10 @@ func uimsgloop() { C.uimsgloop() } +func uistop() { + C.uistop() +} + func issue(req *Request) { C.issue(unsafe.Pointer(req)) } diff --git a/redo/uitask_darwin.m b/redo/uitask_darwin.m index faf78a2..842f991 100644 --- a/redo/uitask_darwin.m +++ b/redo/uitask_darwin.m @@ -32,7 +32,26 @@ void uimsgloop(void) [NSApp run]; } -// thanks to mikeash in irc.freenode.net/#macdev for suggesting the use of Grand Dispatch and blocks for this +// 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 void issue(void *what) { dispatch_async(dispatch_get_main_queue(), ^{