Attempted to fix the lack of resizable window borders by setting the NSApplication activation policy. This fixed it, and also fixed a bunch of other things, such as the application being seen as part of Terminal, lack of dock icon, lack of application menu, etc.

This commit is contained in:
Pietro Gagliardi 2014-03-01 20:31:17 -05:00
parent 10e9f6b927
commit 0709351fed
3 changed files with 18 additions and 0 deletions

View File

@ -27,6 +27,15 @@ id _objc_msgSend_uint(id obj, SEL sel, uintptr_t a)
return objc_msgSend(obj, sel, (NSUInteger) a);
}
/*
same as above, but for NSInteger
*/
id objc_msgSend_int(id obj, SEL sel, intptr_t a)
{
return objc_msgSend(obj, sel, (NSInteger) a);
}
/*
These are the objc_msgSend() wrappers around NSRect. The problem is that while on 32-bit systems, NSRect is a concrete structure, on 64-bit systems it's just a typedef to CGRect. While in practice just using CGRect everywhere seems to work, better to be safe than sorry.

View File

@ -75,6 +75,7 @@ m1(sel, SEL)
extern id _objc_msgSend_uint(id obj, SEL sel, uintptr_t a);
m1(ptr, void *)
m1(bool, BOOL)
extern id objc_msgSend_int(id obj, SEL sel, intptr_t a);
m2(id_id, id, id)
extern id _objc_msgSend_rect_bool(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h, BOOL b);

View File

@ -2,6 +2,7 @@
package ui
import (
"fmt"
"runtime"
"unsafe"
)
@ -66,10 +67,17 @@ var (
_NSApplication = objc_getClass("NSApplication")
_sharedApplication = sel_getUid("sharedApplication")
_setActivationPolicy = sel_getUid("setActivationPolicy:")
)
func initCocoa() (NSApp C.id, err error) {
NSApp = C.objc_msgSend_noargs(_NSApplication, _sharedApplication)
r := C.objc_msgSend_int(NSApp, _setActivationPolicy,
0) // NSApplicationActivationPolicyRegular
if C.BOOL(uintptr(unsafe.Pointer(r))) != C.BOOL(C.YES) {
err = fmt.Errorf("error setting NSApplication activation policy (basically identifies our program as a separate program; needed for several things, such as Dock icon, menu, window resizing, etc.) (unknown reason)")
return
}
err = mkAppDelegate()
return
}