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