1 /* X Selection processing for Emacs.
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 /* Rewritten by jwz */
26 #include <stdio.h> /* termhooks.h needs this */
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
36 #include "xterm.h" /* for all of the X includes */
37 #include "dispextern.h" /* frame.h seems to want this */
38 #include "frame.h" /* Need this to get the X window of selected_frame */
39 #include "blockinput.h"
42 #include "termhooks.h"
45 #include <X11/Xproto.h>
49 static Lisp_Object x_atom_to_symbol
P_ ((Display
*dpy
, Atom atom
));
50 static Atom symbol_to_x_atom
P_ ((struct x_display_info
*, Display
*,
52 static void x_own_selection
P_ ((Lisp_Object
, Lisp_Object
));
53 static Lisp_Object x_get_local_selection
P_ ((Lisp_Object
, Lisp_Object
, int));
54 static void x_decline_selection_request
P_ ((struct input_event
*));
55 static Lisp_Object x_selection_request_lisp_error
P_ ((Lisp_Object
));
56 static Lisp_Object queue_selection_requests_unwind
P_ ((Lisp_Object
));
57 static Lisp_Object some_frame_on_display
P_ ((struct x_display_info
*));
58 static Lisp_Object x_catch_errors_unwind
P_ ((Lisp_Object
));
59 static void x_reply_selection_request
P_ ((struct input_event
*, int,
60 unsigned char *, int, Atom
));
61 static int waiting_for_other_props_on_window
P_ ((Display
*, Window
));
62 static struct prop_location
*expect_property_change
P_ ((Display
*, Window
,
64 static void unexpect_property_change
P_ ((struct prop_location
*));
65 static Lisp_Object wait_for_property_change_unwind
P_ ((Lisp_Object
));
66 static void wait_for_property_change
P_ ((struct prop_location
*));
67 static Lisp_Object x_get_foreign_selection
P_ ((Lisp_Object
,
70 static void x_get_window_property
P_ ((Display
*, Window
, Atom
,
71 unsigned char **, int *,
72 Atom
*, int *, unsigned long *, int));
73 static void receive_incremental_selection
P_ ((Display
*, Window
, Atom
,
74 Lisp_Object
, unsigned,
75 unsigned char **, int *,
76 Atom
*, int *, unsigned long *));
77 static Lisp_Object x_get_window_property_as_lisp_data
P_ ((Display
*,
80 static Lisp_Object selection_data_to_lisp_data
P_ ((Display
*, unsigned char *,
82 static void lisp_data_to_selection_data
P_ ((Display
*, Lisp_Object
,
83 unsigned char **, Atom
*,
84 unsigned *, int *, int *));
85 static Lisp_Object clean_local_selection_data
P_ ((Lisp_Object
));
86 static void initialize_cut_buffers
P_ ((Display
*, Window
));
89 /* Printing traces to stderr. */
91 #ifdef TRACE_SELECTION
93 fprintf (stderr, "%d: " fmt "\n", getpid ())
94 #define TRACE1(fmt, a0) \
95 fprintf (stderr, "%d: " fmt "\n", getpid (), a0)
96 #define TRACE2(fmt, a0, a1) \
97 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1)
98 #define TRACE3(fmt, a0, a1, a2) \
99 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1, a2)
101 #define TRACE0(fmt) (void) 0
102 #define TRACE1(fmt, a0) (void) 0
103 #define TRACE2(fmt, a0, a1) (void) 0
104 #define TRACE3(fmt, a0, a1) (void) 0
108 #define CUT_BUFFER_SUPPORT
110 Lisp_Object QPRIMARY
, QSECONDARY
, QSTRING
, QINTEGER
, QCLIPBOARD
, QTIMESTAMP
,
111 QTEXT
, QDELETE
, QMULTIPLE
, QINCR
, QEMACS_TMP
, QTARGETS
, QATOM
, QNULL
,
114 Lisp_Object QCOMPOUND_TEXT
; /* This is a type of selection. */
115 Lisp_Object QUTF8_STRING
; /* This is a type of selection. */
117 Lisp_Object Qcompound_text_with_extensions
;
119 #ifdef CUT_BUFFER_SUPPORT
120 Lisp_Object QCUT_BUFFER0
, QCUT_BUFFER1
, QCUT_BUFFER2
, QCUT_BUFFER3
,
121 QCUT_BUFFER4
, QCUT_BUFFER5
, QCUT_BUFFER6
, QCUT_BUFFER7
;
124 static Lisp_Object Vx_lost_selection_functions
;
125 static Lisp_Object Vx_sent_selection_functions
;
126 /* Coding system for communicating with other X clients via selection
128 static Lisp_Object Vselection_coding_system
;
130 /* Coding system for the next communicating with other X clients. */
131 static Lisp_Object Vnext_selection_coding_system
;
133 static Lisp_Object Qforeign_selection
;
135 /* If this is a smaller number than the max-request-size of the display,
136 emacs will use INCR selection transfer when the selection is larger
137 than this. The max-request-size is usually around 64k, so if you want
138 emacs to use incremental selection transfers when the selection is
139 smaller than that, set this. I added this mostly for debugging the
140 incremental transfer stuff, but it might improve server performance. */
141 #define MAX_SELECTION_QUANTUM 0xFFFFFF
144 #define SELECTION_QUANTUM(dpy) ((XMaxRequestSize(dpy) << 2) - 100)
146 #define SELECTION_QUANTUM(dpy) (((dpy)->max_request_size << 2) - 100)
149 /* The timestamp of the last input event Emacs received from the X server. */
150 /* Defined in keyboard.c. */
151 extern unsigned long last_event_timestamp
;
153 /* This is an association list whose elements are of the form
154 ( SELECTION-NAME SELECTION-VALUE SELECTION-TIMESTAMP FRAME)
155 SELECTION-NAME is a lisp symbol, whose name is the name of an X Atom.
156 SELECTION-VALUE is the value that emacs owns for that selection.
157 It may be any kind of Lisp object.
158 SELECTION-TIMESTAMP is the time at which emacs began owning this selection,
159 as a cons of two 16-bit numbers (making a 32 bit time.)
160 FRAME is the frame for which we made the selection.
161 If there is an entry in this alist, then it can be assumed that Emacs owns
163 The only (eq) parts of this list that are visible from Lisp are the
165 static Lisp_Object Vselection_alist
;
167 /* This is an alist whose CARs are selection-types (whose names are the same
168 as the names of X Atoms) and whose CDRs are the names of Lisp functions to
169 call to convert the given Emacs selection value to a string representing
170 the given selection type. This is for Lisp-level extension of the emacs
171 selection handling. */
172 static Lisp_Object Vselection_converter_alist
;
174 /* If the selection owner takes too long to reply to a selection request,
175 we give up on it. This is in milliseconds (0 = no timeout.) */
176 static EMACS_INT x_selection_timeout
;
180 /* Define a queue to save up SELECTION_REQUEST_EVENT events for later
183 struct selection_event_queue
185 struct input_event event
;
186 struct selection_event_queue
*next
;
189 static struct selection_event_queue
*selection_queue
;
191 /* Nonzero means queue up SELECTION_REQUEST_EVENT events. */
193 static int x_queue_selection_requests
;
195 /* Queue up an SELECTION_REQUEST_EVENT *EVENT, to be processed later. */
198 x_queue_event (event
)
199 struct input_event
*event
;
201 struct selection_event_queue
*queue_tmp
;
203 /* Don't queue repeated requests.
204 This only happens for large requests which uses the incremental protocol. */
205 for (queue_tmp
= selection_queue
; queue_tmp
; queue_tmp
= queue_tmp
->next
)
207 if (!bcmp (&queue_tmp
->event
, event
, sizeof (*event
)))
209 TRACE1 ("DECLINE DUP SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
210 x_decline_selection_request (event
);
216 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
218 if (queue_tmp
!= NULL
)
220 TRACE1 ("QUEUE SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
221 queue_tmp
->event
= *event
;
222 queue_tmp
->next
= selection_queue
;
223 selection_queue
= queue_tmp
;
227 /* Start queuing SELECTION_REQUEST_EVENT events. */
230 x_start_queuing_selection_requests ()
232 if (x_queue_selection_requests
)
235 x_queue_selection_requests
++;
236 TRACE1 ("x_start_queuing_selection_requests %d", x_queue_selection_requests
);
239 /* Stop queuing SELECTION_REQUEST_EVENT events. */
242 x_stop_queuing_selection_requests ()
244 TRACE1 ("x_stop_queuing_selection_requests %d", x_queue_selection_requests
);
245 --x_queue_selection_requests
;
247 /* Take all the queued events and put them back
248 so that they get processed afresh. */
250 while (selection_queue
!= NULL
)
252 struct selection_event_queue
*queue_tmp
= selection_queue
;
253 TRACE1 ("RESTORE SELECTION EVENT %08lx", (unsigned long)queue_tmp
);
254 kbd_buffer_unget_event (&queue_tmp
->event
);
255 selection_queue
= queue_tmp
->next
;
256 xfree ((char *)queue_tmp
);
261 /* This converts a Lisp symbol to a server Atom, avoiding a server
262 roundtrip whenever possible. */
265 symbol_to_x_atom (dpyinfo
, display
, sym
)
266 struct x_display_info
*dpyinfo
;
271 if (NILP (sym
)) return 0;
272 if (EQ (sym
, QPRIMARY
)) return XA_PRIMARY
;
273 if (EQ (sym
, QSECONDARY
)) return XA_SECONDARY
;
274 if (EQ (sym
, QSTRING
)) return XA_STRING
;
275 if (EQ (sym
, QINTEGER
)) return XA_INTEGER
;
276 if (EQ (sym
, QATOM
)) return XA_ATOM
;
277 if (EQ (sym
, QCLIPBOARD
)) return dpyinfo
->Xatom_CLIPBOARD
;
278 if (EQ (sym
, QTIMESTAMP
)) return dpyinfo
->Xatom_TIMESTAMP
;
279 if (EQ (sym
, QTEXT
)) return dpyinfo
->Xatom_TEXT
;
280 if (EQ (sym
, QCOMPOUND_TEXT
)) return dpyinfo
->Xatom_COMPOUND_TEXT
;
281 if (EQ (sym
, QUTF8_STRING
)) return dpyinfo
->Xatom_UTF8_STRING
;
282 if (EQ (sym
, QDELETE
)) return dpyinfo
->Xatom_DELETE
;
283 if (EQ (sym
, QMULTIPLE
)) return dpyinfo
->Xatom_MULTIPLE
;
284 if (EQ (sym
, QINCR
)) return dpyinfo
->Xatom_INCR
;
285 if (EQ (sym
, QEMACS_TMP
)) return dpyinfo
->Xatom_EMACS_TMP
;
286 if (EQ (sym
, QTARGETS
)) return dpyinfo
->Xatom_TARGETS
;
287 if (EQ (sym
, QNULL
)) return dpyinfo
->Xatom_NULL
;
288 #ifdef CUT_BUFFER_SUPPORT
289 if (EQ (sym
, QCUT_BUFFER0
)) return XA_CUT_BUFFER0
;
290 if (EQ (sym
, QCUT_BUFFER1
)) return XA_CUT_BUFFER1
;
291 if (EQ (sym
, QCUT_BUFFER2
)) return XA_CUT_BUFFER2
;
292 if (EQ (sym
, QCUT_BUFFER3
)) return XA_CUT_BUFFER3
;
293 if (EQ (sym
, QCUT_BUFFER4
)) return XA_CUT_BUFFER4
;
294 if (EQ (sym
, QCUT_BUFFER5
)) return XA_CUT_BUFFER5
;
295 if (EQ (sym
, QCUT_BUFFER6
)) return XA_CUT_BUFFER6
;
296 if (EQ (sym
, QCUT_BUFFER7
)) return XA_CUT_BUFFER7
;
298 if (!SYMBOLP (sym
)) abort ();
300 TRACE1 (" XInternAtom %s", (char *) SDATA (SYMBOL_NAME (sym
)));
302 val
= XInternAtom (display
, (char *) SDATA (SYMBOL_NAME (sym
)), False
);
308 /* This converts a server Atom to a Lisp symbol, avoiding server roundtrips
309 and calls to intern whenever possible. */
312 x_atom_to_symbol (dpy
, atom
)
316 struct x_display_info
*dpyinfo
;
335 #ifdef CUT_BUFFER_SUPPORT
355 dpyinfo
= x_display_info_for_display (dpy
);
356 if (atom
== dpyinfo
->Xatom_CLIPBOARD
)
358 if (atom
== dpyinfo
->Xatom_TIMESTAMP
)
360 if (atom
== dpyinfo
->Xatom_TEXT
)
362 if (atom
== dpyinfo
->Xatom_COMPOUND_TEXT
)
363 return QCOMPOUND_TEXT
;
364 if (atom
== dpyinfo
->Xatom_UTF8_STRING
)
366 if (atom
== dpyinfo
->Xatom_DELETE
)
368 if (atom
== dpyinfo
->Xatom_MULTIPLE
)
370 if (atom
== dpyinfo
->Xatom_INCR
)
372 if (atom
== dpyinfo
->Xatom_EMACS_TMP
)
374 if (atom
== dpyinfo
->Xatom_TARGETS
)
376 if (atom
== dpyinfo
->Xatom_NULL
)
380 str
= XGetAtomName (dpy
, atom
);
382 TRACE1 ("XGetAtomName --> %s", str
);
383 if (! str
) return Qnil
;
386 /* This was allocated by Xlib, so use XFree. */
392 /* Do protocol to assert ourself as a selection owner.
393 Update the Vselection_alist so that we can reply to later requests for
397 x_own_selection (selection_name
, selection_value
)
398 Lisp_Object selection_name
, selection_value
;
400 struct frame
*sf
= SELECTED_FRAME ();
401 Window selecting_window
;
403 Time time
= last_event_timestamp
;
405 struct x_display_info
*dpyinfo
;
407 if (! FRAME_X_P (sf
))
410 selecting_window
= FRAME_X_WINDOW (sf
);
411 display
= FRAME_X_DISPLAY (sf
);
412 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
414 CHECK_SYMBOL (selection_name
);
415 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection_name
);
418 x_catch_errors (display
);
419 XSetSelectionOwner (display
, selection_atom
, selecting_window
, time
);
420 x_check_errors (display
, "Can't set selection: %s");
424 /* Now update the local cache */
426 Lisp_Object selection_time
;
427 Lisp_Object selection_data
;
428 Lisp_Object prev_value
;
430 selection_time
= long_to_cons ((unsigned long) time
);
431 selection_data
= Fcons (selection_name
,
432 Fcons (selection_value
,
433 Fcons (selection_time
,
434 Fcons (selected_frame
, Qnil
))));
435 prev_value
= assq_no_quit (selection_name
, Vselection_alist
);
437 Vselection_alist
= Fcons (selection_data
, Vselection_alist
);
439 /* If we already owned the selection, remove the old selection data.
440 Perhaps we should destructively modify it instead.
441 Don't use Fdelq as that may QUIT. */
442 if (!NILP (prev_value
))
444 Lisp_Object rest
; /* we know it's not the CAR, so it's easy. */
445 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
446 if (EQ (prev_value
, Fcar (XCDR (rest
))))
448 XSETCDR (rest
, Fcdr (XCDR (rest
)));
455 /* Given a selection-name and desired type, look up our local copy of
456 the selection value and convert it to the type.
457 The value is nil or a string.
458 This function is used both for remote requests (LOCAL_REQUEST is zero)
459 and for local x-get-selection-internal (LOCAL_REQUEST is nonzero).
461 This calls random Lisp code, and may signal or gc. */
464 x_get_local_selection (selection_symbol
, target_type
, local_request
)
465 Lisp_Object selection_symbol
, target_type
;
468 Lisp_Object local_value
;
469 Lisp_Object handler_fn
, value
, type
, check
;
472 local_value
= assq_no_quit (selection_symbol
, Vselection_alist
);
474 if (NILP (local_value
)) return Qnil
;
476 /* TIMESTAMP and MULTIPLE are special cases 'cause that's easiest. */
477 if (EQ (target_type
, QTIMESTAMP
))
480 value
= XCAR (XCDR (XCDR (local_value
)));
483 else if (EQ (target_type
, QDELETE
))
486 Fx_disown_selection_internal
488 XCAR (XCDR (XCDR (local_value
))));
493 #if 0 /* #### MULTIPLE doesn't work yet */
494 else if (CONSP (target_type
)
495 && XCAR (target_type
) == QMULTIPLE
)
500 pairs
= XCDR (target_type
);
501 size
= XVECTOR (pairs
)->size
;
502 /* If the target is MULTIPLE, then target_type looks like
503 (MULTIPLE . [[SELECTION1 TARGET1] [SELECTION2 TARGET2] ... ])
504 We modify the second element of each pair in the vector and
505 return it as [[SELECTION1 <value1>] [SELECTION2 <value2>] ... ]
507 for (i
= 0; i
< size
; i
++)
510 pair
= XVECTOR (pairs
)->contents
[i
];
511 XVECTOR (pair
)->contents
[1]
512 = x_get_local_selection (XVECTOR (pair
)->contents
[0],
513 XVECTOR (pair
)->contents
[1],
521 /* Don't allow a quit within the converter.
522 When the user types C-g, he would be surprised
523 if by luck it came during a converter. */
524 count
= SPECPDL_INDEX ();
525 specbind (Qinhibit_quit
, Qt
);
527 CHECK_SYMBOL (target_type
);
528 handler_fn
= Fcdr (Fassq (target_type
, Vselection_converter_alist
));
529 /* gcpro is not needed here since nothing but HANDLER_FN
530 is live, and that ought to be a symbol. */
532 if (!NILP (handler_fn
))
533 value
= call3 (handler_fn
,
534 selection_symbol
, (local_request
? Qnil
: target_type
),
535 XCAR (XCDR (local_value
)));
538 unbind_to (count
, Qnil
);
541 /* Make sure this value is of a type that we could transmit
542 to another X client. */
546 && SYMBOLP (XCAR (value
)))
548 check
= XCDR (value
);
556 /* Check for a value that cons_to_long could handle. */
557 else if (CONSP (check
)
558 && INTEGERP (XCAR (check
))
559 && (INTEGERP (XCDR (check
))
561 (CONSP (XCDR (check
))
562 && INTEGERP (XCAR (XCDR (check
)))
563 && NILP (XCDR (XCDR (check
))))))
566 signal_error ("Invalid data returned by selection-conversion function",
567 list2 (handler_fn
, value
));
570 /* Subroutines of x_reply_selection_request. */
572 /* Send a SelectionNotify event to the requestor with property=None,
573 meaning we were unable to do what they wanted. */
576 x_decline_selection_request (event
)
577 struct input_event
*event
;
579 XSelectionEvent reply
;
581 reply
.type
= SelectionNotify
;
582 reply
.display
= SELECTION_EVENT_DISPLAY (event
);
583 reply
.requestor
= SELECTION_EVENT_REQUESTOR (event
);
584 reply
.selection
= SELECTION_EVENT_SELECTION (event
);
585 reply
.time
= SELECTION_EVENT_TIME (event
);
586 reply
.target
= SELECTION_EVENT_TARGET (event
);
587 reply
.property
= None
;
589 /* The reason for the error may be that the receiver has
590 died in the meantime. Handle that case. */
592 x_catch_errors (reply
.display
);
593 XSendEvent (reply
.display
, reply
.requestor
, False
, 0L, (XEvent
*) &reply
);
594 XFlush (reply
.display
);
599 /* This is the selection request currently being processed.
600 It is set to zero when the request is fully processed. */
601 static struct input_event
*x_selection_current_request
;
603 /* Display info in x_selection_request. */
605 static struct x_display_info
*selection_request_dpyinfo
;
607 /* Used as an unwind-protect clause so that, if a selection-converter signals
608 an error, we tell the requester that we were unable to do what they wanted
609 before we throw to top-level or go into the debugger or whatever. */
612 x_selection_request_lisp_error (ignore
)
615 if (x_selection_current_request
!= 0
616 && selection_request_dpyinfo
->display
)
617 x_decline_selection_request (x_selection_current_request
);
622 x_catch_errors_unwind (dummy
)
632 /* This stuff is so that INCR selections are reentrant (that is, so we can
633 be servicing multiple INCR selection requests simultaneously.) I haven't
634 actually tested that yet. */
636 /* Keep a list of the property changes that are awaited. */
646 struct prop_location
*next
;
649 static struct prop_location
*expect_property_change ();
650 static void wait_for_property_change ();
651 static void unexpect_property_change ();
652 static int waiting_for_other_props_on_window ();
654 static int prop_location_identifier
;
656 static Lisp_Object property_change_reply
;
658 static struct prop_location
*property_change_reply_object
;
660 static struct prop_location
*property_change_wait_list
;
663 queue_selection_requests_unwind (tem
)
666 x_stop_queuing_selection_requests ();
670 /* Return some frame whose display info is DPYINFO.
671 Return nil if there is none. */
674 some_frame_on_display (dpyinfo
)
675 struct x_display_info
*dpyinfo
;
677 Lisp_Object list
, frame
;
679 FOR_EACH_FRAME (list
, frame
)
681 if (FRAME_X_P (XFRAME (frame
))
682 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
689 /* Send the reply to a selection request event EVENT.
690 TYPE is the type of selection data requested.
691 DATA and SIZE describe the data to send, already converted.
692 FORMAT is the unit-size (in bits) of the data to be transmitted. */
695 x_reply_selection_request (event
, format
, data
, size
, type
)
696 struct input_event
*event
;
701 XSelectionEvent reply
;
702 Display
*display
= SELECTION_EVENT_DISPLAY (event
);
703 Window window
= SELECTION_EVENT_REQUESTOR (event
);
705 int format_bytes
= format
/8;
706 int max_bytes
= SELECTION_QUANTUM (display
);
707 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
708 int count
= SPECPDL_INDEX ();
710 if (max_bytes
> MAX_SELECTION_QUANTUM
)
711 max_bytes
= MAX_SELECTION_QUANTUM
;
713 reply
.type
= SelectionNotify
;
714 reply
.display
= display
;
715 reply
.requestor
= window
;
716 reply
.selection
= SELECTION_EVENT_SELECTION (event
);
717 reply
.time
= SELECTION_EVENT_TIME (event
);
718 reply
.target
= SELECTION_EVENT_TARGET (event
);
719 reply
.property
= SELECTION_EVENT_PROPERTY (event
);
720 if (reply
.property
== None
)
721 reply
.property
= reply
.target
;
724 /* The protected block contains wait_for_property_change, which can
725 run random lisp code (process handlers) or signal. Therefore, we
726 put the x_uncatch_errors call in an unwind. */
727 record_unwind_protect (x_catch_errors_unwind
, Qnil
);
728 x_catch_errors (display
);
730 #ifdef TRACE_SELECTION
733 char *sel
= XGetAtomName (display
, reply
.selection
);
734 char *tgt
= XGetAtomName (display
, reply
.target
);
735 TRACE3 ("%s, target %s (%d)", sel
, tgt
, ++cnt
);
736 if (sel
) XFree (sel
);
737 if (tgt
) XFree (tgt
);
739 #endif /* TRACE_SELECTION */
741 /* Store the data on the requested property.
742 If the selection is large, only store the first N bytes of it.
744 bytes_remaining
= size
* format_bytes
;
745 if (bytes_remaining
<= max_bytes
)
747 /* Send all the data at once, with minimal handshaking. */
748 TRACE1 ("Sending all %d bytes", bytes_remaining
);
749 XChangeProperty (display
, window
, reply
.property
, type
, format
,
750 PropModeReplace
, data
, size
);
751 /* At this point, the selection was successfully stored; ack it. */
752 XSendEvent (display
, window
, False
, 0L, (XEvent
*) &reply
);
756 /* Send an INCR selection. */
757 struct prop_location
*wait_object
;
761 frame
= some_frame_on_display (dpyinfo
);
763 /* If the display no longer has frames, we can't expect
764 to get many more selection requests from it, so don't
765 bother trying to queue them. */
768 x_start_queuing_selection_requests ();
770 record_unwind_protect (queue_selection_requests_unwind
,
774 if (x_window_to_frame (dpyinfo
, window
)) /* #### debug */
775 error ("Attempt to transfer an INCR to ourself!");
777 TRACE2 ("Start sending %d bytes incrementally (%s)",
778 bytes_remaining
, XGetAtomName (display
, reply
.property
));
779 wait_object
= expect_property_change (display
, window
, reply
.property
,
782 TRACE1 ("Set %s to number of bytes to send",
783 XGetAtomName (display
, reply
.property
));
785 /* XChangeProperty expects an array of long even if long is more than
789 value
[0] = bytes_remaining
;
790 XChangeProperty (display
, window
, reply
.property
, dpyinfo
->Xatom_INCR
,
792 (unsigned char *) value
, 1);
795 XSelectInput (display
, window
, PropertyChangeMask
);
797 /* Tell 'em the INCR data is there... */
798 TRACE0 ("Send SelectionNotify event");
799 XSendEvent (display
, window
, False
, 0L, (XEvent
*) &reply
);
802 had_errors
= x_had_errors_p (display
);
805 /* First, wait for the requester to ack by deleting the property.
806 This can run random lisp code (process handlers) or signal. */
809 TRACE1 ("Waiting for ACK (deletion of %s)",
810 XGetAtomName (display
, reply
.property
));
811 wait_for_property_change (wait_object
);
814 unexpect_property_change (wait_object
);
817 while (bytes_remaining
)
819 int i
= ((bytes_remaining
< max_bytes
)
826 = expect_property_change (display
, window
, reply
.property
,
829 TRACE1 ("Sending increment of %d bytes", i
);
830 TRACE1 ("Set %s to increment data",
831 XGetAtomName (display
, reply
.property
));
833 /* Append the next chunk of data to the property. */
834 XChangeProperty (display
, window
, reply
.property
, type
, format
,
835 PropModeAppend
, data
, i
/ format_bytes
);
836 bytes_remaining
-= i
;
839 had_errors
= x_had_errors_p (display
);
845 /* Now wait for the requester to ack this chunk by deleting the
846 property. This can run random lisp code or signal. */
847 TRACE1 ("Waiting for increment ACK (deletion of %s)",
848 XGetAtomName (display
, reply
.property
));
849 wait_for_property_change (wait_object
);
852 /* Now write a zero-length chunk to the property to tell the
853 requester that we're done. */
855 if (! waiting_for_other_props_on_window (display
, window
))
856 XSelectInput (display
, window
, 0L);
858 TRACE1 ("Set %s to a 0-length chunk to indicate EOF",
859 XGetAtomName (display
, reply
.property
));
860 XChangeProperty (display
, window
, reply
.property
, type
, format
,
861 PropModeReplace
, data
, 0);
862 TRACE0 ("Done sending incrementally");
865 /* rms, 2003-01-03: I think I have fixed this bug. */
866 /* The window we're communicating with may have been deleted
867 in the meantime (that's a real situation from a bug report).
868 In this case, there may be events in the event queue still
869 refering to the deleted window, and we'll get a BadWindow error
870 in XTread_socket when processing the events. I don't have
871 an idea how to fix that. gerd, 2001-01-98. */
872 /* 2004-09-10: XSync and UNBLOCK so that possible protocol errors are
873 delivered before uncatch errors. */
874 XSync (display
, False
);
877 /* GTK queues events in addition to the queue in Xlib. So we
878 UNBLOCK to enter the event loop and get possible errors delivered,
879 and then BLOCK again because x_uncatch_errors requires it. */
881 /* This calls x_uncatch_errors. */
882 unbind_to (count
, Qnil
);
886 /* Handle a SelectionRequest event EVENT.
887 This is called from keyboard.c when such an event is found in the queue. */
890 x_handle_selection_request (event
)
891 struct input_event
*event
;
893 struct gcpro gcpro1
, gcpro2
, gcpro3
;
894 Lisp_Object local_selection_data
;
895 Lisp_Object selection_symbol
;
896 Lisp_Object target_symbol
;
897 Lisp_Object converted_selection
;
898 Time local_selection_time
;
899 Lisp_Object successful_p
;
901 struct x_display_info
*dpyinfo
902 = x_display_info_for_display (SELECTION_EVENT_DISPLAY (event
));
904 TRACE2 ("x_handle_selection_request, from=0x%08lx time=%lu",
905 (unsigned long) SELECTION_EVENT_REQUESTOR (event
),
906 (unsigned long) SELECTION_EVENT_TIME (event
));
908 local_selection_data
= Qnil
;
909 target_symbol
= Qnil
;
910 converted_selection
= Qnil
;
913 GCPRO3 (local_selection_data
, converted_selection
, target_symbol
);
915 selection_symbol
= x_atom_to_symbol (SELECTION_EVENT_DISPLAY (event
),
916 SELECTION_EVENT_SELECTION (event
));
918 local_selection_data
= assq_no_quit (selection_symbol
, Vselection_alist
);
920 if (NILP (local_selection_data
))
922 /* Someone asked for the selection, but we don't have it any more.
924 x_decline_selection_request (event
);
928 local_selection_time
= (Time
)
929 cons_to_long (XCAR (XCDR (XCDR (local_selection_data
))));
931 if (SELECTION_EVENT_TIME (event
) != CurrentTime
932 && local_selection_time
> SELECTION_EVENT_TIME (event
))
934 /* Someone asked for the selection, and we have one, but not the one
937 x_decline_selection_request (event
);
941 x_selection_current_request
= event
;
942 count
= SPECPDL_INDEX ();
943 selection_request_dpyinfo
= dpyinfo
;
944 record_unwind_protect (x_selection_request_lisp_error
, Qnil
);
946 target_symbol
= x_atom_to_symbol (SELECTION_EVENT_DISPLAY (event
),
947 SELECTION_EVENT_TARGET (event
));
949 #if 0 /* #### MULTIPLE doesn't work yet */
950 if (EQ (target_symbol
, QMULTIPLE
))
951 target_symbol
= fetch_multiple_target (event
);
954 /* Convert lisp objects back into binary data */
957 = x_get_local_selection (selection_symbol
, target_symbol
, 0);
959 if (! NILP (converted_selection
))
967 if (CONSP (converted_selection
) && NILP (XCDR (converted_selection
)))
969 x_decline_selection_request (event
);
973 lisp_data_to_selection_data (SELECTION_EVENT_DISPLAY (event
),
975 &data
, &type
, &size
, &format
, &nofree
);
977 x_reply_selection_request (event
, format
, data
, size
, type
);
980 /* Indicate we have successfully processed this event. */
981 x_selection_current_request
= 0;
983 /* Use xfree, not XFree, because lisp_data_to_selection_data
984 calls xmalloc itself. */
990 unbind_to (count
, Qnil
);
994 /* Let random lisp code notice that the selection has been asked for. */
997 rest
= Vx_sent_selection_functions
;
998 if (!EQ (rest
, Qunbound
))
999 for (; CONSP (rest
); rest
= Fcdr (rest
))
1000 call3 (Fcar (rest
), selection_symbol
, target_symbol
, successful_p
);
1006 /* Handle a SelectionClear event EVENT, which indicates that some
1007 client cleared out our previously asserted selection.
1008 This is called from keyboard.c when such an event is found in the queue. */
1011 x_handle_selection_clear (event
)
1012 struct input_event
*event
;
1014 Display
*display
= SELECTION_EVENT_DISPLAY (event
);
1015 Atom selection
= SELECTION_EVENT_SELECTION (event
);
1016 Time changed_owner_time
= SELECTION_EVENT_TIME (event
);
1018 Lisp_Object selection_symbol
, local_selection_data
;
1019 Time local_selection_time
;
1020 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1021 struct x_display_info
*t_dpyinfo
;
1023 TRACE0 ("x_handle_selection_clear");
1026 /* If the new selection owner is also Emacs,
1027 don't clear the new selection. */
1029 /* Check each display on the same terminal,
1030 to see if this Emacs job now owns the selection
1031 through that display. */
1032 for (t_dpyinfo
= x_display_list
; t_dpyinfo
; t_dpyinfo
= t_dpyinfo
->next
)
1033 if (t_dpyinfo
->terminal
->kboard
== dpyinfo
->terminal
->kboard
)
1036 = XGetSelectionOwner (t_dpyinfo
->display
, selection
);
1037 if (x_window_to_frame (t_dpyinfo
, owner_window
) != 0)
1046 selection_symbol
= x_atom_to_symbol (display
, selection
);
1048 local_selection_data
= assq_no_quit (selection_symbol
, Vselection_alist
);
1050 /* Well, we already believe that we don't own it, so that's just fine. */
1051 if (NILP (local_selection_data
)) return;
1053 local_selection_time
= (Time
)
1054 cons_to_long (XCAR (XCDR (XCDR (local_selection_data
))));
1056 /* This SelectionClear is for a selection that we no longer own, so we can
1057 disregard it. (That is, we have reasserted the selection since this
1058 request was generated.) */
1060 if (changed_owner_time
!= CurrentTime
1061 && local_selection_time
> changed_owner_time
)
1064 /* Otherwise, we're really honest and truly being told to drop it.
1065 Don't use Fdelq as that may QUIT;. */
1067 if (EQ (local_selection_data
, Fcar (Vselection_alist
)))
1068 Vselection_alist
= Fcdr (Vselection_alist
);
1072 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
1073 if (EQ (local_selection_data
, Fcar (XCDR (rest
))))
1075 XSETCDR (rest
, Fcdr (XCDR (rest
)));
1080 /* Let random lisp code notice that the selection has been stolen. */
1084 rest
= Vx_lost_selection_functions
;
1085 if (!EQ (rest
, Qunbound
))
1087 for (; CONSP (rest
); rest
= Fcdr (rest
))
1088 call1 (Fcar (rest
), selection_symbol
);
1089 prepare_menu_bars ();
1090 redisplay_preserve_echo_area (20);
1096 x_handle_selection_event (event
)
1097 struct input_event
*event
;
1099 TRACE0 ("x_handle_selection_event");
1101 if (event
->kind
== SELECTION_REQUEST_EVENT
)
1103 if (x_queue_selection_requests
)
1104 x_queue_event (event
);
1106 x_handle_selection_request (event
);
1109 x_handle_selection_clear (event
);
1113 /* Clear all selections that were made from frame F.
1114 We do this when about to delete a frame. */
1117 x_clear_frame_selections (f
)
1123 XSETFRAME (frame
, f
);
1125 /* Otherwise, we're really honest and truly being told to drop it.
1126 Don't use Fdelq as that may QUIT;. */
1128 /* Delete elements from the beginning of Vselection_alist. */
1129 while (!NILP (Vselection_alist
)
1130 && EQ (frame
, Fcar (Fcdr (Fcdr (Fcdr (Fcar (Vselection_alist
)))))))
1132 /* Let random Lisp code notice that the selection has been stolen. */
1133 Lisp_Object hooks
, selection_symbol
;
1135 hooks
= Vx_lost_selection_functions
;
1136 selection_symbol
= Fcar (Fcar (Vselection_alist
));
1138 if (!EQ (hooks
, Qunbound
))
1140 for (; CONSP (hooks
); hooks
= Fcdr (hooks
))
1141 call1 (Fcar (hooks
), selection_symbol
);
1142 #if 0 /* This can crash when deleting a frame
1143 from x_connection_closed. Anyway, it seems unnecessary;
1144 something else should cause a redisplay. */
1145 redisplay_preserve_echo_area (21);
1149 Vselection_alist
= Fcdr (Vselection_alist
);
1152 /* Delete elements after the beginning of Vselection_alist. */
1153 for (rest
= Vselection_alist
; !NILP (rest
); rest
= Fcdr (rest
))
1154 if (EQ (frame
, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest
))))))))
1156 /* Let random Lisp code notice that the selection has been stolen. */
1157 Lisp_Object hooks
, selection_symbol
;
1159 hooks
= Vx_lost_selection_functions
;
1160 selection_symbol
= Fcar (Fcar (XCDR (rest
)));
1162 if (!EQ (hooks
, Qunbound
))
1164 for (; CONSP (hooks
); hooks
= Fcdr (hooks
))
1165 call1 (Fcar (hooks
), selection_symbol
);
1166 #if 0 /* See above */
1167 redisplay_preserve_echo_area (22);
1170 XSETCDR (rest
, Fcdr (XCDR (rest
)));
1175 /* Nonzero if any properties for DISPLAY and WINDOW
1176 are on the list of what we are waiting for. */
1179 waiting_for_other_props_on_window (display
, window
)
1183 struct prop_location
*rest
= property_change_wait_list
;
1185 if (rest
->display
== display
&& rest
->window
== window
)
1192 /* Add an entry to the list of property changes we are waiting for.
1193 DISPLAY, WINDOW, PROPERTY, STATE describe what we will wait for.
1194 The return value is a number that uniquely identifies
1195 this awaited property change. */
1197 static struct prop_location
*
1198 expect_property_change (display
, window
, property
, state
)
1204 struct prop_location
*pl
= (struct prop_location
*) xmalloc (sizeof *pl
);
1205 pl
->identifier
= ++prop_location_identifier
;
1206 pl
->display
= display
;
1207 pl
->window
= window
;
1208 pl
->property
= property
;
1209 pl
->desired_state
= state
;
1210 pl
->next
= property_change_wait_list
;
1212 property_change_wait_list
= pl
;
1216 /* Delete an entry from the list of property changes we are waiting for.
1217 IDENTIFIER is the number that uniquely identifies the entry. */
1220 unexpect_property_change (location
)
1221 struct prop_location
*location
;
1223 struct prop_location
*prev
= 0, *rest
= property_change_wait_list
;
1226 if (rest
== location
)
1229 prev
->next
= rest
->next
;
1231 property_change_wait_list
= rest
->next
;
1240 /* Remove the property change expectation element for IDENTIFIER. */
1243 wait_for_property_change_unwind (loc
)
1246 struct prop_location
*location
= XSAVE_VALUE (loc
)->pointer
;
1248 unexpect_property_change (location
);
1249 if (location
== property_change_reply_object
)
1250 property_change_reply_object
= 0;
1254 /* Actually wait for a property change.
1255 IDENTIFIER should be the value that expect_property_change returned. */
1258 wait_for_property_change (location
)
1259 struct prop_location
*location
;
1262 int count
= SPECPDL_INDEX ();
1264 if (property_change_reply_object
)
1267 /* Make sure to do unexpect_property_change if we quit or err. */
1268 record_unwind_protect (wait_for_property_change_unwind
,
1269 make_save_value (location
, 0));
1271 XSETCAR (property_change_reply
, Qnil
);
1272 property_change_reply_object
= location
;
1274 /* If the event we are waiting for arrives beyond here, it will set
1275 property_change_reply, because property_change_reply_object says so. */
1276 if (! location
->arrived
)
1278 secs
= x_selection_timeout
/ 1000;
1279 usecs
= (x_selection_timeout
% 1000) * 1000;
1280 TRACE2 (" Waiting %d secs, %d usecs", secs
, usecs
);
1281 wait_reading_process_output (secs
, usecs
, 0, 0,
1282 property_change_reply
, NULL
, 0);
1284 if (NILP (XCAR (property_change_reply
)))
1286 TRACE0 (" Timed out");
1287 error ("Timed out waiting for property-notify event");
1291 unbind_to (count
, Qnil
);
1294 /* Called from XTread_socket in response to a PropertyNotify event. */
1297 x_handle_property_notify (event
)
1298 XPropertyEvent
*event
;
1300 struct prop_location
*prev
= 0, *rest
= property_change_wait_list
;
1305 && rest
->property
== event
->atom
1306 && rest
->window
== event
->window
1307 && rest
->display
== event
->display
1308 && rest
->desired_state
== event
->state
)
1310 TRACE2 ("Expected %s of property %s",
1311 (event
->state
== PropertyDelete
? "deletion" : "change"),
1312 XGetAtomName (event
->display
, event
->atom
));
1316 /* If this is the one wait_for_property_change is waiting for,
1317 tell it to wake up. */
1318 if (rest
== property_change_reply_object
)
1319 XSETCAR (property_change_reply
, Qt
);
1331 #if 0 /* #### MULTIPLE doesn't work yet */
1334 fetch_multiple_target (event
)
1335 XSelectionRequestEvent
*event
;
1337 Display
*display
= event
->display
;
1338 Window window
= event
->requestor
;
1339 Atom target
= event
->target
;
1340 Atom selection_atom
= event
->selection
;
1345 x_get_window_property_as_lisp_data (display
, window
, target
,
1346 QMULTIPLE
, selection_atom
));
1350 copy_multiple_data (obj
)
1357 return Fcons (XCAR (obj
), copy_multiple_data (XCDR (obj
)));
1360 vec
= Fmake_vector (size
= XVECTOR (obj
)->size
, Qnil
);
1361 for (i
= 0; i
< size
; i
++)
1363 Lisp_Object vec2
= XVECTOR (obj
)->contents
[i
];
1364 CHECK_VECTOR (vec2
);
1365 if (XVECTOR (vec2
)->size
!= 2)
1366 /* ??? Confusing error message */
1367 signal_error ("Vectors must be of length 2", vec2
);
1368 XVECTOR (vec
)->contents
[i
] = Fmake_vector (2, Qnil
);
1369 XVECTOR (XVECTOR (vec
)->contents
[i
])->contents
[0]
1370 = XVECTOR (vec2
)->contents
[0];
1371 XVECTOR (XVECTOR (vec
)->contents
[i
])->contents
[1]
1372 = XVECTOR (vec2
)->contents
[1];
1380 /* Variables for communication with x_handle_selection_notify. */
1381 static Atom reading_which_selection
;
1382 static Lisp_Object reading_selection_reply
;
1383 static Window reading_selection_window
;
1385 /* Do protocol to read selection-data from the server.
1386 Converts this to Lisp data and returns it. */
1389 x_get_foreign_selection (selection_symbol
, target_type
, time_stamp
)
1390 Lisp_Object selection_symbol
, target_type
, time_stamp
;
1392 struct frame
*sf
= SELECTED_FRAME ();
1393 Window requestor_window
;
1395 struct x_display_info
*dpyinfo
;
1396 Time requestor_time
= last_event_timestamp
;
1397 Atom target_property
;
1398 Atom selection_atom
;
1401 int count
= SPECPDL_INDEX ();
1404 if (! FRAME_X_P (sf
))
1407 requestor_window
= FRAME_X_WINDOW (sf
);
1408 display
= FRAME_X_DISPLAY (sf
);
1409 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
1410 target_property
= dpyinfo
->Xatom_EMACS_TMP
;
1411 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection_symbol
);
1413 if (CONSP (target_type
))
1414 type_atom
= symbol_to_x_atom (dpyinfo
, display
, XCAR (target_type
));
1416 type_atom
= symbol_to_x_atom (dpyinfo
, display
, target_type
);
1418 if (! NILP (time_stamp
))
1420 if (CONSP (time_stamp
))
1421 requestor_time
= (Time
) cons_to_long (time_stamp
);
1422 else if (INTEGERP (time_stamp
))
1423 requestor_time
= (Time
) XUINT (time_stamp
);
1424 else if (FLOATP (time_stamp
))
1425 requestor_time
= (Time
) XFLOAT_DATA (time_stamp
);
1427 error ("TIME_STAMP must be cons or number");
1432 /* The protected block contains wait_reading_process_output, which
1433 can run random lisp code (process handlers) or signal.
1434 Therefore, we put the x_uncatch_errors call in an unwind. */
1435 record_unwind_protect (x_catch_errors_unwind
, Qnil
);
1436 x_catch_errors (display
);
1438 TRACE2 ("Get selection %s, type %s",
1439 XGetAtomName (display
, type_atom
),
1440 XGetAtomName (display
, target_property
));
1442 XConvertSelection (display
, selection_atom
, type_atom
, target_property
,
1443 requestor_window
, requestor_time
);
1446 /* Prepare to block until the reply has been read. */
1447 reading_selection_window
= requestor_window
;
1448 reading_which_selection
= selection_atom
;
1449 XSETCAR (reading_selection_reply
, Qnil
);
1451 frame
= some_frame_on_display (dpyinfo
);
1453 /* If the display no longer has frames, we can't expect
1454 to get many more selection requests from it, so don't
1455 bother trying to queue them. */
1458 x_start_queuing_selection_requests ();
1460 record_unwind_protect (queue_selection_requests_unwind
,
1465 /* This allows quits. Also, don't wait forever. */
1466 secs
= x_selection_timeout
/ 1000;
1467 usecs
= (x_selection_timeout
% 1000) * 1000;
1468 TRACE1 (" Start waiting %d secs for SelectionNotify", secs
);
1469 wait_reading_process_output (secs
, usecs
, 0, 0,
1470 reading_selection_reply
, NULL
, 0);
1471 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply
)));
1474 if (x_had_errors_p (display
))
1475 error ("Cannot get selection");
1476 /* This calls x_uncatch_errors. */
1477 unbind_to (count
, Qnil
);
1480 if (NILP (XCAR (reading_selection_reply
)))
1481 error ("Timed out waiting for reply from selection owner");
1482 if (EQ (XCAR (reading_selection_reply
), Qlambda
))
1483 error ("No `%s' selection", SDATA (SYMBOL_NAME (selection_symbol
)));
1485 /* Otherwise, the selection is waiting for us on the requested property. */
1487 x_get_window_property_as_lisp_data (display
, requestor_window
,
1488 target_property
, target_type
,
1492 /* Subroutines of x_get_window_property_as_lisp_data */
1494 /* Use xfree, not XFree, to free the data obtained with this function. */
1497 x_get_window_property (display
, window
, property
, data_ret
, bytes_ret
,
1498 actual_type_ret
, actual_format_ret
, actual_size_ret
,
1503 unsigned char **data_ret
;
1505 Atom
*actual_type_ret
;
1506 int *actual_format_ret
;
1507 unsigned long *actual_size_ret
;
1511 unsigned long bytes_remaining
;
1513 unsigned char *tmp_data
= 0;
1515 int buffer_size
= SELECTION_QUANTUM (display
);
1517 if (buffer_size
> MAX_SELECTION_QUANTUM
)
1518 buffer_size
= MAX_SELECTION_QUANTUM
;
1522 /* First probe the thing to find out how big it is. */
1523 result
= XGetWindowProperty (display
, window
, property
,
1524 0L, 0L, False
, AnyPropertyType
,
1525 actual_type_ret
, actual_format_ret
,
1527 &bytes_remaining
, &tmp_data
);
1528 if (result
!= Success
)
1536 /* This was allocated by Xlib, so use XFree. */
1537 XFree ((char *) tmp_data
);
1539 if (*actual_type_ret
== None
|| *actual_format_ret
== 0)
1545 total_size
= bytes_remaining
+ 1;
1546 *data_ret
= (unsigned char *) xmalloc (total_size
);
1548 /* Now read, until we've gotten it all. */
1549 while (bytes_remaining
)
1551 #ifdef TRACE_SELECTION
1552 int last
= bytes_remaining
;
1555 = XGetWindowProperty (display
, window
, property
,
1556 (long)offset
/4, (long)buffer_size
/4,
1559 actual_type_ret
, actual_format_ret
,
1560 actual_size_ret
, &bytes_remaining
, &tmp_data
);
1562 TRACE2 ("Read %ld bytes from property %s",
1563 last
- bytes_remaining
,
1564 XGetAtomName (display
, property
));
1566 /* If this doesn't return Success at this point, it means that
1567 some clod deleted the selection while we were in the midst of
1568 reading it. Deal with that, I guess.... */
1569 if (result
!= Success
)
1572 /* The man page for XGetWindowProperty says:
1573 "If the returned format is 32, the returned data is represented
1574 as a long array and should be cast to that type to obtain the
1576 This applies even if long is more than 32 bits, the X library
1577 converts from 32 bit elements received from the X server to long
1578 and passes the long array to us. Thus, for that case bcopy can not
1579 be used. We convert to a 32 bit type here, because so much code
1582 The bytes and offsets passed to XGetWindowProperty refers to the
1583 property and those are indeed in 32 bit quantities if format is 32. */
1585 if (*actual_format_ret
== 32 && *actual_format_ret
< BITS_PER_LONG
)
1588 int *idata
= (int *) ((*data_ret
) + offset
);
1589 long *ldata
= (long *) tmp_data
;
1591 for (i
= 0; i
< *actual_size_ret
; ++i
)
1593 idata
[i
]= (int) ldata
[i
];
1599 *actual_size_ret
*= *actual_format_ret
/ 8;
1600 bcopy (tmp_data
, (*data_ret
) + offset
, *actual_size_ret
);
1601 offset
+= *actual_size_ret
;
1604 /* This was allocated by Xlib, so use XFree. */
1605 XFree ((char *) tmp_data
);
1610 *bytes_ret
= offset
;
1613 /* Use xfree, not XFree, to free the data obtained with this function. */
1616 receive_incremental_selection (display
, window
, property
, target_type
,
1617 min_size_bytes
, data_ret
, size_bytes_ret
,
1618 type_ret
, format_ret
, size_ret
)
1622 Lisp_Object target_type
; /* for error messages only */
1623 unsigned int min_size_bytes
;
1624 unsigned char **data_ret
;
1625 int *size_bytes_ret
;
1627 unsigned long *size_ret
;
1631 struct prop_location
*wait_object
;
1632 *size_bytes_ret
= min_size_bytes
;
1633 *data_ret
= (unsigned char *) xmalloc (*size_bytes_ret
);
1635 TRACE1 ("Read %d bytes incrementally", min_size_bytes
);
1637 /* At this point, we have read an INCR property.
1638 Delete the property to ack it.
1639 (But first, prepare to receive the next event in this handshake.)
1641 Now, we must loop, waiting for the sending window to put a value on
1642 that property, then reading the property, then deleting it to ack.
1643 We are done when the sender places a property of length 0.
1646 XSelectInput (display
, window
, STANDARD_EVENT_SET
| PropertyChangeMask
);
1647 TRACE1 (" Delete property %s",
1648 SDATA (SYMBOL_NAME (x_atom_to_symbol (display
, property
))));
1649 XDeleteProperty (display
, window
, property
);
1650 TRACE1 (" Expect new value of property %s",
1651 SDATA (SYMBOL_NAME (x_atom_to_symbol (display
, property
))));
1652 wait_object
= expect_property_change (display
, window
, property
,
1659 unsigned char *tmp_data
;
1662 TRACE0 (" Wait for property change");
1663 wait_for_property_change (wait_object
);
1665 /* expect it again immediately, because x_get_window_property may
1666 .. no it won't, I don't get it.
1667 .. Ok, I get it now, the Xt code that implements INCR is broken. */
1668 TRACE0 (" Get property value");
1669 x_get_window_property (display
, window
, property
,
1670 &tmp_data
, &tmp_size_bytes
,
1671 type_ret
, format_ret
, size_ret
, 1);
1673 TRACE1 (" Read increment of %d bytes", tmp_size_bytes
);
1675 if (tmp_size_bytes
== 0) /* we're done */
1677 TRACE0 ("Done reading incrementally");
1679 if (! waiting_for_other_props_on_window (display
, window
))
1680 XSelectInput (display
, window
, STANDARD_EVENT_SET
);
1681 /* Use xfree, not XFree, because x_get_window_property
1682 calls xmalloc itself. */
1683 if (tmp_data
) xfree (tmp_data
);
1688 TRACE1 (" ACK by deleting property %s",
1689 XGetAtomName (display
, property
));
1690 XDeleteProperty (display
, window
, property
);
1691 wait_object
= expect_property_change (display
, window
, property
,
1696 if (*size_bytes_ret
< offset
+ tmp_size_bytes
)
1698 *size_bytes_ret
= offset
+ tmp_size_bytes
;
1699 *data_ret
= (unsigned char *) xrealloc (*data_ret
, *size_bytes_ret
);
1702 bcopy (tmp_data
, (*data_ret
) + offset
, tmp_size_bytes
);
1703 offset
+= tmp_size_bytes
;
1705 /* Use xfree, not XFree, because x_get_window_property
1706 calls xmalloc itself. */
1712 /* Once a requested selection is "ready" (we got a SelectionNotify event),
1713 fetch value from property PROPERTY of X window WINDOW on display DISPLAY.
1714 TARGET_TYPE and SELECTION_ATOM are used in error message if this fails. */
1717 x_get_window_property_as_lisp_data (display
, window
, property
, target_type
,
1722 Lisp_Object target_type
; /* for error messages only */
1723 Atom selection_atom
; /* for error messages only */
1727 unsigned long actual_size
;
1728 unsigned char *data
= 0;
1731 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1733 TRACE0 ("Reading selection data");
1735 x_get_window_property (display
, window
, property
, &data
, &bytes
,
1736 &actual_type
, &actual_format
, &actual_size
, 1);
1739 int there_is_a_selection_owner
;
1741 there_is_a_selection_owner
1742 = XGetSelectionOwner (display
, selection_atom
);
1744 if (there_is_a_selection_owner
)
1745 signal_error ("Selection owner couldn't convert",
1747 ? list2 (target_type
,
1748 x_atom_to_symbol (display
, actual_type
))
1751 signal_error ("No selection",
1752 x_atom_to_symbol (display
, selection_atom
));
1755 if (actual_type
== dpyinfo
->Xatom_INCR
)
1757 /* That wasn't really the data, just the beginning. */
1759 unsigned int min_size_bytes
= * ((unsigned int *) data
);
1761 /* Use xfree, not XFree, because x_get_window_property
1762 calls xmalloc itself. */
1763 xfree ((char *) data
);
1765 receive_incremental_selection (display
, window
, property
, target_type
,
1766 min_size_bytes
, &data
, &bytes
,
1767 &actual_type
, &actual_format
,
1772 TRACE1 (" Delete property %s", XGetAtomName (display
, property
));
1773 XDeleteProperty (display
, window
, property
);
1777 /* It's been read. Now convert it to a lisp object in some semi-rational
1779 val
= selection_data_to_lisp_data (display
, data
, bytes
,
1780 actual_type
, actual_format
);
1782 /* Use xfree, not XFree, because x_get_window_property
1783 calls xmalloc itself. */
1784 xfree ((char *) data
);
1788 /* These functions convert from the selection data read from the server into
1789 something that we can use from Lisp, and vice versa.
1791 Type: Format: Size: Lisp Type:
1792 ----- ------- ----- -----------
1795 ATOM 32 > 1 Vector of Symbols
1797 * 16 > 1 Vector of Integers
1798 * 32 1 if <=16 bits: Integer
1799 if > 16 bits: Cons of top16, bot16
1800 * 32 > 1 Vector of the above
1802 When converting a Lisp number to C, it is assumed to be of format 16 if
1803 it is an integer, and of format 32 if it is a cons of two integers.
1805 When converting a vector of numbers from Lisp to C, it is assumed to be
1806 of format 16 if every element in the vector is an integer, and is assumed
1807 to be of format 32 if any element is a cons of two integers.
1809 When converting an object to C, it may be of the form (SYMBOL . <data>)
1810 where SYMBOL is what we should claim that the type is. Format and
1811 representation are as above.
1813 Important: When format is 32, data should contain an array of int,
1814 not an array of long as the X library returns. This makes a difference
1815 when sizeof(long) != sizeof(int). */
1820 selection_data_to_lisp_data (display
, data
, size
, type
, format
)
1822 unsigned char *data
;
1826 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1828 if (type
== dpyinfo
->Xatom_NULL
)
1831 /* Convert any 8-bit data to a string, for compactness. */
1832 else if (format
== 8)
1834 Lisp_Object str
, lispy_type
;
1836 str
= make_unibyte_string ((char *) data
, size
);
1837 /* Indicate that this string is from foreign selection by a text
1838 property `foreign-selection' so that the caller of
1839 x-get-selection-internal (usually x-get-selection) can know
1840 that the string must be decode. */
1841 if (type
== dpyinfo
->Xatom_COMPOUND_TEXT
)
1842 lispy_type
= QCOMPOUND_TEXT
;
1843 else if (type
== dpyinfo
->Xatom_UTF8_STRING
)
1844 lispy_type
= QUTF8_STRING
;
1846 lispy_type
= QSTRING
;
1847 Fput_text_property (make_number (0), make_number (size
),
1848 Qforeign_selection
, lispy_type
, str
);
1851 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to
1852 a vector of symbols.
1854 else if (type
== XA_ATOM
)
1857 /* On a 64 bit machine sizeof(Atom) == sizeof(long) == 8.
1858 But the callers of these function has made sure the data for
1859 format == 32 is an array of int. Thus, use int instead
1861 int *idata
= (int *) data
;
1863 if (size
== sizeof (int))
1864 return x_atom_to_symbol (display
, (Atom
) idata
[0]);
1867 Lisp_Object v
= Fmake_vector (make_number (size
/ sizeof (int)),
1869 for (i
= 0; i
< size
/ sizeof (int); i
++)
1870 Faset (v
, make_number (i
),
1871 x_atom_to_symbol (display
, (Atom
) idata
[i
]));
1876 /* Convert a single 16 or small 32 bit number to a Lisp_Int.
1877 If the number is > 16 bits, convert it to a cons of integers,
1878 16 bits in each half.
1880 else if (format
== 32 && size
== sizeof (int))
1881 return long_to_cons (((unsigned int *) data
) [0]);
1882 else if (format
== 16 && size
== sizeof (short))
1883 return make_number ((int) (((unsigned short *) data
) [0]));
1885 /* Convert any other kind of data to a vector of numbers, represented
1886 as above (as an integer, or a cons of two 16 bit integers.)
1888 else if (format
== 16)
1892 v
= Fmake_vector (make_number (size
/ 2), make_number (0));
1893 for (i
= 0; i
< size
/ 2; i
++)
1895 int j
= (int) ((unsigned short *) data
) [i
];
1896 Faset (v
, make_number (i
), make_number (j
));
1903 Lisp_Object v
= Fmake_vector (make_number (size
/ 4), make_number (0));
1904 for (i
= 0; i
< size
/ 4; i
++)
1906 unsigned int j
= ((unsigned int *) data
) [i
];
1907 Faset (v
, make_number (i
), long_to_cons (j
));
1914 /* Use xfree, not XFree, to free the data obtained with this function. */
1917 lisp_data_to_selection_data (display
, obj
,
1918 data_ret
, type_ret
, size_ret
,
1919 format_ret
, nofree_ret
)
1922 unsigned char **data_ret
;
1924 unsigned int *size_ret
;
1928 Lisp_Object type
= Qnil
;
1929 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
1933 if (CONSP (obj
) && SYMBOLP (XCAR (obj
)))
1937 if (CONSP (obj
) && NILP (XCDR (obj
)))
1941 if (EQ (obj
, QNULL
) || (EQ (type
, QNULL
)))
1942 { /* This is not the same as declining */
1948 else if (STRINGP (obj
))
1950 if (SCHARS (obj
) < SBYTES (obj
))
1951 /* OBJ is a multibyte string containing a non-ASCII char. */
1952 signal_error ("Non-ASCII string must be encoded in advance", obj
);
1956 *size_ret
= SBYTES (obj
);
1957 *data_ret
= SDATA (obj
);
1960 else if (SYMBOLP (obj
))
1964 *data_ret
= (unsigned char *) xmalloc (sizeof (Atom
) + 1);
1965 (*data_ret
) [sizeof (Atom
)] = 0;
1966 (*(Atom
**) data_ret
) [0] = symbol_to_x_atom (dpyinfo
, display
, obj
);
1967 if (NILP (type
)) type
= QATOM
;
1969 else if (INTEGERP (obj
)
1970 && XINT (obj
) < 0xFFFF
1971 && XINT (obj
) > -0xFFFF)
1975 *data_ret
= (unsigned char *) xmalloc (sizeof (short) + 1);
1976 (*data_ret
) [sizeof (short)] = 0;
1977 (*(short **) data_ret
) [0] = (short) XINT (obj
);
1978 if (NILP (type
)) type
= QINTEGER
;
1980 else if (INTEGERP (obj
)
1981 || (CONSP (obj
) && INTEGERP (XCAR (obj
))
1982 && (INTEGERP (XCDR (obj
))
1983 || (CONSP (XCDR (obj
))
1984 && INTEGERP (XCAR (XCDR (obj
)))))))
1988 *data_ret
= (unsigned char *) xmalloc (sizeof (long) + 1);
1989 (*data_ret
) [sizeof (long)] = 0;
1990 (*(unsigned long **) data_ret
) [0] = cons_to_long (obj
);
1991 if (NILP (type
)) type
= QINTEGER
;
1993 else if (VECTORP (obj
))
1995 /* Lisp_Vectors may represent a set of ATOMs;
1996 a set of 16 or 32 bit INTEGERs;
1997 or a set of ATOM_PAIRs (represented as [[A1 A2] [A3 A4] ...]
2001 if (SYMBOLP (XVECTOR (obj
)->contents
[0]))
2002 /* This vector is an ATOM set */
2004 if (NILP (type
)) type
= QATOM
;
2005 *size_ret
= XVECTOR (obj
)->size
;
2007 *data_ret
= (unsigned char *) xmalloc ((*size_ret
) * sizeof (Atom
));
2008 for (i
= 0; i
< *size_ret
; i
++)
2009 if (SYMBOLP (XVECTOR (obj
)->contents
[i
]))
2010 (*(Atom
**) data_ret
) [i
]
2011 = symbol_to_x_atom (dpyinfo
, display
, XVECTOR (obj
)->contents
[i
]);
2013 signal_error ("All elements of selection vector must have same type", obj
);
2015 #if 0 /* #### MULTIPLE doesn't work yet */
2016 else if (VECTORP (XVECTOR (obj
)->contents
[0]))
2017 /* This vector is an ATOM_PAIR set */
2019 if (NILP (type
)) type
= QATOM_PAIR
;
2020 *size_ret
= XVECTOR (obj
)->size
;
2022 *data_ret
= (unsigned char *)
2023 xmalloc ((*size_ret
) * sizeof (Atom
) * 2);
2024 for (i
= 0; i
< *size_ret
; i
++)
2025 if (VECTORP (XVECTOR (obj
)->contents
[i
]))
2027 Lisp_Object pair
= XVECTOR (obj
)->contents
[i
];
2028 if (XVECTOR (pair
)->size
!= 2)
2030 "Elements of the vector must be vectors of exactly two elements",
2033 (*(Atom
**) data_ret
) [i
* 2]
2034 = symbol_to_x_atom (dpyinfo
, display
,
2035 XVECTOR (pair
)->contents
[0]);
2036 (*(Atom
**) data_ret
) [(i
* 2) + 1]
2037 = symbol_to_x_atom (dpyinfo
, display
,
2038 XVECTOR (pair
)->contents
[1]);
2041 signal_error ("All elements of the vector must be of the same type",
2047 /* This vector is an INTEGER set, or something like it */
2050 *size_ret
= XVECTOR (obj
)->size
;
2051 if (NILP (type
)) type
= QINTEGER
;
2053 for (i
= 0; i
< *size_ret
; i
++)
2054 if (CONSP (XVECTOR (obj
)->contents
[i
]))
2056 else if (!INTEGERP (XVECTOR (obj
)->contents
[i
]))
2057 signal_error (/* Qselection_error */
2058 "Elements of selection vector must be integers or conses of integers",
2061 /* Use sizeof(long) even if it is more than 32 bits. See comment
2062 in x_get_window_property and x_fill_property_data. */
2064 if (*format_ret
== 32) data_size
= sizeof(long);
2065 *data_ret
= (unsigned char *) xmalloc (*size_ret
* data_size
);
2066 for (i
= 0; i
< *size_ret
; i
++)
2067 if (*format_ret
== 32)
2068 (*((unsigned long **) data_ret
)) [i
]
2069 = cons_to_long (XVECTOR (obj
)->contents
[i
]);
2071 (*((unsigned short **) data_ret
)) [i
]
2072 = (unsigned short) cons_to_long (XVECTOR (obj
)->contents
[i
]);
2076 signal_error (/* Qselection_error */ "Unrecognized selection data", obj
);
2078 *type_ret
= symbol_to_x_atom (dpyinfo
, display
, type
);
2082 clean_local_selection_data (obj
)
2086 && INTEGERP (XCAR (obj
))
2087 && CONSP (XCDR (obj
))
2088 && INTEGERP (XCAR (XCDR (obj
)))
2089 && NILP (XCDR (XCDR (obj
))))
2090 obj
= Fcons (XCAR (obj
), XCDR (obj
));
2093 && INTEGERP (XCAR (obj
))
2094 && INTEGERP (XCDR (obj
)))
2096 if (XINT (XCAR (obj
)) == 0)
2098 if (XINT (XCAR (obj
)) == -1)
2099 return make_number (- XINT (XCDR (obj
)));
2104 int size
= XVECTOR (obj
)->size
;
2107 return clean_local_selection_data (XVECTOR (obj
)->contents
[0]);
2108 copy
= Fmake_vector (make_number (size
), Qnil
);
2109 for (i
= 0; i
< size
; i
++)
2110 XVECTOR (copy
)->contents
[i
]
2111 = clean_local_selection_data (XVECTOR (obj
)->contents
[i
]);
2117 /* Called from XTread_socket to handle SelectionNotify events.
2118 If it's the selection we are waiting for, stop waiting
2119 by setting the car of reading_selection_reply to non-nil.
2120 We store t there if the reply is successful, lambda if not. */
2123 x_handle_selection_notify (event
)
2124 XSelectionEvent
*event
;
2126 if (event
->requestor
!= reading_selection_window
)
2128 if (event
->selection
!= reading_which_selection
)
2131 TRACE0 ("Received SelectionNotify");
2132 XSETCAR (reading_selection_reply
,
2133 (event
->property
!= 0 ? Qt
: Qlambda
));
2137 DEFUN ("x-own-selection-internal", Fx_own_selection_internal
,
2138 Sx_own_selection_internal
, 2, 2, 0,
2139 doc
: /* Assert an X selection of the given TYPE with the given VALUE.
2140 TYPE is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2141 \(Those are literal upper-case symbol names, since that's what X expects.)
2142 VALUE is typically a string, or a cons of two markers, but may be
2143 anything that the functions on `selection-converter-alist' know about. */)
2144 (selection_name
, selection_value
)
2145 Lisp_Object selection_name
, selection_value
;
2148 CHECK_SYMBOL (selection_name
);
2149 if (NILP (selection_value
)) error ("SELECTION-VALUE may not be nil");
2150 x_own_selection (selection_name
, selection_value
);
2151 return selection_value
;
2155 /* Request the selection value from the owner. If we are the owner,
2156 simply return our selection value. If we are not the owner, this
2157 will block until all of the data has arrived. */
2159 DEFUN ("x-get-selection-internal", Fx_get_selection_internal
,
2160 Sx_get_selection_internal
, 2, 3, 0,
2161 doc
: /* Return text selected from some X window.
2162 SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2163 \(Those are literal upper-case symbol names, since that's what X expects.)
2164 TYPE is the type of data desired, typically `STRING'.
2165 TIME_STAMP is the time to use in the XConvertSelection call for foreign
2166 selections. If omitted, defaults to the time for the last event. */)
2167 (selection_symbol
, target_type
, time_stamp
)
2168 Lisp_Object selection_symbol
, target_type
, time_stamp
;
2170 Lisp_Object val
= Qnil
;
2171 struct gcpro gcpro1
, gcpro2
;
2172 GCPRO2 (target_type
, val
); /* we store newly consed data into these */
2174 CHECK_SYMBOL (selection_symbol
);
2176 #if 0 /* #### MULTIPLE doesn't work yet */
2177 if (CONSP (target_type
)
2178 && XCAR (target_type
) == QMULTIPLE
)
2180 CHECK_VECTOR (XCDR (target_type
));
2181 /* So we don't destructively modify this... */
2182 target_type
= copy_multiple_data (target_type
);
2186 CHECK_SYMBOL (target_type
);
2188 val
= x_get_local_selection (selection_symbol
, target_type
, 1);
2192 val
= x_get_foreign_selection (selection_symbol
, target_type
, time_stamp
);
2197 && SYMBOLP (XCAR (val
)))
2200 if (CONSP (val
) && NILP (XCDR (val
)))
2203 val
= clean_local_selection_data (val
);
2209 DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal
,
2210 Sx_disown_selection_internal
, 1, 2, 0,
2211 doc
: /* If we own the selection SELECTION, disown it.
2212 Disowning it means there is no such selection. */)
2214 Lisp_Object selection
;
2218 Atom selection_atom
;
2220 struct selection_input_event sie
;
2221 struct input_event ie
;
2224 struct x_display_info
*dpyinfo
;
2225 struct frame
*sf
= SELECTED_FRAME ();
2228 if (! FRAME_X_P (sf
))
2231 display
= FRAME_X_DISPLAY (sf
);
2232 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2233 CHECK_SYMBOL (selection
);
2235 timestamp
= last_event_timestamp
;
2237 timestamp
= cons_to_long (time
);
2239 if (NILP (assq_no_quit (selection
, Vselection_alist
)))
2240 return Qnil
; /* Don't disown the selection when we're not the owner. */
2242 selection_atom
= symbol_to_x_atom (dpyinfo
, display
, selection
);
2245 XSetSelectionOwner (display
, selection_atom
, None
, timestamp
);
2248 /* It doesn't seem to be guaranteed that a SelectionClear event will be
2249 generated for a window which owns the selection when that window sets
2250 the selection owner to None. The NCD server does, the MIT Sun4 server
2251 doesn't. So we synthesize one; this means we might get two, but
2252 that's ok, because the second one won't have any effect. */
2253 SELECTION_EVENT_DISPLAY (&event
.sie
) = display
;
2254 SELECTION_EVENT_SELECTION (&event
.sie
) = selection_atom
;
2255 SELECTION_EVENT_TIME (&event
.sie
) = timestamp
;
2256 x_handle_selection_clear (&event
.ie
);
2261 /* Get rid of all the selections in buffer BUFFER.
2262 This is used when we kill a buffer. */
2265 x_disown_buffer_selections (buffer
)
2269 struct buffer
*buf
= XBUFFER (buffer
);
2271 for (tail
= Vselection_alist
; CONSP (tail
); tail
= XCDR (tail
))
2273 Lisp_Object elt
, value
;
2276 if (CONSP (value
) && MARKERP (XCAR (value
))
2277 && XMARKER (XCAR (value
))->buffer
== buf
)
2278 Fx_disown_selection_internal (XCAR (elt
), Qnil
);
2282 DEFUN ("x-selection-owner-p", Fx_selection_owner_p
, Sx_selection_owner_p
,
2284 doc
: /* Whether the current Emacs process owns the given X Selection.
2285 The arg should be the name of the selection in question, typically one of
2286 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2287 \(Those are literal upper-case symbol names, since that's what X expects.)
2288 For convenience, the symbol nil is the same as `PRIMARY',
2289 and t is the same as `SECONDARY'. */)
2291 Lisp_Object selection
;
2294 CHECK_SYMBOL (selection
);
2295 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2296 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2298 if (NILP (Fassq (selection
, Vselection_alist
)))
2303 DEFUN ("x-selection-exists-p", Fx_selection_exists_p
, Sx_selection_exists_p
,
2305 doc
: /* Whether there is an owner for the given X Selection.
2306 The arg should be the name of the selection in question, typically one of
2307 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
2308 \(Those are literal upper-case symbol names, since that's what X expects.)
2309 For convenience, the symbol nil is the same as `PRIMARY',
2310 and t is the same as `SECONDARY'. */)
2312 Lisp_Object selection
;
2317 struct frame
*sf
= SELECTED_FRAME ();
2319 /* It should be safe to call this before we have an X frame. */
2320 if (! FRAME_X_P (sf
))
2323 dpy
= FRAME_X_DISPLAY (sf
);
2324 CHECK_SYMBOL (selection
);
2325 if (!NILP (Fx_selection_owner_p (selection
)))
2327 if (EQ (selection
, Qnil
)) selection
= QPRIMARY
;
2328 if (EQ (selection
, Qt
)) selection
= QSECONDARY
;
2329 atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
), dpy
, selection
);
2333 owner
= XGetSelectionOwner (dpy
, atom
);
2335 return (owner
? Qt
: Qnil
);
2339 #ifdef CUT_BUFFER_SUPPORT
2341 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
2343 initialize_cut_buffers (display
, window
)
2347 unsigned char *data
= (unsigned char *) "";
2349 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
2350 PropModeAppend, data, 0)
2351 FROB (XA_CUT_BUFFER0
);
2352 FROB (XA_CUT_BUFFER1
);
2353 FROB (XA_CUT_BUFFER2
);
2354 FROB (XA_CUT_BUFFER3
);
2355 FROB (XA_CUT_BUFFER4
);
2356 FROB (XA_CUT_BUFFER5
);
2357 FROB (XA_CUT_BUFFER6
);
2358 FROB (XA_CUT_BUFFER7
);
2364 #define CHECK_CUT_BUFFER(symbol) \
2365 do { CHECK_SYMBOL ((symbol)); \
2366 if (!EQ((symbol), QCUT_BUFFER0) && !EQ((symbol), QCUT_BUFFER1) \
2367 && !EQ((symbol), QCUT_BUFFER2) && !EQ((symbol), QCUT_BUFFER3) \
2368 && !EQ((symbol), QCUT_BUFFER4) && !EQ((symbol), QCUT_BUFFER5) \
2369 && !EQ((symbol), QCUT_BUFFER6) && !EQ((symbol), QCUT_BUFFER7)) \
2370 signal_error ("Doesn't name a cut buffer", (symbol)); \
2373 DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal
,
2374 Sx_get_cut_buffer_internal
, 1, 1, 0,
2375 doc
: /* Returns the value of the named cut buffer (typically CUT_BUFFER0). */)
2381 unsigned char *data
;
2388 struct x_display_info
*dpyinfo
;
2389 struct frame
*sf
= SELECTED_FRAME ();
2393 if (! FRAME_X_P (sf
))
2396 display
= FRAME_X_DISPLAY (sf
);
2397 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
2398 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2399 CHECK_CUT_BUFFER (buffer
);
2400 buffer_atom
= symbol_to_x_atom (dpyinfo
, display
, buffer
);
2402 x_get_window_property (display
, window
, buffer_atom
, &data
, &bytes
,
2403 &type
, &format
, &size
, 0);
2404 if (!data
|| !format
)
2407 if (format
!= 8 || type
!= XA_STRING
)
2408 signal_error ("Cut buffer doesn't contain 8-bit data",
2409 list2 (x_atom_to_symbol (display
, type
),
2410 make_number (format
)));
2412 ret
= (bytes
? make_unibyte_string ((char *) data
, bytes
) : Qnil
);
2413 /* Use xfree, not XFree, because x_get_window_property
2414 calls xmalloc itself. */
2420 DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal
,
2421 Sx_store_cut_buffer_internal
, 2, 2, 0,
2422 doc
: /* Sets the value of the named cut buffer (typically CUT_BUFFER0). */)
2424 Lisp_Object buffer
, string
;
2428 unsigned char *data
;
2430 int bytes_remaining
;
2433 struct frame
*sf
= SELECTED_FRAME ();
2437 if (! FRAME_X_P (sf
))
2440 display
= FRAME_X_DISPLAY (sf
);
2441 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2443 max_bytes
= SELECTION_QUANTUM (display
);
2444 if (max_bytes
> MAX_SELECTION_QUANTUM
)
2445 max_bytes
= MAX_SELECTION_QUANTUM
;
2447 CHECK_CUT_BUFFER (buffer
);
2448 CHECK_STRING (string
);
2449 buffer_atom
= symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf
),
2451 data
= (unsigned char *) SDATA (string
);
2452 bytes
= SBYTES (string
);
2453 bytes_remaining
= bytes
;
2455 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2457 initialize_cut_buffers (display
, window
);
2458 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2463 /* Don't mess up with an empty value. */
2464 if (!bytes_remaining
)
2465 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2466 PropModeReplace
, data
, 0);
2468 while (bytes_remaining
)
2470 int chunk
= (bytes_remaining
< max_bytes
2471 ? bytes_remaining
: max_bytes
);
2472 XChangeProperty (display
, window
, buffer_atom
, XA_STRING
, 8,
2473 (bytes_remaining
== bytes
2478 bytes_remaining
-= chunk
;
2485 DEFUN ("x-rotate-cut-buffers-internal", Fx_rotate_cut_buffers_internal
,
2486 Sx_rotate_cut_buffers_internal
, 1, 1, 0,
2487 doc
: /* Rotate the values of the cut buffers by the given number of step.
2488 Positive means shift the values forward, negative means backward. */)
2495 struct frame
*sf
= SELECTED_FRAME ();
2499 if (! FRAME_X_P (sf
))
2502 display
= FRAME_X_DISPLAY (sf
);
2503 window
= RootWindow (display
, 0); /* Cut buffers are on screen 0 */
2507 if (! FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
)
2509 initialize_cut_buffers (display
, window
);
2510 FRAME_X_DISPLAY_INFO (sf
)->cut_buffers_initialized
= 1;
2513 props
[0] = XA_CUT_BUFFER0
;
2514 props
[1] = XA_CUT_BUFFER1
;
2515 props
[2] = XA_CUT_BUFFER2
;
2516 props
[3] = XA_CUT_BUFFER3
;
2517 props
[4] = XA_CUT_BUFFER4
;
2518 props
[5] = XA_CUT_BUFFER5
;
2519 props
[6] = XA_CUT_BUFFER6
;
2520 props
[7] = XA_CUT_BUFFER7
;
2522 XRotateWindowProperties (display
, window
, props
, 8, XINT (n
));
2529 /***********************************************************************
2530 Drag and drop support
2531 ***********************************************************************/
2532 /* Check that lisp values are of correct type for x_fill_property_data.
2533 That is, number, string or a cons with two numbers (low and high 16
2534 bit parts of a 32 bit number). */
2537 x_check_property_data (data
)
2543 for (iter
= data
; CONSP (iter
) && size
!= -1; iter
= XCDR (iter
), ++size
)
2545 Lisp_Object o
= XCAR (iter
);
2547 if (! NUMBERP (o
) && ! STRINGP (o
) && ! CONSP (o
))
2549 else if (CONSP (o
) &&
2550 (! NUMBERP (XCAR (o
)) || ! NUMBERP (XCDR (o
))))
2557 /* Convert lisp values to a C array. Values may be a number, a string
2558 which is taken as an X atom name and converted to the atom value, or
2559 a cons containing the two 16 bit parts of a 32 bit number.
2561 DPY is the display use to look up X atoms.
2562 DATA is a Lisp list of values to be converted.
2563 RET is the C array that contains the converted values. It is assumed
2564 it is big enough to hold all values.
2565 FORMAT is 8, 16 or 32 and denotes char/short/long for each C value to
2566 be stored in RET. Note that long is used for 32 even if long is more
2567 than 32 bits (see man pages for XChangeProperty, XGetWindowProperty and
2568 XClientMessageEvent). */
2571 x_fill_property_data (dpy
, data
, ret
, format
)
2578 long *d32
= (long *) ret
;
2579 short *d16
= (short *) ret
;
2580 char *d08
= (char *) ret
;
2583 for (iter
= data
; CONSP (iter
); iter
= XCDR (iter
))
2585 Lisp_Object o
= XCAR (iter
);
2588 val
= (long) XFASTINT (o
);
2589 else if (FLOATP (o
))
2590 val
= (long) XFLOAT_DATA (o
);
2592 val
= (long) cons_to_long (o
);
2593 else if (STRINGP (o
))
2596 val
= (long) XInternAtom (dpy
, (char *) SDATA (o
), False
);
2600 error ("Wrong type, must be string, number or cons");
2603 *d08
++ = (char) val
;
2604 else if (format
== 16)
2605 *d16
++ = (short) val
;
2611 /* Convert an array of C values to a Lisp list.
2612 F is the frame to be used to look up X atoms if the TYPE is XA_ATOM.
2613 DATA is a C array of values to be converted.
2614 TYPE is the type of the data. Only XA_ATOM is special, it converts
2615 each number in DATA to its corresponfing X atom as a symbol.
2616 FORMAT is 8, 16 or 32 and gives the size in bits for each C value to
2618 SIZE is the number of elements in DATA.
2620 Important: When format is 32, data should contain an array of int,
2621 not an array of long as the X library returns. This makes a difference
2622 when sizeof(long) != sizeof(int).
2624 Also see comment for selection_data_to_lisp_data above. */
2627 x_property_data_to_lisp (f
, data
, type
, format
, size
)
2629 unsigned char *data
;
2634 return selection_data_to_lisp_data (FRAME_X_DISPLAY (f
),
2635 data
, size
*format
/8, type
, format
);
2638 /* Get the mouse position in frame relative coordinates. */
2641 mouse_position_for_drop (f
, x
, y
)
2646 Window root
, dummy_window
;
2651 XQueryPointer (FRAME_X_DISPLAY (f
),
2652 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
2654 /* The root window which contains the pointer. */
2657 /* Window pointer is on, not used */
2660 /* The position on that root window. */
2663 /* x/y in dummy_window coordinates, not used. */
2666 /* Modifier keys and pointer buttons, about which
2668 (unsigned int *) &dummy
);
2671 /* Absolute to relative. */
2672 *x
-= f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
);
2673 *y
-= f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
);
2678 DEFUN ("x-get-atom-name", Fx_get_atom_name
,
2679 Sx_get_atom_name
, 1, 2, 0,
2680 doc
: /* Return the X atom name for VALUE as a string.
2681 VALUE may be a number or a cons where the car is the upper 16 bits and
2682 the cdr is the lower 16 bits of a 32 bit value.
2683 Use the display for FRAME or the current frame if FRAME is not given or nil.
2685 If the value is 0 or the atom is not known, return the empty string. */)
2687 Lisp_Object value
, frame
;
2689 struct frame
*f
= check_x_frame (frame
);
2691 Lisp_Object ret
= Qnil
;
2692 Display
*dpy
= FRAME_X_DISPLAY (f
);
2696 if (INTEGERP (value
))
2697 atom
= (Atom
) XUINT (value
);
2698 else if (FLOATP (value
))
2699 atom
= (Atom
) XFLOAT_DATA (value
);
2700 else if (CONSP (value
))
2701 atom
= (Atom
) cons_to_long (value
);
2703 error ("Wrong type, value must be number or cons");
2706 x_catch_errors (dpy
);
2707 name
= atom
? XGetAtomName (dpy
, atom
) : "";
2708 had_errors
= x_had_errors_p (dpy
);
2709 x_uncatch_errors ();
2712 ret
= make_string (name
, strlen (name
));
2714 if (atom
&& name
) XFree (name
);
2715 if (NILP (ret
)) ret
= make_string ("", 0);
2722 DEFUN ("x-register-dnd-atom", Fx_register_dnd_atom
,
2723 Sx_register_dnd_atom
, 1, 2, 0,
2724 doc
: /* Request that dnd events are made for ClientMessages with ATOM.
2725 ATOM can be a symbol or a string. The ATOM is interned on the display that
2726 FRAME is on. If FRAME is nil, the selected frame is used. */)
2728 Lisp_Object atom
, frame
;
2731 struct frame
*f
= check_x_frame (frame
);
2733 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2737 x_atom
= symbol_to_x_atom (dpyinfo
, FRAME_X_DISPLAY (f
), atom
);
2738 else if (STRINGP (atom
))
2741 x_atom
= XInternAtom (FRAME_X_DISPLAY (f
), (char *) SDATA (atom
), False
);
2745 error ("ATOM must be a symbol or a string");
2747 for (i
= 0; i
< dpyinfo
->x_dnd_atoms_length
; ++i
)
2748 if (dpyinfo
->x_dnd_atoms
[i
] == x_atom
)
2751 if (dpyinfo
->x_dnd_atoms_length
== dpyinfo
->x_dnd_atoms_size
)
2753 dpyinfo
->x_dnd_atoms_size
*= 2;
2754 dpyinfo
->x_dnd_atoms
= xrealloc (dpyinfo
->x_dnd_atoms
,
2755 sizeof (*dpyinfo
->x_dnd_atoms
)
2756 * dpyinfo
->x_dnd_atoms_size
);
2759 dpyinfo
->x_dnd_atoms
[dpyinfo
->x_dnd_atoms_length
++] = x_atom
;
2763 /* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT. */
2766 x_handle_dnd_message (f
, event
, dpyinfo
, bufp
)
2768 XClientMessageEvent
*event
;
2769 struct x_display_info
*dpyinfo
;
2770 struct input_event
*bufp
;
2774 /* format 32 => size 5, format 16 => size 10, format 8 => size 20 */
2775 unsigned long size
= 160/event
->format
;
2777 unsigned char *data
= (unsigned char *) event
->data
.b
;
2781 for (i
= 0; i
< dpyinfo
->x_dnd_atoms_length
; ++i
)
2782 if (dpyinfo
->x_dnd_atoms
[i
] == event
->message_type
) break;
2784 if (i
== dpyinfo
->x_dnd_atoms_length
) return 0;
2786 XSETFRAME (frame
, f
);
2788 /* On a 64 bit machine, the event->data.l array members are 64 bits (long),
2789 but the x_property_data_to_lisp (or rather selection_data_to_lisp_data)
2790 function expects them to be of size int (i.e. 32). So to be able to
2791 use that function, put the data in the form it expects if format is 32. */
2793 if (event
->format
== 32 && event
->format
< BITS_PER_LONG
)
2796 for (i
= 0; i
< 5; ++i
) /* There are only 5 longs in a ClientMessage. */
2797 idata
[i
] = (int) event
->data
.l
[i
];
2798 data
= (unsigned char *) idata
;
2801 vec
= Fmake_vector (make_number (4), Qnil
);
2802 AREF (vec
, 0) = SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f
),
2803 event
->message_type
));
2804 AREF (vec
, 1) = frame
;
2805 AREF (vec
, 2) = make_number (event
->format
);
2806 AREF (vec
, 3) = x_property_data_to_lisp (f
,
2808 event
->message_type
,
2812 mouse_position_for_drop (f
, &x
, &y
);
2813 bufp
->kind
= DRAG_N_DROP_EVENT
;
2814 bufp
->frame_or_window
= frame
;
2815 bufp
->timestamp
= CurrentTime
;
2816 bufp
->x
= make_number (x
);
2817 bufp
->y
= make_number (y
);
2819 bufp
->modifiers
= 0;
2824 DEFUN ("x-send-client-message", Fx_send_client_event
,
2825 Sx_send_client_message
, 6, 6, 0,
2826 doc
: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY.
2828 For DISPLAY, specify either a frame or a display name (a string).
2829 If DISPLAY is nil, that stands for the selected frame's display.
2830 DEST may be a number, in which case it is a Window id. The value 0 may
2831 be used to send to the root window of the DISPLAY.
2832 If DEST is a cons, it is converted to a 32 bit number
2833 with the high 16 bits from the car and the lower 16 bit from the cdr. That
2834 number is then used as a window id.
2835 If DEST is a frame the event is sent to the outer window of that frame.
2836 Nil means the currently selected frame.
2837 If DEST is the string "PointerWindow" the event is sent to the window that
2838 contains the pointer. If DEST is the string "InputFocus" the event is
2839 sent to the window that has the input focus.
2840 FROM is the frame sending the event. Use nil for currently selected frame.
2841 MESSAGE-TYPE is the name of an Atom as a string.
2842 FORMAT must be one of 8, 16 or 32 and determines the size of the values in
2843 bits. VALUES is a list of numbers, cons and/or strings containing the values
2844 to send. If a value is a string, it is converted to an Atom and the value of
2845 the Atom is sent. If a value is a cons, it is converted to a 32 bit number
2846 with the high 16 bits from the car and the lower 16 bit from the cdr.
2847 If more values than fits into the event is given, the excessive values
2849 (display
, dest
, from
, message_type
, format
, values
)
2850 Lisp_Object display
, dest
, from
, message_type
, format
, values
;
2852 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
2857 struct frame
*f
= check_x_frame (from
);
2860 CHECK_STRING (message_type
);
2861 CHECK_NUMBER (format
);
2862 CHECK_CONS (values
);
2864 if (x_check_property_data (values
) == -1)
2865 error ("Bad data in VALUES, must be number, cons or string");
2867 event
.xclient
.type
= ClientMessage
;
2868 event
.xclient
.format
= XFASTINT (format
);
2870 if (event
.xclient
.format
!= 8 && event
.xclient
.format
!= 16
2871 && event
.xclient
.format
!= 32)
2872 error ("FORMAT must be one of 8, 16 or 32");
2874 if (FRAMEP (dest
) || NILP (dest
))
2876 struct frame
*fdest
= check_x_frame (dest
);
2877 wdest
= FRAME_OUTER_WINDOW (fdest
);
2879 else if (STRINGP (dest
))
2881 if (strcmp (SDATA (dest
), "PointerWindow") == 0)
2882 wdest
= PointerWindow
;
2883 else if (strcmp (SDATA (dest
), "InputFocus") == 0)
2886 error ("DEST as a string must be one of PointerWindow or InputFocus");
2888 else if (INTEGERP (dest
))
2889 wdest
= (Window
) XFASTINT (dest
);
2890 else if (FLOATP (dest
))
2891 wdest
= (Window
) XFLOAT_DATA (dest
);
2892 else if (CONSP (dest
))
2894 if (! NUMBERP (XCAR (dest
)) || ! NUMBERP (XCDR (dest
)))
2895 error ("Both car and cdr for DEST must be numbers");
2897 wdest
= (Window
) cons_to_long (dest
);
2900 error ("DEST must be a frame, nil, string, number or cons");
2902 if (wdest
== 0) wdest
= dpyinfo
->root_window
;
2903 to_root
= wdest
== dpyinfo
->root_window
;
2905 for (cons
= values
, size
= 0; CONSP (cons
); cons
= XCDR (cons
), ++size
)
2910 event
.xclient
.message_type
2911 = XInternAtom (dpyinfo
->display
, SDATA (message_type
), False
);
2912 event
.xclient
.display
= dpyinfo
->display
;
2914 /* Some clients (metacity for example) expects sending window to be here
2915 when sending to the root window. */
2916 event
.xclient
.window
= to_root
? FRAME_OUTER_WINDOW (f
) : wdest
;
2919 memset (event
.xclient
.data
.b
, 0, sizeof (event
.xclient
.data
.b
));
2920 x_fill_property_data (dpyinfo
->display
, values
, event
.xclient
.data
.b
,
2921 event
.xclient
.format
);
2923 /* If event mask is 0 the event is sent to the client that created
2924 the destination window. But if we are sending to the root window,
2925 there is no such client. Then we set the event mask to 0xffff. The
2926 event then goes to clients selecting for events on the root window. */
2927 x_catch_errors (dpyinfo
->display
);
2929 int propagate
= to_root
? False
: True
;
2930 unsigned mask
= to_root
? 0xffff : 0;
2931 XSendEvent (dpyinfo
->display
, wdest
, propagate
, mask
, &event
);
2932 XFlush (dpyinfo
->display
);
2934 x_uncatch_errors ();
2944 defsubr (&Sx_get_selection_internal
);
2945 defsubr (&Sx_own_selection_internal
);
2946 defsubr (&Sx_disown_selection_internal
);
2947 defsubr (&Sx_selection_owner_p
);
2948 defsubr (&Sx_selection_exists_p
);
2950 #ifdef CUT_BUFFER_SUPPORT
2951 defsubr (&Sx_get_cut_buffer_internal
);
2952 defsubr (&Sx_store_cut_buffer_internal
);
2953 defsubr (&Sx_rotate_cut_buffers_internal
);
2956 defsubr (&Sx_get_atom_name
);
2957 defsubr (&Sx_send_client_message
);
2958 defsubr (&Sx_register_dnd_atom
);
2960 reading_selection_reply
= Fcons (Qnil
, Qnil
);
2961 staticpro (&reading_selection_reply
);
2962 reading_selection_window
= 0;
2963 reading_which_selection
= 0;
2965 property_change_wait_list
= 0;
2966 prop_location_identifier
= 0;
2967 property_change_reply
= Fcons (Qnil
, Qnil
);
2968 staticpro (&property_change_reply
);
2970 Vselection_alist
= Qnil
;
2971 staticpro (&Vselection_alist
);
2973 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist
,
2974 doc
: /* An alist associating X Windows selection-types with functions.
2975 These functions are called to convert the selection, with three args:
2976 the name of the selection (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
2977 a desired type to which the selection should be converted;
2978 and the local selection value (whatever was given to `x-own-selection').
2980 The function should return the value to send to the X server
2981 \(typically a string). A return value of nil
2982 means that the conversion could not be done.
2983 A return value which is the symbol `NULL'
2984 means that a side-effect was executed,
2985 and there is no meaningful selection value. */);
2986 Vselection_converter_alist
= Qnil
;
2988 DEFVAR_LISP ("x-lost-selection-functions", &Vx_lost_selection_functions
,
2989 doc
: /* A list of functions to be called when Emacs loses an X selection.
2990 \(This happens when some other X client makes its own selection
2991 or when a Lisp program explicitly clears the selection.)
2992 The functions are called with one argument, the selection type
2993 \(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'). */);
2994 Vx_lost_selection_functions
= Qnil
;
2996 DEFVAR_LISP ("x-sent-selection-functions", &Vx_sent_selection_functions
,
2997 doc
: /* A list of functions to be called when Emacs answers a selection request.
2998 The functions are called with four arguments:
2999 - the selection name (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
3000 - the selection-type which Emacs was asked to convert the
3001 selection into before sending (for example, `STRING' or `LENGTH');
3002 - a flag indicating success or failure for responding to the request.
3003 We might have failed (and declined the request) for any number of reasons,
3004 including being asked for a selection that we no longer own, or being asked
3005 to convert into a type that we don't know about or that is inappropriate.
3006 This hook doesn't let you change the behavior of Emacs's selection replies,
3007 it merely informs you that they have happened. */);
3008 Vx_sent_selection_functions
= Qnil
;
3010 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system
,
3011 doc
: /* Coding system for communicating with other X clients.
3013 When sending text via selection and clipboard, if the requested
3014 data-type is not "UTF8_STRING", the text is encoded by this coding
3017 When receiving text, if the data-type of the received text is not
3018 "UTF8_STRING", it is decoded by this coding system.
3020 See also the documentation of the variable `x-select-request-type' how
3021 to control which data-type to request for receiving text.
3023 The default value is `compound-text-with-extensions'. */);
3024 Vselection_coding_system
= intern ("compound-text-with-extensions");
3026 DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system
,
3027 doc
: /* Coding system for the next communication with other X clients.
3028 Usually, `selection-coding-system' is used for communicating with
3029 other X clients. But, if this variable is set, it is used for the
3030 next communication only. After the communication, this variable is
3032 Vnext_selection_coding_system
= Qnil
;
3034 DEFVAR_INT ("x-selection-timeout", &x_selection_timeout
,
3035 doc
: /* Number of milliseconds to wait for a selection reply.
3036 If the selection owner doesn't reply in this time, we give up.
3037 A value of 0 means wait as long as necessary. This is initialized from the
3038 \"*selectionTimeout\" resource. */);
3039 x_selection_timeout
= 0;
3041 QPRIMARY
= intern ("PRIMARY"); staticpro (&QPRIMARY
);
3042 QSECONDARY
= intern ("SECONDARY"); staticpro (&QSECONDARY
);
3043 QSTRING
= intern ("STRING"); staticpro (&QSTRING
);
3044 QINTEGER
= intern ("INTEGER"); staticpro (&QINTEGER
);
3045 QCLIPBOARD
= intern ("CLIPBOARD"); staticpro (&QCLIPBOARD
);
3046 QTIMESTAMP
= intern ("TIMESTAMP"); staticpro (&QTIMESTAMP
);
3047 QTEXT
= intern ("TEXT"); staticpro (&QTEXT
);
3048 QCOMPOUND_TEXT
= intern ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT
);
3049 QUTF8_STRING
= intern ("UTF8_STRING"); staticpro (&QUTF8_STRING
);
3050 QDELETE
= intern ("DELETE"); staticpro (&QDELETE
);
3051 QMULTIPLE
= intern ("MULTIPLE"); staticpro (&QMULTIPLE
);
3052 QINCR
= intern ("INCR"); staticpro (&QINCR
);
3053 QEMACS_TMP
= intern ("_EMACS_TMP_"); staticpro (&QEMACS_TMP
);
3054 QTARGETS
= intern ("TARGETS"); staticpro (&QTARGETS
);
3055 QATOM
= intern ("ATOM"); staticpro (&QATOM
);
3056 QATOM_PAIR
= intern ("ATOM_PAIR"); staticpro (&QATOM_PAIR
);
3057 QNULL
= intern ("NULL"); staticpro (&QNULL
);
3058 Qcompound_text_with_extensions
= intern ("compound-text-with-extensions");
3059 staticpro (&Qcompound_text_with_extensions
);
3061 #ifdef CUT_BUFFER_SUPPORT
3062 QCUT_BUFFER0
= intern ("CUT_BUFFER0"); staticpro (&QCUT_BUFFER0
);
3063 QCUT_BUFFER1
= intern ("CUT_BUFFER1"); staticpro (&QCUT_BUFFER1
);
3064 QCUT_BUFFER2
= intern ("CUT_BUFFER2"); staticpro (&QCUT_BUFFER2
);
3065 QCUT_BUFFER3
= intern ("CUT_BUFFER3"); staticpro (&QCUT_BUFFER3
);
3066 QCUT_BUFFER4
= intern ("CUT_BUFFER4"); staticpro (&QCUT_BUFFER4
);
3067 QCUT_BUFFER5
= intern ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5
);
3068 QCUT_BUFFER6
= intern ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6
);
3069 QCUT_BUFFER7
= intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7
);
3072 Qforeign_selection
= intern ("foreign-selection");
3073 staticpro (&Qforeign_selection
);
3076 /* arch-tag: 7c293b0f-9918-4f69-8ac7-03e142307236
3077 (do not change this comment) */