ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/screen.C
(Generate patch)

Comparing rxvt-unicode/src/screen.C (file contents):
Revision 1.8 by pcg, Wed Dec 17 09:00:35 2003 UTC vs.
Revision 1.20 by pcg, Fri Jan 30 15:58:07 2004 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*--------------------------------*-C-*--------------------------------------*
2 * File: screen.c 2 * File: screen.c
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * $Id: screen.C,v 1.8 2003/12/17 09:00:35 pcg Exp $
5 * 4 *
6 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> 5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com>
7 * 6 *
8 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
89/* 88/*
90 * CLEAR_ROWS : clear <num> rows starting from row <row> 89 * CLEAR_ROWS : clear <num> rows starting from row <row>
91 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 90 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
92 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour 91 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
93 */ 92 */
94#define drawBuffer (R->TermWin.vt) 93#define drawBuffer TermWin.vt
95 94
96#define CLEAR_ROWS(row, num) \ 95#define CLEAR_ROWS(row, num) \
97 if (R->TermWin.mapped) \ 96 if (TermWin.mapped) \
98 XClearArea(R->Xdisplay, drawBuffer, R->TermWin.int_bwidth, \ 97 XClearArea (Xdisplay, drawBuffer, TermWin.int_bwidth, \
99 Row2Pixel(row), (unsigned int)R->TermWin.width, \ 98 Row2Pixel(row), (unsigned int)TermWin.width, \
100 (unsigned int)Height2Pixel(num), False) 99 (unsigned int)Height2Pixel(num), False)
101 100
102#define CLEAR_CHARS(x, y, num) \ 101#define CLEAR_CHARS(x, y, num) \
103 if (R->TermWin.mapped) \ 102 if (TermWin.mapped) \
104 XClearArea(R->Xdisplay, drawBuffer, x, y, \ 103 XClearArea (Xdisplay, drawBuffer, x, y, \
105 (unsigned int)Width2Pixel(num), \ 104 (unsigned int)Width2Pixel(num), \
106 (unsigned int)Height2Pixel(1), False) 105 (unsigned int)Height2Pixel(1), False)
107 106
108#define ERASE_ROWS(row, num) \ 107#define ERASE_ROWS(row, num) \
109 XFillRectangle(R->Xdisplay, drawBuffer, R->TermWin.gc, \ 108 XFillRectangle (Xdisplay, drawBuffer, TermWin.gc, \
110 R->TermWin.int_bwidth, Row2Pixel(row), \ 109 TermWin.int_bwidth, Row2Pixel(row), \
111 (unsigned int)R->TermWin.width, \ 110 (unsigned int)TermWin.width, \
112 (unsigned int)Height2Pixel(num)) 111 (unsigned int)Height2Pixel(num))
113 112
114/* ------------------------------------------------------------------------- * 113/* ------------------------------------------------------------------------- *
115 * SCREEN `COMMON' ROUTINES * 114 * SCREEN `COMMON' ROUTINES *
116 * ------------------------------------------------------------------------- */ 115 * ------------------------------------------------------------------------- */
117/* Fill part/all of a line with blanks. */ 116/* Fill part/all of a line with blanks. */
227#if NSCREENS 226#if NSCREENS
228 swap.flags = Screen_DefaultFlags; 227 swap.flags = Screen_DefaultFlags;
229 swap.cur.row = swap.cur.col = 0; 228 swap.cur.row = swap.cur.col = 0;
230 swap.charset = 0; 229 swap.charset = 0;
231 current_screen = SECONDARY; 230 current_screen = SECONDARY;
232 rxvt_scr_cursor(aR_ SAVE); 231 rxvt_scr_cursor (this, SAVE);
233 current_screen = PRIMARY; 232 current_screen = PRIMARY;
234#endif 233#endif
235 234
236 selection.text = NULL; 235 selection.text = NULL;
237 selection.len = 0; 236 selection.len = 0;
289 else if (nrow > prev_nrow) 288 else if (nrow > prev_nrow)
290 { 289 {
291 /* add rows */ 290 /* add rows */
292 scr_reset_realloc (); /* realloc _first_ */ 291 scr_reset_realloc (); /* realloc _first_ */
293 292
294 TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this 293 TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this
295 294
296 k = min (TermWin.nscrolled, nrow - prev_nrow); 295 k = min (TermWin.nscrolled, nrow - prev_nrow);
297 296
298 for (p = prev_total_rows; p < total_rows; p++) 297 for (p = prev_total_rows; p < total_rows; p++)
299 { 298 {
447 /* then so is screen.rend[i] */ 446 /* then so is screen.rend[i] */
448 assert(screen.rend[i]); 447 assert(screen.rend[i]);
449 } 448 }
450#endif 449#endif
451 450
452 delete talloc; 451 delete talloc; talloc = 0;
453 delete ralloc; 452 delete ralloc; ralloc = 0;
454 453
455 free (screen.text); 454 free (screen.text);
456 free (screen.tlen); 455 free (screen.tlen);
457 free (screen.rend); 456 free (screen.rend);
458 free (drawn_text); 457 free (drawn_text);
485 484
486 R->scr_release (); 485 R->scr_release ();
487 R->prev_nrow = R->prev_ncol = 0; 486 R->prev_nrow = R->prev_ncol = 0;
488 R->scr_reset (); 487 R->scr_reset ();
489 488
490 rxvt_scr_clear (aR); 489 R->scr_clear ();
491 rxvt_scr_refresh (aR_ SLOW_REFRESH); 490 R->scr_refresh (SLOW_REFRESH);
492#ifdef RXVT_GRAPHICS 491#ifdef RXVT_GRAPHICS
493 rxvt_Gr_reset (aR); 492 rxvt_Gr_reset (aR);
494#endif 493#endif
495} 494}
496 495
899 case 'z': c = 0x2265; break; case '{': c = 0x03c0; break; case '|': c = 0x2260; break; 898 case 'z': c = 0x2265; break; case '{': c = 0x03c0; break; case '|': c = 0x2260; break;
900 case '}': c = 0x00a3; break; case '~': c = 0x00b7; break; 899 case '}': c = 0x00a3; break; case '~': c = 0x00b7; break;
901 } 900 }
902 901
903 rend_t rend = SET_FONT (R->rstyle, R->TermWin.fontset->find_font (c)); 902 rend_t rend = SET_FONT (R->rstyle, R->TermWin.fontset->find_font (c));
904
905 stp[R->screen.cur.col] = c;
906 srp[R->screen.cur.col] = rend;
907
908 if (c > 255)
909 {
910 // rely on wcwidth to tell us the character width, at least for non iso-8859-1 903 // rely on wcwidth to tell us the character width, at least for non-ascii
911 int width = wcwidth (c); 904 int width = c <= 128 ? 1 : wcwidth (c);
905
906 // width -1 characters (e.g. combining chars) are ignored currently.
907 if (width > 0)
908 do
912 909 {
913 if (width > 1) 910 stp[R->screen.cur.col] = c;
914 {
915 while (--width > 0 && R->screen.cur.col < last_col - 1)
916 {
917
918 srp[R->screen.cur.col] |= RS_wide; 911 srp[R->screen.cur.col] = rend;
919 912
913 if (R->screen.cur.col < last_col - 1)
920 R->screen.cur.col++; 914 R->screen.cur.col++;
921 stp[R->screen.cur.col] = NOCHAR; 915 else
922 srp[R->screen.cur.col] = rend;
923 } 916 {
924 }
925 }
926
927 if (R->screen.cur.col < last_col - 1)
928 R->screen.cur.col++;
929 else {
930 R->screen.tlen[row] = last_col; 917 R->screen.tlen[row] = last_col;
931 if (R->screen.flags & Screen_Autowrap) 918 if (R->screen.flags & Screen_Autowrap)
932 R->screen.flags |= Screen_WrapNext; 919 R->screen.flags |= Screen_WrapNext;
920 break;
921 }
922
923 c = NOCHAR;
933 } 924 }
925 while (--width > 0);
926 else
927 1; /* handle combining character etc. here. */
934 } 928 }
929
935 if (R->screen.tlen[row] != -1) /* XXX: think about this */ 930 if (R->screen.tlen[row] != -1) /* XXX: think about this */
936 MAX_IT(R->screen.tlen[row], R->screen.cur.col); 931 MAX_IT(R->screen.tlen[row], R->screen.cur.col);
937 932
938/* 933/*
939 * If we wrote anywhere in the selected area, kill the selection 934 * If we wrote anywhere in the selected area, kill the selection
940 * XXX: should we kill the mark too? Possibly, but maybe that 935 * XXX: should we kill the mark too? Possibly, but maybe that
941 * should be a similar check. 936 * should be a similar check.
1211 * Erase part of whole of the screen 1206 * Erase part of whole of the screen
1212 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J 1207 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J
1213 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J 1208 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J
1214 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1209 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1215 */ 1210 */
1216/* EXTPROTO */
1217void 1211void
1218rxvt_scr_erase_screen(pR_ int mode) 1212rxvt_term::scr_erase_screen (int mode)
1219{ 1213{
1220 int num; 1214 int num;
1221 int32_t row, row_offset; 1215 int32_t row, row_offset;
1222 rend_t ren; 1216 rend_t ren;
1223 XGCValues gcvalue; 1217 XGCValues gcvalue;
1224 1218
1225 R->want_refresh = 1; 1219 want_refresh = 1;
1226 D_SCREEN((stderr, "rxvt_scr_erase_screen(%d) at screen row: %d", mode, R->screen.cur.row)); 1220 D_SCREEN((stderr, "rxvt_scr_erase_screen(%d) at screen row: %d", mode, screen.cur.row));
1227 ZERO_SCROLLBACK(R); 1221 ZERO_SCROLLBACK(this);
1228 row_offset = (int32_t)R->TermWin.saveLines; 1222 row_offset = (int32_t)TermWin.saveLines;
1229 1223
1230 switch (mode) { 1224 switch (mode) {
1231 case 0: /* erase to end of screen */ 1225 case 0: /* erase to end of screen */
1232 rxvt_selection_check(aR_ 1); 1226 rxvt_selection_check(this,1);
1233 rxvt_scr_erase_line(aR_ 0); 1227 rxvt_scr_erase_line(this,0);
1234 row = R->screen.cur.row + 1; /* possible OOB */ 1228 row = screen.cur.row + 1; /* possible OOB */
1235 num = R->TermWin.nrow - row; 1229 num = TermWin.nrow - row;
1236 break; 1230 break;
1237 case 1: /* erase to beginning of screen */ 1231 case 1: /* erase to beginning of screen */
1238 rxvt_selection_check(aR_ 3); 1232 rxvt_selection_check(this,3);
1239 rxvt_scr_erase_line(aR_ 1); 1233 rxvt_scr_erase_line(this,1);
1240 row = 0; 1234 row = 0;
1241 num = R->screen.cur.row; 1235 num = screen.cur.row;
1242 break; 1236 break;
1243 case 2: /* erase whole screen */ 1237 case 2: /* erase whole screen */
1244 rxvt_selection_check(aR_ 3); 1238 rxvt_selection_check (this, 3);
1245#ifdef RXVT_GRAPHICS 1239#ifdef RXVT_GRAPHICS
1246 rxvt_Gr_ClearScreen(aR); 1240 rxvt_Gr_ClearScreen (this);
1247#endif 1241#endif
1248 row = 0; 1242 row = 0;
1249 num = R->TermWin.nrow; 1243 num = TermWin.nrow;
1250 break; 1244 break;
1251 default: 1245 default:
1252 return; 1246 return;
1253 } 1247 }
1254 R->refresh_type |= REFRESH_BOUNDS; 1248 refresh_type |= REFRESH_BOUNDS;
1255 if (R->selection.op && R->current_screen == R->selection.screen 1249 if (selection.op && current_screen == selection.screen
1256 && ((R->selection.beg.row >= row && R->selection.beg.row <= row + num) 1250 && ((selection.beg.row >= row && selection.beg.row <= row + num)
1257 || (R->selection.end.row >= row 1251 || (selection.end.row >= row
1258 && R->selection.end.row <= row + num))) 1252 && selection.end.row <= row + num)))
1259 CLEAR_SELECTION(R); 1253 CLEAR_SELECTION (this);
1260 if (row >= R->TermWin.nrow) /* Out Of Bounds */ 1254 if (row >= TermWin.nrow) /* Out Of Bounds */
1261 return; 1255 return;
1262 MIN_IT(num, (R->TermWin.nrow - row)); 1256 MIN_IT(num, (TermWin.nrow - row));
1263 if (R->rstyle & (RS_RVid | RS_Uline)) 1257 if (rstyle & (RS_RVid | RS_Uline))
1264 ren = (rend_t) ~RS_None; 1258 ren = (rend_t) ~RS_None;
1265 else if (GET_BASEBG(R->rstyle) == Color_bg) { 1259 else if (GET_BASEBG(rstyle) == Color_bg) {
1266 ren = DEFAULT_RSTYLE; 1260 ren = DEFAULT_RSTYLE;
1267 CLEAR_ROWS(row, num); 1261 CLEAR_ROWS(row, num);
1268 } else { 1262 } else {
1269 ren = (R->rstyle & (RS_fgMask | RS_bgMask)); 1263 ren = (rstyle & (RS_fgMask | RS_bgMask));
1270 gcvalue.foreground = R->PixColors[GET_BGCOLOR(R->rstyle)]; 1264 gcvalue.foreground = PixColors[GET_BGCOLOR(rstyle)];
1271 XChangeGC(R->Xdisplay, R->TermWin.gc, GCForeground, &gcvalue); 1265 XChangeGC(Xdisplay, TermWin.gc, GCForeground, &gcvalue);
1272 ERASE_ROWS(row, num); 1266 ERASE_ROWS(row, num);
1273 gcvalue.foreground = R->PixColors[Color_fg]; 1267 gcvalue.foreground = PixColors[Color_fg];
1274 XChangeGC(R->Xdisplay, R->TermWin.gc, GCForeground, &gcvalue); 1268 XChangeGC(Xdisplay, TermWin.gc, GCForeground, &gcvalue);
1275 } 1269 }
1276 for (; num--; row++) { 1270 for (; num--; row++) {
1277 R->scr_blank_screen_mem (R->screen.text, R->screen.rend, 1271 scr_blank_screen_mem (screen.text, screen.rend,
1278 (unsigned int)(row + row_offset), R->rstyle); 1272 (unsigned int)(row + row_offset), rstyle);
1279 R->screen.tlen[row + row_offset] = 0; 1273 screen.tlen[row + row_offset] = 0;
1280 R->scr_blank_line (R->drawn_text[row], R->drawn_rend[row], 1274 scr_blank_line (drawn_text[row], drawn_rend[row],
1281 (unsigned int)R->TermWin.ncol, ren); 1275 (unsigned int)TermWin.ncol, ren);
1282 } 1276 }
1283} 1277}
1284 1278
1285/* ------------------------------------------------------------------------- */ 1279/* ------------------------------------------------------------------------- */
1286/* 1280/*
1570 1564
1571 gcvalue.foreground = R->PixColors[Color_fg]; 1565 gcvalue.foreground = R->PixColors[Color_fg];
1572 gcvalue.background = R->PixColors[Color_bg]; 1566 gcvalue.background = R->PixColors[Color_bg];
1573 XChangeGC(R->Xdisplay, R->TermWin.gc, GCBackground | GCForeground, 1567 XChangeGC(R->Xdisplay, R->TermWin.gc, GCBackground | GCForeground,
1574 &gcvalue); 1568 &gcvalue);
1575 rxvt_scr_clear(aR); 1569 R->scr_clear ();
1576 rxvt_scr_touch(aR_ True); 1570 R->scr_touch (true);
1577 } 1571 }
1578} 1572}
1579 1573
1580/* ------------------------------------------------------------------------- */ 1574/* ------------------------------------------------------------------------- */
1581/* 1575/*
1651 rxvt_set_font_style(aR); 1645 rxvt_set_font_style(aR);
1652} 1646}
1653 1647
1654 1648
1655/* ------------------------------------------------------------------------- * 1649/* ------------------------------------------------------------------------- *
1656 * GRAPHICS COLOURS *
1657 * ------------------------------------------------------------------------- */
1658
1659#ifdef RXVT_GRAPHICS
1660/* EXTPROTO */
1661int
1662rxvt_scr_get_fgcolor(pR)
1663{
1664 return GET_FGCOLOR(R->rstyle);
1665}
1666
1667/* ------------------------------------------------------------------------- */
1668/* EXTPROTO */
1669int
1670rxvt_scr_get_bgcolor(pR)
1671{
1672 return GET_BGCOLOR(R->rstyle);
1673}
1674#endif
1675
1676/* ------------------------------------------------------------------------- *
1677 * MAJOR SCREEN MANIPULATION * 1650 * MAJOR SCREEN MANIPULATION *
1678 * ------------------------------------------------------------------------- */ 1651 * ------------------------------------------------------------------------- */
1652
1653/*
1654 * refresh matching text.
1655 */
1656bool
1657rxvt_term::scr_refresh_rend (rend_t mask, rend_t value)
1658{
1659 bool found = false;
1660
1661 for (int i = 0; i < TermWin.nrow; i++)
1662 {
1663 int col = 0;
1664 rend_t *drp = drawn_rend [i];
1665
1666 for (; col < TermWin.ncol; col++, drp++)
1667 if ((*drp & mask) == value)
1668 {
1669 found = true;
1670 *drp = ~value;
1671 }
1672 }
1673
1674 return found;
1675}
1679 1676
1680/* 1677/*
1681 * Refresh an area 1678 * Refresh an area
1682 */ 1679 */
1683enum { 1680enum {
1684 PART_BEG = 0, 1681 PART_BEG = 0,
1685 PART_END, 1682 PART_END,
1686 RC_COUNT 1683 RC_COUNT
1687}; 1684};
1688 1685
1689/* EXTPROTO */
1690void 1686void
1691rxvt_scr_expose(pR_ int x, int y, int width, int height, Bool refresh) 1687rxvt_term::scr_expose (int x, int y, int width, int height, bool refresh)
1692{ 1688{
1693 int i; 1689 int i;
1694 row_col_t rc[RC_COUNT]; 1690 row_col_t rc[RC_COUNT];
1695 1691
1696 if (R->drawn_text == NULL) /* sanity check */ 1692 if (drawn_text == NULL) /* sanity check */
1697 return; 1693 return;
1698 1694
1699#ifdef DEBUG_STRICT 1695#ifdef DEBUG_STRICT
1700 x = max(x, (int)R->TermWin.int_bwidth); 1696 x = max(x, (int)TermWin.int_bwidth);
1701 x = min(x, (int)R->TermWin.width); 1697 x = min(x, (int)TermWin.width);
1702 y = max(y, (int)R->TermWin.int_bwidth); 1698 y = max(y, (int)TermWin.int_bwidth);
1703 y = min(y, (int)R->TermWin.height); 1699 y = min(y, (int)TermWin.height);
1704#endif 1700#endif
1705 1701
1706/* round down */ 1702/* round down */
1707 rc[PART_BEG].col = Pixel2Col(x); 1703 rc[PART_BEG].col = Pixel2Col(x);
1708 rc[PART_BEG].row = Pixel2Row(y); 1704 rc[PART_BEG].row = Pixel2Row(y);
1709/* round up */ 1705/* round up */
1710 rc[PART_END].col = Pixel2Width(x + width + R->TermWin.fwidth - 1); 1706 rc[PART_END].col = Pixel2Width(x + width + TermWin.fwidth - 1);
1711 rc[PART_END].row = Pixel2Row(y + height + R->TermWin.fheight - 1); 1707 rc[PART_END].row = Pixel2Row(y + height + TermWin.fheight - 1);
1712 1708
1713/* sanity checks */ 1709/* sanity checks */
1714 for (i = PART_BEG; i < RC_COUNT; i++) { 1710 for (i = PART_BEG; i < RC_COUNT; i++)
1711 {
1715 MIN_IT(rc[i].col, R->TermWin.ncol - 1); 1712 MIN_IT(rc[i].col, TermWin.ncol - 1);
1716 MIN_IT(rc[i].row, R->TermWin.nrow - 1); 1713 MIN_IT(rc[i].row, TermWin.nrow - 1);
1717 } 1714 }
1718 1715
1719 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)); 1716 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));
1720 1717
1721 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1718 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1722 fill_text (&(R->drawn_text[i][rc[PART_BEG].col]), 0, 1719 fill_text (&(drawn_text[i][rc[PART_BEG].col]), 0,
1723 (rc[PART_END].col - rc[PART_BEG].col + 1)); 1720 (rc[PART_END].col - rc[PART_BEG].col + 1));
1724 1721
1725 if (refresh) 1722 if (refresh)
1726 rxvt_scr_refresh(aR_ SLOW_REFRESH | REFRESH_BOUNDS); 1723 scr_refresh (SLOW_REFRESH | REFRESH_BOUNDS);
1727} 1724}
1728 1725
1729/* ------------------------------------------------------------------------- */ 1726/* ------------------------------------------------------------------------- */
1730/* 1727/*
1731 * Refresh the entire screen 1728 * Refresh the entire screen
1732 */ 1729 */
1733/* EXTPROTO */
1734void 1730void
1735rxvt_scr_touch(pR_ Bool refresh) 1731rxvt_term::scr_touch (bool refresh)
1736{ 1732{
1737 rxvt_scr_expose(aR_ 0, 0, R->TermWin.width, R->TermWin.height, refresh); 1733 scr_expose (0, 0, TermWin.width, TermWin.height, refresh);
1738} 1734}
1739 1735
1740/* ------------------------------------------------------------------------- */ 1736/* ------------------------------------------------------------------------- */
1741/* 1737/*
1742 * Move the display so that the line represented by scrollbar value Y is at 1738 * Move the display so that the line represented by scrollbar value Y is at
1861 * Refresh the screen 1857 * Refresh the screen
1862 * R->drawn_text/R->drawn_rend contain the screen information before the update. 1858 * R->drawn_text/R->drawn_rend contain the screen information before the update.
1863 * R->screen.text/R->screen.rend contain what the screen will change to. 1859 * R->screen.text/R->screen.rend contain what the screen will change to.
1864 */ 1860 */
1865 1861
1866#if defined (NO_BRIGHTCOLOR) || defined (VERYBOLD)
1867# define MONO_BOLD(x) ((x) & (RS_Bold|RS_Blink))
1868# define MONO_BOLD_FG(x, fg) MONO_BOLD(x)
1869#else
1870# define MONO_BOLD(x) \
1871 (((x) & (RS_Bold | RS_fgMask)) == (RS_Bold | Color_fg))
1872# define MONO_BOLD_FG(x, fg) (((x) & RS_Bold) && (fg) == Color_fg)
1873#endif
1874
1875#define FONT_WIDTH(X, Y) \ 1862#define FONT_WIDTH(X, Y) \
1876 (X)->per_char[(Y) - (X)->min_char_or_byte2].width 1863 (X)->per_char[(Y) - (X)->min_char_or_byte2].width
1877#define FONT_RBEAR(X, Y) \ 1864#define FONT_RBEAR(X, Y) \
1878 (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing 1865 (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing
1879#define FONT_LBEAR(X, Y) \ 1866#define FONT_LBEAR(X, Y) \
1880 (X)->per_char[(Y) - (X)->min_char_or_byte2].lbearing 1867 (X)->per_char[(Y) - (X)->min_char_or_byte2].lbearing
1881#define IS_FONT_CHAR(X, Y) \ 1868#define IS_FONT_CHAR(X, Y) \
1882 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2) 1869 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2)
1883 1870
1884/* EXTPROTO */
1885void 1871void
1886rxvt_scr_refresh(pR_ unsigned char refresh_type) 1872rxvt_term::scr_refresh (unsigned char refresh_type)
1887{ 1873{
1888 unsigned char clearfirst, /* first character writes before cell */ 1874 unsigned char clearfirst, /* first character writes before cell */
1889 clearlast, /* last character writes beyond cell */ 1875 clearlast, /* last character writes beyond cell */
1890 must_clear, /* use draw_string not draw_image_string */ 1876 must_clear, /* use draw_string not draw_image_string */
1891#ifndef NO_BOLDFONT
1892 bfont, /* we've changed font to bold font */
1893#endif
1894 rvid, /* reverse video this position */ 1877 rvid, /* reverse video this position */
1895 wbyte, /* we're in multibyte */
1896 showcursor; /* show the cursor */ 1878 showcursor; /* show the cursor */
1897 int fore, back; /* desired foreground/background */
1898 int16_t col, row, /* column/row we're processing */ 1879 int16_t col, row, /* column/row we're processing */
1899 ocrow; /* old cursor row */ 1880 ocrow; /* old cursor row */
1900 int cursorwidth; 1881 int cursorwidth;
1901 int i, /* tmp */ 1882 int i, /* tmp */
1902 row_offset; /* basic offset in screen structure */ 1883 row_offset; /* basic offset in screen structure */
1904 rend_t cc1; /* store colours at cursor position(s) */ 1885 rend_t cc1; /* store colours at cursor position(s) */
1905 rend_t cc2; /* store colours at cursor position(s) */ 1886 rend_t cc2; /* store colours at cursor position(s) */
1906#endif 1887#endif
1907 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ 1888 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */
1908 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ 1889 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */
1909 char *buffer; /* local copy of R->buffer */
1910 1890
1911 if (refresh_type == NO_REFRESH || !R->TermWin.mapped) 1891 if (refresh_type == NO_REFRESH || !TermWin.mapped)
1912 return; 1892 return;
1913 1893
1914 /* 1894 /*
1915 * A: set up vars 1895 * A: set up vars
1916 */ 1896 */
1917 clearfirst = clearlast = must_clear = wbyte = 0; 1897 clearfirst = clearlast = must_clear = 0;
1918#ifndef NO_BOLDFONT
1919 bfont = 0;
1920#endif
1921 1898
1922 if (R->currmaxcol < R->TermWin.ncol)
1923 {
1924 R->currmaxcol = R->TermWin.ncol;
1925 R->buffer = (char *)rxvt_realloc (R->buffer,
1926 sizeof(char) * (R->currmaxcol + 1) * MB_CUR_MAX);
1927 }
1928
1929 buffer = R->buffer;
1930 R->refresh_count = 0; 1899 refresh_count = 0;
1931 1900
1932 row_offset = R->TermWin.saveLines - R->TermWin.view_start; 1901 row_offset = TermWin.saveLines - TermWin.view_start;
1933 1902
1934 if ((refresh_type & REFRESH_BOUNDS)) 1903 if ((refresh_type & REFRESH_BOUNDS))
1935 { 1904 {
1936 clearfirst = clearlast = 1; 1905 clearfirst = clearlast = 1;
1937 R->refresh_type &= ~REFRESH_BOUNDS; 1906 refresh_type &= ~REFRESH_BOUNDS;
1938 } 1907 }
1939 1908
1940#if defined(XPM_BACKGROUND) 1909#if defined(XPM_BACKGROUND)
1941 must_clear |= (R->bgPixmap.pixmap != None); 1910 must_clear |= (bgPixmap.pixmap != None);
1942#endif 1911#endif
1943#if defined(TRANSPARENT) 1912#if defined(TRANSPARENT)
1944 must_clear |= ((R->Options & Opt_transparent) && R->am_transparent); 1913 must_clear |= ((Options & Opt_transparent) && am_transparent);
1945#endif 1914#endif
1946 ocrow = R->oldcursor.row; /* is there an old outline cursor on screen? */ 1915 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1947 1916
1948/* 1917 /*
1949 * B: reverse any characters which are selected 1918 * B: reverse any characters which are selected
1950 */ 1919 */
1951 rxvt_scr_reverse_selection(aR); 1920 rxvt_scr_reverse_selection (this);
1952 1921
1953/* 1922 /*
1954 * C: set the cursor character(s) 1923 * C: set the cursor character(s)
1955 */ 1924 */
1956 { 1925 {
1957 unsigned char setoldcursor; 1926 unsigned char setoldcursor;
1958 rend_t ccol1, /* Cursor colour */ 1927 rend_t ccol1, /* Cursor colour */
1959 ccol2; /* Cursor colour2 */ 1928 ccol2; /* Cursor colour2 */
1960 1929
1961 showcursor = (R->screen.flags & Screen_VisibleCursor); 1930 showcursor = (screen.flags & Screen_VisibleCursor);
1962 cursorwidth = 0; 1931 cursorwidth = 0;
1963#ifdef CURSOR_BLINK 1932#ifdef CURSOR_BLINK
1964 if (R->hidden_cursor) 1933 if (hidden_cursor)
1965 showcursor = 0; 1934 showcursor = 0;
1966#endif 1935#endif
1967 1936
1968 cursorwidth = 0; 1937 cursorwidth = 0;
1969 1938
1970 if (showcursor) 1939 if (showcursor)
1971 { 1940 {
1972 cursorwidth++; 1941 cursorwidth++;
1973 1942
1974 srp = &(R->screen.rend[R->screen.cur.row + R->TermWin.saveLines] 1943 srp = &(screen.rend[screen.cur.row + TermWin.saveLines]
1975 [R->screen.cur.col]); 1944 [screen.cur.col]);
1976 1945
1977 if (showcursor && R->TermWin.focus) 1946 if (showcursor && TermWin.focus)
1978 { 1947 {
1979 *srp ^= RS_RVid; 1948 *srp ^= RS_RVid;
1980#ifndef NO_CURSORCOLOR 1949#ifndef NO_CURSORCOLOR
1981 cc1 = *srp & (RS_fgMask | RS_bgMask); 1950 cc1 = *srp & (RS_fgMask | RS_bgMask);
1982 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor)) 1951 if (ISSET_PIXCOLOR (this, Color_cursor))
1983 ccol1 = Color_cursor; 1952 ccol1 = Color_cursor;
1984 else 1953 else
1985#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 1954#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1986 ccol1 = GET_FGCOLOR(R->rstyle); 1955 ccol1 = GET_FGCOLOR(rstyle);
1987#else 1956#else
1988 ccol1 = Color_fg; 1957 ccol1 = Color_fg;
1989#endif 1958#endif
1990 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor2)) 1959 if (ISSET_PIXCOLOR (this, Color_cursor2))
1991 ccol2 = Color_cursor2; 1960 ccol2 = Color_cursor2;
1992 else 1961 else
1993#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 1962#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1994 ccol2 = GET_BGCOLOR(R->rstyle); 1963 ccol2 = GET_BGCOLOR(rstyle);
1995#else 1964#else
1996 ccol2 = Color_bg; 1965 ccol2 = Color_bg;
1997#endif 1966#endif
1998 *srp = SET_FGCOLOR(*srp, ccol1); 1967 *srp = SET_FGCOLOR(*srp, ccol1);
1999 *srp = SET_BGCOLOR(*srp, ccol2); 1968 *srp = SET_BGCOLOR(*srp, ccol2);
2000#endif 1969#endif
2001 } 1970 }
2002
2003 while (IS_WIDE (*srp))
2004 cursorwidth++, srp++;
2005 } 1971 }
2006 1972
2007 /* make sure no outline cursor is left around */ 1973 /* make sure no outline cursor is left around */
2008 setoldcursor = 0; 1974 setoldcursor = 0;
2009 if (ocrow != -1) { 1975 if (ocrow != -1) {
2010 if (R->screen.cur.row + R->TermWin.view_start != ocrow 1976 if (screen.cur.row + TermWin.view_start != ocrow
2011 || R->screen.cur.col != R->oldcursor.col) { 1977 || screen.cur.col != oldcursor.col) {
2012 if (ocrow < R->TermWin.nrow 1978 if (ocrow < TermWin.nrow
2013 && R->oldcursor.col < R->TermWin.ncol) { 1979 && oldcursor.col < TermWin.ncol) {
2014 R->drawn_rend[ocrow][R->oldcursor.col] ^= (RS_RVid | RS_Uline); 1980 drawn_rend[ocrow][oldcursor.col] ^= (RS_RVid | RS_Uline);
2015 } 1981 }
2016 if (R->TermWin.focus || !showcursor) 1982 if (TermWin.focus || !showcursor)
2017 R->oldcursor.row = -1; 1983 oldcursor.row = -1;
2018 else 1984 else
2019 setoldcursor = 1; 1985 setoldcursor = 1;
2020 } 1986 }
2021 } else if (!R->TermWin.focus) 1987 } else if (!TermWin.focus)
2022 setoldcursor = 1; 1988 setoldcursor = 1;
2023 if (setoldcursor) { 1989 if (setoldcursor) {
2024 if (R->screen.cur.row + R->TermWin.view_start >= R->TermWin.nrow) 1990 if (screen.cur.row + TermWin.view_start >= TermWin.nrow)
2025 R->oldcursor.row = -1; 1991 oldcursor.row = -1;
2026 else { 1992 else {
2027 R->oldcursor.row = R->screen.cur.row + R->TermWin.view_start; 1993 oldcursor.row = screen.cur.row + TermWin.view_start;
2028 R->oldcursor.col = R->screen.cur.col; 1994 oldcursor.col = screen.cur.col;
2029 } 1995 }
2030 } 1996 }
2031 } 1997 }
2032 1998
2033#ifndef NO_SLOW_LINK_SUPPORT 1999#ifndef NO_SLOW_LINK_SUPPORT
2034/* 2000 /*
2035 * D: CopyArea pass - very useful for slower links 2001 * D: CopyArea pass - very useful for slower links
2036 * This has been deliberately kept simple. 2002 * This has been deliberately kept simple.
2037 */ 2003 */
2038 i = R->num_scr; 2004 i = num_scr;
2039 if (refresh_type == FAST_REFRESH && R->num_scr_allow && i 2005 if (refresh_type == FAST_REFRESH && num_scr_allow && i
2040 && abs(i) < R->TermWin.nrow && !must_clear) 2006 && abs(i) < TermWin.nrow && !must_clear)
2041 { 2007 {
2042 int16_t nits; 2008 int16_t nits;
2043 int j; 2009 int j;
2044 rend_t *drp2; 2010 rend_t *drp2;
2045 text_t *dtp2; 2011 text_t *dtp2;
2046 int len, wlen; 2012 int len, wlen;
2047 2013
2048 j = R->TermWin.nrow; 2014 j = TermWin.nrow;
2049 wlen = len = -1; 2015 wlen = len = -1;
2050 row = i > 0 ? 0 : j - 1; 2016 row = i > 0 ? 0 : j - 1;
2051 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2017 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2052 { 2018 {
2053 if (row + i >= 0 && row + i < R->TermWin.nrow && row + i != ocrow) 2019 if (row + i >= 0 && row + i < TermWin.nrow && row + i != ocrow)
2054 { 2020 {
2055 stp = R->screen.text[row + row_offset]; 2021 stp = screen.text[row + row_offset];
2056 srp = R->screen.rend[row + row_offset]; 2022 srp = screen.rend[row + row_offset];
2057 dtp = R->drawn_text[row]; 2023 dtp = drawn_text[row];
2058 dtp2 = R->drawn_text[row + i]; 2024 dtp2 = drawn_text[row + i];
2059 drp = R->drawn_rend[row]; 2025 drp = drawn_rend[row];
2060 drp2 = R->drawn_rend[row + i]; 2026 drp2 = drawn_rend[row + i];
2061 2027
2062 for (nits = 0, col = R->TermWin.ncol; col--; ) 2028 for (nits = 0, col = TermWin.ncol; col--; )
2063 if (stp[col] != dtp2[col] || srp[col] != drp2[col]) 2029 if (stp[col] != dtp2[col] || srp[col] != drp2[col])
2064 nits--; 2030 nits--;
2065 else if (stp[col] != dtp[col] || srp[col] != drp[col]) 2031 else if (stp[col] != dtp[col] || srp[col] != drp[col])
2066 nits++; 2032 nits++;
2067 2033
2068 if (nits > 8) /* XXX: arbitrary choice */ 2034 if (nits > 8) /* XXX: arbitrary choice */
2069 { 2035 {
2070 for (col = R->TermWin.ncol; col--; ) 2036 for (col = TermWin.ncol; col--; )
2071 { 2037 {
2072 *dtp++ = *dtp2++; 2038 *dtp++ = *dtp2++;
2073 *drp++ = *drp2++; 2039 *drp++ = *drp2++;
2074 } 2040 }
2075 2041
2084 if (len != -1) 2050 if (len != -1)
2085 { 2051 {
2086 /* also comes here at end if needed because of >= above */ 2052 /* also comes here at end if needed because of >= above */
2087 if (wlen < len) 2053 if (wlen < len)
2088 SWAP_IT(wlen, len, int); 2054 SWAP_IT(wlen, len, int);
2055
2089 D_SCREEN((stderr, "rxvt_scr_refresh(): XCopyArea: %d -> %d (height: %d)", len + i, len, wlen - len + 1)); 2056 D_SCREEN((stderr, "rxvt_scr_refresh(): XCopyArea: %d -> %d (height: %d)", len + i, len, wlen - len + 1));
2090 XCopyArea(R->Xdisplay, R->TermWin.vt, R->TermWin.vt, 2057 XCopyArea (Xdisplay, TermWin.vt, TermWin.vt,
2091 R->TermWin.gc, 0, Row2Pixel(len + i), 2058 TermWin.gc, 0, Row2Pixel (len + i),
2092 (unsigned int)TermWin_TotalWidth(), 2059 (unsigned int)TermWin_TotalWidth (),
2093 (unsigned int)Height2Pixel(wlen - len + 1), 2060 (unsigned int)Height2Pixel (wlen - len + 1),
2094 0, Row2Pixel(len)); 2061 0, Row2Pixel (len));
2095 len = -1; 2062 len = -1;
2096 } 2063 }
2097 } 2064 }
2098 } 2065 }
2099#endif 2066#endif
2100 2067
2101/* 2068 /*
2102 * E: main pass across every character 2069 * E: main pass across every character
2103 */ 2070 */
2104 for (row = 0; row < R->TermWin.nrow; row++) 2071 for (row = 0; row < TermWin.nrow; row++)
2105 { 2072 {
2106 stp = R->screen.text[row + row_offset]; 2073 stp = screen.text[row + row_offset];
2107 srp = R->screen.rend[row + row_offset]; 2074 srp = screen.rend[row + row_offset];
2108 dtp = R->drawn_text[row]; 2075 dtp = drawn_text[row];
2109 drp = R->drawn_rend[row]; 2076 drp = drawn_rend[row];
2110 2077
2111/* 2078 /*
2112 * E2: OK, now the real pass 2079 * E2: OK, now the real pass
2113 */ 2080 */
2114 int ypixel = (int)Row2Pixel(row); 2081 int ypixel = (int)Row2Pixel(row);
2115 2082
2116 for (col = 0; col < R->TermWin.ncol; col++) 2083 for (col = 0; col < TermWin.ncol; col++)
2117 { 2084 {
2118 /* compare new text with old - if exactly the same then continue */ 2085 /* compare new text with old - if exactly the same then continue */
2119 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2086 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2120 2087
2121 if (stp[col] == dtp[col] /* Must match characters to skip. */ 2088 if (stp[col] == dtp[col] /* Must match characters to skip. */
2137 2104
2138 int xpixel = Col2Pixel(col); 2105 int xpixel = Col2Pixel(col);
2139 2106
2140 // this loop looks very messy, it can probably be optimized 2107 // this loop looks very messy, it can probably be optimized
2141 // and cleaned a bit by you? 2108 // and cleaned a bit by you?
2142 for (i = 0; ++col < R->TermWin.ncol; ) 2109 for (i = 0; ++col < TermWin.ncol; )
2143 { 2110 {
2144 if (stp[col] == NOCHAR) 2111 if (stp[col] == NOCHAR)
2145 { 2112 {
2146 dtp[col] = stp[col]; 2113 dtp[col] = stp[col];
2147 drp[col] = rend; 2114 drp[col] = rend;
2151 i++; 2118 i++;
2152 2119
2153 continue; 2120 continue;
2154 } 2121 }
2155 2122
2156 if (((rend ^ srp[col]) & ~RS_wide) != 0) 2123 if (rend != srp[col])
2157 break; 2124 break;
2158 2125
2159 count++; 2126 count++;
2160 2127
2161 if (stp[col] != dtp[col] 2128 if (stp[col] != dtp[col]
2173 } 2140 }
2174 2141
2175 col--; /* went one too far. move back */ 2142 col--; /* went one too far. move back */
2176 count -= i; /* dump any matching trailing chars */ 2143 count -= i; /* dump any matching trailing chars */
2177 2144
2178/* 2145 /*
2179 * Determine the attributes for the string 2146 * Determine the attributes for the string
2180 */ 2147 */
2181 int fid = GET_FONT(rend); 2148 int fid = GET_FONT (rend);
2182 fore = GET_FGCOLOR(rend); 2149 int fore = GET_FGCOLOR (rend); // desired foreground
2183 back = GET_BGCOLOR(rend); 2150 int back = GET_BGCOLOR (rend); // desired background
2151
2184 rend = GET_ATTR(rend); 2152 rend = GET_ATTR (rend);
2185 2153
2186 rvid = (rend & RS_RVid) ? 1 : 0; 2154 rvid = !!(rend & RS_RVid);
2187#ifdef OPTION_HC 2155#ifdef TEXT_BLINK
2188 if (!rvid && (rend & RS_Blink)) 2156 if (rend & RS_Blink)
2189 { 2157 {
2190 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_HC)) 2158 if (!text_blink_ev.active)
2191 back = Color_HC;
2192 else 2159 {
2193 rvid = !rvid; /* fall back */ 2160 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
2161 hidden_text = 0;
2162 }
2163 else if (hidden_text)
2164 fore = back;
2194 } 2165 }
2195#endif 2166#endif
2196 if (rvid) 2167 if (rvid)
2197 { 2168 {
2198 SWAP_IT(fore, back, int); 2169 SWAP_IT(fore, back, int);
2199 2170
2200#ifndef NO_BOLD_UNDERLINE_REVERSE 2171#ifndef NO_BOLD_UNDERLINE_REVERSE
2201 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_RV) 2172 if (ISSET_PIXCOLOR (this, Color_RV)
2202# ifndef NO_CURSORCOLOR 2173# ifndef NO_CURSORCOLOR
2203 && !ISSET_PIXCOLOR(R, Color_cursor) 2174 && !ISSET_PIXCOLOR (this, Color_cursor)
2204# endif 2175# endif
2205 ) 2176 )
2206 back = Color_RV; 2177 back = Color_RV;
2207#endif 2178#endif
2208 } 2179 }
2209#ifndef NO_BOLD_UNDERLINE_REVERSE 2180#ifndef NO_BOLD_UNDERLINE_REVERSE
2210 else if (rend & RS_Bold) 2181 else if (rend & RS_Bold)
2211 { 2182 {
2212 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_BD)) 2183 if (ISSET_PIXCOLOR (this, Color_BD))
2213 {
2214 fore = Color_BD; 2184 fore = Color_BD;
2215# ifndef VERYBOLD 2185 else if (fore == Color_fg)
2216 rend &= ~RS_Bold; /* we've taken care of it */ 2186 fore = Color_White;
2217# endif
2218 }
2219 } 2187 }
2220 else if (rend & RS_Uline) 2188 else if (rend & RS_Uline)
2221 { 2189 {
2222 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_UL)) 2190 if (ISSET_PIXCOLOR (this, Color_UL))
2223 {
2224 fore = Color_UL; 2191 fore = Color_UL;
2225 rend &= ~RS_Uline; /* we've taken care of it */
2226 }
2227 } 2192 }
2228#endif 2193#endif
2229 2194
2230/* 2195 /*
2231 * Actually do the drawing of the string here 2196 * Actually do the drawing of the string here
2232 */ 2197 */
2233 rxvt_font *font = (*R->TermWin.fontset)[fid]; 2198 rxvt_font *font = (*TermWin.fontset)[fid];
2234 2199
2235 if (back == Color_bg) 2200 if (back == Color_bg)
2236 { 2201 {
2237 if (must_clear) 2202 if (must_clear)
2238 { 2203 {
2241 { 2206 {
2242 font->draw (xpixel, ypixel, text, count, fore, -1); 2207 font->draw (xpixel, ypixel, text, count, fore, -1);
2243 goto nodraw; 2208 goto nodraw;
2244 } 2209 }
2245 2210
2246 CLEAR_CHARS(xpixel, ypixel, count); 2211 CLEAR_CHARS (xpixel, ypixel, count);
2247nodraw: ; 2212nodraw: ;
2248 } 2213 }
2249 else 2214 else
2250 font->draw (xpixel, ypixel, text, count, fore, Color_bg); 2215 font->draw (xpixel, ypixel, text, count, fore, Color_bg);
2251 } 2216 }
2252 else 2217 else
2253 font->draw (xpixel, ypixel, text, count, fore, back); 2218 font->draw (xpixel, ypixel, text, count, fore, back);
2254 2219
2255 if ((rend & RS_Uline) && (font->descent > 1)) 2220 if ((rend & RS_Uline) && (font->descent > 1))
2256 XDrawLine(R->Xdisplay, drawBuffer, R->TermWin.gc, 2221 XDrawLine(Xdisplay, drawBuffer, TermWin.gc,
2257 xpixel, ypixel + font->ascent + 1, 2222 xpixel, ypixel + font->ascent + 1,
2258 xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1); 2223 xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1);
2259 } /* for (col....) */ 2224 } /* for (col....) */
2260 } /* for (row....) */ 2225 } /* for (row....) */
2261 2226
2262/* 2227 /*
2263 * G: cleanup cursor and display outline cursor if necessary 2228 * G: cleanup cursor and display outline cursor if necessary
2264 */ 2229 */
2265 if (showcursor) { 2230 if (showcursor) {
2266 if (R->TermWin.focus) { 2231 if (TermWin.focus) {
2267 srp = &(R->screen.rend[R->screen.cur.row + R->TermWin.saveLines] 2232 srp = &(screen.rend[screen.cur.row + TermWin.saveLines]
2268 [R->screen.cur.col]); 2233 [screen.cur.col]);
2269 *srp ^= RS_RVid; 2234 *srp ^= RS_RVid;
2270#ifndef NO_CURSORCOLOR 2235#ifndef NO_CURSORCOLOR
2271 *srp = (*srp & ~(RS_fgMask | RS_bgMask)) | cc1; 2236 *srp = (*srp & ~(RS_fgMask | RS_bgMask)) | cc1;
2272#endif 2237#endif
2273 } else if (R->oldcursor.row >= 0) { 2238 } else if (oldcursor.row >= 0) {
2274#ifndef NO_CURSORCOLOR 2239#ifndef NO_CURSORCOLOR
2275 unsigned long gcmask; /* Graphics Context mask */ 2240 unsigned long gcmask; /* Graphics Context mask */
2276 2241
2277 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor)) { 2242 if (ISSET_PIXCOLOR (this, Color_cursor))
2278 XSetForeground (R->Xdisplay, R->TermWin.gc, R->PixColors[Color_cursor]); 2243 XSetForeground (Xdisplay, TermWin.gc, PixColors[Color_cursor]);
2279 }
2280#endif 2244#endif
2281 XDrawRectangle(R->Xdisplay, drawBuffer, R->TermWin.gc, 2245 XDrawRectangle(Xdisplay, drawBuffer, TermWin.gc,
2282 Col2Pixel(R->oldcursor.col), 2246 Col2Pixel(oldcursor.col),
2283 Row2Pixel(R->oldcursor.row), 2247 Row2Pixel(oldcursor.row),
2284 (unsigned int)(Width2Pixel(cursorwidth) - 1), 2248 (unsigned int)(Width2Pixel(cursorwidth) - 1),
2285 (unsigned int)(Height2Pixel(1) - R->TermWin.lineSpace - 1)); 2249 (unsigned int)(Height2Pixel(1) - TermWin.lineSpace - 1));
2286 } 2250 }
2287 } 2251 }
2288/* 2252
2253 /*
2289 * H: cleanup selection 2254 * H: cleanup selection
2290 */ 2255 */
2291 rxvt_scr_reverse_selection(aR); 2256 rxvt_scr_reverse_selection (this);
2292 2257
2293/* 2258 /*
2294 * I: other general cleanup 2259 * I: other general cleanup
2295 */ 2260 */
2296 if (clearfirst && R->TermWin.int_bwidth) 2261 if (clearfirst && TermWin.int_bwidth)
2297 /* 2262 /*
2298 * clear the whole screen height, note that width == 0 is treated 2263 * clear the whole screen height, note that width == 0 is treated
2299 * specially by XClearArea 2264 * specially by XClearArea
2300 */ 2265 */
2301 XClearArea(R->Xdisplay, R->TermWin.vt, 0, 0, 2266 XClearArea(Xdisplay, TermWin.vt, 0, 0,
2302 (unsigned int)R->TermWin.int_bwidth, 2267 (unsigned int)TermWin.int_bwidth,
2303 (unsigned int)TermWin_TotalHeight(), False); 2268 (unsigned int)TermWin_TotalHeight(), False);
2304 if (clearlast && R->TermWin.int_bwidth) 2269 if (clearlast && TermWin.int_bwidth)
2305 /* 2270 /*
2306 * clear the whole screen height, note that width == 0 is treated 2271 * clear the whole screen height, note that width == 0 is treated
2307 * specially by XClearArea 2272 * specially by XClearArea
2308 */ 2273 */
2309 XClearArea(R->Xdisplay, R->TermWin.vt, 2274 XClearArea(Xdisplay, TermWin.vt,
2310 R->TermWin.width + R->TermWin.int_bwidth, 0, 2275 TermWin.width + TermWin.int_bwidth, 0,
2311 (unsigned int)R->TermWin.int_bwidth, 2276 (unsigned int)TermWin.int_bwidth,
2312 (unsigned int)TermWin_TotalHeight(), False); 2277 (unsigned int)TermWin_TotalHeight(), False);
2313 if (refresh_type & SMOOTH_REFRESH) 2278 if (refresh_type & SMOOTH_REFRESH)
2314 XSync(R->Xdisplay, False); 2279 XSync(Xdisplay, False);
2315 2280
2316 R->num_scr = 0; 2281 num_scr = 0;
2317 R->num_scr_allow = 1; 2282 num_scr_allow = 1;
2318 R->want_refresh = 0; /* screen is current */ 2283 want_refresh = 0; /* screen is current */
2319} 2284}
2320/* ------------------------------------------------------------------------- */
2321 2285
2322/* EXTPROTO */ 2286/* ------------------------------------------------------------------------- */
2323void 2287void
2324rxvt_scr_clear(pR) 2288rxvt_term::scr_clear()
2325{ 2289{
2326 if (!R->TermWin.mapped) 2290 if (!TermWin.mapped)
2327 return; 2291 return;
2292
2328 R->num_scr_allow = 0; 2293 num_scr_allow = 0;
2329 R->want_refresh = 1; 2294 want_refresh = 1;
2330#ifdef TRANSPARENT 2295#ifdef TRANSPARENT
2331 if ((R->Options & Opt_transparent) && (R->am_pixmap_trans == 0)) { 2296 if ((Options & Opt_transparent) && (am_pixmap_trans == 0))
2332 int i; 2297 {
2298 int i;
2333 2299
2334 if (!(R->Options & Opt_transparent_all)) 2300 if (!(Options & Opt_transparent_all))
2335 i = 0; 2301 i = 0;
2336 else 2302 else
2337 i = (int)(sizeof(R->TermWin.parent) / sizeof(Window)); 2303 i = (int)(sizeof(TermWin.parent) / sizeof(Window));
2338 for (; i--;) 2304
2305 while (i--)
2339 if (R->TermWin.parent[i] != None) 2306 if (TermWin.parent[i] != None)
2340 XClearWindow(R->Xdisplay, R->TermWin.parent[i]); 2307 XClearWindow(Xdisplay, TermWin.parent[i]);
2341 } 2308 }
2342#endif 2309#endif
2310
2343 XClearWindow(R->Xdisplay, R->TermWin.vt); 2311 XClearWindow (Xdisplay, TermWin.vt);
2344} 2312}
2345 2313
2346/* ------------------------------------------------------------------------- */ 2314/* ------------------------------------------------------------------------- */
2347/* INTPROTO */ 2315/* INTPROTO */
2348void 2316void
2362 i = end_row; 2330 i = end_row;
2363 } 2331 }
2364 end_row += R->TermWin.nrow; 2332 end_row += R->TermWin.nrow;
2365 for (; i < row && i < end_row; i++, col = 0) 2333 for (; i < row && i < end_row; i++, col = 0)
2366 for (srp = R->screen.rend[i]; col < R->TermWin.ncol; col++) 2334 for (srp = R->screen.rend[i]; col < R->TermWin.ncol; col++)
2367#ifndef OPTION_HC
2368 srp[col] ^= RS_RVid; 2335 srp[col] ^= RS_RVid;
2369#else
2370 srp[col] ^= RS_Blink;
2371#endif
2372 if (i == row && i < end_row) 2336 if (i == row && i < end_row)
2373 for (srp = R->screen.rend[i]; col < R->selection.end.col; col++) 2337 for (srp = R->screen.rend[i]; col < R->selection.end.col; col++)
2374#ifndef OPTION_HC
2375 srp[col] ^= RS_RVid; 2338 srp[col] ^= RS_RVid;
2376#else
2377 srp[col] ^= RS_Blink;
2378#endif
2379 } 2339 }
2380} 2340}
2381 2341
2382/* ------------------------------------------------------------------------- */ 2342/* ------------------------------------------------------------------------- */
2383/* 2343/*
2456rxvt_term::paste (const unsigned char *data, unsigned int len) 2416rxvt_term::paste (const unsigned char *data, unsigned int len)
2457{ 2417{
2458 unsigned int i, j, n; 2418 unsigned int i, j, n;
2459 unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE); 2419 unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE);
2460 2420
2421#if 0
2422 /* a paste should act like the user is typing, so check scrollTtyKeypress */
2423 ZERO_SCROLLBACK (r);
2424#endif
2425
2461 /* convert normal newline chars into common keyboard Return key sequence */ 2426 /* convert normal newline chars into common keyboard Return key sequence */
2462 for (i = 0; i < len; i += PROP_SIZE) 2427 for (i = 0; i < len; i += PROP_SIZE)
2463 { 2428 {
2464 n = min (len - i, PROP_SIZE); 2429 n = min (len - i, PROP_SIZE);
2465 MEMCPY (ds, data + i, n); 2430 MEMCPY (ds, data + i, n);
2484rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) 2449rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop)
2485{ 2450{
2486 long nread = 0; 2451 long nread = 0;
2487 unsigned long bytes_after; 2452 unsigned long bytes_after;
2488 XTextProperty ct; 2453 XTextProperty ct;
2489 int dummy_count;
2490 char **cl;
2491 2454
2492 D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); 2455 D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait));
2493 2456
2494 if (prop == None) /* check for failed XConvertSelection */ 2457 if (prop == None) /* check for failed XConvertSelection */
2495 { 2458 {
2498 int selnum = R->selection_type & Sel_whereMask; 2461 int selnum = R->selection_type & Sel_whereMask;
2499 2462
2500 R->selection_type = 0; 2463 R->selection_type = 0;
2501 if (selnum != Sel_direct) 2464 if (selnum != Sel_direct)
2502 rxvt_selection_request_other(aR_ XA_STRING, selnum); 2465 rxvt_selection_request_other(aR_ XA_STRING, selnum);
2466 }
2467
2468 if ((R->selection_type & Sel_UTF8String))
2469 {
2470 int selnum = R->selection_type & Sel_whereMask;
2471
2472 R->selection_type = Sel_CompoundText;
2473 if (selnum != Sel_direct)
2474 rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], selnum);
2475 else
2476 R->selection_type = 0;
2503 } 2477 }
2504 2478
2505 return 0; 2479 return 0;
2506 } 2480 }
2507 2481
2542 nread = -1; /* discount any previous stuff */ 2516 nread = -1; /* discount any previous stuff */
2543 break; 2517 break;
2544 } 2518 }
2545 2519
2546 nread += ct.nitems; 2520 nread += ct.nitems;
2521
2522 char **cl;
2523 int cr;
2547 if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, 2524 if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl,
2548 &dummy_count) == Success && cl) 2525 &cr) >= 0 && cl)
2549 { 2526 {
2527 for (int i = 0; i < cr; i++)
2550 R->paste ((unsigned char *)cl[0], STRLEN (cl[0])); 2528 R->paste ((unsigned char *)cl[i], STRLEN (cl[i]));
2529
2551 XFreeStringList (cl); 2530 XFreeStringList (cl);
2552 } 2531 }
2553 else 2532 else
2554 R->paste (ct.value, ct.nitems); 2533 R->paste (ct.value, ct.nitems);
2555 2534
2570} 2549}
2571 2550
2572void 2551void
2573rxvt_term::incr_cb (time_watcher &w) 2552rxvt_term::incr_cb (time_watcher &w)
2574{ 2553{
2575 w.stop ();
2576 selection_wait = Sel_none; 2554 selection_wait = Sel_none;
2577 2555
2578 rxvt_print_error("data loss: timeout on INCR selection paste"); 2556 rxvt_print_error ("data loss: timeout on INCR selection paste");
2579} 2557}
2580 2558
2581/* 2559/*
2582 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> 2560 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2583 */ 2561 */
2649 int i; 2627 int i;
2650 2628
2651 R->selection_request_time = tm; 2629 R->selection_request_time = tm;
2652 R->selection_wait = Sel_normal; 2630 R->selection_wait = Sel_normal;
2653 for (i = Sel_Primary; i <= Sel_Clipboard; i++) { 2631 for (i = Sel_Primary; i <= Sel_Clipboard; i++) {
2632#if X_HAVE_UTF8_STRING
2633 R->selection_type = Sel_UTF8String;
2634 if (rxvt_selection_request_other(aR_ R->xa[XA_UTF8_STRING], i))
2635 return;
2636#else
2654 R->selection_type = Sel_CompoundText; 2637 R->selection_type = Sel_CompoundText;
2655 if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) 2638 if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i))
2656 return; 2639 return;
2640#endif
2657 } 2641 }
2658 } 2642 }
2659 R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ 2643 R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */
2660 D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); 2644 D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0"));
2661 rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); 2645 rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False);
2793 { 2777 {
2794 free (new_selection_text); 2778 free (new_selection_text);
2795 return; 2779 return;
2796 } 2780 }
2797 2781
2798 // due to MB_MAX_CUR, selection wastage is usually high 2782 // due to MB_MAX_CUR, selection wastage is usually high, so realloc
2799 if (str - (char *)new_selection_text > 1024) 2783 if (str - (char *)new_selection_text > 1024)
2800 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); 2784 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1);
2801 2785
2802 R->selection.len = i; 2786 R->selection.len = i;
2787
2803 if (R->selection.text) 2788 if (R->selection.text)
2804 free (R->selection.text); 2789 free (R->selection.text);
2805 2790
2806 R->selection.text = new_selection_text; 2791 R->selection.text = new_selection_text;
2807 2792
2808 XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); 2793 XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm);
2809 if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) 2794 if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt)
2810 rxvt_print_error("can't get primary selection"); 2795 rxvt_print_error("can't get primary selection");
2796
2797
2798 {
2799 XTextProperty ct;
2800 char *cl = (char *)R->selection.text;
2801
2802 if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, XStringStyle, &ct) >= 0)
2803 {
2804 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8,
2805 PropModeReplace, ct.value, ct.nitems);
2806 XFree (ct.value);
2807 }
2808 else
2811 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, 2809 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8,
2812 PropModeReplace, R->selection.text, (int)R->selection.len); 2810 PropModeReplace, R->selection.text, (int)R->selection.len);
2811 }
2812
2813 R->selection_time = tm; 2813 R->selection_time = tm;
2814 D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); 2814 D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len));
2815} 2815}
2816 2816
2817/* ------------------------------------------------------------------------- */ 2817/* ------------------------------------------------------------------------- */
2818/* 2818/*
2819 * Mark or select text based upon number of clicks: 1, 2, or 3 2819 * Mark or select text based upon number of clicks: 1, 2, or 3
2820 * EXT: button 1 press 2820 * EXT: button 1 press
2821 */ 2821 */
2822/* EXTPROTO */
2823void 2822void
2824rxvt_selection_click(pR_ int clicks, int x, int y) 2823rxvt_term::selection_click (int clicks, int x, int y)
2825{ 2824{
2826 D_SELECT((stderr, "rxvt_selection_click(%d, %d, %d)", clicks, x, y)); 2825 D_SELECT((stderr, "rxvt_selection_click(%d, %d, %d)", clicks, x, y));
2827 2826
2828 clicks = ((clicks - 1) % 3) + 1; 2827 clicks = ((clicks - 1) % 3) + 1;
2829 R->selection.clicks = clicks; /* save clicks so extend will work */ 2828 selection.clicks = clicks; /* save clicks so extend will work */
2830 2829
2831 rxvt_selection_start_colrow(aR_ Pixel2Col(x), Pixel2Row(y)); 2830 rxvt_selection_start_colrow (this, Pixel2Col(x), Pixel2Row(y));
2831
2832 if (clicks == 2 || clicks == 3) 2832 if (clicks == 2 || clicks == 3)
2833 rxvt_selection_extend_colrow(aR_ R->selection.mark.col, 2833 rxvt_selection_extend_colrow (this, selection.mark.col,
2834 R->selection.mark.row
2835 + R->TermWin.view_start, 2834 selection.mark.row + TermWin.view_start,
2836 0, /* button 3 */ 2835 0, /* button 3 */
2837 1, /* button press */ 2836 1, /* button press */
2838 0); /* click change */ 2837 0); /* click change */
2839} 2838}
2840 2839
2841/* ------------------------------------------------------------------------- */ 2840/* ------------------------------------------------------------------------- */
2842/* 2841/*
2843 * Mark a selection at the specified col/row 2842 * Mark a selection at the specified col/row
2953 * EXT: button 3 press; button 1 or 3 drag 2952 * EXT: button 3 press; button 1 or 3 drag
2954 * flag == 0 ==> button 1 2953 * flag == 0 ==> button 1
2955 * flag == 1 ==> button 3 press 2954 * flag == 1 ==> button 3 press
2956 * flag == 2 ==> button 3 motion 2955 * flag == 2 ==> button 3 motion
2957 */ 2956 */
2958/* EXTPROTO */
2959void 2957void
2960rxvt_selection_extend(pR_ int x, int y, int flag) 2958rxvt_term::selection_extend (int x, int y, int flag)
2961{ 2959{
2962 int col, row; 2960 int col, row;
2963 2961
2964 col = Pixel2Col(x); 2962 col = Pixel2Col(x);
2965 row = Pixel2Row(y); 2963 row = Pixel2Row(y);
2966 MAX_IT(row, 0); 2964 MAX_IT(row, 0);
2967 MIN_IT(row, (int)R->TermWin.nrow - 1); 2965 MIN_IT(row, (int)TermWin.nrow - 1);
2968 MAX_IT(col, 0); 2966 MAX_IT(col, 0);
2969 MIN_IT(col, (int)R->TermWin.ncol); 2967 MIN_IT(col, (int)TermWin.ncol);
2968
2970#ifndef NO_NEW_SELECTION 2969#ifndef NO_NEW_SELECTION
2971/* 2970 /*
2972 * If we're selecting characters (single click) then we must check first 2971 * If we're selecting characters (single click) then we must check first
2973 * if we are at the same place as the original mark. If we are then 2972 * if we are at the same place as the original mark. If we are then
2974 * select nothing. Otherwise, if we're to the right of the mark, you have to 2973 * select nothing. Otherwise, if we're to the right of the mark, you have to
2975 * be _past_ a character for it to be selected. 2974 * be _past_ a character for it to be selected.
2976 */ 2975 */
2977 if (R->selection_style != OLD_SELECT) { 2976 if (selection_style != OLD_SELECT)
2977 {
2978 if (((R->selection.clicks % 3) == 1) && !flag 2978 if (((selection.clicks % 3) == 1) && !flag
2979 && (col == R->selection.mark.col 2979 && (col == selection.mark.col
2980 && (row == R->selection.mark.row + R->TermWin.view_start))) { 2980 && (row == selection.mark.row + TermWin.view_start)))
2981 {
2981 /* select nothing */ 2982 /* select nothing */
2982 R->selection.beg.row = R->selection.end.row = 0; 2983 selection.beg.row = selection.end.row = 0;
2983 R->selection.beg.col = R->selection.end.col = 0; 2984 selection.beg.col = selection.end.col = 0;
2984 R->selection.clicks = 4; 2985 selection.clicks = 4;
2985 R->want_refresh = 1; 2986 want_refresh = 1;
2986 D_SELECT((stderr, "rxvt_selection_extend() R->selection.clicks = 4")); 2987 D_SELECT((stderr, "rxvt_selection_extend() selection.clicks = 4"));
2987 return; 2988 return;
2988 } 2989 }
2989 } 2990 }
2990#endif 2991#endif
2991 if (R->selection.clicks == 4) 2992 if (selection.clicks == 4)
2992 R->selection.clicks = 1; 2993 selection.clicks = 1;
2994
2993 rxvt_selection_extend_colrow(aR_ col, row, !!flag, /* ? button 3 */ 2995 rxvt_selection_extend_colrow (this, col, row, !!flag, /* ? button 3 */
2994 flag == 1 ? 1 : 0, /* ? button press */ 2996 flag == 1 ? 1 : 0, /* ? button press */
2995 0); /* no click change */ 2997 0); /* no click change */
2996} 2998}
2997 2999
2998/* ------------------------------------------------------------------------- */ 3000/* ------------------------------------------------------------------------- */
2999/* 3001/*
3000 * Extend the selection to the specified col/row 3002 * Extend the selection to the specified col/row
3254/* ------------------------------------------------------------------------- */ 3256/* ------------------------------------------------------------------------- */
3255/* 3257/*
3256 * Double click on button 3 when already selected 3258 * Double click on button 3 when already selected
3257 * EXT: button 3 double click 3259 * EXT: button 3 double click
3258 */ 3260 */
3259/* EXTPROTO */
3260void 3261void
3261rxvt_selection_rotate(pR_ int x, int y) 3262rxvt_term::selection_rotate (int x, int y)
3262{ 3263{
3263 R->selection.clicks = R->selection.clicks % 3 + 1; 3264 selection.clicks = selection.clicks % 3 + 1;
3264 rxvt_selection_extend_colrow(aR_ Pixel2Col(x), Pixel2Row(y), 1, 0, 1); 3265 rxvt_selection_extend_colrow (this, Pixel2Col(x), Pixel2Row(y), 1, 0, 1);
3265} 3266}
3266 3267
3267/* ------------------------------------------------------------------------- */ 3268/* ------------------------------------------------------------------------- */
3268/* 3269/*
3269 * On some systems, the Atom typedef is 64 bits wide. We need to have a type 3270 * On some systems, the Atom typedef is 64 bits wide. We need to have a type
3270 * that is exactly 32 bits wide, because a format of 64 is not allowed by 3271 * that is exactly 32 bits wide, because a format of 64 is not allowed by
3271 * the X11 protocol. 3272 * the X11 protocol.
3272 */ 3273 */
3273typedef CARD32 Atom32; 3274typedef CARD32 Atom32;
3274 3275
3275/* ------------------------------------------------------------------------- */ 3276/* ------------------------------------------------------------------------- */
3276/* 3277/*
3277 * Respond to a request for our current selection 3278 * Respond to a request for our current selection
3278 * EXT: SelectionRequest 3279 * EXT: SelectionRequest
3280/* EXTPROTO */ 3281/* EXTPROTO */
3281void 3282void
3282rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) 3283rxvt_selection_send(pR_ const XSelectionRequestEvent *rq)
3283{ 3284{
3284 XSelectionEvent ev; 3285 XSelectionEvent ev;
3285#ifdef USE_XIM
3286 Atom32 target_list[4];
3287#else
3288 Atom32 target_list[3];
3289#endif
3290 Atom target;
3291 XTextProperty ct; 3286 XTextProperty ct;
3292 XICCEncodingStyle style; 3287 XICCEncodingStyle style;
3293 char *cl[2], dummy[1]; 3288 Atom target;
3294 3289
3295 ev.type = SelectionNotify; 3290 ev.type = SelectionNotify;
3296 ev.property = None; 3291 ev.property = None;
3297 ev.display = rq->display; 3292 ev.display = rq->display;
3298 ev.requestor = rq->requestor; 3293 ev.requestor = rq->requestor;
3299 ev.selection = rq->selection; 3294 ev.selection = rq->selection;
3300 ev.target = rq->target; 3295 ev.target = rq->target;
3301 ev.time = rq->time; 3296 ev.time = rq->time;
3302 3297
3303 if (rq->target == R->xa[XA_TARGETS]) { 3298 if (rq->target == R->xa[XA_TARGETS]) {
3299 Atom32 target_list[5];
3300 Atom32 *target = target_list;
3301
3304 target_list[0] = (Atom32) R->xa[XA_TARGETS]; 3302 *target++ = (Atom32) R->xa[XA_TARGETS];
3305 target_list[1] = (Atom32) XA_STRING; 3303 *target++ = (Atom32) XA_STRING;
3306 target_list[2] = (Atom32) R->xa[XA_TEXT]; 3304 *target++ = (Atom32) R->xa[XA_TEXT];
3307#ifdef USE_XIM
3308 target_list[3] = (Atom32) R->xa[XA_COMPOUND_TEXT]; 3305 *target++ = (Atom32) R->xa[XA_COMPOUND_TEXT];
3306#if X_HAVE_UTF8_STRING
3307 *target++ = (Atom32) R->xa[XA_UTF8_STRING];
3309#endif 3308#endif
3310 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, 3309 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM,
3311 (8 * sizeof(target_list[0])), PropModeReplace, 3310 (8 * sizeof(target_list[0])), PropModeReplace,
3312 (unsigned char *)target_list, 3311 (unsigned char *)target_list,
3313 (sizeof(target_list) / sizeof(target_list[0]))); 3312 target - target_list);
3314 ev.property = rq->property; 3313 ev.property = rq->property;
3315 } else if (rq->target == R->xa[XA_MULTIPLE]) { 3314 } else if (rq->target == R->xa[XA_MULTIPLE]) {
3316 /* TODO: Handle MULTIPLE */ 3315 /* TODO: Handle MULTIPLE */
3317 } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { 3316 } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) {
3318 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, 3317 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER,
3319 (8 * sizeof(Time)), PropModeReplace, 3318 (8 * sizeof(Time)), PropModeReplace,
3320 (unsigned char *)&R->selection_time, 1); 3319 (unsigned char *)&R->selection_time, 1);
3321 ev.property = rq->property; 3320 ev.property = rq->property;
3322 } else if (rq->target == XA_STRING 3321 } else if (rq->target == XA_STRING
3322 || rq->target == R->xa[XA_TEXT]
3323 || rq->target == R->xa[XA_COMPOUND_TEXT] 3323 || rq->target == R->xa[XA_COMPOUND_TEXT]
3324 || rq->target == R->xa[XA_TEXT]) { 3324 || rq->target == R->xa[XA_UTF8_STRING]
3325#ifdef USE_XIM 3325 ) {
3326 short freect = 0; 3326 short freect = 0;
3327#endif
3328 int selectlen; 3327 int selectlen;
3328 char *cl;
3329 3329
3330#ifdef USE_XIM 3330 target = rq->target;
3331
3331 if (rq->target != XA_STRING) { 3332 if (target == XA_STRING)
3333 // we actually don't do XA_STRING, but who cares, as i18n clients
3334 // will ask for another format anyways.
3335 style = XStringStyle;
3336 else if (target == R->xa[XA_TEXT])
3337 style = XTextStyle;
3338 else if (target == R->xa[XA_COMPOUND_TEXT])
3339 style = XCompoundTextStyle;
3340#if X_HAVE_UTF8_STRING
3341 else if (target == R->xa[XA_UTF8_STRING])
3342 style = XUTF8StringStyle;
3343#endif
3344 else
3345 {
3332 target = R->xa[XA_COMPOUND_TEXT]; 3346 target = R->xa[XA_COMPOUND_TEXT];
3333 style = (rq->target == R->xa[XA_COMPOUND_TEXT])
3334 ? XCompoundTextStyle : XStdICCTextStyle;
3335 } else
3336#endif
3337 {
3338 target = XA_STRING;
3339 style = XStringStyle; 3347 style = XCompoundTextStyle;
3340 } 3348 }
3349
3341 if (R->selection.text) { 3350 if (R->selection.text) {
3342 cl[0] = (char *)R->selection.text; 3351 cl = (char *)R->selection.text;
3343 selectlen = R->selection.len; 3352 selectlen = R->selection.len;
3344 } else { 3353 } else {
3345 cl[0] = dummy; 3354 cl = "";
3346 *dummy = '\0';
3347 selectlen = 0; 3355 selectlen = 0;
3348 } 3356 }
3349#ifdef USE_XIM 3357
3350 if (XmbTextListToTextProperty(R->Xdisplay, cl, 1, style, &ct) 3358 if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, style, &ct) >= 0)
3351 == Success) /* if we failed to convert then send it raw */
3352 freect = 1; 3359 freect = 1;
3353 else 3360 else
3354#endif
3355 { 3361 {
3362 /* if we failed to convert then send it raw */
3356 ct.value = (unsigned char *)cl[0]; 3363 ct.value = (unsigned char *)cl;
3357 ct.nitems = selectlen; 3364 ct.nitems = selectlen;
3358 } 3365 }
3366
3359 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, 3367 XChangeProperty(R->Xdisplay, rq->requestor, rq->property,
3360 target, 8, PropModeReplace, 3368 target, 8, PropModeReplace,
3361 ct.value, (int)ct.nitems); 3369 ct.value, (int)ct.nitems);
3362 ev.property = rq->property; 3370 ev.property = rq->property;
3363#ifdef USE_XIM 3371
3364 if (freect) 3372 if (freect)
3365 XFree(ct.value); 3373 XFree (ct.value);
3366#endif
3367 } 3374 }
3368 XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); 3375 XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev);
3369} 3376}
3370 3377
3371/* ------------------------------------------------------------------------- * 3378/* ------------------------------------------------------------------------- *
3373 * ------------------------------------------------------------------------- */ 3380 * ------------------------------------------------------------------------- */
3374 3381
3375/* 3382/*
3376 * return col/row values corresponding to x/y pixel values 3383 * return col/row values corresponding to x/y pixel values
3377 */ 3384 */
3378/* EXTPROTO */
3379void 3385void
3380rxvt_pixel_position(pR_ int *x, int *y) 3386rxvt_term::pixel_position (int *x, int *y)
3381{ 3387{
3382 *x = Pixel2Col(*x); 3388 *x = Pixel2Col(*x);
3383/* MAX_IT(*x, 0); MIN_IT(*x, (int)R->TermWin.ncol - 1); */ 3389 /* MAX_IT(*x, 0); MIN_IT(*x, (int)R->TermWin.ncol - 1); */
3384 *y = Pixel2Row(*y); 3390 *y = Pixel2Row(*y);
3385/* MAX_IT(*y, 0); MIN_IT(*y, (int)R->TermWin.nrow - 1); */ 3391 /* MAX_IT(*y, 0); MIN_IT(*y, (int)R->TermWin.nrow - 1); */
3386} 3392}
3393
3387/* ------------------------------------------------------------------------- */ 3394/* ------------------------------------------------------------------------- */
3388#ifdef USE_XIM 3395#ifdef USE_XIM
3389/* EXTPROTO */
3390void 3396void
3391rxvt_setPosition(pR_ XPoint *pos) 3397rxvt_term::set_position (XPoint *pos)
3392{ 3398{
3393 XWindowAttributes xwa; 3399 XWindowAttributes xwa;
3394 3400
3395 XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &xwa); 3401 XGetWindowAttributes (Xdisplay, TermWin.vt, &xwa);
3396 pos->x = Col2Pixel(R->screen.cur.col) + xwa.x; 3402 pos->x = Col2Pixel (screen.cur.col) + xwa.x;
3397 pos->y = Height2Pixel((R->screen.cur.row + 1)) + xwa.y 3403 pos->y = Height2Pixel ((screen.cur.row + 1)) + xwa.y - TermWin.lineSpace;
3398 - R->TermWin.lineSpace;
3399} 3404}
3405
3400#endif 3406#endif
3401/* ------------------------------------------------------------------------- */ 3407/* ------------------------------------------------------------------------- */
3402 3408
3403/* ------------------------------------------------------------------------- * 3409/* ------------------------------------------------------------------------- *
3404 * DEBUG ROUTINES * 3410 * DEBUG ROUTINES *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines