--- rxvt-unicode/src/screen.C 2006/01/03 04:18:47 1.205 +++ rxvt-unicode/src/screen.C 2006/01/19 17:37:01 1.241 @@ -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 @@ -117,7 +117,7 @@ /* Fill part/all of a line with blanks. */ void -rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) +rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) const { if (!l.t) { @@ -126,6 +126,8 @@ width = ncol; } + l.touch (); + efs &= ~RS_baseattrMask; efs = SET_FONT (efs, FONTSET (efs)->find_font (' ')); @@ -142,9 +144,12 @@ /* ------------------------------------------------------------------------- */ /* Fill a full line with blanks - make sure it is allocated first */ void -rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) +rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) const { scr_blank_line (l, 0, ncol, efs); + + l.l = 0; + l.f = 0; } /* ------------------------------------------------------------------------- * @@ -176,7 +181,7 @@ //TODO//FIXME saveLines++; prev_nrow--; - nsaved++; + top_row--; } want_refresh = 1; @@ -191,18 +196,16 @@ { /* * 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 */ - nsaved = 0; /* no saved lines */ + top_row = 0; /* no saved lines */ term_start = 0; talloc = new rxvt_salloc (ncol * sizeof (text_t)); ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); - 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)); + row_buf = (line_t *)rxvt_calloc (total_rows + nrow, 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--; ) { @@ -233,7 +236,6 @@ selection.op = SELECTION_CLEAR; selection.screen = PRIMARY; selection.clicks = 0; - CLEAR_ALL_SELECTION (); rvideo = 0; } else @@ -257,7 +259,6 @@ #endif 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)); for (int row = min (nrow, prev_nrow); row--; ) @@ -272,13 +273,14 @@ drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); } - line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); + line_t *old_buf = row_buf; + row_buf = (line_t *)rxvt_calloc (total_rows + nrow, 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 pend = MOD (term_start + top_row , prev_total_rows); int q = total_rows; // rewrapped row - if (nsaved) + if (top_row) { // re-wrap lines, this is rather ugly, possibly because I am too dumb // to come up with a lean and mean algorithm. @@ -292,7 +294,6 @@ #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; @@ -320,10 +321,15 @@ { qline = row_buf + qrow; lalloc (*qline); - qline->set_is_longer (); + qline->l = ncol; + qline->is_longer (1); int qcol = 0; + // see below for cursor adjustment rationale + if (p == ocur.row) + screen.cur.row = q - (total_rows - nrow); + // fill a single destination line while (lofs < llen && qcol < ncol) { @@ -343,8 +349,10 @@ 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)); @@ -355,24 +363,17 @@ } qline->l = llen ? MOD (llen - 1, ncol) + 1 : 0; -#ifdef DEBUG_STRICT //TODO//FIXME//TEMPORARY - if (qline->l < 0) - { - fprintf (stderr, "ERROR, PLEASE REPORT to rxvt-unicode@plan9.de: qline->l %d = llen %d < ncol %d ? %d : MOD %d\n", qline->l,llen,ncol,llen,MOD (llen - 1, ncol) + 1);//D - qline->l = 0; - } -#endif + 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; + top_row = q - term_start; // make sure all terminal lines exist - while (nsaved < 0) - scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); - + while (top_row > 0) + scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE); } else { @@ -395,11 +396,6 @@ term_start = 0; } -#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; @@ -411,6 +407,8 @@ free (tabs); } + CLEAR_ALL_SELECTION (); + prev_nrow = nrow; prev_ncol = ncol; @@ -421,7 +419,7 @@ tt_winch (); - PERL_INVOKE ((this, HOOK_RESET, DT_END)); + HOOK_INVOKE ((this, HOOK_RESET, DT_END)); } /* ------------------------------------------------------------------------- */ @@ -437,7 +435,6 @@ free (row_buf); free (swap_buf); free (drawn_buf); - free (temp_buf); free (tabs); row_buf = 0; // signal that we freed all the arrays @@ -455,7 +452,7 @@ scr_reset (); scr_clear (true); - scr_refresh (SLOW_REFRESH); + scr_refresh (); } /* ------------------------------------------------------------------------- * @@ -579,7 +576,7 @@ void rxvt_term::scr_color (unsigned int color, int fgbg) { - if (color > maxTermCOLOR) + if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) color = fgbg; if (fgbg == Color_fg) @@ -620,40 +617,69 @@ if (count > 0 && row1 == 0 - && row2 == nrow - 1 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll))) { - nsaved = min (nsaved + count, saveLines); + top_row = max (top_row - count, -saveLines); - PERL_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, nsaved, DT_END)); - + // scroll everything up 'count' lines term_start = (term_start + count) % total_rows; + // sever bottommost line + { + line_t &l = ROW(row2 - count); + l.is_longer (0); + l.touch (); + } + + // 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; + } + + // 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) { selection.beg.row -= count; selection.end.row -= count; selection.mark.row -= count; - if (selection.beg.row < -nsaved - || selection.end.row < -nsaved - || selection.mark.row < -nsaved) + if (selection.beg.row < top_row + || selection.end.row < top_row + || selection.mark.row < top_row) { CLEAR_ALL_SELECTION (); selection.op = SELECTION_CLEAR; } } - for (int i = count; i--; ) - { - ROW(row2 - i).l = 0; - scr_blank_screen_mem (ROW(row2 - i), rstyle); - } - + // finally move the view window, if desired if (OPTION (Opt_scrollWithBuffer) && view_start != 0 - && view_start != saveLines) + && view_start != -saveLines) scr_page (UP, count); + + if (SHOULD_INVOKE (HOOK_SCROLL_BACK)) + HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, top_row, DT_END)); } else { @@ -687,6 +713,8 @@ min_it (count, rows); + line_t *temp_buf = row_buf + total_rows; + for (int row = 0; row < rows; row++) { temp_buf [row] = ROW(row1 + (row + count + rows) % rows); @@ -707,37 +735,37 @@ * 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 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 + minlines += screen.cur.row - screen.bscroll; + + if (minlines > 0 && screen.tscroll == 0 - && screen.bscroll == (nrow - 1)) + && 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.col < ncol); assert (screen.cur.row < nrow - && screen.cur.row >= -nsaved); + && screen.cur.row >= top_row); #endif int row = screen.cur.row; @@ -747,13 +775,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; @@ -767,8 +794,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; @@ -795,10 +821,11 @@ if (screen.flags & Screen_WrapNext) { - line->set_is_longer (); - scr_do_wrap (); + line->l = ncol; + line->is_longer (1); + row = screen.cur.row; line = &ROW(row); /* _must_ refresh */ } @@ -813,7 +840,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 @@ -875,7 +902,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 = ' '; @@ -883,16 +910,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; @@ -904,11 +933,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 { @@ -917,31 +950,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) @@ -953,8 +986,7 @@ } } - 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); @@ -1014,6 +1046,7 @@ if (tabs[i]) { x = i; + if (!--count) break; } @@ -1030,8 +1063,7 @@ { 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; @@ -1095,8 +1127,10 @@ scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); else { - if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN - ROW(screen.cur.row).l = ncol; + line_t &l = ROW(screen.cur.row); + + l.touch (); + l.is_longer (0); scr_gotorc (0, 0, R_RELATIVE); scr_insdel_chars (1, DELETE); @@ -1198,6 +1232,9 @@ line_t &line = ROW(screen.cur.row); + line.touch (); + line.is_longer (0); + switch (mode) { case 0: /* erase to end of line */ @@ -1301,8 +1338,7 @@ for (; num--; row++) { - ROW (row).l = 0; - scr_blank_screen_mem (ROW (row), rstyle); + scr_blank_screen_mem (ROW(row), rstyle); scr_blank_line (drawn_buf [row], 0, ncol, ren); } } @@ -1314,7 +1350,7 @@ want_refresh = 1; ZERO_SCROLLBACK (); - nsaved = 0; + top_row = 0; } #endif @@ -1345,7 +1381,8 @@ for (int j = ncol; j--; ) *r1++ = fs; - line.l = ncol; /* make the `E's selectable */ + line.is_longer (0); + line.touch (ncol); } } @@ -1404,6 +1441,9 @@ line_t *line = &ROW(row); + line->touch (); + line->is_longer (0); + switch (insdel) { case INSERT: @@ -1413,11 +1453,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)) @@ -1440,6 +1476,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; @@ -1452,12 +1490,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)) @@ -1579,7 +1613,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; } /* ------------------------------------------------------------------------- */ @@ -1636,7 +1670,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; @@ -1653,6 +1688,7 @@ case 'K': /* German character set */ break; } +#endif } /* ------------------------------------------------------------------------- */ @@ -1758,8 +1794,10 @@ for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); + num_scr_allow = 0; + if (refresh) - scr_refresh (SLOW_REFRESH); + scr_refresh (); } /* ------------------------------------------------------------------------- */ @@ -1777,24 +1815,10 @@ * Move the display so that the line represented by scrollbar value Y is at * the top of the screen */ -int +void rxvt_term::scr_move_to (int y, int len) { - long p = 0; - unsigned int oldviewstart; - - oldviewstart = view_start; - - if (y < len) - { - p = (nrow + nsaved) * (len - y) / len; - p -= (long) (nrow - 1); - p = max (p, 0); - } - - view_start = (unsigned int)min (p, nsaved); - - return scr_changeview (oldviewstart); + scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1)); } /* ------------------------------------------------------------------------- */ @@ -1802,40 +1826,31 @@ * Page the screen up/down nlines * direction should be UP or DN */ -int +bool rxvt_term::scr_page (enum page_dirn direction, int nlines) { - int n; - unsigned int oldviewstart; - - oldviewstart = view_start; - - if (direction == UP) - { - n = view_start + nlines; - view_start = min (n, nsaved); - } - else - { - n = view_start - nlines; - view_start = max (n, 0); - } + int new_view_start = + direction == UP ? view_start - nlines + : view_start + nlines; - return scr_changeview (oldviewstart); + return scr_changeview (new_view_start); } -int -rxvt_term::scr_changeview (unsigned int oldviewstart) +bool +rxvt_term::scr_changeview (int new_view_start) { - PERL_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END)); + clamp_it (new_view_start, top_row, 0); - if (view_start != oldviewstart) - { - want_refresh = 1; - num_scr -= (view_start - oldviewstart); - } + if (new_view_start == view_start) + return false; + + num_scr += new_view_start - view_start; + view_start = new_view_start; + want_refresh = 1; + + HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END)); - return (int) (view_start - oldviewstart); + return true; } /* ------------------------------------------------------------------------- */ @@ -1854,6 +1869,7 @@ if (OPTION (Opt_visualBell)) { scr_rvideo_mode (!rvideo); /* refresh also done */ + display->flush (); rxvt_usleep (VISUAL_BELL_DURATION); scr_rvideo_mode (!rvideo); /* refresh also done */ } @@ -1877,13 +1893,13 @@ if (fullhist) { - nrows = nrow + nsaved; - row_start = -nsaved; + nrows = nrow - top_row; + row_start = top_row; } else { nrows = nrow; - row_start = -view_start; + row_start = view_start; } wctomb (0, 0); @@ -1925,7 +1941,7 @@ * screen.text/screen.rend contain what the screen will change to. */ void -rxvt_term::scr_refresh (unsigned char refresh_type) +rxvt_term::scr_refresh () { unsigned char must_clear, /* use draw_string not draw_image_string */ showcursor; /* show the cursor */ @@ -2021,7 +2037,7 @@ setoldcursor = 0; if (ocrow != -1) { - if (screen.cur.row + view_start != ocrow + if (screen.cur.row - view_start != ocrow || screen.cur.col != oldcursor.col) { if (ocrow < nrow @@ -2039,17 +2055,17 @@ if (setoldcursor) { - if (screen.cur.row + view_start >= nrow) + if (screen.cur.row - view_start >= nrow) oldcursor.row = -1; else { - oldcursor.row = screen.cur.row + view_start; + oldcursor.row = screen.cur.row - view_start; oldcursor.col = screen.cur.col; } } } - PERL_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); + HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); #if ENABLE_OVERLAY scr_swap_overlay (); #endif @@ -2059,7 +2075,6 @@ * D: CopyArea pass - very useful for slower links * This has been deliberately kept simple. */ - i = num_scr; if (!display->is_local && refresh_type == FAST_REFRESH && num_scr_allow && num_scr && abs (num_scr) < nrow && !must_clear) @@ -2067,6 +2082,7 @@ int16_t nits; int j; int len, wlen; + dLocal (int, num_scr); j = nrow; wlen = len = -1; @@ -2075,7 +2091,7 @@ { if (row + i >= 0 && row + i < nrow && row + i != ocrow) { - line_t s = ROW(row - view_start); + line_t s = ROW(view_start + row); line_t d = drawn_buf[row]; line_t d2 = drawn_buf[row + i]; @@ -2109,7 +2125,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; @@ -2123,8 +2139,8 @@ */ for (row = 0; row < nrow; row++) { - text_t *stp = ROW(row - view_start).t; - rend_t *srp = ROW(row - view_start).r; + text_t *stp = ROW(view_start + row).t; + rend_t *srp = ROW(view_start + row).r; text_t *dtp = drawn_buf[row].t; rend_t *drp = drawn_buf[row].r; @@ -2322,7 +2338,7 @@ #if ENABLE_OVERLAY scr_swap_overlay (); #endif - PERL_INVOKE ((this, HOOK_REFRESH_END, DT_END)); + HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END)); /* * G: cleanup cursor and display outline cursor if necessary @@ -2371,19 +2387,18 @@ */ scr_reverse_selection (); - if (refresh_type & SMOOTH_REFRESH) - XFlush (display->display); - num_scr = 0; num_scr_allow = 1; } 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])); } @@ -2445,57 +2460,72 @@ XClearWindow (display->display, vt); } +void +rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) +{ + int view_end = view_start + nrow; + int row, col; + + for (row = max (beg_row, view_start); row <= min (end_row, view_end); row++) + { + text_t *stp = ROW(row).t; + rend_t *srp = ROW(row).r; + + for (col = beg_col; col < end_col; col++) + srp[col] ^= rstyle1; + + while (col-- > beg_col && (stp[col] == NOCHAR || unicode::is_space (stp[col]))) + srp[col] ^= rstyle2; + + if (++col < end_col) + srp[col] ^= rstyle2; + } +} + +void +rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle) +{ + int view_end = view_start + nrow; + int row, col; + + if (beg_row >= view_start) + { + col = beg_col; + row = beg_row; + } + else + { + col = 0; + row = view_start; + } + + for (; row < min (end_row, view_end); row++, col = 0) + for (rend_t *srp = ROW(row).r; col < ncol; col++) + srp[col] ^= rstyle; + + if (row == end_row) + for (rend_t *srp = ROW(row).r; col < end_col; col++) + srp[col] ^= rstyle; +} + /* ------------------------------------------------------------------------- */ void rxvt_term::scr_reverse_selection () { if (selection.op && current_screen == selection.screen - && selection.end.row >= -view_start) + && selection.end.row >= view_start) { - int view_end = -view_start + nrow; - int row, col; - #if ENABLE_FRILLS if (selection.rect) - { - for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++) - { - 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; - } - } + scr_xor_rect (selection.beg.row, selection.beg.col, + selection.end.row, selection.end.col, + RS_RVid, RS_RVid | RS_Uline); else #endif - { - if (selection.beg.row >= -view_start) - { - col = selection.beg.col; - row = selection.beg.row; - } - else - { - col = 0; - row = -view_start; - } - - 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 (row == selection.end.row) - for (rend_t *srp = ROW(row).r; col < selection.end.col; col++) - srp[col] ^= RS_RVid; - } + scr_xor_span (selection.beg.row, selection.beg.col, + selection.end.row, selection.end.col, + RS_RVid); } } @@ -2543,9 +2573,9 @@ return; pos.row = pos.col = 0; - 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) + if (!IN_RANGE_EXC (selection.beg.row, top_row, nrow) + || !IN_RANGE_EXC (selection.mark.row, top_row, nrow) + || !IN_RANGE_EXC (selection.end.row, top_row, nrow) || (check_more == 1 && current_screen == selection.screen && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) @@ -2566,7 +2596,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++) @@ -2720,7 +2750,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 @@ -2729,12 +2759,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); @@ -2774,15 +2804,12 @@ * EXT: button 2 release */ void -rxvt_term::selection_request (Time tm, int x, int y) +rxvt_term::selection_request (Time tm) { - if (x < 0 || x >= width || y < 0 || y >= height) - return; /* outside window */ - 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; } @@ -2884,7 +2911,7 @@ if (selection.clicks == 4) return; /* nothing selected, go away */ - if (PERL_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END))) + if (HOOK_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END))) return; i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); @@ -2908,7 +2935,7 @@ } else #endif - end_col = ROW(row).is_longer () ? ncol : ROW(row).l; //TODO//FIXME//LEN + end_col = ROW(row).l; col = max (col, 0); @@ -2920,6 +2947,7 @@ min_it (end_col, selection.end.col); t = ROW(row).t + col; + for (; col < end_col; col++) { if (*t == NOCHAR) @@ -2978,7 +3006,7 @@ selection.len = ofs; selection.text = (wchar_t *)rxvt_realloc (new_selection_text, (ofs + 1) * sizeof (wchar_t)); - if (PERL_INVOKE ((this, HOOK_SEL_GRAB, DT_LONG, (long)tm, DT_END))) + if (HOOK_INVOKE ((this, HOOK_SEL_GRAB, DT_LONG, (long)tm, DT_END))) return; selection_grab (tm); @@ -2996,7 +3024,10 @@ return true; } else - return false; + { + selection_clear (); + return false; + } #if 0 XTextProperty ct; @@ -3020,11 +3051,20 @@ clicks = ((clicks - 1) % 3) + 1; selection.clicks = clicks; /* save clicks so extend will work */ + if (clicks == 2 && !selection.rect + && HOOK_INVOKE ((this, HOOK_SEL_EXTEND, DT_END))) + { + MEvent.clicks = 1; // what a mess + selection.screen = current_screen; + selection.op = SELECTION_CONT; + return; + } + selection_start_colrow (Pixel2Col (x), Pixel2Row (y)); if (clicks == 2 || clicks == 3) selection_extend_colrow (selection.mark.col, - selection.mark.row + view_start, + selection.mark.row - view_start, 0, /* button 3 */ 1, /* button press */ 0); /* click change */ @@ -3039,10 +3079,10 @@ { want_refresh = 1; - selection.mark.row = row - view_start; + selection.mark.row = row + view_start; selection.mark.col = col; - selection.mark.row = clamp (selection.mark.row, -nsaved, nrow - 1); + selection.mark.row = clamp (selection.mark.row, top_row, nrow - 1); selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); while (selection.mark.col > 0 @@ -3080,7 +3120,7 @@ if (dirn == UP) { - bound.row = - nsaved - 1; + bound.row = top_row - 1; bound.col = 0; dirnadd = -1; } @@ -3138,7 +3178,6 @@ break; } -Old_Word_Selection_You_Die: if (dirn == DN) col++; /* put us on one past the end */ @@ -3169,7 +3208,7 @@ */ if (((selection.clicks % 3) == 1) && !flag && (col == selection.mark.col - && (row == selection.mark.row + view_start))) + && (row == selection.mark.row - view_start))) { /* select nothing */ selection.beg.row = selection.end.row = 0; @@ -3234,7 +3273,7 @@ } pos.col = col; - pos.row = row - view_start; + pos.row = view_start + row; /* * This is mainly xterm style selection with a couple of differences, mainly @@ -3729,8 +3768,8 @@ text_t *t1 = ov_text[y]; rend_t *r1 = ov_rend[y]; - text_t *t2 = ROW(y + ov_y - view_start).t + ov_x; - rend_t *r2 = ROW(y + ov_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--; ) {