Active and passive selections
The methods for transferring data can be classified into active and passive, depending on whether the client handling the selected data has to actively participate in the transfer to a client requesting it: ; Passive: When some data is selected, the client handling the window where this selection is done transfers it somewhere, and no longer needs to care about it; ; Active: Transfer of data to a client requires the client "holding" the selection to actively participate in the exchange. Selections and drag-and-drop are active mechanisms: after some text is selected in a window, the client handling the window must actively support a protocol for transferring the data to the application requesting it. By contrast, cut buffers are a passive mechanism: after some text is selected, it is transferred to a cut buffer and remains there even if the application handling the window terminates and the window is destroyed. The X clipboard is a passive mechanism as perceived by the client holding the selection, but requires thexclipboard
client to actively support any subsequent data transfer.
An advantage of active mechanisms is that the data can be converted to a different format before the transfer. In particular, the client receiving the data can request the selection data to be converted into a suitable form. If the sending client refuses to do so, the receiver can request a different format. For example, a piece of text rendering Selections
The X Window System supports an arbitrary number of selections; every selection is identified by a string (more precisely, anatom
). The most used selection is the PRIMARY
selection.
The following requests are specific to selection transfer, although transfer also involves other requests:
# request to know which window owns the selection
# request to set the window that owns the selection
# request to convert the selection
The owner of the selection is typically the window in which the selected text is located, if any. When the user selects some text in a window, the client handling the window must tell the server that the window is the owner of the selection.
When the user tries to paste the selection into another window, that window's handler initiates a protocol for getting the selected text from the other client. This protocol involves the second and third requests of the list above, and is not specified by the X protocol but as a convention in the Inter-Client Communication Convention Manual (ICCCM).
In particular, the destination client begins by asking the server which window owns the selection. Then the two clients transfer the selection via the server. This exchange involves a property of a window, and an arbitrary piece of data attached to the window. If the content of the selection is considered small enough to be transferred all at once, the steps that take place are:
# the recipient of the selection requests the selection to be converted, specifying a property of a window (this may be the window where the text has to be pasted)
# in response, the server sends to the current owner of the selection a SelectionRequest
event;
# the owner places the selected text in the property of the window that the requestor has specified by sending a ChangeProperty
; request to the server
# the owner sends a request to the server to send the requester a SelectionNotify
to notify that the selection has been transferred
# the requester can now read the selection in the property of the window by sending one or more GetProperty
requests to the server;
# the requester destroys the property; if the owner has requested to be informed of this, it is sent a PropertyNotify
event.
If the content is large, it should be transferred in chunks. In this case, both clients express interest in PropertyNotify
events: this way, the selection owner knows when the selection has been read, and the requester knows when another chunk has been placed in the property.
The XFixes extension allow clients to listen for selection changes.
Clipboard
The most used selection is thePRIMARY
selection, and is used when the user selects some data. The CLIPBOARD
selection is used when the user selects some data and explicitly requests it to be "copied" to the clipboard, such as by invoking "Copy" under the "Edit" menu of an application. An associated request of "Paste" results in the data of the CLIPBOARD
selection being used.
At the level of the core protocol, the PRIMARY
and CLIPBOARD
selections do not differ. But the xclipboard
client makes them behave differently. In particular, when another client asserts the ownership of the CLIPBOARD
selection, this program requests and displays it in a window. Any further request for this selection are handled by xclipboard
. This way, the content of the selection survives the client having copied it.
Cut buffers
Cut buffers are another mechanism to transfer data, in particular selected text. They are window properties of the root window, namedCUT_BUFFER1
, etc. Unlike selections, cut buffers do not involve a direct interaction between clients. Rather, when text is selected in a window, the window owner copies this text into the property of the root window called CUT_BUFFER1
. When the user pastes the text in another window, the window owner reads this property of the root window.
The xcutsel
program transfers data between selections and cut buffers, and the xcb
program allows various kinds of access to the cut buffers.
Cut buffers are considered obsolete.
XDND
XdndAware
which contains the highest version of the protocol that the program supports. This way, applications which support newer versions can fall back to older versions in order to interoperate correctly. In addition, all applications that are written without support for Xdnd will be ignored.
When the cursor enters the target window, the source checks the presence of the XdndAware
property on that window. If this property is present, an exchange begins:
* the source tells the target that the cursor has entered the target while dragging some data by sending an event XdndEnter
* the target can find out which kind of data is dragged (text, image, etc.) by looking at this event and possibly by further interaction with the source
While the cursor is inside the target window:
* the source sends XdndPosition
events to tell the target where the cursor currently is
* the target replies with XdndStatus
events to tell the source whether the data can be dropped in the current position
* the source sends a message XdndLeave
or XdndDrop
when the cursor has left the window or the button has been released, respectively
If the user drops, the target requests the selection from the source as usual. When the transfer of the selection is concluded, the target sends an XdndFinish
event to tell the source that the transfer has been successful.
In summary, the protocol is driven by the source, which keeps the target informed of what is happening with the cursor. In reply, the target tells the source whether a drop would be accepted or not. The target must also be informed when the user releases the mouse button, as this event starts a regular request for a selection, which is a protocol driven by the target.
The above is the description of the Xdnd convention for drag-and-drop. Different conventions for drag-and-drop are used in Motif, OffiX, and Amulet.
XDS
The ''Direct Save Protocol'', abbreviated ''XDS'' (for ''X'' Window ''D''irect ''S''ave Protocol), is a software protocol that supports saving files byPrograms
The following programs specifically operate on data transfer mechanisms: * xcutsel transfers data from selections to cut buffers or vice versa * xclipboard, glipper (See also
* X Window System protocols and architecture * X Window System core protocol * ICCCMReferences
External links