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.347 by sf-exg, Sat Aug 28 11:03:04 2010 UTC vs.
Revision 1.382 by sf-exg, Tue Apr 26 16:19:45 2011 UTC

1/*---------------------------------------------------------------------------* 1/*---------------------------------------------------------------------------*
2 * File: screen.C 2 * File: screen.C
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * 4 *
5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> 5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com>
6 * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2007 Marc Lehmann <schmorp@schmorp.de>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
38 while (len--) 38 while (len--)
39 *start++ = value; 39 *start++ = value;
40} 40}
41 41
42/* ------------------------------------------------------------------------- */ 42/* ------------------------------------------------------------------------- */
43#define PROP_SIZE 256*1024
44#define PASTE_SIZE 32768
45#define TABSIZE 8 /* default tab size */ 43#define TABSIZE 8 /* default tab size */
46 44
47/* ------------------------------------------------------------------------- * 45/* ------------------------------------------------------------------------- *
48 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 46 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
49 * ------------------------------------------------------------------------- */ 47 * ------------------------------------------------------------------------- */
144 col--; 142 col--;
145 143
146 rend_t rend = l.r[col] & ~RS_baseattrMask; 144 rend_t rend = l.r[col] & ~RS_baseattrMask;
147 rend = SET_FONT (rend, FONTSET (rend)->find_font (' ')); 145 rend = SET_FONT (rend, FONTSET (rend)->find_font (' '));
148 146
147 l.touch ();
148
149 // found start, nuke 149 // found start, nuke
150 do { 150 do {
151 l.t[col] = ' '; 151 l.t[col] = ' ';
152 l.r[col] = rend; 152 l.r[col] = rend;
153 col++; 153 col++;
159 * ------------------------------------------------------------------------- */ 159 * ------------------------------------------------------------------------- */
160 160
161void 161void
162rxvt_term::scr_reset () 162rxvt_term::scr_reset ()
163{ 163{
164#if ENABLE_OVERLAY
165 scr_overlay_off ();
166#endif
167
164 view_start = 0; 168 view_start = 0;
165 num_scr = 0; 169 num_scr = 0;
166 170
167 if (ncol == 0) 171 if (ncol == 0)
168 ncol = 80; 172 ncol = 80;
398 } 402 }
399 403
400 free (tabs); 404 free (tabs);
401 tabs = (char *)rxvt_malloc (ncol); 405 tabs = (char *)rxvt_malloc (ncol);
402 406
403 for (int col = ncol; --col; ) 407 for (int col = ncol; col--; )
404 tabs [col] = col % TABSIZE == 0; 408 tabs [col] = col % TABSIZE == 0;
405 409
406 CLEAR_ALL_SELECTION (); 410 CLEAR_ALL_SELECTION ();
407 411
408 prev_nrow = nrow; 412 prev_nrow = nrow;
898# else 902# else
899 c = 0xfffd; 903 c = 0xfffd;
900# endif 904# endif
901#endif 905#endif
902 906
903 // nuke the character at this position, if required
904 if (expect_false (
905 line->t[screen.cur.col] == NOCHAR
906 || (screen.cur.col < ncol - 1
907 && line->t[screen.cur.col + 1] == NOCHAR)
908 ))
909 scr_kill_char (*line, screen.cur.col);
910
911 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); 907 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
912 908
913 // if the character doesn't fit into the remaining columns... 909 // if the character doesn't fit into the remaining columns...
914 if (expect_false (screen.cur.col > ncol - width && ncol >= width)) 910 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
915 { 911 {
912 if (screen.flags & Screen_Autowrap)
913 {
916 // ... artificially enlargen the previous one 914 // ... artificially enlargen the previous one
917 c = NOCHAR; 915 c = NOCHAR;
918 // and try the same character next loop iteration 916 // and try the same character next loop iteration
919 --str; 917 --str;
918 }
919 else
920 screen.cur.col = ncol - width;
920 } 921 }
922
923 // nuke the character at this position, if required
924 // due to wonderful coincidences everywhere else in this loop
925 // we never have to check for overwriting a wide char itself,
926 // only its tail.
927 if (expect_false (line->t[screen.cur.col] == NOCHAR))
928 scr_kill_char (*line, screen.cur.col);
921 929
922 line->touch (); 930 line->touch ();
923 931
924 do 932 do
925 { 933 {
931 else 939 else
932 { 940 {
933 line->l = ncol; 941 line->l = ncol;
934 if (screen.flags & Screen_Autowrap) 942 if (screen.flags & Screen_Autowrap)
935 screen.flags |= Screen_WrapNext; 943 screen.flags |= Screen_WrapNext;
936 break; 944
945 goto end_of_line;
937 } 946 }
938 947
939 c = NOCHAR; 948 c = NOCHAR;
940 } 949 }
941 while (expect_false (--width > 0)); 950 while (expect_false (--width > 0));
942 951
943 // pad with spaces when overwriting wide character with smaller one 952 // pad with spaces when overwriting wide character with smaller one
944 if (expect_false (!width)) 953 for (int c = screen.cur.col; expect_false (c < ncol && line->t[c] == NOCHAR); c++)
945 { 954 {
946 line->touch ();
947
948 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
949 {
950 line->t[c] = ' '; 955 line->t[c] = ' ';
951 line->r[c] = rend; 956 line->r[c] = rend;
952 }
953 } 957 }
958
959end_of_line:
960 ;
954 } 961 }
955#if ENABLE_COMBINING 962#if ENABLE_COMBINING
956 else // width == 0 963 else // width == 0
957 { 964 {
958 if (c != 0xfeff) // ignore BOM 965 if (c != 0xfeff) // ignore BOM
1021 1028
1022 want_refresh = 1; 1029 want_refresh = 1;
1023#endif 1030#endif
1024 } 1031 }
1025 } 1032 }
1033 else if (screen.flags & Screen_WrapNext)
1034 screen.flags &= ~Screen_WrapNext;
1026 else 1035 else
1027 scr_gotorc (0, -1, RELATIVE); 1036 scr_gotorc (0, -1, RELATIVE);
1028} 1037}
1029 1038
1030/* ------------------------------------------------------------------------- */ 1039/* ------------------------------------------------------------------------- */
1678 { 1687 {
1679 rvideo_state = on; 1688 rvideo_state = on;
1680 1689
1681 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1690 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1682#ifdef HAVE_BG_PIXMAP 1691#ifdef HAVE_BG_PIXMAP
1683 if (bgPixmap.pixmap == None) 1692 if (bg_pixmap == None)
1684#endif 1693#endif
1685 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 1694 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
1686 1695
1687 XGCValues gcvalue; 1696 XGCValues gcvalue;
1688 gcvalue.foreground = pix_colors[Color_fg]; 1697 gcvalue.foreground = pix_colors[Color_fg];
1915 1924
1916# ifndef NO_MAPALERT 1925# ifndef NO_MAPALERT
1917# ifdef MAPALERT_OPTION 1926# ifdef MAPALERT_OPTION
1918 if (option (Opt_mapAlert)) 1927 if (option (Opt_mapAlert))
1919# endif 1928# endif
1920 XMapWindow (dpy, parent[0]); 1929 XMapWindow (dpy, parent);
1921# endif 1930# endif
1922 1931
1923# if ENABLE_FRILLS 1932# if ENABLE_FRILLS
1924 if (option (Opt_urgentOnBell)) 1933 if (option (Opt_urgentOnBell))
1925 set_urgency (1); 1934 set_urgency (1);
2024 refresh_count = 0; 2033 refresh_count = 0;
2025 2034
2026 unsigned int old_screen_flags = screen.flags; 2035 unsigned int old_screen_flags = screen.flags;
2027 char have_bg = 0; 2036 char have_bg = 0;
2028#ifdef HAVE_BG_PIXMAP 2037#ifdef HAVE_BG_PIXMAP
2029 have_bg = bgPixmap.pixmap != None; 2038 have_bg = bg_pixmap != None;
2030#endif 2039#endif
2031 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2040 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
2032 2041
2033 /* 2042 /*
2034 * B: reverse any characters which are selected 2043 * B: reverse any characters which are selected
2501 scr_remap_chars (swap_buf [i]); 2510 scr_remap_chars (swap_buf [i]);
2502 } 2511 }
2503} 2512}
2504 2513
2505void 2514void
2506rxvt_term::scr_recolour () NOTHROW 2515rxvt_term::scr_recolour (bool refresh) NOTHROW
2507{ 2516{
2517 bool transparent = false;
2518
2508#ifdef HAVE_BG_PIXMAP 2519#ifdef HAVE_BG_PIXMAP
2509 bgPixmap.apply (); 2520 if (bg_pixmap != None)
2510#else 2521 {
2522# ifdef ENABLE_TRANSPARENCY
2523 if (bg_flags & BG_IS_TRANSPARENT)
2524 {
2525 XSetWindowBackgroundPixmap (dpy, parent, bg_pixmap);
2526 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
2511 2527
2528 transparent = true;
2529 }
2530 else
2531# endif
2532 {
2533 XSetWindowBackground (dpy, parent, pix_colors[Color_border]);
2534 XSetWindowBackgroundPixmap (dpy, vt, bg_pixmap);
2535 }
2536 }
2537 else
2538#endif
2539 {
2512 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]); 2540 XSetWindowBackground (dpy, parent, pix_colors[Color_border]);
2513 XClearWindow (dpy, parent[0]);
2514 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 2541 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2542 }
2543
2544 XClearWindow (dpy, parent);
2515 2545
2516 if (scrollBar.win) 2546 if (scrollBar.win)
2517 { 2547 {
2548 if (transparent)
2549 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
2550 else
2518 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); 2551 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2519 scrollBar.state = STATE_IDLE; 2552 scrollBar.state = STATE_IDLE;
2520 scrollBar.show (0); 2553 scrollBar.show (0);
2521 } 2554 }
2522 2555
2523#endif 2556 if (refresh)
2524 2557 {
2525 /* bgPixmap.apply () does not do the following : */
2526 scr_clear (); 2558 scr_clear ();
2527 scr_touch (true); 2559 scr_touch (true);
2560 }
2528 want_refresh = 1; 2561 want_refresh = 1;
2529} 2562}
2530 2563
2531/* ------------------------------------------------------------------------- */ 2564/* ------------------------------------------------------------------------- */
2532void 2565void
2620void 2653void
2621rxvt_term::scr_dump (int fd) NOTHROW 2654rxvt_term::scr_dump (int fd) NOTHROW
2622{ 2655{
2623 int row, wrote; 2656 int row, wrote;
2624 unsigned int width, towrite; 2657 unsigned int width, towrite;
2625 char r1[] = "\n"; 2658 const char r1[] = "\n";
2626 2659
2627 for (row = saveLines + top_row; 2660 for (row = saveLines + top_row;
2628 row < saveLines + nrow - 1; row++) 2661 row < saveLines + nrow - 1; row++)
2629 { 2662 {
2630 width = row_buf[row].l >= 0 ? row_buf[row].l 2663 width = row_buf[row].l >= 0 ? row_buf[row].l
2703 tt_paste (data, len); 2736 tt_paste (data, len);
2704} 2737}
2705 2738
2706/* ------------------------------------------------------------------------- */ 2739/* ------------------------------------------------------------------------- */
2707/* 2740/*
2708 * Respond to a notification that a primary selection has been sent 2741 * Request PRIMARY, SECONDARY or CLIPBOARD selection.
2709 * EXT: SelectionNotify 2742 * if the requested selection has no owner or is empty CUT_BUFFER0 is used
2710 */ 2743 * as fallback
2711void
2712rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) NOTHROW
2713{
2714 if (prop == None) /* check for failed XConvertSelection */
2715 {
2716 if ((selection_type & Sel_CompoundText))
2717 {
2718 int selnum = selection_type & Sel_whereMask;
2719
2720 selection_type = 0;
2721 if (selnum != Sel_direct)
2722 selection_request_other (XA_STRING, selnum);
2723 }
2724
2725 if ((selection_type & Sel_UTF8String))
2726 {
2727 int selnum = selection_type & Sel_whereMask;
2728
2729 selection_type = Sel_CompoundText;
2730 if (selnum != Sel_direct)
2731 selection_request_other (xa[XA_COMPOUND_TEXT], selnum);
2732 else
2733 selection_type = 0;
2734 }
2735
2736 return;
2737 }
2738
2739 unsigned long bytes_after;
2740 XTextProperty ct;
2741
2742 if (XGetWindowProperty (dpy, win, prop,
2743 0, PROP_SIZE / 4,
2744 delete_prop, AnyPropertyType,
2745 &ct.encoding, &ct.format,
2746 &ct.nitems, &bytes_after,
2747 &ct.value) != Success)
2748 {
2749 ct.value = 0;
2750 goto bailout;
2751 }
2752
2753 if (ct.encoding == None)
2754 goto bailout;
2755
2756 if (bytes_after)
2757 {
2758 // fetch and append remaining data
2759 XTextProperty ct2;
2760
2761 if (XGetWindowProperty (dpy, win, prop,
2762 ct.nitems / 4, (bytes_after + 3) / 4,
2763 delete_prop, AnyPropertyType,
2764 &ct2.encoding, &ct2.format,
2765 &ct2.nitems, &bytes_after,
2766 &ct2.value) != Success)
2767 goto bailout;
2768
2769 // realloc should be compatible to XFree, here, and elsewhere, too
2770 ct.value = (unsigned char *)realloc (ct.value, ct.nitems + ct2.nitems + 1);
2771 memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems + 1);
2772 ct.nitems += ct2.nitems;
2773
2774 XFree (ct2.value);
2775 }
2776
2777 if (ct.value == 0)
2778 goto bailout;
2779
2780 if (ct.encoding == xa[XA_INCR])
2781 {
2782 // INCR selection, start handshake
2783 if (!delete_prop)
2784 XDeleteProperty (dpy, win, prop);
2785
2786 selection_wait = Sel_incr;
2787 incr_buf_fill = 0;
2788 incr_ev.start (10);
2789
2790 goto bailout;
2791 }
2792
2793 if (ct.nitems == 0)
2794 {
2795 if (selection_wait == Sel_incr)
2796 {
2797 XFree (ct.value);
2798
2799 // finally complete, now paste the whole thing
2800 selection_wait = Sel_normal;
2801 ct.value = (unsigned char *)incr_buf;
2802 ct.nitems = incr_buf_fill;
2803 incr_buf = 0;
2804 incr_buf_size = 0;
2805 incr_ev.stop ();
2806 }
2807 else
2808 {
2809 if (selection_wait == Sel_normal
2810 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2811 {
2812 /*
2813 * pass through again trying CUT_BUFFER0 if we've come from
2814 * XConvertSelection () but nothing was presented
2815 */
2816 selection_paste (display->root, XA_CUT_BUFFER0, False);
2817 }
2818
2819 goto bailout;
2820 }
2821 }
2822 else if (selection_wait == Sel_incr)
2823 {
2824 incr_ev.start (10);
2825
2826 while (incr_buf_fill + ct.nitems > incr_buf_size)
2827 {
2828 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2829 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2830 }
2831
2832 memcpy (incr_buf + incr_buf_fill, ct.value, ct.nitems);
2833 incr_buf_fill += ct.nitems;
2834
2835 goto bailout;
2836 }
2837
2838 char **cl;
2839 int cr;
2840
2841#if !ENABLE_MINIMAL
2842 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2843 // so recode it manually
2844 if (ct.encoding == xa[XA_UTF8_STRING])
2845 {
2846 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2847 char *s = rxvt_wcstombs (w);
2848 free (w);
2849 // TODO: strlen == only the first element will be converted. well...
2850 paste (s, strlen (s));
2851 free (s);
2852 }
2853 else
2854#endif
2855 if (XmbTextPropertyToTextList (dpy, &ct, &cl, &cr) >= 0
2856 && cl)
2857 {
2858 for (int i = 0; i < cr; i++)
2859 paste (cl[i], strlen (cl[i]));
2860
2861 XFreeStringList (cl);
2862 }
2863 else
2864 paste ((char *)ct.value, ct.nitems); // paste raw
2865
2866bailout:
2867 XFree (ct.value);
2868
2869 if (selection_wait == Sel_normal)
2870 selection_wait = Sel_none;
2871}
2872
2873void
2874rxvt_term::incr_cb (ev::timer &w, int revents) NOTHROW
2875{
2876 selection_wait = Sel_none;
2877
2878 incr_buf_size = 0;
2879 free (incr_buf);
2880
2881 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2882}
2883
2884void
2885rxvt_term::selection_property (Window win, Atom prop) NOTHROW
2886{
2887 if (prop == None || selection_wait != Sel_incr)
2888 return;
2889
2890 selection_paste (win, prop, true);
2891}
2892
2893/* ------------------------------------------------------------------------- */
2894/*
2895 * Request the current selection:
2896 * Order: > internal selection if available
2897 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+)
2898 * > CUT_BUFFER0
2899 * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
2900 * will auto fallback to CUT_BUFFER0
2901 * EXT: button 2 release 2744 * EXT: button 2 release
2902 */ 2745 */
2903void 2746void
2904rxvt_term::selection_request (Time tm, int selnum) NOTHROW 2747rxvt_term::selection_request (Time tm, int selnum) NOTHROW
2905{ 2748{
2906 if (selection.text && selnum == Sel_Primary) 2749 if (!selection_req)
2907 {
2908 /* internal selection */
2909 char *str = rxvt_wcstombs (selection.text, selection.len);
2910 paste (str, strlen (str));
2911 free (str);
2912 return;
2913 } 2750 {
2914 else 2751 selection_req = new rxvt_selection (display, selnum, tm, vt, xa[XA_VT_SELECTION], this);
2752 selection_req->run ();
2915 { 2753 }
2916 selection_request_time = tm;
2917 selection_wait = Sel_normal;
2918
2919#if X_HAVE_UTF8_STRING
2920 selection_type = Sel_UTF8String;
2921 if (selection_request_other (xa[XA_UTF8_STRING], selnum))
2922 return;
2923#else
2924 selection_type = Sel_CompoundText;
2925 if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum))
2926 return;
2927#endif
2928 }
2929
2930 selection_wait = Sel_none; /* don't loop in selection_paste () */
2931 selection_paste (display->root, XA_CUT_BUFFER0, false);
2932}
2933
2934int
2935rxvt_term::selection_request_other (Atom target, int selnum) NOTHROW
2936{
2937 Atom sel;
2938
2939 selection_type |= selnum;
2940
2941 if (selnum == Sel_Primary)
2942 sel = XA_PRIMARY;
2943 else if (selnum == Sel_Secondary)
2944 sel = XA_SECONDARY;
2945 else
2946 sel = xa[XA_CLIPBOARD];
2947
2948 if (XGetSelectionOwner (dpy, sel) != None)
2949 {
2950 XConvertSelection (dpy, sel, target, xa[XA_VT_SELECTION],
2951 vt, selection_request_time);
2952 return 1;
2953 }
2954
2955 return 0;
2956} 2754}
2957 2755
2958/* ------------------------------------------------------------------------- */ 2756/* ------------------------------------------------------------------------- */
2959/* 2757/*
2960 * Clear all selected text 2758 * Clear all selected text
2991 * EXT: button 1 or 3 release 2789 * EXT: button 1 or 3 release
2992 */ 2790 */
2993void 2791void
2994rxvt_term::selection_make (Time tm) 2792rxvt_term::selection_make (Time tm)
2995{ 2793{
2996 int i; 2794 int size;
2997 wchar_t *new_selection_text; 2795 wchar_t *new_selection_text;
2998 text_t *t; 2796 text_t *t;
2999 2797
3000 switch (selection.op) 2798 switch (selection.op)
3001 { 2799 {
3017 return; /* nothing selected, go away */ 2815 return; /* nothing selected, go away */
3018 2816
3019 if (HOOK_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END))) 2817 if (HOOK_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END)))
3020 return; 2818 return;
3021 2819
3022 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); 2820 size = (selection.end.row - selection.beg.row + 1) * (ncol + 1);
3023 new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t)); 2821 new_selection_text = (wchar_t *)rxvt_malloc ((size + 4) * sizeof (wchar_t));
3024 2822
3025 int ofs = 0; 2823 int ofs = 0;
3026 int extra = 0; 2824 int extra = 0;
3027 2825
3028 int col = selection.beg.col; 2826 int col = selection.beg.col;
3034 { 2832 {
3035#if !ENABLE_MINIMAL 2833#if !ENABLE_MINIMAL
3036 if (selection.rect) 2834 if (selection.rect)
3037 { 2835 {
3038 col = selection.beg.col; 2836 col = selection.beg.col;
3039 end_col = ncol + 1; 2837 end_col = selection.end.col;
3040 } 2838 }
3041 else 2839 else
3042#endif 2840#endif
3043 end_col = ROW(row).l; 2841 end_col = ROW(row).l;
3044 2842
3045 col = max (col, 0); 2843 col = max (col, 0);
3046 2844
3047 if (row == selection.end.row 2845 if (row == selection.end.row)
3048#if !ENABLE_MINIMAL
3049 || selection.rect
3050#endif
3051 )
3052 min_it (end_col, selection.end.col); 2846 min_it (end_col, selection.end.col);
3053 2847
3054 t = ROW(row).t + col; 2848 t = ROW(row).t + col;
3055 2849
3056 for (; col < end_col; col++) 2850 for (; col < end_col; col++)
3064 2858
3065 extra -= (len - 1); 2859 extra -= (len - 1);
3066 2860
3067 if (extra < 0) 2861 if (extra < 0)
3068 { 2862 {
3069 extra += i; 2863 extra += size;
3070 i += i; 2864 size += size;
3071 new_selection_text = (wchar_t *)rxvt_realloc (new_selection_text, (i + 4) * sizeof (wchar_t)); 2865 new_selection_text = (wchar_t *)rxvt_realloc (new_selection_text, (size + 4) * sizeof (wchar_t));
3072 } 2866 }
3073 2867
3074 ofs += rxvt_composite.expand (*t++, new_selection_text + ofs); 2868 ofs += rxvt_composite.expand (*t++, new_selection_text + ofs);
3075 } 2869 }
3076#endif 2870#endif
3088 2882
3089 new_selection_text[ofs++] = C0_LF; 2883 new_selection_text[ofs++] = C0_LF;
3090 } 2884 }
3091 else 2885 else
3092#endif 2886#endif
3093 if (!ROW(row).is_longer () && row != selection.end.row) 2887 if (!ROW(row).is_longer ()
2888 && (row != selection.end.row || end_col != selection.end.col)
2889 && (row != selection.beg.row || selection.beg.col < ncol))
3094 new_selection_text[ofs++] = C0_LF; 2890 new_selection_text[ofs++] = C0_LF;
3095 } 2891 }
3096
3097 if (end_col != selection.end.col)
3098 new_selection_text[ofs++] = C0_LF;
3099 2892
3100 new_selection_text[ofs] = 0; 2893 new_selection_text[ofs] = 0;
3101 2894
3102 if (ofs == 0) 2895 if (ofs == 0)
3103 { 2896 {
3609 * EXT: SelectionRequest 3402 * EXT: SelectionRequest
3610 */ 3403 */
3611void 3404void
3612rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW 3405rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW
3613{ 3406{
3407 Atom property = rq.property == None ? rq.target : rq.property;
3614 XSelectionEvent ev; 3408 XSelectionEvent ev;
3615 3409
3616 ev.type = SelectionNotify; 3410 ev.type = SelectionNotify;
3617 ev.property = None; 3411 ev.property = None;
3618 ev.display = rq.display; 3412 ev.display = rq.display;
3633 *target++ = xa[XA_COMPOUND_TEXT]; 3427 *target++ = xa[XA_COMPOUND_TEXT];
3634#if X_HAVE_UTF8_STRING 3428#if X_HAVE_UTF8_STRING
3635 *target++ = xa[XA_UTF8_STRING]; 3429 *target++ = xa[XA_UTF8_STRING];
3636#endif 3430#endif
3637 3431
3638 XChangeProperty (dpy, rq.requestor, rq.property, XA_ATOM, 3432 XChangeProperty (dpy, rq.requestor, property, XA_ATOM,
3639 32, PropModeReplace, 3433 32, PropModeReplace,
3640 (unsigned char *)target_list, target - target_list); 3434 (unsigned char *)target_list, target - target_list);
3641 ev.property = rq.property; 3435 ev.property = property;
3642 } 3436 }
3643#if TODO // TODO 3437#if TODO // TODO
3644 else if (rq.target == xa[XA_MULTIPLE]) 3438 else if (rq.target == xa[XA_MULTIPLE])
3645 { 3439 {
3646 /* TODO: Handle MULTIPLE */ 3440 /* TODO: Handle MULTIPLE */
3647 } 3441 }
3648#endif 3442#endif
3649 else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == XA_PRIMARY && selection.text) 3443 else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == XA_PRIMARY && selection.text)
3650 { 3444 {
3651 XChangeProperty (dpy, rq.requestor, rq.property, rq.target, 3445 XChangeProperty (dpy, rq.requestor, property, rq.target,
3652 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3446 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3653 ev.property = rq.property; 3447 ev.property = property;
3654 } 3448 }
3655 else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == xa[XA_CLIPBOARD] && selection.clip_text) 3449 else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == xa[XA_CLIPBOARD] && selection.clip_text)
3656 { 3450 {
3657 XChangeProperty (dpy, rq.requestor, rq.property, rq.target, 3451 XChangeProperty (dpy, rq.requestor, property, rq.target,
3658 32, PropModeReplace, (unsigned char *)&clipboard_time, 1); 3452 32, PropModeReplace, (unsigned char *)&clipboard_time, 1);
3659 ev.property = rq.property; 3453 ev.property = property;
3660 } 3454 }
3661 else if (rq.target == XA_STRING 3455 else if (rq.target == XA_STRING
3662 || rq.target == xa[XA_TEXT] 3456 || rq.target == xa[XA_TEXT]
3663 || rq.target == xa[XA_COMPOUND_TEXT] 3457 || rq.target == xa[XA_COMPOUND_TEXT]
3664 || rq.target == xa[XA_UTF8_STRING] 3458 || rq.target == xa[XA_UTF8_STRING]
3735 ct.value = (unsigned char *)cl; 3529 ct.value = (unsigned char *)cl;
3736 ct.nitems = selectlen; 3530 ct.nitems = selectlen;
3737 ct.encoding = target; 3531 ct.encoding = target;
3738 } 3532 }
3739 3533
3740 XChangeProperty (dpy, rq.requestor, rq.property, 3534 XChangeProperty (dpy, rq.requestor, property,
3741 ct.encoding, 8, PropModeReplace, 3535 ct.encoding, 8, PropModeReplace,
3742 ct.value, (int)ct.nitems); 3536 ct.value, (int)ct.nitems);
3743 ev.property = rq.property; 3537 ev.property = property;
3744 3538
3745 if (freect) 3539 if (freect)
3746 XFree (ct.value); 3540 XFree (ct.value);
3747 } 3541 }
3748 3542

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines