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