Drag-And-Drop for files

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

### Dragging files

The goal of Drag-And-Drop is to allow users to quickly and easily move data from one program to another. This requires that all programs use the same protocol and the same data types.

An especially important data type is the file. All programs should accept dropped files where ever possible in order to allow users to use a graphical file manager to access their data.

Since UNIX provides powerful networking support and X allows the user to display file managers from different machines on the same screen, one must actually use the full URL, including the host name, for each file that is dragged. Simple programs can then reject files that are not available locally, while sophisticated programs can use a method such as ftp to retrieve them. (The sample implementation includes code to convert between URL's and local file names.)

The data type of a URL or list of URL's is text/uri-list. It is an error to not include the host name (the value returned by `gethostname()`) as part of the URL. (Consider the case when the user drags a file to the trash. Without the host name, this could delete a file from the wrong file system!)

In order for file managers to be able to communicate with each other, one also needs to be able to specify that the target perform particular actions on the dropped files. The predefined actions XdndActionCopy, XdndActionMove, and XdndActionLink should be used for this purpose. Targets other than file managers should respond with XdndActionPrivate to indicate that they will do something else with the files, e.g. search them, compile them, etc. File managers should provide visual feedback in the cursor if the target accepts the requested action. (e.g. display a small arrow if the target accepts XdndActionLink)

It is important to note that file managers will often have to block until receiving XdndFinished. As an example, if the user drags a file from a local directory to a directory opened via ftp, then the user should not be allowed to delete or move the file until the ftp transfer is complete. (Of course, the program should not block off more than these two directories.)

Dragging files to a trashcan is a special case that must be handled separately. In this case, the most natural model is for the user to set the trashcan to either store or incinerate mode and then for the trashcan to accept text/uri-list or XdndActionAsk. The former means "perform the action selected by the user," while the latter means "ask the user which action to perform in this case." The best way for the trashcan to tell the user about its current setting is to change its appearance.

When dragging files from a file manager window, the default action should be XdndActionMove.

When dragging files from other programs (e.g. a list of files to search or compile), XdndActionPrivate should be the default because it isn't clear what the user intends to do. File managers should treat this as copy, while trashcans should treat it as move.

Last updated on February 22, 2000

Back to the main page.