0
|
1 /* X Selection processing for XEmacs
|
|
2 Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not synched with FSF. */
|
|
22
|
|
23 /* Rewritten by jwz */
|
|
24
|
|
25 #include <config.h>
|
|
26 #include "lisp.h"
|
|
27
|
|
28 #include "buffer.h"
|
|
29 #include "console-x.h"
|
|
30 #include "objects-x.h"
|
|
31
|
|
32 #include "frame.h"
|
|
33 #include "opaque.h"
|
|
34 #include "systime.h"
|
|
35
|
|
36 #ifdef LWLIB_USES_MOTIF
|
|
37 # define MOTIF_CLIPBOARDS
|
|
38 #endif
|
|
39
|
|
40 #ifdef MOTIF_CLIPBOARDS
|
|
41 # include <Xm/CutPaste.h>
|
|
42 static void hack_motif_clipboard_selection (Atom selection_atom,
|
|
43 Lisp_Object selection_value,
|
|
44 Time thyme, Display *display,
|
|
45 Window selecting_window,
|
|
46 Bool owned_p);
|
|
47 #endif
|
|
48
|
|
49 #define CUT_BUFFER_SUPPORT
|
|
50
|
|
51 Lisp_Object QPRIMARY, QSECONDARY, QSTRING, QINTEGER, QCLIPBOARD, QTIMESTAMP,
|
|
52 QTEXT, QDELETE, QMULTIPLE, QINCR, QEMACS_TMP, QTARGETS, QATOM, QNULL,
|
|
53 QATOM_PAIR, QCOMPOUND_TEXT;
|
|
54
|
|
55 #ifdef EPOCH
|
|
56 Lisp_Object QARC, QBITMAP, QCARDINAL, QCURSOR, QDRAWABLE, QFONT, QINTEGER,
|
|
57 QPIXMAP, QPOINT, QRECTANGLE, QWINDOW, QWM_HINTS, QWM_SIZE_HINTS;
|
|
58 #endif /* EPOCH */
|
|
59
|
|
60 #ifdef CUT_BUFFER_SUPPORT
|
|
61 Lisp_Object QCUT_BUFFER0, QCUT_BUFFER1, QCUT_BUFFER2, QCUT_BUFFER3,
|
|
62 QCUT_BUFFER4, QCUT_BUFFER5, QCUT_BUFFER6, QCUT_BUFFER7;
|
|
63 #endif
|
|
64
|
|
65 Lisp_Object Vx_lost_selection_hooks;
|
|
66 Lisp_Object Vx_sent_selection_hooks;
|
|
67
|
|
68 /* If this is a smaller number than the max-request-size of the display,
|
|
69 emacs will use INCR selection transfer when the selection is larger
|
|
70 than this. The max-request-size is usually around 64k, so if you want
|
|
71 emacs to use incremental selection transfers when the selection is
|
|
72 smaller than that, set this. I added this mostly for debugging the
|
|
73 incremental transfer stuff, but it might improve server performance.
|
|
74 */
|
|
75 #define MAX_SELECTION_QUANTUM 0xFFFFFF
|
|
76
|
|
77 #define SELECTION_QUANTUM(dpy) ((XMaxRequestSize (dpy) << 2) - 100)
|
|
78
|
|
79 /* This is an association list whose elements are of the form
|
|
80 ( selection-name selection-value selection-timestamp )
|
|
81 selection-name is a lisp symbol, whose name is the name of an X Atom.
|
|
82 selection-value is the value that emacs owns for that selection.
|
|
83 It may be any kind of Lisp object.
|
|
84 selection-timestamp is the time at which emacs began owning this selection,
|
|
85 as a cons of two 16-bit numbers (making a 32 bit time).
|
|
86 If there is an entry in this alist, then it can be assumed that emacs owns
|
|
87 that selection.
|
|
88 The only (eq) parts of this list that are visible from elisp are the
|
|
89 selection-values.
|
|
90 */
|
|
91 Lisp_Object Vselection_alist;
|
|
92
|
|
93 /* This is an alist whose CARs are selection-types (whose names are the same
|
|
94 as the names of X Atoms) and whose CDRs are the names of Lisp functions to
|
|
95 call to convert the given Emacs selection value to a string representing
|
|
96 the given selection type. This is for elisp-level extension of the emacs
|
|
97 selection handling.
|
|
98 */
|
|
99 Lisp_Object Vselection_converter_alist;
|
|
100
|
|
101 /* If the selection owner takes too long to reply to a selection request,
|
|
102 we give up on it. This is in seconds (0 = no timeout).
|
|
103 */
|
|
104 int x_selection_timeout;
|
|
105
|
|
106
|
|
107 /* Utility functions */
|
|
108
|
|
109 static void lisp_data_to_selection_data (struct device *,
|
|
110 Lisp_Object obj,
|
|
111 unsigned char **data_ret,
|
|
112 Atom *type_ret,
|
|
113 unsigned int *size_ret,
|
|
114 int *format_ret);
|
|
115 static Lisp_Object selection_data_to_lisp_data (struct device *,
|
|
116 unsigned char *data,
|
|
117 int size,
|
|
118 Atom type,
|
|
119 int format);
|
|
120 static Lisp_Object x_get_window_property_as_lisp_data (Display *,
|
|
121 Window,
|
|
122 Atom property,
|
|
123 Lisp_Object target_type,
|
|
124 Atom selection_atom);
|
|
125
|
|
126 static int expect_property_change (Display *, Window, Atom prop, int state);
|
|
127 static void wait_for_property_change (long);
|
|
128 static void unexpect_property_change (int);
|
|
129 static int waiting_for_other_props_on_window (Display *, Window);
|
|
130
|
|
131 /* This converts a Lisp symbol to a server Atom, avoiding a server
|
|
132 roundtrip whenever possible.
|
|
133 */
|
|
134 Atom
|
|
135 symbol_to_x_atom (struct device *d, Lisp_Object sym, int only_if_exists)
|
|
136 {
|
|
137 Display *display = DEVICE_X_DISPLAY (d);
|
|
138 Atom val;
|
|
139 if (NILP (sym)) return XA_PRIMARY;
|
|
140 if (EQ (sym, Qt)) return XA_SECONDARY;
|
|
141 if (EQ (sym, QPRIMARY)) return XA_PRIMARY;
|
|
142 if (EQ (sym, QSECONDARY)) return XA_SECONDARY;
|
|
143 if (EQ (sym, QSTRING)) return XA_STRING;
|
|
144 if (EQ (sym, QINTEGER)) return XA_INTEGER;
|
|
145 if (EQ (sym, QATOM)) return XA_ATOM;
|
|
146 if (EQ (sym, QCLIPBOARD)) return DEVICE_XATOM_CLIPBOARD (d);
|
|
147 if (EQ (sym, QTIMESTAMP)) return DEVICE_XATOM_TIMESTAMP (d);
|
|
148 if (EQ (sym, QTEXT)) return DEVICE_XATOM_TEXT (d);
|
|
149 if (EQ (sym, QDELETE)) return DEVICE_XATOM_DELETE (d);
|
|
150 if (EQ (sym, QMULTIPLE)) return DEVICE_XATOM_MULTIPLE (d);
|
|
151 if (EQ (sym, QINCR)) return DEVICE_XATOM_INCR (d);
|
|
152 if (EQ (sym, QEMACS_TMP)) return DEVICE_XATOM_EMACS_TMP (d);
|
|
153 if (EQ (sym, QTARGETS)) return DEVICE_XATOM_TARGETS (d);
|
|
154 if (EQ (sym, QNULL)) return DEVICE_XATOM_NULL (d);
|
|
155 if (EQ (sym, QATOM_PAIR)) return DEVICE_XATOM_ATOM_PAIR (d);
|
|
156 if (EQ (sym, QCOMPOUND_TEXT)) return DEVICE_XATOM_COMPOUND_TEXT (d);
|
|
157 #ifdef EPOCH
|
|
158 if (EQ (sym, QARC)) return XA_ARC;
|
|
159 if (EQ (sym, QBITMAP)) return XA_BITMAP;
|
|
160 if (EQ (sym, QCARDINAL)) return XA_CARDINAL;
|
|
161 if (EQ (sym, QCURSOR)) return XA_CURSOR;
|
|
162 if (EQ (sym, QDRAWABLE)) return XA_DRAWABLE;
|
|
163 if (EQ (sym, QFONT)) return XA_FONT;
|
|
164 if (EQ (sym, QINTEGER)) return XA_INTEGER;
|
|
165 if (EQ (sym, QPIXMAP)) return XA_PIXMAP;
|
|
166 if (EQ (sym, QPOINT)) return XA_POINT;
|
|
167 if (EQ (sym, QRECTANGLE)) return XA_RECTANGLE;
|
|
168 if (EQ (sym, QWINDOW)) return XA_WINDOW;
|
|
169 if (EQ (sym, QWM_HINTS)) return XA_WM_HINTS;
|
|
170 if (EQ (sym, QWM_SIZE_HINTS)) return XA_WM_SIZE_HINTS;
|
|
171 #endif /* EPOCH */
|
|
172
|
|
173 #ifdef CUT_BUFFER_SUPPORT
|
|
174 if (EQ (sym, QCUT_BUFFER0)) return XA_CUT_BUFFER0;
|
|
175 if (EQ (sym, QCUT_BUFFER1)) return XA_CUT_BUFFER1;
|
|
176 if (EQ (sym, QCUT_BUFFER2)) return XA_CUT_BUFFER2;
|
|
177 if (EQ (sym, QCUT_BUFFER3)) return XA_CUT_BUFFER3;
|
|
178 if (EQ (sym, QCUT_BUFFER4)) return XA_CUT_BUFFER4;
|
|
179 if (EQ (sym, QCUT_BUFFER5)) return XA_CUT_BUFFER5;
|
|
180 if (EQ (sym, QCUT_BUFFER6)) return XA_CUT_BUFFER6;
|
|
181 if (EQ (sym, QCUT_BUFFER7)) return XA_CUT_BUFFER7;
|
|
182 #endif
|
|
183 {
|
|
184 CONST char *nameext;
|
|
185 Lisp_Object namesym;
|
|
186 XSETSTRING (namesym, XSYMBOL (sym)->name);
|
|
187 GET_C_STRING_CTEXT_DATA_ALLOCA (namesym, nameext);
|
|
188 val = XInternAtom (display, nameext, only_if_exists ? True : False);
|
|
189 }
|
|
190 return val;
|
|
191 }
|
|
192
|
|
193
|
|
194 /* This converts a server Atom to a Lisp symbol, avoiding server roundtrips
|
|
195 and calls to intern whenever possible.
|
|
196 */
|
|
197 Lisp_Object
|
|
198 x_atom_to_symbol (struct device *d, Atom atom)
|
|
199 {
|
|
200 char *str;
|
|
201 Display *display = DEVICE_X_DISPLAY (d);
|
|
202
|
|
203 if (! atom) return Qnil;
|
|
204 if (atom == XA_PRIMARY) return QPRIMARY;
|
|
205 if (atom == XA_SECONDARY) return QSECONDARY;
|
|
206 if (atom == XA_STRING) return QSTRING;
|
|
207 if (atom == XA_INTEGER) return QINTEGER;
|
|
208 if (atom == XA_ATOM) return QATOM;
|
|
209 if (atom == DEVICE_XATOM_CLIPBOARD (d)) return QCLIPBOARD;
|
|
210 if (atom == DEVICE_XATOM_TIMESTAMP (d)) return QTIMESTAMP;
|
|
211 if (atom == DEVICE_XATOM_TEXT (d)) return QTEXT;
|
|
212 if (atom == DEVICE_XATOM_DELETE (d)) return QDELETE;
|
|
213 if (atom == DEVICE_XATOM_MULTIPLE (d)) return QMULTIPLE;
|
|
214 if (atom == DEVICE_XATOM_INCR (d)) return QINCR;
|
|
215 if (atom == DEVICE_XATOM_EMACS_TMP (d)) return QEMACS_TMP;
|
|
216 if (atom == DEVICE_XATOM_TARGETS (d)) return QTARGETS;
|
|
217 if (atom == DEVICE_XATOM_NULL (d)) return QNULL;
|
|
218 if (atom == DEVICE_XATOM_ATOM_PAIR (d)) return QATOM_PAIR;
|
|
219 if (atom == DEVICE_XATOM_COMPOUND_TEXT (d)) return QCOMPOUND_TEXT;
|
|
220
|
|
221 #ifdef EPOCH
|
|
222 if (atom == XA_ARC) return QARC;
|
|
223 if (atom == XA_BITMAP) return QBITMAP;
|
|
224 if (atom == XA_CARDINAL) return QCARDINAL;
|
|
225 if (atom == XA_CURSOR) return QCURSOR;
|
|
226 if (atom == XA_DRAWABLE) return QDRAWABLE;
|
|
227 if (atom == XA_FONT) return QFONT;
|
|
228 if (atom == XA_INTEGER) return QINTEGER;
|
|
229 if (atom == XA_PIXMAP) return QPIXMAP;
|
|
230 if (atom == XA_POINT) return QPOINT;
|
|
231 if (atom == XA_RECTANGLE) return QRECTANGLE;
|
|
232 if (atom == XA_WINDOW) return QWINDOW;
|
|
233 if (atom == XA_WM_HINTS) return QWM_HINTS;
|
|
234 if (atom == XA_WM_SIZE_HINTS) return QWM_SIZE_HINTS;
|
|
235 #endif /* EPOCH */
|
|
236 #ifdef CUT_BUFFER_SUPPORT
|
|
237 if (atom == XA_CUT_BUFFER0) return QCUT_BUFFER0;
|
|
238 if (atom == XA_CUT_BUFFER1) return QCUT_BUFFER1;
|
|
239 if (atom == XA_CUT_BUFFER2) return QCUT_BUFFER2;
|
|
240 if (atom == XA_CUT_BUFFER3) return QCUT_BUFFER3;
|
|
241 if (atom == XA_CUT_BUFFER4) return QCUT_BUFFER4;
|
|
242 if (atom == XA_CUT_BUFFER5) return QCUT_BUFFER5;
|
|
243 if (atom == XA_CUT_BUFFER6) return QCUT_BUFFER6;
|
|
244 if (atom == XA_CUT_BUFFER7) return QCUT_BUFFER7;
|
|
245 #endif
|
|
246
|
|
247 str = XGetAtomName (display, atom);
|
|
248 if (! str) return Qnil;
|
|
249 {
|
|
250 CONST char *intstr;
|
|
251 Lisp_Object val;
|
|
252
|
|
253 GET_C_CHARPTR_INT_CTEXT_DATA_ALLOCA (str, intstr);
|
|
254 val = intern (intstr);
|
|
255 XFree (str);
|
|
256 return val;
|
|
257 }
|
|
258 }
|
|
259
|
|
260
|
|
261 /* Do protocol to assert ourself as a selection owner.
|
|
262 Update the Vselection_alist so that we can reply to later requests for
|
|
263 our selection.
|
|
264 */
|
|
265 static void
|
|
266 x_own_selection (Lisp_Object selection_name, Lisp_Object selection_value)
|
|
267 {
|
|
268 struct device *d = decode_x_device (Qnil);
|
|
269 Display *display = DEVICE_X_DISPLAY (d);
|
|
270 struct frame *sel_frame = selected_frame ();
|
|
271 Window selecting_window = XtWindow (FRAME_X_TEXT_WIDGET (sel_frame));
|
|
272 /* Use the time of the last-read mouse or keyboard event.
|
|
273 For selection purposes, we use this as a sleazy way of knowing what the
|
|
274 current time is in server-time. This assumes that the most recently read
|
|
275 mouse or keyboard event has something to do with the assertion of the
|
|
276 selection, which is probably true.
|
|
277 */
|
|
278 Time thyme = DEVICE_X_MOUSE_TIMESTAMP (d);
|
|
279 Atom selection_atom;
|
|
280
|
|
281 CHECK_SYMBOL (selection_name);
|
|
282 selection_atom = symbol_to_x_atom (d, selection_name, 0);
|
|
283
|
|
284 XSetSelectionOwner (display, selection_atom, selecting_window, thyme);
|
|
285
|
|
286 /* Now update the local cache */
|
|
287 {
|
|
288 /* We do NOT use time_to_lisp() here any more, like we used to.
|
|
289 That assumed equivalence of time_t and Time, which is not
|
|
290 necessarily the case (e.g. under OSF on the Alphas, where
|
|
291 Time is a 64-bit quantity and time_t is a 32-bit quantity).
|
|
292
|
|
293 Opaque pointers are the clean way to go here.
|
|
294 */
|
|
295 Lisp_Object selection_time = make_opaque (sizeof (thyme), (void *) &thyme);
|
|
296 Lisp_Object selection_data = Fcons (selection_name,
|
|
297 Fcons (selection_value,
|
|
298 Fcons (selection_time, Qnil)));
|
|
299 Lisp_Object prev_value = assq_no_quit (selection_name, Vselection_alist);
|
|
300 Vselection_alist = Fcons (selection_data, Vselection_alist);
|
|
301
|
|
302 /* If we already owned the selection, remove the old selection data.
|
|
303 Perhaps we should destructively modify it instead.
|
|
304 Don't use Fdelq() as that may QUIT;.
|
|
305 */
|
|
306 if (!NILP (prev_value))
|
|
307 {
|
|
308 Lisp_Object rest; /* we know it's not the CAR, so it's easy. */
|
|
309 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
|
|
310 if (EQ (prev_value, Fcar (XCDR (rest))))
|
|
311 {
|
|
312 XCDR (rest) = Fcdr (XCDR (rest));
|
|
313 break;
|
|
314 }
|
|
315 }
|
|
316 #ifdef MOTIF_CLIPBOARDS
|
|
317 hack_motif_clipboard_selection (selection_atom, selection_value,
|
|
318 thyme, display, selecting_window,
|
|
319 !NILP (prev_value));
|
|
320 #endif
|
|
321 }
|
|
322 }
|
|
323
|
|
324
|
|
325 #ifdef MOTIF_CLIPBOARDS /* Bend over baby. Take it and like it. */
|
|
326
|
|
327 # ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
|
|
328 static void motif_clipboard_cb ();
|
|
329 # endif
|
|
330
|
|
331 static void
|
|
332 hack_motif_clipboard_selection (Atom selection_atom,
|
|
333 Lisp_Object selection_value,
|
|
334 Time thyme,
|
|
335 Display *display,
|
|
336 Window selecting_window,
|
|
337 Bool owned_p)
|
|
338 {
|
|
339 struct device *d = get_device_from_display (display);
|
|
340 /* Those Motif wankers can't be bothered to follow the ICCCM, and do
|
|
341 their own non-Xlib non-Xt clipboard processing. So we have to do
|
|
342 this so that linked-in Motif widgets don't get themselves wedged.
|
|
343 */
|
|
344 if (selection_atom == DEVICE_XATOM_CLIPBOARD (d)
|
|
345 && STRINGP (selection_value)
|
|
346
|
|
347 /* If we already own the clipboard, don't own it again in the Motif
|
|
348 way. This might lose in some subtle way, since the timestamp won't
|
|
349 be current, but owning the selection on the Motif way does a
|
|
350 SHITLOAD of X protocol, and it makes killing text be incredibly
|
|
351 slow when using an X terminal. ARRRRGGGHHH!!!!
|
|
352 */
|
|
353 /* No, this is no good, because then Motif text fields don't bother
|
|
354 to look up the new value, and you can't Copy from a buffer, Paste
|
|
355 into a text field, then Copy something else from the buffer and
|
2
|
356 paste it into the text field -- it pastes the first thing again. */
|
0
|
357 /* && !owned_p */
|
|
358 )
|
|
359 {
|
|
360 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
|
|
361 Widget widget = FRAME_X_TEXT_WIDGET (selected_frame());
|
|
362 #endif
|
|
363 long itemid;
|
|
364 #if XmVersion >= 1002
|
|
365 long dataid;
|
|
366 #else
|
|
367 int dataid; /* 1.2 wants long, but 1.1.5 wants int... */
|
|
368 #endif
|
|
369 XmString fmh;
|
2
|
370 fmh = XmStringCreateLtoR ((String) "Clipboard",
|
|
371 XmSTRING_DEFAULT_CHARSET);
|
0
|
372 while (ClipboardSuccess !=
|
|
373 XmClipboardStartCopy (display, selecting_window, fmh, thyme,
|
|
374 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
|
|
375 widget, motif_clipboard_cb,
|
|
376 #else
|
|
377 0, NULL,
|
|
378 #endif
|
|
379 &itemid))
|
|
380 ;
|
|
381 XmStringFree (fmh);
|
|
382 while (ClipboardSuccess !=
|
2
|
383 XmClipboardCopy (display, selecting_window, itemid,
|
|
384 (String) "STRING",
|
0
|
385 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
|
|
386 /* O'Reilly examples say size can be 0,
|
|
387 but this clearly is not the case. */
|
|
388 0, string_length (XSTRING (selection_value)) + 1,
|
|
389 (int) selecting_window, /* private id */
|
|
390 #else /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
|
|
391 (char *) string_data (XSTRING (selection_value)),
|
|
392 string_length (XSTRING (selection_value)) + 1,
|
|
393 0,
|
|
394 #endif /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
|
|
395 &dataid))
|
|
396 ;
|
|
397 while (ClipboardSuccess !=
|
|
398 XmClipboardEndCopy (display, selecting_window, itemid))
|
|
399 ;
|
|
400 }
|
|
401 }
|
|
402
|
|
403 # ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
|
|
404 /* I tried to treat the clipboard like a real selection, and not send
|
|
405 the data until it was requested, but it looks like that just doesn't
|
|
406 work at all unless the selection owner and requestor are in different
|
|
407 processes. From reading the Motif source, it looks like they never
|
|
408 even considered having two widgets in the same application transfer
|
|
409 data between each other using "by-name" clipboard values. What a
|
|
410 bunch of fuckups.
|
|
411 */
|
|
412 static void
|
|
413 motif_clipboard_cb (Widget widget, int *data_id, int *private_id, int *reason)
|
|
414 {
|
|
415 switch (*reason)
|
|
416 {
|
|
417 case XmCR_CLIPBOARD_DATA_REQUEST:
|
|
418 {
|
|
419 Display *dpy = XtDisplay (widget);
|
|
420 Window window = (Window) *private_id;
|
|
421 Lisp_Object selection = assq_no_quit (QCLIPBOARD, Vselection_alist);
|
|
422 if (NILP (selection)) abort ();
|
|
423 selection = XCDR (selection);
|
|
424 if (!STRINGP (selection)) abort ();
|
|
425 XmClipboardCopyByName (dpy, window, *data_id,
|
|
426 (char *) string_data (XSTRING (selection)),
|
|
427 string_length (XSTRING (selection)) + 1,
|
|
428 0);
|
|
429 }
|
|
430 break;
|
|
431 case XmCR_CLIPBOARD_DATA_DELETE:
|
|
432 default:
|
|
433 /* don't need to free anything */
|
|
434 break;
|
|
435 }
|
|
436 }
|
|
437 # endif /* MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
|
|
438 #endif /* MOTIF_CLIPBOARDS */
|
|
439
|
|
440
|
|
441 /* Given a selection-name and desired type, this looks up our local copy of
|
|
442 the selection value and converts it to the type. It returns nil or a
|
|
443 string. This calls random elisp code, and may signal or gc.
|
|
444 */
|
|
445 static Lisp_Object
|
|
446 x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
|
|
447 {
|
|
448 /* This function can GC */
|
|
449 Lisp_Object local_value = assq_no_quit (selection_symbol, Vselection_alist);
|
|
450 Lisp_Object handler_fn, value, check;
|
|
451
|
|
452 if (NILP (local_value)) return Qnil;
|
|
453
|
|
454 /* TIMESTAMP and MULTIPLE are special cases 'cause that's easiest. */
|
|
455 if (EQ (target_type, QTIMESTAMP))
|
|
456 {
|
|
457 handler_fn = Qnil;
|
|
458 value = XCAR (XCDR (XCDR (local_value)));
|
|
459 }
|
|
460
|
|
461 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
462 else if (CONSP (target_type) &&
|
|
463 XCAR (target_type) == QMULTIPLE)
|
|
464 {
|
|
465 Lisp_Object pairs = XCDR (target_type);
|
|
466 int size = XVECTOR (pairs)->size;
|
|
467 int i;
|
|
468 /* If the target is MULTIPLE, then target_type looks like
|
|
469 (MULTIPLE . [[SELECTION1 TARGET1] [SELECTION2 TARGET2] ... ])
|
|
470 We modify the second element of each pair in the vector and
|
|
471 return it as [[SELECTION1 <value1>] [SELECTION2 <value2>] ... ]
|
|
472 */
|
|
473 for (i = 0; i < size; i++)
|
|
474 {
|
|
475 Lisp_Object pair = vector_data (XVECTOR (pairs)) [i];
|
|
476 vector_data (XVECTOR (pair)) [1] =
|
|
477 x_get_local_selection (vector_data (XVECTOR (pair)) [0],
|
|
478 vector_data (XVECTOR (pair)) [1]);
|
|
479 }
|
|
480 return pairs;
|
|
481 }
|
|
482 #endif
|
|
483 else
|
|
484 {
|
|
485 CHECK_SYMBOL (target_type);
|
|
486 handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist));
|
|
487 if (NILP (handler_fn)) return Qnil;
|
|
488 value = call3 (handler_fn,
|
|
489 selection_symbol, target_type,
|
|
490 XCAR (XCDR (local_value)));
|
|
491 }
|
|
492
|
|
493 /* This lets the selection function to return (TYPE . VALUE). For example,
|
|
494 when the selected type is LINE_NUMBER, the returned type is SPAN, not
|
|
495 INTEGER.
|
|
496 */
|
|
497 check = value;
|
|
498 if (CONSP (value) && SYMBOLP (XCAR (value)))
|
|
499 check = XCDR (value);
|
|
500
|
|
501 /* Strings, vectors, and symbols are converted to selection data format in
|
|
502 the obvious way. Integers are converted to 16 bit quantities if they're
|
|
503 small enough, otherwise 32 bits are used.
|
|
504 */
|
|
505 if (STRINGP (check) ||
|
|
506 VECTORP (check) ||
|
|
507 SYMBOLP (check) ||
|
2
|
508 INTP (check) ||
|
|
509 CHARP (check) ||
|
0
|
510 NILP (value))
|
|
511 return value;
|
|
512
|
|
513 /* (N . M) or (N M) get turned into a 32 bit quantity. So if you want to
|
|
514 always return a small quantity as 32 bits, your converter routine needs
|
|
515 to return a cons.
|
|
516 */
|
|
517 else if (CONSP (check) &&
|
|
518 INTP (XCAR (check)) &&
|
|
519 (INTP (XCDR (check)) ||
|
|
520 (CONSP (XCDR (check)) &&
|
|
521 INTP (XCAR (XCDR (check))) &&
|
|
522 NILP (XCDR (XCDR (check))))))
|
|
523 return value;
|
|
524 /* Otherwise the lisp converter function returned something unrecognized.
|
|
525 */
|
|
526 else
|
|
527 signal_error (Qerror,
|
|
528 list3 (build_string
|
|
529 ("unrecognized selection-conversion type"),
|
|
530 handler_fn,
|
|
531 value));
|
|
532
|
|
533 return Qnil; /* suppress compiler warning */
|
|
534 }
|
|
535
|
|
536
|
|
537
|
|
538 /* Send a SelectionNotify event to the requestor with property=None, meaning
|
|
539 we were unable to do what they wanted.
|
|
540 */
|
|
541 static void
|
|
542 x_decline_selection_request (XSelectionRequestEvent *event)
|
|
543 {
|
|
544 XSelectionEvent reply;
|
|
545 reply.type = SelectionNotify;
|
|
546 reply.display = event->display;
|
|
547 reply.requestor = event->requestor;
|
|
548 reply.selection = event->selection;
|
|
549 reply.time = event->time;
|
|
550 reply.target = event->target;
|
|
551 reply.property = None;
|
|
552
|
|
553 (void) XSendEvent (reply.display, reply.requestor, False, 0L,
|
|
554 (XEvent *) &reply);
|
|
555 XFlush (reply.display);
|
|
556 }
|
|
557
|
|
558
|
|
559 /* Used as an unwind-protect clause so that, if a selection-converter signals
|
|
560 an error, we tell the requestor that we were unable to do what they wanted
|
|
561 before we throw to top-level or go into the debugger or whatever.
|
|
562 */
|
|
563 static Lisp_Object
|
|
564 x_selection_request_lisp_error (Lisp_Object closure)
|
|
565 {
|
|
566 XSelectionRequestEvent *event = (XSelectionRequestEvent *)
|
|
567 get_opaque_ptr (closure);
|
|
568
|
|
569 free_opaque_ptr (closure);
|
|
570 if (event->type == 0) /* we set this to mean "completed normally" */
|
|
571 return Qnil;
|
|
572 x_decline_selection_request (event);
|
|
573 return Qnil;
|
|
574 }
|
|
575
|
|
576
|
|
577 /* Convert our selection to the requested type, and put that data where the
|
|
578 requestor wants it. Then tell them whether we've succeeded.
|
|
579 */
|
|
580 static void
|
|
581 x_reply_selection_request (XSelectionRequestEvent *event, int format,
|
|
582 unsigned char *data, int size, Atom type)
|
|
583 {
|
|
584 /* This function can GC */
|
|
585 XSelectionEvent reply;
|
|
586 Display *display = event->display;
|
|
587 struct device *d = get_device_from_display (display);
|
|
588 Window window = event->requestor;
|
|
589 int bytes_remaining;
|
|
590 int format_bytes = format/8;
|
|
591 int max_bytes = SELECTION_QUANTUM (display);
|
|
592 if (max_bytes > MAX_SELECTION_QUANTUM) max_bytes = MAX_SELECTION_QUANTUM;
|
|
593
|
|
594 reply.type = SelectionNotify;
|
|
595 reply.display = display;
|
|
596 reply.requestor = window;
|
|
597 reply.selection = event->selection;
|
|
598 reply.time = event->time;
|
|
599 reply.target = event->target;
|
|
600 reply.property = (event->property == None ? event->target : event->property);
|
|
601
|
|
602 /* #### XChangeProperty can generate BadAlloc, and we must handle it! */
|
|
603
|
|
604 /* Store the data on the requested property.
|
|
605 If the selection is large, only store the first N bytes of it.
|
|
606 */
|
|
607 bytes_remaining = size * format_bytes;
|
|
608 if (bytes_remaining <= max_bytes)
|
|
609 {
|
|
610 /* Send all the data at once, with minimal handshaking. */
|
|
611 #if 0
|
|
612 stderr_out ("\nStoring all %d\n", bytes_remaining);
|
|
613 #endif
|
|
614 XChangeProperty (display, window, reply.property, type, format,
|
|
615 PropModeReplace, data, size);
|
|
616 /* At this point, the selection was successfully stored; ack it. */
|
|
617 (void) XSendEvent (display, window, False, 0L, (XEvent *) &reply);
|
|
618 XFlush (display);
|
|
619 }
|
|
620 else
|
|
621 {
|
|
622 /* Send an INCR selection. */
|
|
623 int prop_id;
|
|
624
|
|
625 if (x_window_to_frame (d, window)) /* #### debug */
|
|
626 error ("attempt to transfer an INCR to ourself!");
|
|
627 #if 0
|
|
628 stderr_out ("\nINCR %d\n", bytes_remaining);
|
|
629 #endif
|
|
630 prop_id = expect_property_change (display, window, reply.property,
|
|
631 PropertyDelete);
|
|
632
|
|
633 XChangeProperty (display, window, reply.property, DEVICE_XATOM_INCR (d),
|
|
634 32, PropModeReplace, (unsigned char *)
|
|
635 &bytes_remaining, 1);
|
|
636 XSelectInput (display, window, PropertyChangeMask);
|
|
637 /* Tell 'em the INCR data is there... */
|
|
638 (void) XSendEvent (display, window, False, 0L, (XEvent *) &reply);
|
|
639 XFlush (display);
|
|
640
|
|
641 /* First, wait for the requestor to ack by deleting the property.
|
|
642 This can run random lisp code (process handlers) or signal.
|
|
643 */
|
|
644 wait_for_property_change (prop_id);
|
|
645
|
|
646 while (bytes_remaining)
|
|
647 {
|
|
648 int i = ((bytes_remaining < max_bytes)
|
|
649 ? bytes_remaining
|
|
650 : max_bytes);
|
|
651 prop_id = expect_property_change (display, window, reply.property,
|
|
652 PropertyDelete);
|
|
653 #if 0
|
|
654 stderr_out (" INCR adding %d\n", i);
|
|
655 #endif
|
|
656 /* Append the next chunk of data to the property. */
|
|
657 XChangeProperty (display, window, reply.property, type, format,
|
|
658 PropModeAppend, data, i / format_bytes);
|
|
659 bytes_remaining -= i;
|
|
660 data += i;
|
|
661
|
|
662 /* Now wait for the requestor to ack this chunk by deleting the
|
|
663 property. This can run random lisp code or signal.
|
|
664 */
|
|
665 wait_for_property_change (prop_id);
|
|
666 }
|
|
667 /* Now write a zero-length chunk to the property to tell the requestor
|
|
668 that we're done. */
|
|
669 #if 0
|
|
670 stderr_out (" INCR done\n");
|
|
671 #endif
|
|
672 if (! waiting_for_other_props_on_window (display, window))
|
|
673 XSelectInput (display, window, 0L);
|
|
674
|
|
675 XChangeProperty (display, window, reply.property, type, format,
|
|
676 PropModeReplace, data, 0);
|
|
677 }
|
|
678 }
|
|
679
|
|
680
|
|
681
|
|
682 /* Called from the event-loop in response to a SelectionRequest event.
|
|
683 */
|
|
684 void
|
|
685 x_handle_selection_request (XSelectionRequestEvent *event)
|
|
686 {
|
|
687 /* This function can GC */
|
|
688 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
689 XSelectionEvent reply;
|
|
690 Lisp_Object local_selection_data = Qnil;
|
|
691 Lisp_Object selection_symbol;
|
|
692 Lisp_Object target_symbol = Qnil;
|
|
693 Lisp_Object converted_selection = Qnil;
|
|
694 Time local_selection_time;
|
|
695 Lisp_Object successful_p = Qnil;
|
|
696 int count;
|
|
697 struct device *d = get_device_from_display (event->display);
|
|
698
|
|
699 GCPRO3 (local_selection_data, converted_selection, target_symbol);
|
|
700
|
|
701 reply.type = SelectionNotify; /* Construct the reply event */
|
|
702 reply.display = event->display;
|
|
703 reply.requestor = event->requestor;
|
|
704 reply.selection = event->selection;
|
|
705 reply.time = event->time;
|
|
706 reply.target = event->target;
|
|
707 reply.property = (event->property == None ? event->target : event->property);
|
|
708
|
|
709 selection_symbol = x_atom_to_symbol (d, event->selection);
|
|
710
|
|
711 local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
|
|
712
|
|
713 #if 0
|
|
714 # define CDR(x) (XCDR (x))
|
|
715 # define CAR(x) (XCAR (x))
|
|
716 /* This list isn't user-visible, so it can't "go bad." */
|
|
717 if (!CONSP (local_selection_data)) abort ();
|
|
718 if (!CONSP (CDR (local_selection_data))) abort ();
|
|
719 if (!CONSP (CDR (CDR (local_selection_data)))) abort ();
|
|
720 if (!NILP (CDR (CDR (CDR (local_selection_data))))) abort ();
|
|
721 if (!CONSP (CAR (CDR (CDR (local_selection_data))))) abort ();
|
|
722 if (!INTP (CAR (CAR (CDR (CDR (local_selection_data)))))) abort ();
|
|
723 if (!INTP (CDR (CAR (CDR (CDR (local_selection_data)))))) abort ();
|
|
724 # undef CAR
|
|
725 # undef CDR
|
|
726 #endif
|
|
727
|
|
728 if (NILP (local_selection_data))
|
|
729 {
|
|
730 /* Someone asked for the selection, but we don't have it any more.
|
|
731 */
|
|
732 x_decline_selection_request (event);
|
|
733 goto DONE_LABEL;
|
|
734 }
|
|
735
|
|
736 local_selection_time =
|
|
737 * (Time *) XOPAQUE_DATA (XCAR (XCDR (XCDR (local_selection_data))));
|
|
738
|
|
739 if (event->time != CurrentTime &&
|
|
740 local_selection_time > event->time)
|
|
741 {
|
|
742 /* Someone asked for the selection, and we have one, but not the one
|
|
743 they're looking for.
|
|
744 */
|
|
745 x_decline_selection_request (event);
|
|
746 goto DONE_LABEL;
|
|
747 }
|
|
748
|
|
749 count = specpdl_depth ();
|
|
750 record_unwind_protect (x_selection_request_lisp_error,
|
|
751 make_opaque_ptr (event));
|
|
752 target_symbol = x_atom_to_symbol (d, event->target);
|
|
753
|
|
754 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
755 if (EQ (target_symbol, QMULTIPLE))
|
|
756 target_symbol = fetch_multiple_target (event);
|
|
757 #endif
|
|
758
|
|
759 /* Convert lisp objects back into binary data */
|
|
760
|
|
761 converted_selection =
|
|
762 x_get_local_selection (selection_symbol, target_symbol);
|
|
763
|
|
764 if (! NILP (converted_selection))
|
|
765 {
|
|
766 unsigned char *data;
|
|
767 unsigned int size;
|
|
768 int format;
|
|
769 Atom type;
|
|
770 lisp_data_to_selection_data (d, converted_selection,
|
|
771 &data, &type, &size, &format);
|
|
772
|
|
773 x_reply_selection_request (event, format, data, size, type);
|
|
774 successful_p = Qt;
|
|
775 /* Tell x_selection_request_lisp_error() it's cool. */
|
|
776 event->type = 0;
|
|
777 xfree (data);
|
|
778 }
|
|
779 unbind_to (count, Qnil);
|
|
780
|
|
781 DONE_LABEL:
|
|
782
|
|
783 UNGCPRO;
|
|
784
|
|
785 /* Let random lisp code notice that the selection has been asked for.
|
|
786 */
|
|
787 {
|
|
788 Lisp_Object rest;
|
|
789 Lisp_Object val = Vx_sent_selection_hooks;
|
|
790 if (!UNBOUNDP (val) && !NILP (val))
|
|
791 {
|
|
792 if (CONSP (val) && !EQ (XCAR (val), Qlambda))
|
|
793 for (rest = val; !NILP (rest); rest = Fcdr (rest))
|
|
794 call3 (Fcar(rest), selection_symbol, target_symbol,
|
|
795 successful_p);
|
|
796 else
|
|
797 call3 (val, selection_symbol, target_symbol,
|
|
798 successful_p);
|
|
799 }
|
|
800 }
|
|
801 }
|
|
802
|
|
803
|
|
804 /* Called from the event-loop in response to a SelectionClear event.
|
|
805 */
|
|
806 void
|
|
807 x_handle_selection_clear (XSelectionClearEvent *event)
|
|
808 {
|
|
809 Display *display = event->display;
|
|
810 struct device *d = get_device_from_display (display);
|
|
811 Atom selection = event->selection;
|
|
812 Time changed_owner_time = event->time;
|
|
813
|
|
814 Lisp_Object selection_symbol, local_selection_data;
|
|
815 Time local_selection_time;
|
|
816
|
|
817 selection_symbol = x_atom_to_symbol (d, selection);
|
|
818
|
|
819 local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
|
|
820
|
|
821 /* Well, we already believe that we don't own it, so that's just fine. */
|
|
822 if (NILP (local_selection_data)) return;
|
|
823
|
|
824 local_selection_time =
|
|
825 * (Time *) XOPAQUE_DATA (XCAR (XCDR (XCDR (local_selection_data))));
|
|
826
|
|
827 /* This SelectionClear is for a selection that we no longer own, so we can
|
|
828 disregard it. (That is, we have reasserted the selection since this
|
|
829 request was generated.)
|
|
830 */
|
|
831 if (changed_owner_time != CurrentTime &&
|
|
832 local_selection_time > changed_owner_time)
|
|
833 return;
|
|
834
|
|
835 /* Otherwise, we're really honest and truly being told to drop it.
|
|
836 Don't use Fdelq() as that may QUIT;.
|
|
837 */
|
|
838 if (EQ (local_selection_data, Fcar (Vselection_alist)))
|
|
839 Vselection_alist = Fcdr (Vselection_alist);
|
|
840 else
|
|
841 {
|
|
842 Lisp_Object rest;
|
|
843 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
|
|
844 if (EQ (local_selection_data, Fcar (XCDR (rest))))
|
|
845 {
|
|
846 XCDR (rest) = Fcdr (XCDR (rest));
|
|
847 break;
|
|
848 }
|
|
849 }
|
|
850
|
|
851 /* Let random lisp code notice that the selection has been stolen.
|
|
852 */
|
|
853 {
|
|
854 Lisp_Object rest;
|
|
855 Lisp_Object val = Vx_lost_selection_hooks;
|
|
856 if (!UNBOUNDP (val) && !NILP (val))
|
|
857 {
|
|
858 if (CONSP (val) && !EQ (XCAR (val), Qlambda))
|
|
859 for (rest = val; !NILP (rest); rest = Fcdr (rest))
|
|
860 call1 (Fcar (rest), selection_symbol);
|
|
861 else
|
|
862 call1 (val, selection_symbol);
|
|
863 }
|
|
864 }
|
|
865 }
|
|
866
|
|
867
|
|
868 /* This stuff is so that INCR selections are reentrant (that is, so we can
|
|
869 be servicing multiple INCR selection requests simultaneously). I haven't
|
|
870 actually tested that yet.
|
|
871 */
|
|
872
|
|
873 static int prop_location_tick;
|
|
874
|
|
875 static struct prop_location {
|
|
876 int tick;
|
|
877 Display *display;
|
|
878 Window window;
|
|
879 Atom property;
|
|
880 int desired_state;
|
|
881 struct prop_location *next;
|
|
882 } *for_whom_the_bell_tolls;
|
|
883
|
|
884
|
|
885 static int
|
|
886 property_deleted_p (void *tick)
|
|
887 {
|
|
888 struct prop_location *rest = for_whom_the_bell_tolls;
|
|
889 while (rest)
|
|
890 if (rest->tick == (long) tick)
|
|
891 return 0;
|
|
892 else
|
|
893 rest = rest->next;
|
|
894 return 1;
|
|
895 }
|
|
896
|
|
897 static int
|
|
898 waiting_for_other_props_on_window (Display *display, Window window)
|
|
899 {
|
|
900 struct prop_location *rest = for_whom_the_bell_tolls;
|
|
901 while (rest)
|
|
902 if (rest->display == display && rest->window == window)
|
|
903 return 1;
|
|
904 else
|
|
905 rest = rest->next;
|
|
906 return 0;
|
|
907 }
|
|
908
|
|
909
|
|
910 static int
|
|
911 expect_property_change (Display *display, Window window,
|
|
912 Atom property, int state)
|
|
913 {
|
|
914 struct prop_location *pl = (struct prop_location *)
|
|
915 xmalloc (sizeof (struct prop_location));
|
|
916 pl->tick = ++prop_location_tick;
|
|
917 pl->display = display;
|
|
918 pl->window = window;
|
|
919 pl->property = property;
|
|
920 pl->desired_state = state;
|
|
921 pl->next = for_whom_the_bell_tolls;
|
|
922 for_whom_the_bell_tolls = pl;
|
|
923 return pl->tick;
|
|
924 }
|
|
925
|
|
926 static void
|
|
927 unexpect_property_change (int tick)
|
|
928 {
|
|
929 struct prop_location *prev = 0, *rest = for_whom_the_bell_tolls;
|
|
930 while (rest)
|
|
931 {
|
|
932 if (rest->tick == tick)
|
|
933 {
|
|
934 if (prev)
|
|
935 prev->next = rest->next;
|
|
936 else
|
|
937 for_whom_the_bell_tolls = rest->next;
|
|
938 xfree (rest);
|
|
939 return;
|
|
940 }
|
|
941 prev = rest;
|
|
942 rest = rest->next;
|
|
943 }
|
|
944 }
|
|
945
|
|
946 static void
|
|
947 wait_for_property_change (long tick)
|
|
948 {
|
|
949 /* This function can GC */
|
|
950 wait_delaying_user_input (property_deleted_p, (void *) tick);
|
|
951 }
|
|
952
|
|
953
|
|
954 /* Called from the event-loop in response to a PropertyNotify event.
|
|
955 */
|
|
956 void
|
|
957 x_handle_property_notify (XPropertyEvent *event)
|
|
958 {
|
|
959 struct prop_location *prev = 0, *rest = for_whom_the_bell_tolls;
|
|
960 while (rest)
|
|
961 {
|
|
962 if (rest->property == event->atom &&
|
|
963 rest->window == event->window &&
|
|
964 rest->display == event->display &&
|
|
965 rest->desired_state == event->state)
|
|
966 {
|
|
967 #if 0
|
|
968 stderr_out ("Saw expected prop-%s on %s\n",
|
|
969 (event->state == PropertyDelete ? "delete" : "change"),
|
|
970 (char *) string_data (XSYMBOL (x_atom_to_symbol (get_device_from_display (event->display), event->atom))->name);
|
|
971 #endif
|
|
972 if (prev)
|
|
973 prev->next = rest->next;
|
|
974 else
|
|
975 for_whom_the_bell_tolls = rest->next;
|
|
976 xfree (rest);
|
|
977 return;
|
|
978 }
|
|
979 prev = rest;
|
|
980 rest = rest->next;
|
|
981 }
|
|
982 #if 0
|
|
983 stderr_out ("Saw UNexpected prop-%s on %s\n",
|
|
984 (event->state == PropertyDelete ? "delete" : "change"),
|
|
985 (char *) string_data (XSYMBOL (x_atom_to_symbol (get_device_from_display (event->display), event->atom))->name));
|
|
986 #endif
|
|
987 }
|
|
988
|
|
989
|
|
990
|
|
991 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
992
|
|
993 static Lisp_Object
|
|
994 fetch_multiple_target (XSelectionRequestEvent *event)
|
|
995 {
|
|
996 /* This function can GC */
|
|
997 Display *display = event->display;
|
|
998 Window window = event->requestor;
|
|
999 Atom target = event->target;
|
|
1000 Atom selection_atom = event->selection;
|
|
1001 int result;
|
|
1002
|
|
1003 return
|
|
1004 Fcons (QMULTIPLE,
|
|
1005 x_get_window_property_as_lisp_data (display, window, target,
|
|
1006 QMULTIPLE,
|
|
1007 selection_atom));
|
|
1008 }
|
|
1009
|
|
1010 static Lisp_Object
|
|
1011 copy_multiple_data (Lisp_Object obj)
|
|
1012 {
|
|
1013 Lisp_Object vec;
|
|
1014 int i;
|
|
1015 int size;
|
|
1016 if (CONSP (obj))
|
|
1017 return Fcons (XCAR (obj), copy_multiple_data (XCDR (obj)));
|
|
1018
|
|
1019 CHECK_VECTOR (obj);
|
|
1020 size = XVECTOR (obj)->size;
|
|
1021 vec = make_vector (size, Qnil);
|
|
1022 for (i = 0; i < size; i++)
|
|
1023 {
|
|
1024 Lisp_Object vec2 = vector_data (XVECTOR (obj)) [i];
|
|
1025 CHECK_VECTOR (vec2);
|
|
1026 if (XVECTOR (vec2)->size != 2)
|
|
1027 signal_error (Qerror, list2 (build_string
|
|
1028 ("vectors must be of length 2"),
|
|
1029 vec2));
|
|
1030 vector_data (XVECTOR (vec)) [i] = make_vector (2, Qnil);
|
|
1031 vector_data (XVECTOR (vector_data (XVECTOR (vec)) [i])) [0] =
|
|
1032 vector_data (XVECTOR (vec2)) [0];
|
|
1033 vector_data (XVECTOR (vector_data (XVECTOR (vec)) [i])) [1] =
|
|
1034 vector_data (XVECTOR (vec2)) [1];
|
|
1035 }
|
|
1036 return vec;
|
|
1037 }
|
|
1038
|
|
1039 #endif
|
|
1040
|
|
1041
|
|
1042 static int reading_selection_reply;
|
|
1043 static Atom reading_which_selection;
|
|
1044 static int selection_reply_timed_out;
|
|
1045
|
|
1046 static int
|
|
1047 selection_reply_done (void *ignore)
|
|
1048 {
|
|
1049 return !reading_selection_reply;
|
|
1050 }
|
|
1051
|
|
1052 static Lisp_Object Qx_selection_reply_timeout_internal;
|
|
1053
|
|
1054 DEFUN ("x-selection-reply-timeout-internal",
|
|
1055 Fx_selection_reply_timeout_internal,
|
|
1056 Sx_selection_reply_timeout_internal, 1, 1, 0 /*
|
|
1057
|
|
1058 */ )
|
|
1059 (arg)
|
|
1060 Lisp_Object arg;
|
|
1061 {
|
|
1062 selection_reply_timed_out = 1;
|
|
1063 reading_selection_reply = 0;
|
|
1064 return Qnil;
|
|
1065 }
|
|
1066
|
|
1067
|
|
1068 /* Do protocol to read selection-data from the server.
|
|
1069 Converts this to lisp data and returns it.
|
|
1070 */
|
|
1071 static Lisp_Object
|
|
1072 x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
|
|
1073 {
|
|
1074 /* This function can GC */
|
|
1075 struct device *d = decode_x_device (Qnil);
|
|
1076 Display *display = DEVICE_X_DISPLAY (d);
|
|
1077 struct frame *sel_frame = selected_frame ();
|
|
1078 Window requestor_window = XtWindow (FRAME_X_TEXT_WIDGET (sel_frame));
|
|
1079 Time requestor_time = DEVICE_X_MOUSE_TIMESTAMP (d);
|
|
1080 Atom target_property = DEVICE_XATOM_EMACS_TMP (d);
|
|
1081 Atom selection_atom = symbol_to_x_atom (d, selection_symbol, 0);
|
|
1082 Atom type_atom;
|
|
1083 int speccount;
|
|
1084
|
|
1085 if (CONSP (target_type))
|
|
1086 type_atom = symbol_to_x_atom (d, XCAR (target_type), 0);
|
|
1087 else
|
|
1088 type_atom = symbol_to_x_atom (d, target_type, 0);
|
|
1089
|
|
1090 XConvertSelection (display, selection_atom, type_atom, target_property,
|
|
1091 requestor_window, requestor_time);
|
|
1092
|
|
1093 /* Block until the reply has been read. */
|
|
1094 reading_selection_reply = (int) requestor_window;
|
|
1095 reading_which_selection = selection_atom;
|
|
1096 selection_reply_timed_out = 0;
|
|
1097
|
|
1098 speccount = specpdl_depth ();
|
|
1099
|
|
1100 /* add a timeout handler */
|
|
1101 if (x_selection_timeout > 0)
|
|
1102 {
|
|
1103 Lisp_Object id = Fadd_timeout (make_int (x_selection_timeout),
|
|
1104 Qx_selection_reply_timeout_internal,
|
|
1105 Qnil, Qnil);
|
|
1106 record_unwind_protect (Fdisable_timeout, id);
|
|
1107 }
|
|
1108
|
|
1109 /* This is ^Gable */
|
|
1110 wait_delaying_user_input (selection_reply_done, 0);
|
|
1111
|
|
1112 if (selection_reply_timed_out)
|
|
1113 error ("timed out waiting for reply from selection owner");
|
|
1114
|
|
1115 unbind_to (speccount, Qnil);
|
|
1116
|
|
1117 /* otherwise, the selection is waiting for us on the requested property. */
|
|
1118 return
|
|
1119 x_get_window_property_as_lisp_data (display, requestor_window,
|
|
1120 target_property, target_type,
|
|
1121 selection_atom);
|
|
1122 }
|
|
1123
|
|
1124
|
|
1125 static void
|
|
1126 x_get_window_property (Display *display, Window window, Atom property,
|
|
1127 unsigned char **data_ret, int *bytes_ret,
|
|
1128 Atom *actual_type_ret, int *actual_format_ret,
|
|
1129 unsigned long *actual_size_ret, int delete_p)
|
|
1130 {
|
|
1131 int total_size;
|
|
1132 unsigned long bytes_remaining;
|
|
1133 int offset = 0;
|
|
1134 unsigned char *tmp_data = 0;
|
|
1135 int result;
|
|
1136 int buffer_size = SELECTION_QUANTUM (display);
|
|
1137 if (buffer_size > MAX_SELECTION_QUANTUM) buffer_size = MAX_SELECTION_QUANTUM;
|
|
1138
|
|
1139 /* First probe the thing to find out how big it is. */
|
|
1140 result = XGetWindowProperty (display, window, property,
|
|
1141 0, 0, False, AnyPropertyType,
|
|
1142 actual_type_ret, actual_format_ret,
|
|
1143 actual_size_ret,
|
|
1144 &bytes_remaining, &tmp_data);
|
|
1145 if (result != Success)
|
|
1146 {
|
|
1147 *data_ret = 0;
|
|
1148 *bytes_ret = 0;
|
|
1149 return;
|
|
1150 }
|
|
1151 XFree ((char *) tmp_data);
|
|
1152
|
|
1153 if (*actual_type_ret == None || *actual_format_ret == 0)
|
|
1154 {
|
|
1155 if (delete_p) XDeleteProperty (display, window, property);
|
|
1156 *data_ret = 0;
|
|
1157 *bytes_ret = 0;
|
|
1158 return;
|
|
1159 }
|
|
1160
|
|
1161 total_size = bytes_remaining + 1;
|
|
1162 *data_ret = (unsigned char *) xmalloc (total_size);
|
|
1163
|
|
1164 /* Now read, until weve gotten it all. */
|
|
1165 while (bytes_remaining)
|
|
1166 {
|
|
1167 #if 0
|
|
1168 int last = bytes_remaining;
|
|
1169 #endif
|
|
1170 result =
|
|
1171 XGetWindowProperty (display, window, property,
|
|
1172 offset/4, buffer_size/4,
|
|
1173 (delete_p ? True : False),
|
|
1174 AnyPropertyType,
|
|
1175 actual_type_ret, actual_format_ret,
|
|
1176 actual_size_ret, &bytes_remaining, &tmp_data);
|
|
1177 #if 0
|
|
1178 stderr_out ("<< read %d\n", last-bytes_remaining);
|
|
1179 #endif
|
|
1180 /* If this doesn't return Success at this point, it means that
|
|
1181 some clod deleted the selection while we were in the midst of
|
|
1182 reading it. Deal with that, I guess....
|
|
1183 */
|
|
1184 if (result != Success) break;
|
|
1185 *actual_size_ret *= *actual_format_ret / 8;
|
|
1186 memcpy ((*data_ret) + offset, tmp_data, *actual_size_ret);
|
|
1187 offset += *actual_size_ret;
|
|
1188 XFree ((char *) tmp_data);
|
|
1189 }
|
|
1190 *bytes_ret = offset;
|
|
1191 }
|
|
1192
|
|
1193
|
|
1194 static void
|
|
1195 receive_incremental_selection (Display *display, Window window, Atom property,
|
|
1196 /* this one is for error messages only */
|
|
1197 Lisp_Object target_type,
|
|
1198 unsigned int min_size_bytes,
|
|
1199 unsigned char **data_ret, int *size_bytes_ret,
|
|
1200 Atom *type_ret, int *format_ret,
|
|
1201 unsigned long *size_ret)
|
|
1202 {
|
|
1203 /* This function can GC */
|
|
1204 int offset = 0;
|
|
1205 int prop_id;
|
|
1206 *size_bytes_ret = min_size_bytes;
|
|
1207 *data_ret = (unsigned char *) xmalloc (*size_bytes_ret);
|
|
1208 #if 0
|
|
1209 stderr_out ("\nread INCR %d\n", min_size_bytes);
|
|
1210 #endif
|
|
1211 /* At this point, we have read an INCR property, and deleted it (which
|
|
1212 is how we ack its receipt: the sending window will be selecting
|
|
1213 PropertyNotify events on our window to notice this).
|
|
1214
|
|
1215 Now, we must loop, waiting for the sending window to put a value on
|
|
1216 that property, then reading the property, then deleting it to ack.
|
|
1217 We are done when the sender places a property of length 0.
|
|
1218 */
|
|
1219 prop_id = expect_property_change (display, window, property,
|
|
1220 PropertyNewValue);
|
|
1221 while (1)
|
|
1222 {
|
|
1223 unsigned char *tmp_data;
|
|
1224 int tmp_size_bytes;
|
|
1225 wait_for_property_change (prop_id);
|
|
1226 /* expect it again immediately, because x_get_window_property may
|
|
1227 .. no it wont, I dont get it.
|
|
1228 .. Ok, I get it now, the Xt code that implements INCR is broken.
|
|
1229 */
|
|
1230 prop_id = expect_property_change (display, window, property,
|
|
1231 PropertyNewValue);
|
|
1232 x_get_window_property (display, window, property,
|
|
1233 &tmp_data, &tmp_size_bytes,
|
|
1234 type_ret, format_ret, size_ret, 1);
|
|
1235
|
|
1236 if (tmp_size_bytes == 0) /* we're done */
|
|
1237 {
|
|
1238 #if 0
|
|
1239 stderr_out (" read INCR done\n");
|
|
1240 #endif
|
|
1241 unexpect_property_change (prop_id);
|
|
1242 if (tmp_data) xfree (tmp_data);
|
|
1243 break;
|
|
1244 }
|
|
1245 #if 0
|
|
1246 stderr_out (" read INCR %d\n", tmp_size_bytes);
|
|
1247 #endif
|
|
1248 if (*size_bytes_ret < offset + tmp_size_bytes)
|
|
1249 {
|
|
1250 #if 0
|
|
1251 stderr_out (" read INCR realloc %d -> %d\n",
|
|
1252 *size_bytes_ret, offset + tmp_size_bytes);
|
|
1253 #endif
|
|
1254 *size_bytes_ret = offset + tmp_size_bytes;
|
|
1255 *data_ret = (unsigned char *) xrealloc (*data_ret, *size_bytes_ret);
|
|
1256 }
|
|
1257 memcpy ((*data_ret) + offset, tmp_data, tmp_size_bytes);
|
|
1258 offset += tmp_size_bytes;
|
|
1259 xfree (tmp_data);
|
|
1260 }
|
|
1261 }
|
|
1262
|
|
1263
|
|
1264 static Lisp_Object
|
|
1265 x_get_window_property_as_lisp_data (Display *display,
|
|
1266 Window window,
|
|
1267 Atom property,
|
|
1268 /* next two for error messages only */
|
|
1269 Lisp_Object target_type,
|
|
1270 Atom selection_atom)
|
|
1271 {
|
|
1272 /* This function can GC */
|
|
1273 Atom actual_type;
|
|
1274 int actual_format;
|
|
1275 unsigned long actual_size;
|
|
1276 unsigned char *data = 0;
|
|
1277 int bytes = 0;
|
|
1278 Lisp_Object val;
|
|
1279 struct device *d = get_device_from_display (display);
|
|
1280
|
|
1281 x_get_window_property (display, window, property, &data, &bytes,
|
|
1282 &actual_type, &actual_format, &actual_size, 1);
|
|
1283 if (! data)
|
|
1284 {
|
|
1285 int there_is_a_selection_owner;
|
|
1286 there_is_a_selection_owner =
|
|
1287 XGetSelectionOwner (display, selection_atom);
|
|
1288 signal_error (Qerror,
|
|
1289 (there_is_a_selection_owner
|
|
1290 ? Fcons (build_string ("selection owner couldn't convert"),
|
|
1291 (actual_type
|
|
1292 ? list2 (target_type,
|
|
1293 x_atom_to_symbol (d, actual_type))
|
|
1294 : list1 (target_type)))
|
|
1295 : list2 (build_string ("no selection"),
|
|
1296 x_atom_to_symbol (d, selection_atom))));
|
|
1297 }
|
|
1298
|
|
1299 if (actual_type == DEVICE_XATOM_INCR (d))
|
|
1300 {
|
|
1301 /* Ok, that data wasnt *the* data, it was just the beginning. */
|
|
1302
|
|
1303 unsigned int min_size_bytes = * ((unsigned int *) data);
|
|
1304 XFree ((char *) data);
|
|
1305 receive_incremental_selection (display, window, property, target_type,
|
|
1306 min_size_bytes, &data, &bytes,
|
|
1307 &actual_type, &actual_format,
|
|
1308 &actual_size);
|
|
1309 }
|
|
1310
|
|
1311 /* It's been read. Now convert it to a lisp object in some semi-rational
|
|
1312 manner.
|
|
1313 */
|
|
1314 val = selection_data_to_lisp_data (d, data, bytes,
|
|
1315 actual_type, actual_format);
|
|
1316
|
|
1317 xfree (data);
|
|
1318 return val;
|
|
1319 }
|
|
1320
|
|
1321 /* These functions convert from the selection data read from the server into
|
|
1322 something that we can use from elisp, and vice versa.
|
|
1323
|
|
1324 Type: Format: Size: Elisp Type:
|
|
1325 ----- ------- ----- -----------
|
|
1326 * 8 * String
|
|
1327 ATOM 32 1 Symbol
|
|
1328 ATOM 32 > 1 Vector of Symbols
|
|
1329 * 16 1 Integer
|
|
1330 * 16 > 1 Vector of Integers
|
|
1331 * 32 1 if <=16 bits: Integer
|
|
1332 if > 16 bits: Cons of top16, bot16
|
|
1333 * 32 > 1 Vector of the above
|
|
1334
|
|
1335 When converting a Lisp number to C, it is assumed to be of format 16 if
|
|
1336 it is an integer, and of format 32 if it is a cons of two integers.
|
|
1337
|
|
1338 When converting a vector of numbers from Elisp to C, it is assumed to be
|
|
1339 of format 16 if every element in the vector is an integer, and is assumed
|
|
1340 to be of format 32 if any element is a cons of two integers.
|
|
1341
|
|
1342 When converting an object to C, it may be of the form (SYMBOL . <data>)
|
|
1343 where SYMBOL is what we should claim that the type is. Format and
|
|
1344 representation are as above.
|
|
1345 */
|
|
1346
|
|
1347
|
|
1348 static Lisp_Object
|
|
1349 selection_data_to_lisp_data (struct device *d,
|
|
1350 unsigned char *data,
|
|
1351 int size,
|
|
1352 Atom type,
|
|
1353 int format)
|
|
1354 {
|
|
1355 if (type == DEVICE_XATOM_NULL (d))
|
|
1356 return QNULL;
|
|
1357
|
|
1358 /* Convert any 8-bit data to a string, for compactness. */
|
|
1359 else if (format == 8)
|
|
1360 return make_ext_string (data, size,
|
|
1361 type == DEVICE_XATOM_TEXT (d)
|
|
1362 || type == DEVICE_XATOM_COMPOUND_TEXT (d)
|
|
1363 ? FORMAT_CTEXT : FORMAT_BINARY);
|
|
1364
|
|
1365 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to
|
|
1366 a vector of symbols.
|
|
1367 */
|
|
1368 else if (type == XA_ATOM)
|
|
1369 {
|
|
1370 int i;
|
|
1371 if (size == sizeof (Atom))
|
|
1372 return x_atom_to_symbol (d, *((Atom *) data));
|
|
1373 else
|
|
1374 {
|
|
1375 Lisp_Object v = Fmake_vector (make_int (size / sizeof (Atom)),
|
|
1376 Qzero);
|
|
1377 for (i = 0; i < size / sizeof (Atom); i++)
|
|
1378 Faset (v, make_int (i),
|
|
1379 x_atom_to_symbol (d, ((Atom *) data) [i]));
|
|
1380 return v;
|
|
1381 }
|
|
1382 }
|
|
1383
|
|
1384 /* Convert a single 16 or small 32 bit number to a Lisp_Int.
|
|
1385 If the number is > 16 bits, convert it to a cons of integers,
|
|
1386 16 bits in each half.
|
|
1387 */
|
|
1388 else if (format == 32 && size == sizeof (long))
|
|
1389 return word_to_lisp (((unsigned long *) data) [0]);
|
|
1390 else if (format == 16 && size == sizeof (short))
|
|
1391 return make_int ((int) (((unsigned short *) data) [0]));
|
|
1392
|
|
1393 /* Convert any other kind of data to a vector of numbers, represented
|
|
1394 as above (as an integer, or a cons of two 16 bit integers).
|
|
1395
|
|
1396 #### Perhaps we should return the actual type to lisp as well.
|
|
1397
|
|
1398 (x-get-selection-internal 'PRIMARY 'LINE_NUMBER)
|
|
1399 ==> [4 4]
|
|
1400
|
|
1401 and perhaps it should be
|
|
1402
|
|
1403 (x-get-selection-internal 'PRIMARY 'LINE_NUMBER)
|
|
1404 ==> (SPAN . [4 4])
|
|
1405
|
|
1406 Right now the fact that the return type was SPAN is discarded before
|
|
1407 lisp code gets to see it.
|
|
1408 */
|
|
1409 else if (format == 16)
|
|
1410 {
|
|
1411 int i;
|
|
1412 Lisp_Object v = make_vector (size / 4, Qzero);
|
|
1413 for (i = 0; i < size / 4; i++)
|
|
1414 {
|
|
1415 int j = (int) ((unsigned short *) data) [i];
|
|
1416 Faset (v, make_int (i), make_int (j));
|
|
1417 }
|
|
1418 return v;
|
|
1419 }
|
|
1420 else
|
|
1421 {
|
|
1422 int i;
|
|
1423 Lisp_Object v = make_vector (size / 4, Qzero);
|
|
1424 for (i = 0; i < size / 4; i++)
|
|
1425 {
|
|
1426 unsigned long j = ((unsigned long *) data) [i];
|
|
1427 Faset (v, make_int (i), word_to_lisp (j));
|
|
1428 }
|
|
1429 return v;
|
|
1430 }
|
|
1431 }
|
|
1432
|
|
1433
|
|
1434 static void
|
|
1435 lisp_data_to_selection_data (struct device *d,
|
|
1436 Lisp_Object obj,
|
|
1437 unsigned char **data_ret,
|
|
1438 Atom *type_ret,
|
|
1439 unsigned int *size_ret,
|
|
1440 int *format_ret)
|
|
1441 {
|
|
1442 Lisp_Object type = Qnil;
|
|
1443
|
|
1444 if (CONSP (obj) && SYMBOLP (XCAR (obj)))
|
|
1445 {
|
|
1446 type = XCAR (obj);
|
|
1447 obj = XCDR (obj);
|
|
1448 if (CONSP (obj) && NILP (XCDR (obj)))
|
|
1449 obj = XCAR (obj);
|
|
1450 }
|
|
1451
|
|
1452 if (EQ (obj, QNULL) || (EQ (type, QNULL)))
|
|
1453 { /* This is not the same as declining */
|
|
1454 *format_ret = 32;
|
|
1455 *size_ret = 0;
|
|
1456 *data_ret = 0;
|
|
1457 type = QNULL;
|
|
1458 }
|
|
1459 else if (STRINGP (obj))
|
|
1460 {
|
|
1461 Extbyte *extval;
|
|
1462 Extcount extvallen;
|
|
1463
|
|
1464 if (NILP (type))
|
|
1465 GET_STRING_CTEXT_DATA_ALLOCA (obj, extval, extvallen);
|
|
1466 else
|
|
1467 GET_STRING_BINARY_DATA_ALLOCA (obj, extval, extvallen);
|
|
1468 *format_ret = 8;
|
|
1469 *size_ret = extvallen;
|
|
1470 *data_ret = (unsigned char *) xmalloc (*size_ret);
|
|
1471 memcpy (*data_ret, extval, *size_ret);
|
|
1472 if (NILP (type)) type = QSTRING;
|
|
1473 }
|
|
1474 else if (SYMBOLP (obj))
|
|
1475 {
|
|
1476 *format_ret = 32;
|
|
1477 *size_ret = 1;
|
|
1478 *data_ret = (unsigned char *) xmalloc (sizeof (Atom) + 1);
|
|
1479 (*data_ret) [sizeof (Atom)] = 0;
|
|
1480 (*(Atom **) data_ret) [0] = symbol_to_x_atom (d, obj, 0);
|
|
1481 if (NILP (type)) type = QATOM;
|
|
1482 }
|
|
1483 else if (INTP (obj) &&
|
|
1484 XINT (obj) <= 0x7FFF &&
|
|
1485 XINT (obj) >= -0x8000)
|
|
1486 {
|
|
1487 *format_ret = 16;
|
|
1488 *size_ret = 1;
|
|
1489 *data_ret = (unsigned char *) xmalloc (sizeof (short) + 1);
|
|
1490 (*data_ret) [sizeof (short)] = 0;
|
|
1491 (*(short **) data_ret) [0] = (short) XINT (obj);
|
|
1492 if (NILP (type)) type = QINTEGER;
|
|
1493 }
|
|
1494 else if (INTP (obj) || CONSP (obj))
|
|
1495 {
|
|
1496 *format_ret = 32;
|
|
1497 *size_ret = 1;
|
|
1498 *data_ret = (unsigned char *) xmalloc (sizeof (long) + 1);
|
|
1499 (*data_ret) [sizeof (long)] = 0;
|
|
1500 (*(unsigned long **) data_ret) [0] = lisp_to_word (obj);
|
|
1501 if (NILP (type)) type = QINTEGER;
|
|
1502 }
|
|
1503 else if (VECTORP (obj))
|
|
1504 {
|
|
1505 /* Lisp_Vectors may represent a set of ATOMs;
|
|
1506 a set of 16 or 32 bit INTEGERs;
|
|
1507 or a set of ATOM_PAIRs (represented as [[A1 A2] [A3 A4] ...]
|
|
1508 */
|
|
1509 int i;
|
|
1510
|
|
1511 if (SYMBOLP (vector_data (XVECTOR (obj)) [0]))
|
|
1512 /* This vector is an ATOM set */
|
|
1513 {
|
|
1514 if (NILP (type)) type = QATOM;
|
|
1515 *size_ret = XVECTOR (obj)->size;
|
|
1516 *format_ret = 32;
|
|
1517 *data_ret = (unsigned char *) xmalloc ((*size_ret) * sizeof (Atom));
|
|
1518 for (i = 0; i < *size_ret; i++)
|
|
1519 if (SYMBOLP (vector_data (XVECTOR (obj)) [i]))
|
|
1520 (*(Atom **) data_ret) [i] =
|
|
1521 symbol_to_x_atom (d, vector_data (XVECTOR (obj)) [i], 0);
|
|
1522 else
|
|
1523 signal_error (Qerror, /* Qselection_error */
|
|
1524 list2 (build_string
|
|
1525 ("all elements of the vector must be of the same type"),
|
|
1526 obj));
|
|
1527 }
|
|
1528 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
1529 else if (VECTORP (vector_data (XVECTOR (obj)) [0]))
|
|
1530 /* This vector is an ATOM_PAIR set */
|
|
1531 {
|
|
1532 if (NILP (type)) type = QATOM_PAIR;
|
|
1533 *size_ret = XVECTOR (obj)->size;
|
|
1534 *format_ret = 32;
|
|
1535 *data_ret = (unsigned char *)
|
|
1536 xmalloc ((*size_ret) * sizeof (Atom) * 2);
|
|
1537 for (i = 0; i < *size_ret; i++)
|
|
1538 if (VECTORP (vector_data (XVECTOR (obj)) [i]))
|
|
1539 {
|
|
1540 Lisp_Object pair = vector_data (XVECTOR (obj)) [i];
|
|
1541 if (XVECTOR (pair)->size != 2)
|
|
1542 signal_error (Qerror,
|
|
1543 list2 (build_string
|
|
1544 ("elements of the vector must be vectors of exactly two elements"),
|
|
1545 pair));
|
|
1546
|
|
1547 (*(Atom **) data_ret) [i * 2] =
|
|
1548 symbol_to_x_atom (d, vector_data (XVECTOR (pair)) [0], 0);
|
|
1549 (*(Atom **) data_ret) [(i * 2) + 1] =
|
|
1550 symbol_to_x_atom (d, vector_data (XVECTOR (pair)) [1], 0);
|
|
1551 }
|
|
1552 else
|
|
1553 signal_error (Qerror,
|
|
1554 list2 (build_string
|
|
1555 ("all elements of the vector must be of the same type"),
|
|
1556 obj));
|
|
1557 }
|
|
1558 #endif
|
|
1559 else
|
|
1560 /* This vector is an INTEGER set, or something like it */
|
|
1561 {
|
|
1562 *size_ret = XVECTOR (obj)->size;
|
|
1563 if (NILP (type)) type = QINTEGER;
|
|
1564 *format_ret = 16;
|
|
1565 for (i = 0; i < *size_ret; i++)
|
|
1566 if (CONSP (vector_data (XVECTOR (obj)) [i]))
|
|
1567 *format_ret = 32;
|
|
1568 else if (!INTP (vector_data (XVECTOR (obj)) [i]))
|
|
1569 signal_error (Qerror, /* Qselection_error */
|
|
1570 list2 (build_string
|
|
1571 ("all elements of the vector must be integers or conses of integers"),
|
|
1572 obj));
|
|
1573
|
|
1574 *data_ret = (unsigned char *) xmalloc (*size_ret * (*format_ret/8));
|
|
1575 for (i = 0; i < *size_ret; i++)
|
|
1576 if (*format_ret == 32)
|
|
1577 (*((unsigned long **) data_ret)) [i] =
|
|
1578 lisp_to_word (vector_data (XVECTOR (obj)) [i]);
|
|
1579 else
|
|
1580 (*((unsigned short **) data_ret)) [i] =
|
|
1581 (unsigned short) lisp_to_word (vector_data (XVECTOR (obj)) [i]);
|
|
1582 }
|
|
1583 }
|
|
1584 else
|
|
1585 signal_error (Qerror, /* Qselection_error */
|
|
1586 list2 (build_string ("unrecognized selection data"),
|
|
1587 obj));
|
|
1588
|
|
1589 *type_ret = symbol_to_x_atom (d, type, 0);
|
|
1590 }
|
|
1591
|
|
1592 static Lisp_Object
|
|
1593 clean_local_selection_data (Lisp_Object obj)
|
|
1594 {
|
|
1595 if (CONSP (obj) &&
|
|
1596 INTP (XCAR (obj)) &&
|
|
1597 CONSP (XCDR (obj)) &&
|
|
1598 INTP (XCAR (XCDR (obj))) &&
|
|
1599 NILP (XCDR (XCDR (obj))))
|
|
1600 obj = Fcons (XCAR (obj), XCDR (obj));
|
|
1601
|
|
1602 if (CONSP (obj) &&
|
|
1603 INTP (XCAR (obj)) &&
|
|
1604 INTP (XCDR (obj)))
|
|
1605 {
|
|
1606 if (XINT (XCAR (obj)) == 0)
|
|
1607 return XCDR (obj);
|
|
1608 if (XINT (XCAR (obj)) == -1)
|
|
1609 return make_int (- XINT (XCDR (obj)));
|
|
1610 }
|
|
1611 if (VECTORP (obj))
|
|
1612 {
|
|
1613 int i;
|
|
1614 int size = XVECTOR (obj)->size;
|
|
1615 Lisp_Object copy;
|
|
1616 if (size == 1)
|
|
1617 return clean_local_selection_data (vector_data (XVECTOR (obj)) [0]);
|
|
1618 copy = make_vector (size, Qnil);
|
|
1619 for (i = 0; i < size; i++)
|
|
1620 vector_data (XVECTOR (copy)) [i] =
|
|
1621 clean_local_selection_data (vector_data (XVECTOR (obj)) [i]);
|
|
1622 return copy;
|
|
1623 }
|
|
1624 return obj;
|
|
1625 }
|
|
1626
|
|
1627
|
|
1628 /* Called from the event loop to handle SelectionNotify events.
|
|
1629 I don't think this needs to be reentrant.
|
|
1630 */
|
|
1631 void
|
|
1632 x_handle_selection_notify (XSelectionEvent *event)
|
|
1633 {
|
|
1634 if (! reading_selection_reply)
|
|
1635 {
|
|
1636 message ("received an unexpected SelectionNotify event");
|
|
1637 return;
|
|
1638 }
|
|
1639 if (event->requestor != reading_selection_reply)
|
|
1640 {
|
|
1641 message ("received a SelectionNotify event for the wrong window");
|
|
1642 return;
|
|
1643 }
|
|
1644 if (event->selection != reading_which_selection)
|
|
1645 {
|
|
1646 message ("received the wrong selection type in SelectionNotify!");
|
|
1647 return;
|
|
1648 }
|
|
1649
|
|
1650 reading_selection_reply = 0; /* we're done now. */
|
|
1651 }
|
|
1652
|
|
1653
|
|
1654 DEFUN ("x-own-selection-internal",
|
|
1655 Fx_own_selection_internal, Sx_own_selection_internal,
|
|
1656 2, 2, 0 /*
|
|
1657 Assert an X selection of the given TYPE with the given VALUE.
|
|
1658 TYPE is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
|
|
1659 VALUE is typically a string, or a cons of two markers, but may be
|
|
1660 anything that the functions on selection-converter-alist know about.
|
|
1661 */ )
|
|
1662 (selection_name, selection_value)
|
|
1663 Lisp_Object selection_name, selection_value;
|
|
1664 {
|
|
1665 CHECK_SYMBOL (selection_name);
|
|
1666 if (NILP (selection_value)) error ("selection-value may not be nil.");
|
|
1667 x_own_selection (selection_name, selection_value);
|
|
1668 return selection_value;
|
|
1669 }
|
|
1670
|
|
1671
|
|
1672 /* Request the selection value from the owner. If we are the owner,
|
|
1673 simply return our selection value. If we are not the owner, this
|
|
1674 will block until all of the data has arrived.
|
|
1675 */
|
|
1676 DEFUN ("x-get-selection-internal",
|
|
1677 Fx_get_selection_internal, Sx_get_selection_internal, 2, 2, 0 /*
|
|
1678 Return text selected from some X window.
|
|
1679 SELECTION is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
|
|
1680 TYPE is the type of data desired, typically STRING.
|
|
1681 */ )
|
|
1682 (selection_symbol, target_type)
|
|
1683 Lisp_Object selection_symbol, target_type;
|
|
1684 {
|
|
1685 /* This function can GC */
|
|
1686 Lisp_Object val = Qnil;
|
|
1687 struct gcpro gcpro1, gcpro2;
|
|
1688 GCPRO2 (target_type, val); /* we store newly consed data into these */
|
|
1689 CHECK_SYMBOL (selection_symbol);
|
|
1690
|
|
1691 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
1692 if (CONSP (target_type) &&
|
|
1693 XCAR (target_type) == QMULTIPLE)
|
|
1694 {
|
|
1695 CHECK_VECTOR (XCDR (target_type));
|
|
1696 /* So we don't destructively modify this... */
|
|
1697 target_type = copy_multiple_data (target_type);
|
|
1698 }
|
|
1699 else
|
|
1700 #endif
|
|
1701 CHECK_SYMBOL (target_type);
|
|
1702
|
|
1703 val = x_get_local_selection (selection_symbol, target_type);
|
|
1704
|
|
1705 if (NILP (val))
|
|
1706 {
|
|
1707 val = x_get_foreign_selection (selection_symbol,
|
|
1708 target_type);
|
|
1709 goto DONE_LABEL;
|
|
1710 }
|
|
1711
|
|
1712 if (CONSP (val) &&
|
|
1713 SYMBOLP (XCAR (val)))
|
|
1714 {
|
|
1715 val = XCDR (val);
|
|
1716 if (CONSP (val) && NILP (XCDR (val)))
|
|
1717 val = XCAR (val);
|
|
1718 }
|
|
1719 val = clean_local_selection_data (val);
|
|
1720 DONE_LABEL:
|
|
1721 UNGCPRO;
|
|
1722 return val;
|
|
1723 }
|
|
1724
|
|
1725 DEFUN ("x-disown-selection-internal",
|
|
1726 Fx_disown_selection_internal, Sx_disown_selection_internal, 1, 2, 0 /*
|
|
1727 If we own the named selection, then disown it (make there be no selection).
|
|
1728 */ )
|
|
1729 (selection, timeval)
|
|
1730 Lisp_Object selection;
|
|
1731 Lisp_Object timeval;
|
|
1732 {
|
|
1733 struct device *d = decode_x_device (Qnil);
|
|
1734 Display *display = DEVICE_X_DISPLAY (d);
|
|
1735 Time timestamp;
|
|
1736 Atom selection_atom;
|
|
1737 XSelectionClearEvent event;
|
|
1738
|
|
1739 CHECK_SYMBOL (selection);
|
|
1740 if (NILP (timeval))
|
|
1741 timestamp = DEVICE_X_MOUSE_TIMESTAMP (d);
|
|
1742 else
|
|
1743 {
|
|
1744 /* #### This is bogus. See the comment above about problems
|
|
1745 on OSF/1 and DEC Alphas. Yet another reason why it sucks
|
|
1746 to have the implementation (i.e. cons of two 16-bit
|
|
1747 integers) exposed. */
|
|
1748 time_t the_time;
|
|
1749 lisp_to_time (timeval, &the_time);
|
|
1750 timestamp = (Time) the_time;
|
|
1751 }
|
|
1752
|
|
1753 if (NILP (assq_no_quit (selection, Vselection_alist)))
|
|
1754 return Qnil; /* Don't disown the selection when we're not the owner. */
|
|
1755
|
|
1756 selection_atom = symbol_to_x_atom (d, selection, 0);
|
|
1757
|
|
1758 XSetSelectionOwner (display, selection_atom, None, timestamp);
|
|
1759
|
|
1760 /* It doesn't seem to be guaranteed that a SelectionClear event will be
|
|
1761 generated for a window which owns the selection when that window sets
|
|
1762 the selection owner to None. The NCD server does, the MIT Sun4 server
|
|
1763 doesn't. So we synthesize one; this means we might get two, but
|
|
1764 that's ok, because the second one won't have any effect.
|
|
1765 */
|
|
1766 event.display = display;
|
|
1767 event.selection = selection_atom;
|
|
1768 event.time = timestamp;
|
|
1769 x_handle_selection_clear (&event);
|
|
1770
|
|
1771 return Qt;
|
|
1772 }
|
|
1773
|
|
1774
|
|
1775 DEFUN ("x-selection-owner-p",
|
|
1776 Fx_selection_owner_p, Sx_selection_owner_p, 0, 1, 0 /*
|
|
1777 Whether the current emacs process owns the given X Selection.
|
|
1778 The arg should be the name of the selection in question, typically one of
|
|
1779 the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience, the symbol
|
|
1780 nil is the same as PRIMARY, and t is the same as SECONDARY.)
|
|
1781 */ )
|
|
1782 (selection)
|
|
1783 Lisp_Object selection;
|
|
1784 {
|
|
1785 CHECK_SYMBOL (selection);
|
|
1786 if (EQ (selection, Qnil)) selection = QPRIMARY;
|
|
1787 if (EQ (selection, Qt)) selection = QSECONDARY;
|
|
1788
|
|
1789 if (NILP (Fassq (selection, Vselection_alist)))
|
|
1790 return Qnil;
|
|
1791 return Qt;
|
|
1792 }
|
|
1793
|
|
1794 DEFUN ("x-selection-exists-p",
|
|
1795 Fx_selection_exists_p, Sx_selection_exists_p, 0, 1, 0 /*
|
|
1796 Whether there is an owner for the given X Selection.
|
|
1797 The arg should be the name of the selection in question, typically one of
|
|
1798 the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience, the symbol
|
|
1799 nil is the same as PRIMARY, and t is the same as SECONDARY.)
|
|
1800 */ )
|
|
1801 (selection)
|
|
1802 Lisp_Object selection;
|
|
1803 {
|
|
1804 Window owner;
|
|
1805 struct device *d = decode_x_device (Qnil);
|
|
1806 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1807 CHECK_SYMBOL (selection);
|
|
1808 if (!NILP (Fx_selection_owner_p (selection)))
|
|
1809 return Qt;
|
|
1810 owner = XGetSelectionOwner (dpy, symbol_to_x_atom (d, selection, 0));
|
|
1811 return (owner ? Qt : Qnil);
|
|
1812 }
|
|
1813
|
|
1814
|
|
1815 #ifdef CUT_BUFFER_SUPPORT
|
|
1816
|
|
1817 static int cut_buffers_initialized; /* Whether we're sure they all exist */
|
|
1818
|
|
1819 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
|
|
1820 static void
|
|
1821 initialize_cut_buffers (Display *display, Window window)
|
|
1822 {
|
|
1823 unsigned CONST char *data = (unsigned CONST char *) "";
|
|
1824 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
|
|
1825 PropModeAppend, data, 0)
|
|
1826 FROB (XA_CUT_BUFFER0);
|
|
1827 FROB (XA_CUT_BUFFER1);
|
|
1828 FROB (XA_CUT_BUFFER2);
|
|
1829 FROB (XA_CUT_BUFFER3);
|
|
1830 FROB (XA_CUT_BUFFER4);
|
|
1831 FROB (XA_CUT_BUFFER5);
|
|
1832 FROB (XA_CUT_BUFFER6);
|
|
1833 FROB (XA_CUT_BUFFER7);
|
|
1834 #undef FROB
|
|
1835 cut_buffers_initialized = 1;
|
|
1836 }
|
|
1837
|
|
1838
|
|
1839 #define CHECK_CUTBUFFER(symbol) \
|
|
1840 { CHECK_SYMBOL (symbol); \
|
|
1841 if (!EQ((symbol),QCUT_BUFFER0) && !EQ((symbol),QCUT_BUFFER1) && \
|
|
1842 !EQ((symbol),QCUT_BUFFER2) && !EQ((symbol),QCUT_BUFFER3) && \
|
|
1843 !EQ((symbol),QCUT_BUFFER4) && !EQ((symbol),QCUT_BUFFER5) && \
|
|
1844 !EQ((symbol),QCUT_BUFFER6) && !EQ((symbol),QCUT_BUFFER7)) \
|
|
1845 signal_error (Qerror, list2 (build_string ("doesn't name a cutbuffer"), \
|
|
1846 (symbol))); \
|
|
1847 }
|
|
1848
|
|
1849 DEFUN ("x-get-cutbuffer-internal", Fx_get_cutbuffer_internal,
|
|
1850 Sx_get_cutbuffer_internal, 1, 1, 0 /*
|
|
1851 Return the value of the named cutbuffer (typically CUT_BUFFER0).
|
|
1852 */ )
|
|
1853 (buffer)
|
|
1854 Lisp_Object buffer;
|
|
1855 {
|
|
1856 struct device *d = decode_x_device (Qnil);
|
|
1857 Display *display = DEVICE_X_DISPLAY (d);
|
|
1858 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
|
|
1859 Atom buffer_atom;
|
|
1860 unsigned char *data;
|
|
1861 int bytes;
|
|
1862 Atom type;
|
|
1863 int format;
|
|
1864 unsigned long size;
|
|
1865 Lisp_Object ret;
|
|
1866
|
|
1867 CHECK_CUTBUFFER (buffer);
|
|
1868 buffer_atom = symbol_to_x_atom (d, buffer, 0);
|
|
1869
|
|
1870 x_get_window_property (display, window, buffer_atom, &data, &bytes,
|
|
1871 &type, &format, &size, 0);
|
|
1872 if (!data) return Qnil;
|
|
1873
|
|
1874 if (format != 8 || type != XA_STRING)
|
|
1875 signal_simple_error_2 ("cut buffer doesn't contain 8-bit data",
|
|
1876 x_atom_to_symbol (d, type),
|
|
1877 make_int (format));
|
|
1878
|
|
1879 ret = (bytes ? make_ext_string (data, bytes, FORMAT_BINARY) : Qnil);
|
|
1880 xfree (data);
|
|
1881 return ret;
|
|
1882 }
|
|
1883
|
|
1884
|
|
1885 DEFUN ("x-store-cutbuffer-internal", Fx_store_cutbuffer_internal,
|
|
1886 Sx_store_cutbuffer_internal, 2, 2, 0 /*
|
|
1887 Sets the value of the named cutbuffer (typically CUT_BUFFER0).
|
|
1888 */ )
|
|
1889 (buffer, string)
|
|
1890 Lisp_Object buffer, string;
|
|
1891 {
|
|
1892 struct device *d = decode_x_device (Qnil);
|
|
1893 Display *display = DEVICE_X_DISPLAY (d);
|
|
1894 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
|
|
1895 Atom buffer_atom;
|
|
1896 unsigned char *data;
|
|
1897 int bytes;
|
|
1898 int bytes_remaining;
|
|
1899 int max_bytes = SELECTION_QUANTUM (display);
|
|
1900 if (max_bytes > MAX_SELECTION_QUANTUM) max_bytes = MAX_SELECTION_QUANTUM;
|
|
1901
|
|
1902 CHECK_CUTBUFFER (buffer);
|
|
1903 CHECK_STRING (string);
|
|
1904 buffer_atom = symbol_to_x_atom (d, buffer, 0);
|
|
1905 GET_STRING_BINARY_DATA_ALLOCA (string, data, bytes);
|
|
1906 bytes_remaining = bytes;
|
|
1907
|
|
1908 if (! cut_buffers_initialized) initialize_cut_buffers (display, window);
|
|
1909
|
|
1910 while (bytes_remaining)
|
|
1911 {
|
|
1912 int chunk = (bytes_remaining < max_bytes
|
|
1913 ? bytes_remaining : max_bytes);
|
|
1914 XChangeProperty (display, window, buffer_atom, XA_STRING, 8,
|
|
1915 (bytes_remaining == bytes
|
|
1916 ? PropModeReplace
|
|
1917 : PropModeAppend),
|
|
1918 data, chunk);
|
|
1919 data += chunk;
|
|
1920 bytes_remaining -= chunk;
|
|
1921 }
|
|
1922 return string;
|
|
1923 }
|
|
1924
|
|
1925
|
|
1926 DEFUN ("x-rotate-cutbuffers-internal", Fx_rotate_cutbuffers_internal,
|
|
1927 Sx_rotate_cutbuffers_internal, 1, 1, 0 /*
|
|
1928 Rotate the values of the cutbuffers by the given number of steps;
|
|
1929 positive means move values forward, negative means backward.
|
|
1930 */ )
|
|
1931 (n)
|
|
1932 Lisp_Object n;
|
|
1933 {
|
|
1934 struct device *d = decode_x_device (Qnil);
|
|
1935 Display *display = DEVICE_X_DISPLAY (d);
|
|
1936 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
|
|
1937 Atom props [8];
|
|
1938
|
|
1939 CHECK_INT (n);
|
|
1940 if (XINT (n) == 0)
|
|
1941 return n;
|
|
1942 if (! cut_buffers_initialized)
|
|
1943 initialize_cut_buffers (display, window);
|
|
1944 props[0] = XA_CUT_BUFFER0;
|
|
1945 props[1] = XA_CUT_BUFFER1;
|
|
1946 props[2] = XA_CUT_BUFFER2;
|
|
1947 props[3] = XA_CUT_BUFFER3;
|
|
1948 props[4] = XA_CUT_BUFFER4;
|
|
1949 props[5] = XA_CUT_BUFFER5;
|
|
1950 props[6] = XA_CUT_BUFFER6;
|
|
1951 props[7] = XA_CUT_BUFFER7;
|
|
1952 XRotateWindowProperties (display, window, props, 8, XINT (n));
|
|
1953 return n;
|
|
1954 }
|
|
1955
|
|
1956 #endif
|
|
1957
|
|
1958
|
|
1959 /************************************************************************/
|
|
1960 /* initialization */
|
|
1961 /************************************************************************/
|
|
1962
|
|
1963 void
|
|
1964 syms_of_xselect (void)
|
|
1965 {
|
|
1966 defsubr (&Sx_get_selection_internal);
|
|
1967 defsubr (&Sx_own_selection_internal);
|
|
1968 defsubr (&Sx_disown_selection_internal);
|
|
1969 defsubr (&Sx_selection_owner_p);
|
|
1970 defsubr (&Sx_selection_exists_p);
|
|
1971
|
|
1972 #ifdef CUT_BUFFER_SUPPORT
|
|
1973 defsubr (&Sx_get_cutbuffer_internal);
|
|
1974 defsubr (&Sx_store_cutbuffer_internal);
|
|
1975 defsubr (&Sx_rotate_cutbuffers_internal);
|
|
1976 #endif
|
|
1977
|
|
1978 /* Unfortunately, timeout handlers must be lisp functions. */
|
|
1979 defsymbol (&Qx_selection_reply_timeout_internal,
|
|
1980 "x-selection-reply-timeout-internal");
|
|
1981 defsubr (&Sx_selection_reply_timeout_internal);
|
|
1982
|
|
1983 defsymbol (&QPRIMARY, "PRIMARY");
|
|
1984 defsymbol (&QSECONDARY, "SECONDARY");
|
|
1985 defsymbol (&QSTRING, "STRING");
|
|
1986 defsymbol (&QINTEGER, "INTEGER");
|
|
1987 defsymbol (&QCLIPBOARD, "CLIPBOARD");
|
|
1988 defsymbol (&QTIMESTAMP, "TIMESTAMP");
|
|
1989 defsymbol (&QTEXT, "TEXT");
|
|
1990 defsymbol (&QTIMESTAMP, "TIMESTAMP");
|
|
1991 defsymbol (&QDELETE, "DELETE");
|
|
1992 defsymbol (&QMULTIPLE, "MULTIPLE");
|
|
1993 defsymbol (&QINCR, "INCR");
|
|
1994 defsymbol (&QEMACS_TMP, "_EMACS_TMP_");
|
|
1995 defsymbol (&QTARGETS, "TARGETS");
|
|
1996 defsymbol (&QATOM, "ATOM");
|
|
1997 defsymbol (&QATOM_PAIR, "ATOM_PAIR");
|
|
1998 defsymbol (&QCOMPOUND_TEXT, "COMPOUND_TEXT");
|
|
1999 defsymbol (&QNULL, "NULL");
|
|
2000
|
|
2001 #ifdef EPOCH
|
|
2002 defsymbol (&QARC, "ARC");
|
|
2003 defsymbol (&QBITMAP, "BITMAP");
|
|
2004 defsymbol (&QCARDINAL, "CARDINAL");
|
|
2005 defsymbol (&QCURSOR, "CURSOR");
|
|
2006 defsymbol (&QDRAWABLE, "DRAWABLE");
|
|
2007 defsymbol (&QFONT, "FONT");
|
|
2008 defsymbol (&QINTEGER, "INTEGER");
|
|
2009 defsymbol (&QPIXMAP, "PIXMAP");
|
|
2010 defsymbol (&QPOINT, "POINT");
|
|
2011 defsymbol (&QRECTANGLE, "RECTANGLE");
|
|
2012 defsymbol (&QWINDOW, "WINDOW");
|
|
2013 defsymbol (&QWM_HINTS, "WM_HINTS");
|
|
2014 defsymbol (&QWM_SIZE_HINTS, "WM_SIZE_HINTS");
|
|
2015 #endif /* EPOCH */
|
|
2016
|
|
2017 #ifdef CUT_BUFFER_SUPPORT
|
|
2018 defsymbol (&QCUT_BUFFER0, "CUT_BUFFER0");
|
|
2019 defsymbol (&QCUT_BUFFER1, "CUT_BUFFER1");
|
|
2020 defsymbol (&QCUT_BUFFER2, "CUT_BUFFER2");
|
|
2021 defsymbol (&QCUT_BUFFER3, "CUT_BUFFER3");
|
|
2022 defsymbol (&QCUT_BUFFER4, "CUT_BUFFER4");
|
|
2023 defsymbol (&QCUT_BUFFER5, "CUT_BUFFER5");
|
|
2024 defsymbol (&QCUT_BUFFER6, "CUT_BUFFER6");
|
|
2025 defsymbol (&QCUT_BUFFER7, "CUT_BUFFER7");
|
|
2026 #endif
|
|
2027 }
|
|
2028
|
|
2029 void
|
|
2030 vars_of_xselect (void)
|
|
2031 {
|
|
2032 #ifdef CUT_BUFFER_SUPPORT
|
|
2033 cut_buffers_initialized = 0;
|
|
2034 Fprovide (intern ("cut-buffer"));
|
|
2035 #endif
|
|
2036
|
|
2037 reading_selection_reply = 0;
|
|
2038 reading_which_selection = 0;
|
|
2039 selection_reply_timed_out = 0;
|
|
2040 for_whom_the_bell_tolls = 0;
|
|
2041 prop_location_tick = 0;
|
|
2042
|
|
2043 Vselection_alist = Qnil;
|
|
2044 staticpro (&Vselection_alist);
|
|
2045
|
|
2046 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist /*
|
|
2047 An alist associating selection-types (such as STRING and TIMESTAMP) with
|
|
2048 functions. These functions will be called with three args: the name of the
|
|
2049 selection (typically PRIMARY, SECONDARY, or CLIPBOARD); a desired type to
|
|
2050 which the selection should be converted; and the local selection value
|
|
2051 (whatever had been passed to `x-own-selection'). These functions should
|
|
2052 return the value to send to the X server, which should be one of:
|
|
2053
|
|
2054 -- nil (the conversion could not be done)
|
|
2055 -- a cons of a symbol and any of the following values; the symbol
|
|
2056 explicitly specifies the type that will be sent.
|
|
2057 -- a string (Will be left as is and sent in the 'STRING format as 8-bit data.)
|
|
2058 -- a character (Same as for strings.)
|
|
2059 -- the symbol 'NULL (Indicates that there is no meaningful return value.
|
|
2060 Empty 32-bit data with a type of 'NULL will be sent.)
|
|
2061 -- a symbol (Will be converted into an atom. If the type is not specified,
|
|
2062 a type of 'ATOM will be sent.)
|
|
2063 -- an integer (Will be converted into a 16-bit or 32-bit integer depending
|
|
2064 on the value. If the type is not specified, a type of
|
|
2065 'INTEGER will be sent.)
|
|
2066 -- a cons (HIGH . LOW) of integers (Will be converted into a 32-bit integer.
|
|
2067 If the type is not specified, a type of
|
|
2068 'INTEGER will be sent.)
|
|
2069 -- a vector of symbols (Will be converted into a list of atoms. If the type
|
|
2070 is not specified, a type of 'ATOM will be sent.)
|
|
2071 -- a vector of integers (Will be converted into a list of 16-bit integers.
|
|
2072 If the type is not specified, a type of 'INTEGER
|
|
2073 will be sent.)
|
|
2074 -- a vector of integers and/or conses (HIGH . LOW) of integers
|
|
2075 (Will be converted into a list of 16-bit integers.
|
|
2076 If the type is not specified, a type of 'INTEGER
|
|
2077 will be sent.)
|
|
2078 */ );
|
|
2079 Vselection_converter_alist = Qnil;
|
|
2080
|
|
2081 DEFVAR_LISP ("x-lost-selection-hooks", &Vx_lost_selection_hooks /*
|
|
2082 A function or functions to be called after the X server has notified us
|
|
2083 that we have lost the selection. The function(s) will be called with one
|
|
2084 argument, a symbol naming the selection (typically PRIMARY, SECONDARY, or
|
|
2085 CLIPBOARD).
|
|
2086 */ );
|
|
2087 Vx_lost_selection_hooks = Qunbound;
|
|
2088
|
|
2089 DEFVAR_LISP ("x-sent-selection-hooks", &Vx_sent_selection_hooks /*
|
|
2090 A function or functions to be called after we have responded to some
|
|
2091 other client's request for the value of a selection that we own. The
|
|
2092 function(s) will be called with four arguments:
|
|
2093 - the name of the selection (typically PRIMARY, SECONDARY, or CLIPBOARD);
|
|
2094 - the name of the selection-type which we were requested to convert the
|
|
2095 selection into before sending (for example, STRING or LENGTH);
|
|
2096 - and whether we successfully transmitted the selection.
|
|
2097 We might have failed (and declined the request) for any number of reasons,
|
|
2098 including being asked for a selection that we no longer own, or being asked
|
|
2099 to convert into a type that we don't know about or that is inappropriate.
|
|
2100 This hook doesn't let you change the behavior of emacs's selection replies,
|
|
2101 it merely informs you that they have happened.
|
|
2102 */ );
|
|
2103 Vx_sent_selection_hooks = Qunbound;
|
|
2104
|
|
2105 DEFVAR_INT ("x-selection-timeout", &x_selection_timeout /*
|
|
2106 If the selection owner doesn't reply in this many seconds, we give up.
|
|
2107 A value of 0 means wait as long as necessary. This is initialized from the
|
|
2108 \"*selectionTimeout\" resource (which is expressed in milliseconds).
|
|
2109 */ );
|
|
2110 x_selection_timeout = 0;
|
|
2111 }
|
|
2112
|
|
2113 void
|
|
2114 Xatoms_of_xselect (struct device *d)
|
|
2115 {
|
|
2116 #define ATOM(x) XInternAtom (DEVICE_X_DISPLAY (d), (x), False)
|
2
|
2117 #define ATOMIZE(x) DEVICE_XATOM_##x (d) = ATOM(#x)
|
0
|
2118
|
|
2119 /* Non-predefined atoms that we might end up using a lot */
|
2
|
2120 ATOMIZE (CLIPBOARD);
|
|
2121 ATOMIZE (TIMESTAMP);
|
|
2122 ATOMIZE (TEXT);
|
|
2123 ATOMIZE (DELETE);
|
|
2124 ATOMIZE (MULTIPLE);
|
|
2125 ATOMIZE (INCR);
|
|
2126 ATOMIZE (TARGETS);
|
|
2127 ATOMIZE (NULL);
|
|
2128 ATOMIZE (ATOM_PAIR);
|
|
2129 ATOMIZE (COMPOUND_TEXT);
|
|
2130 DEVICE_XATOM_EMACS_TMP (d) = ATOM ("_EMACS_TMP_");
|
0
|
2131 }
|