12.4.3 Acquiring Selection Ownership
When the user decides to select something in an application, the application needs to become the selection owner. Being the selection owner means that when any other application requests the value of the selection with XConvertSelection( ), the owner gets the resulting XSelectionRequest event. The transfer of selection ownership also makes sure that only one application at a time is attempting to set the properties. The previous application to call XSetSelectionOwner(), if it was another application, receives a SelectionClear event, which indicates to it that it should clear any area it has highlighted.
Note that if the time in the XSetSelectionOwner() request is in the future relative to the server's current time or if it is in the past relative to the last time the selection concerned changed hands, the XSetSelectionOwner() request appears to the client to succeed, but ownership is not actually transferred. To ensure that ownership has been transferred, a client must perform the sequence shown in Example 12-8.
Example 12-8. Code to ensure transfer of selection ownership
XSetSelectionOwnerfdisplay, selection_atom, owner, time); if (XGetSelectionOwner(display, selection_atom) != owner) {
If XGetSelectionOwner( ) returns a window ID rather than None, then the selection ownership was successfully transferred.
12.4.4 Responsibilities of the Selection Owner
When a requestor wants the value of a selection, the owner receives a Selection-Request event. Example 12-9 shows the XSelectionRequestEvent structure.
Example 12-9. The XSelectionRequestEvent structure
typedef struct { int type; unsigned long serial; /* # of last request processed by
* server */
Bool send_event; /* True if this came from SendEvent
* request */
Display *display; /* Display the event was read from */ Window owner; Window requestor; Atom selection; Atom target; Atom property; Time time; } XSelectionRequestEvent;
Interclient Communication 431