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