--- rxvt-unicode/src/screen.C 2004/12/12 15:13:37 1.147 +++ rxvt-unicode/src/screen.C 2005/10/25 19:04:46 1.169 @@ -30,7 +30,6 @@ #include /* get the typedef for CARD32 */ #include -#include #include "salloc.C" // HACK, should be a seperate compile! @@ -41,7 +40,8 @@ } /* ------------------------------------------------------------------------- */ -#define PROP_SIZE 16384 +#define PROP_SIZE 256*1024 +#define PASTE_SIZE 32768 #define TABSIZE 8 /* default tab size */ /* ------------------------------------------------------------------------- * @@ -204,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++) { @@ -295,7 +295,6 @@ /* we have fewer rows so fix up cursor position */ MIN_IT (screen.cur.row, (int32_t)nrow - 1); - MIN_IT (swap.cur.row, (int32_t)nrow - 1); scr_reset_realloc (); /* realloc _last_ */ } @@ -336,13 +335,11 @@ screen.s_cur.row += k; TermWin.nscrolled -= k; } + #ifdef DEBUG_STRICT assert (screen.cur.row < TermWin.nrow); - assert (swap.cur.row < TermWin.nrow); #else /* drive with your eyes closed */ - MIN_IT (screen.cur.row, nrow - 1); - MIN_IT (swap.cur.row, nrow - 1); #endif TermWin.ncol = ncol; // save b/c scr_blank_screen_mem uses this } @@ -395,7 +392,6 @@ } MIN_IT (screen.cur.col, (int16_t)ncol - 1); - MIN_IT (swap.cur.col, (int16_t)ncol - 1); delete talloc; talloc = ta; delete ralloc; ralloc = ra; @@ -567,19 +563,14 @@ selection_check (2); /* check for boundary cross */ - SWAP_IT (current_screen, scrn, int); + i = current_screen; current_screen = scrn; scrn = i; SWAP_IT (screen.cur.row, swap.cur.row, int16_t); SWAP_IT (screen.cur.col, swap.cur.col, int16_t); -# ifdef DEBUG_STRICT - assert (screen.cur.row >= 0 && screen.cur.row < prev_nrow); - assert (screen.cur.col >= 0 && screen.cur.col < prev_ncol); -# else /* drive with your eyes closed */ MAX_IT (screen.cur.row, 0); MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); MAX_IT (screen.cur.col, 0); MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1); -# endif #if NSCREENS if (options & Opt_secondaryScreen) @@ -602,8 +593,7 @@ else #endif if (options & Opt_secondaryScroll) - //if (current_screen == PRIMARY) - scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0); + scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0); return scrn; } @@ -711,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; } } @@ -730,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 *)); @@ -746,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]; @@ -767,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 *)); @@ -785,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 (); @@ -827,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 */ @@ -879,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 @@ -895,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 } } @@ -918,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) @@ -955,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; @@ -982,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; @@ -1173,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); @@ -1402,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 @@ -1410,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 (); @@ -1904,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; @@ -1918,6 +1929,7 @@ n = TermWin.view_start - nlines; TermWin.view_start = max (n, 0); } + return scr_changeview (oldviewstart); } @@ -1938,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 } @@ -2015,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) { @@ -2053,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? */ @@ -2090,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 + } } } @@ -2298,27 +2310,27 @@ while (i && text[count] == NOCHAR) count++, i--; -#if ENABLE_STYLES - // force redraw after "careful" characters to avoid pixel droppings - if (srp[col] & RS_Careful && col < TermWin.ncol - 1 && 0) - drp[col + 1] = ~srp[col + 1]; - - // include previous careful character(s) if possible, looks nicer (best effort...) - while (text > stp - && srp[text - stp - 1] & RS_Careful - && RS_SAME (rend, srp[text - stp - 1])) - text--, count++, xpixel -= TermWin.fwidth; -#endif - /* * Determine the attributes for the string */ int fore = GET_FGCOLOR (rend); // desired foreground int back = GET_BGCOLOR (rend); // desired background - // only do special processing if ana attributes are set, which is rare - if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink)) + // only do special processing if any attributes are set, which is rare + if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) { +#if ENABLE_STYLES + // force redraw after "careful" characters to avoid pixel droppings + if (srp[col] & RS_Careful && col < TermWin.ncol - 1 && 0) + drp[col + 1] = ~srp[col + 1]; + + // include previous careful character(s) if possible, looks nicer (best effort...) + while (text > stp + && srp[text - stp - 1] & RS_Careful + && RS_SAME (rend, srp[text - stp - 1])) + text--, count++, xpixel -= TermWin.fwidth; +#endif + bool invert = rend & RS_RVid; #ifndef NO_BOLD_UNDERLINE_REVERSE @@ -2355,6 +2367,12 @@ #ifndef NO_BOLD_UNDERLINE_REVERSE if (ISSET_PIXCOLOR (Color_RV)) back = Color_RV; + + if (fore == back) + { + fore = Color_bg; + back = Color_fg; + } #endif } @@ -2402,7 +2420,13 @@ if (rend & RS_Uline && font->descent > 1 && fore != back) { - XSetForeground (display->display, TermWin.gc, pix_colors[fore]); +#if ENABLE_FRILLS + if (ISSET_PIXCOLOR (Color_underline)) + XSetForeground (display->display, TermWin.gc, pix_colors[Color_underline]); + else +#endif + XSetForeground (display->display, TermWin.gc, pix_colors[fore]); + XDrawLine (display->display, drawBuffer, TermWin.gc, xpixel, ypixel + font->ascent + 1, xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); @@ -2421,24 +2445,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)); @@ -2520,22 +2555,6 @@ num_scr_allow = 0; want_refresh = 1; -#if TRANSPARENT - if ((options & Opt_transparent) && (am_pixmap_trans == 0)) - { - int i; - - if (!(options & Opt_transparent_all)) - i = 0; - else - i = (int) (sizeof (TermWin.parent) / sizeof (Window)); - - while (i--) - if (TermWin.parent[i] != None) - XClearWindow (display->display, TermWin.parent[i]); - } -#endif - if (really) XClearWindow (display->display, TermWin.vt); } @@ -2658,25 +2677,14 @@ * Paste a selection direct to the command fd */ void -rxvt_term::paste (const unsigned char *data, unsigned int len) +rxvt_term::paste (unsigned char *data, unsigned int len) { - unsigned int i, j, n; - unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE); - /* convert normal newline chars into common keyboard Return key sequence */ - for (i = 0; i < len; i += PROP_SIZE) - { - n = min (len - i, PROP_SIZE); - memcpy (ds, data + i, n); + for (unsigned int i = 0; i < len; i++) + if (data[i] == C0_LF) + data[i] = C0_CR; - for (j = 0; j < n; j++) - if (ds[j] == C0_LF) - ds[j] = C0_CR; - - tt_write (ds, (int)n); - } - - free (ds); + tt_write (data, len); } /* ------------------------------------------------------------------------- */ @@ -2684,13 +2692,9 @@ * Respond to a notification that a primary selection has been sent * EXT: SelectionNotify */ -int +void rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) { - long nread = 0; - unsigned long bytes_after; - XTextProperty ct; - if (prop == None) /* check for failed XConvertSelection */ { if ((selection_type & Sel_CompoundText)) @@ -2713,36 +2717,80 @@ selection_type = 0; } - return 0; + return; } - for (;;) + unsigned long bytes_after; + XTextProperty ct; + + if (XGetWindowProperty (display->display, win, prop, + 0, PROP_SIZE / 4, + delete_prop, AnyPropertyType, + &ct.encoding, &ct.format, + &ct.nitems, &bytes_after, + &ct.value) != Success) { - if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), - (long) (PROP_SIZE / 4), delete_prop, - AnyPropertyType, &ct.encoding, &ct.format, - &ct.nitems, &bytes_after, - &ct.value) != Success) - break; + ct.value = 0; + goto bailout; + } - if (ct.encoding == 0) - break; + if (ct.encoding == None) + goto bailout; - if (ct.encoding == xa[XA_INCR]) - { - // INCR selection, start handshake - XDeleteProperty (display->display, win, prop); - selection_wait = Sel_incr; - incr_ev.start (NOW + 10); - break; - } + if (bytes_after) + { + // fetch and append remaining data + XTextProperty ct2; + + if (XGetWindowProperty (display->display, win, prop, + ct.nitems / 4, (bytes_after + 3) / 4, + delete_prop, AnyPropertyType, + &ct2.encoding, &ct2.format, + &ct2.nitems, &bytes_after, + &ct2.value) != Success) + goto bailout; - if (ct.value == NULL) - continue; + // realloc should be compatible to XFree, here, and elsewhere, too + ct.value = (unsigned char *)realloc (ct.value, ct.nitems + ct2.nitems + 1); + memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems + 1); + ct.nitems += ct2.nitems; + + XFree (ct2.value); + } + + if (ct.value == 0) + goto bailout; + + if (ct.encoding == xa[XA_INCR]) + { + // INCR selection, start handshake + if (!delete_prop) + XDeleteProperty (display->display, win, prop); - if (ct.nitems == 0) + selection_wait = Sel_incr; + incr_buf_fill = 0; + incr_ev.start (NOW + 10); + + goto bailout; + } + + if (ct.nitems == 0) + { + if (selection_wait == Sel_incr) + { + XFree (ct.value); + + // finally complete, now paste the whole thing + selection_wait = Sel_normal; + ct.value = (unsigned char *)incr_buf; + ct.nitems = incr_buf_fill; + incr_buf = 0; + incr_buf_size = 0; + incr_ev.stop (); + } + else { - if (selection_wait == Sel_normal && nread == 0 + if (selection_wait == Sel_normal && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion { /* @@ -2752,54 +2800,58 @@ selection_paste (display->root, XA_CUT_BUFFER0, False); } - nread = -1; /* discount any previous stuff */ - break; + goto bailout; } + } + else if (selection_wait == Sel_incr) + { + incr_ev.start (NOW + 10); - nread += ct.nitems; - - char **cl; - int cr; - -#if ENABLE_FRILLS - // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it - // so recode it manually - if (ct.encoding == xa[XA_UTF8_STRING]) + while (incr_buf_fill + ct.nitems > incr_buf_size) { - wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); - char *s = rxvt_wcstombs (w); + incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024; + incr_buf = (char *)realloc (incr_buf, incr_buf_size); + } - // TODO: strlen == only the first element will be converted. well... - paste ((unsigned char *)s, strlen (s)); + memcpy (incr_buf + incr_buf_fill, ct.value, ct.nitems); + incr_buf_fill += ct.nitems; - free (s); - free (w); - } - else -#endif - if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 && cl) - { - for (int i = 0; i < cr; i++) - paste ((unsigned char *)cl[i], strlen (cl[i])); + goto bailout; + } - XFreeStringList (cl); - } - else - paste (ct.value, ct.nitems); + char **cl; + int cr; - if (bytes_after == 0) - break; +#if ENABLE_FRILLS + // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it + // so recode it manually + if (ct.encoding == xa[XA_UTF8_STRING]) + { + wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); + char *s = rxvt_wcstombs (w); + free (w); + // TODO: strlen == only the first element will be converted. well... + paste ((unsigned char *)s, strlen (s)); + free (s); + } + else +#endif + if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 + && cl) + { + for (int i = 0; i < cr; i++) + paste ((unsigned char *)cl[i], strlen (cl[i])); - XFree (ct.value); + XFreeStringList (cl); } + else + paste (ct.value, ct.nitems); // paste raw - if (ct.value) - XFree (ct.value); +bailout: + XFree (ct.value); if (selection_wait == Sel_normal) selection_wait = Sel_none; - - return (int)nread; } void @@ -2807,25 +2859,19 @@ { selection_wait = Sel_none; + incr_buf_size = 0; + free (incr_buf); + rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); } -/* - * INCR support originally provided by Paul Sheer - */ void rxvt_term::selection_property (Window win, Atom prop) { if (prop == None || selection_wait != Sel_incr) return; - if (selection_paste (win, prop, 1) > 0) - incr_ev.start (NOW + 10); - else - { - selection_wait = Sel_none; - incr_ev.stop (); - } + selection_paste (win, prop, true); } /* ------------------------------------------------------------------------- */ @@ -2872,17 +2918,14 @@ } } - selection_wait = Sel_none; /* don't loop in rxvt_selection_paste () */ - selection_paste (display->root, XA_CUT_BUFFER0, False); + selection_wait = Sel_none; /* don't loop in selection_paste () */ + selection_paste (display->root, XA_CUT_BUFFER0, false); } int 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; @@ -3387,7 +3430,7 @@ else if (selection.clicks == 3) { #if ENABLE_FRILLS - if ((options & Opt_tripleclickwords)) + if (options & Opt_tripleclickwords) { int end_row; @@ -3415,6 +3458,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++; } } @@ -3504,6 +3556,7 @@ rxvt_term::selection_send (const XSelectionRequestEvent &rq) { XSelectionEvent ev; + dDisp; ev.type = SelectionNotify; ev.property = None; @@ -3527,7 +3580,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; @@ -3540,7 +3593,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; } @@ -3608,7 +3661,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 { @@ -3618,7 +3671,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; @@ -3627,7 +3680,7 @@ XFree (ct.value); } - XSendEvent (display->display, rq.requestor, False, 0L, (XEvent *)&ev); + XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev); } /* ------------------------------------------------------------------------- * @@ -3757,6 +3810,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)