clipboard #14
@ -245,7 +245,17 @@ func (window *window) handleSelectionNotify (
|
|||||||
// Follow:
|
// Follow:
|
||||||
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.4
|
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.4
|
||||||
if window.selectionRequest == nil { return }
|
if window.selectionRequest == nil { return }
|
||||||
die := func (err error) { window.selectionRequest(nil, err) }
|
die := func (err error) {
|
||||||
|
window.selectionRequest(nil, err)
|
||||||
|
window.selectionRequest = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the property argument is None, the conversion has been refused.
|
||||||
|
// This can mean either that there is no owner for the selection, that
|
||||||
|
// the owner does not support the conversion implied by the target, or
|
||||||
|
// that the server did not have sufficient space to accommodate the
|
||||||
|
// data.
|
||||||
|
if event.Property == 0 { die(nil); return }
|
||||||
|
|
||||||
// When using GetProperty to retrieve the value of a selection, the
|
// When using GetProperty to retrieve the value of a selection, the
|
||||||
// property argument should be set to the corresponding value in the
|
// property argument should be set to the corresponding value in the
|
||||||
|
@ -290,7 +290,10 @@ func (window *window) Paste (accept data.Mime, callback func (io.Reader, error))
|
|||||||
// Follow:
|
// Follow:
|
||||||
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.4
|
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.4
|
||||||
|
|
||||||
die := func (err error) { callback(nil, err) }
|
die := func (err error) {
|
||||||
|
window.selectionRequest = nil
|
||||||
|
callback(nil, err)
|
||||||
|
}
|
||||||
if window.selectionRequest != nil {
|
if window.selectionRequest != nil {
|
||||||
// TODO: add the request to a queue and take care of it when the
|
// TODO: add the request to a queue and take care of it when the
|
||||||
// current selection has completed
|
// current selection has completed
|
||||||
@ -299,8 +302,10 @@ func (window *window) Paste (accept data.Mime, callback func (io.Reader, error))
|
|||||||
|
|
||||||
selectionName := "CLIPBOARD"
|
selectionName := "CLIPBOARD"
|
||||||
propertyName := "TOMO_SELECTION"
|
propertyName := "TOMO_SELECTION"
|
||||||
// TODO: change based on mime type
|
targetName := accept.String()
|
||||||
targetName := "TEXT"
|
if accept == data.M("text", "plain") {
|
||||||
|
targetName = "UTF8_STRING"
|
||||||
|
}
|
||||||
|
|
||||||
// get atoms
|
// get atoms
|
||||||
selectionAtom, err := xprop.Atm(window.backend.connection, selectionName)
|
selectionAtom, err := xprop.Atm(window.backend.connection, selectionName)
|
||||||
|
10
data/data.go
10
data/data.go
@ -16,6 +16,16 @@ type Mime struct {
|
|||||||
Type, Subtype string
|
Type, Subtype string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// M is shorthand for creating a MIME type.
|
||||||
|
func M (ty, subtype string) Mime {
|
||||||
|
return Mime { ty, subtype }
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the string representation of the MIME type.
|
||||||
|
func (mime Mime) String () string {
|
||||||
|
return mime.Type + "/" + mime.Subtype
|
||||||
|
}
|
||||||
|
|
||||||
var MimePlain = Mime { "text", "plain" }
|
var MimePlain = Mime { "text", "plain" }
|
||||||
|
|
||||||
var MimeFile = Mime { "text", "uri-list" }
|
var MimeFile = Mime { "text", "uri-list" }
|
||||||
|
@ -32,10 +32,18 @@ func run () {
|
|||||||
popups.DialogKindError,
|
popups.DialogKindError,
|
||||||
window,
|
window,
|
||||||
"Error",
|
"Error",
|
||||||
"No text data in clipboard:\n" + err.Error())
|
"Cannot get clipboard:\n" + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if clipboard == nil {
|
||||||
|
popups.NewDialog (
|
||||||
|
popups.DialogKindError,
|
||||||
|
window,
|
||||||
|
"Clipboard Empty",
|
||||||
|
"No text data in clipboard")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
text, _ := io.ReadAll(clipboard)
|
text, _ := io.ReadAll(clipboard)
|
||||||
tomo.Do (func () {
|
tomo.Do (func () {
|
||||||
|
Reference in New Issue
Block a user