mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
app/internal/window: macOS clipboard support
Updates gio#31 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user