Add support for giving up the selection, forcibly and voluntarily
This commit is contained in:
		
							parent
							
								
									751ec20833
								
							
						
					
					
						commit
						0180a79b25
					
				
							
								
								
									
										36
									
								
								v2/claim.go
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								v2/claim.go
									
									
									
									
									
								
							| @ -14,6 +14,8 @@ type Claim struct { | |||||||
| 	window    *xwindow.Window | 	window    *xwindow.Window | ||||||
| 	data      Data | 	data      Data | ||||||
| 	selection xproto.Atom | 	selection xproto.Atom | ||||||
|  | 	timestamp xproto.Timestamp | ||||||
|  | 	active    bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NewClaim claims ownership of a specified selection, and allows using data | // NewClaim claims ownership of a specified selection, and allows using data | ||||||
| @ -50,9 +52,11 @@ func NewClaim (window *xwindow.Window, selection xproto.Atom, data Data, timesta | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return &Claim { | 	return &Claim { | ||||||
|  | 		active:    true, | ||||||
| 		window:    window, | 		window:    window, | ||||||
| 		data:      data, | 		data:      data, | ||||||
| 		selection: selection, | 		selection: selection, | ||||||
|  | 		timestamp: timestamp, | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -184,3 +188,35 @@ func (claim *Claim) HandlePropertyNotify ( | |||||||
| ) { | ) { | ||||||
| 	// TODO | 	// TODO | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // While the selection claim is active, HandleSelectionClear should be called | ||||||
|  | // when the requesting window recieves a SelectionClear event. This must be | ||||||
|  | // registered as an event handler manually. | ||||||
|  | func (claim *Claim) HandleSelectionClear ( | ||||||
|  | 	connection *xgbutil.XUtil, | ||||||
|  | 	event xevent.SelectionClearEvent, | ||||||
|  | ) { | ||||||
|  | 	// If a client gives up ownership of a selection or if some other client | ||||||
|  | 	// executes a SetSelectionOwner for it and thus reassigns it forcibly, | ||||||
|  | 	// the previous owner will receive a SelectionClear event. | ||||||
|  | 	claim.active = false | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // 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. | ||||||
|  | func (claim *Claim) Close () error { | ||||||
|  | 	if !claim.active { return nil } | ||||||
|  | 	claim.active = false | ||||||
|  | 
 | ||||||
|  | 	// To relinquish ownership of a selection voluntarily, a client should | ||||||
|  | 	// execute a SetSelectionOwner request for that selection atom, with | ||||||
|  | 	// owner specified as None and the time specified as the timestamp that | ||||||
|  | 	// was used to acquire the selection.  | ||||||
|  | 	err := xproto.SetSelectionOwnerChecked ( | ||||||
|  | 		claim.window.X.Conn(), | ||||||
|  | 		0, claim.selection, claim.timestamp).Check() | ||||||
|  | 	if err != nil { return err } | ||||||
|  | 
 | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  | |||||||
| @ -68,6 +68,7 @@ func main () { | |||||||
| 	window.Listen(xproto.EventMaskPropertyChange) | 	window.Listen(xproto.EventMaskPropertyChange) | ||||||
| 	xevent.PropertyNotifyFun(claim.HandlePropertyNotify).Connect(X, window.Id) | 	xevent.PropertyNotifyFun(claim.HandlePropertyNotify).Connect(X, window.Id) | ||||||
| 	xevent.SelectionRequestFun(claim.HandleSelectionRequest).Connect(X, window.Id) | 	xevent.SelectionRequestFun(claim.HandleSelectionRequest).Connect(X, window.Id) | ||||||
|  | 	xevent.SelectionClearFun(claim.HandleSelectionClear).Connect(X, window.Id) | ||||||
| 	 | 	 | ||||||
| 	log.Println("running main event loop") | 	log.Println("running main event loop") | ||||||
| 	xevent.Main(X) | 	xevent.Main(X) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user