summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-07-03 11:53:21 -0400
committerPietro Gagliardi <[email protected]>2014-07-03 11:53:21 -0400
commitb460466e4b7d479a015bb686adb42056ef189abe (patch)
treef2b729088df05276473d291a70e7bdc785ebe998
parent1287ba89682b98b4196db7b9f81569f2abdb5761 (diff)
Implemented Post() on Mac OS X.
-rw-r--r--delegateuitask_darwin.m19
-rw-r--r--objc_darwin.h1
-rw-r--r--uitask_darwin.go23
3 files changed, 43 insertions, 0 deletions
diff --git a/delegateuitask_darwin.m b/delegateuitask_darwin.m
index a1f9501..94051c0 100644
--- a/delegateuitask_darwin.m
+++ b/delegateuitask_darwin.m
@@ -56,6 +56,13 @@ extern NSRect dummyRect;
@implementation appDelegate
+- (void)uipost:(id)pv
+{
+ NSValue *v = (NSValue *) pv;
+
+ appDelegate_uipost([v pointerValue]);
+}
+
- (BOOL)windowShouldClose:(id)win
{
return appDelegate_windowShouldClose(win);
@@ -123,6 +130,18 @@ BOOL initCocoa(id appDelegate)
return YES;
}
+void uipost(id appDelegate, void *data)
+{
+ // need an autorelease pool here
+ NSAutoreleasePool *pool;
+
+ pool = [NSAutoreleasePool new];
+ [appDelegate performSelectorOnMainThread:@selector(uipost:)
+ withObject:[NSValue valueWithPointer:data]
+ waitUntilDone:YES]; // note this bit; see uitask_darwin.go for details
+ [pool release];
+}
+
void breakMainLoop(void)
{
NSEvent *e;
diff --git a/objc_darwin.h b/objc_darwin.h
index eda09c4..0068d89 100644
--- a/objc_darwin.h
+++ b/objc_darwin.h
@@ -63,6 +63,7 @@ extern uintptr_t keyCode(id);
extern id makeAppDelegate(void);
extern id windowGetContentView(id);
extern BOOL initCocoa(id);
+extern void uipost(id, void *);
extern void breakMainLoop(void);
extern void cocoaMainLoop(void);
diff --git a/uitask_darwin.go b/uitask_darwin.go
index d4bc842..d9292ff 100644
--- a/uitask_darwin.go
+++ b/uitask_darwin.go
@@ -4,6 +4,7 @@ package ui
import (
"fmt"
+ "unsafe"
)
// #cgo CFLAGS: -mmacosx-version-min=10.7 -DMACOSX_DEPLOYMENT_TARGET=10.7
@@ -32,6 +33,28 @@ func ui() {
C.cocoaMainLoop()
}
+// we're going to call the appDelegate selector with waitUntilDone:YES so we don't have to worry about garbage collection
+// we DO need to collect the two pointers together, though
+
+type uipostmsg struct {
+ w *Window
+ data interface{}
+}
+
+//export appDelegate_uipost
+func appDelegate_uipost(xmsg unsafe.Pointer) {
+ msg := (*uipostmsg)(xmsg)
+ msg.w.sysData.post(msg.data)
+}
+
+func uipost(w *Window, data interface{}) {
+ msg := &uipostmsg{
+ w: w,
+ data: data,
+ }
+ C.uipost(appDelegate, unsafe.Pointer(msg))
+}
+
func initCocoa() (err error) {
makeAppDelegate()
if C.initCocoa(appDelegate) != C.YES {