--- rxvt-unicode/src/screen.C 2005/12/22 00:07:47 1.188 +++ rxvt-unicode/src/screen.C 2006/01/03 17:34:44 1.206 @@ -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 \ @@ -273,91 +274,138 @@ line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); - // re-wrap lines, this is rather ugly, possibly because I am too dumb - // to come up with a lean and mean algorithm. - 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 != pend && q > 0) + if (nsaved) { - p = MOD (p - 1, prev_total_rows); -#ifdef DEBUG_STRICT - assert (old_buf [MOD (p, prev_total_rows)].t); -#endif + // re-wrap lines, this is rather ugly, possibly because I am too dumb + // to come up with a lean and mean algorithm. - int llen = old_buf [MOD (p, prev_total_rows)].l; + row_col_t ocur = screen.cur; + ocur.row = MOD (term_start + ocur.row, prev_total_rows); - while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) + do { p = MOD (p - 1, prev_total_rows); +#ifdef DEBUG_STRICT + assert (old_buf [MOD (p, prev_total_rows)].t); +#endif - llen += prev_ncol; - } + int plines = 1; + int llen = old_buf [MOD (p, prev_total_rows)].l; - int qlines = max (0, (llen - 1) / ncol) + 1; + while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) + { + p = MOD (p - 1, prev_total_rows); - // drop partial lines completely - if (q < qlines) - break; + plines++; + llen += prev_ncol; + } - q -= qlines; + int qlines = max (0, (llen - 1) / ncol) + 1; - int lofs = 0; - line_t *qline; + // drop partial lines completely + if (q < qlines) + break; - // re-assemble the full line by destination lines - for (int qrow = q; qlines--; qrow++) - { - qline = row_buf + qrow; - lalloc (*qline); - qline->set_is_longer (); + q -= qlines; - int qcol = 0; + int lofs = 0; + line_t *qline; - // fill a single destination line - while (lofs < llen && qcol < ncol) + // re-assemble the full line by destination lines + for (int qrow = q; qlines--; qrow++) { - int prow = lofs / prev_ncol; - int pcol = lofs % prev_ncol; + qline = row_buf + qrow; + lalloc (*qline); + qline->set_is_longer (); + + int qcol = 0; + + // fill a single destination line + while (lofs < llen && qcol < ncol) + { + int prow = lofs / prev_ncol; + int pcol = lofs % prev_ncol; + + prow = MOD (p + prow, prev_total_rows); - line_t &pline = old_buf [MOD (p + prow, prev_total_rows)]; + // 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); - int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); + line_t &pline = old_buf [prow]; - assert (len); - assert (pline.t); + int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); - memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); - memcpy (qline->r + qcol, pline.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)); + + lofs += len; + qcol += len; + } + } + + 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 + 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); - qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1; - scr_blank_line (*qline, qline->l, ncol - qline->l, 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]; - term_start = total_rows - nrow; - view_start = 0; - nsaved = term_start - q; + qline = pline; + lresize (qline); + } - // make sure all terminal lines exist - while (nsaved < 0) - scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); + for (int row = prev_nrow; row < nrow; row++) + { + row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE); + } + + term_start = 0; + } +#ifdef DEBUG_STRICT //TODO: remove for (int i = -nsaved; i < nrow; i++) - assert (ROW (i).t);//D + assert (ROW (i).t); +#endif free (old_buf); delete old_ta; delete old_ra; - min_it (screen.cur.row, nrow - 1); - min_it (screen.cur.col, ncol - 1); + clamp_it (screen.cur.row, 0, nrow - 1); + clamp_it (screen.cur.col, 0, ncol - 1); if (tabs) free (tabs); @@ -372,6 +420,8 @@ tabs [col] = col % TABSIZE == 0; tt_winch (); + + PERL_INVOKE ((this, HOOK_RESET, DT_END)); } /* ------------------------------------------------------------------------- */ @@ -485,7 +535,7 @@ screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1); #if NSCREENS - if (options & Opt_secondaryScreen) + if (OPTION (Opt_secondaryScreen)) { num_scr = 0; @@ -499,7 +549,7 @@ } else #endif - if (options & Opt_secondaryScroll) + if (OPTION (Opt_secondaryScroll)) scr_scroll_text (0, prev_nrow - 1, prev_nrow); return scrn; @@ -571,9 +621,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); + + PERL_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) @@ -582,13 +635,22 @@ 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); + { + ROW(row2 - i).l = 0; + 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); @@ -597,20 +659,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; @@ -655,7 +714,7 @@ unsigned char checksel; unicode_t c; - int row, last_col; + int last_col; const unicode_t *strend = str + len; want_refresh = 1; @@ -680,7 +739,7 @@ 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; @@ -692,7 +751,7 @@ if (c < 0x20) if (c == C0_LF) - { + { if (!line->is_longer ()) /* XXX: think about this */ max_it (line->l, screen.cur.col); @@ -947,9 +1006,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] == ' '; @@ -969,7 +1026,7 @@ // 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); @@ -1034,16 +1091,12 @@ 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; - - if (ROW(row).is_longer ()) //TODO//FIXME//LEN - ROW(row).l = ncol; + if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN + ROW(screen.cur.row).l = ncol; scr_gotorc (0, 0, R_RELATIVE); scr_insdel_chars (1, DELETE); @@ -1136,21 +1189,21 @@ 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); switch (mode) { case 0: /* erase to end of line */ col = screen.cur.col; num = ncol - col; - min_it (ROW(row).l, 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 (); @@ -1165,7 +1218,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 (); @@ -1174,7 +1227,7 @@ return; } - scr_blank_line (ROW(row), col, num, rstyle); + scr_blank_line (line, col, num, rstyle); } /* ------------------------------------------------------------------------- */ @@ -1239,7 +1292,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]; @@ -1248,8 +1301,8 @@ for (; num--; row++) { - scr_blank_screen_mem (ROW (row), rstyle); ROW (row).l = 0; + scr_blank_screen_mem (ROW (row), rstyle); scr_blank_line (drawn_buf [row], 0, ncol, ren); } } @@ -1548,7 +1601,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]); @@ -1774,6 +1827,8 @@ int rxvt_term::scr_changeview (unsigned int oldviewstart) { + PERL_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END)); + if (view_start != oldviewstart) { want_refresh = 1; @@ -1791,12 +1846,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); @@ -1897,7 +1952,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? */ @@ -1931,7 +1986,7 @@ if (showcursor && focus) { - if (options & Opt_cursorUnderline) + if (OPTION (Opt_cursorUnderline)) *crp ^= RS_Uline; else { @@ -1943,7 +1998,7 @@ ccol1 = Color_cursor; else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol1 = GET_FGCOLOR (rstyle); + ccol1 = fgcolor_of (rstyle); #else ccol1 = Color_fg; #endif @@ -1951,7 +2006,7 @@ ccol2 = Color_cursor2; else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol2 = GET_BGCOLOR (rstyle); + ccol2 = bgcolor_of (rstyle); #else ccol2 = Color_bg; #endif @@ -1994,6 +2049,7 @@ } } + PERL_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); #if ENABLE_OVERLAY scr_swap_overlay (); #endif @@ -2142,10 +2198,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 @@ -2266,6 +2322,7 @@ #if ENABLE_OVERLAY scr_swap_overlay (); #endif + PERL_INVOKE ((this, HOOK_REFRESH_END, DT_END)); /* * G: cleanup cursor and display outline cursor if necessary @@ -2274,7 +2331,7 @@ { if (focus) { - if (options & Opt_cursorUnderline) + if (OPTION (Opt_cursorUnderline)) *crp ^= RS_Uline; else { @@ -2403,8 +2460,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 @@ -2417,7 +2485,7 @@ else { col = 0; - row = view_start; + row = -view_start; } for (; row < min (selection.end.row, view_end); row++, col = 0) @@ -2816,6 +2884,9 @@ if (selection.clicks == 4) return; /* nothing selected, go away */ + if (PERL_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)); @@ -2841,8 +2912,12 @@ 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++) @@ -2870,8 +2945,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) @@ -2891,11 +2978,25 @@ 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))) + 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; @@ -2906,8 +3007,6 @@ XFree (ct.value); } #endif - - selection_time = tm; } /* ------------------------------------------------------------------------- */ @@ -3226,13 +3325,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 (!PERL_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); @@ -3303,9 +3405,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; } @@ -3514,7 +3615,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; @@ -3631,8 +3732,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--; ) {