1 /* X Selection processing for Emacs.
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006 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 2, or (at your option)
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; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 /* Rewritten by jwz */
26 #include <stdio.h> /* termhooks.h needs this */
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
36 #include "xterm.h" /* for all of the X includes */
37 #include "dispextern.h" /* frame.h seems to want this */
38 #include "frame.h" /* Need this to get the X window of selected_frame */
39 #include "blockinput.h"
42 #include "termhooks.h"
45 #include <X11/Xproto.h>
49 static Lisp_Object x_atom_to_symbol
P_ ((Display
*dpy
, Atom atom
));
50 static Atom symbol_to_x_atom
P_ ((struct x_display_info
*, Display
*,
52 static void x_own_selection
P_ ((Lisp_Object
, Lisp_Object
));
53 static Lisp_Object x_get_local_selection
P_ ((Lisp_Object
, Lisp_Object
, int));
54 static void x_decline_selection_request
P_ ((struct input_event
*));
55 static Lisp_Object x_selection_request_lisp_error
P_ ((Lisp_Object
));
56 static Lisp_Object queue_selection_requests_unwind
P_ ((Lisp_Object
));
57 static Lisp_Object some_frame_on_display
P_ ((struct x_display_info
*));
58 static Lisp_Object x_catch_errors_unwind
P_ ((Lisp_Object
));
59 static void x_reply_selection_request
P_ ((struct input_event
*, int,
60 unsigned char *, int, Atom
));
61 static int waiting_for_other_props_on_window
P_ ((Display
*, Window
));
62 static struct prop_location
*expect_property_change
P_ ((Display
*, Window
,
64 static void unexpect_property_change
P_ ((struct prop_location
*));
65 static Lisp_Object wait_for_property_change_unwind
P_ ((Lisp_Object
));
66 static void wait_for_property_change
P_ ((struct prop_location
*));
67 static Lisp_Object x_get_foreign_selection
P_ ((Lisp_Object
,
70 static void x_get_window_property
P_ ((Display
*, Window
, Atom
,
71 unsigned char **, int *,
72 Atom
*, int *, unsigned long *, int));
73 static void receive_incremental_selection
P_ ((Display
*, Window
, Atom
,
74 Lisp_Object
, unsigned,
75 unsigned char **, int *,
76 Atom
*, int *, unsigned long *));
77 static Lisp_Object x_get_window_property_as_lisp_data
P_ ((Display
*,
80 static Lisp_Object selection_data_to_lisp_data
P_ ((Display
*, unsigned char *,
82 static void lisp_data_to_selection_data
P_ ((Display
*, Lisp_Object
,
83 unsigned char **, Atom
*,
84 unsigned *, int *, int *));
85 static Lisp_Object clean_local_selection_data
P_ ((Lisp_Object
));
86 static void initialize_cut_buffers
P_ ((Display
*, Window
));
89 /* Printing traces to stderr. */
91 #ifdef TRACE_SELECTION
93 fprintf (stderr, "%d: " fmt "\n", getpid ())
94 #define TRACE1(fmt, a0) \
95 fprintf (stderr, "%d: " fmt "\n", getpid (), a0)
96 #define TRACE2(fmt, a0, a1) \
97 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1)
98 #define TRACE3(fmt, a0, a1, a2) \
99 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1, a2)
101 #define TRACE0(fmt) (void) 0
102 #define TRACE1(fmt, a0) (void) 0
103 #define TRACE2(fmt, a0, a1) (void) 0
104 #define TRACE3(fmt, a0, a1) (void) 0
108 #define CUT_BUFFER_SUPPORT
110 Lisp_Object QPRIMARY
, QSECONDARY
, QSTRING
, QINTEGER
, QCLIPBOARD
, QTIMESTAMP
,
111 QTEXT
, QDELETE
, QMULTIPLE
, QINCR
, QEMACS_TMP
, QTARGETS
, QATOM
, QNULL
,
114 Lisp_Object QCOMPOUND_TEXT
; /* This is a type of selection. */
115 Lisp_Object QUTF8_STRING
; /* This is a type of selection. */
117 Lisp_Object Qcompound_text_with_extensions
;
119 #ifdef CUT_BUFFER_SUPPORT
120 Lisp_Object QCUT_BUFFER0
, QCUT_BUFFER1
, QCUT_BUFFER2
, QCUT_BUFFER3
,
121 QCUT_BUFFER4
, QCUT_BUFFER5
, QCUT_BUFFER6
, QCUT_BUFFER7
;
124 static Lisp_Object Vx_lost_selection_functions
;
125 static Lisp_Object Vx_sent_selection_functions
;
126 /* Coding system for communicating with other X clients via cutbuffer,
127 selection, and clipboard. */
128 static Lisp_Object Vselection_coding_system
;
130 /* Coding system for the next communicating with other X clients. */
131 static Lisp_Object Vnext_selection_coding_system
;
133 static Lisp_Object Qforeign_selection
;
135 /* If this is a smaller number than the max-request-size of the display,
136 emacs will use INCR selection transfer when the selection is larger
137 than this. The max-request-size is usually around 64k, so if you want
138 emacs to use incremental selection transfers when the selection is
139 smaller than that, set this. I added this mostly for debugging the
140 incremental transfer stuff, but it might improve server performance. */
141 #define MAX_SELECTION_QUANTUM 0xFFFFFF
144 #define SELECTION_QUANTUM(dpy) ((XMaxRequestSize(dpy) << 2) - 100)
146 #define SELECTION_QUANTUM(dpy) (((dpy)->max_request_size << 2) - 100)
149 /* The timestamp of the last input event Emacs received from the X server. */
150 /* Defined in keyboard.c. */
151 extern unsigned long last_event_timestamp
;
153 /* This is an association list whose elements are of the form
154 ( SELECTION-NAME SELECTION-VALUE SELECTION-TIMESTAMP FRAME)
155 SELECTION-NAME is a lisp symbol, whose name is the name of an X Atom.
156 SELECTION-VALUE is the value that emacs owns for that selection.
157 It may be any kind of Lisp object.
158 SELECTION-TIMESTAMP is the time at which emacs began owning this selection,
159 as a cons of two 16-bit numbers (making a 32 bit time.)
160 FRAME is the frame for which we made the selection.
161 If there is an entry in this alist, then it can be assumed that Emacs owns
163 The only (eq) parts of this list that are visible from Lisp are the
165 static Lisp_Object Vselection_alist
;
167 /* This is an alist whose CARs are selection-types (whose names are the same
168 as the names of X Atoms) and whose CDRs are the names of Lisp functions to
169 call to convert the given Emacs selection value to a string representing
170 the given selection type. This is for Lisp-level extension of the emacs
171 selection handling. */
172 static Lisp_Object Vselection_converter_alist
;
174 /* If the selection owner takes too long to reply to a selection request,
175 we give up on it. This is in milliseconds (0 = no timeout.) */
176 static EMACS_INT x_selection_timeout
;
180 /* Define a queue to save up SELECTION_REQUEST_EVENT events for later
183 struct selection_event_queue
185 struct input_event event
;
186 struct selection_event_queue
*next
;
189 static struct selection_event_queue
*selection_queue
;
191 /* Nonzero means queue up SELECTION_REQUEST_EVENT events. */
193 static int x_queue_selection_requests
;
195 /* Queue up an SELECTION_REQUEST_EVENT *EVENT, to be processed later. */
198 x_queue_event (event
)
199 struct input_event
*event
;
201 struct selection_event_queue
*queue_tmp
;
203 /* Don't queue repeated requests.
204 This only happens for large requests which uses the incremental protocol. */
205 for (queue_tmp
= selection_queue
; queue_tmp
; queue_tmp
= queue_tmp
->next
)
207 if (!bcmp (&queue_tmp
->event
, event
, sizeof (*event
)))
209 TRACE1 ("DECLINE DUP SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
210 x_decline_selection_request (event
);
216 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
218 if (queue_tmp
!= NULL
)
220 TRACE1 ("QUEUE SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
221 queue_tmp
->event
= *event
;
222 queue_tmp
->next
= selection_queue
;
223 selection_queue
= queue_tmp
;
227 /* Start queuing SELECTION_REQUEST_EVENT events. */
230 x_start_queuing_selection_requests ()
232 if (x_queue_selection_requests
)
235 x_queue_selection_requests
++;
236 TRACE1 ("x_start_queuing_selection_requests %d", x_queue_selection_requests
);
239 /* Stop queuing SELECTION_REQUEST_EVENT events. */
242 x_stop_queuing_selection_requests ()
244 TRACE1 ("x_stop_queuing_selection_requests %d", x_queue_selection_requests
);
245 --x_queue_selection_requests
;
247 /* Take all the queued events and put them back
248 so that they get processed afresh. */
250 while (selection_queue
!= NULL
)
252 struct selection_event_queue
*queue_tmp
= selection_queue
;
253 TRACE1 ("RESTORE SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
254 kbd_buffer_unget_event (&queue_tmp
->event
);
255 selection_queue
= queue_tmp
->next
;
256 xfree ((char *)queue_tmp
);
261 /* This converts a Lisp symbol to a server Atom, avoiding a server
262 roundtrip whenever possible. */
265 symbol_to_x_atom (dpyinfo
, display
, sym
)
266 struct x_display_info
*dpyinfo
;
271 if (NILP (sym
)) return 0;
272 if (EQ (sym
, QPRIMARY
)) return XA_PRIMARY
;
273 if (EQ (sym
, QSECONDARY
)) return XA_SECONDARY
;
274 if (EQ (sym
, QSTRING
)) return XA_STRING
;
275 if (EQ (sym
, QINTEGER
)) return XA_INTEGER
;
276 if (EQ (sym
, QATOM
)) return XA_ATOM
;
277 if (EQ (sym
, QCLIPBOARD
)) return dpyinfo
->Xatom_CLIPBOARD
;
278 if (EQ (sym
, QTIMESTAMP
)) return dpyinfo
->Xatom_TIMESTAMP
;
279 if (EQ (sym
, QTEXT
)) return dpyinfo
->Xatom_TEXT
;
280 if (EQ (sym
, QCOMPOUND_TEXT
)) return dpyinfo
->Xatom_COMPOUND_TEXT
;
281 if (EQ (sym
, QUTF8_STRING
)) return dpyinfo
->Xatom_UTF8_STRING
;
282 if (EQ (sym
, QDELETE
)) return dpyinfo
->Xatom_DELETE
;
283 if (EQ (sym
, QMULTIPLE
)) return dpyinfo
->Xatom_MULTIPLE
;
284 if (EQ (sym
, QINCR
)) return dpyinfo
->Xatom_INCR
;
285 if (EQ (sym
, QEMACS_TMP
)) return dpyinfo
->Xatom_EMACS_TMP
;
286 if (EQ (sym
, QTARGETS
)) return dpyinfo
->Xatom_TARGETS
;
287 if (EQ (sym
, QNULL
)) return dpyinfo
->Xatom_NULL
;
288 #ifdef CUT_BUFFER_SUPPORT
289 if (EQ (sym
, QCUT_BUFFER0
)) return XA_CUT_BUFFER0
;
290 if (EQ (sym
, QCUT_BUFFER1
)) return XA_CUT_BUFFER1
;
291 if (EQ (sym
, QCUT_BUFFER2
)) return XA_CUT_BUFFER2
;
292 if (EQ (sym
, QCUT_BUFFER3
)) return XA_CUT_BUFFER3
;
293 if (EQ (sym
, QCUT_BUFFER4
)) return XA_CUT_BUFFER4
;
294 if (EQ (sym
, QCUT_BUFFER5
)) return XA_CUT_BUFFER5
;
295 if (EQ (sym
, QCUT_BUFFER6
)) return XA_CUT_BUFFER6
;
296 if (EQ (sym
, QCUT_BUFFER7
)) return XA_CUT_BUFFER7
;
298 if (!SYMBOLP (sym
)) abort ();
300 TRACE1 (" XInternAtom %s", (char *) SDATA (SYMBOL_NAME (sym
)));
302 val
= XInternAtom (display
, (char *) SDATA (SYMBOL_NAME (sym
)), False
);
308 /* This converts a server Atom to a Lisp symbol, avoiding server roundtrips
309 and calls to intern whenever possible. */
312 x_atom_to_symbol (dpy
, atom
)
316 struct x_display_info
*dpyinfo
;
335 #ifdef CUT_BUFFER_SUPPORT
355 dpyinfo
= x_display_info_for_display (dpy
);
356 if (atom
== dpyinfo
->Xatom_CLIPBOARD
)
358 if (atom
== dpyinfo
->Xatom_TIMESTAMP
)
360 if (atom
== dpyinfo
->Xatom_TEXT
)
362 if (atom
== dpyinfo
->Xatom_COMPOUND_TEXT
)
363 return QCOMPOUND_TEXT
;
364 if (atom
== dpyinfo
->Xatom_UTF8_STRING
)
366 if (atom
== dpyinfo
->Xatom_DELETE
)
368 if (atom
== dpyinfo
->Xatom_MULTIPLE
)
370 if (atom
== dpyinfo
->Xatom_INCR
)
372 if (atom
== dpyinfo
->Xatom_EMACS_TMP
)
374 if (atom
== dpyinfo
->Xatom_TARGETS
)
376 if (atom
== dpyinfo
->Xatom_NULL
)
380 str
= XGetAtomName (dpy
, atom
);
382 TRACE1 ("XGetAtomName --> %s", str
);
383 if (! str
) return Qnil
;
386 /* This was allocated by Xlib, so use XFree. */
392 /* Do protocol to assert ourself as a selection owner.
393 Update the Vselection_alist so that we can reply to later requests for
397 x_own_selection (selection_name
, selection_value
)
398 Lisp_Object selection_name
, selection_value
;
400 struct frame
*sf
= SELECTED_FRAME ();
401 Window selecting_window
;
403 Time time
= last_event_timestamp
;
405 struct x_display_info
*dpyinfo
;
407 if (! FRAME_X_P (sf
))
410 selecting_window
= FRAME_X_WINDOW (sf
);
411 display
= FRAME_X_DISPLAY (sf
);
412 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
414 CHECK_SYMBOL (selection_name
);
415 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection_name
);
418 x_catch_errors (display
);
419 XSetSelectionOwner (display
, selection_atom
, selecting_window
, time
);
420 x_check_errors (display
, "Can't set selection: %s");
424 /* Now update the local cache */
426 Lisp_Object selection_time
;
427 Lisp_Object selection_data
;
428 Lisp_Object prev_value
;
430 selection_time
= long_to_cons ((unsigned long) time
);
431 selection_data
= Fcons (selection_name
,
432 Fcons (selection_value
,
433 Fcons (selection_time
,
434 Fcons (selected_frame
, Qnil
))));
435 prev_value
= assq_no_quit (selection_name
, Vselection_alist
);
437 Vselection_alist
= Fcons (selection_data
, Vselection_alist
);
439 /* If we already owned the selection, remove the old selection data.
440 Perhaps we should destructively modify it instead.
441 Don't use Fdelq as that may QUIT. */
442 if (!NILP (prev_value
))
444 Lisp_Object rest
; /* we know it's not the CAR, so it's easy. */
445 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
446 if (EQ (prev_value
, Fcar (XCDR (rest
))))
448 XSETCDR (rest
, Fcdr (XCDR (rest
)));
455 /* Given a selection-name and desired type, look up our local copy of
456 the selection value and convert it to the type.
457 The value is nil or a string.
458 This function is used both for remote requests (LOCAL_REQUEST is zero)
459 and for local x-get-selection-internal (LOCAL_REQUEST is nonzero).
461 This calls random Lisp code, and may signal or gc. */
464 x_get_local_selection (selection_symbol
, target_type
, local_request
)
465 Lisp_Object selection_symbol
, target_type
;
468 Lisp_Object local_value
;
469 Lisp_Object handler_fn
, value
, type
, check
;
472 local_value
= assq_no_quit (selection_symbol
, Vselection_alist
);
474 if (NILP (local_value
)) return Qnil
;
476 /* TIMESTAMP and MULTIPLE are special cases 'cause that's easiest. */
477 if (EQ (target_type
, QTIMESTAMP
))
480 value
= XCAR (XCDR (XCDR (local_value
)));
483 else if (EQ (target_type
, QDELETE
))
486 Fx_disown_selection_internal
488 XCAR (XCDR (XCDR (local_value
))));
493 #if 0 /* #### MULTIPLE doesn't work yet */
494 else if (CONSP (target_type
)
495 && XCAR (target_type
) == QMULTIPLE
)
500 pairs
= XCDR (target_type
);
501 size
= XVECTOR (pairs
)->size
;
502 /* If the target is MULTIPLE, then target_type looks like
503 (MULTIPLE . [[SELECTION1 TARGET1] [SELECTION2 TARGET2] ... ])
504 We modify the second element of each pair in the vector and
505 return it as [[SELECTION1 <value1>] [SELECTION2 <value2>] ... ]
507 for (i
= 0; i
< size
; i
++)
510 pair
= XVECTOR (pairs
)->contents
[i
];
511 XVECTOR (pair
)->contents
[1]
512 = x_get_local_selection (XVECTOR (pair
)->contents
[0],
513 XVECTOR (pair
)->contents
[1],
521 /* Don't allow a quit within the converter.
522 When the user types C-g, he would be surprised
523 if by luck it came during a converter. */
524 count
= SPECPDL_INDEX ();
525 specbind (Qinhibit_quit
, Qt
);
527 CHECK_SYMBOL (target_type
);
528 handler_fn
= Fcdr (Fassq (target_type
, Vselection_converter_alist
));
529 /* gcpro is not needed here since nothing but HANDLER_FN
530 is live, and that ought to be a symbol. */
532 if (!NILP (handler_fn
))
533 value
= call3 (handler_fn
,
534 selection_symbol
, (local_request
? Qnil
: target_type
),
535 XCAR (XCDR (local_value
)));
538 unbind_to (count
, Qnil
);
541 /* Make sure this value is of a type that we could transmit
542 to another X client. */
546 && SYMBOLP (XCAR (value
)))
548 check
= XCDR (value
);
556 /* Check for a value that cons_to_long could handle. */
557 else if (CONSP (check
)
558 && INTEGERP (XCAR (check
))
559 && (INTEGERP (XCDR (check
))
561 (CONSP (XCDR (check
))
562 && INTEGERP (XCAR (XCDR (check
)))
563 && NILP (XCDR (XCDR (check
))))))
568 Fcons (build_string ("invalid data returned by selection-conversion function"),
569 Fcons (handler_fn
, Fcons (value
, Qnil
))));
572 /* Subroutines of x_reply_selection_request. */
574 /* Send a SelectionNotify event to the requestor with property=None,
575 meaning we were unable to do what they wanted. */
578 x_decline_selection_request (event
)
579 struct input_event
*event
;
581 XSelectionEvent reply
;
583 reply
.type
= SelectionNotify
;
584 reply
.display
= SELECTION_EVENT_DISPLAY (event
);
585 reply
.requestor
= SELECTION_EVENT_REQUESTOR (event
);
586 reply
.selection
= SELECTION_EVENT_SELECTION (event
);
587 reply
.time
= SELECTION_EVENT_TIME (event
);
588 reply
.target
= SELECTION_EVENT_TARGET (event
);
589 reply
.property
= None
;
591 /* The reason for the error may be that the receiver has
592 died in the meantime. Handle that case. */
594 x_catch_errors (reply
.display
);
595 XSendEvent (reply
.display
, reply
.requestor
, False
, 0L, (XEvent
*) &reply
);
596 XFlush (reply
.display
);
601 /* This is the selection request currently being processed.
602 It is set to zero when the request is fully processed. */
603 static struct input_event
*x_selection_current_request
;
605 /* Display info in x_selection_request. */
607 static struct x_display_info
*selection_request_dpyinfo
;
609 /* Used as an unwind-protect clause so that, if a selection-converter signals
610 an error, we tell the requester that we were unable to do what they wanted
611 before we throw to top-level or go into the debugger or whatever. */
614 x_selection_request_lisp_error (ignore
)
617 if (x_selection_current_request
!= 0
618 && selection_request_dpyinfo
->display
)
619 x_decline_selection_request (x_selection_current_request
);
624 x_catch_errors_unwind (dummy
)
634 /* This stuff is so that INCR selections are reentrant (that is, so we can
635 be servicing multiple INCR selection requests simultaneously.) I haven't
636 actually tested that yet. */
638 /* Keep a list of the property changes that are awaited. */
648 struct prop_location
*next
;
651 static struct prop_location
*expect_property_change ();
652 static void wait_for_property_change ();
653 static void unexpect_property_change ();
654 static int waiting_for_other_props_on_window ();
656 static int prop_location_identifier
;
658 static Lisp_Object property_change_reply
;
660 static struct prop_location
*property_change_reply_object
;
662 static struct prop_location
*property_change_wait_list
;
665 queue_selection_requests_unwind (tem
)
668 x_stop_queuing_selection_requests ();
672 /* Return some frame whose display info is DPYINFO.
673 Return nil if there is none. */
676 some_frame_on_display (dpyinfo
)
677 struct x_display_info
*dpyinfo
;
679 Lisp_Object list
, frame
;
681 FOR_EACH_FRAME (list
, frame
)
683 if (FRAME_X_P (XFRAME (frame
))
684 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
691 /* Send the reply to a selection request event EVENT.
692 TYPE is the type of selection data requested.
693 DATA and SIZE describe the data to send, already converted.
694 FORMAT is the unit-size (in bits) of the data to be transmitted. */
697 x_reply_selection_request (event
, format
, data
, size
, type
)
698 struct input_event
*event
;
703 XSelectionEvent reply
;
704 Display
*display
= SELECTION_EVENT_DISPLAY (event
);
705 Window window
= SELECTION_EVENT_REQUESTOR (event
);
707 int format_bytes
= format
/8;
708 int max_bytes
= SELECTION_QUANTUM (display
);
709 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
710 int count
= SPECPDL_INDEX ();
712 if (max_bytes
> MAX_SELECTION_QUANTUM
)
713 max_bytes
= MAX_SELECTION_QUANTUM
;
715 reply
.type
= SelectionNotify
;
716 reply
.display
= display
;
717 reply
.requestor
= window
;
718 reply
.selection
= SELECTION_EVENT_SELECTION (event
);
719 reply
.time
= SELECTION_EVENT_TIME (event
);
720 reply
.target
= SELECTION_EVENT_TARGET (event
);
721 reply
.property
= SELECTION_EVENT_PROPERTY (event
);
722 if (reply
.property
== None
)
723 reply
.property
= reply
.target
;
726 /* The protected block contains wait_for_property_change, which can
727 run random lisp code (process handlers) or signal. Therefore, we
728 put the x_uncatch_errors call in an unwind. */
729 record_unwind_protect (x_catch_errors_unwind
, Qnil
);
730 x_catch_errors (display
);
732 #ifdef TRACE_SELECTION
735 char *sel
= XGetAtomName (display
, reply
.selection
);
736 char *tgt
= XGetAtomName (display
, reply
.target
);
737 TRACE3 ("%s, target %s (%d)", sel
, tgt
, ++cnt
);
738 if (sel
) XFree (sel
);
739 if (tgt
) XFree (tgt
);
741 #endif /* TRACE_SELECTION */
743 /* Store the data on the requested property.
744 If the selection is large, only store the first N bytes of it.
746 bytes_remaining
= size
* format_bytes
;
747 if (bytes_remaining
<= max_bytes
)
749 /* Send all the data at once, with minimal handshaking. */
750 TRACE1 ("Sending all %d bytes", bytes_remaining
);
751 XChangeProperty (display
, window
, reply
.property
, type
, format
,
752 PropModeReplace
, data
, size
);
753 /* At this point, the selection was successfully stored; ack it. */
754 XSendEvent (display
, window
, False
, 0L, (XEvent
*) &reply
);
758 /* Send an INCR selection. */
759 struct prop_location
*wait_object
;
763 frame
= some_frame_on_display (dpyinfo
);
765 /* If the display no longer has frames, we can't expect
766 to get many more selection requests from it, so don't
767 bother trying to queue them. */
770 x_start_queuing_selection_requests ();
772 record_unwind_protect (queue_selection_requests_unwind
,
776 if (x_window_to_frame (dpyinfo
, window
)) /* #### debug */
777 error ("Attempt to transfer an INCR to ourself!");
779 TRACE2 ("Start sending %d bytes incrementally (%s)",
780 bytes_remaining
, XGetAtomName (display
, reply
.property
));
781 wait_object
= expect_property_change (display
, window
, reply
.property
,
784 TRACE1 ("Set %s to number of bytes to send",
785 XGetAtomName (display
, reply
.property
));
787 /* XChangeProperty expects an array of long even if long is more than
791 value
[0] = bytes_remaining
;
792 XChangeProperty (display
, window
, reply
.property
, dpyinfo
->Xatom_INCR
,
794 (unsigned char *) value
, 1);
797 XSelectInput (display
, window
, PropertyChangeMask
);
799 /* Tell 'em the INCR data is there... */
800 TRACE0 ("Send SelectionNotify event");
801 XSendEvent (display
, window
, False
, 0L, (XEvent
*) &reply
);
804 had_errors
= x_had_errors_p (display
);
807 /* First, wait for the requester to ack by deleting the property.
808 This can run random lisp code (process handlers) or signal. */
811 TRACE1 ("Waiting for ACK (deletion of %s)",
812 XGetAtomName (display
, reply
.property
));
813 wait_for_property_change (wait_object
);
816 unexpect_property_change (wait_object
);
819 while (bytes_remaining
)
821 int i
= ((bytes_remaining
< max_bytes
)
828 = expect_property_change (display
, window
, reply
.property
,
831 TRACE1 ("Sending increment of %d bytes", i
);
832 TRACE1 ("Set %s to increment data",
833 XGetAtomName (display
, reply
.property
));
835 /* Append the next chunk of data to the property. */
836 XChangeProperty (display
, window
, reply
.property
, type
, format
,
837 PropModeAppend
, data
, i
/ format_bytes
);
838 bytes_remaining
-= i
;
841 had_errors
= x_had_errors_p (display
);
847 /* Now wait for the requester to ack this chunk by deleting the
848 property. This can run random lisp code or signal. */
849 TRACE1 ("Waiting for increment ACK (deletion of %s)",
850 XGetAtomName (display
, reply
.property
));
851 wait_for_property_change (wait_object
);
854 /* Now write a zero-length chunk to the property to tell the
855 requester that we're done. */
857 if (! waiting_for_other_props_on_window (display
, window
))
858 XSelectInput (display
, window
, 0L);
860 TRACE1 ("Set %s to a 0-length chunk to indicate EOF",
861 XGetAtomName (display
, reply
.property
));
862 XChangeProperty (display
, window
, reply
.property
, type
, format
,
863 PropModeReplace
, data
, 0);
864 TRACE0 ("Done sending incrementally");
867 /* rms, 2003-01-03: I think I have fixed this bug. */
868 /* The window we're communicating with may have been deleted
869 in the meantime (that's a real situation from a bug report).
870 In this case, there may be events in the event queue still
871 refering to the deleted window, and we'll get a BadWindow error
872 in XTread_socket when processing the events. I don't have
873 an idea how to fix that. gerd, 2001-01-98. */
874 /* 2004-09-10: XSync and UNBLOCK so that possible protocol errors are
875 delivered before uncatch errors. */
876 XSync (display
, False
);
879 /* GTK queues events in addition to the queue in Xlib. So we
880 UNBLOCK to enter the event loop and get possible errors delivered,
881 and then BLOCK again because x_uncatch_errors requires it. */
883 /* This calls x_uncatch_errors. */
884 unbind_to (count
, Qnil
);
888 /* Handle a SelectionRequest event EVENT.
889 This is called from keyboard.c when such an event is found in the queue. */
892 x_handle_selection_request (event
)
893 struct input_event
*event
;
895 struct gcpro gcpro1
, gcpro2
, gcpro3
;
896 Lisp_Object local_selection_data
;
897 Lisp_Object selection_symbol
;
898 Lisp_Object target_symbol
;
899 Lisp_Object converted_selection
;
900 Time local_selection_time
;
901 Lisp_Object successful_p
;
903 struct x_display_info
*dpyinfo
904 = x_display_info_for_display (SELECTION_EVENT_DISPLAY (event
));
906 TRACE2 ("x_handle_selection_request, from=0x%08lx time=%lu",
907 (unsigned long) SELECTION_EVENT_REQUESTOR (event
),
908 (unsigned long) SELECTION_EVENT_TIME (event
));
910 local_selection_data
= Qnil
;
911 target_symbol
= Qnil
;
912 converted_selection
= Qnil
;
915 GCPRO3 (local_selection_data
, converted_selection
, target_symbol
);
917 selection_symbol
= x_atom_to_symbol (SELECTION_EVENT_DISPLAY (event
),
918 SELECTION_EVENT_SELECTION (event
));
920 local_selection_data
= assq_no_quit (selection_symbol
, Vselection_alist
);
922 if (NILP (local_selection_data
))
924 /* Someone asked for the selection, but we don't have it any more.
926 x_decline_selection_request (event
);
930 local_selection_time
= (Time
)
931 cons_to_long (XCAR (XCDR (XCDR (local_selection_data
))));
933 if (SELECTION_EVENT_TIME (event
) != CurrentTime
934 && local_selection_time
> SELECTION_EVENT_TIME (event
))
936 /* Someone asked for the selection, and we have one, but not the one
939 x_decline_selection_request (event
);
943 x_selection_current_request
= event
;
944 count
= SPECPDL_INDEX ();
945 selection_request_dpyinfo
= dpyinfo
;
946 record_unwind_protect (x_selection_request_lisp_error
, Qnil
);
948 target_symbol
= x_atom_to_symbol (SELECTION_EVENT_DISPLAY (event
),
949 SELECTION_EVENT_TARGET (event
));
951 #if 0 /* #### MULTIPLE doesn't work yet */
952 if (EQ (target_symbol
, QMULTIPLE
))
953 target_symbol
= fetch_multiple_target (event
);
956 /* Convert lisp objects back into binary data */
959 = x_get_local_selection (selection_symbol
, target_symbol
, 0);
961 if (! NILP (converted_selection
))
969 lisp_data_to_selection_data (SELECTION_EVENT_DISPLAY (event
),
971 &data
, &type
, &size
, &format
, &nofree
);
973 x_reply_selection_request (event
, format
, data
, size
, type
);
976 /* Indicate we have successfully processed this event. */
977 x_selection_current_request
= 0;
979 /* Use xfree, not XFree, because lisp_data_to_selection_data
980 calls xmalloc itself. */
984 unbind_to (count
, Qnil
);
988 /* Let random lisp code notice that the selection has been asked for. */
991 rest
= Vx_sent_selection_functions
;
992 if (!EQ (rest
, Qunbound
))
993 for (; CONSP (rest
); rest
= Fcdr (rest
))
994 call3 (Fcar (rest
), selection_symbol
, target_symbol
, successful_p
);
1000 /* Handle a SelectionClear event EVENT, which indicates that some
1001 client cleared out our previously asserted selection.
1002 This is called from keyboard.c when such an event is found in the queue. */
1005 x_handle_selection_clear (event
)
1006 struct input_event
*event
;
1008 Display
*display
= SELECTION_EVENT_DISPLAY (event
);
1009 Atom selection
= SELECTION_EVENT_SELECTION (event
);
1010 Time changed_owner_time
= SELECTION_EVENT_TIME (event
);
1012 Lisp_Object selection_symbol
, local_selection_data
;
1013 Time local_selection_time
;
1014 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1015 struct x_display_info
*t_dpyinfo
;
1017 TRACE0 ("x_handle_selection_clear");
1019 /* If the new selection owner is also Emacs,
1020 don't clear the new selection. */
1022 /* Check each display on the same terminal,
1023 to see if this Emacs job now owns the selection
1024 through that display. */
1025 for (t_dpyinfo
= x_display_list
; t_dpyinfo
; t_dpyinfo
= t_dpyinfo
->next
)
1026 if (t_dpyinfo
->terminal
->kboard
== dpyinfo
->terminal
->kboard
)
1029 = XGetSelectionOwner (t_dpyinfo
->display
, selection
);
1030 if (x_window_to_frame (t_dpyinfo
, owner_window
) != 0)
1038 selection_symbol
= x_atom_to_symbol (display
, selection
);
1040 local_selection_data
= assq_no_quit (selection_symbol
, Vselection_alist
);
1042 /* Well, we already believe that we don't own it, so that's just fine. */
1043 if (NILP (local_selection_data
)) return;
1045 local_selection_time
= (Time
)
1046 cons_to_long (XCAR (XCDR (XCDR (local_selection_data
))));
1048 /* This SelectionClear is for a selection that we no longer own, so we can
1049 disregard it. (That is, we have reasserted the selection since this
1050 request was generated.) */
1052 if (changed_owner_time
!= CurrentTime
1053 && local_selection_time
> changed_owner_time
)
1056 /* Otherwise, we're really honest and truly being told to drop it.
1057 Don't use Fdelq as that may QUIT;. */
1059 if (EQ (local_selection_data
, Fcar (Vselection_alist
)))
1060 Vselection_alist
= Fcdr (Vselection_alist
);
1064 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
1065 if (EQ (local_selection_data
, Fcar (XCDR (rest
))))
1067 XSETCDR (rest
, Fcdr (XCDR (rest
)));
1072 /* Let random lisp code notice that the selection has been stolen. */
1076 rest
= Vx_lost_selection_functions
;
1077 if (!EQ (rest
, Qunbound
))
1079 for (; CONSP (rest
); rest
= Fcdr (rest
))
1080 call1 (Fcar (rest
), selection_symbol
);
1081 prepare_menu_bars ();
1082 redisplay_preserve_echo_area (20);
1088 x_handle_selection_event (event
)
1089 struct input_event
*event
;
1091 TRACE0 ("x_handle_selection_event");
1093 if (event
->kind
== SELECTION_REQUEST_EVENT
)
1095 if (x_queue_selection_requests
)
1096 x_queue_event (event
);
1098 x_handle_selection_request (event
);
1101 x_handle_selection_clear (event
);
1105 /* Clear all selections that were made from frame F.
1106 We do this when about to delete a frame. */
1109 x_clear_frame_selections (f
)
1115 XSETFRAME (frame
, f
);
1117 /* Otherwise, we're really honest and truly being told to drop it.
1118 Don't use Fdelq as that may QUIT;. */
1120 /* Delete elements from the beginning of Vselection_alist. */
1121 while (!NILP (Vselection_alist
)
1122 && EQ (frame
, Fcar (Fcdr (Fcdr (Fcdr (Fcar (Vselection_alist
)))))))
1124 /* Let random Lisp code notice that the selection has been stolen. */
1125 Lisp_Object hooks
, selection_symbol
;
1127 hooks
= Vx_lost_selection_functions
;
1128 selection_symbol
= Fcar (Fcar (Vselection_alist
));
1130 if (!EQ (hooks
, Qunbound
))
1132 for (; CONSP (hooks
); hooks
= Fcdr (hooks
))
1133 call1 (Fcar (hooks
), selection_symbol
);
1134 #if 0 /* This can crash when deleting a frame
1135 from x_connection_closed. Anyway, it seems unnecessary;
1136 something else should cause a redisplay. */
1137 redisplay_preserve_echo_area (21);
1141 Vselection_alist
= Fcdr (Vselection_alist
);
1144 /* Delete elements after the beginning of Vselection_alist. */
1145 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
1146 if (EQ (frame
, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest
))))))))
1148 /* Let random Lisp code notice that the selection has been stolen. */
1149 Lisp_Object hooks
, selection_symbol
;
1151 hooks
= Vx_lost_selection_functions
;
1152 selection_symbol
= Fcar (Fcar (XCDR (rest
)));
1154 if (!EQ (hooks
, Qunbound
))
1156 for (; CONSP (hooks
); hooks
= Fcdr (hooks
))
1157 call1 (Fcar (hooks
), selection_symbol
);
1158 #if 0 /* See above */
1159 redisplay_preserve_echo_area (22);
1162 XSETCDR (rest
, Fcdr (XCDR (rest
)));
1167 /* Nonzero if any properties for DISPLAY and WINDOW
1168 are on the list of what we are waiting for. */
1171 waiting_for_other_props_on_window (display
, window
)
1175 struct prop_location
*rest
= property_change_wait_list
;
1177 if (rest
->display
== display
&& rest
->window
== window
)
1184 /* Add an entry to the list of property changes we are waiting for.
1185 DISPLAY, WINDOW, PROPERTY, STATE describe what we will wait for.
1186 The return value is a number that uniquely identifies
1187 this awaited property change. */
1189 static struct prop_location
*
1190 expect_property_change (display
, window
, property
, state
)
1196 struct prop_location
*pl
= (struct prop_location
*) xmalloc (sizeof *pl
);
1197 pl
->identifier
= ++prop_location_identifier
;
1198 pl
->display
= display
;
1199 pl
->window
= window
;
1200 pl
->property
= property
;
1201 pl
->desired_state
= state
;
1202 pl
->next
= property_change_wait_list
;
1204 property_change_wait_list
= pl
;
1208 /* Delete an entry from the list of property changes we are waiting for.
1209 IDENTIFIER is the number that uniquely identifies the entry. */
1212 unexpect_property_change (location
)
1213 struct prop_location
*location
;
1215 struct prop_location
*prev
= 0, *rest
= property_change_wait_list
;
1218 if (rest
== location
)
1221 prev
->next
= rest
->next
;
1223 property_change_wait_list
= rest
->next
;
1232 /* Remove the property change expectation element for IDENTIFIER. */
1235 wait_for_property_change_unwind (loc
)
1238 struct prop_location
*location
= XSAVE_VALUE (loc
)->pointer
;
1240 unexpect_property_change (location
);
1241 if (location
== property_change_reply_object
)
1242 property_change_reply_object
= 0;
1246 /* Actually wait for a property change.
1247 IDENTIFIER should be the value that expect_property_change returned. */
1250 wait_for_property_change (location
)
1251 struct prop_location
*location
;
1254 int count
= SPECPDL_INDEX ();
1256 if (property_change_reply_object
)
1259 /* Make sure to do unexpect_property_change if we quit or err. */
1260 record_unwind_protect (wait_for_property_change_unwind
,
1261 make_save_value (location
, 0));
1263 XSETCAR (property_change_reply
, Qnil
);
1264 property_change_reply_object
= location
;
1266 /* If the event we are waiting for arrives beyond here, it will set
1267 property_change_reply, because property_change_reply_object says so. */
1268 if (! location
->arrived
)
1270 secs
= x_selection_timeout
/ 1000;
1271 usecs
= (x_selection_timeout
% 1000) * 1000;
1272 TRACE2 (" Waiting %d secs, %d usecs", secs
, usecs
);
1273 wait_reading_process_output (secs
, usecs
, 0, 0,
1274 property_change_reply
, NULL
, 0);
1276 if (NILP (XCAR (property_change_reply
)))
1278 TRACE0 (" Timed out");
1279 error ("Timed out waiting for property-notify event");
1283 unbind_to (count
, Qnil
);
1286 /* Called from XTread_socket in response to a PropertyNotify event. */
1289 x_handle_property_notify (event
)
1290 XPropertyEvent
*event
;
1292 struct prop_location
*prev
= 0, *rest
= property_change_wait_list
;
1297 && rest
->property
== event
->atom
1298 && rest
->window
== event
->window
1299 && rest
->display
== event
->display
1300 && rest
->desired_state
== event
->state
)
1302 TRACE2 ("Expected %s of property %s",
1303 (event
->state
== PropertyDelete
? "deletion" : "change"),
1304 XGetAtomName (event
->display
, event
->atom
));
1308 /* If this is the one wait_for_property_change is waiting for,
1309 tell it to wake up. */
1310 if (rest
== property_change_reply_object
)
1311 XSETCAR (property_change_reply
, Qt
);
1323 #if 0 /* #### MULTIPLE doesn't work yet */
1326 fetch_multiple_target (event
)
1327 XSelectionRequestEvent
*event
;
1329 Display
*display
= event
->display
;
1330 Window window
= event
->requestor
;
1331 Atom target
= event
->target
;
1332 Atom selection_atom
= event
->selection
;
1337 x_get_window_property_as_lisp_data (display
, window
, target
,
1338 QMULTIPLE
, selection_atom
));
1342 copy_multiple_data (obj
)
1349 return Fcons (XCAR (obj
), copy_multiple_data (XCDR (obj
)));
1352 vec
= Fmake_vector (size
= XVECTOR (obj
)->size
, Qnil
);
1353 for (i
= 0; i
< size
; i
++)
1355 Lisp_Object vec2
= XVECTOR (obj
)->contents
[i
];
1356 CHECK_VECTOR (vec2
);
1357 if (XVECTOR (vec2
)->size
!= 2)
1358 /* ??? Confusing error message */
1359 Fsignal (Qerror
, Fcons (build_string ("vectors must be of length 2"),
1360 Fcons (vec2
, Qnil
)));
1361 XVECTOR (vec
)->contents
[i
] = Fmake_vector (2, Qnil
);
1362 XVECTOR (XVECTOR (vec
)->contents
[i
])->contents
[0]
1363 = XVECTOR (vec2
)->contents
[0];
1364 XVECTOR (XVECTOR (vec
)->contents
[i
])->contents
[1]
1365 = XVECTOR (vec2
)->contents
[1];
1373 /* Variables for communication with x_handle_selection_notify. */
1374 static Atom reading_which_selection
;
1375 static Lisp_Object reading_selection_reply
;
1376 static Window reading_selection_window
;
1378 /* Do protocol to read selection-data from the server.
1379 Converts this to Lisp data and returns it. */
1382 x_get_foreign_selection (selection_symbol
, target_type
, time_stamp
)
1383 Lisp_Object selection_symbol
, target_type
, time_stamp
;
1385 struct frame
*sf
= SELECTED_FRAME ();
1386 Window requestor_window
;
1388 struct x_display_info
*dpyinfo
;
1389 Time requestor_time
= last_event_timestamp
;
1390 Atom target_property
;
1391 Atom selection_atom
;
1394 int count
= SPECPDL_INDEX ();
1397 if (! FRAME_X_P (sf
))
1400 requestor_window
= FRAME_X_WINDOW (sf
);
1401 display
= FRAME_X_DISPLAY (sf
);
1402 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
1403 target_property
= dpyinfo
->Xatom_EMACS_TMP
;
1404 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection_symbol
);
1406 if (CONSP (target_type
))
1407 type_atom
= symbol_to_x_atom (dpyinfo
, display
, XCAR (target_type
));
1409 type_atom
= symbol_to_x_atom (dpyinfo
, display
, target_type
);
1411 if (! NILP (time_stamp
))
1413 if (CONSP (time_stamp
))
1414 requestor_time
= (Time
) cons_to_long (time_stamp
);
1415 else if (INTEGERP (time_stamp
))
1416 requestor_time
= (Time
) XUINT (time_stamp
);
1417 else if (FLOATP (time_stamp
))
1418 requestor_time
= (Time
) XFLOAT_DATA (time_stamp
);
1420 error ("TIME_STAMP must be cons or number");
1425 /* The protected block contains wait_reading_process_output, which
1426 can run random lisp code (process handlers) or signal.
1427 Therefore, we put the x_uncatch_errors call in an unwind. */
1428 record_unwind_protect (x_catch_errors_unwind
, Qnil
);
1429 x_catch_errors (display
);
1431 TRACE2 ("Get selection %s, type %s",
1432 XGetAtomName (display
, type_atom
),
1433 XGetAtomName (display
, target_property
));
1435 XConvertSelection (display
, selection_atom
, type_atom
, target_property
,
1436 requestor_window
, requestor_time
);
1439 /* Prepare to block until the reply has been read. */
1440 reading_selection_window
= requestor_window
;
1441 reading_which_selection
= selection_atom
;
1442 XSETCAR (reading_selection_reply
, Qnil
);
1444 frame
= some_frame_on_display (dpyinfo
);
1446 /* If the display no longer has frames, we can't expect
1447 to get many more selection requests from it, so don't
1448 bother trying to queue them. */
1451 x_start_queuing_selection_requests ();
1453 record_unwind_protect (queue_selection_requests_unwind
,
1458 /* This allows quits. Also, don't wait forever. */
1459 secs
= x_selection_timeout
/ 1000;
1460 usecs
= (x_selection_timeout
% 1000) * 1000;
1461 TRACE1 (" Start waiting %d secs for SelectionNotify", secs
);
1462 wait_reading_process_output (secs
, usecs
, 0, 0,
1463 reading_selection_reply
, NULL
, 0);
1464 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply
)));
1467 if (x_had_errors_p (display
))
1468 error ("Cannot get selection");
1469 /* This calls x_uncatch_errors. */
1470 unbind_to (count
, Qnil
);
1473 if (NILP (XCAR (reading_selection_reply
)))
1474 error ("Timed out waiting for reply from selection owner");
1475 if (EQ (XCAR (reading_selection_reply
), Qlambda
))
1476 error ("No `%s' selection", SDATA (SYMBOL_NAME (selection_symbol
)));
1478 /* Otherwise, the selection is waiting for us on the requested property. */
1480 x_get_window_property_as_lisp_data (display
, requestor_window
,
1481 target_property
, target_type
,
1485 /* Subroutines of x_get_window_property_as_lisp_data */
1487 /* Use xfree, not XFree, to free the data obtained with this function. */
1490 x_get_window_property (display
, window
, property
, data_ret
, bytes_ret
,
1491 actual_type_ret
, actual_format_ret
, actual_size_ret
,
1496 unsigned char **data_ret
;
1498 Atom
*actual_type_ret
;
1499 int *actual_format_ret
;
1500 unsigned long *actual_size_ret
;
1504 unsigned long bytes_remaining
;
1506 unsigned char *tmp_data
= 0;
1508 int buffer_size
= SELECTION_QUANTUM (display
);
1510 if (buffer_size
> MAX_SELECTION_QUANTUM
)
1511 buffer_size
= MAX_SELECTION_QUANTUM
;
1515 /* First probe the thing to find out how big it is. */
1516 result
= XGetWindowProperty (display
, window
, property
,
1517 0L, 0L, False
, AnyPropertyType
,
1518 actual_type_ret
, actual_format_ret
,
1520 &bytes_remaining
, &tmp_data
);
1521 if (result
!= Success
)
1529 /* This was allocated by Xlib, so use XFree. */
1530 XFree ((char *) tmp_data
);
1532 if (*actual_type_ret
== None
|| *actual_format_ret
== 0)
1538 total_size
= bytes_remaining
+ 1;
1539 *data_ret
= (unsigned char *) xmalloc (total_size
);
1541 /* Now read, until we've gotten it all. */
1542 while (bytes_remaining
)
1544 #ifdef TRACE_SELECTION
1545 int last
= bytes_remaining
;
1548 = XGetWindowProperty (display
, window
, property
,
1549 (long)offset
/4, (long)buffer_size
/4,
1552 actual_type_ret
, actual_format_ret
,
1553 actual_size_ret
, &bytes_remaining
, &tmp_data
);
1555 TRACE2 ("Read %ld bytes from property %s",
1556 last
- bytes_remaining
,
1557 XGetAtomName (display
, property
));
1559 /* If this doesn't return Success at this point, it means that
1560 some clod deleted the selection while we were in the midst of
1561 reading it. Deal with that, I guess.... */
1562 if (result
!= Success
)
1565 /* The man page for XGetWindowProperty says:
1566 "If the returned format is 32, the returned data is represented
1567 as a long array and should be cast to that type to obtain the
1569 This applies even if long is more than 32 bits, the X library
1570 converts from 32 bit elements received from the X server to long
1571 and passes the long array to us. Thus, for that case bcopy can not
1572 be used. We convert to a 32 bit type here, because so much code
1575 The bytes and offsets passed to XGetWindowProperty refers to the
1576 property and those are indeed in 32 bit quantities if format is 32. */
1578 if (*actual_format_ret
== 32 && *actual_format_ret
< BITS_PER_LONG
)
1581 int *idata
= (int *) ((*data_ret
) + offset
);
1582 long *ldata
= (long *) tmp_data
;
1584 for (i
= 0; i
< *actual_size_ret
; ++i
)
1586 idata
[i
]= (int) ldata
[i
];
1592 *actual_size_ret
*= *actual_format_ret
/ 8;
1593 bcopy (tmp_data
, (*data_ret
) + offset
, *actual_size_ret
);
1594 offset
+= *actual_size_ret
;
1597 /* This was allocated by Xlib, so use XFree. */
1598 XFree ((char *) tmp_data
);
1603 *bytes_ret
= offset
;
1606 /* Use xfree, not XFree, to free the data obtained with this function. */
1609 receive_incremental_selection (display
, window
, property
, target_type
,
1610 min_size_bytes
, data_ret
, size_bytes_ret
,
1611 type_ret
, format_ret
, size_ret
)
1615 Lisp_Object target_type
; /* for error messages only */
1616 unsigned int min_size_bytes
;
1617 unsigned char **data_ret
;
1618 int *size_bytes_ret
;
1620 unsigned long *size_ret
;
1624 struct prop_location
*wait_object
;
1625 *size_bytes_ret
= min_size_bytes
;
1626 *data_ret
= (unsigned char *) xmalloc (*size_bytes_ret
);
1628 TRACE1 ("Read %d bytes incrementally", min_size_bytes
);
1630 /* At this point, we have read an INCR property.
1631 Delete the property to ack it.
1632 (But first, prepare to receive the next event in this handshake.)
1634 Now, we must loop, waiting for the sending window to put a value on
1635 that property, then reading the property, then deleting it to ack.
1636 We are done when the sender places a property of length 0.
1639 XSelectInput (display
, window
, STANDARD_EVENT_SET
| PropertyChangeMask
);
1640 TRACE1 (" Delete property %s",
1641 SDATA (SYMBOL_NAME (x_atom_to_symbol (display
, property
))));
1642 XDeleteProperty (display
, window
, property
);
1643 TRACE1 (" Expect new value of property %s",
1644 SDATA (SYMBOL_NAME (x_atom_to_symbol (display
, property
))));
1645 wait_object
= expect_property_change (display
, window
, property
,
1652 unsigned char *tmp_data
;
1655 TRACE0 (" Wait for property change");
1656 wait_for_property_change (wait_object
);
1658 /* expect it again immediately, because x_get_window_property may
1659 .. no it won't, I don't get it.
1660 .. Ok, I get it now, the Xt code that implements INCR is broken. */
1661 TRACE0 (" Get property value");
1662 x_get_window_property (display
, window
, property
,
1663 &tmp_data
, &tmp_size_bytes
,
1664 type_ret
, format_ret
, size_ret
, 1);
1666 TRACE1 (" Read increment of %d bytes", tmp_size_bytes
);
1668 if (tmp_size_bytes
== 0) /* we're done */
1670 TRACE0 ("Done reading incrementally");
1672 if (! waiting_for_other_props_on_window (display
, window
))
1673 XSelectInput (display
, window
, STANDARD_EVENT_SET
);
1674 /* Use xfree, not XFree, because x_get_window_property
1675 calls xmalloc itself. */
1676 if (tmp_data
) xfree (tmp_data
);
1681 TRACE1 (" ACK by deleting property %s",
1682 XGetAtomName (display
, property
));
1683 XDeleteProperty (display
, window
, property
);
1684 wait_object
= expect_property_change (display
, window
, property
,
1689 if (*size_bytes_ret
< offset
+ tmp_size_bytes
)
1691 *size_bytes_ret
= offset
+ tmp_size_bytes
;
1692 *data_ret
= (unsigned char *) xrealloc (*data_ret
, *size_bytes_ret
);
1695 bcopy (tmp_data
, (*data_ret
) + offset
, tmp_size_bytes
);
1696 offset
+= tmp_size_bytes
;
1698 /* Use xfree, not XFree, because x_get_window_property
1699 calls xmalloc itself. */
1705 /* Once a requested selection is "ready" (we got a SelectionNotify event),
1706 fetch value from property PROPERTY of X window WINDOW on display DISPLAY.
1707 TARGET_TYPE and SELECTION_ATOM are used in error message if this fails. */
1710 x_get_window_property_as_lisp_data (display
, window
, property
, target_type
,
1715 Lisp_Object target_type
; /* for error messages only */
1716 Atom selection_atom
; /* for error messages only */
1720 unsigned long actual_size
;
1721 unsigned char *data
= 0;
1724 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1726 TRACE0 ("Reading selection data");
1728 x_get_window_property (display
, window
, property
, &data
, &bytes
,
1729 &actual_type
, &actual_format
, &actual_size
, 1);
1732 int there_is_a_selection_owner
;
1734 there_is_a_selection_owner
1735 = XGetSelectionOwner (display
, selection_atom
);
1738 there_is_a_selection_owner
1739 ? Fcons (build_string ("selection owner couldn't convert"),
1741 ? Fcons (target_type
,
1742 Fcons (x_atom_to_symbol (display
,
1745 : Fcons (target_type
, Qnil
))
1746 : Fcons (build_string ("no selection"),
1747 Fcons (x_atom_to_symbol (display
,
1752 if (actual_type
== dpyinfo
->Xatom_INCR
)
1754 /* That wasn't really the data, just the beginning. */
1756 unsigned int min_size_bytes
= * ((unsigned int *) data
);
1758 /* Use xfree, not XFree, because x_get_window_property
1759 calls xmalloc itself. */
1760 xfree ((char *) data
);
1762 receive_incremental_selection (display
, window
, property
, target_type
,
1763 min_size_bytes
, &data
, &bytes
,
1764 &actual_type
, &actual_format
,
1769 TRACE1 (" Delete property %s", XGetAtomName (display
, property
));
1770 XDeleteProperty (display
, window
, property
);
1774 /* It's been read. Now convert it to a lisp object in some semi-rational
1776 val
= selection_data_to_lisp_data (display
, data
, bytes
,
1777 actual_type
, actual_format
);
1779 /* Use xfree, not XFree, because x_get_window_property
1780 calls xmalloc itself. */
1781 xfree ((char *) data
);
1785 /* These functions convert from the selection data read from the server into
1786 something that we can use from Lisp, and vice versa.
1788 Type: Format: Size: Lisp Type:
1789 ----- ------- ----- -----------
1792 ATOM 32 > 1 Vector of Symbols
1794 * 16 > 1 Vector of Integers
1795 * 32 1 if <=16 bits: Integer
1796 if > 16 bits: Cons of top16, bot16
1797 * 32 > 1 Vector of the above
1799 When converting a Lisp number to C, it is assumed to be of format 16 if
1800 it is an integer, and of format 32 if it is a cons of two integers.
1802 When converting a vector of numbers from Lisp to C, it is assumed to be
1803 of format 16 if every element in the vector is an integer, and is assumed
1804 to be of format 32 if any element is a cons of two integers.
1806 When converting an object to C, it may be of the form (SYMBOL . <data>)
1807 where SYMBOL is what we should claim that the type is. Format and
1808 representation are as above.
1810 Important: When format is 32, data should contain an array of int,
1811 not an array of long as the X library returns. This makes a difference
1812 when sizeof(long) != sizeof(int). */
1817 selection_data_to_lisp_data (display
, data
, size
, type
, format
)
1819 unsigned char *data
;
1823 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1825 if (type
== dpyinfo
->Xatom_NULL
)
1828 /* Convert any 8-bit data to a string, for compactness. */
1829 else if (format
== 8)
1831 Lisp_Object str
, lispy_type
;
1833 str
= make_unibyte_string ((char *) data
, size
);
1834 /* Indicate that this string is from foreign selection by a text
1835 property `foreign-selection' so that the caller of
1836 x-get-selection-internal (usually x-get-selection) can know
1837 that the string must be decode. */
1838 if (type
== dpyinfo
->Xatom_COMPOUND_TEXT
)
1839 lispy_type
= QCOMPOUND_TEXT
;
1840 else if (type
== dpyinfo
->Xatom_UTF8_STRING
)
1841 lispy_type
= QUTF8_STRING
;
1843 lispy_type
= QSTRING
;
1844 Fput_text_property (make_number (0), make_number (size
),
1845 Qforeign_selection
, lispy_type
, str
);
1848 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to
1849 a vector of symbols.
1851 else if (type
== XA_ATOM
)
1854 /* On a 64 bit machine sizeof(Atom) == sizeof(long) == 8.
1855 But the callers of these function has made sure the data for
1856 format == 32 is an array of int. Thus, use int instead
1858 int *idata
= (int *) data
;
1860 if (size
== sizeof (int))
1861 return x_atom_to_symbol (display
, (Atom
) idata
[0]);
1864 Lisp_Object v
= Fmake_vector (make_number (size
/ sizeof (int)),
1866 for (i
= 0; i
< size
/ sizeof (int); i
++)
1867 Faset (v
, make_number (i
),
1868 x_atom_to_symbol (display
, (Atom
) idata
[i
]));
1873 /* Convert a single 16 or small 32 bit number to a Lisp_Int.
1874 If the number is > 16 bits, convert it to a cons of integers,
1875 16 bits in each half.
1877 else if (format
== 32 && size
== sizeof (int))
1878 return long_to_cons (((unsigned int *) data
) [0]);
1879 else if (format
== 16 && size
== sizeof (short))
1880 return make_number ((int) (((unsigned short *) data
) [0]));
1882 /* Convert any other kind of data to a vector of numbers, represented
1883 as above (as an integer, or a cons of two 16 bit integers.)
1885 else if (format
== 16)
1889 v
= Fmake_vector (make_number (size
/ 2), make_number (0));
1890 for (i
= 0; i
< size
/ 2; i
++)
1892 int j
= (int) ((unsigned short *) data
) [i
];
1893 Faset (v
, make_number (i
), make_number (j
));
1900 Lisp_Object v
= Fmake_vector (make_number (size
/ 4), make_number (0));
1901 for (i
= 0; i
< size
/ 4; i
++)
1903 unsigned int j
= ((unsigned int *) data
) [i
];
1904 Faset (v
, make_number (i
), long_to_cons (j
));
1911 /* Use xfree, not XFree, to free the data obtained with this function. */
1914 lisp_data_to_selection_data (display
, obj
,
1915 data_ret
, type_ret
, size_ret
,
1916 format_ret
, nofree_ret
)
1919 unsigned char **data_ret
;
1921 unsigned int *size_ret
;
1925 Lisp_Object type
= Qnil
;
1926 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1930 if (CONSP (obj
) && SYMBOLP (XCAR (obj
)))
1934 if (CONSP (obj
) && NILP (XCDR (obj
)))
1938 if (EQ (obj
, QNULL
) || (EQ (type
, QNULL
)))
1939 { /* This is not the same as declining */
1945 else if (STRINGP (obj
))
1947 if (SCHARS (obj
) < SBYTES (obj
))
1948 /* OBJ is a multibyte string containing a non-ASCII char. */
1949 Fsignal (Qerror
, /* Qselection_error */
1951 ("Non-ASCII string must be encoded in advance"),
1952 Fcons (obj
, Qnil
)));
1956 *size_ret
= SBYTES (obj
);
1957 *data_ret
= SDATA (obj
);
1960 else if (SYMBOLP (obj
))
1964 *data_ret
= (unsigned char *) xmalloc (sizeof (Atom
) + 1);
1965 (*data_ret
) [sizeof (Atom
)] = 0;
1966 (*(Atom
**) data_ret
) [0] = symbol_to_x_atom (dpyinfo
, display
, obj
);
1967 if (NILP (type
)) type
= QATOM
;
1969 else if (INTEGERP (obj
)
1970 && XINT (obj
) < 0xFFFF
1971 && XINT (obj
) > -0xFFFF)
1975 *data_ret
= (unsigned char *) xmalloc (sizeof (short) + 1);
1976 (*data_ret
) [sizeof (short)] = 0;
1977 (*(short **) data_ret
) [0] = (short) XINT (obj
);
1978 if (NILP (type
)) type
= QINTEGER
;
1980 else if (INTEGERP (obj
)
1981 || (CONSP (obj
) && INTEGERP (XCAR (obj
))
1982 && (INTEGERP (XCDR (obj
))
1983 || (CONSP (XCDR (obj
))
1984 && INTEGERP (XCAR (XCDR (obj
)))))))
1988 *data_ret
= (unsigned char *) xmalloc (sizeof (long) + 1);
1989 (*data_ret
) [sizeof (long)] = 0;
1990 (*(unsigned long **) data_ret
) [0] = cons_to_long (obj
);
1991 if (NILP (type
)) type
= QINTEGER
;
1993 else if (VECTORP (obj
))
1995 /* Lisp_Vectors may represent a set of ATOMs;
1996 a set of 16 or 32 bit INTEGERs;
1997 or a set of ATOM_PAIRs (represented as [[A1 A2] [A3 A4] ...]
2001 if (SYMBOLP (XVECTOR (obj
)->contents
[0]))
2002 /* This vector is an ATOM set */
2004 if (NILP (type
)) type
= QATOM
;
2005 *size_ret
= XVECTOR (obj
)->size
;
2007 *data_ret
= (unsigned char *) xmalloc ((*size_ret
) * sizeof (Atom
));
2008 for (i
= 0; i
< *size_ret
; i
++)
2009 if (SYMBOLP (XVECTOR (obj
)->contents
[i
]))
2010 (*(Atom
**) data_ret
) [i
]
2011 = symbol_to_x_atom (dpyinfo
, display
, XVECTOR (obj
)->contents
[i
]);
2013 Fsignal (Qerror
, /* Qselection_error */
2015 ("all elements of selection vector must have same type"),
2016 Fcons (obj
, Qnil
)));
2018 #if 0 /* #### MULTIPLE doesn't work yet */
2019 else if (VECTORP (XVECTOR (obj
)->contents
[0]))
2020 /* This vector is an ATOM_PAIR set */
2022 if (NILP (type
)) type
= QATOM_PAIR
;
2023 *size_ret
= XVECTOR (obj
)->size
;
2025 *data_ret
= (unsigned char *)
2026 xmalloc ((*size_ret
) * sizeof (Atom
) * 2);
2027 for (i
= 0; i
< *size_ret
; i
++)
2028 if (VECTORP (XVECTOR (obj
)->contents
[i
]))
2030 Lisp_Object pair
= XVECTOR (obj
)->contents
[i
];
2031 if (XVECTOR (pair
)->size
!= 2)
2034 ("elements of the vector must be vectors of exactly two elements"),
2035 Fcons (pair
, Qnil
)));
2037 (*(Atom
**) data_ret
) [i
* 2]
2038 = symbol_to_x_atom (dpyinfo
, display
,
2039 XVECTOR (pair
)->contents
[0]);
2040 (*(Atom
**) data_ret
) [(i
* 2) + 1]
2041 = symbol_to_x_atom (dpyinfo
, display
,
2042 XVECTOR (pair
)->contents
[1]);
2047 ("all elements of the vector must be of the same type"),
2048 Fcons (obj
, Qnil
)));
2053 /* This vector is an INTEGER set, or something like it */
2056 *size_ret
= XVECTOR (obj
)->size
;
2057 if (NILP (type
)) type
= QINTEGER
;
2059 for (i
= 0; i
< *size_ret
; i
++)
2060 if (CONSP (XVECTOR (obj
)->contents
[i
]))
2062 else if (!INTEGERP (XVECTOR (obj
)->contents
[i
]))
2063 Fsignal (Qerror
, /* Qselection_error */
2065 ("elements of selection vector must be integers or conses of integers"),
2066 Fcons (obj
, Qnil
)));
2068 /* Use sizeof(long) even if it is more than 32 bits. See comment
2069 in x_get_window_property and x_fill_property_data. */
2071 if (*format_ret
== 32) data_size
= sizeof(long);
2072 *data_ret
= (unsigned char *) xmalloc (*size_ret
* data_size
);
2073 for (i
= 0; i
< *size_ret
; i
++)
2074 if (*format_ret
== 32)
2075 (*((unsigned long **) data_ret
)) [i
]
2076 = cons_to_long (XVECTOR (obj
)->contents
[i
]);
2078 (*((unsigned short **) data_ret
)) [i
]
2079 = (unsigned short) cons_to_long (XVECTOR (obj
)->contents
[i
]);
2083 Fsignal (Qerror
, /* Qselection_error */
2084 Fcons (build_string ("unrecognized selection data"),
2085 Fcons (obj
, Qnil
)));
2087 *type_ret
= symbol_to_x_atom (dpyinfo
, display
, type
);
2091 clean_local_selection_data (obj
)
2095 && INTEGERP (XCAR (obj
))
2096 && CONSP (XCDR (obj
))
2097 && INTEGERP (XCAR (XCDR (obj
)))
2098 && NILP (XCDR (XCDR (obj
))))
2099 obj
= Fcons (XCAR (obj
), XCDR (obj
));
2102 && INTEGERP (XCAR (obj
))
2103 && INTEGERP (XCDR (obj
)))
2105 if (XINT (XCAR (obj
)) == 0)
2107 if (XINT (XCAR (obj
)) == -1)
2108 return make_number (- XINT (XCDR (obj
)));
2113 int size
= XVECTOR (obj
)->size
;
2116 return clean_local_selection_data (XVECTOR (obj
)->contents
[0]);
2117 copy
= Fmake_vector (make_number (size
), Qnil
);
2118 for (i
= 0; i
< size
; i
++)
2119 XVECTOR (copy
)->contents
[i
]
2120 = clean_local_selection_data (XVECTOR (obj
)->contents
[i
]);
2126 /* Called from XTread_socket to handle SelectionNotify events.
2127 If it's the selection we are waiting for, stop waiting
2128 by setting the car of reading_selection_reply to non-nil.
2129 We store t there if the reply is successful, lambda if not. */
2132 x_handle_selection_notify (event
)
2133 XSelectionEvent
*event
;
2135 if (event
->requestor
!= reading_selection_window
)
2137 if (event
->selection
!= reading_which_selection
)
2140 TRACE0 ("Received SelectionNotify");
2141 XSETCAR (reading_selection_reply
,
2142 (event
->property
!= 0 ? Qt
: Qlambda
));
2146 DEFUN ("x-own-selection-internal", Fx_own_selection_internal
,
2147 Sx_own_selection_internal
, 2, 2, 0,
2148 doc
: /* Assert an X selection of the given TYPE with the given VALUE.
2149 TYPE is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2150 \(Those are literal upper-case symbol names, since that's what X expects.)
2151 VALUE is typically a string, or a cons of two markers, but may be
2152 anything that the functions on `selection-converter-alist' know about. */)
2153 (selection_name
, selection_value
)
2154 Lisp_Object selection_name
, selection_value
;
2157 CHECK_SYMBOL (selection_name
);
2158 if (NILP (selection_value
)) error ("SELECTION-VALUE may not be nil");
2159 x_own_selection (selection_name
, selection_value
);
2160 return selection_value
;
2164 /* Request the selection value from the owner. If we are the owner,
2165 simply return our selection value. If we are not the owner, this
2166 will block until all of the data has arrived. */
2168 DEFUN ("x-get-selection-internal", Fx_get_selection_internal
,
2169 Sx_get_selection_internal
, 2, 3, 0,
2170 doc
: /* Return text selected from some X window.
2171 SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2172 \(Those are literal upper-case symbol names, since that's what X expects.)
2173 TYPE is the type of data desired, typically `STRING'.
2174 TIME_STAMP is the time to use in the XConvertSelection call for foreign
2175 selections. If omitted, defaults to the time for the last event. */)
2176 (selection_symbol
, target_type
, time_stamp
)
2177 Lisp_Object selection_symbol
, target_type
, time_stamp
;
2179 Lisp_Object val
= Qnil
;
2180 struct gcpro gcpro1
, gcpro2
;
2181 GCPRO2 (target_type
, val
); /* we store newly consed data into these */
2183 CHECK_SYMBOL (selection_symbol
);
2185 #if 0 /* #### MULTIPLE doesn't work yet */
2186 if (CONSP (target_type
)
2187 && XCAR (target_type
) == QMULTIPLE
)
2189 CHECK_VECTOR (XCDR (target_type
));
2190 /* So we don't destructively modify this... */
2191 target_type
= copy_multiple_data (target_type
);
2195 CHECK_SYMBOL (target_type
);
2197 val
= x_get_local_selection (selection_symbol
, target_type
, 1);
2201 val
= x_get_foreign_selection (selection_symbol
, target_type
, time_stamp
);
2206 && SYMBOLP (XCAR (val
)))
2209 if (CONSP (val
) && NILP (XCDR (val
)))
2212 val
= clean_local_selection_data (val
);
2218 DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal
,
2219 Sx_disown_selection_internal
, 1, 2, 0,
2220 doc
: /* If we own the selection SELECTION, disown it.
2221 Disowning it means there is no such selection. */)
2223 Lisp_Object selection
;
2227 Atom selection_atom
;
2229 struct selection_input_event sie
;
2230 struct input_event ie
;
2233 struct x_display_info
*dpyinfo
;
2234 struct frame
*sf
= SELECTED_FRAME ();
2237 if (! FRAME_X_P (sf
))
2240 display
= FRAME_X_DISPLAY (sf
);
2241 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2242 CHECK_SYMBOL (selection
);
2244 timestamp
= last_event_timestamp
;
2246 timestamp
= cons_to_long (time
);
2248 if (NILP (assq_no_quit (selection
, Vselection_alist
)))
2249 return Qnil
; /* Don't disown the selection when we're not the owner. */
2251 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection
);
2254 XSetSelectionOwner (display
, selection_atom
, None
, timestamp
);
2257 /* It doesn't seem to be guaranteed that a SelectionClear event will be
2258 generated for a window which owns the selection when that window sets
2259 the selection owner to None. The NCD server does, the MIT Sun4 server
2260 doesn't. So we synthesize one; this means we might get two, but
2261 that's ok, because the second one won't have any effect. */
2262 SELECTION_EVENT_DISPLAY (&event
.sie
) = display
;
2263 SELECTION_EVENT_SELECTION (&event
.sie
) = selection_atom
;
2264 SELECTION_EVENT_TIME (&event
.sie
) = timestamp
;
2265 x_handle_selection_clear (&event
.ie
);
2270 /* Get rid of all the selections in buffer BUFFER.
2271 This is used when we kill a buffer. */
2274 x_disown_buffer_selections (buffer
)
2278 struct buffer
*buf
= XBUFFER (buffer
);
2280 for (tail
= Vselection_alist
; CONSP (tail
); tail
= XCDR (tail
))
2282 Lisp_Object elt
, value
;
2285 if (CONSP (value
) && MARKERP (XCAR (value
))
2286 && XMARKER (XCAR (value
))->buffer
== buf
)
2287 Fx_disown_selection_internal (XCAR (elt
), Qnil
);
2291 DEFUN ("x-selection-owner-p", Fx_selection_owner_p
, Sx_selection_owner_p
,
2293 doc
: /* Whether the current Emacs process owns the given X Selection.
2294 The arg should be the name of the selection in question, typically one of
2295 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2296 \(Those are literal upper-case symbol names, since that's what X expects.)
2297 For convenience, the symbol nil is the same as `PRIMARY',
2298 and t is the same as `SECONDARY'. */)
2300 Lisp_Object selection
;
2303 CHECK_SYMBOL (selection
);
2304 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2305 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2307 if (NILP (Fassq (selection
, Vselection_alist
)))
2312 DEFUN ("x-selection-exists-p", Fx_selection_exists_p
, Sx_selection_exists_p
,
2314 doc
: /* Whether there is an owner for the given X Selection.
2315 The arg should be the name of the selection in question, typically one of
2316 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2317 \(Those are literal upper-case symbol names, since that's what X expects.)
2318 For convenience, the symbol nil is the same as `PRIMARY',
2319 and t is the same as `SECONDARY'. */)
2321 Lisp_Object selection
;
2326 struct frame
*sf
= SELECTED_FRAME ();
2328 /* It should be safe to call this before we have an X frame. */
2329 if (! FRAME_X_P (sf
))
2332 dpy
= FRAME_X_DISPLAY (sf
);
2333 CHECK_SYMBOL (selection
);
2334 if (!NILP (Fx_selection_owner_p (selection
)))
2336 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2337 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2338 atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
), dpy
, selection
);
2342 owner
= XGetSelectionOwner (dpy
, atom
);
2344 return (owner
? Qt
: Qnil
);
2348 #ifdef CUT_BUFFER_SUPPORT
2350 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
2352 initialize_cut_buffers (display
, window
)
2356 unsigned char *data
= (unsigned char *) "";
2358 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
2359 PropModeAppend, data, 0)
2360 FROB (XA_CUT_BUFFER0
);
2361 FROB (XA_CUT_BUFFER1
);
2362 FROB (XA_CUT_BUFFER2
);
2363 FROB (XA_CUT_BUFFER3
);
2364 FROB (XA_CUT_BUFFER4
);
2365 FROB (XA_CUT_BUFFER5
);
2366 FROB (XA_CUT_BUFFER6
);
2367 FROB (XA_CUT_BUFFER7
);
2373 #define CHECK_CUT_BUFFER(symbol) \
2374 { CHECK_SYMBOL ((symbol)); \
2375 if (!EQ((symbol), QCUT_BUFFER0) && !EQ((symbol), QCUT_BUFFER1) \
2376 && !EQ((symbol), QCUT_BUFFER2) && !EQ((symbol), QCUT_BUFFER3) \
2377 && !EQ((symbol), QCUT_BUFFER4) && !EQ((symbol), QCUT_BUFFER5) \
2378 && !EQ((symbol), QCUT_BUFFER6) && !EQ((symbol), QCUT_BUFFER7)) \
2380 Fcons (build_string ("doesn't name a cut buffer"), \
2381 Fcons ((symbol), Qnil))); \
2384 DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal
,
2385 Sx_get_cut_buffer_internal
, 1, 1, 0,
2386 doc
: /* Returns the value of the named cut buffer (typically CUT_BUFFER0). */)
2392 unsigned char *data
;
2399 struct x_display_info
*dpyinfo
;
2400 struct frame
*sf
= SELECTED_FRAME ();
2404 if (! FRAME_X_P (sf
))
2407 display
= FRAME_X_DISPLAY (sf
);
2408 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2409 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2410 CHECK_CUT_BUFFER (buffer
);
2411 buffer_atom
= symbol_to_x_atom (dpyinfo
, display
, buffer
);
2413 x_get_window_property (display
, window
, buffer_atom
, &data
, &bytes
,
2414 &type
, &format
, &size
, 0);
2415 if (!data
|| !format
)
2418 if (format
!= 8 || type
!= XA_STRING
)
2420 Fcons (build_string ("cut buffer doesn't contain 8-bit data"),
2421 Fcons (x_atom_to_symbol (display
, type
),
2422 Fcons (make_number (format
), Qnil
))));
2424 ret
= (bytes
? make_unibyte_string ((char *) data
, bytes
) : Qnil
);
2425 /* Use xfree, not XFree, because x_get_window_property
2426 calls xmalloc itself. */
2432 DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal
,
2433 Sx_store_cut_buffer_internal
, 2, 2, 0,
2434 doc
: /* Sets the value of the named cut buffer (typically CUT_BUFFER0). */)
2436 Lisp_Object buffer
, string
;
2440 unsigned char *data
;
2442 int bytes_remaining
;
2445 struct frame
*sf
= SELECTED_FRAME ();
2449 if (! FRAME_X_P (sf
))
2452 display
= FRAME_X_DISPLAY (sf
);
2453 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2455 max_bytes
= SELECTION_QUANTUM (display
);
2456 if (max_bytes
> MAX_SELECTION_QUANTUM
)
2457 max_bytes
= MAX_SELECTION_QUANTUM
;
2459 CHECK_CUT_BUFFER (buffer
);
2460 CHECK_STRING (string
);
2461 buffer_atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
),
2463 data
= (unsigned char *) SDATA (string
);
2464 bytes
= SBYTES (string
);
2465 bytes_remaining
= bytes
;
2467 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2469 initialize_cut_buffers (display
, window
);
2470 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2475 /* Don't mess up with an empty value. */
2476 if (!bytes_remaining
)
2477 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2478 PropModeReplace
, data
, 0);
2480 while (bytes_remaining
)
2482 int chunk
= (bytes_remaining
< max_bytes
2483 ? bytes_remaining
: max_bytes
);
2484 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2485 (bytes_remaining
== bytes
2490 bytes_remaining
-= chunk
;
2497 DEFUN ("x-rotate-cut-buffers-internal", Fx_rotate_cut_buffers_internal
,
2498 Sx_rotate_cut_buffers_internal
, 1, 1, 0,
2499 doc
: /* Rotate the values of the cut buffers by the given number of step.
2500 Positive means shift the values forward, negative means backward. */)
2507 struct frame
*sf
= SELECTED_FRAME ();
2511 if (! FRAME_X_P (sf
))
2514 display
= FRAME_X_DISPLAY (sf
);
2515 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2519 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2521 initialize_cut_buffers (display
, window
);
2522 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2525 props
[0] = XA_CUT_BUFFER0
;
2526 props
[1] = XA_CUT_BUFFER1
;
2527 props
[2] = XA_CUT_BUFFER2
;
2528 props
[3] = XA_CUT_BUFFER3
;
2529 props
[4] = XA_CUT_BUFFER4
;
2530 props
[5] = XA_CUT_BUFFER5
;
2531 props
[6] = XA_CUT_BUFFER6
;
2532 props
[7] = XA_CUT_BUFFER7
;
2534 XRotateWindowProperties (display
, window
, props
, 8, XINT (n
));
2541 /***********************************************************************
2542 Drag and drop support
2543 ***********************************************************************/
2544 /* Check that lisp values are of correct type for x_fill_property_data.
2545 That is, number, string or a cons with two numbers (low and high 16
2546 bit parts of a 32 bit number). */
2549 x_check_property_data (data
)
2555 for (iter
= data
; CONSP (iter
) && size
!= -1; iter
= XCDR (iter
), ++size
)
2557 Lisp_Object o
= XCAR (iter
);
2559 if (! NUMBERP (o
) && ! STRINGP (o
) && ! CONSP (o
))
2561 else if (CONSP (o
) &&
2562 (! NUMBERP (XCAR (o
)) || ! NUMBERP (XCDR (o
))))
2569 /* Convert lisp values to a C array. Values may be a number, a string
2570 which is taken as an X atom name and converted to the atom value, or
2571 a cons containing the two 16 bit parts of a 32 bit number.
2573 DPY is the display use to look up X atoms.
2574 DATA is a Lisp list of values to be converted.
2575 RET is the C array that contains the converted values. It is assumed
2576 it is big enough to hold all values.
2577 FORMAT is 8, 16 or 32 and denotes char/short/long for each C value to
2578 be stored in RET. Note that long is used for 32 even if long is more
2579 than 32 bits (see man pages for XChangeProperty, XGetWindowProperty and
2580 XClientMessageEvent). */
2583 x_fill_property_data (dpy
, data
, ret
, format
)
2590 long *d32
= (long *) ret
;
2591 short *d16
= (short *) ret
;
2592 char *d08
= (char *) ret
;
2595 for (iter
= data
; CONSP (iter
); iter
= XCDR (iter
))
2597 Lisp_Object o
= XCAR (iter
);
2600 val
= (long) XFASTINT (o
);
2601 else if (FLOATP (o
))
2602 val
= (long) XFLOAT_DATA (o
);
2604 val
= (long) cons_to_long (o
);
2605 else if (STRINGP (o
))
2608 val
= (long) XInternAtom (dpy
, (char *) SDATA (o
), False
);
2612 error ("Wrong type, must be string, number or cons");
2615 *d08
++ = (char) val
;
2616 else if (format
== 16)
2617 *d16
++ = (short) val
;
2623 /* Convert an array of C values to a Lisp list.
2624 F is the frame to be used to look up X atoms if the TYPE is XA_ATOM.
2625 DATA is a C array of values to be converted.
2626 TYPE is the type of the data. Only XA_ATOM is special, it converts
2627 each number in DATA to its corresponfing X atom as a symbol.
2628 FORMAT is 8, 16 or 32 and gives the size in bits for each C value to
2630 SIZE is the number of elements in DATA.
2632 Important: When format is 32, data should contain an array of int,
2633 not an array of long as the X library returns. This makes a difference
2634 when sizeof(long) != sizeof(int).
2636 Also see comment for selection_data_to_lisp_data above. */
2639 x_property_data_to_lisp (f
, data
, type
, format
, size
)
2641 unsigned char *data
;
2646 return selection_data_to_lisp_data (FRAME_X_DISPLAY (f
),
2647 data
, size
*format
/8, type
, format
);
2650 /* Get the mouse position in frame relative coordinates. */
2653 mouse_position_for_drop (f
, x
, y
)
2658 Window root
, dummy_window
;
2663 XQueryPointer (FRAME_X_DISPLAY (f
),
2664 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
2666 /* The root window which contains the pointer. */
2669 /* Window pointer is on, not used */
2672 /* The position on that root window. */
2675 /* x/y in dummy_window coordinates, not used. */
2678 /* Modifier keys and pointer buttons, about which
2680 (unsigned int *) &dummy
);
2683 /* Absolute to relative. */
2684 *x
-= f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
);
2685 *y
-= f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
);
2690 DEFUN ("x-get-atom-name", Fx_get_atom_name
,
2691 Sx_get_atom_name
, 1, 2, 0,
2692 doc
: /* Return the X atom name for VALUE as a string.
2693 VALUE may be a number or a cons where the car is the upper 16 bits and
2694 the cdr is the lower 16 bits of a 32 bit value.
2695 Use the display for FRAME or the current frame if FRAME is not given or nil.
2697 If the value is 0 or the atom is not known, return the empty string. */)
2699 Lisp_Object value
, frame
;
2701 struct frame
*f
= check_x_frame (frame
);
2703 Lisp_Object ret
= Qnil
;
2704 Display
*dpy
= FRAME_X_DISPLAY (f
);
2708 if (INTEGERP (value
))
2709 atom
= (Atom
) XUINT (value
);
2710 else if (FLOATP (value
))
2711 atom
= (Atom
) XFLOAT_DATA (value
);
2712 else if (CONSP (value
))
2713 atom
= (Atom
) cons_to_long (value
);
2715 error ("Wrong type, value must be number or cons");
2718 x_catch_errors (dpy
);
2719 name
= atom
? XGetAtomName (dpy
, atom
) : "";
2720 had_errors
= x_had_errors_p (dpy
);
2721 x_uncatch_errors ();
2724 ret
= make_string (name
, strlen (name
));
2726 if (atom
&& name
) XFree (name
);
2727 if (NILP (ret
)) ret
= make_string ("", 0);
2734 /* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT.
2735 TODO: Check if this client event really is a DND event? */
2738 x_handle_dnd_message (f
, event
, dpyinfo
, bufp
)
2740 XClientMessageEvent
*event
;
2741 struct x_display_info
*dpyinfo
;
2742 struct input_event
*bufp
;
2746 /* format 32 => size 5, format 16 => size 10, format 8 => size 20 */
2747 unsigned long size
= 160/event
->format
;
2749 unsigned char *data
= (unsigned char *) event
->data
.b
;
2752 XSETFRAME (frame
, f
);
2754 /* On a 64 bit machine, the event->data.l array members are 64 bits (long),
2755 but the x_property_data_to_lisp (or rather selection_data_to_lisp_data)
2756 function expects them to be of size int (i.e. 32). So to be able to
2757 use that function, put the data in the form it expects if format is 32. */
2759 if (event
->format
== 32 && event
->format
< BITS_PER_LONG
)
2762 for (i
= 0; i
< 5; ++i
) /* There are only 5 longs in a ClientMessage. */
2763 idata
[i
] = (int) event
->data
.l
[i
];
2764 data
= (unsigned char *) idata
;
2767 vec
= Fmake_vector (make_number (4), Qnil
);
2768 AREF (vec
, 0) = SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f
),
2769 event
->message_type
));
2770 AREF (vec
, 1) = frame
;
2771 AREF (vec
, 2) = make_number (event
->format
);
2772 AREF (vec
, 3) = x_property_data_to_lisp (f
,
2774 event
->message_type
,
2778 mouse_position_for_drop (f
, &x
, &y
);
2779 bufp
->kind
= DRAG_N_DROP_EVENT
;
2780 bufp
->frame_or_window
= frame
;
2781 bufp
->timestamp
= CurrentTime
;
2782 bufp
->x
= make_number (x
);
2783 bufp
->y
= make_number (y
);
2785 bufp
->modifiers
= 0;
2790 DEFUN ("x-send-client-message", Fx_send_client_event
,
2791 Sx_send_client_message
, 6, 6, 0,
2792 doc
: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY.
2794 For DISPLAY, specify either a frame or a display name (a string).
2795 If DISPLAY is nil, that stands for the selected frame's display.
2796 DEST may be a number, in which case it is a Window id. The value 0 may
2797 be used to send to the root window of the DISPLAY.
2798 If DEST is a cons, it is converted to a 32 bit number
2799 with the high 16 bits from the car and the lower 16 bit from the cdr. That
2800 number is then used as a window id.
2801 If DEST is a frame the event is sent to the outer window of that frame.
2802 Nil means the currently selected frame.
2803 If DEST is the string "PointerWindow" the event is sent to the window that
2804 contains the pointer. If DEST is the string "InputFocus" the event is
2805 sent to the window that has the input focus.
2806 FROM is the frame sending the event. Use nil for currently selected frame.
2807 MESSAGE-TYPE is the name of an Atom as a string.
2808 FORMAT must be one of 8, 16 or 32 and determines the size of the values in
2809 bits. VALUES is a list of numbers, cons and/or strings containing the values
2810 to send. If a value is a string, it is converted to an Atom and the value of
2811 the Atom is sent. If a value is a cons, it is converted to a 32 bit number
2812 with the high 16 bits from the car and the lower 16 bit from the cdr.
2813 If more values than fits into the event is given, the excessive values
2815 (display
, dest
, from
, message_type
, format
, values
)
2816 Lisp_Object display
, dest
, from
, message_type
, format
, values
;
2818 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
2823 struct frame
*f
= check_x_frame (from
);
2826 CHECK_STRING (message_type
);
2827 CHECK_NUMBER (format
);
2828 CHECK_CONS (values
);
2830 if (x_check_property_data (values
) == -1)
2831 error ("Bad data in VALUES, must be number, cons or string");
2833 event
.xclient
.type
= ClientMessage
;
2834 event
.xclient
.format
= XFASTINT (format
);
2836 if (event
.xclient
.format
!= 8 && event
.xclient
.format
!= 16
2837 && event
.xclient
.format
!= 32)
2838 error ("FORMAT must be one of 8, 16 or 32");
2840 if (FRAMEP (dest
) || NILP (dest
))
2842 struct frame
*fdest
= check_x_frame (dest
);
2843 wdest
= FRAME_OUTER_WINDOW (fdest
);
2845 else if (STRINGP (dest
))
2847 if (strcmp (SDATA (dest
), "PointerWindow") == 0)
2848 wdest
= PointerWindow
;
2849 else if (strcmp (SDATA (dest
), "InputFocus") == 0)
2852 error ("DEST as a string must be one of PointerWindow or InputFocus");
2854 else if (INTEGERP (dest
))
2855 wdest
= (Window
) XFASTINT (dest
);
2856 else if (FLOATP (dest
))
2857 wdest
= (Window
) XFLOAT_DATA (dest
);
2858 else if (CONSP (dest
))
2860 if (! NUMBERP (XCAR (dest
)) || ! NUMBERP (XCDR (dest
)))
2861 error ("Both car and cdr for DEST must be numbers");
2863 wdest
= (Window
) cons_to_long (dest
);
2866 error ("DEST must be a frame, nil, string, number or cons");
2868 if (wdest
== 0) wdest
= dpyinfo
->root_window
;
2869 to_root
= wdest
== dpyinfo
->root_window
;
2871 for (cons
= values
, size
= 0; CONSP (cons
); cons
= XCDR (cons
), ++size
)
2876 event
.xclient
.message_type
2877 = XInternAtom (dpyinfo
->display
, SDATA (message_type
), False
);
2878 event
.xclient
.display
= dpyinfo
->display
;
2880 /* Some clients (metacity for example) expects sending window to be here
2881 when sending to the root window. */
2882 event
.xclient
.window
= to_root
? FRAME_OUTER_WINDOW (f
) : wdest
;
2885 memset (event
.xclient
.data
.b
, 0, sizeof (event
.xclient
.data
.b
));
2886 x_fill_property_data (dpyinfo
->display
, values
, event
.xclient
.data
.b
,
2887 event
.xclient
.format
);
2889 /* If event mask is 0 the event is sent to the client that created
2890 the destination window. But if we are sending to the root window,
2891 there is no such client. Then we set the event mask to 0xffff. The
2892 event then goes to clients selecting for events on the root window. */
2893 x_catch_errors (dpyinfo
->display
);
2895 int propagate
= to_root
? False
: True
;
2896 unsigned mask
= to_root
? 0xffff : 0;
2897 XSendEvent (dpyinfo
->display
, wdest
, propagate
, mask
, &event
);
2898 XFlush (dpyinfo
->display
);
2900 x_uncatch_errors ();
2910 defsubr (&Sx_get_selection_internal
);
2911 defsubr (&Sx_own_selection_internal
);
2912 defsubr (&Sx_disown_selection_internal
);
2913 defsubr (&Sx_selection_owner_p
);
2914 defsubr (&Sx_selection_exists_p
);
2916 #ifdef CUT_BUFFER_SUPPORT
2917 defsubr (&Sx_get_cut_buffer_internal
);
2918 defsubr (&Sx_store_cut_buffer_internal
);
2919 defsubr (&Sx_rotate_cut_buffers_internal
);
2922 defsubr (&Sx_get_atom_name
);
2923 defsubr (&Sx_send_client_message
);
2925 reading_selection_reply
= Fcons (Qnil
, Qnil
);
2926 staticpro (&reading_selection_reply
);
2927 reading_selection_window
= 0;
2928 reading_which_selection
= 0;
2930 property_change_wait_list
= 0;
2931 prop_location_identifier
= 0;
2932 property_change_reply
= Fcons (Qnil
, Qnil
);
2933 staticpro (&property_change_reply
);
2935 Vselection_alist
= Qnil
;
2936 staticpro (&Vselection_alist
);
2938 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist
,
2939 doc
: /* An alist associating X Windows selection-types with functions.
2940 These functions are called to convert the selection, with three args:
2941 the name of the selection (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2942 a desired type to which the selection should be converted;
2943 and the local selection value (whatever was given to `x-own-selection').
2945 The function should return the value to send to the X server
2946 \(typically a string). A return value of nil
2947 means that the conversion could not be done.
2948 A return value which is the symbol `NULL'
2949 means that a side-effect was executed,
2950 and there is no meaningful selection value. */);
2951 Vselection_converter_alist
= Qnil
;
2953 DEFVAR_LISP ("x-lost-selection-functions", &Vx_lost_selection_functions
,
2954 doc
: /* A list of functions to be called when Emacs loses an X selection.
2955 \(This happens when some other X client makes its own selection
2956 or when a Lisp program explicitly clears the selection.)
2957 The functions are called with one argument, the selection type
2958 \(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'). */);
2959 Vx_lost_selection_functions
= Qnil
;
2961 DEFVAR_LISP ("x-sent-selection-functions", &Vx_sent_selection_functions
,
2962 doc
: /* A list of functions to be called when Emacs answers a selection request.
2963 The functions are called with four arguments:
2964 - the selection name (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2965 - the selection-type which Emacs was asked to convert the
2966 selection into before sending (for example, `STRING' or `LENGTH');
2967 - a flag indicating success or failure for responding to the request.
2968 We might have failed (and declined the request) for any number of reasons,
2969 including being asked for a selection that we no longer own, or being asked
2970 to convert into a type that we don't know about or that is inappropriate.
2971 This hook doesn't let you change the behavior of Emacs's selection replies,
2972 it merely informs you that they have happened. */);
2973 Vx_sent_selection_functions
= Qnil
;
2975 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system
,
2976 doc
: /* Coding system for communicating with other X clients.
2977 When sending or receiving text via cut_buffer, selection, and clipboard,
2978 the text is encoded or decoded by this coding system.
2979 The default value is `compound-text-with-extensions'. */);
2980 Vselection_coding_system
= intern ("compound-text-with-extensions");
2982 DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system
,
2983 doc
: /* Coding system for the next communication with other X clients.
2984 Usually, `selection-coding-system' is used for communicating with
2985 other X clients. But, if this variable is set, it is used for the
2986 next communication only. After the communication, this variable is
2988 Vnext_selection_coding_system
= Qnil
;
2990 DEFVAR_INT ("x-selection-timeout", &x_selection_timeout
,
2991 doc
: /* Number of milliseconds to wait for a selection reply.
2992 If the selection owner doesn't reply in this time, we give up.
2993 A value of 0 means wait as long as necessary. This is initialized from the
2994 \"*selectionTimeout\" resource. */);
2995 x_selection_timeout
= 0;
2997 QPRIMARY
= intern ("PRIMARY"); staticpro (&QPRIMARY
);
2998 QSECONDARY
= intern ("SECONDARY"); staticpro (&QSECONDARY
);
2999 QSTRING
= intern ("STRING"); staticpro (&QSTRING
);
3000 QINTEGER
= intern ("INTEGER"); staticpro (&QINTEGER
);
3001 QCLIPBOARD
= intern ("CLIPBOARD"); staticpro (&QCLIPBOARD
);
3002 QTIMESTAMP
= intern ("TIMESTAMP"); staticpro (&QTIMESTAMP
);
3003 QTEXT
= intern ("TEXT"); staticpro (&QTEXT
);
3004 QCOMPOUND_TEXT
= intern ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT
);
3005 QUTF8_STRING
= intern ("UTF8_STRING"); staticpro (&QUTF8_STRING
);
3006 QDELETE
= intern ("DELETE"); staticpro (&QDELETE
);
3007 QMULTIPLE
= intern ("MULTIPLE"); staticpro (&QMULTIPLE
);
3008 QINCR
= intern ("INCR"); staticpro (&QINCR
);
3009 QEMACS_TMP
= intern ("_EMACS_TMP_"); staticpro (&QEMACS_TMP
);
3010 QTARGETS
= intern ("TARGETS"); staticpro (&QTARGETS
);
3011 QATOM
= intern ("ATOM"); staticpro (&QATOM
);
3012 QATOM_PAIR
= intern ("ATOM_PAIR"); staticpro (&QATOM_PAIR
);
3013 QNULL
= intern ("NULL"); staticpro (&QNULL
);
3014 Qcompound_text_with_extensions
= intern ("compound-text-with-extensions");
3015 staticpro (&Qcompound_text_with_extensions
);
3017 #ifdef CUT_BUFFER_SUPPORT
3018 QCUT_BUFFER0
= intern ("CUT_BUFFER0"); staticpro (&QCUT_BUFFER0
);
3019 QCUT_BUFFER1
= intern ("CUT_BUFFER1"); staticpro (&QCUT_BUFFER1
);
3020 QCUT_BUFFER2
= intern ("CUT_BUFFER2"); staticpro (&QCUT_BUFFER2
);
3021 QCUT_BUFFER3
= intern ("CUT_BUFFER3"); staticpro (&QCUT_BUFFER3
);
3022 QCUT_BUFFER4
= intern ("CUT_BUFFER4"); staticpro (&QCUT_BUFFER4
);
3023 QCUT_BUFFER5
= intern ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5
);
3024 QCUT_BUFFER6
= intern ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6
);
3025 QCUT_BUFFER7
= intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7
);
3028 Qforeign_selection
= intern ("foreign-selection");
3029 staticpro (&Qforeign_selection
);
3032 /* arch-tag: 7c293b0f-9918-4f69-8ac7-03e142307236
3033 (do not change this comment) */