comparison src/xselect.c @ 90103:3ebd9bdb4fe5

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-13 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-83 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-89 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-90 Update from CVS: man/calc.texi: Add macro for LaTeX for info output. * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-91 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-94 Update from CVS
author Miles Bader <miles@gnu.org>
date Sun, 13 Feb 2005 07:19:08 +0000
parents 72cf6261961e 22a410b2373b
children 7e3f621f1dd4
comparison
equal deleted inserted replaced
90102:9b4f359c4117 90103:3ebd9bdb4fe5
171 static Lisp_Object Vselection_converter_alist; 171 static Lisp_Object Vselection_converter_alist;
172 172
173 /* 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,
174 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.) */
175 static EMACS_INT x_selection_timeout; 175 static EMACS_INT x_selection_timeout;
176
177 /* Utility functions */
178
179 static void lisp_data_to_selection_data ();
180 static Lisp_Object selection_data_to_lisp_data ();
181 static Lisp_Object x_get_window_property_as_lisp_data ();
182 176
183 177
184 178
185 /* Define a queue to save up SELECTION_REQUEST_EVENT events for later 179 /* Define a queue to save up SELECTION_REQUEST_EVENT events for later
186 handling. */ 180 handling. */
767 wait_object = expect_property_change (display, window, reply.property, 761 wait_object = expect_property_change (display, window, reply.property,
768 PropertyDelete); 762 PropertyDelete);
769 763
770 TRACE1 ("Set %s to number of bytes to send", 764 TRACE1 ("Set %s to number of bytes to send",
771 XGetAtomName (display, reply.property)); 765 XGetAtomName (display, reply.property));
772 XChangeProperty (display, window, reply.property, dpyinfo->Xatom_INCR, 766 {
773 32, PropModeReplace, 767 /* XChangeProperty expects an array of long even if long is more than
774 (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
775 XSelectInput (display, window, PropertyChangeMask); 777 XSelectInput (display, window, PropertyChangeMask);
776 778
777 /* Tell 'em the INCR data is there... */ 779 /* Tell 'em the INCR data is there... */
778 TRACE0 ("Send SelectionNotify event"); 780 TRACE0 ("Send SelectionNotify event");
779 XSendEvent (display, window, False, 0L, (XEvent *) &reply); 781 XSendEvent (display, window, False, 0L, (XEvent *) &reply);
794 unexpect_property_change (wait_object); 796 unexpect_property_change (wait_object);
795 797
796 TRACE0 ("Got ACK"); 798 TRACE0 ("Got ACK");
797 while (bytes_remaining) 799 while (bytes_remaining)
798 { 800 {
799 int i = ((bytes_remaining < max_bytes) 801 int i = ((bytes_remaining < max_bytes)
800 ? bytes_remaining 802 ? bytes_remaining
801 : max_bytes); 803 : max_bytes);
802 804
803 BLOCK_INPUT; 805 BLOCK_INPUT;
804 806
805 wait_object 807 wait_object
806 = expect_property_change (display, window, reply.property, 808 = expect_property_change (display, window, reply.property,
1521 /* 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
1522 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
1523 reading it. Deal with that, I guess.... */ 1525 reading it. Deal with that, I guess.... */
1524 if (result != Success) 1526 if (result != Success)
1525 break; 1527 break;
1526 *actual_size_ret *= *actual_format_ret / 8; 1528
1527 bcopy (tmp_data, (*data_ret) + offset, *actual_size_ret); 1529 /* The man page for XGetWindowProperty says:
1528 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 }
1529 1560
1530 /* This was allocated by Xlib, so use XFree. */ 1561 /* This was allocated by Xlib, so use XFree. */
1531 XFree ((char *) tmp_data); 1562 XFree ((char *) tmp_data);
1532 } 1563 }
1533 1564
1736 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
1737 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.
1738 1769
1739 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>)
1740 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
1741 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). */
1742 1777
1743 1778
1744 1779
1745 static Lisp_Object 1780 static Lisp_Object
1746 selection_data_to_lisp_data (display, data, size, type, format) 1781 selection_data_to_lisp_data (display, data, size, type, format)
1778 a vector of symbols. 1813 a vector of symbols.
1779 */ 1814 */
1780 else if (type == XA_ATOM) 1815 else if (type == XA_ATOM)
1781 { 1816 {
1782 int i; 1817 int i;
1783 if (size == sizeof (Atom)) 1818 /* On a 64 bit machine sizeof(Atom) == sizeof(long) == 8.
1784 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]);
1785 else 1826 else
1786 { 1827 {
1787 Lisp_Object v = Fmake_vector (make_number (size / sizeof (Atom)), 1828 Lisp_Object v = Fmake_vector (make_number (size / sizeof (int)),
1788 make_number (0)); 1829 make_number (0));
1789 for (i = 0; i < size / sizeof (Atom); i++) 1830 for (i = 0; i < size / sizeof (int); i++)
1790 Faset (v, make_number (i), 1831 Faset (v, make_number (i),
1791 x_atom_to_symbol (display, ((Atom *) data) [i])); 1832 x_atom_to_symbol (display, (Atom) idata[i]));
1792 return v; 1833 return v;
1793 } 1834 }
1794 } 1835 }
1795 1836
1796 /* 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.
1968 } 2009 }
1969 #endif 2010 #endif
1970 else 2011 else
1971 /* This vector is an INTEGER set, or something like it */ 2012 /* This vector is an INTEGER set, or something like it */
1972 { 2013 {
2014 int data_size = 2;
1973 *size_ret = XVECTOR (obj)->size; 2015 *size_ret = XVECTOR (obj)->size;
1974 if (NILP (type)) type = QINTEGER; 2016 if (NILP (type)) type = QINTEGER;
1975 *format_ret = 16; 2017 *format_ret = 16;
1976 for (i = 0; i < *size_ret; i++) 2018 for (i = 0; i < *size_ret; i++)
1977 if (CONSP (XVECTOR (obj)->contents [i])) 2019 if (CONSP (XVECTOR (obj)->contents [i]))
1980 Fsignal (Qerror, /* Qselection_error */ 2022 Fsignal (Qerror, /* Qselection_error */
1981 Fcons (build_string 2023 Fcons (build_string
1982 ("elements of selection vector must be integers or conses of integers"), 2024 ("elements of selection vector must be integers or conses of integers"),
1983 Fcons (obj, Qnil))); 2025 Fcons (obj, Qnil)));
1984 2026
1985 *data_ret = (unsigned char *) xmalloc (*size_ret * (*format_ret/8)); 2027 /* Use sizeof(long) even if it is more than 32 bits. See comment
2028 in x_get_window_property and x_fill_property_data. */
2029
2030 if (*format_ret == 32) data_size = sizeof(long);
2031 *data_ret = (unsigned char *) xmalloc (*size_ret * data_size);
1986 for (i = 0; i < *size_ret; i++) 2032 for (i = 0; i < *size_ret; i++)
1987 if (*format_ret == 32) 2033 if (*format_ret == 32)
1988 (*((unsigned long **) data_ret)) [i] 2034 (*((unsigned long **) data_ret)) [i]
1989 = cons_to_long (XVECTOR (obj)->contents [i]); 2035 = cons_to_long (XVECTOR (obj)->contents [i]);
1990 else 2036 else
2467 2513
2468 DPY is the display use to look up X atoms. 2514 DPY is the display use to look up X atoms.
2469 DATA is a Lisp list of values to be converted. 2515 DATA is a Lisp list of values to be converted.
2470 RET is the C array that contains the converted values. It is assumed 2516 RET is the C array that contains the converted values. It is assumed
2471 it is big enough to hold all values. 2517 it is big enough to hold all values.
2472 FORMAT is 8, 16 or 32 and gives the size in bits for each C value to 2518 FORMAT is 8, 16 or 32 and denotes char/short/long for each C value to
2473 be stored in RET. */ 2519 be stored in RET. Note that long is used for 32 even if long is more
2520 than 32 bits (see man pages for XChangeProperty, XGetWindowProperty and
2521 XClientMessageEvent). */
2474 2522
2475 void 2523 void
2476 x_fill_property_data (dpy, data, ret, format) 2524 x_fill_property_data (dpy, data, ret, format)
2477 Display *dpy; 2525 Display *dpy;
2478 Lisp_Object data; 2526 Lisp_Object data;
2479 void *ret; 2527 void *ret;
2480 int format; 2528 int format;
2481 { 2529 {
2482 CARD32 val; 2530 long val;
2483 CARD32 *d32 = (CARD32 *) ret; 2531 long *d32 = (long *) ret;
2484 CARD16 *d16 = (CARD16 *) ret; 2532 short *d16 = (short *) ret;
2485 CARD8 *d08 = (CARD8 *) ret; 2533 char *d08 = (char *) ret;
2486 Lisp_Object iter; 2534 Lisp_Object iter;
2487 2535
2488 for (iter = data; CONSP (iter); iter = XCDR (iter)) 2536 for (iter = data; CONSP (iter); iter = XCDR (iter))
2489 { 2537 {
2490 Lisp_Object o = XCAR (iter); 2538 Lisp_Object o = XCAR (iter);
2491 2539
2492 if (INTEGERP (o)) 2540 if (INTEGERP (o))
2493 val = (CARD32) XFASTINT (o); 2541 val = (long) XFASTINT (o);
2494 else if (FLOATP (o)) 2542 else if (FLOATP (o))
2495 val = (CARD32) XFLOAT_DATA (o); 2543 val = (long) XFLOAT_DATA (o);
2496 else if (CONSP (o)) 2544 else if (CONSP (o))
2497 val = (CARD32) cons_to_long (o); 2545 val = (long) cons_to_long (o);
2498 else if (STRINGP (o)) 2546 else if (STRINGP (o))
2499 { 2547 {
2500 BLOCK_INPUT; 2548 BLOCK_INPUT;
2501 val = XInternAtom (dpy, (char *) SDATA (o), False); 2549 val = (long) XInternAtom (dpy, (char *) SDATA (o), False);
2502 UNBLOCK_INPUT; 2550 UNBLOCK_INPUT;
2503 } 2551 }
2504 else 2552 else
2505 error ("Wrong type, must be string, number or cons"); 2553 error ("Wrong type, must be string, number or cons");
2506 2554
2507 if (format == 8) 2555 if (format == 8)
2508 *d08++ = (CARD8) val; 2556 *d08++ = (char) val;
2509 else if (format == 16) 2557 else if (format == 16)
2510 *d16++ = (CARD16) val; 2558 *d16++ = (short) val;
2511 else 2559 else
2512 *d32++ = val; 2560 *d32++ = val;
2513 } 2561 }
2514 } 2562 }
2515 2563
2520 each number in DATA to its corresponfing X atom as a symbol. 2568 each number in DATA to its corresponfing X atom as a symbol.
2521 FORMAT is 8, 16 or 32 and gives the size in bits for each C value to 2569 FORMAT is 8, 16 or 32 and gives the size in bits for each C value to
2522 be stored in RET. 2570 be stored in RET.
2523 SIZE is the number of elements in DATA. 2571 SIZE is the number of elements in DATA.
2524 2572
2573 Important: When format is 32, data should contain an array of int,
2574 not an array of long as the X library returns. This makes a difference
2575 when sizeof(long) != sizeof(int).
2576
2525 Also see comment for selection_data_to_lisp_data above. */ 2577 Also see comment for selection_data_to_lisp_data above. */
2526 2578
2527 Lisp_Object 2579 Lisp_Object
2528 x_property_data_to_lisp (f, data, type, format, size) 2580 x_property_data_to_lisp (f, data, type, format, size)
2529 struct frame *f; 2581 struct frame *f;
2631 struct x_display_info *dpyinfo; 2683 struct x_display_info *dpyinfo;
2632 struct input_event *bufp; 2684 struct input_event *bufp;
2633 { 2685 {
2634 Lisp_Object vec; 2686 Lisp_Object vec;
2635 Lisp_Object frame; 2687 Lisp_Object frame;
2636 unsigned long size = (8*sizeof (event->data))/event->format; 2688 /* format 32 => size 5, format 16 => size 10, format 8 => size 20 */
2689 unsigned long size = 160/event->format;
2637 int x, y; 2690 int x, y;
2638 unsigned char *data = (unsigned char *) event->data.b; 2691 unsigned char *data = (unsigned char *) event->data.b;
2639 int idata[5]; 2692 int idata[5];
2640 2693
2641 XSETFRAME (frame, f); 2694 XSETFRAME (frame, f);
2710 Lisp_Object cons; 2763 Lisp_Object cons;
2711 int size; 2764 int size;
2712 struct frame *f = check_x_frame (from); 2765 struct frame *f = check_x_frame (from);
2713 int count; 2766 int count;
2714 int to_root; 2767 int to_root;
2715 int idata[5];
2716 void *data;
2717 2768
2718 CHECK_STRING (message_type); 2769 CHECK_STRING (message_type);
2719 CHECK_NUMBER (format); 2770 CHECK_NUMBER (format);
2720 CHECK_CONS (values); 2771 CHECK_CONS (values);
2721 2772
2772 /* Some clients (metacity for example) expects sending window to be here 2823 /* Some clients (metacity for example) expects sending window to be here
2773 when sending to the root window. */ 2824 when sending to the root window. */
2774 event.xclient.window = to_root ? FRAME_OUTER_WINDOW (f) : wdest; 2825 event.xclient.window = to_root ? FRAME_OUTER_WINDOW (f) : wdest;
2775 2826
2776 2827
2777 if (event.xclient.format == 32 && event.xclient.format < BITS_PER_LONG) 2828 memset (event.xclient.data.b, 0, sizeof (event.xclient.data.b));
2778 { 2829 x_fill_property_data (dpyinfo->display, values, event.xclient.data.b,
2779 /* x_fill_property_data expects data to hold 32 bit values when 2830 event.xclient.format);
2780 format == 32, but on a 64 bit machine long is 64 bits. 2831
2781 event.xclient.l is an array of long, so we must compensate. */
2782
2783 memset (idata, 0, sizeof (idata));
2784 data = idata;
2785 }
2786 else
2787 {
2788 memset (event.xclient.data.b, 0, sizeof (event.xclient.data.b));
2789 data = event.xclient.data.b;
2790 }
2791
2792 x_fill_property_data (dpyinfo->display, values, data, event.xclient.format);
2793
2794 if (data == idata)
2795 {
2796 int i;
2797 for (i = 0; i < 5; ++i) /* There are only 5 longs in a ClientMessage. */
2798 event.xclient.data.l[i] = (long) idata[i];
2799 }
2800
2801 /* If event mask is 0 the event is sent to the client that created 2832 /* If event mask is 0 the event is sent to the client that created
2802 the destination window. But if we are sending to the root window, 2833 the destination window. But if we are sending to the root window,
2803 there is no such client. Then we set the event mask to 0xffff. The 2834 there is no such client. Then we set the event mask to 0xffff. The
2804 event then goes to clients selecting for events on the root window. */ 2835 event then goes to clients selecting for events on the root window. */
2805 count = x_catch_errors (dpyinfo->display); 2836 count = x_catch_errors (dpyinfo->display);