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