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.141 by root, Wed Dec 1 02:12:18 2004 UTC vs.
Revision 1.155 by root, Thu Feb 3 07:45:39 2005 UTC

39 while (len--) 39 while (len--)
40 *start++ = value; 40 *start++ = value;
41} 41}
42 42
43/* ------------------------------------------------------------------------- */ 43/* ------------------------------------------------------------------------- */
44#define PROP_SIZE 16384 44#define PROP_SIZE 256*1024
45#define PASTE_SIZE 32768
45#define TABSIZE 8 /* default tab size */ 46#define TABSIZE 8 /* default tab size */
46 47
47/* ------------------------------------------------------------------------- * 48/* ------------------------------------------------------------------------- *
48 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 49 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
49 * ------------------------------------------------------------------------- */ 50 * ------------------------------------------------------------------------- */
293 ralloc->free (drawn_rend[p]); 294 ralloc->free (drawn_rend[p]);
294 } 295 }
295 296
296 /* we have fewer rows so fix up cursor position */ 297 /* we have fewer rows so fix up cursor position */
297 MIN_IT (screen.cur.row, (int32_t)nrow - 1); 298 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
298 MIN_IT (swap.cur.row, (int32_t)nrow - 1);
299 299
300 scr_reset_realloc (); /* realloc _last_ */ 300 scr_reset_realloc (); /* realloc _last_ */
301 } 301 }
302 else if (nrow > prev_nrow) 302 else if (nrow > prev_nrow)
303 { 303 {
334 scr_scroll_text (0, (int)nrow - 1, -k, 1); 334 scr_scroll_text (0, (int)nrow - 1, -k, 1);
335 screen.cur.row += k; 335 screen.cur.row += k;
336 screen.s_cur.row += k; 336 screen.s_cur.row += k;
337 TermWin.nscrolled -= k; 337 TermWin.nscrolled -= k;
338 } 338 }
339
339#ifdef DEBUG_STRICT 340#ifdef DEBUG_STRICT
340 assert (screen.cur.row < TermWin.nrow); 341 assert (screen.cur.row < TermWin.nrow);
341 assert (swap.cur.row < TermWin.nrow);
342#else /* drive with your eyes closed */ 342#else /* drive with your eyes closed */
343
344 MIN_IT (screen.cur.row, nrow - 1); 343 MIN_IT (screen.cur.row, nrow - 1);
345 MIN_IT (swap.cur.row, nrow - 1);
346#endif 344#endif
347 TermWin.ncol = ncol; // save b/c scr_blank_screen_mem uses this 345 TermWin.ncol = ncol; // save b/c scr_blank_screen_mem uses this
348 } 346 }
349 347
350 /* resize columns */ 348 /* resize columns */
393 } 391 }
394 392
395 } 393 }
396 394
397 MIN_IT (screen.cur.col, (int16_t)ncol - 1); 395 MIN_IT (screen.cur.col, (int16_t)ncol - 1);
398 MIN_IT (swap.cur.col, (int16_t)ncol - 1);
399 396
400 delete talloc; talloc = ta; 397 delete talloc; talloc = ta;
401 delete ralloc; ralloc = ra; 398 delete ralloc; ralloc = ra;
402 } 399 }
403 400
565 if (current_screen == scrn) 562 if (current_screen == scrn)
566 return scrn; 563 return scrn;
567 564
568 selection_check (2); /* check for boundary cross */ 565 selection_check (2); /* check for boundary cross */
569 566
570 SWAP_IT (current_screen, scrn, int); 567 i = current_screen; current_screen = scrn; scrn = i;
571 568
572 SWAP_IT (screen.cur.row, swap.cur.row, int16_t); 569 SWAP_IT (screen.cur.row, swap.cur.row, int16_t);
573 SWAP_IT (screen.cur.col, swap.cur.col, int16_t); 570 SWAP_IT (screen.cur.col, swap.cur.col, int16_t);
574# ifdef DEBUG_STRICT
575 assert (screen.cur.row >= 0 && screen.cur.row < prev_nrow);
576 assert (screen.cur.col >= 0 && screen.cur.col < prev_ncol);
577# else /* drive with your eyes closed */
578 MAX_IT (screen.cur.row, 0); 571 MAX_IT (screen.cur.row, 0);
579 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); 572 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1);
580 MAX_IT (screen.cur.col, 0); 573 MAX_IT (screen.cur.col, 0);
581 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1); 574 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1);
582# endif
583 575
584#if NSCREENS 576#if NSCREENS
585 if (options & Opt_secondaryScreen) 577 if (options & Opt_secondaryScreen)
586 { 578 {
587 num_scr = 0; 579 num_scr = 0;
600 swap.flags |= Screen_VisibleCursor; 592 swap.flags |= Screen_VisibleCursor;
601 } 593 }
602 else 594 else
603#endif 595#endif
604 if (options & Opt_secondaryScroll) 596 if (options & Opt_secondaryScroll)
605 //if (current_screen == PRIMARY)
606 scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0); 597 scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0);
607 598
608 return scrn; 599 return scrn;
609} 600}
610 601
611// clear WrapNext indicator, solidifying position on next line 602// clear WrapNext indicator, solidifying position on next line
888 // rely on wcwidth to tell us the character width, at least for non-latin1 879 // rely on wcwidth to tell us the character width, at least for non-latin1
889 // do wcwidth before further replacements, as wcwidth says that line-drawing 880 // do wcwidth before further replacements, as wcwidth says that line-drawing
890 // characters have width -1 (DOH!) on GNU/Linux sometimes. 881 // characters have width -1 (DOH!) on GNU/Linux sometimes.
891 int width = c < 0x100 ? 1 : wcwidth (c); 882 int width = c < 0x100 ? 1 : wcwidth (c);
892 883
893 if (screen.flags & Screen_Insert)
894 scr_insdel_chars (width, INSERT);
895
896 if (charsets[screen.charset] == '0') // DEC SPECIAL 884 if (charsets[screen.charset] == '0') // DEC SPECIAL
897 { 885 {
898 // vt100 special graphics and line drawing 886 // vt100 special graphics and line drawing
899 // 5f-7e standard vt100 887 // 5f-7e standard vt100
900 // 40-5e rxvt extension for extra curses acs chars 888 // 40-5e rxvt extension for extra curses acs chars
901 static uint16_t vt100_0[63] = { // 5f .. 7e 889 static uint16_t vt100_0[63] = { // 40 .. 7e
902 0x0000, 0x2191, 0x2193, 0x2192, 0x2190, 0x2588, 0x259a, 0x2603, // 40-47 hi mr. snowman! 890 0x0000, 0x2191, 0x2193, 0x2192, 0x2190, 0x2588, 0x259a, 0x2603, // 40-47 hi mr. snowman!
903 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 48-4f 891 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 48-4f
904 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 50-57 892 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 50-57
905 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, // 58-5f 893 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, // 58-5f
906 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, // 60-67 894 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, // 60-67
914 c = vt100_0[c - 0x40]; 902 c = vt100_0[c - 0x40];
915 width = 1; 903 width = 1;
916 } 904 }
917 } 905 }
918 906
907 if (screen.flags & Screen_Insert)
908 scr_insdel_chars (width, INSERT);
909
919 if (width != 0) 910 if (width != 0)
920 { 911 {
921 // some utf-8 decoders decode surrogate characters. 912 // some utf-8 decoders decode surrogate characters.
922 if (0xd800 <= c && c <= 0xdfff) 913 if (0xd800 <= c && c <= 0xdfff)
923 c = 0xfffd; 914 c = 0xfffd;
973 c = NOCHAR; 964 c = NOCHAR;
974 } 965 }
975 while (--width > 0); 966 while (--width > 0);
976 967
977 // pad with spaces when overwriting wide character with smaller one 968 // pad with spaces when overwriting wide character with smaller one
969 if (!width)
978 for (int c = screen.cur.col; c < last_col && stp[c] == NOCHAR; c++) 970 for (int c = screen.cur.col; c < last_col && stp[c] == NOCHAR; c++)
979 { 971 {
980 stp[c] = ' '; 972 stp[c] = ' ';
981 srp[c] = rend; 973 srp[c] = rend;
982 } 974 }
983 } 975 }
984 else if (width == 0) 976 else if (width == 0)
985 { 977 {
986#if ENABLE_COMBINING 978#if ENABLE_COMBINING
987 // handle combining characters 979 // handle combining characters
2398 } 2390 }
2399 else 2391 else
2400 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back); 2392 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back);
2401 2393
2402 if (rend & RS_Uline && font->descent > 1 && fore != back) 2394 if (rend & RS_Uline && font->descent > 1 && fore != back)
2395 {
2396#if ENABLE_FRILLS
2397 if (ISSET_PIXCOLOR (Color_underline))
2398 XSetForeground (display->display, TermWin.gc, pix_colors[Color_underline]);
2399 else
2400#endif
2401 XSetForeground (display->display, TermWin.gc, pix_colors[fore]);
2402
2403 XDrawLine (display->display, drawBuffer, TermWin.gc, 2403 XDrawLine (display->display, drawBuffer, TermWin.gc,
2404 xpixel, ypixel + font->ascent + 1, 2404 xpixel, ypixel + font->ascent + 1,
2405 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2405 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2406 }
2406 } /* for (col....) */ 2407 } /* for (col....) */
2407 } /* for (row....) */ 2408 } /* for (row....) */
2408 2409
2409#if ENABLE_OVERLAY 2410#if ENABLE_OVERLAY
2410 scr_swap_overlay (); 2411 scr_swap_overlay ();
2652/* ------------------------------------------------------------------------- */ 2653/* ------------------------------------------------------------------------- */
2653/* 2654/*
2654 * Paste a selection direct to the command fd 2655 * Paste a selection direct to the command fd
2655 */ 2656 */
2656void 2657void
2657rxvt_term::paste (const unsigned char *data, unsigned int len) 2658rxvt_term::paste (unsigned char *data, unsigned int len)
2658{ 2659{
2659 unsigned int i, j, n;
2660 unsigned char *ds = (unsigned char *)rxvt_malloc (PROP_SIZE);
2661
2662 /* convert normal newline chars into common keyboard Return key sequence */ 2660 /* convert normal newline chars into common keyboard Return key sequence */
2663 for (i = 0; i < len; i += PROP_SIZE) 2661 for (unsigned int i = 0; i < len; i++)
2664 {
2665 n = min (len - i, PROP_SIZE);
2666 memcpy (ds, data + i, n);
2667
2668 for (j = 0; j < n; j++)
2669 if (ds[j] == C0_LF) 2662 if (data[i] == C0_LF)
2670 ds[j] = C0_CR; 2663 data[i] = C0_CR;
2671 2664
2672 tt_write (ds, (int)n); 2665 tt_write (data, len);
2673 }
2674
2675 free (ds);
2676} 2666}
2677 2667
2678/* ------------------------------------------------------------------------- */ 2668/* ------------------------------------------------------------------------- */
2679/* 2669/*
2680 * Respond to a notification that a primary selection has been sent 2670 * Respond to a notification that a primary selection has been sent
2681 * EXT: SelectionNotify 2671 * EXT: SelectionNotify
2682 */ 2672 */
2683int 2673void
2684rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) 2674rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop)
2685{ 2675{
2686 long nread = 0;
2687 unsigned long bytes_after;
2688 XTextProperty ct;
2689
2690 if (prop == None) /* check for failed XConvertSelection */ 2676 if (prop == None) /* check for failed XConvertSelection */
2691 { 2677 {
2692 if ((selection_type & Sel_CompoundText)) 2678 if ((selection_type & Sel_CompoundText))
2693 { 2679 {
2694 int selnum = selection_type & Sel_whereMask; 2680 int selnum = selection_type & Sel_whereMask;
2707 selection_request_other (xa[XA_COMPOUND_TEXT], selnum); 2693 selection_request_other (xa[XA_COMPOUND_TEXT], selnum);
2708 else 2694 else
2709 selection_type = 0; 2695 selection_type = 0;
2710 } 2696 }
2711 2697
2712 return 0; 2698 return;
2713 }
2714
2715 for (;;)
2716 { 2699 }
2700
2701 unsigned long bytes_after;
2702 XTextProperty ct;
2703
2704 if (XGetWindowProperty (display->display, win, prop,
2705 0, PROP_SIZE / 4,
2706 delete_prop, AnyPropertyType,
2707 &ct.encoding, &ct.format,
2708 &ct.nitems, &bytes_after,
2709 &ct.value) != Success)
2710 {
2711 ct.value = 0;
2712 goto bailout;
2713 }
2714
2715 if (ct.encoding == None)
2716 goto bailout;
2717
2718 if (bytes_after)
2719 {
2720 // fetch and append remaining data
2721 XTextProperty ct2;
2722
2717 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), 2723 if (XGetWindowProperty (display->display, win, prop,
2718 (long) (PROP_SIZE / 4), delete_prop, 2724 ct.nitems / 4, (bytes_after + 3) / 4,
2725 delete_prop, AnyPropertyType,
2719 AnyPropertyType, &ct.encoding, &ct.format, 2726 &ct2.encoding, &ct2.format,
2720 &ct.nitems, &bytes_after, 2727 &ct2.nitems, &bytes_after,
2721 &ct.value) != Success) 2728 &ct2.value) != Success)
2722 break; 2729 goto bailout;
2723 2730
2724 if (ct.encoding == 0) 2731 // realloc should be compatible to XFree, here, and elsewhere, too
2725 break; 2732 ct.value = (unsigned char *)realloc (ct.value, ct.nitems + ct2.nitems + 1);
2733 memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems + 1);
2734 ct.nitems += ct2.nitems;
2726 2735
2736 XFree (ct2.value);
2737 }
2738
2739 if (ct.value == 0)
2740 goto bailout;
2741
2727 if (ct.encoding == xa[XA_INCR]) 2742 if (ct.encoding == xa[XA_INCR])
2728 { 2743 {
2729 // INCR selection, start handshake 2744 // INCR selection, start handshake
2745 if (!delete_prop)
2730 XDeleteProperty (display->display, win, prop); 2746 XDeleteProperty (display->display, win, prop);
2747
2731 selection_wait = Sel_incr; 2748 selection_wait = Sel_incr;
2749 incr_buf_fill = 0;
2732 incr_ev.start (NOW + 10); 2750 incr_ev.start (NOW + 10);
2733 break;
2734 }
2735 2751
2736 if (ct.value == NULL) 2752 goto bailout;
2737 continue; 2753 }
2738 2754
2739 if (ct.nitems == 0) 2755 if (ct.nitems == 0)
2756 {
2757 if (selection_wait == Sel_incr)
2758 {
2759 XFree (ct.value);
2760
2761 // finally complete, now paste the whole thing
2762 selection_wait = Sel_normal;
2763 ct.value = (unsigned char *)incr_buf;
2764 ct.nitems = incr_buf_fill;
2765 incr_buf = 0;
2766 incr_buf_size = 0;
2767 incr_ev.stop ();
2740 { 2768 }
2769 else
2770 {
2741 if (selection_wait == Sel_normal && nread == 0 2771 if (selection_wait == Sel_normal
2742 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2772 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2743 { 2773 {
2744 /* 2774 /*
2745 * pass through again trying CUT_BUFFER0 if we've come from 2775 * pass through again trying CUT_BUFFER0 if we've come from
2746 * XConvertSelection () but nothing was presented 2776 * XConvertSelection () but nothing was presented
2747 */ 2777 */
2748 selection_paste (display->root, XA_CUT_BUFFER0, False); 2778 selection_paste (display->root, XA_CUT_BUFFER0, False);
2749 } 2779 }
2750 2780
2751 nread = -1; /* discount any previous stuff */ 2781 goto bailout;
2752 break; 2782 }
2783 }
2784 else if (selection_wait == Sel_incr)
2785 {
2786 incr_ev.start (NOW + 10);
2787
2788 while (incr_buf_fill + ct.nitems > incr_buf_size)
2753 } 2789 {
2790 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2791 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2792 }
2754 2793
2794 memcpy (incr_buf + incr_buf_fill, ct.value, ct.nitems);
2755 nread += ct.nitems; 2795 incr_buf_fill += ct.nitems;
2756 2796
2797 goto bailout;
2798 }
2799
2757 char **cl; 2800 char **cl;
2758 int cr; 2801 int cr;
2802
2803#if ENABLE_FRILLS
2804 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2805 // so recode it manually
2806 if (ct.encoding == xa[XA_UTF8_STRING])
2807 {
2808 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2809 char *s = rxvt_wcstombs (w);
2810 free (w);
2811 // TODO: strlen == only the first element will be converted. well...
2812 paste ((unsigned char *)s, strlen (s));
2813 free (s);
2814 }
2815 else
2816#endif
2759 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 && cl) 2817 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0
2760 { 2818 && cl)
2819 {
2761 for (int i = 0; i < cr; i++) 2820 for (int i = 0; i < cr; i++)
2762 paste ((unsigned char *)cl[i], strlen (cl[i])); 2821 paste ((unsigned char *)cl[i], strlen (cl[i]));
2763 2822
2764 XFreeStringList (cl); 2823 XFreeStringList (cl);
2765 } 2824 }
2766 else 2825 else
2767 paste (ct.value, ct.nitems); 2826 paste (ct.value, ct.nitems); // paste raw
2768 2827
2769 if (bytes_after == 0) 2828bailout:
2770 break;
2771
2772 XFree (ct.value);
2773 }
2774
2775 if (ct.value)
2776 XFree (ct.value); 2829 XFree (ct.value);
2777 2830
2778 if (selection_wait == Sel_normal) 2831 if (selection_wait == Sel_normal)
2779 selection_wait = Sel_none; 2832 selection_wait = Sel_none;
2780
2781 return (int)nread;
2782} 2833}
2783 2834
2784void 2835void
2785rxvt_term::incr_cb (time_watcher &w) 2836rxvt_term::incr_cb (time_watcher &w)
2786{ 2837{
2787 selection_wait = Sel_none; 2838 selection_wait = Sel_none;
2788 2839
2840 incr_buf_size = 0;
2841 free (incr_buf);
2842
2789 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 2843 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2790} 2844}
2791 2845
2792/*
2793 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2794 */
2795void 2846void
2796rxvt_term::selection_property (Window win, Atom prop) 2847rxvt_term::selection_property (Window win, Atom prop)
2797{ 2848{
2798 if (prop == None || selection_wait != Sel_incr) 2849 if (prop == None || selection_wait != Sel_incr)
2799 return; 2850 return;
2800 2851
2801 if (selection_paste (win, prop, 1) > 0) 2852 selection_paste (win, prop, true);
2802 incr_ev.start (NOW + 10);
2803 else
2804 {
2805 selection_wait = Sel_none;
2806 incr_ev.stop ();
2807 }
2808} 2853}
2809 2854
2810/* ------------------------------------------------------------------------- */ 2855/* ------------------------------------------------------------------------- */
2811/* 2856/*
2812 * Request the current selection: 2857 * Request the current selection:
2846#else 2891#else
2847 selection_type = Sel_CompoundText; 2892 selection_type = Sel_CompoundText;
2848 if (selection_request_other (xa[XA_COMPOUND_TEXT], i)) 2893 if (selection_request_other (xa[XA_COMPOUND_TEXT], i))
2849 return; 2894 return;
2850#endif 2895#endif
2851
2852 } 2896 }
2853 } 2897 }
2854 2898
2855 selection_wait = Sel_none; /* don't loop in rxvt_selection_paste () */ 2899 selection_wait = Sel_none; /* don't loop in selection_paste () */
2856 selection_paste (display->root, XA_CUT_BUFFER0, False); 2900 selection_paste (display->root, XA_CUT_BUFFER0, false);
2857} 2901}
2858 2902
2859int 2903int
2860rxvt_term::selection_request_other (Atom target, int selnum) 2904rxvt_term::selection_request_other (Atom target, int selnum)
2861{ 2905{
3017#if 0 3061#if 0
3018 XTextProperty ct; 3062 XTextProperty ct;
3019 3063
3020 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3064 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0)
3021 { 3065 {
3022 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 3066 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
3023 PropModeReplace, ct.value, ct.nitems);
3024 XFree (ct.value); 3067 XFree (ct.value);
3025 } 3068 }
3026#endif 3069#endif
3027 3070
3028 selection_time = tm; 3071 selection_time = tm;
3366 selection_delimit_word (DN, &selection.end, &selection.end); 3409 selection_delimit_word (DN, &selection.end, &selection.end);
3367 } 3410 }
3368 else if (selection.clicks == 3) 3411 else if (selection.clicks == 3)
3369 { 3412 {
3370#if ENABLE_FRILLS 3413#if ENABLE_FRILLS
3371 if ((options & Opt_tripleclickwords)) 3414 if (options & Opt_tripleclickwords)
3372 { 3415 {
3373 int end_row; 3416 int end_row;
3374 3417
3375 selection_delimit_word (UP, &selection.beg, &selection.beg); 3418 selection_delimit_word (UP, &selection.beg, &selection.beg);
3376 end_row = screen.tlen[selection.mark.row + TermWin.saveLines]; 3419 end_row = screen.tlen[selection.mark.row + TermWin.saveLines];
3394 if (ROWCOL_IS_AFTER (selection.mark, selection.beg)) 3437 if (ROWCOL_IS_AFTER (selection.mark, selection.beg))
3395 selection.mark.col++; 3438 selection.mark.col++;
3396 3439
3397 selection.beg.col = 0; 3440 selection.beg.col = 0;
3398 selection.end.col = ncol; 3441 selection.end.col = ncol;
3442
3443 // select a complete logical line
3444 while (selection.beg.row > -TermWin.saveLines
3445 && screen.tlen[selection.beg.row - 1 + TermWin.saveLines] == -1)
3446 selection.beg.row--;
3447
3448 while (selection.end.row < TermWin.nrow
3449 && screen.tlen[selection.end.row + TermWin.saveLines] == -1)
3450 selection.end.row++;
3399 } 3451 }
3400 } 3452 }
3401 3453
3402 if (button3 && buttonpress) 3454 if (button3 && buttonpress)
3403 { /* mark may need to be changed */ 3455 { /* mark may need to be changed */
3483 */ 3535 */
3484void 3536void
3485rxvt_term::selection_send (const XSelectionRequestEvent &rq) 3537rxvt_term::selection_send (const XSelectionRequestEvent &rq)
3486{ 3538{
3487 XSelectionEvent ev; 3539 XSelectionEvent ev;
3488 XTextProperty ct;
3489 XICCEncodingStyle style;
3490 Atom target;
3491 3540
3492 ev.type = SelectionNotify; 3541 ev.type = SelectionNotify;
3493 ev.property = None; 3542 ev.property = None;
3494 ev.display = rq.display; 3543 ev.display = rq.display;
3495 ev.requestor = rq.requestor; 3544 ev.requestor = rq.requestor;
3532 || rq.target == xa[XA_TEXT] 3581 || rq.target == xa[XA_TEXT]
3533 || rq.target == xa[XA_COMPOUND_TEXT] 3582 || rq.target == xa[XA_COMPOUND_TEXT]
3534 || rq.target == xa[XA_UTF8_STRING] 3583 || rq.target == xa[XA_UTF8_STRING]
3535 ) 3584 )
3536 { 3585 {
3586 XTextProperty ct;
3587 Atom target = rq.target;
3537 short freect = 0; 3588 short freect = 0;
3538 int selectlen; 3589 int selectlen;
3539 wchar_t *cl; 3590 wchar_t *cl;
3540 3591 enum {
3541 target = rq.target; 3592 enc_string = XStringStyle,
3593 enc_text = XStdICCTextStyle,
3594 enc_compound_text = XCompoundTextStyle,
3595#ifdef X_HAVE_UTF8_STRING
3596 enc_utf8 = XUTF8StringStyle,
3597#else
3598 enc_utf8 = -1,
3599#endif
3600 } style;
3542 3601
3543 if (target == XA_STRING) 3602 if (target == XA_STRING)
3544 // we actually don't do XA_STRING, but who cares, as i18n clients 3603 // we actually don't do XA_STRING, but who cares, as i18n clients
3545 // will ask for another format anyways. 3604 // will ask for another format anyways.
3546 style = XStringStyle; 3605 style = enc_string;
3547 else if (target == xa[XA_TEXT]) 3606 else if (target == xa[XA_TEXT])
3548 style = XStdICCTextStyle; 3607 style = enc_text;
3549 else if (target == xa[XA_COMPOUND_TEXT]) 3608 else if (target == xa[XA_COMPOUND_TEXT])
3550 style = XCompoundTextStyle; 3609 style = enc_compound_text;
3551#if X_HAVE_UTF8_STRING 3610#if ENABLE_FRILLS
3552 else if (target == xa[XA_UTF8_STRING]) 3611 else if (target == xa[XA_UTF8_STRING])
3553 style = XUTF8StringStyle; 3612 style = enc_utf8;
3554#endif 3613#endif
3555 else 3614 else
3556 { 3615 {
3557 target = xa[XA_COMPOUND_TEXT]; 3616 target = xa[XA_COMPOUND_TEXT];
3558 style = XCompoundTextStyle; 3617 style = enc_compound_text;
3559 } 3618 }
3560 3619
3561 if (selection.text) 3620 if (selection.text)
3562 { 3621 {
3563 cl = selection.text; 3622 cl = selection.text;
3567 { 3626 {
3568 cl = L""; 3627 cl = L"";
3569 selectlen = 0; 3628 selectlen = 0;
3570 } 3629 }
3571 3630
3572 // Xwc doesn't handle iso-10646 in wchar_t gracefully, so maybe recode it 3631#if ENABLE_FRILLS
3573 // manually for XUTF8StringStyle. 3632 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
3633 // so recode it manually
3634 if (style == enc_utf8)
3635 {
3636 freect = 1;
3637 ct.encoding = target;
3638 ct.format = 8;
3639 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen);
3640 ct.nitems = strlen ((char *)ct.value);
3641 }
3642 else
3643#endif
3574 if (XwcTextListToTextProperty (display->display, &cl, 1, style, &ct) >= 0) 3644 if (XwcTextListToTextProperty (display->display, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0)
3575 freect = 1; 3645 freect = 1;
3576 else 3646 else
3577 { 3647 {
3578 /* if we failed to convert then send it raw */ 3648 /* if we failed to convert then send it raw */
3579 ct.value = (unsigned char *)cl; 3649 ct.value = (unsigned char *)cl;
3580 ct.nitems = selectlen; 3650 ct.nitems = selectlen;
3651 ct.encoding = target;
3581 } 3652 }
3582 3653
3583 XChangeProperty (display->display, rq.requestor, rq.property, 3654 XChangeProperty (display->display, rq.requestor, rq.property,
3584 target, 8, PropModeReplace, 3655 ct.encoding, 8, PropModeReplace,
3585 ct.value, (int)ct.nitems); 3656 ct.value, (int)ct.nitems);
3586 ev.property = rq.property; 3657 ev.property = rq.property;
3587 3658
3588 if (freect) 3659 if (freect)
3589 XFree (ct.value); 3660 XFree (ct.value);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines