app/internal/window: macOS clipboard support

Updates gio#31

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-17 12:50:15 +02:00
parent 1e934673d7
commit 9534337a43
4 changed files with 71 additions and 1 deletions
+19
View File
@@ -3,9 +3,17 @@
package window
/*
#include <Foundation/Foundation.h>
__attribute__ ((visibility ("hidden"))) void gio_wakeupMainThread(void);
__attribute__ ((visibility ("hidden"))) NSUInteger gio_nsstringLength(CFTypeRef str);
__attribute__ ((visibility ("hidden"))) void gio_nsstringGetCharacters(CFTypeRef str, unichar *chars, NSUInteger loc, NSUInteger length);
*/
import "C"
import (
"unicode/utf16"
"unsafe"
)
var mainFuncs = make(chan func(), 1)
@@ -28,3 +36,14 @@ func gio_dispatchMainFuncs() {
}
}
}
// nsstringToString converts a NSString to a Go string, and
// releases the original string.
func nsstringToString(str C.CFTypeRef) string {
defer C.CFRelease(str)
n := C.gio_nsstringLength(str)
chars := make([]uint16, n)
C.gio_nsstringGetCharacters(str, (*C.unichar)(unsafe.Pointer(&chars[0])), 0, n)
utf8 := utf16.Decode(chars)
return string(utf8)
}