1 | /*--------------------------------*-C-*--------------------------------------* |
1 | /*--------------------------------*-C-*--------------------------------------* |
2 | * File: screen.c |
2 | * File: screen.c |
3 | *---------------------------------------------------------------------------* |
3 | *---------------------------------------------------------------------------* |
4 | * $Id: screen.C,v 1.11 2003/12/18 13:33:03 pcg Exp $ |
|
|
5 | * |
4 | * |
6 | * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> |
5 | * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> |
7 | * |
6 | * |
8 | * This program is free software; you can redistribute it and/or modify |
7 | * 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 |
8 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
289 | else if (nrow > prev_nrow) |
288 | else if (nrow > prev_nrow) |
290 | { |
289 | { |
291 | /* add rows */ |
290 | /* add rows */ |
292 | scr_reset_realloc (); /* realloc _first_ */ |
291 | scr_reset_realloc (); /* realloc _first_ */ |
293 | |
292 | |
294 | TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
293 | TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
295 | |
294 | |
296 | k = min (TermWin.nscrolled, nrow - prev_nrow); |
295 | k = min (TermWin.nscrolled, nrow - prev_nrow); |
297 | |
296 | |
298 | for (p = prev_total_rows; p < total_rows; p++) |
297 | for (p = prev_total_rows; p < total_rows; p++) |
299 | { |
298 | { |
… | |
… | |
447 | /* then so is screen.rend[i] */ |
446 | /* then so is screen.rend[i] */ |
448 | assert(screen.rend[i]); |
447 | assert(screen.rend[i]); |
449 | } |
448 | } |
450 | #endif |
449 | #endif |
451 | |
450 | |
452 | delete talloc; |
451 | delete talloc; talloc = 0; |
453 | delete ralloc; |
452 | delete ralloc; ralloc = 0; |
454 | |
453 | |
455 | free (screen.text); |
454 | free (screen.text); |
456 | free (screen.tlen); |
455 | free (screen.tlen); |
457 | free (screen.rend); |
456 | free (screen.rend); |
458 | free (drawn_text); |
457 | free (drawn_text); |
… | |
… | |
899 | case 'z': c = 0x2265; break; case '{': c = 0x03c0; break; case '|': c = 0x2260; break; |
898 | case 'z': c = 0x2265; break; case '{': c = 0x03c0; break; case '|': c = 0x2260; break; |
900 | case '}': c = 0x00a3; break; case '~': c = 0x00b7; break; |
899 | case '}': c = 0x00a3; break; case '~': c = 0x00b7; break; |
901 | } |
900 | } |
902 | |
901 | |
903 | rend_t rend = SET_FONT (R->rstyle, R->TermWin.fontset->find_font (c)); |
902 | rend_t rend = SET_FONT (R->rstyle, R->TermWin.fontset->find_font (c)); |
904 | |
|
|
905 | stp[R->screen.cur.col] = c; |
|
|
906 | srp[R->screen.cur.col] = rend; |
|
|
907 | |
|
|
908 | if (c > 255) |
|
|
909 | { |
|
|
910 | // rely on wcwidth to tell us the character width, at least for non iso-8859-1 |
903 | // rely on wcwidth to tell us the character width, at least for non-ascii |
911 | int width = wcwidth (c); |
904 | int width = c <= 128 ? 1 : wcwidth (c); |
|
|
905 | |
|
|
906 | // width -1 characters (e.g. combining chars) are ignored currently. |
|
|
907 | if (width > 0) |
|
|
908 | do |
912 | |
909 | { |
913 | if (width > 1) |
910 | stp[R->screen.cur.col] = c; |
914 | { |
|
|
915 | while (--width > 0 && R->screen.cur.col < last_col - 1) |
|
|
916 | { |
|
|
917 | |
|
|
918 | srp[R->screen.cur.col] |= RS_wide; |
911 | srp[R->screen.cur.col] = rend; |
919 | |
912 | |
|
|
913 | if (R->screen.cur.col < last_col - 1) |
920 | R->screen.cur.col++; |
914 | R->screen.cur.col++; |
921 | stp[R->screen.cur.col] = NOCHAR; |
915 | else |
922 | srp[R->screen.cur.col] = rend; |
|
|
923 | } |
916 | { |
924 | } |
|
|
925 | } |
|
|
926 | |
|
|
927 | if (R->screen.cur.col < last_col - 1) |
|
|
928 | R->screen.cur.col++; |
|
|
929 | else { |
|
|
930 | R->screen.tlen[row] = last_col; |
917 | R->screen.tlen[row] = last_col; |
931 | if (R->screen.flags & Screen_Autowrap) |
918 | if (R->screen.flags & Screen_Autowrap) |
932 | R->screen.flags |= Screen_WrapNext; |
919 | R->screen.flags |= Screen_WrapNext; |
|
|
920 | break; |
|
|
921 | } |
|
|
922 | |
|
|
923 | c = NOCHAR; |
933 | } |
924 | } |
|
|
925 | while (--width > 0); |
|
|
926 | else |
|
|
927 | 1; /* handle combining character etc. here. */ |
934 | } |
928 | } |
|
|
929 | |
935 | if (R->screen.tlen[row] != -1) /* XXX: think about this */ |
930 | if (R->screen.tlen[row] != -1) /* XXX: think about this */ |
936 | MAX_IT(R->screen.tlen[row], R->screen.cur.col); |
931 | MAX_IT(R->screen.tlen[row], R->screen.cur.col); |
937 | |
932 | |
938 | /* |
933 | /* |
939 | * If we wrote anywhere in the selected area, kill the selection |
934 | * If we wrote anywhere in the selected area, kill the selection |
940 | * XXX: should we kill the mark too? Possibly, but maybe that |
935 | * XXX: should we kill the mark too? Possibly, but maybe that |
941 | * should be a similar check. |
936 | * should be a similar check. |
… | |
… | |
1650 | rxvt_set_font_style(aR); |
1645 | rxvt_set_font_style(aR); |
1651 | } |
1646 | } |
1652 | |
1647 | |
1653 | |
1648 | |
1654 | /* ------------------------------------------------------------------------- * |
1649 | /* ------------------------------------------------------------------------- * |
1655 | * GRAPHICS COLOURS * |
|
|
1656 | * ------------------------------------------------------------------------- */ |
|
|
1657 | |
|
|
1658 | #ifdef RXVT_GRAPHICS |
|
|
1659 | /* EXTPROTO */ |
|
|
1660 | int |
|
|
1661 | rxvt_scr_get_fgcolor(pR) |
|
|
1662 | { |
|
|
1663 | return GET_FGCOLOR(R->rstyle); |
|
|
1664 | } |
|
|
1665 | |
|
|
1666 | /* ------------------------------------------------------------------------- */ |
|
|
1667 | /* EXTPROTO */ |
|
|
1668 | int |
|
|
1669 | rxvt_scr_get_bgcolor(pR) |
|
|
1670 | { |
|
|
1671 | return GET_BGCOLOR(R->rstyle); |
|
|
1672 | } |
|
|
1673 | #endif |
|
|
1674 | |
|
|
1675 | /* ------------------------------------------------------------------------- * |
|
|
1676 | * MAJOR SCREEN MANIPULATION * |
1650 | * MAJOR SCREEN MANIPULATION * |
1677 | * ------------------------------------------------------------------------- */ |
1651 | * ------------------------------------------------------------------------- */ |
|
|
1652 | |
|
|
1653 | /* |
|
|
1654 | * refresh matching text. |
|
|
1655 | */ |
|
|
1656 | bool |
|
|
1657 | rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) |
|
|
1658 | { |
|
|
1659 | bool found = false; |
|
|
1660 | |
|
|
1661 | for (int i = 0; i < TermWin.nrow; i++) |
|
|
1662 | { |
|
|
1663 | int col = 0; |
|
|
1664 | rend_t *drp = drawn_rend [i]; |
|
|
1665 | |
|
|
1666 | for (; col < TermWin.ncol; col++, drp++) |
|
|
1667 | if ((*drp & mask) == value) |
|
|
1668 | { |
|
|
1669 | found = true; |
|
|
1670 | *drp = ~value; |
|
|
1671 | } |
|
|
1672 | } |
|
|
1673 | |
|
|
1674 | return found; |
|
|
1675 | } |
1678 | |
1676 | |
1679 | /* |
1677 | /* |
1680 | * Refresh an area |
1678 | * Refresh an area |
1681 | */ |
1679 | */ |
1682 | enum { |
1680 | enum { |
… | |
… | |
1859 | * Refresh the screen |
1857 | * Refresh the screen |
1860 | * R->drawn_text/R->drawn_rend contain the screen information before the update. |
1858 | * R->drawn_text/R->drawn_rend contain the screen information before the update. |
1861 | * R->screen.text/R->screen.rend contain what the screen will change to. |
1859 | * R->screen.text/R->screen.rend contain what the screen will change to. |
1862 | */ |
1860 | */ |
1863 | |
1861 | |
1864 | #if defined (NO_BRIGHTCOLOR) || defined (VERYBOLD) |
|
|
1865 | # define MONO_BOLD(x) ((x) & (RS_Bold|RS_Blink)) |
|
|
1866 | # define MONO_BOLD_FG(x, fg) MONO_BOLD(x) |
|
|
1867 | #else |
|
|
1868 | # define MONO_BOLD(x) \ |
|
|
1869 | (((x) & (RS_Bold | RS_fgMask)) == (RS_Bold | Color_fg)) |
|
|
1870 | # define MONO_BOLD_FG(x, fg) (((x) & RS_Bold) && (fg) == Color_fg) |
|
|
1871 | #endif |
|
|
1872 | |
|
|
1873 | #define FONT_WIDTH(X, Y) \ |
1862 | #define FONT_WIDTH(X, Y) \ |
1874 | (X)->per_char[(Y) - (X)->min_char_or_byte2].width |
1863 | (X)->per_char[(Y) - (X)->min_char_or_byte2].width |
1875 | #define FONT_RBEAR(X, Y) \ |
1864 | #define FONT_RBEAR(X, Y) \ |
1876 | (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing |
1865 | (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing |
1877 | #define FONT_LBEAR(X, Y) \ |
1866 | #define FONT_LBEAR(X, Y) \ |
… | |
… | |
1883 | rxvt_term::scr_refresh (unsigned char refresh_type) |
1872 | rxvt_term::scr_refresh (unsigned char refresh_type) |
1884 | { |
1873 | { |
1885 | unsigned char clearfirst, /* first character writes before cell */ |
1874 | unsigned char clearfirst, /* first character writes before cell */ |
1886 | clearlast, /* last character writes beyond cell */ |
1875 | clearlast, /* last character writes beyond cell */ |
1887 | must_clear, /* use draw_string not draw_image_string */ |
1876 | must_clear, /* use draw_string not draw_image_string */ |
1888 | #ifndef NO_BOLDFONT |
|
|
1889 | bfont, /* we've changed font to bold font */ |
|
|
1890 | #endif |
|
|
1891 | rvid, /* reverse video this position */ |
1877 | rvid, /* reverse video this position */ |
1892 | wbyte, /* we're in multibyte */ |
|
|
1893 | showcursor; /* show the cursor */ |
1878 | showcursor; /* show the cursor */ |
1894 | int fore, back; /* desired foreground/background */ |
|
|
1895 | int16_t col, row, /* column/row we're processing */ |
1879 | int16_t col, row, /* column/row we're processing */ |
1896 | ocrow; /* old cursor row */ |
1880 | ocrow; /* old cursor row */ |
1897 | int cursorwidth; |
1881 | int cursorwidth; |
1898 | int i, /* tmp */ |
1882 | int i, /* tmp */ |
1899 | row_offset; /* basic offset in screen structure */ |
1883 | row_offset; /* basic offset in screen structure */ |
… | |
… | |
1901 | rend_t cc1; /* store colours at cursor position(s) */ |
1885 | rend_t cc1; /* store colours at cursor position(s) */ |
1902 | rend_t cc2; /* store colours at cursor position(s) */ |
1886 | rend_t cc2; /* store colours at cursor position(s) */ |
1903 | #endif |
1887 | #endif |
1904 | rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ |
1888 | rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ |
1905 | text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ |
1889 | text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ |
1906 | char *buffer; /* local copy of buffer */ |
|
|
1907 | |
1890 | |
1908 | if (refresh_type == NO_REFRESH || !TermWin.mapped) |
1891 | if (refresh_type == NO_REFRESH || !TermWin.mapped) |
1909 | return; |
1892 | return; |
1910 | |
1893 | |
1911 | /* |
1894 | /* |
1912 | * A: set up vars |
1895 | * A: set up vars |
1913 | */ |
1896 | */ |
1914 | clearfirst = clearlast = must_clear = wbyte = 0; |
1897 | clearfirst = clearlast = must_clear = 0; |
1915 | #ifndef NO_BOLDFONT |
|
|
1916 | bfont = 0; |
|
|
1917 | #endif |
|
|
1918 | |
1898 | |
1919 | if (currmaxcol < TermWin.ncol) |
1899 | if (currmaxcol < TermWin.ncol) |
1920 | { |
1900 | { |
1921 | currmaxcol = TermWin.ncol; |
1901 | currmaxcol = TermWin.ncol; |
1922 | buffer = (char *)rxvt_realloc (buffer, |
1902 | buffer = (char *)rxvt_realloc (buffer, |
1923 | sizeof(char) * (currmaxcol + 1) * MB_CUR_MAX); |
1903 | sizeof(char) * (currmaxcol + 1) * MB_CUR_MAX); |
1924 | } |
1904 | } |
1925 | |
1905 | |
1926 | buffer = buffer; |
|
|
1927 | refresh_count = 0; |
1906 | refresh_count = 0; |
1928 | |
1907 | |
1929 | row_offset = TermWin.saveLines - TermWin.view_start; |
1908 | row_offset = TermWin.saveLines - TermWin.view_start; |
1930 | |
1909 | |
1931 | if ((refresh_type & REFRESH_BOUNDS)) |
1910 | if ((refresh_type & REFRESH_BOUNDS)) |
… | |
… | |
1940 | #if defined(TRANSPARENT) |
1919 | #if defined(TRANSPARENT) |
1941 | must_clear |= ((Options & Opt_transparent) && am_transparent); |
1920 | must_clear |= ((Options & Opt_transparent) && am_transparent); |
1942 | #endif |
1921 | #endif |
1943 | ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ |
1922 | ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ |
1944 | |
1923 | |
1945 | /* |
1924 | /* |
1946 | * B: reverse any characters which are selected |
1925 | * B: reverse any characters which are selected |
1947 | */ |
1926 | */ |
1948 | rxvt_scr_reverse_selection (this); |
1927 | rxvt_scr_reverse_selection (this); |
1949 | |
1928 | |
1950 | /* |
1929 | /* |
1951 | * C: set the cursor character(s) |
1930 | * C: set the cursor character(s) |
1952 | */ |
1931 | */ |
1953 | { |
1932 | { |
1954 | unsigned char setoldcursor; |
1933 | unsigned char setoldcursor; |
1955 | rend_t ccol1, /* Cursor colour */ |
1934 | rend_t ccol1, /* Cursor colour */ |
1956 | ccol2; /* Cursor colour2 */ |
1935 | ccol2; /* Cursor colour2 */ |
1957 | |
1936 | |
… | |
… | |
1994 | #endif |
1973 | #endif |
1995 | *srp = SET_FGCOLOR(*srp, ccol1); |
1974 | *srp = SET_FGCOLOR(*srp, ccol1); |
1996 | *srp = SET_BGCOLOR(*srp, ccol2); |
1975 | *srp = SET_BGCOLOR(*srp, ccol2); |
1997 | #endif |
1976 | #endif |
1998 | } |
1977 | } |
1999 | |
|
|
2000 | while (IS_WIDE (*srp)) |
|
|
2001 | cursorwidth++, srp++; |
|
|
2002 | } |
1978 | } |
2003 | |
1979 | |
2004 | /* make sure no outline cursor is left around */ |
1980 | /* make sure no outline cursor is left around */ |
2005 | setoldcursor = 0; |
1981 | setoldcursor = 0; |
2006 | if (ocrow != -1) { |
1982 | if (ocrow != -1) { |
… | |
… | |
2026 | } |
2002 | } |
2027 | } |
2003 | } |
2028 | } |
2004 | } |
2029 | |
2005 | |
2030 | #ifndef NO_SLOW_LINK_SUPPORT |
2006 | #ifndef NO_SLOW_LINK_SUPPORT |
2031 | /* |
2007 | /* |
2032 | * D: CopyArea pass - very useful for slower links |
2008 | * D: CopyArea pass - very useful for slower links |
2033 | * This has been deliberately kept simple. |
2009 | * This has been deliberately kept simple. |
2034 | */ |
2010 | */ |
2035 | i = num_scr; |
2011 | i = num_scr; |
2036 | if (refresh_type == FAST_REFRESH && num_scr_allow && i |
2012 | if (refresh_type == FAST_REFRESH && num_scr_allow && i |
2037 | && abs(i) < TermWin.nrow && !must_clear) |
2013 | && abs(i) < TermWin.nrow && !must_clear) |
2038 | { |
2014 | { |
2039 | int16_t nits; |
2015 | int16_t nits; |
… | |
… | |
2094 | } |
2070 | } |
2095 | } |
2071 | } |
2096 | } |
2072 | } |
2097 | #endif |
2073 | #endif |
2098 | |
2074 | |
2099 | /* |
2075 | /* |
2100 | * E: main pass across every character |
2076 | * E: main pass across every character |
2101 | */ |
2077 | */ |
2102 | for (row = 0; row < TermWin.nrow; row++) |
2078 | for (row = 0; row < TermWin.nrow; row++) |
2103 | { |
2079 | { |
2104 | stp = screen.text[row + row_offset]; |
2080 | stp = screen.text[row + row_offset]; |
2105 | srp = screen.rend[row + row_offset]; |
2081 | srp = screen.rend[row + row_offset]; |
2106 | dtp = drawn_text[row]; |
2082 | dtp = drawn_text[row]; |
2107 | drp = drawn_rend[row]; |
2083 | drp = drawn_rend[row]; |
2108 | |
2084 | |
2109 | /* |
2085 | /* |
2110 | * E2: OK, now the real pass |
2086 | * E2: OK, now the real pass |
2111 | */ |
2087 | */ |
2112 | int ypixel = (int)Row2Pixel(row); |
2088 | int ypixel = (int)Row2Pixel(row); |
2113 | |
2089 | |
2114 | for (col = 0; col < TermWin.ncol; col++) |
2090 | for (col = 0; col < TermWin.ncol; col++) |
2115 | { |
2091 | { |
2116 | /* compare new text with old - if exactly the same then continue */ |
2092 | /* compare new text with old - if exactly the same then continue */ |
… | |
… | |
2149 | i++; |
2125 | i++; |
2150 | |
2126 | |
2151 | continue; |
2127 | continue; |
2152 | } |
2128 | } |
2153 | |
2129 | |
2154 | if (((rend ^ srp[col]) & ~RS_wide) != 0) |
2130 | if (rend != srp[col]) |
2155 | break; |
2131 | break; |
2156 | |
2132 | |
2157 | count++; |
2133 | count++; |
2158 | |
2134 | |
2159 | if (stp[col] != dtp[col] |
2135 | if (stp[col] != dtp[col] |
… | |
… | |
2171 | } |
2147 | } |
2172 | |
2148 | |
2173 | col--; /* went one too far. move back */ |
2149 | col--; /* went one too far. move back */ |
2174 | count -= i; /* dump any matching trailing chars */ |
2150 | count -= i; /* dump any matching trailing chars */ |
2175 | |
2151 | |
2176 | /* |
2152 | /* |
2177 | * Determine the attributes for the string |
2153 | * Determine the attributes for the string |
2178 | */ |
2154 | */ |
2179 | int fid = GET_FONT(rend); |
2155 | int fid = GET_FONT (rend); |
2180 | fore = GET_FGCOLOR(rend); |
2156 | int fore = GET_FGCOLOR (rend); // desired foreground |
2181 | back = GET_BGCOLOR(rend); |
2157 | int back = GET_BGCOLOR (rend); // desired background |
|
|
2158 | |
2182 | rend = GET_ATTR(rend); |
2159 | rend = GET_ATTR (rend); |
2183 | |
2160 | |
2184 | rvid = (rend & RS_RVid) ? 1 : 0; |
2161 | rvid = !!(rend & RS_RVid); |
|
|
2162 | #ifdef TEXT_BLINK |
|
|
2163 | if (rend & RS_Blink) |
|
|
2164 | { |
|
|
2165 | if (!text_blink_ev.active) |
|
|
2166 | { |
|
|
2167 | text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); |
|
|
2168 | hidden_text = 0; |
|
|
2169 | } |
|
|
2170 | else if (hidden_text) |
|
|
2171 | fore = back; |
|
|
2172 | } |
2185 | #ifdef OPTION_HC |
2173 | #elif OPTION_HC |
2186 | if (!rvid && (rend & RS_Blink)) |
2174 | if (!rvid && (rend & RS_Blink)) |
2187 | { |
2175 | { |
2188 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_HC)) |
2176 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_HC)) |
2189 | back = Color_HC; |
2177 | back = Color_HC; |
2190 | else |
2178 | else |
… | |
… | |
2205 | #endif |
2193 | #endif |
2206 | } |
2194 | } |
2207 | #ifndef NO_BOLD_UNDERLINE_REVERSE |
2195 | #ifndef NO_BOLD_UNDERLINE_REVERSE |
2208 | else if (rend & RS_Bold) |
2196 | else if (rend & RS_Bold) |
2209 | { |
2197 | { |
|
|
2198 | if (Xdepth > 2) |
2210 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_BD)) |
2199 | if (ISSET_PIXCOLOR (this, Color_BD)) |
2211 | { |
|
|
2212 | fore = Color_BD; |
2200 | fore = Color_BD; |
2213 | # ifndef VERYBOLD |
|
|
2214 | rend &= ~RS_Bold; /* we've taken care of it */ |
|
|
2215 | # endif |
|
|
2216 | } |
2201 | else |
|
|
2202 | fore = Color_White; |
2217 | } |
2203 | } |
2218 | else if (rend & RS_Uline) |
2204 | else if (rend & RS_Uline) |
2219 | { |
2205 | { |
2220 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_UL)) |
2206 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_UL)) |
2221 | { |
|
|
2222 | fore = Color_UL; |
2207 | fore = Color_UL; |
2223 | rend &= ~RS_Uline; /* we've taken care of it */ |
|
|
2224 | } |
|
|
2225 | } |
2208 | } |
2226 | #endif |
2209 | #endif |
2227 | |
2210 | |
2228 | /* |
2211 | /* |
2229 | * Actually do the drawing of the string here |
2212 | * Actually do the drawing of the string here |
2230 | */ |
2213 | */ |
2231 | rxvt_font *font = (*TermWin.fontset)[fid]; |
2214 | rxvt_font *font = (*TermWin.fontset)[fid]; |
2232 | |
2215 | |
2233 | if (back == Color_bg) |
2216 | if (back == Color_bg) |
2234 | { |
2217 | { |
2235 | if (must_clear) |
2218 | if (must_clear) |
… | |
… | |
2255 | xpixel, ypixel + font->ascent + 1, |
2238 | xpixel, ypixel + font->ascent + 1, |
2256 | xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1); |
2239 | xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1); |
2257 | } /* for (col....) */ |
2240 | } /* for (col....) */ |
2258 | } /* for (row....) */ |
2241 | } /* for (row....) */ |
2259 | |
2242 | |
2260 | /* |
2243 | /* |
2261 | * G: cleanup cursor and display outline cursor if necessary |
2244 | * G: cleanup cursor and display outline cursor if necessary |
2262 | */ |
2245 | */ |
2263 | if (showcursor) { |
2246 | if (showcursor) { |
2264 | if (TermWin.focus) { |
2247 | if (TermWin.focus) { |
2265 | srp = &(screen.rend[screen.cur.row + TermWin.saveLines] |
2248 | srp = &(screen.rend[screen.cur.row + TermWin.saveLines] |
2266 | [screen.cur.col]); |
2249 | [screen.cur.col]); |
2267 | *srp ^= RS_RVid; |
2250 | *srp ^= RS_RVid; |
… | |
… | |
2280 | Row2Pixel(oldcursor.row), |
2263 | Row2Pixel(oldcursor.row), |
2281 | (unsigned int)(Width2Pixel(cursorwidth) - 1), |
2264 | (unsigned int)(Width2Pixel(cursorwidth) - 1), |
2282 | (unsigned int)(Height2Pixel(1) - TermWin.lineSpace - 1)); |
2265 | (unsigned int)(Height2Pixel(1) - TermWin.lineSpace - 1)); |
2283 | } |
2266 | } |
2284 | } |
2267 | } |
2285 | /* |
2268 | |
|
|
2269 | /* |
2286 | * H: cleanup selection |
2270 | * H: cleanup selection |
2287 | */ |
2271 | */ |
2288 | rxvt_scr_reverse_selection (this); |
2272 | rxvt_scr_reverse_selection (this); |
2289 | |
2273 | |
2290 | /* |
2274 | /* |
2291 | * I: other general cleanup |
2275 | * I: other general cleanup |
2292 | */ |
2276 | */ |
2293 | if (clearfirst && TermWin.int_bwidth) |
2277 | if (clearfirst && TermWin.int_bwidth) |
2294 | /* |
2278 | /* |
2295 | * clear the whole screen height, note that width == 0 is treated |
2279 | * clear the whole screen height, note that width == 0 is treated |
2296 | * specially by XClearArea |
2280 | * specially by XClearArea |
2297 | */ |
2281 | */ |
… | |
… | |
2489 | rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) |
2473 | rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) |
2490 | { |
2474 | { |
2491 | long nread = 0; |
2475 | long nread = 0; |
2492 | unsigned long bytes_after; |
2476 | unsigned long bytes_after; |
2493 | XTextProperty ct; |
2477 | XTextProperty ct; |
2494 | int dummy_count; |
|
|
2495 | char **cl; |
|
|
2496 | |
2478 | |
2497 | D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); |
2479 | D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); |
2498 | |
2480 | |
2499 | if (prop == None) /* check for failed XConvertSelection */ |
2481 | if (prop == None) /* check for failed XConvertSelection */ |
2500 | { |
2482 | { |
… | |
… | |
2503 | int selnum = R->selection_type & Sel_whereMask; |
2485 | int selnum = R->selection_type & Sel_whereMask; |
2504 | |
2486 | |
2505 | R->selection_type = 0; |
2487 | R->selection_type = 0; |
2506 | if (selnum != Sel_direct) |
2488 | if (selnum != Sel_direct) |
2507 | rxvt_selection_request_other(aR_ XA_STRING, selnum); |
2489 | rxvt_selection_request_other(aR_ XA_STRING, selnum); |
|
|
2490 | } |
|
|
2491 | |
|
|
2492 | if ((R->selection_type & Sel_UTF8String)) |
|
|
2493 | { |
|
|
2494 | int selnum = R->selection_type & Sel_whereMask; |
|
|
2495 | |
|
|
2496 | R->selection_type = Sel_CompoundText; |
|
|
2497 | if (selnum != Sel_direct) |
|
|
2498 | rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], selnum); |
|
|
2499 | else |
|
|
2500 | R->selection_type = 0; |
2508 | } |
2501 | } |
2509 | |
2502 | |
2510 | return 0; |
2503 | return 0; |
2511 | } |
2504 | } |
2512 | |
2505 | |
… | |
… | |
2547 | nread = -1; /* discount any previous stuff */ |
2540 | nread = -1; /* discount any previous stuff */ |
2548 | break; |
2541 | break; |
2549 | } |
2542 | } |
2550 | |
2543 | |
2551 | nread += ct.nitems; |
2544 | nread += ct.nitems; |
|
|
2545 | |
|
|
2546 | char **cl; |
|
|
2547 | int cr; |
2552 | if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, |
2548 | if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, |
2553 | &dummy_count) == Success && cl) |
2549 | &cr) >= 0 && cl) |
2554 | { |
2550 | { |
|
|
2551 | for (int i = 0; i < cr; i++) |
2555 | R->paste ((unsigned char *)cl[0], STRLEN (cl[0])); |
2552 | R->paste ((unsigned char *)cl[i], STRLEN (cl[i])); |
|
|
2553 | |
2556 | XFreeStringList (cl); |
2554 | XFreeStringList (cl); |
2557 | } |
2555 | } |
2558 | else |
2556 | else |
2559 | R->paste (ct.value, ct.nitems); |
2557 | R->paste (ct.value, ct.nitems); |
2560 | |
2558 | |
… | |
… | |
2575 | } |
2573 | } |
2576 | |
2574 | |
2577 | void |
2575 | void |
2578 | rxvt_term::incr_cb (time_watcher &w) |
2576 | rxvt_term::incr_cb (time_watcher &w) |
2579 | { |
2577 | { |
2580 | w.stop (); |
|
|
2581 | selection_wait = Sel_none; |
2578 | selection_wait = Sel_none; |
2582 | |
2579 | |
2583 | rxvt_print_error("data loss: timeout on INCR selection paste"); |
2580 | rxvt_print_error ("data loss: timeout on INCR selection paste"); |
2584 | } |
2581 | } |
2585 | |
2582 | |
2586 | /* |
2583 | /* |
2587 | * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> |
2584 | * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> |
2588 | */ |
2585 | */ |
… | |
… | |
2654 | int i; |
2651 | int i; |
2655 | |
2652 | |
2656 | R->selection_request_time = tm; |
2653 | R->selection_request_time = tm; |
2657 | R->selection_wait = Sel_normal; |
2654 | R->selection_wait = Sel_normal; |
2658 | for (i = Sel_Primary; i <= Sel_Clipboard; i++) { |
2655 | for (i = Sel_Primary; i <= Sel_Clipboard; i++) { |
|
|
2656 | #if X_HAVE_UTF8_STRING |
|
|
2657 | R->selection_type = Sel_UTF8String; |
|
|
2658 | if (rxvt_selection_request_other(aR_ R->xa[XA_UTF8_STRING], i)) |
|
|
2659 | return; |
|
|
2660 | #else |
2659 | R->selection_type = Sel_CompoundText; |
2661 | R->selection_type = Sel_CompoundText; |
2660 | if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) |
2662 | if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) |
2661 | return; |
2663 | return; |
|
|
2664 | #endif |
2662 | } |
2665 | } |
2663 | } |
2666 | } |
2664 | R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ |
2667 | R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ |
2665 | D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); |
2668 | D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); |
2666 | rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); |
2669 | rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); |
… | |
… | |
2798 | { |
2801 | { |
2799 | free (new_selection_text); |
2802 | free (new_selection_text); |
2800 | return; |
2803 | return; |
2801 | } |
2804 | } |
2802 | |
2805 | |
2803 | // due to MB_MAX_CUR, selection wastage is usually high |
2806 | // due to MB_MAX_CUR, selection wastage is usually high, so realloc |
2804 | if (str - (char *)new_selection_text > 1024) |
2807 | if (str - (char *)new_selection_text > 1024) |
2805 | new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); |
2808 | new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); |
2806 | |
2809 | |
2807 | R->selection.len = i; |
2810 | R->selection.len = i; |
|
|
2811 | |
2808 | if (R->selection.text) |
2812 | if (R->selection.text) |
2809 | free (R->selection.text); |
2813 | free (R->selection.text); |
2810 | |
2814 | |
2811 | R->selection.text = new_selection_text; |
2815 | R->selection.text = new_selection_text; |
2812 | |
2816 | |
2813 | XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); |
2817 | XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); |
2814 | if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) |
2818 | if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) |
2815 | rxvt_print_error("can't get primary selection"); |
2819 | rxvt_print_error("can't get primary selection"); |
|
|
2820 | |
|
|
2821 | |
|
|
2822 | { |
|
|
2823 | XTextProperty ct; |
|
|
2824 | char *cl = (char *)R->selection.text; |
|
|
2825 | |
|
|
2826 | if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, XStringStyle, &ct) >= 0) |
|
|
2827 | { |
|
|
2828 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
|
|
2829 | PropModeReplace, ct.value, ct.nitems); |
|
|
2830 | XFree (ct.value); |
|
|
2831 | } |
|
|
2832 | else |
2816 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
2833 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
2817 | PropModeReplace, R->selection.text, (int)R->selection.len); |
2834 | PropModeReplace, R->selection.text, (int)R->selection.len); |
|
|
2835 | } |
|
|
2836 | |
2818 | R->selection_time = tm; |
2837 | R->selection_time = tm; |
2819 | D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); |
2838 | D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); |
2820 | } |
2839 | } |
2821 | |
2840 | |
2822 | /* ------------------------------------------------------------------------- */ |
2841 | /* ------------------------------------------------------------------------- */ |
… | |
… | |
3274 | /* |
3293 | /* |
3275 | * On some systems, the Atom typedef is 64 bits wide. We need to have a type |
3294 | * On some systems, the Atom typedef is 64 bits wide. We need to have a type |
3276 | * that is exactly 32 bits wide, because a format of 64 is not allowed by |
3295 | * that is exactly 32 bits wide, because a format of 64 is not allowed by |
3277 | * the X11 protocol. |
3296 | * the X11 protocol. |
3278 | */ |
3297 | */ |
3279 | typedef CARD32 Atom32; |
3298 | typedef CARD32 Atom32; |
3280 | |
3299 | |
3281 | /* ------------------------------------------------------------------------- */ |
3300 | /* ------------------------------------------------------------------------- */ |
3282 | /* |
3301 | /* |
3283 | * Respond to a request for our current selection |
3302 | * Respond to a request for our current selection |
3284 | * EXT: SelectionRequest |
3303 | * EXT: SelectionRequest |
… | |
… | |
3286 | /* EXTPROTO */ |
3305 | /* EXTPROTO */ |
3287 | void |
3306 | void |
3288 | rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) |
3307 | rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) |
3289 | { |
3308 | { |
3290 | XSelectionEvent ev; |
3309 | XSelectionEvent ev; |
3291 | #ifdef USE_XIM |
|
|
3292 | Atom32 target_list[4]; |
|
|
3293 | #else |
|
|
3294 | Atom32 target_list[3]; |
|
|
3295 | #endif |
|
|
3296 | Atom target; |
|
|
3297 | XTextProperty ct; |
3310 | XTextProperty ct; |
3298 | XICCEncodingStyle style; |
3311 | XICCEncodingStyle style; |
3299 | char *cl[2], dummy[1]; |
3312 | Atom target; |
3300 | |
3313 | |
3301 | ev.type = SelectionNotify; |
3314 | ev.type = SelectionNotify; |
3302 | ev.property = None; |
3315 | ev.property = None; |
3303 | ev.display = rq->display; |
3316 | ev.display = rq->display; |
3304 | ev.requestor = rq->requestor; |
3317 | ev.requestor = rq->requestor; |
3305 | ev.selection = rq->selection; |
3318 | ev.selection = rq->selection; |
3306 | ev.target = rq->target; |
3319 | ev.target = rq->target; |
3307 | ev.time = rq->time; |
3320 | ev.time = rq->time; |
3308 | |
3321 | |
3309 | if (rq->target == R->xa[XA_TARGETS]) { |
3322 | if (rq->target == R->xa[XA_TARGETS]) { |
|
|
3323 | Atom32 target_list[5]; |
|
|
3324 | Atom32 *target = target_list; |
|
|
3325 | |
3310 | target_list[0] = (Atom32) R->xa[XA_TARGETS]; |
3326 | *target++ = (Atom32) R->xa[XA_TARGETS]; |
3311 | target_list[1] = (Atom32) XA_STRING; |
3327 | *target++ = (Atom32) XA_STRING; |
3312 | target_list[2] = (Atom32) R->xa[XA_TEXT]; |
3328 | *target++ = (Atom32) R->xa[XA_TEXT]; |
3313 | #ifdef USE_XIM |
|
|
3314 | target_list[3] = (Atom32) R->xa[XA_COMPOUND_TEXT]; |
3329 | *target++ = (Atom32) R->xa[XA_COMPOUND_TEXT]; |
|
|
3330 | #if X_HAVE_UTF8_STRING |
|
|
3331 | *target++ = (Atom32) R->xa[XA_UTF8_STRING]; |
3315 | #endif |
3332 | #endif |
3316 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, |
3333 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, |
3317 | (8 * sizeof(target_list[0])), PropModeReplace, |
3334 | (8 * sizeof(target_list[0])), PropModeReplace, |
3318 | (unsigned char *)target_list, |
3335 | (unsigned char *)target_list, |
3319 | (sizeof(target_list) / sizeof(target_list[0]))); |
3336 | target - target_list); |
3320 | ev.property = rq->property; |
3337 | ev.property = rq->property; |
3321 | } else if (rq->target == R->xa[XA_MULTIPLE]) { |
3338 | } else if (rq->target == R->xa[XA_MULTIPLE]) { |
3322 | /* TODO: Handle MULTIPLE */ |
3339 | /* TODO: Handle MULTIPLE */ |
3323 | } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { |
3340 | } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { |
3324 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, |
3341 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, |
3325 | (8 * sizeof(Time)), PropModeReplace, |
3342 | (8 * sizeof(Time)), PropModeReplace, |
3326 | (unsigned char *)&R->selection_time, 1); |
3343 | (unsigned char *)&R->selection_time, 1); |
3327 | ev.property = rq->property; |
3344 | ev.property = rq->property; |
3328 | } else if (rq->target == XA_STRING |
3345 | } else if (rq->target == XA_STRING |
|
|
3346 | || rq->target == R->xa[XA_TEXT] |
3329 | || rq->target == R->xa[XA_COMPOUND_TEXT] |
3347 | || rq->target == R->xa[XA_COMPOUND_TEXT] |
3330 | || rq->target == R->xa[XA_TEXT]) { |
3348 | || rq->target == R->xa[XA_UTF8_STRING] |
3331 | #ifdef USE_XIM |
3349 | ) { |
3332 | short freect = 0; |
3350 | short freect = 0; |
3333 | #endif |
|
|
3334 | int selectlen; |
3351 | int selectlen; |
|
|
3352 | char *cl; |
3335 | |
3353 | |
3336 | #ifdef USE_XIM |
3354 | target = rq->target; |
|
|
3355 | |
3337 | if (rq->target != XA_STRING) { |
3356 | if (target == XA_STRING) |
|
|
3357 | // we actually don't do XA_STRING, but who cares, as i18n clients |
|
|
3358 | // will ask for another format anyways. |
|
|
3359 | style = XStringStyle; |
|
|
3360 | else if (target == R->xa[XA_TEXT]) |
|
|
3361 | style = XTextStyle; |
|
|
3362 | else if (target == R->xa[XA_COMPOUND_TEXT]) |
|
|
3363 | style = XCompoundTextStyle; |
|
|
3364 | #if X_HAVE_UTF8_STRING |
|
|
3365 | else if (target == R->xa[XA_UTF8_STRING]) |
|
|
3366 | style = XUTF8StringStyle; |
|
|
3367 | #endif |
|
|
3368 | else |
|
|
3369 | { |
3338 | target = R->xa[XA_COMPOUND_TEXT]; |
3370 | target = R->xa[XA_COMPOUND_TEXT]; |
3339 | style = (rq->target == R->xa[XA_COMPOUND_TEXT]) |
|
|
3340 | ? XCompoundTextStyle : XStdICCTextStyle; |
|
|
3341 | } else |
|
|
3342 | #endif |
|
|
3343 | { |
|
|
3344 | target = XA_STRING; |
|
|
3345 | style = XStringStyle; |
3371 | style = XCompoundTextStyle; |
3346 | } |
3372 | } |
|
|
3373 | |
3347 | if (R->selection.text) { |
3374 | if (R->selection.text) { |
3348 | cl[0] = (char *)R->selection.text; |
3375 | cl = (char *)R->selection.text; |
3349 | selectlen = R->selection.len; |
3376 | selectlen = R->selection.len; |
3350 | } else { |
3377 | } else { |
3351 | cl[0] = dummy; |
3378 | cl = ""; |
3352 | *dummy = '\0'; |
|
|
3353 | selectlen = 0; |
3379 | selectlen = 0; |
3354 | } |
3380 | } |
3355 | #ifdef USE_XIM |
3381 | |
3356 | if (XmbTextListToTextProperty(R->Xdisplay, cl, 1, style, &ct) |
3382 | if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, style, &ct) >= 0) |
3357 | == Success) /* if we failed to convert then send it raw */ |
|
|
3358 | freect = 1; |
3383 | freect = 1; |
3359 | else |
3384 | else |
3360 | #endif |
|
|
3361 | { |
3385 | { |
|
|
3386 | /* if we failed to convert then send it raw */ |
3362 | ct.value = (unsigned char *)cl[0]; |
3387 | ct.value = (unsigned char *)cl; |
3363 | ct.nitems = selectlen; |
3388 | ct.nitems = selectlen; |
3364 | } |
3389 | } |
|
|
3390 | |
3365 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, |
3391 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, |
3366 | target, 8, PropModeReplace, |
3392 | target, 8, PropModeReplace, |
3367 | ct.value, (int)ct.nitems); |
3393 | ct.value, (int)ct.nitems); |
3368 | ev.property = rq->property; |
3394 | ev.property = rq->property; |
3369 | #ifdef USE_XIM |
3395 | |
3370 | if (freect) |
3396 | if (freect) |
3371 | XFree(ct.value); |
3397 | XFree (ct.value); |
3372 | #endif |
|
|
3373 | } |
3398 | } |
3374 | XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); |
3399 | XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); |
3375 | } |
3400 | } |
3376 | |
3401 | |
3377 | /* ------------------------------------------------------------------------- * |
3402 | /* ------------------------------------------------------------------------- * |