Changed the clipboard API so that it will work with X

In X, clipboard/selection data is specific to each window, and it
may take some time before the clipboard data is fully transferred.
This actually makes sense because there can be entire images in
the clipboard and it is important the clipboard API supports large
file transfer. Because of this, the Copy and Paste methods have
been moved into Window, and Paste now returns a channel.
This commit is contained in:
Sasha Koshka 2023-03-25 13:32:48 -04:00
parent 6a3f45a2e0
commit 02a27447b9
2 changed files with 11 additions and 16 deletions

View File

@ -1,13 +1,13 @@
package elements
import "io"
import "image"
import "git.tebibyte.media/sashakoshka/tomo/data"
// Window represents a top-level container generated by the currently running
// backend. It can contain a single element. It is hidden by default, and must
// be explicitly shown with the Show() method.
type Window interface {
Parent
// Adopt sets the root element of the window. There can only be one of
// these at one time.
Adopt (Element)
@ -27,6 +27,15 @@ type Window interface {
// NewModal creates a new modal dialog window.
NewModal (width, height int) (window Window, err error)
// Copy puts data into the clipboard.
Copy (data.Data)
// Paste requests the data currently in the clipboard. When the data is
// available, it is sent on the returned channel. If there is no data on
// the clipboard matching the requested mime type, the channel will be
// sent nil.
Paste (accept data.Mime) <- chan io.Reader
// Show shows the window. The window starts off hidden, so this must be
// called after initial setup to make sure it is visible.

14
tomo.go
View File

@ -4,7 +4,6 @@ import "os"
import "io"
import "path/filepath"
import "git.tebibyte.media/sashakoshka/tomo/dirs"
import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/config"
import "git.tebibyte.media/sashakoshka/tomo/elements"
@ -47,19 +46,6 @@ func NewWindow (width, height int) (window elements.MainWindow, err error) {
return backend.NewWindow(width, height)
}
// Copy puts data into the clipboard.
func Copy (data data.Data) {
assertBackend()
backend.Copy(data)
}
// Paste returns the data currently in the clipboard. This method may
// return nil.
func Paste (accept []data.Mime) (data.Data) {
assertBackend()
return backend.Paste(accept)
}
// SetTheme sets the theme of all open windows.
func SetTheme (theme theme.Theme) {
backend.SetTheme(theme)