Assuming the text editor already uses the selection mechanism to transfer text to other applications, adding the line number capability should be easy. It would simply need to look for a new target type that indicated to it to figure out what line number the selected text is on. It might choose the first line, if more than one line were selected, or simply display an error message telling the user to select a single line.

The debugger application would then make the call shown in Example 12-7.

Example 12-7. Setting the primary selection to a line number

Display display; Atom target;

Window debugger_window; Time time;

Bool only_if_exists; Atom data_prop;

/* We create atom for data to be put into */ data_prop = XInternAtom( display, "STOP_LINE_NUM",

only_if_exists = False);

/* Target type atom must have been created by owner */ target_type = XInternAtom(display, "LINE_NUMBER",

only_if_exists == True);

if (target_type == None) { fprintf(stderr, "%s: selection owner did not create \

LINE_NUMBER atom", argv[ 0 ]); return(False); }

XConvertSelection (display, XA_PRIMARY, target_type, data_prop, debugger_window, time == triggering_event_time)

/* Wait for a SelectionNotify event and, if the property * member is the same as data_prop, the conversion went fine; * if the property member is None, the conversion failed */

The server sends all of the above information in a SelectionRequest event to the text editor client (which had previously made itself the owner of the selection with XSet-Selection0wner()).

The text editor stores the data in the property specified in the SelectionRequest event on debugger_window, then sends a SelectionNotify event (using XSend-Event ( )) to the requesting application. Upon receiving this event, the debugger reads this property and uses its value to place a break point in the C program.

Now that you have seen a more practical application of selections, we'll move on to a more precise description of each step in the selection transfer process.

430 Xlib Programming Manual