mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
io/input,io/clipboard: [API] replace WriteOp with command
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -160,7 +160,7 @@ type driver interface {
|
||||
// ReadClipboard requests the clipboard content.
|
||||
ReadClipboard()
|
||||
// WriteClipboard requests a clipboard write.
|
||||
WriteClipboard(s string)
|
||||
WriteClipboard(mime string, s []byte)
|
||||
// Configure the window.
|
||||
Configure([]Option)
|
||||
// SetCursor updates the current cursor to name.
|
||||
|
||||
+2
-2
@@ -1295,9 +1295,9 @@ func newWindow(window *callbacks, options []Option) error {
|
||||
return <-mainWindow.errs
|
||||
}
|
||||
|
||||
func (w *window) WriteClipboard(s string) {
|
||||
func (w *window) WriteClipboard(mime string, s []byte) {
|
||||
runInJVM(javaVM(), func(env *C.JNIEnv) {
|
||||
jstr := javaString(env, s)
|
||||
jstr := javaString(env, string(s))
|
||||
callStaticVoidMethod(env, android.gioCls, android.mwriteClipboard,
|
||||
jvalue(android.appCtx), jvalue(jstr))
|
||||
})
|
||||
|
||||
+2
-2
@@ -268,8 +268,8 @@ func (w *window) ReadClipboard() {
|
||||
w.w.Event(clipboard.Event{Text: content})
|
||||
}
|
||||
|
||||
func (w *window) WriteClipboard(s string) {
|
||||
u16 := utf16.Encode([]rune(s))
|
||||
func (w *window) WriteClipboard(mime string, s []byte) {
|
||||
u16 := utf16.Encode([]rune(string(s)))
|
||||
var chars *C.unichar
|
||||
if len(u16) > 0 {
|
||||
chars = (*C.unichar)(unsafe.Pointer(&u16[0]))
|
||||
|
||||
+2
-2
@@ -533,14 +533,14 @@ func (w *window) ReadClipboard() {
|
||||
w.clipboard.Call("readText", w.clipboard).Call("then", w.clipboardCallback)
|
||||
}
|
||||
|
||||
func (w *window) WriteClipboard(s string) {
|
||||
func (w *window) WriteClipboard(mime string, s []byte) {
|
||||
if w.clipboard.IsUndefined() {
|
||||
return
|
||||
}
|
||||
if w.clipboard.Get("writeText").IsUndefined() {
|
||||
return
|
||||
}
|
||||
w.clipboard.Call("writeText", s)
|
||||
w.clipboard.Call("writeText", string(s))
|
||||
}
|
||||
|
||||
func (w *window) Configure(options []Option) {
|
||||
|
||||
+2
-2
@@ -308,8 +308,8 @@ func (w *window) ReadClipboard() {
|
||||
w.w.Event(clipboard.Event{Text: content})
|
||||
}
|
||||
|
||||
func (w *window) WriteClipboard(s string) {
|
||||
cstr := stringToNSString(s)
|
||||
func (w *window) WriteClipboard(mime string, s []byte) {
|
||||
cstr := stringToNSString(string(s))
|
||||
defer C.CFRelease(cstr)
|
||||
C.writeClipboard(cstr)
|
||||
}
|
||||
|
||||
+2
-2
@@ -1033,8 +1033,8 @@ func (w *window) ReadClipboard() {
|
||||
}()
|
||||
}
|
||||
|
||||
func (w *window) WriteClipboard(s string) {
|
||||
w.disp.writeClipboard([]byte(s))
|
||||
func (w *window) WriteClipboard(mime string, s []byte) {
|
||||
w.disp.writeClipboard(s)
|
||||
}
|
||||
|
||||
func (w *window) Configure(options []Option) {
|
||||
|
||||
+2
-2
@@ -735,8 +735,8 @@ func (w *window) Configure(options []Option) {
|
||||
w.update()
|
||||
}
|
||||
|
||||
func (w *window) WriteClipboard(s string) {
|
||||
w.writeClipboard(s)
|
||||
func (w *window) WriteClipboard(mime string, s []byte) {
|
||||
w.writeClipboard(string(s))
|
||||
}
|
||||
|
||||
func (w *window) writeClipboard(s string) error {
|
||||
|
||||
+2
-2
@@ -151,8 +151,8 @@ func (w *x11Window) ReadClipboard() {
|
||||
C.XConvertSelection(w.x, w.atoms.clipboard, w.atoms.utf8string, w.atoms.clipboardContent, w.xw, C.CurrentTime)
|
||||
}
|
||||
|
||||
func (w *x11Window) WriteClipboard(s string) {
|
||||
w.clipboard.content = []byte(s)
|
||||
func (w *x11Window) WriteClipboard(mime string, s []byte) {
|
||||
w.clipboard.content = s
|
||||
C.XSetSelectionOwner(w.x, w.atoms.clipboard, w.xw, C.CurrentTime)
|
||||
C.XSetSelectionOwner(w.x, w.atoms.primary, w.xw, C.CurrentTime)
|
||||
}
|
||||
|
||||
+2
-9
@@ -316,8 +316,8 @@ func (w *Window) processFrame(d driver) {
|
||||
if hint, ok := q.TextInputHint(); ok {
|
||||
d.SetInputHint(hint)
|
||||
}
|
||||
if txt, ok := q.WriteClipboard(); ok {
|
||||
d.WriteClipboard(txt)
|
||||
if mime, txt, ok := q.WriteClipboard(); ok {
|
||||
d.WriteClipboard(mime, txt)
|
||||
}
|
||||
if q.ReadClipboard() {
|
||||
d.ReadClipboard()
|
||||
@@ -372,13 +372,6 @@ func (w *Window) Option(opts ...Option) {
|
||||
}
|
||||
}
|
||||
|
||||
// WriteClipboard writes a string to the clipboard.
|
||||
func (w *Window) WriteClipboard(s string) {
|
||||
w.driverDefer(func(d driver) {
|
||||
d.WriteClipboard(s)
|
||||
})
|
||||
}
|
||||
|
||||
// Run f in the same thread as the native window event loop, and wait for f to
|
||||
// return or the window to close. Run is guaranteed not to deadlock if it is
|
||||
// invoked during the handling of a ViewEvent, system.FrameEvent,
|
||||
|
||||
Reference in New Issue
Block a user