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.32 by pcg, Sun Feb 22 10:38:11 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
1835 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2) 1856 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2)
1836 1857
1837void 1858void
1838rxvt_term::scr_refresh (unsigned char refresh_type) 1859rxvt_term::scr_refresh (unsigned char refresh_type)
1839{ 1860{
1840 unsigned char clearfirst, /* first character writes before cell */ 1861 unsigned char clearfirst, /* first character writes before cell */
1841 clearlast, /* last character writes beyond cell */ 1862 clearlast, /* last character writes beyond cell */
1842 must_clear, /* use draw_string not draw_image_string */ 1863 must_clear, /* use draw_string not draw_image_string */
1843 rvid, /* reverse video this position */ 1864 rvid, /* reverse video this position */
1844 showcursor; /* show the cursor */ 1865 showcursor; /* show the cursor */
1845 int16_t col, row, /* column/row we're processing */ 1866 int16_t col, row, /* column/row we're processing */
1846 ocrow; /* old cursor row */ 1867 ocrow; /* old cursor row */
1847 int cursorwidth;
1848 int i, /* tmp */ 1868 int i, /* tmp */
1849 row_offset; /* basic offset in screen structure */ 1869 row_offset; /* basic offset in screen structure */
1850#ifndef NO_CURSORCOLOR 1870#ifndef NO_CURSORCOLOR
1851 rend_t cc1; /* store colours at cursor position (s) */ 1871 rend_t cc1; /* store colours at cursor position (s) */
1852#endif 1872#endif
1853 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ 1873 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */
1854 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ 1874 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */
1855 1875
1856 if (refresh_type == NO_REFRESH || !TermWin.mapped) 1876 if (refresh_type == NO_REFRESH || !TermWin.mapped)
1857 return; 1877 return;
1858 1878
1859 /* 1879 /*
1891 unsigned char setoldcursor; 1911 unsigned char setoldcursor;
1892 rend_t ccol1, /* Cursor colour */ 1912 rend_t ccol1, /* Cursor colour */
1893 ccol2; /* Cursor colour2 */ 1913 ccol2; /* Cursor colour2 */
1894 1914
1895 showcursor = (screen.flags & Screen_VisibleCursor); 1915 showcursor = (screen.flags & Screen_VisibleCursor);
1896 cursorwidth = 0;
1897#ifdef CURSOR_BLINK 1916#ifdef CURSOR_BLINK
1898 if (hidden_cursor) 1917 if (hidden_cursor)
1899 showcursor = 0; 1918 showcursor = 0;
1900#endif 1919#endif
1901 1920
1902 cursorwidth = 0;
1903
1904 if (showcursor) 1921 if (showcursor)
1905 { 1922 {
1906 cursorwidth++;
1907
1908 srp = & (screen.rend[screen.cur.row + TermWin.saveLines] 1923 srp = & (screen.rend[screen.cur.row + TermWin.saveLines]
1909 [screen.cur.col]); 1924 [screen.cur.col]);
1910 1925
1911 if (showcursor && TermWin.focus) 1926 if (showcursor && TermWin.focus)
1912 { 1927 {
1930 ccol2 = Color_bg; 1945 ccol2 = Color_bg;
1931#endif 1946#endif
1932 *srp = SET_FGCOLOR (*srp, ccol1); 1947 *srp = SET_FGCOLOR (*srp, ccol1);
1933 *srp = SET_BGCOLOR (*srp, ccol2); 1948 *srp = SET_BGCOLOR (*srp, ccol2);
1934#endif 1949#endif
1935
1936 } 1950 }
1937 } 1951 }
1938 1952
1939 /* make sure no outline cursor is left around */ 1953 /* make sure no outline cursor is left around */
1940 setoldcursor = 0; 1954 setoldcursor = 0;
2053 int ypixel = (int)Row2Pixel (row); 2067 int ypixel = (int)Row2Pixel (row);
2054 2068
2055 for (col = 0; col < TermWin.ncol; col++) 2069 for (col = 0; col < TermWin.ncol; col++)
2056 { 2070 {
2057 /* 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
2058 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2084 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2059
2060 if (stp[col] == dtp[col] /* Must match characters to skip. */
2061 && (rend == drp[col] /* Either rendition the same or */
2062 || (stp[col] == ' ' /* space w/ no background change */
2063 && GET_BGATTR (rend) == GET_BGATTR (drp[col]))))
2064 continue;
2065
2066 text_t *text = stp + col; 2085 text_t *text = stp + col;
2067 int count = 1; 2086 int count = 1;
2068 2087
2069 /* redraw one or more characters */
2070
2071 dtp[col] = stp[col]; 2088 dtp[col] = stp[col];
2072 drp[col] = rend; 2089 drp[col] = rend;
2073
2074 if (*text == NOCHAR) // never start redrawing at invisible characters. */
2075 continue;
2076 2090
2077 int xpixel = Col2Pixel (col); 2091 int xpixel = Col2Pixel (col);
2078 2092
2079 // this loop looks very messy, it can probably be optimized 2093 // this loop looks very messy, it can probably be optimized
2080 // and cleaned a bit by you? 2094 // and cleaned a bit by you?
2121 int fore = GET_FGCOLOR (rend); // desired foreground 2135 int fore = GET_FGCOLOR (rend); // desired foreground
2122 int back = GET_BGCOLOR (rend); // desired background 2136 int back = GET_BGCOLOR (rend); // desired background
2123 2137
2124 rend = GET_ATTR (rend); 2138 rend = GET_ATTR (rend);
2125 2139
2126 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
2127 if (rvid) 2158 if (rvid)
2128 { 2159 {
2129 SWAP_IT (fore, back, int); 2160 SWAP_IT (fore, back, int);
2130 2161
2131#ifndef NO_BOLD_UNDERLINE_REVERSE 2162#ifndef NO_BOLD_UNDERLINE_REVERSE
2134 && !ISSET_PIXCOLOR (Color_cursor) 2165 && !ISSET_PIXCOLOR (Color_cursor)
2135# endif 2166# endif
2136 ) 2167 )
2137 back = Color_RV; 2168 back = Color_RV;
2138#endif 2169#endif
2139
2140 } 2170 }
2171
2141#ifdef TEXT_BLINK 2172#ifdef TEXT_BLINK
2142 if (rend & RS_Blink) 2173 if (rend & RS_Blink && back == Color_bg)
2143 { 2174 {
2144 if (!text_blink_ev.active) 2175 if (!text_blink_ev.active)
2145 { 2176 {
2146 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2177 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
2147 hidden_text = 0; 2178 hidden_text = 0;
2148 } 2179 }
2149 else if (hidden_text) 2180 else if (hidden_text)
2150 fore = back; 2181 fore = back;
2151 } 2182 }
2152#endif 2183#endif
2153#ifndef NO_BOLD_UNDERLINE_REVERSE
2154 else if (rend & RS_Bold)
2155 {
2156 if (ISSET_PIXCOLOR (Color_BD))
2157 fore = Color_BD;
2158 else if (fore == Color_fg)
2159 fore = Color_White;
2160 }
2161 else if (rend & RS_Uline)
2162 {
2163 if (ISSET_PIXCOLOR (Color_UL))
2164 fore = Color_UL;
2165 }
2166#endif
2167 2184
2168 /* 2185 /*
2169 * Actually do the drawing of the string here 2186 * Actually do the drawing of the string here
2170 */ 2187 */
2171 rxvt_font *font = (*TermWin.fontset)[fid]; 2188 rxvt_font *font = (*TermWin.fontset)[fid];
2172 2189
2173 if (back == fore) 2190 if (back == fore)
2174 font->clear_rect (xpixel, ypixel, 2191 font->clear_rect (*TermWin.drawable, xpixel, ypixel,
2175 TermWin.fwidth * count, TermWin.fheight, 2192 TermWin.fwidth * count, TermWin.fheight,
2176 back); 2193 back);
2177 else if (back == Color_bg) 2194 else if (back == Color_bg)
2178 { 2195 {
2179 if (must_clear) 2196 if (must_clear)
2181 CLEAR_CHARS (xpixel, ypixel, count); 2198 CLEAR_CHARS (xpixel, ypixel, count);
2182 2199
2183 for (i = 0; i < count; i++) /* don't draw empty strings */ 2200 for (i = 0; i < count; i++) /* don't draw empty strings */
2184 if (text[i] != ' ') 2201 if (text[i] != ' ')
2185 { 2202 {
2186 font->draw (xpixel, ypixel, text, count, fore, -1); 2203 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, -1);
2187 break; 2204 break;
2188 } 2205 }
2189 } 2206 }
2190 else 2207 else
2191 font->draw (xpixel, ypixel, text, count, fore, Color_bg); 2208 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, Color_bg);
2192 } 2209 }
2193 else 2210 else
2194 font->draw (xpixel, ypixel, text, count, fore, back); 2211 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back);
2195 2212
2196 if ((rend & RS_Uline) && (font->descent > 1)) 2213 if ((rend & RS_Uline) && (font->descent > 1))
2197 XDrawLine (display->display, drawBuffer, TermWin.gc, 2214 XDrawLine (display->display, drawBuffer, TermWin.gc,
2198 xpixel, ypixel + font->ascent + 1, 2215 xpixel, ypixel + font->ascent + 1,
2199 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2216 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2200 } /* for (col....) */ 2217 } /* for (col....) */
2201 } /* for (row....) */ 2218 } /* for (row....) */
2202 2219
2203 /* 2220 /*
2204 * G: cleanup cursor and display outline cursor if necessary 2221 * G: cleanup cursor and display outline cursor if necessary
2211 [screen.cur.col]); 2228 [screen.cur.col]);
2212 *srp ^= RS_RVid; 2229 *srp ^= RS_RVid;
2213#ifndef NO_CURSORCOLOR 2230#ifndef NO_CURSORCOLOR
2214 *srp = (*srp & ~ (RS_fgMask | RS_bgMask)) | cc1; 2231 *srp = (*srp & ~ (RS_fgMask | RS_bgMask)) | cc1;
2215#endif 2232#endif
2216
2217 } 2233 }
2218 else if (oldcursor.row >= 0) 2234 else if (oldcursor.row >= 0)
2219 { 2235 {
2220#ifndef NO_CURSORCOLOR 2236#ifndef NO_CURSORCOLOR
2221 if (ISSET_PIXCOLOR (Color_cursor)) 2237 if (ISSET_PIXCOLOR (Color_cursor))
2222 XSetForeground (display->display, TermWin.gc, PixColors[Color_cursor]); 2238 XSetForeground (display->display, TermWin.gc, PixColors[Color_cursor]);
2223#endif 2239#endif
2240 int cursorwidth = 1;
2241 while (oldcursor.col + cursorwidth < TermWin.ncol
2242 && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR)
2243 cursorwidth++;
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 */
2690rxvt_term::selection_clear () 2717rxvt_term::selection_clear ()
2691{ 2718{
2692 D_SELECT ((stderr, "rxvt_selection_clear ()")); 2719 D_SELECT ((stderr, "rxvt_selection_clear ()"));
2693 2720
2694 want_refresh = 1; 2721 want_refresh = 1;
2695 if (selection.text)
2696 free (selection.text); 2722 free (selection.text);
2697 selection.text = NULL; 2723 selection.text = NULL;
2698 selection.len = 0; 2724 selection.len = 0;
2699 CLEAR_SELECTION (); 2725 CLEAR_SELECTION ();
2700} 2726}
2701 2727
2705 * EXT: button 1 or 3 release 2731 * EXT: button 1 or 3 release
2706 */ 2732 */
2707void 2733void
2708rxvt_term::selection_make (Time tm) 2734rxvt_term::selection_make (Time tm)
2709{ 2735{
2710 int i, col, end_col, row, end_row; 2736 int i, col, end_col, row, end_row;
2711 unsigned char *new_selection_text; 2737 unsigned char *new_selection_text;
2712 char *str; 2738 char *str;
2713 text_t *t; 2739 text_t *t;
2714#ifdef ACS_ASCII
2715 rend_t *re;
2716#endif
2717 2740
2718 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));
2719 switch (selection.op) 2742 switch (selection.op)
2720 { 2743 {
2721 case SELECTION_CONT: 2744 case SELECTION_CONT:
2727 selection.op = SELECTION_DONE; 2750 selection.op = SELECTION_DONE;
2728 /* FALLTHROUGH */ 2751 /* FALLTHROUGH */
2729 default: 2752 default:
2730 return; 2753 return;
2731 } 2754 }
2755
2732 selection.op = SELECTION_DONE; 2756 selection.op = SELECTION_DONE;
2733 2757
2734 if (selection.clicks == 4) 2758 if (selection.clicks == 4)
2735 return; /* nothing selected, go away */ 2759 return; /* nothing selected, go away */
2736 2760
2737 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;
2738 str = (char *)rxvt_malloc (i * MB_CUR_MAX + 1); 2762 str = (char *)rxvt_malloc ((i + 2) * MB_CUR_MAX + 1);
2739 2763
2740 new_selection_text = (unsigned char *)str; 2764 new_selection_text = (unsigned char *)str;
2741 2765
2742 col = selection.beg.col; 2766 col = selection.beg.col;
2743 MAX_IT (col, 0); 2767 MAX_IT (col, 0);
2744 row = selection.beg.row + TermWin.saveLines; 2768 row = selection.beg.row + TermWin.saveLines;
2745 end_row = selection.end.row + TermWin.saveLines; 2769 end_row = selection.end.row + TermWin.saveLines;
2770 struct mbstate mbs;
2746 2771
2747 for (; row <= end_row; row++, col = 0) 2772 for (; row <= end_row; row++, col = 0)
2748 { 2773 {
2749 t = & (screen.text[row][col]); 2774 t = & (screen.text[row][col]);
2750 2775
2759 for (; col < end_col; col++) 2784 for (; col < end_col; col++)
2760 if (*t == NOCHAR) 2785 if (*t == NOCHAR)
2761 t++; 2786 t++;
2762 else 2787 else
2763 { 2788 {
2764 int len = wctomb (str, *t++); 2789 int len = wcrtomb (str, *t++, mbs);
2765 if (len > 0) 2790 if (len > 0)
2766 str += len; 2791 str += len;
2767 } 2792 }
2768 2793
2769 if (screen.tlen[row] != -1 && row != end_row) 2794 if (screen.tlen[row] != -1 && row != end_row)
2787 { 2812 {
2788 free (new_selection_text); 2813 free (new_selection_text);
2789 return; 2814 return;
2790 } 2815 }
2791 2816
2792 // 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
2793 if (str - (char *)new_selection_text > 1024) 2818 if (str - (char *)new_selection_text > 1024)
2794 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);
2795 2820
2796 selection.len = i; 2821 selection.len = i;
2797 2822
2811 char *cl = (char *)selection.text; 2836 char *cl = (char *)selection.text;
2812 2837
2813 if (XmbTextListToTextProperty (display->display, &cl, 1, XStringStyle, &ct) >= 0) 2838 if (XmbTextListToTextProperty (display->display, &cl, 1, XStringStyle, &ct) >= 0)
2814 { 2839 {
2815 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 2840 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8,
2816 PropModeReplace, ct.value, ct.nitems); 2841 PropModeReplace, ct.value, ct.nitems);
2817 XFree (ct.value); 2842 XFree (ct.value);
2818 } 2843 }
2819 else 2844 else
2820 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 2845 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8,
2821 PropModeReplace, selection.text, (int)selection.len); 2846 PropModeReplace, selection.text, (int)selection.len);
2822 } 2847 }
2823 2848
2824 selection_time = tm; 2849 selection_time = tm;
2825 D_SELECT ((stderr, "rxvt_selection_make (): selection.len=%d", selection.len)); 2850 D_SELECT ((stderr, "rxvt_selection_make (): selection.len=%d", selection.len));
2826} 2851}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines