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.352 by root, Fri Oct 15 20:52:15 2010 UTC vs.
Revision 1.373 by sf-exg, Sat Feb 12 00:30:01 2011 UTC

38 while (len--) 38 while (len--)
39 *start++ = value; 39 *start++ = value;
40} 40}
41 41
42/* ------------------------------------------------------------------------- */ 42/* ------------------------------------------------------------------------- */
43#define PROP_SIZE 256*1024
44#define PASTE_SIZE 32768
45#define TABSIZE 8 /* default tab size */ 43#define TABSIZE 8 /* default tab size */
46 44
47/* ------------------------------------------------------------------------- * 45/* ------------------------------------------------------------------------- *
48 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 46 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
49 * ------------------------------------------------------------------------- */ 47 * ------------------------------------------------------------------------- */
400 } 398 }
401 399
402 free (tabs); 400 free (tabs);
403 tabs = (char *)rxvt_malloc (ncol); 401 tabs = (char *)rxvt_malloc (ncol);
404 402
405 for (int col = ncol; --col; ) 403 for (int col = ncol; col--; )
406 tabs [col] = col % TABSIZE == 0; 404 tabs [col] = col % TABSIZE == 0;
407 405
408 CLEAR_ALL_SELECTION (); 406 CLEAR_ALL_SELECTION ();
409 407
410 prev_nrow = nrow; 408 prev_nrow = nrow;
917 else 915 else
918 screen.cur.col = ncol - width; 916 screen.cur.col = ncol - width;
919 } 917 }
920 918
921 // nuke the character at this position, if required 919 // nuke the character at this position, if required
922 if (expect_false ( 920 // due to wonderful coincidences everywhere else in this loop
921 // we never have to check for overwriting a wide char itself,
922 // only its tail.
923 line->t[screen.cur.col] == NOCHAR 923 if (expect_false (line->t[screen.cur.col] == NOCHAR))
924 || (screen.cur.col < ncol - 1
925 && line->t[screen.cur.col + 1] == NOCHAR)
926 ))
927 scr_kill_char (*line, screen.cur.col); 924 scr_kill_char (*line, screen.cur.col);
928 925
929 line->touch (); 926 line->touch ();
930 927
931 do 928 do
1686 { 1683 {
1687 rvideo_state = on; 1684 rvideo_state = on;
1688 1685
1689 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1686 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1690#ifdef HAVE_BG_PIXMAP 1687#ifdef HAVE_BG_PIXMAP
1691 if (bgPixmap.pixmap == None) 1688 if (bg_pixmap == None)
1692#endif 1689#endif
1693 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 1690 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
1694 1691
1695 XGCValues gcvalue; 1692 XGCValues gcvalue;
1696 gcvalue.foreground = pix_colors[Color_fg]; 1693 gcvalue.foreground = pix_colors[Color_fg];
2032 refresh_count = 0; 2029 refresh_count = 0;
2033 2030
2034 unsigned int old_screen_flags = screen.flags; 2031 unsigned int old_screen_flags = screen.flags;
2035 char have_bg = 0; 2032 char have_bg = 0;
2036#ifdef HAVE_BG_PIXMAP 2033#ifdef HAVE_BG_PIXMAP
2037 have_bg = bgPixmap.pixmap != None; 2034 have_bg = bg_pixmap != None;
2038#endif 2035#endif
2039 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2036 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
2040 2037
2041 /* 2038 /*
2042 * B: reverse any characters which are selected 2039 * B: reverse any characters which are selected
2509 scr_remap_chars (swap_buf [i]); 2506 scr_remap_chars (swap_buf [i]);
2510 } 2507 }
2511} 2508}
2512 2509
2513void 2510void
2514rxvt_term::scr_recolour () NOTHROW 2511rxvt_term::scr_recolour (bool refresh) NOTHROW
2515{ 2512{
2513 bool transparent = false;
2514
2516#ifdef HAVE_BG_PIXMAP 2515#ifdef HAVE_BG_PIXMAP
2517 bgPixmap.apply (); 2516 if (bg_pixmap != None)
2518#else 2517 {
2518# ifdef ENABLE_TRANSPARENCY
2519 if (bg_flags & BG_IS_TRANSPARENT)
2520 {
2521 XSetWindowBackgroundPixmap (dpy, parent[0], bg_pixmap);
2522 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
2519 2523
2524 transparent = true;
2525 }
2526 else
2527# endif
2528 {
2529 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]);
2530 XSetWindowBackgroundPixmap (dpy, vt, bg_pixmap);
2531 }
2532 }
2533 else
2534#endif
2535 {
2520 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]); 2536 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]);
2537 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2538 }
2539
2521 XClearWindow (dpy, parent[0]); 2540 XClearWindow (dpy, parent[0]);
2522 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2523 2541
2524 if (scrollBar.win) 2542 if (scrollBar.win)
2525 { 2543 {
2544 if (transparent)
2545 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
2546 else
2526 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); 2547 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2527 scrollBar.state = STATE_IDLE; 2548 scrollBar.state = STATE_IDLE;
2528 scrollBar.show (0); 2549 scrollBar.show (0);
2529 } 2550 }
2530 2551
2531#endif 2552 if (refresh)
2532 2553 {
2533 /* bgPixmap.apply () does not do the following : */
2534 scr_clear (); 2554 scr_clear ();
2535 scr_touch (true); 2555 scr_touch (true);
2556 }
2536 want_refresh = 1; 2557 want_refresh = 1;
2537} 2558}
2538 2559
2539/* ------------------------------------------------------------------------- */ 2560/* ------------------------------------------------------------------------- */
2540void 2561void
2628void 2649void
2629rxvt_term::scr_dump (int fd) NOTHROW 2650rxvt_term::scr_dump (int fd) NOTHROW
2630{ 2651{
2631 int row, wrote; 2652 int row, wrote;
2632 unsigned int width, towrite; 2653 unsigned int width, towrite;
2633 char r1[] = "\n"; 2654 const char r1[] = "\n";
2634 2655
2635 for (row = saveLines + top_row; 2656 for (row = saveLines + top_row;
2636 row < saveLines + nrow - 1; row++) 2657 row < saveLines + nrow - 1; row++)
2637 { 2658 {
2638 width = row_buf[row].l >= 0 ? row_buf[row].l 2659 width = row_buf[row].l >= 0 ? row_buf[row].l
2711 tt_paste (data, len); 2732 tt_paste (data, len);
2712} 2733}
2713 2734
2714/* ------------------------------------------------------------------------- */ 2735/* ------------------------------------------------------------------------- */
2715/* 2736/*
2716 * Respond to a notification that a primary selection has been sent
2717 * EXT: SelectionNotify
2718 */
2719void
2720rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) NOTHROW
2721{
2722 if (prop == None) /* check for failed XConvertSelection */
2723 {
2724 if ((selection_type & Sel_CompoundText))
2725 {
2726 int selnum = selection_type & Sel_whereMask;
2727
2728 selection_type = 0;
2729 if (selnum != Sel_direct)
2730 selection_request_other (XA_STRING, selnum);
2731 }
2732
2733 if ((selection_type & Sel_UTF8String))
2734 {
2735 int selnum = selection_type & Sel_whereMask;
2736
2737 selection_type = Sel_CompoundText;
2738 if (selnum != Sel_direct)
2739 selection_request_other (xa[XA_COMPOUND_TEXT], selnum);
2740 else
2741 selection_type = 0;
2742 }
2743
2744 return;
2745 }
2746
2747 unsigned long bytes_after;
2748 XTextProperty ct;
2749
2750 if (XGetWindowProperty (dpy, win, prop,
2751 0, PROP_SIZE / 4,
2752 delete_prop, AnyPropertyType,
2753 &ct.encoding, &ct.format,
2754 &ct.nitems, &bytes_after,
2755 &ct.value) != Success)
2756 {
2757 ct.value = 0;
2758 goto bailout;
2759 }
2760
2761 if (ct.encoding == None)
2762 goto bailout;
2763
2764 if (bytes_after)
2765 {
2766 // fetch and append remaining data
2767 XTextProperty ct2;
2768
2769 if (XGetWindowProperty (dpy, win, prop,
2770 ct.nitems / 4, (bytes_after + 3) / 4,
2771 delete_prop, AnyPropertyType,
2772 &ct2.encoding, &ct2.format,
2773 &ct2.nitems, &bytes_after,
2774 &ct2.value) != Success)
2775 goto bailout;
2776
2777 // realloc should be compatible to XFree, here, and elsewhere, too
2778 ct.value = (unsigned char *)realloc (ct.value, ct.nitems + ct2.nitems + 1);
2779 memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems + 1);
2780 ct.nitems += ct2.nitems;
2781
2782 XFree (ct2.value);
2783 }
2784
2785 if (ct.value == 0)
2786 goto bailout;
2787
2788 if (ct.encoding == xa[XA_INCR])
2789 {
2790 // INCR selection, start handshake
2791 if (!delete_prop)
2792 XDeleteProperty (dpy, win, prop);
2793
2794 selection_wait = Sel_incr;
2795 incr_buf_fill = 0;
2796 incr_ev.start (10);
2797
2798 goto bailout;
2799 }
2800
2801 if (ct.nitems == 0)
2802 {
2803 if (selection_wait == Sel_incr)
2804 {
2805 XFree (ct.value);
2806
2807 // finally complete, now paste the whole thing
2808 selection_wait = Sel_normal;
2809 ct.value = (unsigned char *)incr_buf;
2810 ct.nitems = incr_buf_fill;
2811 incr_buf = 0;
2812 incr_buf_size = 0;
2813 incr_ev.stop ();
2814 }
2815 else
2816 {
2817 if (selection_wait == Sel_normal
2818 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2819 {
2820 /*
2821 * pass through again trying CUT_BUFFER0 if we've come from
2822 * XConvertSelection () but nothing was presented
2823 */
2824 selection_paste (display->root, XA_CUT_BUFFER0, False);
2825 }
2826
2827 goto bailout;
2828 }
2829 }
2830 else if (selection_wait == Sel_incr)
2831 {
2832 incr_ev.start (10);
2833
2834 while (incr_buf_fill + ct.nitems > incr_buf_size)
2835 {
2836 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2837 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2838 }
2839
2840 memcpy (incr_buf + incr_buf_fill, ct.value, ct.nitems);
2841 incr_buf_fill += ct.nitems;
2842
2843 goto bailout;
2844 }
2845
2846 char **cl;
2847 int cr;
2848
2849#if !ENABLE_MINIMAL
2850 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2851 // so recode it manually
2852 if (ct.encoding == xa[XA_UTF8_STRING])
2853 {
2854 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2855 char *s = rxvt_wcstombs (w);
2856 free (w);
2857 // TODO: strlen == only the first element will be converted. well...
2858 paste (s, strlen (s));
2859 free (s);
2860 }
2861 else
2862#endif
2863 if (XmbTextPropertyToTextList (dpy, &ct, &cl, &cr) >= 0
2864 && cl)
2865 {
2866 for (int i = 0; i < cr; i++)
2867 paste (cl[i], strlen (cl[i]));
2868
2869 XFreeStringList (cl);
2870 }
2871 else
2872 paste ((char *)ct.value, ct.nitems); // paste raw
2873
2874bailout:
2875 XFree (ct.value);
2876
2877 if (selection_wait == Sel_normal)
2878 selection_wait = Sel_none;
2879}
2880
2881void
2882rxvt_term::incr_cb (ev::timer &w, int revents) NOTHROW
2883{
2884 selection_wait = Sel_none;
2885
2886 incr_buf_size = 0;
2887 free (incr_buf);
2888
2889 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2890}
2891
2892void
2893rxvt_term::selection_property (Window win, Atom prop) NOTHROW
2894{
2895 if (prop == None || selection_wait != Sel_incr)
2896 return;
2897
2898 selection_paste (win, prop, true);
2899}
2900
2901/* ------------------------------------------------------------------------- */
2902/*
2903 * Request the current selection: 2737 * Request the current selection:
2904 * Order: > internal selection if available 2738 * Order: > internal selection if available
2905 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+) 2739 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+)
2906 * > CUT_BUFFER0 2740 * > CUT_BUFFER0
2907 * (+) if ownership is claimed but property is empty, rxvt_selection_paste () 2741 * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
2908 * will auto fallback to CUT_BUFFER0 2742 * will auto fallback to CUT_BUFFER0
2909 * EXT: button 2 release 2743 * EXT: button 2 release
2910 */ 2744 */
2745
2746static void
2747selection_cb (char *data, unsigned int len, rxvt_selection *rs, void *ptr)
2748{
2749 rxvt_term *term = (rxvt_term *)ptr;
2750
2751 if (data)
2752 term->paste (data, len);
2753 delete rs;
2754 term->selection_req = 0;
2755}
2756
2911void 2757void
2912rxvt_term::selection_request (Time tm, int selnum) NOTHROW 2758rxvt_term::selection_request (Time tm, int selnum) NOTHROW
2913{ 2759{
2914 if (selection.text && selnum == Sel_Primary) 2760 if (selection.text && selnum == Sel_Primary)
2915 { 2761 {
2917 char *str = rxvt_wcstombs (selection.text, selection.len); 2763 char *str = rxvt_wcstombs (selection.text, selection.len);
2918 paste (str, strlen (str)); 2764 paste (str, strlen (str));
2919 free (str); 2765 free (str);
2920 return; 2766 return;
2921 } 2767 }
2922 else 2768 else if (!selection_req)
2923 {
2924 selection_request_time = tm;
2925 selection_wait = Sel_normal;
2926
2927#if X_HAVE_UTF8_STRING
2928 selection_type = Sel_UTF8String;
2929 if (selection_request_other (xa[XA_UTF8_STRING], selnum))
2930 return;
2931#else
2932 selection_type = Sel_CompoundText;
2933 if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum))
2934 return;
2935#endif
2936 } 2769 {
2937 2770 selection_req = new rxvt_selection (display, selnum, tm, vt, xa[XA_VT_SELECTION], selection_cb, this);
2938 selection_wait = Sel_none; /* don't loop in selection_paste () */ 2771 selection_req->run ();
2939 selection_paste (display->root, XA_CUT_BUFFER0, false);
2940}
2941
2942int
2943rxvt_term::selection_request_other (Atom target, int selnum) NOTHROW
2944{
2945 Atom sel;
2946
2947 selection_type |= selnum;
2948
2949 if (selnum == Sel_Primary)
2950 sel = XA_PRIMARY;
2951 else if (selnum == Sel_Secondary)
2952 sel = XA_SECONDARY;
2953 else
2954 sel = xa[XA_CLIPBOARD];
2955
2956 if (XGetSelectionOwner (dpy, sel) != None)
2957 { 2772 }
2958 XConvertSelection (dpy, sel, target, xa[XA_VT_SELECTION],
2959 vt, selection_request_time);
2960 return 1;
2961 }
2962
2963 return 0;
2964} 2773}
2965 2774
2966/* ------------------------------------------------------------------------- */ 2775/* ------------------------------------------------------------------------- */
2967/* 2776/*
2968 * Clear all selected text 2777 * Clear all selected text
2999 * EXT: button 1 or 3 release 2808 * EXT: button 1 or 3 release
3000 */ 2809 */
3001void 2810void
3002rxvt_term::selection_make (Time tm) 2811rxvt_term::selection_make (Time tm)
3003{ 2812{
3004 int i; 2813 int size;
3005 wchar_t *new_selection_text; 2814 wchar_t *new_selection_text;
3006 text_t *t; 2815 text_t *t;
3007 2816
3008 switch (selection.op) 2817 switch (selection.op)
3009 { 2818 {
3025 return; /* nothing selected, go away */ 2834 return; /* nothing selected, go away */
3026 2835
3027 if (HOOK_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END))) 2836 if (HOOK_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END)))
3028 return; 2837 return;
3029 2838
3030 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); 2839 size = (selection.end.row - selection.beg.row + 1) * (ncol + 1);
3031 new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t)); 2840 new_selection_text = (wchar_t *)rxvt_malloc ((size + 4) * sizeof (wchar_t));
3032 2841
3033 int ofs = 0; 2842 int ofs = 0;
3034 int extra = 0; 2843 int extra = 0;
3035 2844
3036 int col = selection.beg.col; 2845 int col = selection.beg.col;
3042 { 2851 {
3043#if !ENABLE_MINIMAL 2852#if !ENABLE_MINIMAL
3044 if (selection.rect) 2853 if (selection.rect)
3045 { 2854 {
3046 col = selection.beg.col; 2855 col = selection.beg.col;
3047 end_col = ncol + 1; 2856 end_col = selection.end.col;
3048 } 2857 }
3049 else 2858 else
3050#endif 2859#endif
3051 end_col = ROW(row).l; 2860 end_col = ROW(row).l;
3052 2861
3053 col = max (col, 0); 2862 col = max (col, 0);
3054 2863
3055 if (row == selection.end.row 2864 if (row == selection.end.row)
3056#if !ENABLE_MINIMAL
3057 || selection.rect
3058#endif
3059 )
3060 min_it (end_col, selection.end.col); 2865 min_it (end_col, selection.end.col);
3061 2866
3062 t = ROW(row).t + col; 2867 t = ROW(row).t + col;
3063 2868
3064 for (; col < end_col; col++) 2869 for (; col < end_col; col++)
3072 2877
3073 extra -= (len - 1); 2878 extra -= (len - 1);
3074 2879
3075 if (extra < 0) 2880 if (extra < 0)
3076 { 2881 {
3077 extra += i; 2882 extra += size;
3078 i += i; 2883 size += size;
3079 new_selection_text = (wchar_t *)rxvt_realloc (new_selection_text, (i + 4) * sizeof (wchar_t)); 2884 new_selection_text = (wchar_t *)rxvt_realloc (new_selection_text, (size + 4) * sizeof (wchar_t));
3080 } 2885 }
3081 2886
3082 ofs += rxvt_composite.expand (*t++, new_selection_text + ofs); 2887 ofs += rxvt_composite.expand (*t++, new_selection_text + ofs);
3083 } 2888 }
3084#endif 2889#endif
3096 2901
3097 new_selection_text[ofs++] = C0_LF; 2902 new_selection_text[ofs++] = C0_LF;
3098 } 2903 }
3099 else 2904 else
3100#endif 2905#endif
3101 if (!ROW(row).is_longer () && row != selection.end.row) 2906 if (!ROW(row).is_longer ()
2907 && (row != selection.end.row || end_col != selection.end.col)
2908 && (row != selection.beg.row || selection.beg.col < ncol))
3102 new_selection_text[ofs++] = C0_LF; 2909 new_selection_text[ofs++] = C0_LF;
3103 } 2910 }
3104
3105 if (end_col != selection.end.col)
3106 new_selection_text[ofs++] = C0_LF;
3107 2911
3108 new_selection_text[ofs] = 0; 2912 new_selection_text[ofs] = 0;
3109 2913
3110 if (ofs == 0) 2914 if (ofs == 0)
3111 { 2915 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines