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.35 by pcg, Tue Feb 24 11:48:40 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?
2114 int fore = GET_FGCOLOR (rend); // desired foreground 2135 int fore = GET_FGCOLOR (rend); // desired foreground
2115 int back = GET_BGCOLOR (rend); // desired background 2136 int back = GET_BGCOLOR (rend); // desired background
2116 2137
2117 rend = GET_ATTR (rend); 2138 rend = GET_ATTR (rend);
2118 2139
2119 rvid = !! (rend & RS_RVid); 2140 rvid = !!(rend & RS_RVid);
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
2120 if (rvid) 2158 if (rvid)
2121 { 2159 {
2122 SWAP_IT (fore, back, int); 2160 SWAP_IT (fore, back, int);
2123 2161
2124#ifndef NO_BOLD_UNDERLINE_REVERSE 2162#ifndef NO_BOLD_UNDERLINE_REVERSE
2127 && !ISSET_PIXCOLOR (Color_cursor) 2165 && !ISSET_PIXCOLOR (Color_cursor)
2128# endif 2166# endif
2129 ) 2167 )
2130 back = Color_RV; 2168 back = Color_RV;
2131#endif 2169#endif
2132
2133 } 2170 }
2171
2134#ifdef TEXT_BLINK 2172#ifdef TEXT_BLINK
2135 if (rend & RS_Blink) 2173 if (rend & RS_Blink && back == Color_bg)
2136 { 2174 {
2137 if (!text_blink_ev.active) 2175 if (!text_blink_ev.active)
2138 { 2176 {
2139 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2177 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
2140 hidden_text = 0; 2178 hidden_text = 0;
2141 } 2179 }
2142 else if (hidden_text) 2180 else if (hidden_text)
2143 fore = back; 2181 fore = back;
2144 }
2145#endif
2146#ifndef NO_BOLD_UNDERLINE_REVERSE
2147 else if (rend & RS_Bold)
2148 {
2149 if (ISSET_PIXCOLOR (Color_BD))
2150 fore = Color_BD;
2151 else if (fore == Color_fg)
2152 fore = Color_White;
2153 }
2154 else if (rend & RS_Uline)
2155 {
2156 if (ISSET_PIXCOLOR (Color_UL))
2157 fore = Color_UL;
2158 } 2182 }
2159#endif 2183#endif
2160 2184
2161 /* 2185 /*
2162 * Actually do the drawing of the string here 2186 * Actually do the drawing of the string here
2186 else 2210 else
2187 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back); 2211 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back);
2188 2212
2189 if ((rend & RS_Uline) && (font->descent > 1)) 2213 if ((rend & RS_Uline) && (font->descent > 1))
2190 XDrawLine (display->display, drawBuffer, TermWin.gc, 2214 XDrawLine (display->display, drawBuffer, TermWin.gc,
2191 xpixel, ypixel + font->ascent + 1, 2215 xpixel, ypixel + font->ascent + 1,
2192 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2216 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2193 } /* for (col....) */ 2217 } /* for (col....) */
2194 } /* for (row....) */ 2218 } /* for (row....) */
2195 2219
2196 /* 2220 /*
2197 * G: cleanup cursor and display outline cursor if necessary 2221 * G: cleanup cursor and display outline cursor if necessary
2217 while (oldcursor.col + cursorwidth < TermWin.ncol 2241 while (oldcursor.col + cursorwidth < TermWin.ncol
2218 && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR) 2242 && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR)
2219 cursorwidth++; 2243 cursorwidth++;
2220 2244
2221 XDrawRectangle (display->display, drawBuffer, TermWin.gc, 2245 XDrawRectangle (display->display, drawBuffer, TermWin.gc,
2222 Col2Pixel (oldcursor.col), 2246 Col2Pixel (oldcursor.col),
2223 Row2Pixel (oldcursor.row), 2247 Row2Pixel (oldcursor.row),
2224 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2248 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2225 (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1)); 2249 (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1));
2226 } 2250 }
2227 } 2251 }
2228 2252
2229 /* 2253 /*
2230 * H: cleanup selection 2254 * H: cleanup selection
2238 /* 2262 /*
2239 * clear the whole screen height, note that width == 0 is treated 2263 * clear the whole screen height, note that width == 0 is treated
2240 * specially by XClearArea 2264 * specially by XClearArea
2241 */ 2265 */
2242 XClearArea (display->display, TermWin.vt, 0, 0, 2266 XClearArea (display->display, TermWin.vt, 0, 0,
2243 (unsigned int)TermWin.int_bwidth, 2267 (unsigned int)TermWin.int_bwidth,
2244 (unsigned int)TermWin_TotalHeight (), False); 2268 (unsigned int)TermWin_TotalHeight (), False);
2269
2245 if (clearlast && TermWin.int_bwidth) 2270 if (clearlast && TermWin.int_bwidth)
2246 /* 2271 /*
2247 * clear the whole screen height, note that width == 0 is treated 2272 * clear the whole screen height, note that width == 0 is treated
2248 * specially by XClearArea 2273 * specially by XClearArea
2249 */ 2274 */
2250 XClearArea (display->display, TermWin.vt, 2275 XClearArea (display->display, TermWin.vt,
2251 TermWin.width + TermWin.int_bwidth, 0, 2276 TermWin.width + TermWin.int_bwidth, 0,
2252 (unsigned int)TermWin.int_bwidth, 2277 (unsigned int)TermWin.int_bwidth,
2253 (unsigned int)TermWin_TotalHeight (), False); 2278 (unsigned int)TermWin_TotalHeight (), False);
2279
2254 if (refresh_type & SMOOTH_REFRESH) 2280 if (refresh_type & SMOOTH_REFRESH)
2255 XSync (display->display, False); 2281 XSync (display->display, False);
2256 2282
2257 num_scr = 0; 2283 num_scr = 0;
2258 num_scr_allow = 1; 2284 num_scr_allow = 1;
2282 } 2308 }
2283} 2309}
2284 2310
2285/* ------------------------------------------------------------------------- */ 2311/* ------------------------------------------------------------------------- */
2286void 2312void
2287rxvt_term::scr_clear () 2313rxvt_term::scr_clear (bool really)
2288{ 2314{
2289 if (!TermWin.mapped) 2315 if (!TermWin.mapped)
2290 return; 2316 return;
2291 2317
2292 num_scr_allow = 0; 2318 num_scr_allow = 0;
2293 want_refresh = 1; 2319 want_refresh = 1;
2320
2294#ifdef TRANSPARENT 2321#ifdef TRANSPARENT
2295 if ((Options & Opt_transparent) && (am_pixmap_trans == 0)) 2322 if ((Options & Opt_transparent) && (am_pixmap_trans == 0))
2296 { 2323 {
2297 int i; 2324 int i;
2298 2325
2305 if (TermWin.parent[i] != None) 2332 if (TermWin.parent[i] != None)
2306 XClearWindow (display->display, TermWin.parent[i]); 2333 XClearWindow (display->display, TermWin.parent[i]);
2307 } 2334 }
2308#endif 2335#endif
2309 2336
2337 if (really)
2310 XClearWindow (display->display, TermWin.vt); 2338 XClearWindow (display->display, TermWin.vt);
2311} 2339}
2312 2340
2313/* ------------------------------------------------------------------------- */ 2341/* ------------------------------------------------------------------------- */
2314void 2342void
2315rxvt_term::scr_reverse_selection () 2343rxvt_term::scr_reverse_selection ()
2316{ 2344{
2317 int i, col, row, end_row;
2318 rend_t *srp;
2319
2320 if (selection.op && current_screen == selection.screen) 2345 if (selection.op && current_screen == selection.screen)
2321 { 2346 {
2322 end_row = TermWin.saveLines - TermWin.view_start; 2347 int end_row = TermWin.saveLines - TermWin.view_start;
2323 i = selection.beg.row + TermWin.saveLines; 2348 int i = selection.beg.row + TermWin.saveLines;
2324 row = selection.end.row + TermWin.saveLines; 2349 int col, row = selection.end.row + TermWin.saveLines;
2350 rend_t *srp;
2351
2325 if (i >= end_row) 2352 if (i >= end_row)
2326 col = selection.beg.col; 2353 col = selection.beg.col;
2327 else 2354 else
2328 { 2355 {
2329 col = 0; 2356 col = 0;
2330 i = end_row; 2357 i = end_row;
2331 } 2358 }
2359
2332 end_row += TermWin.nrow; 2360 end_row += TermWin.nrow;
2333 for (; i < row && i < end_row; i++, col = 0) 2361 for (; i < row && i < end_row; i++, col = 0)
2334 for (srp = screen.rend[i]; col < TermWin.ncol; col++) 2362 for (srp = screen.rend[i]; col < TermWin.ncol; col++)
2335 srp[col] ^= RS_RVid; 2363 srp[col] ^= RS_RVid;
2364
2336 if (i == row && i < end_row) 2365 if (i == row && i < end_row)
2337 for (srp = screen.rend[i]; col < selection.end.col; col++) 2366 for (srp = screen.rend[i]; col < selection.end.col; col++)
2338 srp[col] ^= RS_RVid; 2367 srp[col] ^= RS_RVid;
2339 } 2368 }
2340} 2369}
2479 } 2508 }
2480 2509
2481 for (;;) 2510 for (;;)
2482 { 2511 {
2483 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), 2512 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4),
2484 (long) (PROP_SIZE / 4), delete_prop, 2513 (long) (PROP_SIZE / 4), delete_prop,
2485 AnyPropertyType, &ct.encoding, &ct.format, 2514 AnyPropertyType, &ct.encoding, &ct.format,
2486 &ct.nitems, &bytes_after, 2515 &ct.nitems, &bytes_after,
2487 &ct.value) != Success) 2516 &ct.value) != Success)
2488 break; 2517 break;
2489 2518
2490 if (ct.encoding == 0) 2519 if (ct.encoding == 0)
2491 { 2520 {
2492 D_SELECT ((stderr, "rxvt_selection_paste: property didn't exist!")); 2521 D_SELECT ((stderr, "rxvt_selection_paste: property didn't exist!"));
2500 } 2529 }
2501 2530
2502 if (ct.nitems == 0) 2531 if (ct.nitems == 0)
2503 { 2532 {
2504 D_SELECT ((stderr, "rxvt_selection_paste: property empty - also INCR end")); 2533 D_SELECT ((stderr, "rxvt_selection_paste: property empty - also INCR end"));
2505 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
2506 { 2536 {
2507 /* 2537 /*
2508 * pass through again trying CUT_BUFFER0 if we've come from 2538 * pass through again trying CUT_BUFFER0 if we've come from
2509 * XConvertSelection () but nothing was presented 2539 * XConvertSelection () but nothing was presented
2510 */ 2540 */
2701 * EXT: button 1 or 3 release 2731 * EXT: button 1 or 3 release
2702 */ 2732 */
2703void 2733void
2704rxvt_term::selection_make (Time tm) 2734rxvt_term::selection_make (Time tm)
2705{ 2735{
2706 int i, col, end_col, row, end_row; 2736 int i, col, end_col, row, end_row;
2707 unsigned char *new_selection_text; 2737 unsigned char *new_selection_text;
2708 char *str; 2738 char *str;
2709 text_t *t; 2739 text_t *t;
2710#ifdef ACS_ASCII
2711 rend_t *re;
2712#endif
2713 2740
2714 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));
2715 switch (selection.op) 2742 switch (selection.op)
2716 { 2743 {
2717 case SELECTION_CONT: 2744 case SELECTION_CONT:
2723 selection.op = SELECTION_DONE; 2750 selection.op = SELECTION_DONE;
2724 /* FALLTHROUGH */ 2751 /* FALLTHROUGH */
2725 default: 2752 default:
2726 return; 2753 return;
2727 } 2754 }
2755
2728 selection.op = SELECTION_DONE; 2756 selection.op = SELECTION_DONE;
2729 2757
2730 if (selection.clicks == 4) 2758 if (selection.clicks == 4)
2731 return; /* nothing selected, go away */ 2759 return; /* nothing selected, go away */
2732 2760
2733 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;
2734 str = (char *)rxvt_malloc (i * MB_CUR_MAX + 1); 2762 str = (char *)rxvt_malloc ((i + 2) * MB_CUR_MAX + 1);
2735 2763
2736 new_selection_text = (unsigned char *)str; 2764 new_selection_text = (unsigned char *)str;
2737 2765
2738 col = selection.beg.col; 2766 col = selection.beg.col;
2739 MAX_IT (col, 0); 2767 MAX_IT (col, 0);
2740 row = selection.beg.row + TermWin.saveLines; 2768 row = selection.beg.row + TermWin.saveLines;
2741 end_row = selection.end.row + TermWin.saveLines; 2769 end_row = selection.end.row + TermWin.saveLines;
2770 struct mbstate mbs;
2742 2771
2743 for (; row <= end_row; row++, col = 0) 2772 for (; row <= end_row; row++, col = 0)
2744 { 2773 {
2745 t = & (screen.text[row][col]); 2774 t = & (screen.text[row][col]);
2746 2775
2755 for (; col < end_col; col++) 2784 for (; col < end_col; col++)
2756 if (*t == NOCHAR) 2785 if (*t == NOCHAR)
2757 t++; 2786 t++;
2758 else 2787 else
2759 { 2788 {
2760 int len = wctomb (str, *t++); 2789 int len = wcrtomb (str, *t++, mbs);
2761 if (len > 0) 2790 if (len > 0)
2762 str += len; 2791 str += len;
2763 } 2792 }
2764 2793
2765 if (screen.tlen[row] != -1 && row != end_row) 2794 if (screen.tlen[row] != -1 && row != end_row)
2783 { 2812 {
2784 free (new_selection_text); 2813 free (new_selection_text);
2785 return; 2814 return;
2786 } 2815 }
2787 2816
2788 // 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
2789 if (str - (char *)new_selection_text > 1024) 2818 if (str - (char *)new_selection_text > 1024)
2790 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);
2791 2820
2792 selection.len = i; 2821 selection.len = i;
2793 2822
2807 char *cl = (char *)selection.text; 2836 char *cl = (char *)selection.text;
2808 2837
2809 if (XmbTextListToTextProperty (display->display, &cl, 1, XStringStyle, &ct) >= 0) 2838 if (XmbTextListToTextProperty (display->display, &cl, 1, XStringStyle, &ct) >= 0)
2810 { 2839 {
2811 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 2840 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8,
2812 PropModeReplace, ct.value, ct.nitems); 2841 PropModeReplace, ct.value, ct.nitems);
2813 XFree (ct.value); 2842 XFree (ct.value);
2814 } 2843 }
2815 else 2844 else
2816 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 2845 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8,
2817 PropModeReplace, selection.text, (int)selection.len); 2846 PropModeReplace, selection.text, (int)selection.len);
2818 } 2847 }
2819 2848
2820 selection_time = tm; 2849 selection_time = tm;
2821 D_SELECT ((stderr, "rxvt_selection_make (): selection.len=%d", selection.len)); 2850 D_SELECT ((stderr, "rxvt_selection_make (): selection.len=%d", selection.len));
2822} 2851}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines