Dropping on non-XDND windows

# Drag-And-Drop Protocol for the X Window System

### Dropping on windows that do not support XDND

Since middle clicking is the universal shortcut for pasting in X, one can drop data into a window that does not support XDND by:

1. After the mouse has been released to trigger the drop, grab ownership of XA_PRIMARY.

2. Send a ButtonPress event and then a ButtonRelease event to the deepest subwindow containing the mouse to simulate a middle click. The times for these events should be the time of the actual button release +1 and +2, respectively. These values will not be used by anybody else, so one can unambiguously recognize the resulting `XConvertSelection()` request.

3. If a request for XA_PRIMARY arrives bearing the timestamp of either the ButtonPress or the ButtonRelease event, treat it as a request for XdndSelection. Note that you must use the X data types instead of the MIME types in this case. (e.g. XA_STRING instead of text/plain)

Since text is usually the only data that can be pasted into older programs that do not support XDND (e.g. `xterm` and `emacs`), it is a good idea to only use the above trick when dragging text. As an example, if one drags anything else and fakes a middle click in `xterm`, it will paste the contents of XA_SECONDARY, which is not what the user wants.

Thanks to Jeroen van der Zijp for the idea.

To get this to work with `xterm`, you must add

> `XTerm.VT100.allowSendEvents: True`

to your `.Xdefaults` file.

Last updated on September 9, 1998

Back to the main page.