--- rxvt-unicode/src/screen.C 2005/12/22 19:39:29 1.193 +++ rxvt-unicode/src/screen.C 2006/01/11 05:14:26 1.222 @@ -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,6 +147,9 @@ 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; } /* ------------------------------------------------------------------------- * @@ -190,7 +196,6 @@ { /* * 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 */ term_start = 0; @@ -198,10 +203,9 @@ 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--; ) { @@ -256,7 +260,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--; ) @@ -271,7 +274,8 @@ 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); @@ -291,7 +295,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; @@ -319,7 +322,8 @@ { qline = row_buf + qrow; lalloc (*qline); - qline->set_is_longer (); + qline->l = ncol; + qline->is_longer (1); int qcol = 0; @@ -353,7 +357,8 @@ } } - qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1; + 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); @@ -364,7 +369,6 @@ // make sure all terminal lines exist while (nsaved < 0) scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); - } else { @@ -412,6 +416,8 @@ tabs [col] = col % TABSIZE == 0; tt_winch (); + + HOOK_INVOKE ((this, HOOK_RESET, DT_END)); } /* ------------------------------------------------------------------------- */ @@ -427,7 +433,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 @@ -525,7 +530,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; @@ -539,7 +544,7 @@ } else #endif - if (options & Opt_secondaryScroll) + if (OPTION (Opt_secondaryScroll)) scr_scroll_text (0, prev_nrow - 1, prev_nrow); return scrn; @@ -569,7 +574,7 @@ void rxvt_term::scr_color (unsigned int color, int fgbg) { - if (color > maxTermCOLOR) + if (!IN_RANGE_INC (color, minTermCOLOR, maxTermCOLOR)) color = fgbg; if (fgbg == Color_fg) @@ -611,9 +616,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) @@ -622,13 +630,28 @@ 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); + { + // basically thi is a slightly optimized scr_blank_screen_mem + // it is worth the effort on slower machines + line_t &l = ROW(row2 - i); + + scr_blank_line (l, 0, l.l, rstyle); + + l.l = 0; + l.f = 0; + } - if ((options & Opt_scrollWithBuffer) + if (OPTION (Opt_scrollWithBuffer) && view_start != 0 && view_start != saveLines) scr_page (UP, count); @@ -637,20 +660,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; @@ -668,6 +688,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); @@ -688,35 +710,35 @@ * 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); #endif @@ -728,13 +750,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; @@ -748,8 +769,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; @@ -776,7 +796,8 @@ if (screen.flags & Screen_WrapNext) { - line->set_is_longer (); + max_it (line->l, ncol); + line->is_longer (1); scr_do_wrap (); @@ -794,7 +815,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 @@ -856,7 +877,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 = ' '; @@ -864,16 +885,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; @@ -885,11 +908,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 { @@ -898,31 +925,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) @@ -934,8 +961,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); @@ -995,6 +1021,7 @@ if (tabs[i]) { x = i; + if (!--count) break; } @@ -1007,12 +1034,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; @@ -1076,8 +1102,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); @@ -1179,6 +1207,9 @@ line_t &line = ROW(screen.cur.row); + line.touch (); + line.is_longer (0); + switch (mode) { case 0: /* erase to end of line */ @@ -1273,7 +1304,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]; @@ -1282,8 +1313,7 @@ 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); } } @@ -1326,7 +1356,8 @@ for (int j = ncol; j--; ) *r1++ = fs; - line.l = ncol; /* make the `E's selectable */ + line.is_longer (0); + line.touch (ncol); } } @@ -1385,6 +1416,9 @@ line_t *line = &ROW(row); + line->touch (); + line->is_longer (0); + switch (insdel) { case INSERT: @@ -1394,11 +1428,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)) @@ -1421,6 +1451,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; @@ -1433,12 +1465,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)) @@ -1560,7 +1588,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; } /* ------------------------------------------------------------------------- */ @@ -1582,7 +1610,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]); @@ -1617,7 +1645,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; @@ -1634,6 +1663,7 @@ case 'K': /* German character set */ break; } +#endif } /* ------------------------------------------------------------------------- */ @@ -1810,11 +1840,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; } /* ------------------------------------------------------------------------- */ @@ -1825,14 +1857,15 @@ # 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 */ + display->flush (); rxvt_usleep (VISUAL_BELL_DURATION); scr_rvideo_mode (!rvideo); /* refresh also done */ } @@ -1931,7 +1964,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? */ @@ -1965,7 +1998,7 @@ if (showcursor && focus) { - if (options & Opt_cursorUnderline) + if (OPTION (Opt_cursorUnderline)) *crp ^= RS_Uline; else { @@ -1977,7 +2010,7 @@ ccol1 = Color_cursor; else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol1 = GET_FGCOLOR (rstyle); + ccol1 = fgcolor_of (rstyle); #else ccol1 = Color_fg; #endif @@ -1985,7 +2018,7 @@ ccol2 = Color_cursor2; else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol2 = GET_BGCOLOR (rstyle); + ccol2 = bgcolor_of (rstyle); #else ccol2 = Color_bg; #endif @@ -2028,6 +2061,7 @@ } } + HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); #if ENABLE_OVERLAY scr_swap_overlay (); #endif @@ -2087,7 +2121,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; @@ -2176,10 +2210,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 @@ -2300,6 +2334,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 @@ -2308,7 +2343,7 @@ { if (focus) { - if (options & Opt_cursorUnderline) + if (OPTION (Opt_cursorUnderline)) *crp ^= RS_Uline; else { @@ -2348,19 +2383,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])); } @@ -2422,6 +2456,54 @@ 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 () @@ -2430,38 +2512,16 @@ && current_screen == selection.screen && 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++) - for (rend_t *srp = ROW(row).r, col = selection.beg.col; col < selection.end.col; col++) - srp[col] ^= RS_RVid; - } + 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); } } @@ -2532,7 +2592,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++) @@ -2686,7 +2746,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 @@ -2695,12 +2755,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); @@ -2748,7 +2808,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; } @@ -2850,6 +2910,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)); @@ -2871,14 +2934,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) @@ -2904,8 +2972,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) @@ -2925,11 +3005,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; @@ -2940,8 +3034,6 @@ XFree (ct.value); } #endif - - selection_time = tm; } /* ------------------------------------------------------------------------- */ @@ -3073,7 +3165,6 @@ break; } -Old_Word_Selection_You_Die: if (dirn == DN) col++; /* put us on one past the end */ @@ -3260,13 +3351,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); @@ -3337,9 +3431,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; } @@ -3548,7 +3641,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; @@ -3665,8 +3758,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--; ) {