From 59bc001677e2016d734c48ff1aa8f674eef177ca Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 17 May 2020 18:51:24 +0200 Subject: [PATCH] app,io/system: implement clipboard reading and writing The app.ReadClipboard and app.WriteClipboard can be used to interact with the system clipboard. The clipboard may be asynchronous, so system.ClipboardEvent is introduced to deliver the result of a read. Updates gio#31 Signed-off-by: Elias Naur --- app/internal/window/window.go | 5 +++++ app/window.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/internal/window/window.go b/app/internal/window/window.go index c9c94761..b52ece19 100644 --- a/app/internal/window/window.go +++ b/app/internal/window/window.go @@ -54,6 +54,11 @@ type Driver interface { // ShowTextInput updates the virtual keyboard state. ShowTextInput(show bool) NewContext() (Context, error) + + // ReadClipboard requests the clipboard content. + ReadClipboard() + // WriteClipboard requests a clipboard write. + WriteClipboard(s string) } type windowRendezvous struct { diff --git a/app/window.go b/app/window.go index 26dc07b7..bd251efc 100644 --- a/app/window.go +++ b/app/window.go @@ -191,6 +191,22 @@ func (w *Window) Invalidate() { } } +// ReadClipboard initiates a read of the clipboard in the form +// of a system.ClipboardEvent. Multiple reads may be coalescedd +// to a single event. +func (w *Window) ReadClipboard() { + w.driverDo(func() { + w.driver.ReadClipboard() + }) +} + +// WriteClipboard writes a string to the clipboard. +func (w *Window) WriteClipboard(s string) { + w.driverDo(func() { + w.driver.WriteClipboard(s) + }) +} + // driverDo calls f as soon as the window has a valid driver attached, // or does nothing if the window is destroyed while waiting. func (w *Window) driverDo(f func()) {