summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-07-13 21:31:13 -0400
committerPietro Gagliardi <[email protected]>2014-07-13 21:31:13 -0400
commit0e7589af4718d8f90bbc007306c75c2a39386d2f (patch)
treead4ab0ea2764593900e08614157b38076e85ddfc
parent0eded3f7749a8a767a2002b52236c1c2e93363cb (diff)
Implemented Stop() on Mac OS X.
-rw-r--r--redo/objc_darwin.h1
-rw-r--r--redo/uitask_darwin.go4
-rw-r--r--redo/uitask_darwin.m21
3 files changed, 25 insertions, 1 deletions
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(), ^{