1 /* X Selection processing for Emacs.
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* Rewritten by jwz */
24 #include <stdio.h> /* termhooks.h needs this */
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
35 #include "xterm.h" /* for all of the X includes */
36 #include "dispextern.h" /* frame.h seems to want this */
37 #include "frame.h" /* Need this to get the X window of selected_frame */
38 #include "blockinput.h"
41 #include "termhooks.h"
44 #include <X11/Xproto.h>
48 static Lisp_Object
x_atom_to_symbol (Display
*dpy
, Atom atom
);
49 static Atom
symbol_to_x_atom (struct x_display_info
*, Display
*,
51 static void x_own_selection (Lisp_Object
, Lisp_Object
);
52 static Lisp_Object
x_get_local_selection (Lisp_Object
, Lisp_Object
, int);
53 static void x_decline_selection_request (struct input_event
*);
54 static Lisp_Object
x_selection_request_lisp_error (Lisp_Object
);
55 static Lisp_Object
queue_selection_requests_unwind (Lisp_Object
);
56 static Lisp_Object
some_frame_on_display (struct x_display_info
*);
57 static Lisp_Object
x_catch_errors_unwind (Lisp_Object
);
58 static void x_reply_selection_request (struct input_event
*, int,
59 unsigned char *, int, Atom
);
60 static int waiting_for_other_props_on_window (Display
*, Window
);
61 static struct prop_location
*expect_property_change (Display
*, Window
,
63 static void unexpect_property_change (struct prop_location
*);
64 static Lisp_Object
wait_for_property_change_unwind (Lisp_Object
);
65 static void wait_for_property_change (struct prop_location
*);
66 static Lisp_Object
x_get_foreign_selection (Lisp_Object
,
69 static void x_get_window_property (Display
*, Window
, Atom
,
70 unsigned char **, int *,
71 Atom
*, int *, unsigned long *, int);
72 static void receive_incremental_selection (Display
*, Window
, Atom
,
73 Lisp_Object
, unsigned,
74 unsigned char **, int *,
75 Atom
*, int *, unsigned long *);
76 static Lisp_Object
x_get_window_property_as_lisp_data (Display
*,
79 static Lisp_Object
selection_data_to_lisp_data (Display
*, unsigned char *,
81 static void lisp_data_to_selection_data (Display
*, Lisp_Object
,
82 unsigned char **, Atom
*,
83 unsigned *, int *, int *);
84 static Lisp_Object
clean_local_selection_data (Lisp_Object
);
85 static void initialize_cut_buffers (Display
*, Window
);
88 /* Printing traces to stderr. */
90 #ifdef TRACE_SELECTION
92 fprintf (stderr, "%d: " fmt "\n", getpid ())
93 #define TRACE1(fmt, a0) \
94 fprintf (stderr, "%d: " fmt "\n", getpid (), a0)
95 #define TRACE2(fmt, a0, a1) \
96 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1)
97 #define TRACE3(fmt, a0, a1, a2) \
98 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1, a2)
100 #define TRACE0(fmt) (void) 0
101 #define TRACE1(fmt, a0) (void) 0
102 #define TRACE2(fmt, a0, a1) (void) 0
103 #define TRACE3(fmt, a0, a1) (void) 0
107 #define CUT_BUFFER_SUPPORT
109 Lisp_Object QPRIMARY
, QSECONDARY
, QSTRING
, QINTEGER
, QCLIPBOARD
, QTIMESTAMP
,
110 QTEXT
, QDELETE
, QMULTIPLE
, QINCR
, QEMACS_TMP
, QTARGETS
, QATOM
, QNULL
,
113 Lisp_Object QCOMPOUND_TEXT
; /* This is a type of selection. */
114 Lisp_Object QUTF8_STRING
; /* This is a type of selection. */
116 Lisp_Object Qcompound_text_with_extensions
;
118 #ifdef CUT_BUFFER_SUPPORT
119 Lisp_Object QCUT_BUFFER0
, QCUT_BUFFER1
, QCUT_BUFFER2
, QCUT_BUFFER3
,
120 QCUT_BUFFER4
, QCUT_BUFFER5
, QCUT_BUFFER6
, QCUT_BUFFER7
;
123 static Lisp_Object Vx_lost_selection_functions
;
124 static Lisp_Object Vx_sent_selection_functions
;
125 static Lisp_Object Qforeign_selection
;
127 /* If this is a smaller number than the max-request-size of the display,
128 emacs will use INCR selection transfer when the selection is larger
129 than this. The max-request-size is usually around 64k, so if you want
130 emacs to use incremental selection transfers when the selection is
131 smaller than that, set this. I added this mostly for debugging the
132 incremental transfer stuff, but it might improve server performance. */
133 #define MAX_SELECTION_QUANTUM 0xFFFFFF
135 #define SELECTION_QUANTUM(dpy) ((XMaxRequestSize(dpy) << 2) - 100)
137 /* The timestamp of the last input event Emacs received from the X server. */
138 /* Defined in keyboard.c. */
139 extern unsigned long last_event_timestamp
;
141 /* This is an association list whose elements are of the form
142 ( SELECTION-NAME SELECTION-VALUE SELECTION-TIMESTAMP FRAME)
143 SELECTION-NAME is a lisp symbol, whose name is the name of an X Atom.
144 SELECTION-VALUE is the value that emacs owns for that selection.
145 It may be any kind of Lisp object.
146 SELECTION-TIMESTAMP is the time at which emacs began owning this selection,
147 as a cons of two 16-bit numbers (making a 32 bit time.)
148 FRAME is the frame for which we made the selection.
149 If there is an entry in this alist, then it can be assumed that Emacs owns
151 The only (eq) parts of this list that are visible from Lisp are the
153 static Lisp_Object Vselection_alist
;
155 /* This is an alist whose CARs are selection-types (whose names are the same
156 as the names of X Atoms) and whose CDRs are the names of Lisp functions to
157 call to convert the given Emacs selection value to a string representing
158 the given selection type. This is for Lisp-level extension of the emacs
159 selection handling. */
160 static Lisp_Object Vselection_converter_alist
;
162 /* If the selection owner takes too long to reply to a selection request,
163 we give up on it. This is in milliseconds (0 = no timeout.) */
164 static EMACS_INT x_selection_timeout
;
168 /* Define a queue to save up SELECTION_REQUEST_EVENT events for later
171 struct selection_event_queue
173 struct input_event event
;
174 struct selection_event_queue
*next
;
177 static struct selection_event_queue
*selection_queue
;
179 /* Nonzero means queue up SELECTION_REQUEST_EVENT events. */
181 static int x_queue_selection_requests
;
183 /* Queue up an SELECTION_REQUEST_EVENT *EVENT, to be processed later. */
186 x_queue_event (struct input_event
*event
)
188 struct selection_event_queue
*queue_tmp
;
190 /* Don't queue repeated requests.
191 This only happens for large requests which uses the incremental protocol. */
192 for (queue_tmp
= selection_queue
; queue_tmp
; queue_tmp
= queue_tmp
->next
)
194 if (!memcmp (&queue_tmp
->event
, event
, sizeof (*event
)))
196 TRACE1 ("DECLINE DUP SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
197 x_decline_selection_request (event
);
203 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
205 if (queue_tmp
!= NULL
)
207 TRACE1 ("QUEUE SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
208 queue_tmp
->event
= *event
;
209 queue_tmp
->next
= selection_queue
;
210 selection_queue
= queue_tmp
;
214 /* Start queuing SELECTION_REQUEST_EVENT events. */
217 x_start_queuing_selection_requests (void)
219 if (x_queue_selection_requests
)
222 x_queue_selection_requests
++;
223 TRACE1 ("x_start_queuing_selection_requests %d", x_queue_selection_requests
);
226 /* Stop queuing SELECTION_REQUEST_EVENT events. */
229 x_stop_queuing_selection_requests (void)
231 TRACE1 ("x_stop_queuing_selection_requests %d", x_queue_selection_requests
);
232 --x_queue_selection_requests
;
234 /* Take all the queued events and put them back
235 so that they get processed afresh. */
237 while (selection_queue
!= NULL
)
239 struct selection_event_queue
*queue_tmp
= selection_queue
;
240 TRACE1 ("RESTORE SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
241 kbd_buffer_unget_event (&queue_tmp
->event
);
242 selection_queue
= queue_tmp
->next
;
243 xfree ((char *)queue_tmp
);
248 /* This converts a Lisp symbol to a server Atom, avoiding a server
249 roundtrip whenever possible. */
252 symbol_to_x_atom (struct x_display_info
*dpyinfo
, Display
*display
, Lisp_Object sym
)
255 if (NILP (sym
)) return 0;
256 if (EQ (sym
, QPRIMARY
)) return XA_PRIMARY
;
257 if (EQ (sym
, QSECONDARY
)) return XA_SECONDARY
;
258 if (EQ (sym
, QSTRING
)) return XA_STRING
;
259 if (EQ (sym
, QINTEGER
)) return XA_INTEGER
;
260 if (EQ (sym
, QATOM
)) return XA_ATOM
;
261 if (EQ (sym
, QCLIPBOARD
)) return dpyinfo
->Xatom_CLIPBOARD
;
262 if (EQ (sym
, QTIMESTAMP
)) return dpyinfo
->Xatom_TIMESTAMP
;
263 if (EQ (sym
, QTEXT
)) return dpyinfo
->Xatom_TEXT
;
264 if (EQ (sym
, QCOMPOUND_TEXT
)) return dpyinfo
->Xatom_COMPOUND_TEXT
;
265 if (EQ (sym
, QUTF8_STRING
)) return dpyinfo
->Xatom_UTF8_STRING
;
266 if (EQ (sym
, QDELETE
)) return dpyinfo
->Xatom_DELETE
;
267 if (EQ (sym
, QMULTIPLE
)) return dpyinfo
->Xatom_MULTIPLE
;
268 if (EQ (sym
, QINCR
)) return dpyinfo
->Xatom_INCR
;
269 if (EQ (sym
, QEMACS_TMP
)) return dpyinfo
->Xatom_EMACS_TMP
;
270 if (EQ (sym
, QTARGETS
)) return dpyinfo
->Xatom_TARGETS
;
271 if (EQ (sym
, QNULL
)) return dpyinfo
->Xatom_NULL
;
272 #ifdef CUT_BUFFER_SUPPORT
273 if (EQ (sym
, QCUT_BUFFER0
)) return XA_CUT_BUFFER0
;
274 if (EQ (sym
, QCUT_BUFFER1
)) return XA_CUT_BUFFER1
;
275 if (EQ (sym
, QCUT_BUFFER2
)) return XA_CUT_BUFFER2
;
276 if (EQ (sym
, QCUT_BUFFER3
)) return XA_CUT_BUFFER3
;
277 if (EQ (sym
, QCUT_BUFFER4
)) return XA_CUT_BUFFER4
;
278 if (EQ (sym
, QCUT_BUFFER5
)) return XA_CUT_BUFFER5
;
279 if (EQ (sym
, QCUT_BUFFER6
)) return XA_CUT_BUFFER6
;
280 if (EQ (sym
, QCUT_BUFFER7
)) return XA_CUT_BUFFER7
;
282 if (!SYMBOLP (sym
)) abort ();
284 TRACE1 (" XInternAtom %s", (char *) SDATA (SYMBOL_NAME (sym
)));
286 val
= XInternAtom (display
, (char *) SDATA (SYMBOL_NAME (sym
)), False
);
292 /* This converts a server Atom to a Lisp symbol, avoiding server roundtrips
293 and calls to intern whenever possible. */
296 x_atom_to_symbol (Display
*dpy
, Atom atom
)
298 struct x_display_info
*dpyinfo
;
317 #ifdef CUT_BUFFER_SUPPORT
337 dpyinfo
= x_display_info_for_display (dpy
);
338 if (atom
== dpyinfo
->Xatom_CLIPBOARD
)
340 if (atom
== dpyinfo
->Xatom_TIMESTAMP
)
342 if (atom
== dpyinfo
->Xatom_TEXT
)
344 if (atom
== dpyinfo
->Xatom_COMPOUND_TEXT
)
345 return QCOMPOUND_TEXT
;
346 if (atom
== dpyinfo
->Xatom_UTF8_STRING
)
348 if (atom
== dpyinfo
->Xatom_DELETE
)
350 if (atom
== dpyinfo
->Xatom_MULTIPLE
)
352 if (atom
== dpyinfo
->Xatom_INCR
)
354 if (atom
== dpyinfo
->Xatom_EMACS_TMP
)
356 if (atom
== dpyinfo
->Xatom_TARGETS
)
358 if (atom
== dpyinfo
->Xatom_NULL
)
362 str
= XGetAtomName (dpy
, atom
);
364 TRACE1 ("XGetAtomName --> %s", str
);
365 if (! str
) return Qnil
;
368 /* This was allocated by Xlib, so use XFree. */
374 /* Do protocol to assert ourself as a selection owner.
375 Update the Vselection_alist so that we can reply to later requests for
379 x_own_selection (Lisp_Object selection_name
, Lisp_Object selection_value
)
381 struct frame
*sf
= SELECTED_FRAME ();
382 Window selecting_window
;
384 Time time
= last_event_timestamp
;
386 struct x_display_info
*dpyinfo
;
388 if (! FRAME_X_P (sf
))
391 selecting_window
= FRAME_X_WINDOW (sf
);
392 display
= FRAME_X_DISPLAY (sf
);
393 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
395 CHECK_SYMBOL (selection_name
);
396 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection_name
);
399 x_catch_errors (display
);
400 XSetSelectionOwner (display
, selection_atom
, selecting_window
, time
);
401 x_check_errors (display
, "Can't set selection: %s");
405 /* Now update the local cache */
407 Lisp_Object selection_time
;
408 Lisp_Object selection_data
;
409 Lisp_Object prev_value
;
411 selection_time
= long_to_cons ((unsigned long) time
);
412 selection_data
= Fcons (selection_name
,
413 Fcons (selection_value
,
414 Fcons (selection_time
,
415 Fcons (selected_frame
, Qnil
))));
416 prev_value
= assq_no_quit (selection_name
, Vselection_alist
);
418 Vselection_alist
= Fcons (selection_data
, Vselection_alist
);
420 /* If we already owned the selection, remove the old selection data.
421 Perhaps we should destructively modify it instead.
422 Don't use Fdelq as that may QUIT. */
423 if (!NILP (prev_value
))
425 Lisp_Object rest
; /* we know it's not the CAR, so it's easy. */
426 for (rest
= Vselection_alist
; CONSP (rest
); rest
= XCDR (rest
))
427 if (EQ (prev_value
, Fcar (XCDR (rest
))))
429 XSETCDR (rest
, Fcdr (XCDR (rest
)));
436 /* Given a selection-name and desired type, look up our local copy of
437 the selection value and convert it to the type.
438 The value is nil or a string.
439 This function is used both for remote requests (LOCAL_REQUEST is zero)
440 and for local x-get-selection-internal (LOCAL_REQUEST is nonzero).
442 This calls random Lisp code, and may signal or gc. */
445 x_get_local_selection (Lisp_Object selection_symbol
, Lisp_Object target_type
, int local_request
)
447 Lisp_Object local_value
;
448 Lisp_Object handler_fn
, value
, type
, check
;
451 local_value
= assq_no_quit (selection_symbol
, Vselection_alist
);
453 if (NILP (local_value
)) return Qnil
;
455 /* TIMESTAMP and MULTIPLE are special cases 'cause that's easiest. */
456 if (EQ (target_type
, QTIMESTAMP
))
459 value
= XCAR (XCDR (XCDR (local_value
)));
462 else if (EQ (target_type
, QDELETE
))
465 Fx_disown_selection_internal
467 XCAR (XCDR (XCDR (local_value
))));
472 #if 0 /* #### MULTIPLE doesn't work yet */
473 else if (CONSP (target_type
)
474 && XCAR (target_type
) == QMULTIPLE
)
479 pairs
= XCDR (target_type
);
480 size
= XVECTOR (pairs
)->size
;
481 /* If the target is MULTIPLE, then target_type looks like
482 (MULTIPLE . [[SELECTION1 TARGET1] [SELECTION2 TARGET2] ... ])
483 We modify the second element of each pair in the vector and
484 return it as [[SELECTION1 <value1>] [SELECTION2 <value2>] ... ]
486 for (i
= 0; i
< size
; i
++)
489 pair
= XVECTOR (pairs
)->contents
[i
];
490 XVECTOR (pair
)->contents
[1]
491 = x_get_local_selection (XVECTOR (pair
)->contents
[0],
492 XVECTOR (pair
)->contents
[1],
500 /* Don't allow a quit within the converter.
501 When the user types C-g, he would be surprised
502 if by luck it came during a converter. */
503 count
= SPECPDL_INDEX ();
504 specbind (Qinhibit_quit
, Qt
);
506 CHECK_SYMBOL (target_type
);
507 handler_fn
= Fcdr (Fassq (target_type
, Vselection_converter_alist
));
508 /* gcpro is not needed here since nothing but HANDLER_FN
509 is live, and that ought to be a symbol. */
511 if (!NILP (handler_fn
))
512 value
= call3 (handler_fn
,
513 selection_symbol
, (local_request
? Qnil
: target_type
),
514 XCAR (XCDR (local_value
)));
517 unbind_to (count
, Qnil
);
520 /* Make sure this value is of a type that we could transmit
521 to another X client. */
525 && SYMBOLP (XCAR (value
)))
527 check
= XCDR (value
);
535 /* Check for a value that cons_to_long could handle. */
536 else if (CONSP (check
)
537 && INTEGERP (XCAR (check
))
538 && (INTEGERP (XCDR (check
))
540 (CONSP (XCDR (check
))
541 && INTEGERP (XCAR (XCDR (check
)))
542 && NILP (XCDR (XCDR (check
))))))
545 signal_error ("Invalid data returned by selection-conversion function",
546 list2 (handler_fn
, value
));
549 /* Subroutines of x_reply_selection_request. */
551 /* Send a SelectionNotify event to the requestor with property=None,
552 meaning we were unable to do what they wanted. */
555 x_decline_selection_request (struct input_event
*event
)
557 XSelectionEvent reply
;
559 reply
.type
= SelectionNotify
;
560 reply
.display
= SELECTION_EVENT_DISPLAY (event
);
561 reply
.requestor
= SELECTION_EVENT_REQUESTOR (event
);
562 reply
.selection
= SELECTION_EVENT_SELECTION (event
);
563 reply
.time
= SELECTION_EVENT_TIME (event
);
564 reply
.target
= SELECTION_EVENT_TARGET (event
);
565 reply
.property
= None
;
567 /* The reason for the error may be that the receiver has
568 died in the meantime. Handle that case. */
570 x_catch_errors (reply
.display
);
571 XSendEvent (reply
.display
, reply
.requestor
, False
, 0L, (XEvent
*) &reply
);
572 XFlush (reply
.display
);
577 /* This is the selection request currently being processed.
578 It is set to zero when the request is fully processed. */
579 static struct input_event
*x_selection_current_request
;
581 /* Display info in x_selection_request. */
583 static struct x_display_info
*selection_request_dpyinfo
;
585 /* Used as an unwind-protect clause so that, if a selection-converter signals
586 an error, we tell the requester that we were unable to do what they wanted
587 before we throw to top-level or go into the debugger or whatever. */
590 x_selection_request_lisp_error (Lisp_Object ignore
)
592 if (x_selection_current_request
!= 0
593 && selection_request_dpyinfo
->display
)
594 x_decline_selection_request (x_selection_current_request
);
599 x_catch_errors_unwind (Lisp_Object dummy
)
608 /* This stuff is so that INCR selections are reentrant (that is, so we can
609 be servicing multiple INCR selection requests simultaneously.) I haven't
610 actually tested that yet. */
612 /* Keep a list of the property changes that are awaited. */
622 struct prop_location
*next
;
625 static struct prop_location
*expect_property_change (Display
*display
, Window window
, Atom property
, int state
);
626 static void wait_for_property_change (struct prop_location
*location
);
627 static void unexpect_property_change (struct prop_location
*location
);
628 static int waiting_for_other_props_on_window (Display
*display
, Window window
);
630 static int prop_location_identifier
;
632 static Lisp_Object property_change_reply
;
634 static struct prop_location
*property_change_reply_object
;
636 static struct prop_location
*property_change_wait_list
;
639 queue_selection_requests_unwind (Lisp_Object tem
)
641 x_stop_queuing_selection_requests ();
645 /* Return some frame whose display info is DPYINFO.
646 Return nil if there is none. */
649 some_frame_on_display (struct x_display_info
*dpyinfo
)
651 Lisp_Object list
, frame
;
653 FOR_EACH_FRAME (list
, frame
)
655 if (FRAME_X_P (XFRAME (frame
))
656 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
663 /* Send the reply to a selection request event EVENT.
664 TYPE is the type of selection data requested.
665 DATA and SIZE describe the data to send, already converted.
666 FORMAT is the unit-size (in bits) of the data to be transmitted. */
668 #ifdef TRACE_SELECTION
669 static int x_reply_selection_request_cnt
;
670 #endif /* TRACE_SELECTION */
673 x_reply_selection_request (struct input_event
*event
, int format
, unsigned char *data
, int size
, Atom type
)
675 XSelectionEvent reply
;
676 Display
*display
= SELECTION_EVENT_DISPLAY (event
);
677 Window window
= SELECTION_EVENT_REQUESTOR (event
);
679 int format_bytes
= format
/8;
680 int max_bytes
= SELECTION_QUANTUM (display
);
681 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
682 int count
= SPECPDL_INDEX ();
684 if (max_bytes
> MAX_SELECTION_QUANTUM
)
685 max_bytes
= MAX_SELECTION_QUANTUM
;
687 reply
.type
= SelectionNotify
;
688 reply
.display
= display
;
689 reply
.requestor
= window
;
690 reply
.selection
= SELECTION_EVENT_SELECTION (event
);
691 reply
.time
= SELECTION_EVENT_TIME (event
);
692 reply
.target
= SELECTION_EVENT_TARGET (event
);
693 reply
.property
= SELECTION_EVENT_PROPERTY (event
);
694 if (reply
.property
== None
)
695 reply
.property
= reply
.target
;
698 /* The protected block contains wait_for_property_change, which can
699 run random lisp code (process handlers) or signal. Therefore, we
700 put the x_uncatch_errors call in an unwind. */
701 record_unwind_protect (x_catch_errors_unwind
, Qnil
);
702 x_catch_errors (display
);
704 #ifdef TRACE_SELECTION
706 char *sel
= XGetAtomName (display
, reply
.selection
);
707 char *tgt
= XGetAtomName (display
, reply
.target
);
708 TRACE3 ("%s, target %s (%d)", sel
, tgt
, ++x_reply_selection_request_cnt
);
709 if (sel
) XFree (sel
);
710 if (tgt
) XFree (tgt
);
712 #endif /* TRACE_SELECTION */
714 /* Store the data on the requested property.
715 If the selection is large, only store the first N bytes of it.
717 bytes_remaining
= size
* format_bytes
;
718 if (bytes_remaining
<= max_bytes
)
720 /* Send all the data at once, with minimal handshaking. */
721 TRACE1 ("Sending all %d bytes", bytes_remaining
);
722 XChangeProperty (display
, window
, reply
.property
, type
, format
,
723 PropModeReplace
, data
, size
);
724 /* At this point, the selection was successfully stored; ack it. */
725 XSendEvent (display
, window
, False
, 0L, (XEvent
*) &reply
);
729 /* Send an INCR selection. */
730 struct prop_location
*wait_object
;
734 frame
= some_frame_on_display (dpyinfo
);
736 /* If the display no longer has frames, we can't expect
737 to get many more selection requests from it, so don't
738 bother trying to queue them. */
741 x_start_queuing_selection_requests ();
743 record_unwind_protect (queue_selection_requests_unwind
,
747 if (x_window_to_frame (dpyinfo
, window
)) /* #### debug */
748 error ("Attempt to transfer an INCR to ourself!");
750 TRACE2 ("Start sending %d bytes incrementally (%s)",
751 bytes_remaining
, XGetAtomName (display
, reply
.property
));
752 wait_object
= expect_property_change (display
, window
, reply
.property
,
755 TRACE1 ("Set %s to number of bytes to send",
756 XGetAtomName (display
, reply
.property
));
758 /* XChangeProperty expects an array of long even if long is more than
762 value
[0] = bytes_remaining
;
763 XChangeProperty (display
, window
, reply
.property
, dpyinfo
->Xatom_INCR
,
765 (unsigned char *) value
, 1);
768 XSelectInput (display
, window
, PropertyChangeMask
);
770 /* Tell 'em the INCR data is there... */
771 TRACE0 ("Send SelectionNotify event");
772 XSendEvent (display
, window
, False
, 0L, (XEvent
*) &reply
);
775 had_errors
= x_had_errors_p (display
);
778 /* First, wait for the requester to ack by deleting the property.
779 This can run random lisp code (process handlers) or signal. */
782 TRACE1 ("Waiting for ACK (deletion of %s)",
783 XGetAtomName (display
, reply
.property
));
784 wait_for_property_change (wait_object
);
787 unexpect_property_change (wait_object
);
790 while (bytes_remaining
)
792 int i
= ((bytes_remaining
< max_bytes
)
794 : max_bytes
) / format_bytes
;
799 = expect_property_change (display
, window
, reply
.property
,
802 TRACE1 ("Sending increment of %d elements", i
);
803 TRACE1 ("Set %s to increment data",
804 XGetAtomName (display
, reply
.property
));
806 /* Append the next chunk of data to the property. */
807 XChangeProperty (display
, window
, reply
.property
, type
, format
,
808 PropModeAppend
, data
, i
);
809 bytes_remaining
-= i
* format_bytes
;
811 data
+= i
* sizeof (long);
813 data
+= i
* format_bytes
;
815 had_errors
= x_had_errors_p (display
);
821 /* Now wait for the requester to ack this chunk by deleting the
822 property. This can run random lisp code or signal. */
823 TRACE1 ("Waiting for increment ACK (deletion of %s)",
824 XGetAtomName (display
, reply
.property
));
825 wait_for_property_change (wait_object
);
828 /* Now write a zero-length chunk to the property to tell the
829 requester that we're done. */
831 if (! waiting_for_other_props_on_window (display
, window
))
832 XSelectInput (display
, window
, 0L);
834 TRACE1 ("Set %s to a 0-length chunk to indicate EOF",
835 XGetAtomName (display
, reply
.property
));
836 XChangeProperty (display
, window
, reply
.property
, type
, format
,
837 PropModeReplace
, data
, 0);
838 TRACE0 ("Done sending incrementally");
841 /* rms, 2003-01-03: I think I have fixed this bug. */
842 /* The window we're communicating with may have been deleted
843 in the meantime (that's a real situation from a bug report).
844 In this case, there may be events in the event queue still
845 refering to the deleted window, and we'll get a BadWindow error
846 in XTread_socket when processing the events. I don't have
847 an idea how to fix that. gerd, 2001-01-98. */
848 /* 2004-09-10: XSync and UNBLOCK so that possible protocol errors are
849 delivered before uncatch errors. */
850 XSync (display
, False
);
853 /* GTK queues events in addition to the queue in Xlib. So we
854 UNBLOCK to enter the event loop and get possible errors delivered,
855 and then BLOCK again because x_uncatch_errors requires it. */
857 /* This calls x_uncatch_errors. */
858 unbind_to (count
, Qnil
);
862 /* Handle a SelectionRequest event EVENT.
863 This is called from keyboard.c when such an event is found in the queue. */
866 x_handle_selection_request (struct input_event
*event
)
868 struct gcpro gcpro1
, gcpro2
, gcpro3
;
869 Lisp_Object local_selection_data
;
870 Lisp_Object selection_symbol
;
871 Lisp_Object target_symbol
;
872 Lisp_Object converted_selection
;
873 Time local_selection_time
;
874 Lisp_Object successful_p
;
876 struct x_display_info
*dpyinfo
877 = x_display_info_for_display (SELECTION_EVENT_DISPLAY (event
));
879 TRACE2 ("x_handle_selection_request, from=0x%08lx time=%lu",
880 (unsigned long) SELECTION_EVENT_REQUESTOR (event
),
881 (unsigned long) SELECTION_EVENT_TIME (event
));
883 local_selection_data
= Qnil
;
884 target_symbol
= Qnil
;
885 converted_selection
= Qnil
;
888 GCPRO3 (local_selection_data
, converted_selection
, target_symbol
);
890 selection_symbol
= x_atom_to_symbol (SELECTION_EVENT_DISPLAY (event
),
891 SELECTION_EVENT_SELECTION (event
));
893 local_selection_data
= assq_no_quit (selection_symbol
, Vselection_alist
);
895 if (NILP (local_selection_data
))
897 /* Someone asked for the selection, but we don't have it any more.
899 x_decline_selection_request (event
);
903 local_selection_time
= (Time
)
904 cons_to_long (XCAR (XCDR (XCDR (local_selection_data
))));
906 if (SELECTION_EVENT_TIME (event
) != CurrentTime
907 && local_selection_time
> SELECTION_EVENT_TIME (event
))
909 /* Someone asked for the selection, and we have one, but not the one
912 x_decline_selection_request (event
);
916 x_selection_current_request
= event
;
917 count
= SPECPDL_INDEX ();
918 selection_request_dpyinfo
= dpyinfo
;
919 record_unwind_protect (x_selection_request_lisp_error
, Qnil
);
921 target_symbol
= x_atom_to_symbol (SELECTION_EVENT_DISPLAY (event
),
922 SELECTION_EVENT_TARGET (event
));
924 #if 0 /* #### MULTIPLE doesn't work yet */
925 if (EQ (target_symbol
, QMULTIPLE
))
926 target_symbol
= fetch_multiple_target (event
);
929 /* Convert lisp objects back into binary data */
932 = x_get_local_selection (selection_symbol
, target_symbol
, 0);
934 if (! NILP (converted_selection
))
942 if (CONSP (converted_selection
) && NILP (XCDR (converted_selection
)))
944 x_decline_selection_request (event
);
948 lisp_data_to_selection_data (SELECTION_EVENT_DISPLAY (event
),
950 &data
, &type
, &size
, &format
, &nofree
);
952 x_reply_selection_request (event
, format
, data
, size
, type
);
955 /* Indicate we have successfully processed this event. */
956 x_selection_current_request
= 0;
958 /* Use xfree, not XFree, because lisp_data_to_selection_data
959 calls xmalloc itself. */
965 unbind_to (count
, Qnil
);
969 /* Let random lisp code notice that the selection has been asked for. */
972 rest
= Vx_sent_selection_functions
;
973 if (!EQ (rest
, Qunbound
))
974 for (; CONSP (rest
); rest
= Fcdr (rest
))
975 call3 (Fcar (rest
), selection_symbol
, target_symbol
, successful_p
);
981 /* Handle a SelectionClear event EVENT, which indicates that some
982 client cleared out our previously asserted selection.
983 This is called from keyboard.c when such an event is found in the queue. */
986 x_handle_selection_clear (struct input_event
*event
)
988 Display
*display
= SELECTION_EVENT_DISPLAY (event
);
989 Atom selection
= SELECTION_EVENT_SELECTION (event
);
990 Time changed_owner_time
= SELECTION_EVENT_TIME (event
);
992 Lisp_Object selection_symbol
, local_selection_data
;
993 Time local_selection_time
;
994 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
995 struct x_display_info
*t_dpyinfo
;
997 TRACE0 ("x_handle_selection_clear");
999 /* If the new selection owner is also Emacs,
1000 don't clear the new selection. */
1002 /* Check each display on the same terminal,
1003 to see if this Emacs job now owns the selection
1004 through that display. */
1005 for (t_dpyinfo
= x_display_list
; t_dpyinfo
; t_dpyinfo
= t_dpyinfo
->next
)
1006 if (t_dpyinfo
->terminal
->kboard
== dpyinfo
->terminal
->kboard
)
1009 = XGetSelectionOwner (t_dpyinfo
->display
, selection
);
1010 if (x_window_to_frame (t_dpyinfo
, owner_window
) != 0)
1018 selection_symbol
= x_atom_to_symbol (display
, selection
);
1020 local_selection_data
= assq_no_quit (selection_symbol
, Vselection_alist
);
1022 /* Well, we already believe that we don't own it, so that's just fine. */
1023 if (NILP (local_selection_data
)) return;
1025 local_selection_time
= (Time
)
1026 cons_to_long (XCAR (XCDR (XCDR (local_selection_data
))));
1028 /* This SelectionClear is for a selection that we no longer own, so we can
1029 disregard it. (That is, we have reasserted the selection since this
1030 request was generated.) */
1032 if (changed_owner_time
!= CurrentTime
1033 && local_selection_time
> changed_owner_time
)
1036 /* Otherwise, we're really honest and truly being told to drop it.
1037 Don't use Fdelq as that may QUIT;. */
1039 if (EQ (local_selection_data
, Fcar (Vselection_alist
)))
1040 Vselection_alist
= Fcdr (Vselection_alist
);
1044 for (rest
= Vselection_alist
; CONSP (rest
); rest
= XCDR (rest
))
1045 if (EQ (local_selection_data
, Fcar (XCDR (rest
))))
1047 XSETCDR (rest
, Fcdr (XCDR (rest
)));
1052 /* Let random lisp code notice that the selection has been stolen. */
1056 rest
= Vx_lost_selection_functions
;
1057 if (!EQ (rest
, Qunbound
))
1059 for (; CONSP (rest
); rest
= Fcdr (rest
))
1060 call1 (Fcar (rest
), selection_symbol
);
1061 prepare_menu_bars ();
1062 redisplay_preserve_echo_area (20);
1068 x_handle_selection_event (struct input_event
*event
)
1070 TRACE0 ("x_handle_selection_event");
1072 if (event
->kind
== SELECTION_REQUEST_EVENT
)
1074 if (x_queue_selection_requests
)
1075 x_queue_event (event
);
1077 x_handle_selection_request (event
);
1080 x_handle_selection_clear (event
);
1084 /* Clear all selections that were made from frame F.
1085 We do this when about to delete a frame. */
1088 x_clear_frame_selections (FRAME_PTR f
)
1093 XSETFRAME (frame
, f
);
1095 /* Otherwise, we're really honest and truly being told to drop it.
1096 Don't use Fdelq as that may QUIT;. */
1098 /* Delete elements from the beginning of Vselection_alist. */
1099 while (!NILP (Vselection_alist
)
1100 && EQ (frame
, Fcar (Fcdr (Fcdr (Fcdr (Fcar (Vselection_alist
)))))))
1102 /* Let random Lisp code notice that the selection has been stolen. */
1103 Lisp_Object hooks
, selection_symbol
;
1105 hooks
= Vx_lost_selection_functions
;
1106 selection_symbol
= Fcar (Fcar (Vselection_alist
));
1108 if (!EQ (hooks
, Qunbound
))
1110 for (; CONSP (hooks
); hooks
= Fcdr (hooks
))
1111 call1 (Fcar (hooks
), selection_symbol
);
1112 #if 0 /* This can crash when deleting a frame
1113 from x_connection_closed. Anyway, it seems unnecessary;
1114 something else should cause a redisplay. */
1115 redisplay_preserve_echo_area (21);
1119 Vselection_alist
= Fcdr (Vselection_alist
);
1122 /* Delete elements after the beginning of Vselection_alist. */
1123 for (rest
= Vselection_alist
; CONSP (rest
); rest
= XCDR (rest
))
1124 if (EQ (frame
, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest
))))))))
1126 /* Let random Lisp code notice that the selection has been stolen. */
1127 Lisp_Object hooks
, selection_symbol
;
1129 hooks
= Vx_lost_selection_functions
;
1130 selection_symbol
= Fcar (Fcar (XCDR (rest
)));
1132 if (!EQ (hooks
, Qunbound
))
1134 for (; CONSP (hooks
); hooks
= Fcdr (hooks
))
1135 call1 (Fcar (hooks
), selection_symbol
);
1136 #if 0 /* See above */
1137 redisplay_preserve_echo_area (22);
1140 XSETCDR (rest
, Fcdr (XCDR (rest
)));
1145 /* Nonzero if any properties for DISPLAY and WINDOW
1146 are on the list of what we are waiting for. */
1149 waiting_for_other_props_on_window (Display
*display
, Window window
)
1151 struct prop_location
*rest
= property_change_wait_list
;
1153 if (rest
->display
== display
&& rest
->window
== window
)
1160 /* Add an entry to the list of property changes we are waiting for.
1161 DISPLAY, WINDOW, PROPERTY, STATE describe what we will wait for.
1162 The return value is a number that uniquely identifies
1163 this awaited property change. */
1165 static struct prop_location
*
1166 expect_property_change (Display
*display
, Window window
, Atom property
, int state
)
1168 struct prop_location
*pl
= (struct prop_location
*) xmalloc (sizeof *pl
);
1169 pl
->identifier
= ++prop_location_identifier
;
1170 pl
->display
= display
;
1171 pl
->window
= window
;
1172 pl
->property
= property
;
1173 pl
->desired_state
= state
;
1174 pl
->next
= property_change_wait_list
;
1176 property_change_wait_list
= pl
;
1180 /* Delete an entry from the list of property changes we are waiting for.
1181 IDENTIFIER is the number that uniquely identifies the entry. */
1184 unexpect_property_change (struct prop_location
*location
)
1186 struct prop_location
*prev
= 0, *rest
= property_change_wait_list
;
1189 if (rest
== location
)
1192 prev
->next
= rest
->next
;
1194 property_change_wait_list
= rest
->next
;
1203 /* Remove the property change expectation element for IDENTIFIER. */
1206 wait_for_property_change_unwind (Lisp_Object loc
)
1208 struct prop_location
*location
= XSAVE_VALUE (loc
)->pointer
;
1210 unexpect_property_change (location
);
1211 if (location
== property_change_reply_object
)
1212 property_change_reply_object
= 0;
1216 /* Actually wait for a property change.
1217 IDENTIFIER should be the value that expect_property_change returned. */
1220 wait_for_property_change (struct prop_location
*location
)
1223 int count
= SPECPDL_INDEX ();
1225 if (property_change_reply_object
)
1228 /* Make sure to do unexpect_property_change if we quit or err. */
1229 record_unwind_protect (wait_for_property_change_unwind
,
1230 make_save_value (location
, 0));
1232 XSETCAR (property_change_reply
, Qnil
);
1233 property_change_reply_object
= location
;
1235 /* If the event we are waiting for arrives beyond here, it will set
1236 property_change_reply, because property_change_reply_object says so. */
1237 if (! location
->arrived
)
1239 secs
= x_selection_timeout
/ 1000;
1240 usecs
= (x_selection_timeout
% 1000) * 1000;
1241 TRACE2 (" Waiting %d secs, %d usecs", secs
, usecs
);
1242 wait_reading_process_output (secs
, usecs
, 0, 0,
1243 property_change_reply
, NULL
, 0);
1245 if (NILP (XCAR (property_change_reply
)))
1247 TRACE0 (" Timed out");
1248 error ("Timed out waiting for property-notify event");
1252 unbind_to (count
, Qnil
);
1255 /* Called from XTread_socket in response to a PropertyNotify event. */
1258 x_handle_property_notify (XPropertyEvent
*event
)
1260 struct prop_location
*prev
= 0, *rest
= property_change_wait_list
;
1265 && rest
->property
== event
->atom
1266 && rest
->window
== event
->window
1267 && rest
->display
== event
->display
1268 && rest
->desired_state
== event
->state
)
1270 TRACE2 ("Expected %s of property %s",
1271 (event
->state
== PropertyDelete
? "deletion" : "change"),
1272 XGetAtomName (event
->display
, event
->atom
));
1276 /* If this is the one wait_for_property_change is waiting for,
1277 tell it to wake up. */
1278 if (rest
== property_change_reply_object
)
1279 XSETCAR (property_change_reply
, Qt
);
1291 #if 0 /* #### MULTIPLE doesn't work yet */
1294 fetch_multiple_target (event
)
1295 XSelectionRequestEvent
*event
;
1297 Display
*display
= event
->display
;
1298 Window window
= event
->requestor
;
1299 Atom target
= event
->target
;
1300 Atom selection_atom
= event
->selection
;
1305 x_get_window_property_as_lisp_data (display
, window
, target
,
1306 QMULTIPLE
, selection_atom
));
1310 copy_multiple_data (obj
)
1317 return Fcons (XCAR (obj
), copy_multiple_data (XCDR (obj
)));
1320 vec
= Fmake_vector (size
= XVECTOR (obj
)->size
, Qnil
);
1321 for (i
= 0; i
< size
; i
++)
1323 Lisp_Object vec2
= XVECTOR (obj
)->contents
[i
];
1324 CHECK_VECTOR (vec2
);
1325 if (XVECTOR (vec2
)->size
!= 2)
1326 /* ??? Confusing error message */
1327 signal_error ("Vectors must be of length 2", vec2
);
1328 XVECTOR (vec
)->contents
[i
] = Fmake_vector (2, Qnil
);
1329 XVECTOR (XVECTOR (vec
)->contents
[i
])->contents
[0]
1330 = XVECTOR (vec2
)->contents
[0];
1331 XVECTOR (XVECTOR (vec
)->contents
[i
])->contents
[1]
1332 = XVECTOR (vec2
)->contents
[1];
1340 /* Variables for communication with x_handle_selection_notify. */
1341 static Atom reading_which_selection
;
1342 static Lisp_Object reading_selection_reply
;
1343 static Window reading_selection_window
;
1345 /* Do protocol to read selection-data from the server.
1346 Converts this to Lisp data and returns it. */
1349 x_get_foreign_selection (Lisp_Object selection_symbol
, Lisp_Object target_type
, Lisp_Object time_stamp
)
1351 struct frame
*sf
= SELECTED_FRAME ();
1352 Window requestor_window
;
1354 struct x_display_info
*dpyinfo
;
1355 Time requestor_time
= last_event_timestamp
;
1356 Atom target_property
;
1357 Atom selection_atom
;
1360 int count
= SPECPDL_INDEX ();
1363 if (! FRAME_X_P (sf
))
1366 requestor_window
= FRAME_X_WINDOW (sf
);
1367 display
= FRAME_X_DISPLAY (sf
);
1368 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
1369 target_property
= dpyinfo
->Xatom_EMACS_TMP
;
1370 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection_symbol
);
1372 if (CONSP (target_type
))
1373 type_atom
= symbol_to_x_atom (dpyinfo
, display
, XCAR (target_type
));
1375 type_atom
= symbol_to_x_atom (dpyinfo
, display
, target_type
);
1377 if (! NILP (time_stamp
))
1379 if (CONSP (time_stamp
))
1380 requestor_time
= (Time
) cons_to_long (time_stamp
);
1381 else if (INTEGERP (time_stamp
))
1382 requestor_time
= (Time
) XUINT (time_stamp
);
1383 else if (FLOATP (time_stamp
))
1384 requestor_time
= (Time
) XFLOAT_DATA (time_stamp
);
1386 error ("TIME_STAMP must be cons or number");
1391 /* The protected block contains wait_reading_process_output, which
1392 can run random lisp code (process handlers) or signal.
1393 Therefore, we put the x_uncatch_errors call in an unwind. */
1394 record_unwind_protect (x_catch_errors_unwind
, Qnil
);
1395 x_catch_errors (display
);
1397 TRACE2 ("Get selection %s, type %s",
1398 XGetAtomName (display
, type_atom
),
1399 XGetAtomName (display
, target_property
));
1401 XConvertSelection (display
, selection_atom
, type_atom
, target_property
,
1402 requestor_window
, requestor_time
);
1405 /* Prepare to block until the reply has been read. */
1406 reading_selection_window
= requestor_window
;
1407 reading_which_selection
= selection_atom
;
1408 XSETCAR (reading_selection_reply
, Qnil
);
1410 frame
= some_frame_on_display (dpyinfo
);
1412 /* If the display no longer has frames, we can't expect
1413 to get many more selection requests from it, so don't
1414 bother trying to queue them. */
1417 x_start_queuing_selection_requests ();
1419 record_unwind_protect (queue_selection_requests_unwind
,
1424 /* This allows quits. Also, don't wait forever. */
1425 secs
= x_selection_timeout
/ 1000;
1426 usecs
= (x_selection_timeout
% 1000) * 1000;
1427 TRACE1 (" Start waiting %d secs for SelectionNotify", secs
);
1428 wait_reading_process_output (secs
, usecs
, 0, 0,
1429 reading_selection_reply
, NULL
, 0);
1430 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply
)));
1433 if (x_had_errors_p (display
))
1434 error ("Cannot get selection");
1435 /* This calls x_uncatch_errors. */
1436 unbind_to (count
, Qnil
);
1439 if (NILP (XCAR (reading_selection_reply
)))
1440 error ("Timed out waiting for reply from selection owner");
1441 if (EQ (XCAR (reading_selection_reply
), Qlambda
))
1444 /* Otherwise, the selection is waiting for us on the requested property. */
1446 x_get_window_property_as_lisp_data (display
, requestor_window
,
1447 target_property
, target_type
,
1451 /* Subroutines of x_get_window_property_as_lisp_data */
1453 /* Use xfree, not XFree, to free the data obtained with this function. */
1456 x_get_window_property (display
, window
, property
, data_ret
, bytes_ret
,
1457 actual_type_ret
, actual_format_ret
, actual_size_ret
,
1462 unsigned char **data_ret
;
1464 Atom
*actual_type_ret
;
1465 int *actual_format_ret
;
1466 unsigned long *actual_size_ret
;
1470 unsigned long bytes_remaining
;
1472 unsigned char *tmp_data
= 0;
1474 int buffer_size
= SELECTION_QUANTUM (display
);
1476 if (buffer_size
> MAX_SELECTION_QUANTUM
)
1477 buffer_size
= MAX_SELECTION_QUANTUM
;
1481 /* First probe the thing to find out how big it is. */
1482 result
= XGetWindowProperty (display
, window
, property
,
1483 0L, 0L, False
, AnyPropertyType
,
1484 actual_type_ret
, actual_format_ret
,
1486 &bytes_remaining
, &tmp_data
);
1487 if (result
!= Success
)
1495 /* This was allocated by Xlib, so use XFree. */
1496 XFree ((char *) tmp_data
);
1498 if (*actual_type_ret
== None
|| *actual_format_ret
== 0)
1504 total_size
= bytes_remaining
+ 1;
1505 *data_ret
= (unsigned char *) xmalloc (total_size
);
1507 /* Now read, until we've gotten it all. */
1508 while (bytes_remaining
)
1510 #ifdef TRACE_SELECTION
1511 int last
= bytes_remaining
;
1514 = XGetWindowProperty (display
, window
, property
,
1515 (long)offset
/4, (long)buffer_size
/4,
1518 actual_type_ret
, actual_format_ret
,
1519 actual_size_ret
, &bytes_remaining
, &tmp_data
);
1521 TRACE2 ("Read %ld bytes from property %s",
1522 last
- bytes_remaining
,
1523 XGetAtomName (display
, property
));
1525 /* If this doesn't return Success at this point, it means that
1526 some clod deleted the selection while we were in the midst of
1527 reading it. Deal with that, I guess.... */
1528 if (result
!= Success
)
1531 /* The man page for XGetWindowProperty says:
1532 "If the returned format is 32, the returned data is represented
1533 as a long array and should be cast to that type to obtain the
1535 This applies even if long is more than 32 bits, the X library
1536 converts from 32 bit elements received from the X server to long
1537 and passes the long array to us. Thus, for that case memcpy can not
1538 be used. We convert to a 32 bit type here, because so much code
1541 The bytes and offsets passed to XGetWindowProperty refers to the
1542 property and those are indeed in 32 bit quantities if format is 32. */
1544 if (*actual_format_ret
== 32 && *actual_format_ret
< BITS_PER_LONG
)
1547 int *idata
= (int *) ((*data_ret
) + offset
);
1548 long *ldata
= (long *) tmp_data
;
1550 for (i
= 0; i
< *actual_size_ret
; ++i
)
1552 idata
[i
]= (int) ldata
[i
];
1558 *actual_size_ret
*= *actual_format_ret
/ 8;
1559 memcpy ((*data_ret
) + offset
, tmp_data
, *actual_size_ret
);
1560 offset
+= *actual_size_ret
;
1563 /* This was allocated by Xlib, so use XFree. */
1564 XFree ((char *) tmp_data
);
1569 *bytes_ret
= offset
;
1572 /* Use xfree, not XFree, to free the data obtained with this function. */
1575 receive_incremental_selection (display
, window
, property
, target_type
,
1576 min_size_bytes
, data_ret
, size_bytes_ret
,
1577 type_ret
, format_ret
, size_ret
)
1581 Lisp_Object target_type
; /* for error messages only */
1582 unsigned int min_size_bytes
;
1583 unsigned char **data_ret
;
1584 int *size_bytes_ret
;
1586 unsigned long *size_ret
;
1590 struct prop_location
*wait_object
;
1591 *size_bytes_ret
= min_size_bytes
;
1592 *data_ret
= (unsigned char *) xmalloc (*size_bytes_ret
);
1594 TRACE1 ("Read %d bytes incrementally", min_size_bytes
);
1596 /* At this point, we have read an INCR property.
1597 Delete the property to ack it.
1598 (But first, prepare to receive the next event in this handshake.)
1600 Now, we must loop, waiting for the sending window to put a value on
1601 that property, then reading the property, then deleting it to ack.
1602 We are done when the sender places a property of length 0.
1605 XSelectInput (display
, window
, STANDARD_EVENT_SET
| PropertyChangeMask
);
1606 TRACE1 (" Delete property %s",
1607 SDATA (SYMBOL_NAME (x_atom_to_symbol (display
, property
))));
1608 XDeleteProperty (display
, window
, property
);
1609 TRACE1 (" Expect new value of property %s",
1610 SDATA (SYMBOL_NAME (x_atom_to_symbol (display
, property
))));
1611 wait_object
= expect_property_change (display
, window
, property
,
1618 unsigned char *tmp_data
;
1621 TRACE0 (" Wait for property change");
1622 wait_for_property_change (wait_object
);
1624 /* expect it again immediately, because x_get_window_property may
1625 .. no it won't, I don't get it.
1626 .. Ok, I get it now, the Xt code that implements INCR is broken. */
1627 TRACE0 (" Get property value");
1628 x_get_window_property (display
, window
, property
,
1629 &tmp_data
, &tmp_size_bytes
,
1630 type_ret
, format_ret
, size_ret
, 1);
1632 TRACE1 (" Read increment of %d bytes", tmp_size_bytes
);
1634 if (tmp_size_bytes
== 0) /* we're done */
1636 TRACE0 ("Done reading incrementally");
1638 if (! waiting_for_other_props_on_window (display
, window
))
1639 XSelectInput (display
, window
, STANDARD_EVENT_SET
);
1640 /* Use xfree, not XFree, because x_get_window_property
1641 calls xmalloc itself. */
1647 TRACE1 (" ACK by deleting property %s",
1648 XGetAtomName (display
, property
));
1649 XDeleteProperty (display
, window
, property
);
1650 wait_object
= expect_property_change (display
, window
, property
,
1655 if (*size_bytes_ret
< offset
+ tmp_size_bytes
)
1657 *size_bytes_ret
= offset
+ tmp_size_bytes
;
1658 *data_ret
= (unsigned char *) xrealloc (*data_ret
, *size_bytes_ret
);
1661 memcpy ((*data_ret
) + offset
, tmp_data
, tmp_size_bytes
);
1662 offset
+= tmp_size_bytes
;
1664 /* Use xfree, not XFree, because x_get_window_property
1665 calls xmalloc itself. */
1671 /* Once a requested selection is "ready" (we got a SelectionNotify event),
1672 fetch value from property PROPERTY of X window WINDOW on display DISPLAY.
1673 TARGET_TYPE and SELECTION_ATOM are used in error message if this fails. */
1676 x_get_window_property_as_lisp_data (display
, window
, property
, target_type
,
1681 Lisp_Object target_type
; /* for error messages only */
1682 Atom selection_atom
; /* for error messages only */
1686 unsigned long actual_size
;
1687 unsigned char *data
= 0;
1690 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1692 TRACE0 ("Reading selection data");
1694 x_get_window_property (display
, window
, property
, &data
, &bytes
,
1695 &actual_type
, &actual_format
, &actual_size
, 1);
1698 int there_is_a_selection_owner
;
1700 there_is_a_selection_owner
1701 = XGetSelectionOwner (display
, selection_atom
);
1703 if (there_is_a_selection_owner
)
1704 signal_error ("Selection owner couldn't convert",
1706 ? list2 (target_type
,
1707 x_atom_to_symbol (display
, actual_type
))
1710 signal_error ("No selection",
1711 x_atom_to_symbol (display
, selection_atom
));
1714 if (actual_type
== dpyinfo
->Xatom_INCR
)
1716 /* That wasn't really the data, just the beginning. */
1718 unsigned int min_size_bytes
= * ((unsigned int *) data
);
1720 /* Use xfree, not XFree, because x_get_window_property
1721 calls xmalloc itself. */
1722 xfree ((char *) data
);
1724 receive_incremental_selection (display
, window
, property
, target_type
,
1725 min_size_bytes
, &data
, &bytes
,
1726 &actual_type
, &actual_format
,
1731 TRACE1 (" Delete property %s", XGetAtomName (display
, property
));
1732 XDeleteProperty (display
, window
, property
);
1736 /* It's been read. Now convert it to a lisp object in some semi-rational
1738 val
= selection_data_to_lisp_data (display
, data
, bytes
,
1739 actual_type
, actual_format
);
1741 /* Use xfree, not XFree, because x_get_window_property
1742 calls xmalloc itself. */
1743 xfree ((char *) data
);
1747 /* These functions convert from the selection data read from the server into
1748 something that we can use from Lisp, and vice versa.
1750 Type: Format: Size: Lisp Type:
1751 ----- ------- ----- -----------
1754 ATOM 32 > 1 Vector of Symbols
1756 * 16 > 1 Vector of Integers
1757 * 32 1 if <=16 bits: Integer
1758 if > 16 bits: Cons of top16, bot16
1759 * 32 > 1 Vector of the above
1761 When converting a Lisp number to C, it is assumed to be of format 16 if
1762 it is an integer, and of format 32 if it is a cons of two integers.
1764 When converting a vector of numbers from Lisp to C, it is assumed to be
1765 of format 16 if every element in the vector is an integer, and is assumed
1766 to be of format 32 if any element is a cons of two integers.
1768 When converting an object to C, it may be of the form (SYMBOL . <data>)
1769 where SYMBOL is what we should claim that the type is. Format and
1770 representation are as above.
1772 Important: When format is 32, data should contain an array of int,
1773 not an array of long as the X library returns. This makes a difference
1774 when sizeof(long) != sizeof(int). */
1779 selection_data_to_lisp_data (Display
*display
, unsigned char *data
, int size
, Atom type
, int format
)
1781 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1783 if (type
== dpyinfo
->Xatom_NULL
)
1786 /* Convert any 8-bit data to a string, for compactness. */
1787 else if (format
== 8)
1789 Lisp_Object str
, lispy_type
;
1791 str
= make_unibyte_string ((char *) data
, size
);
1792 /* Indicate that this string is from foreign selection by a text
1793 property `foreign-selection' so that the caller of
1794 x-get-selection-internal (usually x-get-selection) can know
1795 that the string must be decode. */
1796 if (type
== dpyinfo
->Xatom_COMPOUND_TEXT
)
1797 lispy_type
= QCOMPOUND_TEXT
;
1798 else if (type
== dpyinfo
->Xatom_UTF8_STRING
)
1799 lispy_type
= QUTF8_STRING
;
1801 lispy_type
= QSTRING
;
1802 Fput_text_property (make_number (0), make_number (size
),
1803 Qforeign_selection
, lispy_type
, str
);
1806 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to
1807 a vector of symbols.
1809 else if (type
== XA_ATOM
)
1812 /* On a 64 bit machine sizeof(Atom) == sizeof(long) == 8.
1813 But the callers of these function has made sure the data for
1814 format == 32 is an array of int. Thus, use int instead
1816 int *idata
= (int *) data
;
1818 if (size
== sizeof (int))
1819 return x_atom_to_symbol (display
, (Atom
) idata
[0]);
1822 Lisp_Object v
= Fmake_vector (make_number (size
/ sizeof (int)),
1824 for (i
= 0; i
< size
/ sizeof (int); i
++)
1825 Faset (v
, make_number (i
),
1826 x_atom_to_symbol (display
, (Atom
) idata
[i
]));
1831 /* Convert a single 16-bit number or a small 32-bit number to a Lisp_Int.
1832 If the number is 32 bits and won't fit in a Lisp_Int,
1833 convert it to a cons of integers, 16 bits in each half.
1835 else if (format
== 32 && size
== sizeof (int))
1836 return long_to_cons (((unsigned int *) data
) [0]);
1837 else if (format
== 16 && size
== sizeof (short))
1838 return make_number ((int) (((unsigned short *) data
) [0]));
1840 /* Convert any other kind of data to a vector of numbers, represented
1841 as above (as an integer, or a cons of two 16 bit integers.)
1843 else if (format
== 16)
1847 v
= Fmake_vector (make_number (size
/ 2), make_number (0));
1848 for (i
= 0; i
< size
/ 2; i
++)
1850 int j
= (int) ((unsigned short *) data
) [i
];
1851 Faset (v
, make_number (i
), make_number (j
));
1858 Lisp_Object v
= Fmake_vector (make_number (size
/ 4), make_number (0));
1859 for (i
= 0; i
< size
/ 4; i
++)
1861 unsigned int j
= ((unsigned int *) data
) [i
];
1862 Faset (v
, make_number (i
), long_to_cons (j
));
1869 /* Use xfree, not XFree, to free the data obtained with this function. */
1872 lisp_data_to_selection_data (display
, obj
,
1873 data_ret
, type_ret
, size_ret
,
1874 format_ret
, nofree_ret
)
1877 unsigned char **data_ret
;
1879 unsigned int *size_ret
;
1883 Lisp_Object type
= Qnil
;
1884 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1888 if (CONSP (obj
) && SYMBOLP (XCAR (obj
)))
1892 if (CONSP (obj
) && NILP (XCDR (obj
)))
1896 if (EQ (obj
, QNULL
) || (EQ (type
, QNULL
)))
1897 { /* This is not the same as declining */
1903 else if (STRINGP (obj
))
1905 if (SCHARS (obj
) < SBYTES (obj
))
1906 /* OBJ is a multibyte string containing a non-ASCII char. */
1907 signal_error ("Non-ASCII string must be encoded in advance", obj
);
1911 *size_ret
= SBYTES (obj
);
1912 *data_ret
= SDATA (obj
);
1915 else if (SYMBOLP (obj
))
1919 *data_ret
= (unsigned char *) xmalloc (sizeof (Atom
) + 1);
1920 (*data_ret
) [sizeof (Atom
)] = 0;
1921 (*(Atom
**) data_ret
) [0] = symbol_to_x_atom (dpyinfo
, display
, obj
);
1922 if (NILP (type
)) type
= QATOM
;
1924 else if (INTEGERP (obj
)
1925 && XINT (obj
) < 0xFFFF
1926 && XINT (obj
) > -0xFFFF)
1930 *data_ret
= (unsigned char *) xmalloc (sizeof (short) + 1);
1931 (*data_ret
) [sizeof (short)] = 0;
1932 (*(short **) data_ret
) [0] = (short) XINT (obj
);
1933 if (NILP (type
)) type
= QINTEGER
;
1935 else if (INTEGERP (obj
)
1936 || (CONSP (obj
) && INTEGERP (XCAR (obj
))
1937 && (INTEGERP (XCDR (obj
))
1938 || (CONSP (XCDR (obj
))
1939 && INTEGERP (XCAR (XCDR (obj
)))))))
1943 *data_ret
= (unsigned char *) xmalloc (sizeof (long) + 1);
1944 (*data_ret
) [sizeof (long)] = 0;
1945 (*(unsigned long **) data_ret
) [0] = cons_to_long (obj
);
1946 if (NILP (type
)) type
= QINTEGER
;
1948 else if (VECTORP (obj
))
1950 /* Lisp_Vectors may represent a set of ATOMs;
1951 a set of 16 or 32 bit INTEGERs;
1952 or a set of ATOM_PAIRs (represented as [[A1 A2] [A3 A4] ...]
1956 if (SYMBOLP (XVECTOR (obj
)->contents
[0]))
1957 /* This vector is an ATOM set */
1959 if (NILP (type
)) type
= QATOM
;
1960 *size_ret
= XVECTOR (obj
)->size
;
1962 *data_ret
= (unsigned char *) xmalloc ((*size_ret
) * sizeof (Atom
));
1963 for (i
= 0; i
< *size_ret
; i
++)
1964 if (SYMBOLP (XVECTOR (obj
)->contents
[i
]))
1965 (*(Atom
**) data_ret
) [i
]
1966 = symbol_to_x_atom (dpyinfo
, display
, XVECTOR (obj
)->contents
[i
]);
1968 signal_error ("All elements of selection vector must have same type", obj
);
1970 #if 0 /* #### MULTIPLE doesn't work yet */
1971 else if (VECTORP (XVECTOR (obj
)->contents
[0]))
1972 /* This vector is an ATOM_PAIR set */
1974 if (NILP (type
)) type
= QATOM_PAIR
;
1975 *size_ret
= XVECTOR (obj
)->size
;
1977 *data_ret
= (unsigned char *)
1978 xmalloc ((*size_ret
) * sizeof (Atom
) * 2);
1979 for (i
= 0; i
< *size_ret
; i
++)
1980 if (VECTORP (XVECTOR (obj
)->contents
[i
]))
1982 Lisp_Object pair
= XVECTOR (obj
)->contents
[i
];
1983 if (XVECTOR (pair
)->size
!= 2)
1985 "Elements of the vector must be vectors of exactly two elements",
1988 (*(Atom
**) data_ret
) [i
* 2]
1989 = symbol_to_x_atom (dpyinfo
, display
,
1990 XVECTOR (pair
)->contents
[0]);
1991 (*(Atom
**) data_ret
) [(i
* 2) + 1]
1992 = symbol_to_x_atom (dpyinfo
, display
,
1993 XVECTOR (pair
)->contents
[1]);
1996 signal_error ("All elements of the vector must be of the same type",
2002 /* This vector is an INTEGER set, or something like it */
2005 *size_ret
= XVECTOR (obj
)->size
;
2006 if (NILP (type
)) type
= QINTEGER
;
2008 for (i
= 0; i
< *size_ret
; i
++)
2009 if (CONSP (XVECTOR (obj
)->contents
[i
]))
2011 else if (!INTEGERP (XVECTOR (obj
)->contents
[i
]))
2012 signal_error (/* Qselection_error */
2013 "Elements of selection vector must be integers or conses of integers",
2016 /* Use sizeof(long) even if it is more than 32 bits. See comment
2017 in x_get_window_property and x_fill_property_data. */
2019 if (*format_ret
== 32) data_size
= sizeof(long);
2020 *data_ret
= (unsigned char *) xmalloc (*size_ret
* data_size
);
2021 for (i
= 0; i
< *size_ret
; i
++)
2022 if (*format_ret
== 32)
2023 (*((unsigned long **) data_ret
)) [i
]
2024 = cons_to_long (XVECTOR (obj
)->contents
[i
]);
2026 (*((unsigned short **) data_ret
)) [i
]
2027 = (unsigned short) cons_to_long (XVECTOR (obj
)->contents
[i
]);
2031 signal_error (/* Qselection_error */ "Unrecognized selection data", obj
);
2033 *type_ret
= symbol_to_x_atom (dpyinfo
, display
, type
);
2037 clean_local_selection_data (Lisp_Object obj
)
2040 && INTEGERP (XCAR (obj
))
2041 && CONSP (XCDR (obj
))
2042 && INTEGERP (XCAR (XCDR (obj
)))
2043 && NILP (XCDR (XCDR (obj
))))
2044 obj
= Fcons (XCAR (obj
), XCDR (obj
));
2047 && INTEGERP (XCAR (obj
))
2048 && INTEGERP (XCDR (obj
)))
2050 if (XINT (XCAR (obj
)) == 0)
2052 if (XINT (XCAR (obj
)) == -1)
2053 return make_number (- XINT (XCDR (obj
)));
2058 int size
= XVECTOR (obj
)->size
;
2061 return clean_local_selection_data (XVECTOR (obj
)->contents
[0]);
2062 copy
= Fmake_vector (make_number (size
), Qnil
);
2063 for (i
= 0; i
< size
; i
++)
2064 XVECTOR (copy
)->contents
[i
]
2065 = clean_local_selection_data (XVECTOR (obj
)->contents
[i
]);
2071 /* Called from XTread_socket to handle SelectionNotify events.
2072 If it's the selection we are waiting for, stop waiting
2073 by setting the car of reading_selection_reply to non-nil.
2074 We store t there if the reply is successful, lambda if not. */
2077 x_handle_selection_notify (XSelectionEvent
*event
)
2079 if (event
->requestor
!= reading_selection_window
)
2081 if (event
->selection
!= reading_which_selection
)
2084 TRACE0 ("Received SelectionNotify");
2085 XSETCAR (reading_selection_reply
,
2086 (event
->property
!= 0 ? Qt
: Qlambda
));
2090 DEFUN ("x-own-selection-internal", Fx_own_selection_internal
,
2091 Sx_own_selection_internal
, 2, 2, 0,
2092 doc
: /* Assert an X selection of the given TYPE with the given VALUE.
2093 TYPE is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2094 \(Those are literal upper-case symbol names, since that's what X expects.)
2095 VALUE is typically a string, or a cons of two markers, but may be
2096 anything that the functions on `selection-converter-alist' know about. */)
2097 (Lisp_Object selection_name
, Lisp_Object selection_value
)
2100 CHECK_SYMBOL (selection_name
);
2101 if (NILP (selection_value
)) error ("SELECTION-VALUE may not be nil");
2102 x_own_selection (selection_name
, selection_value
);
2103 return selection_value
;
2107 /* Request the selection value from the owner. If we are the owner,
2108 simply return our selection value. If we are not the owner, this
2109 will block until all of the data has arrived. */
2111 DEFUN ("x-get-selection-internal", Fx_get_selection_internal
,
2112 Sx_get_selection_internal
, 2, 3, 0,
2113 doc
: /* Return text selected from some X window.
2114 SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2115 \(Those are literal upper-case symbol names, since that's what X expects.)
2116 TYPE is the type of data desired, typically `STRING'.
2117 TIME_STAMP is the time to use in the XConvertSelection call for foreign
2118 selections. If omitted, defaults to the time for the last event. */)
2119 (Lisp_Object selection_symbol
, Lisp_Object target_type
, Lisp_Object time_stamp
)
2121 Lisp_Object val
= Qnil
;
2122 struct gcpro gcpro1
, gcpro2
;
2123 GCPRO2 (target_type
, val
); /* we store newly consed data into these */
2125 CHECK_SYMBOL (selection_symbol
);
2127 #if 0 /* #### MULTIPLE doesn't work yet */
2128 if (CONSP (target_type
)
2129 && XCAR (target_type
) == QMULTIPLE
)
2131 CHECK_VECTOR (XCDR (target_type
));
2132 /* So we don't destructively modify this... */
2133 target_type
= copy_multiple_data (target_type
);
2137 CHECK_SYMBOL (target_type
);
2139 val
= x_get_local_selection (selection_symbol
, target_type
, 1);
2143 val
= x_get_foreign_selection (selection_symbol
, target_type
, time_stamp
);
2148 && SYMBOLP (XCAR (val
)))
2151 if (CONSP (val
) && NILP (XCDR (val
)))
2154 val
= clean_local_selection_data (val
);
2160 DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal
,
2161 Sx_disown_selection_internal
, 1, 2, 0,
2162 doc
: /* If we own the selection SELECTION, disown it.
2163 Disowning it means there is no such selection. */)
2164 (Lisp_Object selection
, Lisp_Object time
)
2167 Atom selection_atom
;
2169 struct selection_input_event sie
;
2170 struct input_event ie
;
2173 struct x_display_info
*dpyinfo
;
2174 struct frame
*sf
= SELECTED_FRAME ();
2177 if (! FRAME_X_P (sf
))
2180 display
= FRAME_X_DISPLAY (sf
);
2181 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2182 CHECK_SYMBOL (selection
);
2184 timestamp
= last_event_timestamp
;
2186 timestamp
= cons_to_long (time
);
2188 if (NILP (assq_no_quit (selection
, Vselection_alist
)))
2189 return Qnil
; /* Don't disown the selection when we're not the owner. */
2191 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection
);
2194 XSetSelectionOwner (display
, selection_atom
, None
, timestamp
);
2197 /* It doesn't seem to be guaranteed that a SelectionClear event will be
2198 generated for a window which owns the selection when that window sets
2199 the selection owner to None. The NCD server does, the MIT Sun4 server
2200 doesn't. So we synthesize one; this means we might get two, but
2201 that's ok, because the second one won't have any effect. */
2202 SELECTION_EVENT_DISPLAY (&event
.sie
) = display
;
2203 SELECTION_EVENT_SELECTION (&event
.sie
) = selection_atom
;
2204 SELECTION_EVENT_TIME (&event
.sie
) = timestamp
;
2205 x_handle_selection_clear (&event
.ie
);
2210 /* Get rid of all the selections in buffer BUFFER.
2211 This is used when we kill a buffer. */
2214 x_disown_buffer_selections (Lisp_Object buffer
)
2217 struct buffer
*buf
= XBUFFER (buffer
);
2219 for (tail
= Vselection_alist
; CONSP (tail
); tail
= XCDR (tail
))
2221 Lisp_Object elt
, value
;
2224 if (CONSP (value
) && MARKERP (XCAR (value
))
2225 && XMARKER (XCAR (value
))->buffer
== buf
)
2226 Fx_disown_selection_internal (XCAR (elt
), Qnil
);
2230 DEFUN ("x-selection-owner-p", Fx_selection_owner_p
, Sx_selection_owner_p
,
2232 doc
: /* Whether the current Emacs process owns the given X Selection.
2233 The arg should be the name of the selection in question, typically one of
2234 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2235 \(Those are literal upper-case symbol names, since that's what X expects.)
2236 For convenience, the symbol nil is the same as `PRIMARY',
2237 and t is the same as `SECONDARY'. */)
2238 (Lisp_Object selection
)
2241 CHECK_SYMBOL (selection
);
2242 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2243 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2245 if (NILP (Fassq (selection
, Vselection_alist
)))
2250 DEFUN ("x-selection-exists-p", Fx_selection_exists_p
, Sx_selection_exists_p
,
2252 doc
: /* Whether there is an owner for the given X Selection.
2253 The arg should be the name of the selection in question, typically one of
2254 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2255 \(Those are literal upper-case symbol names, since that's what X expects.)
2256 For convenience, the symbol nil is the same as `PRIMARY',
2257 and t is the same as `SECONDARY'. */)
2258 (Lisp_Object selection
)
2263 struct frame
*sf
= SELECTED_FRAME ();
2265 /* It should be safe to call this before we have an X frame. */
2266 if (! FRAME_X_P (sf
))
2269 dpy
= FRAME_X_DISPLAY (sf
);
2270 CHECK_SYMBOL (selection
);
2271 if (!NILP (Fx_selection_owner_p (selection
)))
2273 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2274 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2275 atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
), dpy
, selection
);
2279 owner
= XGetSelectionOwner (dpy
, atom
);
2281 return (owner
? Qt
: Qnil
);
2285 #ifdef CUT_BUFFER_SUPPORT
2287 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
2289 initialize_cut_buffers (Display
*display
, Window window
)
2291 unsigned char *data
= (unsigned char *) "";
2293 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
2294 PropModeAppend, data, 0)
2295 FROB (XA_CUT_BUFFER0
);
2296 FROB (XA_CUT_BUFFER1
);
2297 FROB (XA_CUT_BUFFER2
);
2298 FROB (XA_CUT_BUFFER3
);
2299 FROB (XA_CUT_BUFFER4
);
2300 FROB (XA_CUT_BUFFER5
);
2301 FROB (XA_CUT_BUFFER6
);
2302 FROB (XA_CUT_BUFFER7
);
2308 #define CHECK_CUT_BUFFER(symbol) \
2309 do { CHECK_SYMBOL ((symbol)); \
2310 if (!EQ((symbol), QCUT_BUFFER0) && !EQ((symbol), QCUT_BUFFER1) \
2311 && !EQ((symbol), QCUT_BUFFER2) && !EQ((symbol), QCUT_BUFFER3) \
2312 && !EQ((symbol), QCUT_BUFFER4) && !EQ((symbol), QCUT_BUFFER5) \
2313 && !EQ((symbol), QCUT_BUFFER6) && !EQ((symbol), QCUT_BUFFER7)) \
2314 signal_error ("Doesn't name a cut buffer", (symbol)); \
2317 DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal
,
2318 Sx_get_cut_buffer_internal
, 1, 1, 0,
2319 doc
: /* Returns the value of the named cut buffer (typically CUT_BUFFER0). */)
2320 (Lisp_Object buffer
)
2324 unsigned char *data
= NULL
;
2331 struct x_display_info
*dpyinfo
;
2332 struct frame
*sf
= SELECTED_FRAME ();
2336 if (! FRAME_X_P (sf
))
2339 display
= FRAME_X_DISPLAY (sf
);
2340 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2341 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2342 CHECK_CUT_BUFFER (buffer
);
2343 buffer_atom
= symbol_to_x_atom (dpyinfo
, display
, buffer
);
2345 x_get_window_property (display
, window
, buffer_atom
, &data
, &bytes
,
2346 &type
, &format
, &size
, 0);
2348 if (!data
|| !format
)
2354 if (format
!= 8 || type
!= XA_STRING
)
2355 signal_error ("Cut buffer doesn't contain 8-bit data",
2356 list2 (x_atom_to_symbol (display
, type
),
2357 make_number (format
)));
2359 ret
= (bytes
? make_unibyte_string ((char *) data
, bytes
) : Qnil
);
2360 /* Use xfree, not XFree, because x_get_window_property
2361 calls xmalloc itself. */
2367 DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal
,
2368 Sx_store_cut_buffer_internal
, 2, 2, 0,
2369 doc
: /* Sets the value of the named cut buffer (typically CUT_BUFFER0). */)
2370 (Lisp_Object buffer
, Lisp_Object string
)
2374 unsigned char *data
;
2376 int bytes_remaining
;
2379 struct frame
*sf
= SELECTED_FRAME ();
2383 if (! FRAME_X_P (sf
))
2386 display
= FRAME_X_DISPLAY (sf
);
2387 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2389 max_bytes
= SELECTION_QUANTUM (display
);
2390 if (max_bytes
> MAX_SELECTION_QUANTUM
)
2391 max_bytes
= MAX_SELECTION_QUANTUM
;
2393 CHECK_CUT_BUFFER (buffer
);
2394 CHECK_STRING (string
);
2395 buffer_atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
),
2397 data
= (unsigned char *) SDATA (string
);
2398 bytes
= SBYTES (string
);
2399 bytes_remaining
= bytes
;
2401 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2403 initialize_cut_buffers (display
, window
);
2404 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2409 /* Don't mess up with an empty value. */
2410 if (!bytes_remaining
)
2411 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2412 PropModeReplace
, data
, 0);
2414 while (bytes_remaining
)
2416 int chunk
= (bytes_remaining
< max_bytes
2417 ? bytes_remaining
: max_bytes
);
2418 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2419 (bytes_remaining
== bytes
2424 bytes_remaining
-= chunk
;
2431 DEFUN ("x-rotate-cut-buffers-internal", Fx_rotate_cut_buffers_internal
,
2432 Sx_rotate_cut_buffers_internal
, 1, 1, 0,
2433 doc
: /* Rotate the values of the cut buffers by N steps.
2434 Positive N means shift the values forward, negative means backward. */)
2440 struct frame
*sf
= SELECTED_FRAME ();
2444 if (! FRAME_X_P (sf
))
2447 display
= FRAME_X_DISPLAY (sf
);
2448 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2452 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2454 initialize_cut_buffers (display
, window
);
2455 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2458 props
[0] = XA_CUT_BUFFER0
;
2459 props
[1] = XA_CUT_BUFFER1
;
2460 props
[2] = XA_CUT_BUFFER2
;
2461 props
[3] = XA_CUT_BUFFER3
;
2462 props
[4] = XA_CUT_BUFFER4
;
2463 props
[5] = XA_CUT_BUFFER5
;
2464 props
[6] = XA_CUT_BUFFER6
;
2465 props
[7] = XA_CUT_BUFFER7
;
2467 XRotateWindowProperties (display
, window
, props
, 8, XINT (n
));
2474 /***********************************************************************
2475 Drag and drop support
2476 ***********************************************************************/
2477 /* Check that lisp values are of correct type for x_fill_property_data.
2478 That is, number, string or a cons with two numbers (low and high 16
2479 bit parts of a 32 bit number). */
2482 x_check_property_data (Lisp_Object data
)
2487 for (iter
= data
; CONSP (iter
) && size
!= -1; iter
= XCDR (iter
), ++size
)
2489 Lisp_Object o
= XCAR (iter
);
2491 if (! NUMBERP (o
) && ! STRINGP (o
) && ! CONSP (o
))
2493 else if (CONSP (o
) &&
2494 (! NUMBERP (XCAR (o
)) || ! NUMBERP (XCDR (o
))))
2501 /* Convert lisp values to a C array. Values may be a number, a string
2502 which is taken as an X atom name and converted to the atom value, or
2503 a cons containing the two 16 bit parts of a 32 bit number.
2505 DPY is the display use to look up X atoms.
2506 DATA is a Lisp list of values to be converted.
2507 RET is the C array that contains the converted values. It is assumed
2508 it is big enough to hold all values.
2509 FORMAT is 8, 16 or 32 and denotes char/short/long for each C value to
2510 be stored in RET. Note that long is used for 32 even if long is more
2511 than 32 bits (see man pages for XChangeProperty, XGetWindowProperty and
2512 XClientMessageEvent). */
2515 x_fill_property_data (Display
*dpy
, Lisp_Object data
, void *ret
, int format
)
2518 long *d32
= (long *) ret
;
2519 short *d16
= (short *) ret
;
2520 char *d08
= (char *) ret
;
2523 for (iter
= data
; CONSP (iter
); iter
= XCDR (iter
))
2525 Lisp_Object o
= XCAR (iter
);
2528 val
= (long) XFASTINT (o
);
2529 else if (FLOATP (o
))
2530 val
= (long) XFLOAT_DATA (o
);
2532 val
= (long) cons_to_long (o
);
2533 else if (STRINGP (o
))
2536 val
= (long) XInternAtom (dpy
, (char *) SDATA (o
), False
);
2540 error ("Wrong type, must be string, number or cons");
2543 *d08
++ = (char) val
;
2544 else if (format
== 16)
2545 *d16
++ = (short) val
;
2551 /* Convert an array of C values to a Lisp list.
2552 F is the frame to be used to look up X atoms if the TYPE is XA_ATOM.
2553 DATA is a C array of values to be converted.
2554 TYPE is the type of the data. Only XA_ATOM is special, it converts
2555 each number in DATA to its corresponfing X atom as a symbol.
2556 FORMAT is 8, 16 or 32 and gives the size in bits for each C value to
2558 SIZE is the number of elements in DATA.
2560 Important: When format is 32, data should contain an array of int,
2561 not an array of long as the X library returns. This makes a difference
2562 when sizeof(long) != sizeof(int).
2564 Also see comment for selection_data_to_lisp_data above. */
2567 x_property_data_to_lisp (struct frame
*f
, unsigned char *data
, Atom type
, int format
, long unsigned int size
)
2569 return selection_data_to_lisp_data (FRAME_X_DISPLAY (f
),
2570 data
, size
*format
/8, type
, format
);
2573 /* Get the mouse position in frame relative coordinates. */
2576 mouse_position_for_drop (FRAME_PTR f
, int *x
, int *y
)
2578 Window root
, dummy_window
;
2583 XQueryPointer (FRAME_X_DISPLAY (f
),
2584 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
2586 /* The root window which contains the pointer. */
2589 /* Window pointer is on, not used */
2592 /* The position on that root window. */
2595 /* x/y in dummy_window coordinates, not used. */
2598 /* Modifier keys and pointer buttons, about which
2600 (unsigned int *) &dummy
);
2603 /* Absolute to relative. */
2604 *x
-= f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
);
2605 *y
-= f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
);
2610 DEFUN ("x-get-atom-name", Fx_get_atom_name
,
2611 Sx_get_atom_name
, 1, 2, 0,
2612 doc
: /* Return the X atom name for VALUE as a string.
2613 VALUE may be a number or a cons where the car is the upper 16 bits and
2614 the cdr is the lower 16 bits of a 32 bit value.
2615 Use the display for FRAME or the current frame if FRAME is not given or nil.
2617 If the value is 0 or the atom is not known, return the empty string. */)
2618 (Lisp_Object value
, Lisp_Object frame
)
2620 struct frame
*f
= check_x_frame (frame
);
2622 Lisp_Object ret
= Qnil
;
2623 Display
*dpy
= FRAME_X_DISPLAY (f
);
2627 if (INTEGERP (value
))
2628 atom
= (Atom
) XUINT (value
);
2629 else if (FLOATP (value
))
2630 atom
= (Atom
) XFLOAT_DATA (value
);
2631 else if (CONSP (value
))
2632 atom
= (Atom
) cons_to_long (value
);
2634 error ("Wrong type, value must be number or cons");
2637 x_catch_errors (dpy
);
2638 name
= atom
? XGetAtomName (dpy
, atom
) : "";
2639 had_errors
= x_had_errors_p (dpy
);
2640 x_uncatch_errors ();
2643 ret
= make_string (name
, strlen (name
));
2645 if (atom
&& name
) XFree (name
);
2646 if (NILP (ret
)) ret
= empty_unibyte_string
;
2653 DEFUN ("x-register-dnd-atom", Fx_register_dnd_atom
,
2654 Sx_register_dnd_atom
, 1, 2, 0,
2655 doc
: /* Request that dnd events are made for ClientMessages with ATOM.
2656 ATOM can be a symbol or a string. The ATOM is interned on the display that
2657 FRAME is on. If FRAME is nil, the selected frame is used. */)
2658 (Lisp_Object atom
, Lisp_Object frame
)
2661 struct frame
*f
= check_x_frame (frame
);
2663 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2667 x_atom
= symbol_to_x_atom (dpyinfo
, FRAME_X_DISPLAY (f
), atom
);
2668 else if (STRINGP (atom
))
2671 x_atom
= XInternAtom (FRAME_X_DISPLAY (f
), (char *) SDATA (atom
), False
);
2675 error ("ATOM must be a symbol or a string");
2677 for (i
= 0; i
< dpyinfo
->x_dnd_atoms_length
; ++i
)
2678 if (dpyinfo
->x_dnd_atoms
[i
] == x_atom
)
2681 if (dpyinfo
->x_dnd_atoms_length
== dpyinfo
->x_dnd_atoms_size
)
2683 dpyinfo
->x_dnd_atoms_size
*= 2;
2684 dpyinfo
->x_dnd_atoms
= xrealloc (dpyinfo
->x_dnd_atoms
,
2685 sizeof (*dpyinfo
->x_dnd_atoms
)
2686 * dpyinfo
->x_dnd_atoms_size
);
2689 dpyinfo
->x_dnd_atoms
[dpyinfo
->x_dnd_atoms_length
++] = x_atom
;
2693 /* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT. */
2696 x_handle_dnd_message (struct frame
*f
, XClientMessageEvent
*event
, struct x_display_info
*dpyinfo
, struct input_event
*bufp
)
2700 /* format 32 => size 5, format 16 => size 10, format 8 => size 20 */
2701 unsigned long size
= 160/event
->format
;
2703 unsigned char *data
= (unsigned char *) event
->data
.b
;
2707 for (i
= 0; i
< dpyinfo
->x_dnd_atoms_length
; ++i
)
2708 if (dpyinfo
->x_dnd_atoms
[i
] == event
->message_type
) break;
2710 if (i
== dpyinfo
->x_dnd_atoms_length
) return 0;
2712 XSETFRAME (frame
, f
);
2714 /* On a 64 bit machine, the event->data.l array members are 64 bits (long),
2715 but the x_property_data_to_lisp (or rather selection_data_to_lisp_data)
2716 function expects them to be of size int (i.e. 32). So to be able to
2717 use that function, put the data in the form it expects if format is 32. */
2719 if (event
->format
== 32 && event
->format
< BITS_PER_LONG
)
2722 for (i
= 0; i
< 5; ++i
) /* There are only 5 longs in a ClientMessage. */
2723 idata
[i
] = (int) event
->data
.l
[i
];
2724 data
= (unsigned char *) idata
;
2727 vec
= Fmake_vector (make_number (4), Qnil
);
2728 ASET (vec
, 0, SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f
),
2729 event
->message_type
)));
2730 ASET (vec
, 1, frame
);
2731 ASET (vec
, 2, make_number (event
->format
));
2732 ASET (vec
, 3, x_property_data_to_lisp (f
,
2734 event
->message_type
,
2738 mouse_position_for_drop (f
, &x
, &y
);
2739 bufp
->kind
= DRAG_N_DROP_EVENT
;
2740 bufp
->frame_or_window
= frame
;
2741 bufp
->timestamp
= CurrentTime
;
2742 bufp
->x
= make_number (x
);
2743 bufp
->y
= make_number (y
);
2745 bufp
->modifiers
= 0;
2750 DEFUN ("x-send-client-message", Fx_send_client_event
,
2751 Sx_send_client_message
, 6, 6, 0,
2752 doc
: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY.
2754 For DISPLAY, specify either a frame or a display name (a string).
2755 If DISPLAY is nil, that stands for the selected frame's display.
2756 DEST may be a number, in which case it is a Window id. The value 0 may
2757 be used to send to the root window of the DISPLAY.
2758 If DEST is a cons, it is converted to a 32 bit number
2759 with the high 16 bits from the car and the lower 16 bit from the cdr. That
2760 number is then used as a window id.
2761 If DEST is a frame the event is sent to the outer window of that frame.
2762 A value of nil means the currently selected frame.
2763 If DEST is the string "PointerWindow" the event is sent to the window that
2764 contains the pointer. If DEST is the string "InputFocus" the event is
2765 sent to the window that has the input focus.
2766 FROM is the frame sending the event. Use nil for currently selected frame.
2767 MESSAGE-TYPE is the name of an Atom as a string.
2768 FORMAT must be one of 8, 16 or 32 and determines the size of the values in
2769 bits. VALUES is a list of numbers, cons and/or strings containing the values
2770 to send. If a value is a string, it is converted to an Atom and the value of
2771 the Atom is sent. If a value is a cons, it is converted to a 32 bit number
2772 with the high 16 bits from the car and the lower 16 bit from the cdr.
2773 If more values than fits into the event is given, the excessive values
2775 (Lisp_Object display
, Lisp_Object dest
, Lisp_Object from
, Lisp_Object message_type
, Lisp_Object format
, Lisp_Object values
)
2777 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
2782 struct frame
*f
= check_x_frame (from
);
2785 CHECK_STRING (message_type
);
2786 CHECK_NUMBER (format
);
2787 CHECK_CONS (values
);
2789 if (x_check_property_data (values
) == -1)
2790 error ("Bad data in VALUES, must be number, cons or string");
2792 event
.xclient
.type
= ClientMessage
;
2793 event
.xclient
.format
= XFASTINT (format
);
2795 if (event
.xclient
.format
!= 8 && event
.xclient
.format
!= 16
2796 && event
.xclient
.format
!= 32)
2797 error ("FORMAT must be one of 8, 16 or 32");
2799 if (FRAMEP (dest
) || NILP (dest
))
2801 struct frame
*fdest
= check_x_frame (dest
);
2802 wdest
= FRAME_OUTER_WINDOW (fdest
);
2804 else if (STRINGP (dest
))
2806 if (strcmp (SDATA (dest
), "PointerWindow") == 0)
2807 wdest
= PointerWindow
;
2808 else if (strcmp (SDATA (dest
), "InputFocus") == 0)
2811 error ("DEST as a string must be one of PointerWindow or InputFocus");
2813 else if (INTEGERP (dest
))
2814 wdest
= (Window
) XFASTINT (dest
);
2815 else if (FLOATP (dest
))
2816 wdest
= (Window
) XFLOAT_DATA (dest
);
2817 else if (CONSP (dest
))
2819 if (! NUMBERP (XCAR (dest
)) || ! NUMBERP (XCDR (dest
)))
2820 error ("Both car and cdr for DEST must be numbers");
2822 wdest
= (Window
) cons_to_long (dest
);
2825 error ("DEST must be a frame, nil, string, number or cons");
2827 if (wdest
== 0) wdest
= dpyinfo
->root_window
;
2828 to_root
= wdest
== dpyinfo
->root_window
;
2830 for (cons
= values
, size
= 0; CONSP (cons
); cons
= XCDR (cons
), ++size
)
2835 event
.xclient
.message_type
2836 = XInternAtom (dpyinfo
->display
, SDATA (message_type
), False
);
2837 event
.xclient
.display
= dpyinfo
->display
;
2839 /* Some clients (metacity for example) expects sending window to be here
2840 when sending to the root window. */
2841 event
.xclient
.window
= to_root
? FRAME_OUTER_WINDOW (f
) : wdest
;
2844 memset (event
.xclient
.data
.b
, 0, sizeof (event
.xclient
.data
.b
));
2845 x_fill_property_data (dpyinfo
->display
, values
, event
.xclient
.data
.b
,
2846 event
.xclient
.format
);
2848 /* If event mask is 0 the event is sent to the client that created
2849 the destination window. But if we are sending to the root window,
2850 there is no such client. Then we set the event mask to 0xffff. The
2851 event then goes to clients selecting for events on the root window. */
2852 x_catch_errors (dpyinfo
->display
);
2854 int propagate
= to_root
? False
: True
;
2855 unsigned mask
= to_root
? 0xffff : 0;
2856 XSendEvent (dpyinfo
->display
, wdest
, propagate
, mask
, &event
);
2857 XFlush (dpyinfo
->display
);
2859 x_uncatch_errors ();
2867 syms_of_xselect (void)
2869 defsubr (&Sx_get_selection_internal
);
2870 defsubr (&Sx_own_selection_internal
);
2871 defsubr (&Sx_disown_selection_internal
);
2872 defsubr (&Sx_selection_owner_p
);
2873 defsubr (&Sx_selection_exists_p
);
2875 #ifdef CUT_BUFFER_SUPPORT
2876 defsubr (&Sx_get_cut_buffer_internal
);
2877 defsubr (&Sx_store_cut_buffer_internal
);
2878 defsubr (&Sx_rotate_cut_buffers_internal
);
2881 defsubr (&Sx_get_atom_name
);
2882 defsubr (&Sx_send_client_message
);
2883 defsubr (&Sx_register_dnd_atom
);
2885 reading_selection_reply
= Fcons (Qnil
, Qnil
);
2886 staticpro (&reading_selection_reply
);
2887 reading_selection_window
= 0;
2888 reading_which_selection
= 0;
2890 property_change_wait_list
= 0;
2891 prop_location_identifier
= 0;
2892 property_change_reply
= Fcons (Qnil
, Qnil
);
2893 staticpro (&property_change_reply
);
2895 Vselection_alist
= Qnil
;
2896 staticpro (&Vselection_alist
);
2898 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist
,
2899 doc
: /* An alist associating X Windows selection-types with functions.
2900 These functions are called to convert the selection, with three args:
2901 the name of the selection (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2902 a desired type to which the selection should be converted;
2903 and the local selection value (whatever was given to `x-own-selection').
2905 The function should return the value to send to the X server
2906 \(typically a string). A return value of nil
2907 means that the conversion could not be done.
2908 A return value which is the symbol `NULL'
2909 means that a side-effect was executed,
2910 and there is no meaningful selection value. */);
2911 Vselection_converter_alist
= Qnil
;
2913 DEFVAR_LISP ("x-lost-selection-functions", &Vx_lost_selection_functions
,
2914 doc
: /* A list of functions to be called when Emacs loses an X selection.
2915 \(This happens when some other X client makes its own selection
2916 or when a Lisp program explicitly clears the selection.)
2917 The functions are called with one argument, the selection type
2918 \(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'). */);
2919 Vx_lost_selection_functions
= Qnil
;
2921 DEFVAR_LISP ("x-sent-selection-functions", &Vx_sent_selection_functions
,
2922 doc
: /* A list of functions to be called when Emacs answers a selection request.
2923 The functions are called with four arguments:
2924 - the selection name (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2925 - the selection-type which Emacs was asked to convert the
2926 selection into before sending (for example, `STRING' or `LENGTH');
2927 - a flag indicating success or failure for responding to the request.
2928 We might have failed (and declined the request) for any number of reasons,
2929 including being asked for a selection that we no longer own, or being asked
2930 to convert into a type that we don't know about or that is inappropriate.
2931 This hook doesn't let you change the behavior of Emacs's selection replies,
2932 it merely informs you that they have happened. */);
2933 Vx_sent_selection_functions
= Qnil
;
2935 DEFVAR_INT ("x-selection-timeout", &x_selection_timeout
,
2936 doc
: /* Number of milliseconds to wait for a selection reply.
2937 If the selection owner doesn't reply in this time, we give up.
2938 A value of 0 means wait as long as necessary. This is initialized from the
2939 \"*selectionTimeout\" resource. */);
2940 x_selection_timeout
= 0;
2942 QPRIMARY
= intern_c_string ("PRIMARY"); staticpro (&QPRIMARY
);
2943 QSECONDARY
= intern_c_string ("SECONDARY"); staticpro (&QSECONDARY
);
2944 QSTRING
= intern_c_string ("STRING"); staticpro (&QSTRING
);
2945 QINTEGER
= intern_c_string ("INTEGER"); staticpro (&QINTEGER
);
2946 QCLIPBOARD
= intern_c_string ("CLIPBOARD"); staticpro (&QCLIPBOARD
);
2947 QTIMESTAMP
= intern_c_string ("TIMESTAMP"); staticpro (&QTIMESTAMP
);
2948 QTEXT
= intern_c_string ("TEXT"); staticpro (&QTEXT
);
2949 QCOMPOUND_TEXT
= intern_c_string ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT
);
2950 QUTF8_STRING
= intern_c_string ("UTF8_STRING"); staticpro (&QUTF8_STRING
);
2951 QDELETE
= intern_c_string ("DELETE"); staticpro (&QDELETE
);
2952 QMULTIPLE
= intern_c_string ("MULTIPLE"); staticpro (&QMULTIPLE
);
2953 QINCR
= intern_c_string ("INCR"); staticpro (&QINCR
);
2954 QEMACS_TMP
= intern_c_string ("_EMACS_TMP_"); staticpro (&QEMACS_TMP
);
2955 QTARGETS
= intern_c_string ("TARGETS"); staticpro (&QTARGETS
);
2956 QATOM
= intern_c_string ("ATOM"); staticpro (&QATOM
);
2957 QATOM_PAIR
= intern_c_string ("ATOM_PAIR"); staticpro (&QATOM_PAIR
);
2958 QNULL
= intern_c_string ("NULL"); staticpro (&QNULL
);
2959 Qcompound_text_with_extensions
= intern_c_string ("compound-text-with-extensions");
2960 staticpro (&Qcompound_text_with_extensions
);
2962 #ifdef CUT_BUFFER_SUPPORT
2963 QCUT_BUFFER0
= intern_c_string ("CUT_BUFFER0"); staticpro (&QCUT_BUFFER0
);
2964 QCUT_BUFFER1
= intern_c_string ("CUT_BUFFER1"); staticpro (&QCUT_BUFFER1
);
2965 QCUT_BUFFER2
= intern_c_string ("CUT_BUFFER2"); staticpro (&QCUT_BUFFER2
);
2966 QCUT_BUFFER3
= intern_c_string ("CUT_BUFFER3"); staticpro (&QCUT_BUFFER3
);
2967 QCUT_BUFFER4
= intern_c_string ("CUT_BUFFER4"); staticpro (&QCUT_BUFFER4
);
2968 QCUT_BUFFER5
= intern_c_string ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5
);
2969 QCUT_BUFFER6
= intern_c_string ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6
);
2970 QCUT_BUFFER7
= intern_c_string ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7
);
2973 Qforeign_selection
= intern_c_string ("foreign-selection");
2974 staticpro (&Qforeign_selection
);
2977 /* arch-tag: 7c293b0f-9918-4f69-8ac7-03e142307236
2978 (do not change this comment) */