Compare commits

2 Commits

Author SHA1 Message Date
181583dc57 Selection requests now take in a timestamp 2024-07-11 17:31:36 -04:00
991d74f365 claimRequests must be strictly data 2024-07-11 17:23:01 -04:00
3 changed files with 12 additions and 15 deletions

View File

@@ -21,12 +21,6 @@ type claimRequest struct {
event xevent.SelectionRequestEvent
}
// Close closes the request's reader and does other cleanup. It does not remove
// the request from the claim.
func (this *claimRequest) Close () error {
return this.reader.Close()
}
type claimRequestKey struct {
property xproto.Atom
requestor xproto.Window
@@ -287,7 +281,7 @@ func (claim *Claim) HandlePropertyNotify (
if !ok { return }
done := func () {
request.Close()
request.reader.Close()
delete(claim.requests, key)
}

View File

@@ -82,7 +82,8 @@ func main () {
request, _ := xgbsel.NewRequest (
requestor { window: window },
clipboard,
property)
property,
xproto.TimeCurrentTime)
// listen for events
window.Listen(xproto.EventMaskPropertyChange)

View File

@@ -45,14 +45,19 @@ type Request struct {
destination xproto.Atom
incrBuffer []byte
incrTarget Target
timestamp xproto.Timestamp
}
// NewRequest sends a new selection request.
func NewRequest (requestor Requestor, source, destination xproto.Atom) (*Request, error) {
// NewRequest sends a new selection request. The timestamp should be set to that
// of the event that triggered the request, such as a Ctrl+V event, or a mouse
// button event that led to text being pasted. If the claim was not triggered by
// an event, and *only* in this scenario, specify xproto.TimeCurrentTime.
func NewRequest (requestor Requestor, source, destination xproto.Atom, timestamp xproto.Timestamp) (*Request, error) {
request := &Request {
source: source,
destination: destination,
requestor: requestor,
timestamp: timestamp,
}
targets, err := xprop.Atm(requestor.Window().X, "TARGETS")
@@ -86,17 +91,14 @@ func (request *Request) convertSelection (target xproto.Atom, switchTo selReqSta
// to a window that it created; the owner will place the reply property
// there. The requestor should set the time argument to the timestamp on
// the event that triggered the request for the selection value. Note
// that clients should not specify CurrentTime*.
// that clients should not specify CurrentTime.
err = xproto.ConvertSelectionChecked (
request.requestor.Window().X.Conn(),
request.requestor.Window().Id,
request.source,
target,
request.destination,
// TODO: *possibly replace this zero with an actual timestamp
// received from the server. this is non-trivial as we cannot
// rely on the timestamp of the last received event.
0).Check()
request.timestamp).Check()
if err != nil { request.die(err); return }
request.state = switchTo