1 | /*--------------------------------*-C-*--------------------------------------* |
1 | /*--------------------------------*-C-*--------------------------------------* |
2 | * File: screen.c |
2 | * File: screen.c |
3 | *---------------------------------------------------------------------------* |
3 | *---------------------------------------------------------------------------* |
4 | * $Id: screen.C,v 1.14 2003/12/26 07:42:23 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 |
… | |
… | |
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); |
… | |
… | |
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 | // rely on wcwidth to tell us the character width, at least for non-ascii |
903 | // rely on wcwidth to tell us the character width, at least for non-ascii |
905 | int width = c <= 128 ? 1 : wcwidth (c); |
904 | int width = c <= 128 ? 1 : wcwidth (c); |
906 | |
905 | |
907 | // width 0 characters (e.g. combining chars) are ignored. your problem, really |
906 | // width -1 characters (e.g. combining chars) are ignored currently. |
908 | while (width-- > 0) |
907 | if (width > 0) |
|
|
908 | do |
909 | { |
909 | { |
910 | stp[R->screen.cur.col] = c; |
910 | stp[R->screen.cur.col] = c; |
911 | srp[R->screen.cur.col] = rend; |
911 | srp[R->screen.cur.col] = rend; |
912 | |
912 | |
913 | if (R->screen.cur.col < last_col - 1) |
913 | if (R->screen.cur.col < last_col - 1) |
914 | R->screen.cur.col++; |
914 | R->screen.cur.col++; |
915 | else |
915 | else |
916 | { |
916 | { |
917 | R->screen.tlen[row] = last_col; |
917 | R->screen.tlen[row] = last_col; |
918 | if (R->screen.flags & Screen_Autowrap) |
918 | if (R->screen.flags & Screen_Autowrap) |
919 | R->screen.flags |= Screen_WrapNext; |
919 | R->screen.flags |= Screen_WrapNext; |
920 | break; |
920 | break; |
921 | } |
921 | } |
922 | |
922 | |
923 | c = NOCHAR; |
923 | c = NOCHAR; |
924 | } |
924 | } |
|
|
925 | while (--width > 0); |
|
|
926 | else |
|
|
927 | 1; /* handle combining character etc. here. */ |
925 | } |
928 | } |
|
|
929 | |
926 | if (R->screen.tlen[row] != -1) /* XXX: think about this */ |
930 | if (R->screen.tlen[row] != -1) /* XXX: think about this */ |
927 | MAX_IT(R->screen.tlen[row], R->screen.cur.col); |
931 | MAX_IT(R->screen.tlen[row], R->screen.cur.col); |
928 | |
932 | |
929 | /* |
933 | /* |
930 | * If we wrote anywhere in the selected area, kill the selection |
934 | * If we wrote anywhere in the selected area, kill the selection |
931 | * XXX: should we kill the mark too? Possibly, but maybe that |
935 | * XXX: should we kill the mark too? Possibly, but maybe that |
932 | * should be a similar check. |
936 | * should be a similar check. |
… | |
… | |
1641 | rxvt_set_font_style(aR); |
1645 | rxvt_set_font_style(aR); |
1642 | } |
1646 | } |
1643 | |
1647 | |
1644 | |
1648 | |
1645 | /* ------------------------------------------------------------------------- * |
1649 | /* ------------------------------------------------------------------------- * |
1646 | * GRAPHICS COLOURS * |
|
|
1647 | * ------------------------------------------------------------------------- */ |
|
|
1648 | |
|
|
1649 | #ifdef RXVT_GRAPHICS |
|
|
1650 | /* EXTPROTO */ |
|
|
1651 | int |
|
|
1652 | rxvt_scr_get_fgcolor(pR) |
|
|
1653 | { |
|
|
1654 | return GET_FGCOLOR(R->rstyle); |
|
|
1655 | } |
|
|
1656 | |
|
|
1657 | /* ------------------------------------------------------------------------- */ |
|
|
1658 | /* EXTPROTO */ |
|
|
1659 | int |
|
|
1660 | rxvt_scr_get_bgcolor(pR) |
|
|
1661 | { |
|
|
1662 | return GET_BGCOLOR(R->rstyle); |
|
|
1663 | } |
|
|
1664 | #endif |
|
|
1665 | |
|
|
1666 | /* ------------------------------------------------------------------------- * |
|
|
1667 | * MAJOR SCREEN MANIPULATION * |
1650 | * MAJOR SCREEN MANIPULATION * |
1668 | * ------------------------------------------------------------------------- */ |
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 | } |
1669 | |
1676 | |
1670 | /* |
1677 | /* |
1671 | * Refresh an area |
1678 | * Refresh an area |
1672 | */ |
1679 | */ |
1673 | enum { |
1680 | enum { |
… | |
… | |
1850 | * Refresh the screen |
1857 | * Refresh the screen |
1851 | * 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. |
1852 | * 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. |
1853 | */ |
1860 | */ |
1854 | |
1861 | |
1855 | #if defined (NO_BRIGHTCOLOR) || defined (VERYBOLD) |
|
|
1856 | # define MONO_BOLD(x) ((x) & (RS_Bold|RS_Blink)) |
|
|
1857 | # define MONO_BOLD_FG(x, fg) MONO_BOLD(x) |
|
|
1858 | #else |
|
|
1859 | # define MONO_BOLD(x) \ |
|
|
1860 | (((x) & (RS_Bold | RS_fgMask)) == (RS_Bold | Color_fg)) |
|
|
1861 | # define MONO_BOLD_FG(x, fg) (((x) & RS_Bold) && (fg) == Color_fg) |
|
|
1862 | #endif |
|
|
1863 | |
|
|
1864 | #define FONT_WIDTH(X, Y) \ |
1862 | #define FONT_WIDTH(X, Y) \ |
1865 | (X)->per_char[(Y) - (X)->min_char_or_byte2].width |
1863 | (X)->per_char[(Y) - (X)->min_char_or_byte2].width |
1866 | #define FONT_RBEAR(X, Y) \ |
1864 | #define FONT_RBEAR(X, Y) \ |
1867 | (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing |
1865 | (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing |
1868 | #define FONT_LBEAR(X, Y) \ |
1866 | #define FONT_LBEAR(X, Y) \ |
… | |
… | |
1874 | rxvt_term::scr_refresh (unsigned char refresh_type) |
1872 | rxvt_term::scr_refresh (unsigned char refresh_type) |
1875 | { |
1873 | { |
1876 | unsigned char clearfirst, /* first character writes before cell */ |
1874 | unsigned char clearfirst, /* first character writes before cell */ |
1877 | clearlast, /* last character writes beyond cell */ |
1875 | clearlast, /* last character writes beyond cell */ |
1878 | must_clear, /* use draw_string not draw_image_string */ |
1876 | must_clear, /* use draw_string not draw_image_string */ |
1879 | #ifndef NO_BOLDFONT |
|
|
1880 | bfont, /* we've changed font to bold font */ |
|
|
1881 | #endif |
|
|
1882 | rvid, /* reverse video this position */ |
1877 | rvid, /* reverse video this position */ |
1883 | wbyte, /* we're in multibyte */ |
|
|
1884 | showcursor; /* show the cursor */ |
1878 | showcursor; /* show the cursor */ |
1885 | int fore, back; /* desired foreground/background */ |
|
|
1886 | int16_t col, row, /* column/row we're processing */ |
1879 | int16_t col, row, /* column/row we're processing */ |
1887 | ocrow; /* old cursor row */ |
1880 | ocrow; /* old cursor row */ |
1888 | int cursorwidth; |
1881 | int cursorwidth; |
1889 | int i, /* tmp */ |
1882 | int i, /* tmp */ |
1890 | row_offset; /* basic offset in screen structure */ |
1883 | row_offset; /* basic offset in screen structure */ |
… | |
… | |
1899 | return; |
1892 | return; |
1900 | |
1893 | |
1901 | /* |
1894 | /* |
1902 | * A: set up vars |
1895 | * A: set up vars |
1903 | */ |
1896 | */ |
1904 | clearfirst = clearlast = must_clear = wbyte = 0; |
1897 | clearfirst = clearlast = must_clear = 0; |
1905 | #ifndef NO_BOLDFONT |
|
|
1906 | bfont = 0; |
|
|
1907 | #endif |
|
|
1908 | |
|
|
1909 | if (currmaxcol < TermWin.ncol) |
|
|
1910 | { |
|
|
1911 | currmaxcol = TermWin.ncol; |
|
|
1912 | buffer = (char *)rxvt_realloc (buffer, |
|
|
1913 | sizeof(char) * (currmaxcol + 1) * MB_CUR_MAX); |
|
|
1914 | } |
|
|
1915 | |
1898 | |
1916 | refresh_count = 0; |
1899 | refresh_count = 0; |
1917 | |
1900 | |
1918 | row_offset = TermWin.saveLines - TermWin.view_start; |
1901 | row_offset = TermWin.saveLines - TermWin.view_start; |
1919 | |
1902 | |
… | |
… | |
1963 | if (showcursor && TermWin.focus) |
1946 | if (showcursor && TermWin.focus) |
1964 | { |
1947 | { |
1965 | *srp ^= RS_RVid; |
1948 | *srp ^= RS_RVid; |
1966 | #ifndef NO_CURSORCOLOR |
1949 | #ifndef NO_CURSORCOLOR |
1967 | cc1 = *srp & (RS_fgMask | RS_bgMask); |
1950 | cc1 = *srp & (RS_fgMask | RS_bgMask); |
1968 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor)) |
1951 | if (ISSET_PIXCOLOR (this, Color_cursor)) |
1969 | ccol1 = Color_cursor; |
1952 | ccol1 = Color_cursor; |
1970 | else |
1953 | else |
1971 | #ifdef CURSOR_COLOR_IS_RENDITION_COLOR |
1954 | #ifdef CURSOR_COLOR_IS_RENDITION_COLOR |
1972 | ccol1 = GET_FGCOLOR(rstyle); |
1955 | ccol1 = GET_FGCOLOR(rstyle); |
1973 | #else |
1956 | #else |
1974 | ccol1 = Color_fg; |
1957 | ccol1 = Color_fg; |
1975 | #endif |
1958 | #endif |
1976 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor2)) |
1959 | if (ISSET_PIXCOLOR (this, Color_cursor2)) |
1977 | ccol2 = Color_cursor2; |
1960 | ccol2 = Color_cursor2; |
1978 | else |
1961 | else |
1979 | #ifdef CURSOR_COLOR_IS_RENDITION_COLOR |
1962 | #ifdef CURSOR_COLOR_IS_RENDITION_COLOR |
1980 | ccol2 = GET_BGCOLOR(rstyle); |
1963 | ccol2 = GET_BGCOLOR(rstyle); |
1981 | #else |
1964 | #else |
… | |
… | |
1983 | #endif |
1966 | #endif |
1984 | *srp = SET_FGCOLOR(*srp, ccol1); |
1967 | *srp = SET_FGCOLOR(*srp, ccol1); |
1985 | *srp = SET_BGCOLOR(*srp, ccol2); |
1968 | *srp = SET_BGCOLOR(*srp, ccol2); |
1986 | #endif |
1969 | #endif |
1987 | } |
1970 | } |
1988 | |
|
|
1989 | while (IS_WIDE (*srp)) |
|
|
1990 | cursorwidth++, srp++; |
|
|
1991 | } |
1971 | } |
1992 | |
1972 | |
1993 | /* make sure no outline cursor is left around */ |
1973 | /* make sure no outline cursor is left around */ |
1994 | setoldcursor = 0; |
1974 | setoldcursor = 0; |
1995 | if (ocrow != -1) { |
1975 | if (ocrow != -1) { |
… | |
… | |
2138 | i++; |
2118 | i++; |
2139 | |
2119 | |
2140 | continue; |
2120 | continue; |
2141 | } |
2121 | } |
2142 | |
2122 | |
2143 | if (((rend ^ srp[col]) & ~RS_wide) != 0) |
2123 | if (rend != srp[col]) |
2144 | break; |
2124 | break; |
2145 | |
2125 | |
2146 | count++; |
2126 | count++; |
2147 | |
2127 | |
2148 | if (stp[col] != dtp[col] |
2128 | if (stp[col] != dtp[col] |
… | |
… | |
2163 | count -= i; /* dump any matching trailing chars */ |
2143 | count -= i; /* dump any matching trailing chars */ |
2164 | |
2144 | |
2165 | /* |
2145 | /* |
2166 | * Determine the attributes for the string |
2146 | * Determine the attributes for the string |
2167 | */ |
2147 | */ |
2168 | int fid = GET_FONT(rend); |
2148 | int fid = GET_FONT (rend); |
2169 | fore = GET_FGCOLOR(rend); |
2149 | int fore = GET_FGCOLOR (rend); // desired foreground |
2170 | back = GET_BGCOLOR(rend); |
2150 | int back = GET_BGCOLOR (rend); // desired background |
|
|
2151 | |
2171 | rend = GET_ATTR(rend); |
2152 | rend = GET_ATTR (rend); |
2172 | |
2153 | |
2173 | rvid = (rend & RS_RVid) ? 1 : 0; |
2154 | rvid = !!(rend & RS_RVid); |
2174 | #ifdef OPTION_HC |
2155 | #ifdef TEXT_BLINK |
2175 | if (!rvid && (rend & RS_Blink)) |
2156 | if (rend & RS_Blink) |
2176 | { |
2157 | { |
2177 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_HC)) |
2158 | if (!text_blink_ev.active) |
2178 | back = Color_HC; |
|
|
2179 | else |
2159 | { |
2180 | rvid = !rvid; /* fall back */ |
2160 | text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); |
|
|
2161 | hidden_text = 0; |
|
|
2162 | } |
|
|
2163 | else if (hidden_text) |
|
|
2164 | fore = back; |
2181 | } |
2165 | } |
2182 | #endif |
2166 | #endif |
2183 | if (rvid) |
2167 | if (rvid) |
2184 | { |
2168 | { |
2185 | SWAP_IT(fore, back, int); |
2169 | SWAP_IT(fore, back, int); |
2186 | |
2170 | |
2187 | #ifndef NO_BOLD_UNDERLINE_REVERSE |
2171 | #ifndef NO_BOLD_UNDERLINE_REVERSE |
2188 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_RV) |
2172 | if (ISSET_PIXCOLOR (this, Color_RV) |
2189 | # ifndef NO_CURSORCOLOR |
2173 | # ifndef NO_CURSORCOLOR |
2190 | && !ISSET_PIXCOLOR (this, Color_cursor) |
2174 | && !ISSET_PIXCOLOR (this, Color_cursor) |
2191 | # endif |
2175 | # endif |
2192 | ) |
2176 | ) |
2193 | back = Color_RV; |
2177 | back = Color_RV; |
2194 | #endif |
2178 | #endif |
2195 | } |
2179 | } |
2196 | #ifndef NO_BOLD_UNDERLINE_REVERSE |
2180 | #ifndef NO_BOLD_UNDERLINE_REVERSE |
2197 | else if (rend & RS_Bold) |
2181 | else if (rend & RS_Bold) |
2198 | { |
2182 | { |
2199 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_BD)) |
2183 | if (ISSET_PIXCOLOR (this, Color_BD)) |
2200 | { |
|
|
2201 | fore = Color_BD; |
2184 | fore = Color_BD; |
2202 | # ifndef VERYBOLD |
2185 | else if (fore == Color_fg) |
2203 | rend &= ~RS_Bold; /* we've taken care of it */ |
2186 | fore = Color_White; |
2204 | # endif |
|
|
2205 | } |
|
|
2206 | } |
2187 | } |
2207 | else if (rend & RS_Uline) |
2188 | else if (rend & RS_Uline) |
2208 | { |
2189 | { |
2209 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_UL)) |
2190 | if (ISSET_PIXCOLOR (this, Color_UL)) |
2210 | { |
|
|
2211 | fore = Color_UL; |
2191 | fore = Color_UL; |
2212 | rend &= ~RS_Uline; /* we've taken care of it */ |
|
|
2213 | } |
|
|
2214 | } |
2192 | } |
2215 | #endif |
2193 | #endif |
2216 | |
2194 | |
2217 | /* |
2195 | /* |
2218 | * Actually do the drawing of the string here |
2196 | * Actually do the drawing of the string here |
… | |
… | |
2259 | #endif |
2237 | #endif |
2260 | } else if (oldcursor.row >= 0) { |
2238 | } else if (oldcursor.row >= 0) { |
2261 | #ifndef NO_CURSORCOLOR |
2239 | #ifndef NO_CURSORCOLOR |
2262 | unsigned long gcmask; /* Graphics Context mask */ |
2240 | unsigned long gcmask; /* Graphics Context mask */ |
2263 | |
2241 | |
2264 | if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor)) |
2242 | if (ISSET_PIXCOLOR (this, Color_cursor)) |
2265 | XSetForeground (Xdisplay, TermWin.gc, PixColors[Color_cursor]); |
2243 | XSetForeground (Xdisplay, TermWin.gc, PixColors[Color_cursor]); |
2266 | #endif |
2244 | #endif |
2267 | XDrawRectangle(Xdisplay, drawBuffer, TermWin.gc, |
2245 | XDrawRectangle(Xdisplay, drawBuffer, TermWin.gc, |
2268 | Col2Pixel(oldcursor.col), |
2246 | Col2Pixel(oldcursor.col), |
2269 | Row2Pixel(oldcursor.row), |
2247 | Row2Pixel(oldcursor.row), |
… | |
… | |
2352 | i = end_row; |
2330 | i = end_row; |
2353 | } |
2331 | } |
2354 | end_row += R->TermWin.nrow; |
2332 | end_row += R->TermWin.nrow; |
2355 | for (; i < row && i < end_row; i++, col = 0) |
2333 | for (; i < row && i < end_row; i++, col = 0) |
2356 | for (srp = R->screen.rend[i]; col < R->TermWin.ncol; col++) |
2334 | for (srp = R->screen.rend[i]; col < R->TermWin.ncol; col++) |
2357 | #ifndef OPTION_HC |
|
|
2358 | srp[col] ^= RS_RVid; |
2335 | srp[col] ^= RS_RVid; |
2359 | #else |
|
|
2360 | srp[col] ^= RS_Blink; |
|
|
2361 | #endif |
|
|
2362 | if (i == row && i < end_row) |
2336 | if (i == row && i < end_row) |
2363 | for (srp = R->screen.rend[i]; col < R->selection.end.col; col++) |
2337 | for (srp = R->screen.rend[i]; col < R->selection.end.col; col++) |
2364 | #ifndef OPTION_HC |
|
|
2365 | srp[col] ^= RS_RVid; |
2338 | srp[col] ^= RS_RVid; |
2366 | #else |
|
|
2367 | srp[col] ^= RS_Blink; |
|
|
2368 | #endif |
|
|
2369 | } |
2339 | } |
2370 | } |
2340 | } |
2371 | |
2341 | |
2372 | /* ------------------------------------------------------------------------- */ |
2342 | /* ------------------------------------------------------------------------- */ |
2373 | /* |
2343 | /* |
… | |
… | |
2479 | rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) |
2449 | rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) |
2480 | { |
2450 | { |
2481 | long nread = 0; |
2451 | long nread = 0; |
2482 | unsigned long bytes_after; |
2452 | unsigned long bytes_after; |
2483 | XTextProperty ct; |
2453 | XTextProperty ct; |
2484 | int dummy_count; |
|
|
2485 | char **cl; |
|
|
2486 | |
2454 | |
2487 | D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); |
2455 | D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); |
2488 | |
2456 | |
2489 | if (prop == None) /* check for failed XConvertSelection */ |
2457 | if (prop == None) /* check for failed XConvertSelection */ |
2490 | { |
2458 | { |
… | |
… | |
2493 | int selnum = R->selection_type & Sel_whereMask; |
2461 | int selnum = R->selection_type & Sel_whereMask; |
2494 | |
2462 | |
2495 | R->selection_type = 0; |
2463 | R->selection_type = 0; |
2496 | if (selnum != Sel_direct) |
2464 | if (selnum != Sel_direct) |
2497 | rxvt_selection_request_other(aR_ XA_STRING, selnum); |
2465 | rxvt_selection_request_other(aR_ XA_STRING, selnum); |
|
|
2466 | } |
|
|
2467 | |
|
|
2468 | if ((R->selection_type & Sel_UTF8String)) |
|
|
2469 | { |
|
|
2470 | int selnum = R->selection_type & Sel_whereMask; |
|
|
2471 | |
|
|
2472 | R->selection_type = Sel_CompoundText; |
|
|
2473 | if (selnum != Sel_direct) |
|
|
2474 | rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], selnum); |
|
|
2475 | else |
|
|
2476 | R->selection_type = 0; |
2498 | } |
2477 | } |
2499 | |
2478 | |
2500 | return 0; |
2479 | return 0; |
2501 | } |
2480 | } |
2502 | |
2481 | |
… | |
… | |
2537 | nread = -1; /* discount any previous stuff */ |
2516 | nread = -1; /* discount any previous stuff */ |
2538 | break; |
2517 | break; |
2539 | } |
2518 | } |
2540 | |
2519 | |
2541 | nread += ct.nitems; |
2520 | nread += ct.nitems; |
|
|
2521 | |
|
|
2522 | char **cl; |
|
|
2523 | int cr; |
2542 | if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, |
2524 | if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, |
2543 | &dummy_count) == Success && cl) |
2525 | &cr) >= 0 && cl) |
2544 | { |
2526 | { |
|
|
2527 | for (int i = 0; i < cr; i++) |
2545 | R->paste ((unsigned char *)cl[0], STRLEN (cl[0])); |
2528 | R->paste ((unsigned char *)cl[i], STRLEN (cl[i])); |
|
|
2529 | |
2546 | XFreeStringList (cl); |
2530 | XFreeStringList (cl); |
2547 | } |
2531 | } |
2548 | else |
2532 | else |
2549 | R->paste (ct.value, ct.nitems); |
2533 | R->paste (ct.value, ct.nitems); |
2550 | |
2534 | |
… | |
… | |
2565 | } |
2549 | } |
2566 | |
2550 | |
2567 | void |
2551 | void |
2568 | rxvt_term::incr_cb (time_watcher &w) |
2552 | rxvt_term::incr_cb (time_watcher &w) |
2569 | { |
2553 | { |
2570 | w.stop (); |
|
|
2571 | selection_wait = Sel_none; |
2554 | selection_wait = Sel_none; |
2572 | |
2555 | |
2573 | rxvt_print_error("data loss: timeout on INCR selection paste"); |
2556 | rxvt_print_error ("data loss: timeout on INCR selection paste"); |
2574 | } |
2557 | } |
2575 | |
2558 | |
2576 | /* |
2559 | /* |
2577 | * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> |
2560 | * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> |
2578 | */ |
2561 | */ |
… | |
… | |
2644 | int i; |
2627 | int i; |
2645 | |
2628 | |
2646 | R->selection_request_time = tm; |
2629 | R->selection_request_time = tm; |
2647 | R->selection_wait = Sel_normal; |
2630 | R->selection_wait = Sel_normal; |
2648 | for (i = Sel_Primary; i <= Sel_Clipboard; i++) { |
2631 | for (i = Sel_Primary; i <= Sel_Clipboard; i++) { |
|
|
2632 | #if X_HAVE_UTF8_STRING |
|
|
2633 | R->selection_type = Sel_UTF8String; |
|
|
2634 | if (rxvt_selection_request_other(aR_ R->xa[XA_UTF8_STRING], i)) |
|
|
2635 | return; |
|
|
2636 | #else |
2649 | R->selection_type = Sel_CompoundText; |
2637 | R->selection_type = Sel_CompoundText; |
2650 | if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) |
2638 | if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) |
2651 | return; |
2639 | return; |
|
|
2640 | #endif |
2652 | } |
2641 | } |
2653 | } |
2642 | } |
2654 | R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ |
2643 | R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ |
2655 | D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); |
2644 | D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); |
2656 | rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); |
2645 | rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); |
… | |
… | |
2788 | { |
2777 | { |
2789 | free (new_selection_text); |
2778 | free (new_selection_text); |
2790 | return; |
2779 | return; |
2791 | } |
2780 | } |
2792 | |
2781 | |
2793 | // due to MB_MAX_CUR, selection wastage is usually high |
2782 | // due to MB_MAX_CUR, selection wastage is usually high, so realloc |
2794 | if (str - (char *)new_selection_text > 1024) |
2783 | if (str - (char *)new_selection_text > 1024) |
2795 | new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); |
2784 | new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); |
2796 | |
2785 | |
2797 | R->selection.len = i; |
2786 | R->selection.len = i; |
|
|
2787 | |
2798 | if (R->selection.text) |
2788 | if (R->selection.text) |
2799 | free (R->selection.text); |
2789 | free (R->selection.text); |
2800 | |
2790 | |
2801 | R->selection.text = new_selection_text; |
2791 | R->selection.text = new_selection_text; |
2802 | |
2792 | |
2803 | XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); |
2793 | XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); |
2804 | if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) |
2794 | if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) |
2805 | rxvt_print_error("can't get primary selection"); |
2795 | rxvt_print_error("can't get primary selection"); |
|
|
2796 | |
|
|
2797 | |
|
|
2798 | { |
|
|
2799 | XTextProperty ct; |
|
|
2800 | char *cl = (char *)R->selection.text; |
|
|
2801 | |
|
|
2802 | if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, XStringStyle, &ct) >= 0) |
|
|
2803 | { |
|
|
2804 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
|
|
2805 | PropModeReplace, ct.value, ct.nitems); |
|
|
2806 | XFree (ct.value); |
|
|
2807 | } |
|
|
2808 | else |
2806 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
2809 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
2807 | PropModeReplace, R->selection.text, (int)R->selection.len); |
2810 | PropModeReplace, R->selection.text, (int)R->selection.len); |
|
|
2811 | } |
|
|
2812 | |
2808 | R->selection_time = tm; |
2813 | R->selection_time = tm; |
2809 | D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); |
2814 | D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); |
2810 | } |
2815 | } |
2811 | |
2816 | |
2812 | /* ------------------------------------------------------------------------- */ |
2817 | /* ------------------------------------------------------------------------- */ |
… | |
… | |
3264 | /* |
3269 | /* |
3265 | * On some systems, the Atom typedef is 64 bits wide. We need to have a type |
3270 | * On some systems, the Atom typedef is 64 bits wide. We need to have a type |
3266 | * that is exactly 32 bits wide, because a format of 64 is not allowed by |
3271 | * that is exactly 32 bits wide, because a format of 64 is not allowed by |
3267 | * the X11 protocol. |
3272 | * the X11 protocol. |
3268 | */ |
3273 | */ |
3269 | typedef CARD32 Atom32; |
3274 | typedef CARD32 Atom32; |
3270 | |
3275 | |
3271 | /* ------------------------------------------------------------------------- */ |
3276 | /* ------------------------------------------------------------------------- */ |
3272 | /* |
3277 | /* |
3273 | * Respond to a request for our current selection |
3278 | * Respond to a request for our current selection |
3274 | * EXT: SelectionRequest |
3279 | * EXT: SelectionRequest |
… | |
… | |
3276 | /* EXTPROTO */ |
3281 | /* EXTPROTO */ |
3277 | void |
3282 | void |
3278 | rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) |
3283 | rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) |
3279 | { |
3284 | { |
3280 | XSelectionEvent ev; |
3285 | XSelectionEvent ev; |
3281 | #ifdef USE_XIM |
|
|
3282 | Atom32 target_list[4]; |
|
|
3283 | #else |
|
|
3284 | Atom32 target_list[3]; |
|
|
3285 | #endif |
|
|
3286 | Atom target; |
|
|
3287 | XTextProperty ct; |
3286 | XTextProperty ct; |
3288 | XICCEncodingStyle style; |
3287 | XICCEncodingStyle style; |
3289 | char *cl[2], dummy[1]; |
3288 | Atom target; |
3290 | |
3289 | |
3291 | ev.type = SelectionNotify; |
3290 | ev.type = SelectionNotify; |
3292 | ev.property = None; |
3291 | ev.property = None; |
3293 | ev.display = rq->display; |
3292 | ev.display = rq->display; |
3294 | ev.requestor = rq->requestor; |
3293 | ev.requestor = rq->requestor; |
3295 | ev.selection = rq->selection; |
3294 | ev.selection = rq->selection; |
3296 | ev.target = rq->target; |
3295 | ev.target = rq->target; |
3297 | ev.time = rq->time; |
3296 | ev.time = rq->time; |
3298 | |
3297 | |
3299 | if (rq->target == R->xa[XA_TARGETS]) { |
3298 | if (rq->target == R->xa[XA_TARGETS]) { |
|
|
3299 | Atom32 target_list[5]; |
|
|
3300 | Atom32 *target = target_list; |
|
|
3301 | |
3300 | target_list[0] = (Atom32) R->xa[XA_TARGETS]; |
3302 | *target++ = (Atom32) R->xa[XA_TARGETS]; |
3301 | target_list[1] = (Atom32) XA_STRING; |
3303 | *target++ = (Atom32) XA_STRING; |
3302 | target_list[2] = (Atom32) R->xa[XA_TEXT]; |
3304 | *target++ = (Atom32) R->xa[XA_TEXT]; |
3303 | #ifdef USE_XIM |
|
|
3304 | target_list[3] = (Atom32) R->xa[XA_COMPOUND_TEXT]; |
3305 | *target++ = (Atom32) R->xa[XA_COMPOUND_TEXT]; |
|
|
3306 | #if X_HAVE_UTF8_STRING |
|
|
3307 | *target++ = (Atom32) R->xa[XA_UTF8_STRING]; |
3305 | #endif |
3308 | #endif |
3306 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, |
3309 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, |
3307 | (8 * sizeof(target_list[0])), PropModeReplace, |
3310 | (8 * sizeof(target_list[0])), PropModeReplace, |
3308 | (unsigned char *)target_list, |
3311 | (unsigned char *)target_list, |
3309 | (sizeof(target_list) / sizeof(target_list[0]))); |
3312 | target - target_list); |
3310 | ev.property = rq->property; |
3313 | ev.property = rq->property; |
3311 | } else if (rq->target == R->xa[XA_MULTIPLE]) { |
3314 | } else if (rq->target == R->xa[XA_MULTIPLE]) { |
3312 | /* TODO: Handle MULTIPLE */ |
3315 | /* TODO: Handle MULTIPLE */ |
3313 | } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { |
3316 | } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { |
3314 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, |
3317 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, |
3315 | (8 * sizeof(Time)), PropModeReplace, |
3318 | (8 * sizeof(Time)), PropModeReplace, |
3316 | (unsigned char *)&R->selection_time, 1); |
3319 | (unsigned char *)&R->selection_time, 1); |
3317 | ev.property = rq->property; |
3320 | ev.property = rq->property; |
3318 | } else if (rq->target == XA_STRING |
3321 | } else if (rq->target == XA_STRING |
|
|
3322 | || rq->target == R->xa[XA_TEXT] |
3319 | || rq->target == R->xa[XA_COMPOUND_TEXT] |
3323 | || rq->target == R->xa[XA_COMPOUND_TEXT] |
3320 | || rq->target == R->xa[XA_TEXT]) { |
3324 | || rq->target == R->xa[XA_UTF8_STRING] |
3321 | #ifdef USE_XIM |
3325 | ) { |
3322 | short freect = 0; |
3326 | short freect = 0; |
3323 | #endif |
|
|
3324 | int selectlen; |
3327 | int selectlen; |
|
|
3328 | char *cl; |
3325 | |
3329 | |
3326 | #ifdef USE_XIM |
3330 | target = rq->target; |
|
|
3331 | |
3327 | if (rq->target != XA_STRING) { |
3332 | if (target == XA_STRING) |
|
|
3333 | // we actually don't do XA_STRING, but who cares, as i18n clients |
|
|
3334 | // will ask for another format anyways. |
|
|
3335 | style = XStringStyle; |
|
|
3336 | else if (target == R->xa[XA_TEXT]) |
|
|
3337 | style = XTextStyle; |
|
|
3338 | else if (target == R->xa[XA_COMPOUND_TEXT]) |
|
|
3339 | style = XCompoundTextStyle; |
|
|
3340 | #if X_HAVE_UTF8_STRING |
|
|
3341 | else if (target == R->xa[XA_UTF8_STRING]) |
|
|
3342 | style = XUTF8StringStyle; |
|
|
3343 | #endif |
|
|
3344 | else |
|
|
3345 | { |
3328 | target = R->xa[XA_COMPOUND_TEXT]; |
3346 | target = R->xa[XA_COMPOUND_TEXT]; |
3329 | style = (rq->target == R->xa[XA_COMPOUND_TEXT]) |
|
|
3330 | ? XCompoundTextStyle : XStdICCTextStyle; |
|
|
3331 | } else |
|
|
3332 | #endif |
|
|
3333 | { |
|
|
3334 | target = XA_STRING; |
|
|
3335 | style = XStringStyle; |
3347 | style = XCompoundTextStyle; |
3336 | } |
3348 | } |
|
|
3349 | |
3337 | if (R->selection.text) { |
3350 | if (R->selection.text) { |
3338 | cl[0] = (char *)R->selection.text; |
3351 | cl = (char *)R->selection.text; |
3339 | selectlen = R->selection.len; |
3352 | selectlen = R->selection.len; |
3340 | } else { |
3353 | } else { |
3341 | cl[0] = dummy; |
3354 | cl = ""; |
3342 | *dummy = '\0'; |
|
|
3343 | selectlen = 0; |
3355 | selectlen = 0; |
3344 | } |
3356 | } |
3345 | #ifdef USE_XIM |
3357 | |
3346 | if (XmbTextListToTextProperty(R->Xdisplay, cl, 1, style, &ct) |
3358 | if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, style, &ct) >= 0) |
3347 | == Success) /* if we failed to convert then send it raw */ |
|
|
3348 | freect = 1; |
3359 | freect = 1; |
3349 | else |
3360 | else |
3350 | #endif |
|
|
3351 | { |
3361 | { |
|
|
3362 | /* if we failed to convert then send it raw */ |
3352 | ct.value = (unsigned char *)cl[0]; |
3363 | ct.value = (unsigned char *)cl; |
3353 | ct.nitems = selectlen; |
3364 | ct.nitems = selectlen; |
3354 | } |
3365 | } |
|
|
3366 | |
3355 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, |
3367 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, |
3356 | target, 8, PropModeReplace, |
3368 | target, 8, PropModeReplace, |
3357 | ct.value, (int)ct.nitems); |
3369 | ct.value, (int)ct.nitems); |
3358 | ev.property = rq->property; |
3370 | ev.property = rq->property; |
3359 | #ifdef USE_XIM |
3371 | |
3360 | if (freect) |
3372 | if (freect) |
3361 | XFree(ct.value); |
3373 | XFree (ct.value); |
3362 | #endif |
|
|
3363 | } |
3374 | } |
3364 | XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); |
3375 | XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); |
3365 | } |
3376 | } |
3366 | |
3377 | |
3367 | /* ------------------------------------------------------------------------- * |
3378 | /* ------------------------------------------------------------------------- * |