--- rxvt-unicode/src/screen.C 2006/02/18 15:44:26 1.261 +++ rxvt-unicode/src/screen.C 2007/12/11 03:30:50 1.285 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*--------------------------------------* +/*---------------------------------------------------------------------------* * File: screen.C *---------------------------------------------------------------------------* * @@ -28,13 +28,11 @@ #include "rxvt.h" /* NECESSARY */ #include "rxvtperl.h" /* NECESSARY */ -#include /* get the typedef for CARD32 */ - #include #include "salloc.C" // HACK, should be a seperate compile! -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; @@ -49,7 +47,7 @@ * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * * ------------------------------------------------------------------------- */ #define ZERO_SCROLLBACK() \ - if (OPTION (Opt_scrollTtyOutput)) \ + if (option (Opt_scrollTtyOutput)) \ view_start = 0 #define CLEAR_SELECTION() \ selection.beg.row = selection.beg.col \ @@ -163,6 +161,7 @@ scr_overlay_off (); #endif + rvideo_mode = false; view_start = 0; num_scr = 0; @@ -239,7 +238,6 @@ selection.op = SELECTION_CLEAR; selection.screen = PRIMARY; selection.clicks = 0; - rvideo_state = rvideo_mode = false; } else { @@ -278,7 +276,7 @@ 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 + top_row , prev_total_rows); int q = total_rows; // rewrapped row @@ -332,7 +330,7 @@ // see below for cursor adjustment rationale if (p == ocur.row) screen.cur.row = q - (total_rows - nrow); - + // fill a single destination line while (lofs < llen && qcol < ncol) { @@ -368,7 +366,7 @@ term_start = total_rows - nrow; top_row = q - term_start; - + // make sure all terminal lines exist while (top_row > 0) scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE); @@ -376,7 +374,7 @@ 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)]; @@ -409,9 +407,9 @@ prev_nrow = nrow; prev_ncol = ncol; - tabs = (char *)rxvt_malloc (ncol * sizeof (char)); + tabs = (char *)rxvt_malloc (ncol); - for (int col = ncol; col--; ) + for (int col = ncol; --col; ) tabs [col] = col % TABSIZE == 0; if (current_screen != PRIMARY) @@ -512,7 +510,7 @@ void rxvt_term::scr_swap_screen () { - if (!OPTION (Opt_secondaryScreen)) + if (!option (Opt_secondaryScreen)) return; for (int i = prev_nrow; i--; ) @@ -544,7 +542,7 @@ int i = current_screen; current_screen = scrn; scrn = i; #if NSCREENS - if (OPTION (Opt_secondaryScreen)) + if (option (Opt_secondaryScreen)) { num_scr = 0; @@ -557,7 +555,7 @@ } else #endif - if (OPTION (Opt_secondaryScroll)) + if (option (Opt_secondaryScroll)) scr_scroll_text (0, prev_nrow - 1, prev_nrow); } @@ -626,7 +624,7 @@ if (count > 0 && row1 == 0 - && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll))) + && (current_screen == PRIMARY || option (Opt_secondaryScroll))) { top_row = max (top_row - count, -saveLines); @@ -668,7 +666,7 @@ ::swap (l1, l2); l2.touch (); } - + // move and/or clear selection, if any if (selection.op && current_screen == selection.screen) { @@ -686,7 +684,7 @@ } // finally move the view window, if desired - if (OPTION (Opt_scrollWithBuffer) + if (option (Opt_scrollWithBuffer) && view_start != 0 && view_start != -saveLines) scr_page (UP, count); @@ -714,7 +712,7 @@ selection.beg.row -= count; selection.end.row -= count; selection.mark.row -= count; - + selection_check (0); } } @@ -836,7 +834,7 @@ if (screen.flags & Screen_WrapNext) { scr_do_wrap (); - + line->l = ncol; line->is_longer (1); @@ -1064,7 +1062,7 @@ if (!--count) break; } - else + else ht &= l.t[i] == ' ' && RS_SAME (l.r[i], base_rend); @@ -1073,7 +1071,7 @@ // store horizontal tab commands as characters inside the text // buffer so they can be selected and pasted. - if (ht && OPTION (Opt_pastableTabs)) + if (ht && option (Opt_pastableTabs)) { base_rend = SET_FONT (base_rend, 0); @@ -1190,7 +1188,8 @@ else { if (screen.flags & Screen_Relative) - { /* relative origin mode */ + { + /* relative origin mode */ screen.cur.row = row + screen.tscroll; min_it (screen.cur.row, screen.bscroll); } @@ -1476,7 +1475,8 @@ || (selection.end.col + count >= ncol)) CLEAR_SELECTION (); else - { /* shift selection */ + { + /* shift selection */ selection.beg.col += count; selection.mark.col += count; /* XXX: yes? */ selection.end.col += count; @@ -1625,7 +1625,7 @@ rxvt_term::scr_set_tab (int mode) NOTHROW { if (mode < 0) - memset (tabs, 0, ncol * sizeof (char)); + memset (tabs, 0, ncol); else if (screen.cur.col < ncol) tabs [screen.cur.col] = !!mode; } @@ -1650,12 +1650,9 @@ rvideo_state = on; ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); -#if XPM_BACKGROUND +#ifdef HAVE_BG_PIXMAP if (bgPixmap.pixmap == None) #endif -#if TRANSPARENT - if (!OPTION (Opt_transparent) || am_transparent == 0) -#endif XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); XGCValues gcvalue; @@ -1808,7 +1805,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); @@ -1873,7 +1870,7 @@ #ifndef NO_BELL void -rxvt_term::bell_cb (time_watcher &w) +rxvt_term::bell_cb (ev::timer &w, int revents) { rvideo_bell = false; scr_rvideo_mode (rvideo_mode); @@ -1888,22 +1885,32 @@ # ifndef NO_MAPALERT # ifdef MAPALERT_OPTION - if (OPTION (Opt_mapAlert)) + if (option (Opt_mapAlert)) # endif XMapWindow (dpy, parent[0]); # endif - if (OPTION (Opt_visualBell)) +# if ENABLE_FRILLS + if (option (Opt_urgentOnBell)) + { + if (XWMHints *h = XGetWMHints(dpy, parent[0])) + { + h->flags |= XUrgencyHint; + XSetWMHints (dpy, parent[0], h); + } + } +# endif + + if (option (Opt_visualBell)) { rvideo_bell = true; scr_rvideo_mode (rvideo_mode); display->flush (); - bell_ev.start (NOW + VISUAL_BELL_DURATION); + bell_ev.start (VISUAL_BELL_DURATION); } else XBell (dpy, 0); - #endif } @@ -1980,6 +1987,8 @@ rend_t cc1; /* store colours at cursor position (s) */ #endif rend_t *crp; // cursor rendition pointer + rend_t ccol1, /* Cursor colour */ + ccol2; /* Cursor colour2 */ want_refresh = 0; /* screen is current */ @@ -1992,12 +2001,9 @@ have_bg = 0; refresh_count = 0; -#if XPM_BACKGROUND +#ifdef HAVE_BG_PIXMAP have_bg |= bgPixmap.pixmap != None; #endif -#if TRANSPARENT - have_bg |= OPTION (Opt_transparent) && am_transparent; -#endif ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ /* @@ -2010,8 +2016,6 @@ */ { unsigned char setoldcursor; - rend_t ccol1, /* Cursor colour */ - ccol2; /* Cursor colour2 */ showcursor = (screen.flags & Screen_VisibleCursor); #ifdef CURSOR_BLINK @@ -2028,35 +2032,38 @@ crp = &ROW(screen.cur.row).r[col]; - if (showcursor && focus) - { - if (OPTION (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 + cc1 = *crp & (RS_fgMask | RS_bgMask); + if (ISSET_PIXCOLOR (Color_cursor)) + ccol1 = Color_cursor; + else +#endif #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol1 = fgcolor_of (rstyle); + ccol1 = fgcolor_of (rstyle); #else - ccol1 = Color_fg; + ccol1 = Color_fg; +#endif + +#ifndef NO_CURSORCOLOR + if (ISSET_PIXCOLOR (Color_cursor2)) + ccol2 = Color_cursor2; + else #endif - if (ISSET_PIXCOLOR (Color_cursor2)) - ccol2 = Color_cursor2; - else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol2 = bgcolor_of (rstyle); + ccol2 = bgcolor_of (rstyle); #else - ccol2 = Color_bg; + ccol2 = Color_bg; #endif + + if (showcursor && focus) + { + if (option (Opt_cursorUnderline)) + *crp ^= RS_Uline; + else + { + *crp ^= RS_RVid; *crp = SET_FGCOLOR (*crp, ccol1); *crp = SET_BGCOLOR (*crp, ccol2); -#endif } } } @@ -2255,24 +2262,6 @@ // 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 - // "careful" (too wide) character handling - - // 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 -= fwidth; - - // force redraw after "careful" characters to avoid pixel droppings - for (int i = 0; srp[col + i] & RS_Careful && col + i < ncol - 1; i++) - drp[col + i + 1] = srp[col + i + 1] ^ RS_redraw; - - // force redraw before "careful" characters to avoid pixel droppings - for (int i = 0; srp[text - stp - i] & RS_Careful && text - i > stp; i++) - drp[text - stp - i - 1] = srp[text - stp - i - 1] ^ RS_redraw; -#endif - bool invert = rend & RS_RVid; #ifndef NO_BOLD_UNDERLINE_REVERSE @@ -2298,18 +2287,29 @@ # endif } - if (rend & RS_Uline && ISSET_PIXCOLOR (Color_UL)) + if (rend & RS_Uline && fore == Color_fg && ISSET_PIXCOLOR (Color_UL)) fore = Color_UL; #endif if (invert) { - ::swap (fore, back); +#ifdef OPTION_HC + if ((showcursor && row == screen.cur.row && text - stp == screen.cur.col) + || !ISSET_PIXCOLOR (Color_HC)) +#endif + /* invert the column if no highlightColor is set or it is the + * current cursor column */ + ::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; @@ -2321,15 +2321,33 @@ #ifdef TEXT_BLINK if (rend & RS_Blink && (back == Color_bg || fore == Color_bg)) { - if (!text_blink_ev.active) + if (!ev_is_active (&text_blink_ev)) { - text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); + text_blink_ev.start (TEXT_BLINK_INTERVAL, TEXT_BLINK_INTERVAL); hidden_text = 0; } else if (hidden_text) fore = back; } #endif + +#if ENABLE_STYLES + // "careful" (too wide) character handling + + // 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 -= fwidth; + + // force redraw after "careful" characters to avoid pixel droppings + for (int i = 0; srp[col + i] & RS_Careful && col + i < ncol - 1; i++) + drp[col + i + 1] = srp[col + i + 1] ^ RS_redraw; + + // force redraw before "careful" characters to avoid pixel droppings + for (int i = 0; srp[text - stp - i] & RS_Careful && text - i > stp; i++) + drp[text - stp - i - 1] = srp[text - stp - i - 1] ^ RS_redraw; +#endif } /* @@ -2337,16 +2355,14 @@ */ rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; - if (back == fore) - font->clear_rect (*drawable, xpixel, ypixel, fwidth * count, fheight, back); - else if (back == Color_bg && have_bg) + if (have_bg && back == Color_bg) { // this is very ugly, maybe push it into ->draw? for (i = 0; i < count; i++) /* don't draw empty strings */ if (text[i] != ' ') { - font->draw (*drawable, xpixel, ypixel, text, count, fore, -1); + font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_transparent); goto did_clear; } @@ -2384,7 +2400,7 @@ { if (focus) { - if (OPTION (Opt_cursorUnderline)) + if (option (Opt_cursorUnderline)) *crp ^= RS_Uline; else { @@ -2409,7 +2425,9 @@ #ifndef NO_CURSORCOLOR if (ISSET_PIXCOLOR (Color_cursor)) XSetForeground (dpy, gc, pix_colors[Color_cursor]); + else #endif + XSetForeground (dpy, gc, pix_colors[ccol1]); XDrawRectangle (dpy, drawBuffer, gc, Col2Pixel (col), @@ -2456,31 +2474,25 @@ void rxvt_term::scr_recolour () NOTHROW { - if (1 -#if TRANSPARENT - && !am_transparent -#endif -#if XPM_BACKGROUND - && !bgPixmap.pixmap -#endif - ) - { - XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]); - XClearWindow (dpy, parent[0]); - XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); -#if HAVE_SCROLLBARS - if (scrollBar.win) - { - XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); - scrollBar.setIdle (); - scrollbar_show (0); - } -#endif - } - +#ifdef HAVE_BG_PIXMAP + bgPixmap.apply (); +#else + XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]); + XClearWindow (dpy, parent[0]); + XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); +# if HAVE_SCROLLBARS + if (scrollBar.win) + { + XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); + scrollBar.setIdle (); + scrollbar_show (0); + } +# endif scr_clear (); scr_touch (true); want_refresh = 1; +#endif + } /* ------------------------------------------------------------------------- */ @@ -2725,7 +2737,7 @@ selection_wait = Sel_incr; incr_buf_fill = 0; - incr_ev.start (NOW + 10); + incr_ev.start (10); goto bailout; } @@ -2744,7 +2756,7 @@ incr_buf_size = 0; incr_ev.stop (); } - else + else { if (selection_wait == Sel_normal && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion @@ -2761,7 +2773,7 @@ } else if (selection_wait == Sel_incr) { - incr_ev.start (NOW + 10); + incr_ev.start (10); while (incr_buf_fill + ct.nitems > incr_buf_size) { @@ -2811,7 +2823,7 @@ } void -rxvt_term::incr_cb (time_watcher &w) NOTHROW +rxvt_term::incr_cb (ev::timer &w, int revents) NOTHROW { selection_wait = Sel_none; @@ -2832,7 +2844,7 @@ /* ------------------------------------------------------------------------- */ /* - * Request the current selection: + * Request the current selection: * Order: > internal selection if available * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+) * > CUT_BUFFER0 @@ -2844,7 +2856,8 @@ rxvt_term::selection_request (Time tm, int selnum) NOTHROW { if (selection.text && selnum == Sel_Primary) - { /* internal selection */ + { + /* internal selection */ char *str = rxvt_wcstombs (selection.text, selection.len); paste (str, strlen (str)); free (str); @@ -3120,9 +3133,10 @@ while (selection.mark.col > 0 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) --selection.mark.col; - + if (selection.op) - { /* clear the old selection */ + { + /* clear the old selection */ selection.beg.row = selection.end.row = selection.mark.row; selection.beg.col = selection.end.col = selection.mark.col; } @@ -3321,7 +3335,8 @@ * time of the most recent button3 press */ if (button3 && buttonpress) - { /* button3 press */ + { + /* button3 press */ /* * first determine which edge of the selection we are closest to */ @@ -3349,7 +3364,8 @@ } } else - { /* button1 drag or button3 drag */ + { + /* button1 drag or button3 drag */ if (ROWCOL_IS_AFTER (selection.mark, pos)) { if (selection.mark.row == selection.end.row @@ -3402,7 +3418,7 @@ else if (selection.clicks == 3) { #if ENABLE_FRILLS - if (OPTION (Opt_tripleclickwords)) + if (option (Opt_tripleclickwords)) { selection_delimit_word (UP, &selection.beg, &selection.beg); @@ -3440,7 +3456,8 @@ } if (button3 && buttonpress) - { /* mark may need to be changed */ + { + /* mark may need to be changed */ if (closeto == LEFT) { selection.mark.row = selection.end.row; @@ -3649,22 +3666,6 @@ XSendEvent (dpy, rq.requestor, False, 0L, (XEvent *)&ev); } - -/* ------------------------------------------------------------------------- * - * MOUSE ROUTINES * - * ------------------------------------------------------------------------- */ - -/* - * return col/row values corresponding to x/y pixel values - */ -void -rxvt_term::pixel_position (int *x, int *y) NOTHROW -{ - *x = Pixel2Col (*x); - /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */ - *y = Pixel2Row (*y); - /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */ -} /* ------------------------------------------------------------------------- */ #ifdef USE_XIM