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;
|
16
|
370 String encoding = (String) "STRING";
|
|
371 Extbyte *data = XSTRING_DATA (selection_value);
|
|
372 Extcount bytes = XSTRING_LENGTH (selection_value);
|
|
373
|
70
|
374 #ifdef MULE
|
|
375 {
|
|
376 enum { ASCII, LATIN_1, WORLD } chartypes = ASCII;
|
|
377 CONST Bufbyte *ptr = data, *end = ptr + bytes;
|
|
378 /* Optimize for the common ASCII case */
|
|
379 while (ptr <= end)
|
|
380 {
|
|
381 if (BYTE_ASCII_P (*ptr))
|
|
382 {
|
|
383 ptr++;
|
|
384 continue;
|
|
385 }
|
|
386
|
74
|
387 if ((*ptr) == LEADING_BYTE_LATIN_ISO8859_1 ||
|
70
|
388 (*ptr) == LEADING_BYTE_CONTROL_1)
|
|
389 {
|
|
390 chartypes = LATIN_1;
|
|
391 ptr += 2;
|
|
392 continue;
|
|
393 }
|
|
394
|
|
395 chartypes = WORLD;
|
|
396 break;
|
|
397 }
|
|
398
|
|
399 switch (chartypes)
|
|
400 {
|
|
401 case LATIN_1:
|
|
402 GET_STRING_BINARY_DATA_ALLOCA (selection_value, data, bytes);
|
|
403 break;
|
|
404 case WORLD:
|
|
405 GET_STRING_CTEXT_DATA_ALLOCA (selection_value, data, bytes);
|
|
406 encoding = (String) "COMPOUND_TEXT";
|
|
407 break;
|
|
408 }
|
|
409 }
|
|
410 #endif /* MULE */
|
16
|
411
|
2
|
412 fmh = XmStringCreateLtoR ((String) "Clipboard",
|
|
413 XmSTRING_DEFAULT_CHARSET);
|
0
|
414 while (ClipboardSuccess !=
|
|
415 XmClipboardStartCopy (display, selecting_window, fmh, thyme,
|
|
416 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
|
|
417 widget, motif_clipboard_cb,
|
|
418 #else
|
|
419 0, NULL,
|
|
420 #endif
|
|
421 &itemid))
|
|
422 ;
|
|
423 XmStringFree (fmh);
|
|
424 while (ClipboardSuccess !=
|
16
|
425 XmClipboardCopy (display, selecting_window, itemid, encoding,
|
0
|
426 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
|
16
|
427 /* O'Reilly examples say size can be 0,
|
0
|
428 but this clearly is not the case. */
|
16
|
429 0, bytes, (int) selecting_window, /* private id */
|
0
|
430 #else /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
|
16
|
431 (XtPointer) data, bytes, 0,
|
0
|
432 #endif /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
|
|
433 &dataid))
|
|
434 ;
|
|
435 while (ClipboardSuccess !=
|
|
436 XmClipboardEndCopy (display, selecting_window, itemid))
|
|
437 ;
|
|
438 }
|
|
439 }
|
|
440
|
|
441 # ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
|
|
442 /* I tried to treat the clipboard like a real selection, and not send
|
|
443 the data until it was requested, but it looks like that just doesn't
|
|
444 work at all unless the selection owner and requestor are in different
|
|
445 processes. From reading the Motif source, it looks like they never
|
|
446 even considered having two widgets in the same application transfer
|
|
447 data between each other using "by-name" clipboard values. What a
|
|
448 bunch of fuckups.
|
|
449 */
|
|
450 static void
|
|
451 motif_clipboard_cb (Widget widget, int *data_id, int *private_id, int *reason)
|
|
452 {
|
|
453 switch (*reason)
|
|
454 {
|
|
455 case XmCR_CLIPBOARD_DATA_REQUEST:
|
|
456 {
|
|
457 Display *dpy = XtDisplay (widget);
|
|
458 Window window = (Window) *private_id;
|
|
459 Lisp_Object selection = assq_no_quit (QCLIPBOARD, Vselection_alist);
|
|
460 if (NILP (selection)) abort ();
|
|
461 selection = XCDR (selection);
|
|
462 if (!STRINGP (selection)) abort ();
|
|
463 XmClipboardCopyByName (dpy, window, *data_id,
|
16
|
464 (char *) XSTRING_DATA (selection),
|
|
465 XSTRING_LENGTH (selection) + 1,
|
0
|
466 0);
|
|
467 }
|
|
468 break;
|
|
469 case XmCR_CLIPBOARD_DATA_DELETE:
|
|
470 default:
|
|
471 /* don't need to free anything */
|
|
472 break;
|
|
473 }
|
|
474 }
|
|
475 # endif /* MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
|
|
476 #endif /* MOTIF_CLIPBOARDS */
|
|
477
|
|
478
|
|
479 /* Given a selection-name and desired type, this looks up our local copy of
|
|
480 the selection value and converts it to the type. It returns nil or a
|
|
481 string. This calls random elisp code, and may signal or gc.
|
|
482 */
|
|
483 static Lisp_Object
|
|
484 x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
|
|
485 {
|
|
486 /* This function can GC */
|
|
487 Lisp_Object local_value = assq_no_quit (selection_symbol, Vselection_alist);
|
|
488 Lisp_Object handler_fn, value, check;
|
|
489
|
|
490 if (NILP (local_value)) return Qnil;
|
|
491
|
|
492 /* TIMESTAMP and MULTIPLE are special cases 'cause that's easiest. */
|
|
493 if (EQ (target_type, QTIMESTAMP))
|
|
494 {
|
|
495 handler_fn = Qnil;
|
|
496 value = XCAR (XCDR (XCDR (local_value)));
|
|
497 }
|
|
498
|
|
499 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
500 else if (CONSP (target_type) &&
|
|
501 XCAR (target_type) == QMULTIPLE)
|
|
502 {
|
|
503 Lisp_Object pairs = XCDR (target_type);
|
|
504 int size = XVECTOR (pairs)->size;
|
|
505 int i;
|
|
506 /* If the target is MULTIPLE, then target_type looks like
|
|
507 (MULTIPLE . [[SELECTION1 TARGET1] [SELECTION2 TARGET2] ... ])
|
|
508 We modify the second element of each pair in the vector and
|
|
509 return it as [[SELECTION1 <value1>] [SELECTION2 <value2>] ... ]
|
|
510 */
|
|
511 for (i = 0; i < size; i++)
|
|
512 {
|
|
513 Lisp_Object pair = vector_data (XVECTOR (pairs)) [i];
|
|
514 vector_data (XVECTOR (pair)) [1] =
|
|
515 x_get_local_selection (vector_data (XVECTOR (pair)) [0],
|
|
516 vector_data (XVECTOR (pair)) [1]);
|
|
517 }
|
|
518 return pairs;
|
|
519 }
|
|
520 #endif
|
|
521 else
|
|
522 {
|
|
523 CHECK_SYMBOL (target_type);
|
|
524 handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist));
|
|
525 if (NILP (handler_fn)) return Qnil;
|
|
526 value = call3 (handler_fn,
|
|
527 selection_symbol, target_type,
|
|
528 XCAR (XCDR (local_value)));
|
|
529 }
|
|
530
|
|
531 /* This lets the selection function to return (TYPE . VALUE). For example,
|
|
532 when the selected type is LINE_NUMBER, the returned type is SPAN, not
|
|
533 INTEGER.
|
|
534 */
|
|
535 check = value;
|
|
536 if (CONSP (value) && SYMBOLP (XCAR (value)))
|
|
537 check = XCDR (value);
|
|
538
|
|
539 /* Strings, vectors, and symbols are converted to selection data format in
|
|
540 the obvious way. Integers are converted to 16 bit quantities if they're
|
|
541 small enough, otherwise 32 bits are used.
|
|
542 */
|
|
543 if (STRINGP (check) ||
|
|
544 VECTORP (check) ||
|
|
545 SYMBOLP (check) ||
|
2
|
546 INTP (check) ||
|
|
547 CHARP (check) ||
|
0
|
548 NILP (value))
|
|
549 return value;
|
|
550
|
|
551 /* (N . M) or (N M) get turned into a 32 bit quantity. So if you want to
|
|
552 always return a small quantity as 32 bits, your converter routine needs
|
|
553 to return a cons.
|
|
554 */
|
|
555 else if (CONSP (check) &&
|
|
556 INTP (XCAR (check)) &&
|
|
557 (INTP (XCDR (check)) ||
|
|
558 (CONSP (XCDR (check)) &&
|
|
559 INTP (XCAR (XCDR (check))) &&
|
|
560 NILP (XCDR (XCDR (check))))))
|
|
561 return value;
|
|
562 /* Otherwise the lisp converter function returned something unrecognized.
|
|
563 */
|
|
564 else
|
|
565 signal_error (Qerror,
|
|
566 list3 (build_string
|
|
567 ("unrecognized selection-conversion type"),
|
|
568 handler_fn,
|
|
569 value));
|
|
570
|
|
571 return Qnil; /* suppress compiler warning */
|
|
572 }
|
|
573
|
|
574
|
|
575
|
|
576 /* Send a SelectionNotify event to the requestor with property=None, meaning
|
|
577 we were unable to do what they wanted.
|
|
578 */
|
|
579 static void
|
|
580 x_decline_selection_request (XSelectionRequestEvent *event)
|
|
581 {
|
|
582 XSelectionEvent reply;
|
|
583 reply.type = SelectionNotify;
|
|
584 reply.display = event->display;
|
|
585 reply.requestor = event->requestor;
|
|
586 reply.selection = event->selection;
|
|
587 reply.time = event->time;
|
|
588 reply.target = event->target;
|
|
589 reply.property = None;
|
|
590
|
|
591 (void) XSendEvent (reply.display, reply.requestor, False, 0L,
|
|
592 (XEvent *) &reply);
|
|
593 XFlush (reply.display);
|
|
594 }
|
|
595
|
|
596
|
|
597 /* Used as an unwind-protect clause so that, if a selection-converter signals
|
|
598 an error, we tell the requestor that we were unable to do what they wanted
|
|
599 before we throw to top-level or go into the debugger or whatever.
|
|
600 */
|
|
601 static Lisp_Object
|
|
602 x_selection_request_lisp_error (Lisp_Object closure)
|
|
603 {
|
|
604 XSelectionRequestEvent *event = (XSelectionRequestEvent *)
|
|
605 get_opaque_ptr (closure);
|
|
606
|
|
607 free_opaque_ptr (closure);
|
|
608 if (event->type == 0) /* we set this to mean "completed normally" */
|
|
609 return Qnil;
|
|
610 x_decline_selection_request (event);
|
|
611 return Qnil;
|
|
612 }
|
|
613
|
|
614
|
|
615 /* Convert our selection to the requested type, and put that data where the
|
|
616 requestor wants it. Then tell them whether we've succeeded.
|
|
617 */
|
|
618 static void
|
|
619 x_reply_selection_request (XSelectionRequestEvent *event, int format,
|
|
620 unsigned char *data, int size, Atom type)
|
|
621 {
|
|
622 /* This function can GC */
|
|
623 XSelectionEvent reply;
|
|
624 Display *display = event->display;
|
|
625 struct device *d = get_device_from_display (display);
|
|
626 Window window = event->requestor;
|
|
627 int bytes_remaining;
|
|
628 int format_bytes = format/8;
|
|
629 int max_bytes = SELECTION_QUANTUM (display);
|
|
630 if (max_bytes > MAX_SELECTION_QUANTUM) max_bytes = MAX_SELECTION_QUANTUM;
|
|
631
|
|
632 reply.type = SelectionNotify;
|
|
633 reply.display = display;
|
|
634 reply.requestor = window;
|
|
635 reply.selection = event->selection;
|
|
636 reply.time = event->time;
|
|
637 reply.target = event->target;
|
|
638 reply.property = (event->property == None ? event->target : event->property);
|
|
639
|
|
640 /* #### XChangeProperty can generate BadAlloc, and we must handle it! */
|
|
641
|
|
642 /* Store the data on the requested property.
|
|
643 If the selection is large, only store the first N bytes of it.
|
|
644 */
|
|
645 bytes_remaining = size * format_bytes;
|
|
646 if (bytes_remaining <= max_bytes)
|
|
647 {
|
|
648 /* Send all the data at once, with minimal handshaking. */
|
|
649 #if 0
|
|
650 stderr_out ("\nStoring all %d\n", bytes_remaining);
|
|
651 #endif
|
|
652 XChangeProperty (display, window, reply.property, type, format,
|
|
653 PropModeReplace, data, size);
|
|
654 /* At this point, the selection was successfully stored; ack it. */
|
|
655 (void) XSendEvent (display, window, False, 0L, (XEvent *) &reply);
|
|
656 XFlush (display);
|
|
657 }
|
|
658 else
|
|
659 {
|
|
660 /* Send an INCR selection. */
|
|
661 int prop_id;
|
|
662
|
|
663 if (x_window_to_frame (d, window)) /* #### debug */
|
|
664 error ("attempt to transfer an INCR to ourself!");
|
|
665 #if 0
|
|
666 stderr_out ("\nINCR %d\n", bytes_remaining);
|
|
667 #endif
|
|
668 prop_id = expect_property_change (display, window, reply.property,
|
|
669 PropertyDelete);
|
|
670
|
|
671 XChangeProperty (display, window, reply.property, DEVICE_XATOM_INCR (d),
|
|
672 32, PropModeReplace, (unsigned char *)
|
|
673 &bytes_remaining, 1);
|
|
674 XSelectInput (display, window, PropertyChangeMask);
|
|
675 /* Tell 'em the INCR data is there... */
|
|
676 (void) XSendEvent (display, window, False, 0L, (XEvent *) &reply);
|
|
677 XFlush (display);
|
|
678
|
|
679 /* First, wait for the requestor to ack by deleting the property.
|
|
680 This can run random lisp code (process handlers) or signal.
|
|
681 */
|
|
682 wait_for_property_change (prop_id);
|
|
683
|
|
684 while (bytes_remaining)
|
|
685 {
|
|
686 int i = ((bytes_remaining < max_bytes)
|
|
687 ? bytes_remaining
|
|
688 : max_bytes);
|
|
689 prop_id = expect_property_change (display, window, reply.property,
|
|
690 PropertyDelete);
|
|
691 #if 0
|
|
692 stderr_out (" INCR adding %d\n", i);
|
|
693 #endif
|
|
694 /* Append the next chunk of data to the property. */
|
|
695 XChangeProperty (display, window, reply.property, type, format,
|
|
696 PropModeAppend, data, i / format_bytes);
|
|
697 bytes_remaining -= i;
|
|
698 data += i;
|
|
699
|
|
700 /* Now wait for the requestor to ack this chunk by deleting the
|
|
701 property. This can run random lisp code or signal.
|
|
702 */
|
|
703 wait_for_property_change (prop_id);
|
|
704 }
|
|
705 /* Now write a zero-length chunk to the property to tell the requestor
|
|
706 that we're done. */
|
|
707 #if 0
|
|
708 stderr_out (" INCR done\n");
|
|
709 #endif
|
|
710 if (! waiting_for_other_props_on_window (display, window))
|
|
711 XSelectInput (display, window, 0L);
|
|
712
|
|
713 XChangeProperty (display, window, reply.property, type, format,
|
|
714 PropModeReplace, data, 0);
|
|
715 }
|
|
716 }
|
|
717
|
|
718
|
|
719
|
|
720 /* Called from the event-loop in response to a SelectionRequest event.
|
|
721 */
|
|
722 void
|
|
723 x_handle_selection_request (XSelectionRequestEvent *event)
|
|
724 {
|
|
725 /* This function can GC */
|
|
726 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
727 XSelectionEvent reply;
|
|
728 Lisp_Object local_selection_data = Qnil;
|
|
729 Lisp_Object selection_symbol;
|
|
730 Lisp_Object target_symbol = Qnil;
|
|
731 Lisp_Object converted_selection = Qnil;
|
|
732 Time local_selection_time;
|
|
733 Lisp_Object successful_p = Qnil;
|
|
734 int count;
|
|
735 struct device *d = get_device_from_display (event->display);
|
|
736
|
|
737 GCPRO3 (local_selection_data, converted_selection, target_symbol);
|
|
738
|
|
739 reply.type = SelectionNotify; /* Construct the reply event */
|
|
740 reply.display = event->display;
|
|
741 reply.requestor = event->requestor;
|
|
742 reply.selection = event->selection;
|
|
743 reply.time = event->time;
|
|
744 reply.target = event->target;
|
|
745 reply.property = (event->property == None ? event->target : event->property);
|
|
746
|
|
747 selection_symbol = x_atom_to_symbol (d, event->selection);
|
|
748
|
|
749 local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
|
|
750
|
|
751 #if 0
|
|
752 # define CDR(x) (XCDR (x))
|
|
753 # define CAR(x) (XCAR (x))
|
|
754 /* This list isn't user-visible, so it can't "go bad." */
|
|
755 if (!CONSP (local_selection_data)) abort ();
|
|
756 if (!CONSP (CDR (local_selection_data))) abort ();
|
|
757 if (!CONSP (CDR (CDR (local_selection_data)))) abort ();
|
|
758 if (!NILP (CDR (CDR (CDR (local_selection_data))))) abort ();
|
|
759 if (!CONSP (CAR (CDR (CDR (local_selection_data))))) abort ();
|
|
760 if (!INTP (CAR (CAR (CDR (CDR (local_selection_data)))))) abort ();
|
|
761 if (!INTP (CDR (CAR (CDR (CDR (local_selection_data)))))) abort ();
|
|
762 # undef CAR
|
|
763 # undef CDR
|
|
764 #endif
|
|
765
|
|
766 if (NILP (local_selection_data))
|
|
767 {
|
|
768 /* Someone asked for the selection, but we don't have it any more.
|
|
769 */
|
|
770 x_decline_selection_request (event);
|
|
771 goto DONE_LABEL;
|
|
772 }
|
|
773
|
|
774 local_selection_time =
|
|
775 * (Time *) XOPAQUE_DATA (XCAR (XCDR (XCDR (local_selection_data))));
|
|
776
|
|
777 if (event->time != CurrentTime &&
|
|
778 local_selection_time > event->time)
|
|
779 {
|
|
780 /* Someone asked for the selection, and we have one, but not the one
|
|
781 they're looking for.
|
|
782 */
|
|
783 x_decline_selection_request (event);
|
|
784 goto DONE_LABEL;
|
|
785 }
|
|
786
|
|
787 count = specpdl_depth ();
|
|
788 record_unwind_protect (x_selection_request_lisp_error,
|
|
789 make_opaque_ptr (event));
|
|
790 target_symbol = x_atom_to_symbol (d, event->target);
|
|
791
|
|
792 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
793 if (EQ (target_symbol, QMULTIPLE))
|
|
794 target_symbol = fetch_multiple_target (event);
|
|
795 #endif
|
|
796
|
|
797 /* Convert lisp objects back into binary data */
|
|
798
|
|
799 converted_selection =
|
|
800 x_get_local_selection (selection_symbol, target_symbol);
|
|
801
|
|
802 if (! NILP (converted_selection))
|
|
803 {
|
|
804 unsigned char *data;
|
|
805 unsigned int size;
|
|
806 int format;
|
|
807 Atom type;
|
|
808 lisp_data_to_selection_data (d, converted_selection,
|
|
809 &data, &type, &size, &format);
|
|
810
|
|
811 x_reply_selection_request (event, format, data, size, type);
|
|
812 successful_p = Qt;
|
|
813 /* Tell x_selection_request_lisp_error() it's cool. */
|
|
814 event->type = 0;
|
|
815 xfree (data);
|
|
816 }
|
|
817 unbind_to (count, Qnil);
|
|
818
|
|
819 DONE_LABEL:
|
|
820
|
|
821 UNGCPRO;
|
|
822
|
|
823 /* Let random lisp code notice that the selection has been asked for.
|
|
824 */
|
|
825 {
|
|
826 Lisp_Object rest;
|
|
827 Lisp_Object val = Vx_sent_selection_hooks;
|
|
828 if (!UNBOUNDP (val) && !NILP (val))
|
|
829 {
|
|
830 if (CONSP (val) && !EQ (XCAR (val), Qlambda))
|
|
831 for (rest = val; !NILP (rest); rest = Fcdr (rest))
|
|
832 call3 (Fcar(rest), selection_symbol, target_symbol,
|
|
833 successful_p);
|
|
834 else
|
|
835 call3 (val, selection_symbol, target_symbol,
|
|
836 successful_p);
|
|
837 }
|
|
838 }
|
|
839 }
|
|
840
|
|
841
|
|
842 /* Called from the event-loop in response to a SelectionClear event.
|
|
843 */
|
|
844 void
|
|
845 x_handle_selection_clear (XSelectionClearEvent *event)
|
|
846 {
|
|
847 Display *display = event->display;
|
|
848 struct device *d = get_device_from_display (display);
|
|
849 Atom selection = event->selection;
|
|
850 Time changed_owner_time = event->time;
|
|
851
|
|
852 Lisp_Object selection_symbol, local_selection_data;
|
|
853 Time local_selection_time;
|
|
854
|
|
855 selection_symbol = x_atom_to_symbol (d, selection);
|
|
856
|
|
857 local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
|
|
858
|
|
859 /* Well, we already believe that we don't own it, so that's just fine. */
|
|
860 if (NILP (local_selection_data)) return;
|
|
861
|
|
862 local_selection_time =
|
|
863 * (Time *) XOPAQUE_DATA (XCAR (XCDR (XCDR (local_selection_data))));
|
|
864
|
|
865 /* This SelectionClear is for a selection that we no longer own, so we can
|
|
866 disregard it. (That is, we have reasserted the selection since this
|
|
867 request was generated.)
|
|
868 */
|
|
869 if (changed_owner_time != CurrentTime &&
|
|
870 local_selection_time > changed_owner_time)
|
|
871 return;
|
|
872
|
|
873 /* Otherwise, we're really honest and truly being told to drop it.
|
|
874 Don't use Fdelq() as that may QUIT;.
|
|
875 */
|
|
876 if (EQ (local_selection_data, Fcar (Vselection_alist)))
|
|
877 Vselection_alist = Fcdr (Vselection_alist);
|
|
878 else
|
|
879 {
|
|
880 Lisp_Object rest;
|
|
881 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
|
|
882 if (EQ (local_selection_data, Fcar (XCDR (rest))))
|
|
883 {
|
|
884 XCDR (rest) = Fcdr (XCDR (rest));
|
|
885 break;
|
|
886 }
|
|
887 }
|
|
888
|
|
889 /* Let random lisp code notice that the selection has been stolen.
|
|
890 */
|
|
891 {
|
|
892 Lisp_Object rest;
|
|
893 Lisp_Object val = Vx_lost_selection_hooks;
|
|
894 if (!UNBOUNDP (val) && !NILP (val))
|
|
895 {
|
|
896 if (CONSP (val) && !EQ (XCAR (val), Qlambda))
|
|
897 for (rest = val; !NILP (rest); rest = Fcdr (rest))
|
|
898 call1 (Fcar (rest), selection_symbol);
|
|
899 else
|
|
900 call1 (val, selection_symbol);
|
|
901 }
|
|
902 }
|
|
903 }
|
|
904
|
|
905
|
|
906 /* This stuff is so that INCR selections are reentrant (that is, so we can
|
|
907 be servicing multiple INCR selection requests simultaneously). I haven't
|
|
908 actually tested that yet.
|
|
909 */
|
|
910
|
|
911 static int prop_location_tick;
|
|
912
|
|
913 static struct prop_location {
|
|
914 int tick;
|
|
915 Display *display;
|
|
916 Window window;
|
|
917 Atom property;
|
|
918 int desired_state;
|
|
919 struct prop_location *next;
|
|
920 } *for_whom_the_bell_tolls;
|
|
921
|
|
922
|
|
923 static int
|
|
924 property_deleted_p (void *tick)
|
|
925 {
|
|
926 struct prop_location *rest = for_whom_the_bell_tolls;
|
|
927 while (rest)
|
|
928 if (rest->tick == (long) tick)
|
|
929 return 0;
|
|
930 else
|
|
931 rest = rest->next;
|
|
932 return 1;
|
|
933 }
|
|
934
|
|
935 static int
|
|
936 waiting_for_other_props_on_window (Display *display, Window window)
|
|
937 {
|
|
938 struct prop_location *rest = for_whom_the_bell_tolls;
|
|
939 while (rest)
|
|
940 if (rest->display == display && rest->window == window)
|
|
941 return 1;
|
|
942 else
|
|
943 rest = rest->next;
|
|
944 return 0;
|
|
945 }
|
|
946
|
|
947
|
|
948 static int
|
|
949 expect_property_change (Display *display, Window window,
|
|
950 Atom property, int state)
|
|
951 {
|
|
952 struct prop_location *pl = (struct prop_location *)
|
|
953 xmalloc (sizeof (struct prop_location));
|
|
954 pl->tick = ++prop_location_tick;
|
|
955 pl->display = display;
|
|
956 pl->window = window;
|
|
957 pl->property = property;
|
|
958 pl->desired_state = state;
|
|
959 pl->next = for_whom_the_bell_tolls;
|
|
960 for_whom_the_bell_tolls = pl;
|
|
961 return pl->tick;
|
|
962 }
|
|
963
|
|
964 static void
|
|
965 unexpect_property_change (int tick)
|
|
966 {
|
|
967 struct prop_location *prev = 0, *rest = for_whom_the_bell_tolls;
|
|
968 while (rest)
|
|
969 {
|
|
970 if (rest->tick == tick)
|
|
971 {
|
|
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 }
|
|
983
|
|
984 static void
|
|
985 wait_for_property_change (long tick)
|
|
986 {
|
|
987 /* This function can GC */
|
|
988 wait_delaying_user_input (property_deleted_p, (void *) tick);
|
|
989 }
|
|
990
|
|
991
|
|
992 /* Called from the event-loop in response to a PropertyNotify event.
|
|
993 */
|
|
994 void
|
|
995 x_handle_property_notify (XPropertyEvent *event)
|
|
996 {
|
|
997 struct prop_location *prev = 0, *rest = for_whom_the_bell_tolls;
|
|
998 while (rest)
|
|
999 {
|
|
1000 if (rest->property == event->atom &&
|
|
1001 rest->window == event->window &&
|
|
1002 rest->display == event->display &&
|
|
1003 rest->desired_state == event->state)
|
|
1004 {
|
|
1005 #if 0
|
|
1006 stderr_out ("Saw expected prop-%s on %s\n",
|
|
1007 (event->state == PropertyDelete ? "delete" : "change"),
|
|
1008 (char *) string_data (XSYMBOL (x_atom_to_symbol (get_device_from_display (event->display), event->atom))->name);
|
|
1009 #endif
|
|
1010 if (prev)
|
|
1011 prev->next = rest->next;
|
|
1012 else
|
|
1013 for_whom_the_bell_tolls = rest->next;
|
|
1014 xfree (rest);
|
|
1015 return;
|
|
1016 }
|
|
1017 prev = rest;
|
|
1018 rest = rest->next;
|
|
1019 }
|
|
1020 #if 0
|
|
1021 stderr_out ("Saw UNexpected prop-%s on %s\n",
|
|
1022 (event->state == PropertyDelete ? "delete" : "change"),
|
|
1023 (char *) string_data (XSYMBOL (x_atom_to_symbol (get_device_from_display (event->display), event->atom))->name));
|
|
1024 #endif
|
|
1025 }
|
|
1026
|
|
1027
|
|
1028
|
|
1029 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
1030
|
|
1031 static Lisp_Object
|
|
1032 fetch_multiple_target (XSelectionRequestEvent *event)
|
|
1033 {
|
|
1034 /* This function can GC */
|
|
1035 Display *display = event->display;
|
|
1036 Window window = event->requestor;
|
|
1037 Atom target = event->target;
|
|
1038 Atom selection_atom = event->selection;
|
|
1039 int result;
|
|
1040
|
|
1041 return
|
|
1042 Fcons (QMULTIPLE,
|
|
1043 x_get_window_property_as_lisp_data (display, window, target,
|
|
1044 QMULTIPLE,
|
|
1045 selection_atom));
|
|
1046 }
|
|
1047
|
|
1048 static Lisp_Object
|
|
1049 copy_multiple_data (Lisp_Object obj)
|
|
1050 {
|
|
1051 Lisp_Object vec;
|
|
1052 int i;
|
|
1053 int size;
|
|
1054 if (CONSP (obj))
|
|
1055 return Fcons (XCAR (obj), copy_multiple_data (XCDR (obj)));
|
|
1056
|
|
1057 CHECK_VECTOR (obj);
|
|
1058 size = XVECTOR (obj)->size;
|
|
1059 vec = make_vector (size, Qnil);
|
|
1060 for (i = 0; i < size; i++)
|
|
1061 {
|
|
1062 Lisp_Object vec2 = vector_data (XVECTOR (obj)) [i];
|
|
1063 CHECK_VECTOR (vec2);
|
|
1064 if (XVECTOR (vec2)->size != 2)
|
|
1065 signal_error (Qerror, list2 (build_string
|
|
1066 ("vectors must be of length 2"),
|
|
1067 vec2));
|
|
1068 vector_data (XVECTOR (vec)) [i] = make_vector (2, Qnil);
|
|
1069 vector_data (XVECTOR (vector_data (XVECTOR (vec)) [i])) [0] =
|
|
1070 vector_data (XVECTOR (vec2)) [0];
|
|
1071 vector_data (XVECTOR (vector_data (XVECTOR (vec)) [i])) [1] =
|
|
1072 vector_data (XVECTOR (vec2)) [1];
|
|
1073 }
|
|
1074 return vec;
|
|
1075 }
|
|
1076
|
|
1077 #endif
|
|
1078
|
|
1079
|
|
1080 static int reading_selection_reply;
|
|
1081 static Atom reading_which_selection;
|
|
1082 static int selection_reply_timed_out;
|
|
1083
|
|
1084 static int
|
|
1085 selection_reply_done (void *ignore)
|
|
1086 {
|
|
1087 return !reading_selection_reply;
|
|
1088 }
|
|
1089
|
|
1090 static Lisp_Object Qx_selection_reply_timeout_internal;
|
|
1091
|
|
1092 DEFUN ("x-selection-reply-timeout-internal",
|
20
|
1093 Fx_selection_reply_timeout_internal, 1, 1, 0, /*
|
0
|
1094
|
20
|
1095 */
|
|
1096 (arg))
|
0
|
1097 {
|
|
1098 selection_reply_timed_out = 1;
|
|
1099 reading_selection_reply = 0;
|
|
1100 return Qnil;
|
|
1101 }
|
|
1102
|
|
1103
|
|
1104 /* Do protocol to read selection-data from the server.
|
|
1105 Converts this to lisp data and returns it.
|
|
1106 */
|
|
1107 static Lisp_Object
|
|
1108 x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
|
|
1109 {
|
|
1110 /* This function can GC */
|
|
1111 struct device *d = decode_x_device (Qnil);
|
|
1112 Display *display = DEVICE_X_DISPLAY (d);
|
|
1113 struct frame *sel_frame = selected_frame ();
|
|
1114 Window requestor_window = XtWindow (FRAME_X_TEXT_WIDGET (sel_frame));
|
|
1115 Time requestor_time = DEVICE_X_MOUSE_TIMESTAMP (d);
|
|
1116 Atom target_property = DEVICE_XATOM_EMACS_TMP (d);
|
|
1117 Atom selection_atom = symbol_to_x_atom (d, selection_symbol, 0);
|
|
1118 Atom type_atom;
|
|
1119 int speccount;
|
|
1120
|
|
1121 if (CONSP (target_type))
|
|
1122 type_atom = symbol_to_x_atom (d, XCAR (target_type), 0);
|
|
1123 else
|
|
1124 type_atom = symbol_to_x_atom (d, target_type, 0);
|
|
1125
|
|
1126 XConvertSelection (display, selection_atom, type_atom, target_property,
|
|
1127 requestor_window, requestor_time);
|
|
1128
|
|
1129 /* Block until the reply has been read. */
|
|
1130 reading_selection_reply = (int) requestor_window;
|
|
1131 reading_which_selection = selection_atom;
|
|
1132 selection_reply_timed_out = 0;
|
|
1133
|
|
1134 speccount = specpdl_depth ();
|
|
1135
|
|
1136 /* add a timeout handler */
|
|
1137 if (x_selection_timeout > 0)
|
|
1138 {
|
|
1139 Lisp_Object id = Fadd_timeout (make_int (x_selection_timeout),
|
|
1140 Qx_selection_reply_timeout_internal,
|
|
1141 Qnil, Qnil);
|
|
1142 record_unwind_protect (Fdisable_timeout, id);
|
|
1143 }
|
|
1144
|
|
1145 /* This is ^Gable */
|
|
1146 wait_delaying_user_input (selection_reply_done, 0);
|
|
1147
|
|
1148 if (selection_reply_timed_out)
|
|
1149 error ("timed out waiting for reply from selection owner");
|
|
1150
|
|
1151 unbind_to (speccount, Qnil);
|
|
1152
|
|
1153 /* otherwise, the selection is waiting for us on the requested property. */
|
|
1154 return
|
|
1155 x_get_window_property_as_lisp_data (display, requestor_window,
|
|
1156 target_property, target_type,
|
|
1157 selection_atom);
|
|
1158 }
|
|
1159
|
|
1160
|
|
1161 static void
|
|
1162 x_get_window_property (Display *display, Window window, Atom property,
|
|
1163 unsigned char **data_ret, int *bytes_ret,
|
|
1164 Atom *actual_type_ret, int *actual_format_ret,
|
|
1165 unsigned long *actual_size_ret, int delete_p)
|
|
1166 {
|
|
1167 int total_size;
|
|
1168 unsigned long bytes_remaining;
|
|
1169 int offset = 0;
|
|
1170 unsigned char *tmp_data = 0;
|
|
1171 int result;
|
|
1172 int buffer_size = SELECTION_QUANTUM (display);
|
|
1173 if (buffer_size > MAX_SELECTION_QUANTUM) buffer_size = MAX_SELECTION_QUANTUM;
|
|
1174
|
|
1175 /* First probe the thing to find out how big it is. */
|
|
1176 result = XGetWindowProperty (display, window, property,
|
|
1177 0, 0, False, AnyPropertyType,
|
|
1178 actual_type_ret, actual_format_ret,
|
|
1179 actual_size_ret,
|
|
1180 &bytes_remaining, &tmp_data);
|
|
1181 if (result != Success)
|
|
1182 {
|
|
1183 *data_ret = 0;
|
|
1184 *bytes_ret = 0;
|
|
1185 return;
|
|
1186 }
|
|
1187 XFree ((char *) tmp_data);
|
|
1188
|
|
1189 if (*actual_type_ret == None || *actual_format_ret == 0)
|
|
1190 {
|
|
1191 if (delete_p) XDeleteProperty (display, window, property);
|
|
1192 *data_ret = 0;
|
|
1193 *bytes_ret = 0;
|
|
1194 return;
|
|
1195 }
|
|
1196
|
|
1197 total_size = bytes_remaining + 1;
|
|
1198 *data_ret = (unsigned char *) xmalloc (total_size);
|
|
1199
|
|
1200 /* Now read, until weve gotten it all. */
|
|
1201 while (bytes_remaining)
|
|
1202 {
|
|
1203 #if 0
|
|
1204 int last = bytes_remaining;
|
|
1205 #endif
|
|
1206 result =
|
|
1207 XGetWindowProperty (display, window, property,
|
|
1208 offset/4, buffer_size/4,
|
|
1209 (delete_p ? True : False),
|
|
1210 AnyPropertyType,
|
|
1211 actual_type_ret, actual_format_ret,
|
|
1212 actual_size_ret, &bytes_remaining, &tmp_data);
|
|
1213 #if 0
|
|
1214 stderr_out ("<< read %d\n", last-bytes_remaining);
|
|
1215 #endif
|
|
1216 /* If this doesn't return Success at this point, it means that
|
|
1217 some clod deleted the selection while we were in the midst of
|
|
1218 reading it. Deal with that, I guess....
|
|
1219 */
|
|
1220 if (result != Success) break;
|
|
1221 *actual_size_ret *= *actual_format_ret / 8;
|
|
1222 memcpy ((*data_ret) + offset, tmp_data, *actual_size_ret);
|
|
1223 offset += *actual_size_ret;
|
|
1224 XFree ((char *) tmp_data);
|
|
1225 }
|
|
1226 *bytes_ret = offset;
|
|
1227 }
|
|
1228
|
|
1229
|
|
1230 static void
|
|
1231 receive_incremental_selection (Display *display, Window window, Atom property,
|
|
1232 /* this one is for error messages only */
|
|
1233 Lisp_Object target_type,
|
|
1234 unsigned int min_size_bytes,
|
|
1235 unsigned char **data_ret, int *size_bytes_ret,
|
|
1236 Atom *type_ret, int *format_ret,
|
|
1237 unsigned long *size_ret)
|
|
1238 {
|
|
1239 /* This function can GC */
|
|
1240 int offset = 0;
|
|
1241 int prop_id;
|
|
1242 *size_bytes_ret = min_size_bytes;
|
|
1243 *data_ret = (unsigned char *) xmalloc (*size_bytes_ret);
|
|
1244 #if 0
|
|
1245 stderr_out ("\nread INCR %d\n", min_size_bytes);
|
|
1246 #endif
|
|
1247 /* At this point, we have read an INCR property, and deleted it (which
|
|
1248 is how we ack its receipt: the sending window will be selecting
|
|
1249 PropertyNotify events on our window to notice this).
|
|
1250
|
|
1251 Now, we must loop, waiting for the sending window to put a value on
|
|
1252 that property, then reading the property, then deleting it to ack.
|
|
1253 We are done when the sender places a property of length 0.
|
|
1254 */
|
|
1255 prop_id = expect_property_change (display, window, property,
|
|
1256 PropertyNewValue);
|
|
1257 while (1)
|
|
1258 {
|
|
1259 unsigned char *tmp_data;
|
|
1260 int tmp_size_bytes;
|
|
1261 wait_for_property_change (prop_id);
|
|
1262 /* expect it again immediately, because x_get_window_property may
|
|
1263 .. no it wont, I dont get it.
|
|
1264 .. Ok, I get it now, the Xt code that implements INCR is broken.
|
|
1265 */
|
|
1266 prop_id = expect_property_change (display, window, property,
|
|
1267 PropertyNewValue);
|
|
1268 x_get_window_property (display, window, property,
|
|
1269 &tmp_data, &tmp_size_bytes,
|
|
1270 type_ret, format_ret, size_ret, 1);
|
|
1271
|
|
1272 if (tmp_size_bytes == 0) /* we're done */
|
|
1273 {
|
|
1274 #if 0
|
|
1275 stderr_out (" read INCR done\n");
|
|
1276 #endif
|
|
1277 unexpect_property_change (prop_id);
|
|
1278 if (tmp_data) xfree (tmp_data);
|
|
1279 break;
|
|
1280 }
|
|
1281 #if 0
|
|
1282 stderr_out (" read INCR %d\n", tmp_size_bytes);
|
|
1283 #endif
|
|
1284 if (*size_bytes_ret < offset + tmp_size_bytes)
|
|
1285 {
|
|
1286 #if 0
|
|
1287 stderr_out (" read INCR realloc %d -> %d\n",
|
|
1288 *size_bytes_ret, offset + tmp_size_bytes);
|
|
1289 #endif
|
|
1290 *size_bytes_ret = offset + tmp_size_bytes;
|
|
1291 *data_ret = (unsigned char *) xrealloc (*data_ret, *size_bytes_ret);
|
|
1292 }
|
|
1293 memcpy ((*data_ret) + offset, tmp_data, tmp_size_bytes);
|
|
1294 offset += tmp_size_bytes;
|
|
1295 xfree (tmp_data);
|
|
1296 }
|
|
1297 }
|
|
1298
|
|
1299
|
|
1300 static Lisp_Object
|
|
1301 x_get_window_property_as_lisp_data (Display *display,
|
|
1302 Window window,
|
|
1303 Atom property,
|
|
1304 /* next two for error messages only */
|
|
1305 Lisp_Object target_type,
|
|
1306 Atom selection_atom)
|
|
1307 {
|
|
1308 /* This function can GC */
|
|
1309 Atom actual_type;
|
|
1310 int actual_format;
|
|
1311 unsigned long actual_size;
|
|
1312 unsigned char *data = 0;
|
|
1313 int bytes = 0;
|
|
1314 Lisp_Object val;
|
|
1315 struct device *d = get_device_from_display (display);
|
|
1316
|
|
1317 x_get_window_property (display, window, property, &data, &bytes,
|
|
1318 &actual_type, &actual_format, &actual_size, 1);
|
|
1319 if (! data)
|
|
1320 {
|
|
1321 int there_is_a_selection_owner;
|
|
1322 there_is_a_selection_owner =
|
|
1323 XGetSelectionOwner (display, selection_atom);
|
|
1324 signal_error (Qerror,
|
|
1325 (there_is_a_selection_owner
|
|
1326 ? Fcons (build_string ("selection owner couldn't convert"),
|
|
1327 (actual_type
|
|
1328 ? list2 (target_type,
|
|
1329 x_atom_to_symbol (d, actual_type))
|
|
1330 : list1 (target_type)))
|
|
1331 : list2 (build_string ("no selection"),
|
|
1332 x_atom_to_symbol (d, selection_atom))));
|
|
1333 }
|
|
1334
|
|
1335 if (actual_type == DEVICE_XATOM_INCR (d))
|
|
1336 {
|
|
1337 /* Ok, that data wasnt *the* data, it was just the beginning. */
|
|
1338
|
|
1339 unsigned int min_size_bytes = * ((unsigned int *) data);
|
|
1340 XFree ((char *) data);
|
|
1341 receive_incremental_selection (display, window, property, target_type,
|
|
1342 min_size_bytes, &data, &bytes,
|
|
1343 &actual_type, &actual_format,
|
|
1344 &actual_size);
|
|
1345 }
|
|
1346
|
|
1347 /* It's been read. Now convert it to a lisp object in some semi-rational
|
|
1348 manner.
|
|
1349 */
|
|
1350 val = selection_data_to_lisp_data (d, data, bytes,
|
|
1351 actual_type, actual_format);
|
|
1352
|
|
1353 xfree (data);
|
|
1354 return val;
|
|
1355 }
|
|
1356
|
|
1357 /* These functions convert from the selection data read from the server into
|
|
1358 something that we can use from elisp, and vice versa.
|
|
1359
|
|
1360 Type: Format: Size: Elisp Type:
|
|
1361 ----- ------- ----- -----------
|
|
1362 * 8 * String
|
|
1363 ATOM 32 1 Symbol
|
|
1364 ATOM 32 > 1 Vector of Symbols
|
|
1365 * 16 1 Integer
|
|
1366 * 16 > 1 Vector of Integers
|
|
1367 * 32 1 if <=16 bits: Integer
|
|
1368 if > 16 bits: Cons of top16, bot16
|
|
1369 * 32 > 1 Vector of the above
|
|
1370
|
|
1371 When converting a Lisp number to C, it is assumed to be of format 16 if
|
|
1372 it is an integer, and of format 32 if it is a cons of two integers.
|
|
1373
|
|
1374 When converting a vector of numbers from Elisp to C, it is assumed to be
|
|
1375 of format 16 if every element in the vector is an integer, and is assumed
|
|
1376 to be of format 32 if any element is a cons of two integers.
|
|
1377
|
|
1378 When converting an object to C, it may be of the form (SYMBOL . <data>)
|
|
1379 where SYMBOL is what we should claim that the type is. Format and
|
|
1380 representation are as above.
|
70
|
1381
|
|
1382 NOTE: Under Mule, when someone shoves us a string without a type, we
|
|
1383 set the type to 'COMPOUND_TEXT and automatically convert to Compound
|
|
1384 Text. If the string has a type, we assume that the user wants the
|
|
1385 data sent as-is so we just do "binary" conversion.
|
0
|
1386 */
|
|
1387
|
|
1388
|
|
1389 static Lisp_Object
|
|
1390 selection_data_to_lisp_data (struct device *d,
|
|
1391 unsigned char *data,
|
|
1392 int size,
|
|
1393 Atom type,
|
|
1394 int format)
|
|
1395 {
|
|
1396 if (type == DEVICE_XATOM_NULL (d))
|
|
1397 return QNULL;
|
|
1398
|
|
1399 /* Convert any 8-bit data to a string, for compactness. */
|
|
1400 else if (format == 8)
|
|
1401 return make_ext_string (data, size,
|
|
1402 type == DEVICE_XATOM_TEXT (d)
|
|
1403 || type == DEVICE_XATOM_COMPOUND_TEXT (d)
|
|
1404 ? FORMAT_CTEXT : FORMAT_BINARY);
|
|
1405
|
|
1406 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to
|
|
1407 a vector of symbols.
|
|
1408 */
|
|
1409 else if (type == XA_ATOM)
|
|
1410 {
|
|
1411 int i;
|
|
1412 if (size == sizeof (Atom))
|
|
1413 return x_atom_to_symbol (d, *((Atom *) data));
|
|
1414 else
|
|
1415 {
|
|
1416 Lisp_Object v = Fmake_vector (make_int (size / sizeof (Atom)),
|
|
1417 Qzero);
|
|
1418 for (i = 0; i < size / sizeof (Atom); i++)
|
|
1419 Faset (v, make_int (i),
|
|
1420 x_atom_to_symbol (d, ((Atom *) data) [i]));
|
|
1421 return v;
|
|
1422 }
|
|
1423 }
|
|
1424
|
|
1425 /* Convert a single 16 or small 32 bit number to a Lisp_Int.
|
|
1426 If the number is > 16 bits, convert it to a cons of integers,
|
|
1427 16 bits in each half.
|
|
1428 */
|
|
1429 else if (format == 32 && size == sizeof (long))
|
|
1430 return word_to_lisp (((unsigned long *) data) [0]);
|
|
1431 else if (format == 16 && size == sizeof (short))
|
|
1432 return make_int ((int) (((unsigned short *) data) [0]));
|
|
1433
|
|
1434 /* Convert any other kind of data to a vector of numbers, represented
|
|
1435 as above (as an integer, or a cons of two 16 bit integers).
|
|
1436
|
|
1437 #### Perhaps we should return the actual type to lisp as well.
|
|
1438
|
|
1439 (x-get-selection-internal 'PRIMARY 'LINE_NUMBER)
|
|
1440 ==> [4 4]
|
|
1441
|
|
1442 and perhaps it should be
|
|
1443
|
|
1444 (x-get-selection-internal 'PRIMARY 'LINE_NUMBER)
|
|
1445 ==> (SPAN . [4 4])
|
|
1446
|
|
1447 Right now the fact that the return type was SPAN is discarded before
|
|
1448 lisp code gets to see it.
|
|
1449 */
|
|
1450 else if (format == 16)
|
|
1451 {
|
|
1452 int i;
|
|
1453 Lisp_Object v = make_vector (size / 4, Qzero);
|
|
1454 for (i = 0; i < size / 4; i++)
|
|
1455 {
|
|
1456 int j = (int) ((unsigned short *) data) [i];
|
|
1457 Faset (v, make_int (i), make_int (j));
|
|
1458 }
|
|
1459 return v;
|
|
1460 }
|
|
1461 else
|
|
1462 {
|
|
1463 int i;
|
|
1464 Lisp_Object v = make_vector (size / 4, Qzero);
|
|
1465 for (i = 0; i < size / 4; i++)
|
|
1466 {
|
|
1467 unsigned long j = ((unsigned long *) data) [i];
|
|
1468 Faset (v, make_int (i), word_to_lisp (j));
|
|
1469 }
|
|
1470 return v;
|
|
1471 }
|
|
1472 }
|
|
1473
|
|
1474
|
|
1475 static void
|
|
1476 lisp_data_to_selection_data (struct device *d,
|
|
1477 Lisp_Object obj,
|
|
1478 unsigned char **data_ret,
|
|
1479 Atom *type_ret,
|
|
1480 unsigned int *size_ret,
|
|
1481 int *format_ret)
|
|
1482 {
|
|
1483 Lisp_Object type = Qnil;
|
|
1484
|
|
1485 if (CONSP (obj) && SYMBOLP (XCAR (obj)))
|
|
1486 {
|
|
1487 type = XCAR (obj);
|
|
1488 obj = XCDR (obj);
|
|
1489 if (CONSP (obj) && NILP (XCDR (obj)))
|
|
1490 obj = XCAR (obj);
|
|
1491 }
|
|
1492
|
|
1493 if (EQ (obj, QNULL) || (EQ (type, QNULL)))
|
|
1494 { /* This is not the same as declining */
|
|
1495 *format_ret = 32;
|
|
1496 *size_ret = 0;
|
|
1497 *data_ret = 0;
|
|
1498 type = QNULL;
|
|
1499 }
|
|
1500 else if (STRINGP (obj))
|
|
1501 {
|
|
1502 Extbyte *extval;
|
|
1503 Extcount extvallen;
|
|
1504
|
|
1505 if (NILP (type))
|
|
1506 GET_STRING_CTEXT_DATA_ALLOCA (obj, extval, extvallen);
|
|
1507 else
|
|
1508 GET_STRING_BINARY_DATA_ALLOCA (obj, extval, extvallen);
|
|
1509 *format_ret = 8;
|
|
1510 *size_ret = extvallen;
|
|
1511 *data_ret = (unsigned char *) xmalloc (*size_ret);
|
|
1512 memcpy (*data_ret, extval, *size_ret);
|
70
|
1513 #ifdef MULE
|
|
1514 if (NILP (type)) type = QCOMPOUND_TEXT;
|
|
1515 #else
|
0
|
1516 if (NILP (type)) type = QSTRING;
|
70
|
1517 #endif
|
|
1518 }
|
|
1519 else if (CHARP (obj))
|
|
1520 {
|
|
1521 Bufbyte buf[MAX_EMCHAR_LEN];
|
|
1522 Bytecount len;
|
|
1523 CONST Extbyte *extval;
|
|
1524 Extcount extvallen;
|
|
1525
|
|
1526 *format_ret = 8;
|
|
1527 len = set_charptr_emchar (buf, XCHAR (obj));
|
|
1528 GET_CHARPTR_EXT_CTEXT_DATA_ALLOCA (buf, len, extval, extvallen);
|
|
1529 *size_ret = extvallen;
|
|
1530 *data_ret = (unsigned char *) xmalloc (*size_ret);
|
|
1531 memcpy (*data_ret, extval, *size_ret);
|
|
1532 #ifdef MULE
|
|
1533 if (NILP (type)) type = QCOMPOUND_TEXT;
|
|
1534 #else
|
|
1535 if (NILP (type)) type = QSTRING;
|
|
1536 #endif
|
0
|
1537 }
|
|
1538 else if (SYMBOLP (obj))
|
|
1539 {
|
|
1540 *format_ret = 32;
|
|
1541 *size_ret = 1;
|
|
1542 *data_ret = (unsigned char *) xmalloc (sizeof (Atom) + 1);
|
|
1543 (*data_ret) [sizeof (Atom)] = 0;
|
|
1544 (*(Atom **) data_ret) [0] = symbol_to_x_atom (d, obj, 0);
|
|
1545 if (NILP (type)) type = QATOM;
|
|
1546 }
|
|
1547 else if (INTP (obj) &&
|
|
1548 XINT (obj) <= 0x7FFF &&
|
|
1549 XINT (obj) >= -0x8000)
|
|
1550 {
|
|
1551 *format_ret = 16;
|
|
1552 *size_ret = 1;
|
|
1553 *data_ret = (unsigned char *) xmalloc (sizeof (short) + 1);
|
|
1554 (*data_ret) [sizeof (short)] = 0;
|
|
1555 (*(short **) data_ret) [0] = (short) XINT (obj);
|
|
1556 if (NILP (type)) type = QINTEGER;
|
|
1557 }
|
|
1558 else if (INTP (obj) || CONSP (obj))
|
|
1559 {
|
|
1560 *format_ret = 32;
|
|
1561 *size_ret = 1;
|
|
1562 *data_ret = (unsigned char *) xmalloc (sizeof (long) + 1);
|
|
1563 (*data_ret) [sizeof (long)] = 0;
|
|
1564 (*(unsigned long **) data_ret) [0] = lisp_to_word (obj);
|
|
1565 if (NILP (type)) type = QINTEGER;
|
|
1566 }
|
|
1567 else if (VECTORP (obj))
|
|
1568 {
|
|
1569 /* Lisp_Vectors may represent a set of ATOMs;
|
|
1570 a set of 16 or 32 bit INTEGERs;
|
|
1571 or a set of ATOM_PAIRs (represented as [[A1 A2] [A3 A4] ...]
|
|
1572 */
|
|
1573 int i;
|
|
1574
|
|
1575 if (SYMBOLP (vector_data (XVECTOR (obj)) [0]))
|
|
1576 /* This vector is an ATOM set */
|
|
1577 {
|
|
1578 if (NILP (type)) type = QATOM;
|
|
1579 *size_ret = XVECTOR (obj)->size;
|
|
1580 *format_ret = 32;
|
|
1581 *data_ret = (unsigned char *) xmalloc ((*size_ret) * sizeof (Atom));
|
|
1582 for (i = 0; i < *size_ret; i++)
|
|
1583 if (SYMBOLP (vector_data (XVECTOR (obj)) [i]))
|
|
1584 (*(Atom **) data_ret) [i] =
|
|
1585 symbol_to_x_atom (d, vector_data (XVECTOR (obj)) [i], 0);
|
|
1586 else
|
|
1587 signal_error (Qerror, /* Qselection_error */
|
|
1588 list2 (build_string
|
|
1589 ("all elements of the vector must be of the same type"),
|
|
1590 obj));
|
|
1591 }
|
|
1592 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
1593 else if (VECTORP (vector_data (XVECTOR (obj)) [0]))
|
|
1594 /* This vector is an ATOM_PAIR set */
|
|
1595 {
|
|
1596 if (NILP (type)) type = QATOM_PAIR;
|
|
1597 *size_ret = XVECTOR (obj)->size;
|
|
1598 *format_ret = 32;
|
|
1599 *data_ret = (unsigned char *)
|
|
1600 xmalloc ((*size_ret) * sizeof (Atom) * 2);
|
|
1601 for (i = 0; i < *size_ret; i++)
|
|
1602 if (VECTORP (vector_data (XVECTOR (obj)) [i]))
|
|
1603 {
|
|
1604 Lisp_Object pair = vector_data (XVECTOR (obj)) [i];
|
|
1605 if (XVECTOR (pair)->size != 2)
|
|
1606 signal_error (Qerror,
|
|
1607 list2 (build_string
|
|
1608 ("elements of the vector must be vectors of exactly two elements"),
|
|
1609 pair));
|
|
1610
|
|
1611 (*(Atom **) data_ret) [i * 2] =
|
|
1612 symbol_to_x_atom (d, vector_data (XVECTOR (pair)) [0], 0);
|
|
1613 (*(Atom **) data_ret) [(i * 2) + 1] =
|
|
1614 symbol_to_x_atom (d, vector_data (XVECTOR (pair)) [1], 0);
|
|
1615 }
|
|
1616 else
|
|
1617 signal_error (Qerror,
|
|
1618 list2 (build_string
|
|
1619 ("all elements of the vector must be of the same type"),
|
|
1620 obj));
|
|
1621 }
|
|
1622 #endif
|
|
1623 else
|
|
1624 /* This vector is an INTEGER set, or something like it */
|
|
1625 {
|
|
1626 *size_ret = XVECTOR (obj)->size;
|
|
1627 if (NILP (type)) type = QINTEGER;
|
|
1628 *format_ret = 16;
|
|
1629 for (i = 0; i < *size_ret; i++)
|
|
1630 if (CONSP (vector_data (XVECTOR (obj)) [i]))
|
|
1631 *format_ret = 32;
|
|
1632 else if (!INTP (vector_data (XVECTOR (obj)) [i]))
|
|
1633 signal_error (Qerror, /* Qselection_error */
|
|
1634 list2 (build_string
|
|
1635 ("all elements of the vector must be integers or conses of integers"),
|
|
1636 obj));
|
|
1637
|
|
1638 *data_ret = (unsigned char *) xmalloc (*size_ret * (*format_ret/8));
|
|
1639 for (i = 0; i < *size_ret; i++)
|
|
1640 if (*format_ret == 32)
|
|
1641 (*((unsigned long **) data_ret)) [i] =
|
|
1642 lisp_to_word (vector_data (XVECTOR (obj)) [i]);
|
|
1643 else
|
|
1644 (*((unsigned short **) data_ret)) [i] =
|
|
1645 (unsigned short) lisp_to_word (vector_data (XVECTOR (obj)) [i]);
|
|
1646 }
|
|
1647 }
|
|
1648 else
|
|
1649 signal_error (Qerror, /* Qselection_error */
|
|
1650 list2 (build_string ("unrecognized selection data"),
|
|
1651 obj));
|
|
1652
|
|
1653 *type_ret = symbol_to_x_atom (d, type, 0);
|
|
1654 }
|
|
1655
|
|
1656 static Lisp_Object
|
|
1657 clean_local_selection_data (Lisp_Object obj)
|
|
1658 {
|
|
1659 if (CONSP (obj) &&
|
|
1660 INTP (XCAR (obj)) &&
|
|
1661 CONSP (XCDR (obj)) &&
|
|
1662 INTP (XCAR (XCDR (obj))) &&
|
|
1663 NILP (XCDR (XCDR (obj))))
|
|
1664 obj = Fcons (XCAR (obj), XCDR (obj));
|
|
1665
|
|
1666 if (CONSP (obj) &&
|
|
1667 INTP (XCAR (obj)) &&
|
|
1668 INTP (XCDR (obj)))
|
|
1669 {
|
|
1670 if (XINT (XCAR (obj)) == 0)
|
|
1671 return XCDR (obj);
|
|
1672 if (XINT (XCAR (obj)) == -1)
|
|
1673 return make_int (- XINT (XCDR (obj)));
|
|
1674 }
|
|
1675 if (VECTORP (obj))
|
|
1676 {
|
|
1677 int i;
|
|
1678 int size = XVECTOR (obj)->size;
|
|
1679 Lisp_Object copy;
|
|
1680 if (size == 1)
|
|
1681 return clean_local_selection_data (vector_data (XVECTOR (obj)) [0]);
|
|
1682 copy = make_vector (size, Qnil);
|
|
1683 for (i = 0; i < size; i++)
|
|
1684 vector_data (XVECTOR (copy)) [i] =
|
|
1685 clean_local_selection_data (vector_data (XVECTOR (obj)) [i]);
|
|
1686 return copy;
|
|
1687 }
|
|
1688 return obj;
|
|
1689 }
|
|
1690
|
|
1691
|
|
1692 /* Called from the event loop to handle SelectionNotify events.
|
|
1693 I don't think this needs to be reentrant.
|
|
1694 */
|
|
1695 void
|
|
1696 x_handle_selection_notify (XSelectionEvent *event)
|
|
1697 {
|
|
1698 if (! reading_selection_reply)
|
|
1699 {
|
|
1700 message ("received an unexpected SelectionNotify event");
|
|
1701 return;
|
|
1702 }
|
|
1703 if (event->requestor != reading_selection_reply)
|
|
1704 {
|
|
1705 message ("received a SelectionNotify event for the wrong window");
|
|
1706 return;
|
|
1707 }
|
|
1708 if (event->selection != reading_which_selection)
|
|
1709 {
|
|
1710 message ("received the wrong selection type in SelectionNotify!");
|
|
1711 return;
|
|
1712 }
|
|
1713
|
|
1714 reading_selection_reply = 0; /* we're done now. */
|
|
1715 }
|
|
1716
|
|
1717
|
20
|
1718 DEFUN ("x-own-selection-internal", Fx_own_selection_internal, 2, 2, 0, /*
|
0
|
1719 Assert an X selection of the given TYPE with the given VALUE.
|
|
1720 TYPE is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
|
|
1721 VALUE is typically a string, or a cons of two markers, but may be
|
|
1722 anything that the functions on selection-converter-alist know about.
|
20
|
1723 */
|
|
1724 (selection_name, selection_value))
|
0
|
1725 {
|
|
1726 CHECK_SYMBOL (selection_name);
|
|
1727 if (NILP (selection_value)) error ("selection-value may not be nil.");
|
|
1728 x_own_selection (selection_name, selection_value);
|
|
1729 return selection_value;
|
|
1730 }
|
|
1731
|
|
1732
|
|
1733 /* Request the selection value from the owner. If we are the owner,
|
|
1734 simply return our selection value. If we are not the owner, this
|
|
1735 will block until all of the data has arrived.
|
|
1736 */
|
20
|
1737 DEFUN ("x-get-selection-internal", Fx_get_selection_internal, 2, 2, 0, /*
|
0
|
1738 Return text selected from some X window.
|
|
1739 SELECTION is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
|
70
|
1740 TYPE is the type of data desired, typically STRING or COMPOUND_TEXT.
|
|
1741 Under Mule, if the resultant data comes back as 8-bit data in type
|
|
1742 TEXT or COMPOUND_TEXT, it will be decoded as Compound Text.
|
20
|
1743 */
|
|
1744 (selection_symbol, target_type))
|
0
|
1745 {
|
|
1746 /* This function can GC */
|
|
1747 Lisp_Object val = Qnil;
|
|
1748 struct gcpro gcpro1, gcpro2;
|
|
1749 GCPRO2 (target_type, val); /* we store newly consed data into these */
|
|
1750 CHECK_SYMBOL (selection_symbol);
|
|
1751
|
|
1752 #if 0 /* #### MULTIPLE doesn't work yet */
|
|
1753 if (CONSP (target_type) &&
|
|
1754 XCAR (target_type) == QMULTIPLE)
|
|
1755 {
|
|
1756 CHECK_VECTOR (XCDR (target_type));
|
|
1757 /* So we don't destructively modify this... */
|
|
1758 target_type = copy_multiple_data (target_type);
|
|
1759 }
|
|
1760 else
|
|
1761 #endif
|
|
1762 CHECK_SYMBOL (target_type);
|
|
1763
|
|
1764 val = x_get_local_selection (selection_symbol, target_type);
|
|
1765
|
|
1766 if (NILP (val))
|
|
1767 {
|
|
1768 val = x_get_foreign_selection (selection_symbol,
|
|
1769 target_type);
|
|
1770 goto DONE_LABEL;
|
|
1771 }
|
|
1772
|
|
1773 if (CONSP (val) &&
|
|
1774 SYMBOLP (XCAR (val)))
|
|
1775 {
|
|
1776 val = XCDR (val);
|
|
1777 if (CONSP (val) && NILP (XCDR (val)))
|
|
1778 val = XCAR (val);
|
|
1779 }
|
|
1780 val = clean_local_selection_data (val);
|
|
1781 DONE_LABEL:
|
|
1782 UNGCPRO;
|
|
1783 return val;
|
|
1784 }
|
|
1785
|
20
|
1786 DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal, 1, 2, 0, /*
|
0
|
1787 If we own the named selection, then disown it (make there be no selection).
|
20
|
1788 */
|
|
1789 (selection, timeval))
|
0
|
1790 {
|
|
1791 struct device *d = decode_x_device (Qnil);
|
|
1792 Display *display = DEVICE_X_DISPLAY (d);
|
|
1793 Time timestamp;
|
|
1794 Atom selection_atom;
|
|
1795 XSelectionClearEvent event;
|
|
1796
|
|
1797 CHECK_SYMBOL (selection);
|
|
1798 if (NILP (timeval))
|
|
1799 timestamp = DEVICE_X_MOUSE_TIMESTAMP (d);
|
|
1800 else
|
|
1801 {
|
|
1802 /* #### This is bogus. See the comment above about problems
|
|
1803 on OSF/1 and DEC Alphas. Yet another reason why it sucks
|
|
1804 to have the implementation (i.e. cons of two 16-bit
|
|
1805 integers) exposed. */
|
|
1806 time_t the_time;
|
|
1807 lisp_to_time (timeval, &the_time);
|
|
1808 timestamp = (Time) the_time;
|
|
1809 }
|
|
1810
|
|
1811 if (NILP (assq_no_quit (selection, Vselection_alist)))
|
|
1812 return Qnil; /* Don't disown the selection when we're not the owner. */
|
|
1813
|
|
1814 selection_atom = symbol_to_x_atom (d, selection, 0);
|
|
1815
|
|
1816 XSetSelectionOwner (display, selection_atom, None, timestamp);
|
|
1817
|
|
1818 /* It doesn't seem to be guaranteed that a SelectionClear event will be
|
|
1819 generated for a window which owns the selection when that window sets
|
|
1820 the selection owner to None. The NCD server does, the MIT Sun4 server
|
|
1821 doesn't. So we synthesize one; this means we might get two, but
|
|
1822 that's ok, because the second one won't have any effect.
|
|
1823 */
|
|
1824 event.display = display;
|
|
1825 event.selection = selection_atom;
|
|
1826 event.time = timestamp;
|
|
1827 x_handle_selection_clear (&event);
|
|
1828
|
|
1829 return Qt;
|
|
1830 }
|
|
1831
|
|
1832
|
20
|
1833 DEFUN ("x-selection-owner-p", Fx_selection_owner_p, 0, 1, 0, /*
|
0
|
1834 Whether the current emacs process owns the given X Selection.
|
|
1835 The arg should be the name of the selection in question, typically one of
|
|
1836 the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience, the symbol
|
|
1837 nil is the same as PRIMARY, and t is the same as SECONDARY.)
|
20
|
1838 */
|
|
1839 (selection))
|
0
|
1840 {
|
|
1841 CHECK_SYMBOL (selection);
|
|
1842 if (EQ (selection, Qnil)) selection = QPRIMARY;
|
|
1843 if (EQ (selection, Qt)) selection = QSECONDARY;
|
|
1844
|
|
1845 if (NILP (Fassq (selection, Vselection_alist)))
|
|
1846 return Qnil;
|
|
1847 return Qt;
|
|
1848 }
|
|
1849
|
20
|
1850 DEFUN ("x-selection-exists-p", Fx_selection_exists_p, 0, 1, 0, /*
|
0
|
1851 Whether there is an owner for the given X Selection.
|
|
1852 The arg should be the name of the selection in question, typically one of
|
|
1853 the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience, the symbol
|
|
1854 nil is the same as PRIMARY, and t is the same as SECONDARY.)
|
20
|
1855 */
|
|
1856 (selection))
|
0
|
1857 {
|
|
1858 Window owner;
|
|
1859 struct device *d = decode_x_device (Qnil);
|
|
1860 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1861 CHECK_SYMBOL (selection);
|
|
1862 if (!NILP (Fx_selection_owner_p (selection)))
|
|
1863 return Qt;
|
|
1864 owner = XGetSelectionOwner (dpy, symbol_to_x_atom (d, selection, 0));
|
|
1865 return (owner ? Qt : Qnil);
|
|
1866 }
|
|
1867
|
|
1868
|
|
1869 #ifdef CUT_BUFFER_SUPPORT
|
|
1870
|
|
1871 static int cut_buffers_initialized; /* Whether we're sure they all exist */
|
|
1872
|
|
1873 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
|
|
1874 static void
|
|
1875 initialize_cut_buffers (Display *display, Window window)
|
|
1876 {
|
16
|
1877 static unsigned CONST char * CONST data = (unsigned CONST char *) "";
|
0
|
1878 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
|
|
1879 PropModeAppend, data, 0)
|
|
1880 FROB (XA_CUT_BUFFER0);
|
|
1881 FROB (XA_CUT_BUFFER1);
|
|
1882 FROB (XA_CUT_BUFFER2);
|
|
1883 FROB (XA_CUT_BUFFER3);
|
|
1884 FROB (XA_CUT_BUFFER4);
|
|
1885 FROB (XA_CUT_BUFFER5);
|
|
1886 FROB (XA_CUT_BUFFER6);
|
|
1887 FROB (XA_CUT_BUFFER7);
|
|
1888 #undef FROB
|
|
1889 cut_buffers_initialized = 1;
|
|
1890 }
|
|
1891
|
|
1892 #define CHECK_CUTBUFFER(symbol) \
|
|
1893 { CHECK_SYMBOL (symbol); \
|
|
1894 if (!EQ((symbol),QCUT_BUFFER0) && !EQ((symbol),QCUT_BUFFER1) && \
|
|
1895 !EQ((symbol),QCUT_BUFFER2) && !EQ((symbol),QCUT_BUFFER3) && \
|
|
1896 !EQ((symbol),QCUT_BUFFER4) && !EQ((symbol),QCUT_BUFFER5) && \
|
|
1897 !EQ((symbol),QCUT_BUFFER6) && !EQ((symbol),QCUT_BUFFER7)) \
|
16
|
1898 signal_error (Qerror, list2 (build_string ("Doesn't name a cutbuffer"), \
|
0
|
1899 (symbol))); \
|
|
1900 }
|
|
1901
|
20
|
1902 DEFUN ("x-get-cutbuffer-internal", Fx_get_cutbuffer_internal, 1, 1, 0, /*
|
16
|
1903 Return the value of the named CUTBUFFER (typically CUT_BUFFER0).
|
20
|
1904 */
|
|
1905 (cutbuffer))
|
0
|
1906 {
|
|
1907 struct device *d = decode_x_device (Qnil);
|
|
1908 Display *display = DEVICE_X_DISPLAY (d);
|
|
1909 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
|
16
|
1910 Atom cut_buffer_atom;
|
0
|
1911 unsigned char *data;
|
|
1912 int bytes;
|
|
1913 Atom type;
|
|
1914 int format;
|
|
1915 unsigned long size;
|
|
1916 Lisp_Object ret;
|
|
1917
|
16
|
1918 CHECK_CUTBUFFER (cutbuffer);
|
|
1919 cut_buffer_atom = symbol_to_x_atom (d, cutbuffer, 0);
|
0
|
1920
|
16
|
1921 x_get_window_property (display, window, cut_buffer_atom, &data, &bytes,
|
0
|
1922 &type, &format, &size, 0);
|
|
1923 if (!data) return Qnil;
|
16
|
1924
|
0
|
1925 if (format != 8 || type != XA_STRING)
|
16
|
1926 signal_simple_error_2 ("Cut buffer doesn't contain 8-bit STRING data",
|
0
|
1927 x_atom_to_symbol (d, type),
|
|
1928 make_int (format));
|
|
1929
|
70
|
1930 /* We cheat - if the string contains an ESC character, that's
|
|
1931 technically not allowed in a STRING, so we assume it's
|
|
1932 COMPOUND_TEXT that we stored there ourselves earlier,
|
|
1933 in x-store-cutbuffer-internal */
|
16
|
1934 ret = (bytes ?
|
|
1935 make_ext_string (data, bytes,
|
70
|
1936 memchr (data, 0x1b, bytes) ?
|
|
1937 FORMAT_CTEXT : FORMAT_BINARY)
|
16
|
1938 : Qnil);
|
0
|
1939 xfree (data);
|
|
1940 return ret;
|
|
1941 }
|
|
1942
|
|
1943
|
20
|
1944 DEFUN ("x-store-cutbuffer-internal", Fx_store_cutbuffer_internal, 2, 2, 0, /*
|
16
|
1945 Set the value of the named CUTBUFFER (typically CUT_BUFFER0) to STRING.
|
20
|
1946 */
|
|
1947 (cutbuffer, string))
|
0
|
1948 {
|
|
1949 struct device *d = decode_x_device (Qnil);
|
|
1950 Display *display = DEVICE_X_DISPLAY (d);
|
|
1951 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
|
16
|
1952 Atom cut_buffer_atom;
|
|
1953 Extbyte *data = XSTRING_DATA (string);
|
|
1954 Extcount bytes = XSTRING_LENGTH (string);
|
|
1955 Extcount bytes_remaining;
|
0
|
1956 int max_bytes = SELECTION_QUANTUM (display);
|
70
|
1957 #ifdef MULE
|
|
1958 CONST Bufbyte *ptr, *end;
|
|
1959 Atom encoding = XA_STRING;
|
|
1960 enum { ASCII, LATIN_1, WORLD } chartypes = ASCII;
|
|
1961 #endif
|
16
|
1962
|
|
1963 if (max_bytes > MAX_SELECTION_QUANTUM)
|
|
1964 max_bytes = MAX_SELECTION_QUANTUM;
|
0
|
1965
|
16
|
1966 CHECK_CUTBUFFER (cutbuffer);
|
0
|
1967 CHECK_STRING (string);
|
16
|
1968 cut_buffer_atom = symbol_to_x_atom (d, cutbuffer, 0);
|
|
1969
|
|
1970 if (! cut_buffers_initialized)
|
|
1971 initialize_cut_buffers (display, window);
|
|
1972
|
70
|
1973 /* We use the STRING encoding (Latin-1 only) if we can, else COMPOUND_TEXT.
|
|
1974 We cheat and use type = `STRING' even when using COMPOUND_TEXT.
|
|
1975 The ICCCM requires that this be so, and other clients assume it,
|
|
1976 as we do ourselves in initialize_cut_buffers. */
|
|
1977
|
|
1978 #ifdef MULE
|
|
1979 /* Optimize for the common ASCII case */
|
|
1980 for (ptr = data, end = ptr + bytes; ptr <= end; )
|
|
1981 {
|
|
1982 if (BYTE_ASCII_P (*ptr))
|
|
1983 {
|
|
1984 ptr++;
|
|
1985 continue;
|
|
1986 }
|
|
1987
|
74
|
1988 if ((*ptr) == LEADING_BYTE_LATIN_ISO8859_1 ||
|
70
|
1989 (*ptr) == LEADING_BYTE_CONTROL_1)
|
|
1990 {
|
|
1991 chartypes = LATIN_1;
|
|
1992 ptr += 2;
|
|
1993 continue;
|
|
1994 }
|
|
1995
|
|
1996 chartypes = WORLD;
|
|
1997 break;
|
|
1998 }
|
|
1999
|
|
2000 switch (chartypes)
|
|
2001 {
|
|
2002 case LATIN_1: GET_STRING_BINARY_DATA_ALLOCA (string, data, bytes); break;
|
|
2003 case WORLD: GET_STRING_CTEXT_DATA_ALLOCA (string, data, bytes); break;
|
|
2004 }
|
|
2005 #endif /* MULE */
|
|
2006
|
0
|
2007 bytes_remaining = bytes;
|
|
2008
|
|
2009 while (bytes_remaining)
|
|
2010 {
|
16
|
2011 int chunk = bytes_remaining < max_bytes ? bytes_remaining : max_bytes;
|
|
2012 XChangeProperty (display, window, cut_buffer_atom, XA_STRING, 8,
|
0
|
2013 (bytes_remaining == bytes
|
16
|
2014 ? PropModeReplace : PropModeAppend),
|
0
|
2015 data, chunk);
|
|
2016 data += chunk;
|
|
2017 bytes_remaining -= chunk;
|
|
2018 }
|
|
2019 return string;
|
|
2020 }
|
|
2021
|
|
2022
|
20
|
2023 DEFUN ("x-rotate-cutbuffers-internal", Fx_rotate_cutbuffers_internal, 1, 1, 0, /*
|
0
|
2024 Rotate the values of the cutbuffers by the given number of steps;
|
|
2025 positive means move values forward, negative means backward.
|
20
|
2026 */
|
|
2027 (n))
|
0
|
2028 {
|
|
2029 struct device *d = decode_x_device (Qnil);
|
|
2030 Display *display = DEVICE_X_DISPLAY (d);
|
|
2031 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
|
|
2032 Atom props [8];
|
|
2033
|
|
2034 CHECK_INT (n);
|
|
2035 if (XINT (n) == 0)
|
|
2036 return n;
|
|
2037 if (! cut_buffers_initialized)
|
|
2038 initialize_cut_buffers (display, window);
|
|
2039 props[0] = XA_CUT_BUFFER0;
|
|
2040 props[1] = XA_CUT_BUFFER1;
|
|
2041 props[2] = XA_CUT_BUFFER2;
|
|
2042 props[3] = XA_CUT_BUFFER3;
|
|
2043 props[4] = XA_CUT_BUFFER4;
|
|
2044 props[5] = XA_CUT_BUFFER5;
|
|
2045 props[6] = XA_CUT_BUFFER6;
|
|
2046 props[7] = XA_CUT_BUFFER7;
|
|
2047 XRotateWindowProperties (display, window, props, 8, XINT (n));
|
|
2048 return n;
|
|
2049 }
|
|
2050
|
16
|
2051 #endif /* CUT_BUFFER_SUPPORT */
|
0
|
2052
|
70
|
2053
|
0
|
2054
|
|
2055 /************************************************************************/
|
|
2056 /* initialization */
|
|
2057 /************************************************************************/
|
|
2058
|
|
2059 void
|
|
2060 syms_of_xselect (void)
|
|
2061 {
|
20
|
2062 DEFSUBR (Fx_get_selection_internal);
|
|
2063 DEFSUBR (Fx_own_selection_internal);
|
|
2064 DEFSUBR (Fx_disown_selection_internal);
|
|
2065 DEFSUBR (Fx_selection_owner_p);
|
|
2066 DEFSUBR (Fx_selection_exists_p);
|
0
|
2067
|
|
2068 #ifdef CUT_BUFFER_SUPPORT
|
20
|
2069 DEFSUBR (Fx_get_cutbuffer_internal);
|
|
2070 DEFSUBR (Fx_store_cutbuffer_internal);
|
|
2071 DEFSUBR (Fx_rotate_cutbuffers_internal);
|
16
|
2072 #endif /* CUT_BUFFER_SUPPORT */
|
0
|
2073
|
|
2074 /* Unfortunately, timeout handlers must be lisp functions. */
|
|
2075 defsymbol (&Qx_selection_reply_timeout_internal,
|
|
2076 "x-selection-reply-timeout-internal");
|
20
|
2077 DEFSUBR (Fx_selection_reply_timeout_internal);
|
0
|
2078
|
|
2079 defsymbol (&QPRIMARY, "PRIMARY");
|
|
2080 defsymbol (&QSECONDARY, "SECONDARY");
|
|
2081 defsymbol (&QSTRING, "STRING");
|
|
2082 defsymbol (&QINTEGER, "INTEGER");
|
|
2083 defsymbol (&QCLIPBOARD, "CLIPBOARD");
|
|
2084 defsymbol (&QTIMESTAMP, "TIMESTAMP");
|
|
2085 defsymbol (&QTEXT, "TEXT");
|
|
2086 defsymbol (&QTIMESTAMP, "TIMESTAMP");
|
|
2087 defsymbol (&QDELETE, "DELETE");
|
|
2088 defsymbol (&QMULTIPLE, "MULTIPLE");
|
|
2089 defsymbol (&QINCR, "INCR");
|
|
2090 defsymbol (&QEMACS_TMP, "_EMACS_TMP_");
|
|
2091 defsymbol (&QTARGETS, "TARGETS");
|
|
2092 defsymbol (&QATOM, "ATOM");
|
|
2093 defsymbol (&QATOM_PAIR, "ATOM_PAIR");
|
|
2094 defsymbol (&QCOMPOUND_TEXT, "COMPOUND_TEXT");
|
|
2095 defsymbol (&QNULL, "NULL");
|
|
2096
|
|
2097 #ifdef EPOCH
|
|
2098 defsymbol (&QARC, "ARC");
|
|
2099 defsymbol (&QBITMAP, "BITMAP");
|
|
2100 defsymbol (&QCARDINAL, "CARDINAL");
|
|
2101 defsymbol (&QCURSOR, "CURSOR");
|
|
2102 defsymbol (&QDRAWABLE, "DRAWABLE");
|
|
2103 defsymbol (&QFONT, "FONT");
|
|
2104 defsymbol (&QINTEGER, "INTEGER");
|
|
2105 defsymbol (&QPIXMAP, "PIXMAP");
|
|
2106 defsymbol (&QPOINT, "POINT");
|
|
2107 defsymbol (&QRECTANGLE, "RECTANGLE");
|
|
2108 defsymbol (&QWINDOW, "WINDOW");
|
|
2109 defsymbol (&QWM_HINTS, "WM_HINTS");
|
|
2110 defsymbol (&QWM_SIZE_HINTS, "WM_SIZE_HINTS");
|
|
2111 #endif /* EPOCH */
|
|
2112
|
|
2113 #ifdef CUT_BUFFER_SUPPORT
|
|
2114 defsymbol (&QCUT_BUFFER0, "CUT_BUFFER0");
|
|
2115 defsymbol (&QCUT_BUFFER1, "CUT_BUFFER1");
|
|
2116 defsymbol (&QCUT_BUFFER2, "CUT_BUFFER2");
|
|
2117 defsymbol (&QCUT_BUFFER3, "CUT_BUFFER3");
|
|
2118 defsymbol (&QCUT_BUFFER4, "CUT_BUFFER4");
|
|
2119 defsymbol (&QCUT_BUFFER5, "CUT_BUFFER5");
|
|
2120 defsymbol (&QCUT_BUFFER6, "CUT_BUFFER6");
|
|
2121 defsymbol (&QCUT_BUFFER7, "CUT_BUFFER7");
|
|
2122 #endif
|
|
2123 }
|
|
2124
|
|
2125 void
|
|
2126 vars_of_xselect (void)
|
|
2127 {
|
|
2128 #ifdef CUT_BUFFER_SUPPORT
|
|
2129 cut_buffers_initialized = 0;
|
|
2130 Fprovide (intern ("cut-buffer"));
|
|
2131 #endif
|
|
2132
|
|
2133 reading_selection_reply = 0;
|
|
2134 reading_which_selection = 0;
|
|
2135 selection_reply_timed_out = 0;
|
|
2136 for_whom_the_bell_tolls = 0;
|
|
2137 prop_location_tick = 0;
|
|
2138
|
|
2139 Vselection_alist = Qnil;
|
|
2140 staticpro (&Vselection_alist);
|
|
2141
|
|
2142 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist /*
|
|
2143 An alist associating selection-types (such as STRING and TIMESTAMP) with
|
|
2144 functions. These functions will be called with three args: the name of the
|
|
2145 selection (typically PRIMARY, SECONDARY, or CLIPBOARD); a desired type to
|
|
2146 which the selection should be converted; and the local selection value
|
|
2147 (whatever had been passed to `x-own-selection'). These functions should
|
|
2148 return the value to send to the X server, which should be one of:
|
|
2149
|
|
2150 -- nil (the conversion could not be done)
|
|
2151 -- a cons of a symbol and any of the following values; the symbol
|
|
2152 explicitly specifies the type that will be sent.
|
70
|
2153 -- a string (If the type is not specified, then if Mule support exists,
|
|
2154 the string will be converted to Compound Text and sent in
|
|
2155 the 'COMPOUND_TEXT format; otherwise (no Mule support),
|
|
2156 the string will be left as-is and sent in the 'STRING
|
|
2157 format. If the type is specified, the string will be
|
|
2158 left as-is (or converted to binary format under Mule).
|
|
2159 In all cases, 8-bit data it sent.)
|
|
2160 -- a character (With Mule support, will be converted to Compound Text
|
|
2161 whether or not a type is specified. If a type is not
|
|
2162 specified, a type of 'STRING or 'COMPOUND_TEXT will be
|
|
2163 sent, as for strings.)
|
0
|
2164 -- the symbol 'NULL (Indicates that there is no meaningful return value.
|
|
2165 Empty 32-bit data with a type of 'NULL will be sent.)
|
|
2166 -- a symbol (Will be converted into an atom. If the type is not specified,
|
|
2167 a type of 'ATOM will be sent.)
|
|
2168 -- an integer (Will be converted into a 16-bit or 32-bit integer depending
|
|
2169 on the value. If the type is not specified, a type of
|
|
2170 'INTEGER will be sent.)
|
|
2171 -- a cons (HIGH . LOW) of integers (Will be converted into a 32-bit integer.
|
|
2172 If the type is not specified, a type of
|
|
2173 'INTEGER will be sent.)
|
|
2174 -- a vector of symbols (Will be converted into a list of atoms. If the type
|
|
2175 is not specified, a type of 'ATOM will be sent.)
|
|
2176 -- a vector of integers (Will be converted into a list of 16-bit integers.
|
|
2177 If the type is not specified, a type of 'INTEGER
|
|
2178 will be sent.)
|
|
2179 -- a vector of integers and/or conses (HIGH . LOW) of integers
|
|
2180 (Will be converted into a list of 16-bit integers.
|
|
2181 If the type is not specified, a type of 'INTEGER
|
|
2182 will be sent.)
|
|
2183 */ );
|
|
2184 Vselection_converter_alist = Qnil;
|
|
2185
|
|
2186 DEFVAR_LISP ("x-lost-selection-hooks", &Vx_lost_selection_hooks /*
|
|
2187 A function or functions to be called after the X server has notified us
|
|
2188 that we have lost the selection. The function(s) will be called with one
|
|
2189 argument, a symbol naming the selection (typically PRIMARY, SECONDARY, or
|
|
2190 CLIPBOARD).
|
|
2191 */ );
|
|
2192 Vx_lost_selection_hooks = Qunbound;
|
|
2193
|
|
2194 DEFVAR_LISP ("x-sent-selection-hooks", &Vx_sent_selection_hooks /*
|
|
2195 A function or functions to be called after we have responded to some
|
|
2196 other client's request for the value of a selection that we own. The
|
|
2197 function(s) will be called with four arguments:
|
|
2198 - the name of the selection (typically PRIMARY, SECONDARY, or CLIPBOARD);
|
|
2199 - the name of the selection-type which we were requested to convert the
|
|
2200 selection into before sending (for example, STRING or LENGTH);
|
|
2201 - and whether we successfully transmitted the selection.
|
|
2202 We might have failed (and declined the request) for any number of reasons,
|
|
2203 including being asked for a selection that we no longer own, or being asked
|
|
2204 to convert into a type that we don't know about or that is inappropriate.
|
|
2205 This hook doesn't let you change the behavior of emacs's selection replies,
|
|
2206 it merely informs you that they have happened.
|
|
2207 */ );
|
|
2208 Vx_sent_selection_hooks = Qunbound;
|
|
2209
|
|
2210 DEFVAR_INT ("x-selection-timeout", &x_selection_timeout /*
|
|
2211 If the selection owner doesn't reply in this many seconds, we give up.
|
|
2212 A value of 0 means wait as long as necessary. This is initialized from the
|
|
2213 \"*selectionTimeout\" resource (which is expressed in milliseconds).
|
|
2214 */ );
|
|
2215 x_selection_timeout = 0;
|
|
2216 }
|
|
2217
|
|
2218 void
|
|
2219 Xatoms_of_xselect (struct device *d)
|
|
2220 {
|
|
2221 #define ATOM(x) XInternAtom (DEVICE_X_DISPLAY (d), (x), False)
|
2
|
2222 #define ATOMIZE(x) DEVICE_XATOM_##x (d) = ATOM(#x)
|
0
|
2223
|
|
2224 /* Non-predefined atoms that we might end up using a lot */
|
2
|
2225 ATOMIZE (CLIPBOARD);
|
|
2226 ATOMIZE (TIMESTAMP);
|
|
2227 ATOMIZE (TEXT);
|
|
2228 ATOMIZE (DELETE);
|
|
2229 ATOMIZE (MULTIPLE);
|
|
2230 ATOMIZE (INCR);
|
|
2231 ATOMIZE (TARGETS);
|
|
2232 ATOMIZE (NULL);
|
|
2233 ATOMIZE (ATOM_PAIR);
|
|
2234 ATOMIZE (COMPOUND_TEXT);
|
|
2235 DEVICE_XATOM_EMACS_TMP (d) = ATOM ("_EMACS_TMP_");
|
0
|
2236 }
|