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.150 by root, Mon Dec 13 19:16:36 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
2656/* ------------------------------------------------------------------------- */ 2656/* ------------------------------------------------------------------------- */
2657/* 2657/*
2658 * Paste a selection direct to the command fd 2658 * Paste a selection direct to the command fd
2659 */ 2659 */
2660void 2660void
2661rxvt_term::paste (const unsigned char *data, unsigned int len) 2661rxvt_term::paste (unsigned char *data, unsigned int len)
2662{ 2662{
2663 unsigned int i, j, n;
2664 unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE);
2665
2666 /* convert normal newline chars into common keyboard Return key sequence */ 2663 /* convert normal newline chars into common keyboard Return key sequence */
2667 for (i = 0; i < len; i += PROP_SIZE) 2664 for (unsigned int i = 0; i < len; i++)
2668 {
2669 n = min (len - i, PROP_SIZE);
2670 memcpy (ds, data + i, n);
2671
2672 for (j = 0; j < n; j++)
2673 if (ds[j] == C0_LF) 2665 if (data[i] == C0_LF)
2674 ds[j] = C0_CR; 2666 data[i] = C0_CR;
2675 2667
2676 tt_write (ds, (int)n); 2668 tt_write (data, len);
2677 }
2678
2679 free (ds);
2680} 2669}
2681 2670
2682/* ------------------------------------------------------------------------- */ 2671/* ------------------------------------------------------------------------- */
2683/* 2672/*
2684 * Respond to a notification that a primary selection has been sent 2673 * Respond to a notification that a primary selection has been sent
2685 * EXT: SelectionNotify 2674 * EXT: SelectionNotify
2686 */ 2675 */
2687int 2676void
2688rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) 2677rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop)
2689{ 2678{
2690 long nread = 0;
2691 unsigned long bytes_after;
2692 XTextProperty ct;
2693
2694 if (prop == None) /* check for failed XConvertSelection */ 2679 if (prop == None) /* check for failed XConvertSelection */
2695 { 2680 {
2696 if ((selection_type & Sel_CompoundText)) 2681 if ((selection_type & Sel_CompoundText))
2697 { 2682 {
2698 int selnum = selection_type & Sel_whereMask; 2683 int selnum = selection_type & Sel_whereMask;
2711 selection_request_other (xa[XA_COMPOUND_TEXT], selnum); 2696 selection_request_other (xa[XA_COMPOUND_TEXT], selnum);
2712 else 2697 else
2713 selection_type = 0; 2698 selection_type = 0;
2714 } 2699 }
2715 2700
2716 return 0; 2701 return;
2717 }
2718
2719 for (;;)
2720 { 2702 }
2703
2704 unsigned long bytes_after;
2705 XTextProperty ct;
2706
2707 if (XGetWindowProperty (display->display, win, prop,
2708 0, PROP_SIZE / 4,
2709 delete_prop, AnyPropertyType,
2710 &ct.encoding, &ct.format,
2711 &ct.nitems, &bytes_after,
2712 &ct.value) != Success)
2713 {
2714 ct.value = 0;
2715 goto bailout;
2716 }
2717
2718 if (ct.encoding == None)
2719 goto bailout;
2720
2721 if (bytes_after)
2722 {
2723 // fetch and append remaining data
2724 XTextProperty ct2;
2725
2721 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), 2726 if (XGetWindowProperty (display->display, win, prop,
2722 (long) (PROP_SIZE / 4), delete_prop, 2727 ct.nitems / 4, (bytes_after + 3) / 4,
2728 delete_prop, AnyPropertyType,
2723 AnyPropertyType, &ct.encoding, &ct.format, 2729 &ct2.encoding, &ct2.format,
2724 &ct.nitems, &bytes_after, 2730 &ct2.nitems, &bytes_after,
2725 &ct.value) != Success) 2731 &ct2.value) != Success)
2726 break; 2732 goto bailout;
2727 2733
2728 if (ct.encoding == 0) 2734 // realloc should be compatible to XFree, here, and elsewhere, too
2729 break; 2735 ct.value = (unsigned char *)realloc (ct.value, ct.nitems + ct2.nitems + 1);
2736 memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems + 1);
2737 ct.nitems += ct2.nitems;
2730 2738
2739 XFree (ct2.value);
2740 }
2741
2742 if (ct.value == 0)
2743 goto bailout;
2744
2731 if (ct.encoding == xa[XA_INCR]) 2745 if (ct.encoding == xa[XA_INCR])
2732 { 2746 {
2733 // INCR selection, start handshake 2747 // INCR selection, start handshake
2748 if (!delete_prop)
2734 XDeleteProperty (display->display, win, prop); 2749 XDeleteProperty (display->display, win, prop);
2750
2735 selection_wait = Sel_incr; 2751 selection_wait = Sel_incr;
2752 incr_buf_fill = 0;
2736 incr_ev.start (NOW + 10); 2753 incr_ev.start (NOW + 10);
2737 break;
2738 }
2739 2754
2740 if (ct.value == NULL) 2755 goto bailout;
2741 continue; 2756 }
2742 2757
2743 if (ct.nitems == 0) 2758 if (ct.nitems == 0)
2759 {
2760 if (selection_wait == Sel_incr)
2761 {
2762 XFree (ct.value);
2763
2764 // finally complete, now paste the whole thing
2765 selection_wait = Sel_normal;
2766 ct.value = (unsigned char *)incr_buf;
2767 ct.nitems = incr_buf_fill;
2768 incr_buf = 0;
2769 incr_buf_size = 0;
2770 incr_ev.stop ();
2744 { 2771 }
2772 else
2773 {
2745 if (selection_wait == Sel_normal && nread == 0 2774 if (selection_wait == Sel_normal
2746 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2775 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2747 { 2776 {
2748 /* 2777 /*
2749 * pass through again trying CUT_BUFFER0 if we've come from 2778 * pass through again trying CUT_BUFFER0 if we've come from
2750 * XConvertSelection () but nothing was presented 2779 * XConvertSelection () but nothing was presented
2751 */ 2780 */
2752 selection_paste (display->root, XA_CUT_BUFFER0, False); 2781 selection_paste (display->root, XA_CUT_BUFFER0, False);
2753 } 2782 }
2754 2783
2755 nread = -1; /* discount any previous stuff */ 2784 goto bailout;
2756 break; 2785 }
2786 }
2787 else if (selection_wait == Sel_incr)
2788 {
2789 incr_ev.start (NOW + 10);
2790
2791 while (incr_buf_fill + ct.nitems > incr_buf_size)
2757 } 2792 {
2793 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2794 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2795 }
2758 2796
2797 memcpy (incr_buf + incr_buf_fill, ct.value, ct.nitems);
2759 nread += ct.nitems; 2798 incr_buf_fill += ct.nitems;
2760 2799
2800 goto bailout;
2801 }
2802
2761 char **cl; 2803 char **cl;
2762 int cr; 2804 int cr;
2763 2805
2764#if ENABLE_FRILLS 2806#if ENABLE_FRILLS
2765 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 2807 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2766 // so recode it manually 2808 // so recode it manually
2767 if (ct.encoding == xa[XA_UTF8_STRING]) 2809 if (ct.encoding == xa[XA_UTF8_STRING])
2768 { 2810 {
2769 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); 2811 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2770 char *s = rxvt_wcstombs (w); 2812 char *s = rxvt_wcstombs (w);
2771 2813 free (w);
2772 // TODO: strlen == only the first element will be converted. well... 2814 // TODO: strlen == only the first element will be converted. well...
2773 paste ((unsigned char *)s, strlen (s)); 2815 paste ((unsigned char *)s, strlen (s));
2774
2775 free (s); 2816 free (s);
2776 free (w); 2817 }
2777 }
2778 else 2818 else
2779#endif 2819#endif
2780 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 && cl) 2820 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0
2781 { 2821 && cl)
2822 {
2782 for (int i = 0; i < cr; i++) 2823 for (int i = 0; i < cr; i++)
2783 paste ((unsigned char *)cl[i], strlen (cl[i])); 2824 paste ((unsigned char *)cl[i], strlen (cl[i]));
2784 2825
2785 XFreeStringList (cl); 2826 XFreeStringList (cl);
2786 } 2827 }
2787 else 2828 else
2788 paste (ct.value, ct.nitems); 2829 paste (ct.value, ct.nitems); // paste raw
2789 2830
2790 if (bytes_after == 0) 2831bailout:
2791 break;
2792
2793 XFree (ct.value);
2794 }
2795
2796 if (ct.value)
2797 XFree (ct.value); 2832 XFree (ct.value);
2798 2833
2799 if (selection_wait == Sel_normal) 2834 if (selection_wait == Sel_normal)
2800 selection_wait = Sel_none; 2835 selection_wait = Sel_none;
2801
2802 return (int)nread;
2803} 2836}
2804 2837
2805void 2838void
2806rxvt_term::incr_cb (time_watcher &w) 2839rxvt_term::incr_cb (time_watcher &w)
2807{ 2840{
2808 selection_wait = Sel_none; 2841 selection_wait = Sel_none;
2809 2842
2843 incr_buf_size = 0;
2844 free (incr_buf);
2845
2810 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 2846 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2811} 2847}
2812 2848
2813/*
2814 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2815 */
2816void 2849void
2817rxvt_term::selection_property (Window win, Atom prop) 2850rxvt_term::selection_property (Window win, Atom prop)
2818{ 2851{
2819 if (prop == None || selection_wait != Sel_incr) 2852 if (prop == None || selection_wait != Sel_incr)
2820 return; 2853 return;
2821 2854
2822 if (selection_paste (win, prop, 1) > 0) 2855 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} 2856}
2830 2857
2831/* ------------------------------------------------------------------------- */ 2858/* ------------------------------------------------------------------------- */
2832/* 2859/*
2833 * Request the current selection: 2860 * Request the current selection:
2870 return; 2897 return;
2871#endif 2898#endif
2872 } 2899 }
2873 } 2900 }
2874 2901
2875 selection_wait = Sel_none; /* don't loop in rxvt_selection_paste () */ 2902 selection_wait = Sel_none; /* don't loop in selection_paste () */
2876 selection_paste (display->root, XA_CUT_BUFFER0, False); 2903 selection_paste (display->root, XA_CUT_BUFFER0, false);
2877} 2904}
2878 2905
2879int 2906int
2880rxvt_term::selection_request_other (Atom target, int selnum) 2907rxvt_term::selection_request_other (Atom target, int selnum)
2881{ 2908{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines