app: move system.ClipboardEvent to its own package

API change. Update your code with gofmt rule and goimports:

gofmt -r "system.ClipboardEvent -> clipboard.Event"
goimports

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Inkeliz
2020-12-04 03:56:13 +00:00
committed by Elias Naur
parent feb93baee0
commit 828f19304b
10 changed files with 30 additions and 20 deletions
+2 -1
View File
@@ -52,6 +52,7 @@ import (
"unsafe" "unsafe"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/io/clipboard"
"gioui.org/io/key" "gioui.org/io/key"
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/io/system" "gioui.org/io/system"
@@ -647,7 +648,7 @@ func (w *window) ReadClipboard() {
return return
} }
content := goString(env, C.jstring(c)) content := goString(env, C.jstring(c))
w.callbacks.Event(system.ClipboardEvent{Text: content}) w.callbacks.Event(clipboard.Event{Text: content})
}) })
} }
+2 -1
View File
@@ -38,6 +38,7 @@ import (
"unsafe" "unsafe"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/io/clipboard"
"gioui.org/io/key" "gioui.org/io/key"
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/io/system" "gioui.org/io/system"
@@ -223,7 +224,7 @@ func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.C
func (w *window) ReadClipboard() { func (w *window) ReadClipboard() {
runOnMain(func() { runOnMain(func() {
content := nsstringToString(C.gio_readClipboard()) content := nsstringToString(C.gio_readClipboard())
w.w.Event(system.ClipboardEvent{Text: content}) w.w.Event(clipboard.Event{Text: content})
}) })
} }
+2 -1
View File
@@ -12,6 +12,7 @@ import (
"unicode/utf8" "unicode/utf8"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/io/clipboard"
"gioui.org/io/key" "gioui.org/io/key"
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/io/system" "gioui.org/io/system"
@@ -59,7 +60,7 @@ func NewWindow(win Callbacks, opts *Options) error {
}) })
w.clipboardCallback = w.funcOf(func(this js.Value, args []js.Value) interface{} { w.clipboardCallback = w.funcOf(func(this js.Value, args []js.Value) interface{} {
content := args[0].String() content := args[0].String()
win.Event(system.ClipboardEvent{Text: content}) win.Event(clipboard.Event{Text: content})
return nil return nil
}) })
w.addEventListeners() w.addEventListeners()
+2 -1
View File
@@ -14,6 +14,7 @@ import (
"unsafe" "unsafe"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/io/clipboard"
"gioui.org/io/key" "gioui.org/io/key"
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/io/system" "gioui.org/io/system"
@@ -108,7 +109,7 @@ func (w *window) contextView() C.CFTypeRef {
func (w *window) ReadClipboard() { func (w *window) ReadClipboard() {
runOnMain(func() { runOnMain(func() {
content := nsstringToString(C.gio_readClipboard()) content := nsstringToString(C.gio_readClipboard())
w.w.Event(system.ClipboardEvent{Text: content}) w.w.Event(clipboard.Event{Text: content})
}) })
} }
+3 -2
View File
@@ -22,6 +22,7 @@ import (
"gioui.org/app/internal/xkb" "gioui.org/app/internal/xkb"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/internal/fling" "gioui.org/internal/fling"
"gioui.org/io/clipboard"
"gioui.org/io/key" "gioui.org/io/key"
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/io/system" "gioui.org/io/system"
@@ -1134,14 +1135,14 @@ func (w *window) process() {
r, err := w.disp.readClipboard() r, err := w.disp.readClipboard()
// Send empty responses on unavailable clipboards or errors. // Send empty responses on unavailable clipboards or errors.
if r == nil || err != nil { if r == nil || err != nil {
w.w.Event(system.ClipboardEvent{}) w.w.Event(clipboard.Event{})
return return
} }
// Don't let slow clipboard transfers block event loop. // Don't let slow clipboard transfers block event loop.
go func() { go func() {
defer r.Close() defer r.Close()
data, _ := ioutil.ReadAll(r) data, _ := ioutil.ReadAll(r)
w.w.Event(system.ClipboardEvent{Text: string(data)}) w.w.Event(clipboard.Event{Text: string(data)})
}() }()
} }
if writeClipboard != nil { if writeClipboard != nil {
+2 -1
View File
@@ -22,6 +22,7 @@ import (
"gioui.org/unit" "gioui.org/unit"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/io/clipboard"
"gioui.org/io/key" "gioui.org/io/key"
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/io/system" "gioui.org/io/system"
@@ -513,7 +514,7 @@ func (w *window) readClipboard() error {
hdr.Len = n hdr.Len = n
content := string(utf16.Decode(u16)) content := string(utf16.Decode(u16))
go func() { go func() {
w.w.Event(system.ClipboardEvent{Text: content}) w.w.Event(clipboard.Event{Text: content})
}() }()
return nil return nil
} }
+2 -1
View File
@@ -36,6 +36,7 @@ import (
"unsafe" "unsafe"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/io/clipboard"
"gioui.org/io/key" "gioui.org/io/key"
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/io/system" "gioui.org/io/system"
@@ -434,7 +435,7 @@ func (h *x11EventHandler) handleEvents() bool {
break break
} }
str := C.GoStringN((*C.char)(unsafe.Pointer(text.value)), C.int(text.nitems)) str := C.GoStringN((*C.char)(unsafe.Pointer(text.value)), C.int(text.nitems))
w.w.Event(system.ClipboardEvent{Text: str}) w.w.Event(clipboard.Event{Text: str})
case C.SelectionRequest: case C.SelectionRequest:
cevt := (*C.XSelectionRequestEvent)(unsafe.Pointer(xev)) cevt := (*C.XSelectionRequestEvent)(unsafe.Pointer(xev))
if cevt.selection != w.atoms.clipboard || cevt.property == C.None { if cevt.selection != w.atoms.clipboard || cevt.property == C.None {
+1 -1
View File
@@ -195,7 +195,7 @@ func (w *Window) Invalidate() {
} }
// ReadClipboard initiates a read of the clipboard in the form // ReadClipboard initiates a read of the clipboard in the form
// of a system.ClipboardEvent. Multiple reads may be coalesced // of a clipboard.Event. Multiple reads may be coalesced
// to a single event. // to a single event.
func (w *Window) ReadClipboard() { func (w *Window) ReadClipboard() {
go w.driverDo(func() { go w.driverDo(func() {
+10
View File
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Unlicense OR MIT
package clipboard
// Event is generated when the clipboard content is requested.
type Event struct {
Text string
}
func (Event) ImplementsEvent() {}
+4 -11
View File
@@ -60,12 +60,6 @@ type DestroyEvent struct {
Err error Err error
} }
// ClipboardEvent is sent once for each request for the
// clipboard content.
type ClipboardEvent struct {
Text string
}
// Insets is the space taken up by // Insets is the space taken up by
// system decoration such as translucent // system decoration such as translucent
// system bars and software keyboards. // system bars and software keyboards.
@@ -118,8 +112,7 @@ func (l Stage) String() string {
} }
} }
func (FrameEvent) ImplementsEvent() {} func (FrameEvent) ImplementsEvent() {}
func (StageEvent) ImplementsEvent() {} func (StageEvent) ImplementsEvent() {}
func (*CommandEvent) ImplementsEvent() {} func (*CommandEvent) ImplementsEvent() {}
func (DestroyEvent) ImplementsEvent() {} func (DestroyEvent) ImplementsEvent() {}
func (ClipboardEvent) ImplementsEvent() {}