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.306 by root, Sun Jun 15 10:15:39 2008 UTC vs.
Revision 1.311 by root, Wed Oct 15 14:48:22 2008 UTC

83 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col) 83 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col)
84#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \ 84#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \
85 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col) 85 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col)
86 86
87/* 87/*
88 * CLEAR_ROWS : clear <num> rows starting from row <row>
89 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 88 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
90 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
91 */ 89 */
92#define CLEAR_ROWS(row, num) \
93 if (mapped) \
94 XClearArea (dpy, vt, 0, \
95 Row2Pixel (row), (unsigned int)width, \
96 (unsigned int)Height2Pixel (num), False)
97
98#define CLEAR_CHARS(x, y, num) \ 90#define CLEAR_CHARS(x, y, num) \
99 if (mapped) \ 91 if (mapped) \
100 XClearArea (dpy, vt, x, y, \ 92 XClearArea (dpy, vt, x, y, \
101 (unsigned int)Width2Pixel (num), \ 93 (unsigned int)Width2Pixel (num), \
102 (unsigned int)Height2Pixel (1), False) 94 (unsigned int)Height2Pixel (1), False)
103
104#define ERASE_ROWS(row, num) \
105 XFillRectangle (dpy, vt, gc, \
106 0, Row2Pixel (row), \
107 (unsigned int)width, \
108 (unsigned int)Height2Pixel (num))
109 95
110/* ------------------------------------------------------------------------- * 96/* ------------------------------------------------------------------------- *
111 * SCREEN `COMMON' ROUTINES * 97 * SCREEN `COMMON' ROUTINES *
112 * ------------------------------------------------------------------------- */ 98 * ------------------------------------------------------------------------- */
113 99
785 771
786 while (str < strend) 772 while (str < strend)
787 { 773 {
788 c = (unicode_t)*str++; // convert to rxvt-unicodes representation 774 c = (unicode_t)*str++; // convert to rxvt-unicodes representation
789 775
790 if (c < 0x20) 776 if (expect_false (c < 0x20))
791 if (c == C0_LF) 777 if (c == C0_LF)
792 { 778 {
793 max_it (line->l, screen.cur.col); 779 max_it (line->l, screen.cur.col);
794 780
795 screen.flags &= ~Screen_WrapNext; 781 screen.flags &= ~Screen_WrapNext;
814 { 800 {
815 scr_tab (1, true); 801 scr_tab (1, true);
816 continue; 802 continue;
817 } 803 }
818 804
805 if (expect_false (
819 if (checksel /* see if we're writing within selection */ 806 checksel /* see if we're writing within selection */
820 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 807 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
821 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 808 && ROWCOL_IS_BEFORE (screen.cur, selection.end)
809 ))
822 { 810 {
823 checksel = 0; 811 checksel = 0;
824 /* 812 /*
825 * If we wrote anywhere in the selected area, kill the selection 813 * If we wrote anywhere in the selected area, kill the selection
826 * XXX: should we kill the mark too? Possibly, but maybe that 814 * XXX: should we kill the mark too? Possibly, but maybe that
827 * should be a similar check. 815 * should be a similar check.
828 */ 816 */
829 CLEAR_SELECTION (); 817 CLEAR_SELECTION ();
830 } 818 }
831 819
832 if (screen.flags & Screen_WrapNext) 820 if (expect_false (screen.flags & Screen_WrapNext))
833 { 821 {
834 scr_do_wrap (); 822 scr_do_wrap ();
835 823
836 line->l = ncol; 824 line->l = ncol;
837 line->is_longer (1); 825 line->is_longer (1);
839 row = screen.cur.row; 827 row = screen.cur.row;
840 line = &ROW(row); /* _must_ refresh */ 828 line = &ROW(row); /* _must_ refresh */
841 } 829 }
842 830
843 // some utf-8 decoders "decode" surrogate characters: let's fix this. 831 // some utf-8 decoders "decode" surrogate characters: let's fix this.
844 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 832 if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff)))
845 c = 0xfffd; 833 c = 0xfffd;
846 834
847 // rely on wcwidth to tell us the character width, do wcwidth before 835 // rely on wcwidth to tell us the character width, do wcwidth before
848 // further replacements, as wcwidth might return -1 for the line 836 // further replacements, as wcwidth might return -1 for the line
849 // drawing characters below as they might be invalid in the current 837 // drawing characters below as they might be invalid in the current
850 // locale. 838 // locale.
851 int width = WCWIDTH (c); 839 int width = WCWIDTH (c);
852 840
853 if (charsets [screen.charset] == '0') // DEC SPECIAL 841 if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL
854 { 842 {
855 // vt100 special graphics and line drawing 843 // vt100 special graphics and line drawing
856 // 5f-7e standard vt100 844 // 5f-7e standard vt100
857 // 40-5e rxvt extension for extra curses acs chars 845 // 40-5e rxvt extension for extra curses acs chars
858 static uint16_t vt100_0[62] = { // 41 .. 7e 846 static uint16_t vt100_0[62] = { // 41 .. 7e
871 c = vt100_0[c - 0x41]; 859 c = vt100_0[c - 0x41];
872 width = 1; // vt100 line drawing characters are always single-width 860 width = 1; // vt100 line drawing characters are always single-width
873 } 861 }
874 } 862 }
875 863
876 if (screen.flags & Screen_Insert) 864 if (expect_false (screen.flags & Screen_Insert))
877 scr_insdel_chars (width, INSERT); 865 scr_insdel_chars (width, INSERT);
878 866
879 if (width != 0) 867 if (width != 0)
880 { 868 {
881#if !UNICODE_3 869#if !UNICODE_3
887 c = 0xfffd; 875 c = 0xfffd;
888# endif 876# endif
889#endif 877#endif
890 878
891 // nuke the character at this position, if required 879 // nuke the character at this position, if required
880 if (expect_false (
892 if (line->t[screen.cur.col] == NOCHAR 881 line->t[screen.cur.col] == NOCHAR
893 || (screen.cur.col < ncol - 1 882 || (screen.cur.col < ncol - 1
894 && line->t[screen.cur.col + 1] == NOCHAR)) 883 && line->t[screen.cur.col + 1] == NOCHAR)
884 ))
895 { 885 {
896 int col = screen.cur.col; 886 int col = screen.cur.col;
897 887
898 // find begin 888 // find begin
899 while (col > 0 && line->t[col] == NOCHAR) 889 while (col > 0 && line->t[col] == NOCHAR)
910 } 900 }
911 901
912 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); 902 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
913 903
914 // if the character doesn't fit into the remaining columns... 904 // if the character doesn't fit into the remaining columns...
915 if (screen.cur.col > ncol - width && ncol >= width) 905 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
916 { 906 {
917 // ...output spaces 907 // ...output spaces
918 c = ' '; 908 c = ' ';
919 // and try the same character next loop iteration 909 // and try the same character next loop iteration
920 --str; 910 --str;
925 do 915 do
926 { 916 {
927 line->t[screen.cur.col] = c; 917 line->t[screen.cur.col] = c;
928 line->r[screen.cur.col] = rend; 918 line->r[screen.cur.col] = rend;
929 919
930 if (screen.cur.col < ncol - 1) 920 if (expect_true (screen.cur.col < ncol - 1))
931 screen.cur.col++; 921 screen.cur.col++;
932 else 922 else
933 { 923 {
934 line->l = ncol; 924 line->l = ncol;
935 if (screen.flags & Screen_Autowrap) 925 if (screen.flags & Screen_Autowrap)
937 break; 927 break;
938 } 928 }
939 929
940 c = NOCHAR; 930 c = NOCHAR;
941 } 931 }
942 while (--width > 0); 932 while (expect_false (--width > 0));
943 933
944 // pad with spaces when overwriting wide character with smaller one 934 // pad with spaces when overwriting wide character with smaller one
945 if (!width) 935 if (expect_false (!width))
946 { 936 {
947 line->touch (); 937 line->touch ();
948 938
949 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) 939 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
950 { 940 {
951 line->t[c] = ' '; 941 line->t[c] = ' ';
952 line->r[c] = rend; 942 line->r[c] = rend;
953 } 943 }
954 } 944 }
955 } 945 }
946#if ENABLE_COMBINING
956 else // width == 0 947 else // width == 0
957 { 948 {
958#if ENABLE_COMBINING 949 if (c != 0xfeff) // ignore BOM
959 // handle combining characters
960 // we just tag the accent on the previous on-screen character.
961 // this is arguably not correct, but also arguably not wrong.
962 // we don't handle double-width characters nicely yet.
963 line_t *linep;
964 text_t *tp;
965 rend_t *rp;
966
967 if (screen.cur.col > 0)
968 { 950 {
951 // handle combining characters
952 // we just tag the accent on the previous on-screen character.
953 // this is arguably not correct, but also arguably not wrong.
954 // we don't handle double-width characters nicely yet.
955 line_t *linep;
956 text_t *tp;
957 rend_t *rp;
958
959 if (screen.cur.col > 0)
960 {
969 linep = line; 961 linep = line;
970 tp = line->t + screen.cur.col - 1; 962 tp = line->t + screen.cur.col - 1;
971 rp = line->r + screen.cur.col - 1; 963 rp = line->r + screen.cur.col - 1;
964 }
965 else if (screen.cur.row > 0
966 && ROW(screen.cur.row - 1).is_longer ())
967 {
968 linep = &ROW(screen.cur.row - 1);
969 tp = line->t + ncol - 1;
970 rp = line->r + ncol - 1;
971 }
972 else
973 continue;
974
975 linep->touch ();
976
977 while (*tp == NOCHAR && tp > linep->t)
978 tp--, rp--;
979
980 // first try to find a precomposed character
981 unicode_t n = rxvt_compose (*tp, c);
982 if (n == NOCHAR)
983 n = rxvt_composite.compose (*tp, c);
984
985 *tp = n;
986 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
972 } 987 }
973 else if (screen.cur.row > 0
974 && ROW(screen.cur.row - 1).is_longer ())
975 {
976 linep = &ROW(screen.cur.row - 1);
977 tp = line->t + ncol - 1;
978 rp = line->r + ncol - 1;
979 } 988 }
980 else
981 continue;
982
983 linep->touch ();
984
985 while (*tp == NOCHAR && tp > linep->t)
986 tp--, rp--;
987
988 // first try to find a precomposed character
989 unicode_t n = rxvt_compose (*tp, c);
990 if (n == NOCHAR)
991 n = rxvt_composite.compose (*tp, c);
992
993 *tp = n;
994 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
995#endif 989#endif
996 }
997 } 990 }
998 991
999 max_it (line->l, screen.cur.col); 992 max_it (line->l, screen.cur.col);
1000 993
1001#ifdef DEBUG_STRICT 994#ifdef DEBUG_STRICT
1336 if (row >= nrow) /* Out Of Bounds */ 1329 if (row >= nrow) /* Out Of Bounds */
1337 return; 1330 return;
1338 1331
1339 min_it (num, nrow - row); 1332 min_it (num, nrow - row);
1340 1333
1334 /*TODO: the xlceararea/xfillrectangle below don't take scroll offste into account, ask mikachu for details */
1341 if (rstyle & (RS_RVid | RS_Uline)) 1335 if (rstyle & (RS_RVid | RS_Uline))
1342 ren = (rend_t) ~RS_None; 1336 ren = (rend_t) ~RS_None;
1343 else if (GET_BASEBG (rstyle) == Color_bg) 1337 else if (GET_BASEBG (rstyle) == Color_bg)
1344 { 1338 {
1345 ren = DEFAULT_RSTYLE; 1339 ren = DEFAULT_RSTYLE;
1346 CLEAR_ROWS (row, num); 1340
1341 if (mapped)
1342 XClearArea (dpy, vt, 0,
1343 Row2Pixel (row), (unsigned int)width,
1344 (unsigned int)Height2Pixel (num), False);
1347 } 1345 }
1348 else 1346 else
1349 { 1347 {
1350 ren = rstyle & (RS_fgMask | RS_bgMask); 1348 ren = rstyle & (RS_fgMask | RS_bgMask);
1349
1351 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1350 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1352 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1351 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1353 ERASE_ROWS (row, num); 1352 XFillRectangle (dpy, vt, gc,
1353 0, Row2Pixel (row),
1354 (unsigned int)width,
1355 (unsigned int)Height2Pixel (num));
1354 gcvalue.foreground = pix_colors[Color_fg]; 1356 gcvalue.foreground = pix_colors[Color_fg];
1355 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1357 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1356 } 1358 }
1357 1359
1358 for (; num--; row++) 1360 for (; num--; row++)
1897 XMapWindow (dpy, parent[0]); 1899 XMapWindow (dpy, parent[0]);
1898# endif 1900# endif
1899 1901
1900# if ENABLE_FRILLS 1902# if ENABLE_FRILLS
1901 if (option (Opt_urgentOnBell)) 1903 if (option (Opt_urgentOnBell))
1902 { 1904 set_urgency (1);
1903 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1904 {
1905 h->flags |= XUrgencyHint;
1906 XSetWMHints (dpy, parent[0], h);
1907 }
1908 }
1909# endif 1905# endif
1910 1906
1911 if (option (Opt_visualBell)) 1907 if (option (Opt_visualBell))
1912 { 1908 {
1913 rvideo_bell = true; 1909 rvideo_bell = true;
1926void 1922void
1927rxvt_term::scr_printscreen (int fullhist) NOTHROW 1923rxvt_term::scr_printscreen (int fullhist) NOTHROW
1928{ 1924{
1929#ifdef PRINTPIPE 1925#ifdef PRINTPIPE
1930 int nrows, row_start; 1926 int nrows, row_start;
1931 FILE *fd; 1927 FILE *fd = popen_printer ();
1932 1928
1933 if ((fd = popen_printer ()) == NULL) 1929 if (!fd)
1934 return; 1930 return;
1935 1931
1936 if (fullhist) 1932 if (fullhist)
1937 { 1933 {
1938 nrows = nrow - top_row; 1934 nrows = nrow - top_row;
2208 continue; 2204 continue;
2209 2205
2210 // redraw one or more characters 2206 // redraw one or more characters
2211 2207
2212 // seek to the beginning of wide characters 2208 // seek to the beginning of wide characters
2213 while (stp[col] == NOCHAR && col > 0) 2209 while (expect_false (stp[col] == NOCHAR && col > 0))
2214 --col; 2210 --col;
2215 2211
2216 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2212 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2217 text_t *text = stp + col; 2213 text_t *text = stp + col;
2218 int count = 1; 2214 int count = 1;
2255 2251
2256 col--; /* went one too far. move back */ 2252 col--; /* went one too far. move back */
2257 count -= i; /* dump any matching trailing chars */ 2253 count -= i; /* dump any matching trailing chars */
2258 2254
2259 // sometimes we optimize away the trailing NOCHAR's, add them back 2255 // sometimes we optimize away the trailing NOCHAR's, add them back
2260 while (i && text[count] == NOCHAR) 2256 while (expect_false (i && text[count] == NOCHAR))
2261 count++, i--; 2257 count++, i--;
2262 2258
2263 /* 2259 /*
2264 * Determine the attributes for the string 2260 * Determine the attributes for the string
2265 */ 2261 */
2266 int fore = fgcolor_of (rend); // desired foreground 2262 int fore = fgcolor_of (rend); // desired foreground
2267 int back = bgcolor_of (rend); // desired background 2263 int back = bgcolor_of (rend); // desired background
2268 2264
2269 // only do special processing if any attributes are set, which is unlikely 2265 // only do special processing if any attributes are set, which is unlikely
2270 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2266 if (expect_false (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)))
2271 { 2267 {
2272 bool invert = rend & RS_RVid; 2268 bool invert = rend & RS_RVid;
2273 2269
2274#ifndef NO_BOLD_UNDERLINE_REVERSE 2270#ifndef NO_BOLD_UNDERLINE_REVERSE
2275 if (rend & RS_Bold && fore == Color_fg) 2271 if (rend & RS_Bold && fore == Color_fg)
2358 /* 2354 /*
2359 * Actually do the drawing of the string here 2355 * Actually do the drawing of the string here
2360 */ 2356 */
2361 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2357 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2362 2358
2363 if (have_bg && back == Color_bg) 2359 if (expect_true (have_bg && back == Color_bg))
2364 { 2360 {
2365 // this is very ugly, maybe push it into ->draw? 2361 // this is very ugly, maybe push it into ->draw?
2366 2362
2367 for (i = 0; i < count; i++) /* don't draw empty strings */ 2363 for (i = 0; i < count; i++) /* don't draw empty strings */
2368 if (text[i] != ' ') 2364 if (text[i] != ' ')
2375 did_clear: ; 2371 did_clear: ;
2376 } 2372 }
2377 else 2373 else
2378 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2374 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2379 2375
2380 if (rend & RS_Uline && font->descent > 1 && fore != back) 2376 if (expect_false (rend & RS_Uline && font->descent > 1 && fore != back))
2381 { 2377 {
2382#if ENABLE_FRILLS 2378#if ENABLE_FRILLS
2383 if (ISSET_PIXCOLOR (Color_underline)) 2379 if (ISSET_PIXCOLOR (Color_underline))
2384 XSetForeground (dpy, gc, pix_colors[Color_underline]); 2380 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2385 else 2381 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines