diff --git a/v2/claim.go b/v2/claim.go index d9304ea..01765c4 100644 --- a/v2/claim.go +++ b/v2/claim.go @@ -25,7 +25,7 @@ type Claim struct { data Data selection xproto.Atom timestamp xproto.Timestamp - active bool + open bool requests map[xproto.Atom] claimRequest } @@ -64,7 +64,7 @@ func NewClaim (window *xwindow.Window, selection xproto.Atom, data Data, timesta } return &Claim { - active: true, + open: true, window: window, data: data, selection: selection, @@ -131,6 +131,10 @@ func (claim *Claim) HandleSelectionRequest ( connection *xgbutil.XUtil, event xevent.SelectionRequestEvent, ) { + // do not fulfill *new* selection requests after the claim has been + // relinquished + if !claim.open { return } + // Follow: // https://tronche.com/gui/x/icccm/sec-2.html#s-2.2 @@ -279,15 +283,28 @@ func (claim *Claim) HandleSelectionClear ( // is, before it receives notification that the requestor has received // all the data), it must continue to service the ongoing transfer until // it is complete. - claim.active = false + claim.open = false +} + +// Open returns false if the claim has been relinquished, either from recieving +// a SelectionClear event or with the Close method. +func (claim *Claim) Open () bool { + return claim.open +} + +// Active returns true if requests are currently being fulfilled. While this is +// true, the claim should still be forwarded events regardless if it is closed +// or not. It is safe to forward the same event to multiple claims. +func (claim *Claim) Active () bool { + return len(claim.requests) > 0 } // Close voluntarily relinquishes the selection claim. This will inform the X // server that the selection is being voluntarily given up, and cause the claim -// to stop responding to events. +// to stop fulfilling new requests. func (claim *Claim) Close () error { - if !claim.active { return nil } - claim.active = false + if !claim.open { return nil } + claim.open = false // To relinquish ownership of a selection voluntarily, a client should // execute a SetSelectionOwner request for that selection atom, with