ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/screen.C
(Generate patch)

Comparing rxvt-unicode/src/screen.C (file contents):
Revision 1.147 by root, Sun Dec 12 15:13:37 2004 UTC vs.
Revision 1.149 by root, Mon Dec 13 06:44:18 2004 UTC

39 while (len--) 39 while (len--)
40 *start++ = value; 40 *start++ = value;
41} 41}
42 42
43/* ------------------------------------------------------------------------- */ 43/* ------------------------------------------------------------------------- */
44#define PROP_SIZE 16384 44#define PROP_SIZE 256*1024
45#define PASTE_SIZE 32768
45#define TABSIZE 8 /* default tab size */ 46#define TABSIZE 8 /* default tab size */
46 47
47/* ------------------------------------------------------------------------- * 48/* ------------------------------------------------------------------------- *
48 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 49 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
49 * ------------------------------------------------------------------------- */ 50 * ------------------------------------------------------------------------- */
600 swap.flags |= Screen_VisibleCursor; 601 swap.flags |= Screen_VisibleCursor;
601 } 602 }
602 else 603 else
603#endif 604#endif
604 if (options & Opt_secondaryScroll) 605 if (options & Opt_secondaryScroll)
605 //if (current_screen == PRIMARY)
606 scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0); 606 scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0);
607 607
608 return scrn; 608 return scrn;
609} 609}
610 610
611// clear WrapNext indicator, solidifying position on next line 611// clear WrapNext indicator, solidifying position on next line
2659 */ 2659 */
2660void 2660void
2661rxvt_term::paste (const unsigned char *data, unsigned int len) 2661rxvt_term::paste (const unsigned char *data, unsigned int len)
2662{ 2662{
2663 unsigned int i, j, n; 2663 unsigned int i, j, n;
2664 unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE); 2664 unsigned char *ds = (unsigned char *)rxvt_malloc (PASTE_SIZE);
2665 2665
2666 /* convert normal newline chars into common keyboard Return key sequence */ 2666 /* convert normal newline chars into common keyboard Return key sequence */
2667 for (i = 0; i < len; i += PROP_SIZE) 2667 for (i = 0; i < len; i += PASTE_SIZE)
2668 { 2668 {
2669 n = min (len - i, PROP_SIZE); 2669 n = min (len - i, PASTE_SIZE);
2670 memcpy (ds, data + i, n); 2670 memcpy (ds, data + i, n);
2671 2671
2672 for (j = 0; j < n; j++) 2672 for (j = 0; j < n; j++)
2673 if (ds[j] == C0_LF) 2673 if (ds[j] == C0_LF)
2674 ds[j] = C0_CR; 2674 ds[j] = C0_CR;
2682/* ------------------------------------------------------------------------- */ 2682/* ------------------------------------------------------------------------- */
2683/* 2683/*
2684 * Respond to a notification that a primary selection has been sent 2684 * Respond to a notification that a primary selection has been sent
2685 * EXT: SelectionNotify 2685 * EXT: SelectionNotify
2686 */ 2686 */
2687int 2687void
2688rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) 2688rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop)
2689{ 2689{
2690 long nread = 0;
2691 unsigned long bytes_after;
2692 XTextProperty ct;
2693
2694 if (prop == None) /* check for failed XConvertSelection */ 2690 if (prop == None) /* check for failed XConvertSelection */
2695 { 2691 {
2696 if ((selection_type & Sel_CompoundText)) 2692 if ((selection_type & Sel_CompoundText))
2697 { 2693 {
2698 int selnum = selection_type & Sel_whereMask; 2694 int selnum = selection_type & Sel_whereMask;
2711 selection_request_other (xa[XA_COMPOUND_TEXT], selnum); 2707 selection_request_other (xa[XA_COMPOUND_TEXT], selnum);
2712 else 2708 else
2713 selection_type = 0; 2709 selection_type = 0;
2714 } 2710 }
2715 2711
2716 return 0; 2712 return;
2717 }
2718
2719 for (;;)
2720 { 2713 }
2714
2715 unsigned long bytes_after;
2716 XTextProperty ct;
2717
2718 if (XGetWindowProperty (display->display, win, prop,
2719 0, PROP_SIZE / 4,
2720 delete_prop, AnyPropertyType,
2721 &ct.encoding, &ct.format,
2722 &ct.nitems, &bytes_after,
2723 &ct.value) != Success)
2724 {
2725 ct.value = 0;
2726 goto bailout;
2727 }
2728
2729 if (ct.encoding == None)
2730 goto bailout;
2731
2732 if (bytes_after)
2733 {
2734 // fetch and append remaining data
2735 XTextProperty ct2;
2736
2721 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), 2737 if (XGetWindowProperty (display->display, win, prop,
2722 (long) (PROP_SIZE / 4), delete_prop, 2738 ct.nitems / 4, (bytes_after + 3) / 4,
2739 delete_prop, AnyPropertyType,
2723 AnyPropertyType, &ct.encoding, &ct.format, 2740 &ct2.encoding, &ct2.format,
2724 &ct.nitems, &bytes_after, 2741 &ct2.nitems, &bytes_after,
2725 &ct.value) != Success) 2742 &ct2.value) != Success)
2726 break; 2743 goto bailout;
2727 2744
2728 if (ct.encoding == 0) 2745 // realloc should be compatible to XFree, here, and elsewhere, too
2729 break; 2746 ct.value = (unsigned char *)realloc (ct.value, ct.nitems + ct2.nitems + 1);
2747 memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems + 1);
2748 ct.nitems += ct2.nitems;
2730 2749
2750 XFree (ct2.value);
2751 }
2752
2753 if (ct.value == 0)
2754 goto bailout;
2755
2731 if (ct.encoding == xa[XA_INCR]) 2756 if (ct.encoding == xa[XA_INCR])
2732 { 2757 {
2733 // INCR selection, start handshake 2758 // INCR selection, start handshake
2759 if (!delete_prop)
2734 XDeleteProperty (display->display, win, prop); 2760 XDeleteProperty (display->display, win, prop);
2761
2735 selection_wait = Sel_incr; 2762 selection_wait = Sel_incr;
2763 incr_buf_fill = 0;
2736 incr_ev.start (NOW + 10); 2764 incr_ev.start (NOW + 10);
2737 break;
2738 }
2739 2765
2740 if (ct.value == NULL) 2766 goto bailout;
2741 continue; 2767 }
2742 2768
2743 if (ct.nitems == 0) 2769 if (ct.nitems == 0)
2770 {
2771 if (selection_wait == Sel_incr)
2772 {
2773 XFree (ct.value);
2774
2775 // finally complete, now paste the whole thing
2776 selection_wait = Sel_normal;
2777 ct.value = (unsigned char *)incr_buf;
2778 ct.nitems = incr_buf_fill;
2779 incr_buf = 0;
2780 incr_buf_size = 0;
2781 incr_ev.stop ();
2744 { 2782 }
2783 else
2784 {
2745 if (selection_wait == Sel_normal && nread == 0 2785 if (selection_wait == Sel_normal
2746 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2786 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2747 { 2787 {
2748 /* 2788 /*
2749 * pass through again trying CUT_BUFFER0 if we've come from 2789 * pass through again trying CUT_BUFFER0 if we've come from
2750 * XConvertSelection () but nothing was presented 2790 * XConvertSelection () but nothing was presented
2751 */ 2791 */
2752 selection_paste (display->root, XA_CUT_BUFFER0, False); 2792 selection_paste (display->root, XA_CUT_BUFFER0, False);
2753 } 2793 }
2754 2794
2755 nread = -1; /* discount any previous stuff */ 2795 goto bailout;
2756 break; 2796 }
2797 }
2798 else if (selection_wait == Sel_incr)
2799 {
2800 incr_ev.start (NOW + 10);
2801
2802 while (incr_buf_fill + ct.nitems > incr_buf_size)
2757 } 2803 {
2804 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2805 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2806 }
2758 2807
2808 memcpy (incr_buf + incr_buf_fill, ct.value, ct.nitems);
2759 nread += ct.nitems; 2809 incr_buf_fill += ct.nitems;
2760 2810
2811 goto bailout;
2812 }
2813
2761 char **cl; 2814 char **cl;
2762 int cr; 2815 int cr;
2763 2816
2764#if ENABLE_FRILLS 2817#if ENABLE_FRILLS
2765 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 2818 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2766 // so recode it manually 2819 // so recode it manually
2767 if (ct.encoding == xa[XA_UTF8_STRING]) 2820 if (ct.encoding == xa[XA_UTF8_STRING])
2768 { 2821 {
2769 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); 2822 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2770 char *s = rxvt_wcstombs (w); 2823 char *s = rxvt_wcstombs (w);
2771 2824 free (w);
2772 // TODO: strlen == only the first element will be converted. well... 2825 // TODO: strlen == only the first element will be converted. well...
2773 paste ((unsigned char *)s, strlen (s)); 2826 paste ((unsigned char *)s, strlen (s));
2774
2775 free (s); 2827 free (s);
2776 free (w); 2828 }
2777 }
2778 else 2829 else
2779#endif 2830#endif
2780 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 && cl) 2831 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0
2781 { 2832 && cl)
2833 {
2782 for (int i = 0; i < cr; i++) 2834 for (int i = 0; i < cr; i++)
2783 paste ((unsigned char *)cl[i], strlen (cl[i])); 2835 paste ((unsigned char *)cl[i], strlen (cl[i]));
2784 2836
2785 XFreeStringList (cl); 2837 XFreeStringList (cl);
2786 } 2838 }
2787 else 2839 else
2788 paste (ct.value, ct.nitems); 2840 paste (ct.value, ct.nitems); // paste raw
2789 2841
2790 if (bytes_after == 0) 2842bailout:
2791 break;
2792
2793 XFree (ct.value);
2794 }
2795
2796 if (ct.value)
2797 XFree (ct.value); 2843 XFree (ct.value);
2798 2844
2799 if (selection_wait == Sel_normal) 2845 if (selection_wait == Sel_normal)
2800 selection_wait = Sel_none; 2846 selection_wait = Sel_none;
2801
2802 return (int)nread;
2803} 2847}
2804 2848
2805void 2849void
2806rxvt_term::incr_cb (time_watcher &w) 2850rxvt_term::incr_cb (time_watcher &w)
2807{ 2851{
2808 selection_wait = Sel_none; 2852 selection_wait = Sel_none;
2809 2853
2854 incr_buf_size = 0;
2855 free (incr_buf);
2856
2810 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 2857 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2811} 2858}
2812 2859
2813/*
2814 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2815 */
2816void 2860void
2817rxvt_term::selection_property (Window win, Atom prop) 2861rxvt_term::selection_property (Window win, Atom prop)
2818{ 2862{
2819 if (prop == None || selection_wait != Sel_incr) 2863 if (prop == None || selection_wait != Sel_incr)
2820 return; 2864 return;
2821 2865
2822 if (selection_paste (win, prop, 1) > 0) 2866 selection_paste (win, prop, true);
2823 incr_ev.start (NOW + 10);
2824 else
2825 {
2826 selection_wait = Sel_none;
2827 incr_ev.stop ();
2828 }
2829} 2867}
2830 2868
2831/* ------------------------------------------------------------------------- */ 2869/* ------------------------------------------------------------------------- */
2832/* 2870/*
2833 * Request the current selection: 2871 * Request the current selection:
2870 return; 2908 return;
2871#endif 2909#endif
2872 } 2910 }
2873 } 2911 }
2874 2912
2875 selection_wait = Sel_none; /* don't loop in rxvt_selection_paste () */ 2913 selection_wait = Sel_none; /* don't loop in selection_paste () */
2876 selection_paste (display->root, XA_CUT_BUFFER0, False); 2914 selection_paste (display->root, XA_CUT_BUFFER0, false);
2877} 2915}
2878 2916
2879int 2917int
2880rxvt_term::selection_request_other (Atom target, int selnum) 2918rxvt_term::selection_request_other (Atom target, int selnum)
2881{ 2919{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines