--- rxvt-unicode/src/screen.C 2006/01/21 14:25:05 1.246 +++ rxvt-unicode/src/screen.C 2006/01/28 14:23:16 1.254 @@ -95,18 +95,18 @@ #define CLEAR_ROWS(row, num) \ if (mapped) \ - XClearArea (display->display, drawBuffer, 0, \ + XClearArea (xdisp, drawBuffer, 0, \ Row2Pixel (row), (unsigned int)width, \ (unsigned int)Height2Pixel (num), False) #define CLEAR_CHARS(x, y, num) \ if (mapped) \ - XClearArea (display->display, drawBuffer, x, y, \ + XClearArea (xdisp, drawBuffer, x, y, \ (unsigned int)Width2Pixel (num), \ (unsigned int)Height2Pixel (1), False) #define ERASE_ROWS(row, num) \ - XFillRectangle (display->display, drawBuffer, gc, \ + XFillRectangle (xdisp, drawBuffer, gc, \ 0, Row2Pixel (row), \ (unsigned int)width, \ (unsigned int)Height2Pixel (num)) @@ -128,7 +128,7 @@ l.touch (); - efs &= ~RS_baseattrMask; + efs &= ~RS_baseattrMask; // remove italic etc. fontstyles efs = SET_FONT (efs, FONTSET (efs)->find_font (' ')); text_t *et = l.t + col; @@ -175,8 +175,11 @@ if (ncol == prev_ncol && nrow == prev_nrow) return; + if (current_screen != PRIMARY) + scr_swap_screen (); + // we need at least two lines for wrapping to work correctly - if (nrow + saveLines < 2) + while (nrow + saveLines < 2) { //TODO//FIXME saveLines++; @@ -197,7 +200,7 @@ /* * first time called so just malloc everything: don't rely on realloc */ - top_row = 0; /* no saved lines */ + top_row = 0; term_start = 0; talloc = new rxvt_salloc (ncol * sizeof (text_t)); @@ -282,7 +285,7 @@ if (top_row) { - // re-wrap lines, this is rather ugly, possibly because I am too dumb + // Re-wrap lines. This is rather ugly, possibly because I am too dumb // to come up with a lean and mean algorithm. row_col_t ocur = screen.cur; @@ -349,11 +352,6 @@ int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); -#if DEBUG_STRICT - assert (len); - assert (pline.t); -#endif - memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); @@ -403,8 +401,7 @@ clamp_it (screen.cur.row, 0, nrow - 1); clamp_it (screen.cur.col, 0, ncol - 1); - if (tabs) - free (tabs); + free (tabs); } CLEAR_ALL_SELECTION (); @@ -417,6 +414,9 @@ for (int col = ncol; col--; ) tabs [col] = col % TABSIZE == 0; + if (current_screen != PRIMARY) + scr_swap_screen (); + tt_winch (); HOOK_INVOKE ((this, HOOK_RESET, DT_END)); @@ -429,15 +429,18 @@ void rxvt_term::scr_release () NOTHROW { - delete talloc; talloc = 0; - delete ralloc; ralloc = 0; + if (row_buf) + { + delete talloc; talloc = 0; + delete ralloc; ralloc = 0; - free (row_buf); - free (swap_buf); - free (drawn_buf); - free (tabs); + free (row_buf); + free (swap_buf); + free (drawn_buf); + free (tabs); - row_buf = 0; // signal that we freed all the arrays + row_buf = 0; // signal that we freed all the arrays + } } /* ------------------------------------------------------------------------- */ @@ -445,7 +448,7 @@ * Hard reset */ void -rxvt_term::scr_poweron () NOTHROW +rxvt_term::scr_poweron () { scr_release (); prev_nrow = prev_ncol = 0; @@ -506,50 +509,56 @@ #endif } +void +rxvt_term::scr_swap_screen () +{ + if (!OPTION (Opt_secondaryScreen)) + return; + + for (int i = prev_nrow; i--; ) + ::swap (ROW(i), swap_buf [i]); + + ::swap (screen.cur, swap.cur); + + screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1); + screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1); +} + /* ------------------------------------------------------------------------- */ /* * Swap between primary and secondary screens * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l */ -int -rxvt_term::scr_change_screen (int scrn) NOTHROW +void +rxvt_term::scr_change_screen (int scrn) { + if (scrn == current_screen) + return; + want_refresh = 1; view_start = 0; - if (current_screen == scrn) - return scrn; - selection_check (2); /* check for boundary cross */ int i = current_screen; current_screen = scrn; scrn = i; - ::swap (screen.cur.row, swap.cur.row); - ::swap (screen.cur.col, swap.cur.col); - - screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1); - screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1); - #if NSCREENS if (OPTION (Opt_secondaryScreen)) { num_scr = 0; - for (int i = prev_nrow; i--; ) - ::swap (ROW(i), swap_buf [i]); + scr_swap_screen (); ::swap (screen.charset, swap.charset); - ::swap (screen.flags, swap.flags); + ::swap (screen.flags, swap.flags); screen.flags |= Screen_VisibleCursor; - swap.flags |= Screen_VisibleCursor; + swap.flags |= Screen_VisibleCursor; } else #endif if (OPTION (Opt_secondaryScroll)) scr_scroll_text (0, prev_nrow - 1, prev_nrow); - - return scrn; } // clear WrapNext indicator, solidifying position on next line @@ -634,14 +643,18 @@ // erase newly scrolled-in lines for (int i = count; i--; ) { - // basically this is a slightly optimized scr_blank_screen_mem - // it is worth the effort on slower machines line_t &l = ROW(nrow - 1 - i); - scr_blank_line (l, 0, l.l, rstyle); - - l.l = 0; - l.f = 0; + // optimize if already cleared, can be significant on slow machines + // could be rolled into scr_blank_screen_mem + if (l.r && l.l < ncol - 1 && !((l.r[l.l + 1] ^ rstyle) & RS_bgMask)) + { + scr_blank_line (l, 0, l.l, rstyle); + l.l = 0; + l.f = 0; + } + else + scr_blank_screen_mem (l, rstyle); } // now copy lines below the scroll region bottom to the @@ -751,6 +764,7 @@ if (minlines > 0) { minlines += screen.cur.row - screen.bscroll; + min_it (minlines, screen.cur.row - top_row); if (minlines > 0 && screen.tscroll == 0 @@ -834,11 +848,11 @@ if (IN_RANGE_INC (c, 0xd800, 0xdfff)) c = 0xfffd; - // rely on wcwidth to tell us the character width, at least for non-latin1 - // do wcwidth before further replacements, as wcwidth might return -1 - // for the line drawing characters below as they might be invalid in the current + // rely on wcwidth to tell us the character width, do wcwidth before + // further replacements, as wcwidth might return -1 for the line + // drawing characters below as they might be invalid in the current // locale. - int width = c < 0x100 ? 1 : wcwidth (c); + int width = WCWIDTH (c); if (charsets [screen.charset] == '0') // DEC SPECIAL { @@ -1330,10 +1344,10 @@ { ren = rstyle & (RS_fgMask | RS_bgMask); gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; - XChangeGC (display->display, gc, GCForeground, &gcvalue); + XChangeGC (xdisp, gc, GCForeground, &gcvalue); ERASE_ROWS (row, num); gcvalue.foreground = pix_colors[Color_fg]; - XChangeGC (display->display, gc, GCForeground, &gcvalue); + XChangeGC (xdisp, gc, GCForeground, &gcvalue); } for (; num--; row++) @@ -1642,12 +1656,12 @@ #if TRANSPARENT if (!OPTION (Opt_transparent) || am_transparent == 0) #endif - XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); + XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]); XGCValues gcvalue; gcvalue.foreground = pix_colors[Color_fg]; gcvalue.background = pix_colors[Color_bg]; - XChangeGC (display->display, gc, GCBackground | GCForeground, &gcvalue); + XChangeGC (xdisp, gc, GCBackground | GCForeground, &gcvalue); scr_clear (); scr_touch (true); @@ -1877,7 +1891,7 @@ # ifdef MAPALERT_OPTION if (OPTION (Opt_mapAlert)) # endif - XMapWindow (display->display, parent[0]); + XMapWindow (xdisp, parent[0]); # endif if (OPTION (Opt_visualBell)) @@ -1889,7 +1903,7 @@ bell_ev.start (NOW + VISUAL_BELL_DURATION); } else - XBell (display->display, 0); + XBell (xdisp, 0); #endif } @@ -2138,7 +2152,7 @@ if (wlen < len) ::swap (wlen, len); - XCopyArea (display->display, vt, vt, + XCopyArea (xdisp, vt, vt, gc, 0, Row2Pixel (len + i), (unsigned int)this->width, (unsigned int)Height2Pixel (wlen - len + 1), @@ -2236,15 +2250,21 @@ if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) { #if ENABLE_STYLES - // force redraw after "careful" characters to avoid pixel droppings - if (srp[col] & RS_Careful && col < ncol - 1 && 0) - drp[col + 1] = ~srp[col + 1]; + // "careful" (too wide) character handling // include previous careful character(s) if possible, looks nicer (best effort...) while (text > stp && srp[text - stp - 1] & RS_Careful && RS_SAME (rend, srp[text - stp - 1])) text--, count++, xpixel -= fwidth; + + // force redraw after "careful" characters to avoid pixel droppings + for (int i = 0; srp[col + i] & RS_Careful && col + i < ncol - 1; i++) + drp[col + i + 1] = ~srp[col + i + 1]; + + // force redraw before "careful" characters to avoid pixel droppings + for (int i = 0; srp[text - stp - i] & RS_Careful && text - i > stp; i++) + drp[text - stp - i - 1] = ~srp[text - stp - i - 1]; #endif bool invert = rend & RS_RVid; @@ -2338,12 +2358,12 @@ { #if ENABLE_FRILLS if (ISSET_PIXCOLOR (Color_underline)) - XSetForeground (display->display, gc, pix_colors[Color_underline]); + XSetForeground (xdisp, gc, pix_colors[Color_underline]); else #endif - XSetForeground (display->display, gc, pix_colors[fore]); + XSetForeground (xdisp, gc, pix_colors[fore]); - XDrawLine (display->display, drawBuffer, gc, + XDrawLine (xdisp, drawBuffer, gc, xpixel, ypixel + font->ascent + 1, xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); } @@ -2386,10 +2406,10 @@ #ifndef NO_CURSORCOLOR if (ISSET_PIXCOLOR (Color_cursor)) - XSetForeground (display->display, gc, pix_colors[Color_cursor]); + XSetForeground (xdisp, gc, pix_colors[Color_cursor]); #endif - XDrawRectangle (display->display, drawBuffer, gc, + XDrawRectangle (xdisp, drawBuffer, gc, Col2Pixel (col), Row2Pixel (oldcursor.row), (unsigned int) (Width2Pixel (cursorwidth) - 1), @@ -2443,13 +2463,13 @@ #endif ) { - XSetWindowBackground (display->display, parent[0], pix_colors[Color_border]); - XClearWindow (display->display, parent[0]); - XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); + XSetWindowBackground (xdisp, parent[0], pix_colors[Color_border]); + XClearWindow (xdisp, parent[0]); + XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]); #if HAVE_SCROLLBARS if (scrollBar.win) { - XSetWindowBackground (display->display, scrollBar.win, pix_colors[Color_border]); + XSetWindowBackground (xdisp, scrollBar.win, pix_colors[Color_border]); scrollBar.setIdle (); scrollbar_show (0); } @@ -2472,7 +2492,7 @@ want_refresh = 1; if (really) - XClearWindow (display->display, vt); + XClearWindow (xdisp, vt); } void @@ -2657,7 +2677,7 @@ unsigned long bytes_after; XTextProperty ct; - if (XGetWindowProperty (display->display, win, prop, + if (XGetWindowProperty (xdisp, win, prop, 0, PROP_SIZE / 4, delete_prop, AnyPropertyType, &ct.encoding, &ct.format, @@ -2676,7 +2696,7 @@ // fetch and append remaining data XTextProperty ct2; - if (XGetWindowProperty (display->display, win, prop, + if (XGetWindowProperty (xdisp, win, prop, ct.nitems / 4, (bytes_after + 3) / 4, delete_prop, AnyPropertyType, &ct2.encoding, &ct2.format, @@ -2699,7 +2719,7 @@ { // INCR selection, start handshake if (!delete_prop) - XDeleteProperty (display->display, win, prop); + XDeleteProperty (xdisp, win, prop); selection_wait = Sel_incr; incr_buf_fill = 0; @@ -2770,7 +2790,7 @@ } else #endif - if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 + if (XmbTextPropertyToTextList (xdisp, &ct, &cl, &cr) >= 0 && cl) { for (int i = 0; i < cr; i++) @@ -2862,9 +2882,9 @@ else sel = xa[XA_CLIPBOARD]; - if (XGetSelectionOwner (display->display, sel) != None) + if (XGetSelectionOwner (xdisp, sel) != None) { - XConvertSelection (display->display, sel, target, xa[XA_VT_SELECTION], + XConvertSelection (xdisp, sel, target, xa[XA_VT_SELECTION], vt, selection_request_time); return 1; } @@ -3027,8 +3047,8 @@ { selection_time = tm; - XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); - if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) + XSetSelectionOwner (xdisp, XA_PRIMARY, vt, tm); + if (XGetSelectionOwner (xdisp, XA_PRIMARY) == vt) { display->set_selection_owner (this); return true; @@ -3042,7 +3062,7 @@ #if 0 XTextProperty ct; - if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) + if (XwcTextListToTextProperty (xdisp, &selection.text, 1, XStringStyle, &ct) >= 0) { set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); XFree (ct.value); @@ -3500,7 +3520,6 @@ rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW { XSelectionEvent ev; - dDisp; ev.type = SelectionNotify; ev.property = None; @@ -3524,7 +3543,7 @@ *target++ = xa[XA_UTF8_STRING]; #endif - XChangeProperty (disp, rq.requestor, rq.property, XA_ATOM, + XChangeProperty (xdisp, rq.requestor, rq.property, XA_ATOM, 32, PropModeReplace, (unsigned char *)target_list, target - target_list); ev.property = rq.property; @@ -3537,7 +3556,7 @@ #endif else if (rq.target == xa[XA_TIMESTAMP] && selection.text) { - XChangeProperty (disp, rq.requestor, rq.property, rq.target, + XChangeProperty (xdisp, rq.requestor, rq.property, rq.target, 32, PropModeReplace, (unsigned char *)&selection_time, 1); ev.property = rq.property; } @@ -3605,7 +3624,7 @@ } else #endif - if (XwcTextListToTextProperty (disp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) + if (XwcTextListToTextProperty (xdisp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) freect = 1; else { @@ -3615,7 +3634,7 @@ ct.encoding = target; } - XChangeProperty (disp, rq.requestor, rq.property, + XChangeProperty (xdisp, rq.requestor, rq.property, ct.encoding, 8, PropModeReplace, ct.value, (int)ct.nitems); ev.property = rq.property; @@ -3624,7 +3643,7 @@ XFree (ct.value); } - XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev); + XSendEvent (xdisp, rq.requestor, False, 0L, (XEvent *)&ev); } /* ------------------------------------------------------------------------- * @@ -3650,7 +3669,7 @@ { XWindowAttributes xwa; - XGetWindowAttributes (display->display, vt, &xwa); + XGetWindowAttributes (xdisp, vt, &xwa); pos.x = xwa.x + Col2Pixel (screen.cur.col); pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase; @@ -3756,7 +3775,7 @@ while (*s) { text_t t = *s++; - int width = wcwidth (t); + int width = WCWIDTH (t); while (width--) {