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.435 by sf-exg, Sun Mar 24 10:12:04 2013 UTC vs.
Revision 1.459 by root, Tue Jun 25 03:35:01 2019 UTC

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-2007 Marc Lehmann <schmorp@schmorp.de> 6 * Copyright (c) 2003-2007 Marc Lehmann <schmorp@schmorp.de>
7 * Copyright (c) 2015 Emanuele Giaquinta <e.giaquinta@glauco.it>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * 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 10 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version. 12 * (at your option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
254 255
255 scr_alloc (); 256 scr_alloc ();
256 257
257 if (!prev_row_buf) 258 if (!prev_row_buf)
258 { 259 {
259 /*
260 * first time called (or after scr_release) so just malloc everything: don't rely on realloc
261 */
262 top_row = 0; 260 top_row = 0;
263 term_start = 0; 261 term_start = 0;
264 262
265 memset (charsets, 'B', sizeof (charsets)); 263 memset (charsets, 'B', sizeof (charsets));
266 rstyle = DEFAULT_RSTYLE; 264 rstyle = DEFAULT_RSTYLE;
617 * Change the colour for following text 615 * Change the colour for following text
618 */ 616 */
619void 617void
620rxvt_term::scr_color (unsigned int color, int fgbg) NOTHROW 618rxvt_term::scr_color (unsigned int color, int fgbg) NOTHROW
621{ 619{
622 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) 620 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR24))
623 color = fgbg; 621 color = fgbg;
624 622
625 if (fgbg == Color_fg) 623 if (fgbg == Color_fg)
626 rstyle = SET_FGCOLOR (rstyle, color); 624 rstyle = SET_FGCOLOR (rstyle, color);
627 else 625 else
718 716
719 // finally move the view window, if desired 717 // finally move the view window, if desired
720 if (option (Opt_scrollWithBuffer) 718 if (option (Opt_scrollWithBuffer)
721 && view_start != 0 719 && view_start != 0
722 && view_start != -saveLines) 720 && view_start != -saveLines)
723 scr_page (UP, count); 721 scr_page (count);
724 722
725 if (SHOULD_INVOKE (HOOK_SCROLL_BACK)) 723 if (SHOULD_INVOKE (HOOK_SCROLL_BACK))
726 HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, top_row, DT_END)); 724 HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, top_row, DT_END));
727 } 725 }
728 else 726 else
1014 } 1012 }
1015 else if (screen.cur.row > 0 1013 else if (screen.cur.row > 0
1016 && ROW(screen.cur.row - 1).is_longer ()) 1014 && ROW(screen.cur.row - 1).is_longer ())
1017 { 1015 {
1018 linep = &ROW(screen.cur.row - 1); 1016 linep = &ROW(screen.cur.row - 1);
1019 tp = line->t + ncol - 1; 1017 tp = linep->t + ncol - 1;
1020 rp = line->r + ncol - 1; 1018 rp = linep->r + ncol - 1;
1021 } 1019 }
1022 else 1020 else
1023 continue; 1021 continue;
1024 1022
1025 linep->touch (); 1023 linep->touch ();
1243 * direction should be UP or DN 1241 * direction should be UP or DN
1244 */ 1242 */
1245void 1243void
1246rxvt_term::scr_index (enum page_dirn direction) NOTHROW 1244rxvt_term::scr_index (enum page_dirn direction) NOTHROW
1247{ 1245{
1248 int dirn;
1249
1250 want_refresh = 1; 1246 want_refresh = 1;
1251 ZERO_SCROLLBACK (); 1247 ZERO_SCROLLBACK ();
1252 1248
1253 dirn = ((direction == UP) ? 1 : -1);
1254
1255 screen.flags &= ~Screen_WrapNext; 1249 screen.flags &= ~Screen_WrapNext;
1256 1250
1257 if ((screen.cur.row == screen.bscroll && direction == UP) 1251 if ((screen.cur.row == screen.bscroll && direction == UP)
1258 || (screen.cur.row == screen.tscroll && direction == DN)) 1252 || (screen.cur.row == screen.tscroll && direction == DN))
1259 scr_scroll_text (screen.tscroll, screen.bscroll, dirn); 1253 scr_scroll_text (screen.tscroll, screen.bscroll, direction);
1260 else 1254 else
1261 screen.cur.row += dirn; 1255 screen.cur.row += direction;
1262 1256
1263 clamp_it (screen.cur.row, 0, nrow - 1); 1257 clamp_it (screen.cur.row, 0, nrow - 1);
1264 selection_check (0); 1258 selection_check (0);
1265} 1259}
1266 1260
1720 1714
1721 if (rvideo_state != on) 1715 if (rvideo_state != on)
1722 { 1716 {
1723 rvideo_state = on; 1717 rvideo_state = on;
1724 1718
1719#if OFF_FOCUS_FADING
1720 if (rs[Rs_fade])
1721 {
1722 ::swap (pix_colors_focused[Color_fg], pix_colors_focused[Color_bg]);
1723 ::swap (pix_colors_unfocused[Color_fg], pix_colors_unfocused[Color_bg]);
1724 }
1725 else
1726#endif
1725 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1727 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1726#ifdef HAVE_IMG 1728#ifdef HAVE_IMG
1727 if (bg_img == 0) 1729 if (bg_img == 0)
1728#endif 1730#endif
1729 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 1731 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
1904 * the top of the screen 1906 * the top of the screen
1905 */ 1907 */
1906void 1908void
1907rxvt_term::scr_move_to (int y, int len) NOTHROW 1909rxvt_term::scr_move_to (int y, int len) NOTHROW
1908{ 1910{
1909 scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1)); 1911 // lerp (y, 0, len, top_row, nrow - 1)
1912 scr_changeview (top_row + (nrow - 1 - top_row) * y / len);
1910} 1913}
1911 1914
1912/* ------------------------------------------------------------------------- */ 1915/* ------------------------------------------------------------------------- */
1913/* 1916/*
1914 * Page the screen up/down nlines 1917 * Page the screen up/down nlines
1915 * direction should be UP or DN 1918 * direction should be UP or DN
1916 */ 1919 */
1917bool 1920bool
1918rxvt_term::scr_page (enum page_dirn direction, int nlines) NOTHROW 1921rxvt_term::scr_page (int nlines) NOTHROW
1919{ 1922{
1920 int new_view_start =
1921 direction == UP ? view_start - nlines
1922 : view_start + nlines;
1923
1924 return scr_changeview (new_view_start); 1923 return scr_changeview (view_start - nlines);
1925} 1924}
1926 1925
1927bool 1926bool
1928rxvt_term::scr_changeview (int new_view_start) NOTHROW 1927rxvt_term::scr_changeview (int new_view_start) NOTHROW
1929{ 1928{
2051 int i; /* tmp */ 2050 int i; /* tmp */
2052 rend_t ccol1, /* Cursor colour */ 2051 rend_t ccol1, /* Cursor colour */
2053 ccol2; /* Cursor colour2 */ 2052 ccol2; /* Cursor colour2 */
2054 rend_t cur_rend; 2053 rend_t cur_rend;
2055 int cur_col; 2054 int cur_col;
2055 int cursorwidth;
2056 2056
2057 want_refresh = 0; /* screen is current */ 2057 want_refresh = 0; /* screen is current */
2058 2058
2059 if (refresh_type == NO_REFRESH || !mapped) 2059 if (refresh_type == NO_REFRESH || !mapped)
2060 return; 2060 return;
2085 2085
2086 /* 2086 /*
2087 * C: set the cursor character (s) 2087 * C: set the cursor character (s)
2088 */ 2088 */
2089 { 2089 {
2090 bool setoldcursor;
2091
2092#ifdef CURSOR_BLINK 2090#ifdef CURSOR_BLINK
2093 if (hidden_cursor) 2091 if (hidden_cursor)
2094 showcursor = 0; 2092 showcursor = 0;
2095#endif 2093#endif
2096 2094
2098 { 2096 {
2099 int col = screen.cur.col; 2097 int col = screen.cur.col;
2100 2098
2101 while (col && ROW(screen.cur.row).t[col] == NOCHAR) 2099 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
2102 col--; 2100 col--;
2101
2102 cursorwidth = 1;
2103 while (col + cursorwidth < ncol
2104 && ROW(screen.cur.row).t[col + cursorwidth] == NOCHAR)
2105 cursorwidth++;
2103 2106
2104 cur_rend = ROW(screen.cur.row).r[col]; 2107 cur_rend = ROW(screen.cur.row).r[col];
2105 cur_col = col; 2108 cur_col = col;
2106 2109
2107#ifndef NO_CURSORCOLOR 2110#ifndef NO_CURSORCOLOR
2124 ccol2 = bgcolor_of (rstyle); 2127 ccol2 = bgcolor_of (rstyle);
2125#else 2128#else
2126 ccol2 = Color_bg; 2129 ccol2 = Color_bg;
2127#endif 2130#endif
2128 2131
2129 if (focus) 2132 if (focus && cursor_type == 0)
2130 { 2133 {
2131 rend_t rend = cur_rend; 2134 rend_t rend = cur_rend;
2132 2135
2133 if (option (Opt_cursorUnderline))
2134 rend ^= RS_Uline;
2135 else
2136 {
2137 rend ^= RS_RVid; 2136 rend ^= RS_RVid;
2138 rend = SET_FGCOLOR (rend, ccol1); 2137 rend = SET_FGCOLOR (rend, ccol1);
2139 rend = SET_BGCOLOR (rend, ccol2); 2138 rend = SET_BGCOLOR (rend, ccol2);
2140 }
2141 2139
2142 scr_set_char_rend (ROW(screen.cur.row), cur_col, rend); 2140 scr_set_char_rend (ROW(screen.cur.row), cur_col, rend);
2143 } 2141 }
2144 } 2142 }
2145 2143
2146 /* make sure no outline cursor is left around */ 2144 /* make sure no outline cursor is left around */
2147 setoldcursor = 0; 2145 if (ocrow != -1 && ocrow < nrow && oldcursor.col < ncol)
2148 if (ocrow != -1) 2146 drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline);
2147
2148 // save the current cursor coordinates if the cursor is visible
2149 // and either the window is unfocused or the cursor style is
2150 // underline or vertical bar, so as to clear the outline cursor in
2151 // the next refresh if the cursor moves or becomes invisible
2152 if (showcursor && (!focus || cursor_type != 0) && screen.cur.row - view_start < nrow)
2149 { 2153 {
2150 if (screen.cur.row - view_start != ocrow 2154 oldcursor.row = screen.cur.row - view_start;
2151 || screen.cur.col != oldcursor.col) 2155 oldcursor.col = screen.cur.col;
2152 {
2153 if (ocrow < nrow
2154 && oldcursor.col < ncol)
2155 drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline);
2156
2157 if (focus || !showcursor)
2158 oldcursor.row = -1;
2159 else
2160 setoldcursor = 1;
2161 }
2162 } 2156 }
2163 else if (!focus) 2157 else
2164 setoldcursor = 1;
2165
2166 if (setoldcursor)
2167 {
2168 if (screen.cur.row - view_start >= nrow)
2169 oldcursor.row = -1; 2158 oldcursor.row = -1;
2170 else
2171 {
2172 oldcursor.row = screen.cur.row - view_start;
2173 oldcursor.col = screen.cur.col;
2174 }
2175 }
2176 } 2159 }
2177 2160
2178#ifndef NO_SLOW_LINK_SUPPORT 2161#ifndef NO_SLOW_LINK_SUPPORT
2179 /* 2162 /*
2180 * D: CopyArea pass - very useful for slower links 2163 * D: CopyArea pass - very useful for slower links
2261 int ypixel = (int)Row2Pixel (row); 2244 int ypixel = (int)Row2Pixel (row);
2262 2245
2263 for (col = 0; col < ncol; col++) 2246 for (col = 0; col < ncol; col++)
2264 { 2247 {
2265 /* compare new text with old - if exactly the same then continue */ 2248 /* compare new text with old - if exactly the same then continue */
2266 if (stp[col] == dtp[col] /* Must match characters to skip. */ 2249 if (stp[col] == dtp[col] && RS_SAME (srp[col], drp[col]))
2267 && (RS_SAME (srp[col], drp[col]) /* Either rendition the same or */
2268 || (stp[col] == ' ' /* space w/ no background change */
2269 && GET_BGATTR (srp[col]) == GET_BGATTR (drp[col]))))
2270 continue; 2250 continue;
2271 2251
2272 // redraw one or more characters 2252 // redraw one or more characters
2273 2253
2274 // seek to the beginning of wide characters 2254 // seek to the beginning of wide characters
2446 else 2426 else
2447 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2427 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2448 2428
2449 if (ecb_unlikely (rend & RS_Uline && font->descent > 1 && fore != back)) 2429 if (ecb_unlikely (rend & RS_Uline && font->descent > 1 && fore != back))
2450 { 2430 {
2431 if (showcursor && focus && row == screen.cur.row
2432 && IN_RANGE_EXC (col, cur_col, cur_col + cursorwidth))
2433 XSetForeground (dpy, gc, pix_colors[ccol1]);
2434 else
2451#if ENABLE_FRILLS 2435#if ENABLE_FRILLS
2452 if (ISSET_PIXCOLOR (Color_underline)) 2436 if (ISSET_PIXCOLOR (Color_underline))
2453 XSetForeground (dpy, gc, pix_colors[Color_underline]); 2437 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2454 else 2438 else
2455#endif 2439#endif
2466 * G: cleanup cursor and display outline cursor if necessary 2450 * G: cleanup cursor and display outline cursor if necessary
2467 */ 2451 */
2468 if (showcursor) 2452 if (showcursor)
2469 { 2453 {
2470 if (focus) 2454 if (focus)
2455 {
2456 if (cursor_type == 0)
2471 scr_set_char_rend (ROW(screen.cur.row), cur_col, cur_rend); 2457 scr_set_char_rend (ROW(screen.cur.row), cur_col, cur_rend);
2458 else if (oldcursor.row >= 0)
2459 {
2460 XSetForeground (dpy, gc, pix_colors[ccol1]);
2461 if (cursor_type == 1)
2462 XFillRectangle (dpy, vt, gc,
2463 Col2Pixel (cur_col),
2464 Row2Pixel (oldcursor.row + 1) - 2,
2465 Width2Pixel (1),
2466 2);
2467 else
2468 XFillRectangle (dpy, vt, gc,
2469 Col2Pixel (cur_col),
2470 Row2Pixel (oldcursor.row),
2471 2,
2472 Height2Pixel (1));
2473 }
2474 }
2472 else if (oldcursor.row >= 0) 2475 else if (oldcursor.row >= 0)
2473 { 2476 {
2474 int cursorwidth = 1;
2475 int col = oldcursor.col;
2476
2477 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
2478 col--;
2479
2480 while (col + cursorwidth < ncol
2481 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2482 cursorwidth++;
2483
2484#ifndef NO_CURSORCOLOR
2485 if (ISSET_PIXCOLOR (Color_cursor))
2486 XSetForeground (dpy, gc, pix_colors[Color_cursor]);
2487 else
2488#endif
2489 XSetForeground (dpy, gc, pix_colors[ccol1]); 2477 XSetForeground (dpy, gc, pix_colors[ccol1]);
2490 2478
2491 XDrawRectangle (dpy, vt, gc, 2479 XDrawRectangle (dpy, vt, gc,
2492 Col2Pixel (col), 2480 Col2Pixel (cur_col),
2493 Row2Pixel (oldcursor.row), 2481 Row2Pixel (oldcursor.row),
2494 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2482 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2495 (unsigned int) (Height2Pixel (1) - 1)); 2483 (unsigned int) (Height2Pixel (1) - 1));
2496 } 2484 }
2497 } 2485 }
2535 scr_remap_chars (swap_buf [i]); 2523 scr_remap_chars (swap_buf [i]);
2536 } 2524 }
2537} 2525}
2538 2526
2539void ecb_cold 2527void ecb_cold
2540rxvt_term::scr_recolour (bool refresh) NOTHROW 2528rxvt_term::scr_recolor (bool refresh) NOTHROW
2541{ 2529{
2542 bool transparent = false; 2530 bool transparent = false;
2543 2531
2544#ifdef HAVE_IMG 2532#ifdef HAVE_IMG
2545 if (bg_img != 0) 2533 if (bg_img != 0)
2566 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 2554 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2567 } 2555 }
2568 2556
2569 XClearWindow (dpy, parent); 2557 XClearWindow (dpy, parent);
2570 2558
2571 if (scrollBar.win) 2559 if (scrollBar.state && scrollBar.win)
2572 { 2560 {
2573 if (transparent) 2561 if (transparent)
2574 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); 2562 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
2575 else 2563 else
2576 XSetWindowBackground (dpy, scrollBar.win, pix_colors[scrollBar.color ()]); 2564 XSetWindowBackground (dpy, scrollBar.win, pix_colors[scrollBar.color ()]);
2704 2692
2705void 2693void
2706rxvt_term::selection_changed () NOTHROW 2694rxvt_term::selection_changed () NOTHROW
2707{ 2695{
2708 line_t &r1 = ROW (selection.beg.row); 2696 line_t &r1 = ROW (selection.beg.row);
2709 while (selection.beg.col > 0 && r1.t [selection.beg.col] == NOCHAR) 2697 while (selection.beg.col < r1.l && r1.t [selection.beg.col] == NOCHAR)
2710 --selection.beg.col; 2698 ++selection.beg.col;
2711 2699
2712 line_t &r2 = ROW (selection.end.row); 2700 line_t &r2 = ROW (selection.end.row);
2713 while (selection.end.col < r2.l && r2.t [selection.end.col] == NOCHAR) 2701 while (selection.end.col < r2.l && r2.t [selection.end.col] == NOCHAR)
2714 ++selection.end.col; 2702 ++selection.end.col;
2715 2703
3512 cl = selection.clip_text; 3500 cl = selection.clip_text;
3513 selectlen = selection.clip_len; 3501 selectlen = selection.clip_len;
3514 } 3502 }
3515 else 3503 else
3516 { 3504 {
3517 cl = L""; 3505 cl = (wchar_t *)L"";
3518 selectlen = 0; 3506 selectlen = 0;
3519 } 3507 }
3520 3508
3521#if !ENABLE_MINIMAL 3509#if !ENABLE_MINIMAL
3522 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 3510 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines