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.37 by pcg, Tue Feb 24 23:58:13 2004 UTC vs.
Revision 1.43 by pcg, Wed Mar 3 02:59:53 2004 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*--------------------------------*-C-*--------------------------------------*
2 * File: screen.c 2 * File: screen.c
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * 4 *
5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> 5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com>
6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 11 * (at your option) any later version.
16 * 17 *
17 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *--------------------------------------------------------------------------*/ 21 *--------------------------------------------------------------------------*/
22
21/* 23/*
22 * We handle _all_ screen updates and selections 24 * This file handles _all_ screen updates and selections
23 */ 25 */
24 26
25#include "../config.h" /* NECESSARY */ 27#include "../config.h" /* NECESSARY */
26#define INTERN_SCREEN 28#define INTERN_SCREEN
27#include "rxvt.h" /* NECESSARY */ 29#include "rxvt.h" /* NECESSARY */
30#include <X11/Xmd.h> /* get the typedef for CARD32 */ 32#include <X11/Xmd.h> /* get the typedef for CARD32 */
31 33
32#include <stdint.h> 34#include <stdint.h>
33#include <wchar.h> 35#include <wchar.h>
34 36
35#include "salloc.C" // HACK!! 37#include "salloc.C" // HACK, should be a seperate compile!
36 38
37inline void fill_text (text_t *start, text_t value, int len) 39inline void fill_text (text_t *start, text_t value, int len)
38{ 40{
39 while (len--) 41 while (len--)
40 *start++ = value; 42 *start++ = value;
887 // rely on wcwidth to tell us the character width, at least for non-ascii 889 // rely on wcwidth to tell us the character width, at least for non-ascii
888 int width = c <= 128 ? 1 : wcwidth (c); 890 int width = c <= 128 ? 1 : wcwidth (c);
889 891
890 // width -1 characters (e.g. combining chars) are ignored currently. 892 // width -1 characters (e.g. combining chars) are ignored currently.
891 if (width > 0) 893 if (width > 0)
894 {
892 do 895 do
893 { 896 {
894 stp[screen.cur.col] = c; 897 stp[screen.cur.col] = c;
895 srp[screen.cur.col] = rend; 898 srp[screen.cur.col] = rend;
896 899
897 if (screen.cur.col < last_col - 1) 900 if (screen.cur.col < last_col - 1)
898 screen.cur.col++; 901 screen.cur.col++;
899 else 902 else
900 { 903 {
901 screen.tlen[row] = last_col; 904 screen.tlen[row] = last_col;
902 if (screen.flags & Screen_Autowrap) 905 if (screen.flags & Screen_Autowrap)
903 screen.flags |= Screen_WrapNext; 906 screen.flags |= Screen_WrapNext;
904 break; 907 break;
905 } 908 }
906 909
907 c = NOCHAR; 910 c = NOCHAR;
908 } 911 }
909 while (--width > 0); 912 while (--width > 0);
913
914 // pad with spaces when overwriting wide character with smaller one
915 for (int c = screen.cur.col; stp[c] == NOCHAR && c < last_col; c++)
916 {
917 stp[c] = ' ';
918 srp[c] = rend;
919 }
920 }
910 else 921 else
911 (void)0; /* handle combining character etc. here. */ 922 (void)0; /* handle combining character etc. here. */
912 } 923 }
913 924
914 if (screen.tlen[row] != -1) /* XXX: think about this */ 925 if (screen.tlen[row] != -1) /* XXX: think about this */
1096 else 1107 else
1097 screen.cur.row = row; 1108 screen.cur.row = row;
1098 } 1109 }
1099 MAX_IT (screen.cur.row, 0); 1110 MAX_IT (screen.cur.row, 0);
1100 MIN_IT (screen.cur.row, (int32_t)TermWin.nrow - 1); 1111 MIN_IT (screen.cur.row, (int32_t)TermWin.nrow - 1);
1112
1113 while (screen.cur.col > 0
1114 && screen.text[screen.cur.row + TermWin.saveLines][screen.cur.col] == NOCHAR)
1115 screen.cur.col--;
1101} 1116}
1102 1117
1103/* ------------------------------------------------------------------------- */ 1118/* ------------------------------------------------------------------------- */
1104/* 1119/*
1105 * direction should be UP or DN 1120 * direction should be UP or DN
2052 int ypixel = (int)Row2Pixel (row); 2067 int ypixel = (int)Row2Pixel (row);
2053 2068
2054 for (col = 0; col < TermWin.ncol; col++) 2069 for (col = 0; col < TermWin.ncol; col++)
2055 { 2070 {
2056 /* compare new text with old - if exactly the same then continue */ 2071 /* compare new text with old - if exactly the same then continue */
2072 if (stp[col] == dtp[col] /* Must match characters to skip. */
2073 && (srp[col] == drp[col] /* Either rendition the same or */
2074 || (stp[col] == ' ' /* space w/ no background change */
2075 && GET_BGATTR (srp[col]) == GET_BGATTR (drp[col]))))
2076 continue;
2077
2078 // redraw one or more characters
2079
2080 // seek to the beginning if wide characters
2081 while (stp[col] == NOCHAR && col > 0)
2082 --col;
2083
2057 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2084 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2058
2059 if (stp[col] == dtp[col] /* Must match characters to skip. */
2060 && (rend == drp[col] /* Either rendition the same or */
2061 || (stp[col] == ' ' /* space w/ no background change */
2062 && GET_BGATTR (rend) == GET_BGATTR (drp[col]))))
2063 continue;
2064
2065 text_t *text = stp + col; 2085 text_t *text = stp + col;
2066 int count = 1; 2086 int count = 1;
2067 2087
2068 /* redraw one or more characters */
2069
2070 dtp[col] = stp[col]; 2088 dtp[col] = stp[col];
2071 drp[col] = rend; 2089 drp[col] = rend;
2072
2073 if (*text == NOCHAR) // never start redrawing at invisible characters. */
2074 continue;
2075 2090
2076 int xpixel = Col2Pixel (col); 2091 int xpixel = Col2Pixel (col);
2077 2092
2078 // this loop looks very messy, it can probably be optimized 2093 // this loop looks very messy, it can probably be optimized
2079 // and cleaned a bit by you? 2094 // and cleaned a bit by you?
2153 back = Color_RV; 2168 back = Color_RV;
2154#endif 2169#endif
2155 } 2170 }
2156 2171
2157#ifdef TEXT_BLINK 2172#ifdef TEXT_BLINK
2158 if (rend & RS_Blink) 2173 if (rend & RS_Blink && back == Color_bg)
2159 { 2174 {
2160 if (!text_blink_ev.active) 2175 if (!text_blink_ev.active)
2161 { 2176 {
2162 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2177 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
2163 hidden_text = 0; 2178 hidden_text = 0;
2195 else 2210 else
2196 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back); 2211 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back);
2197 2212
2198 if ((rend & RS_Uline) && (font->descent > 1)) 2213 if ((rend & RS_Uline) && (font->descent > 1))
2199 XDrawLine (display->display, drawBuffer, TermWin.gc, 2214 XDrawLine (display->display, drawBuffer, TermWin.gc,
2200 xpixel, ypixel + font->ascent + 1, 2215 xpixel, ypixel + font->ascent + 1,
2201 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2216 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2202 } /* for (col....) */ 2217 } /* for (col....) */
2203 } /* for (row....) */ 2218 } /* for (row....) */
2204 2219
2205 /* 2220 /*
2206 * G: cleanup cursor and display outline cursor if necessary 2221 * G: cleanup cursor and display outline cursor if necessary
2226 while (oldcursor.col + cursorwidth < TermWin.ncol 2241 while (oldcursor.col + cursorwidth < TermWin.ncol
2227 && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR) 2242 && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR)
2228 cursorwidth++; 2243 cursorwidth++;
2229 2244
2230 XDrawRectangle (display->display, drawBuffer, TermWin.gc, 2245 XDrawRectangle (display->display, drawBuffer, TermWin.gc,
2231 Col2Pixel (oldcursor.col), 2246 Col2Pixel (oldcursor.col),
2232 Row2Pixel (oldcursor.row), 2247 Row2Pixel (oldcursor.row),
2233 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2248 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2234 (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1)); 2249 (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1));
2235 } 2250 }
2236 } 2251 }
2237 2252
2238 /* 2253 /*
2239 * H: cleanup selection 2254 * H: cleanup selection
2247 /* 2262 /*
2248 * clear the whole screen height, note that width == 0 is treated 2263 * clear the whole screen height, note that width == 0 is treated
2249 * specially by XClearArea 2264 * specially by XClearArea
2250 */ 2265 */
2251 XClearArea (display->display, TermWin.vt, 0, 0, 2266 XClearArea (display->display, TermWin.vt, 0, 0,
2252 (unsigned int)TermWin.int_bwidth, 2267 (unsigned int)TermWin.int_bwidth,
2253 (unsigned int)TermWin_TotalHeight (), False); 2268 (unsigned int)TermWin_TotalHeight (), False);
2269
2254 if (clearlast && TermWin.int_bwidth) 2270 if (clearlast && TermWin.int_bwidth)
2255 /* 2271 /*
2256 * clear the whole screen height, note that width == 0 is treated 2272 * clear the whole screen height, note that width == 0 is treated
2257 * specially by XClearArea 2273 * specially by XClearArea
2258 */ 2274 */
2259 XClearArea (display->display, TermWin.vt, 2275 XClearArea (display->display, TermWin.vt,
2260 TermWin.width + TermWin.int_bwidth, 0, 2276 TermWin.width + TermWin.int_bwidth, 0,
2261 (unsigned int)TermWin.int_bwidth, 2277 (unsigned int)TermWin.int_bwidth,
2262 (unsigned int)TermWin_TotalHeight (), False); 2278 (unsigned int)TermWin_TotalHeight (), False);
2279
2263 if (refresh_type & SMOOTH_REFRESH) 2280 if (refresh_type & SMOOTH_REFRESH)
2264 XSync (display->display, False); 2281 XSync (display->display, False);
2265 2282
2266 num_scr = 0; 2283 num_scr = 0;
2267 num_scr_allow = 1; 2284 num_scr_allow = 1;
2291 } 2308 }
2292} 2309}
2293 2310
2294/* ------------------------------------------------------------------------- */ 2311/* ------------------------------------------------------------------------- */
2295void 2312void
2296rxvt_term::scr_clear () 2313rxvt_term::scr_clear (bool really)
2297{ 2314{
2298 if (!TermWin.mapped) 2315 if (!TermWin.mapped)
2299 return; 2316 return;
2300 2317
2301 num_scr_allow = 0; 2318 num_scr_allow = 0;
2302 want_refresh = 1; 2319 want_refresh = 1;
2320
2303#ifdef TRANSPARENT 2321#ifdef TRANSPARENT
2304 if ((Options & Opt_transparent) && (am_pixmap_trans == 0)) 2322 if ((Options & Opt_transparent) && (am_pixmap_trans == 0))
2305 { 2323 {
2306 int i; 2324 int i;
2307 2325
2314 if (TermWin.parent[i] != None) 2332 if (TermWin.parent[i] != None)
2315 XClearWindow (display->display, TermWin.parent[i]); 2333 XClearWindow (display->display, TermWin.parent[i]);
2316 } 2334 }
2317#endif 2335#endif
2318 2336
2337 if (really)
2319 XClearWindow (display->display, TermWin.vt); 2338 XClearWindow (display->display, TermWin.vt);
2320} 2339}
2321 2340
2322/* ------------------------------------------------------------------------- */ 2341/* ------------------------------------------------------------------------- */
2323void 2342void
2324rxvt_term::scr_reverse_selection () 2343rxvt_term::scr_reverse_selection ()
2325{ 2344{
2326 int i, col, row, end_row;
2327 rend_t *srp;
2328
2329 if (selection.op && current_screen == selection.screen) 2345 if (selection.op && current_screen == selection.screen)
2330 { 2346 {
2331 end_row = TermWin.saveLines - TermWin.view_start; 2347 int end_row = TermWin.saveLines - TermWin.view_start;
2332 i = selection.beg.row + TermWin.saveLines; 2348 int i = selection.beg.row + TermWin.saveLines;
2333 row = selection.end.row + TermWin.saveLines; 2349 int col, row = selection.end.row + TermWin.saveLines;
2350 rend_t *srp;
2351
2334 if (i >= end_row) 2352 if (i >= end_row)
2335 col = selection.beg.col; 2353 col = selection.beg.col;
2336 else 2354 else
2337 { 2355 {
2338 col = 0; 2356 col = 0;
2339 i = end_row; 2357 i = end_row;
2340 } 2358 }
2359
2341 end_row += TermWin.nrow; 2360 end_row += TermWin.nrow;
2342 for (; i < row && i < end_row; i++, col = 0) 2361 for (; i < row && i < end_row; i++, col = 0)
2343 for (srp = screen.rend[i]; col < TermWin.ncol; col++) 2362 for (srp = screen.rend[i]; col < TermWin.ncol; col++)
2344 srp[col] ^= RS_RVid; 2363 srp[col] ^= RS_RVid;
2364
2345 if (i == row && i < end_row) 2365 if (i == row && i < end_row)
2346 for (srp = screen.rend[i]; col < selection.end.col; col++) 2366 for (srp = screen.rend[i]; col < selection.end.col; col++)
2347 srp[col] ^= RS_RVid; 2367 srp[col] ^= RS_RVid;
2348 } 2368 }
2349} 2369}
2488 } 2508 }
2489 2509
2490 for (;;) 2510 for (;;)
2491 { 2511 {
2492 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), 2512 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4),
2493 (long) (PROP_SIZE / 4), delete_prop, 2513 (long) (PROP_SIZE / 4), delete_prop,
2494 AnyPropertyType, &ct.encoding, &ct.format, 2514 AnyPropertyType, &ct.encoding, &ct.format,
2495 &ct.nitems, &bytes_after, 2515 &ct.nitems, &bytes_after,
2496 &ct.value) != Success) 2516 &ct.value) != Success)
2497 break; 2517 break;
2498 2518
2499 if (ct.encoding == 0) 2519 if (ct.encoding == 0)
2500 { 2520 {
2501 D_SELECT ((stderr, "rxvt_selection_paste: property didn't exist!")); 2521 D_SELECT ((stderr, "rxvt_selection_paste: property didn't exist!"));
2509 } 2529 }
2510 2530
2511 if (ct.nitems == 0) 2531 if (ct.nitems == 0)
2512 { 2532 {
2513 D_SELECT ((stderr, "rxvt_selection_paste: property empty - also INCR end")); 2533 D_SELECT ((stderr, "rxvt_selection_paste: property empty - also INCR end"));
2514 if (selection_wait == Sel_normal && nread == 0) 2534 if (selection_wait == Sel_normal && nread == 0
2535 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2515 { 2536 {
2516 /* 2537 /*
2517 * pass through again trying CUT_BUFFER0 if we've come from 2538 * pass through again trying CUT_BUFFER0 if we've come from
2518 * XConvertSelection () but nothing was presented 2539 * XConvertSelection () but nothing was presented
2519 */ 2540 */
2710 * EXT: button 1 or 3 release 2731 * EXT: button 1 or 3 release
2711 */ 2732 */
2712void 2733void
2713rxvt_term::selection_make (Time tm) 2734rxvt_term::selection_make (Time tm)
2714{ 2735{
2715 int i, col, end_col, row, end_row; 2736 int i, col, end_col, row, end_row;
2716 unsigned char *new_selection_text; 2737 unsigned char *new_selection_text;
2717 char *str; 2738 char *str;
2718 text_t *t; 2739 text_t *t;
2719#ifdef ACS_ASCII
2720 rend_t *re;
2721#endif
2722 2740
2723 D_SELECT ((stderr, "rxvt_selection_make (): selection.op=%d, selection.clicks=%d", selection.op, selection.clicks)); 2741 D_SELECT ((stderr, "rxvt_selection_make (): selection.op=%d, selection.clicks=%d", selection.op, selection.clicks));
2724 switch (selection.op) 2742 switch (selection.op)
2725 { 2743 {
2726 case SELECTION_CONT: 2744 case SELECTION_CONT:
2732 selection.op = SELECTION_DONE; 2750 selection.op = SELECTION_DONE;
2733 /* FALLTHROUGH */ 2751 /* FALLTHROUGH */
2734 default: 2752 default:
2735 return; 2753 return;
2736 } 2754 }
2755
2737 selection.op = SELECTION_DONE; 2756 selection.op = SELECTION_DONE;
2738 2757
2739 if (selection.clicks == 4) 2758 if (selection.clicks == 4)
2740 return; /* nothing selected, go away */ 2759 return; /* nothing selected, go away */
2741 2760
2742 i = (selection.end.row - selection.beg.row + 1) * (TermWin.ncol + 1) + 1; 2761 i = (selection.end.row - selection.beg.row + 1) * (TermWin.ncol + 1) + 1;
2743 str = (char *)rxvt_malloc (i * MB_CUR_MAX + 1); 2762 str = (char *)rxvt_malloc ((i + 2) * MB_CUR_MAX + 1);
2744 2763
2745 new_selection_text = (unsigned char *)str; 2764 new_selection_text = (unsigned char *)str;
2746 2765
2747 col = selection.beg.col; 2766 col = selection.beg.col;
2748 MAX_IT (col, 0); 2767 MAX_IT (col, 0);
2749 row = selection.beg.row + TermWin.saveLines; 2768 row = selection.beg.row + TermWin.saveLines;
2750 end_row = selection.end.row + TermWin.saveLines; 2769 end_row = selection.end.row + TermWin.saveLines;
2770 struct mbstate mbs;
2751 2771
2752 for (; row <= end_row; row++, col = 0) 2772 for (; row <= end_row; row++, col = 0)
2753 { 2773 {
2754 t = & (screen.text[row][col]); 2774 t = & (screen.text[row][col]);
2755 2775
2764 for (; col < end_col; col++) 2784 for (; col < end_col; col++)
2765 if (*t == NOCHAR) 2785 if (*t == NOCHAR)
2766 t++; 2786 t++;
2767 else 2787 else
2768 { 2788 {
2769 int len = wctomb (str, *t++); 2789 int len = wcrtomb (str, *t++, mbs);
2770 if (len > 0) 2790 if (len > 0)
2771 str += len; 2791 str += len;
2772 } 2792 }
2773 2793
2774 if (screen.tlen[row] != -1 && row != end_row) 2794 if (screen.tlen[row] != -1 && row != end_row)
2792 { 2812 {
2793 free (new_selection_text); 2813 free (new_selection_text);
2794 return; 2814 return;
2795 } 2815 }
2796 2816
2797 // due to MB_MAX_CUR, selection wastage is usually high, so realloc 2817 // due to MB_CUR_MAX, selection wastage is usually high, so realloc
2798 if (str - (char *)new_selection_text > 1024) 2818 if (str - (char *)new_selection_text > 1024)
2799 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); 2819 new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1);
2800 2820
2801 selection.len = i; 2821 selection.len = i;
2802 2822
2816 char *cl = (char *)selection.text; 2836 char *cl = (char *)selection.text;
2817 2837
2818 if (XmbTextListToTextProperty (display->display, &cl, 1, XStringStyle, &ct) >= 0) 2838 if (XmbTextListToTextProperty (display->display, &cl, 1, XStringStyle, &ct) >= 0)
2819 { 2839 {
2820 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 2840 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8,
2821 PropModeReplace, ct.value, ct.nitems); 2841 PropModeReplace, ct.value, ct.nitems);
2822 XFree (ct.value); 2842 XFree (ct.value);
2823 } 2843 }
2824 else 2844 else
2825 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 2845 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8,
2826 PropModeReplace, selection.text, (int)selection.len); 2846 PropModeReplace, selection.text, (int)selection.len);
2827 } 2847 }
2828 2848
2829 selection_time = tm; 2849 selection_time = tm;
2830 D_SELECT ((stderr, "rxvt_selection_make (): selection.len=%d", selection.len)); 2850 D_SELECT ((stderr, "rxvt_selection_make (): selection.len=%d", selection.len));
2831} 2851}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines