--- rxvt-unicode/src/screen.C 2011/03/21 13:46:17 1.377 +++ rxvt-unicode/src/screen.C 2011/09/01 08:11:27 1.394 @@ -161,6 +161,10 @@ void rxvt_term::scr_reset () { +#if ENABLE_OVERLAY + scr_overlay_off (); +#endif + view_start = 0; num_scr = 0; @@ -201,7 +205,7 @@ talloc = new rxvt_salloc (ncol * sizeof (text_t)); ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); - row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t)); + row_buf = (line_t *)rxvt_calloc (total_rows , sizeof (line_t)); drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); @@ -273,7 +277,7 @@ } line_t *old_buf = row_buf; - row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t)); + row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row int pend = MOD (term_start + top_row , prev_total_rows); @@ -636,24 +640,38 @@ && row1 == 0 && (current_screen == PRIMARY || option (Opt_secondaryScroll))) { - top_row = max (top_row - count, -saveLines); + min_it (count, total_rows - (nrow - (row2 + 1))); - // scroll everything up 'count' lines - term_start = (term_start + count) % total_rows; + top_row = max (top_row - count, -saveLines); // sever bottommost line { - line_t &l = ROW(row2 - count); + line_t &l = ROW(row2); l.is_longer (0); l.touch (); } + // scroll everything up 'count' lines + term_start = (term_start + count) % total_rows; + + // now copy lines below the scroll region bottom to the + // bottom of the screen again, so they look as if they + // hadn't moved. + for (int i = nrow; --i > row2; ) + { + line_t &l1 = ROW(i - count); + line_t &l2 = ROW(i); + + ::swap (l1, l2); + l2.touch (); + } + // erase newly scrolled-in lines for (int i = count; i--; ) { - line_t &l = ROW(nrow - 1 - i); + line_t &l = ROW(row2 - i); - // optimize if already cleared, can be significant on slow machines + // optimise 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_fgMask | RS_bgMask))) { @@ -665,18 +683,6 @@ scr_blank_screen_mem (l, rstyle); } - // now copy lines below the scroll region bottom to the - // bottom of the screen again, so they look as if they - // hadn't moved. - for (int i = nrow; --i > row2; ) - { - line_t &l1 = ROW(i - count); - line_t &l2 = ROW(i); - - ::swap (l1, l2); - l2.touch (); - } - // move and/or clear selection, if any if (selection.op && current_screen == selection.screen) { @@ -730,11 +736,19 @@ // use a simple and robust scrolling algorithm, this // part of scr_scroll_text is not time-critical. + // sever line above scroll region + if (row1) + { + line_t &l = ROW(row1 - 1); + l.is_longer (0); + l.touch (); + } + int rows = row2 - row1 + 1; min_it (count, rows); - line_t *temp_buf = row_buf + total_rows; + line_t *temp_buf = rxvt_temp_buf (rows); for (int row = 0; row < rows; row++) { @@ -746,6 +760,13 @@ for (int row = 0; row < rows; row++) ROW(row1 + row) = temp_buf [row]; + + // sever bottommost line + { + line_t &l = ROW(row2); + l.is_longer (0); + l.touch (); + } } return count; @@ -797,7 +818,7 @@ { c = (unicode_t)*str++; // convert to rxvt-unicodes representation - if (expect_false (c < 0x20)) + if (ecb_unlikely (c < 0x20)) if (c == C0_LF) { max_it (line->l, screen.cur.col); @@ -826,7 +847,7 @@ continue; } - if (expect_false ( + if (ecb_unlikely ( checksel /* see if we're writing within selection */ && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) && ROWCOL_IS_BEFORE (screen.cur, selection.end) @@ -841,7 +862,7 @@ CLEAR_SELECTION (); } - if (expect_false (screen.flags & Screen_WrapNext)) + if (ecb_unlikely (screen.flags & Screen_WrapNext)) { scr_do_wrap (); @@ -853,7 +874,7 @@ } // some utf-8 decoders "decode" surrogate characters: let's fix this. - if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff))) + if (ecb_unlikely (IN_RANGE_INC (c, 0xd800, 0xdfff))) c = 0xfffd; // rely on wcwidth to tell us the character width, do wcwidth before @@ -862,7 +883,7 @@ // locale. int width = WCWIDTH (c); - if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL + if (ecb_unlikely (charsets [screen.charset] == '0')) // DEC SPECIAL { // vt100 special graphics and line drawing // 5f-7e standard vt100 @@ -885,7 +906,7 @@ } } - if (expect_false (screen.flags & Screen_Insert)) + if (ecb_unlikely (screen.flags & Screen_Insert)) scr_insdel_chars (width, INSERT); if (width != 0) @@ -903,7 +924,7 @@ rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); // if the character doesn't fit into the remaining columns... - if (expect_false (screen.cur.col > ncol - width && ncol >= width)) + if (ecb_unlikely (screen.cur.col > ncol - width && ncol >= width)) { if (screen.flags & Screen_Autowrap) { @@ -920,7 +941,7 @@ // due to wonderful coincidences everywhere else in this loop // we never have to check for overwriting a wide char itself, // only its tail. - if (expect_false (line->t[screen.cur.col] == NOCHAR)) + if (ecb_unlikely (line->t[screen.cur.col] == NOCHAR)) scr_kill_char (*line, screen.cur.col); line->touch (); @@ -930,7 +951,7 @@ line->t[screen.cur.col] = c; line->r[screen.cur.col] = rend; - if (expect_true (screen.cur.col < ncol - 1)) + if (ecb_likely (screen.cur.col < ncol - 1)) screen.cur.col++; else { @@ -943,10 +964,10 @@ c = NOCHAR; } - while (expect_false (--width > 0)); + while (ecb_unlikely (--width > 0)); // pad with spaces when overwriting wide character with smaller one - for (int c = screen.cur.col; expect_false (c < ncol && line->t[c] == NOCHAR); c++) + for (int c = screen.cur.col; ecb_unlikely (c < ncol && line->t[c] == NOCHAR); c++) { line->t[c] = ' '; line->r[c] = rend; @@ -1922,7 +1943,7 @@ # ifdef MAPALERT_OPTION if (option (Opt_mapAlert)) # endif - XMapWindow (dpy, parent[0]); + XMapWindow (dpy, parent); # endif # if ENABLE_FRILLS @@ -1945,7 +1966,6 @@ } /* ------------------------------------------------------------------------- */ -/* ARGSUSED */ void rxvt_term::scr_printscreen (int fullhist) NOTHROW { @@ -2233,7 +2253,7 @@ // redraw one or more characters // seek to the beginning of wide characters - while (expect_false (stp[col] == NOCHAR && col > 0)) + while (ecb_unlikely (stp[col] == NOCHAR && col > 0)) --col; rend_t rend = srp[col]; /* screen rendition (target rendition) */ @@ -2281,7 +2301,7 @@ count -= i; /* dump any matching trailing chars */ // sometimes we optimize away the trailing NOCHAR's, add them back - while (expect_false (i && text[count] == NOCHAR)) + while (ecb_unlikely (i && text[count] == NOCHAR)) count++, i--; /* @@ -2291,7 +2311,7 @@ int back = bgcolor_of (rend); // desired background // only do special processing if any attributes are set, which is unlikely - if (expect_false (rend & (RS_baseattrMask | RS_Careful | RS_Sel))) + if (ecb_unlikely (rend & (RS_baseattrMask | RS_Careful | RS_Sel))) { bool invert = rend & RS_RVid; @@ -2390,7 +2410,7 @@ */ rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; - if (expect_true (have_bg && back == Color_bg)) + if (ecb_likely (have_bg && back == Color_bg)) { // this is very ugly, maybe push it into ->draw? @@ -2407,7 +2427,7 @@ else font->draw (*drawable, xpixel, ypixel, text, count, fore, back); - if (expect_false (rend & RS_Uline && font->descent > 1 && fore != back)) + if (ecb_unlikely (rend & RS_Uline && font->descent > 1 && fore != back)) { #if ENABLE_FRILLS if (ISSET_PIXCOLOR (Color_underline)) @@ -2518,7 +2538,7 @@ # ifdef ENABLE_TRANSPARENCY if (bg_flags & BG_IS_TRANSPARENT) { - XSetWindowBackgroundPixmap (dpy, parent[0], bg_pixmap); + XSetWindowBackgroundPixmap (dpy, parent, bg_pixmap); XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); transparent = true; @@ -2526,18 +2546,18 @@ else # endif { - XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]); + XSetWindowBackground (dpy, parent, pix_colors[Color_border]); XSetWindowBackgroundPixmap (dpy, vt, bg_pixmap); } } else #endif { - XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]); + XSetWindowBackground (dpy, parent, pix_colors[Color_border]); XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); } - XClearWindow (dpy, parent[0]); + XClearWindow (dpy, parent); if (scrollBar.win) { @@ -2545,7 +2565,7 @@ XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); else XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); - scrollBar.state = STATE_IDLE; + scrollBar.state = SB_STATE_IDLE; scrollBar.show (0); } @@ -2734,25 +2754,15 @@ /* ------------------------------------------------------------------------- */ /* - * Request the current selection: - * Order: > internal selection if available - * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+) - * > CUT_BUFFER0 - * (+) if ownership is claimed but property is empty, rxvt_selection_paste () - * will auto fallback to CUT_BUFFER0 + * Request PRIMARY, SECONDARY or CLIPBOARD selection. + * if the requested selection has no owner or is empty CUT_BUFFER0 is used + * as fallback * EXT: button 2 release */ void rxvt_term::selection_request (Time tm, int selnum) NOTHROW { - if (selection.text && selnum == Sel_Primary) - { - /* internal selection */ - char *str = rxvt_wcstombs (selection.text, selection.len); - paste (str, strlen (str)); - free (str); - } - else if (!selection_req) + if (!selection_req) { selection_req = new rxvt_selection (display, selnum, tm, vt, xa[XA_VT_SELECTION], this); selection_req->run (); @@ -3410,6 +3420,7 @@ void rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW { + Atom property = rq.property == None ? rq.target : rq.property; XSelectionEvent ev; ev.type = SelectionNotify; @@ -3434,10 +3445,10 @@ *target++ = xa[XA_UTF8_STRING]; #endif - XChangeProperty (dpy, rq.requestor, rq.property, XA_ATOM, + XChangeProperty (dpy, rq.requestor, property, XA_ATOM, 32, PropModeReplace, (unsigned char *)target_list, target - target_list); - ev.property = rq.property; + ev.property = property; } #if TODO // TODO else if (rq.target == xa[XA_MULTIPLE]) @@ -3447,15 +3458,15 @@ #endif else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == XA_PRIMARY && selection.text) { - XChangeProperty (dpy, rq.requestor, rq.property, rq.target, + XChangeProperty (dpy, rq.requestor, property, rq.target, 32, PropModeReplace, (unsigned char *)&selection_time, 1); - ev.property = rq.property; + ev.property = property; } else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == xa[XA_CLIPBOARD] && selection.clip_text) { - XChangeProperty (dpy, rq.requestor, rq.property, rq.target, + XChangeProperty (dpy, rq.requestor, property, rq.target, 32, PropModeReplace, (unsigned char *)&clipboard_time, 1); - ev.property = rq.property; + ev.property = property; } else if (rq.target == XA_STRING || rq.target == xa[XA_TEXT] @@ -3536,10 +3547,10 @@ ct.encoding = target; } - XChangeProperty (dpy, rq.requestor, rq.property, + XChangeProperty (dpy, rq.requestor, property, ct.encoding, 8, PropModeReplace, ct.value, (int)ct.nitems); - ev.property = rq.property; + ev.property = property; if (freect) XFree (ct.value);