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