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.36 by pcg, Tue Feb 24 22:28:42 2004 UTC vs.
Revision 1.43 by pcg, Wed Mar 3 02:59:53 2004 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*--------------------------------*-C-*--------------------------------------*
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-2004 Marc Lehmann <pcg@goof.com>
6 * 7 *
7 * 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
8 * 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
9 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 11 * (at your option) any later version.
16 * 17 *
17 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *--------------------------------------------------------------------------*/ 21 *--------------------------------------------------------------------------*/
22
21/* 23/*
22 * We handle _all_ screen updates and selections 24 * This file handles _all_ screen updates and selections
23 */ 25 */
24 26
25#include "../config.h" /* NECESSARY */ 27#include "../config.h" /* NECESSARY */
26#define INTERN_SCREEN 28#define INTERN_SCREEN
27#include "rxvt.h" /* NECESSARY */ 29#include "rxvt.h" /* NECESSARY */
30#include <X11/Xmd.h> /* get the typedef for CARD32 */ 32#include <X11/Xmd.h> /* get the typedef for CARD32 */
31 33
32#include <stdint.h> 34#include <stdint.h>
33#include <wchar.h> 35#include <wchar.h>
34 36
35#include "salloc.C" // HACK!! 37#include "salloc.C" // HACK, should be a seperate compile!
36 38
37inline void fill_text (text_t *start, text_t value, int len) 39inline void fill_text (text_t *start, text_t value, int len)
38{ 40{
39 while (len--) 41 while (len--)
40 *start++ = value; 42 *start++ = value;
862 scr_insdel_chars (1, INSERT); 864 scr_insdel_chars (1, INSERT);
863 865
864 if (charsets[screen.charset] == '0') // DEC SPECIAL 866 if (charsets[screen.charset] == '0') // DEC SPECIAL
865 switch (c) 867 switch (c)
866 { 868 {
869 // dunno where these come from
870#if 0
867 case '+': c = 0x2192; break; case ',': c = 0x2190; break; case '-': c = 0x2191; break; 871 case '+': c = 0x2192; break; case ',': c = 0x2190; break; case '-': c = 0x2191; break;
868 case '.': c = 0x2193; break; case '0': c = 0x25ae; break; case '`': c = 0x25c6; break; 872 case '.': c = 0x2193; break; case '0': c = 0x25ae; break;
873#endif
874 // vt100 special graphics and line drawing
875 case '`': c = 0x25c6; break; case '_': c = 0x0020; break;
869 case 'a': c = 0x2592; break; case 'f': c = 0x00b0; break; case 'g': c = 0x00b1; break; 876 case 'a': c = 0x2592; break; case 'b': c = 0x2409; break; case 'c': c = 0x240c; break;
870 case 'h': c = 0x2592; break; case 'i': c = 0x2603; break; case 'j': c = 0x2518; break;
871 case 'k': c = 0x2510; break; case 'l': c = 0x250c; break; case 'm': c = 0x2514; break; 877 case 'd': c = 0x240d; break; case 'e': c = 0x240a; break; case 'f': c = 0x00b0; break;
878 case 'g': c = 0x00b1; break; case 'h': c = 0x2424; break; case 'i': c = 0x240b; break;
872 case 'n': c = 0x253c; break; case 'o': c = 0x23ba; break; case 'p': c = 0x23bb; break; 879 case 'j': c = 0x2518; break; case 'k': c = 0x2510; break; case 'l': c = 0x250c; break;
873 case 'q': c = 0x2500; break; case 'r': c = 0x23bc; break; case 's': c = 0x23bd; break; 880 case 'm': c = 0x2514; break; case 'n': c = 0x253c; break; case 'o': c = 0x23ba; break;
874 case 't': c = 0x251c; break; case 'u': c = 0x2524; break; case 'v': c = 0x2534; break; 881 case 'p': c = 0x23bb; break; case 'q': c = 0x2500; break; case 'r': c = 0x23bc; break;
875 case 'w': c = 0x252c; break; case 'x': c = 0x2502; break; case 'y': c = 0x2264; break; 882 case 's': c = 0x23bd; break; case 't': c = 0x251c; break; case 'u': c = 0x2524; break;
876 case 'z': c = 0x2265; break; case '{': c = 0x03c0; break; case '|': c = 0x2260; break; 883 case 'v': c = 0x2534; break; case 'w': c = 0x252c; break; case 'x': c = 0x2502; break;
884 case 'y': c = 0x2264; break; case 'z': c = 0x2265; break; case '{': c = 0x03c0; break;
877 case '}': c = 0x00a3; break; case '~': c = 0x00b7; break; 885 case '|': c = 0x2260; break; case '}': c = 0x00a3; break; case '~': c = 0x00b7; break;
878 } 886 }
879 887
880 rend_t rend = SET_FONT (rstyle, TermWin.fontset->find_font (c)); 888 rend_t rend = SET_FONT (rstyle, TermWin.fontset->find_font (c));
881 // rely on wcwidth to tell us the character width, at least for non-ascii 889 // rely on wcwidth to tell us the character width, at least for non-ascii
882 int width = c <= 128 ? 1 : wcwidth (c); 890 int width = c <= 128 ? 1 : wcwidth (c);
883 891
884 // width -1 characters (e.g. combining chars) are ignored currently. 892 // width -1 characters (e.g. combining chars) are ignored currently.
885 if (width > 0) 893 if (width > 0)
894 {
886 do 895 do
887 { 896 {
888 stp[screen.cur.col] = c; 897 stp[screen.cur.col] = c;
889 srp[screen.cur.col] = rend; 898 srp[screen.cur.col] = rend;
890 899
891 if (screen.cur.col < last_col - 1) 900 if (screen.cur.col < last_col - 1)
892 screen.cur.col++; 901 screen.cur.col++;
893 else 902 else
894 { 903 {
895 screen.tlen[row] = last_col; 904 screen.tlen[row] = last_col;
896 if (screen.flags & Screen_Autowrap) 905 if (screen.flags & Screen_Autowrap)
897 screen.flags |= Screen_WrapNext; 906 screen.flags |= Screen_WrapNext;
898 break; 907 break;
899 } 908 }
900 909
901 c = NOCHAR; 910 c = NOCHAR;
902 } 911 }
903 while (--width > 0); 912 while (--width > 0);
913
914 // pad with spaces when overwriting wide character with smaller one
915 for (int c = screen.cur.col; stp[c] == NOCHAR && c < last_col; c++)
916 {
917 stp[c] = ' ';
918 srp[c] = rend;
919 }
920 }
904 else 921 else
905 (void)0; /* handle combining character etc. here. */ 922 (void)0; /* handle combining character etc. here. */
906 } 923 }
907 924
908 if (screen.tlen[row] != -1) /* XXX: think about this */ 925 if (screen.tlen[row] != -1) /* XXX: think about this */
1090 else 1107 else
1091 screen.cur.row = row; 1108 screen.cur.row = row;
1092 } 1109 }
1093 MAX_IT (screen.cur.row, 0); 1110 MAX_IT (screen.cur.row, 0);
1094 MIN_IT (screen.cur.row, (int32_t)TermWin.nrow - 1); 1111 MIN_IT (screen.cur.row, (int32_t)TermWin.nrow - 1);
1112
1113 while (screen.cur.col > 0
1114 && screen.text[screen.cur.row + TermWin.saveLines][screen.cur.col] == NOCHAR)
1115 screen.cur.col--;
1095} 1116}
1096 1117
1097/* ------------------------------------------------------------------------- */ 1118/* ------------------------------------------------------------------------- */
1098/* 1119/*
1099 * direction should be UP or DN 1120 * direction should be UP or DN
2046 int ypixel = (int)Row2Pixel (row); 2067 int ypixel = (int)Row2Pixel (row);
2047 2068
2048 for (col = 0; col < TermWin.ncol; col++) 2069 for (col = 0; col < TermWin.ncol; col++)
2049 { 2070 {
2050 /* compare new text with old - if exactly the same then continue */ 2071 /* compare new text with old - if exactly the same then continue */
2072 if (stp[col] == dtp[col] /* Must match characters to skip. */
2073 && (srp[col] == drp[col] /* Either rendition the same or */
2074 || (stp[col] == ' ' /* space w/ no background change */
2075 && GET_BGATTR (srp[col]) == GET_BGATTR (drp[col]))))
2076 continue;
2077
2078 // redraw one or more characters
2079
2080 // seek to the beginning if wide characters
2081 while (stp[col] == NOCHAR && col > 0)
2082 --col;
2083
2051 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2084 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2052
2053 if (stp[col] == dtp[col] /* Must match characters to skip. */
2054 && (rend == drp[col] /* Either rendition the same or */
2055 || (stp[col] == ' ' /* space w/ no background change */
2056 && GET_BGATTR (rend) == GET_BGATTR (drp[col]))))
2057 continue;
2058
2059 text_t *text = stp + col; 2085 text_t *text = stp + col;
2060 int count = 1; 2086 int count = 1;
2061 2087
2062 /* redraw one or more characters */
2063
2064 dtp[col] = stp[col]; 2088 dtp[col] = stp[col];
2065 drp[col] = rend; 2089 drp[col] = rend;
2066
2067 if (*text == NOCHAR) // never start redrawing at invisible characters. */
2068 continue;
2069 2090
2070 int xpixel = Col2Pixel (col); 2091 int xpixel = Col2Pixel (col);
2071 2092
2072 // this loop looks very messy, it can probably be optimized 2093 // this loop looks very messy, it can probably be optimized
2073 // and cleaned a bit by you? 2094 // and cleaned a bit by you?
2116 2137
2117 rend = GET_ATTR (rend); 2138 rend = GET_ATTR (rend);
2118 2139
2119 rvid = !!(rend & RS_RVid); 2140 rvid = !!(rend & RS_RVid);
2120 2141
2142#ifndef NO_BOLD_UNDERLINE_REVERSE
2143 if (rend & RS_Bold && fore == Color_fg)
2144 {
2145 if (ISSET_PIXCOLOR (Color_BD))
2146 fore = Color_BD;
2147 else
2148 rvid = !rvid;
2149 }
2150
2151 if (rend & RS_Uline)
2152 {
2153 if (ISSET_PIXCOLOR (Color_UL))
2154 fore = Color_UL;
2155 }
2156#endif
2157
2158 if (rvid)
2159 {
2160 SWAP_IT (fore, back, int);
2161
2162#ifndef NO_BOLD_UNDERLINE_REVERSE
2163 if (ISSET_PIXCOLOR (Color_RV)
2164# ifndef NO_CURSORCOLOR
2165 && !ISSET_PIXCOLOR (Color_cursor)
2166# endif
2167 )
2168 back = Color_RV;
2169#endif
2170 }
2171
2121#ifdef TEXT_BLINK 2172#ifdef TEXT_BLINK
2122 if (rend & RS_Blink) 2173 if (rend & RS_Blink && back == Color_bg)
2123 { 2174 {
2124 if (!text_blink_ev.active) 2175 if (!text_blink_ev.active)
2125 { 2176 {
2126 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2177 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
2127 hidden_text = 0; 2178 hidden_text = 0;
2128 } 2179 }
2129 else if (hidden_text) 2180 else if (hidden_text)
2130 fore = back; 2181 fore = back;
2131 } 2182 }
2132#endif 2183#endif
2133
2134#ifndef NO_BOLD_UNDERLINE_REVERSE
2135 if (rend & RS_Bold && fore == Color_fg)
2136 {
2137 if (ISSET_PIXCOLOR (Color_BD))
2138 fore = Color_BD;
2139 else
2140 rvid = !rvid;
2141 }
2142
2143 if (rend & RS_Uline)
2144 {
2145 if (ISSET_PIXCOLOR (Color_UL))
2146 fore = Color_UL;
2147 }
2148#endif
2149
2150 if (rvid)
2151 {
2152 SWAP_IT (fore, back, int);
2153
2154#ifndef NO_BOLD_UNDERLINE_REVERSE
2155 if (ISSET_PIXCOLOR (Color_RV)
2156# ifndef NO_CURSORCOLOR
2157 && !ISSET_PIXCOLOR (Color_cursor)
2158# endif
2159 )
2160 back = Color_RV;
2161#endif
2162 }
2163 2184
2164 /* 2185 /*
2165 * Actually do the drawing of the string here 2186 * Actually do the drawing of the string here
2166 */ 2187 */
2167 rxvt_font *font = (*TermWin.fontset)[fid]; 2188 rxvt_font *font = (*TermWin.fontset)[fid];
2189 else 2210 else
2190 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back); 2211 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back);
2191 2212
2192 if ((rend & RS_Uline) && (font->descent > 1)) 2213 if ((rend & RS_Uline) && (font->descent > 1))
2193 XDrawLine (display->display, drawBuffer, TermWin.gc, 2214 XDrawLine (display->display, drawBuffer, TermWin.gc,
2194 xpixel, ypixel + font->ascent + 1, 2215 xpixel, ypixel + font->ascent + 1,
2195 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2216 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2196 } /* for (col....) */ 2217 } /* for (col....) */
2197 } /* for (row....) */ 2218 } /* for (row....) */
2198 2219
2199 /* 2220 /*
2200 * G: cleanup cursor and display outline cursor if necessary 2221 * G: cleanup cursor and display outline cursor if necessary
2220 while (oldcursor.col + cursorwidth < TermWin.ncol 2241 while (oldcursor.col + cursorwidth < TermWin.ncol
2221 && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR) 2242 && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR)
2222 cursorwidth++; 2243 cursorwidth++;
2223 2244
2224 XDrawRectangle (display->display, drawBuffer, TermWin.gc, 2245 XDrawRectangle (display->display, drawBuffer, TermWin.gc,
2225 Col2Pixel (oldcursor.col), 2246 Col2Pixel (oldcursor.col),
2226 Row2Pixel (oldcursor.row), 2247 Row2Pixel (oldcursor.row),
2227 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2248 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2228 (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1)); 2249 (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1));
2229 } 2250 }
2230 } 2251 }
2231 2252
2232 /* 2253 /*
2233 * H: cleanup selection 2254 * H: cleanup selection
2241 /* 2262 /*
2242 * clear the whole screen height, note that width == 0 is treated 2263 * clear the whole screen height, note that width == 0 is treated
2243 * specially by XClearArea 2264 * specially by XClearArea
2244 */ 2265 */
2245 XClearArea (display->display, TermWin.vt, 0, 0, 2266 XClearArea (display->display, TermWin.vt, 0, 0,
2246 (unsigned int)TermWin.int_bwidth, 2267 (unsigned int)TermWin.int_bwidth,
2247 (unsigned int)TermWin_TotalHeight (), False); 2268 (unsigned int)TermWin_TotalHeight (), False);
2269
2248 if (clearlast && TermWin.int_bwidth) 2270 if (clearlast && TermWin.int_bwidth)
2249 /* 2271 /*
2250 * clear the whole screen height, note that width == 0 is treated 2272 * clear the whole screen height, note that width == 0 is treated
2251 * specially by XClearArea 2273 * specially by XClearArea
2252 */ 2274 */
2253 XClearArea (display->display, TermWin.vt, 2275 XClearArea (display->display, TermWin.vt,
2254 TermWin.width + TermWin.int_bwidth, 0, 2276 TermWin.width + TermWin.int_bwidth, 0,
2255 (unsigned int)TermWin.int_bwidth, 2277 (unsigned int)TermWin.int_bwidth,
2256 (unsigned int)TermWin_TotalHeight (), False); 2278 (unsigned int)TermWin_TotalHeight (), False);
2279
2257 if (refresh_type & SMOOTH_REFRESH) 2280 if (refresh_type & SMOOTH_REFRESH)
2258 XSync (display->display, False); 2281 XSync (display->display, False);
2259 2282
2260 num_scr = 0; 2283 num_scr = 0;
2261 num_scr_allow = 1; 2284 num_scr_allow = 1;
2285 } 2308 }
2286} 2309}
2287 2310
2288/* ------------------------------------------------------------------------- */ 2311/* ------------------------------------------------------------------------- */
2289void 2312void
2290rxvt_term::scr_clear () 2313rxvt_term::scr_clear (bool really)
2291{ 2314{
2292 if (!TermWin.mapped) 2315 if (!TermWin.mapped)
2293 return; 2316 return;
2294 2317
2295 num_scr_allow = 0; 2318 num_scr_allow = 0;
2296 want_refresh = 1; 2319 want_refresh = 1;
2320
2297#ifdef TRANSPARENT 2321#ifdef TRANSPARENT
2298 if ((Options & Opt_transparent) && (am_pixmap_trans == 0)) 2322 if ((Options & Opt_transparent) && (am_pixmap_trans == 0))
2299 { 2323 {
2300 int i; 2324 int i;
2301 2325
2308 if (TermWin.parent[i] != None) 2332 if (TermWin.parent[i] != None)
2309 XClearWindow (display->display, TermWin.parent[i]); 2333 XClearWindow (display->display, TermWin.parent[i]);
2310 } 2334 }
2311#endif 2335#endif
2312 2336
2337 if (really)
2313 XClearWindow (display->display, TermWin.vt); 2338 XClearWindow (display->display, TermWin.vt);
2314} 2339}
2315 2340
2316/* ------------------------------------------------------------------------- */ 2341/* ------------------------------------------------------------------------- */
2317void 2342void
2318rxvt_term::scr_reverse_selection () 2343rxvt_term::scr_reverse_selection ()
2319{ 2344{
2320 int i, col, row, end_row;
2321 rend_t *srp;
2322
2323 if (selection.op && current_screen == selection.screen) 2345 if (selection.op && current_screen == selection.screen)
2324 { 2346 {
2325 end_row = TermWin.saveLines - TermWin.view_start; 2347 int end_row = TermWin.saveLines - TermWin.view_start;
2326 i = selection.beg.row + TermWin.saveLines; 2348 int i = selection.beg.row + TermWin.saveLines;
2327 row = selection.end.row + TermWin.saveLines; 2349 int col, row = selection.end.row + TermWin.saveLines;
2350 rend_t *srp;
2351
2328 if (i >= end_row) 2352 if (i >= end_row)
2329 col = selection.beg.col; 2353 col = selection.beg.col;
2330 else 2354 else
2331 { 2355 {
2332 col = 0; 2356 col = 0;
2333 i = end_row; 2357 i = end_row;
2334 } 2358 }
2359
2335 end_row += TermWin.nrow; 2360 end_row += TermWin.nrow;
2336 for (; i < row && i < end_row; i++, col = 0) 2361 for (; i < row && i < end_row; i++, col = 0)
2337 for (srp = screen.rend[i]; col < TermWin.ncol; col++) 2362 for (srp = screen.rend[i]; col < TermWin.ncol; col++)
2338 srp[col] ^= RS_RVid; 2363 srp[col] ^= RS_RVid;
2364
2339 if (i == row && i < end_row) 2365 if (i == row && i < end_row)
2340 for (srp = screen.rend[i]; col < selection.end.col; col++) 2366 for (srp = screen.rend[i]; col < selection.end.col; col++)
2341 srp[col] ^= RS_RVid; 2367 srp[col] ^= RS_RVid;
2342 } 2368 }
2343} 2369}
2482 } 2508 }
2483 2509
2484 for (;;) 2510 for (;;)
2485 { 2511 {
2486 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), 2512 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4),
2487 (long) (PROP_SIZE / 4), delete_prop, 2513 (long) (PROP_SIZE / 4), delete_prop,
2488 AnyPropertyType, &ct.encoding, &ct.format, 2514 AnyPropertyType, &ct.encoding, &ct.format,
2489 &ct.nitems, &bytes_after, 2515 &ct.nitems, &bytes_after,
2490 &ct.value) != Success) 2516 &ct.value) != Success)
2491 break; 2517 break;
2492 2518
2493 if (ct.encoding == 0) 2519 if (ct.encoding == 0)
2494 { 2520 {
2495 D_SELECT ((stderr, "rxvt_selection_paste: property didn't exist!")); 2521 D_SELECT ((stderr, "rxvt_selection_paste: property didn't exist!"));
2503 } 2529 }
2504 2530
2505 if (ct.nitems == 0) 2531 if (ct.nitems == 0)
2506 { 2532 {
2507 D_SELECT ((stderr, "rxvt_selection_paste: property empty - also INCR end")); 2533 D_SELECT ((stderr, "rxvt_selection_paste: property empty - also INCR end"));
2508 if (selection_wait == Sel_normal && nread == 0) 2534 if (selection_wait == Sel_normal && nread == 0
2535 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2509 { 2536 {
2510 /* 2537 /*
2511 * pass through again trying CUT_BUFFER0 if we've come from 2538 * pass through again trying CUT_BUFFER0 if we've come from
2512 * XConvertSelection () but nothing was presented 2539 * XConvertSelection () but nothing was presented
2513 */ 2540 */
2704 * EXT: button 1 or 3 release 2731 * EXT: button 1 or 3 release
2705 */ 2732 */
2706void 2733void
2707rxvt_term::selection_make (Time tm) 2734rxvt_term::selection_make (Time tm)
2708{ 2735{
2709 int i, col, end_col, row, end_row; 2736 int i, col, end_col, row, end_row;
2710 unsigned char *new_selection_text; 2737 unsigned char *new_selection_text;
2711 char *str; 2738 char *str;
2712 text_t *t; 2739 text_t *t;
2713#ifdef ACS_ASCII
2714 rend_t *re;
2715#endif
2716 2740
2717 D_SELECT ((stderr, "rxvt_selection_make (): selection.op=%d, selection.clicks=%d", selection.op, selection.clicks)); 2741 D_SELECT ((stderr, "rxvt_selection_make (): selection.op=%d, selection.clicks=%d", selection.op, selection.clicks));
2718 switch (selection.op) 2742 switch (selection.op)
2719 { 2743 {
2720 case SELECTION_CONT: 2744 case SELECTION_CONT:
2726 selection.op = SELECTION_DONE; 2750 selection.op = SELECTION_DONE;
2727 /* FALLTHROUGH */ 2751 /* FALLTHROUGH */
2728 default: 2752 default:
2729 return; 2753 return;
2730 } 2754 }
2755
2731 selection.op = SELECTION_DONE; 2756 selection.op = SELECTION_DONE;
2732 2757
2733 if (selection.clicks == 4) 2758 if (selection.clicks == 4)
2734 return; /* nothing selected, go away */ 2759 return; /* nothing selected, go away */
2735 2760
2736 i = (selection.end.row - selection.beg.row + 1) * (TermWin.ncol + 1) + 1; 2761 i = (selection.end.row - selection.beg.row + 1) * (TermWin.ncol + 1) + 1;
2737 str = (char *)rxvt_malloc (i * MB_CUR_MAX + 1); 2762 str = (char *)rxvt_malloc ((i + 2) * MB_CUR_MAX + 1);
2738 2763
2739 new_selection_text = (unsigned char *)str; 2764 new_selection_text = (unsigned char *)str;
2740 2765
2741 col = selection.beg.col; 2766 col = selection.beg.col;
2742 MAX_IT (col, 0); 2767 MAX_IT (col, 0);
2743 row = selection.beg.row + TermWin.saveLines; 2768 row = selection.beg.row + TermWin.saveLines;
2744 end_row = selection.end.row + TermWin.saveLines; 2769 end_row = selection.end.row + TermWin.saveLines;
2770 struct mbstate mbs;
2745 2771
2746 for (; row <= end_row; row++, col = 0) 2772 for (; row <= end_row; row++, col = 0)
2747 { 2773 {
2748 t = & (screen.text[row][col]); 2774 t = & (screen.text[row][col]);
2749 2775
2758 for (; col < end_col; col++) 2784 for (; col < end_col; col++)
2759 if (*t == NOCHAR) 2785 if (*t == NOCHAR)
2760 t++; 2786 t++;
2761 else 2787 else
2762 { 2788 {
2763 int len = wctomb (str, *t++); 2789 int len = wcrtomb (str, *t++, mbs);
2764 if (len > 0) 2790 if (len > 0)
2765 str += len; 2791 str += len;
2766 } 2792 }
2767 2793
2768 if (screen.tlen[row] != -1 && row != end_row) 2794 if (screen.tlen[row] != -1 && row != end_row)
2786 { 2812 {
2787 free (new_selection_text); 2813 free (new_selection_text);
2788 return; 2814 return;
2789 } 2815 }
2790 2816
2791 // due to MB_MAX_CUR, selection wastage is usually high, so realloc 2817 // due to MB_CUR_MAX, selection wastage is usually high, so realloc
2792 if (str - (char *)new_selection_text > 1024) 2818 if (str - (char *)new_selection_text > 1024)
2793 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); 2819 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1);
2794 2820
2795 selection.len = i; 2821 selection.len = i;
2796 2822
2810 char *cl = (char *)selection.text; 2836 char *cl = (char *)selection.text;
2811 2837
2812 if (XmbTextListToTextProperty (display->display, &cl, 1, XStringStyle, &ct) >= 0) 2838 if (XmbTextListToTextProperty (display->display, &cl, 1, XStringStyle, &ct) >= 0)
2813 { 2839 {
2814 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 2840 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8,
2815 PropModeReplace, ct.value, ct.nitems); 2841 PropModeReplace, ct.value, ct.nitems);
2816 XFree (ct.value); 2842 XFree (ct.value);
2817 } 2843 }
2818 else 2844 else
2819 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 2845 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8,
2820 PropModeReplace, selection.text, (int)selection.len); 2846 PropModeReplace, selection.text, (int)selection.len);
2821 } 2847 }
2822 2848
2823 selection_time = tm; 2849 selection_time = tm;
2824 D_SELECT ((stderr, "rxvt_selection_make (): selection.len=%d", selection.len)); 2850 D_SELECT ((stderr, "rxvt_selection_make (): selection.len=%d", selection.len));
2825} 2851}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines