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.10 by pcg, Thu Dec 18 08:06:46 2003 UTC vs.
Revision 1.18 by pcg, Wed Jan 28 23:40:50 2004 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*--------------------------------*-C-*--------------------------------------*
2 * File: screen.c 2 * File: screen.c
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * $Id: screen.C,v 1.10 2003/12/18 08:06:46 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. */
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 * ------------------------------------------------------------------------- */
1679 1652
1680/* 1653/*
1681 * Refresh an area 1654 * Refresh an area
1684 PART_BEG = 0, 1657 PART_BEG = 0,
1685 PART_END, 1658 PART_END,
1686 RC_COUNT 1659 RC_COUNT
1687}; 1660};
1688 1661
1689/* EXTPROTO */
1690void 1662void
1691rxvt_scr_expose(pR_ int x, int y, int width, int height, Bool refresh) 1663rxvt_term::scr_expose (int x, int y, int width, int height, bool refresh)
1692{ 1664{
1693 int i; 1665 int i;
1694 row_col_t rc[RC_COUNT]; 1666 row_col_t rc[RC_COUNT];
1695 1667
1696 if (R->drawn_text == NULL) /* sanity check */ 1668 if (drawn_text == NULL) /* sanity check */
1697 return; 1669 return;
1698 1670
1699#ifdef DEBUG_STRICT 1671#ifdef DEBUG_STRICT
1700 x = max(x, (int)R->TermWin.int_bwidth); 1672 x = max(x, (int)TermWin.int_bwidth);
1701 x = min(x, (int)R->TermWin.width); 1673 x = min(x, (int)TermWin.width);
1702 y = max(y, (int)R->TermWin.int_bwidth); 1674 y = max(y, (int)TermWin.int_bwidth);
1703 y = min(y, (int)R->TermWin.height); 1675 y = min(y, (int)TermWin.height);
1704#endif 1676#endif
1705 1677
1706/* round down */ 1678/* round down */
1707 rc[PART_BEG].col = Pixel2Col(x); 1679 rc[PART_BEG].col = Pixel2Col(x);
1708 rc[PART_BEG].row = Pixel2Row(y); 1680 rc[PART_BEG].row = Pixel2Row(y);
1709/* round up */ 1681/* round up */
1710 rc[PART_END].col = Pixel2Width(x + width + R->TermWin.fwidth - 1); 1682 rc[PART_END].col = Pixel2Width(x + width + TermWin.fwidth - 1);
1711 rc[PART_END].row = Pixel2Row(y + height + R->TermWin.fheight - 1); 1683 rc[PART_END].row = Pixel2Row(y + height + TermWin.fheight - 1);
1712 1684
1713/* sanity checks */ 1685/* sanity checks */
1714 for (i = PART_BEG; i < RC_COUNT; i++) { 1686 for (i = PART_BEG; i < RC_COUNT; i++)
1687 {
1715 MIN_IT(rc[i].col, R->TermWin.ncol - 1); 1688 MIN_IT(rc[i].col, TermWin.ncol - 1);
1716 MIN_IT(rc[i].row, R->TermWin.nrow - 1); 1689 MIN_IT(rc[i].row, TermWin.nrow - 1);
1717 } 1690 }
1718 1691
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)); 1692 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 1693
1721 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1694 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1722 fill_text (&(R->drawn_text[i][rc[PART_BEG].col]), 0, 1695 fill_text (&(drawn_text[i][rc[PART_BEG].col]), 0,
1723 (rc[PART_END].col - rc[PART_BEG].col + 1)); 1696 (rc[PART_END].col - rc[PART_BEG].col + 1));
1724 1697
1725 if (refresh) 1698 if (refresh)
1726 rxvt_scr_refresh(aR_ SLOW_REFRESH | REFRESH_BOUNDS); 1699 scr_refresh (SLOW_REFRESH | REFRESH_BOUNDS);
1727} 1700}
1728 1701
1729/* ------------------------------------------------------------------------- */ 1702/* ------------------------------------------------------------------------- */
1730/* 1703/*
1731 * Refresh the entire screen 1704 * Refresh the entire screen
1732 */ 1705 */
1733/* EXTPROTO */
1734void 1706void
1735rxvt_scr_touch(pR_ Bool refresh) 1707rxvt_term::scr_touch (bool refresh)
1736{ 1708{
1737 rxvt_scr_expose(aR_ 0, 0, R->TermWin.width, R->TermWin.height, refresh); 1709 scr_expose (0, 0, TermWin.width, TermWin.height, refresh);
1738} 1710}
1739 1711
1740/* ------------------------------------------------------------------------- */ 1712/* ------------------------------------------------------------------------- */
1741/* 1713/*
1742 * Move the display so that the line represented by scrollbar value Y is at 1714 * Move the display so that the line represented by scrollbar value Y is at
1861 * Refresh the screen 1833 * Refresh the screen
1862 * R->drawn_text/R->drawn_rend contain the screen information before the update. 1834 * 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. 1835 * R->screen.text/R->screen.rend contain what the screen will change to.
1864 */ 1836 */
1865 1837
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) \ 1838#define FONT_WIDTH(X, Y) \
1876 (X)->per_char[(Y) - (X)->min_char_or_byte2].width 1839 (X)->per_char[(Y) - (X)->min_char_or_byte2].width
1877#define FONT_RBEAR(X, Y) \ 1840#define FONT_RBEAR(X, Y) \
1878 (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing 1841 (X)->per_char[(Y) - (X)->min_char_or_byte2].rbearing
1879#define FONT_LBEAR(X, Y) \ 1842#define FONT_LBEAR(X, Y) \
1880 (X)->per_char[(Y) - (X)->min_char_or_byte2].lbearing 1843 (X)->per_char[(Y) - (X)->min_char_or_byte2].lbearing
1881#define IS_FONT_CHAR(X, Y) \ 1844#define IS_FONT_CHAR(X, Y) \
1882 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2) 1845 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2)
1883 1846
1884/* EXTPROTO */
1885void 1847void
1886rxvt_scr_refresh(pR_ unsigned char refresh_type) 1848rxvt_term::scr_refresh (unsigned char refresh_type)
1887{ 1849{
1888 unsigned char clearfirst, /* first character writes before cell */ 1850 unsigned char clearfirst, /* first character writes before cell */
1889 clearlast, /* last character writes beyond cell */ 1851 clearlast, /* last character writes beyond cell */
1890 must_clear, /* use draw_string not draw_image_string */ 1852 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 */ 1853 rvid, /* reverse video this position */
1895 wbyte, /* we're in multibyte */
1896 showcursor; /* show the cursor */ 1854 showcursor; /* show the cursor */
1897 int fore, back; /* desired foreground/background */
1898 int16_t col, row, /* column/row we're processing */ 1855 int16_t col, row, /* column/row we're processing */
1899 ocrow; /* old cursor row */ 1856 ocrow; /* old cursor row */
1900 int cursorwidth; 1857 int cursorwidth;
1901 int i, /* tmp */ 1858 int i, /* tmp */
1902 row_offset; /* basic offset in screen structure */ 1859 row_offset; /* basic offset in screen structure */
1904 rend_t cc1; /* store colours at cursor position(s) */ 1861 rend_t cc1; /* store colours at cursor position(s) */
1905 rend_t cc2; /* store colours at cursor position(s) */ 1862 rend_t cc2; /* store colours at cursor position(s) */
1906#endif 1863#endif
1907 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ 1864 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */
1908 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ 1865 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */
1909 char *buffer; /* local copy of R->buffer */
1910 1866
1911 if (refresh_type == NO_REFRESH || !R->TermWin.mapped) 1867 if (refresh_type == NO_REFRESH || !TermWin.mapped)
1912 return; 1868 return;
1913 1869
1914 /* 1870 /*
1915 * A: set up vars 1871 * A: set up vars
1916 */ 1872 */
1917 clearfirst = clearlast = must_clear = wbyte = 0; 1873 clearfirst = clearlast = must_clear = 0;
1918#ifndef NO_BOLDFONT
1919 bfont = 0;
1920#endif
1921 1874
1922 if (R->currmaxcol < R->TermWin.ncol) 1875 if (currmaxcol < TermWin.ncol)
1923 { 1876 {
1924 R->currmaxcol = R->TermWin.ncol; 1877 currmaxcol = TermWin.ncol;
1925 R->buffer = (char *)rxvt_realloc (R->buffer, 1878 buffer = (char *)rxvt_realloc (buffer,
1926 sizeof(char) * (R->currmaxcol + 1) * MB_CUR_MAX); 1879 sizeof(char) * (currmaxcol + 1) * MB_CUR_MAX);
1927 } 1880 }
1928 1881
1929 buffer = R->buffer;
1930 R->refresh_count = 0; 1882 refresh_count = 0;
1931 1883
1932 row_offset = R->TermWin.saveLines - R->TermWin.view_start; 1884 row_offset = TermWin.saveLines - TermWin.view_start;
1933 1885
1934 if ((refresh_type & REFRESH_BOUNDS)) 1886 if ((refresh_type & REFRESH_BOUNDS))
1935 { 1887 {
1936 clearfirst = clearlast = 1; 1888 clearfirst = clearlast = 1;
1937 R->refresh_type &= ~REFRESH_BOUNDS; 1889 refresh_type &= ~REFRESH_BOUNDS;
1938 } 1890 }
1939 1891
1940#if defined(XPM_BACKGROUND) 1892#if defined(XPM_BACKGROUND)
1941 must_clear |= (R->bgPixmap.pixmap != None); 1893 must_clear |= (bgPixmap.pixmap != None);
1942#endif 1894#endif
1943#if defined(TRANSPARENT) 1895#if defined(TRANSPARENT)
1944 must_clear |= ((R->Options & Opt_transparent) && R->am_transparent); 1896 must_clear |= ((Options & Opt_transparent) && am_transparent);
1945#endif 1897#endif
1946 ocrow = R->oldcursor.row; /* is there an old outline cursor on screen? */ 1898 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1947 1899
1948/* 1900 /*
1949 * B: reverse any characters which are selected 1901 * B: reverse any characters which are selected
1950 */ 1902 */
1951 rxvt_scr_reverse_selection(aR); 1903 rxvt_scr_reverse_selection (this);
1952 1904
1953/* 1905 /*
1954 * C: set the cursor character(s) 1906 * C: set the cursor character(s)
1955 */ 1907 */
1956 { 1908 {
1957 unsigned char setoldcursor; 1909 unsigned char setoldcursor;
1958 rend_t ccol1, /* Cursor colour */ 1910 rend_t ccol1, /* Cursor colour */
1959 ccol2; /* Cursor colour2 */ 1911 ccol2; /* Cursor colour2 */
1960 1912
1961 showcursor = (R->screen.flags & Screen_VisibleCursor); 1913 showcursor = (screen.flags & Screen_VisibleCursor);
1962 cursorwidth = 0; 1914 cursorwidth = 0;
1963#ifdef CURSOR_BLINK 1915#ifdef CURSOR_BLINK
1964 if (R->hidden_cursor) 1916 if (hidden_cursor)
1965 showcursor = 0; 1917 showcursor = 0;
1966#endif 1918#endif
1967 1919
1968 cursorwidth = 0; 1920 cursorwidth = 0;
1969 1921
1970 if (showcursor) 1922 if (showcursor)
1971 { 1923 {
1972 cursorwidth++; 1924 cursorwidth++;
1973 1925
1974 srp = &(R->screen.rend[R->screen.cur.row + R->TermWin.saveLines] 1926 srp = &(screen.rend[screen.cur.row + TermWin.saveLines]
1975 [R->screen.cur.col]); 1927 [screen.cur.col]);
1976 1928
1977 if (showcursor && R->TermWin.focus) 1929 if (showcursor && TermWin.focus)
1978 { 1930 {
1979 *srp ^= RS_RVid; 1931 *srp ^= RS_RVid;
1980#ifndef NO_CURSORCOLOR 1932#ifndef NO_CURSORCOLOR
1981 cc1 = *srp & (RS_fgMask | RS_bgMask); 1933 cc1 = *srp & (RS_fgMask | RS_bgMask);
1982 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor)) 1934 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor))
1983 ccol1 = Color_cursor; 1935 ccol1 = Color_cursor;
1984 else 1936 else
1985#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 1937#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1986 ccol1 = GET_FGCOLOR(R->rstyle); 1938 ccol1 = GET_FGCOLOR(rstyle);
1987#else 1939#else
1988 ccol1 = Color_fg; 1940 ccol1 = Color_fg;
1989#endif 1941#endif
1990 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor2)) 1942 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor2))
1991 ccol2 = Color_cursor2; 1943 ccol2 = Color_cursor2;
1992 else 1944 else
1993#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 1945#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1994 ccol2 = GET_BGCOLOR(R->rstyle); 1946 ccol2 = GET_BGCOLOR(rstyle);
1995#else 1947#else
1996 ccol2 = Color_bg; 1948 ccol2 = Color_bg;
1997#endif 1949#endif
1998 *srp = SET_FGCOLOR(*srp, ccol1); 1950 *srp = SET_FGCOLOR(*srp, ccol1);
1999 *srp = SET_BGCOLOR(*srp, ccol2); 1951 *srp = SET_BGCOLOR(*srp, ccol2);
2000#endif 1952#endif
2001 } 1953 }
2002
2003 while (IS_WIDE (*srp))
2004 cursorwidth++, srp++;
2005 } 1954 }
2006 1955
2007 /* make sure no outline cursor is left around */ 1956 /* make sure no outline cursor is left around */
2008 setoldcursor = 0; 1957 setoldcursor = 0;
2009 if (ocrow != -1) { 1958 if (ocrow != -1) {
2010 if (R->screen.cur.row + R->TermWin.view_start != ocrow 1959 if (screen.cur.row + TermWin.view_start != ocrow
2011 || R->screen.cur.col != R->oldcursor.col) { 1960 || screen.cur.col != oldcursor.col) {
2012 if (ocrow < R->TermWin.nrow 1961 if (ocrow < TermWin.nrow
2013 && R->oldcursor.col < R->TermWin.ncol) { 1962 && oldcursor.col < TermWin.ncol) {
2014 R->drawn_rend[ocrow][R->oldcursor.col] ^= (RS_RVid | RS_Uline); 1963 drawn_rend[ocrow][oldcursor.col] ^= (RS_RVid | RS_Uline);
2015 } 1964 }
2016 if (R->TermWin.focus || !showcursor) 1965 if (TermWin.focus || !showcursor)
2017 R->oldcursor.row = -1; 1966 oldcursor.row = -1;
2018 else 1967 else
2019 setoldcursor = 1; 1968 setoldcursor = 1;
2020 } 1969 }
2021 } else if (!R->TermWin.focus) 1970 } else if (!TermWin.focus)
2022 setoldcursor = 1; 1971 setoldcursor = 1;
2023 if (setoldcursor) { 1972 if (setoldcursor) {
2024 if (R->screen.cur.row + R->TermWin.view_start >= R->TermWin.nrow) 1973 if (screen.cur.row + TermWin.view_start >= TermWin.nrow)
2025 R->oldcursor.row = -1; 1974 oldcursor.row = -1;
2026 else { 1975 else {
2027 R->oldcursor.row = R->screen.cur.row + R->TermWin.view_start; 1976 oldcursor.row = screen.cur.row + TermWin.view_start;
2028 R->oldcursor.col = R->screen.cur.col; 1977 oldcursor.col = screen.cur.col;
2029 } 1978 }
2030 } 1979 }
2031 } 1980 }
2032 1981
2033#ifndef NO_SLOW_LINK_SUPPORT 1982#ifndef NO_SLOW_LINK_SUPPORT
2034/* 1983 /*
2035 * D: CopyArea pass - very useful for slower links 1984 * D: CopyArea pass - very useful for slower links
2036 * This has been deliberately kept simple. 1985 * This has been deliberately kept simple.
2037 */ 1986 */
2038 i = R->num_scr; 1987 i = num_scr;
2039 if (refresh_type == FAST_REFRESH && R->num_scr_allow && i 1988 if (refresh_type == FAST_REFRESH && num_scr_allow && i
2040 && abs(i) < R->TermWin.nrow && !must_clear) 1989 && abs(i) < TermWin.nrow && !must_clear)
2041 { 1990 {
2042 int16_t nits; 1991 int16_t nits;
2043 int j; 1992 int j;
2044 rend_t *drp2; 1993 rend_t *drp2;
2045 text_t *dtp2; 1994 text_t *dtp2;
2046 int len, wlen; 1995 int len, wlen;
2047 1996
2048 j = R->TermWin.nrow; 1997 j = TermWin.nrow;
2049 wlen = len = -1; 1998 wlen = len = -1;
2050 row = i > 0 ? 0 : j - 1; 1999 row = i > 0 ? 0 : j - 1;
2051 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2000 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2052 { 2001 {
2053 if (row + i >= 0 && row + i < R->TermWin.nrow && row + i != ocrow) 2002 if (row + i >= 0 && row + i < TermWin.nrow && row + i != ocrow)
2054 { 2003 {
2055 stp = R->screen.text[row + row_offset]; 2004 stp = screen.text[row + row_offset];
2056 srp = R->screen.rend[row + row_offset]; 2005 srp = screen.rend[row + row_offset];
2057 dtp = R->drawn_text[row]; 2006 dtp = drawn_text[row];
2058 dtp2 = R->drawn_text[row + i]; 2007 dtp2 = drawn_text[row + i];
2059 drp = R->drawn_rend[row]; 2008 drp = drawn_rend[row];
2060 drp2 = R->drawn_rend[row + i]; 2009 drp2 = drawn_rend[row + i];
2061 2010
2062 for (nits = 0, col = R->TermWin.ncol; col--; ) 2011 for (nits = 0, col = TermWin.ncol; col--; )
2063 if (stp[col] != dtp2[col] || srp[col] != drp2[col]) 2012 if (stp[col] != dtp2[col] || srp[col] != drp2[col])
2064 nits--; 2013 nits--;
2065 else if (stp[col] != dtp[col] || srp[col] != drp[col]) 2014 else if (stp[col] != dtp[col] || srp[col] != drp[col])
2066 nits++; 2015 nits++;
2067 2016
2068 if (nits > 8) /* XXX: arbitrary choice */ 2017 if (nits > 8) /* XXX: arbitrary choice */
2069 { 2018 {
2070 for (col = R->TermWin.ncol; col--; ) 2019 for (col = TermWin.ncol; col--; )
2071 { 2020 {
2072 *dtp++ = *dtp2++; 2021 *dtp++ = *dtp2++;
2073 *drp++ = *drp2++; 2022 *drp++ = *drp2++;
2074 } 2023 }
2075 2024
2084 if (len != -1) 2033 if (len != -1)
2085 { 2034 {
2086 /* also comes here at end if needed because of >= above */ 2035 /* also comes here at end if needed because of >= above */
2087 if (wlen < len) 2036 if (wlen < len)
2088 SWAP_IT(wlen, len, int); 2037 SWAP_IT(wlen, len, int);
2038
2089 D_SCREEN((stderr, "rxvt_scr_refresh(): XCopyArea: %d -> %d (height: %d)", len + i, len, wlen - len + 1)); 2039 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, 2040 XCopyArea (Xdisplay, TermWin.vt, TermWin.vt,
2091 R->TermWin.gc, 0, Row2Pixel(len + i), 2041 TermWin.gc, 0, Row2Pixel (len + i),
2092 (unsigned int)TermWin_TotalWidth(), 2042 (unsigned int)TermWin_TotalWidth (),
2093 (unsigned int)Height2Pixel(wlen - len + 1), 2043 (unsigned int)Height2Pixel (wlen - len + 1),
2094 0, Row2Pixel(len)); 2044 0, Row2Pixel (len));
2095 len = -1; 2045 len = -1;
2096 } 2046 }
2097 } 2047 }
2098 } 2048 }
2099#endif 2049#endif
2100 2050
2101/* 2051 /*
2102 * E: main pass across every character 2052 * E: main pass across every character
2103 */ 2053 */
2104 for (row = 0; row < R->TermWin.nrow; row++) 2054 for (row = 0; row < TermWin.nrow; row++)
2105 { 2055 {
2106 stp = R->screen.text[row + row_offset]; 2056 stp = screen.text[row + row_offset];
2107 srp = R->screen.rend[row + row_offset]; 2057 srp = screen.rend[row + row_offset];
2108 dtp = R->drawn_text[row]; 2058 dtp = drawn_text[row];
2109 drp = R->drawn_rend[row]; 2059 drp = drawn_rend[row];
2110 2060
2111/* 2061 /*
2112 * E2: OK, now the real pass 2062 * E2: OK, now the real pass
2113 */ 2063 */
2114 int ypixel = (int)Row2Pixel(row); 2064 int ypixel = (int)Row2Pixel(row);
2115 2065
2116 for (col = 0; col < R->TermWin.ncol; col++) 2066 for (col = 0; col < TermWin.ncol; col++)
2117 { 2067 {
2118 /* compare new text with old - if exactly the same then continue */ 2068 /* compare new text with old - if exactly the same then continue */
2119 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2069 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2120 2070
2121 if (stp[col] == dtp[col] /* Must match characters to skip. */ 2071 if (stp[col] == dtp[col] /* Must match characters to skip. */
2137 2087
2138 int xpixel = Col2Pixel(col); 2088 int xpixel = Col2Pixel(col);
2139 2089
2140 // this loop looks very messy, it can probably be optimized 2090 // this loop looks very messy, it can probably be optimized
2141 // and cleaned a bit by you? 2091 // and cleaned a bit by you?
2142 for (i = 0; ++col < R->TermWin.ncol; ) 2092 for (i = 0; ++col < TermWin.ncol; )
2143 { 2093 {
2144 if (stp[col] == NOCHAR) 2094 if (stp[col] == NOCHAR)
2145 { 2095 {
2146 dtp[col] = stp[col]; 2096 dtp[col] = stp[col];
2147 drp[col] = rend; 2097 drp[col] = rend;
2151 i++; 2101 i++;
2152 2102
2153 continue; 2103 continue;
2154 } 2104 }
2155 2105
2156 if (((rend ^ srp[col]) & ~RS_wide) != 0) 2106 if (rend != srp[col])
2157 break; 2107 break;
2158 2108
2159 count++; 2109 count++;
2160 2110
2161 if (stp[col] != dtp[col] 2111 if (stp[col] != dtp[col]
2173 } 2123 }
2174 2124
2175 col--; /* went one too far. move back */ 2125 col--; /* went one too far. move back */
2176 count -= i; /* dump any matching trailing chars */ 2126 count -= i; /* dump any matching trailing chars */
2177 2127
2178/* 2128 /*
2179 * Determine the attributes for the string 2129 * Determine the attributes for the string
2180 */ 2130 */
2181 int fid = GET_FONT(rend); 2131 int fid = GET_FONT (rend);
2182 fore = GET_FGCOLOR(rend); 2132 int fore = GET_FGCOLOR (rend); // desired foreground
2183 back = GET_BGCOLOR(rend); 2133 int back = GET_BGCOLOR (rend); // desired background
2134
2184 rend = GET_ATTR(rend); 2135 rend = GET_ATTR (rend);
2185 2136
2186 rvid = (rend & RS_RVid) ? 1 : 0; 2137 rvid = !!(rend & RS_RVid);
2187#ifdef OPTION_HC 2138#ifdef OPTION_HC
2188 if (!rvid && (rend & RS_Blink)) 2139 if (!rvid && (rend & RS_Blink))
2189 { 2140 {
2190 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_HC)) 2141 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_HC))
2191 back = Color_HC; 2142 back = Color_HC;
2192 else 2143 else
2193 rvid = !rvid; /* fall back */ 2144 rvid = !rvid; /* fall back */
2194 } 2145 }
2195#endif 2146#endif
2196 if (rvid) 2147 if (rvid)
2197 { 2148 {
2198 SWAP_IT(fore, back, int); 2149 SWAP_IT(fore, back, int);
2199 2150
2200#ifndef NO_BOLD_UNDERLINE_REVERSE 2151#ifndef NO_BOLD_UNDERLINE_REVERSE
2201 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_RV) 2152 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_RV)
2202# ifndef NO_CURSORCOLOR 2153# ifndef NO_CURSORCOLOR
2203 && !ISSET_PIXCOLOR(R, Color_cursor) 2154 && !ISSET_PIXCOLOR (this, Color_cursor)
2204# endif 2155# endif
2205 ) 2156 )
2206 back = Color_RV; 2157 back = Color_RV;
2207#endif 2158#endif
2208 } 2159 }
2209#ifndef NO_BOLD_UNDERLINE_REVERSE 2160#ifndef NO_BOLD_UNDERLINE_REVERSE
2210 else if (rend & RS_Bold) 2161 else if (rend & RS_Bold)
2211 { 2162 {
2212 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_BD)) 2163 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_BD))
2213 {
2214 fore = Color_BD; 2164 fore = Color_BD;
2215# ifndef VERYBOLD
2216 rend &= ~RS_Bold; /* we've taken care of it */
2217# endif
2218 }
2219 } 2165 }
2220 else if (rend & RS_Uline) 2166 else if (rend & RS_Uline)
2221 { 2167 {
2222 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_UL)) 2168 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_UL))
2223 {
2224 fore = Color_UL; 2169 fore = Color_UL;
2225 rend &= ~RS_Uline; /* we've taken care of it */
2226 }
2227 } 2170 }
2228#endif 2171#endif
2229 2172
2230/* 2173 /*
2231 * Actually do the drawing of the string here 2174 * Actually do the drawing of the string here
2232 */ 2175 */
2233 rxvt_font *font = (*R->TermWin.fontset)[fid]; 2176 rxvt_font *font = (*TermWin.fontset)[fid];
2234 2177
2235 if (back == Color_bg) 2178 if (back == Color_bg)
2236 { 2179 {
2237 if (must_clear) 2180 if (must_clear)
2238 { 2181 {
2241 { 2184 {
2242 font->draw (xpixel, ypixel, text, count, fore, -1); 2185 font->draw (xpixel, ypixel, text, count, fore, -1);
2243 goto nodraw; 2186 goto nodraw;
2244 } 2187 }
2245 2188
2246 CLEAR_CHARS(xpixel, ypixel, count); 2189 CLEAR_CHARS (xpixel, ypixel, count);
2247nodraw: ; 2190nodraw: ;
2248 } 2191 }
2249 else 2192 else
2250 font->draw (xpixel, ypixel, text, count, fore, Color_bg); 2193 font->draw (xpixel, ypixel, text, count, fore, Color_bg);
2251 } 2194 }
2252 else 2195 else
2253 font->draw (xpixel, ypixel, text, count, fore, back); 2196 font->draw (xpixel, ypixel, text, count, fore, back);
2254 2197
2255 if ((rend & RS_Uline) && (font->descent > 1)) 2198 if ((rend & RS_Uline) && (font->descent > 1))
2256 XDrawLine(R->Xdisplay, drawBuffer, R->TermWin.gc, 2199 XDrawLine(Xdisplay, drawBuffer, TermWin.gc,
2257 xpixel, ypixel + font->ascent + 1, 2200 xpixel, ypixel + font->ascent + 1,
2258 xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1); 2201 xpixel + Width2Pixel(count) - 1, ypixel + font->ascent + 1);
2259 } /* for (col....) */ 2202 } /* for (col....) */
2260 } /* for (row....) */ 2203 } /* for (row....) */
2261 2204
2262/* 2205 /*
2263 * G: cleanup cursor and display outline cursor if necessary 2206 * G: cleanup cursor and display outline cursor if necessary
2264 */ 2207 */
2265 if (showcursor) { 2208 if (showcursor) {
2266 if (R->TermWin.focus) { 2209 if (TermWin.focus) {
2267 srp = &(R->screen.rend[R->screen.cur.row + R->TermWin.saveLines] 2210 srp = &(screen.rend[screen.cur.row + TermWin.saveLines]
2268 [R->screen.cur.col]); 2211 [screen.cur.col]);
2269 *srp ^= RS_RVid; 2212 *srp ^= RS_RVid;
2270#ifndef NO_CURSORCOLOR 2213#ifndef NO_CURSORCOLOR
2271 *srp = (*srp & ~(RS_fgMask | RS_bgMask)) | cc1; 2214 *srp = (*srp & ~(RS_fgMask | RS_bgMask)) | cc1;
2272#endif 2215#endif
2273 } else if (R->oldcursor.row >= 0) { 2216 } else if (oldcursor.row >= 0) {
2274#ifndef NO_CURSORCOLOR 2217#ifndef NO_CURSORCOLOR
2275 unsigned long gcmask; /* Graphics Context mask */ 2218 unsigned long gcmask; /* Graphics Context mask */
2276 2219
2277 if (XDEPTH > 2 && ISSET_PIXCOLOR(R, Color_cursor)) { 2220 if (Xdepth > 2 && ISSET_PIXCOLOR (this, Color_cursor))
2278 XSetForeground (R->Xdisplay, R->TermWin.gc, R->PixColors[Color_cursor]); 2221 XSetForeground (Xdisplay, TermWin.gc, PixColors[Color_cursor]);
2279 }
2280#endif 2222#endif
2281 XDrawRectangle(R->Xdisplay, drawBuffer, R->TermWin.gc, 2223 XDrawRectangle(Xdisplay, drawBuffer, TermWin.gc,
2282 Col2Pixel(R->oldcursor.col), 2224 Col2Pixel(oldcursor.col),
2283 Row2Pixel(R->oldcursor.row), 2225 Row2Pixel(oldcursor.row),
2284 (unsigned int)(Width2Pixel(cursorwidth) - 1), 2226 (unsigned int)(Width2Pixel(cursorwidth) - 1),
2285 (unsigned int)(Height2Pixel(1) - R->TermWin.lineSpace - 1)); 2227 (unsigned int)(Height2Pixel(1) - TermWin.lineSpace - 1));
2286 } 2228 }
2287 } 2229 }
2288/* 2230
2231 /*
2289 * H: cleanup selection 2232 * H: cleanup selection
2290 */ 2233 */
2291 rxvt_scr_reverse_selection(aR); 2234 rxvt_scr_reverse_selection (this);
2292 2235
2293/* 2236 /*
2294 * I: other general cleanup 2237 * I: other general cleanup
2295 */ 2238 */
2296 if (clearfirst && R->TermWin.int_bwidth) 2239 if (clearfirst && TermWin.int_bwidth)
2297 /* 2240 /*
2298 * clear the whole screen height, note that width == 0 is treated 2241 * clear the whole screen height, note that width == 0 is treated
2299 * specially by XClearArea 2242 * specially by XClearArea
2300 */ 2243 */
2301 XClearArea(R->Xdisplay, R->TermWin.vt, 0, 0, 2244 XClearArea(Xdisplay, TermWin.vt, 0, 0,
2302 (unsigned int)R->TermWin.int_bwidth, 2245 (unsigned int)TermWin.int_bwidth,
2303 (unsigned int)TermWin_TotalHeight(), False); 2246 (unsigned int)TermWin_TotalHeight(), False);
2304 if (clearlast && R->TermWin.int_bwidth) 2247 if (clearlast && TermWin.int_bwidth)
2305 /* 2248 /*
2306 * clear the whole screen height, note that width == 0 is treated 2249 * clear the whole screen height, note that width == 0 is treated
2307 * specially by XClearArea 2250 * specially by XClearArea
2308 */ 2251 */
2309 XClearArea(R->Xdisplay, R->TermWin.vt, 2252 XClearArea(Xdisplay, TermWin.vt,
2310 R->TermWin.width + R->TermWin.int_bwidth, 0, 2253 TermWin.width + TermWin.int_bwidth, 0,
2311 (unsigned int)R->TermWin.int_bwidth, 2254 (unsigned int)TermWin.int_bwidth,
2312 (unsigned int)TermWin_TotalHeight(), False); 2255 (unsigned int)TermWin_TotalHeight(), False);
2313 if (refresh_type & SMOOTH_REFRESH) 2256 if (refresh_type & SMOOTH_REFRESH)
2314 XSync(R->Xdisplay, False); 2257 XSync(Xdisplay, False);
2315 2258
2316 R->num_scr = 0; 2259 num_scr = 0;
2317 R->num_scr_allow = 1; 2260 num_scr_allow = 1;
2318 R->want_refresh = 0; /* screen is current */ 2261 want_refresh = 0; /* screen is current */
2319} 2262}
2320/* ------------------------------------------------------------------------- */
2321 2263
2322/* EXTPROTO */ 2264/* ------------------------------------------------------------------------- */
2323void 2265void
2324rxvt_scr_clear(pR) 2266rxvt_term::scr_clear()
2325{ 2267{
2326 if (!R->TermWin.mapped) 2268 if (!TermWin.mapped)
2327 return; 2269 return;
2270
2328 R->num_scr_allow = 0; 2271 num_scr_allow = 0;
2329 R->want_refresh = 1; 2272 want_refresh = 1;
2330#ifdef TRANSPARENT 2273#ifdef TRANSPARENT
2331 if ((R->Options & Opt_transparent) && (R->am_pixmap_trans == 0)) { 2274 if ((Options & Opt_transparent) && (am_pixmap_trans == 0))
2332 int i; 2275 {
2276 int i;
2333 2277
2334 if (!(R->Options & Opt_transparent_all)) 2278 if (!(Options & Opt_transparent_all))
2335 i = 0; 2279 i = 0;
2336 else 2280 else
2337 i = (int)(sizeof(R->TermWin.parent) / sizeof(Window)); 2281 i = (int)(sizeof(TermWin.parent) / sizeof(Window));
2338 for (; i--;) 2282
2283 while (i--)
2339 if (R->TermWin.parent[i] != None) 2284 if (TermWin.parent[i] != None)
2340 XClearWindow(R->Xdisplay, R->TermWin.parent[i]); 2285 XClearWindow(Xdisplay, TermWin.parent[i]);
2341 } 2286 }
2342#endif 2287#endif
2288
2343 XClearWindow(R->Xdisplay, R->TermWin.vt); 2289 XClearWindow (Xdisplay, TermWin.vt);
2344} 2290}
2345 2291
2346/* ------------------------------------------------------------------------- */ 2292/* ------------------------------------------------------------------------- */
2347/* INTPROTO */ 2293/* INTPROTO */
2348void 2294void
2489rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) 2435rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop)
2490{ 2436{
2491 long nread = 0; 2437 long nread = 0;
2492 unsigned long bytes_after; 2438 unsigned long bytes_after;
2493 XTextProperty ct; 2439 XTextProperty ct;
2494 int dummy_count;
2495 char **cl;
2496 2440
2497 D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); 2441 D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait));
2498 2442
2499 if (prop == None) /* check for failed XConvertSelection */ 2443 if (prop == None) /* check for failed XConvertSelection */
2500 { 2444 {
2503 int selnum = R->selection_type & Sel_whereMask; 2447 int selnum = R->selection_type & Sel_whereMask;
2504 2448
2505 R->selection_type = 0; 2449 R->selection_type = 0;
2506 if (selnum != Sel_direct) 2450 if (selnum != Sel_direct)
2507 rxvt_selection_request_other(aR_ XA_STRING, selnum); 2451 rxvt_selection_request_other(aR_ XA_STRING, selnum);
2452 }
2453
2454 if ((R->selection_type & Sel_UTF8String))
2455 {
2456 int selnum = R->selection_type & Sel_whereMask;
2457
2458 R->selection_type = Sel_CompoundText;
2459 if (selnum != Sel_direct)
2460 rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], selnum);
2461 else
2462 R->selection_type = 0;
2508 } 2463 }
2509 2464
2510 return 0; 2465 return 0;
2511 } 2466 }
2512 2467
2547 nread = -1; /* discount any previous stuff */ 2502 nread = -1; /* discount any previous stuff */
2548 break; 2503 break;
2549 } 2504 }
2550 2505
2551 nread += ct.nitems; 2506 nread += ct.nitems;
2507
2508 char **cl;
2509 int cr;
2552 if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, 2510 if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl,
2553 &dummy_count) == Success && cl) 2511 &cr) >= 0 && cl)
2554 { 2512 {
2513 for (int i = 0; i < cr; i++)
2555 R->paste ((unsigned char *)cl[0], STRLEN (cl[0])); 2514 R->paste ((unsigned char *)cl[i], STRLEN (cl[i]));
2515
2556 XFreeStringList (cl); 2516 XFreeStringList (cl);
2557 } 2517 }
2558 else 2518 else
2559 R->paste (ct.value, ct.nitems); 2519 R->paste (ct.value, ct.nitems);
2560 2520
2575} 2535}
2576 2536
2577void 2537void
2578rxvt_term::incr_cb (time_watcher &w) 2538rxvt_term::incr_cb (time_watcher &w)
2579{ 2539{
2580 w.stop ();
2581 selection_wait = Sel_none; 2540 selection_wait = Sel_none;
2582 2541
2583 rxvt_print_error("data loss: timeout on INCR selection paste"); 2542 rxvt_print_error ("data loss: timeout on INCR selection paste");
2584} 2543}
2585 2544
2586/* 2545/*
2587 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> 2546 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2588 */ 2547 */
2654 int i; 2613 int i;
2655 2614
2656 R->selection_request_time = tm; 2615 R->selection_request_time = tm;
2657 R->selection_wait = Sel_normal; 2616 R->selection_wait = Sel_normal;
2658 for (i = Sel_Primary; i <= Sel_Clipboard; i++) { 2617 for (i = Sel_Primary; i <= Sel_Clipboard; i++) {
2618#if X_HAVE_UTF8_STRING
2619 R->selection_type = Sel_UTF8String;
2620 if (rxvt_selection_request_other(aR_ R->xa[XA_UTF8_STRING], i))
2621 return;
2622#else
2659 R->selection_type = Sel_CompoundText; 2623 R->selection_type = Sel_CompoundText;
2660 if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) 2624 if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i))
2661 return; 2625 return;
2626#endif
2662 } 2627 }
2663 } 2628 }
2664 R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ 2629 R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */
2665 D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); 2630 D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0"));
2666 rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); 2631 rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False);
2798 { 2763 {
2799 free (new_selection_text); 2764 free (new_selection_text);
2800 return; 2765 return;
2801 } 2766 }
2802 2767
2803 // due to MB_MAX_CUR, selection wastage is usually high 2768 // due to MB_MAX_CUR, selection wastage is usually high, so realloc
2804 if (str - (char *)new_selection_text > 1024) 2769 if (str - (char *)new_selection_text > 1024)
2805 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); 2770 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1);
2806 2771
2807 R->selection.len = i; 2772 R->selection.len = i;
2773
2808 if (R->selection.text) 2774 if (R->selection.text)
2809 free (R->selection.text); 2775 free (R->selection.text);
2810 2776
2811 R->selection.text = new_selection_text; 2777 R->selection.text = new_selection_text;
2812 2778
2813 XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); 2779 XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm);
2814 if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) 2780 if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt)
2815 rxvt_print_error("can't get primary selection"); 2781 rxvt_print_error("can't get primary selection");
2782
2783
2784 {
2785 XTextProperty ct;
2786 char *cl = (char *)R->selection.text;
2787
2788 if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, XStringStyle, &ct) >= 0)
2789 {
2790 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8,
2791 PropModeReplace, ct.value, ct.nitems);
2792 XFree (ct.value);
2793 }
2794 else
2816 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, 2795 XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8,
2817 PropModeReplace, R->selection.text, (int)R->selection.len); 2796 PropModeReplace, R->selection.text, (int)R->selection.len);
2797 }
2798
2818 R->selection_time = tm; 2799 R->selection_time = tm;
2819 D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); 2800 D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len));
2820} 2801}
2821 2802
2822/* ------------------------------------------------------------------------- */ 2803/* ------------------------------------------------------------------------- */
2823/* 2804/*
2824 * Mark or select text based upon number of clicks: 1, 2, or 3 2805 * Mark or select text based upon number of clicks: 1, 2, or 3
2825 * EXT: button 1 press 2806 * EXT: button 1 press
2826 */ 2807 */
2827/* EXTPROTO */
2828void 2808void
2829rxvt_selection_click(pR_ int clicks, int x, int y) 2809rxvt_term::selection_click (int clicks, int x, int y)
2830{ 2810{
2831 D_SELECT((stderr, "rxvt_selection_click(%d, %d, %d)", clicks, x, y)); 2811 D_SELECT((stderr, "rxvt_selection_click(%d, %d, %d)", clicks, x, y));
2832 2812
2833 clicks = ((clicks - 1) % 3) + 1; 2813 clicks = ((clicks - 1) % 3) + 1;
2834 R->selection.clicks = clicks; /* save clicks so extend will work */ 2814 selection.clicks = clicks; /* save clicks so extend will work */
2835 2815
2836 rxvt_selection_start_colrow(aR_ Pixel2Col(x), Pixel2Row(y)); 2816 rxvt_selection_start_colrow (this, Pixel2Col(x), Pixel2Row(y));
2817
2837 if (clicks == 2 || clicks == 3) 2818 if (clicks == 2 || clicks == 3)
2838 rxvt_selection_extend_colrow(aR_ R->selection.mark.col, 2819 rxvt_selection_extend_colrow (this, selection.mark.col,
2839 R->selection.mark.row
2840 + R->TermWin.view_start, 2820 selection.mark.row + TermWin.view_start,
2841 0, /* button 3 */ 2821 0, /* button 3 */
2842 1, /* button press */ 2822 1, /* button press */
2843 0); /* click change */ 2823 0); /* click change */
2844} 2824}
2845 2825
2846/* ------------------------------------------------------------------------- */ 2826/* ------------------------------------------------------------------------- */
2847/* 2827/*
2848 * Mark a selection at the specified col/row 2828 * Mark a selection at the specified col/row
2958 * EXT: button 3 press; button 1 or 3 drag 2938 * EXT: button 3 press; button 1 or 3 drag
2959 * flag == 0 ==> button 1 2939 * flag == 0 ==> button 1
2960 * flag == 1 ==> button 3 press 2940 * flag == 1 ==> button 3 press
2961 * flag == 2 ==> button 3 motion 2941 * flag == 2 ==> button 3 motion
2962 */ 2942 */
2963/* EXTPROTO */
2964void 2943void
2965rxvt_selection_extend(pR_ int x, int y, int flag) 2944rxvt_term::selection_extend (int x, int y, int flag)
2966{ 2945{
2967 int col, row; 2946 int col, row;
2968 2947
2969 col = Pixel2Col(x); 2948 col = Pixel2Col(x);
2970 row = Pixel2Row(y); 2949 row = Pixel2Row(y);
2971 MAX_IT(row, 0); 2950 MAX_IT(row, 0);
2972 MIN_IT(row, (int)R->TermWin.nrow - 1); 2951 MIN_IT(row, (int)TermWin.nrow - 1);
2973 MAX_IT(col, 0); 2952 MAX_IT(col, 0);
2974 MIN_IT(col, (int)R->TermWin.ncol); 2953 MIN_IT(col, (int)TermWin.ncol);
2954
2975#ifndef NO_NEW_SELECTION 2955#ifndef NO_NEW_SELECTION
2976/* 2956 /*
2977 * If we're selecting characters (single click) then we must check first 2957 * If we're selecting characters (single click) then we must check first
2978 * if we are at the same place as the original mark. If we are then 2958 * if we are at the same place as the original mark. If we are then
2979 * select nothing. Otherwise, if we're to the right of the mark, you have to 2959 * select nothing. Otherwise, if we're to the right of the mark, you have to
2980 * be _past_ a character for it to be selected. 2960 * be _past_ a character for it to be selected.
2981 */ 2961 */
2982 if (R->selection_style != OLD_SELECT) { 2962 if (selection_style != OLD_SELECT)
2963 {
2983 if (((R->selection.clicks % 3) == 1) && !flag 2964 if (((selection.clicks % 3) == 1) && !flag
2984 && (col == R->selection.mark.col 2965 && (col == selection.mark.col
2985 && (row == R->selection.mark.row + R->TermWin.view_start))) { 2966 && (row == selection.mark.row + TermWin.view_start)))
2967 {
2986 /* select nothing */ 2968 /* select nothing */
2987 R->selection.beg.row = R->selection.end.row = 0; 2969 selection.beg.row = selection.end.row = 0;
2988 R->selection.beg.col = R->selection.end.col = 0; 2970 selection.beg.col = selection.end.col = 0;
2989 R->selection.clicks = 4; 2971 selection.clicks = 4;
2990 R->want_refresh = 1; 2972 want_refresh = 1;
2991 D_SELECT((stderr, "rxvt_selection_extend() R->selection.clicks = 4")); 2973 D_SELECT((stderr, "rxvt_selection_extend() selection.clicks = 4"));
2992 return; 2974 return;
2993 } 2975 }
2994 } 2976 }
2995#endif 2977#endif
2996 if (R->selection.clicks == 4) 2978 if (selection.clicks == 4)
2997 R->selection.clicks = 1; 2979 selection.clicks = 1;
2980
2998 rxvt_selection_extend_colrow(aR_ col, row, !!flag, /* ? button 3 */ 2981 rxvt_selection_extend_colrow (this, col, row, !!flag, /* ? button 3 */
2999 flag == 1 ? 1 : 0, /* ? button press */ 2982 flag == 1 ? 1 : 0, /* ? button press */
3000 0); /* no click change */ 2983 0); /* no click change */
3001} 2984}
3002 2985
3003/* ------------------------------------------------------------------------- */ 2986/* ------------------------------------------------------------------------- */
3004/* 2987/*
3005 * Extend the selection to the specified col/row 2988 * Extend the selection to the specified col/row
3259/* ------------------------------------------------------------------------- */ 3242/* ------------------------------------------------------------------------- */
3260/* 3243/*
3261 * Double click on button 3 when already selected 3244 * Double click on button 3 when already selected
3262 * EXT: button 3 double click 3245 * EXT: button 3 double click
3263 */ 3246 */
3264/* EXTPROTO */
3265void 3247void
3266rxvt_selection_rotate(pR_ int x, int y) 3248rxvt_term::selection_rotate (int x, int y)
3267{ 3249{
3268 R->selection.clicks = R->selection.clicks % 3 + 1; 3250 selection.clicks = selection.clicks % 3 + 1;
3269 rxvt_selection_extend_colrow(aR_ Pixel2Col(x), Pixel2Row(y), 1, 0, 1); 3251 rxvt_selection_extend_colrow (this, Pixel2Col(x), Pixel2Row(y), 1, 0, 1);
3270} 3252}
3271 3253
3272/* ------------------------------------------------------------------------- */ 3254/* ------------------------------------------------------------------------- */
3273/* 3255/*
3274 * On some systems, the Atom typedef is 64 bits wide. We need to have a type 3256 * On some systems, the Atom typedef is 64 bits wide. We need to have a type
3275 * that is exactly 32 bits wide, because a format of 64 is not allowed by 3257 * that is exactly 32 bits wide, because a format of 64 is not allowed by
3276 * the X11 protocol. 3258 * the X11 protocol.
3277 */ 3259 */
3278typedef CARD32 Atom32; 3260typedef CARD32 Atom32;
3279 3261
3280/* ------------------------------------------------------------------------- */ 3262/* ------------------------------------------------------------------------- */
3281/* 3263/*
3282 * Respond to a request for our current selection 3264 * Respond to a request for our current selection
3283 * EXT: SelectionRequest 3265 * EXT: SelectionRequest
3285/* EXTPROTO */ 3267/* EXTPROTO */
3286void 3268void
3287rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) 3269rxvt_selection_send(pR_ const XSelectionRequestEvent *rq)
3288{ 3270{
3289 XSelectionEvent ev; 3271 XSelectionEvent ev;
3290#ifdef USE_XIM
3291 Atom32 target_list[4];
3292#else
3293 Atom32 target_list[3];
3294#endif
3295 Atom target;
3296 XTextProperty ct; 3272 XTextProperty ct;
3297 XICCEncodingStyle style; 3273 XICCEncodingStyle style;
3298 char *cl[2], dummy[1]; 3274 Atom target;
3299 3275
3300 ev.type = SelectionNotify; 3276 ev.type = SelectionNotify;
3301 ev.property = None; 3277 ev.property = None;
3302 ev.display = rq->display; 3278 ev.display = rq->display;
3303 ev.requestor = rq->requestor; 3279 ev.requestor = rq->requestor;
3304 ev.selection = rq->selection; 3280 ev.selection = rq->selection;
3305 ev.target = rq->target; 3281 ev.target = rq->target;
3306 ev.time = rq->time; 3282 ev.time = rq->time;
3307 3283
3308 if (rq->target == R->xa[XA_TARGETS]) { 3284 if (rq->target == R->xa[XA_TARGETS]) {
3285 Atom32 target_list[5];
3286 Atom32 *target = target_list;
3287
3309 target_list[0] = (Atom32) R->xa[XA_TARGETS]; 3288 *target++ = (Atom32) R->xa[XA_TARGETS];
3310 target_list[1] = (Atom32) XA_STRING; 3289 *target++ = (Atom32) XA_STRING;
3311 target_list[2] = (Atom32) R->xa[XA_TEXT]; 3290 *target++ = (Atom32) R->xa[XA_TEXT];
3312#ifdef USE_XIM
3313 target_list[3] = (Atom32) R->xa[XA_COMPOUND_TEXT]; 3291 *target++ = (Atom32) R->xa[XA_COMPOUND_TEXT];
3292#if X_HAVE_UTF8_STRING
3293 *target++ = (Atom32) R->xa[XA_UTF8_STRING];
3314#endif 3294#endif
3315 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, 3295 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM,
3316 (8 * sizeof(target_list[0])), PropModeReplace, 3296 (8 * sizeof(target_list[0])), PropModeReplace,
3317 (unsigned char *)target_list, 3297 (unsigned char *)target_list,
3318 (sizeof(target_list) / sizeof(target_list[0]))); 3298 target - target_list);
3319 ev.property = rq->property; 3299 ev.property = rq->property;
3320 } else if (rq->target == R->xa[XA_MULTIPLE]) { 3300 } else if (rq->target == R->xa[XA_MULTIPLE]) {
3321 /* TODO: Handle MULTIPLE */ 3301 /* TODO: Handle MULTIPLE */
3322 } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { 3302 } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) {
3323 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, 3303 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER,
3324 (8 * sizeof(Time)), PropModeReplace, 3304 (8 * sizeof(Time)), PropModeReplace,
3325 (unsigned char *)&R->selection_time, 1); 3305 (unsigned char *)&R->selection_time, 1);
3326 ev.property = rq->property; 3306 ev.property = rq->property;
3327 } else if (rq->target == XA_STRING 3307 } else if (rq->target == XA_STRING
3308 || rq->target == R->xa[XA_TEXT]
3328 || rq->target == R->xa[XA_COMPOUND_TEXT] 3309 || rq->target == R->xa[XA_COMPOUND_TEXT]
3329 || rq->target == R->xa[XA_TEXT]) { 3310 || rq->target == R->xa[XA_UTF8_STRING]
3330#ifdef USE_XIM 3311 ) {
3331 short freect = 0; 3312 short freect = 0;
3332#endif
3333 int selectlen; 3313 int selectlen;
3314 char *cl;
3334 3315
3335#ifdef USE_XIM 3316 target = rq->target;
3317
3336 if (rq->target != XA_STRING) { 3318 if (target == XA_STRING)
3319 // we actually don't do XA_STRING, but who cares, as i18n clients
3320 // will ask for another format anyways.
3321 style = XStringStyle;
3322 else if (target == R->xa[XA_TEXT])
3323 style = XTextStyle;
3324 else if (target == R->xa[XA_COMPOUND_TEXT])
3325 style = XCompoundTextStyle;
3326#if X_HAVE_UTF8_STRING
3327 else if (target == R->xa[XA_UTF8_STRING])
3328 style = XUTF8StringStyle;
3329#endif
3330 else
3331 {
3337 target = R->xa[XA_COMPOUND_TEXT]; 3332 target = R->xa[XA_COMPOUND_TEXT];
3338 style = (rq->target == R->xa[XA_COMPOUND_TEXT])
3339 ? XCompoundTextStyle : XStdICCTextStyle;
3340 } else
3341#endif
3342 {
3343 target = XA_STRING;
3344 style = XStringStyle; 3333 style = XCompoundTextStyle;
3345 } 3334 }
3335
3346 if (R->selection.text) { 3336 if (R->selection.text) {
3347 cl[0] = (char *)R->selection.text; 3337 cl = (char *)R->selection.text;
3348 selectlen = R->selection.len; 3338 selectlen = R->selection.len;
3349 } else { 3339 } else {
3350 cl[0] = dummy; 3340 cl = "";
3351 *dummy = '\0';
3352 selectlen = 0; 3341 selectlen = 0;
3353 } 3342 }
3354#ifdef USE_XIM 3343
3355 if (XmbTextListToTextProperty(R->Xdisplay, cl, 1, style, &ct) 3344 if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, style, &ct) >= 0)
3356 == Success) /* if we failed to convert then send it raw */
3357 freect = 1; 3345 freect = 1;
3358 else 3346 else
3359#endif
3360 { 3347 {
3348 /* if we failed to convert then send it raw */
3361 ct.value = (unsigned char *)cl[0]; 3349 ct.value = (unsigned char *)cl;
3362 ct.nitems = selectlen; 3350 ct.nitems = selectlen;
3363 } 3351 }
3352
3364 XChangeProperty(R->Xdisplay, rq->requestor, rq->property, 3353 XChangeProperty(R->Xdisplay, rq->requestor, rq->property,
3365 target, 8, PropModeReplace, 3354 target, 8, PropModeReplace,
3366 ct.value, (int)ct.nitems); 3355 ct.value, (int)ct.nitems);
3367 ev.property = rq->property; 3356 ev.property = rq->property;
3368#ifdef USE_XIM 3357
3369 if (freect) 3358 if (freect)
3370 XFree(ct.value); 3359 XFree (ct.value);
3371#endif
3372 } 3360 }
3373 XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); 3361 XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev);
3374} 3362}
3375 3363
3376/* ------------------------------------------------------------------------- * 3364/* ------------------------------------------------------------------------- *
3378 * ------------------------------------------------------------------------- */ 3366 * ------------------------------------------------------------------------- */
3379 3367
3380/* 3368/*
3381 * return col/row values corresponding to x/y pixel values 3369 * return col/row values corresponding to x/y pixel values
3382 */ 3370 */
3383/* EXTPROTO */
3384void 3371void
3385rxvt_pixel_position(pR_ int *x, int *y) 3372rxvt_term::pixel_position (int *x, int *y)
3386{ 3373{
3387 *x = Pixel2Col(*x); 3374 *x = Pixel2Col(*x);
3388/* MAX_IT(*x, 0); MIN_IT(*x, (int)R->TermWin.ncol - 1); */ 3375 /* MAX_IT(*x, 0); MIN_IT(*x, (int)R->TermWin.ncol - 1); */
3389 *y = Pixel2Row(*y); 3376 *y = Pixel2Row(*y);
3390/* MAX_IT(*y, 0); MIN_IT(*y, (int)R->TermWin.nrow - 1); */ 3377 /* MAX_IT(*y, 0); MIN_IT(*y, (int)R->TermWin.nrow - 1); */
3391} 3378}
3379
3392/* ------------------------------------------------------------------------- */ 3380/* ------------------------------------------------------------------------- */
3393#ifdef USE_XIM 3381#ifdef USE_XIM
3394/* EXTPROTO */
3395void 3382void
3396rxvt_setPosition(pR_ XPoint *pos) 3383rxvt_term::set_position (XPoint *pos)
3397{ 3384{
3398 XWindowAttributes xwa; 3385 XWindowAttributes xwa;
3399 3386
3400 XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &xwa); 3387 XGetWindowAttributes (Xdisplay, TermWin.vt, &xwa);
3401 pos->x = Col2Pixel(R->screen.cur.col) + xwa.x; 3388 pos->x = Col2Pixel (screen.cur.col) + xwa.x;
3402 pos->y = Height2Pixel((R->screen.cur.row + 1)) + xwa.y 3389 pos->y = Height2Pixel ((screen.cur.row + 1)) + xwa.y - TermWin.lineSpace;
3403 - R->TermWin.lineSpace;
3404} 3390}
3391
3405#endif 3392#endif
3406/* ------------------------------------------------------------------------- */ 3393/* ------------------------------------------------------------------------- */
3407 3394
3408/* ------------------------------------------------------------------------- * 3395/* ------------------------------------------------------------------------- *
3409 * DEBUG ROUTINES * 3396 * DEBUG ROUTINES *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines