1 /* X Selection processing for Emacs.
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003
3 Free Software Foundation.
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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Rewritten by jwz */
27 #include "xterm.h" /* for all of the X includes */
28 #include "dispextern.h" /* frame.h seems to want this */
29 #include "frame.h" /* Need this to get the X window of selected_frame */
30 #include "blockinput.h"
36 static Lisp_Object x_atom_to_symbol
P_ ((Display
*dpy
, Atom atom
));
37 static Atom symbol_to_x_atom
P_ ((struct x_display_info
*, Display
*,
39 static void x_own_selection
P_ ((Lisp_Object
, Lisp_Object
));
40 static Lisp_Object x_get_local_selection
P_ ((Lisp_Object
, Lisp_Object
, int));
41 static void x_decline_selection_request
P_ ((struct input_event
*));
42 static Lisp_Object x_selection_request_lisp_error
P_ ((Lisp_Object
));
43 static Lisp_Object queue_selection_requests_unwind
P_ ((Lisp_Object
));
44 static Lisp_Object some_frame_on_display
P_ ((struct x_display_info
*));
45 static void x_reply_selection_request
P_ ((struct input_event
*, int,
46 unsigned char *, int, Atom
));
47 static int waiting_for_other_props_on_window
P_ ((Display
*, Window
));
48 static struct prop_location
*expect_property_change
P_ ((Display
*, Window
,
50 static void unexpect_property_change
P_ ((struct prop_location
*));
51 static Lisp_Object wait_for_property_change_unwind
P_ ((Lisp_Object
));
52 static void wait_for_property_change
P_ ((struct prop_location
*));
53 static Lisp_Object x_get_foreign_selection
P_ ((Lisp_Object
, Lisp_Object
));
54 static void x_get_window_property
P_ ((Display
*, Window
, Atom
,
55 unsigned char **, int *,
56 Atom
*, int *, unsigned long *, int));
57 static void receive_incremental_selection
P_ ((Display
*, Window
, Atom
,
58 Lisp_Object
, unsigned,
59 unsigned char **, int *,
60 Atom
*, int *, unsigned long *));
61 static Lisp_Object x_get_window_property_as_lisp_data
P_ ((Display
*,
64 static Lisp_Object selection_data_to_lisp_data
P_ ((Display
*, unsigned char *,
66 static void lisp_data_to_selection_data
P_ ((Display
*, Lisp_Object
,
67 unsigned char **, Atom
*,
68 unsigned *, int *, int *));
69 static Lisp_Object clean_local_selection_data
P_ ((Lisp_Object
));
70 static void initialize_cut_buffers
P_ ((Display
*, Window
));
73 /* Printing traces to stderr. */
75 #ifdef TRACE_SELECTION
77 fprintf (stderr, "%d: " fmt "\n", getpid ())
78 #define TRACE1(fmt, a0) \
79 fprintf (stderr, "%d: " fmt "\n", getpid (), a0)
80 #define TRACE2(fmt, a0, a1) \
81 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1)
83 #define TRACE0(fmt) (void) 0
84 #define TRACE1(fmt, a0) (void) 0
85 #define TRACE2(fmt, a0, a1) (void) 0
89 #define CUT_BUFFER_SUPPORT
91 Lisp_Object QPRIMARY
, QSECONDARY
, QSTRING
, QINTEGER
, QCLIPBOARD
, QTIMESTAMP
,
92 QTEXT
, QDELETE
, QMULTIPLE
, QINCR
, QEMACS_TMP
, QTARGETS
, QATOM
, QNULL
,
95 Lisp_Object QCOMPOUND_TEXT
; /* This is a type of selection. */
96 Lisp_Object QUTF8_STRING
; /* This is a type of selection. */
98 Lisp_Object Qcompound_text_with_extensions
;
100 #ifdef CUT_BUFFER_SUPPORT
101 Lisp_Object QCUT_BUFFER0
, QCUT_BUFFER1
, QCUT_BUFFER2
, QCUT_BUFFER3
,
102 QCUT_BUFFER4
, QCUT_BUFFER5
, QCUT_BUFFER6
, QCUT_BUFFER7
;
105 static Lisp_Object Vx_lost_selection_hooks
;
106 static Lisp_Object Vx_sent_selection_hooks
;
107 /* Coding system for communicating with other X clients via cutbuffer,
108 selection, and clipboard. */
109 static Lisp_Object Vselection_coding_system
;
111 /* Coding system for the next communicating with other X clients. */
112 static Lisp_Object Vnext_selection_coding_system
;
114 static Lisp_Object Qforeign_selection
;
116 /* If this is a smaller number than the max-request-size of the display,
117 emacs will use INCR selection transfer when the selection is larger
118 than this. The max-request-size is usually around 64k, so if you want
119 emacs to use incremental selection transfers when the selection is
120 smaller than that, set this. I added this mostly for debugging the
121 incremental transfer stuff, but it might improve server performance. */
122 #define MAX_SELECTION_QUANTUM 0xFFFFFF
125 #define SELECTION_QUANTUM(dpy) ((XMaxRequestSize(dpy) << 2) - 100)
127 #define SELECTION_QUANTUM(dpy) (((dpy)->max_request_size << 2) - 100)
130 /* The timestamp of the last input event Emacs received from the X server. */
131 /* Defined in keyboard.c. */
132 extern unsigned long last_event_timestamp
;
134 /* This is an association list whose elements are of the form
135 ( SELECTION-NAME SELECTION-VALUE SELECTION-TIMESTAMP FRAME)
136 SELECTION-NAME is a lisp symbol, whose name is the name of an X Atom.
137 SELECTION-VALUE is the value that emacs owns for that selection.
138 It may be any kind of Lisp object.
139 SELECTION-TIMESTAMP is the time at which emacs began owning this selection,
140 as a cons of two 16-bit numbers (making a 32 bit time.)
141 FRAME is the frame for which we made the selection.
142 If there is an entry in this alist, then it can be assumed that Emacs owns
144 The only (eq) parts of this list that are visible from Lisp are the
146 static Lisp_Object Vselection_alist
;
148 /* This is an alist whose CARs are selection-types (whose names are the same
149 as the names of X Atoms) and whose CDRs are the names of Lisp functions to
150 call to convert the given Emacs selection value to a string representing
151 the given selection type. This is for Lisp-level extension of the emacs
152 selection handling. */
153 static Lisp_Object Vselection_converter_alist
;
155 /* If the selection owner takes too long to reply to a selection request,
156 we give up on it. This is in milliseconds (0 = no timeout.) */
157 static EMACS_INT x_selection_timeout
;
159 /* Utility functions */
161 static void lisp_data_to_selection_data ();
162 static Lisp_Object
selection_data_to_lisp_data ();
163 static Lisp_Object
x_get_window_property_as_lisp_data ();
165 /* This converts a Lisp symbol to a server Atom, avoiding a server
166 roundtrip whenever possible. */
169 symbol_to_x_atom (dpyinfo
, display
, sym
)
170 struct x_display_info
*dpyinfo
;
175 if (NILP (sym
)) return 0;
176 if (EQ (sym
, QPRIMARY
)) return XA_PRIMARY
;
177 if (EQ (sym
, QSECONDARY
)) return XA_SECONDARY
;
178 if (EQ (sym
, QSTRING
)) return XA_STRING
;
179 if (EQ (sym
, QINTEGER
)) return XA_INTEGER
;
180 if (EQ (sym
, QATOM
)) return XA_ATOM
;
181 if (EQ (sym
, QCLIPBOARD
)) return dpyinfo
->Xatom_CLIPBOARD
;
182 if (EQ (sym
, QTIMESTAMP
)) return dpyinfo
->Xatom_TIMESTAMP
;
183 if (EQ (sym
, QTEXT
)) return dpyinfo
->Xatom_TEXT
;
184 if (EQ (sym
, QCOMPOUND_TEXT
)) return dpyinfo
->Xatom_COMPOUND_TEXT
;
185 if (EQ (sym
, QUTF8_STRING
)) return dpyinfo
->Xatom_UTF8_STRING
;
186 if (EQ (sym
, QDELETE
)) return dpyinfo
->Xatom_DELETE
;
187 if (EQ (sym
, QMULTIPLE
)) return dpyinfo
->Xatom_MULTIPLE
;
188 if (EQ (sym
, QINCR
)) return dpyinfo
->Xatom_INCR
;
189 if (EQ (sym
, QEMACS_TMP
)) return dpyinfo
->Xatom_EMACS_TMP
;
190 if (EQ (sym
, QTARGETS
)) return dpyinfo
->Xatom_TARGETS
;
191 if (EQ (sym
, QNULL
)) return dpyinfo
->Xatom_NULL
;
192 #ifdef CUT_BUFFER_SUPPORT
193 if (EQ (sym
, QCUT_BUFFER0
)) return XA_CUT_BUFFER0
;
194 if (EQ (sym
, QCUT_BUFFER1
)) return XA_CUT_BUFFER1
;
195 if (EQ (sym
, QCUT_BUFFER2
)) return XA_CUT_BUFFER2
;
196 if (EQ (sym
, QCUT_BUFFER3
)) return XA_CUT_BUFFER3
;
197 if (EQ (sym
, QCUT_BUFFER4
)) return XA_CUT_BUFFER4
;
198 if (EQ (sym
, QCUT_BUFFER5
)) return XA_CUT_BUFFER5
;
199 if (EQ (sym
, QCUT_BUFFER6
)) return XA_CUT_BUFFER6
;
200 if (EQ (sym
, QCUT_BUFFER7
)) return XA_CUT_BUFFER7
;
202 if (!SYMBOLP (sym
)) abort ();
204 TRACE1 (" XInternAtom %s", (char *) SDATA (SYMBOL_NAME (sym
)));
206 val
= XInternAtom (display
, (char *) SDATA (SYMBOL_NAME (sym
)), False
);
212 /* This converts a server Atom to a Lisp symbol, avoiding server roundtrips
213 and calls to intern whenever possible. */
216 x_atom_to_symbol (dpy
, atom
)
220 struct x_display_info
*dpyinfo
;
239 #ifdef CUT_BUFFER_SUPPORT
259 dpyinfo
= x_display_info_for_display (dpy
);
260 if (atom
== dpyinfo
->Xatom_CLIPBOARD
)
262 if (atom
== dpyinfo
->Xatom_TIMESTAMP
)
264 if (atom
== dpyinfo
->Xatom_TEXT
)
266 if (atom
== dpyinfo
->Xatom_COMPOUND_TEXT
)
267 return QCOMPOUND_TEXT
;
268 if (atom
== dpyinfo
->Xatom_UTF8_STRING
)
270 if (atom
== dpyinfo
->Xatom_DELETE
)
272 if (atom
== dpyinfo
->Xatom_MULTIPLE
)
274 if (atom
== dpyinfo
->Xatom_INCR
)
276 if (atom
== dpyinfo
->Xatom_EMACS_TMP
)
278 if (atom
== dpyinfo
->Xatom_TARGETS
)
280 if (atom
== dpyinfo
->Xatom_NULL
)
284 str
= XGetAtomName (dpy
, atom
);
286 TRACE1 ("XGetAtomName --> %s", str
);
287 if (! str
) return Qnil
;
290 /* This was allocated by Xlib, so use XFree. */
296 /* Do protocol to assert ourself as a selection owner.
297 Update the Vselection_alist so that we can reply to later requests for
301 x_own_selection (selection_name
, selection_value
)
302 Lisp_Object selection_name
, selection_value
;
304 struct frame
*sf
= SELECTED_FRAME ();
305 Window selecting_window
;
307 Time time
= last_event_timestamp
;
309 struct x_display_info
*dpyinfo
;
312 if (! FRAME_X_P (sf
))
315 selecting_window
= FRAME_X_WINDOW (sf
);
316 display
= FRAME_X_DISPLAY (sf
);
317 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
319 CHECK_SYMBOL (selection_name
);
320 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection_name
);
323 count
= x_catch_errors (display
);
324 XSetSelectionOwner (display
, selection_atom
, selecting_window
, time
);
325 x_check_errors (display
, "Can't set selection: %s");
326 x_uncatch_errors (display
, count
);
329 /* Now update the local cache */
331 Lisp_Object selection_time
;
332 Lisp_Object selection_data
;
333 Lisp_Object prev_value
;
335 selection_time
= long_to_cons ((unsigned long) time
);
336 selection_data
= Fcons (selection_name
,
337 Fcons (selection_value
,
338 Fcons (selection_time
,
339 Fcons (selected_frame
, Qnil
))));
340 prev_value
= assq_no_quit (selection_name
, Vselection_alist
);
342 Vselection_alist
= Fcons (selection_data
, Vselection_alist
);
344 /* If we already owned the selection, remove the old selection data.
345 Perhaps we should destructively modify it instead.
346 Don't use Fdelq as that may QUIT. */
347 if (!NILP (prev_value
))
349 Lisp_Object rest
; /* we know it's not the CAR, so it's easy. */
350 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
351 if (EQ (prev_value
, Fcar (XCDR (rest
))))
353 XSETCDR (rest
, Fcdr (XCDR (rest
)));
360 /* Given a selection-name and desired type, look up our local copy of
361 the selection value and convert it to the type.
362 The value is nil or a string.
363 This function is used both for remote requests (LOCAL_REQUEST is zero)
364 and for local x-get-selection-internal (LOCAL_REQUEST is nonzero).
366 This calls random Lisp code, and may signal or gc. */
369 x_get_local_selection (selection_symbol
, target_type
, local_request
)
370 Lisp_Object selection_symbol
, target_type
;
373 Lisp_Object local_value
;
374 Lisp_Object handler_fn
, value
, type
, check
;
377 local_value
= assq_no_quit (selection_symbol
, Vselection_alist
);
379 if (NILP (local_value
)) return Qnil
;
381 /* TIMESTAMP and MULTIPLE are special cases 'cause that's easiest. */
382 if (EQ (target_type
, QTIMESTAMP
))
385 value
= XCAR (XCDR (XCDR (local_value
)));
388 else if (EQ (target_type
, QDELETE
))
391 Fx_disown_selection_internal
393 XCAR (XCDR (XCDR (local_value
))));
398 #if 0 /* #### MULTIPLE doesn't work yet */
399 else if (CONSP (target_type
)
400 && XCAR (target_type
) == QMULTIPLE
)
405 pairs
= XCDR (target_type
);
406 size
= XVECTOR (pairs
)->size
;
407 /* If the target is MULTIPLE, then target_type looks like
408 (MULTIPLE . [[SELECTION1 TARGET1] [SELECTION2 TARGET2] ... ])
409 We modify the second element of each pair in the vector and
410 return it as [[SELECTION1 <value1>] [SELECTION2 <value2>] ... ]
412 for (i
= 0; i
< size
; i
++)
415 pair
= XVECTOR (pairs
)->contents
[i
];
416 XVECTOR (pair
)->contents
[1]
417 = x_get_local_selection (XVECTOR (pair
)->contents
[0],
418 XVECTOR (pair
)->contents
[1],
426 /* Don't allow a quit within the converter.
427 When the user types C-g, he would be surprised
428 if by luck it came during a converter. */
429 count
= SPECPDL_INDEX ();
430 specbind (Qinhibit_quit
, Qt
);
432 CHECK_SYMBOL (target_type
);
433 handler_fn
= Fcdr (Fassq (target_type
, Vselection_converter_alist
));
434 /* gcpro is not needed here since nothing but HANDLER_FN
435 is live, and that ought to be a symbol. */
437 if (!NILP (handler_fn
))
438 value
= call3 (handler_fn
,
439 selection_symbol
, (local_request
? Qnil
: target_type
),
440 XCAR (XCDR (local_value
)));
443 unbind_to (count
, Qnil
);
446 /* Make sure this value is of a type that we could transmit
447 to another X client. */
451 && SYMBOLP (XCAR (value
)))
453 check
= XCDR (value
);
461 /* Check for a value that cons_to_long could handle. */
462 else if (CONSP (check
)
463 && INTEGERP (XCAR (check
))
464 && (INTEGERP (XCDR (check
))
466 (CONSP (XCDR (check
))
467 && INTEGERP (XCAR (XCDR (check
)))
468 && NILP (XCDR (XCDR (check
))))))
473 Fcons (build_string ("invalid data returned by selection-conversion function"),
474 Fcons (handler_fn
, Fcons (value
, Qnil
))));
477 /* Subroutines of x_reply_selection_request. */
479 /* Send a SelectionNotify event to the requestor with property=None,
480 meaning we were unable to do what they wanted. */
483 x_decline_selection_request (event
)
484 struct input_event
*event
;
486 XSelectionEvent reply
;
489 reply
.type
= SelectionNotify
;
490 reply
.display
= SELECTION_EVENT_DISPLAY (event
);
491 reply
.requestor
= SELECTION_EVENT_REQUESTOR (event
);
492 reply
.selection
= SELECTION_EVENT_SELECTION (event
);
493 reply
.time
= SELECTION_EVENT_TIME (event
);
494 reply
.target
= SELECTION_EVENT_TARGET (event
);
495 reply
.property
= None
;
497 /* The reason for the error may be that the receiver has
498 died in the meantime. Handle that case. */
500 count
= x_catch_errors (reply
.display
);
501 XSendEvent (reply
.display
, reply
.requestor
, False
, 0L, (XEvent
*) &reply
);
502 XFlush (reply
.display
);
503 x_uncatch_errors (reply
.display
, count
);
507 /* This is the selection request currently being processed.
508 It is set to zero when the request is fully processed. */
509 static struct input_event
*x_selection_current_request
;
511 /* Display info in x_selection_request. */
513 static struct x_display_info
*selection_request_dpyinfo
;
515 /* Used as an unwind-protect clause so that, if a selection-converter signals
516 an error, we tell the requester that we were unable to do what they wanted
517 before we throw to top-level or go into the debugger or whatever. */
520 x_selection_request_lisp_error (ignore
)
523 if (x_selection_current_request
!= 0
524 && selection_request_dpyinfo
->display
)
525 x_decline_selection_request (x_selection_current_request
);
530 /* This stuff is so that INCR selections are reentrant (that is, so we can
531 be servicing multiple INCR selection requests simultaneously.) I haven't
532 actually tested that yet. */
534 /* Keep a list of the property changes that are awaited. */
544 struct prop_location
*next
;
547 static struct prop_location
*expect_property_change ();
548 static void wait_for_property_change ();
549 static void unexpect_property_change ();
550 static int waiting_for_other_props_on_window ();
552 static int prop_location_identifier
;
554 static Lisp_Object property_change_reply
;
556 static struct prop_location
*property_change_reply_object
;
558 static struct prop_location
*property_change_wait_list
;
561 queue_selection_requests_unwind (frame
)
564 FRAME_PTR f
= XFRAME (frame
);
567 x_stop_queuing_selection_requests (FRAME_X_DISPLAY (f
));
571 /* Return some frame whose display info is DPYINFO.
572 Return nil if there is none. */
575 some_frame_on_display (dpyinfo
)
576 struct x_display_info
*dpyinfo
;
578 Lisp_Object list
, frame
;
580 FOR_EACH_FRAME (list
, frame
)
582 if (FRAME_X_P (XFRAME (frame
))
583 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
590 /* Send the reply to a selection request event EVENT.
591 TYPE is the type of selection data requested.
592 DATA and SIZE describe the data to send, already converted.
593 FORMAT is the unit-size (in bits) of the data to be transmitted. */
596 x_reply_selection_request (event
, format
, data
, size
, type
)
597 struct input_event
*event
;
602 XSelectionEvent reply
;
603 Display
*display
= SELECTION_EVENT_DISPLAY (event
);
604 Window window
= SELECTION_EVENT_REQUESTOR (event
);
606 int format_bytes
= format
/8;
607 int max_bytes
= SELECTION_QUANTUM (display
);
608 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
611 if (max_bytes
> MAX_SELECTION_QUANTUM
)
612 max_bytes
= MAX_SELECTION_QUANTUM
;
614 reply
.type
= SelectionNotify
;
615 reply
.display
= display
;
616 reply
.requestor
= window
;
617 reply
.selection
= SELECTION_EVENT_SELECTION (event
);
618 reply
.time
= SELECTION_EVENT_TIME (event
);
619 reply
.target
= SELECTION_EVENT_TARGET (event
);
620 reply
.property
= SELECTION_EVENT_PROPERTY (event
);
621 if (reply
.property
== None
)
622 reply
.property
= reply
.target
;
624 /* #### XChangeProperty can generate BadAlloc, and we must handle it! */
626 count
= x_catch_errors (display
);
628 /* Store the data on the requested property.
629 If the selection is large, only store the first N bytes of it.
631 bytes_remaining
= size
* format_bytes
;
632 if (bytes_remaining
<= max_bytes
)
634 /* Send all the data at once, with minimal handshaking. */
635 TRACE1 ("Sending all %d bytes", bytes_remaining
);
636 XChangeProperty (display
, window
, reply
.property
, type
, format
,
637 PropModeReplace
, data
, size
);
638 /* At this point, the selection was successfully stored; ack it. */
639 XSendEvent (display
, window
, False
, 0L, (XEvent
*) &reply
);
643 /* Send an INCR selection. */
644 struct prop_location
*wait_object
;
648 frame
= some_frame_on_display (dpyinfo
);
650 /* If the display no longer has frames, we can't expect
651 to get many more selection requests from it, so don't
652 bother trying to queue them. */
655 x_start_queuing_selection_requests (display
);
657 record_unwind_protect (queue_selection_requests_unwind
,
661 if (x_window_to_frame (dpyinfo
, window
)) /* #### debug */
662 error ("Attempt to transfer an INCR to ourself!");
664 TRACE2 ("Start sending %d bytes incrementally (%s)",
665 bytes_remaining
, XGetAtomName (display
, reply
.property
));
666 wait_object
= expect_property_change (display
, window
, reply
.property
,
669 TRACE1 ("Set %s to number of bytes to send",
670 XGetAtomName (display
, reply
.property
));
671 XChangeProperty (display
, window
, reply
.property
, dpyinfo
->Xatom_INCR
,
673 (unsigned char *) &bytes_remaining
, 1);
674 XSelectInput (display
, window
, PropertyChangeMask
);
676 /* Tell 'em the INCR data is there... */
677 TRACE0 ("Send SelectionNotify event");
678 XSendEvent (display
, window
, False
, 0L, (XEvent
*) &reply
);
681 had_errors
= x_had_errors_p (display
);
684 /* First, wait for the requester to ack by deleting the property.
685 This can run random lisp code (process handlers) or signal. */
688 TRACE1 ("Waiting for ACK (deletion of %s)",
689 XGetAtomName (display
, reply
.property
));
690 wait_for_property_change (wait_object
);
694 while (bytes_remaining
)
696 int i
= ((bytes_remaining
< max_bytes
)
703 = expect_property_change (display
, window
, reply
.property
,
706 TRACE1 ("Sending increment of %d bytes", i
);
707 TRACE1 ("Set %s to increment data",
708 XGetAtomName (display
, reply
.property
));
710 /* Append the next chunk of data to the property. */
711 XChangeProperty (display
, window
, reply
.property
, type
, format
,
712 PropModeAppend
, data
, i
/ format_bytes
);
713 bytes_remaining
-= i
;
716 had_errors
= x_had_errors_p (display
);
722 /* Now wait for the requester to ack this chunk by deleting the
723 property. This can run random lisp code or signal. */
724 TRACE1 ("Waiting for increment ACK (deletion of %s)",
725 XGetAtomName (display
, reply
.property
));
726 wait_for_property_change (wait_object
);
729 /* Now write a zero-length chunk to the property to tell the
730 requester that we're done. */
732 if (! waiting_for_other_props_on_window (display
, window
))
733 XSelectInput (display
, window
, 0L);
735 TRACE1 ("Set %s to a 0-length chunk to indicate EOF",
736 XGetAtomName (display
, reply
.property
));
737 XChangeProperty (display
, window
, reply
.property
, type
, format
,
738 PropModeReplace
, data
, 0);
739 TRACE0 ("Done sending incrementally");
742 /* rms, 2003-01-03: I think I have fixed this bug. */
743 /* The window we're communicating with may have been deleted
744 in the meantime (that's a real situation from a bug report).
745 In this case, there may be events in the event queue still
746 refering to the deleted window, and we'll get a BadWindow error
747 in XTread_socket when processing the events. I don't have
748 an idea how to fix that. gerd, 2001-01-98. */
750 x_uncatch_errors (display
, count
);
754 /* Handle a SelectionRequest event EVENT.
755 This is called from keyboard.c when such an event is found in the queue. */
758 x_handle_selection_request (event
)
759 struct input_event
*event
;
761 struct gcpro gcpro1
, gcpro2
, gcpro3
;
762 Lisp_Object local_selection_data
;
763 Lisp_Object selection_symbol
;
764 Lisp_Object target_symbol
;
765 Lisp_Object converted_selection
;
766 Time local_selection_time
;
767 Lisp_Object successful_p
;
769 struct x_display_info
*dpyinfo
770 = x_display_info_for_display (SELECTION_EVENT_DISPLAY (event
));
772 local_selection_data
= Qnil
;
773 target_symbol
= Qnil
;
774 converted_selection
= Qnil
;
777 GCPRO3 (local_selection_data
, converted_selection
, target_symbol
);
779 selection_symbol
= x_atom_to_symbol (SELECTION_EVENT_DISPLAY (event
),
780 SELECTION_EVENT_SELECTION (event
));
782 local_selection_data
= assq_no_quit (selection_symbol
, Vselection_alist
);
784 if (NILP (local_selection_data
))
786 /* Someone asked for the selection, but we don't have it any more.
788 x_decline_selection_request (event
);
792 local_selection_time
= (Time
)
793 cons_to_long (XCAR (XCDR (XCDR (local_selection_data
))));
795 if (SELECTION_EVENT_TIME (event
) != CurrentTime
796 && local_selection_time
> SELECTION_EVENT_TIME (event
))
798 /* Someone asked for the selection, and we have one, but not the one
801 x_decline_selection_request (event
);
805 x_selection_current_request
= event
;
806 count
= SPECPDL_INDEX ();
807 selection_request_dpyinfo
= dpyinfo
;
808 record_unwind_protect (x_selection_request_lisp_error
, Qnil
);
810 target_symbol
= x_atom_to_symbol (SELECTION_EVENT_DISPLAY (event
),
811 SELECTION_EVENT_TARGET (event
));
813 #if 0 /* #### MULTIPLE doesn't work yet */
814 if (EQ (target_symbol
, QMULTIPLE
))
815 target_symbol
= fetch_multiple_target (event
);
818 /* Convert lisp objects back into binary data */
821 = x_get_local_selection (selection_symbol
, target_symbol
, 0);
823 if (! NILP (converted_selection
))
831 lisp_data_to_selection_data (SELECTION_EVENT_DISPLAY (event
),
833 &data
, &type
, &size
, &format
, &nofree
);
835 x_reply_selection_request (event
, format
, data
, size
, type
);
838 /* Indicate we have successfully processed this event. */
839 x_selection_current_request
= 0;
841 /* Use xfree, not XFree, because lisp_data_to_selection_data
842 calls xmalloc itself. */
846 unbind_to (count
, Qnil
);
850 /* Let random lisp code notice that the selection has been asked for. */
853 rest
= Vx_sent_selection_hooks
;
854 if (!EQ (rest
, Qunbound
))
855 for (; CONSP (rest
); rest
= Fcdr (rest
))
856 call3 (Fcar (rest
), selection_symbol
, target_symbol
, successful_p
);
862 /* Handle a SelectionClear event EVENT, which indicates that some
863 client cleared out our previously asserted selection.
864 This is called from keyboard.c when such an event is found in the queue. */
867 x_handle_selection_clear (event
)
868 struct input_event
*event
;
870 Display
*display
= SELECTION_EVENT_DISPLAY (event
);
871 Atom selection
= SELECTION_EVENT_SELECTION (event
);
872 Time changed_owner_time
= SELECTION_EVENT_TIME (event
);
874 Lisp_Object selection_symbol
, local_selection_data
;
875 Time local_selection_time
;
876 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
877 struct x_display_info
*t_dpyinfo
;
879 /* If the new selection owner is also Emacs,
880 don't clear the new selection. */
882 /* Check each display on the same terminal,
883 to see if this Emacs job now owns the selection
884 through that display. */
885 for (t_dpyinfo
= x_display_list
; t_dpyinfo
; t_dpyinfo
= t_dpyinfo
->next
)
886 if (t_dpyinfo
->kboard
== dpyinfo
->kboard
)
889 = XGetSelectionOwner (t_dpyinfo
->display
, selection
);
890 if (x_window_to_frame (t_dpyinfo
, owner_window
) != 0)
898 selection_symbol
= x_atom_to_symbol (display
, selection
);
900 local_selection_data
= assq_no_quit (selection_symbol
, Vselection_alist
);
902 /* Well, we already believe that we don't own it, so that's just fine. */
903 if (NILP (local_selection_data
)) return;
905 local_selection_time
= (Time
)
906 cons_to_long (XCAR (XCDR (XCDR (local_selection_data
))));
908 /* This SelectionClear is for a selection that we no longer own, so we can
909 disregard it. (That is, we have reasserted the selection since this
910 request was generated.) */
912 if (changed_owner_time
!= CurrentTime
913 && local_selection_time
> changed_owner_time
)
916 /* Otherwise, we're really honest and truly being told to drop it.
917 Don't use Fdelq as that may QUIT;. */
919 if (EQ (local_selection_data
, Fcar (Vselection_alist
)))
920 Vselection_alist
= Fcdr (Vselection_alist
);
924 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
925 if (EQ (local_selection_data
, Fcar (XCDR (rest
))))
927 XSETCDR (rest
, Fcdr (XCDR (rest
)));
932 /* Let random lisp code notice that the selection has been stolen. */
936 rest
= Vx_lost_selection_hooks
;
937 if (!EQ (rest
, Qunbound
))
939 for (; CONSP (rest
); rest
= Fcdr (rest
))
940 call1 (Fcar (rest
), selection_symbol
);
941 prepare_menu_bars ();
942 redisplay_preserve_echo_area (20);
947 /* Clear all selections that were made from frame F.
948 We do this when about to delete a frame. */
951 x_clear_frame_selections (f
)
957 XSETFRAME (frame
, f
);
959 /* Otherwise, we're really honest and truly being told to drop it.
960 Don't use Fdelq as that may QUIT;. */
962 /* Delete elements from the beginning of Vselection_alist. */
963 while (!NILP (Vselection_alist
)
964 && EQ (frame
, Fcar (Fcdr (Fcdr (Fcdr (Fcar (Vselection_alist
)))))))
966 /* Let random Lisp code notice that the selection has been stolen. */
967 Lisp_Object hooks
, selection_symbol
;
969 hooks
= Vx_lost_selection_hooks
;
970 selection_symbol
= Fcar (Fcar (Vselection_alist
));
972 if (!EQ (hooks
, Qunbound
))
974 for (; CONSP (hooks
); hooks
= Fcdr (hooks
))
975 call1 (Fcar (hooks
), selection_symbol
);
976 #if 0 /* This can crash when deleting a frame
977 from x_connection_closed. Anyway, it seems unnecessary;
978 something else should cause a redisplay. */
979 redisplay_preserve_echo_area (21);
983 Vselection_alist
= Fcdr (Vselection_alist
);
986 /* Delete elements after the beginning of Vselection_alist. */
987 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
988 if (EQ (frame
, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest
))))))))
990 /* Let random Lisp code notice that the selection has been stolen. */
991 Lisp_Object hooks
, selection_symbol
;
993 hooks
= Vx_lost_selection_hooks
;
994 selection_symbol
= Fcar (Fcar (XCDR (rest
)));
996 if (!EQ (hooks
, Qunbound
))
998 for (; CONSP (hooks
); hooks
= Fcdr (hooks
))
999 call1 (Fcar (hooks
), selection_symbol
);
1000 #if 0 /* See above */
1001 redisplay_preserve_echo_area (22);
1004 XSETCDR (rest
, Fcdr (XCDR (rest
)));
1009 /* Nonzero if any properties for DISPLAY and WINDOW
1010 are on the list of what we are waiting for. */
1013 waiting_for_other_props_on_window (display
, window
)
1017 struct prop_location
*rest
= property_change_wait_list
;
1019 if (rest
->display
== display
&& rest
->window
== window
)
1026 /* Add an entry to the list of property changes we are waiting for.
1027 DISPLAY, WINDOW, PROPERTY, STATE describe what we will wait for.
1028 The return value is a number that uniquely identifies
1029 this awaited property change. */
1031 static struct prop_location
*
1032 expect_property_change (display
, window
, property
, state
)
1038 struct prop_location
*pl
= (struct prop_location
*) xmalloc (sizeof *pl
);
1039 pl
->identifier
= ++prop_location_identifier
;
1040 pl
->display
= display
;
1041 pl
->window
= window
;
1042 pl
->property
= property
;
1043 pl
->desired_state
= state
;
1044 pl
->next
= property_change_wait_list
;
1046 property_change_wait_list
= pl
;
1050 /* Delete an entry from the list of property changes we are waiting for.
1051 IDENTIFIER is the number that uniquely identifies the entry. */
1054 unexpect_property_change (location
)
1055 struct prop_location
*location
;
1057 struct prop_location
*prev
= 0, *rest
= property_change_wait_list
;
1060 if (rest
== location
)
1063 prev
->next
= rest
->next
;
1065 property_change_wait_list
= rest
->next
;
1074 /* Remove the property change expectation element for IDENTIFIER. */
1077 wait_for_property_change_unwind (identifierval
)
1078 Lisp_Object identifierval
;
1080 unexpect_property_change ((struct prop_location
*)
1081 (XFASTINT (XCAR (identifierval
)) << 16
1082 | XFASTINT (XCDR (identifierval
))));
1086 /* Actually wait for a property change.
1087 IDENTIFIER should be the value that expect_property_change returned. */
1090 wait_for_property_change (location
)
1091 struct prop_location
*location
;
1094 int count
= SPECPDL_INDEX ();
1097 tem
= Fcons (Qnil
, Qnil
);
1098 XSETCARFASTINT (tem
, (EMACS_UINT
)location
>> 16);
1099 XSETCDRFASTINT (tem
, (EMACS_UINT
)location
& 0xffff);
1101 /* Make sure to do unexpect_property_change if we quit or err. */
1102 record_unwind_protect (wait_for_property_change_unwind
, tem
);
1104 XSETCAR (property_change_reply
, Qnil
);
1106 property_change_reply_object
= location
;
1107 /* If the event we are waiting for arrives beyond here, it will set
1108 property_change_reply, because property_change_reply_object says so. */
1109 if (! location
->arrived
)
1111 secs
= x_selection_timeout
/ 1000;
1112 usecs
= (x_selection_timeout
% 1000) * 1000;
1113 TRACE2 (" Waiting %d secs, %d usecs", secs
, usecs
);
1114 wait_reading_process_input (secs
, usecs
, property_change_reply
, 0);
1116 if (NILP (XCAR (property_change_reply
)))
1118 TRACE0 (" Timed out");
1119 error ("Timed out waiting for property-notify event");
1123 unbind_to (count
, Qnil
);
1126 /* Called from XTread_socket in response to a PropertyNotify event. */
1129 x_handle_property_notify (event
)
1130 XPropertyEvent
*event
;
1132 struct prop_location
*prev
= 0, *rest
= property_change_wait_list
;
1136 if (rest
->property
== event
->atom
1137 && rest
->window
== event
->window
1138 && rest
->display
== event
->display
1139 && rest
->desired_state
== event
->state
)
1141 TRACE2 ("Expected %s of property %s",
1142 (event
->state
== PropertyDelete
? "deletion" : "change"),
1143 XGetAtomName (event
->display
, event
->atom
));
1147 /* If this is the one wait_for_property_change is waiting for,
1148 tell it to wake up. */
1149 if (rest
== property_change_reply_object
)
1150 XSETCAR (property_change_reply
, Qt
);
1153 prev
->next
= rest
->next
;
1155 property_change_wait_list
= rest
->next
;
1167 #if 0 /* #### MULTIPLE doesn't work yet */
1170 fetch_multiple_target (event
)
1171 XSelectionRequestEvent
*event
;
1173 Display
*display
= event
->display
;
1174 Window window
= event
->requestor
;
1175 Atom target
= event
->target
;
1176 Atom selection_atom
= event
->selection
;
1181 x_get_window_property_as_lisp_data (display
, window
, target
,
1182 QMULTIPLE
, selection_atom
));
1186 copy_multiple_data (obj
)
1193 return Fcons (XCAR (obj
), copy_multiple_data (XCDR (obj
)));
1196 vec
= Fmake_vector (size
= XVECTOR (obj
)->size
, Qnil
);
1197 for (i
= 0; i
< size
; i
++)
1199 Lisp_Object vec2
= XVECTOR (obj
)->contents
[i
];
1200 CHECK_VECTOR (vec2
);
1201 if (XVECTOR (vec2
)->size
!= 2)
1202 /* ??? Confusing error message */
1203 Fsignal (Qerror
, Fcons (build_string ("vectors must be of length 2"),
1204 Fcons (vec2
, Qnil
)));
1205 XVECTOR (vec
)->contents
[i
] = Fmake_vector (2, Qnil
);
1206 XVECTOR (XVECTOR (vec
)->contents
[i
])->contents
[0]
1207 = XVECTOR (vec2
)->contents
[0];
1208 XVECTOR (XVECTOR (vec
)->contents
[i
])->contents
[1]
1209 = XVECTOR (vec2
)->contents
[1];
1217 /* Variables for communication with x_handle_selection_notify. */
1218 static Atom reading_which_selection
;
1219 static Lisp_Object reading_selection_reply
;
1220 static Window reading_selection_window
;
1222 /* Do protocol to read selection-data from the server.
1223 Converts this to Lisp data and returns it. */
1226 x_get_foreign_selection (selection_symbol
, target_type
)
1227 Lisp_Object selection_symbol
, target_type
;
1229 struct frame
*sf
= SELECTED_FRAME ();
1230 Window requestor_window
;
1232 struct x_display_info
*dpyinfo
;
1233 Time requestor_time
= last_event_timestamp
;
1234 Atom target_property
;
1235 Atom selection_atom
;
1241 if (! FRAME_X_P (sf
))
1244 requestor_window
= FRAME_X_WINDOW (sf
);
1245 display
= FRAME_X_DISPLAY (sf
);
1246 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
1247 target_property
= dpyinfo
->Xatom_EMACS_TMP
;
1248 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection_symbol
);
1250 if (CONSP (target_type
))
1251 type_atom
= symbol_to_x_atom (dpyinfo
, display
, XCAR (target_type
));
1253 type_atom
= symbol_to_x_atom (dpyinfo
, display
, target_type
);
1257 count
= x_catch_errors (display
);
1259 TRACE2 ("Get selection %s, type %s",
1260 XGetAtomName (display
, type_atom
),
1261 XGetAtomName (display
, target_property
));
1263 XConvertSelection (display
, selection_atom
, type_atom
, target_property
,
1264 requestor_window
, requestor_time
);
1267 /* Prepare to block until the reply has been read. */
1268 reading_selection_window
= requestor_window
;
1269 reading_which_selection
= selection_atom
;
1270 XSETCAR (reading_selection_reply
, Qnil
);
1272 frame
= some_frame_on_display (dpyinfo
);
1274 /* If the display no longer has frames, we can't expect
1275 to get many more selection requests from it, so don't
1276 bother trying to queue them. */
1279 x_start_queuing_selection_requests (display
);
1281 record_unwind_protect (queue_selection_requests_unwind
,
1286 /* This allows quits. Also, don't wait forever. */
1287 secs
= x_selection_timeout
/ 1000;
1288 usecs
= (x_selection_timeout
% 1000) * 1000;
1289 TRACE1 (" Start waiting %d secs for SelectionNotify", secs
);
1290 wait_reading_process_input (secs
, usecs
, reading_selection_reply
, 0);
1291 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply
)));
1294 x_check_errors (display
, "Cannot get selection: %s");
1295 x_uncatch_errors (display
, count
);
1298 if (NILP (XCAR (reading_selection_reply
)))
1299 error ("Timed out waiting for reply from selection owner");
1300 if (EQ (XCAR (reading_selection_reply
), Qlambda
))
1301 error ("No `%s' selection", SDATA (SYMBOL_NAME (selection_symbol
)));
1303 /* Otherwise, the selection is waiting for us on the requested property. */
1305 x_get_window_property_as_lisp_data (display
, requestor_window
,
1306 target_property
, target_type
,
1310 /* Subroutines of x_get_window_property_as_lisp_data */
1312 /* Use xfree, not XFree, to free the data obtained with this function. */
1315 x_get_window_property (display
, window
, property
, data_ret
, bytes_ret
,
1316 actual_type_ret
, actual_format_ret
, actual_size_ret
,
1321 unsigned char **data_ret
;
1323 Atom
*actual_type_ret
;
1324 int *actual_format_ret
;
1325 unsigned long *actual_size_ret
;
1329 unsigned long bytes_remaining
;
1331 unsigned char *tmp_data
= 0;
1333 int buffer_size
= SELECTION_QUANTUM (display
);
1335 if (buffer_size
> MAX_SELECTION_QUANTUM
)
1336 buffer_size
= MAX_SELECTION_QUANTUM
;
1340 /* First probe the thing to find out how big it is. */
1341 result
= XGetWindowProperty (display
, window
, property
,
1342 0L, 0L, False
, AnyPropertyType
,
1343 actual_type_ret
, actual_format_ret
,
1345 &bytes_remaining
, &tmp_data
);
1346 if (result
!= Success
)
1354 /* This was allocated by Xlib, so use XFree. */
1355 XFree ((char *) tmp_data
);
1357 if (*actual_type_ret
== None
|| *actual_format_ret
== 0)
1363 total_size
= bytes_remaining
+ 1;
1364 *data_ret
= (unsigned char *) xmalloc (total_size
);
1366 /* Now read, until we've gotten it all. */
1367 while (bytes_remaining
)
1369 #ifdef TRACE_SELECTION
1370 int last
= bytes_remaining
;
1373 = XGetWindowProperty (display
, window
, property
,
1374 (long)offset
/4, (long)buffer_size
/4,
1377 actual_type_ret
, actual_format_ret
,
1378 actual_size_ret
, &bytes_remaining
, &tmp_data
);
1380 TRACE2 ("Read %ld bytes from property %s",
1381 last
- bytes_remaining
,
1382 XGetAtomName (display
, property
));
1384 /* If this doesn't return Success at this point, it means that
1385 some clod deleted the selection while we were in the midst of
1386 reading it. Deal with that, I guess.... */
1387 if (result
!= Success
)
1389 *actual_size_ret
*= *actual_format_ret
/ 8;
1390 bcopy (tmp_data
, (*data_ret
) + offset
, *actual_size_ret
);
1391 offset
+= *actual_size_ret
;
1393 /* This was allocated by Xlib, so use XFree. */
1394 XFree ((char *) tmp_data
);
1399 *bytes_ret
= offset
;
1402 /* Use xfree, not XFree, to free the data obtained with this function. */
1405 receive_incremental_selection (display
, window
, property
, target_type
,
1406 min_size_bytes
, data_ret
, size_bytes_ret
,
1407 type_ret
, format_ret
, size_ret
)
1411 Lisp_Object target_type
; /* for error messages only */
1412 unsigned int min_size_bytes
;
1413 unsigned char **data_ret
;
1414 int *size_bytes_ret
;
1416 unsigned long *size_ret
;
1420 struct prop_location
*wait_object
;
1421 *size_bytes_ret
= min_size_bytes
;
1422 *data_ret
= (unsigned char *) xmalloc (*size_bytes_ret
);
1424 TRACE1 ("Read %d bytes incrementally", min_size_bytes
);
1426 /* At this point, we have read an INCR property.
1427 Delete the property to ack it.
1428 (But first, prepare to receive the next event in this handshake.)
1430 Now, we must loop, waiting for the sending window to put a value on
1431 that property, then reading the property, then deleting it to ack.
1432 We are done when the sender places a property of length 0.
1435 XSelectInput (display
, window
, STANDARD_EVENT_SET
| PropertyChangeMask
);
1436 TRACE1 (" Delete property %s",
1437 XSYMBOL (x_atom_to_symbol (display
, property
))->name
->data
);
1438 XDeleteProperty (display
, window
, property
);
1439 TRACE1 (" Expect new value of property %s",
1440 XSYMBOL (x_atom_to_symbol (display
, property
))->name
->data
);
1441 wait_object
= expect_property_change (display
, window
, property
,
1448 unsigned char *tmp_data
;
1451 TRACE0 (" Wait for property change");
1452 wait_for_property_change (wait_object
);
1454 /* expect it again immediately, because x_get_window_property may
1455 .. no it won't, I don't get it.
1456 .. Ok, I get it now, the Xt code that implements INCR is broken. */
1457 TRACE0 (" Get property value");
1458 x_get_window_property (display
, window
, property
,
1459 &tmp_data
, &tmp_size_bytes
,
1460 type_ret
, format_ret
, size_ret
, 1);
1462 TRACE1 (" Read increment of %d bytes", tmp_size_bytes
);
1464 if (tmp_size_bytes
== 0) /* we're done */
1466 TRACE0 ("Done reading incrementally");
1468 if (! waiting_for_other_props_on_window (display
, window
))
1469 XSelectInput (display
, window
, STANDARD_EVENT_SET
);
1470 unexpect_property_change (wait_object
);
1471 /* Use xfree, not XFree, because x_get_window_property
1472 calls xmalloc itself. */
1473 if (tmp_data
) xfree (tmp_data
);
1478 TRACE1 (" ACK by deleting property %s",
1479 XGetAtomName (display
, property
));
1480 XDeleteProperty (display
, window
, property
);
1481 wait_object
= expect_property_change (display
, window
, property
,
1486 if (*size_bytes_ret
< offset
+ tmp_size_bytes
)
1488 *size_bytes_ret
= offset
+ tmp_size_bytes
;
1489 *data_ret
= (unsigned char *) xrealloc (*data_ret
, *size_bytes_ret
);
1492 bcopy (tmp_data
, (*data_ret
) + offset
, tmp_size_bytes
);
1493 offset
+= tmp_size_bytes
;
1495 /* Use xfree, not XFree, because x_get_window_property
1496 calls xmalloc itself. */
1502 /* Once a requested selection is "ready" (we got a SelectionNotify event),
1503 fetch value from property PROPERTY of X window WINDOW on display DISPLAY.
1504 TARGET_TYPE and SELECTION_ATOM are used in error message if this fails. */
1507 x_get_window_property_as_lisp_data (display
, window
, property
, target_type
,
1512 Lisp_Object target_type
; /* for error messages only */
1513 Atom selection_atom
; /* for error messages only */
1517 unsigned long actual_size
;
1518 unsigned char *data
= 0;
1521 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1523 TRACE0 ("Reading selection data");
1525 x_get_window_property (display
, window
, property
, &data
, &bytes
,
1526 &actual_type
, &actual_format
, &actual_size
, 1);
1529 int there_is_a_selection_owner
;
1531 there_is_a_selection_owner
1532 = XGetSelectionOwner (display
, selection_atom
);
1535 there_is_a_selection_owner
1536 ? Fcons (build_string ("selection owner couldn't convert"),
1538 ? Fcons (target_type
,
1539 Fcons (x_atom_to_symbol (display
,
1542 : Fcons (target_type
, Qnil
))
1543 : Fcons (build_string ("no selection"),
1544 Fcons (x_atom_to_symbol (display
,
1549 if (actual_type
== dpyinfo
->Xatom_INCR
)
1551 /* That wasn't really the data, just the beginning. */
1553 unsigned int min_size_bytes
= * ((unsigned int *) data
);
1555 /* Use xfree, not XFree, because x_get_window_property
1556 calls xmalloc itself. */
1557 xfree ((char *) data
);
1559 receive_incremental_selection (display
, window
, property
, target_type
,
1560 min_size_bytes
, &data
, &bytes
,
1561 &actual_type
, &actual_format
,
1566 TRACE1 (" Delete property %s", XGetAtomName (display
, property
));
1567 XDeleteProperty (display
, window
, property
);
1571 /* It's been read. Now convert it to a lisp object in some semi-rational
1573 val
= selection_data_to_lisp_data (display
, data
, bytes
,
1574 actual_type
, actual_format
);
1576 /* Use xfree, not XFree, because x_get_window_property
1577 calls xmalloc itself. */
1578 xfree ((char *) data
);
1582 /* These functions convert from the selection data read from the server into
1583 something that we can use from Lisp, and vice versa.
1585 Type: Format: Size: Lisp Type:
1586 ----- ------- ----- -----------
1589 ATOM 32 > 1 Vector of Symbols
1591 * 16 > 1 Vector of Integers
1592 * 32 1 if <=16 bits: Integer
1593 if > 16 bits: Cons of top16, bot16
1594 * 32 > 1 Vector of the above
1596 When converting a Lisp number to C, it is assumed to be of format 16 if
1597 it is an integer, and of format 32 if it is a cons of two integers.
1599 When converting a vector of numbers from Lisp to C, it is assumed to be
1600 of format 16 if every element in the vector is an integer, and is assumed
1601 to be of format 32 if any element is a cons of two integers.
1603 When converting an object to C, it may be of the form (SYMBOL . <data>)
1604 where SYMBOL is what we should claim that the type is. Format and
1605 representation are as above. */
1610 selection_data_to_lisp_data (display
, data
, size
, type
, format
)
1612 unsigned char *data
;
1616 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1618 if (type
== dpyinfo
->Xatom_NULL
)
1621 /* Convert any 8-bit data to a string, for compactness. */
1622 else if (format
== 8)
1624 Lisp_Object str
, lispy_type
;
1626 str
= make_unibyte_string ((char *) data
, size
);
1627 /* Indicate that this string is from foreign selection by a text
1628 property `foreign-selection' so that the caller of
1629 x-get-selection-internal (usually x-get-selection) can know
1630 that the string must be decode. */
1631 if (type
== dpyinfo
->Xatom_COMPOUND_TEXT
)
1632 lispy_type
= QCOMPOUND_TEXT
;
1633 else if (type
== dpyinfo
->Xatom_UTF8_STRING
)
1634 lispy_type
= QUTF8_STRING
;
1636 lispy_type
= QSTRING
;
1637 Fput_text_property (make_number (0), make_number (size
),
1638 Qforeign_selection
, lispy_type
, str
);
1641 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to
1642 a vector of symbols.
1644 else if (type
== XA_ATOM
)
1647 if (size
== sizeof (Atom
))
1648 return x_atom_to_symbol (display
, *((Atom
*) data
));
1651 Lisp_Object v
= Fmake_vector (make_number (size
/ sizeof (Atom
)),
1653 for (i
= 0; i
< size
/ sizeof (Atom
); i
++)
1654 Faset (v
, make_number (i
),
1655 x_atom_to_symbol (display
, ((Atom
*) data
) [i
]));
1660 /* Convert a single 16 or small 32 bit number to a Lisp_Int.
1661 If the number is > 16 bits, convert it to a cons of integers,
1662 16 bits in each half.
1664 else if (format
== 32 && size
== sizeof (int))
1665 return long_to_cons (((unsigned int *) data
) [0]);
1666 else if (format
== 16 && size
== sizeof (short))
1667 return make_number ((int) (((unsigned short *) data
) [0]));
1669 /* Convert any other kind of data to a vector of numbers, represented
1670 as above (as an integer, or a cons of two 16 bit integers.)
1672 else if (format
== 16)
1676 v
= Fmake_vector (make_number (size
/ 2), make_number (0));
1677 for (i
= 0; i
< size
/ 2; i
++)
1679 int j
= (int) ((unsigned short *) data
) [i
];
1680 Faset (v
, make_number (i
), make_number (j
));
1687 Lisp_Object v
= Fmake_vector (make_number (size
/ 4), make_number (0));
1688 for (i
= 0; i
< size
/ 4; i
++)
1690 unsigned int j
= ((unsigned int *) data
) [i
];
1691 Faset (v
, make_number (i
), long_to_cons (j
));
1698 /* Use xfree, not XFree, to free the data obtained with this function. */
1701 lisp_data_to_selection_data (display
, obj
,
1702 data_ret
, type_ret
, size_ret
,
1703 format_ret
, nofree_ret
)
1706 unsigned char **data_ret
;
1708 unsigned int *size_ret
;
1712 Lisp_Object type
= Qnil
;
1713 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1717 if (CONSP (obj
) && SYMBOLP (XCAR (obj
)))
1721 if (CONSP (obj
) && NILP (XCDR (obj
)))
1725 if (EQ (obj
, QNULL
) || (EQ (type
, QNULL
)))
1726 { /* This is not the same as declining */
1732 else if (STRINGP (obj
))
1734 xassert (! STRING_MULTIBYTE (obj
));
1738 *size_ret
= SBYTES (obj
);
1739 *data_ret
= SDATA (obj
);
1742 else if (SYMBOLP (obj
))
1746 *data_ret
= (unsigned char *) xmalloc (sizeof (Atom
) + 1);
1747 (*data_ret
) [sizeof (Atom
)] = 0;
1748 (*(Atom
**) data_ret
) [0] = symbol_to_x_atom (dpyinfo
, display
, obj
);
1749 if (NILP (type
)) type
= QATOM
;
1751 else if (INTEGERP (obj
)
1752 && XINT (obj
) < 0xFFFF
1753 && XINT (obj
) > -0xFFFF)
1757 *data_ret
= (unsigned char *) xmalloc (sizeof (short) + 1);
1758 (*data_ret
) [sizeof (short)] = 0;
1759 (*(short **) data_ret
) [0] = (short) XINT (obj
);
1760 if (NILP (type
)) type
= QINTEGER
;
1762 else if (INTEGERP (obj
)
1763 || (CONSP (obj
) && INTEGERP (XCAR (obj
))
1764 && (INTEGERP (XCDR (obj
))
1765 || (CONSP (XCDR (obj
))
1766 && INTEGERP (XCAR (XCDR (obj
)))))))
1770 *data_ret
= (unsigned char *) xmalloc (sizeof (long) + 1);
1771 (*data_ret
) [sizeof (long)] = 0;
1772 (*(unsigned long **) data_ret
) [0] = cons_to_long (obj
);
1773 if (NILP (type
)) type
= QINTEGER
;
1775 else if (VECTORP (obj
))
1777 /* Lisp_Vectors may represent a set of ATOMs;
1778 a set of 16 or 32 bit INTEGERs;
1779 or a set of ATOM_PAIRs (represented as [[A1 A2] [A3 A4] ...]
1783 if (SYMBOLP (XVECTOR (obj
)->contents
[0]))
1784 /* This vector is an ATOM set */
1786 if (NILP (type
)) type
= QATOM
;
1787 *size_ret
= XVECTOR (obj
)->size
;
1789 *data_ret
= (unsigned char *) xmalloc ((*size_ret
) * sizeof (Atom
));
1790 for (i
= 0; i
< *size_ret
; i
++)
1791 if (SYMBOLP (XVECTOR (obj
)->contents
[i
]))
1792 (*(Atom
**) data_ret
) [i
]
1793 = symbol_to_x_atom (dpyinfo
, display
, XVECTOR (obj
)->contents
[i
]);
1795 Fsignal (Qerror
, /* Qselection_error */
1797 ("all elements of selection vector must have same type"),
1798 Fcons (obj
, Qnil
)));
1800 #if 0 /* #### MULTIPLE doesn't work yet */
1801 else if (VECTORP (XVECTOR (obj
)->contents
[0]))
1802 /* This vector is an ATOM_PAIR set */
1804 if (NILP (type
)) type
= QATOM_PAIR
;
1805 *size_ret
= XVECTOR (obj
)->size
;
1807 *data_ret
= (unsigned char *)
1808 xmalloc ((*size_ret
) * sizeof (Atom
) * 2);
1809 for (i
= 0; i
< *size_ret
; i
++)
1810 if (VECTORP (XVECTOR (obj
)->contents
[i
]))
1812 Lisp_Object pair
= XVECTOR (obj
)->contents
[i
];
1813 if (XVECTOR (pair
)->size
!= 2)
1816 ("elements of the vector must be vectors of exactly two elements"),
1817 Fcons (pair
, Qnil
)));
1819 (*(Atom
**) data_ret
) [i
* 2]
1820 = symbol_to_x_atom (dpyinfo
, display
,
1821 XVECTOR (pair
)->contents
[0]);
1822 (*(Atom
**) data_ret
) [(i
* 2) + 1]
1823 = symbol_to_x_atom (dpyinfo
, display
,
1824 XVECTOR (pair
)->contents
[1]);
1829 ("all elements of the vector must be of the same type"),
1830 Fcons (obj
, Qnil
)));
1835 /* This vector is an INTEGER set, or something like it */
1837 *size_ret
= XVECTOR (obj
)->size
;
1838 if (NILP (type
)) type
= QINTEGER
;
1840 for (i
= 0; i
< *size_ret
; i
++)
1841 if (CONSP (XVECTOR (obj
)->contents
[i
]))
1843 else if (!INTEGERP (XVECTOR (obj
)->contents
[i
]))
1844 Fsignal (Qerror
, /* Qselection_error */
1846 ("elements of selection vector must be integers or conses of integers"),
1847 Fcons (obj
, Qnil
)));
1849 *data_ret
= (unsigned char *) xmalloc (*size_ret
* (*format_ret
/8));
1850 for (i
= 0; i
< *size_ret
; i
++)
1851 if (*format_ret
== 32)
1852 (*((unsigned long **) data_ret
)) [i
]
1853 = cons_to_long (XVECTOR (obj
)->contents
[i
]);
1855 (*((unsigned short **) data_ret
)) [i
]
1856 = (unsigned short) cons_to_long (XVECTOR (obj
)->contents
[i
]);
1860 Fsignal (Qerror
, /* Qselection_error */
1861 Fcons (build_string ("unrecognised selection data"),
1862 Fcons (obj
, Qnil
)));
1864 *type_ret
= symbol_to_x_atom (dpyinfo
, display
, type
);
1868 clean_local_selection_data (obj
)
1872 && INTEGERP (XCAR (obj
))
1873 && CONSP (XCDR (obj
))
1874 && INTEGERP (XCAR (XCDR (obj
)))
1875 && NILP (XCDR (XCDR (obj
))))
1876 obj
= Fcons (XCAR (obj
), XCDR (obj
));
1879 && INTEGERP (XCAR (obj
))
1880 && INTEGERP (XCDR (obj
)))
1882 if (XINT (XCAR (obj
)) == 0)
1884 if (XINT (XCAR (obj
)) == -1)
1885 return make_number (- XINT (XCDR (obj
)));
1890 int size
= XVECTOR (obj
)->size
;
1893 return clean_local_selection_data (XVECTOR (obj
)->contents
[0]);
1894 copy
= Fmake_vector (make_number (size
), Qnil
);
1895 for (i
= 0; i
< size
; i
++)
1896 XVECTOR (copy
)->contents
[i
]
1897 = clean_local_selection_data (XVECTOR (obj
)->contents
[i
]);
1903 /* Called from XTread_socket to handle SelectionNotify events.
1904 If it's the selection we are waiting for, stop waiting
1905 by setting the car of reading_selection_reply to non-nil.
1906 We store t there if the reply is successful, lambda if not. */
1909 x_handle_selection_notify (event
)
1910 XSelectionEvent
*event
;
1912 if (event
->requestor
!= reading_selection_window
)
1914 if (event
->selection
!= reading_which_selection
)
1917 TRACE0 ("Received SelectionNotify");
1918 XSETCAR (reading_selection_reply
,
1919 (event
->property
!= 0 ? Qt
: Qlambda
));
1923 DEFUN ("x-own-selection-internal", Fx_own_selection_internal
,
1924 Sx_own_selection_internal
, 2, 2, 0,
1925 doc
: /* Assert an X selection of the given TYPE with the given VALUE.
1926 TYPE is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
1927 \(Those are literal upper-case symbol names, since that's what X expects.)
1928 VALUE is typically a string, or a cons of two markers, but may be
1929 anything that the functions on `selection-converter-alist' know about. */)
1930 (selection_name
, selection_value
)
1931 Lisp_Object selection_name
, selection_value
;
1934 CHECK_SYMBOL (selection_name
);
1935 if (NILP (selection_value
)) error ("selection-value may not be nil");
1936 x_own_selection (selection_name
, selection_value
);
1937 return selection_value
;
1941 /* Request the selection value from the owner. If we are the owner,
1942 simply return our selection value. If we are not the owner, this
1943 will block until all of the data has arrived. */
1945 DEFUN ("x-get-selection-internal", Fx_get_selection_internal
,
1946 Sx_get_selection_internal
, 2, 2, 0,
1947 doc
: /* Return text selected from some X window.
1948 SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
1949 \(Those are literal upper-case symbol names, since that's what X expects.)
1950 TYPE is the type of data desired, typically `STRING'. */)
1951 (selection_symbol
, target_type
)
1952 Lisp_Object selection_symbol
, target_type
;
1954 Lisp_Object val
= Qnil
;
1955 struct gcpro gcpro1
, gcpro2
;
1956 GCPRO2 (target_type
, val
); /* we store newly consed data into these */
1958 CHECK_SYMBOL (selection_symbol
);
1960 #if 0 /* #### MULTIPLE doesn't work yet */
1961 if (CONSP (target_type
)
1962 && XCAR (target_type
) == QMULTIPLE
)
1964 CHECK_VECTOR (XCDR (target_type
));
1965 /* So we don't destructively modify this... */
1966 target_type
= copy_multiple_data (target_type
);
1970 CHECK_SYMBOL (target_type
);
1972 val
= x_get_local_selection (selection_symbol
, target_type
, 1);
1976 val
= x_get_foreign_selection (selection_symbol
, target_type
);
1981 && SYMBOLP (XCAR (val
)))
1984 if (CONSP (val
) && NILP (XCDR (val
)))
1987 val
= clean_local_selection_data (val
);
1993 DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal
,
1994 Sx_disown_selection_internal
, 1, 2, 0,
1995 doc
: /* If we own the selection SELECTION, disown it.
1996 Disowning it means there is no such selection. */)
1998 Lisp_Object selection
;
2002 Atom selection_atom
;
2003 struct selection_input_event event
;
2005 struct x_display_info
*dpyinfo
;
2006 struct frame
*sf
= SELECTED_FRAME ();
2009 if (! FRAME_X_P (sf
))
2012 display
= FRAME_X_DISPLAY (sf
);
2013 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2014 CHECK_SYMBOL (selection
);
2016 timestamp
= last_event_timestamp
;
2018 timestamp
= cons_to_long (time
);
2020 if (NILP (assq_no_quit (selection
, Vselection_alist
)))
2021 return Qnil
; /* Don't disown the selection when we're not the owner. */
2023 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection
);
2026 XSetSelectionOwner (display
, selection_atom
, None
, timestamp
);
2029 /* It doesn't seem to be guaranteed that a SelectionClear event will be
2030 generated for a window which owns the selection when that window sets
2031 the selection owner to None. The NCD server does, the MIT Sun4 server
2032 doesn't. So we synthesize one; this means we might get two, but
2033 that's ok, because the second one won't have any effect. */
2034 SELECTION_EVENT_DISPLAY (&event
) = display
;
2035 SELECTION_EVENT_SELECTION (&event
) = selection_atom
;
2036 SELECTION_EVENT_TIME (&event
) = timestamp
;
2037 x_handle_selection_clear ((struct input_event
*) &event
);
2042 /* Get rid of all the selections in buffer BUFFER.
2043 This is used when we kill a buffer. */
2046 x_disown_buffer_selections (buffer
)
2050 struct buffer
*buf
= XBUFFER (buffer
);
2052 for (tail
= Vselection_alist
; CONSP (tail
); tail
= XCDR (tail
))
2054 Lisp_Object elt
, value
;
2057 if (CONSP (value
) && MARKERP (XCAR (value
))
2058 && XMARKER (XCAR (value
))->buffer
== buf
)
2059 Fx_disown_selection_internal (XCAR (elt
), Qnil
);
2063 DEFUN ("x-selection-owner-p", Fx_selection_owner_p
, Sx_selection_owner_p
,
2065 doc
: /* Whether the current Emacs process owns the given X Selection.
2066 The arg should be the name of the selection in question, typically one of
2067 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2068 \(Those are literal upper-case symbol names, since that's what X expects.)
2069 For convenience, the symbol nil is the same as `PRIMARY',
2070 and t is the same as `SECONDARY'. */)
2072 Lisp_Object selection
;
2075 CHECK_SYMBOL (selection
);
2076 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2077 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2079 if (NILP (Fassq (selection
, Vselection_alist
)))
2084 DEFUN ("x-selection-exists-p", Fx_selection_exists_p
, Sx_selection_exists_p
,
2086 doc
: /* Whether there is an owner for the given X Selection.
2087 The arg should be the name of the selection in question, typically one of
2088 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2089 \(Those are literal upper-case symbol names, since that's what X expects.)
2090 For convenience, the symbol nil is the same as `PRIMARY',
2091 and t is the same as `SECONDARY'. */)
2093 Lisp_Object selection
;
2098 struct frame
*sf
= SELECTED_FRAME ();
2100 /* It should be safe to call this before we have an X frame. */
2101 if (! FRAME_X_P (sf
))
2104 dpy
= FRAME_X_DISPLAY (sf
);
2105 CHECK_SYMBOL (selection
);
2106 if (!NILP (Fx_selection_owner_p (selection
)))
2108 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2109 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2110 atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
), dpy
, selection
);
2114 owner
= XGetSelectionOwner (dpy
, atom
);
2116 return (owner
? Qt
: Qnil
);
2120 #ifdef CUT_BUFFER_SUPPORT
2122 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
2124 initialize_cut_buffers (display
, window
)
2128 unsigned char *data
= (unsigned char *) "";
2130 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
2131 PropModeAppend, data, 0)
2132 FROB (XA_CUT_BUFFER0
);
2133 FROB (XA_CUT_BUFFER1
);
2134 FROB (XA_CUT_BUFFER2
);
2135 FROB (XA_CUT_BUFFER3
);
2136 FROB (XA_CUT_BUFFER4
);
2137 FROB (XA_CUT_BUFFER5
);
2138 FROB (XA_CUT_BUFFER6
);
2139 FROB (XA_CUT_BUFFER7
);
2145 #define CHECK_CUT_BUFFER(symbol) \
2146 { CHECK_SYMBOL ((symbol)); \
2147 if (!EQ((symbol), QCUT_BUFFER0) && !EQ((symbol), QCUT_BUFFER1) \
2148 && !EQ((symbol), QCUT_BUFFER2) && !EQ((symbol), QCUT_BUFFER3) \
2149 && !EQ((symbol), QCUT_BUFFER4) && !EQ((symbol), QCUT_BUFFER5) \
2150 && !EQ((symbol), QCUT_BUFFER6) && !EQ((symbol), QCUT_BUFFER7)) \
2152 Fcons (build_string ("doesn't name a cut buffer"), \
2153 Fcons ((symbol), Qnil))); \
2156 DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal
,
2157 Sx_get_cut_buffer_internal
, 1, 1, 0,
2158 doc
: /* Returns the value of the named cut buffer (typically CUT_BUFFER0). */)
2164 unsigned char *data
;
2171 struct x_display_info
*dpyinfo
;
2172 struct frame
*sf
= SELECTED_FRAME ();
2176 if (! FRAME_X_P (sf
))
2179 display
= FRAME_X_DISPLAY (sf
);
2180 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2181 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2182 CHECK_CUT_BUFFER (buffer
);
2183 buffer_atom
= symbol_to_x_atom (dpyinfo
, display
, buffer
);
2185 x_get_window_property (display
, window
, buffer_atom
, &data
, &bytes
,
2186 &type
, &format
, &size
, 0);
2187 if (!data
|| !format
)
2190 if (format
!= 8 || type
!= XA_STRING
)
2192 Fcons (build_string ("cut buffer doesn't contain 8-bit data"),
2193 Fcons (x_atom_to_symbol (display
, type
),
2194 Fcons (make_number (format
), Qnil
))));
2196 ret
= (bytes
? make_string ((char *) data
, bytes
) : Qnil
);
2197 /* Use xfree, not XFree, because x_get_window_property
2198 calls xmalloc itself. */
2204 DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal
,
2205 Sx_store_cut_buffer_internal
, 2, 2, 0,
2206 doc
: /* Sets the value of the named cut buffer (typically CUT_BUFFER0). */)
2208 Lisp_Object buffer
, string
;
2212 unsigned char *data
;
2214 int bytes_remaining
;
2217 struct frame
*sf
= SELECTED_FRAME ();
2221 if (! FRAME_X_P (sf
))
2224 display
= FRAME_X_DISPLAY (sf
);
2225 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2227 max_bytes
= SELECTION_QUANTUM (display
);
2228 if (max_bytes
> MAX_SELECTION_QUANTUM
)
2229 max_bytes
= MAX_SELECTION_QUANTUM
;
2231 CHECK_CUT_BUFFER (buffer
);
2232 CHECK_STRING (string
);
2233 buffer_atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
),
2235 data
= (unsigned char *) SDATA (string
);
2236 bytes
= SBYTES (string
);
2237 bytes_remaining
= bytes
;
2239 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2241 initialize_cut_buffers (display
, window
);
2242 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2247 /* Don't mess up with an empty value. */
2248 if (!bytes_remaining
)
2249 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2250 PropModeReplace
, data
, 0);
2252 while (bytes_remaining
)
2254 int chunk
= (bytes_remaining
< max_bytes
2255 ? bytes_remaining
: max_bytes
);
2256 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2257 (bytes_remaining
== bytes
2262 bytes_remaining
-= chunk
;
2269 DEFUN ("x-rotate-cut-buffers-internal", Fx_rotate_cut_buffers_internal
,
2270 Sx_rotate_cut_buffers_internal
, 1, 1, 0,
2271 doc
: /* Rotate the values of the cut buffers by the given number of step.
2272 Positive means shift the values forward, negative means backward. */)
2279 struct frame
*sf
= SELECTED_FRAME ();
2283 if (! FRAME_X_P (sf
))
2286 display
= FRAME_X_DISPLAY (sf
);
2287 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2291 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2293 initialize_cut_buffers (display
, window
);
2294 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2297 props
[0] = XA_CUT_BUFFER0
;
2298 props
[1] = XA_CUT_BUFFER1
;
2299 props
[2] = XA_CUT_BUFFER2
;
2300 props
[3] = XA_CUT_BUFFER3
;
2301 props
[4] = XA_CUT_BUFFER4
;
2302 props
[5] = XA_CUT_BUFFER5
;
2303 props
[6] = XA_CUT_BUFFER6
;
2304 props
[7] = XA_CUT_BUFFER7
;
2306 XRotateWindowProperties (display
, window
, props
, 8, XINT (n
));
2316 defsubr (&Sx_get_selection_internal
);
2317 defsubr (&Sx_own_selection_internal
);
2318 defsubr (&Sx_disown_selection_internal
);
2319 defsubr (&Sx_selection_owner_p
);
2320 defsubr (&Sx_selection_exists_p
);
2322 #ifdef CUT_BUFFER_SUPPORT
2323 defsubr (&Sx_get_cut_buffer_internal
);
2324 defsubr (&Sx_store_cut_buffer_internal
);
2325 defsubr (&Sx_rotate_cut_buffers_internal
);
2328 reading_selection_reply
= Fcons (Qnil
, Qnil
);
2329 staticpro (&reading_selection_reply
);
2330 reading_selection_window
= 0;
2331 reading_which_selection
= 0;
2333 property_change_wait_list
= 0;
2334 prop_location_identifier
= 0;
2335 property_change_reply
= Fcons (Qnil
, Qnil
);
2336 staticpro (&property_change_reply
);
2338 Vselection_alist
= Qnil
;
2339 staticpro (&Vselection_alist
);
2341 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist
,
2342 doc
: /* An alist associating X Windows selection-types with functions.
2343 These functions are called to convert the selection, with three args:
2344 the name of the selection (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2345 a desired type to which the selection should be converted;
2346 and the local selection value (whatever was given to `x-own-selection').
2348 The function should return the value to send to the X server
2349 \(typically a string). A return value of nil
2350 means that the conversion could not be done.
2351 A return value which is the symbol `NULL'
2352 means that a side-effect was executed,
2353 and there is no meaningful selection value. */);
2354 Vselection_converter_alist
= Qnil
;
2356 DEFVAR_LISP ("x-lost-selection-hooks", &Vx_lost_selection_hooks
,
2357 doc
: /* A list of functions to be called when Emacs loses an X selection.
2358 \(This happens when some other X client makes its own selection
2359 or when a Lisp program explicitly clears the selection.)
2360 The functions are called with one argument, the selection type
2361 \(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'). */);
2362 Vx_lost_selection_hooks
= Qnil
;
2364 DEFVAR_LISP ("x-sent-selection-hooks", &Vx_sent_selection_hooks
,
2365 doc
: /* A list of functions to be called when Emacs answers a selection request.
2366 The functions are called with four arguments:
2367 - the selection name (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2368 - the selection-type which Emacs was asked to convert the
2369 selection into before sending (for example, `STRING' or `LENGTH');
2370 - a flag indicating success or failure for responding to the request.
2371 We might have failed (and declined the request) for any number of reasons,
2372 including being asked for a selection that we no longer own, or being asked
2373 to convert into a type that we don't know about or that is inappropriate.
2374 This hook doesn't let you change the behavior of Emacs's selection replies,
2375 it merely informs you that they have happened. */);
2376 Vx_sent_selection_hooks
= Qnil
;
2378 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system
,
2379 doc
: /* Coding system for communicating with other X clients.
2380 When sending or receiving text via cut_buffer, selection, and clipboard,
2381 the text is encoded or decoded by this coding system.
2382 The default value is `compound-text-with-extensions'. */);
2383 Vselection_coding_system
= intern ("compound-text-with-extensions");
2385 DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system
,
2386 doc
: /* Coding system for the next communication with other X clients.
2387 Usually, `selection-coding-system' is used for communicating with
2388 other X clients. But, if this variable is set, it is used for the
2389 next communication only. After the communication, this variable is
2391 Vnext_selection_coding_system
= Qnil
;
2393 DEFVAR_INT ("x-selection-timeout", &x_selection_timeout
,
2394 doc
: /* Number of milliseconds to wait for a selection reply.
2395 If the selection owner doesn't reply in this time, we give up.
2396 A value of 0 means wait as long as necessary. This is initialized from the
2397 \"*selectionTimeout\" resource. */);
2398 x_selection_timeout
= 0;
2400 QPRIMARY
= intern ("PRIMARY"); staticpro (&QPRIMARY
);
2401 QSECONDARY
= intern ("SECONDARY"); staticpro (&QSECONDARY
);
2402 QSTRING
= intern ("STRING"); staticpro (&QSTRING
);
2403 QINTEGER
= intern ("INTEGER"); staticpro (&QINTEGER
);
2404 QCLIPBOARD
= intern ("CLIPBOARD"); staticpro (&QCLIPBOARD
);
2405 QTIMESTAMP
= intern ("TIMESTAMP"); staticpro (&QTIMESTAMP
);
2406 QTEXT
= intern ("TEXT"); staticpro (&QTEXT
);
2407 QCOMPOUND_TEXT
= intern ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT
);
2408 QUTF8_STRING
= intern ("UTF8_STRING"); staticpro (&QUTF8_STRING
);
2409 QTIMESTAMP
= intern ("TIMESTAMP"); staticpro (&QTIMESTAMP
);
2410 QDELETE
= intern ("DELETE"); staticpro (&QDELETE
);
2411 QMULTIPLE
= intern ("MULTIPLE"); staticpro (&QMULTIPLE
);
2412 QINCR
= intern ("INCR"); staticpro (&QINCR
);
2413 QEMACS_TMP
= intern ("_EMACS_TMP_"); staticpro (&QEMACS_TMP
);
2414 QTARGETS
= intern ("TARGETS"); staticpro (&QTARGETS
);
2415 QATOM
= intern ("ATOM"); staticpro (&QATOM
);
2416 QATOM_PAIR
= intern ("ATOM_PAIR"); staticpro (&QATOM_PAIR
);
2417 QNULL
= intern ("NULL"); staticpro (&QNULL
);
2418 Qcompound_text_with_extensions
= intern ("compound-text-with-extensions");
2419 staticpro (&Qcompound_text_with_extensions
);
2421 #ifdef CUT_BUFFER_SUPPORT
2422 QCUT_BUFFER0
= intern ("CUT_BUFFER0"); staticpro (&QCUT_BUFFER0
);
2423 QCUT_BUFFER1
= intern ("CUT_BUFFER1"); staticpro (&QCUT_BUFFER1
);
2424 QCUT_BUFFER2
= intern ("CUT_BUFFER2"); staticpro (&QCUT_BUFFER2
);
2425 QCUT_BUFFER3
= intern ("CUT_BUFFER3"); staticpro (&QCUT_BUFFER3
);
2426 QCUT_BUFFER4
= intern ("CUT_BUFFER4"); staticpro (&QCUT_BUFFER4
);
2427 QCUT_BUFFER5
= intern ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5
);
2428 QCUT_BUFFER6
= intern ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6
);
2429 QCUT_BUFFER7
= intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7
);
2432 Qforeign_selection
= intern ("foreign-selection");
2433 staticpro (&Qforeign_selection
);
2436 /* arch-tag: 7c293b0f-9918-4f69-8ac7-03e142307236
2437 (do not change this comment) */