12.4 Selections

Selections are the primary mechanism X11 defines for clients that want to exchange information with other clients. A selection transfers arbitrary information between two clients. You can think of a selection as a piece of text or graphics that is highlighted in one application and can be pasted into another, though the information transferred can be almost anything. Clients are strongly encouraged to use this mechanism so that there is a uniform procedure in use by all applications.

The user may want to transfer information from an application and, at other times, to the application. Many applications need to be able to assume either role. In particular, clients should not display text in a permanent window without allowing the user to select it and convert it into a string, and any application that requires the user to type extensively should allow the user to paste in text from other applications.

Selections communicate between an owner client and a requestor client. The owner has the data representing the value of a selection, and the requestor wants it. The selection mechanism provides a way to notify other clients when useful data is placed in a property and to allow the owner of the data to convert it to a type asked for by the requestor.

Note that in the X11 environment, all data transferred between clients must go via the server (unless they are running on the same host, but that is a special case). An X11 client can neither assume that another client can open the same files nor communicate directly through IPC channels. The other client may be talking to the server via a completely different networking mechanism (for example, one client might be DECnet and the other TCP/IP). Thus, passing indirect references to data such as file names, hostnames, port numbers, and so on is permitted only if both clients specifically agree.

12.4.1 The Selection Mechanism

Let's look how a typical selection transaction occurs and then go into all the details of how to make it happen. From the user's point of view, it works like this:

1. The user highlights a selection of text or graphics in one application. For example, in xterm, selections are highlighted with the foreground and background colors reversed.

2. The user moves the pointer into another application and presses the key or button that indicates that the selection should be pasted. The keys or buttons used for this purpose in all applications probably should be the ones used by xterm, since most users use the cutting and pasting feature of xterm frequently.

The desired result is that the text or graphics should appear in the application in which it was pasted. Now how do two applications actually make this happen?

The application in which the text or graphics is being selected must first of all figure out what information is being selected and be able to convert it into a format that can be transferred to other applications. If the selection is text (usually the selection is a string) and the selected area is highlighted, by having the user drag the pointer over the area, then this application has to become the owner of a selection atom.

428 Xlib Programming Manual