diff options
| -rw-r--r-- | delegateuitask_darwin.m | 19 | ||||
| -rw-r--r-- | objc_darwin.h | 1 | ||||
| -rw-r--r-- | uitask_darwin.go | 23 |
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 { |
