--- rxvt-unicode/src/screen.C 2005/12/19 02:16:24 1.173 +++ rxvt-unicode/src/screen.C 2005/12/21 14:23:30 1.184 @@ -118,6 +118,13 @@ void rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) { + if (!l.t) + { + lalloc (l); + col = 0; + width = ncol; + } + efs &= ~RS_baseattrMask; efs = SET_FONT (efs, FONTSET (efs)->find_font (' ')); @@ -136,9 +143,6 @@ void rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) { - if (!l.t) - lalloc (l); - scr_blank_line (l, 0, ncol, efs); } @@ -172,13 +176,13 @@ { saveLines++; prev_nrow--; - nscrolled++; + nsaved++; } want_refresh = 1; int prev_total_rows = prev_nrow + saveLines; - int total_rows = nrow + saveLines; + total_rows = nrow + saveLines; screen.tscroll = 0; screen.bscroll = nrow - 1; @@ -189,9 +193,8 @@ * first time called so just malloc everything: don't rely on realloc * Note: this is still needed so that all the scrollback lines are NULL */ - nscrolled = 0; /* no saved lines */ + nsaved = 0; /* no saved lines */ term_start = 0; - nsaved = 0; talloc = new rxvt_salloc (ncol * sizeof (text_t)); ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); @@ -201,13 +204,9 @@ drawn = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); swap_save = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); - screen.line = (line_t **)rxvt_calloc (nrow, sizeof (line_t *)); - - scr_update_term (); - for (p = nrow; p--; ) { - scr_blank_screen_mem (*screen.line[p], DEFAULT_RSTYLE); + scr_blank_screen_mem (ROW(p), DEFAULT_RSTYLE); scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE); } @@ -249,19 +248,19 @@ if (nrow < prev_nrow) { /* delete rows */ - k = min (nscrolled, prev_nrow - nrow); + k = min (nsaved, prev_nrow - nrow); // k = max (0, - ( (nrow - 1) - r->screen.cur.row)); // mmc's http://maruska.dyndns.org/wiki/scrolling-bug //make configurable? //D TODO - scr_scroll_text (0, (int)prev_nrow - 1, k, 1); + scr_scroll_text (0, (int)prev_nrow - 1, k); for (p = nrow; p < prev_nrow; p++) { - lfree (save[p + saveLines]); + lfree (ROW(p)); lfree (swap_save[p]); lfree (drawn[p]); } /* we have fewer rows so fix up cursor position */ - MIN_IT (screen.cur.row, (int32_t)nrow - 1); + min_it (screen.cur.row, (int32_t)nrow - 1); scr_reset_realloc (); /* realloc _last_ */ } @@ -273,7 +272,7 @@ int ocol = ncol; ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this - k = min (nscrolled, nrow - prev_nrow); + k = min (nsaved, nrow - prev_nrow); for (p = prev_total_rows; p < total_rows; p++) save[p].clear (); @@ -281,8 +280,6 @@ for (p = prev_total_rows; p < total_rows - k; p++) scr_blank_screen_mem (save[p], DEFAULT_RSTYLE); - scr_update_term (); - for (p = prev_nrow; p < nrow; p++) { swap_save[p].clear (); scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); @@ -291,16 +288,16 @@ if (k > 0) { - scr_scroll_text (0, (int)nrow - 1, -k, 1); + scr_scroll_text (0, (int)nrow - 1, -k); screen.cur.row += k; screen.s_cur.row += k; - nscrolled -= k; + nsaved -= k; } #ifdef DEBUG_STRICT assert (screen.cur.row < nrow); #else /* drive with your eyes closed */ - MIN_IT (screen.cur.row, nrow - 1); + min_it (screen.cur.row, nrow - 1); #endif ncol = ocol; // save b/c scr_blank_screen_mem uses this } @@ -320,7 +317,7 @@ lresize (swap_save[p]); } - MIN_IT (screen.cur.col, (int16_t)ncol - 1); + min_it (screen.cur.col, (int16_t)ncol - 1); delete old_ta; delete old_ra; @@ -372,7 +369,7 @@ { tp [qrow] = (text_t *)ta->alloc (); rp [qrow] = (rend_t *)ra->alloc (); - tl [qrow] = -1; + tl [qrow] = LINE_CONT1; int qcol = 0; @@ -439,13 +436,10 @@ void rxvt_term::scr_reset_realloc () { - unsigned int total_rows = nrow + saveLines; - - screen.line = (line_t **)rxvt_realloc (screen.line, nrow * sizeof (line_t *)); swap_save = (line_t *) rxvt_realloc (swap_save , nrow * sizeof (line_t)); drawn = (line_t *) rxvt_realloc (drawn , nrow * sizeof (line_t)); + buf = (line_t *) rxvt_realloc (buf , nrow * sizeof (line_t)); save = (line_t *) rxvt_realloc (save , total_rows * sizeof (line_t)); - buf = (line_t *) rxvt_realloc (buf , total_rows * sizeof (line_t)); } /* ------------------------------------------------------------------------- */ @@ -455,14 +449,9 @@ void rxvt_term::scr_release () { - unsigned int total_rows; - - total_rows = nrow + saveLines; - delete talloc; talloc = 0; delete ralloc; ralloc = 0; - free (screen.line); free (save); free (swap_save); free (drawn); @@ -528,14 +517,14 @@ } /* boundary check in case screen size changed between SAVE and RESTORE */ - MIN_IT (s->cur.row, nrow - 1); - MIN_IT (s->cur.col, ncol - 1); + min_it (s->cur.row, nrow - 1); + min_it (s->cur.col, ncol - 1); #ifdef DEBUG_STRICT assert (s->cur.row >= 0); assert (s->cur.col >= 0); #else /* drive with your eyes closed */ - MAX_IT (s->cur.row, 0); - MAX_IT (s->cur.col, 0); + max_it (s->cur.row, 0); + max_it (s->cur.col, 0); #endif } @@ -548,13 +537,7 @@ int rxvt_term::scr_change_screen (int scrn) { - int i; -#if NSCREENS - int offset; -#endif - want_refresh = 1; - view_start = 0; if (current_screen == scrn) @@ -562,33 +545,31 @@ selection_check (2); /* check for boundary cross */ - i = current_screen; current_screen = scrn; scrn = i; + int i = current_screen; current_screen = scrn; scrn = i; + + ::swap (screen.cur.row, swap.cur.row); + ::swap (screen.cur.col, swap.cur.col); - SWAP_IT (screen.cur.row, swap.cur.row, int16_t); - SWAP_IT (screen.cur.col, swap.cur.col, int16_t); - MAX_IT (screen.cur.row, 0); - MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); - MAX_IT (screen.cur.col, 0); - MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1); + 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 (options & Opt_secondaryScreen) { num_scr = 0; - offset = saveLines; - for (i = prev_nrow; i--;) - SWAP_IT (*(screen.line[i]), swap_save[i], line_t); + for (int i = nrow; i--; ) + ::swap (ROW(i), swap_save[i]); - SWAP_IT (screen.charset, swap.charset, int16_t); - SWAP_IT (screen.flags, swap.flags, int); + ::swap (screen.charset, swap.charset); + ::swap (screen.flags, swap.flags); screen.flags |= Screen_VisibleCursor; swap.flags |= Screen_VisibleCursor; } else #endif if (options & Opt_secondaryScroll) - scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0); + scr_scroll_text (0, prev_nrow - 1, prev_nrow); return scrn; } @@ -605,7 +586,7 @@ screen.cur.col = 0; if (screen.cur.row == screen.bscroll) - scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0); + scr_scroll_text (screen.tscroll, screen.bscroll, 1); else if (screen.cur.row < nrow - 1) screen.cur.row++; } @@ -641,122 +622,91 @@ rstyle &= ~style; } -// set screen.line pointers to the actual lines in the save buffer -void -rxvt_term::scr_update_term () -{ - for (int i = nrow; i--; ) - screen.line[i] = save + saveLines + i; -} - /* ------------------------------------------------------------------------- */ /* * Scroll text between and inclusive, by lines * count positive ==> scroll up * count negative ==> scroll down - * spec == 0 for normal routines */ int -rxvt_term::scr_scroll_text (int row1, int row2, int count, int spec) +rxvt_term::scr_scroll_text (int row1, int row2, int count) { - int i, j; - if (count == 0 || (row1 > row2)) return 0; want_refresh = 1; + num_scr += count; - if (row1 == 0 && count > 0 + if (count > 0 + && row1 == 0 + && row2 == nrow - 1 && (current_screen == PRIMARY || options & Opt_secondaryScroll)) { - nscrolled += count; + nsaved = min (nsaved + count, saveLines); + term_start = (term_start + count) % total_rows; - if (nscrolled > saveLines) - nscrolled = saveLines; + if (selection.op && current_screen == selection.screen) + { + selection.beg.row -= count; + selection.end.row -= count; + selection.mark.row -= count; + + selection_check (0); + } + for (int i = count; i--; ) + scr_blank_screen_mem (ROW(row2 - i), rstyle); + if ((options & Opt_scrollWithBuffer) && view_start != 0 && view_start != saveLines) scr_page (UP, count); } - else if (!spec) - row1 += saveLines; - - row2 += saveLines; - - if (selection.op && current_screen == selection.screen) + else { - i = selection.beg.row + saveLines; - j = selection.end.row + saveLines; - - if ((i < row1 && j > row1) - || (i < row2 && j > row2) - || (i - count < row1 && i >= row1) - || (i - count > row2 && i <= row2) - || (j - count < row1 && j >= row1) - || (j - count > row2 && j <= row2)) - { - CLEAR_ALL_SELECTION (); - selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ - } - else if (j >= row1 && j <= row2) + if (selection.op && current_screen == selection.screen) { - /* move selected region too */ - selection.beg.row -= count; - selection.end.row -= count; - selection.mark.row -= count; - } - } - - selection_check (0); /* _after_ nscrolled update */ - - num_scr += count; - j = count; - - if (count < 0) - count = -count; - - i = row2 - row1 + 1; - MIN_IT (count, i); - - if (j > 0) - { - /* scroll up */ + int i = selection.beg.row; + int j = selection.end.row; - /* Copy lines that will get clobbered by the rotation */ - memcpy (buf, save + row1, count * sizeof (line_t)); + if ((i < row1 && j > row1) + || (i < row2 && j > row2) + || (i - count < row1 && i >= row1) + || (i - count > row2 && i <= row2) + || (j - count < row1 && j >= row1) + || (j - count > row2 && j <= row2)) + { + CLEAR_ALL_SELECTION (); + selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ + } + else if (j >= row1 && j <= row2) + { + /* move selected region too */ + selection.beg.row -= count; + selection.end.row -= count; + selection.mark.row -= count; + + selection_check (0); + } + } - /* Rotate lines */ - i = row2 - row1 - count + 1; - memmove (save + row1, save + row1 + count, i * sizeof (line_t)); + // use a simple and robust scrolling algorithm, this + // part of scr_scroll_text is not time-critical. - j = row2 - count + 1, i = count; - } - else /* if (j < 0) */ - { - /* scroll down */ + int rows = row2 - row1 + 1; - /* Copy lines that will get clobbered by the rotation */ - for (i = 0, j = row2; i < count; i++, j--) - buf[i] = save[j]; + for (int row = 0; row < rows; row++) + { + buf [row] = ROW(row1 + (row + count + rows) % rows); - /* Rotate lines */ - for (j = row2, i = j - count; i >= row1; i--, j--) - save[j] = save[i]; + if (!IN_RANGE_EXC (row + count, 0, rows)) + scr_blank_screen_mem (buf [row], rstyle); + } - j = row1, i = count; - count = -count; + for (int row = 0; row < rows; row++) + ROW(row1 + row) = buf [row]; } - /* Resurrect lines */ - memcpy (save + j, buf, i * sizeof (line_t)); - - scr_update_term (); - - if (!spec) /* line length may not equal ncol */ - for (; i--; j++) - scr_blank_screen_mem (save[j], rstyle); - return count; } @@ -787,7 +737,7 @@ && (screen.bscroll == (nrow - 1))) { /* _at least_ this many lines need to be scrolled */ - scr_scroll_text (screen.tscroll, screen.bscroll, nlines, 0); + scr_scroll_text (screen.tscroll, screen.bscroll, nlines); screen.cur.row -= nlines; } } @@ -795,17 +745,17 @@ #ifdef DEBUG_STRICT assert (screen.cur.col < last_col); assert ((screen.cur.row < nrow) - && (screen.cur.row >= - (int32_t)nscrolled)); + && (screen.cur.row >= - (int32_t)nsaved)); #else /* drive with your eyes closed */ - MIN_IT (screen.cur.col, last_col - 1); - MIN_IT (screen.cur.row, (int32_t)nrow - 1); - MAX_IT (screen.cur.row, - (int32_t)nscrolled); + min_it (screen.cur.col, last_col - 1); + min_it (screen.cur.row, (int32_t)nrow - 1); + max_it (screen.cur.row, - (int32_t)nsaved); #endif - row = screen.cur.row + saveLines; + row = screen.cur.row; checksel = selection.op && current_screen == selection.screen ? 1 : 0; - line_t *line = save + row; + line_t *line = &ROW(row); while (str < strend) { @@ -814,23 +764,23 @@ if (c < 0x20) if (c == C0_LF) { - if (line->l != -1) /* XXX: think about this */ - MAX_IT (line->l, screen.cur.col); + if (!line->is_longer ()) /* XXX: think about this */ + max_it (line->l, screen.cur.col); screen.flags &= ~Screen_WrapNext; if (screen.cur.row == screen.bscroll) - scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0); + scr_scroll_text (screen.tscroll, screen.bscroll, 1); else if (screen.cur.row < (nrow - 1)) - row = (++screen.cur.row) + saveLines; + row = ++screen.cur.row; - line = save + row; /* _must_ refresh */ + line = &ROW(row); /* _must_ refresh */ continue; } else if (c == C0_CR) { - if (line->l != -1) /* XXX: think about this */ - MAX_IT (line->l, screen.cur.col); + if (!line->is_longer ()) /* XXX: think about this */ + max_it (line->l, screen.cur.col); screen.flags &= ~Screen_WrapNext; screen.cur.col = 0; @@ -857,16 +807,16 @@ if (screen.flags & Screen_WrapNext) { - line->l = -1; + line->set_is_longer (); scr_do_wrap (); - row = screen.cur.row + saveLines; - line = save + row; /* _must_ refresh */ + row = screen.cur.row; + line = &ROW(row); /* _must_ refresh */ } // some utf-8 decoders "decode" surrogate characters: let's fix this. - if (IN_RANGE (c, 0xd800, 0xdfff)) + if (IN_RANGE_INC (c, 0xd800, 0xdfff)) c = 0xfffd; // rely on wcwidth to tell us the character width, at least for non-latin1 @@ -991,9 +941,9 @@ tp--, rp--; } else if (screen.cur.row > 0 - && save [screen.cur.row - 1 + saveLines].is_cont ()) + && ROW(screen.cur.row - 1).is_longer ()) { - line_t *line = save + (screen.cur.row - 1 + saveLines); + line_t *line = &ROW(screen.cur.row - 1); tp = line->t + last_col - 1; rp = line->r + last_col - 1; @@ -1015,13 +965,13 @@ } } - if (line->l != -1) /* XXX: think about this */ - MAX_IT (line->l, screen.cur.col); + if (!line->is_longer ()) /* XXX: think about this */ + max_it (line->l, screen.cur.col); #ifdef DEBUG_STRICT assert (screen.cur.row >= 0); #else /* drive with your eyes closed */ - MAX_IT (screen.cur.row, 0); + max_it (screen.cur.row, 0); #endif } @@ -1070,9 +1020,9 @@ return; else if (count > 0) { - int row = saveLines + screen.cur.row; + int row = screen.cur.row; - line_t &l = save[row]; + line_t &l = ROW(row); rend_t base_rend = l.r[i]; ht &= l.t[i] == ' '; @@ -1096,8 +1046,8 @@ { base_rend = SET_FONT (base_rend, 0); - if (l.l != -1) /* XXX: think about this */ - MAX_IT (l.l, x); + if (!l.is_longer ()) /* XXX: think about this */ + max_it (l.l, x); i = screen.cur.col; @@ -1143,12 +1093,7 @@ if (screen.cur.col > 0) scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE); else - { - if (save[screen.cur.row + saveLines].l == 0) - return; /* um, yeah? */ - - scr_insdel_chars (1, INSERT); - } + scr_insdel_chars (1, INSERT); } #endif /* ------------------------------------------------------------------------- */ @@ -1168,12 +1113,10 @@ scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); else { - row = screen.cur.row + saveLines; + row = screen.cur.row; - if (save[row].l == 0) - return; /* um, yeah? */ - else if (save[row].is_cont ()) - save[row].l = ncol; + if (ROW(row).is_longer ()) //TODO//FIXME//LEN + ROW(row).l = ncol; scr_gotorc (0, 0, R_RELATIVE); scr_insdel_chars (1, DELETE); @@ -1193,8 +1136,8 @@ ZERO_SCROLLBACK (); screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col; - MAX_IT (screen.cur.col, 0); - MIN_IT (screen.cur.col, (int32_t)ncol - 1); + max_it (screen.cur.col, 0); + min_it (screen.cur.col, (int32_t)ncol - 1); screen.flags &= ~Screen_WrapNext; @@ -1222,14 +1165,14 @@ if (screen.flags & Screen_Relative) { /* relative origin mode */ screen.cur.row = row + screen.tscroll; - MIN_IT (screen.cur.row, screen.bscroll); + min_it (screen.cur.row, screen.bscroll); } else screen.cur.row = row; } - MAX_IT (screen.cur.row, 0); - MIN_IT (screen.cur.row, (int32_t)nrow - 1); + max_it (screen.cur.row, 0); + min_it (screen.cur.row, (int32_t)nrow - 1); } /* ------------------------------------------------------------------------- */ @@ -1250,12 +1193,12 @@ if ((screen.cur.row == screen.bscroll && direction == UP) || (screen.cur.row == screen.tscroll && direction == DN)) - scr_scroll_text (screen.tscroll, screen.bscroll, dirn, 0); + scr_scroll_text (screen.tscroll, screen.bscroll, dirn); else screen.cur.row += dirn; - MAX_IT (screen.cur.row, 0); - MIN_IT (screen.cur.row, (int32_t)nrow - 1); + max_it (screen.cur.row, 0); + min_it (screen.cur.row, (int32_t)nrow - 1); selection_check (0); } @@ -1276,14 +1219,14 @@ selection_check (1); - row = saveLines + screen.cur.row; + row = screen.cur.row; switch (mode) { case 0: /* erase to end of line */ col = screen.cur.col; num = ncol - col; - MIN_IT (save[row].l, (int16_t)col); + min_it (ROW(row).l, (int16_t)col); if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) CLEAR_SELECTION (); @@ -1298,7 +1241,7 @@ case 2: /* erase whole line */ col = 0; num = ncol; - save[row].l = 0; + ROW(row).l = 0; if (selection.beg.row <= screen.cur.row && selection.end.row >= screen.cur.row) CLEAR_SELECTION (); @@ -1307,10 +1250,7 @@ return; } - if (save[row].t) - scr_blank_line (save[row], col, num, rstyle); - else - scr_blank_screen_mem (save[row], rstyle); + scr_blank_line (ROW(row), col, num, rstyle); } /* ------------------------------------------------------------------------- */ @@ -1324,15 +1264,13 @@ rxvt_term::scr_erase_screen (int mode) { int num; - int32_t row, row_offset; + int32_t row; rend_t ren; XGCValues gcvalue; want_refresh = 1; ZERO_SCROLLBACK (); - row_offset = (int32_t)saveLines; - switch (mode) { case 0: /* erase to end of screen */ @@ -1365,7 +1303,7 @@ if (row >= nrow) /* Out Of Bounds */ return; - MIN_IT (num, (nrow - row)); + min_it (num, (nrow - row)); if (rstyle & (RS_RVid | RS_Uline)) ren = (rend_t) ~RS_None; @@ -1386,8 +1324,8 @@ for (; num--; row++) { - scr_blank_screen_mem (save[row + row_offset], rstyle); - save[row + row_offset].l = 0; + scr_blank_screen_mem (ROW (row), rstyle); + ROW (row).l = 0; scr_blank_line (drawn[row], 0, ncol, ren); } } @@ -1399,7 +1337,7 @@ want_refresh = 1; ZERO_SCROLLBACK (); - nscrolled = 0; + nsaved = 0; } #endif @@ -1411,8 +1349,7 @@ void rxvt_term::scr_E () { - int i, j, k; - rend_t *r1, fs; + rend_t fs; want_refresh = 1; ZERO_SCROLLBACK (); @@ -1421,12 +1358,17 @@ selection_check (3); fs = SET_FONT (rstyle, FONTSET (rstyle)->find_font ('E')); - for (k = saveLines, i = nrow; i--; k++) + for (int row = nrow; row--; ) { - save[k].l = ncol; /* make the `E's selectable */ - fill_text (save[k].t, 'E', ncol); - for (r1 = save[k].r, j = ncol; j--; ) + line_t &line = ROW(row); + + fill_text (line.t, 'E', ncol); + rend_t *r1 = line.r; + + for (int j = ncol; j--; ) *r1++ = fs; + + line.l = ncol; /* make the `E's selectable */ } } @@ -1457,7 +1399,7 @@ scr_do_wrap (); - scr_scroll_text (screen.cur.row, screen.bscroll, insdel * count, 0); + scr_scroll_text (screen.cur.row, screen.bscroll, insdel * count); } /* ------------------------------------------------------------------------- */ @@ -1479,11 +1421,11 @@ scr_do_wrap (); selection_check (1); - MIN_IT (count, (ncol - screen.cur.col)); + min_it (count, (ncol - screen.cur.col)); - row = screen.cur.row + saveLines; + row = screen.cur.row; - line_t *line = save + row; + line_t *line = &ROW(row); switch (insdel) { @@ -1494,10 +1436,10 @@ line->r[col] = line->r[col - count]; } - if (line->l != -1) + if (!line->is_longer ()) { line->l += count; - MIN_IT (line->l, ncol); + min_it (line->l, ncol); } if (selection.op && current_screen == selection.screen @@ -1514,14 +1456,14 @@ } } - scr_blank_line (save[row], screen.cur.col, count, rstyle); + scr_blank_line (*line, screen.cur.col, count, rstyle); break; case ERASE: screen.cur.col += count; /* don't worry if > ncol */ selection_check (1); screen.cur.col -= count; - scr_blank_line (save[row], screen.cur.col, count, rstyle); + scr_blank_line (*line, screen.cur.col, count, rstyle); break; case DELETE: @@ -1535,11 +1477,10 @@ scr_blank_line (*line, ncol - count, count, tr); - if (line->is_cont ()) /* break line continuation */ + if (line->is_longer ()) /* break line continuation */ line->l = ncol; - line->l -= count; - MAX_IT (line->l, 0); + max_it (line->l - count, 0); if (selection.op && current_screen == selection.screen && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) @@ -1569,8 +1510,8 @@ void rxvt_term::scr_scroll_region (int top, int bot) { - MAX_IT (top, 0); - MIN_IT (bot, (int)nrow - 1); + max_it (top, 0); + min_it (bot, (int)nrow - 1); if (top > bot) return; @@ -1678,7 +1619,7 @@ if (rvideo != mode) { rvideo = mode; - SWAP_IT (pix_colors[Color_fg], pix_colors[Color_bg], rxvt_color); + ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); #if XPM_BACKGROUND if (bgPixmap.pixmap == None) #endif @@ -1824,10 +1765,11 @@ #endif #ifdef DEBUG_STRICT - x = max (x, 0); - x = min (x, (int)width); - y = max (y, 0); - y = min (y, (int)height); +#if 0 + // that's not debugging //TODO //FIXME + clamp_it (x, 0, width); + clamp_it (y, 0, height); +#endif #endif /* round down */ @@ -1840,8 +1782,8 @@ /* sanity checks */ for (i = PART_BEG; i < RC_COUNT; i++) { - MIN_IT (rc[i].col, ncol - 1); - MIN_IT (rc[i].row, nrow - 1); + min_it (rc[i].col, ncol - 1); + min_it (rc[i].row, nrow - 1); } for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) @@ -1876,12 +1818,12 @@ if (y < len) { - p = (nrow + nscrolled) * (len - y) / len; + p = (nrow + nsaved) * (len - y) / len; p -= (long) (nrow - 1); p = max (p, 0); } - view_start = (unsigned int)min (p, nscrolled); + view_start = (unsigned int)min (p, nsaved); return scr_changeview (oldviewstart); } @@ -1902,7 +1844,7 @@ if (direction == UP) { n = view_start + nlines; - view_start = min (n, nscrolled); + view_start = min (n, nsaved); } else { @@ -1956,31 +1898,31 @@ rxvt_term::scr_printscreen (int fullhist) { #ifdef PRINTPIPE - int i, r1, nrows, row_offset; + int nrows, row_start; FILE *fd; if ((fd = popen_printer ()) == NULL) return; - nrows = nrow; - row_offset = saveLines; - - if (!fullhist) - row_offset -= view_start; + if (fullhist) + { + nrows = nrow + nsaved; + row_start = -nsaved; + } else { - nrows += nscrolled; - row_offset -= nscrolled; + nrows = nrow; + row_start = -view_start; } wctomb (0, 0); - for (r1 = 0; r1 < nrows; r1++) + for (int r1 = 0; r1 < nrows; r1++) { - text_t *tp = save[r1 + row_offset].t; - int len = save[r1 + row_offset].l; + text_t *tp = ROW(r1).t; + int len = ROW(r1).l; - for (i = len >= 0 ? len : ncol - 1; i--; ) + for (int i = len >= 0 ? len : ncol - 1; i--; ) //TODO//FIXME//LEN { char mb[MB_LEN_MAX]; text_t t = *tp++; @@ -2018,8 +1960,7 @@ showcursor; /* show the cursor */ int16_t col, row, /* column/row we're processing */ ocrow; /* old cursor row */ - int i, /* tmp */ - row_offset; /* basic offset in screen structure */ + int i; /* tmp */ #ifndef NO_CURSORCOLOR rend_t cc1; /* store colours at cursor position (s) */ #endif @@ -2036,8 +1977,6 @@ must_clear = 0; refresh_count = 0; - row_offset = saveLines - view_start; - #if XPM_BACKGROUND must_clear |= bgPixmap.pixmap != None; #endif @@ -2069,10 +2008,10 @@ { int col = screen.cur.col; - while (col && screen.line[screen.cur.row]->t[col] == NOCHAR) + while (col && ROW(screen.cur.row).t[col] == NOCHAR) col--; - crp = &screen.line[screen.cur.row]->r[col]; + crp = &ROW(screen.cur.row).r[col]; if (showcursor && focus) { @@ -2150,8 +2089,8 @@ */ i = num_scr; if (!display->is_local - && refresh_type == FAST_REFRESH && num_scr_allow && i - && abs (i) < nrow && !must_clear) + && refresh_type == FAST_REFRESH && num_scr_allow && num_scr + && abs (num_scr) < nrow && !must_clear) { int16_t nits; int j; @@ -2164,7 +2103,7 @@ { if (row + i >= 0 && row + i < nrow && row + i != ocrow) { - line_t s = save[row + row_offset]; + line_t s = ROW(row - view_start); line_t d = drawn[row]; line_t d2 = drawn[row + i]; @@ -2194,7 +2133,7 @@ { /* also comes here at end if needed because of >= above */ if (wlen < len) - SWAP_IT (wlen, len, int); + ::swap (wlen, len); XCopyArea (display->display, vt, vt, gc, 0, Row2Pixel (len + i), @@ -2212,8 +2151,8 @@ */ for (row = 0; row < nrow; row++) { - text_t *stp = save[row + row_offset].t; - rend_t *srp = save[row + row_offset].r; + text_t *stp = ROW(row - view_start).t; + rend_t *srp = ROW(row - view_start).r; text_t *dtp = drawn[row].t; rend_t *drp = drawn[row].r; @@ -2336,7 +2275,7 @@ if (invert) { - SWAP_IT (fore, back, int); + ::swap (fore, back); #ifndef NO_BOLD_UNDERLINE_REVERSE if (ISSET_PIXCOLOR (Color_RV)) @@ -2434,7 +2373,7 @@ int cursorwidth = 1; int col = oldcursor.col; - while (col && save[screen.cur.row + saveLines].t[col] == NOCHAR) + while (col && ROW(screen.cur.row).t[col] == NOCHAR) col--; while (col + cursorwidth < ncol @@ -2479,7 +2418,7 @@ void rxvt_term::scr_remap_chars () { - for (int i = nrow + saveLines; i--; ) + for (int i = total_rows; i--; ) scr_remap_chars (save[i]); for (int i = nrow; i--; ) @@ -2537,41 +2476,40 @@ void rxvt_term::scr_reverse_selection () { - if (selection.op && current_screen == selection.screen) + if (selection.op + && current_screen == selection.screen + && selection.end.row >= -view_start) { - int end_row = saveLines - view_start; - int i = selection.beg.row + saveLines; - int col, row = selection.end.row + saveLines; - rend_t *srp; + int view_end = -view_start + nrow; + int row, col; #if ENABLE_FRILLS if (selection.rect) { - end_row += nrow; - - for (; i <= row && i <= end_row; i++) - for (srp = save[i].r, col = selection.beg.col; col < selection.end.col; col++) + for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++) + for (rend_t *srp = ROW(row).r, col = selection.beg.col; col < selection.end.col; col++) srp[col] ^= RS_RVid; } else #endif { - if (i >= end_row) - col = selection.beg.col; + if (selection.beg.row >= -view_start) + { + col = selection.beg.col; + row = selection.beg.row; + } else { col = 0; - i = end_row; + row = view_start; } - end_row += nrow; - - for (; i < row && i < end_row; i++, col = 0) - for (srp = save[i].r; col < ncol; col++) + for (; row < min (selection.end.row, view_end); row++, col = 0) + for (rend_t *srp = ROW(row).r; col < ncol; col++) srp[col] ^= RS_RVid; - if (i == row && i < end_row) - for (srp = save[i].r; col < selection.end.col; col++) + if (row == selection.end.row) + for (rend_t *srp = ROW(row).r; col < selection.end.col; col++) srp[col] ^= RS_RVid; } } @@ -2590,7 +2528,7 @@ unsigned int width, towrite; char r1[] = "\n"; - for (row = saveLines - nscrolled; + for (row = saveLines - nsaved; row < saveLines + nrow - 1; row++) { width = save[row].l >= 0 ? save[row].l @@ -2612,10 +2550,6 @@ /* ------------------------------------------------------------------------- * * CHARACTER SELECTION * * ------------------------------------------------------------------------- */ - -/* - * -nscrolled <= (selection row) <= nrow - 1 - */ void rxvt_term::selection_check (int check_more) { @@ -2625,12 +2559,9 @@ return; pos.row = pos.col = 0; - if ((selection.beg.row < - (int32_t)nscrolled) - || (selection.beg.row >= nrow) - || (selection.mark.row < - (int32_t)nscrolled) - || (selection.mark.row >= nrow) - || (selection.end.row < - (int32_t)nscrolled) - || (selection.end.row >= nrow) + if (!IN_RANGE_EXC (selection.beg.row, -nsaved, nrow) + || !IN_RANGE_EXC (selection.mark.row, -nsaved, nrow) + || !IN_RANGE_EXC (selection.end.row, -nsaved, nrow) || (check_more == 1 && current_screen == selection.screen && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) @@ -2946,7 +2877,7 @@ void rxvt_term::selection_make (Time tm) { - int i, col, end_col, row, end_row; + int i; wchar_t *new_selection_text; text_t *t; @@ -2972,13 +2903,15 @@ i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t)); - col = selection.beg.col; - row = selection.beg.row + saveLines; - end_row = selection.end.row + saveLines; int ofs = 0; int extra = 0; - for (; row <= end_row; row++, col = 0) + int col = selection.beg.col; + int row = selection.beg.row; + + int end_col; + + for (; row <= selection.end.row; row++, col = 0) { #if ENABLE_FRILLS if (selection.rect) @@ -2988,14 +2921,14 @@ } else #endif - end_col = save[row].is_cont () ? ncol : save[row].l; //TODO//FIXME + end_col = ROW(row).is_longer () ? ncol : ROW(row).l; //TODO//FIXME//LEN - MAX_IT (col, 0); + col = max (col, 0); - if (row == end_row || selection.rect) - MIN_IT (end_col, selection.end.col); + if (row == selection.end.row || selection.rect) + end_col = min (end_col, selection.end.col); - t = &save[row].t[col]; + t = ROW(row).t + col; for (; col < end_col; col++) { if (*t == NOCHAR) @@ -3021,7 +2954,7 @@ new_selection_text[ofs++] = *t++; } - if (save[row].l != -1 && row != end_row) + if (!ROW(row).is_longer () && row != selection.end.row) new_selection_text[ofs++] = C0_LF; } @@ -3090,16 +3023,15 @@ rxvt_term::selection_start_colrow (int col, int row) { want_refresh = 1; - selection.mark.col = col; + selection.mark.row = row - view_start; + selection.mark.col = col; - MAX_IT (selection.mark.row, - (int32_t)nscrolled); - MIN_IT (selection.mark.row, (int32_t)nrow - 1); - MAX_IT (selection.mark.col, 0); - MIN_IT (selection.mark.col, (int32_t)ncol - 1); + selection.mark.row = clamp (selection.mark.row, -nsaved, nrow - 1); + selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); while (selection.mark.col > 0 - && save[selection.mark.row + saveLines].t[selection.mark.col] == NOCHAR) + && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) --selection.mark.col; if (selection.op) @@ -3133,26 +3065,23 @@ if (dirn == UP) { - bound.row = saveLines - nscrolled - 1; + bound.row = - nsaved - 1; bound.col = 0; dirnadd = -1; } else { - bound.row = saveLines + nrow; + bound.row = nrow; bound.col = ncol - 1; dirnadd = 1; } - row = mark->row + saveLines; - col = mark->col; - MAX_IT (col, 0); - /* find the edge of a word */ - stp = &save[row].t[col]; - w1 = DELIMIT_TEXT (*stp); + row = mark->row; + col = max (mark->col, 0); - srp = &save[row].r[col]; - w2 = DELIMIT_REND (*srp); + /* find the edge of a word */ + stp = ROW(row).t + col; w1 = DELIMIT_TEXT (*stp); + srp = ROW(row).r + col; w2 = DELIMIT_REND (*srp); for (;;) { @@ -3172,16 +3101,16 @@ if ((col == bound.col) && (row != bound.row)) { - if (save[ (row - (dirn == UP ? 1 : 0))].is_cont ()) + if (ROW(row - (dirn == UP ? 1 : 0)).is_longer ()) { trow = row + dirnadd; tcol = dirn == UP ? ncol - 1 : 0; - if (save[trow].t == NULL) + if (!ROW(trow).t) break; - stp = & (save[trow].t[tcol]); - srp = & (save[trow].r[tcol]); + stp = ROW(trow).t + tcol; + srp = ROW(trow).r + tcol; if (DELIMIT_TEXT (*stp) != w1 || DELIMIT_REND (*srp) != w2) break; @@ -3199,7 +3128,7 @@ col++; /* put us on one past the end */ /* Poke the values back in */ - ret->row = row - saveLines; + ret->row = row; ret->col = col; } @@ -3214,14 +3143,8 @@ void rxvt_term::selection_extend (int x, int y, int flag) { - int col, row; - - col = Pixel2Col (x); - row = Pixel2Row (y); - MAX_IT (row, 0); - MIN_IT (row, (int)nrow - 1); - MAX_IT (col, 0); - MIN_IT (col, (int)ncol); + int col = clamp (Pixel2Col (x), 0, ncol); + int row = clamp (Pixel2Row (y), 0, nrow - 1); /* * If we're selecting characters (single click) then we must check first @@ -3256,7 +3179,6 @@ void rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) { - int end_col; row_col_t pos; enum { LEFT, RIGHT @@ -3297,9 +3219,7 @@ } pos.col = col; - pos.row = row; - - pos.row -= view_start; /* adjust for scroll */ + pos.row = row - view_start; /* * This is mainly xterm style selection with a couple of differences, mainly @@ -3368,21 +3288,17 @@ if (selection.clicks == 1) { - end_col = save[selection.beg.row + saveLines].l; - - if (selection.beg.col > end_col - && end_col != -1 + if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN + && !ROW(selection.beg.row).is_longer () #if ENABLE_FRILLS && !selection.rect #endif ) selection.beg.col = ncol; - end_col = save[selection.end.row + saveLines].l; - if ( - selection.end.col > end_col - && end_col != -1 + selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN + && !ROW(selection.end.row).is_longer () #if ENABLE_FRILLS && !selection.rect #endif @@ -3402,19 +3318,14 @@ #if ENABLE_FRILLS if (options & Opt_tripleclickwords) { - int end_row; - selection_delimit_word (UP, &selection.beg, &selection.beg); - end_row = save[selection.mark.row + saveLines].l; - for (end_row = selection.mark.row; end_row < nrow; end_row++) + for (int end_row = selection.mark.row; end_row < nrow; end_row++) { - end_col = save[end_row + saveLines].l; - - if (end_col != -1) + if (!ROW(end_row).is_longer ()) { selection.end.row = end_row; - selection.end.col = end_col; + selection.end.col = ROW(end_row).l; selection_remove_trailing_spaces (); break; } @@ -3431,11 +3342,11 @@ // select a complete logical line while (selection.beg.row > -saveLines - && save[selection.beg.row - 1 + saveLines].is_cont ()) + && ROW(selection.beg.row - 1).is_longer ()) selection.beg.row--; while (selection.end.row < nrow - && save[selection.end.row + saveLines].is_cont ()) + && ROW(selection.end.row).is_longer ()) selection.end.row++; } } @@ -3456,7 +3367,7 @@ #if ENABLE_FRILLS if (selection.rect && selection.beg.col > selection.end.col) - SWAP_IT (selection.beg.col, selection.end.col, int); + ::swap (selection.beg.col, selection.end.col); #endif } @@ -3470,9 +3381,9 @@ end_col = selection.end.col; end_row = selection.end.row; - for ( ; end_row >= selection.beg.row; ) + for (; end_row >= selection.beg.row; ) { - stp = save[end_row + saveLines].t; + stp = ROW(end_row).t; while (--end_col >= 0) { @@ -3483,7 +3394,7 @@ } if (end_col >= 0 - || save[end_row - 1 + saveLines].l != -1) + || !ROW(end_row - 1).is_longer ()) { selection.end.col = end_col + 1; selection.end.row = end_row; @@ -3664,9 +3575,9 @@ rxvt_term::pixel_position (int *x, int *y) { *x = Pixel2Col (*x); - /* MAX_IT (*x, 0); MIN_IT (*x, (int)ncol - 1); */ + /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */ *y = Pixel2Row (*y); - /* MAX_IT (*y, 0); MIN_IT (*y, (int)nrow - 1); */ + /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */ } /* ------------------------------------------------------------------------- */ @@ -3698,14 +3609,14 @@ if (y < 0) y = nrow - h; // make space for border - w += 2; MIN_IT (w, ncol); - h += 2; MIN_IT (h, nrow); + w += 2; min_it (w, ncol); + h += 2; min_it (h, nrow); - x -= 1; MAX_IT (x, 0); - y -= 1; MAX_IT (y, 0); + x -= 1; max_it (x, 0); + y -= 1; max_it (y, 0); - MIN_IT (x, ncol - w); - MIN_IT (y, nrow - h); + min_it (x, ncol - w); + min_it (y, nrow - h); ov_x = x; ov_y = y; ov_w = w; ov_h = h; @@ -3801,16 +3712,14 @@ if (!ov_text) return; - int row_offset = ov_y + saveLines - view_start; - // swap screen mem with overlay for (int y = ov_h; y--; ) { text_t *t1 = ov_text[y]; rend_t *r1 = ov_rend[y]; - text_t *t2 = save[y + row_offset].t + ov_x; - rend_t *r2 = save[y + row_offset].r + ov_x; + text_t *t2 = ROW(y - view_start).t + ov_x; + rend_t *r2 = ROW(y - view_start).r + ov_x; for (int x = ov_w; x--; ) { @@ -3822,3 +3731,4 @@ #endif /* ------------------------------------------------------------------------- */ +