annotate src/=xselect.c.old @ 904:4a1ac370d57a

Initial revision
author Eric S. Raymond <esr@snark.thyrsus.com>
date Fri, 31 Jul 1992 22:24:03 +0000
parents 8d43bfe19803
children a411429c4140
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* X Selection processing for emacs
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 641
diff changeset
2 Copyright (C) 1990, 1992 Free Software Foundation.
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 641
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 #include "config.h"
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 #include "lisp.h"
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include "xterm.h"
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
23 #include "buffer.h"
771
538c0bcb418e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
24 #include "frame.h"
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #ifdef HAVE_X11
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 /* Macros for X Selections */
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
29 #define MAX_SELECTION(dpy) (((dpy)->max_request_size << 2) - 100)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
30 #define SELECTION_LENGTH(len,format) ((len) * ((format) >> 2))
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
32 /* The timestamp of the last input event we received from the X server. */
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
33 unsigned long last_event_timestamp;
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 641
diff changeset
34
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 /* t if a mouse button is depressed. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 extern Lisp_Object Vmouse_grabbed;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 /* When emacs became the PRIMARY selection owner. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 Time x_begin_selection_own;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
41 /* When emacs became the SECONDARY selection owner. */
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
42 Time x_begin_secondary_selection_own;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
43
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 /* When emacs became the CLIPBOARD selection owner. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 Time x_begin_clipboard_own;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 /* The value of the current CLIPBOARD selection. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 Lisp_Object Vx_clipboard_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 /* The value of the current PRIMARY selection. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 Lisp_Object Vx_selection_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
53 /* The value of the current SECONDARY selection. */
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
54 Lisp_Object Vx_secondary_selection_value;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
55
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
56 /* Types of selections we may make. Note that Qcut_buffer0 isn't really
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
57 a selection, but it acts like one for the sake of Fx_own_selection and
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
58 Fx_selection_value. */
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
59 Lisp_Object Qprimary, Qsecondary, Qclipboard, Qcut_buffer0;
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
60
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
61 /* Emacs' selection property identifiers. */
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 Atom Xatom_emacs_selection;
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
63 Atom Xatom_emacs_secondary_selection;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 /* Clipboard selection atom. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 Atom Xatom_clipboard_selection;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 /* Clipboard atom. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 Atom Xatom_clipboard;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 /* Atom for indicating incremental selection transfer. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 Atom Xatom_incremental;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 /* Atom for indicating multiple selection request list */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 Atom Xatom_multiple;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 /* Atom for what targets emacs handles. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 Atom Xatom_targets;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 /* Atom for indicating timstamp selection request */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 Atom Xatom_timestamp;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 /* Atom requesting we delete our selection. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 Atom Xatom_delete;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 /* Selection magic. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 Atom Xatom_insert_selection;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 /* Type of property for INSERT_SELECTION. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 Atom Xatom_pair;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 /* More selection magic. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 Atom Xatom_insert_property;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 /* Atom for indicating property type TEXT */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 Atom Xatom_text;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
98 /* Kinds of protocol things we may receive. */
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
99 Atom Xatom_wm_take_focus;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
100 Atom Xatom_wm_save_yourself;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
101 Atom Xatom_wm_delete_window;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
102
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
103 /* Communication with window managers. */
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
104 Atom Xatom_wm_protocols;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
105
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 /* These are to handle incremental selection transfer. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 Window incr_requestor;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 Atom incr_property;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 int incr_nbytes;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 unsigned char *incr_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 unsigned char *incr_ptr;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 /* SELECTION OWNER CODE */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
115
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
116 /* Request selection ownership if we do not already have it. */
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
117
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
118 static int
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
119 own_selection (selection_type, time)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
120 Atom selection_type;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
121 Time time;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
122 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
123 Window owner_window, selecting_window;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
124
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
125 if ((EQ (selection_type, Qprimary) && !NILP (Vx_selection_value))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
126 || ((EQ (selection_type, Qsecondary)) && !NILP (Vx_secondary_selection_value))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
127 || ((EQ (selection_type, Qclipboard)) && !NILP (Vx_clipboard_value)))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
128 return 1;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
129
771
538c0bcb418e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
130 selecting_window = selected_frame->display.x->window_desc;
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
131 XSetSelectionOwner (x_current_display, selection_type,
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
132 selecting_window, time);
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
133 owner_window = XGetSelectionOwner (x_current_display, selection_type);
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
134
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 641
diff changeset
135 if (owner_window != selecting_window)
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
136 return 0;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
137
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
138 return 1;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
139 }
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
140
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 /* Become the selection owner and make our data the selection value.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 If we are already the owner, merely change data and timestamp values.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 This avoids generating SelectionClear events for ourselves. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 DEFUN ("x-own-selection", Fx_own_selection, Sx_own_selection,
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
146 1, 2, "",
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
147 "Make STRING the selection value. Default is the primary selection,\n\
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
148 but optional second argument TYPE may specify secondary or clipboard.\n\
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
149 \n\
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
150 TYPE may also be cut-buffer0, indicating that Emacs should set the X\n\
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
151 cut buffer 0 to STRING. This is for compatibility with older X\n\
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
152 applications which still use the cut buffers; new applications should\n\
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
153 use X selections.")
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
154 (string, type)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
155 register Lisp_Object string, type;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 {
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
157 Atom selection_type;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
158 Lisp_Object val;
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
159 Time event_time = last_event_timestamp;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 CHECK_STRING (string, 0);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161
839
c32d6beb8aec *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 771
diff changeset
162 val = Qnil;
c32d6beb8aec *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 771
diff changeset
163
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
164 if (NILP (type) || EQ (type, Qprimary))
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 {
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
166 BLOCK_INPUT;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
167 if (own_selection (XA_PRIMARY, event_time))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
168 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
169 x_begin_selection_own = event_time;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
170 val = Vx_selection_value = string;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
171 }
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
172 UNBLOCK_INPUT;
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
173 }
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
174 else if (EQ (type, Qsecondary))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
175 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
176 BLOCK_INPUT;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
177 if (own_selection (XA_SECONDARY, event_time))
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 {
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
179 x_begin_secondary_selection_own = event_time;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
180 val = Vx_secondary_selection_value = string;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 }
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
182 UNBLOCK_INPUT;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 }
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
184 else if (EQ (type, Qclipboard))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
185 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
186 BLOCK_INPUT;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
187 if (own_selection (Xatom_clipboard, event_time))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
188 {
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
189 x_begin_clipboard_own = event_time;
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
190 val = Vx_clipboard_value = string;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
191 }
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
192 UNBLOCK_INPUT;
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
193 }
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
194 else if (EQ (type, Qcut_buffer0))
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
195 {
847
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
196 /* DECwindows and some other servers don't seem to like setting
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
197 properties to values larger than about 20k. For very large
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
198 values, they signal an error, but for intermediate values
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
199 they just seem to hang.
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
200
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
201 We could just truncate the request, but it's better to let
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
202 the user know that the strategy he/she's using isn't going to
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
203 work than to have it work partially, but incorrectly. */
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
204 BLOCK_INPUT;
847
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
205 if (XSTRING (string)->size > MAX_SELECTION (x_current_display))
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
206 {
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
207 XStoreBytes (x_current_display, (char *) 0, 0);
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
208 val = Qnil;
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
209 }
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
210 else
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
211 {
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
212 XStoreBytes (x_current_display,
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
213 (char *) XSTRING (string)->data,
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
214 XSTRING (string)->size);
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
215 val = string;
8d43bfe19803 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 839
diff changeset
216 }
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
217 UNBLOCK_INPUT;
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
218 }
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
219 else
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
220 error ("Invalid X selection type");
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
222 return val;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 /* Clear our selection ownership data, as some other client has
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 become the owner. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 void
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 x_disown_selection (old_owner, selection, changed_owner_time)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 Window *old_owner;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 Atom selection;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 Time changed_owner_time;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 {
771
538c0bcb418e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
234 struct frame *s = x_window_to_frame (old_owner);
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 if (s) /* We are the owner */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 if (selection == XA_PRIMARY)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 x_begin_selection_own = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 Vx_selection_value = Qnil;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 }
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
243 else if (selection == XA_SECONDARY)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
244 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
245 x_begin_secondary_selection_own = 0;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
246 Vx_secondary_selection_value = Qnil;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
247 }
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 else if (selection == Xatom_clipboard)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 x_begin_clipboard_own = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 Vx_clipboard_value = Qnil;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 abort (); /* Inconsistent state. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 int x_selection_alloc_error;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 int x_converting_selection;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 /* Reply to some client's request for our selection data. Data is
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
264 placed in a property supplied by the requesting window.
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 If the data exceeds the maximum amount the server can send,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 then prepare to send it incrementally, and reply to the client with
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 the total size of the data.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 But first, check for all the other crufty stuff we could get. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 void
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 x_answer_selection_request (event)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 XSelectionRequestEvent event;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 Time emacs_own_time;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 Lisp_Object selection_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 XSelectionEvent evt;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 int format = 8; /* We have only byte sized (text) data. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 evt.type = SelectionNotify; /* Construct reply event */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 evt.display = event.display;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 evt.requestor = event.requestor;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 evt.selection = event.selection;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 evt.time = event.time;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 evt.target = event.target;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 if (event.selection == XA_PRIMARY)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 emacs_own_time = x_begin_selection_own;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 selection_value = Vx_selection_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 }
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
293 else if (event.selection == XA_SECONDARY)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
294 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
295 emacs_own_time = x_begin_secondary_selection_own;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
296 selection_value = Vx_secondary_selection_value;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
297 }
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 else if (event.selection == Xatom_clipboard)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 emacs_own_time = x_begin_clipboard_own;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 selection_value = Vx_clipboard_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 if (event.time != CurrentTime
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 && event.time < emacs_own_time)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 evt.property = None;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 if (event.property == None) /* obsolete client */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 evt.property = event.target;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 evt.property = event.property;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 if (event.target == Xatom_targets) /* Send List of target atoms */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 else if (event.target == Xatom_multiple) /* Recvd list: <target, prop> */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 Atom type;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 int return_format;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 unsigned long items, bytes_left;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 unsigned char *data;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 int result, i;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
328 if (event.property == 0 /* 0 == NILP */
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 || event.property == None)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 return;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 result = XGetWindowProperty (event.display, event.requestor,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 event.property, 0L, 10000000L,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 True, Xatom_pair, &type, &return_format,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 &items, &bytes_left, &data);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 if (result == Success && type == Xatom_pair)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 for (i = items; i > 0; i--)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 /* Convert each element of the list. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 (void) XSendEvent (x_current_display, evt.requestor, False,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 0L, (XEvent *) &evt);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 return;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 else if (event.target == Xatom_timestamp) /* Send ownership timestamp */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 if (! emacs_own_time)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 format = 32;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 XChangeProperty (evt.display, evt.requestor, evt.property,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 evt.target, format, PropModeReplace,
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
355 (unsigned char *) &emacs_own_time, 1);
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 return;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 else if (event.target == Xatom_delete) /* Delete our selection. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 if (EQ (Qnil, selection_value))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 x_disown_selection (event.owner, event.selection, event.time);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
365 /* Now return property of type NILP, length 0. */
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 XChangeProperty (event.display, event.requestor, event.property,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 0, format, PropModeReplace, (unsigned char *) 0, 0);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 return;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 else if (event.target == Xatom_insert_selection)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 Atom type;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 int return_format;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 unsigned long items, bytes_left;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 unsigned char *data;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 int result = XGetWindowProperty (event.display, event.requestor,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 event.property, 0L, 10000000L,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 True, Xatom_pair, &type, &return_format,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 &items, &bytes_left, &data);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 if (result == Success && type == Xatom_pair)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 /* Convert the first atom to (a selection) to the target
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 indicated by the second atom. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 else if (event.target == Xatom_insert_property)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 Atom type;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 int return_format;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 unsigned long items, bytes_left;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 unsigned char *data;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 int result = XGetWindowProperty (event.display, event.requestor,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 event.property, 0L, 10000000L,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 True, XA_STRING, &type, &return_format,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 &items, &bytes_left, &data);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 if (result == Success && type == XA_STRING && return_format == 8)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 if (event.selection == Xatom_emacs_selection)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 Vx_selection_value = make_string (data);
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
401 else if (event.selection == Xatom_emacs_secondary_selection)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
402 Vx_secondary_selection_value = make_string (data);
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 else if (event.selection == Xatom_clipboard_selection)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 Vx_clipboard_value = make_string (data);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 return;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 else if ((event.target == Xatom_text
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 || event.target == XA_STRING))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 int size = XSTRING (selection_value)->size;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 unsigned char *data = XSTRING (selection_value)->data;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 if (EQ (Qnil, selection_value))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 /* Place data on requestor window's property. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 if (SELECTION_LENGTH (size, format)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 <= MAX_SELECTION (x_current_display))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 x_converting_selection = 1;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 XChangeProperty (evt.display, evt.requestor, evt.property,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 evt.target, format, PropModeReplace,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 data, size);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 if (x_selection_alloc_error)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 x_selection_alloc_error = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 x_converting_selection = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 else /* Send incrementally */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 evt.target = Xatom_incremental;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 incr_requestor = evt.requestor;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 incr_property = evt.property;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 x_converting_selection = 1;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 /* Need to handle Alloc errors on these requests. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 XChangeProperty (evt.display, incr_requestor, incr_property,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 Xatom_incremental, 32,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 PropModeReplace,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 (unsigned char *) &size, 1);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 if (x_selection_alloc_error)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 x_selection_alloc_error = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 x_converting_selection = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 /* Now abort the send. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 incr_nbytes = size;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 incr_value = data;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 incr_ptr = data;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 /* Ask for notification when requestor deletes property. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 XSelectInput (x_current_display, incr_requestor, PropertyChangeMask);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 /* If we're sending incrementally, perhaps block here
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 until all sent? */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 evt.property = None;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 /* Don't do this if there was an Alloc error: abort the transfer
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 by sending None. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 (void) XSendEvent (x_current_display, evt.requestor, False,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 0L, (XEvent *) &evt);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 /* Send an increment of selection data in response to a PropertyNotify event.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 The increment is placed in a property on the requestor's window.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 When the requestor has processed the increment, it deletes the property,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 which sends us another PropertyNotify event.
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 When there is no more data to send, we send a zero-length increment. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 void
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 x_send_incremental (event)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 XPropertyEvent event;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 if (incr_requestor
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 && incr_requestor == event.window
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 && incr_property == event.atom
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 && event.state == PropertyDelete)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 int format = 8;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 int length = MAX_SELECTION (x_current_display);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 int bytes_left = (incr_nbytes - (incr_ptr - incr_value));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 if (length > bytes_left) /* Also sends 0 len when finished. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 length = bytes_left;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 XChangeProperty (x_current_display, incr_requestor,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 incr_property, XA_STRING, format,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 PropModeAppend, incr_ptr, length);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 if (x_selection_alloc_error)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 x_selection_alloc_error = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 x_converting_selection = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 /* Abandon the transmission. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 if (length > 0)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 incr_ptr += length;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 { /* Everything's sent */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 XSelectInput (x_current_display, incr_requestor, 0L);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 incr_requestor = (Window) 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 incr_property = (Atom) 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 incr_nbytes = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 incr_value = (unsigned char *) 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 incr_ptr = (unsigned char *) 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 x_converting_selection = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 /* SELECTION REQUESTOR CODE */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 /* Predicate function used to match a requested event. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 Bool
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 XCheckSelectionEvent (dpy, event, window)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 Display *dpy;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 XEvent *event;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 char *window;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 if (event->type == SelectionNotify)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 if (event->xselection.requestor == (Window) window)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 return True;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 return False;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
539 /* Request a selection value from its owner. This will block until
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
540 all the data is arrived. */
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
542 static Lisp_Object
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
543 get_selection_value (type)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
544 Atom type;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 XEvent event;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 Lisp_Object val;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 Time requestor_time; /* Timestamp of selection request. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 Window requestor_window;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 BLOCK_INPUT;
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
552 requestor_time = last_event_timestamp;
771
538c0bcb418e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
553 requestor_window = selected_frame->display.x->window_desc;
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
554 XConvertSelection (x_current_display, type, XA_STRING,
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 Xatom_emacs_selection, requestor_window, requestor_time);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 XIfEvent (x_current_display,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 &event,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 XCheckSelectionEvent,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 (char *) requestor_window);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 val = x_selection_arrival (&event, requestor_window, requestor_time);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 UNBLOCK_INPUT;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 return val;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
566 /* Request a selection value from the owner. If we are the owner,
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
567 simply return our selection value. If we are not the owner, this
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
568 will block until all of the data has arrived. */
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
570 DEFUN ("x-selection-value", Fx_selection_value, Sx_selection_value,
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
571 0, 1, "",
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
572 "Return the value of one of the selections. Default is the primary\n\
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
573 selection, but optional argument TYPE may specify secondary or clipboard.")
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
574 (type)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
575 register Lisp_Object type;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 {
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
577 Atom selection_type;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
578
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
579 if (NILP (type) || EQ (type, Qprimary))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
580 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
581 if (!NILP (Vx_selection_value))
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 641
diff changeset
582 return Vx_selection_value;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
584 return get_selection_value (XA_PRIMARY);
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
585 }
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
586 else if (EQ (type, Qsecondary))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
587 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
588 if (!NILP (Vx_secondary_selection_value))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
589 return Vx_secondary_selection_value;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
591 return get_selection_value (XA_SECONDARY);
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
592 }
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
593 else if (EQ (type, Qclipboard))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
594 {
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
595 if (!NILP (Vx_clipboard_value))
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
596 return Vx_clipboard_value;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
598 return get_selection_value (Xatom_clipboard);
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
599 }
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
600 else if (EQ (type, Qcut_buffer0))
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
601 {
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
602 char *data;
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
603 int size;
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
604 Lisp_Object string;
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
605
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
606 BLOCK_INPUT;
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
607 data = XFetchBytes (x_current_display, &size);
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
608 if (data == 0)
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
609 string = Qnil;
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
610 else
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
611 string = make_string (data, size);
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
612 UNBLOCK_INPUT;
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
613
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
614 return string;
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
615 }
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
616 else
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
617 error ("Invalid X selection type");
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
619
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 Lisp_Object
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 x_selection_arrival (event, requestor_window, requestor_time)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 register XSelectionEvent *event;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623 Window requestor_window;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624 Time requestor_time;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
625 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626 int result;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627 Atom type, selection;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
628 int format;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
629 unsigned long items;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
630 unsigned long bytes_left;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
631 unsigned char *data = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632 int offset = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
633
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
634 if (event->selection == XA_PRIMARY)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635 selection = Xatom_emacs_selection;
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
636 else if (event->selection == XA_SECONDARY)
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
637 selection = Xatom_emacs_secondary_selection;
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 else if (event->selection == Xatom_clipboard)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639 selection = Xatom_clipboard_selection;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 abort ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
642
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
643 if (event->requestor == requestor_window
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
644 && event->time == requestor_time
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
645 && event->property != None)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 if (event->target != Xatom_incremental)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
647 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
648 unsigned char *return_string =
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649 (unsigned char *) alloca (MAX_SELECTION (x_current_display));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651 do
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
652 {
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
653 result = XGetWindowProperty (x_current_display, requestor_window,
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654 event->property, 0L,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
655 10000000L, True, XA_STRING,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 &type, &format, &items,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657 &bytes_left, &data);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 if (result == Success && type == XA_STRING && format == 8
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659 && offset < MAX_SELECTION (x_current_display))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
661 bcopy (data, return_string + offset, items);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662 offset += items;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
663 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
664 XFree ((char *) data);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
665 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 while (bytes_left);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
667
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
668 return make_string (return_string, offset);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
669 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670 else /* Prepare incremental transfer. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 unsigned char *increment_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 unsigned char *increment_ptr;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 int total_size;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675 int *increment_nbytes = 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677 result = XGetWindowProperty (x_current_display, requestor_window,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 selection, 0L, 10000000L, False,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
679 event->property, &type, &format,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680 &items, &bytes_left,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681 (unsigned char **) &increment_nbytes);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682 if (result == Success)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 XPropertyEvent property_event;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 total_size = *increment_nbytes;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 increment_value = (unsigned char *) alloca (total_size);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 increment_ptr = increment_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 XDeleteProperty (x_current_display, event->requestor,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 event->property);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692 XFlush (x_current_display);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 XFree ((char *) increment_nbytes);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
695 do
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 { /* NOTE: this blocks. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
697 XWindowEvent (x_current_display, requestor_window,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
698 PropertyChangeMask,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
699 (XEvent *) &property_event);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
700
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 if (property_event.atom == selection
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
702 && property_event.state == PropertyNewValue)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
703 do
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
704 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
705 result = XGetWindowProperty (x_current_display,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
706 requestor_window,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
707 selection, 0L,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
708 10000000L, True,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 AnyPropertyType,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710 &type, &format,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
711 &items, &bytes_left,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712 &data);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713 if (result == Success && type == XA_STRING
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 && format == 8)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 bcopy (data, increment_ptr, items);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717 increment_ptr += items;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
719 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
720 while (bytes_left);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
721
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
723 while (increment_ptr < (increment_value + total_size));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
725 return make_string (increment_value,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726 (increment_ptr - increment_value));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730 return Qnil;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
731 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 void
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 syms_of_xselect ()
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 DEFVAR_LISP ("x-selection-value", &Vx_selection_value,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737 "The value of emacs' last cut-string.");
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
738 Vx_selection_value = Qnil;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
739
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
740 DEFVAR_LISP ("x-secondary-selection-value", &Vx_secondary_selection_value,
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
741 "The value of emacs' last secondary cut-string.");
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
742 Vx_secondary_selection_value = Qnil;
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
743
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
744 DEFVAR_LISP ("x-clipboard-value", &Vx_clipboard_value,
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
745 "The string emacs last sent to the clipboard.");
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
746 Vx_clipboard_value = Qnil;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
747
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
748 Qprimary = intern ("primary");
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
749 staticpro (&Qprimary);
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
750 Qsecondary = intern ("secondary");
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
751 staticpro (&Qsecondary);
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
752 Qclipboard = intern ("clipboard");
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
753 staticpro (&Qclipboard);
708
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
754 Qcut_buffer0 = intern ("cut-buffer0");
030fb4635335 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 648
diff changeset
755 staticpro (&Qcut_buffer0);
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
756
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757 defsubr (&Sx_own_selection);
641
78a0b78aa6de *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 485
diff changeset
758 defsubr (&Sx_selection_value);
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
759 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
760 #endif /* X11 */