--- rxvt-unicode/src/screen.C 2012/05/28 16:40:03 1.417 +++ rxvt-unicode/src/screen.C 2017/07/15 08:16:22 1.458 @@ -4,10 +4,11 @@ * * Copyright (c) 1997-2001 Geoff Wing * Copyright (c) 2003-2007 Marc Lehmann + * Copyright (c) 2015 Emanuele Giaquinta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -152,6 +153,16 @@ } while (col < ncol && l.t[col] == NOCHAR); } +// set the rendition of a single wide character beginning at the given column +void +rxvt_term::scr_set_char_rend (line_t &l, int col, rend_t rend) +{ + do { + l.r[col] = rend; + col++; + } while (col < ncol && l.t[col] == NOCHAR); +} + /* ------------------------------------------------------------------------- * * SCREEN INITIALISATION * * ------------------------------------------------------------------------- */ @@ -163,7 +174,7 @@ int rsize = sizeof (rend_t) * ncol; // we assume that rend_t size is a sufficient alignment - // factor for tetx_t and line_t values, and we only + // factor for text_t and line_t values, and we only // need to adjust tsize. tsize = (tsize + sizeof (rend_t) - 1); tsize -= tsize % sizeof (rend_t); @@ -171,7 +182,7 @@ int all_rows = total_rows + nrow + nrow; chunk_size = (sizeof (line_t) + rsize + tsize) * all_rows; - chunk = rxvt_malloc (chunk_size); + chunk = chunk_alloc (chunk_size, 0); char *base = (char *)chunk + sizeof (line_t) * all_rows; @@ -190,6 +201,16 @@ row_buf = swap_buf + nrow; } +void +rxvt_term::copy_line (line_t &dst, line_t &src) +{ + scr_blank_screen_mem (dst, DEFAULT_RSTYLE); + dst.l = min (src.l, ncol); + memcpy (dst.t, src.t, sizeof (text_t) * dst.l); + memcpy (dst.r, src.r, sizeof (rend_t) * dst.l); + dst.f = src.f; +} + void ecb_cold rxvt_term::scr_reset () { @@ -227,19 +248,15 @@ screen.bscroll = nrow - 1; void *prev_chunk = chunk; + size_t prev_chunk_size = chunk_size; line_t *prev_drawn_buf = drawn_buf; line_t *prev_swap_buf = swap_buf; line_t *prev_row_buf = row_buf; - int common_col = min (prev_ncol, ncol); - scr_alloc (); if (!prev_row_buf) { - /* - * first time called so just malloc everything: don't rely on realloc - */ top_row = 0; term_start = 0; @@ -274,15 +291,15 @@ * add or delete rows as appropriate */ + int common_col = min (prev_ncol, ncol); + for (int row = min (nrow, prev_nrow); row--; ) { scr_blank_screen_mem (drawn_buf [row], DEFAULT_RSTYLE); - scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); - memcpy (drawn_buf [row].t, prev_drawn_buf [row].t, sizeof (text_t) * common_col); memcpy (drawn_buf [row].r, prev_drawn_buf [row].r, sizeof (rend_t) * common_col); - memcpy (swap_buf [row].t, prev_swap_buf [row].t, sizeof (text_t) * common_col); - memcpy (swap_buf [row].r, prev_swap_buf [row].r, sizeof (rend_t) * common_col); + + copy_line (swap_buf [row], prev_swap_buf [row]); } int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row @@ -387,10 +404,7 @@ line_t &src = prev_row_buf [MOD (term_start + row, prev_total_rows)]; line_t &dst = row_buf [row]; - scr_blank_screen_mem (dst, DEFAULT_RSTYLE); - - memcpy (dst.t, src.t, sizeof (text_t) * common_col); - memcpy (dst.r, src.r, sizeof (rend_t) * common_col); + copy_line (dst, src); } for (int row = prev_nrow; row < nrow; row++) @@ -410,7 +424,7 @@ if (!drawn_buf [row].valid ()) scr_blank_screen_mem (drawn_buf [row], DEFAULT_RSTYLE); } - free (prev_chunk); + chunk_free (prev_chunk, prev_chunk_size); free (tabs); tabs = (char *)rxvt_malloc (ncol); @@ -428,15 +442,15 @@ HOOK_INVOKE ((this, HOOK_RESET, DT_END)); } -/* ------------------------------------------------------------------------- */ -/* - * Free everything. That way malloc debugging can find leakage. - */ void ecb_cold rxvt_term::scr_release () NOTHROW { - free (chunk); + chunk_free (chunk, chunk_size); + chunk = 0; + row_buf = 0; + free (tabs); + tabs = 0; } /* ------------------------------------------------------------------------- */ @@ -448,8 +462,6 @@ { scr_release (); - row_buf = 0; - tabs = 0; prev_nrow = prev_ncol = 0; rvideo_mode = false; scr_soft_reset (); @@ -605,7 +617,7 @@ void rxvt_term::scr_color (unsigned int color, int fgbg) NOTHROW { - if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) + if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR24)) color = fgbg; if (fgbg == Color_fg) @@ -706,7 +718,7 @@ if (option (Opt_scrollWithBuffer) && view_start != 0 && view_start != -saveLines) - scr_page (UP, count); + scr_page (count); if (SHOULD_INVOKE (HOOK_SCROLL_BACK)) HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, top_row, DT_END)); @@ -1002,8 +1014,8 @@ && ROW(screen.cur.row - 1).is_longer ()) { linep = &ROW(screen.cur.row - 1); - tp = line->t + ncol - 1; - rp = line->r + ncol - 1; + tp = linep->t + ncol - 1; + rp = linep->r + ncol - 1; } else continue; @@ -1231,20 +1243,16 @@ void rxvt_term::scr_index (enum page_dirn direction) NOTHROW { - int dirn; - want_refresh = 1; ZERO_SCROLLBACK (); - dirn = ((direction == UP) ? 1 : -1); - screen.flags &= ~Screen_WrapNext; if ((screen.cur.row == screen.bscroll && direction == UP) || (screen.cur.row == screen.tscroll && direction == DN)) - scr_scroll_text (screen.tscroll, screen.bscroll, dirn); + scr_scroll_text (screen.tscroll, screen.bscroll, direction); else - screen.cur.row += dirn; + screen.cur.row += direction; clamp_it (screen.cur.row, 0, nrow - 1); selection_check (0); @@ -1708,9 +1716,17 @@ { rvideo_state = on; +#if OFF_FOCUS_FADING + if (rs[Rs_fade]) + { + ::swap (pix_colors_focused[Color_fg], pix_colors_focused[Color_bg]); + ::swap (pix_colors_unfocused[Color_fg], pix_colors_unfocused[Color_bg]); + } + else +#endif ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); -#ifdef HAVE_BG_PIXMAP - if (bg_pixmap == None) +#ifdef HAVE_IMG + if (bg_img == 0) #endif XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); @@ -1892,7 +1908,8 @@ void rxvt_term::scr_move_to (int y, int len) NOTHROW { - scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1)); + // lerp (y, 0, len, top_row, nrow - 1) + scr_changeview (top_row + (nrow - 1 - top_row) * y / len); } /* ------------------------------------------------------------------------- */ @@ -1901,13 +1918,9 @@ * direction should be UP or DN */ bool -rxvt_term::scr_page (enum page_dirn direction, int nlines) NOTHROW +rxvt_term::scr_page (int nlines) NOTHROW { - int new_view_start = - direction == UP ? view_start - nlines - : view_start + nlines; - - return scr_changeview (new_view_start); + return scr_changeview (view_start - nlines); } bool @@ -2035,12 +2048,11 @@ int16_t col, row, /* column/row we're processing */ ocrow; /* old cursor row */ int i; /* tmp */ -#ifndef NO_CURSORCOLOR - rend_t cc1; /* store colours at cursor position (s) */ -#endif - rend_t *crp; // cursor rendition pointer rend_t ccol1, /* Cursor colour */ ccol2; /* Cursor colour2 */ + rend_t cur_rend; + int cur_col; + int cursorwidth; want_refresh = 0; /* screen is current */ @@ -2054,8 +2066,8 @@ unsigned int old_screen_flags = screen.flags; bool have_bg = 0; -#ifdef HAVE_BG_PIXMAP - have_bg = bg_pixmap != None; +#ifdef HAVE_IMG + have_bg = bg_img != 0; #endif ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ @@ -2075,8 +2087,6 @@ * C: set the cursor character (s) */ { - bool setoldcursor; - #ifdef CURSOR_BLINK if (hidden_cursor) showcursor = 0; @@ -2089,10 +2099,15 @@ while (col && ROW(screen.cur.row).t[col] == NOCHAR) col--; - crp = &ROW(screen.cur.row).r[col]; + cursorwidth = 1; + while (col + cursorwidth < ncol + && ROW(screen.cur.row).t[col + cursorwidth] == NOCHAR) + cursorwidth++; + + cur_rend = ROW(screen.cur.row).r[col]; + cur_col = col; #ifndef NO_CURSORCOLOR - cc1 = *crp & (RS_fgMask | RS_bgMask); if (ISSET_PIXCOLOR (Color_cursor)) ccol1 = Color_cursor; else @@ -2114,49 +2129,33 @@ ccol2 = Color_bg; #endif - if (focus) + if (focus && cursor_type == 0) { - if (option (Opt_cursorUnderline)) - *crp ^= RS_Uline; - else - { - *crp ^= RS_RVid; - *crp = SET_FGCOLOR (*crp, ccol1); - *crp = SET_BGCOLOR (*crp, ccol2); - } - } - } + rend_t rend = cur_rend; - /* make sure no outline cursor is left around */ - setoldcursor = 0; - if (ocrow != -1) - { - if (screen.cur.row - view_start != ocrow - || screen.cur.col != oldcursor.col) - { - if (ocrow < nrow - && oldcursor.col < ncol) - drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); + rend ^= RS_RVid; + rend = SET_FGCOLOR (rend, ccol1); + rend = SET_BGCOLOR (rend, ccol2); - if (focus || !showcursor) - oldcursor.row = -1; - else - setoldcursor = 1; + scr_set_char_rend (ROW(screen.cur.row), cur_col, rend); } } - else if (!focus) - setoldcursor = 1; - if (setoldcursor) + /* make sure no outline cursor is left around */ + if (ocrow != -1 && ocrow < nrow && oldcursor.col < ncol) + drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); + + // save the current cursor coordinates if the cursor is visible + // and either the window is unfocused or the cursor style is + // underline or vertical bar, so as to clear the outline cursor in + // the next refresh if the cursor moves or becomes invisible + if (showcursor && (!focus || cursor_type != 0) && screen.cur.row - view_start < nrow) { - if (screen.cur.row - view_start >= nrow) - oldcursor.row = -1; - else - { - oldcursor.row = screen.cur.row - view_start; - oldcursor.col = screen.cur.col; - } + oldcursor.row = screen.cur.row - view_start; + oldcursor.col = screen.cur.col; } + else + oldcursor.row = -1; } #ifndef NO_SLOW_LINK_SUPPORT @@ -2247,10 +2246,7 @@ for (col = 0; col < ncol; col++) { /* compare new text with old - if exactly the same then continue */ - if (stp[col] == dtp[col] /* Must match characters to skip. */ - && (RS_SAME (srp[col], drp[col]) /* Either rendition the same or */ - || (stp[col] == ' ' /* space w/ no background change */ - && GET_BGATTR (srp[col]) == GET_BGATTR (drp[col])))) + if (stp[col] == dtp[col] && RS_SAME (srp[col], drp[col])) continue; // redraw one or more characters @@ -2432,6 +2428,10 @@ if (ecb_unlikely (rend & RS_Uline && font->descent > 1 && fore != back)) { + if (showcursor && focus && row == screen.cur.row + && IN_RANGE_EXC (col, cur_col, cur_col + cursorwidth)) + XSetForeground (dpy, gc, pix_colors[ccol1]); + else #if ENABLE_FRILLS if (ISSET_PIXCOLOR (Color_underline)) XSetForeground (dpy, gc, pix_colors[Color_underline]); @@ -2453,37 +2453,31 @@ { if (focus) { - if (option (Opt_cursorUnderline)) - *crp ^= RS_Uline; - else - { - *crp ^= RS_RVid; -#ifndef NO_CURSORCOLOR - *crp = (*crp & ~ (RS_fgMask | RS_bgMask)) | cc1; -#endif + if (cursor_type == 0) + scr_set_char_rend (ROW(screen.cur.row), cur_col, cur_rend); + else if (oldcursor.row >= 0) + { + XSetForeground (dpy, gc, pix_colors[ccol1]); + if (cursor_type == 1) + XFillRectangle (dpy, vt, gc, + Col2Pixel (cur_col), + Row2Pixel (oldcursor.row + 1) - 2, + Width2Pixel (1), + 2); + else + XFillRectangle (dpy, vt, gc, + Col2Pixel (cur_col), + Row2Pixel (oldcursor.row), + 2, + Height2Pixel (1)); } } else if (oldcursor.row >= 0) { - int cursorwidth = 1; - int col = oldcursor.col; - - while (col && ROW(screen.cur.row).t[col] == NOCHAR) - col--; - - while (col + cursorwidth < ncol - && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR) - cursorwidth++; - -#ifndef NO_CURSORCOLOR - if (ISSET_PIXCOLOR (Color_cursor)) - XSetForeground (dpy, gc, pix_colors[Color_cursor]); - else -#endif - XSetForeground (dpy, gc, pix_colors[ccol1]); + XSetForeground (dpy, gc, pix_colors[ccol1]); XDrawRectangle (dpy, vt, gc, - Col2Pixel (col), + Col2Pixel (cur_col), Row2Pixel (oldcursor.row), (unsigned int) (Width2Pixel (cursorwidth) - 1), (unsigned int) (Height2Pixel (1) - 1)); @@ -2531,17 +2525,17 @@ } void ecb_cold -rxvt_term::scr_recolour (bool refresh) NOTHROW +rxvt_term::scr_recolor (bool refresh) NOTHROW { bool transparent = false; -#ifdef HAVE_BG_PIXMAP - if (bg_pixmap != None) +#ifdef HAVE_IMG + if (bg_img != 0) { -# ifdef ENABLE_TRANSPARENCY +# if ENABLE_TRANSPARENCY if (bg_flags & BG_IS_TRANSPARENT) { - XSetWindowBackgroundPixmap (dpy, parent, bg_pixmap); + XSetWindowBackgroundPixmap (dpy, parent, bg_img->pm); XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); transparent = true; @@ -2550,7 +2544,7 @@ # endif { XSetWindowBackground (dpy, parent, pix_colors[Color_border]); - XSetWindowBackgroundPixmap (dpy, vt, bg_pixmap); + XSetWindowBackgroundPixmap (dpy, vt, bg_img->pm); } } else @@ -2562,12 +2556,12 @@ XClearWindow (dpy, parent); - if (scrollBar.win) + if (scrollBar.state && scrollBar.win) { if (transparent) XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); else - XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); + XSetWindowBackground (dpy, scrollBar.win, pix_colors[scrollBar.color ()]); scrollBar.state = SB_STATE_IDLE; scrollBar.show (0); } @@ -2696,6 +2690,20 @@ CLEAR_ALL_SELECTION (); } +void +rxvt_term::selection_changed () NOTHROW +{ + line_t &r1 = ROW (selection.beg.row); + while (selection.beg.col < r1.l && r1.t [selection.beg.col] == NOCHAR) + ++selection.beg.col; + + line_t &r2 = ROW (selection.end.row); + while (selection.end.col < r2.l && r2.t [selection.end.col] == NOCHAR) + ++selection.end.col; + + want_refresh = 1; +} + /* ------------------------------------------------------------------------- */ /* * Paste a selection direct to the command fd @@ -3006,7 +3014,7 @@ */ /* what do we want: spaces/tabs are delimiters or cutchars or non-cutchars */ -#define DELIMIT_TEXT(x) \ +#define DELIMIT_TEXT(x) \ (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x))) #define DELIMIT_REND(x) 1 @@ -3138,8 +3146,6 @@ LEFT, RIGHT } closeto = RIGHT; - want_refresh = 1; - switch (selection.op) { case SELECTION_INIT: @@ -3328,6 +3334,8 @@ if (selection.rect && selection.beg.col > selection.end.col) ::swap (selection.beg.col, selection.end.col); #endif + + selection_changed (); } #if !ENABLE_MINIMAL @@ -3534,7 +3542,7 @@ } /* ------------------------------------------------------------------------- */ -#ifdef USE_XIM +#if USE_XIM void ecb_cold rxvt_term::im_set_position (XPoint &pos) NOTHROW {