--- rxvt-unicode/src/screen.C 2005/12/21 14:19:19 1.183 +++ rxvt-unicode/src/screen.C 2006/01/08 06:35:23 1.215 @@ -3,7 +3,7 @@ *---------------------------------------------------------------------------* * * Copyright (c) 1997-2001 Geoff Wing - * Copyright (c) 2003-2004 Marc Lehmann + * Copyright (c) 2003-2006 Marc Lehmann * * 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 @@ -26,6 +26,7 @@ #include "../config.h" /* NECESSARY */ #include "rxvt.h" /* NECESSARY */ +#include "rxvtperl.h" /* NECESSARY */ #include /* get the typedef for CARD32 */ @@ -48,7 +49,7 @@ * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * * ------------------------------------------------------------------------- */ #define ZERO_SCROLLBACK() \ - if (options & Opt_scrollTtyOutput) \ + if (OPTION (Opt_scrollTtyOutput)) \ view_start = 0 #define CLEAR_SELECTION() \ selection.beg.row = selection.beg.col \ @@ -125,6 +126,8 @@ width = ncol; } + l.touch (); + efs &= ~RS_baseattrMask; efs = SET_FONT (efs, FONTSET (efs)->find_font (' ')); @@ -144,17 +147,18 @@ rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) { scr_blank_line (l, 0, ncol, efs); + + l.l = 0; + l.f = 0; } /* ------------------------------------------------------------------------- * * SCREEN INITIALISATION * * ------------------------------------------------------------------------- */ + void rxvt_term::scr_reset () { - unsigned int p, q; - int k; - #if ENABLE_OVERLAY scr_overlay_off (); #endif @@ -174,6 +178,7 @@ // we need at least two lines for wrapping to work correctly if (nrow + saveLines < 2) { + //TODO//FIXME saveLines++; prev_nrow--; nsaved++; @@ -187,7 +192,7 @@ screen.tscroll = 0; screen.bscroll = nrow - 1; - if (!save) + if (!row_buf) { /* * first time called so just malloc everything: don't rely on realloc @@ -199,16 +204,16 @@ talloc = new rxvt_salloc (ncol * sizeof (text_t)); ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); - save = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); - buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); - drawn = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); - swap_save = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); - - for (p = nrow; p--; ) - { - 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); + row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); + temp_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)); + + for (int row = nrow; row--; ) + { + scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE); + scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); + scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); } memset (charsets, 'B', sizeof (charsets)); @@ -242,182 +247,164 @@ * add or delete rows as appropriate */ - rxvt_salloc *old_ta; - rxvt_salloc *old_ra; + rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t)); + rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); +#if 0 if (nrow < prev_nrow) { - /* delete rows */ - 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); - - for (p = nrow; p < prev_nrow; p++) + for (int row = nrow; row < prev_nrow; row++) { - lfree (ROW(p)); - lfree (swap_save[p]); - lfree (drawn[p]); + lfree (swap_buf [row]); + lfree (drawn_buf[row]); } - - /* we have fewer rows so fix up cursor position */ - min_it (screen.cur.row, (int32_t)nrow - 1); - - scr_reset_realloc (); /* realloc _last_ */ } - else if (nrow > prev_nrow) - { - /* add rows */ - scr_reset_realloc (); /* realloc _first_ */ - - int ocol = ncol; - ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this - - k = min (nsaved, nrow - prev_nrow); - - for (p = prev_total_rows; p < total_rows; p++) - save[p].clear (); - - for (p = prev_total_rows; p < total_rows - k; p++) - scr_blank_screen_mem (save[p], DEFAULT_RSTYLE); - - for (p = prev_nrow; p < nrow; p++) - { - swap_save[p].clear (); scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); - drawn[p].clear (); scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE); - } +#endif - if (k > 0) - { - scr_scroll_text (0, (int)nrow - 1, -k); - screen.cur.row += k; - screen.s_cur.row += k; - nsaved -= k; - } + drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); + temp_buf = (line_t *)rxvt_realloc (temp_buf , nrow * sizeof (line_t)); + swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t)); -#ifdef DEBUG_STRICT - assert (screen.cur.row < nrow); -#else /* drive with your eyes closed */ - min_it (screen.cur.row, nrow - 1); -#endif - ncol = ocol; // save b/c scr_blank_screen_mem uses this + for (int row = min (nrow, prev_nrow); row--; ) + { + lresize (drawn_buf[row]); + lresize (swap_buf [row]); } - /* resize columns */ - if (ncol != prev_ncol) + for (int row = prev_nrow; row < nrow; row++) { - old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t)); - old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); - - for (p = total_rows; p--; ) - lresize (save[p]); - - for (p = nrow; p--; ) - { - lresize (drawn[p]); - lresize (swap_save[p]); - } - - min_it (screen.cur.col, (int16_t)ncol - 1); - - delete old_ta; - delete old_ra; + swap_buf [row].clear (); scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); + drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); } -#if 0 - // re-wrap lines, this is rather ugly, possibly because I am too dumb - // to come up with a lean and mean algorithm. - rxvt_salloc *ta = new rxvt_salloc (ncol * sizeof (text_t)); - rxvt_salloc *ra = new rxvt_salloc (ncol * sizeof (rend_t)); - - text_t **tp = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *)); - rend_t **rp = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *)); - tlen_t *tl = (tlen_t *) rxvt_calloc (total_rows, sizeof (tlen_t)); - - for (p = 0; p < prev_total_rows; p++) printf ("P %p %d\n", save[p].t, save[p].l);//D - - p = prev_total_rows; - q = total_rows; + line_t *old_buf = row_buf; 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 - nsaved , prev_total_rows); + int q = total_rows; // rewrapped row - while (p > 0 && q > 0) + if (nsaved) { - --p; + // re-wrap lines, this is rather ugly, possibly because I am too dumb + // to come up with a lean and mean algorithm. - printf ("pq %d:%d\n", p, q); - if (save[p].t) - { - int llen = save[p].l; + row_col_t ocur = screen.cur; + ocur.row = MOD (term_start + ocur.row, prev_total_rows); - assert (llen >= 0); + do + { + p = MOD (p - 1, prev_total_rows); +#ifdef DEBUG_STRICT + assert (old_buf [MOD (p, prev_total_rows)].t); +#endif + int plines = 1; + int llen = old_buf [MOD (p, prev_total_rows)].l; - while (p && save[p - 1].l < 0) + while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) { - --p; + p = MOD (p - 1, prev_total_rows); + + plines++; llen += prev_ncol; } - int qlines = llen / ncol + 1; - int lofs = 0; + int qlines = max (0, (llen - 1) / ncol) + 1; + + // drop partial lines completely + if (q < qlines) + break; q -= qlines; - int qrow = q; + int lofs = 0; + line_t *qline; - printf ("QL %d llen %d\n", qlines, llen);//D - for (; qlines--; qrow++) + // re-assemble the full line by destination lines + for (int qrow = q; qlines--; qrow++) { - if (qrow >= 0) - { - tp [qrow] = (text_t *)ta->alloc (); - rp [qrow] = (rend_t *)ra->alloc (); - tl [qrow] = LINE_CONT1; - - int qcol = 0; - - for (;;) - { - int prow = lofs / prev_ncol + p; - int pcol = lofs % prev_ncol; + qline = row_buf + qrow; + lalloc (*qline); + qline->l = ncol; + qline->is_longer (1); - int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); + int qcol = 0; - printf ("q %d lofs %d>%d len %d pq %d:%d p %d:%d q :%d\n", q, llen, lofs, len, prev_ncol, ncol, prow, pcol, qcol); + // fill a single destination line + while (lofs < llen && qcol < ncol) + { + int prow = lofs / prev_ncol; + int pcol = lofs % prev_ncol; - if (len <= 0) - { - tl [qrow] = qcol; + prow = MOD (p + prow, prev_total_rows); - TODO - scr_blank_line (tp [qrow] + qcol, rp [qrow] + qcol, - ncol - qcol, DEFAULT_RSTYLE); + // we only adjust the cursor _row_ and put it into + // the topmost line of "long line" it was in, as + // this seems to upset applications/shells/readline + // least. + if (prow == ocur.row) + screen.cur.row = q - (total_rows - nrow); - break; - } + line_t &pline = old_buf [prow]; - assert (lofs < 1000); + int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); - memcpy (tp [qrow] + qcol, save[prow].t + pcol, len * sizeof (text_t)); - memcpy (rp [qrow] + qcol, save[prow].r + pcol, len * sizeof (rend_t)); + assert (len); + assert (pline.t); - lofs += len; - qcol += len; + memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); + memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); - if (qcol == ncol) - break; - } + lofs += len; + qcol += len; } - else - lofs += ncol; } - } + + qline->l = llen ? MOD (llen - 1, ncol) + 1 : 0; + qline->is_longer (0); + scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); + } + while (p != pend && q > 0); + + term_start = total_rows - nrow; + nsaved = term_start - q; + + // make sure all terminal lines exist + while (nsaved < 0) + scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); } + else + { + // if no scrollback exists (yet), wing, instead of wrap + + for (int row = min (nrow, prev_nrow); row--; ) + { + line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; + line_t &qline = row_buf [row]; + + qline = pline; + lresize (qline); + } - free (screen.text); screen.text = tp; - free (screen.rend); screen.rend = rp; - free (screen.tlen); screen.tlen = tl; + for (int row = prev_nrow; row < nrow; row++) + { + row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE); + } + + term_start = 0; + } - for (p = 0; p < total_rows; p++) printf ("P %p %d\n", save[p].t, save[p].l);//D +#ifdef DEBUG_STRICT //TODO: remove + for (int i = -nsaved; i < nrow; i++) + assert (ROW (i).t); #endif + free (old_buf); + delete old_ta; + delete old_ra; + + clamp_it (screen.cur.row, 0, nrow - 1); + clamp_it (screen.cur.col, 0, ncol - 1); + if (tabs) free (tabs); } @@ -427,19 +414,12 @@ tabs = (char *)rxvt_malloc (ncol * sizeof (char)); - for (p = 0; p < ncol; p++) - tabs[p] = (p % TABSIZE == 0) ? 1 : 0; + for (int col = ncol; col--; ) + tabs [col] = col % TABSIZE == 0; tt_winch (); -} -void -rxvt_term::scr_reset_realloc () -{ - 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)); + HOOK_INVOKE ((this, HOOK_RESET, DT_END)); } /* ------------------------------------------------------------------------- */ @@ -452,11 +432,13 @@ delete talloc; talloc = 0; delete ralloc; ralloc = 0; - free (save); - free (swap_save); - free (drawn); - free (buf); + free (row_buf); + free (swap_buf); + free (drawn_buf); + free (temp_buf); free (tabs); + + row_buf = 0; // signal that we freed all the arrays } /* ------------------------------------------------------------------------- */ @@ -522,9 +504,6 @@ #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); #endif } @@ -554,12 +533,12 @@ screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1); #if NSCREENS - if (options & Opt_secondaryScreen) + if (OPTION (Opt_secondaryScreen)) { num_scr = 0; - for (int i = nrow; i--; ) - ::swap (ROW(i), swap_save[i]); + for (int i = prev_nrow; i--; ) + ::swap (ROW(i), swap_buf [i]); ::swap (screen.charset, swap.charset); ::swap (screen.flags, swap.flags); @@ -568,7 +547,7 @@ } else #endif - if (options & Opt_secondaryScroll) + if (OPTION (Opt_secondaryScroll)) scr_scroll_text (0, prev_nrow - 1, prev_nrow); return scrn; @@ -640,9 +619,12 @@ if (count > 0 && row1 == 0 && row2 == nrow - 1 - && (current_screen == PRIMARY || options & Opt_secondaryScroll)) + && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll))) { nsaved = min (nsaved + count, saveLines); + + HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, nsaved, DT_END)); + term_start = (term_start + count) % total_rows; if (selection.op && current_screen == selection.screen) @@ -651,13 +633,19 @@ selection.end.row -= count; selection.mark.row -= count; - selection_check (0); + if (selection.beg.row < -nsaved + || selection.end.row < -nsaved + || selection.mark.row < -nsaved) + { + CLEAR_ALL_SELECTION (); + selection.op = SELECTION_CLEAR; + } } for (int i = count; i--; ) scr_blank_screen_mem (ROW(row2 - i), rstyle); - if ((options & Opt_scrollWithBuffer) + if (OPTION (Opt_scrollWithBuffer) && view_start != 0 && view_start != saveLines) scr_page (UP, count); @@ -666,20 +654,17 @@ { if (selection.op && current_screen == selection.screen) { - int i = selection.beg.row; - int j = selection.end.row; - - 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)) + if ((selection.beg.row < row1 && selection.end.row > row1) + || (selection.beg.row < row2 && selection.end.row > row2) + || (selection.beg.row - count < row1 && selection.beg.row >= row1) + || (selection.beg.row - count > row2 && selection.beg.row <= row2) + || (selection.end.row - count < row1 && selection.end.row >= row1) + || (selection.end.row - count > row2 && selection.end.row <= row2)) { CLEAR_ALL_SELECTION (); - selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ + selection.op = SELECTION_CLEAR; } - else if (j >= row1 && j <= row2) + else if (selection.end.row >= row1 && selection.end.row <= row2) { /* move selected region too */ selection.beg.row -= count; @@ -695,16 +680,18 @@ int rows = row2 - row1 + 1; + min_it (count, rows); + for (int row = 0; row < rows; row++) { - buf [row] = ROW(row1 + (row + count + rows) % rows); + temp_buf [row] = ROW(row1 + (row + count + rows) % rows); if (!IN_RANGE_EXC (row + count, 0, rows)) - scr_blank_screen_mem (buf [row], rstyle); + scr_blank_screen_mem (temp_buf [row], rstyle); } for (int row = 0; row < rows; row++) - ROW(row1 + row) = buf [row]; + ROW(row1 + row) = temp_buf [row]; } return count; @@ -715,43 +702,39 @@ * Add text given in of length to screen struct */ void -rxvt_term::scr_add_lines (const unicode_t *str, int nlines, int len) +rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) { if (len <= 0) /* sanity */ return; unsigned char checksel; unicode_t c; - int row, last_col; - const unicode_t *strend = str + len; + int ncol = this->ncol; + const wchar_t *strend = str + len; want_refresh = 1; ZERO_SCROLLBACK (); - last_col = ncol; - if (nlines > 0) + if (minlines > 0) { - nlines += screen.cur.row - screen.bscroll; - if ((nlines > 0) - && (screen.tscroll == 0) - && (screen.bscroll == (nrow - 1))) + minlines += screen.cur.row - screen.bscroll; + + if (minlines > 0 + && screen.tscroll == 0 + && screen.bscroll == nrow - 1) { /* _at least_ this many lines need to be scrolled */ - scr_scroll_text (screen.tscroll, screen.bscroll, nlines); - screen.cur.row -= nlines; + scr_scroll_text (screen.tscroll, screen.bscroll, minlines); + screen.cur.row -= minlines; } } #ifdef DEBUG_STRICT - assert (screen.cur.col < last_col); - assert ((screen.cur.row < nrow) - && (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)nsaved); + assert (screen.cur.col < ncol); + assert (screen.cur.row < nrow + && screen.cur.row >= -nsaved); #endif - row = screen.cur.row; + int row = screen.cur.row; checksel = selection.op && current_screen == selection.screen ? 1 : 0; @@ -759,13 +742,12 @@ while (str < strend) { - c = *str++; + c = (unicode_t)*str++; // convert to rxvt-unicodes representation if (c < 0x20) if (c == C0_LF) - { - if (!line->is_longer ()) /* XXX: think about this */ - max_it (line->l, screen.cur.col); + { + max_it (line->l, screen.cur.col); screen.flags &= ~Screen_WrapNext; @@ -779,8 +761,7 @@ } else if (c == C0_CR) { - if (!line->is_longer ()) /* XXX: think about this */ - max_it (line->l, screen.cur.col); + max_it (line->l, screen.cur.col); screen.flags &= ~Screen_WrapNext; screen.cur.col = 0; @@ -807,7 +788,8 @@ if (screen.flags & Screen_WrapNext) { - line->set_is_longer (); + max_it (line->l, ncol); + line->is_longer (1); scr_do_wrap (); @@ -825,7 +807,7 @@ // locale. int width = c < 0x100 ? 1 : wcwidth (c); - if (charsets[screen.charset] == '0') // DEC SPECIAL + if (charsets [screen.charset] == '0') // DEC SPECIAL { // vt100 special graphics and line drawing // 5f-7e standard vt100 @@ -887,7 +869,7 @@ rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); // if the character doesn't fit into the remaining columns... - if (screen.cur.col > last_col - width && last_col >= width) + if (screen.cur.col > ncol - width && ncol >= width) { // ...output spaces c = ' '; @@ -895,16 +877,18 @@ --str; } + line->touch (); + do { line->t[screen.cur.col] = c; line->r[screen.cur.col] = rend; - if (screen.cur.col < last_col - 1) + if (screen.cur.col < ncol - 1) screen.cur.col++; else { - line->l = last_col; + line->l = ncol; if (screen.flags & Screen_Autowrap) screen.flags |= Screen_WrapNext; break; @@ -916,11 +900,15 @@ // pad with spaces when overwriting wide character with smaller one if (!width) - for (int c = screen.cur.col; c < last_col && line->t[c] == NOCHAR; c++) - { - line->t[c] = ' '; - line->r[c] = rend; - } + { + line->touch (); + + for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) + { + line->t[c] = ' '; + line->r[c] = rend; + } + } } else // width == 0 { @@ -929,31 +917,31 @@ // we just tag the accent on the previous on-screen character. // this is arguably not correct, but also arguably not wrong. // we don't handle double-width characters nicely yet. + line_t *linep; text_t *tp; rend_t *rp; if (screen.cur.col > 0) { + linep = line; tp = line->t + screen.cur.col - 1; rp = line->r + screen.cur.col - 1; - - while (*tp == NOCHAR && tp > line->t) - tp--, rp--; } else if (screen.cur.row > 0 && ROW(screen.cur.row - 1).is_longer ()) { - line_t *line = &ROW(screen.cur.row - 1); - - tp = line->t + last_col - 1; - rp = line->r + last_col - 1; - - while (*tp == NOCHAR && tp > line->t) - tp--, rp--; + linep = &ROW(screen.cur.row - 1); + tp = line->t + ncol - 1; + rp = line->r + ncol - 1; } else continue; + linep->touch (); + + while (*tp == NOCHAR && tp > linep->t) + tp--, rp--; + // first try to find a precomposed character unicode_t n = rxvt_compose (*tp, c); if (n == NOCHAR) @@ -965,13 +953,10 @@ } } - if (!line->is_longer ()) /* XXX: think about this */ - max_it (line->l, screen.cur.col); + 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); #endif } @@ -1020,9 +1005,7 @@ return; else if (count > 0) { - int row = screen.cur.row; - - line_t &l = ROW(row); + line_t &l = ROW(screen.cur.row); rend_t base_rend = l.r[i]; ht &= l.t[i] == ' '; @@ -1030,6 +1013,7 @@ if (tabs[i]) { x = i; + if (!--count) break; } @@ -1042,12 +1026,11 @@ // store horizontal tab commands as characters inside the text // buffer so they can be selected and pasted. - if (ht && options & Opt_pastableTabs) + if (ht && OPTION (Opt_pastableTabs)) { base_rend = SET_FONT (base_rend, 0); - if (!l.is_longer ()) /* XXX: think about this */ - max_it (l.l, x); + l.touch (x); i = screen.cur.col; @@ -1107,16 +1090,14 @@ void rxvt_term::scr_forwardindex () { - int row; - if (screen.cur.col < ncol - 1) scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); else { - row = screen.cur.row; + line_t &l = ROW(screen.cur.row); - if (ROW(row).is_longer ()) //TODO//FIXME//LEN - ROW(row).l = ncol; + l.touch (); + l.is_longer (0); scr_gotorc (0, 0, R_RELATIVE); scr_insdel_chars (1, DELETE); @@ -1136,8 +1117,7 @@ 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); + clamp_it (screen.cur.col, 0, ncol - 1); screen.flags &= ~Screen_WrapNext; @@ -1171,8 +1151,7 @@ screen.cur.row = row; } - max_it (screen.cur.row, 0); - min_it (screen.cur.row, (int32_t)nrow - 1); + clamp_it (screen.cur.row, 0, nrow - 1); } /* ------------------------------------------------------------------------- */ @@ -1197,8 +1176,7 @@ else screen.cur.row += dirn; - max_it (screen.cur.row, 0); - min_it (screen.cur.row, (int32_t)nrow - 1); + clamp_it (screen.cur.row, 0, nrow - 1); selection_check (0); } @@ -1212,21 +1190,24 @@ void rxvt_term::scr_erase_line (int mode) { - unsigned int row, col, num; + unsigned int col, num; want_refresh = 1; ZERO_SCROLLBACK (); selection_check (1); - row = screen.cur.row; + line_t &line = ROW(screen.cur.row); + + line.touch (); + line.is_longer (0); switch (mode) { case 0: /* erase to end of line */ col = screen.cur.col; num = ncol - col; - min_it (ROW(row).l, (int16_t)col); + min_it (line.l, col); if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) CLEAR_SELECTION (); @@ -1241,7 +1222,7 @@ case 2: /* erase whole line */ col = 0; num = ncol; - ROW(row).l = 0; + line.l = 0; if (selection.beg.row <= screen.cur.row && selection.end.row >= screen.cur.row) CLEAR_SELECTION (); @@ -1250,7 +1231,7 @@ return; } - scr_blank_line (ROW(row), col, num, rstyle); + scr_blank_line (line, col, num, rstyle); } /* ------------------------------------------------------------------------- */ @@ -1303,7 +1284,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; @@ -1315,7 +1296,7 @@ else { ren = rstyle & (RS_fgMask | RS_bgMask); - gcvalue.foreground = pix_colors[GET_BGCOLOR (rstyle)]; + gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; XChangeGC (display->display, gc, GCForeground, &gcvalue); ERASE_ROWS (row, num); gcvalue.foreground = pix_colors[Color_fg]; @@ -1324,9 +1305,8 @@ for (; num--; row++) { - scr_blank_screen_mem (ROW (row), rstyle); - ROW (row).l = 0; - scr_blank_line (drawn[row], 0, ncol, ren); + scr_blank_screen_mem (ROW(row), rstyle); + scr_blank_line (drawn_buf [row], 0, ncol, ren); } } @@ -1368,7 +1348,8 @@ for (int j = ncol; j--; ) *r1++ = fs; - line.l = ncol; /* make the `E's selectable */ + line.is_longer (0); + line.touch (ncol); } } @@ -1421,12 +1402,15 @@ scr_do_wrap (); selection_check (1); - min_it (count, (ncol - screen.cur.col)); + min_it (count, ncol - screen.cur.col); row = screen.cur.row; line_t *line = &ROW(row); + line->touch (); + line->is_longer (0); + switch (insdel) { case INSERT: @@ -1436,11 +1420,7 @@ line->r[col] = line->r[col - count]; } - if (!line->is_longer ()) - { - line->l += count; - min_it (line->l, ncol); - } + line->l = min (line->l + count, ncol); if (selection.op && current_screen == selection.screen && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) @@ -1463,6 +1443,8 @@ screen.cur.col += count; /* don't worry if > ncol */ selection_check (1); screen.cur.col -= count; + + line->l = max (line->l - count, 0); scr_blank_line (*line, screen.cur.col, count, rstyle); break; @@ -1475,12 +1457,8 @@ line->r[col] = line->r[col + count]; } - scr_blank_line (*line, ncol - count, count, tr); - - if (line->is_longer ()) /* break line continuation */ - line->l = ncol; - line->l = max (line->l - count, 0); + scr_blank_line (*line, ncol - count, count, tr); if (selection.op && current_screen == selection.screen && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) @@ -1511,7 +1489,7 @@ rxvt_term::scr_scroll_region (int top, int bot) { max_it (top, 0); - min_it (bot, (int)nrow - 1); + min_it (bot, nrow - 1); if (top > bot) return; @@ -1602,7 +1580,7 @@ if (mode < 0) memset (tabs, 0, ncol * sizeof (char)); else if (screen.cur.col < ncol) - tabs[screen.cur.col] = (mode ? 1 : 0); + tabs [screen.cur.col] = !!mode; } /* ------------------------------------------------------------------------- */ @@ -1624,7 +1602,7 @@ if (bgPixmap.pixmap == None) #endif #if TRANSPARENT - if (! (options & Opt_transparent) || am_transparent == 0) + if (! OPTION (Opt_transparent) || am_transparent == 0) #endif XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); @@ -1659,7 +1637,8 @@ void rxvt_term::set_font_style () { - switch (charsets[screen.charset]) +#if 0 + switch (charsets [screen.charset]) { case '0': /* DEC Special Character & Line Drawing Set */ break; @@ -1676,6 +1655,7 @@ case 'K': /* German character set */ break; } +#endif } /* ------------------------------------------------------------------------- */ @@ -1725,7 +1705,7 @@ for (int i = 0; i < nrow; i++) { int col = 0; - rend_t *drp = drawn[i].r; + rend_t *drp = drawn_buf[i].r; for (; col < ncol; col++, drp++) if ((*drp & mask) == value) @@ -1753,7 +1733,7 @@ int i; row_col_t rc[RC_COUNT]; - if (!drawn) /* sanity check */ + if (!drawn_buf) /* sanity check */ return; #ifndef NO_SLOW_LINK_SUPPORT @@ -1764,13 +1744,6 @@ } #endif -#ifdef DEBUG_STRICT - x = max (x, 0); - x = min (x, (int)width); - y = max (y, 0); - y = min (y, (int)height); -#endif - /* round down */ rc[PART_BEG].col = Pixel2Col (x); rc[PART_BEG].row = Pixel2Row (y); @@ -1786,7 +1759,7 @@ } for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) - fill_text (&drawn[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); + fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); if (refresh) scr_refresh (SLOW_REFRESH); @@ -1859,11 +1832,13 @@ { if (view_start != oldviewstart) { + HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END)); + want_refresh = 1; num_scr -= (view_start - oldviewstart); } - return (int) (view_start - oldviewstart); + return (int)view_start - (int)oldviewstart; } /* ------------------------------------------------------------------------- */ @@ -1874,12 +1849,12 @@ # ifndef NO_MAPALERT # ifdef MAPALERT_OPTION - if (options & Opt_mapAlert) + if (OPTION (Opt_mapAlert)) # endif XMapWindow (display->display, parent[0]); # endif - if (options & Opt_visualBell) + if (OPTION (Opt_visualBell)) { scr_rvideo_mode (!rvideo); /* refresh also done */ rxvt_usleep (VISUAL_BELL_DURATION); @@ -1980,7 +1955,7 @@ must_clear |= bgPixmap.pixmap != None; #endif #if TRANSPARENT - must_clear |= (options & Opt_transparent) && am_transparent; + must_clear |= OPTION (Opt_transparent) && am_transparent; #endif ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ @@ -2014,7 +1989,7 @@ if (showcursor && focus) { - if (options & Opt_cursorUnderline) + if (OPTION (Opt_cursorUnderline)) *crp ^= RS_Uline; else { @@ -2026,7 +2001,7 @@ ccol1 = Color_cursor; else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol1 = GET_FGCOLOR (rstyle); + ccol1 = fgcolor_of (rstyle); #else ccol1 = Color_fg; #endif @@ -2034,7 +2009,7 @@ ccol2 = Color_cursor2; else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol2 = GET_BGCOLOR (rstyle); + ccol2 = bgcolor_of (rstyle); #else ccol2 = Color_bg; #endif @@ -2054,7 +2029,7 @@ { if (ocrow < nrow && oldcursor.col < ncol) - drawn[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); + drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); if (focus || !showcursor) oldcursor.row = -1; @@ -2077,6 +2052,7 @@ } } + HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); #if ENABLE_OVERLAY scr_swap_overlay (); #endif @@ -2103,8 +2079,8 @@ if (row + i >= 0 && row + i < nrow && row + i != ocrow) { line_t s = ROW(row - view_start); - line_t d = drawn[row]; - line_t d2 = drawn[row + i]; + line_t d = drawn_buf[row]; + line_t d2 = drawn_buf[row + i]; for (nits = 0, col = ncol; col--; ) if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col]) @@ -2136,7 +2112,7 @@ XCopyArea (display->display, vt, vt, gc, 0, Row2Pixel (len + i), - (unsigned int)TermWin_TotalWidth (), + (unsigned int)this->width, (unsigned int)Height2Pixel (wlen - len + 1), 0, Row2Pixel (len)); len = -1; @@ -2152,8 +2128,8 @@ { 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; + text_t *dtp = drawn_buf[row].t; + rend_t *drp = drawn_buf[row].r; /* * E2: OK, now the real pass @@ -2225,10 +2201,10 @@ /* * Determine the attributes for the string */ - int fore = GET_FGCOLOR (rend); // desired foreground - int back = GET_BGCOLOR (rend); // desired background + int fore = fgcolor_of (rend); // desired foreground + int back = bgcolor_of (rend); // desired background - // only do special processing if any attributes are set, which is rare + // only do special processing if any attributes are set, which is unlikely if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) { #if ENABLE_STYLES @@ -2349,6 +2325,7 @@ #if ENABLE_OVERLAY scr_swap_overlay (); #endif + HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END)); /* * G: cleanup cursor and display outline cursor if necessary @@ -2357,7 +2334,7 @@ { if (focus) { - if (options & Opt_cursorUnderline) + if (OPTION (Opt_cursorUnderline)) *crp ^= RS_Uline; else { @@ -2376,7 +2353,7 @@ col--; while (col + cursorwidth < ncol - && drawn[oldcursor.row].t[col + cursorwidth] == NOCHAR) + && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR) cursorwidth++; #ifndef NO_CURSORCOLOR @@ -2405,11 +2382,13 @@ } void -rxvt_term::scr_remap_chars (const line_t &l) +rxvt_term::scr_remap_chars (line_t &l) { if (!l.t) return; + l.touch (); // maybe a bit of an overkill, but it's not performance-relevant + for (int i = ncol; i--; ) l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i])); } @@ -2418,12 +2397,12 @@ rxvt_term::scr_remap_chars () { for (int i = total_rows; i--; ) - scr_remap_chars (save[i]); + scr_remap_chars (row_buf [i]); for (int i = nrow; i--; ) { - scr_remap_chars (drawn[i]); - scr_remap_chars (swap_save[i]); + scr_remap_chars (drawn_buf [i]); + scr_remap_chars (swap_buf [i]); } } @@ -2486,8 +2465,19 @@ if (selection.rect) { 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; + { + text_t *stp = ROW(row).t; + rend_t *srp = ROW(row).r; + + for (col = selection.beg.col; col < selection.end.col; col++) + srp[col] ^= RS_RVid; + + while (col-- > selection.beg.col && (stp[col] == NOCHAR || unicode::is_space (stp[col]))) + srp[col] ^= RS_RVid | RS_Uline; + + if (++col < selection.end.col) + srp[col] ^= RS_RVid | RS_Uline; + } } else #endif @@ -2500,7 +2490,7 @@ else { col = 0; - row = view_start; + row = -view_start; } for (; row < min (selection.end.row, view_end); row++, col = 0) @@ -2530,16 +2520,16 @@ for (row = saveLines - nsaved; row < saveLines + nrow - 1; row++) { - width = save[row].l >= 0 ? save[row].l + width = row_buf[row].l >= 0 ? row_buf[row].l : ncol; for (towrite = width; towrite; towrite -= wrote) { - wrote = write (fd, & (save[row].t[width - towrite]), + wrote = write (fd, & (row_buf[row].t[width - towrite]), towrite); if (wrote < 0) return; /* XXX: death, no report */ } - if (save[row].l >= 0) + if (row_buf[row].l >= 0) if (write (fd, r1, 1) <= 0) return; /* XXX: death, no report */ } @@ -2581,7 +2571,7 @@ * Paste a selection direct to the command fd */ void -rxvt_term::paste (unsigned char *data, unsigned int len) +rxvt_term::paste (char *data, unsigned int len) { /* convert normal newline chars into common keyboard Return key sequence */ for (unsigned int i = 0; i < len; i++) @@ -2735,7 +2725,7 @@ char *s = rxvt_wcstombs (w); free (w); // TODO: strlen == only the first element will be converted. well... - paste ((unsigned char *)s, strlen (s)); + paste (s, strlen (s)); free (s); } else @@ -2744,12 +2734,12 @@ && cl) { for (int i = 0; i < cr; i++) - paste ((unsigned char *)cl[i], strlen (cl[i])); + paste (cl[i], strlen (cl[i])); XFreeStringList (cl); } else - paste (ct.value, ct.nitems); // paste raw + paste ((char *)ct.value, ct.nitems); // paste raw bailout: XFree (ct.value); @@ -2797,7 +2787,7 @@ if (selection.text) { /* internal selection */ char *str = rxvt_wcstombs (selection.text, selection.len); - paste ((unsigned char *)str, strlen (str)); + paste (str, strlen (str)); free (str); return; } @@ -2899,6 +2889,9 @@ if (selection.clicks == 4) return; /* nothing selected, go away */ + if (HOOK_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END))) + return; + i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t)); @@ -2920,14 +2913,19 @@ } else #endif - end_col = ROW(row).is_longer () ? ncol : ROW(row).l; //TODO//FIXME//LEN + end_col = ROW(row).l; col = max (col, 0); - if (row == selection.end.row || selection.rect) - end_col = min (end_col, selection.end.col); + if (row == selection.end.row +#if ENABLE_FRILLS + || selection.rect +#endif + ) + min_it (end_col, selection.end.col); t = ROW(row).t + col; + for (; col < end_col; col++) { if (*t == NOCHAR) @@ -2953,8 +2951,20 @@ new_selection_text[ofs++] = *t++; } - if (!ROW(row).is_longer () && row != selection.end.row) - new_selection_text[ofs++] = C0_LF; +#if ENABLE_FRILLS + if (selection.rect) + { + while (ofs + && new_selection_text[ofs - 1] != C0_LF + && unicode::is_space (new_selection_text[ofs - 1])) + --ofs; + + new_selection_text[ofs++] = C0_LF; + } + else +#endif + if (!ROW(row).is_longer () && row != selection.end.row) + new_selection_text[ofs++] = C0_LF; } if (end_col != selection.end.col) @@ -2974,11 +2984,25 @@ selection.len = ofs; selection.text = (wchar_t *)rxvt_realloc (new_selection_text, (ofs + 1) * sizeof (wchar_t)); + if (HOOK_INVOKE ((this, HOOK_SEL_GRAB, DT_LONG, (long)tm, DT_END))) + return; + + selection_grab (tm); +} + +bool +rxvt_term::selection_grab (Time tm) +{ + selection_time = tm; + XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) - display->set_selection_owner (this); + { + display->set_selection_owner (this); + return true; + } else - rxvt_warn ("can't get primary selection, ignoring.\n"); + return false; #if 0 XTextProperty ct; @@ -2989,8 +3013,6 @@ XFree (ct.value); } #endif - - selection_time = tm; } /* ------------------------------------------------------------------------- */ @@ -3122,7 +3144,6 @@ break; } -Old_Word_Selection_You_Die: if (dirn == DN) col++; /* put us on one past the end */ @@ -3309,13 +3330,16 @@ if (ROWCOL_IS_AFTER (selection.end, selection.beg)) selection.end.col--; - selection_delimit_word (UP, &selection.beg, &selection.beg); - selection_delimit_word (DN, &selection.end, &selection.end); + if (!HOOK_INVOKE ((this, HOOK_SEL_EXTEND, DT_END))) + { + selection_delimit_word (UP, &selection.beg, &selection.beg); + selection_delimit_word (DN, &selection.end, &selection.end); + } } else if (selection.clicks == 3) { #if ENABLE_FRILLS - if (options & Opt_tripleclickwords) + if (OPTION (Opt_tripleclickwords)) { selection_delimit_word (UP, &selection.beg, &selection.beg); @@ -3386,9 +3410,8 @@ while (--end_col >= 0) { - if (stp[end_col] != ' ' - && stp[end_col] != '\t' - && stp[end_col] != NOCHAR) + if (stp[end_col] != NOCHAR + && !unicode::is_space (stp[end_col])) break; } @@ -3597,7 +3620,7 @@ void rxvt_term::scr_overlay_new (int x, int y, int w, int h) { - if (nrow < 3 || ncol < 3) + if (nrow < 1 || ncol < 1) return; want_refresh = 1; @@ -3611,11 +3634,8 @@ w += 2; min_it (w, ncol); h += 2; min_it (h, nrow); - x -= 1; max_it (x, 0); - y -= 1; max_it (y, 0); - - min_it (x, ncol - w); - min_it (y, nrow - h); + x -= 1; clamp_it (x, 0, ncol - w); + y -= 1; clamp_it (y, 0, nrow - h); ov_x = x; ov_y = y; ov_w = w; ov_h = h; @@ -3717,8 +3737,8 @@ text_t *t1 = ov_text[y]; rend_t *r1 = ov_rend[y]; - text_t *t2 = ROW(y - view_start).t + ov_x; - rend_t *r2 = ROW(y - view_start).r + ov_x; + text_t *t2 = ROW(y + ov_y - view_start).t + ov_x; + rend_t *r2 = ROW(y + ov_y - view_start).r + ov_x; for (int x = ov_w; x--; ) {