There are two built-in selection atoms: xa_primary and xa_secondary. Unless the client foresees needing two simultaneous selections, it should use xa_primary. It calls XSet-Selection0wner( ), specifying the selection atom, any window that it created (this window is used by other applications to identify the owner), and the time. The time used should be from the event that triggered the bid to own the selection (not CurrentTime) because of race conditions that can otherwise occur. If the client does not already own the selection atom, then this call will generate a SelectionClear event for the old owner, telling it to unhighlight the old selection.
Each client that wants to be able to have a selection pasted into it must set aside a key or button combination to indicate that the user wishes to paste in the current selection. In response to the event that occurs when that key or button combination is pressed, the client calls XConvertSelection( ). This call specifies which selection the application wants (xa_primary until other conventions are established), the property to place the data in, the window on which to set this property, and the time. These arguments are quite clear. But the XConvertSelection( ) call also specifies a target type that the application wants the data in. You need to understand what happens after the XConvertSelection( ) call to understand the purpose of the target type property.
The server places all the arguments of the XConvertSelection( ) call into an XSelectionRequestEvent and sends the event to the selection owner. The owner then tries to convert the selection data into the format specified in the target type property. If the selection owner knows how to convert the data into the requested type, it puts the data in the property specified in the event and returns the atom of this property in the property member of a SelectionNotify event. If the selection owner cannot convert the selection into the requested type, it returns None as the property member in the SelectionNotify event. The owner sends this SelectionNotify event using XSendEvent().
When the requestor receives the SelectionNotify event, it either reads the property if it is set, repeats the request with a different target type if the owner returned None, or gives up on pasting data from that selection owner. It could be that the user is trying to do something like paste graphics into a text-only application.
Now you should understand the selection mechanism in general, so let's look at a more tangible example of how it takes place.
12.4.2 An Example of Selection
Let's say a text editor is the owner of the selection xa__primary. the user is editing a C program and debugging the same C program in another window. The user would like to select a line in the source code and instruct the debugger to stop at that same line without having to type in the line number. Perhaps the debugger would have a button labeled "stop at," which, when pressed, would tell the debugger to request a value for the primary selection. The text editor would allow the user to select text on a line and would be able to convert that selection into a string if it were pasted into another text editor or into a line number if it were pasted into the debugger. Which type the text editor would choose would depend on the target type of the selection request.
Interclient Communication 429