mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
app/internal/window: [iOS] implement clipboard
Updates gio#31 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -17,6 +17,8 @@ __attribute__ ((visibility ("hidden"))) void gio_addLayerToView(CFTypeRef viewRe
|
|||||||
__attribute__ ((visibility ("hidden"))) void gio_updateView(CFTypeRef viewRef, CFTypeRef layerRef);
|
__attribute__ ((visibility ("hidden"))) void gio_updateView(CFTypeRef viewRef, CFTypeRef layerRef);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_removeLayer(CFTypeRef layerRef);
|
__attribute__ ((visibility ("hidden"))) void gio_removeLayer(CFTypeRef layerRef);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_setAnimating(CFTypeRef viewRef, int anim);
|
__attribute__ ((visibility ("hidden"))) void gio_setAnimating(CFTypeRef viewRef, int anim);
|
||||||
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_readClipboard(void);
|
||||||
|
__attribute__ ((visibility ("hidden"))) void gio_writeClipboard(unichar *chars, NSUInteger length);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@@ -26,6 +28,8 @@ import (
|
|||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf16"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"gioui.org/f32"
|
"gioui.org/f32"
|
||||||
"gioui.org/io/key"
|
"gioui.org/io/key"
|
||||||
@@ -199,6 +203,24 @@ func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.C
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *window) ReadClipboard() {
|
||||||
|
runOnMain(func() {
|
||||||
|
content := nsstringToString(C.gio_readClipboard())
|
||||||
|
w.w.Event(system.ClipboardEvent{Text: content})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *window) WriteClipboard(s string) {
|
||||||
|
u16 := utf16.Encode([]rune(s))
|
||||||
|
runOnMain(func() {
|
||||||
|
var chars *C.unichar
|
||||||
|
if len(u16) > 0 {
|
||||||
|
chars = (*C.unichar)(unsafe.Pointer(&u16[0]))
|
||||||
|
}
|
||||||
|
C.gio_writeClipboard(chars, C.NSUInteger(len(u16)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (w *window) SetAnimating(anim bool) {
|
func (w *window) SetAnimating(anim bool) {
|
||||||
v := w.view
|
v := w.view
|
||||||
if v == 0 {
|
if v == 0 {
|
||||||
|
|||||||
@@ -279,6 +279,24 @@ NSArray<UIKeyCommand *> *_keyCommands;
|
|||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
void gio_writeClipboard(unichar *chars, NSUInteger length) {
|
||||||
|
@autoreleasepool {
|
||||||
|
NSString *s = [NSString string];
|
||||||
|
if (length > 0) {
|
||||||
|
s = [NSString stringWithCharacters:chars length:length];
|
||||||
|
}
|
||||||
|
UIPasteboard *p = UIPasteboard.generalPasteboard;
|
||||||
|
p.string = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CFTypeRef gio_readClipboard(void) {
|
||||||
|
@autoreleasepool {
|
||||||
|
UIPasteboard *p = UIPasteboard.generalPasteboard;
|
||||||
|
return (__bridge_retained CFTypeRef)p.string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void gio_setAnimating(CFTypeRef viewRef, int anim) {
|
void gio_setAnimating(CFTypeRef viewRef, int anim) {
|
||||||
GioView *view = (__bridge GioView *)viewRef;
|
GioView *view = (__bridge GioView *)viewRef;
|
||||||
[view setAnimating:(anim ? YES : NO)];
|
[view setAnimating:(anim ? YES : NO)];
|
||||||
|
|||||||
Reference in New Issue
Block a user