Mercurial > emacs
comparison src/xselect.c @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 265dc22fb2c0 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 /* X Selection processing for Emacs. | 1 /* X Selection processing for Emacs. |
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001 | 2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, |
3 Free Software Foundation. | 3 2004, 2005 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GNU Emacs. | 5 This file is part of GNU Emacs. |
6 | 6 |
7 GNU Emacs is free software; you can redistribute it and/or modify | 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 | 8 it under the terms of the GNU General Public License as published by |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 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 | 18 along with GNU Emacs; see the file COPYING. If not, write to |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 Boston, MA 02111-1307, USA. */ | 20 Boston, MA 02110-1301, USA. */ |
21 | 21 |
22 | 22 |
23 /* Rewritten by jwz */ | 23 /* Rewritten by jwz */ |
24 | 24 |
25 #include <config.h> | 25 #include <config.h> |
26 #include <stdio.h> /* termhooks.h needs this */ | |
27 | |
28 #ifdef HAVE_SYS_TYPES_H | |
29 #include <sys/types.h> | |
30 #endif | |
31 #ifdef HAVE_UNISTD_H | |
32 #include <unistd.h> | |
33 #endif | |
34 | |
26 #include "lisp.h" | 35 #include "lisp.h" |
27 #include "xterm.h" /* for all of the X includes */ | 36 #include "xterm.h" /* for all of the X includes */ |
28 #include "dispextern.h" /* frame.h seems to want this */ | 37 #include "dispextern.h" /* frame.h seems to want this */ |
29 #include "frame.h" /* Need this to get the X window of selected_frame */ | 38 #include "frame.h" /* Need this to get the X window of selected_frame */ |
30 #include "blockinput.h" | 39 #include "blockinput.h" |
31 #include "buffer.h" | 40 #include "buffer.h" |
32 #include "charset.h" | |
33 #include "coding.h" | |
34 #include "process.h" | 41 #include "process.h" |
35 #include "composite.h" | 42 #include "termhooks.h" |
43 #include "keyboard.h" | |
44 | |
45 #include <X11/Xproto.h> | |
36 | 46 |
37 struct prop_location; | 47 struct prop_location; |
38 | 48 |
39 static Lisp_Object x_atom_to_symbol P_ ((Display *dpy, Atom atom)); | 49 static Lisp_Object x_atom_to_symbol P_ ((Display *dpy, Atom atom)); |
40 static Atom symbol_to_x_atom P_ ((struct x_display_info *, Display *, | 50 static Atom symbol_to_x_atom P_ ((struct x_display_info *, Display *, |
51 static struct prop_location *expect_property_change P_ ((Display *, Window, | 61 static struct prop_location *expect_property_change P_ ((Display *, Window, |
52 Atom, int)); | 62 Atom, int)); |
53 static void unexpect_property_change P_ ((struct prop_location *)); | 63 static void unexpect_property_change P_ ((struct prop_location *)); |
54 static Lisp_Object wait_for_property_change_unwind P_ ((Lisp_Object)); | 64 static Lisp_Object wait_for_property_change_unwind P_ ((Lisp_Object)); |
55 static void wait_for_property_change P_ ((struct prop_location *)); | 65 static void wait_for_property_change P_ ((struct prop_location *)); |
56 static Lisp_Object x_get_foreign_selection P_ ((Lisp_Object, Lisp_Object)); | 66 static Lisp_Object x_get_foreign_selection P_ ((Lisp_Object, |
67 Lisp_Object, | |
68 Lisp_Object)); | |
57 static void x_get_window_property P_ ((Display *, Window, Atom, | 69 static void x_get_window_property P_ ((Display *, Window, Atom, |
58 unsigned char **, int *, | 70 unsigned char **, int *, |
59 Atom *, int *, unsigned long *, int)); | 71 Atom *, int *, unsigned long *, int)); |
60 static void receive_incremental_selection P_ ((Display *, Window, Atom, | 72 static void receive_incremental_selection P_ ((Display *, Window, Atom, |
61 Lisp_Object, unsigned, | 73 Lisp_Object, unsigned, |
80 fprintf (stderr, "%d: " fmt "\n", getpid ()) | 92 fprintf (stderr, "%d: " fmt "\n", getpid ()) |
81 #define TRACE1(fmt, a0) \ | 93 #define TRACE1(fmt, a0) \ |
82 fprintf (stderr, "%d: " fmt "\n", getpid (), a0) | 94 fprintf (stderr, "%d: " fmt "\n", getpid (), a0) |
83 #define TRACE2(fmt, a0, a1) \ | 95 #define TRACE2(fmt, a0, a1) \ |
84 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1) | 96 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1) |
97 #define TRACE3(fmt, a0, a1, a2) \ | |
98 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1, a2) | |
85 #else | 99 #else |
86 #define TRACE0(fmt) (void) 0 | 100 #define TRACE0(fmt) (void) 0 |
87 #define TRACE1(fmt, a0) (void) 0 | 101 #define TRACE1(fmt, a0) (void) 0 |
88 #define TRACE2(fmt, a0, a1) (void) 0 | 102 #define TRACE2(fmt, a0, a1) (void) 0 |
103 #define TRACE3(fmt, a0, a1) (void) 0 | |
89 #endif | 104 #endif |
90 | 105 |
91 | 106 |
92 #define CUT_BUFFER_SUPPORT | 107 #define CUT_BUFFER_SUPPORT |
93 | 108 |
103 #ifdef CUT_BUFFER_SUPPORT | 118 #ifdef CUT_BUFFER_SUPPORT |
104 Lisp_Object QCUT_BUFFER0, QCUT_BUFFER1, QCUT_BUFFER2, QCUT_BUFFER3, | 119 Lisp_Object QCUT_BUFFER0, QCUT_BUFFER1, QCUT_BUFFER2, QCUT_BUFFER3, |
105 QCUT_BUFFER4, QCUT_BUFFER5, QCUT_BUFFER6, QCUT_BUFFER7; | 120 QCUT_BUFFER4, QCUT_BUFFER5, QCUT_BUFFER6, QCUT_BUFFER7; |
106 #endif | 121 #endif |
107 | 122 |
108 static Lisp_Object Vx_lost_selection_hooks; | 123 static Lisp_Object Vx_lost_selection_functions; |
109 static Lisp_Object Vx_sent_selection_hooks; | 124 static Lisp_Object Vx_sent_selection_functions; |
110 /* Coding system for communicating with other X clients via cutbuffer, | 125 /* Coding system for communicating with other X clients via cutbuffer, |
111 selection, and clipboard. */ | 126 selection, and clipboard. */ |
112 static Lisp_Object Vselection_coding_system; | 127 static Lisp_Object Vselection_coding_system; |
113 | 128 |
114 /* Coding system for the next communicating with other X clients. */ | 129 /* Coding system for the next communicating with other X clients. */ |
115 static Lisp_Object Vnext_selection_coding_system; | 130 static Lisp_Object Vnext_selection_coding_system; |
131 | |
132 static Lisp_Object Qforeign_selection; | |
116 | 133 |
117 /* If this is a smaller number than the max-request-size of the display, | 134 /* If this is a smaller number than the max-request-size of the display, |
118 emacs will use INCR selection transfer when the selection is larger | 135 emacs will use INCR selection transfer when the selection is larger |
119 than this. The max-request-size is usually around 64k, so if you want | 136 than this. The max-request-size is usually around 64k, so if you want |
120 emacs to use incremental selection transfers when the selection is | 137 emacs to use incremental selection transfers when the selection is |
154 static Lisp_Object Vselection_converter_alist; | 171 static Lisp_Object Vselection_converter_alist; |
155 | 172 |
156 /* If the selection owner takes too long to reply to a selection request, | 173 /* If the selection owner takes too long to reply to a selection request, |
157 we give up on it. This is in milliseconds (0 = no timeout.) */ | 174 we give up on it. This is in milliseconds (0 = no timeout.) */ |
158 static EMACS_INT x_selection_timeout; | 175 static EMACS_INT x_selection_timeout; |
176 | |
177 | |
159 | 178 |
160 /* Utility functions */ | 179 /* Define a queue to save up SELECTION_REQUEST_EVENT events for later |
161 | 180 handling. */ |
162 static void lisp_data_to_selection_data (); | 181 |
163 static Lisp_Object selection_data_to_lisp_data (); | 182 struct selection_event_queue |
164 static Lisp_Object x_get_window_property_as_lisp_data (); | 183 { |
184 struct input_event event; | |
185 struct selection_event_queue *next; | |
186 }; | |
187 | |
188 static struct selection_event_queue *selection_queue; | |
189 | |
190 /* Nonzero means queue up SELECTION_REQUEST_EVENT events. */ | |
191 | |
192 static int x_queue_selection_requests; | |
193 | |
194 /* Queue up an SELECTION_REQUEST_EVENT *EVENT, to be processed later. */ | |
195 | |
196 static void | |
197 x_queue_event (event) | |
198 struct input_event *event; | |
199 { | |
200 struct selection_event_queue *queue_tmp; | |
201 | |
202 /* Don't queue repeated requests. | |
203 This only happens for large requests which uses the incremental protocol. */ | |
204 for (queue_tmp = selection_queue; queue_tmp; queue_tmp = queue_tmp->next) | |
205 { | |
206 if (!bcmp (&queue_tmp->event, event, sizeof (*event))) | |
207 { | |
208 TRACE1 ("DECLINE DUP SELECTION EVENT %08lx", (unsigned long)queue_tmp); | |
209 x_decline_selection_request (event); | |
210 return; | |
211 } | |
212 } | |
213 | |
214 queue_tmp | |
215 = (struct selection_event_queue *) xmalloc (sizeof (struct selection_event_queue)); | |
216 | |
217 if (queue_tmp != NULL) | |
218 { | |
219 TRACE1 ("QUEUE SELECTION EVENT %08lx", (unsigned long)queue_tmp); | |
220 queue_tmp->event = *event; | |
221 queue_tmp->next = selection_queue; | |
222 selection_queue = queue_tmp; | |
223 } | |
224 } | |
225 | |
226 /* Start queuing SELECTION_REQUEST_EVENT events. */ | |
227 | |
228 static void | |
229 x_start_queuing_selection_requests () | |
230 { | |
231 if (x_queue_selection_requests) | |
232 abort (); | |
233 | |
234 x_queue_selection_requests++; | |
235 TRACE1 ("x_start_queuing_selection_requests %d", x_queue_selection_requests); | |
236 } | |
237 | |
238 /* Stop queuing SELECTION_REQUEST_EVENT events. */ | |
239 | |
240 static void | |
241 x_stop_queuing_selection_requests () | |
242 { | |
243 TRACE1 ("x_stop_queuing_selection_requests %d", x_queue_selection_requests); | |
244 --x_queue_selection_requests; | |
245 | |
246 /* Take all the queued events and put them back | |
247 so that they get processed afresh. */ | |
248 | |
249 while (selection_queue != NULL) | |
250 { | |
251 struct selection_event_queue *queue_tmp = selection_queue; | |
252 TRACE1 ("RESTORE SELECTION EVENT %08lx", (unsigned long)queue_tmp); | |
253 kbd_buffer_unget_event (&queue_tmp->event); | |
254 selection_queue = queue_tmp->next; | |
255 xfree ((char *)queue_tmp); | |
256 } | |
257 } | |
258 | |
165 | 259 |
166 /* This converts a Lisp symbol to a server Atom, avoiding a server | 260 /* This converts a Lisp symbol to a server Atom, avoiding a server |
167 roundtrip whenever possible. */ | 261 roundtrip whenever possible. */ |
168 | 262 |
169 static Atom | 263 static Atom |
423 count = SPECPDL_INDEX (); | 517 count = SPECPDL_INDEX (); |
424 specbind (Qinhibit_quit, Qt); | 518 specbind (Qinhibit_quit, Qt); |
425 | 519 |
426 CHECK_SYMBOL (target_type); | 520 CHECK_SYMBOL (target_type); |
427 handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist)); | 521 handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist)); |
522 /* gcpro is not needed here since nothing but HANDLER_FN | |
523 is live, and that ought to be a symbol. */ | |
524 | |
428 if (!NILP (handler_fn)) | 525 if (!NILP (handler_fn)) |
429 value = call3 (handler_fn, | 526 value = call3 (handler_fn, |
430 selection_symbol, (local_request ? Qnil : target_type), | 527 selection_symbol, (local_request ? Qnil : target_type), |
431 XCAR (XCDR (local_value))); | 528 XCAR (XCDR (local_value))); |
432 else | 529 else |
547 static struct prop_location *property_change_reply_object; | 644 static struct prop_location *property_change_reply_object; |
548 | 645 |
549 static struct prop_location *property_change_wait_list; | 646 static struct prop_location *property_change_wait_list; |
550 | 647 |
551 static Lisp_Object | 648 static Lisp_Object |
552 queue_selection_requests_unwind (frame) | 649 queue_selection_requests_unwind (tem) |
553 Lisp_Object frame; | 650 Lisp_Object tem; |
554 { | 651 { |
555 FRAME_PTR f = XFRAME (frame); | 652 x_stop_queuing_selection_requests (); |
556 | |
557 if (! NILP (frame)) | |
558 x_stop_queuing_selection_requests (FRAME_X_DISPLAY (f)); | |
559 return Qnil; | 653 return Qnil; |
560 } | 654 } |
561 | 655 |
562 /* Return some frame whose display info is DPYINFO. | 656 /* Return some frame whose display info is DPYINFO. |
563 Return nil if there is none. */ | 657 Return nil if there is none. */ |
613 | 707 |
614 /* #### XChangeProperty can generate BadAlloc, and we must handle it! */ | 708 /* #### XChangeProperty can generate BadAlloc, and we must handle it! */ |
615 BLOCK_INPUT; | 709 BLOCK_INPUT; |
616 count = x_catch_errors (display); | 710 count = x_catch_errors (display); |
617 | 711 |
712 #ifdef TRACE_SELECTION | |
713 { | |
714 static int cnt; | |
715 char *sel = XGetAtomName (display, reply.selection); | |
716 char *tgt = XGetAtomName (display, reply.target); | |
717 TRACE3 ("%s, target %s (%d)", sel, tgt, ++cnt); | |
718 if (sel) XFree (sel); | |
719 if (tgt) XFree (tgt); | |
720 } | |
721 #endif /* TRACE_SELECTION */ | |
722 | |
618 /* Store the data on the requested property. | 723 /* Store the data on the requested property. |
619 If the selection is large, only store the first N bytes of it. | 724 If the selection is large, only store the first N bytes of it. |
620 */ | 725 */ |
621 bytes_remaining = size * format_bytes; | 726 bytes_remaining = size * format_bytes; |
622 if (bytes_remaining <= max_bytes) | 727 if (bytes_remaining <= max_bytes) |
640 /* If the display no longer has frames, we can't expect | 745 /* If the display no longer has frames, we can't expect |
641 to get many more selection requests from it, so don't | 746 to get many more selection requests from it, so don't |
642 bother trying to queue them. */ | 747 bother trying to queue them. */ |
643 if (!NILP (frame)) | 748 if (!NILP (frame)) |
644 { | 749 { |
645 x_start_queuing_selection_requests (display); | 750 x_start_queuing_selection_requests (); |
646 | 751 |
647 record_unwind_protect (queue_selection_requests_unwind, | 752 record_unwind_protect (queue_selection_requests_unwind, |
648 frame); | 753 Qnil); |
649 } | 754 } |
650 | 755 |
651 if (x_window_to_frame (dpyinfo, window)) /* #### debug */ | 756 if (x_window_to_frame (dpyinfo, window)) /* #### debug */ |
652 error ("Attempt to transfer an INCR to ourself!"); | 757 error ("Attempt to transfer an INCR to ourself!"); |
653 | 758 |
656 wait_object = expect_property_change (display, window, reply.property, | 761 wait_object = expect_property_change (display, window, reply.property, |
657 PropertyDelete); | 762 PropertyDelete); |
658 | 763 |
659 TRACE1 ("Set %s to number of bytes to send", | 764 TRACE1 ("Set %s to number of bytes to send", |
660 XGetAtomName (display, reply.property)); | 765 XGetAtomName (display, reply.property)); |
661 XChangeProperty (display, window, reply.property, dpyinfo->Xatom_INCR, | 766 { |
662 32, PropModeReplace, | 767 /* XChangeProperty expects an array of long even if long is more than |
663 (unsigned char *) &bytes_remaining, 1); | 768 32 bits. */ |
769 long value[1]; | |
770 | |
771 value[0] = bytes_remaining; | |
772 XChangeProperty (display, window, reply.property, dpyinfo->Xatom_INCR, | |
773 32, PropModeReplace, | |
774 (unsigned char *) value, 1); | |
775 } | |
776 | |
664 XSelectInput (display, window, PropertyChangeMask); | 777 XSelectInput (display, window, PropertyChangeMask); |
665 | 778 |
666 /* Tell 'em the INCR data is there... */ | 779 /* Tell 'em the INCR data is there... */ |
667 TRACE0 ("Send SelectionNotify event"); | 780 TRACE0 ("Send SelectionNotify event"); |
668 XSendEvent (display, window, False, 0L, (XEvent *) &reply); | 781 XSendEvent (display, window, False, 0L, (XEvent *) &reply); |
677 { | 790 { |
678 TRACE1 ("Waiting for ACK (deletion of %s)", | 791 TRACE1 ("Waiting for ACK (deletion of %s)", |
679 XGetAtomName (display, reply.property)); | 792 XGetAtomName (display, reply.property)); |
680 wait_for_property_change (wait_object); | 793 wait_for_property_change (wait_object); |
681 } | 794 } |
795 else | |
796 unexpect_property_change (wait_object); | |
682 | 797 |
683 TRACE0 ("Got ACK"); | 798 TRACE0 ("Got ACK"); |
684 while (bytes_remaining) | 799 while (bytes_remaining) |
685 { | 800 { |
686 int i = ((bytes_remaining < max_bytes) | 801 int i = ((bytes_remaining < max_bytes) |
687 ? bytes_remaining | 802 ? bytes_remaining |
688 : max_bytes); | 803 : max_bytes); |
689 | 804 |
690 BLOCK_INPUT; | 805 BLOCK_INPUT; |
691 | 806 |
692 wait_object | 807 wait_object |
693 = expect_property_change (display, window, reply.property, | 808 = expect_property_change (display, window, reply.property, |
734 in the meantime (that's a real situation from a bug report). | 849 in the meantime (that's a real situation from a bug report). |
735 In this case, there may be events in the event queue still | 850 In this case, there may be events in the event queue still |
736 refering to the deleted window, and we'll get a BadWindow error | 851 refering to the deleted window, and we'll get a BadWindow error |
737 in XTread_socket when processing the events. I don't have | 852 in XTread_socket when processing the events. I don't have |
738 an idea how to fix that. gerd, 2001-01-98. */ | 853 an idea how to fix that. gerd, 2001-01-98. */ |
739 XFlush (display); | 854 /* 2004-09-10: XSync and UNBLOCK so that possible protocol errors are |
855 delivered before uncatch errors. */ | |
856 XSync (display, False); | |
857 UNBLOCK_INPUT; | |
858 | |
859 /* GTK queues events in addition to the queue in Xlib. So we | |
860 UNBLOCK to enter the event loop and get possible errors delivered, | |
861 and then BLOCK again because x_uncatch_errors requires it. */ | |
862 BLOCK_INPUT; | |
740 x_uncatch_errors (display, count); | 863 x_uncatch_errors (display, count); |
741 UNBLOCK_INPUT; | 864 UNBLOCK_INPUT; |
742 } | 865 } |
743 | 866 |
744 /* Handle a SelectionRequest event EVENT. | 867 /* Handle a SelectionRequest event EVENT. |
745 This is called from keyboard.c when such an event is found in the queue. */ | 868 This is called from keyboard.c when such an event is found in the queue. */ |
746 | 869 |
747 void | 870 static void |
748 x_handle_selection_request (event) | 871 x_handle_selection_request (event) |
749 struct input_event *event; | 872 struct input_event *event; |
750 { | 873 { |
751 struct gcpro gcpro1, gcpro2, gcpro3; | 874 struct gcpro gcpro1, gcpro2, gcpro3; |
752 Lisp_Object local_selection_data; | 875 Lisp_Object local_selection_data; |
757 Lisp_Object successful_p; | 880 Lisp_Object successful_p; |
758 int count; | 881 int count; |
759 struct x_display_info *dpyinfo | 882 struct x_display_info *dpyinfo |
760 = x_display_info_for_display (SELECTION_EVENT_DISPLAY (event)); | 883 = x_display_info_for_display (SELECTION_EVENT_DISPLAY (event)); |
761 | 884 |
885 TRACE2 ("x_handle_selection_request, from=0x%08lx time=%lu", | |
886 (unsigned long) SELECTION_EVENT_REQUESTOR (event), | |
887 (unsigned long) SELECTION_EVENT_TIME (event)); | |
888 | |
762 local_selection_data = Qnil; | 889 local_selection_data = Qnil; |
763 target_symbol = Qnil; | 890 target_symbol = Qnil; |
764 converted_selection = Qnil; | 891 converted_selection = Qnil; |
765 successful_p = Qnil; | 892 successful_p = Qnil; |
766 | 893 |
835 } | 962 } |
836 unbind_to (count, Qnil); | 963 unbind_to (count, Qnil); |
837 | 964 |
838 DONE: | 965 DONE: |
839 | 966 |
840 UNGCPRO; | |
841 | |
842 /* Let random lisp code notice that the selection has been asked for. */ | 967 /* Let random lisp code notice that the selection has been asked for. */ |
843 { | 968 { |
844 Lisp_Object rest; | 969 Lisp_Object rest; |
845 rest = Vx_sent_selection_hooks; | 970 rest = Vx_sent_selection_functions; |
846 if (!EQ (rest, Qunbound)) | 971 if (!EQ (rest, Qunbound)) |
847 for (; CONSP (rest); rest = Fcdr (rest)) | 972 for (; CONSP (rest); rest = Fcdr (rest)) |
848 call3 (Fcar (rest), selection_symbol, target_symbol, successful_p); | 973 call3 (Fcar (rest), selection_symbol, target_symbol, successful_p); |
849 } | 974 } |
975 | |
976 UNGCPRO; | |
850 } | 977 } |
851 | 978 |
852 /* Handle a SelectionClear event EVENT, which indicates that some | 979 /* Handle a SelectionClear event EVENT, which indicates that some |
853 client cleared out our previously asserted selection. | 980 client cleared out our previously asserted selection. |
854 This is called from keyboard.c when such an event is found in the queue. */ | 981 This is called from keyboard.c when such an event is found in the queue. */ |
855 | 982 |
856 void | 983 static void |
857 x_handle_selection_clear (event) | 984 x_handle_selection_clear (event) |
858 struct input_event *event; | 985 struct input_event *event; |
859 { | 986 { |
860 Display *display = SELECTION_EVENT_DISPLAY (event); | 987 Display *display = SELECTION_EVENT_DISPLAY (event); |
861 Atom selection = SELECTION_EVENT_SELECTION (event); | 988 Atom selection = SELECTION_EVENT_SELECTION (event); |
863 | 990 |
864 Lisp_Object selection_symbol, local_selection_data; | 991 Lisp_Object selection_symbol, local_selection_data; |
865 Time local_selection_time; | 992 Time local_selection_time; |
866 struct x_display_info *dpyinfo = x_display_info_for_display (display); | 993 struct x_display_info *dpyinfo = x_display_info_for_display (display); |
867 struct x_display_info *t_dpyinfo; | 994 struct x_display_info *t_dpyinfo; |
995 | |
996 TRACE0 ("x_handle_selection_clear"); | |
868 | 997 |
869 /* If the new selection owner is also Emacs, | 998 /* If the new selection owner is also Emacs, |
870 don't clear the new selection. */ | 999 don't clear the new selection. */ |
871 BLOCK_INPUT; | 1000 BLOCK_INPUT; |
872 /* Check each display on the same terminal, | 1001 /* Check each display on the same terminal, |
921 | 1050 |
922 /* Let random lisp code notice that the selection has been stolen. */ | 1051 /* Let random lisp code notice that the selection has been stolen. */ |
923 | 1052 |
924 { | 1053 { |
925 Lisp_Object rest; | 1054 Lisp_Object rest; |
926 rest = Vx_lost_selection_hooks; | 1055 rest = Vx_lost_selection_functions; |
927 if (!EQ (rest, Qunbound)) | 1056 if (!EQ (rest, Qunbound)) |
928 { | 1057 { |
929 for (; CONSP (rest); rest = Fcdr (rest)) | 1058 for (; CONSP (rest); rest = Fcdr (rest)) |
930 call1 (Fcar (rest), selection_symbol); | 1059 call1 (Fcar (rest), selection_symbol); |
931 prepare_menu_bars (); | 1060 prepare_menu_bars (); |
932 redisplay_preserve_echo_area (20); | 1061 redisplay_preserve_echo_area (20); |
933 } | 1062 } |
934 } | 1063 } |
935 } | 1064 } |
936 | 1065 |
1066 void | |
1067 x_handle_selection_event (event) | |
1068 struct input_event *event; | |
1069 { | |
1070 TRACE0 ("x_handle_selection_event"); | |
1071 | |
1072 if (event->kind == SELECTION_REQUEST_EVENT) | |
1073 { | |
1074 if (x_queue_selection_requests) | |
1075 x_queue_event (event); | |
1076 else | |
1077 x_handle_selection_request (event); | |
1078 } | |
1079 else | |
1080 x_handle_selection_clear (event); | |
1081 } | |
1082 | |
1083 | |
937 /* Clear all selections that were made from frame F. | 1084 /* Clear all selections that were made from frame F. |
938 We do this when about to delete a frame. */ | 1085 We do this when about to delete a frame. */ |
939 | 1086 |
940 void | 1087 void |
941 x_clear_frame_selections (f) | 1088 x_clear_frame_selections (f) |
954 && EQ (frame, Fcar (Fcdr (Fcdr (Fcdr (Fcar (Vselection_alist))))))) | 1101 && EQ (frame, Fcar (Fcdr (Fcdr (Fcdr (Fcar (Vselection_alist))))))) |
955 { | 1102 { |
956 /* Let random Lisp code notice that the selection has been stolen. */ | 1103 /* Let random Lisp code notice that the selection has been stolen. */ |
957 Lisp_Object hooks, selection_symbol; | 1104 Lisp_Object hooks, selection_symbol; |
958 | 1105 |
959 hooks = Vx_lost_selection_hooks; | 1106 hooks = Vx_lost_selection_functions; |
960 selection_symbol = Fcar (Fcar (Vselection_alist)); | 1107 selection_symbol = Fcar (Fcar (Vselection_alist)); |
961 | 1108 |
962 if (!EQ (hooks, Qunbound)) | 1109 if (!EQ (hooks, Qunbound)) |
963 { | 1110 { |
964 for (; CONSP (hooks); hooks = Fcdr (hooks)) | 1111 for (; CONSP (hooks); hooks = Fcdr (hooks)) |
978 if (EQ (frame, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest)))))))) | 1125 if (EQ (frame, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest)))))))) |
979 { | 1126 { |
980 /* Let random Lisp code notice that the selection has been stolen. */ | 1127 /* Let random Lisp code notice that the selection has been stolen. */ |
981 Lisp_Object hooks, selection_symbol; | 1128 Lisp_Object hooks, selection_symbol; |
982 | 1129 |
983 hooks = Vx_lost_selection_hooks; | 1130 hooks = Vx_lost_selection_functions; |
984 selection_symbol = Fcar (Fcar (XCDR (rest))); | 1131 selection_symbol = Fcar (Fcar (XCDR (rest))); |
985 | 1132 |
986 if (!EQ (hooks, Qunbound)) | 1133 if (!EQ (hooks, Qunbound)) |
987 { | 1134 { |
988 for (; CONSP (hooks); hooks = Fcdr (hooks)) | 1135 for (; CONSP (hooks); hooks = Fcdr (hooks)) |
1062 } | 1209 } |
1063 | 1210 |
1064 /* Remove the property change expectation element for IDENTIFIER. */ | 1211 /* Remove the property change expectation element for IDENTIFIER. */ |
1065 | 1212 |
1066 static Lisp_Object | 1213 static Lisp_Object |
1067 wait_for_property_change_unwind (identifierval) | 1214 wait_for_property_change_unwind (loc) |
1068 Lisp_Object identifierval; | 1215 Lisp_Object loc; |
1069 { | 1216 { |
1070 unexpect_property_change ((struct prop_location *) | 1217 struct prop_location *location = XSAVE_VALUE (loc)->pointer; |
1071 (XFASTINT (XCAR (identifierval)) << 16 | 1218 |
1072 | XFASTINT (XCDR (identifierval)))); | 1219 unexpect_property_change (location); |
1220 if (location == property_change_reply_object) | |
1221 property_change_reply_object = 0; | |
1073 return Qnil; | 1222 return Qnil; |
1074 } | 1223 } |
1075 | 1224 |
1076 /* Actually wait for a property change. | 1225 /* Actually wait for a property change. |
1077 IDENTIFIER should be the value that expect_property_change returned. */ | 1226 IDENTIFIER should be the value that expect_property_change returned. */ |
1080 wait_for_property_change (location) | 1229 wait_for_property_change (location) |
1081 struct prop_location *location; | 1230 struct prop_location *location; |
1082 { | 1231 { |
1083 int secs, usecs; | 1232 int secs, usecs; |
1084 int count = SPECPDL_INDEX (); | 1233 int count = SPECPDL_INDEX (); |
1085 Lisp_Object tem; | 1234 |
1086 | 1235 if (property_change_reply_object) |
1087 tem = Fcons (Qnil, Qnil); | 1236 abort (); |
1088 XSETCARFASTINT (tem, (EMACS_UINT)location >> 16); | |
1089 XSETCDRFASTINT (tem, (EMACS_UINT)location & 0xffff); | |
1090 | 1237 |
1091 /* Make sure to do unexpect_property_change if we quit or err. */ | 1238 /* Make sure to do unexpect_property_change if we quit or err. */ |
1092 record_unwind_protect (wait_for_property_change_unwind, tem); | 1239 record_unwind_protect (wait_for_property_change_unwind, |
1240 make_save_value (location, 0)); | |
1093 | 1241 |
1094 XSETCAR (property_change_reply, Qnil); | 1242 XSETCAR (property_change_reply, Qnil); |
1095 | |
1096 property_change_reply_object = location; | 1243 property_change_reply_object = location; |
1244 | |
1097 /* If the event we are waiting for arrives beyond here, it will set | 1245 /* If the event we are waiting for arrives beyond here, it will set |
1098 property_change_reply, because property_change_reply_object says so. */ | 1246 property_change_reply, because property_change_reply_object says so. */ |
1099 if (! location->arrived) | 1247 if (! location->arrived) |
1100 { | 1248 { |
1101 secs = x_selection_timeout / 1000; | 1249 secs = x_selection_timeout / 1000; |
1102 usecs = (x_selection_timeout % 1000) * 1000; | 1250 usecs = (x_selection_timeout % 1000) * 1000; |
1103 TRACE2 (" Waiting %d secs, %d usecs", secs, usecs); | 1251 TRACE2 (" Waiting %d secs, %d usecs", secs, usecs); |
1104 wait_reading_process_input (secs, usecs, property_change_reply, 0); | 1252 wait_reading_process_output (secs, usecs, 0, 0, |
1253 property_change_reply, NULL, 0); | |
1105 | 1254 |
1106 if (NILP (XCAR (property_change_reply))) | 1255 if (NILP (XCAR (property_change_reply))) |
1107 { | 1256 { |
1108 TRACE0 (" Timed out"); | 1257 TRACE0 (" Timed out"); |
1109 error ("Timed out waiting for property-notify event"); | 1258 error ("Timed out waiting for property-notify event"); |
1121 { | 1270 { |
1122 struct prop_location *prev = 0, *rest = property_change_wait_list; | 1271 struct prop_location *prev = 0, *rest = property_change_wait_list; |
1123 | 1272 |
1124 while (rest) | 1273 while (rest) |
1125 { | 1274 { |
1126 if (rest->property == event->atom | 1275 if (!rest->arrived |
1276 && rest->property == event->atom | |
1127 && rest->window == event->window | 1277 && rest->window == event->window |
1128 && rest->display == event->display | 1278 && rest->display == event->display |
1129 && rest->desired_state == event->state) | 1279 && rest->desired_state == event->state) |
1130 { | 1280 { |
1131 TRACE2 ("Expected %s of property %s", | 1281 TRACE2 ("Expected %s of property %s", |
1137 /* If this is the one wait_for_property_change is waiting for, | 1287 /* If this is the one wait_for_property_change is waiting for, |
1138 tell it to wake up. */ | 1288 tell it to wake up. */ |
1139 if (rest == property_change_reply_object) | 1289 if (rest == property_change_reply_object) |
1140 XSETCAR (property_change_reply, Qt); | 1290 XSETCAR (property_change_reply, Qt); |
1141 | 1291 |
1142 if (prev) | |
1143 prev->next = rest->next; | |
1144 else | |
1145 property_change_wait_list = rest->next; | |
1146 xfree (rest); | |
1147 return; | 1292 return; |
1148 } | 1293 } |
1149 | 1294 |
1150 prev = rest; | 1295 prev = rest; |
1151 rest = rest->next; | 1296 rest = rest->next; |
1211 | 1356 |
1212 /* Do protocol to read selection-data from the server. | 1357 /* Do protocol to read selection-data from the server. |
1213 Converts this to Lisp data and returns it. */ | 1358 Converts this to Lisp data and returns it. */ |
1214 | 1359 |
1215 static Lisp_Object | 1360 static Lisp_Object |
1216 x_get_foreign_selection (selection_symbol, target_type) | 1361 x_get_foreign_selection (selection_symbol, target_type, time_stamp) |
1217 Lisp_Object selection_symbol, target_type; | 1362 Lisp_Object selection_symbol, target_type, time_stamp; |
1218 { | 1363 { |
1219 struct frame *sf = SELECTED_FRAME (); | 1364 struct frame *sf = SELECTED_FRAME (); |
1220 Window requestor_window = FRAME_X_WINDOW (sf); | 1365 Window requestor_window = FRAME_X_WINDOW (sf); |
1221 Display *display = FRAME_X_DISPLAY (sf); | 1366 Display *display = FRAME_X_DISPLAY (sf); |
1222 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (sf); | 1367 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (sf); |
1231 if (CONSP (target_type)) | 1376 if (CONSP (target_type)) |
1232 type_atom = symbol_to_x_atom (dpyinfo, display, XCAR (target_type)); | 1377 type_atom = symbol_to_x_atom (dpyinfo, display, XCAR (target_type)); |
1233 else | 1378 else |
1234 type_atom = symbol_to_x_atom (dpyinfo, display, target_type); | 1379 type_atom = symbol_to_x_atom (dpyinfo, display, target_type); |
1235 | 1380 |
1381 if (! NILP (time_stamp)) | |
1382 { | |
1383 if (CONSP (time_stamp)) | |
1384 requestor_time = (Time) cons_to_long (time_stamp); | |
1385 else if (INTEGERP (time_stamp)) | |
1386 requestor_time = (Time) XUINT (time_stamp); | |
1387 else if (FLOATP (time_stamp)) | |
1388 requestor_time = (Time) XFLOAT_DATA (time_stamp); | |
1389 else | |
1390 error ("TIME_STAMP must be cons or number"); | |
1391 } | |
1392 | |
1236 BLOCK_INPUT; | 1393 BLOCK_INPUT; |
1237 | 1394 |
1238 count = x_catch_errors (display); | 1395 count = x_catch_errors (display); |
1239 | 1396 |
1240 TRACE2 ("Get selection %s, type %s", | 1397 TRACE2 ("Get selection %s, type %s", |
1255 /* If the display no longer has frames, we can't expect | 1412 /* If the display no longer has frames, we can't expect |
1256 to get many more selection requests from it, so don't | 1413 to get many more selection requests from it, so don't |
1257 bother trying to queue them. */ | 1414 bother trying to queue them. */ |
1258 if (!NILP (frame)) | 1415 if (!NILP (frame)) |
1259 { | 1416 { |
1260 x_start_queuing_selection_requests (display); | 1417 x_start_queuing_selection_requests (); |
1261 | 1418 |
1262 record_unwind_protect (queue_selection_requests_unwind, | 1419 record_unwind_protect (queue_selection_requests_unwind, |
1263 frame); | 1420 Qnil); |
1264 } | 1421 } |
1265 UNBLOCK_INPUT; | 1422 UNBLOCK_INPUT; |
1266 | 1423 |
1267 /* This allows quits. Also, don't wait forever. */ | 1424 /* This allows quits. Also, don't wait forever. */ |
1268 secs = x_selection_timeout / 1000; | 1425 secs = x_selection_timeout / 1000; |
1269 usecs = (x_selection_timeout % 1000) * 1000; | 1426 usecs = (x_selection_timeout % 1000) * 1000; |
1270 TRACE1 (" Start waiting %d secs for SelectionNotify", secs); | 1427 TRACE1 (" Start waiting %d secs for SelectionNotify", secs); |
1271 wait_reading_process_input (secs, usecs, reading_selection_reply, 0); | 1428 wait_reading_process_output (secs, usecs, 0, 0, |
1429 reading_selection_reply, NULL, 0); | |
1272 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply))); | 1430 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply))); |
1273 | 1431 |
1274 BLOCK_INPUT; | 1432 BLOCK_INPUT; |
1275 x_check_errors (display, "Cannot get selection: %s"); | 1433 x_check_errors (display, "Cannot get selection: %s"); |
1276 x_uncatch_errors (display, count); | 1434 x_uncatch_errors (display, count); |
1365 /* If this doesn't return Success at this point, it means that | 1523 /* If this doesn't return Success at this point, it means that |
1366 some clod deleted the selection while we were in the midst of | 1524 some clod deleted the selection while we were in the midst of |
1367 reading it. Deal with that, I guess.... */ | 1525 reading it. Deal with that, I guess.... */ |
1368 if (result != Success) | 1526 if (result != Success) |
1369 break; | 1527 break; |
1370 *actual_size_ret *= *actual_format_ret / 8; | 1528 |
1371 bcopy (tmp_data, (*data_ret) + offset, *actual_size_ret); | 1529 /* The man page for XGetWindowProperty says: |
1372 offset += *actual_size_ret; | 1530 "If the returned format is 32, the returned data is represented |
1531 as a long array and should be cast to that type to obtain the | |
1532 elements." | |
1533 This applies even if long is more than 32 bits, the X library | |
1534 converts from 32 bit elements received from the X server to long | |
1535 and passes the long array to us. Thus, for that case bcopy can not | |
1536 be used. We convert to a 32 bit type here, because so much code | |
1537 assume on that. | |
1538 | |
1539 The bytes and offsets passed to XGetWindowProperty refers to the | |
1540 property and those are indeed in 32 bit quantities if format is 32. */ | |
1541 | |
1542 if (*actual_format_ret == 32 && *actual_format_ret < BITS_PER_LONG) | |
1543 { | |
1544 unsigned long i; | |
1545 int *idata = (int *) ((*data_ret) + offset); | |
1546 long *ldata = (long *) tmp_data; | |
1547 | |
1548 for (i = 0; i < *actual_size_ret; ++i) | |
1549 { | |
1550 idata[i]= (int) ldata[i]; | |
1551 offset += 4; | |
1552 } | |
1553 } | |
1554 else | |
1555 { | |
1556 *actual_size_ret *= *actual_format_ret / 8; | |
1557 bcopy (tmp_data, (*data_ret) + offset, *actual_size_ret); | |
1558 offset += *actual_size_ret; | |
1559 } | |
1373 | 1560 |
1374 /* This was allocated by Xlib, so use XFree. */ | 1561 /* This was allocated by Xlib, so use XFree. */ |
1375 XFree ((char *) tmp_data); | 1562 XFree ((char *) tmp_data); |
1376 } | 1563 } |
1377 | 1564 |
1413 We are done when the sender places a property of length 0. | 1600 We are done when the sender places a property of length 0. |
1414 */ | 1601 */ |
1415 BLOCK_INPUT; | 1602 BLOCK_INPUT; |
1416 XSelectInput (display, window, STANDARD_EVENT_SET | PropertyChangeMask); | 1603 XSelectInput (display, window, STANDARD_EVENT_SET | PropertyChangeMask); |
1417 TRACE1 (" Delete property %s", | 1604 TRACE1 (" Delete property %s", |
1418 XSYMBOL (x_atom_to_symbol (display, property))->name->data); | 1605 SDATA (SYMBOL_NAME (x_atom_to_symbol (display, property)))); |
1419 XDeleteProperty (display, window, property); | 1606 XDeleteProperty (display, window, property); |
1420 TRACE1 (" Expect new value of property %s", | 1607 TRACE1 (" Expect new value of property %s", |
1421 XSYMBOL (x_atom_to_symbol (display, property))->name->data); | 1608 SDATA (SYMBOL_NAME (x_atom_to_symbol (display, property)))); |
1422 wait_object = expect_property_change (display, window, property, | 1609 wait_object = expect_property_change (display, window, property, |
1423 PropertyNewValue); | 1610 PropertyNewValue); |
1424 XFlush (display); | 1611 XFlush (display); |
1425 UNBLOCK_INPUT; | 1612 UNBLOCK_INPUT; |
1426 | 1613 |
1446 { | 1633 { |
1447 TRACE0 ("Done reading incrementally"); | 1634 TRACE0 ("Done reading incrementally"); |
1448 | 1635 |
1449 if (! waiting_for_other_props_on_window (display, window)) | 1636 if (! waiting_for_other_props_on_window (display, window)) |
1450 XSelectInput (display, window, STANDARD_EVENT_SET); | 1637 XSelectInput (display, window, STANDARD_EVENT_SET); |
1451 unexpect_property_change (wait_object); | |
1452 /* Use xfree, not XFree, because x_get_window_property | 1638 /* Use xfree, not XFree, because x_get_window_property |
1453 calls xmalloc itself. */ | 1639 calls xmalloc itself. */ |
1454 if (tmp_data) xfree (tmp_data); | 1640 if (tmp_data) xfree (tmp_data); |
1455 break; | 1641 break; |
1456 } | 1642 } |
1581 of format 16 if every element in the vector is an integer, and is assumed | 1767 of format 16 if every element in the vector is an integer, and is assumed |
1582 to be of format 32 if any element is a cons of two integers. | 1768 to be of format 32 if any element is a cons of two integers. |
1583 | 1769 |
1584 When converting an object to C, it may be of the form (SYMBOL . <data>) | 1770 When converting an object to C, it may be of the form (SYMBOL . <data>) |
1585 where SYMBOL is what we should claim that the type is. Format and | 1771 where SYMBOL is what we should claim that the type is. Format and |
1586 representation are as above. */ | 1772 representation are as above. |
1773 | |
1774 Important: When format is 32, data should contain an array of int, | |
1775 not an array of long as the X library returns. This makes a difference | |
1776 when sizeof(long) != sizeof(int). */ | |
1587 | 1777 |
1588 | 1778 |
1589 | 1779 |
1590 static Lisp_Object | 1780 static Lisp_Object |
1591 selection_data_to_lisp_data (display, data, size, type, format) | 1781 selection_data_to_lisp_data (display, data, size, type, format) |
1600 return QNULL; | 1790 return QNULL; |
1601 | 1791 |
1602 /* Convert any 8-bit data to a string, for compactness. */ | 1792 /* Convert any 8-bit data to a string, for compactness. */ |
1603 else if (format == 8) | 1793 else if (format == 8) |
1604 { | 1794 { |
1605 Lisp_Object str; | 1795 Lisp_Object str, lispy_type; |
1606 int require_encoding = 0; | 1796 |
1607 | 1797 str = make_unibyte_string ((char *) data, size); |
1608 if ( | 1798 /* Indicate that this string is from foreign selection by a text |
1609 #if 1 | 1799 property `foreign-selection' so that the caller of |
1610 1 | 1800 x-get-selection-internal (usually x-get-selection) can know |
1611 #else | 1801 that the string must be decode. */ |
1612 ! NILP (buffer_defaults.enable_multibyte_characters) | 1802 if (type == dpyinfo->Xatom_COMPOUND_TEXT) |
1613 #endif | 1803 lispy_type = QCOMPOUND_TEXT; |
1614 ) | 1804 else if (type == dpyinfo->Xatom_UTF8_STRING) |
1615 { | 1805 lispy_type = QUTF8_STRING; |
1616 /* If TYPE is `TEXT' or `COMPOUND_TEXT', we should decode | |
1617 DATA to Emacs internal format because DATA may be encoded | |
1618 in compound text format. In addtion, if TYPE is `STRING' | |
1619 and DATA contains any 8-bit Latin-1 code, we should also | |
1620 decode it. */ | |
1621 if (type == dpyinfo->Xatom_TEXT | |
1622 || type == dpyinfo->Xatom_COMPOUND_TEXT) | |
1623 require_encoding = 1; | |
1624 else if (type == XA_STRING) | |
1625 { | |
1626 int i; | |
1627 for (i = 0; i < size; i++) | |
1628 { | |
1629 if (data[i] >= 0x80) | |
1630 { | |
1631 require_encoding = 1; | |
1632 break; | |
1633 } | |
1634 } | |
1635 } | |
1636 } | |
1637 if (!require_encoding) | |
1638 { | |
1639 str = make_unibyte_string ((char *) data, size); | |
1640 Vlast_coding_system_used = Qraw_text; | |
1641 } | |
1642 else | 1806 else |
1643 { | 1807 lispy_type = QSTRING; |
1644 int bufsize; | 1808 Fput_text_property (make_number (0), make_number (size), |
1645 unsigned char *buf; | 1809 Qforeign_selection, lispy_type, str); |
1646 struct coding_system coding; | |
1647 | |
1648 if (NILP (Vnext_selection_coding_system)) | |
1649 Vnext_selection_coding_system = Vselection_coding_system; | |
1650 setup_coding_system | |
1651 (Fcheck_coding_system(Vnext_selection_coding_system), &coding); | |
1652 coding.src_multibyte = 0; | |
1653 coding.dst_multibyte = 1; | |
1654 Vnext_selection_coding_system = Qnil; | |
1655 coding.mode |= CODING_MODE_LAST_BLOCK; | |
1656 /* We explicitely disable composition handling because | |
1657 selection data should not contain any composition | |
1658 sequence. */ | |
1659 coding.composing = COMPOSITION_DISABLED; | |
1660 bufsize = decoding_buffer_size (&coding, size); | |
1661 buf = (unsigned char *) xmalloc (bufsize); | |
1662 decode_coding (&coding, data, buf, size, bufsize); | |
1663 str = make_string_from_bytes ((char *) buf, | |
1664 coding.produced_char, coding.produced); | |
1665 xfree (buf); | |
1666 | |
1667 if (SYMBOLP (coding.post_read_conversion) | |
1668 && !NILP (Ffboundp (coding.post_read_conversion))) | |
1669 str = run_pre_post_conversion_on_str (str, &coding, 0); | |
1670 Vlast_coding_system_used = coding.symbol; | |
1671 } | |
1672 compose_chars_in_text (0, SCHARS (str), str); | |
1673 return str; | 1810 return str; |
1674 } | 1811 } |
1675 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to | 1812 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to |
1676 a vector of symbols. | 1813 a vector of symbols. |
1677 */ | 1814 */ |
1678 else if (type == XA_ATOM) | 1815 else if (type == XA_ATOM) |
1679 { | 1816 { |
1680 int i; | 1817 int i; |
1681 if (size == sizeof (Atom)) | 1818 /* On a 64 bit machine sizeof(Atom) == sizeof(long) == 8. |
1682 return x_atom_to_symbol (display, *((Atom *) data)); | 1819 But the callers of these function has made sure the data for |
1820 format == 32 is an array of int. Thus, use int instead | |
1821 of Atom. */ | |
1822 int *idata = (int *) data; | |
1823 | |
1824 if (size == sizeof (int)) | |
1825 return x_atom_to_symbol (display, (Atom) idata[0]); | |
1683 else | 1826 else |
1684 { | 1827 { |
1685 Lisp_Object v = Fmake_vector (make_number (size / sizeof (Atom)), | 1828 Lisp_Object v = Fmake_vector (make_number (size / sizeof (int)), |
1686 make_number (0)); | 1829 make_number (0)); |
1687 for (i = 0; i < size / sizeof (Atom); i++) | 1830 for (i = 0; i < size / sizeof (int); i++) |
1688 Faset (v, make_number (i), | 1831 Faset (v, make_number (i), |
1689 x_atom_to_symbol (display, ((Atom *) data) [i])); | 1832 x_atom_to_symbol (display, (Atom) idata[i])); |
1690 return v; | 1833 return v; |
1691 } | 1834 } |
1692 } | 1835 } |
1693 | 1836 |
1694 /* Convert a single 16 or small 32 bit number to a Lisp_Int. | 1837 /* Convert a single 16 or small 32 bit number to a Lisp_Int. |
1695 If the number is > 16 bits, convert it to a cons of integers, | 1838 If the number is > 16 bits, convert it to a cons of integers, |
1696 16 bits in each half. | 1839 16 bits in each half. |
1697 */ | 1840 */ |
1698 else if (format == 32 && size == sizeof (long)) | 1841 else if (format == 32 && size == sizeof (int)) |
1699 return long_to_cons (((unsigned long *) data) [0]); | 1842 return long_to_cons (((unsigned int *) data) [0]); |
1700 else if (format == 16 && size == sizeof (short)) | 1843 else if (format == 16 && size == sizeof (short)) |
1701 return make_number ((int) (((unsigned short *) data) [0])); | 1844 return make_number ((int) (((unsigned short *) data) [0])); |
1702 | 1845 |
1703 /* Convert any other kind of data to a vector of numbers, represented | 1846 /* Convert any other kind of data to a vector of numbers, represented |
1704 as above (as an integer, or a cons of two 16 bit integers.) | 1847 as above (as an integer, or a cons of two 16 bit integers.) |
1719 { | 1862 { |
1720 int i; | 1863 int i; |
1721 Lisp_Object v = Fmake_vector (make_number (size / 4), make_number (0)); | 1864 Lisp_Object v = Fmake_vector (make_number (size / 4), make_number (0)); |
1722 for (i = 0; i < size / 4; i++) | 1865 for (i = 0; i < size / 4; i++) |
1723 { | 1866 { |
1724 unsigned long j = ((unsigned long *) data) [i]; | 1867 unsigned int j = ((unsigned int *) data) [i]; |
1725 Faset (v, make_number (i), long_to_cons (j)); | 1868 Faset (v, make_number (i), long_to_cons (j)); |
1726 } | 1869 } |
1727 return v; | 1870 return v; |
1728 } | 1871 } |
1729 } | 1872 } |
1763 *data_ret = 0; | 1906 *data_ret = 0; |
1764 type = QNULL; | 1907 type = QNULL; |
1765 } | 1908 } |
1766 else if (STRINGP (obj)) | 1909 else if (STRINGP (obj)) |
1767 { | 1910 { |
1768 xassert (! STRING_MULTIBYTE (obj)); | 1911 if (SCHARS (obj) < SBYTES (obj)) |
1912 /* OBJ is a multibyte string containing a non-ASCII char. */ | |
1913 Fsignal (Qerror, /* Qselection_error */ | |
1914 Fcons (build_string | |
1915 ("Non-ASCII string must be encoded in advance"), | |
1916 Fcons (obj, Qnil))); | |
1769 if (NILP (type)) | 1917 if (NILP (type)) |
1770 type = QSTRING; | 1918 type = QSTRING; |
1771 *format_ret = 8; | 1919 *format_ret = 8; |
1772 *size_ret = SBYTES (obj); | 1920 *size_ret = SBYTES (obj); |
1773 *data_ret = SDATA (obj); | 1921 *data_ret = SDATA (obj); |
1866 } | 2014 } |
1867 #endif | 2015 #endif |
1868 else | 2016 else |
1869 /* This vector is an INTEGER set, or something like it */ | 2017 /* This vector is an INTEGER set, or something like it */ |
1870 { | 2018 { |
2019 int data_size = 2; | |
1871 *size_ret = XVECTOR (obj)->size; | 2020 *size_ret = XVECTOR (obj)->size; |
1872 if (NILP (type)) type = QINTEGER; | 2021 if (NILP (type)) type = QINTEGER; |
1873 *format_ret = 16; | 2022 *format_ret = 16; |
1874 for (i = 0; i < *size_ret; i++) | 2023 for (i = 0; i < *size_ret; i++) |
1875 if (CONSP (XVECTOR (obj)->contents [i])) | 2024 if (CONSP (XVECTOR (obj)->contents [i])) |
1878 Fsignal (Qerror, /* Qselection_error */ | 2027 Fsignal (Qerror, /* Qselection_error */ |
1879 Fcons (build_string | 2028 Fcons (build_string |
1880 ("elements of selection vector must be integers or conses of integers"), | 2029 ("elements of selection vector must be integers or conses of integers"), |
1881 Fcons (obj, Qnil))); | 2030 Fcons (obj, Qnil))); |
1882 | 2031 |
1883 *data_ret = (unsigned char *) xmalloc (*size_ret * (*format_ret/8)); | 2032 /* Use sizeof(long) even if it is more than 32 bits. See comment |
2033 in x_get_window_property and x_fill_property_data. */ | |
2034 | |
2035 if (*format_ret == 32) data_size = sizeof(long); | |
2036 *data_ret = (unsigned char *) xmalloc (*size_ret * data_size); | |
1884 for (i = 0; i < *size_ret; i++) | 2037 for (i = 0; i < *size_ret; i++) |
1885 if (*format_ret == 32) | 2038 if (*format_ret == 32) |
1886 (*((unsigned long **) data_ret)) [i] | 2039 (*((unsigned long **) data_ret)) [i] |
1887 = cons_to_long (XVECTOR (obj)->contents [i]); | 2040 = cons_to_long (XVECTOR (obj)->contents [i]); |
1888 else | 2041 else |
1890 = (unsigned short) cons_to_long (XVECTOR (obj)->contents [i]); | 2043 = (unsigned short) cons_to_long (XVECTOR (obj)->contents [i]); |
1891 } | 2044 } |
1892 } | 2045 } |
1893 else | 2046 else |
1894 Fsignal (Qerror, /* Qselection_error */ | 2047 Fsignal (Qerror, /* Qselection_error */ |
1895 Fcons (build_string ("unrecognised selection data"), | 2048 Fcons (build_string ("unrecognized selection data"), |
1896 Fcons (obj, Qnil))); | 2049 Fcons (obj, Qnil))); |
1897 | 2050 |
1898 *type_ret = symbol_to_x_atom (dpyinfo, display, type); | 2051 *type_ret = symbol_to_x_atom (dpyinfo, display, type); |
1899 } | 2052 } |
1900 | 2053 |
1964 (selection_name, selection_value) | 2117 (selection_name, selection_value) |
1965 Lisp_Object selection_name, selection_value; | 2118 Lisp_Object selection_name, selection_value; |
1966 { | 2119 { |
1967 check_x (); | 2120 check_x (); |
1968 CHECK_SYMBOL (selection_name); | 2121 CHECK_SYMBOL (selection_name); |
1969 if (NILP (selection_value)) error ("selection-value may not be nil"); | 2122 if (NILP (selection_value)) error ("SELECTION-VALUE may not be nil"); |
1970 x_own_selection (selection_name, selection_value); | 2123 x_own_selection (selection_name, selection_value); |
1971 return selection_value; | 2124 return selection_value; |
1972 } | 2125 } |
1973 | 2126 |
1974 | 2127 |
1975 /* Request the selection value from the owner. If we are the owner, | 2128 /* Request the selection value from the owner. If we are the owner, |
1976 simply return our selection value. If we are not the owner, this | 2129 simply return our selection value. If we are not the owner, this |
1977 will block until all of the data has arrived. */ | 2130 will block until all of the data has arrived. */ |
1978 | 2131 |
1979 DEFUN ("x-get-selection-internal", Fx_get_selection_internal, | 2132 DEFUN ("x-get-selection-internal", Fx_get_selection_internal, |
1980 Sx_get_selection_internal, 2, 2, 0, | 2133 Sx_get_selection_internal, 2, 3, 0, |
1981 doc: /* Return text selected from some X window. | 2134 doc: /* Return text selected from some X window. |
1982 SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. | 2135 SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. |
1983 \(Those are literal upper-case symbol names, since that's what X expects.) | 2136 \(Those are literal upper-case symbol names, since that's what X expects.) |
1984 TYPE is the type of data desired, typically `STRING'. */) | 2137 TYPE is the type of data desired, typically `STRING'. |
1985 (selection_symbol, target_type) | 2138 TIME_STAMP is the time to use in the XConvertSelection call for foreign |
1986 Lisp_Object selection_symbol, target_type; | 2139 selections. If omitted, defaults to the time for the last event. */) |
2140 (selection_symbol, target_type, time_stamp) | |
2141 Lisp_Object selection_symbol, target_type, time_stamp; | |
1987 { | 2142 { |
1988 Lisp_Object val = Qnil; | 2143 Lisp_Object val = Qnil; |
1989 struct gcpro gcpro1, gcpro2; | 2144 struct gcpro gcpro1, gcpro2; |
1990 GCPRO2 (target_type, val); /* we store newly consed data into these */ | 2145 GCPRO2 (target_type, val); /* we store newly consed data into these */ |
1991 check_x (); | 2146 check_x (); |
2005 | 2160 |
2006 val = x_get_local_selection (selection_symbol, target_type, 1); | 2161 val = x_get_local_selection (selection_symbol, target_type, 1); |
2007 | 2162 |
2008 if (NILP (val)) | 2163 if (NILP (val)) |
2009 { | 2164 { |
2010 val = x_get_foreign_selection (selection_symbol, target_type); | 2165 val = x_get_foreign_selection (selection_symbol, target_type, time_stamp); |
2011 goto DONE; | 2166 goto DONE; |
2012 } | 2167 } |
2013 | 2168 |
2014 if (CONSP (val) | 2169 if (CONSP (val) |
2015 && SYMBOLP (XCAR (val))) | 2170 && SYMBOLP (XCAR (val))) |
2032 Lisp_Object selection; | 2187 Lisp_Object selection; |
2033 Lisp_Object time; | 2188 Lisp_Object time; |
2034 { | 2189 { |
2035 Time timestamp; | 2190 Time timestamp; |
2036 Atom selection_atom; | 2191 Atom selection_atom; |
2037 struct selection_input_event event; | 2192 union { |
2193 struct selection_input_event sie; | |
2194 struct input_event ie; | |
2195 } event; | |
2038 Display *display; | 2196 Display *display; |
2039 struct x_display_info *dpyinfo; | 2197 struct x_display_info *dpyinfo; |
2040 struct frame *sf = SELECTED_FRAME (); | 2198 struct frame *sf = SELECTED_FRAME (); |
2041 | 2199 |
2042 check_x (); | 2200 check_x (); |
2060 /* It doesn't seem to be guaranteed that a SelectionClear event will be | 2218 /* It doesn't seem to be guaranteed that a SelectionClear event will be |
2061 generated for a window which owns the selection when that window sets | 2219 generated for a window which owns the selection when that window sets |
2062 the selection owner to None. The NCD server does, the MIT Sun4 server | 2220 the selection owner to None. The NCD server does, the MIT Sun4 server |
2063 doesn't. So we synthesize one; this means we might get two, but | 2221 doesn't. So we synthesize one; this means we might get two, but |
2064 that's ok, because the second one won't have any effect. */ | 2222 that's ok, because the second one won't have any effect. */ |
2065 SELECTION_EVENT_DISPLAY (&event) = display; | 2223 SELECTION_EVENT_DISPLAY (&event.sie) = display; |
2066 SELECTION_EVENT_SELECTION (&event) = selection_atom; | 2224 SELECTION_EVENT_SELECTION (&event.sie) = selection_atom; |
2067 SELECTION_EVENT_TIME (&event) = timestamp; | 2225 SELECTION_EVENT_TIME (&event.sie) = timestamp; |
2068 x_handle_selection_clear ((struct input_event *) &event); | 2226 x_handle_selection_clear (&event.ie); |
2069 | 2227 |
2070 return Qt; | 2228 return Qt; |
2071 } | 2229 } |
2072 | 2230 |
2073 /* Get rid of all the selections in buffer BUFFER. | 2231 /* Get rid of all the selections in buffer BUFFER. |
2218 Fsignal (Qerror, | 2376 Fsignal (Qerror, |
2219 Fcons (build_string ("cut buffer doesn't contain 8-bit data"), | 2377 Fcons (build_string ("cut buffer doesn't contain 8-bit data"), |
2220 Fcons (x_atom_to_symbol (display, type), | 2378 Fcons (x_atom_to_symbol (display, type), |
2221 Fcons (make_number (format), Qnil)))); | 2379 Fcons (make_number (format), Qnil)))); |
2222 | 2380 |
2223 ret = (bytes ? make_string ((char *) data, bytes) : Qnil); | 2381 ret = (bytes ? make_unibyte_string ((char *) data, bytes) : Qnil); |
2224 /* Use xfree, not XFree, because x_get_window_property | 2382 /* Use xfree, not XFree, because x_get_window_property |
2225 calls xmalloc itself. */ | 2383 calls xmalloc itself. */ |
2226 xfree (data); | 2384 xfree (data); |
2227 return ret; | 2385 return ret; |
2228 } | 2386 } |
2327 return n; | 2485 return n; |
2328 } | 2486 } |
2329 | 2487 |
2330 #endif | 2488 #endif |
2331 | 2489 |
2490 /*********************************************************************** | |
2491 Drag and drop support | |
2492 ***********************************************************************/ | |
2493 /* Check that lisp values are of correct type for x_fill_property_data. | |
2494 That is, number, string or a cons with two numbers (low and high 16 | |
2495 bit parts of a 32 bit number). */ | |
2496 | |
2497 int | |
2498 x_check_property_data (data) | |
2499 Lisp_Object data; | |
2500 { | |
2501 Lisp_Object iter; | |
2502 int size = 0; | |
2503 | |
2504 for (iter = data; CONSP (iter) && size != -1; iter = XCDR (iter), ++size) | |
2505 { | |
2506 Lisp_Object o = XCAR (iter); | |
2507 | |
2508 if (! NUMBERP (o) && ! STRINGP (o) && ! CONSP (o)) | |
2509 size = -1; | |
2510 else if (CONSP (o) && | |
2511 (! NUMBERP (XCAR (o)) || ! NUMBERP (XCDR (o)))) | |
2512 size = -1; | |
2513 } | |
2514 | |
2515 return size; | |
2516 } | |
2517 | |
2518 /* Convert lisp values to a C array. Values may be a number, a string | |
2519 which is taken as an X atom name and converted to the atom value, or | |
2520 a cons containing the two 16 bit parts of a 32 bit number. | |
2521 | |
2522 DPY is the display use to look up X atoms. | |
2523 DATA is a Lisp list of values to be converted. | |
2524 RET is the C array that contains the converted values. It is assumed | |
2525 it is big enough to hold all values. | |
2526 FORMAT is 8, 16 or 32 and denotes char/short/long for each C value to | |
2527 be stored in RET. Note that long is used for 32 even if long is more | |
2528 than 32 bits (see man pages for XChangeProperty, XGetWindowProperty and | |
2529 XClientMessageEvent). */ | |
2530 | |
2531 void | |
2532 x_fill_property_data (dpy, data, ret, format) | |
2533 Display *dpy; | |
2534 Lisp_Object data; | |
2535 void *ret; | |
2536 int format; | |
2537 { | |
2538 long val; | |
2539 long *d32 = (long *) ret; | |
2540 short *d16 = (short *) ret; | |
2541 char *d08 = (char *) ret; | |
2542 Lisp_Object iter; | |
2543 | |
2544 for (iter = data; CONSP (iter); iter = XCDR (iter)) | |
2545 { | |
2546 Lisp_Object o = XCAR (iter); | |
2547 | |
2548 if (INTEGERP (o)) | |
2549 val = (long) XFASTINT (o); | |
2550 else if (FLOATP (o)) | |
2551 val = (long) XFLOAT_DATA (o); | |
2552 else if (CONSP (o)) | |
2553 val = (long) cons_to_long (o); | |
2554 else if (STRINGP (o)) | |
2555 { | |
2556 BLOCK_INPUT; | |
2557 val = (long) XInternAtom (dpy, (char *) SDATA (o), False); | |
2558 UNBLOCK_INPUT; | |
2559 } | |
2560 else | |
2561 error ("Wrong type, must be string, number or cons"); | |
2562 | |
2563 if (format == 8) | |
2564 *d08++ = (char) val; | |
2565 else if (format == 16) | |
2566 *d16++ = (short) val; | |
2567 else | |
2568 *d32++ = val; | |
2569 } | |
2570 } | |
2571 | |
2572 /* Convert an array of C values to a Lisp list. | |
2573 F is the frame to be used to look up X atoms if the TYPE is XA_ATOM. | |
2574 DATA is a C array of values to be converted. | |
2575 TYPE is the type of the data. Only XA_ATOM is special, it converts | |
2576 each number in DATA to its corresponfing X atom as a symbol. | |
2577 FORMAT is 8, 16 or 32 and gives the size in bits for each C value to | |
2578 be stored in RET. | |
2579 SIZE is the number of elements in DATA. | |
2580 | |
2581 Important: When format is 32, data should contain an array of int, | |
2582 not an array of long as the X library returns. This makes a difference | |
2583 when sizeof(long) != sizeof(int). | |
2584 | |
2585 Also see comment for selection_data_to_lisp_data above. */ | |
2586 | |
2587 Lisp_Object | |
2588 x_property_data_to_lisp (f, data, type, format, size) | |
2589 struct frame *f; | |
2590 unsigned char *data; | |
2591 Atom type; | |
2592 int format; | |
2593 unsigned long size; | |
2594 { | |
2595 return selection_data_to_lisp_data (FRAME_X_DISPLAY (f), | |
2596 data, size*format/8, type, format); | |
2597 } | |
2598 | |
2599 /* Get the mouse position in frame relative coordinates. */ | |
2600 | |
2601 static void | |
2602 mouse_position_for_drop (f, x, y) | |
2603 FRAME_PTR f; | |
2604 int *x; | |
2605 int *y; | |
2606 { | |
2607 Window root, dummy_window; | |
2608 int dummy; | |
2609 | |
2610 BLOCK_INPUT; | |
2611 | |
2612 XQueryPointer (FRAME_X_DISPLAY (f), | |
2613 DefaultRootWindow (FRAME_X_DISPLAY (f)), | |
2614 | |
2615 /* The root window which contains the pointer. */ | |
2616 &root, | |
2617 | |
2618 /* Window pointer is on, not used */ | |
2619 &dummy_window, | |
2620 | |
2621 /* The position on that root window. */ | |
2622 x, y, | |
2623 | |
2624 /* x/y in dummy_window coordinates, not used. */ | |
2625 &dummy, &dummy, | |
2626 | |
2627 /* Modifier keys and pointer buttons, about which | |
2628 we don't care. */ | |
2629 (unsigned int *) &dummy); | |
2630 | |
2631 | |
2632 /* Absolute to relative. */ | |
2633 *x -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); | |
2634 *y -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); | |
2635 | |
2636 UNBLOCK_INPUT; | |
2637 } | |
2638 | |
2639 DEFUN ("x-get-atom-name", Fx_get_atom_name, | |
2640 Sx_get_atom_name, 1, 2, 0, | |
2641 doc: /* Return the X atom name for VALUE as a string. | |
2642 VALUE may be a number or a cons where the car is the upper 16 bits and | |
2643 the cdr is the lower 16 bits of a 32 bit value. | |
2644 Use the display for FRAME or the current frame if FRAME is not given or nil. | |
2645 | |
2646 If the value is 0 or the atom is not known, return the empty string. */) | |
2647 (value, frame) | |
2648 Lisp_Object value, frame; | |
2649 { | |
2650 struct frame *f = check_x_frame (frame); | |
2651 char *name = 0; | |
2652 Lisp_Object ret = Qnil; | |
2653 int count; | |
2654 Display *dpy = FRAME_X_DISPLAY (f); | |
2655 Atom atom; | |
2656 | |
2657 if (INTEGERP (value)) | |
2658 atom = (Atom) XUINT (value); | |
2659 else if (FLOATP (value)) | |
2660 atom = (Atom) XFLOAT_DATA (value); | |
2661 else if (CONSP (value)) | |
2662 atom = (Atom) cons_to_long (value); | |
2663 else | |
2664 error ("Wrong type, value must be number or cons"); | |
2665 | |
2666 BLOCK_INPUT; | |
2667 count = x_catch_errors (dpy); | |
2668 | |
2669 name = atom ? XGetAtomName (dpy, atom) : ""; | |
2670 | |
2671 if (! x_had_errors_p (dpy)) | |
2672 ret = make_string (name, strlen (name)); | |
2673 | |
2674 x_uncatch_errors (dpy, count); | |
2675 | |
2676 if (atom && name) XFree (name); | |
2677 if (NILP (ret)) ret = make_string ("", 0); | |
2678 | |
2679 UNBLOCK_INPUT; | |
2680 | |
2681 return ret; | |
2682 } | |
2683 | |
2684 /* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT. | |
2685 TODO: Check if this client event really is a DND event? */ | |
2686 | |
2687 int | |
2688 x_handle_dnd_message (f, event, dpyinfo, bufp) | |
2689 struct frame *f; | |
2690 XClientMessageEvent *event; | |
2691 struct x_display_info *dpyinfo; | |
2692 struct input_event *bufp; | |
2693 { | |
2694 Lisp_Object vec; | |
2695 Lisp_Object frame; | |
2696 /* format 32 => size 5, format 16 => size 10, format 8 => size 20 */ | |
2697 unsigned long size = 160/event->format; | |
2698 int x, y; | |
2699 unsigned char *data = (unsigned char *) event->data.b; | |
2700 int idata[5]; | |
2701 | |
2702 XSETFRAME (frame, f); | |
2703 | |
2704 /* On a 64 bit machine, the event->data.l array members are 64 bits (long), | |
2705 but the x_property_data_to_lisp (or rather selection_data_to_lisp_data) | |
2706 function expects them to be of size int (i.e. 32). So to be able to | |
2707 use that function, put the data in the form it expects if format is 32. */ | |
2708 | |
2709 if (event->format == 32 && event->format < BITS_PER_LONG) | |
2710 { | |
2711 int i; | |
2712 for (i = 0; i < 5; ++i) /* There are only 5 longs in a ClientMessage. */ | |
2713 idata[i] = (int) event->data.l[i]; | |
2714 data = (unsigned char *) idata; | |
2715 } | |
2716 | |
2717 vec = Fmake_vector (make_number (4), Qnil); | |
2718 AREF (vec, 0) = SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f), | |
2719 event->message_type)); | |
2720 AREF (vec, 1) = frame; | |
2721 AREF (vec, 2) = make_number (event->format); | |
2722 AREF (vec, 3) = x_property_data_to_lisp (f, | |
2723 data, | |
2724 event->message_type, | |
2725 event->format, | |
2726 size); | |
2727 | |
2728 mouse_position_for_drop (f, &x, &y); | |
2729 bufp->kind = DRAG_N_DROP_EVENT; | |
2730 bufp->frame_or_window = frame; | |
2731 bufp->timestamp = CurrentTime; | |
2732 bufp->x = make_number (x); | |
2733 bufp->y = make_number (y); | |
2734 bufp->arg = vec; | |
2735 bufp->modifiers = 0; | |
2736 | |
2737 return 1; | |
2738 } | |
2739 | |
2740 DEFUN ("x-send-client-message", Fx_send_client_event, | |
2741 Sx_send_client_message, 6, 6, 0, | |
2742 doc: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY. | |
2743 | |
2744 For DISPLAY, specify either a frame or a display name (a string). | |
2745 If DISPLAY is nil, that stands for the selected frame's display. | |
2746 DEST may be a number, in which case it is a Window id. The value 0 may | |
2747 be used to send to the root window of the DISPLAY. | |
2748 If DEST is a cons, it is converted to a 32 bit number | |
2749 with the high 16 bits from the car and the lower 16 bit from the cdr. That | |
2750 number is then used as a window id. | |
2751 If DEST is a frame the event is sent to the outer window of that frame. | |
2752 Nil means the currently selected frame. | |
2753 If DEST is the string "PointerWindow" the event is sent to the window that | |
2754 contains the pointer. If DEST is the string "InputFocus" the event is | |
2755 sent to the window that has the input focus. | |
2756 FROM is the frame sending the event. Use nil for currently selected frame. | |
2757 MESSAGE-TYPE is the name of an Atom as a string. | |
2758 FORMAT must be one of 8, 16 or 32 and determines the size of the values in | |
2759 bits. VALUES is a list of numbers, cons and/or strings containing the values | |
2760 to send. If a value is a string, it is converted to an Atom and the value of | |
2761 the Atom is sent. If a value is a cons, it is converted to a 32 bit number | |
2762 with the high 16 bits from the car and the lower 16 bit from the cdr. | |
2763 If more values than fits into the event is given, the excessive values | |
2764 are ignored. */) | |
2765 (display, dest, from, message_type, format, values) | |
2766 Lisp_Object display, dest, from, message_type, format, values; | |
2767 { | |
2768 struct x_display_info *dpyinfo = check_x_display_info (display); | |
2769 Window wdest; | |
2770 XEvent event; | |
2771 Lisp_Object cons; | |
2772 int size; | |
2773 struct frame *f = check_x_frame (from); | |
2774 int count; | |
2775 int to_root; | |
2776 | |
2777 CHECK_STRING (message_type); | |
2778 CHECK_NUMBER (format); | |
2779 CHECK_CONS (values); | |
2780 | |
2781 if (x_check_property_data (values) == -1) | |
2782 error ("Bad data in VALUES, must be number, cons or string"); | |
2783 | |
2784 event.xclient.type = ClientMessage; | |
2785 event.xclient.format = XFASTINT (format); | |
2786 | |
2787 if (event.xclient.format != 8 && event.xclient.format != 16 | |
2788 && event.xclient.format != 32) | |
2789 error ("FORMAT must be one of 8, 16 or 32"); | |
2790 | |
2791 if (FRAMEP (dest) || NILP (dest)) | |
2792 { | |
2793 struct frame *fdest = check_x_frame (dest); | |
2794 wdest = FRAME_OUTER_WINDOW (fdest); | |
2795 } | |
2796 else if (STRINGP (dest)) | |
2797 { | |
2798 if (strcmp (SDATA (dest), "PointerWindow") == 0) | |
2799 wdest = PointerWindow; | |
2800 else if (strcmp (SDATA (dest), "InputFocus") == 0) | |
2801 wdest = InputFocus; | |
2802 else | |
2803 error ("DEST as a string must be one of PointerWindow or InputFocus"); | |
2804 } | |
2805 else if (INTEGERP (dest)) | |
2806 wdest = (Window) XFASTINT (dest); | |
2807 else if (FLOATP (dest)) | |
2808 wdest = (Window) XFLOAT_DATA (dest); | |
2809 else if (CONSP (dest)) | |
2810 { | |
2811 if (! NUMBERP (XCAR (dest)) || ! NUMBERP (XCDR (dest))) | |
2812 error ("Both car and cdr for DEST must be numbers"); | |
2813 else | |
2814 wdest = (Window) cons_to_long (dest); | |
2815 } | |
2816 else | |
2817 error ("DEST must be a frame, nil, string, number or cons"); | |
2818 | |
2819 if (wdest == 0) wdest = dpyinfo->root_window; | |
2820 to_root = wdest == dpyinfo->root_window; | |
2821 | |
2822 for (cons = values, size = 0; CONSP (cons); cons = XCDR (cons), ++size) | |
2823 ; | |
2824 | |
2825 BLOCK_INPUT; | |
2826 | |
2827 event.xclient.message_type | |
2828 = XInternAtom (dpyinfo->display, SDATA (message_type), False); | |
2829 event.xclient.display = dpyinfo->display; | |
2830 | |
2831 /* Some clients (metacity for example) expects sending window to be here | |
2832 when sending to the root window. */ | |
2833 event.xclient.window = to_root ? FRAME_OUTER_WINDOW (f) : wdest; | |
2834 | |
2835 | |
2836 memset (event.xclient.data.b, 0, sizeof (event.xclient.data.b)); | |
2837 x_fill_property_data (dpyinfo->display, values, event.xclient.data.b, | |
2838 event.xclient.format); | |
2839 | |
2840 /* If event mask is 0 the event is sent to the client that created | |
2841 the destination window. But if we are sending to the root window, | |
2842 there is no such client. Then we set the event mask to 0xffff. The | |
2843 event then goes to clients selecting for events on the root window. */ | |
2844 count = x_catch_errors (dpyinfo->display); | |
2845 { | |
2846 int propagate = to_root ? False : True; | |
2847 unsigned mask = to_root ? 0xffff : 0; | |
2848 XSendEvent (dpyinfo->display, wdest, propagate, mask, &event); | |
2849 XFlush (dpyinfo->display); | |
2850 } | |
2851 x_uncatch_errors (dpyinfo->display, count); | |
2852 UNBLOCK_INPUT; | |
2853 | |
2854 return Qnil; | |
2855 } | |
2856 | |
2857 | |
2332 void | 2858 void |
2333 syms_of_xselect () | 2859 syms_of_xselect () |
2334 { | 2860 { |
2335 defsubr (&Sx_get_selection_internal); | 2861 defsubr (&Sx_get_selection_internal); |
2336 defsubr (&Sx_own_selection_internal); | 2862 defsubr (&Sx_own_selection_internal); |
2341 #ifdef CUT_BUFFER_SUPPORT | 2867 #ifdef CUT_BUFFER_SUPPORT |
2342 defsubr (&Sx_get_cut_buffer_internal); | 2868 defsubr (&Sx_get_cut_buffer_internal); |
2343 defsubr (&Sx_store_cut_buffer_internal); | 2869 defsubr (&Sx_store_cut_buffer_internal); |
2344 defsubr (&Sx_rotate_cut_buffers_internal); | 2870 defsubr (&Sx_rotate_cut_buffers_internal); |
2345 #endif | 2871 #endif |
2872 | |
2873 defsubr (&Sx_get_atom_name); | |
2874 defsubr (&Sx_send_client_message); | |
2346 | 2875 |
2347 reading_selection_reply = Fcons (Qnil, Qnil); | 2876 reading_selection_reply = Fcons (Qnil, Qnil); |
2348 staticpro (&reading_selection_reply); | 2877 staticpro (&reading_selection_reply); |
2349 reading_selection_window = 0; | 2878 reading_selection_window = 0; |
2350 reading_which_selection = 0; | 2879 reading_which_selection = 0; |
2370 A return value which is the symbol `NULL' | 2899 A return value which is the symbol `NULL' |
2371 means that a side-effect was executed, | 2900 means that a side-effect was executed, |
2372 and there is no meaningful selection value. */); | 2901 and there is no meaningful selection value. */); |
2373 Vselection_converter_alist = Qnil; | 2902 Vselection_converter_alist = Qnil; |
2374 | 2903 |
2375 DEFVAR_LISP ("x-lost-selection-hooks", &Vx_lost_selection_hooks, | 2904 DEFVAR_LISP ("x-lost-selection-functions", &Vx_lost_selection_functions, |
2376 doc: /* A list of functions to be called when Emacs loses an X selection. | 2905 doc: /* A list of functions to be called when Emacs loses an X selection. |
2377 \(This happens when some other X client makes its own selection | 2906 \(This happens when some other X client makes its own selection |
2378 or when a Lisp program explicitly clears the selection.) | 2907 or when a Lisp program explicitly clears the selection.) |
2379 The functions are called with one argument, the selection type | 2908 The functions are called with one argument, the selection type |
2380 \(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'). */); | 2909 \(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'). */); |
2381 Vx_lost_selection_hooks = Qnil; | 2910 Vx_lost_selection_functions = Qnil; |
2382 | 2911 |
2383 DEFVAR_LISP ("x-sent-selection-hooks", &Vx_sent_selection_hooks, | 2912 DEFVAR_LISP ("x-sent-selection-functions", &Vx_sent_selection_functions, |
2384 doc: /* A list of functions to be called when Emacs answers a selection request. | 2913 doc: /* A list of functions to be called when Emacs answers a selection request. |
2385 The functions are called with four arguments: | 2914 The functions are called with four arguments: |
2386 - the selection name (typically `PRIMARY', `SECONDARY', or `CLIPBOARD'); | 2915 - the selection name (typically `PRIMARY', `SECONDARY', or `CLIPBOARD'); |
2387 - the selection-type which Emacs was asked to convert the | 2916 - the selection-type which Emacs was asked to convert the |
2388 selection into before sending (for example, `STRING' or `LENGTH'); | 2917 selection into before sending (for example, `STRING' or `LENGTH'); |
2390 We might have failed (and declined the request) for any number of reasons, | 2919 We might have failed (and declined the request) for any number of reasons, |
2391 including being asked for a selection that we no longer own, or being asked | 2920 including being asked for a selection that we no longer own, or being asked |
2392 to convert into a type that we don't know about or that is inappropriate. | 2921 to convert into a type that we don't know about or that is inappropriate. |
2393 This hook doesn't let you change the behavior of Emacs's selection replies, | 2922 This hook doesn't let you change the behavior of Emacs's selection replies, |
2394 it merely informs you that they have happened. */); | 2923 it merely informs you that they have happened. */); |
2395 Vx_sent_selection_hooks = Qnil; | 2924 Vx_sent_selection_functions = Qnil; |
2396 | 2925 |
2397 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, | 2926 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, |
2398 doc: /* Coding system for communicating with other X clients. | 2927 doc: /* Coding system for communicating with other X clients. |
2399 When sending or receiving text via cut_buffer, selection, and clipboard, | 2928 When sending or receiving text via cut_buffer, selection, and clipboard, |
2400 the text is encoded or decoded by this coding system. | 2929 the text is encoded or decoded by this coding system. |
2423 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD); | 2952 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD); |
2424 QTIMESTAMP = intern ("TIMESTAMP"); staticpro (&QTIMESTAMP); | 2953 QTIMESTAMP = intern ("TIMESTAMP"); staticpro (&QTIMESTAMP); |
2425 QTEXT = intern ("TEXT"); staticpro (&QTEXT); | 2954 QTEXT = intern ("TEXT"); staticpro (&QTEXT); |
2426 QCOMPOUND_TEXT = intern ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT); | 2955 QCOMPOUND_TEXT = intern ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT); |
2427 QUTF8_STRING = intern ("UTF8_STRING"); staticpro (&QUTF8_STRING); | 2956 QUTF8_STRING = intern ("UTF8_STRING"); staticpro (&QUTF8_STRING); |
2428 QTIMESTAMP = intern ("TIMESTAMP"); staticpro (&QTIMESTAMP); | |
2429 QDELETE = intern ("DELETE"); staticpro (&QDELETE); | 2957 QDELETE = intern ("DELETE"); staticpro (&QDELETE); |
2430 QMULTIPLE = intern ("MULTIPLE"); staticpro (&QMULTIPLE); | 2958 QMULTIPLE = intern ("MULTIPLE"); staticpro (&QMULTIPLE); |
2431 QINCR = intern ("INCR"); staticpro (&QINCR); | 2959 QINCR = intern ("INCR"); staticpro (&QINCR); |
2432 QEMACS_TMP = intern ("_EMACS_TMP_"); staticpro (&QEMACS_TMP); | 2960 QEMACS_TMP = intern ("_EMACS_TMP_"); staticpro (&QEMACS_TMP); |
2433 QTARGETS = intern ("TARGETS"); staticpro (&QTARGETS); | 2961 QTARGETS = intern ("TARGETS"); staticpro (&QTARGETS); |
2446 QCUT_BUFFER5 = intern ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5); | 2974 QCUT_BUFFER5 = intern ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5); |
2447 QCUT_BUFFER6 = intern ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6); | 2975 QCUT_BUFFER6 = intern ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6); |
2448 QCUT_BUFFER7 = intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7); | 2976 QCUT_BUFFER7 = intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7); |
2449 #endif | 2977 #endif |
2450 | 2978 |
2451 } | 2979 Qforeign_selection = intern ("foreign-selection"); |
2980 staticpro (&Qforeign_selection); | |
2981 } | |
2982 | |
2983 /* arch-tag: 7c293b0f-9918-4f69-8ac7-03e142307236 | |
2984 (do not change this comment) */ |