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.139 by root, Sun Nov 21 18:51:13 2004 UTC vs.
Revision 1.170 by root, Mon Nov 28 19:35:04 2005 UTC

28#include "rxvt.h" /* NECESSARY */ 28#include "rxvt.h" /* NECESSARY */
29 29
30#include <X11/Xmd.h> /* get the typedef for CARD32 */ 30#include <X11/Xmd.h> /* get the typedef for CARD32 */
31 31
32#include <inttypes.h> 32#include <inttypes.h>
33#include <wchar.h>
34 33
35#include "salloc.C" // HACK, should be a seperate compile! 34#include "salloc.C" // HACK, should be a seperate compile!
36 35
37inline void fill_text (text_t *start, text_t value, int len) 36inline void fill_text (text_t *start, text_t value, int len)
38{ 37{
39 while (len--) 38 while (len--)
40 *start++ = value; 39 *start++ = value;
41} 40}
42 41
43/* ------------------------------------------------------------------------- */ 42/* ------------------------------------------------------------------------- */
44#define PROP_SIZE 16384 43#define PROP_SIZE 256*1024
44#define PASTE_SIZE 32768
45#define TABSIZE 8 /* default tab size */ 45#define TABSIZE 8 /* default tab size */
46 46
47/* ------------------------------------------------------------------------- * 47/* ------------------------------------------------------------------------- *
48 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 48 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
49 * ------------------------------------------------------------------------- */ 49 * ------------------------------------------------------------------------- */
202 /* 202 /*
203 * first time called so just malloc everything: don't rely on realloc 203 * first time called so just malloc everything: don't rely on realloc
204 * Note: this is still needed so that all the scrollback lines are NULL 204 * Note: this is still needed so that all the scrollback lines are NULL
205 */ 205 */
206 screen.text = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *)); 206 screen.text = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *));
207 buf_text = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *)); 207 buf_text = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *));
208 drawn_text = (text_t **)rxvt_calloc (nrow, sizeof (text_t *)); 208 drawn_text = (text_t **)rxvt_calloc (nrow, sizeof (text_t *));
209 swap.text = (text_t **)rxvt_calloc (nrow, sizeof (text_t *)); 209 swap.text = (text_t **)rxvt_calloc (nrow, sizeof (text_t *));
210 210
211 screen.tlen = (int16_t *)rxvt_calloc (total_rows, sizeof (int16_t)); 211 screen.tlen = (int16_t *)rxvt_calloc (total_rows, sizeof (int16_t));
212 swap.tlen = (int16_t *)rxvt_calloc (nrow, sizeof (int16_t)); 212 swap.tlen = (int16_t *)rxvt_calloc (nrow, sizeof (int16_t));
213 213
214 screen.rend = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *)); 214 screen.rend = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *));
215 buf_rend = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *)); 215 buf_rend = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *));
216 drawn_rend = (rend_t **)rxvt_calloc (nrow, sizeof (rend_t *)); 216 drawn_rend = (rend_t **)rxvt_calloc (nrow, sizeof (rend_t *));
217 swap.rend = (rend_t **)rxvt_calloc (nrow, sizeof (rend_t *)); 217 swap.rend = (rend_t **)rxvt_calloc (nrow, sizeof (rend_t *));
218 218
219 for (p = 0; p < nrow; p++) 219 for (p = 0; p < nrow; p++)
220 { 220 {
221 q = p + TermWin.saveLines; 221 q = p + TermWin.saveLines;
222 scr_blank_screen_mem (screen.text, screen.rend, q, DEFAULT_RSTYLE); 222 scr_blank_screen_mem (screen.text, screen.rend, q, DEFAULT_RSTYLE);
293 ralloc->free (drawn_rend[p]); 293 ralloc->free (drawn_rend[p]);
294 } 294 }
295 295
296 /* we have fewer rows so fix up cursor position */ 296 /* we have fewer rows so fix up cursor position */
297 MIN_IT (screen.cur.row, (int32_t)nrow - 1); 297 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
298 MIN_IT (swap.cur.row, (int32_t)nrow - 1);
299 298
300 scr_reset_realloc (); /* realloc _last_ */ 299 scr_reset_realloc (); /* realloc _last_ */
301 } 300 }
302 else if (nrow > prev_nrow) 301 else if (nrow > prev_nrow)
303 { 302 {
334 scr_scroll_text (0, (int)nrow - 1, -k, 1); 333 scr_scroll_text (0, (int)nrow - 1, -k, 1);
335 screen.cur.row += k; 334 screen.cur.row += k;
336 screen.s_cur.row += k; 335 screen.s_cur.row += k;
337 TermWin.nscrolled -= k; 336 TermWin.nscrolled -= k;
338 } 337 }
338
339#ifdef DEBUG_STRICT 339#ifdef DEBUG_STRICT
340 assert (screen.cur.row < TermWin.nrow); 340 assert (screen.cur.row < TermWin.nrow);
341 assert (swap.cur.row < TermWin.nrow);
342#else /* drive with your eyes closed */ 341#else /* drive with your eyes closed */
343
344 MIN_IT (screen.cur.row, nrow - 1); 342 MIN_IT (screen.cur.row, nrow - 1);
345 MIN_IT (swap.cur.row, nrow - 1);
346#endif 343#endif
347 TermWin.ncol = ncol; // save b/c scr_blank_screen_mem uses this 344 TermWin.ncol = ncol; // save b/c scr_blank_screen_mem uses this
348 } 345 }
349 346
350 /* resize columns */ 347 /* resize columns */
393 } 390 }
394 391
395 } 392 }
396 393
397 MIN_IT (screen.cur.col, (int16_t)ncol - 1); 394 MIN_IT (screen.cur.col, (int16_t)ncol - 1);
398 MIN_IT (swap.cur.col, (int16_t)ncol - 1);
399 395
400 delete talloc; talloc = ta; 396 delete talloc; talloc = ta;
401 delete ralloc; ralloc = ra; 397 delete ralloc; ralloc = ra;
402 } 398 }
403 399
445 */ 441 */
446void 442void
447rxvt_term::scr_release () 443rxvt_term::scr_release ()
448{ 444{
449 unsigned int total_rows; 445 unsigned int total_rows;
450 int i;
451 446
452 total_rows = TermWin.nrow + TermWin.saveLines; 447 total_rows = TermWin.nrow + TermWin.saveLines;
453 448
454 delete talloc; talloc = 0; 449 delete talloc; talloc = 0;
455 delete ralloc; ralloc = 0; 450 delete ralloc; ralloc = 0;
565 if (current_screen == scrn) 560 if (current_screen == scrn)
566 return scrn; 561 return scrn;
567 562
568 selection_check (2); /* check for boundary cross */ 563 selection_check (2); /* check for boundary cross */
569 564
570 SWAP_IT (current_screen, scrn, int); 565 i = current_screen; current_screen = scrn; scrn = i;
571 566
572 SWAP_IT (screen.cur.row, swap.cur.row, int16_t); 567 SWAP_IT (screen.cur.row, swap.cur.row, int16_t);
573 SWAP_IT (screen.cur.col, swap.cur.col, int16_t); 568 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); 569 MAX_IT (screen.cur.row, 0);
579 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); 570 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1);
580 MAX_IT (screen.cur.col, 0); 571 MAX_IT (screen.cur.col, 0);
581 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1); 572 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1);
582# endif
583 573
584#if NSCREENS 574#if NSCREENS
585 if (options & Opt_secondaryScreen) 575 if (options & Opt_secondaryScreen)
586 { 576 {
587 num_scr = 0; 577 num_scr = 0;
600 swap.flags |= Screen_VisibleCursor; 590 swap.flags |= Screen_VisibleCursor;
601 } 591 }
602 else 592 else
603#endif 593#endif
604 if (options & Opt_secondaryScroll) 594 if (options & Opt_secondaryScroll)
605 //if (current_screen == PRIMARY)
606 scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0); 595 scr_scroll_text (0, prev_nrow - 1, prev_nrow, 0);
607 596
608 return scrn; 597 return scrn;
609} 598}
610 599
611// clear WrapNext indicator, solidifying position on next line 600// clear WrapNext indicator, solidifying position on next line
709 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ 698 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */
710 } 699 }
711 else if (j >= row1 && j <= row2) 700 else if (j >= row1 && j <= row2)
712 { 701 {
713 /* move selected region too */ 702 /* move selected region too */
714 selection.beg.row -= count; 703 selection.beg.row -= count;
715 selection.end.row -= count; 704 selection.end.row -= count;
716 selection.mark.row -= count; 705 selection.mark.row -= count;
717 } 706 }
718 } 707 }
719 708
720 selection_check (0); /* _after_ TermWin.nscrolled update */ 709 selection_check (0); /* _after_ TermWin.nscrolled update */
728 i = row2 - row1 + 1; 717 i = row2 - row1 + 1;
729 MIN_IT (count, i); 718 MIN_IT (count, i);
730 719
731 if (j > 0) 720 if (j > 0)
732 { 721 {
733 /* A: scroll up */ 722 /* scroll up */
734 723
735 /* A1: Copy lines that will get clobbered by the rotation */ 724 /* Copy lines that will get clobbered by the rotation */
736 memcpy (buf_text, screen.text + row1, count * sizeof (text_t *)); 725 memcpy (buf_text, screen.text + row1, count * sizeof (text_t *));
737 memcpy (buf_rend, screen.rend + row1, count * sizeof (rend_t *)); 726 memcpy (buf_rend, screen.rend + row1, count * sizeof (rend_t *));
738 727
739 /* A2: Rotate lines */ 728 /* Rotate lines */
740 i = row2 - row1 - count + 1; 729 i = row2 - row1 - count + 1;
741 memmove (screen.tlen + row1, screen.tlen + row1 + count, i * sizeof (int16_t)); 730 memmove (screen.tlen + row1, screen.tlen + row1 + count, i * sizeof (int16_t));
742 memmove (screen.text + row1, screen.text + row1 + count, i * sizeof (text_t *)); 731 memmove (screen.text + row1, screen.text + row1 + count, i * sizeof (text_t *));
743 memmove (screen.rend + row1, screen.rend + row1 + count, i * sizeof (rend_t *)); 732 memmove (screen.rend + row1, screen.rend + row1 + count, i * sizeof (rend_t *));
744 733
745 j = row2 - count + 1, i = count; 734 j = row2 - count + 1, i = count;
746 } 735 }
747 else /* if (j < 0) */ 736 else /* if (j < 0) */
748 { 737 {
749 /* B: scroll down */ 738 /* scroll down */
750 739
751 /* B1: Copy lines that will get clobbered by the rotation */ 740 /* Copy lines that will get clobbered by the rotation */
752 for (i = 0, j = row2; i < count; i++, j--) 741 for (i = 0, j = row2; i < count; i++, j--)
753 { 742 {
754 buf_text[i] = screen.text[j]; 743 buf_text[i] = screen.text[j];
755 buf_rend[i] = screen.rend[j]; 744 buf_rend[i] = screen.rend[j];
756 } 745 }
757 746
758 /* B2: Rotate lines */ 747 /* Rotate lines */
759 for (j = row2, i = j - count; i >= row1; i--, j--) 748 for (j = row2, i = j - count; i >= row1; i--, j--)
760 { 749 {
761 screen.tlen[j] = screen.tlen[i]; 750 screen.tlen[j] = screen.tlen[i];
762 screen.text[j] = screen.text[i]; 751 screen.text[j] = screen.text[i];
763 screen.rend[j] = screen.rend[i]; 752 screen.rend[j] = screen.rend[i];
765 754
766 j = row1, i = count; 755 j = row1, i = count;
767 count = -count; 756 count = -count;
768 } 757 }
769 758
770 /* C: Resurrect lines */ 759 /* Resurrect lines */
771 memset (screen.tlen + j, 0, i * sizeof (int16_t)); 760 memset (screen.tlen + j, 0, i * sizeof (int16_t));
772 memcpy (screen.text + j, buf_text, i * sizeof (text_t *)); 761 memcpy (screen.text + j, buf_text, i * sizeof (text_t *));
773 memcpy (screen.rend + j, buf_rend, i * sizeof (text_t *)); 762 memcpy (screen.rend + j, buf_rend, i * sizeof (text_t *));
774 if (!spec) /* line length may not equal TermWin.ncol */ 763 if (!spec) /* line length may not equal TermWin.ncol */
775 for (; i--; j++) 764 for (; i--; j++)
783 * Add text given in <str> of length <len> to screen struct 772 * Add text given in <str> of length <len> to screen struct
784 */ 773 */
785void 774void
786rxvt_term::scr_add_lines (const unicode_t *str, int nlines, int len) 775rxvt_term::scr_add_lines (const unicode_t *str, int nlines, int len)
787{ 776{
777 if (len <= 0) /* sanity */
778 return;
779
788 unsigned char checksel; 780 unsigned char checksel;
789 unicode_t c; 781 unicode_t c;
790 int i, row, last_col; 782 int row, last_col;
791 text_t *stp; 783 text_t *stp;
792 rend_t *srp; 784 rend_t *srp;
793 785 const unicode_t *strend = str + len;
794 if (len <= 0) /* sanity */
795 return;
796 786
797 want_refresh = 1; 787 want_refresh = 1;
798 ZERO_SCROLLBACK (); 788 ZERO_SCROLLBACK ();
799 last_col = TermWin.ncol; 789 last_col = TermWin.ncol;
800 790
825 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 815 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
826 816
827 stp = screen.text[row]; 817 stp = screen.text[row];
828 srp = screen.rend[row]; 818 srp = screen.rend[row];
829 819
830 while (len--) 820 while (str < strend)
831 { 821 {
832 c = *str++; 822 c = *str++;
833 823
834 if (c < 0x20) 824 if (c < 0x20)
835 switch (c) 825 if (c == C0_LF)
826 {
827 if (screen.tlen[row] != -1) /* XXX: think about this */
828 MAX_IT (screen.tlen[row], screen.cur.col);
829
830 screen.flags &= ~Screen_WrapNext;
831
832 if (screen.cur.row == screen.bscroll)
833 scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0);
834 else if (screen.cur.row < (TermWin.nrow - 1))
835 row = (++screen.cur.row) + TermWin.saveLines;
836
837 stp = screen.text[row]; /* _must_ refresh */
838 srp = screen.rend[row]; /* _must_ refresh */
839 continue;
840 }
841 else if (c == C0_CR)
836 { 842 {
837 case C0_HT:
838 scr_tab (1, true);
839 continue;
840
841 case C0_LF:
842 if (screen.tlen[row] != -1) /* XXX: think about this */ 843 if (screen.tlen[row] != -1) /* XXX: think about this */
843 MAX_IT (screen.tlen[row], screen.cur.col); 844 MAX_IT (screen.tlen[row], screen.cur.col);
844 845
845 screen.flags &= ~Screen_WrapNext; 846 screen.flags &= ~Screen_WrapNext;
846
847 if (screen.cur.row == screen.bscroll)
848 scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0);
849 else if (screen.cur.row < (TermWin.nrow - 1))
850 row = (++screen.cur.row) + TermWin.saveLines;
851
852 stp = screen.text[row]; /* _must_ refresh */
853 srp = screen.rend[row]; /* _must_ refresh */
854 continue;
855
856 case C0_CR:
857 if (screen.tlen[row] != -1) /* XXX: think about this */
858 MAX_IT (screen.tlen[row], screen.cur.col);
859
860 screen.flags &= ~Screen_WrapNext;
861 screen.cur.col = 0; 847 screen.cur.col = 0;
862 continue; 848 continue;
849 }
850 else if (c == C0_HT)
851 {
852 scr_tab (1, true);
853 continue;
863 } 854 }
864 855
865 if (checksel /* see if we're writing within selection */ 856 if (checksel /* see if we're writing within selection */
866 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 857 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
867 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 858 && ROWCOL_IS_BEFORE (screen.cur, selection.end))
877 868
878 if (screen.flags & Screen_WrapNext) 869 if (screen.flags & Screen_WrapNext)
879 { 870 {
880 screen.tlen[row] = -1; 871 screen.tlen[row] = -1;
881 872
873 scr_do_wrap ();
874
882 scr_do_wrap (); row = screen.cur.row + TermWin.saveLines; 875 row = screen.cur.row + TermWin.saveLines;
883
884 stp = screen.text[row]; /* _must_ refresh */ 876 stp = screen.text[row]; /* _must_ refresh */
885 srp = screen.rend[row]; /* _must_ refresh */ 877 srp = screen.rend[row]; /* _must_ refresh */
886 } 878 }
887 879
888 if (screen.flags & Screen_Insert) 880 // some utf-8 decoders "decode" surrogate characters: let's fix this.
889 scr_insdel_chars (1, INSERT); 881 if (IN_RANGE (c, 0xd800, 0xdfff))
882 c = 0xfffd;
890 883
891 // rely on wcwidth to tell us the character width, at least for non-latin1 884 // rely on wcwidth to tell us the character width, at least for non-latin1
892 // do wcwidth before further replacements, as wcwidth says that line-drawing 885 // do wcwidth before further replacements, as wcwidth might return -1
893 // characters have width -1 (DOH!) on GNU/Linux sometimes. 886 // for the line drawing characters below as they might be invalid in the current
887 // locale.
894 int width = c < 0x100 ? 1 : wcwidth (c); 888 int width = c < 0x100 ? 1 : wcwidth (c);
895 889
896 if (charsets[screen.charset] == '0') // DEC SPECIAL 890 if (charsets[screen.charset] == '0') // DEC SPECIAL
897 { 891 {
898 // vt100 special graphics and line drawing 892 // vt100 special graphics and line drawing
899 // 5f-7e standard vt100 893 // 5f-7e standard vt100
900 // 40-5e rxvt extension for extra curses acs chars 894 // 40-5e rxvt extension for extra curses acs chars
901 static uint16_t vt100_0[63] = { // 5f .. 7e 895 static uint16_t vt100_0[62] = { // 41 .. 7e
902 0x0000, 0x2191, 0x2193, 0x2192, 0x2190, 0x2588, 0x259a, 0x2603, // 40-47 hi mr. snowman! 896 0x2191, 0x2193, 0x2192, 0x2190, 0x2588, 0x259a, 0x2603, // 41-47 hi mr. snowman!
903 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 48-4f 897 0, 0, 0, 0, 0, 0, 0, 0, // 48-4f
904 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 50-57 898 0, 0, 0, 0, 0, 0, 0, 0, // 50-57
905 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, // 58-5f 899 0, 0, 0, 0, 0, 0, 0, 0x0020, // 58-5f
906 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, // 60-67 900 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, // 60-67
907 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, // 68-6f 901 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, // 68-6f
908 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, // 70-77 902 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, // 70-77
909 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, // 78-7e 903 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, // 78-7e
910 }; 904 };
911 905
912 if (c >= 0x40 && c <= 0x7e && vt100_0[c - 0x40]) 906 if (c >= 0x41 && c <= 0x7e && vt100_0[c - 0x41])
913 { 907 {
914 c = vt100_0[c - 0x40]; 908 c = vt100_0[c - 0x41];
915 width = 1; 909 width = 1; // vt100 line drawing characters are always single-width
916 } 910 }
917 } 911 }
918 912
913 if (screen.flags & Screen_Insert)
914 scr_insdel_chars (width, INSERT);
915
919 if (width != 0) 916 if (width != 0)
920 { 917 {
921 // some utf-8 decoders decode surrogate characters.
922 if (0xd800 <= c && c <= 0xdfff)
923 c = 0xfffd;
924
925#if !UNICODE_3 918#if !UNICODE_3
926 // trim characters we can't store directly :( 919 // trim characters we can't store directly :(
927 if (c >= 0x10000) 920 if (c >= 0x10000)
928# if ENABLE_COMBINING 921# if ENABLE_COMBINING
929 c = rxvt_composite.compose (c); // map to lower 16 bits 922 c = rxvt_composite.compose (c); // map to lower 16 bits
952 col++; 945 col++;
953 } while (col < TermWin.ncol && stp[col] == NOCHAR); 946 } while (col < TermWin.ncol && stp[col] == NOCHAR);
954 } 947 }
955 948
956 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); 949 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
950
951 // if the character doesn't fit into the remaining columns...
952 if (screen.cur.col > last_col - width && last_col >= width)
953 {
954 // ...output spaces
955 c = ' ';
956 // and try the same character next loop iteration
957 --str;
958 }
957 959
958 do 960 do
959 { 961 {
960 stp[screen.cur.col] = c; 962 stp[screen.cur.col] = c;
961 srp[screen.cur.col] = rend; 963 srp[screen.cur.col] = rend;
973 c = NOCHAR; 975 c = NOCHAR;
974 } 976 }
975 while (--width > 0); 977 while (--width > 0);
976 978
977 // pad with spaces when overwriting wide character with smaller one 979 // pad with spaces when overwriting wide character with smaller one
980 if (!width)
978 for (int c = screen.cur.col; c < last_col && stp[c] == NOCHAR; c++) 981 for (int c = screen.cur.col; c < last_col && stp[c] == NOCHAR; c++)
979 { 982 {
980 stp[c] = ' '; 983 stp[c] = ' ';
981 srp[c] = rend; 984 srp[c] = rend;
982 } 985 }
983 } 986 }
984 else if (width == 0) 987 else // width == 0
985 { 988 {
986#if ENABLE_COMBINING 989#if ENABLE_COMBINING
987 // handle combining characters 990 // handle combining characters
988 // we just tag the accent on the previous on-screen character. 991 // we just tag the accent on the previous on-screen character.
989 // this is arguably not correct, but also arguably not wrong. 992 // this is arguably not correct, but also arguably not wrong.
990 // we don't handle double-width characters nicely yet. 993 // we don't handle double-width characters nicely yet.
991
992 text_t *tp; 994 text_t *tp;
993 rend_t *rp; 995 rend_t *rp;
994 996
995 if (screen.cur.col > 0) 997 if (screen.cur.col > 0)
996 { 998 {
1100 if (count) 1102 if (count)
1101 x = TermWin.ncol - 1; 1103 x = TermWin.ncol - 1;
1102 1104
1103 // store horizontal tab commands as characters inside the text 1105 // store horizontal tab commands as characters inside the text
1104 // buffer so they can be selected and pasted. 1106 // buffer so they can be selected and pasted.
1105 if (ht) 1107 if (ht && options & Opt_pastableTabs)
1106 { 1108 {
1107 base_rend = SET_FONT (base_rend, 0); 1109 base_rend = SET_FONT (base_rend, 0);
1108 1110
1109 if (screen.tlen[row] != -1) /* XXX: think about this */ 1111 if (screen.tlen[row] != -1) /* XXX: think about this */
1110 MAX_IT (screen.tlen[row], x); 1112 MAX_IT (screen.tlen[row], x);
1170 */ 1172 */
1171#if ENABLE_FRILLS 1173#if ENABLE_FRILLS
1172void 1174void
1173rxvt_term::scr_forwardindex () 1175rxvt_term::scr_forwardindex ()
1174{ 1176{
1175 int row; 1177 int row;
1176 1178
1177 if (screen.cur.col < TermWin.ncol - 1) 1179 if (screen.cur.col < TermWin.ncol - 1)
1178 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1180 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1179 else 1181 else
1180 { 1182 {
1399 screen.tlen[row + row_offset] = 0; 1401 screen.tlen[row + row_offset] = 0;
1400 scr_blank_line (drawn_text[row], drawn_rend[row], (unsigned int)TermWin.ncol, ren); 1402 scr_blank_line (drawn_text[row], drawn_rend[row], (unsigned int)TermWin.ncol, ren);
1401 } 1403 }
1402} 1404}
1403 1405
1406#if ENABLE_FRILLS
1407void
1408rxvt_term::scr_erase_savelines ()
1409{
1410 want_refresh = 1;
1411 ZERO_SCROLLBACK ();
1412
1413 TermWin.nscrolled = 0;
1414}
1415#endif
1416
1404/* ------------------------------------------------------------------------- */ 1417/* ------------------------------------------------------------------------- */
1405/* 1418/*
1406 * Fill the screen with `E's 1419 * Fill the screen with `E's
1407 * XTERM_SEQ: Screen Alignment Test: ESC # 8 1420 * XTERM_SEQ: Screen Alignment Test: ESC # 8
1408 */ 1421 */
1409void 1422void
1410rxvt_term::scr_E () 1423rxvt_term::scr_E ()
1411{ 1424{
1412 int i, j, k; 1425 int i, j, k;
1413 rend_t *r1, fs; 1426 rend_t *r1, fs;
1414 1427
1415 want_refresh = 1; 1428 want_refresh = 1;
1416 ZERO_SCROLLBACK (); 1429 ZERO_SCROLLBACK ();
1417 1430
1418 num_scr_allow = 0; 1431 num_scr_allow = 0;
1901rxvt_term::scr_page (enum page_dirn direction, int nlines) 1914rxvt_term::scr_page (enum page_dirn direction, int nlines)
1902{ 1915{
1903 int n; 1916 int n;
1904 unsigned int oldviewstart; 1917 unsigned int oldviewstart;
1905 1918
1906#ifdef DEBUG_STRICT
1907 assert ((nlines >= 0) && (nlines <= TermWin.nrow));
1908#endif
1909 oldviewstart = TermWin.view_start; 1919 oldviewstart = TermWin.view_start;
1920
1910 if (direction == UP) 1921 if (direction == UP)
1911 { 1922 {
1912 n = TermWin.view_start + nlines; 1923 n = TermWin.view_start + nlines;
1913 TermWin.view_start = min (n, TermWin.nscrolled); 1924 TermWin.view_start = min (n, TermWin.nscrolled);
1914 } 1925 }
1915 else 1926 else
1916 { 1927 {
1917 n = TermWin.view_start - nlines; 1928 n = TermWin.view_start - nlines;
1918 TermWin.view_start = max (n, 0); 1929 TermWin.view_start = max (n, 0);
1919 } 1930 }
1931
1920 return scr_changeview (oldviewstart); 1932 return scr_changeview (oldviewstart);
1921} 1933}
1922 1934
1923int 1935int
1924rxvt_term::scr_changeview (unsigned int oldviewstart) 1936rxvt_term::scr_changeview (unsigned int oldviewstart)
1935/* ------------------------------------------------------------------------- */ 1947/* ------------------------------------------------------------------------- */
1936void 1948void
1937rxvt_term::scr_bell () 1949rxvt_term::scr_bell ()
1938{ 1950{
1939#ifndef NO_BELL 1951#ifndef NO_BELL
1952
1940# ifndef NO_MAPALERT 1953# ifndef NO_MAPALERT
1941# ifdef MAPALERT_OPTION 1954# ifdef MAPALERT_OPTION
1942 if (options & Opt_mapAlert) 1955 if (options & Opt_mapAlert)
1943# endif 1956# endif
1944 XMapWindow (display->display, TermWin.parent[0]); 1957 XMapWindow (display->display, TermWin.parent[0]);
1945# endif 1958# endif
1959
1946 if (options & Opt_visualBell) 1960 if (options & Opt_visualBell)
1947 { 1961 {
1948 scr_rvideo_mode (!rvideo); /* refresh also done */ 1962 scr_rvideo_mode (!rvideo); /* refresh also done */
1963 rxvt_usleep (VISUAL_BELL_DURATION);
1949 scr_rvideo_mode (!rvideo); /* refresh also done */ 1964 scr_rvideo_mode (!rvideo); /* refresh also done */
1950 } 1965 }
1951 else 1966 else
1952 XBell (display->display, 0); 1967 XBell (display->display, 0);
1968
1953#endif 1969#endif
1954} 1970}
1955 1971
1956/* ------------------------------------------------------------------------- */ 1972/* ------------------------------------------------------------------------- */
1957/* ARGSUSED */ 1973/* ARGSUSED */
2012/* 2028/*
2013 * Refresh the screen 2029 * Refresh the screen
2014 * drawn_text/drawn_rend contain the screen information before the update. 2030 * drawn_text/drawn_rend contain the screen information before the update.
2015 * screen.text/screen.rend contain what the screen will change to. 2031 * screen.text/screen.rend contain what the screen will change to.
2016 */ 2032 */
2017
2018#define FONT_WIDTH(X, Y) \
2019 (X)->per_char[ (Y) - (X)->min_char_or_byte2].width
2020#define FONT_RBEAR(X, Y) \
2021 (X)->per_char[ (Y) - (X)->min_char_or_byte2].rbearing
2022#define FONT_LBEAR(X, Y) \
2023 (X)->per_char[ (Y) - (X)->min_char_or_byte2].lbearing
2024#define IS_FONT_CHAR(X, Y) \
2025 ((Y) >= (X)->min_char_or_byte2 && (Y) <= (X)->max_char_or_byte2)
2026
2027void 2033void
2028rxvt_term::scr_refresh (unsigned char refresh_type) 2034rxvt_term::scr_refresh (unsigned char refresh_type)
2029{ 2035{
2030 unsigned char must_clear, /* use draw_string not draw_image_string */ 2036 unsigned char must_clear, /* use draw_string not draw_image_string */
2031 showcursor; /* show the cursor */ 2037 showcursor; /* show the cursor */
2050 refresh_count = 0; 2056 refresh_count = 0;
2051 2057
2052 row_offset = TermWin.saveLines - TermWin.view_start; 2058 row_offset = TermWin.saveLines - TermWin.view_start;
2053 2059
2054#if XPM_BACKGROUND 2060#if XPM_BACKGROUND
2055 must_clear |= (bgPixmap.pixmap != None); 2061 must_clear |= bgPixmap.pixmap != None;
2056#endif 2062#endif
2057#if TRANSPARENT 2063#if TRANSPARENT
2058 must_clear |= ((options & Opt_transparent) && am_transparent); 2064 must_clear |= (options & Opt_transparent) && am_transparent;
2059#endif 2065#endif
2060 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2066 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
2061 2067
2062 /* 2068 /*
2063 * B: reverse any characters which are selected 2069 * B: reverse any characters which are selected
2087 2093
2088 crp = &screen.rend[screen.cur.row + TermWin.saveLines][col]; 2094 crp = &screen.rend[screen.cur.row + TermWin.saveLines][col];
2089 2095
2090 if (showcursor && TermWin.focus) 2096 if (showcursor && TermWin.focus)
2091 { 2097 {
2098 if (options & Opt_cursorUnderline)
2099 *crp ^= RS_Uline;
2100 else
2101 {
2092 *crp ^= RS_RVid; 2102 *crp ^= RS_RVid;
2103
2093#ifndef NO_CURSORCOLOR 2104#ifndef NO_CURSORCOLOR
2094 cc1 = *crp & (RS_fgMask | RS_bgMask); 2105 cc1 = *crp & (RS_fgMask | RS_bgMask);
2095 if (ISSET_PIXCOLOR (Color_cursor)) 2106 if (ISSET_PIXCOLOR (Color_cursor))
2096 ccol1 = Color_cursor; 2107 ccol1 = Color_cursor;
2097 else 2108 else
2098#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 2109#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2099 ccol1 = GET_FGCOLOR (rstyle); 2110 ccol1 = GET_FGCOLOR (rstyle);
2100#else 2111#else
2101 ccol1 = Color_fg; 2112 ccol1 = Color_fg;
2102#endif 2113#endif
2103 if (ISSET_PIXCOLOR (Color_cursor2)) 2114 if (ISSET_PIXCOLOR (Color_cursor2))
2104 ccol2 = Color_cursor2; 2115 ccol2 = Color_cursor2;
2105 else 2116 else
2106#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 2117#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2107 ccol2 = GET_BGCOLOR (rstyle); 2118 ccol2 = GET_BGCOLOR (rstyle);
2108#else 2119#else
2109 ccol2 = Color_bg; 2120 ccol2 = Color_bg;
2110#endif 2121#endif
2111 *crp = SET_FGCOLOR (*crp, ccol1); 2122 *crp = SET_FGCOLOR (*crp, ccol1);
2112 *crp = SET_BGCOLOR (*crp, ccol2); 2123 *crp = SET_BGCOLOR (*crp, ccol2);
2113#endif 2124#endif
2125 }
2114 } 2126 }
2115 } 2127 }
2116 2128
2117 /* make sure no outline cursor is left around */ 2129 /* make sure no outline cursor is left around */
2118 setoldcursor = 0; 2130 setoldcursor = 0;
2148 2160
2149#if ENABLE_OVERLAY 2161#if ENABLE_OVERLAY
2150 scr_swap_overlay (); 2162 scr_swap_overlay ();
2151#endif 2163#endif
2152 2164
2153 rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */
2154 text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */
2155
2156#ifndef NO_SLOW_LINK_SUPPORT 2165#ifndef NO_SLOW_LINK_SUPPORT
2157 /* 2166 /*
2158 * D: CopyArea pass - very useful for slower links 2167 * D: CopyArea pass - very useful for slower links
2159 * This has been deliberately kept simple. 2168 * This has been deliberately kept simple.
2160 */ 2169 */
2244 && GET_BGATTR (srp[col]) == GET_BGATTR (drp[col])))) 2253 && GET_BGATTR (srp[col]) == GET_BGATTR (drp[col]))))
2245 continue; 2254 continue;
2246 2255
2247 // redraw one or more characters 2256 // redraw one or more characters
2248 2257
2249 // seek to the beginning if wide characters 2258 // seek to the beginning of wide characters
2250 while (stp[col] == NOCHAR && col > 0) 2259 while (stp[col] == NOCHAR && col > 0)
2251 --col; 2260 --col;
2252 2261
2253 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2262 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2254 text_t *text = stp + col; 2263 text_t *text = stp + col;
2295 2304
2296 // sometimes we optimize away the trailing NOCHAR's, add them back 2305 // sometimes we optimize away the trailing NOCHAR's, add them back
2297 while (i && text[count] == NOCHAR) 2306 while (i && text[count] == NOCHAR)
2298 count++, i--; 2307 count++, i--;
2299 2308
2300#if ENABLE_STYLES
2301 // force redraw after "careful" characters to avoid pixel droppings
2302 if (srp[col] & RS_Careful && col < TermWin.ncol - 1 && 0)
2303 drp[col + 1] = ~srp[col + 1];
2304
2305 // include previous careful character(s) if possible, looks nicer (best effort...)
2306 while (text > stp
2307 && srp[text - stp - 1] & RS_Careful
2308 && RS_SAME (rend, srp[text - stp - 1]))
2309 text--, count++, xpixel -= TermWin.fwidth;
2310#endif
2311
2312 /* 2309 /*
2313 * Determine the attributes for the string 2310 * Determine the attributes for the string
2314 */ 2311 */
2315 int fore = GET_FGCOLOR (rend); // desired foreground 2312 int fore = GET_FGCOLOR (rend); // desired foreground
2316 int back = GET_BGCOLOR (rend); // desired background 2313 int back = GET_BGCOLOR (rend); // desired background
2317 2314
2318 // only do special processing if ana attributes are set, which is rare 2315 // only do special processing if any attributes are set, which is rare
2319 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink)) 2316 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))
2320 { 2317 {
2318#if ENABLE_STYLES
2319 // force redraw after "careful" characters to avoid pixel droppings
2320 if (srp[col] & RS_Careful && col < TermWin.ncol - 1 && 0)
2321 drp[col + 1] = ~srp[col + 1];
2322
2323 // include previous careful character(s) if possible, looks nicer (best effort...)
2324 while (text > stp
2325 && srp[text - stp - 1] & RS_Careful
2326 && RS_SAME (rend, srp[text - stp - 1]))
2327 text--, count++, xpixel -= TermWin.fwidth;
2328#endif
2329
2321 bool invert = rend & RS_RVid; 2330 bool invert = rend & RS_RVid;
2322 2331
2323#ifndef NO_BOLD_UNDERLINE_REVERSE 2332#ifndef NO_BOLD_UNDERLINE_REVERSE
2324 if (rend & RS_Bold 2333 if (rend & RS_Bold
2325 && fore == Color_fg) 2334 && fore == Color_fg)
2352 SWAP_IT (fore, back, int); 2361 SWAP_IT (fore, back, int);
2353 2362
2354#ifndef NO_BOLD_UNDERLINE_REVERSE 2363#ifndef NO_BOLD_UNDERLINE_REVERSE
2355 if (ISSET_PIXCOLOR (Color_RV)) 2364 if (ISSET_PIXCOLOR (Color_RV))
2356 back = Color_RV; 2365 back = Color_RV;
2366
2367 if (fore == back)
2368 {
2369 fore = Color_bg;
2370 back = Color_fg;
2371 }
2357#endif 2372#endif
2358 } 2373 }
2359 2374
2360#ifdef TEXT_BLINK 2375#ifdef TEXT_BLINK
2361 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg)) 2376 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg))
2398 } 2413 }
2399 else 2414 else
2400 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back); 2415 font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back);
2401 2416
2402 if (rend & RS_Uline && font->descent > 1 && fore != back) 2417 if (rend & RS_Uline && font->descent > 1 && fore != back)
2418 {
2419#if ENABLE_FRILLS
2420 if (ISSET_PIXCOLOR (Color_underline))
2421 XSetForeground (display->display, TermWin.gc, pix_colors[Color_underline]);
2422 else
2423#endif
2424 XSetForeground (display->display, TermWin.gc, pix_colors[fore]);
2425
2403 XDrawLine (display->display, drawBuffer, TermWin.gc, 2426 XDrawLine (display->display, drawBuffer, TermWin.gc,
2404 xpixel, ypixel + font->ascent + 1, 2427 xpixel, ypixel + font->ascent + 1,
2405 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2428 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2429 }
2406 } /* for (col....) */ 2430 } /* for (col....) */
2407 } /* for (row....) */ 2431 } /* for (row....) */
2408 2432
2409#if ENABLE_OVERLAY 2433#if ENABLE_OVERLAY
2410 scr_swap_overlay (); 2434 scr_swap_overlay ();
2415 */ 2439 */
2416 if (showcursor) 2440 if (showcursor)
2417 { 2441 {
2418 if (TermWin.focus) 2442 if (TermWin.focus)
2419 { 2443 {
2444 if (options & Opt_cursorUnderline)
2445 *crp ^= RS_Uline;
2446 else
2447 {
2420 *crp ^= RS_RVid; 2448 *crp ^= RS_RVid;
2421#ifndef NO_CURSORCOLOR 2449#ifndef NO_CURSORCOLOR
2422 *crp = (*crp & ~ (RS_fgMask | RS_bgMask)) | cc1; 2450 *crp = (*crp & ~ (RS_fgMask | RS_bgMask)) | cc1;
2423#endif 2451#endif
2452 }
2424 } 2453 }
2425 else if (oldcursor.row >= 0) 2454 else if (oldcursor.row >= 0)
2426 { 2455 {
2456 int cursorwidth = 1;
2457 int col = oldcursor.col;
2458
2459 while (col && screen.text[screen.cur.row + TermWin.saveLines][col] == NOCHAR)
2460 col--;
2461
2462 while (col + cursorwidth < TermWin.ncol
2463 && drawn_text[oldcursor.row][col + cursorwidth] == NOCHAR)
2464 cursorwidth++;
2465
2427#ifndef NO_CURSORCOLOR 2466#ifndef NO_CURSORCOLOR
2428 if (ISSET_PIXCOLOR (Color_cursor)) 2467 if (ISSET_PIXCOLOR (Color_cursor))
2429 XSetForeground (display->display, TermWin.gc, pix_colors[Color_cursor]); 2468 XSetForeground (display->display, TermWin.gc, pix_colors[Color_cursor]);
2430#endif 2469#endif
2431 int cursorwidth = 1;
2432 while (oldcursor.col + cursorwidth < TermWin.ncol
2433 && drawn_text[oldcursor.row][oldcursor.col + cursorwidth] == NOCHAR)
2434 cursorwidth++;
2435 2470
2436 XDrawRectangle (display->display, drawBuffer, TermWin.gc, 2471 XDrawRectangle (display->display, drawBuffer, TermWin.gc,
2437 Col2Pixel (oldcursor.col), 2472 Col2Pixel (col),
2438 Row2Pixel (oldcursor.row), 2473 Row2Pixel (oldcursor.row),
2439 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2474 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2440 (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1)); 2475 (unsigned int) (Height2Pixel (1) - TermWin.lineSpace - 1));
2441 } 2476 }
2442 } 2477 }
2513 if (!TermWin.mapped) 2548 if (!TermWin.mapped)
2514 return; 2549 return;
2515 2550
2516 num_scr_allow = 0; 2551 num_scr_allow = 0;
2517 want_refresh = 1; 2552 want_refresh = 1;
2518
2519#if TRANSPARENT
2520 if ((options & Opt_transparent) && (am_pixmap_trans == 0))
2521 {
2522 int i;
2523
2524 if (!(options & Opt_transparent_all))
2525 i = 0;
2526 else
2527 i = (int) (sizeof (TermWin.parent) / sizeof (Window));
2528
2529 while (i--)
2530 if (TermWin.parent[i] != None)
2531 XClearWindow (display->display, TermWin.parent[i]);
2532 }
2533#endif
2534 2553
2535 if (really) 2554 if (really)
2536 XClearWindow (display->display, TermWin.vt); 2555 XClearWindow (display->display, TermWin.vt);
2537} 2556}
2538 2557
2652/* ------------------------------------------------------------------------- */ 2671/* ------------------------------------------------------------------------- */
2653/* 2672/*
2654 * Paste a selection direct to the command fd 2673 * Paste a selection direct to the command fd
2655 */ 2674 */
2656void 2675void
2657rxvt_term::paste (const unsigned char *data, unsigned int len) 2676rxvt_term::paste (unsigned char *data, unsigned int len)
2658{ 2677{
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 */ 2678 /* convert normal newline chars into common keyboard Return key sequence */
2663 for (i = 0; i < len; i += PROP_SIZE) 2679 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) 2680 if (data[i] == C0_LF)
2670 ds[j] = C0_CR; 2681 data[i] = C0_CR;
2671 2682
2672 tt_write (ds, (int)n); 2683 tt_write (data, len);
2673 }
2674
2675 free (ds);
2676} 2684}
2677 2685
2678/* ------------------------------------------------------------------------- */ 2686/* ------------------------------------------------------------------------- */
2679/* 2687/*
2680 * Respond to a notification that a primary selection has been sent 2688 * Respond to a notification that a primary selection has been sent
2681 * EXT: SelectionNotify 2689 * EXT: SelectionNotify
2682 */ 2690 */
2683int 2691void
2684rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) 2692rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop)
2685{ 2693{
2686 long nread = 0;
2687 unsigned long bytes_after;
2688 XTextProperty ct;
2689
2690 if (prop == None) /* check for failed XConvertSelection */ 2694 if (prop == None) /* check for failed XConvertSelection */
2691 { 2695 {
2692 if ((selection_type & Sel_CompoundText)) 2696 if ((selection_type & Sel_CompoundText))
2693 { 2697 {
2694 int selnum = selection_type & Sel_whereMask; 2698 int selnum = selection_type & Sel_whereMask;
2707 selection_request_other (xa[XA_COMPOUND_TEXT], selnum); 2711 selection_request_other (xa[XA_COMPOUND_TEXT], selnum);
2708 else 2712 else
2709 selection_type = 0; 2713 selection_type = 0;
2710 } 2714 }
2711 2715
2712 return 0; 2716 return;
2713 }
2714
2715 for (;;)
2716 { 2717 }
2718
2719 unsigned long bytes_after;
2720 XTextProperty ct;
2721
2722 if (XGetWindowProperty (display->display, win, prop,
2723 0, PROP_SIZE / 4,
2724 delete_prop, AnyPropertyType,
2725 &ct.encoding, &ct.format,
2726 &ct.nitems, &bytes_after,
2727 &ct.value) != Success)
2728 {
2729 ct.value = 0;
2730 goto bailout;
2731 }
2732
2733 if (ct.encoding == None)
2734 goto bailout;
2735
2736 if (bytes_after)
2737 {
2738 // fetch and append remaining data
2739 XTextProperty ct2;
2740
2717 if (XGetWindowProperty (display->display, win, prop, (long) (nread / 4), 2741 if (XGetWindowProperty (display->display, win, prop,
2718 (long) (PROP_SIZE / 4), delete_prop, 2742 ct.nitems / 4, (bytes_after + 3) / 4,
2743 delete_prop, AnyPropertyType,
2719 AnyPropertyType, &ct.encoding, &ct.format, 2744 &ct2.encoding, &ct2.format,
2720 &ct.nitems, &bytes_after, 2745 &ct2.nitems, &bytes_after,
2721 &ct.value) != Success) 2746 &ct2.value) != Success)
2722 break; 2747 goto bailout;
2723 2748
2724 if (ct.encoding == 0) 2749 // realloc should be compatible to XFree, here, and elsewhere, too
2725 break; 2750 ct.value = (unsigned char *)realloc (ct.value, ct.nitems + ct2.nitems + 1);
2751 memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems + 1);
2752 ct.nitems += ct2.nitems;
2726 2753
2754 XFree (ct2.value);
2755 }
2756
2757 if (ct.value == 0)
2758 goto bailout;
2759
2727 if (ct.encoding == xa[XA_INCR]) 2760 if (ct.encoding == xa[XA_INCR])
2728 { 2761 {
2729 // INCR selection, start handshake 2762 // INCR selection, start handshake
2763 if (!delete_prop)
2730 XDeleteProperty (display->display, win, prop); 2764 XDeleteProperty (display->display, win, prop);
2765
2731 selection_wait = Sel_incr; 2766 selection_wait = Sel_incr;
2767 incr_buf_fill = 0;
2732 incr_ev.start (NOW + 10); 2768 incr_ev.start (NOW + 10);
2733 break;
2734 }
2735 2769
2736 if (ct.value == NULL) 2770 goto bailout;
2737 continue; 2771 }
2738 2772
2739 if (ct.nitems == 0) 2773 if (ct.nitems == 0)
2774 {
2775 if (selection_wait == Sel_incr)
2776 {
2777 XFree (ct.value);
2778
2779 // finally complete, now paste the whole thing
2780 selection_wait = Sel_normal;
2781 ct.value = (unsigned char *)incr_buf;
2782 ct.nitems = incr_buf_fill;
2783 incr_buf = 0;
2784 incr_buf_size = 0;
2785 incr_ev.stop ();
2740 { 2786 }
2787 else
2788 {
2741 if (selection_wait == Sel_normal && nread == 0 2789 if (selection_wait == Sel_normal
2742 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2790 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2743 { 2791 {
2744 /* 2792 /*
2745 * pass through again trying CUT_BUFFER0 if we've come from 2793 * pass through again trying CUT_BUFFER0 if we've come from
2746 * XConvertSelection () but nothing was presented 2794 * XConvertSelection () but nothing was presented
2747 */ 2795 */
2748 selection_paste (display->root, XA_CUT_BUFFER0, False); 2796 selection_paste (display->root, XA_CUT_BUFFER0, False);
2749 } 2797 }
2750 2798
2751 nread = -1; /* discount any previous stuff */ 2799 goto bailout;
2752 break; 2800 }
2801 }
2802 else if (selection_wait == Sel_incr)
2803 {
2804 incr_ev.start (NOW + 10);
2805
2806 while (incr_buf_fill + ct.nitems > incr_buf_size)
2753 } 2807 {
2808 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2809 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2810 }
2754 2811
2812 memcpy (incr_buf + incr_buf_fill, ct.value, ct.nitems);
2755 nread += ct.nitems; 2813 incr_buf_fill += ct.nitems;
2756 2814
2815 goto bailout;
2816 }
2817
2757 char **cl; 2818 char **cl;
2758 int cr; 2819 int cr;
2820
2821#if ENABLE_FRILLS
2822 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2823 // so recode it manually
2824 if (ct.encoding == xa[XA_UTF8_STRING])
2825 {
2826 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2827 char *s = rxvt_wcstombs (w);
2828 free (w);
2829 // TODO: strlen == only the first element will be converted. well...
2830 paste ((unsigned char *)s, strlen (s));
2831 free (s);
2832 }
2833 else
2834#endif
2759 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 && cl) 2835 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0
2760 { 2836 && cl)
2837 {
2761 for (int i = 0; i < cr; i++) 2838 for (int i = 0; i < cr; i++)
2762 paste ((unsigned char *)cl[i], strlen (cl[i])); 2839 paste ((unsigned char *)cl[i], strlen (cl[i]));
2763 2840
2764 XFreeStringList (cl); 2841 XFreeStringList (cl);
2765 } 2842 }
2766 else 2843 else
2767 paste (ct.value, ct.nitems); 2844 paste (ct.value, ct.nitems); // paste raw
2768 2845
2769 if (bytes_after == 0) 2846bailout:
2770 break;
2771
2772 XFree (ct.value);
2773 }
2774
2775 if (ct.value)
2776 XFree (ct.value); 2847 XFree (ct.value);
2777 2848
2778 if (selection_wait == Sel_normal) 2849 if (selection_wait == Sel_normal)
2779 selection_wait = Sel_none; 2850 selection_wait = Sel_none;
2780
2781 return (int)nread;
2782} 2851}
2783 2852
2784void 2853void
2785rxvt_term::incr_cb (time_watcher &w) 2854rxvt_term::incr_cb (time_watcher &w)
2786{ 2855{
2787 selection_wait = Sel_none; 2856 selection_wait = Sel_none;
2788 2857
2858 incr_buf_size = 0;
2859 free (incr_buf);
2860
2789 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 2861 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2790} 2862}
2791 2863
2792/*
2793 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2794 */
2795void 2864void
2796rxvt_term::selection_property (Window win, Atom prop) 2865rxvt_term::selection_property (Window win, Atom prop)
2797{ 2866{
2798 if (prop == None || selection_wait != Sel_incr) 2867 if (prop == None || selection_wait != Sel_incr)
2799 return; 2868 return;
2800 2869
2801 if (selection_paste (win, prop, 1) > 0) 2870 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} 2871}
2809 2872
2810/* ------------------------------------------------------------------------- */ 2873/* ------------------------------------------------------------------------- */
2811/* 2874/*
2812 * Request the current selection: 2875 * Request the current selection:
2846#else 2909#else
2847 selection_type = Sel_CompoundText; 2910 selection_type = Sel_CompoundText;
2848 if (selection_request_other (xa[XA_COMPOUND_TEXT], i)) 2911 if (selection_request_other (xa[XA_COMPOUND_TEXT], i))
2849 return; 2912 return;
2850#endif 2913#endif
2851
2852 } 2914 }
2853 } 2915 }
2854 2916
2855 selection_wait = Sel_none; /* don't loop in rxvt_selection_paste () */ 2917 selection_wait = Sel_none; /* don't loop in selection_paste () */
2856 selection_paste (display->root, XA_CUT_BUFFER0, False); 2918 selection_paste (display->root, XA_CUT_BUFFER0, false);
2857} 2919}
2858 2920
2859int 2921int
2860rxvt_term::selection_request_other (Atom target, int selnum) 2922rxvt_term::selection_request_other (Atom target, int selnum)
2861{ 2923{
2862 Atom sel; 2924 Atom sel;
2863#ifdef DEBUG_SELECT
2864 char *debug_xa_names[] = { "PRIMARY", "SECONDARY", "CLIPBOARD" };
2865#endif
2866 2925
2867 selection_type |= selnum; 2926 selection_type |= selnum;
2868 2927
2869 if (selnum == Sel_Primary) 2928 if (selnum == Sel_Primary)
2870 sel = XA_PRIMARY; 2929 sel = XA_PRIMARY;
3017#if 0 3076#if 0
3018 XTextProperty ct; 3077 XTextProperty ct;
3019 3078
3020 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3079 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0)
3021 { 3080 {
3022 XChangeProperty (display->display, display->root, XA_CUT_BUFFER0, XA_STRING, 8, 3081 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
3023 PropModeReplace, ct.value, ct.nitems);
3024 XFree (ct.value); 3082 XFree (ct.value);
3025 } 3083 }
3026#endif 3084#endif
3027 3085
3028 selection_time = tm; 3086 selection_time = tm;
3366 selection_delimit_word (DN, &selection.end, &selection.end); 3424 selection_delimit_word (DN, &selection.end, &selection.end);
3367 } 3425 }
3368 else if (selection.clicks == 3) 3426 else if (selection.clicks == 3)
3369 { 3427 {
3370#if ENABLE_FRILLS 3428#if ENABLE_FRILLS
3371 if ((options & Opt_tripleclickwords)) 3429 if (options & Opt_tripleclickwords)
3372 { 3430 {
3373 int end_row; 3431 int end_row;
3374 3432
3375 selection_delimit_word (UP, &selection.beg, &selection.beg); 3433 selection_delimit_word (UP, &selection.beg, &selection.beg);
3376 end_row = screen.tlen[selection.mark.row + TermWin.saveLines]; 3434 end_row = screen.tlen[selection.mark.row + TermWin.saveLines];
3394 if (ROWCOL_IS_AFTER (selection.mark, selection.beg)) 3452 if (ROWCOL_IS_AFTER (selection.mark, selection.beg))
3395 selection.mark.col++; 3453 selection.mark.col++;
3396 3454
3397 selection.beg.col = 0; 3455 selection.beg.col = 0;
3398 selection.end.col = ncol; 3456 selection.end.col = ncol;
3457
3458 // select a complete logical line
3459 while (selection.beg.row > -TermWin.saveLines
3460 && screen.tlen[selection.beg.row - 1 + TermWin.saveLines] == -1)
3461 selection.beg.row--;
3462
3463 while (selection.end.row < TermWin.nrow
3464 && screen.tlen[selection.end.row + TermWin.saveLines] == -1)
3465 selection.end.row++;
3399 } 3466 }
3400 } 3467 }
3401 3468
3402 if (button3 && buttonpress) 3469 if (button3 && buttonpress)
3403 { /* mark may need to be changed */ 3470 { /* mark may need to be changed */
3483 */ 3550 */
3484void 3551void
3485rxvt_term::selection_send (const XSelectionRequestEvent &rq) 3552rxvt_term::selection_send (const XSelectionRequestEvent &rq)
3486{ 3553{
3487 XSelectionEvent ev; 3554 XSelectionEvent ev;
3488 XTextProperty ct; 3555 dDisp;
3489 XICCEncodingStyle style;
3490 Atom target;
3491 3556
3492 ev.type = SelectionNotify; 3557 ev.type = SelectionNotify;
3493 ev.property = None; 3558 ev.property = None;
3494 ev.display = rq.display; 3559 ev.display = rq.display;
3495 ev.requestor = rq.requestor; 3560 ev.requestor = rq.requestor;
3509 *target++ = xa[XA_COMPOUND_TEXT]; 3574 *target++ = xa[XA_COMPOUND_TEXT];
3510#if X_HAVE_UTF8_STRING 3575#if X_HAVE_UTF8_STRING
3511 *target++ = xa[XA_UTF8_STRING]; 3576 *target++ = xa[XA_UTF8_STRING];
3512#endif 3577#endif
3513 3578
3514 XChangeProperty (display->display, rq.requestor, rq.property, XA_ATOM, 3579 XChangeProperty (disp, rq.requestor, rq.property, XA_ATOM,
3515 32, PropModeReplace, 3580 32, PropModeReplace,
3516 (unsigned char *)target_list, target - target_list); 3581 (unsigned char *)target_list, target - target_list);
3517 ev.property = rq.property; 3582 ev.property = rq.property;
3518 } 3583 }
3519#if TODO // TODO 3584#if TODO // TODO
3522 /* TODO: Handle MULTIPLE */ 3587 /* TODO: Handle MULTIPLE */
3523 } 3588 }
3524#endif 3589#endif
3525 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3590 else if (rq.target == xa[XA_TIMESTAMP] && selection.text)
3526 { 3591 {
3527 XChangeProperty (display->display, rq.requestor, rq.property, rq.target, 3592 XChangeProperty (disp, rq.requestor, rq.property, rq.target,
3528 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3593 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3529 ev.property = rq.property; 3594 ev.property = rq.property;
3530 } 3595 }
3531 else if (rq.target == XA_STRING 3596 else if (rq.target == XA_STRING
3532 || rq.target == xa[XA_TEXT] 3597 || rq.target == xa[XA_TEXT]
3533 || rq.target == xa[XA_COMPOUND_TEXT] 3598 || rq.target == xa[XA_COMPOUND_TEXT]
3534 || rq.target == xa[XA_UTF8_STRING] 3599 || rq.target == xa[XA_UTF8_STRING]
3535 ) 3600 )
3536 { 3601 {
3602 XTextProperty ct;
3603 Atom target = rq.target;
3537 short freect = 0; 3604 short freect = 0;
3538 int selectlen; 3605 int selectlen;
3539 wchar_t *cl; 3606 wchar_t *cl;
3540 3607 enum {
3541 target = rq.target; 3608 enc_string = XStringStyle,
3609 enc_text = XStdICCTextStyle,
3610 enc_compound_text = XCompoundTextStyle,
3611#ifdef X_HAVE_UTF8_STRING
3612 enc_utf8 = XUTF8StringStyle,
3613#else
3614 enc_utf8 = -1,
3615#endif
3616 } style;
3542 3617
3543 if (target == XA_STRING) 3618 if (target == XA_STRING)
3544 // we actually don't do XA_STRING, but who cares, as i18n clients 3619 // we actually don't do XA_STRING, but who cares, as i18n clients
3545 // will ask for another format anyways. 3620 // will ask for another format anyways.
3546 style = XStringStyle; 3621 style = enc_string;
3547 else if (target == xa[XA_TEXT]) 3622 else if (target == xa[XA_TEXT])
3548 style = XStdICCTextStyle; 3623 style = enc_text;
3549 else if (target == xa[XA_COMPOUND_TEXT]) 3624 else if (target == xa[XA_COMPOUND_TEXT])
3550 style = XCompoundTextStyle; 3625 style = enc_compound_text;
3551#if X_HAVE_UTF8_STRING 3626#if ENABLE_FRILLS
3552 else if (target == xa[XA_UTF8_STRING]) 3627 else if (target == xa[XA_UTF8_STRING])
3553 style = XUTF8StringStyle; 3628 style = enc_utf8;
3554#endif 3629#endif
3555 else 3630 else
3556 { 3631 {
3557 target = xa[XA_COMPOUND_TEXT]; 3632 target = xa[XA_COMPOUND_TEXT];
3558 style = XCompoundTextStyle; 3633 style = enc_compound_text;
3559 } 3634 }
3560 3635
3561 if (selection.text) 3636 if (selection.text)
3562 { 3637 {
3563 cl = selection.text; 3638 cl = selection.text;
3567 { 3642 {
3568 cl = L""; 3643 cl = L"";
3569 selectlen = 0; 3644 selectlen = 0;
3570 } 3645 }
3571 3646
3572 // Xwc doesn't handle iso-10646 in wchar_t gracefully, so maybe recode it 3647#if ENABLE_FRILLS
3573 // manually for XUTF8StringStyle. 3648 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
3649 // so recode it manually
3650 if (style == enc_utf8)
3651 {
3652 freect = 1;
3653 ct.encoding = target;
3654 ct.format = 8;
3655 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen);
3656 ct.nitems = strlen ((char *)ct.value);
3657 }
3658 else
3659#endif
3574 if (XwcTextListToTextProperty (display->display, &cl, 1, style, &ct) >= 0) 3660 if (XwcTextListToTextProperty (disp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0)
3575 freect = 1; 3661 freect = 1;
3576 else 3662 else
3577 { 3663 {
3578 /* if we failed to convert then send it raw */ 3664 /* if we failed to convert then send it raw */
3579 ct.value = (unsigned char *)cl; 3665 ct.value = (unsigned char *)cl;
3580 ct.nitems = selectlen; 3666 ct.nitems = selectlen;
3667 ct.encoding = target;
3581 } 3668 }
3582 3669
3583 XChangeProperty (display->display, rq.requestor, rq.property, 3670 XChangeProperty (disp, rq.requestor, rq.property,
3584 target, 8, PropModeReplace, 3671 ct.encoding, 8, PropModeReplace,
3585 ct.value, (int)ct.nitems); 3672 ct.value, (int)ct.nitems);
3586 ev.property = rq.property; 3673 ev.property = rq.property;
3587 3674
3588 if (freect) 3675 if (freect)
3589 XFree (ct.value); 3676 XFree (ct.value);
3590 } 3677 }
3591 3678
3592 XSendEvent (display->display, rq.requestor, False, 0L, (XEvent *)&ev); 3679 XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev);
3593} 3680}
3594 3681
3595/* ------------------------------------------------------------------------- * 3682/* ------------------------------------------------------------------------- *
3596 * MOUSE ROUTINES * 3683 * MOUSE ROUTINES *
3597 * ------------------------------------------------------------------------- */ 3684 * ------------------------------------------------------------------------- */
3717 while (*s) 3804 while (*s)
3718 scr_overlay_set (x++, y, *s++); 3805 scr_overlay_set (x++, y, *s++);
3719} 3806}
3720 3807
3721void 3808void
3809rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s)
3810{
3811 while (*s)
3812 {
3813 text_t t = *s++;
3814 int width = wcwidth (t);
3815
3816 while (width--)
3817 {
3818 scr_overlay_set (x++, y, t);
3819 t = NOCHAR;
3820 }
3821 }
3822}
3823
3824void
3722rxvt_term::scr_swap_overlay () 3825rxvt_term::scr_swap_overlay ()
3723{ 3826{
3724 if (!ov_text) 3827 if (!ov_text)
3725 return; 3828 return;
3726 3829

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines