X backend clipboard properly negotiates data type with owner

The clipboard API has been changed to allow an application to
accept a number of different mime types, and the X backend will now
check the accepted types list against the owner's TARGETS list and
choose the best one.
This commit is contained in:
2023-03-29 02:55:12 -04:00
parent 0aede3502b
commit 39dc09bc4a
3 changed files with 146 additions and 20 deletions

View File

@@ -2,6 +2,9 @@ package main
import "io"
import "image"
import _ "image/png"
import _ "image/gif"
import _ "image/jpeg"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/theme"
@@ -15,6 +18,12 @@ func main () {
tomo.Run(run)
}
var validImageTypes = []data.Mime {
data.M("image", "png"),
data.M("image", "gif"),
data.M("image", "jpeg"),
}
func run () {
window, _ := tomo.NewWindow(256, 2)
window.SetTitle("Clipboard")
@@ -39,7 +48,15 @@ func run () {
return
}
imageData, ok := clipboard[data.M("image", "png")]
var imageData io.Reader
var ok bool
for mime, reader := range clipboard {
for _, mimeCheck := range validImageTypes {
if mime == mimeCheck {
imageData = reader
ok = true
}}}
if !ok {
popups.NewDialog (
popups.DialogKindError,
@@ -90,7 +107,7 @@ func run () {
window.Paste(clipboardCallback, data.MimePlain)
})
pasteImageButton.OnClick (func () {
window.Paste(imageClipboardCallback, data.M("image", "png"))
window.Paste(imageClipboardCallback, validImageTypes...)
})
container.Adopt(textInput, true)