From 0709351fed0b5fb5871853505e969bf0ccf17495 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 1 Mar 2014 20:31:17 -0500 Subject: 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. --- bleh_darwin.m | 9 +++++++++ objc_darwin.h | 1 + uitask_darwin.go | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/bleh_darwin.m b/bleh_darwin.m index 04f8930..1c42cca 100644 --- a/bleh_darwin.m +++ b/bleh_darwin.m @@ -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. diff --git a/objc_darwin.h b/objc_darwin.h index 1c960d5..5d6bd41 100644 --- a/objc_darwin.h +++ b/objc_darwin.h @@ -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); diff --git a/uitask_darwin.go b/uitask_darwin.go index c77bb2f..c61ede0 100644 --- a/uitask_darwin.go +++ b/uitask_darwin.go @@ -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 } -- cgit v1.2.3