… | |
… | |
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 | */ |
2660 | void |
2660 | void |
2661 | rxvt_term::paste (const unsigned char *data, unsigned int len) |
2661 | rxvt_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 | */ |
2687 | int |
2687 | void |
2688 | rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) |
2688 | rxvt_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, (long)(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 | unsigned long bytes_after2; |
|
|
2737 | |
2721 | if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), |
2738 | if (XGetWindowProperty (display->display, win, prop, |
2722 | (long) (PROP_SIZE / 4), delete_prop, |
2739 | ct.nitems / 4, (long) (bytes_after + 3) / 4, |
|
|
2740 | delete_prop, AnyPropertyType, |
2723 | AnyPropertyType, &ct.encoding, &ct.format, |
2741 | &ct2.encoding, &ct2.format, |
2724 | &ct.nitems, &bytes_after, |
2742 | &ct2.nitems, &bytes_after2, |
2725 | &ct.value) != Success) |
2743 | &ct2.value) != Success) |
2726 | break; |
2744 | goto bailout; |
2727 | |
2745 | |
2728 | if (ct.encoding == 0) |
2746 | // realloc should be compatible to XFree, here, and elsewhere, too |
2729 | break; |
2747 | ct.value = (unsigned char *)realloc (ct.value, ct.nitems + bytes_after); |
|
|
2748 | memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems); |
|
|
2749 | ct.nitems += ct2.nitems; |
2730 | |
2750 | |
|
|
2751 | XFree (ct2.value); |
|
|
2752 | } |
|
|
2753 | else if (delete_prop) |
|
|
2754 | XDeleteProperty (display->display, win, prop); |
|
|
2755 | |
|
|
2756 | if (ct.value == 0) |
|
|
2757 | goto bailout; |
|
|
2758 | |
2731 | if (ct.encoding == xa[XA_INCR]) |
2759 | if (ct.encoding == xa[XA_INCR]) |
2732 | { |
2760 | { |
2733 | // INCR selection, start handshake |
2761 | // INCR selection, start handshake |
|
|
2762 | if (!delete_prop) |
2734 | XDeleteProperty (display->display, win, prop); |
2763 | XDeleteProperty (display->display, win, prop); |
|
|
2764 | |
2735 | selection_wait = Sel_incr; |
2765 | selection_wait = Sel_incr; |
|
|
2766 | incr_buf_fill = 0; |
2736 | incr_ev.start (NOW + 10); |
2767 | incr_ev.start (NOW + 10); |
2737 | break; |
|
|
2738 | } |
|
|
2739 | |
2768 | |
2740 | if (ct.value == NULL) |
2769 | goto bailout; |
2741 | continue; |
2770 | } |
2742 | |
2771 | |
2743 | if (ct.nitems == 0) |
2772 | if (ct.nitems == 0) |
|
|
2773 | { |
|
|
2774 | if (selection_wait == Sel_incr) |
|
|
2775 | { |
|
|
2776 | XFree (ct.value); |
|
|
2777 | |
|
|
2778 | // finally complete, now paste the whole thing |
|
|
2779 | selection_wait = Sel_normal; |
|
|
2780 | ct.value = (unsigned char *)incr_buf; |
|
|
2781 | ct.nitems = incr_buf_fill; |
|
|
2782 | incr_buf = 0; |
|
|
2783 | incr_buf_size = 0; |
|
|
2784 | incr_ev.stop (); |
2744 | { |
2785 | } |
|
|
2786 | else |
|
|
2787 | { |
2745 | if (selection_wait == Sel_normal && nread == 0 |
2788 | if (selection_wait == Sel_normal |
2746 | && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion |
2789 | && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion |
2747 | { |
2790 | { |
2748 | /* |
2791 | /* |
2749 | * pass through again trying CUT_BUFFER0 if we've come from |
2792 | * pass through again trying CUT_BUFFER0 if we've come from |
2750 | * XConvertSelection () but nothing was presented |
2793 | * XConvertSelection () but nothing was presented |
2751 | */ |
2794 | */ |
2752 | selection_paste (display->root, XA_CUT_BUFFER0, False); |
2795 | selection_paste (display->root, XA_CUT_BUFFER0, False); |
2753 | } |
2796 | } |
2754 | |
2797 | |
2755 | nread = -1; /* discount any previous stuff */ |
2798 | goto bailout; |
2756 | break; |
2799 | } |
|
|
2800 | } |
|
|
2801 | else if (selection_wait == Sel_incr) |
|
|
2802 | { |
|
|
2803 | incr_ev.start (NOW + 10); |
|
|
2804 | |
|
|
2805 | while (incr_buf_fill + ct.nitems > incr_buf_size) |
2757 | } |
2806 | { |
|
|
2807 | incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024; |
|
|
2808 | incr_buf = (char *)realloc (incr_buf, incr_buf_size); |
|
|
2809 | } |
2758 | |
2810 | |
|
|
2811 | memcpy (incr_buf + incr_buf_fill, ct.value, ct.nitems); |
2759 | nread += ct.nitems; |
2812 | incr_buf_fill += ct.nitems; |
2760 | |
2813 | |
|
|
2814 | goto bailout; |
|
|
2815 | } |
|
|
2816 | |
2761 | char **cl; |
2817 | char **cl; |
2762 | int cr; |
2818 | int cr; |
2763 | |
2819 | |
2764 | #if ENABLE_FRILLS |
2820 | #if ENABLE_FRILLS |
2765 | // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it |
2821 | // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it |
2766 | // so recode it manually |
2822 | // so recode it manually |
2767 | if (ct.encoding == xa[XA_UTF8_STRING]) |
2823 | if (ct.encoding == xa[XA_UTF8_STRING]) |
2768 | { |
2824 | { |
2769 | wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); |
2825 | wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); |
2770 | char *s = rxvt_wcstombs (w); |
2826 | char *s = rxvt_wcstombs (w); |
2771 | |
2827 | free (w); |
2772 | // TODO: strlen == only the first element will be converted. well... |
2828 | // TODO: strlen == only the first element will be converted. well... |
2773 | paste ((unsigned char *)s, strlen (s)); |
2829 | paste ((unsigned char *)s, strlen (s)); |
2774 | |
|
|
2775 | free (s); |
2830 | free (s); |
2776 | free (w); |
2831 | } |
2777 | } |
|
|
2778 | else |
2832 | else |
2779 | #endif |
2833 | #endif |
2780 | if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 && cl) |
2834 | if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 |
2781 | { |
2835 | && cl) |
|
|
2836 | { |
2782 | for (int i = 0; i < cr; i++) |
2837 | for (int i = 0; i < cr; i++) |
2783 | paste ((unsigned char *)cl[i], strlen (cl[i])); |
2838 | paste ((unsigned char *)cl[i], strlen (cl[i])); |
2784 | |
2839 | |
2785 | XFreeStringList (cl); |
2840 | XFreeStringList (cl); |
2786 | } |
2841 | } |
2787 | else |
2842 | else |
2788 | paste (ct.value, ct.nitems); |
2843 | paste (ct.value, ct.nitems); // paste raw |
2789 | |
2844 | |
2790 | if (bytes_after == 0) |
2845 | bailout: |
2791 | break; |
|
|
2792 | |
|
|
2793 | XFree (ct.value); |
|
|
2794 | } |
|
|
2795 | |
|
|
2796 | if (ct.value) |
|
|
2797 | XFree (ct.value); |
2846 | XFree (ct.value); |
2798 | |
2847 | |
2799 | if (selection_wait == Sel_normal) |
2848 | if (selection_wait == Sel_normal) |
2800 | selection_wait = Sel_none; |
2849 | selection_wait = Sel_none; |
2801 | |
|
|
2802 | return (int)nread; |
|
|
2803 | } |
2850 | } |
2804 | |
2851 | |
2805 | void |
2852 | void |
2806 | rxvt_term::incr_cb (time_watcher &w) |
2853 | rxvt_term::incr_cb (time_watcher &w) |
2807 | { |
2854 | { |
2808 | selection_wait = Sel_none; |
2855 | selection_wait = Sel_none; |
2809 | |
2856 | |
|
|
2857 | incr_buf_size = 0; |
|
|
2858 | free (incr_buf); |
|
|
2859 | |
2810 | rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); |
2860 | rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); |
2811 | } |
2861 | } |
2812 | |
2862 | |
2813 | /* |
|
|
2814 | * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> |
|
|
2815 | */ |
|
|
2816 | void |
2863 | void |
2817 | rxvt_term::selection_property (Window win, Atom prop) |
2864 | rxvt_term::selection_property (Window win, Atom prop) |
2818 | { |
2865 | { |
2819 | if (prop == None || selection_wait != Sel_incr) |
2866 | if (prop == None || selection_wait != Sel_incr) |
2820 | return; |
2867 | return; |
2821 | |
2868 | |
2822 | if (selection_paste (win, prop, 1) > 0) |
2869 | 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 | } |
2870 | } |
2830 | |
2871 | |
2831 | /* ------------------------------------------------------------------------- */ |
2872 | /* ------------------------------------------------------------------------- */ |
2832 | /* |
2873 | /* |
2833 | * Request the current selection: |
2874 | * Request the current selection: |
… | |
… | |
2870 | return; |
2911 | return; |
2871 | #endif |
2912 | #endif |
2872 | } |
2913 | } |
2873 | } |
2914 | } |
2874 | |
2915 | |
2875 | selection_wait = Sel_none; /* don't loop in rxvt_selection_paste () */ |
2916 | selection_wait = Sel_none; /* don't loop in selection_paste () */ |
2876 | selection_paste (display->root, XA_CUT_BUFFER0, False); |
2917 | selection_paste (display->root, XA_CUT_BUFFER0, false); |
2877 | } |
2918 | } |
2878 | |
2919 | |
2879 | int |
2920 | int |
2880 | rxvt_term::selection_request_other (Atom target, int selnum) |
2921 | rxvt_term::selection_request_other (Atom target, int selnum) |
2881 | { |
2922 | { |