summaryrefslogtreecommitdiff
path: root/uitask_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'uitask_darwin.go')
-rw-r--r--uitask_darwin.go35
1 files changed, 3 insertions, 32 deletions
diff --git a/uitask_darwin.go b/uitask_darwin.go
index 2a32f86..493fd8c 100644
--- a/uitask_darwin.go
+++ b/uitask_darwin.go
@@ -7,17 +7,8 @@ import (
"unsafe"
)
-/*
-We will create an Objective-C class goAppDelegate. It contains two methods:
- - (void)applicationDidFinishLoading:(NSNotification *)unused
- will signal to ui() that we are now in the Cocoa event loop; we make our goAppDelegate instance the NSApplication delegate
- - (void)uitask:(NSValue *)functionPointer
- the function that actually performs our UI task functions; it is called with NSObject's performSelectorOnMainThread system
-*/
-
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
// #include "objc_darwin.h"
-// extern void appDelegate_uitask(id, SEL, id);
import "C"
// temporary for now
@@ -30,7 +21,6 @@ var (
_NSAutoreleasePool = objc_getClass("NSAutoreleasePool")
_NSValue = objc_getClass("NSValue")
- _uitask = sel_getUid("uitask:")
_valueWithPointer = sel_getUid("valueWithPointer:")
_performSelectorOnMainThread =
sel_getUid("performSelectorOnMainThread:withObject:waitUntilDone:")
@@ -43,7 +33,7 @@ func ui(main func()) error {
uitask = make(chan func())
- NSApp, appDelegate, err := initCocoa()
+ NSApp, err := initCocoa()
if err != nil {
return err
}
@@ -73,34 +63,15 @@ func ui(main func()) error {
// TODO move to init_darwin.go?
-const (
- _goAppDelegate = "goAppDelegate"
-)
-
var (
_NSApplication = objc_getClass("NSApplication")
_sharedApplication = sel_getUid("sharedApplication")
)
-func initCocoa() (NSApp C.id, appDelegate C.id, err error) {
- var appdelegateclass C.Class
-
+func initCocoa() (NSApp C.id, err error) {
NSApp = C.objc_msgSend_noargs(_NSApplication, _sharedApplication)
- appdelegateclass, err = makeDelegateClass(_goAppDelegate)
- if err != nil {
- err = fmt.Errorf("error creating NSApplication delegate: %v", err)
- return
- }
- err = addDelegateMethod(appdelegateclass, _uitask, C.appDelegate_uitask)
- if err != nil {
- err = fmt.Errorf("error adding NSApplication delegate uitask: method (to do UI tasks): %v", err)
- return
- }
- // TODO using objc_new() causes a segfault; find out why
- // TODO make alloc followed by init (I thought NSObject provided its own init?)
- appDelegate = objc_alloc(objc_getClass(_goAppDelegate))
-
+ err = mkAppDelegate()
return
}