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 (!bcmp (&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 bcopy 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 bcopy (tmp_data
, (*data_ret
) + offset
, *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 bcopy (tmp_data
, (*data_ret
) + offset
, 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 (selection_name
, selection_value
)
2098 Lisp_Object selection_name
, selection_value
;
2101 CHECK_SYMBOL (selection_name
);
2102 if (NILP (selection_value
)) error ("SELECTION-VALUE may not be nil");
2103 x_own_selection (selection_name
, selection_value
);
2104 return selection_value
;
2108 /* Request the selection value from the owner. If we are the owner,
2109 simply return our selection value. If we are not the owner, this
2110 will block until all of the data has arrived. */
2112 DEFUN ("x-get-selection-internal", Fx_get_selection_internal
,
2113 Sx_get_selection_internal
, 2, 3, 0,
2114 doc
: /* Return text selected from some X window.
2115 SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2116 \(Those are literal upper-case symbol names, since that's what X expects.)
2117 TYPE is the type of data desired, typically `STRING'.
2118 TIME_STAMP is the time to use in the XConvertSelection call for foreign
2119 selections. If omitted, defaults to the time for the last event. */)
2120 (selection_symbol
, target_type
, time_stamp
)
2121 Lisp_Object selection_symbol
, target_type
, time_stamp
;
2123 Lisp_Object val
= Qnil
;
2124 struct gcpro gcpro1
, gcpro2
;
2125 GCPRO2 (target_type
, val
); /* we store newly consed data into these */
2127 CHECK_SYMBOL (selection_symbol
);
2129 #if 0 /* #### MULTIPLE doesn't work yet */
2130 if (CONSP (target_type
)
2131 && XCAR (target_type
) == QMULTIPLE
)
2133 CHECK_VECTOR (XCDR (target_type
));
2134 /* So we don't destructively modify this... */
2135 target_type
= copy_multiple_data (target_type
);
2139 CHECK_SYMBOL (target_type
);
2141 val
= x_get_local_selection (selection_symbol
, target_type
, 1);
2145 val
= x_get_foreign_selection (selection_symbol
, target_type
, time_stamp
);
2150 && SYMBOLP (XCAR (val
)))
2153 if (CONSP (val
) && NILP (XCDR (val
)))
2156 val
= clean_local_selection_data (val
);
2162 DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal
,
2163 Sx_disown_selection_internal
, 1, 2, 0,
2164 doc
: /* If we own the selection SELECTION, disown it.
2165 Disowning it means there is no such selection. */)
2167 Lisp_Object selection
;
2171 Atom selection_atom
;
2173 struct selection_input_event sie
;
2174 struct input_event ie
;
2177 struct x_display_info
*dpyinfo
;
2178 struct frame
*sf
= SELECTED_FRAME ();
2181 if (! FRAME_X_P (sf
))
2184 display
= FRAME_X_DISPLAY (sf
);
2185 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2186 CHECK_SYMBOL (selection
);
2188 timestamp
= last_event_timestamp
;
2190 timestamp
= cons_to_long (time
);
2192 if (NILP (assq_no_quit (selection
, Vselection_alist
)))
2193 return Qnil
; /* Don't disown the selection when we're not the owner. */
2195 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection
);
2198 XSetSelectionOwner (display
, selection_atom
, None
, timestamp
);
2201 /* It doesn't seem to be guaranteed that a SelectionClear event will be
2202 generated for a window which owns the selection when that window sets
2203 the selection owner to None. The NCD server does, the MIT Sun4 server
2204 doesn't. So we synthesize one; this means we might get two, but
2205 that's ok, because the second one won't have any effect. */
2206 SELECTION_EVENT_DISPLAY (&event
.sie
) = display
;
2207 SELECTION_EVENT_SELECTION (&event
.sie
) = selection_atom
;
2208 SELECTION_EVENT_TIME (&event
.sie
) = timestamp
;
2209 x_handle_selection_clear (&event
.ie
);
2214 /* Get rid of all the selections in buffer BUFFER.
2215 This is used when we kill a buffer. */
2218 x_disown_buffer_selections (Lisp_Object buffer
)
2221 struct buffer
*buf
= XBUFFER (buffer
);
2223 for (tail
= Vselection_alist
; CONSP (tail
); tail
= XCDR (tail
))
2225 Lisp_Object elt
, value
;
2228 if (CONSP (value
) && MARKERP (XCAR (value
))
2229 && XMARKER (XCAR (value
))->buffer
== buf
)
2230 Fx_disown_selection_internal (XCAR (elt
), Qnil
);
2234 DEFUN ("x-selection-owner-p", Fx_selection_owner_p
, Sx_selection_owner_p
,
2236 doc
: /* Whether the current Emacs process owns the given X Selection.
2237 The arg should be the name of the selection in question, typically one of
2238 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2239 \(Those are literal upper-case symbol names, since that's what X expects.)
2240 For convenience, the symbol nil is the same as `PRIMARY',
2241 and t is the same as `SECONDARY'. */)
2243 Lisp_Object selection
;
2246 CHECK_SYMBOL (selection
);
2247 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2248 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2250 if (NILP (Fassq (selection
, Vselection_alist
)))
2255 DEFUN ("x-selection-exists-p", Fx_selection_exists_p
, Sx_selection_exists_p
,
2257 doc
: /* Whether there is an owner for the given X Selection.
2258 The arg should be the name of the selection in question, typically one of
2259 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2260 \(Those are literal upper-case symbol names, since that's what X expects.)
2261 For convenience, the symbol nil is the same as `PRIMARY',
2262 and t is the same as `SECONDARY'. */)
2264 Lisp_Object selection
;
2269 struct frame
*sf
= SELECTED_FRAME ();
2271 /* It should be safe to call this before we have an X frame. */
2272 if (! FRAME_X_P (sf
))
2275 dpy
= FRAME_X_DISPLAY (sf
);
2276 CHECK_SYMBOL (selection
);
2277 if (!NILP (Fx_selection_owner_p (selection
)))
2279 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2280 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2281 atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
), dpy
, selection
);
2285 owner
= XGetSelectionOwner (dpy
, atom
);
2287 return (owner
? Qt
: Qnil
);
2291 #ifdef CUT_BUFFER_SUPPORT
2293 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
2295 initialize_cut_buffers (Display
*display
, Window window
)
2297 unsigned char *data
= (unsigned char *) "";
2299 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
2300 PropModeAppend, data, 0)
2301 FROB (XA_CUT_BUFFER0
);
2302 FROB (XA_CUT_BUFFER1
);
2303 FROB (XA_CUT_BUFFER2
);
2304 FROB (XA_CUT_BUFFER3
);
2305 FROB (XA_CUT_BUFFER4
);
2306 FROB (XA_CUT_BUFFER5
);
2307 FROB (XA_CUT_BUFFER6
);
2308 FROB (XA_CUT_BUFFER7
);
2314 #define CHECK_CUT_BUFFER(symbol) \
2315 do { CHECK_SYMBOL ((symbol)); \
2316 if (!EQ((symbol), QCUT_BUFFER0) && !EQ((symbol), QCUT_BUFFER1) \
2317 && !EQ((symbol), QCUT_BUFFER2) && !EQ((symbol), QCUT_BUFFER3) \
2318 && !EQ((symbol), QCUT_BUFFER4) && !EQ((symbol), QCUT_BUFFER5) \
2319 && !EQ((symbol), QCUT_BUFFER6) && !EQ((symbol), QCUT_BUFFER7)) \
2320 signal_error ("Doesn't name a cut buffer", (symbol)); \
2323 DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal
,
2324 Sx_get_cut_buffer_internal
, 1, 1, 0,
2325 doc
: /* Returns the value of the named cut buffer (typically CUT_BUFFER0). */)
2331 unsigned char *data
= NULL
;
2338 struct x_display_info
*dpyinfo
;
2339 struct frame
*sf
= SELECTED_FRAME ();
2343 if (! FRAME_X_P (sf
))
2346 display
= FRAME_X_DISPLAY (sf
);
2347 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2348 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2349 CHECK_CUT_BUFFER (buffer
);
2350 buffer_atom
= symbol_to_x_atom (dpyinfo
, display
, buffer
);
2352 x_get_window_property (display
, window
, buffer_atom
, &data
, &bytes
,
2353 &type
, &format
, &size
, 0);
2355 if (!data
|| !format
)
2361 if (format
!= 8 || type
!= XA_STRING
)
2362 signal_error ("Cut buffer doesn't contain 8-bit data",
2363 list2 (x_atom_to_symbol (display
, type
),
2364 make_number (format
)));
2366 ret
= (bytes
? make_unibyte_string ((char *) data
, bytes
) : Qnil
);
2367 /* Use xfree, not XFree, because x_get_window_property
2368 calls xmalloc itself. */
2374 DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal
,
2375 Sx_store_cut_buffer_internal
, 2, 2, 0,
2376 doc
: /* Sets the value of the named cut buffer (typically CUT_BUFFER0). */)
2378 Lisp_Object buffer
, string
;
2382 unsigned char *data
;
2384 int bytes_remaining
;
2387 struct frame
*sf
= SELECTED_FRAME ();
2391 if (! FRAME_X_P (sf
))
2394 display
= FRAME_X_DISPLAY (sf
);
2395 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2397 max_bytes
= SELECTION_QUANTUM (display
);
2398 if (max_bytes
> MAX_SELECTION_QUANTUM
)
2399 max_bytes
= MAX_SELECTION_QUANTUM
;
2401 CHECK_CUT_BUFFER (buffer
);
2402 CHECK_STRING (string
);
2403 buffer_atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
),
2405 data
= (unsigned char *) SDATA (string
);
2406 bytes
= SBYTES (string
);
2407 bytes_remaining
= bytes
;
2409 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2411 initialize_cut_buffers (display
, window
);
2412 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2417 /* Don't mess up with an empty value. */
2418 if (!bytes_remaining
)
2419 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2420 PropModeReplace
, data
, 0);
2422 while (bytes_remaining
)
2424 int chunk
= (bytes_remaining
< max_bytes
2425 ? bytes_remaining
: max_bytes
);
2426 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2427 (bytes_remaining
== bytes
2432 bytes_remaining
-= chunk
;
2439 DEFUN ("x-rotate-cut-buffers-internal", Fx_rotate_cut_buffers_internal
,
2440 Sx_rotate_cut_buffers_internal
, 1, 1, 0,
2441 doc
: /* Rotate the values of the cut buffers by N steps.
2442 Positive N means shift the values forward, negative means backward. */)
2449 struct frame
*sf
= SELECTED_FRAME ();
2453 if (! FRAME_X_P (sf
))
2456 display
= FRAME_X_DISPLAY (sf
);
2457 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2461 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2463 initialize_cut_buffers (display
, window
);
2464 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2467 props
[0] = XA_CUT_BUFFER0
;
2468 props
[1] = XA_CUT_BUFFER1
;
2469 props
[2] = XA_CUT_BUFFER2
;
2470 props
[3] = XA_CUT_BUFFER3
;
2471 props
[4] = XA_CUT_BUFFER4
;
2472 props
[5] = XA_CUT_BUFFER5
;
2473 props
[6] = XA_CUT_BUFFER6
;
2474 props
[7] = XA_CUT_BUFFER7
;
2476 XRotateWindowProperties (display
, window
, props
, 8, XINT (n
));
2483 /***********************************************************************
2484 Drag and drop support
2485 ***********************************************************************/
2486 /* Check that lisp values are of correct type for x_fill_property_data.
2487 That is, number, string or a cons with two numbers (low and high 16
2488 bit parts of a 32 bit number). */
2491 x_check_property_data (Lisp_Object data
)
2496 for (iter
= data
; CONSP (iter
) && size
!= -1; iter
= XCDR (iter
), ++size
)
2498 Lisp_Object o
= XCAR (iter
);
2500 if (! NUMBERP (o
) && ! STRINGP (o
) && ! CONSP (o
))
2502 else if (CONSP (o
) &&
2503 (! NUMBERP (XCAR (o
)) || ! NUMBERP (XCDR (o
))))
2510 /* Convert lisp values to a C array. Values may be a number, a string
2511 which is taken as an X atom name and converted to the atom value, or
2512 a cons containing the two 16 bit parts of a 32 bit number.
2514 DPY is the display use to look up X atoms.
2515 DATA is a Lisp list of values to be converted.
2516 RET is the C array that contains the converted values. It is assumed
2517 it is big enough to hold all values.
2518 FORMAT is 8, 16 or 32 and denotes char/short/long for each C value to
2519 be stored in RET. Note that long is used for 32 even if long is more
2520 than 32 bits (see man pages for XChangeProperty, XGetWindowProperty and
2521 XClientMessageEvent). */
2524 x_fill_property_data (Display
*dpy
, Lisp_Object data
, void *ret
, int format
)
2527 long *d32
= (long *) ret
;
2528 short *d16
= (short *) ret
;
2529 char *d08
= (char *) ret
;
2532 for (iter
= data
; CONSP (iter
); iter
= XCDR (iter
))
2534 Lisp_Object o
= XCAR (iter
);
2537 val
= (long) XFASTINT (o
);
2538 else if (FLOATP (o
))
2539 val
= (long) XFLOAT_DATA (o
);
2541 val
= (long) cons_to_long (o
);
2542 else if (STRINGP (o
))
2545 val
= (long) XInternAtom (dpy
, (char *) SDATA (o
), False
);
2549 error ("Wrong type, must be string, number or cons");
2552 *d08
++ = (char) val
;
2553 else if (format
== 16)
2554 *d16
++ = (short) val
;
2560 /* Convert an array of C values to a Lisp list.
2561 F is the frame to be used to look up X atoms if the TYPE is XA_ATOM.
2562 DATA is a C array of values to be converted.
2563 TYPE is the type of the data. Only XA_ATOM is special, it converts
2564 each number in DATA to its corresponfing X atom as a symbol.
2565 FORMAT is 8, 16 or 32 and gives the size in bits for each C value to
2567 SIZE is the number of elements in DATA.
2569 Important: When format is 32, data should contain an array of int,
2570 not an array of long as the X library returns. This makes a difference
2571 when sizeof(long) != sizeof(int).
2573 Also see comment for selection_data_to_lisp_data above. */
2576 x_property_data_to_lisp (struct frame
*f
, unsigned char *data
, Atom type
, int format
, long unsigned int size
)
2578 return selection_data_to_lisp_data (FRAME_X_DISPLAY (f
),
2579 data
, size
*format
/8, type
, format
);
2582 /* Get the mouse position in frame relative coordinates. */
2585 mouse_position_for_drop (FRAME_PTR f
, int *x
, int *y
)
2587 Window root
, dummy_window
;
2592 XQueryPointer (FRAME_X_DISPLAY (f
),
2593 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
2595 /* The root window which contains the pointer. */
2598 /* Window pointer is on, not used */
2601 /* The position on that root window. */
2604 /* x/y in dummy_window coordinates, not used. */
2607 /* Modifier keys and pointer buttons, about which
2609 (unsigned int *) &dummy
);
2612 /* Absolute to relative. */
2613 *x
-= f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
);
2614 *y
-= f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
);
2619 DEFUN ("x-get-atom-name", Fx_get_atom_name
,
2620 Sx_get_atom_name
, 1, 2, 0,
2621 doc
: /* Return the X atom name for VALUE as a string.
2622 VALUE may be a number or a cons where the car is the upper 16 bits and
2623 the cdr is the lower 16 bits of a 32 bit value.
2624 Use the display for FRAME or the current frame if FRAME is not given or nil.
2626 If the value is 0 or the atom is not known, return the empty string. */)
2628 Lisp_Object value
, frame
;
2630 struct frame
*f
= check_x_frame (frame
);
2632 Lisp_Object ret
= Qnil
;
2633 Display
*dpy
= FRAME_X_DISPLAY (f
);
2637 if (INTEGERP (value
))
2638 atom
= (Atom
) XUINT (value
);
2639 else if (FLOATP (value
))
2640 atom
= (Atom
) XFLOAT_DATA (value
);
2641 else if (CONSP (value
))
2642 atom
= (Atom
) cons_to_long (value
);
2644 error ("Wrong type, value must be number or cons");
2647 x_catch_errors (dpy
);
2648 name
= atom
? XGetAtomName (dpy
, atom
) : "";
2649 had_errors
= x_had_errors_p (dpy
);
2650 x_uncatch_errors ();
2653 ret
= make_string (name
, strlen (name
));
2655 if (atom
&& name
) XFree (name
);
2656 if (NILP (ret
)) ret
= empty_unibyte_string
;
2663 DEFUN ("x-register-dnd-atom", Fx_register_dnd_atom
,
2664 Sx_register_dnd_atom
, 1, 2, 0,
2665 doc
: /* Request that dnd events are made for ClientMessages with ATOM.
2666 ATOM can be a symbol or a string. The ATOM is interned on the display that
2667 FRAME is on. If FRAME is nil, the selected frame is used. */)
2669 Lisp_Object atom
, frame
;
2672 struct frame
*f
= check_x_frame (frame
);
2674 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2678 x_atom
= symbol_to_x_atom (dpyinfo
, FRAME_X_DISPLAY (f
), atom
);
2679 else if (STRINGP (atom
))
2682 x_atom
= XInternAtom (FRAME_X_DISPLAY (f
), (char *) SDATA (atom
), False
);
2686 error ("ATOM must be a symbol or a string");
2688 for (i
= 0; i
< dpyinfo
->x_dnd_atoms_length
; ++i
)
2689 if (dpyinfo
->x_dnd_atoms
[i
] == x_atom
)
2692 if (dpyinfo
->x_dnd_atoms_length
== dpyinfo
->x_dnd_atoms_size
)
2694 dpyinfo
->x_dnd_atoms_size
*= 2;
2695 dpyinfo
->x_dnd_atoms
= xrealloc (dpyinfo
->x_dnd_atoms
,
2696 sizeof (*dpyinfo
->x_dnd_atoms
)
2697 * dpyinfo
->x_dnd_atoms_size
);
2700 dpyinfo
->x_dnd_atoms
[dpyinfo
->x_dnd_atoms_length
++] = x_atom
;
2704 /* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT. */
2707 x_handle_dnd_message (struct frame
*f
, XClientMessageEvent
*event
, struct x_display_info
*dpyinfo
, struct input_event
*bufp
)
2711 /* format 32 => size 5, format 16 => size 10, format 8 => size 20 */
2712 unsigned long size
= 160/event
->format
;
2714 unsigned char *data
= (unsigned char *) event
->data
.b
;
2718 for (i
= 0; i
< dpyinfo
->x_dnd_atoms_length
; ++i
)
2719 if (dpyinfo
->x_dnd_atoms
[i
] == event
->message_type
) break;
2721 if (i
== dpyinfo
->x_dnd_atoms_length
) return 0;
2723 XSETFRAME (frame
, f
);
2725 /* On a 64 bit machine, the event->data.l array members are 64 bits (long),
2726 but the x_property_data_to_lisp (or rather selection_data_to_lisp_data)
2727 function expects them to be of size int (i.e. 32). So to be able to
2728 use that function, put the data in the form it expects if format is 32. */
2730 if (event
->format
== 32 && event
->format
< BITS_PER_LONG
)
2733 for (i
= 0; i
< 5; ++i
) /* There are only 5 longs in a ClientMessage. */
2734 idata
[i
] = (int) event
->data
.l
[i
];
2735 data
= (unsigned char *) idata
;
2738 vec
= Fmake_vector (make_number (4), Qnil
);
2739 ASET (vec
, 0, SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f
),
2740 event
->message_type
)));
2741 ASET (vec
, 1, frame
);
2742 ASET (vec
, 2, make_number (event
->format
));
2743 ASET (vec
, 3, x_property_data_to_lisp (f
,
2745 event
->message_type
,
2749 mouse_position_for_drop (f
, &x
, &y
);
2750 bufp
->kind
= DRAG_N_DROP_EVENT
;
2751 bufp
->frame_or_window
= frame
;
2752 bufp
->timestamp
= CurrentTime
;
2753 bufp
->x
= make_number (x
);
2754 bufp
->y
= make_number (y
);
2756 bufp
->modifiers
= 0;
2761 DEFUN ("x-send-client-message", Fx_send_client_event
,
2762 Sx_send_client_message
, 6, 6, 0,
2763 doc
: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY.
2765 For DISPLAY, specify either a frame or a display name (a string).
2766 If DISPLAY is nil, that stands for the selected frame's display.
2767 DEST may be a number, in which case it is a Window id. The value 0 may
2768 be used to send to the root window of the DISPLAY.
2769 If DEST is a cons, it is converted to a 32 bit number
2770 with the high 16 bits from the car and the lower 16 bit from the cdr. That
2771 number is then used as a window id.
2772 If DEST is a frame the event is sent to the outer window of that frame.
2773 A value of nil means the currently selected frame.
2774 If DEST is the string "PointerWindow" the event is sent to the window that
2775 contains the pointer. If DEST is the string "InputFocus" the event is
2776 sent to the window that has the input focus.
2777 FROM is the frame sending the event. Use nil for currently selected frame.
2778 MESSAGE-TYPE is the name of an Atom as a string.
2779 FORMAT must be one of 8, 16 or 32 and determines the size of the values in
2780 bits. VALUES is a list of numbers, cons and/or strings containing the values
2781 to send. If a value is a string, it is converted to an Atom and the value of
2782 the Atom is sent. If a value is a cons, it is converted to a 32 bit number
2783 with the high 16 bits from the car and the lower 16 bit from the cdr.
2784 If more values than fits into the event is given, the excessive values
2786 (display
, dest
, from
, message_type
, format
, values
)
2787 Lisp_Object display
, dest
, from
, message_type
, format
, values
;
2789 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
2794 struct frame
*f
= check_x_frame (from
);
2797 CHECK_STRING (message_type
);
2798 CHECK_NUMBER (format
);
2799 CHECK_CONS (values
);
2801 if (x_check_property_data (values
) == -1)
2802 error ("Bad data in VALUES, must be number, cons or string");
2804 event
.xclient
.type
= ClientMessage
;
2805 event
.xclient
.format
= XFASTINT (format
);
2807 if (event
.xclient
.format
!= 8 && event
.xclient
.format
!= 16
2808 && event
.xclient
.format
!= 32)
2809 error ("FORMAT must be one of 8, 16 or 32");
2811 if (FRAMEP (dest
) || NILP (dest
))
2813 struct frame
*fdest
= check_x_frame (dest
);
2814 wdest
= FRAME_OUTER_WINDOW (fdest
);
2816 else if (STRINGP (dest
))
2818 if (strcmp (SDATA (dest
), "PointerWindow") == 0)
2819 wdest
= PointerWindow
;
2820 else if (strcmp (SDATA (dest
), "InputFocus") == 0)
2823 error ("DEST as a string must be one of PointerWindow or InputFocus");
2825 else if (INTEGERP (dest
))
2826 wdest
= (Window
) XFASTINT (dest
);
2827 else if (FLOATP (dest
))
2828 wdest
= (Window
) XFLOAT_DATA (dest
);
2829 else if (CONSP (dest
))
2831 if (! NUMBERP (XCAR (dest
)) || ! NUMBERP (XCDR (dest
)))
2832 error ("Both car and cdr for DEST must be numbers");
2834 wdest
= (Window
) cons_to_long (dest
);
2837 error ("DEST must be a frame, nil, string, number or cons");
2839 if (wdest
== 0) wdest
= dpyinfo
->root_window
;
2840 to_root
= wdest
== dpyinfo
->root_window
;
2842 for (cons
= values
, size
= 0; CONSP (cons
); cons
= XCDR (cons
), ++size
)
2847 event
.xclient
.message_type
2848 = XInternAtom (dpyinfo
->display
, SDATA (message_type
), False
);
2849 event
.xclient
.display
= dpyinfo
->display
;
2851 /* Some clients (metacity for example) expects sending window to be here
2852 when sending to the root window. */
2853 event
.xclient
.window
= to_root
? FRAME_OUTER_WINDOW (f
) : wdest
;
2856 memset (event
.xclient
.data
.b
, 0, sizeof (event
.xclient
.data
.b
));
2857 x_fill_property_data (dpyinfo
->display
, values
, event
.xclient
.data
.b
,
2858 event
.xclient
.format
);
2860 /* If event mask is 0 the event is sent to the client that created
2861 the destination window. But if we are sending to the root window,
2862 there is no such client. Then we set the event mask to 0xffff. The
2863 event then goes to clients selecting for events on the root window. */
2864 x_catch_errors (dpyinfo
->display
);
2866 int propagate
= to_root
? False
: True
;
2867 unsigned mask
= to_root
? 0xffff : 0;
2868 XSendEvent (dpyinfo
->display
, wdest
, propagate
, mask
, &event
);
2869 XFlush (dpyinfo
->display
);
2871 x_uncatch_errors ();
2879 syms_of_xselect (void)
2881 defsubr (&Sx_get_selection_internal
);
2882 defsubr (&Sx_own_selection_internal
);
2883 defsubr (&Sx_disown_selection_internal
);
2884 defsubr (&Sx_selection_owner_p
);
2885 defsubr (&Sx_selection_exists_p
);
2887 #ifdef CUT_BUFFER_SUPPORT
2888 defsubr (&Sx_get_cut_buffer_internal
);
2889 defsubr (&Sx_store_cut_buffer_internal
);
2890 defsubr (&Sx_rotate_cut_buffers_internal
);
2893 defsubr (&Sx_get_atom_name
);
2894 defsubr (&Sx_send_client_message
);
2895 defsubr (&Sx_register_dnd_atom
);
2897 reading_selection_reply
= Fcons (Qnil
, Qnil
);
2898 staticpro (&reading_selection_reply
);
2899 reading_selection_window
= 0;
2900 reading_which_selection
= 0;
2902 property_change_wait_list
= 0;
2903 prop_location_identifier
= 0;
2904 property_change_reply
= Fcons (Qnil
, Qnil
);
2905 staticpro (&property_change_reply
);
2907 Vselection_alist
= Qnil
;
2908 staticpro (&Vselection_alist
);
2910 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist
,
2911 doc
: /* An alist associating X Windows selection-types with functions.
2912 These functions are called to convert the selection, with three args:
2913 the name of the selection (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2914 a desired type to which the selection should be converted;
2915 and the local selection value (whatever was given to `x-own-selection').
2917 The function should return the value to send to the X server
2918 \(typically a string). A return value of nil
2919 means that the conversion could not be done.
2920 A return value which is the symbol `NULL'
2921 means that a side-effect was executed,
2922 and there is no meaningful selection value. */);
2923 Vselection_converter_alist
= Qnil
;
2925 DEFVAR_LISP ("x-lost-selection-functions", &Vx_lost_selection_functions
,
2926 doc
: /* A list of functions to be called when Emacs loses an X selection.
2927 \(This happens when some other X client makes its own selection
2928 or when a Lisp program explicitly clears the selection.)
2929 The functions are called with one argument, the selection type
2930 \(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'). */);
2931 Vx_lost_selection_functions
= Qnil
;
2933 DEFVAR_LISP ("x-sent-selection-functions", &Vx_sent_selection_functions
,
2934 doc
: /* A list of functions to be called when Emacs answers a selection request.
2935 The functions are called with four arguments:
2936 - the selection name (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2937 - the selection-type which Emacs was asked to convert the
2938 selection into before sending (for example, `STRING' or `LENGTH');
2939 - a flag indicating success or failure for responding to the request.
2940 We might have failed (and declined the request) for any number of reasons,
2941 including being asked for a selection that we no longer own, or being asked
2942 to convert into a type that we don't know about or that is inappropriate.
2943 This hook doesn't let you change the behavior of Emacs's selection replies,
2944 it merely informs you that they have happened. */);
2945 Vx_sent_selection_functions
= Qnil
;
2947 DEFVAR_INT ("x-selection-timeout", &x_selection_timeout
,
2948 doc
: /* Number of milliseconds to wait for a selection reply.
2949 If the selection owner doesn't reply in this time, we give up.
2950 A value of 0 means wait as long as necessary. This is initialized from the
2951 \"*selectionTimeout\" resource. */);
2952 x_selection_timeout
= 0;
2954 QPRIMARY
= intern_c_string ("PRIMARY"); staticpro (&QPRIMARY
);
2955 QSECONDARY
= intern_c_string ("SECONDARY"); staticpro (&QSECONDARY
);
2956 QSTRING
= intern_c_string ("STRING"); staticpro (&QSTRING
);
2957 QINTEGER
= intern_c_string ("INTEGER"); staticpro (&QINTEGER
);
2958 QCLIPBOARD
= intern_c_string ("CLIPBOARD"); staticpro (&QCLIPBOARD
);
2959 QTIMESTAMP
= intern_c_string ("TIMESTAMP"); staticpro (&QTIMESTAMP
);
2960 QTEXT
= intern_c_string ("TEXT"); staticpro (&QTEXT
);
2961 QCOMPOUND_TEXT
= intern_c_string ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT
);
2962 QUTF8_STRING
= intern_c_string ("UTF8_STRING"); staticpro (&QUTF8_STRING
);
2963 QDELETE
= intern_c_string ("DELETE"); staticpro (&QDELETE
);
2964 QMULTIPLE
= intern_c_string ("MULTIPLE"); staticpro (&QMULTIPLE
);
2965 QINCR
= intern_c_string ("INCR"); staticpro (&QINCR
);
2966 QEMACS_TMP
= intern_c_string ("_EMACS_TMP_"); staticpro (&QEMACS_TMP
);
2967 QTARGETS
= intern_c_string ("TARGETS"); staticpro (&QTARGETS
);
2968 QATOM
= intern_c_string ("ATOM"); staticpro (&QATOM
);
2969 QATOM_PAIR
= intern_c_string ("ATOM_PAIR"); staticpro (&QATOM_PAIR
);
2970 QNULL
= intern_c_string ("NULL"); staticpro (&QNULL
);
2971 Qcompound_text_with_extensions
= intern_c_string ("compound-text-with-extensions");
2972 staticpro (&Qcompound_text_with_extensions
);
2974 #ifdef CUT_BUFFER_SUPPORT
2975 QCUT_BUFFER0
= intern_c_string ("CUT_BUFFER0"); staticpro (&QCUT_BUFFER0
);
2976 QCUT_BUFFER1
= intern_c_string ("CUT_BUFFER1"); staticpro (&QCUT_BUFFER1
);
2977 QCUT_BUFFER2
= intern_c_string ("CUT_BUFFER2"); staticpro (&QCUT_BUFFER2
);
2978 QCUT_BUFFER3
= intern_c_string ("CUT_BUFFER3"); staticpro (&QCUT_BUFFER3
);
2979 QCUT_BUFFER4
= intern_c_string ("CUT_BUFFER4"); staticpro (&QCUT_BUFFER4
);
2980 QCUT_BUFFER5
= intern_c_string ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5
);
2981 QCUT_BUFFER6
= intern_c_string ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6
);
2982 QCUT_BUFFER7
= intern_c_string ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7
);
2985 Qforeign_selection
= intern_c_string ("foreign-selection");
2986 staticpro (&Qforeign_selection
);
2989 /* arch-tag: 7c293b0f-9918-4f69-8ac7-03e142307236
2990 (do not change this comment) */