--- rxvt-unicode/src/screen.C 2005/01/14 17:15:26 1.153 +++ rxvt-unicode/src/screen.C 2005/08/05 16:42:44 1.167 @@ -30,7 +30,6 @@ #include /* get the typedef for CARD32 */ #include -#include #include "salloc.C" // HACK, should be a seperate compile! @@ -205,17 +204,17 @@ * Note: this is still needed so that all the scrollback lines are NULL */ screen.text = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *)); - buf_text = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *)); - drawn_text = (text_t **)rxvt_calloc (nrow, sizeof (text_t *)); - swap.text = (text_t **)rxvt_calloc (nrow, sizeof (text_t *)); + buf_text = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *)); + drawn_text = (text_t **)rxvt_calloc (nrow, sizeof (text_t *)); + swap.text = (text_t **)rxvt_calloc (nrow, sizeof (text_t *)); screen.tlen = (int16_t *)rxvt_calloc (total_rows, sizeof (int16_t)); - swap.tlen = (int16_t *)rxvt_calloc (nrow, sizeof (int16_t)); + swap.tlen = (int16_t *)rxvt_calloc (nrow, sizeof (int16_t)); screen.rend = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *)); - buf_rend = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *)); - drawn_rend = (rend_t **)rxvt_calloc (nrow, sizeof (rend_t *)); - swap.rend = (rend_t **)rxvt_calloc (nrow, sizeof (rend_t *)); + buf_rend = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *)); + drawn_rend = (rend_t **)rxvt_calloc (nrow, sizeof (rend_t *)); + swap.rend = (rend_t **)rxvt_calloc (nrow, sizeof (rend_t *)); for (p = 0; p < nrow; p++) { @@ -336,10 +335,10 @@ screen.s_cur.row += k; TermWin.nscrolled -= k; } + #ifdef DEBUG_STRICT assert (screen.cur.row < TermWin.nrow); #else /* drive with your eyes closed */ - MIN_IT (screen.cur.row, nrow - 1); #endif TermWin.ncol = ncol; // save b/c scr_blank_screen_mem uses this @@ -702,8 +701,8 @@ else if (j >= row1 && j <= row2) { /* move selected region too */ - selection.beg.row -= count; - selection.end.row -= count; + selection.beg.row -= count; + selection.end.row -= count; selection.mark.row -= count; } } @@ -721,13 +720,13 @@ if (j > 0) { - /* A: scroll up */ + /* scroll up */ - /* A1: Copy lines that will get clobbered by the rotation */ + /* Copy lines that will get clobbered by the rotation */ memcpy (buf_text, screen.text + row1, count * sizeof (text_t *)); memcpy (buf_rend, screen.rend + row1, count * sizeof (rend_t *)); - /* A2: Rotate lines */ + /* Rotate lines */ i = row2 - row1 - count + 1; memmove (screen.tlen + row1, screen.tlen + row1 + count, i * sizeof (int16_t)); memmove (screen.text + row1, screen.text + row1 + count, i * sizeof (text_t *)); @@ -737,16 +736,16 @@ } else /* if (j < 0) */ { - /* B: scroll down */ + /* scroll down */ - /* B1: Copy lines that will get clobbered by the rotation */ + /* Copy lines that will get clobbered by the rotation */ for (i = 0, j = row2; i < count; i++, j--) { buf_text[i] = screen.text[j]; buf_rend[i] = screen.rend[j]; } - /* B2: Rotate lines */ + /* Rotate lines */ for (j = row2, i = j - count; i >= row1; i--, j--) { screen.tlen[j] = screen.tlen[i]; @@ -758,7 +757,7 @@ count = -count; } - /* C: Resurrect lines */ + /* Resurrect lines */ memset (screen.tlen + j, 0, i * sizeof (int16_t)); memcpy (screen.text + j, buf_text, i * sizeof (text_t *)); memcpy (screen.rend + j, buf_rend, i * sizeof (text_t *)); @@ -776,14 +775,15 @@ void rxvt_term::scr_add_lines (const unicode_t *str, int nlines, int len) { + if (len <= 0) /* sanity */ + return; + unsigned char checksel; unicode_t c; int i, row, last_col; text_t *stp; rend_t *srp; - - if (len <= 0) /* sanity */ - return; + const unicode_t *strend = str + len; want_refresh = 1; ZERO_SCROLLBACK (); @@ -818,39 +818,40 @@ stp = screen.text[row]; srp = screen.rend[row]; - while (len--) + while (str < strend) { c = *str++; if (c < 0x20) - switch (c) - { - case C0_HT: - scr_tab (1, true); - continue; - - case C0_LF: - if (screen.tlen[row] != -1) /* XXX: think about this */ - MAX_IT (screen.tlen[row], screen.cur.col); - - screen.flags &= ~Screen_WrapNext; - - if (screen.cur.row == screen.bscroll) - scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0); - else if (screen.cur.row < (TermWin.nrow - 1)) - row = (++screen.cur.row) + TermWin.saveLines; + if (c == C0_LF) + { + if (screen.tlen[row] != -1) /* XXX: think about this */ + MAX_IT (screen.tlen[row], screen.cur.col); + + screen.flags &= ~Screen_WrapNext; + + if (screen.cur.row == screen.bscroll) + scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0); + else if (screen.cur.row < (TermWin.nrow - 1)) + row = (++screen.cur.row) + TermWin.saveLines; - stp = screen.text[row]; /* _must_ refresh */ - srp = screen.rend[row]; /* _must_ refresh */ - continue; - - case C0_CR: - if (screen.tlen[row] != -1) /* XXX: think about this */ - MAX_IT (screen.tlen[row], screen.cur.col); + stp = screen.text[row]; /* _must_ refresh */ + srp = screen.rend[row]; /* _must_ refresh */ + continue; + } + else if (c == C0_CR) + { + if (screen.tlen[row] != -1) /* XXX: think about this */ + MAX_IT (screen.tlen[row], screen.cur.col); - screen.flags &= ~Screen_WrapNext; - screen.cur.col = 0; - continue; + screen.flags &= ~Screen_WrapNext; + screen.cur.col = 0; + continue; + } + else if (c == C0_HT) + { + scr_tab (1, true); + continue; } if (checksel /* see if we're writing within selection */ @@ -870,15 +871,21 @@ { screen.tlen[row] = -1; - scr_do_wrap (); row = screen.cur.row + TermWin.saveLines; - + scr_do_wrap (); + + row = screen.cur.row + TermWin.saveLines; stp = screen.text[row]; /* _must_ refresh */ srp = screen.rend[row]; /* _must_ refresh */ } + // some utf-8 decoders "decode" surrogate characters: let's fix this. + if (IN_RANGE (c, 0xd800, 0xdfff)) + c = 0xfffd; + // rely on wcwidth to tell us the character width, at least for non-latin1 - // do wcwidth before further replacements, as wcwidth says that line-drawing - // characters have width -1 (DOH!) on GNU/Linux sometimes. + // do wcwidth before further replacements, as wcwidth might return -1 + // for the line drawing characters below as they might be invalid in the current + // locale. int width = c < 0x100 ? 1 : wcwidth (c); if (charsets[screen.charset] == '0') // DEC SPECIAL @@ -886,21 +893,21 @@ // vt100 special graphics and line drawing // 5f-7e standard vt100 // 40-5e rxvt extension for extra curses acs chars - static uint16_t vt100_0[63] = { // 40 .. 7e - 0x0000, 0x2191, 0x2193, 0x2192, 0x2190, 0x2588, 0x259a, 0x2603, // 40-47 hi mr. snowman! - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 48-4f - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 50-57 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, // 58-5f + static uint16_t vt100_0[62] = { // 41 .. 7e + 0x2191, 0x2193, 0x2192, 0x2190, 0x2588, 0x259a, 0x2603, // 41-47 hi mr. snowman! + 0, 0, 0, 0, 0, 0, 0, 0, // 48-4f + 0, 0, 0, 0, 0, 0, 0, 0, // 50-57 + 0, 0, 0, 0, 0, 0, 0, 0x0020, // 58-5f 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, // 60-67 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, // 68-6f 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, // 70-77 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, // 78-7e }; - if (c >= 0x40 && c <= 0x7e && vt100_0[c - 0x40]) + if (c >= 0x41 && c <= 0x7e && vt100_0[c - 0x41]) { - c = vt100_0[c - 0x40]; - width = 1; + c = vt100_0[c - 0x41]; + width = 1; // vt100 line drawing characters are always single-width } } @@ -909,10 +916,6 @@ if (width != 0) { - // some utf-8 decoders decode surrogate characters. - if (0xd800 <= c && c <= 0xdfff) - c = 0xfffd; - #if !UNICODE_3 // trim characters we can't store directly :( if (c >= 0x10000) @@ -946,6 +949,15 @@ 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) + { + // ...output spaces + c = ' '; + // and try the same character next loop iteration + --str; + } + do { stp[screen.cur.col] = c; @@ -973,14 +985,13 @@ srp[c] = rend; } } - else if (width == 0) + else // width == 0 { #if ENABLE_COMBINING // handle combining characters // 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. - text_t *tp; rend_t *rp; @@ -1164,7 +1175,7 @@ void rxvt_term::scr_forwardindex () { - int row; + int row; if (screen.cur.col < TermWin.ncol - 1) scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); @@ -1393,6 +1404,17 @@ } } +#if ENABLE_FRILLS +void +rxvt_term::scr_erase_savelines () +{ + want_refresh = 1; + ZERO_SCROLLBACK (); + + TermWin.nscrolled = 0; +} +#endif + /* ------------------------------------------------------------------------- */ /* * Fill the screen with `E's @@ -1401,8 +1423,8 @@ void rxvt_term::scr_E () { - int i, j, k; - rend_t *r1, fs; + int i, j, k; + rend_t *r1, fs; want_refresh = 1; ZERO_SCROLLBACK (); @@ -1895,10 +1917,8 @@ int n; unsigned int oldviewstart; -#ifdef DEBUG_STRICT - assert ((nlines >= 0) && (nlines <= TermWin.nrow)); -#endif oldviewstart = TermWin.view_start; + if (direction == UP) { n = TermWin.view_start + nlines; @@ -1909,6 +1929,7 @@ n = TermWin.view_start - nlines; TermWin.view_start = max (n, 0); } + return scr_changeview (oldviewstart); } @@ -1929,19 +1950,23 @@ rxvt_term::scr_bell () { #ifndef NO_BELL + # ifndef NO_MAPALERT # ifdef MAPALERT_OPTION if (options & Opt_mapAlert) # endif XMapWindow (display->display, TermWin.parent[0]); # endif + if (options & Opt_visualBell) { scr_rvideo_mode (!rvideo); /* refresh also done */ + rxvt_usleep (VISUAL_BELL_DURATION); scr_rvideo_mode (!rvideo); /* refresh also done */ } else XBell (display->display, 0); + #endif } @@ -2006,16 +2031,6 @@ * drawn_text/drawn_rend contain the screen information before the update. * screen.text/screen.rend contain what the screen will change to. */ - -#define FONT_WIDTH(X, Y) \ - (X)->per_char[ (Y) - (X)->min_char_or_byte2].width -#define FONT_RBEAR(X, Y) \ - (X)->per_char[ (Y) - (X)->min_char_or_byte2].rbearing -#define FONT_LBEAR(X, Y) \ - (X)->per_char[ (Y) - (X)->min_char_or_byte2].lbearing -#define IS_FONT_CHAR(X, Y) \ - ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2) - void rxvt_term::scr_refresh (unsigned char refresh_type) { @@ -2044,10 +2059,10 @@ row_offset = TermWin.saveLines - TermWin.view_start; #if XPM_BACKGROUND - must_clear |= (bgPixmap.pixmap != None); + must_clear |= bgPixmap.pixmap != None; #endif #if TRANSPARENT - must_clear |= ((options & Opt_transparent) && am_transparent); + must_clear |= (options & Opt_transparent) && am_transparent; #endif ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ @@ -2081,28 +2096,34 @@ if (showcursor && TermWin.focus) { - *crp ^= RS_RVid; -#ifndef NO_CURSORCOLOR - cc1 = *crp & (RS_fgMask | RS_bgMask); - if (ISSET_PIXCOLOR (Color_cursor)) - ccol1 = Color_cursor; + if (options & Opt_cursorUnderline) + *crp ^= RS_Uline; else + { + *crp ^= RS_RVid; + +#ifndef NO_CURSORCOLOR + cc1 = *crp & (RS_fgMask | RS_bgMask); + if (ISSET_PIXCOLOR (Color_cursor)) + ccol1 = Color_cursor; + else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol1 = GET_FGCOLOR (rstyle); + ccol1 = GET_FGCOLOR (rstyle); #else - ccol1 = Color_fg; + ccol1 = Color_fg; #endif - if (ISSET_PIXCOLOR (Color_cursor2)) - ccol2 = Color_cursor2; - else + if (ISSET_PIXCOLOR (Color_cursor2)) + ccol2 = Color_cursor2; + else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol2 = GET_BGCOLOR (rstyle); + ccol2 = GET_BGCOLOR (rstyle); #else - ccol2 = Color_bg; + ccol2 = Color_bg; #endif - *crp = SET_FGCOLOR (*crp, ccol1); - *crp = SET_BGCOLOR (*crp, ccol2); + *crp = SET_FGCOLOR (*crp, ccol1); + *crp = SET_BGCOLOR (*crp, ccol2); #endif + } } } @@ -2418,24 +2439,35 @@ { if (TermWin.focus) { - *crp ^= RS_RVid; + if (options & Opt_cursorUnderline) + *crp ^= RS_Uline; + else + { + *crp ^= RS_RVid; #ifndef NO_CURSORCOLOR - *crp = (*crp & ~ (RS_fgMask | RS_bgMask)) | cc1; + *crp = (*crp & ~ (RS_fgMask | RS_bgMask)) | cc1; #endif + } } else if (oldcursor.row >= 0) { + int cursorwidth = 1; + int col = oldcursor.col; + + while (col && screen.text[screen.cur.row + TermWin.saveLines][col] == NOCHAR) + col--; + + while (col + cursorwidth < TermWin.ncol + && drawn_text[oldcursor.row][col + cursorwidth] == NOCHAR) + cursorwidth++; + #ifndef NO_CURSORCOLOR if (ISSET_PIXCOLOR (Color_cursor)) XSetForeground (display->display, TermWin.gc, pix_colors[Color_cursor]); #endif - int cursorwidth = 1; - while (oldcursor.col + cursorwidth < TermWin.ncol - && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR) - cursorwidth++; XDrawRectangle (display->display, drawBuffer, TermWin.gc, - Col2Pixel (oldcursor.col), + Col2Pixel (col), Row2Pixel (oldcursor.row), (unsigned int) (Width2Pixel (cursorwidth) - 1), (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1)); @@ -2904,9 +2936,6 @@ rxvt_term::selection_request_other (Atom target, int selnum) { Atom sel; -#ifdef DEBUG_SELECT - char *debug_xa_names[] = { "PRIMARY", "SECONDARY", "CLIPBOARD" }; -#endif selection_type |= selnum; @@ -3411,7 +3440,7 @@ else if (selection.clicks == 3) { #if ENABLE_FRILLS - if ((options & Opt_tripleclickwords)) + if (options & Opt_tripleclickwords) { int end_row; @@ -3439,6 +3468,15 @@ selection.beg.col = 0; selection.end.col = ncol; + + // select a complete logical line + while (selection.beg.row > -TermWin.saveLines + && screen.tlen[selection.beg.row - 1 + TermWin.saveLines] == -1) + selection.beg.row--; + + while (selection.end.row < TermWin.nrow + && screen.tlen[selection.end.row + TermWin.saveLines] == -1) + selection.end.row++; } } @@ -3528,6 +3566,7 @@ rxvt_term::selection_send (const XSelectionRequestEvent &rq) { XSelectionEvent ev; + dDisp; ev.type = SelectionNotify; ev.property = None; @@ -3551,7 +3590,7 @@ *target++ = xa[XA_UTF8_STRING]; #endif - XChangeProperty (display->display, rq.requestor, rq.property, XA_ATOM, + XChangeProperty (disp, rq.requestor, rq.property, XA_ATOM, 32, PropModeReplace, (unsigned char *)target_list, target - target_list); ev.property = rq.property; @@ -3564,7 +3603,7 @@ #endif else if (rq.target == xa[XA_TIMESTAMP] && selection.text) { - XChangeProperty (display->display, rq.requestor, rq.property, rq.target, + XChangeProperty (disp, rq.requestor, rq.property, rq.target, 32, PropModeReplace, (unsigned char *)&selection_time, 1); ev.property = rq.property; } @@ -3632,7 +3671,7 @@ } else #endif - if (XwcTextListToTextProperty (display->display, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) + if (XwcTextListToTextProperty (disp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) freect = 1; else { @@ -3642,7 +3681,7 @@ ct.encoding = target; } - XChangeProperty (display->display, rq.requestor, rq.property, + XChangeProperty (disp, rq.requestor, rq.property, ct.encoding, 8, PropModeReplace, ct.value, (int)ct.nitems); ev.property = rq.property; @@ -3651,7 +3690,7 @@ XFree (ct.value); } - XSendEvent (display->display, rq.requestor, False, 0L, (XEvent *)&ev); + XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev); } /* ------------------------------------------------------------------------- * @@ -3781,6 +3820,22 @@ } void +rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) +{ + while (*s) + { + text_t t = *s++; + int width = wcwidth (t); + + while (width--) + { + scr_overlay_set (x++, y, t); + t = NOCHAR; + } + } +} + +void rxvt_term::scr_swap_overlay () { if (!ov_text)