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