--- rxvt-unicode/src/screen.C 2003/12/17 09:00:35 1.8 +++ rxvt-unicode/src/screen.C 2004/01/28 23:40:50 1.18 @@ -1,7 +1,6 @@ /*--------------------------------*-C-*--------------------------------------* * File: screen.c *---------------------------------------------------------------------------* - * $Id: screen.C,v 1.8 2003/12/17 09:00:35 pcg Exp $ * * Copyright (c) 1997-2001 Geoff Wing * @@ -91,25 +90,25 @@ * CLEAR_CHARS: clear chars starting from pixel position * ERASE_ROWS : set rows starting from row to the foreground colour */ -#define drawBuffer (R->TermWin.vt) +#define drawBuffer TermWin.vt #define CLEAR_ROWS(row, num) \ - if (R->TermWin.mapped) \ - XClearArea(R->Xdisplay, drawBuffer, R->TermWin.int_bwidth, \ - Row2Pixel(row), (unsigned int)R->TermWin.width, \ - (unsigned int)Height2Pixel(num), False) + if (TermWin.mapped) \ + XClearArea (Xdisplay, drawBuffer, TermWin.int_bwidth, \ + Row2Pixel(row), (unsigned int)TermWin.width, \ + (unsigned int)Height2Pixel(num), False) #define CLEAR_CHARS(x, y, num) \ - if (R->TermWin.mapped) \ - XClearArea(R->Xdisplay, drawBuffer, x, y, \ - (unsigned int)Width2Pixel(num), \ - (unsigned int)Height2Pixel(1), False) + if (TermWin.mapped) \ + XClearArea (Xdisplay, drawBuffer, x, y, \ + (unsigned int)Width2Pixel(num), \ + (unsigned int)Height2Pixel(1), False) #define ERASE_ROWS(row, num) \ - XFillRectangle(R->Xdisplay, drawBuffer, R->TermWin.gc, \ - R->TermWin.int_bwidth, Row2Pixel(row), \ - (unsigned int)R->TermWin.width, \ - (unsigned int)Height2Pixel(num)) + XFillRectangle (Xdisplay, drawBuffer, TermWin.gc, \ + TermWin.int_bwidth, Row2Pixel(row), \ + (unsigned int)TermWin.width, \ + (unsigned int)Height2Pixel(num)) /* ------------------------------------------------------------------------- * * SCREEN `COMMON' ROUTINES * @@ -229,7 +228,7 @@ swap.cur.row = swap.cur.col = 0; swap.charset = 0; current_screen = SECONDARY; - rxvt_scr_cursor(aR_ SAVE); + rxvt_scr_cursor (this, SAVE); current_screen = PRIMARY; #endif @@ -291,7 +290,7 @@ /* add rows */ scr_reset_realloc (); /* realloc _first_ */ - TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this + TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this k = min (TermWin.nscrolled, nrow - prev_nrow); @@ -449,8 +448,8 @@ } #endif - delete talloc; - delete ralloc; + delete talloc; talloc = 0; + delete ralloc; ralloc = 0; free (screen.text); free (screen.tlen); @@ -487,8 +486,8 @@ R->prev_nrow = R->prev_ncol = 0; R->scr_reset (); - rxvt_scr_clear (aR); - rxvt_scr_refresh (aR_ SLOW_REFRESH); + R->scr_clear (); + R->scr_refresh (SLOW_REFRESH); #ifdef RXVT_GRAPHICS rxvt_Gr_reset (aR); #endif @@ -901,39 +900,35 @@ } rend_t rend = SET_FONT (R->rstyle, R->TermWin.fontset->find_font (c)); + // rely on wcwidth to tell us the character width, at least for non-ascii + int width = c <= 128 ? 1 : wcwidth (c); - stp[R->screen.cur.col] = c; - srp[R->screen.cur.col] = rend; - - if (c > 255) - { - // rely on wcwidth to tell us the character width, at least for non iso-8859-1 - int width = wcwidth (c); - - if (width > 1) - { - while (--width > 0 && R->screen.cur.col < last_col - 1) - { - - srp[R->screen.cur.col] |= RS_wide; + // width -1 characters (e.g. combining chars) are ignored currently. + if (width > 0) + do + { + stp[R->screen.cur.col] = c; + srp[R->screen.cur.col] = rend; - R->screen.cur.col++; - stp[R->screen.cur.col] = NOCHAR; - srp[R->screen.cur.col] = rend; - } - } - } + if (R->screen.cur.col < last_col - 1) + R->screen.cur.col++; + else + { + R->screen.tlen[row] = last_col; + if (R->screen.flags & Screen_Autowrap) + R->screen.flags |= Screen_WrapNext; + break; + } - if (R->screen.cur.col < last_col - 1) - R->screen.cur.col++; - else { - R->screen.tlen[row] = last_col; - if (R->screen.flags & Screen_Autowrap) - R->screen.flags |= Screen_WrapNext; - } + c = NOCHAR; + } + while (--width > 0); + else + 1; /* handle combining character etc. here. */ } + if (R->screen.tlen[row] != -1) /* XXX: think about this */ - MAX_IT(R->screen.tlen[row], R->screen.cur.col); + MAX_IT(R->screen.tlen[row], R->screen.cur.col); /* * If we wrote anywhere in the selected area, kill the selection @@ -1213,72 +1208,71 @@ * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J * XTERM_SEQ: Clear whole screen : ESC [ 2 J */ -/* EXTPROTO */ void -rxvt_scr_erase_screen(pR_ int mode) +rxvt_term::scr_erase_screen (int mode) { int num; int32_t row, row_offset; rend_t ren; XGCValues gcvalue; - R->want_refresh = 1; - D_SCREEN((stderr, "rxvt_scr_erase_screen(%d) at screen row: %d", mode, R->screen.cur.row)); - ZERO_SCROLLBACK(R); - row_offset = (int32_t)R->TermWin.saveLines; + want_refresh = 1; + D_SCREEN((stderr, "rxvt_scr_erase_screen(%d) at screen row: %d", mode, screen.cur.row)); + ZERO_SCROLLBACK(this); + row_offset = (int32_t)TermWin.saveLines; switch (mode) { case 0: /* erase to end of screen */ - rxvt_selection_check(aR_ 1); - rxvt_scr_erase_line(aR_ 0); - row = R->screen.cur.row + 1; /* possible OOB */ - num = R->TermWin.nrow - row; + rxvt_selection_check(this,1); + rxvt_scr_erase_line(this,0); + row = screen.cur.row + 1; /* possible OOB */ + num = TermWin.nrow - row; break; case 1: /* erase to beginning of screen */ - rxvt_selection_check(aR_ 3); - rxvt_scr_erase_line(aR_ 1); + rxvt_selection_check(this,3); + rxvt_scr_erase_line(this,1); row = 0; - num = R->screen.cur.row; + num = screen.cur.row; break; case 2: /* erase whole screen */ - rxvt_selection_check(aR_ 3); + rxvt_selection_check (this, 3); #ifdef RXVT_GRAPHICS - rxvt_Gr_ClearScreen(aR); + rxvt_Gr_ClearScreen (this); #endif row = 0; - num = R->TermWin.nrow; + num = TermWin.nrow; break; default: return; } - R->refresh_type |= REFRESH_BOUNDS; - if (R->selection.op && R->current_screen == R->selection.screen - && ((R->selection.beg.row >= row && R->selection.beg.row <= row + num) - || (R->selection.end.row >= row - && R->selection.end.row <= row + num))) - CLEAR_SELECTION(R); - if (row >= R->TermWin.nrow) /* Out Of Bounds */ + refresh_type |= REFRESH_BOUNDS; + if (selection.op && current_screen == selection.screen + && ((selection.beg.row >= row && selection.beg.row <= row + num) + || (selection.end.row >= row + && selection.end.row <= row + num))) + CLEAR_SELECTION (this); + if (row >= TermWin.nrow) /* Out Of Bounds */ return; - MIN_IT(num, (R->TermWin.nrow - row)); - if (R->rstyle & (RS_RVid | RS_Uline)) + MIN_IT(num, (TermWin.nrow - row)); + if (rstyle & (RS_RVid | RS_Uline)) ren = (rend_t) ~RS_None; - else if (GET_BASEBG(R->rstyle) == Color_bg) { + else if (GET_BASEBG(rstyle) == Color_bg) { ren = DEFAULT_RSTYLE; CLEAR_ROWS(row, num); } else { - ren = (R->rstyle & (RS_fgMask | RS_bgMask)); - gcvalue.foreground = R->PixColors[GET_BGCOLOR(R->rstyle)]; - XChangeGC(R->Xdisplay, R->TermWin.gc, GCForeground, &gcvalue); + ren = (rstyle & (RS_fgMask | RS_bgMask)); + gcvalue.foreground = PixColors[GET_BGCOLOR(rstyle)]; + XChangeGC(Xdisplay, TermWin.gc, GCForeground, &gcvalue); ERASE_ROWS(row, num); - gcvalue.foreground = R->PixColors[Color_fg]; - XChangeGC(R->Xdisplay, R->TermWin.gc, GCForeground, &gcvalue); + gcvalue.foreground = PixColors[Color_fg]; + XChangeGC(Xdisplay, TermWin.gc, GCForeground, &gcvalue); } for (; num--; row++) { - R->scr_blank_screen_mem (R->screen.text, R->screen.rend, - (unsigned int)(row + row_offset), R->rstyle); - R->screen.tlen[row + row_offset] = 0; - R->scr_blank_line (R->drawn_text[row], R->drawn_rend[row], - (unsigned int)R->TermWin.ncol, ren); + scr_blank_screen_mem (screen.text, screen.rend, + (unsigned int)(row + row_offset), rstyle); + screen.tlen[row + row_offset] = 0; + scr_blank_line (drawn_text[row], drawn_rend[row], + (unsigned int)TermWin.ncol, ren); } } @@ -1572,8 +1566,8 @@ gcvalue.background = R->PixColors[Color_bg]; XChangeGC(R->Xdisplay, R->TermWin.gc, GCBackground | GCForeground, &gcvalue); - rxvt_scr_clear(aR); - rxvt_scr_touch(aR_ True); + R->scr_clear (); + R->scr_touch (true); } } @@ -1653,27 +1647,6 @@ /* ------------------------------------------------------------------------- * - * GRAPHICS COLOURS * - * ------------------------------------------------------------------------- */ - -#ifdef RXVT_GRAPHICS -/* EXTPROTO */ -int -rxvt_scr_get_fgcolor(pR) -{ - return GET_FGCOLOR(R->rstyle); -} - -/* ------------------------------------------------------------------------- */ -/* EXTPROTO */ -int -rxvt_scr_get_bgcolor(pR) -{ - return GET_BGCOLOR(R->rstyle); -} -#endif - -/* ------------------------------------------------------------------------- * * MAJOR SCREEN MANIPULATION * * ------------------------------------------------------------------------- */ @@ -1686,55 +1659,54 @@ RC_COUNT }; -/* EXTPROTO */ void -rxvt_scr_expose(pR_ int x, int y, int width, int height, Bool refresh) +rxvt_term::scr_expose (int x, int y, int width, int height, bool refresh) { - int i; - row_col_t rc[RC_COUNT]; + int i; + row_col_t rc[RC_COUNT]; - if (R->drawn_text == NULL) /* sanity check */ - return; + if (drawn_text == NULL) /* sanity check */ + return; #ifdef DEBUG_STRICT - x = max(x, (int)R->TermWin.int_bwidth); - x = min(x, (int)R->TermWin.width); - y = max(y, (int)R->TermWin.int_bwidth); - y = min(y, (int)R->TermWin.height); + x = max(x, (int)TermWin.int_bwidth); + x = min(x, (int)TermWin.width); + y = max(y, (int)TermWin.int_bwidth); + y = min(y, (int)TermWin.height); #endif /* round down */ - rc[PART_BEG].col = Pixel2Col(x); - rc[PART_BEG].row = Pixel2Row(y); + rc[PART_BEG].col = Pixel2Col(x); + rc[PART_BEG].row = Pixel2Row(y); /* round up */ - rc[PART_END].col = Pixel2Width(x + width + R->TermWin.fwidth - 1); - rc[PART_END].row = Pixel2Row(y + height + R->TermWin.fheight - 1); + rc[PART_END].col = Pixel2Width(x + width + TermWin.fwidth - 1); + rc[PART_END].row = Pixel2Row(y + height + TermWin.fheight - 1); /* sanity checks */ - for (i = PART_BEG; i < RC_COUNT; i++) { - MIN_IT(rc[i].col, R->TermWin.ncol - 1); - MIN_IT(rc[i].row, R->TermWin.nrow - 1); + for (i = PART_BEG; i < RC_COUNT; i++) + { + MIN_IT(rc[i].col, TermWin.ncol - 1); + MIN_IT(rc[i].row, TermWin.nrow - 1); } - D_SCREEN((stderr, "rxvt_scr_expose(x:%d, y:%d, w:%d, h:%d) area (c:%d,r:%d)-(c:%d,r:%d)", x, y, width, height, rc[PART_BEG].col, rc[PART_BEG].row, rc[PART_END].col, rc[PART_END].row)); + D_SCREEN((stderr, "rxvt_scr_expose(x:%d, y:%d, w:%d, h:%d) area (c:%d,r:%d)-(c:%d,r:%d)", x, y, width, height, rc[PART_BEG].col, rc[PART_BEG].row, rc[PART_END].col, rc[PART_END].row)); - for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) - fill_text (&(R->drawn_text[i][rc[PART_BEG].col]), 0, - (rc[PART_END].col - rc[PART_BEG].col + 1)); + for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) + fill_text (&(drawn_text[i][rc[PART_BEG].col]), 0, + (rc[PART_END].col - rc[PART_BEG].col + 1)); - if (refresh) - rxvt_scr_refresh(aR_ SLOW_REFRESH | REFRESH_BOUNDS); + if (refresh) + scr_refresh (SLOW_REFRESH | REFRESH_BOUNDS); } /* ------------------------------------------------------------------------- */ /* * Refresh the entire screen */ -/* EXTPROTO */ void -rxvt_scr_touch(pR_ Bool refresh) +rxvt_term::scr_touch (bool refresh) { - rxvt_scr_expose(aR_ 0, 0, R->TermWin.width, R->TermWin.height, refresh); + scr_expose (0, 0, TermWin.width, TermWin.height, refresh); } /* ------------------------------------------------------------------------- */ @@ -1863,15 +1835,6 @@ * R->screen.text/R->screen.rend contain what the screen will change to. */ -#if defined (NO_BRIGHTCOLOR) || defined (VERYBOLD) -# define MONO_BOLD(x) ((x) & (RS_Bold|RS_Blink)) -# define MONO_BOLD_FG(x, fg) MONO_BOLD(x) -#else -# define MONO_BOLD(x) \ - (((x) & (RS_Bold | RS_fgMask)) == (RS_Bold | Color_fg)) -# define MONO_BOLD_FG(x, fg) (((x) & RS_Bold) && (fg) == Color_fg) -#endif - #define FONT_WIDTH(X, Y) \ (X)->per_char[(Y) - (X)->min_char_or_byte2].width #define FONT_RBEAR(X, Y) \ @@ -1881,20 +1844,14 @@ #define IS_FONT_CHAR(X, Y) \ ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2) -/* EXTPROTO */ void -rxvt_scr_refresh(pR_ unsigned char refresh_type) +rxvt_term::scr_refresh (unsigned char refresh_type) { unsigned char clearfirst, /* first character writes before cell */ clearlast, /* last character writes beyond cell */ must_clear, /* use draw_string not draw_image_string */ -#ifndef NO_BOLDFONT - bfont, /* we've changed font to bold font */ -#endif rvid, /* reverse video this position */ - wbyte, /* we're in multibyte */ showcursor; /* show the cursor */ - int fore, back; /* desired foreground/background */ int16_t col, row, /* column/row we're processing */ ocrow; /* old cursor row */ int cursorwidth; @@ -1906,62 +1863,57 @@ #endif rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ - char *buffer; /* local copy of R->buffer */ - if (refresh_type == NO_REFRESH || !R->TermWin.mapped) + if (refresh_type == NO_REFRESH || !TermWin.mapped) return; /* * A: set up vars */ - clearfirst = clearlast = must_clear = wbyte = 0; -#ifndef NO_BOLDFONT - bfont = 0; -#endif + clearfirst = clearlast = must_clear = 0; - if (R->currmaxcol < R->TermWin.ncol) + if (currmaxcol < TermWin.ncol) { - R->currmaxcol = R->TermWin.ncol; - R->buffer = (char *)rxvt_realloc (R->buffer, - sizeof(char) * (R->currmaxcol + 1) * MB_CUR_MAX); + currmaxcol = TermWin.ncol; + buffer = (char *)rxvt_realloc (buffer, + sizeof(char) * (currmaxcol + 1) * MB_CUR_MAX); } - buffer = R->buffer; - R->refresh_count = 0; + refresh_count = 0; - row_offset = R->TermWin.saveLines - R->TermWin.view_start; + row_offset = TermWin.saveLines - TermWin.view_start; if ((refresh_type & REFRESH_BOUNDS)) { clearfirst = clearlast = 1; - R->refresh_type &= ~REFRESH_BOUNDS; + refresh_type &= ~REFRESH_BOUNDS; } #if defined(XPM_BACKGROUND) - must_clear |= (R->bgPixmap.pixmap != None); + must_clear |= (bgPixmap.pixmap != None); #endif #if defined(TRANSPARENT) - must_clear |= ((R->Options & Opt_transparent) && R->am_transparent); + must_clear |= ((Options & Opt_transparent) && am_transparent); #endif - ocrow = R->oldcursor.row; /* is there an old outline cursor on screen? */ + ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ -/* - * B: reverse any characters which are selected - */ - rxvt_scr_reverse_selection(aR); + /* + * B: reverse any characters which are selected + */ + rxvt_scr_reverse_selection (this); -/* - * C: set the cursor character(s) - */ + /* + * C: set the cursor character(s) + */ { unsigned char setoldcursor; rend_t ccol1, /* Cursor colour */ ccol2; /* Cursor colour2 */ - showcursor = (R->screen.flags & Screen_VisibleCursor); + showcursor = (screen.flags & Screen_VisibleCursor); cursorwidth = 0; #ifdef CURSOR_BLINK - if (R->hidden_cursor) + if (hidden_cursor) showcursor = 0; #endif @@ -1971,27 +1923,27 @@ { cursorwidth++; - srp = &(R->screen.rend[R->screen.cur.row + R->TermWin.saveLines] - [R->screen.cur.col]); + srp = &(screen.rend[screen.cur.row + TermWin.saveLines] + [screen.cur.col]); - if (showcursor && R->TermWin.focus) + if (showcursor && TermWin.focus) { *srp ^= RS_RVid; #ifndef NO_CURSORCOLOR cc1 = *srp & (RS_fgMask | RS_bgMask); - if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor)) + if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor)) ccol1 = Color_cursor; else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol1 = GET_FGCOLOR(R->rstyle); + ccol1 = GET_FGCOLOR(rstyle); #else ccol1 = Color_fg; #endif - if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor2)) + if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor2)) ccol2 = Color_cursor2; else #ifdef CURSOR_COLOR_IS_RENDITION_COLOR - ccol2 = GET_BGCOLOR(R->rstyle); + ccol2 = GET_BGCOLOR(rstyle); #else ccol2 = Color_bg; #endif @@ -1999,45 +1951,42 @@ *srp = SET_BGCOLOR(*srp, ccol2); #endif } - - while (IS_WIDE (*srp)) - cursorwidth++, srp++; } /* make sure no outline cursor is left around */ setoldcursor = 0; if (ocrow != -1) { - if (R->screen.cur.row + R->TermWin.view_start != ocrow - || R->screen.cur.col != R->oldcursor.col) { - if (ocrow < R->TermWin.nrow - && R->oldcursor.col < R->TermWin.ncol) { - R->drawn_rend[ocrow][R->oldcursor.col] ^= (RS_RVid | RS_Uline); + if (screen.cur.row + TermWin.view_start != ocrow + || screen.cur.col != oldcursor.col) { + if (ocrow < TermWin.nrow + && oldcursor.col < TermWin.ncol) { + drawn_rend[ocrow][oldcursor.col] ^= (RS_RVid | RS_Uline); } - if (R->TermWin.focus || !showcursor) - R->oldcursor.row = -1; + if (TermWin.focus || !showcursor) + oldcursor.row = -1; else setoldcursor = 1; } - } else if (!R->TermWin.focus) + } else if (!TermWin.focus) setoldcursor = 1; if (setoldcursor) { - if (R->screen.cur.row + R->TermWin.view_start >= R->TermWin.nrow) - R->oldcursor.row = -1; + if (screen.cur.row + TermWin.view_start >= TermWin.nrow) + oldcursor.row = -1; else { - R->oldcursor.row = R->screen.cur.row + R->TermWin.view_start; - R->oldcursor.col = R->screen.cur.col; + oldcursor.row = screen.cur.row + TermWin.view_start; + oldcursor.col = screen.cur.col; } } } #ifndef NO_SLOW_LINK_SUPPORT -/* - * D: CopyArea pass - very useful for slower links - * This has been deliberately kept simple. - */ - i = R->num_scr; - if (refresh_type == FAST_REFRESH && R->num_scr_allow && i - && abs(i) < R->TermWin.nrow && !must_clear) + /* + * D: CopyArea pass - very useful for slower links + * This has been deliberately kept simple. + */ + i = num_scr; + if (refresh_type == FAST_REFRESH && num_scr_allow && i + && abs(i) < TermWin.nrow && !must_clear) { int16_t nits; int j; @@ -2045,21 +1994,21 @@ text_t *dtp2; int len, wlen; - j = R->TermWin.nrow; + j = TermWin.nrow; wlen = len = -1; row = i > 0 ? 0 : j - 1; for (; j-- >= 0; row += (i > 0 ? 1 : -1)) { - if (row + i >= 0 && row + i < R->TermWin.nrow && row + i != ocrow) + if (row + i >= 0 && row + i < TermWin.nrow && row + i != ocrow) { - stp = R->screen.text[row + row_offset]; - srp = R->screen.rend[row + row_offset]; - dtp = R->drawn_text[row]; - dtp2 = R->drawn_text[row + i]; - drp = R->drawn_rend[row]; - drp2 = R->drawn_rend[row + i]; + stp = screen.text[row + row_offset]; + srp = screen.rend[row + row_offset]; + dtp = drawn_text[row]; + dtp2 = drawn_text[row + i]; + drp = drawn_rend[row]; + drp2 = drawn_rend[row + i]; - for (nits = 0, col = R->TermWin.ncol; col--; ) + for (nits = 0, col = TermWin.ncol; col--; ) if (stp[col] != dtp2[col] || srp[col] != drp2[col]) nits--; else if (stp[col] != dtp[col] || srp[col] != drp[col]) @@ -2067,7 +2016,7 @@ if (nits > 8) /* XXX: arbitrary choice */ { - for (col = R->TermWin.ncol; col--; ) + for (col = TermWin.ncol; col--; ) { *dtp++ = *dtp2++; *drp++ = *drp2++; @@ -2086,34 +2035,35 @@ /* also comes here at end if needed because of >= above */ if (wlen < len) SWAP_IT(wlen, len, int); + D_SCREEN((stderr, "rxvt_scr_refresh(): XCopyArea: %d -> %d (height: %d)", len + i, len, wlen - len + 1)); - XCopyArea(R->Xdisplay, R->TermWin.vt, R->TermWin.vt, - R->TermWin.gc, 0, Row2Pixel(len + i), - (unsigned int)TermWin_TotalWidth(), - (unsigned int)Height2Pixel(wlen - len + 1), - 0, Row2Pixel(len)); + XCopyArea (Xdisplay, TermWin.vt, TermWin.vt, + TermWin.gc, 0, Row2Pixel (len + i), + (unsigned int)TermWin_TotalWidth (), + (unsigned int)Height2Pixel (wlen - len + 1), + 0, Row2Pixel (len)); len = -1; } } } #endif -/* - * E: main pass across every character - */ - for (row = 0; row < R->TermWin.nrow; row++) + /* + * E: main pass across every character + */ + for (row = 0; row < TermWin.nrow; row++) { - stp = R->screen.text[row + row_offset]; - srp = R->screen.rend[row + row_offset]; - dtp = R->drawn_text[row]; - drp = R->drawn_rend[row]; + stp = screen.text[row + row_offset]; + srp = screen.rend[row + row_offset]; + dtp = drawn_text[row]; + drp = drawn_rend[row]; -/* - * E2: OK, now the real pass - */ + /* + * E2: OK, now the real pass + */ int ypixel = (int)Row2Pixel(row); - for (col = 0; col < R->TermWin.ncol; col++) + for (col = 0; col < TermWin.ncol; col++) { /* compare new text with old - if exactly the same then continue */ rend_t rend = srp[col]; /* screen rendition (target rendtion) */ @@ -2139,7 +2089,7 @@ // this loop looks very messy, it can probably be optimized // and cleaned a bit by you? - for (i = 0; ++col < R->TermWin.ncol; ) + for (i = 0; ++col < TermWin.ncol; ) { if (stp[col] == NOCHAR) { @@ -2153,7 +2103,7 @@ continue; } - if (((rend ^ srp[col]) & ~RS_wide) != 0) + if (rend != srp[col]) break; count++; @@ -2175,19 +2125,20 @@ col--; /* went one too far. move back */ count -= i; /* dump any matching trailing chars */ -/* - * Determine the attributes for the string - */ - int fid = GET_FONT(rend); - fore = GET_FGCOLOR(rend); - back = GET_BGCOLOR(rend); - rend = GET_ATTR(rend); + /* + * Determine the attributes for the string + */ + int fid = GET_FONT (rend); + int fore = GET_FGCOLOR (rend); // desired foreground + int back = GET_BGCOLOR (rend); // desired background + + rend = GET_ATTR (rend); - rvid = (rend & RS_RVid) ? 1 : 0; + rvid = !!(rend & RS_RVid); #ifdef OPTION_HC if (!rvid && (rend & RS_Blink)) { - if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_HC)) + if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_HC)) back = Color_HC; else rvid = !rvid; /* fall back */ @@ -2198,9 +2149,9 @@ SWAP_IT(fore, back, int); #ifndef NO_BOLD_UNDERLINE_REVERSE - if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_RV) + if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_RV) # ifndef NO_CURSORCOLOR - && !ISSET_PIXCOLOR(R, Color_cursor) + && !ISSET_PIXCOLOR (this, Color_cursor) # endif ) back = Color_RV; @@ -2209,28 +2160,20 @@ #ifndef NO_BOLD_UNDERLINE_REVERSE else if (rend & RS_Bold) { - if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_BD)) - { - fore = Color_BD; -# ifndef VERYBOLD - rend &= ~RS_Bold; /* we've taken care of it */ -# endif - } + if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_BD)) + fore = Color_BD; } else if (rend & RS_Uline) { - if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_UL)) - { - fore = Color_UL; - rend &= ~RS_Uline; /* we've taken care of it */ - } + if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_UL)) + fore = Color_UL; } #endif -/* - * Actually do the drawing of the string here - */ - rxvt_font *font = (*R->TermWin.fontset)[fid]; + /* + * Actually do the drawing of the string here + */ + rxvt_font *font = (*TermWin.fontset)[fid]; if (back == Color_bg) { @@ -2243,7 +2186,7 @@ goto nodraw; } - CLEAR_CHARS(xpixel, ypixel, count); + CLEAR_CHARS (xpixel, ypixel, count); nodraw: ; } else @@ -2253,94 +2196,97 @@ font->draw (xpixel, ypixel, text, count, fore, back); if ((rend & RS_Uline) && (font->descent > 1)) - XDrawLine(R->Xdisplay, drawBuffer, R->TermWin.gc, + XDrawLine(Xdisplay, drawBuffer, TermWin.gc, xpixel, ypixel + font->ascent + 1, xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1); } /* for (col....) */ } /* for (row....) */ -/* - * G: cleanup cursor and display outline cursor if necessary - */ + /* + * G: cleanup cursor and display outline cursor if necessary + */ if (showcursor) { - if (R->TermWin.focus) { - srp = &(R->screen.rend[R->screen.cur.row + R->TermWin.saveLines] - [R->screen.cur.col]); + if (TermWin.focus) { + srp = &(screen.rend[screen.cur.row + TermWin.saveLines] + [screen.cur.col]); *srp ^= RS_RVid; #ifndef NO_CURSORCOLOR *srp = (*srp & ~(RS_fgMask | RS_bgMask)) | cc1; #endif - } else if (R->oldcursor.row >= 0) { + } else if (oldcursor.row >= 0) { #ifndef NO_CURSORCOLOR unsigned long gcmask; /* Graphics Context mask */ - if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor)) { - XSetForeground (R->Xdisplay, R->TermWin.gc, R->PixColors[Color_cursor]); - } + if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor)) + XSetForeground (Xdisplay, TermWin.gc, PixColors[Color_cursor]); #endif - XDrawRectangle(R->Xdisplay, drawBuffer, R->TermWin.gc, - Col2Pixel(R->oldcursor.col), - Row2Pixel(R->oldcursor.row), + XDrawRectangle(Xdisplay, drawBuffer, TermWin.gc, + Col2Pixel(oldcursor.col), + Row2Pixel(oldcursor.row), (unsigned int)(Width2Pixel(cursorwidth) - 1), - (unsigned int)(Height2Pixel(1) - R->TermWin.lineSpace - 1)); + (unsigned int)(Height2Pixel(1) - TermWin.lineSpace - 1)); } } -/* - * H: cleanup selection - */ - rxvt_scr_reverse_selection(aR); -/* - * I: other general cleanup - */ - if (clearfirst && R->TermWin.int_bwidth) + /* + * H: cleanup selection + */ + rxvt_scr_reverse_selection (this); + + /* + * I: other general cleanup + */ + if (clearfirst && TermWin.int_bwidth) /* * clear the whole screen height, note that width == 0 is treated * specially by XClearArea */ - XClearArea(R->Xdisplay, R->TermWin.vt, 0, 0, - (unsigned int)R->TermWin.int_bwidth, + XClearArea(Xdisplay, TermWin.vt, 0, 0, + (unsigned int)TermWin.int_bwidth, (unsigned int)TermWin_TotalHeight(), False); - if (clearlast && R->TermWin.int_bwidth) + if (clearlast && TermWin.int_bwidth) /* * clear the whole screen height, note that width == 0 is treated * specially by XClearArea */ - XClearArea(R->Xdisplay, R->TermWin.vt, - R->TermWin.width + R->TermWin.int_bwidth, 0, - (unsigned int)R->TermWin.int_bwidth, + XClearArea(Xdisplay, TermWin.vt, + TermWin.width + TermWin.int_bwidth, 0, + (unsigned int)TermWin.int_bwidth, (unsigned int)TermWin_TotalHeight(), False); if (refresh_type & SMOOTH_REFRESH) - XSync(R->Xdisplay, False); + XSync(Xdisplay, False); - R->num_scr = 0; - R->num_scr_allow = 1; - R->want_refresh = 0; /* screen is current */ + num_scr = 0; + num_scr_allow = 1; + want_refresh = 0; /* screen is current */ } -/* ------------------------------------------------------------------------- */ -/* EXTPROTO */ +/* ------------------------------------------------------------------------- */ void -rxvt_scr_clear(pR) +rxvt_term::scr_clear() { - if (!R->TermWin.mapped) - return; - R->num_scr_allow = 0; - R->want_refresh = 1; + if (!TermWin.mapped) + return; + + num_scr_allow = 0; + want_refresh = 1; #ifdef TRANSPARENT - if ((R->Options & Opt_transparent) && (R->am_pixmap_trans == 0)) { - int i; + if ((Options & Opt_transparent) && (am_pixmap_trans == 0)) + { + int i; - if (!(R->Options & Opt_transparent_all)) - i = 0; - else - i = (int)(sizeof(R->TermWin.parent) / sizeof(Window)); - for (; i--;) - if (R->TermWin.parent[i] != None) - XClearWindow(R->Xdisplay, R->TermWin.parent[i]); + if (!(Options & Opt_transparent_all)) + i = 0; + else + i = (int)(sizeof(TermWin.parent) / sizeof(Window)); + + while (i--) + if (TermWin.parent[i] != None) + XClearWindow(Xdisplay, TermWin.parent[i]); } #endif - XClearWindow(R->Xdisplay, R->TermWin.vt); + + XClearWindow (Xdisplay, TermWin.vt); } /* ------------------------------------------------------------------------- */ @@ -2458,6 +2404,11 @@ unsigned int i, j, n; unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE); +#if 0 + /* a paste should act like the user is typing, so check scrollTtyKeypress */ + ZERO_SCROLLBACK (r); +#endif + /* convert normal newline chars into common keyboard Return key sequence */ for (i = 0; i < len; i += PROP_SIZE) { @@ -2486,8 +2437,6 @@ long nread = 0; unsigned long bytes_after; XTextProperty ct; - int dummy_count; - char **cl; D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); @@ -2502,6 +2451,17 @@ rxvt_selection_request_other(aR_ XA_STRING, selnum); } + if ((R->selection_type & Sel_UTF8String)) + { + int selnum = R->selection_type & Sel_whereMask; + + R->selection_type = Sel_CompoundText; + if (selnum != Sel_direct) + rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], selnum); + else + R->selection_type = 0; + } + return 0; } @@ -2544,10 +2504,15 @@ } nread += ct.nitems; + + char **cl; + int cr; if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, - &dummy_count) == Success && cl) + &cr) >= 0 && cl) { - R->paste ((unsigned char *)cl[0], STRLEN (cl[0])); + for (int i = 0; i < cr; i++) + R->paste ((unsigned char *)cl[i], STRLEN (cl[i])); + XFreeStringList (cl); } else @@ -2572,10 +2537,9 @@ void rxvt_term::incr_cb (time_watcher &w) { - w.stop (); selection_wait = Sel_none; - rxvt_print_error("data loss: timeout on INCR selection paste"); + rxvt_print_error ("data loss: timeout on INCR selection paste"); } /* @@ -2651,9 +2615,15 @@ R->selection_request_time = tm; R->selection_wait = Sel_normal; for (i = Sel_Primary; i <= Sel_Clipboard; i++) { +#if X_HAVE_UTF8_STRING + R->selection_type = Sel_UTF8String; + if (rxvt_selection_request_other(aR_ R->xa[XA_UTF8_STRING], i)) + return; +#else R->selection_type = Sel_CompoundText; if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) return; +#endif } } R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ @@ -2795,11 +2765,12 @@ return; } - // due to MB_MAX_CUR, selection wastage is usually high + // due to MB_MAX_CUR, selection wastage is usually high, so realloc if (str - (char *)new_selection_text > 1024) new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); R->selection.len = i; + if (R->selection.text) free (R->selection.text); @@ -2808,8 +2779,23 @@ XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) rxvt_print_error("can't get primary selection"); - XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, - PropModeReplace, R->selection.text, (int)R->selection.len); + + + { + XTextProperty ct; + char *cl = (char *)R->selection.text; + + if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, XStringStyle, &ct) >= 0) + { + XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, + PropModeReplace, ct.value, ct.nitems); + XFree (ct.value); + } + else + XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, + PropModeReplace, R->selection.text, (int)R->selection.len); + } + R->selection_time = tm; D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); } @@ -2819,23 +2805,22 @@ * Mark or select text based upon number of clicks: 1, 2, or 3 * EXT: button 1 press */ -/* EXTPROTO */ void -rxvt_selection_click(pR_ int clicks, int x, int y) +rxvt_term::selection_click (int clicks, int x, int y) { - D_SELECT((stderr, "rxvt_selection_click(%d, %d, %d)", clicks, x, y)); + D_SELECT((stderr, "rxvt_selection_click(%d, %d, %d)", clicks, x, y)); + + clicks = ((clicks - 1) % 3) + 1; + selection.clicks = clicks; /* save clicks so extend will work */ - clicks = ((clicks - 1) % 3) + 1; - R->selection.clicks = clicks; /* save clicks so extend will work */ + rxvt_selection_start_colrow (this, Pixel2Col(x), Pixel2Row(y)); - rxvt_selection_start_colrow(aR_ Pixel2Col(x), Pixel2Row(y)); - if (clicks == 2 || clicks == 3) - rxvt_selection_extend_colrow(aR_ R->selection.mark.col, - R->selection.mark.row - + R->TermWin.view_start, - 0, /* button 3 */ - 1, /* button press */ - 0); /* click change */ + if (clicks == 2 || clicks == 3) + rxvt_selection_extend_colrow (this, selection.mark.col, + selection.mark.row + TermWin.view_start, + 0, /* button 3 */ + 1, /* button press */ + 0); /* click change */ } /* ------------------------------------------------------------------------- */ @@ -2955,44 +2940,47 @@ * flag == 1 ==> button 3 press * flag == 2 ==> button 3 motion */ -/* EXTPROTO */ void -rxvt_selection_extend(pR_ int x, int y, int flag) +rxvt_term::selection_extend (int x, int y, int flag) { - int col, row; + int col, row; + + col = Pixel2Col(x); + row = Pixel2Row(y); + MAX_IT(row, 0); + MIN_IT(row, (int)TermWin.nrow - 1); + MAX_IT(col, 0); + MIN_IT(col, (int)TermWin.ncol); - col = Pixel2Col(x); - row = Pixel2Row(y); - MAX_IT(row, 0); - MIN_IT(row, (int)R->TermWin.nrow - 1); - MAX_IT(col, 0); - MIN_IT(col, (int)R->TermWin.ncol); #ifndef NO_NEW_SELECTION -/* - * If we're selecting characters (single click) then we must check first - * if we are at the same place as the original mark. If we are then - * select nothing. Otherwise, if we're to the right of the mark, you have to - * be _past_ a character for it to be selected. - */ - if (R->selection_style != OLD_SELECT) { - if (((R->selection.clicks % 3) == 1) && !flag - && (col == R->selection.mark.col - && (row == R->selection.mark.row + R->TermWin.view_start))) { - /* select nothing */ - R->selection.beg.row = R->selection.end.row = 0; - R->selection.beg.col = R->selection.end.col = 0; - R->selection.clicks = 4; - R->want_refresh = 1; - D_SELECT((stderr, "rxvt_selection_extend() R->selection.clicks = 4")); - return; + /* + * If we're selecting characters (single click) then we must check first + * if we are at the same place as the original mark. If we are then + * select nothing. Otherwise, if we're to the right of the mark, you have to + * be _past_ a character for it to be selected. + */ + if (selection_style != OLD_SELECT) + { + if (((selection.clicks % 3) == 1) && !flag + && (col == selection.mark.col + && (row == selection.mark.row + TermWin.view_start))) + { + /* select nothing */ + selection.beg.row = selection.end.row = 0; + selection.beg.col = selection.end.col = 0; + selection.clicks = 4; + want_refresh = 1; + D_SELECT((stderr, "rxvt_selection_extend() selection.clicks = 4")); + return; } } #endif - if (R->selection.clicks == 4) - R->selection.clicks = 1; - rxvt_selection_extend_colrow(aR_ col, row, !!flag, /* ? button 3 */ - flag == 1 ? 1 : 0, /* ? button press */ - 0); /* no click change */ + if (selection.clicks == 4) + selection.clicks = 1; + + rxvt_selection_extend_colrow (this, col, row, !!flag, /* ? button 3 */ + flag == 1 ? 1 : 0, /* ? button press */ + 0); /* no click change */ } /* ------------------------------------------------------------------------- */ @@ -3256,12 +3244,11 @@ * Double click on button 3 when already selected * EXT: button 3 double click */ -/* EXTPROTO */ void -rxvt_selection_rotate(pR_ int x, int y) +rxvt_term::selection_rotate (int x, int y) { - R->selection.clicks = R->selection.clicks % 3 + 1; - rxvt_selection_extend_colrow(aR_ Pixel2Col(x), Pixel2Row(y), 1, 0, 1); + selection.clicks = selection.clicks % 3 + 1; + rxvt_selection_extend_colrow (this, Pixel2Col(x), Pixel2Row(y), 1, 0, 1); } /* ------------------------------------------------------------------------- */ @@ -3270,7 +3257,7 @@ * that is exactly 32 bits wide, because a format of 64 is not allowed by * the X11 protocol. */ -typedef CARD32 Atom32; +typedef CARD32 Atom32; /* ------------------------------------------------------------------------- */ /* @@ -3282,15 +3269,9 @@ rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) { XSelectionEvent ev; -#ifdef USE_XIM - Atom32 target_list[4]; -#else - Atom32 target_list[3]; -#endif - Atom target; - XTextProperty ct; + XTextProperty ct; XICCEncodingStyle style; - char *cl[2], dummy[1]; + Atom target; ev.type = SelectionNotify; ev.property = None; @@ -3301,16 +3282,20 @@ ev.time = rq->time; if (rq->target == R->xa[XA_TARGETS]) { - target_list[0] = (Atom32) R->xa[XA_TARGETS]; - target_list[1] = (Atom32) XA_STRING; - target_list[2] = (Atom32) R->xa[XA_TEXT]; -#ifdef USE_XIM - target_list[3] = (Atom32) R->xa[XA_COMPOUND_TEXT]; + Atom32 target_list[5]; + Atom32 *target = target_list; + + *target++ = (Atom32) R->xa[XA_TARGETS]; + *target++ = (Atom32) XA_STRING; + *target++ = (Atom32) R->xa[XA_TEXT]; + *target++ = (Atom32) R->xa[XA_COMPOUND_TEXT]; +#if X_HAVE_UTF8_STRING + *target++ = (Atom32) R->xa[XA_UTF8_STRING]; #endif XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, (8 * sizeof(target_list[0])), PropModeReplace, (unsigned char *)target_list, - (sizeof(target_list) / sizeof(target_list[0]))); + target - target_list); ev.property = rq->property; } else if (rq->target == R->xa[XA_MULTIPLE]) { /* TODO: Handle MULTIPLE */ @@ -3320,50 +3305,58 @@ (unsigned char *)&R->selection_time, 1); ev.property = rq->property; } else if (rq->target == XA_STRING + || rq->target == R->xa[XA_TEXT] || rq->target == R->xa[XA_COMPOUND_TEXT] - || rq->target == R->xa[XA_TEXT]) { -#ifdef USE_XIM - short freect = 0; + || rq->target == R->xa[XA_UTF8_STRING] + ) { + short freect = 0; + int selectlen; + char *cl; + + target = rq->target; + + if (target == XA_STRING) + // we actually don't do XA_STRING, but who cares, as i18n clients + // will ask for another format anyways. + style = XStringStyle; + else if (target == R->xa[XA_TEXT]) + style = XTextStyle; + else if (target == R->xa[XA_COMPOUND_TEXT]) + style = XCompoundTextStyle; +#if X_HAVE_UTF8_STRING + else if (target == R->xa[XA_UTF8_STRING]) + style = XUTF8StringStyle; #endif - int selectlen; - -#ifdef USE_XIM - if (rq->target != XA_STRING) { + else + { target = R->xa[XA_COMPOUND_TEXT]; - style = (rq->target == R->xa[XA_COMPOUND_TEXT]) - ? XCompoundTextStyle : XStdICCTextStyle; - } else -#endif - { - target = XA_STRING; - style = XStringStyle; - } + style = XCompoundTextStyle; + } + if (R->selection.text) { - cl[0] = (char *)R->selection.text; + cl = (char *)R->selection.text; selectlen = R->selection.len; } else { - cl[0] = dummy; - *dummy = '\0'; + cl = ""; selectlen = 0; } -#ifdef USE_XIM - if (XmbTextListToTextProperty(R->Xdisplay, cl, 1, style, &ct) - == Success) /* if we failed to convert then send it raw */ + + if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, style, &ct) >= 0) freect = 1; else -#endif - { - ct.value = (unsigned char *)cl[0]; + { + /* if we failed to convert then send it raw */ + ct.value = (unsigned char *)cl; ct.nitems = selectlen; - } + } + XChangeProperty(R->Xdisplay, rq->requestor, rq->property, target, 8, PropModeReplace, ct.value, (int)ct.nitems); ev.property = rq->property; -#ifdef USE_XIM + if (freect) - XFree(ct.value); -#endif + XFree (ct.value); } XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); } @@ -3375,28 +3368,27 @@ /* * return col/row values corresponding to x/y pixel values */ -/* EXTPROTO */ void -rxvt_pixel_position(pR_ int *x, int *y) +rxvt_term::pixel_position (int *x, int *y) { - *x = Pixel2Col(*x); -/* MAX_IT(*x, 0); MIN_IT(*x, (int)R->TermWin.ncol - 1); */ - *y = Pixel2Row(*y); -/* MAX_IT(*y, 0); MIN_IT(*y, (int)R->TermWin.nrow - 1); */ + *x = Pixel2Col(*x); + /* MAX_IT(*x, 0); MIN_IT(*x, (int)R->TermWin.ncol - 1); */ + *y = Pixel2Row(*y); + /* MAX_IT(*y, 0); MIN_IT(*y, (int)R->TermWin.nrow - 1); */ } + /* ------------------------------------------------------------------------- */ #ifdef USE_XIM -/* EXTPROTO */ void -rxvt_setPosition(pR_ XPoint *pos) +rxvt_term::set_position (XPoint *pos) { - XWindowAttributes xwa; + XWindowAttributes xwa; - XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &xwa); - pos->x = Col2Pixel(R->screen.cur.col) + xwa.x; - pos->y = Height2Pixel((R->screen.cur.row + 1)) + xwa.y - - R->TermWin.lineSpace; + XGetWindowAttributes (Xdisplay, TermWin.vt, &xwa); + pos->x = Col2Pixel (screen.cur.col) + xwa.x; + pos->y = Height2Pixel ((screen.cur.row + 1)) + xwa.y - TermWin.lineSpace; } + #endif /* ------------------------------------------------------------------------- */