--- rxvt-unicode/src/screen.C 2010/01/06 17:52:43 1.331 +++ rxvt-unicode/src/screen.C 2010/10/15 11:07:45 1.351 @@ -30,9 +30,10 @@ #include -#include "salloc.C" // HACK, should be a seperate compile! +#include "salloc.C" // HACK, should be a separate compile! -static inline void fill_text (text_t *start, text_t value, int len) +static inline void +fill_text (text_t *start, text_t value, int len) { while (len--) *start++ = value; @@ -233,6 +234,8 @@ selection.op = SELECTION_CLEAR; selection.screen = PRIMARY; selection.clicks = 0; + selection.clip_text = NULL; + selection.clip_len = 0; } else { @@ -546,7 +549,7 @@ selection_check (2); /* check for boundary cross */ - int i = current_screen; current_screen = scrn; scrn = i; + current_screen = scrn; #if NSCREENS if (option (Opt_secondaryScreen)) @@ -897,6 +900,22 @@ # endif #endif + rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); + + // if the character doesn't fit into the remaining columns... + if (expect_false (screen.cur.col > ncol - width && ncol >= width)) + { + if (screen.flags & Screen_Autowrap) + { + // ... artificially enlargen the previous one + c = NOCHAR; + // and try the same character next loop iteration + --str; + } + else + screen.cur.col = ncol - width; + } + // nuke the character at this position, if required if (expect_false ( line->t[screen.cur.col] == NOCHAR @@ -905,17 +924,6 @@ )) scr_kill_char (*line, screen.cur.col); - rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); - - // if the character doesn't fit into the remaining columns... - if (expect_false (screen.cur.col > ncol - width && ncol >= width)) - { - // ... artificially enlargen the previous one - c = NOCHAR; - // and try the same character next loop iteration - --str; - } - line->touch (); do @@ -1020,6 +1028,8 @@ #endif } } + else if (screen.flags & Screen_WrapNext) + screen.flags &= ~Screen_WrapNext; else scr_gotorc (0, -1, RELATIVE); } @@ -1335,16 +1345,13 @@ min_it (num, nrow - row); - // TODO: the code below does not work when view_start != 0 - // the workaround is to disable the clear and use a normal refresh - // when view_start != 0. mysterious. - if (rstyle & (RS_RVid | RS_Uline)) + if (rstyle & (RS_Blink | RS_RVid | RS_Uline)) ren = (rend_t) ~RS_None; else if (GET_BASEBG (rstyle) == Color_bg) { ren = DEFAULT_RSTYLE; - if (mapped && !view_start) + if (mapped) XClearArea (dpy, vt, 0, Row2Pixel (row - view_start), (unsigned int)width, (unsigned int)Height2Pixel (num), False); @@ -1353,7 +1360,7 @@ { ren = rstyle & (RS_fgMask | RS_bgMask); - if (mapped && !view_start) + if (mapped) { gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; XChangeGC (dpy, gc, GCForeground, &gcvalue); @@ -1370,8 +1377,8 @@ { scr_blank_screen_mem (ROW(row), rstyle); - if (!view_start) - scr_blank_line (drawn_buf [row], 0, ncol, ren); + if (row - view_start < nrow) + scr_blank_line (drawn_buf [row - view_start], 0, ncol, ren); } } @@ -1834,7 +1841,7 @@ min_it (rc[i].col, ncol - 1); min_it (rc[i].row, nrow - 1); } -// TODO: this line somehow causes segfault if scr_expose() is called just after resize + 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); @@ -2085,7 +2092,7 @@ ccol2 = Color_bg; #endif - if (showcursor && focus) + if (focus) { if (option (Opt_cursorUnderline)) *crp ^= RS_Uline; @@ -2231,7 +2238,7 @@ while (expect_false (stp[col] == NOCHAR && col > 0)) --col; - rend_t rend = srp[col]; /* screen rendition (target rendtion) */ + rend_t rend = srp[col]; /* screen rendition (target rendition) */ text_t *text = stp + col; int count = 1; @@ -2286,7 +2293,7 @@ int back = bgcolor_of (rend); // desired background // only do special processing if any attributes are set, which is unlikely - if (expect_false (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))) + if (expect_false (rend & (RS_baseattrMask | RS_Careful | RS_Sel))) { bool invert = rend & RS_RVid; @@ -2315,25 +2322,31 @@ fore = Color_UL; #endif - if (invert) - { #ifdef OPTION_HC - if ((showcursor && row == screen.cur.row && text - stp == screen.cur.col) - || !ISSET_PIXCOLOR (Color_HC)) + if (rend & RS_Sel) + { + /* invert the column if no highlightColor is set or it is the + * current cursor column */ + if (!(showcursor && row == screen.cur.row && text - stp == screen.cur.col) + && ISSET_PIXCOLOR (Color_HC)) + { + if (ISSET_PIXCOLOR (Color_HTC)) + fore = Color_HTC; + // if invert is 0 reverse video is set so we use bg color as fg color + else if (!invert) + fore = back; + + back = Color_HC; + invert = 0; + } + } #endif - /* invert the column if no highlightColor is set or it is the - * current cursor column */ + + if (invert) + { ::swap (fore, back); -#ifdef OPTION_HC - else if (ISSET_PIXCOLOR (Color_HC)) - back = Color_HC; -#endif #ifndef NO_BOLD_UNDERLINE_REVERSE -# ifndef OPTION_HC - if (ISSET_PIXCOLOR (Color_RV)) - back = Color_RV; -# endif if (fore == back) { fore = Color_bg; @@ -2596,12 +2609,12 @@ if (selection.rect) scr_xor_rect (selection.beg.row, selection.beg.col, selection.end.row, selection.end.col, - RS_RVid, RS_RVid | RS_Uline); + RS_Sel | RS_RVid, RS_Sel | RS_RVid | RS_Uline); else #endif scr_xor_span (selection.beg.row, selection.beg.col, selection.end.row, selection.end.col, - RS_RVid); + RS_Sel | RS_RVid); } } @@ -2672,7 +2685,7 @@ * Paste a selection direct to the command fd */ void -rxvt_term::paste (char *data, unsigned int len) NOTHROW +rxvt_term::tt_paste (char *data, unsigned int len) NOTHROW { /* convert normal newline chars into common keyboard Return key sequence */ for (unsigned int i = 0; i < len; i++) @@ -2688,6 +2701,15 @@ tt_printf ("\e[201~"); } +void +rxvt_term::paste (char *data, unsigned int len) NOTHROW +{ + if (HOOK_INVOKE ((this, HOOK_TT_PASTE, DT_STR_LEN, data, len, DT_END))) + return; + + tt_paste (data, len); +} + /* ------------------------------------------------------------------------- */ /* * Respond to a notification that a primary selection has been sent @@ -2904,11 +2926,11 @@ #if X_HAVE_UTF8_STRING selection_type = Sel_UTF8String; if (selection_request_other (xa[XA_UTF8_STRING], selnum)) - return; + return; #else selection_type = Sel_CompoundText; if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum)) - return; + return; #endif } @@ -2946,16 +2968,28 @@ * EXT: SelectionClear */ void -rxvt_term::selection_clear () NOTHROW +rxvt_term::selection_clear (bool clipboard) NOTHROW { - want_refresh = 1; - free (selection.text); - selection.text = NULL; - selection.len = 0; - CLEAR_SELECTION (); + if (!clipboard) + { + want_refresh = 1; + free (selection.text); + selection.text = NULL; + selection.len = 0; + CLEAR_SELECTION (); - if (display->selection_owner == this) - display->selection_owner = 0; + if (display->selection_owner == this) + display->selection_owner = 0; + } + else + { + free (selection.clip_text); + selection.clip_text = NULL; + selection.clip_len = 0; + + if (display->clipboard_owner == this) + display->clipboard_owner = 0; + } } /* ------------------------------------------------------------------------- */ @@ -3091,19 +3125,30 @@ } bool -rxvt_term::selection_grab (Time tm) NOTHROW +rxvt_term::selection_grab (Time tm, bool clipboard) NOTHROW { - selection_time = tm; + Atom sel; + + if (!clipboard) + { + selection_time = tm; + sel = XA_PRIMARY; + } + else + { + clipboard_time = tm; + sel = xa[XA_CLIPBOARD]; + } - XSetSelectionOwner (dpy, XA_PRIMARY, vt, tm); - if (XGetSelectionOwner (dpy, XA_PRIMARY) == vt) + XSetSelectionOwner (dpy, sel, vt, tm); + if (XGetSelectionOwner (dpy, sel) == vt) { - display->set_selection_owner (this); + display->set_selection_owner (this, clipboard); return true; } else { - selection_clear (); + selection_clear (clipboard); return false; } @@ -3608,12 +3653,18 @@ /* TODO: Handle MULTIPLE */ } #endif - else if (rq.target == xa[XA_TIMESTAMP] && selection.text) + else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == XA_PRIMARY && selection.text) { XChangeProperty (dpy, rq.requestor, rq.property, rq.target, 32, PropModeReplace, (unsigned char *)&selection_time, 1); ev.property = rq.property; } + else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == xa[XA_CLIPBOARD] && selection.clip_text) + { + XChangeProperty (dpy, rq.requestor, rq.property, rq.target, + 32, PropModeReplace, (unsigned char *)&clipboard_time, 1); + ev.property = rq.property; + } else if (rq.target == XA_STRING || rq.target == xa[XA_TEXT] || rq.target == xa[XA_COMPOUND_TEXT] @@ -3654,11 +3705,16 @@ style = enc_compound_text; } - if (selection.text) + if (rq.selection == XA_PRIMARY && selection.text) { cl = selection.text; selectlen = selection.len; } + else if (rq.selection == xa[XA_CLIPBOARD] && selection.clip_text) + { + cl = selection.clip_text; + selectlen = selection.clip_len; + } else { cl = L"";