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.54 by pcg, Thu Mar 11 00:53:19 2004 UTC vs.
Revision 1.71 by pcg, Thu Apr 8 20:31:45 2004 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*--------------------------------*-C-*--------------------------------------*
2 * File: screen.c 2 * File: screen.C
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * 4 *
5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> 5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com>
6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
7 * 7 *
439 uint16_t total_rows; 439 uint16_t total_rows;
440 int i; 440 int i;
441 441
442 total_rows = TermWin.nrow + TermWin.saveLines; 442 total_rows = TermWin.nrow + TermWin.saveLines;
443 443
444#ifdef DEBUG_STRICT
445 for (i = 0; i < total_rows; i++)
446 {
447 if (screen.text[i])
448 /* then so is screen.rend[i] */
449 assert (screen.rend[i]);
450 }
451#endif
452
453 delete talloc; talloc = 0; 444 delete talloc; talloc = 0;
454 delete ralloc; ralloc = 0; 445 delete ralloc; ralloc = 0;
455 446
456 free (screen.text); 447 free (screen.text);
457 free (screen.tlen); 448 free (screen.tlen);
500 * XTERM_SEQ: Restore cursor: ESC 8 491 * XTERM_SEQ: Restore cursor: ESC 8
501 */ 492 */
502void 493void
503rxvt_term::scr_cursor (int mode) 494rxvt_term::scr_cursor (int mode)
504{ 495{
505 screen_t *s; 496 screen_t *s;
506 497
507 D_SCREEN ((stderr, "rxvt_scr_cursor (%c)", mode)); 498 D_SCREEN ((stderr, "rxvt_scr_cursor (%c)", mode));
508 499
509#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR) 500#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR)
510 if (current_screen == SECONDARY) 501 if (current_screen == SECONDARY)
511 s = & (swap); 502 s = &swap;
512 else 503 else
513#endif 504#endif
514 s = & (screen); 505 s = &screen;
506
515 switch (mode) 507 switch (mode)
516 { 508 {
517 case SAVE: 509 case SAVE:
518 s->s_cur.row = s->cur.row; 510 s->s_cur.row = s->cur.row;
519 s->s_cur.col = s->cur.col; 511 s->s_cur.col = s->cur.col;
520 s->s_rstyle = rstyle; 512 s->s_rstyle = rstyle;
521 s->s_charset = s->charset; 513 s->s_charset = s->charset;
522 s->s_charset_char = charsets[s->charset]; 514 s->s_charset_char = charsets[s->charset];
523 break; 515 break;
516
524 case RESTORE: 517 case RESTORE:
525 want_refresh = 1; 518 want_refresh = 1;
526 s->cur.row = s->s_cur.row; 519 s->cur.row = s->s_cur.row;
527 s->cur.col = s->s_cur.col; 520 s->cur.col = s->s_cur.col;
528 s->flags &= ~Screen_WrapNext; 521 s->flags &= ~Screen_WrapNext;
530 s->charset = s->s_charset; 523 s->charset = s->s_charset;
531 charsets[s->charset] = s->s_charset_char; 524 charsets[s->charset] = s->s_charset_char;
532 set_font_style (); 525 set_font_style ();
533 break; 526 break;
534 } 527 }
528
535 /* boundary check in case screen size changed between SAVE and RESTORE */ 529 /* boundary check in case screen size changed between SAVE and RESTORE */
536 MIN_IT (s->cur.row, TermWin.nrow - 1); 530 MIN_IT (s->cur.row, TermWin.nrow - 1);
537 MIN_IT (s->cur.col, TermWin.ncol - 1); 531 MIN_IT (s->cur.col, TermWin.ncol - 1);
538#ifdef DEBUG_STRICT 532#ifdef DEBUG_STRICT
539 assert (s->cur.row >= 0); 533 assert (s->cur.row >= 0);
551 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l 545 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l
552 */ 546 */
553int 547int
554rxvt_term::scr_change_screen (int scrn) 548rxvt_term::scr_change_screen (int scrn)
555{ 549{
556 int i; 550 int i;
557#if NSCREENS 551#if NSCREENS
558 int offset; 552 int offset;
559#endif 553#endif
560 554
561 want_refresh = 1; 555 want_refresh = 1;
562 556
563 D_SCREEN ((stderr, "rxvt_scr_change_screen (%d)", scrn)); 557 D_SCREEN ((stderr, "rxvt_scr_change_screen (%d)", scrn));
564 558
565 TermWin.view_start = 0; 559 TermWin.view_start = 0;
566 560
567 if (current_screen == scrn) 561 if (current_screen == scrn)
568 return current_screen; 562 return scrn;
569 563
570 selection_check (2); /* check for boundary cross */ 564 selection_check (2); /* check for boundary cross */
571 565
572 SWAP_IT (current_screen, scrn, int); 566 SWAP_IT (current_screen, scrn, int);
573#if NSCREENS 567#if NSCREENS
568 if (Options & Opt_secondaryScreen)
569 {
574 num_scr = 0; 570 num_scr = 0;
575 offset = TermWin.saveLines; 571 offset = TermWin.saveLines;
576 for (i = prev_nrow; i--;) 572 for (i = prev_nrow; i--;)
577 { 573 {
578 SWAP_IT (screen.text[i + offset], swap.text[i], text_t *); 574 SWAP_IT (screen.text[i + offset], swap.text[i], text_t *);
579 SWAP_IT (screen.tlen[i + offset], swap.tlen[i], int16_t); 575 SWAP_IT (screen.tlen[i + offset], swap.tlen[i], int16_t);
580 SWAP_IT (screen.rend[i + offset], swap.rend[i], rend_t *); 576 SWAP_IT (screen.rend[i + offset], swap.rend[i], rend_t *);
581 } 577 }
582 SWAP_IT (screen.cur.row, swap.cur.row, int16_t); 578 SWAP_IT (screen.cur.row, swap.cur.row, int16_t);
583 SWAP_IT (screen.cur.col, swap.cur.col, int16_t); 579 SWAP_IT (screen.cur.col, swap.cur.col, int16_t);
584# ifdef DEBUG_STRICT 580# ifdef DEBUG_STRICT
585 assert ((screen.cur.row >= 0) && (screen.cur.row < prev_nrow)); 581 assert ((screen.cur.row >= 0) && (screen.cur.row < prev_nrow));
586 assert ((screen.cur.col >= 0) && (screen.cur.col < prev_ncol)); 582 assert ((screen.cur.col >= 0) && (screen.cur.col < prev_ncol));
587# else /* drive with your eyes closed */ 583# else /* drive with your eyes closed */
588 MAX_IT (screen.cur.row, 0); 584 MAX_IT (screen.cur.row, 0);
589 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); 585 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1);
590 MAX_IT (screen.cur.col, 0); 586 MAX_IT (screen.cur.col, 0);
591 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1); 587 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1);
592# endif 588# endif
593 SWAP_IT (screen.charset, swap.charset, int16_t); 589 SWAP_IT (screen.charset, swap.charset, int16_t);
594 SWAP_IT (screen.flags, swap.flags, int); 590 SWAP_IT (screen.flags, swap.flags, int);
595 screen.flags |= Screen_VisibleCursor; 591 screen.flags |= Screen_VisibleCursor;
596 swap.flags |= Screen_VisibleCursor; 592 swap.flags |= Screen_VisibleCursor;
597#else 593 }
598# ifdef SCROLL_ON_NO_SECONDARY 594 else
595#endif
596 if (Options & Opt_secondaryScroll)
599 if (current_screen == PRIMARY) 597 //if (current_screen == PRIMARY)
600 scr_scroll_text (0, (prev_nrow - 1), prev_nrow, 0); 598 scr_scroll_text (0, (prev_nrow - 1), prev_nrow, 0);
601# endif
602#endif
603 return scrn; 599 return scrn;
604} 600}
605 601
606/* ------------------------------------------------------------------------- */ 602/* ------------------------------------------------------------------------- */
607/* 603/*
649 return 0; 645 return 0;
650 646
651 want_refresh = 1; 647 want_refresh = 1;
652 D_SCREEN ((stderr, "rxvt_scroll_text (%d,%d,%d,%d): %s", row1, row2, count, spec, (current_screen == PRIMARY) ? "Primary" : "Secondary")); 648 D_SCREEN ((stderr, "rxvt_scroll_text (%d,%d,%d,%d): %s", row1, row2, count, spec, (current_screen == PRIMARY) ? "Primary" : "Secondary"));
653 649
654 if ((count > 0) && (row1 == 0) && (current_screen == PRIMARY)) 650 if (row1 == 0 && count > 0
651 && (current_screen == PRIMARY || Options & Opt_secondaryScroll))
655 { 652 {
656 nscrolled = (long)TermWin.nscrolled + (long)count; 653 nscrolled = (long)TermWin.nscrolled + (long)count;
657 654
658 if (nscrolled > (long)TermWin.saveLines) 655 if (nscrolled > (long)TermWin.saveLines)
659 TermWin.nscrolled = TermWin.saveLines; 656 TermWin.nscrolled = TermWin.saveLines;
762/* ------------------------------------------------------------------------- */ 759/* ------------------------------------------------------------------------- */
763/* 760/*
764 * Add text given in <str> of length <len> to screen struct 761 * Add text given in <str> of length <len> to screen struct
765 */ 762 */
766void 763void
767rxvt_term::scr_add_lines (const uint32_t *str, int nlines, int len) 764rxvt_term::scr_add_lines (const unicode_t *str, int nlines, int len)
768{ 765{
769 unsigned char checksel, clearsel; 766 unsigned char checksel, clearsel;
770 uint32_t c; 767 unicode_t c;
771 int i, row, last_col; 768 int i, row, last_col;
772 text_t *stp; 769 text_t *stp;
773 rend_t *srp; 770 rend_t *srp;
774 771
775 if (len <= 0) /* sanity */ 772 if (len <= 0) /* sanity */
801 MIN_IT (screen.cur.row, (int32_t)TermWin.nrow - 1); 798 MIN_IT (screen.cur.row, (int32_t)TermWin.nrow - 1);
802 MAX_IT (screen.cur.row, - (int32_t)TermWin.nscrolled); 799 MAX_IT (screen.cur.row, - (int32_t)TermWin.nscrolled);
803#endif 800#endif
804 row = screen.cur.row + TermWin.saveLines; 801 row = screen.cur.row + TermWin.saveLines;
805 802
806 checksel = (selection.op 803 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
807 && current_screen == selection.screen) ? 1 : 0;
808 clearsel = 0; 804 clearsel = 0;
809 805
810 stp = screen.text[row]; 806 stp = screen.text[row];
811 srp = screen.rend[row]; 807 srp = screen.rend[row];
812 808
813 for (i = 0; i < len;) 809 while (len--)
814 { 810 {
815 c = str[i++]; 811 c = *str++;
812
813 if (c < 0x20)
816 switch (c) 814 switch (c)
817 { 815 {
818 case '\t': 816 case C0_HT:
819 scr_tab (1); 817 scr_tab (1);
820 continue; 818 continue;
821 case '\n': 819
820 case C0_LF:
822 if (screen.tlen[row] != -1) /* XXX: think about this */ 821 if (screen.tlen[row] != -1) /* XXX: think about this */
823 MAX_IT (screen.tlen[row], screen.cur.col); 822 MAX_IT (screen.tlen[row], screen.cur.col);
823
824 screen.flags &= ~Screen_WrapNext; 824 screen.flags &= ~Screen_WrapNext;
825
825 if (screen.cur.row == screen.bscroll) 826 if (screen.cur.row == screen.bscroll)
826 scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0); 827 scr_scroll_text (screen.tscroll, screen.bscroll, 1, 0);
827 else if (screen.cur.row < (TermWin.nrow - 1)) 828 else if (screen.cur.row < (TermWin.nrow - 1))
828 row = (++screen.cur.row) + TermWin.saveLines; 829 row = (++screen.cur.row) + TermWin.saveLines;
830
829 stp = screen.text[row]; /* _must_ refresh */ 831 stp = screen.text[row]; /* _must_ refresh */
830 srp = screen.rend[row]; /* _must_ refresh */ 832 srp = screen.rend[row]; /* _must_ refresh */
831 continue; 833 continue;
832 case '\r': 834
835 case C0_CR:
833 if (screen.tlen[row] != -1) /* XXX: think about this */ 836 if (screen.tlen[row] != -1) /* XXX: think about this */
834 MAX_IT (screen.tlen[row], screen.cur.col); 837 MAX_IT (screen.tlen[row], screen.cur.col);
838
835 screen.flags &= ~Screen_WrapNext; 839 screen.flags &= ~Screen_WrapNext;
836 screen.cur.col = 0; 840 screen.cur.col = 0;
837 continue; 841 continue;
838 default:
839 if (c == 127)
840 continue; /* yummmm..... */
841 break;
842 } 842 }
843 843
844 if (checksel /* see if we're writing within selection */ 844 if (checksel /* see if we're writing within selection */
845 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 845 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
846 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 846 && ROWCOL_IS_BEFORE (screen.cur, selection.end))
847 { 847 {
864 } 864 }
865 865
866 if (screen.flags & Screen_Insert) 866 if (screen.flags & Screen_Insert)
867 scr_insdel_chars (1, INSERT); 867 scr_insdel_chars (1, INSERT);
868 868
869 if (IS_COMPOSE (c))
870 c = REPLACEMENT_CHAR;
871
872 // rely on wcwidth to tell us the character width, at least for non-latin1 869 // rely on wcwidth to tell us the character width, at least for non-latin1
873 // do wcwidth before further replacements, as wcwidth says that line-drawing 870 // do wcwidth before further replacements, as wcwidth says that line-drawing
874 // characters have width -1 (DOH!) on gnu/linux sometimes. 871 // characters have width -1 (DOH!) on GNU/Linux sometimes.
875 int width = c < 256 ? 1 : wcwidth (c); 872 int width = c < 256 ? 1 : wcwidth (c);
876 873
877 if (charsets[screen.charset] == '0') // DEC SPECIAL 874 if (charsets[screen.charset] == '0') // DEC SPECIAL
878 switch (c)
879 { 875 {
880 // vt100 special graphics and line drawing 876 // vt100 special graphics and line drawing
881 case '`': c = 0x25c6; break; case '_': c = 0x0020; break; 877 static uint16_t vt100_0[32] = { // 5f .. 7e
882 case 'a': c = 0x2592; break; case 'b': c = 0x2409; break; case 'c': c = 0x240c; break; 878 0x0020, 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
883 case 'd': c = 0x240d; break; case 'e': c = 0x240a; break; case 'f': c = 0x00b0; break; 879 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
884 case 'g': c = 0x00b1; break; case 'h': c = 0x2424; break; case 'i': c = 0x240b; break; 880 0x23ba, 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534,
885 case 'j': c = 0x2518; break; case 'k': c = 0x2510; break; case 'l': c = 0x250c; break; 881 0x252c, 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7,
886 case 'm': c = 0x2514; break; case 'n': c = 0x253c; break; case 'o': c = 0x23ba; break;
887 case 'p': c = 0x23bb; break; case 'q': c = 0x2500; break; case 'r': c = 0x23bc; break;
888 case 's': c = 0x23bd; break; case 't': c = 0x251c; break; case 'u': c = 0x2524; break;
889 case 'v': c = 0x2534; break; case 'w': c = 0x252c; break; case 'x': c = 0x2502; break;
890 case 'y': c = 0x2264; break; case 'z': c = 0x2265; break; case '{': c = 0x03c0; break;
891 case '|': c = 0x2260; break; case '}': c = 0x00a3; break; case '~': c = 0x00b7; break;
892 } 882 };
883
884 if (c >= 0x5f && c <= 0x7e)
885 {
886 c = vt100_0[c - 0x5f];
887 width = 1;
888 }
893 889 }
894 890
895 if (width > 0) 891 if (width > 0)
896 { 892 {
897#if !UNICODE_3 893#if !UNICODE_3 && ENABLE_COMBINING
898 // trim characters we can't store directly :( 894 // trim characters we can't store directly :(
899 if (c >= 0x10000) 895 if (c >= 0x10000)
900 c = rxvt_composite.compose (c); // map to lower 16 bits 896 c = rxvt_composite.compose (c); // map to lower 16 bits
901#endif 897#endif
902 rend_t rend = SET_FONT (rstyle, TermWin.fontset->find_font (c)); 898 rend_t rend = SET_FONT (rstyle, TermWin.fontset->find_font (c));
927 srp[c] = rend; 923 srp[c] = rend;
928 } 924 }
929 } 925 }
930 else if (width == 0) 926 else if (width == 0)
931 { 927 {
932#if ENCODING_COMPOSE 928#if ENABLE_COMBINING
933 // handle combining characters 929 // handle combining characters
934 // we just tag the accent on the previous on-screen character. 930 // we just tag the accent on the previous on-screen character.
935 // this is arguably not correct, but also arguably not wrong. 931 // this is arguably not correct, but also arguably not wrong.
936 // we don't handle double-width characters nicely yet. 932 // we don't handle double-width characters nicely yet.
937 933
955 // handle double-width-chars by making them look extremely ugly 951 // handle double-width-chars by making them look extremely ugly
956 if (*tp == NOCHAR) 952 if (*tp == NOCHAR)
957 *tp = ' '; // hack //D //TODO //--tp, --rp; 953 *tp = ' '; // hack //D //TODO //--tp, --rp;
958 954
959 // first try to find a precomposed character 955 // first try to find a precomposed character
960 uint32_t n = rxvt_compose (*tp, c); 956 unicode_t n = rxvt_compose (*tp, c);
961 if (n == NOCHAR) 957 if (n == NOCHAR)
962 n = rxvt_composite.compose (*tp, c); 958 n = rxvt_composite.compose (*tp, c);
963 959
964 *tp = n; 960 *tp = n;
965 *rp = SET_FONT (*rp, TermWin.fontset->find_font (*tp)); 961 *rp = SET_FONT (*rp, TermWin.fontset->find_font (*tp));
992 */ 988 */
993void 989void
994rxvt_term::scr_backspace () 990rxvt_term::scr_backspace ()
995{ 991{
996 want_refresh = 1; 992 want_refresh = 1;
993
997 if (screen.cur.col == 0) 994 if (screen.cur.col == 0)
998 { 995 {
999 if (screen.cur.row > 0) 996 if (screen.cur.row > 0)
1000 { 997 {
1001#ifdef TERMCAP_HAS_BW 998#ifdef TERMCAP_HAS_BW
1006 1003
1007 } 1004 }
1008 } 1005 }
1009 else if ((screen.flags & Screen_WrapNext) == 0) 1006 else if ((screen.flags & Screen_WrapNext) == 0)
1010 scr_gotorc (0, -1, RELATIVE); 1007 scr_gotorc (0, -1, RELATIVE);
1008
1011 screen.flags &= ~Screen_WrapNext; 1009 screen.flags &= ~Screen_WrapNext;
1012} 1010}
1013 1011
1014/* ------------------------------------------------------------------------- */ 1012/* ------------------------------------------------------------------------- */
1015/* 1013/*
1018 * XTERM_SEQ: CTRL-I 1016 * XTERM_SEQ: CTRL-I
1019 */ 1017 */
1020void 1018void
1021rxvt_term::scr_tab (int count) 1019rxvt_term::scr_tab (int count)
1022{ 1020{
1023 int i, x; 1021 int i, x;
1024 1022
1025 D_SCREEN ((stderr, "rxvt_scr_tab (%d)", count)); 1023 D_SCREEN ((stderr, "rxvt_scr_tab (%d)", count));
1026 want_refresh = 1; 1024 want_refresh = 1;
1027 i = x = screen.cur.col; 1025 i = x = screen.cur.col;
1026
1028 if (count == 0) 1027 if (count == 0)
1029 return; 1028 return;
1030 else if (count > 0) 1029 else if (count > 0)
1031 { 1030 {
1032 for (; ++i < TermWin.ncol; ) 1031 for (; ++i < TermWin.ncol; )
1034 { 1033 {
1035 x = i; 1034 x = i;
1036 if (!--count) 1035 if (!--count)
1037 break; 1036 break;
1038 } 1037 }
1038
1039 if (count) 1039 if (count)
1040 x = TermWin.ncol - 1; 1040 x = TermWin.ncol - 1;
1041 } 1041 }
1042 else /* if (count < 0) */ 1042 else /* if (count < 0) */
1043 { 1043 {
1046 { 1046 {
1047 x = i; 1047 x = i;
1048 if (!++count) 1048 if (!++count)
1049 break; 1049 break;
1050 } 1050 }
1051
1051 if (count) 1052 if (count)
1052 x = 0; 1053 x = 0;
1053 } 1054 }
1055
1054 if (x != screen.cur.col) 1056 if (x != screen.cur.col)
1055 scr_gotorc (0, x, R_RELATIVE); 1057 scr_gotorc (0, x, R_RELATIVE);
1056} 1058}
1057 1059
1058/* ------------------------------------------------------------------------- */ 1060/* ------------------------------------------------------------------------- */
1115 want_refresh = 1; 1117 want_refresh = 1;
1116 ZERO_SCROLLBACK (); 1118 ZERO_SCROLLBACK ();
1117 1119
1118 D_SCREEN ((stderr, "rxvt_scr_gotorc (r:%s%d,c:%s%d): from (r:%d,c:%d)", (relative & R_RELATIVE ? "+" : ""), row, (relative & C_RELATIVE ? "+" : ""), col, screen.cur.row, screen.cur.col)); 1120 D_SCREEN ((stderr, "rxvt_scr_gotorc (r:%s%d,c:%s%d): from (r:%d,c:%d)", (relative & R_RELATIVE ? "+" : ""), row, (relative & C_RELATIVE ? "+" : ""), col, screen.cur.row, screen.cur.col));
1119 1121
1120 screen.cur.col = ((relative & C_RELATIVE) ? (screen.cur.col + col) 1122 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col;
1121 : col);
1122 MAX_IT (screen.cur.col, 0); 1123 MAX_IT (screen.cur.col, 0);
1123 MIN_IT (screen.cur.col, (int32_t)TermWin.ncol - 1); 1124 MIN_IT (screen.cur.col, (int32_t)TermWin.ncol - 1);
1124 1125
1125 screen.flags &= ~Screen_WrapNext; 1126 screen.flags &= ~Screen_WrapNext;
1126 if (relative & R_RELATIVE) 1127 if (relative & R_RELATIVE)
1165 * direction should be UP or DN 1166 * direction should be UP or DN
1166 */ 1167 */
1167void 1168void
1168rxvt_term::scr_index (enum page_dirn direction) 1169rxvt_term::scr_index (enum page_dirn direction)
1169{ 1170{
1170 int dirn; 1171 int dirn;
1171 1172
1172 want_refresh = 1; 1173 want_refresh = 1;
1173 dirn = ((direction == UP) ? 1 : -1); 1174 dirn = ((direction == UP) ? 1 : -1);
1174 D_SCREEN ((stderr, "rxvt_scr_index (%d)", dirn)); 1175 D_SCREEN ((stderr, "rxvt_scr_index (%d)", dirn));
1175 1176
1251 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1252 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1252 */ 1253 */
1253void 1254void
1254rxvt_term::scr_erase_screen (int mode) 1255rxvt_term::scr_erase_screen (int mode)
1255{ 1256{
1256 int num; 1257 int num;
1257 int32_t row, row_offset; 1258 int32_t row, row_offset;
1258 rend_t ren; 1259 rend_t ren;
1259 XGCValues gcvalue; 1260 XGCValues gcvalue;
1260 1261
1261 want_refresh = 1; 1262 want_refresh = 1;
1262 D_SCREEN ((stderr, "rxvt_scr_erase_screen (%d) at screen row: %d", mode, screen.cur.row)); 1263 D_SCREEN ((stderr, "rxvt_scr_erase_screen (%d) at screen row: %d", mode, screen.cur.row));
1263 ZERO_SCROLLBACK (); 1264 ZERO_SCROLLBACK ();
1264 row_offset = (int32_t)TermWin.saveLines; 1265 row_offset = (int32_t)TermWin.saveLines;
1283 num = TermWin.nrow; 1284 num = TermWin.nrow;
1284 break; 1285 break;
1285 default: 1286 default:
1286 return; 1287 return;
1287 } 1288 }
1289
1288 refresh_type |= REFRESH_BOUNDS; 1290 refresh_type |= REFRESH_BOUNDS;
1291
1289 if (selection.op && current_screen == selection.screen 1292 if (selection.op && current_screen == selection.screen
1290 && ((selection.beg.row >= row && selection.beg.row <= row + num) 1293 && ((selection.beg.row >= row && selection.beg.row <= row + num)
1291 || (selection.end.row >= row 1294 || (selection.end.row >= row
1292 && selection.end.row <= row + num))) 1295 && selection.end.row <= row + num)))
1293 CLEAR_SELECTION (); 1296 CLEAR_SELECTION ();
1297
1294 if (row >= TermWin.nrow) /* Out Of Bounds */ 1298 if (row >= TermWin.nrow) /* Out Of Bounds */
1295 return; 1299 return;
1300
1296 MIN_IT (num, (TermWin.nrow - row)); 1301 MIN_IT (num, (TermWin.nrow - row));
1302
1297 if (rstyle & (RS_RVid | RS_Uline)) 1303 if (rstyle & (RS_RVid | RS_Uline))
1298 ren = (rend_t) ~RS_None; 1304 ren = (rend_t) ~RS_None;
1299 else if (GET_BASEBG (rstyle) == Color_bg) 1305 else if (GET_BASEBG (rstyle) == Color_bg)
1300 { 1306 {
1301 ren = DEFAULT_RSTYLE; 1307 ren = DEFAULT_RSTYLE;
1308 XChangeGC (display->display, TermWin.gc, GCForeground, &gcvalue); 1314 XChangeGC (display->display, TermWin.gc, GCForeground, &gcvalue);
1309 ERASE_ROWS (row, num); 1315 ERASE_ROWS (row, num);
1310 gcvalue.foreground = PixColors[Color_fg]; 1316 gcvalue.foreground = PixColors[Color_fg];
1311 XChangeGC (display->display, TermWin.gc, GCForeground, &gcvalue); 1317 XChangeGC (display->display, TermWin.gc, GCForeground, &gcvalue);
1312 } 1318 }
1319
1313 for (; num--; row++) 1320 for (; num--; row++)
1314 { 1321 {
1315 scr_blank_screen_mem (screen.text, screen.rend, 1322 scr_blank_screen_mem (screen.text, screen.rend,
1316 (unsigned int) (row + row_offset), rstyle); 1323 (unsigned int) (row + row_offset), rstyle);
1317 screen.tlen[row + row_offset] = 0; 1324 screen.tlen[row + row_offset] = 0;
1351 * Insert/Delete <count> lines 1358 * Insert/Delete <count> lines
1352 */ 1359 */
1353void 1360void
1354rxvt_term::scr_insdel_lines (int count, int insdel) 1361rxvt_term::scr_insdel_lines (int count, int insdel)
1355{ 1362{
1356 int end; 1363 int end;
1357 1364
1358 ZERO_SCROLLBACK (); 1365 ZERO_SCROLLBACK ();
1359 1366
1360 selection_check (1); 1367 selection_check (1);
1361 1368
1380 * Insert/Delete <count> characters from the current position 1387 * Insert/Delete <count> characters from the current position
1381 */ 1388 */
1382void 1389void
1383rxvt_term::scr_insdel_chars (int count, int insdel) 1390rxvt_term::scr_insdel_chars (int count, int insdel)
1384{ 1391{
1385 int col, row; 1392 int col, row;
1386 rend_t tr; 1393 rend_t tr;
1387 text_t *stp; 1394 text_t *stp;
1388 rend_t *srp; 1395 rend_t *srp;
1389 int16_t *slp; 1396 int16_t *slp;
1390 1397
1391 want_refresh = 1; 1398 want_refresh = 1;
1392 ZERO_SCROLLBACK (); 1399 ZERO_SCROLLBACK ();
1393 1400
1394 if (count <= 0) 1401 if (count <= 0)
1401 screen.flags &= ~Screen_WrapNext; 1408 screen.flags &= ~Screen_WrapNext;
1402 1409
1403 stp = screen.text[row]; 1410 stp = screen.text[row];
1404 srp = screen.rend[row]; 1411 srp = screen.rend[row];
1405 slp = & (screen.tlen[row]); 1412 slp = & (screen.tlen[row]);
1413
1406 switch (insdel) 1414 switch (insdel)
1407 { 1415 {
1408 case INSERT: 1416 case INSERT:
1409 for (col = TermWin.ncol - 1; (col - count) >= screen.cur.col; 1417 for (col = TermWin.ncol - 1; (col - count) >= screen.cur.col;
1410 col--) 1418 col--)
1411 { 1419 {
1412 stp[col] = stp[col - count]; 1420 stp[col] = stp[col - count];
1413 srp[col] = srp[col - count]; 1421 srp[col] = srp[col - count];
1414 } 1422 }
1423
1415 if (*slp != -1) 1424 if (*slp != -1)
1416 { 1425 {
1417 *slp += count; 1426 *slp += count;
1418 MIN_IT (*slp, TermWin.ncol); 1427 MIN_IT (*slp, TermWin.ncol);
1419 } 1428 }
1429
1420 if (selection.op && current_screen == selection.screen 1430 if (selection.op && current_screen == selection.screen
1421 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1431 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1422 { 1432 {
1423 if (selection.end.row != screen.cur.row 1433 if (selection.end.row != screen.cur.row
1424 || (selection.end.col + count >= TermWin.ncol)) 1434 || (selection.end.col + count >= TermWin.ncol))
1428 selection.beg.col += count; 1438 selection.beg.col += count;
1429 selection.mark.col += count; /* XXX: yes? */ 1439 selection.mark.col += count; /* XXX: yes? */
1430 selection.end.col += count; 1440 selection.end.col += count;
1431 } 1441 }
1432 } 1442 }
1443
1433 scr_blank_line (& (stp[screen.cur.col]), & (srp[screen.cur.col]), 1444 scr_blank_line (& (stp[screen.cur.col]), & (srp[screen.cur.col]),
1434 (unsigned int)count, rstyle); 1445 (unsigned int)count, rstyle);
1435 break; 1446 break;
1447
1436 case ERASE: 1448 case ERASE:
1437 screen.cur.col += count; /* don't worry if > TermWin.ncol */ 1449 screen.cur.col += count; /* don't worry if > TermWin.ncol */
1438 selection_check (1); 1450 selection_check (1);
1439 screen.cur.col -= count; 1451 screen.cur.col -= count;
1440 scr_blank_line (& (stp[screen.cur.col]), & (srp[screen.cur.col]), 1452 scr_blank_line (& (stp[screen.cur.col]), & (srp[screen.cur.col]),
1441 (unsigned int)count, rstyle); 1453 (unsigned int)count, rstyle);
1442 break; 1454 break;
1455
1443 case DELETE: 1456 case DELETE:
1444 tr = srp[TermWin.ncol - 1]
1445 & (RS_fgMask | RS_bgMask | RS_baseattrMask); 1457 tr = srp[TermWin.ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask);
1458
1446 for (col = screen.cur.col; (col + count) < TermWin.ncol; col++) 1459 for (col = screen.cur.col; (col + count) < TermWin.ncol; col++)
1447 { 1460 {
1448 stp[col] = stp[col + count]; 1461 stp[col] = stp[col + count];
1449 srp[col] = srp[col + count]; 1462 srp[col] = srp[col + count];
1450 } 1463 }
1464
1451 scr_blank_line (& (stp[TermWin.ncol - count]), 1465 scr_blank_line (& (stp[TermWin.ncol - count]),
1452 & (srp[TermWin.ncol - count]), 1466 & (srp[TermWin.ncol - count]),
1453 (unsigned int)count, tr); 1467 (unsigned int)count, tr);
1468
1454 if (*slp == -1) /* break line continuation */ 1469 if (*slp == -1) /* break line continuation */
1455 *slp = TermWin.ncol; 1470 *slp = TermWin.ncol;
1471
1456 *slp -= count; 1472 *slp -= count;
1457 MAX_IT (*slp, 0); 1473 MAX_IT (*slp, 0);
1474
1458 if (selection.op && current_screen == selection.screen 1475 if (selection.op && current_screen == selection.screen
1459 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1476 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1460 { 1477 {
1461 if (selection.end.row != screen.cur.row 1478 if (selection.end.row != screen.cur.row
1462 || (screen.cur.col >= selection.beg.col - count) 1479 || (screen.cur.col >= selection.beg.col - count)
1468 selection.beg.col -= count; 1485 selection.beg.col -= count;
1469 selection.mark.col -= count; /* XXX: yes? */ 1486 selection.mark.col -= count; /* XXX: yes? */
1470 selection.end.col -= count; 1487 selection.end.col -= count;
1471 } 1488 }
1472 } 1489 }
1490
1473 break; 1491 break;
1474 } 1492 }
1475} 1493}
1476 1494
1477/* ------------------------------------------------------------------------- */ 1495/* ------------------------------------------------------------------------- */
1482void 1500void
1483rxvt_term::scr_scroll_region (int top, int bot) 1501rxvt_term::scr_scroll_region (int top, int bot)
1484{ 1502{
1485 MAX_IT (top, 0); 1503 MAX_IT (top, 0);
1486 MIN_IT (bot, (int)TermWin.nrow - 1); 1504 MIN_IT (bot, (int)TermWin.nrow - 1);
1505
1487 if (top > bot) 1506 if (top > bot)
1488 return; 1507 return;
1508
1489 screen.tscroll = top; 1509 screen.tscroll = top;
1490 screen.bscroll = bot; 1510 screen.bscroll = bot;
1491 scr_gotorc (0, 0, 0); 1511 scr_gotorc (0, 0, 0);
1492} 1512}
1493 1513
1499 */ 1519 */
1500void 1520void
1501rxvt_term::scr_cursor_visible (int mode) 1521rxvt_term::scr_cursor_visible (int mode)
1502{ 1522{
1503 want_refresh = 1; 1523 want_refresh = 1;
1524
1504 if (mode) 1525 if (mode)
1505 screen.flags |= Screen_VisibleCursor; 1526 screen.flags |= Screen_VisibleCursor;
1506 else 1527 else
1507 screen.flags &= ~Screen_VisibleCursor; 1528 screen.flags &= ~Screen_VisibleCursor;
1508} 1529}
1824 if (TermWin.view_start != oldviewstart) 1845 if (TermWin.view_start != oldviewstart)
1825 { 1846 {
1826 want_refresh = 1; 1847 want_refresh = 1;
1827 num_scr -= (TermWin.view_start - oldviewstart); 1848 num_scr -= (TermWin.view_start - oldviewstart);
1828 } 1849 }
1850
1829 return (int) (TermWin.view_start - oldviewstart); 1851 return (int) (TermWin.view_start - oldviewstart);
1830} 1852}
1831 1853
1832/* ------------------------------------------------------------------------- */ 1854/* ------------------------------------------------------------------------- */
1833void 1855void
1951 1973
1952 /* 1974 /*
1953 * C: set the cursor character (s) 1975 * C: set the cursor character (s)
1954 */ 1976 */
1955 { 1977 {
1956 unsigned char setoldcursor; 1978 unsigned char setoldcursor;
1957 rend_t ccol1, /* Cursor colour */ 1979 rend_t ccol1, /* Cursor colour */
1958 ccol2; /* Cursor colour2 */ 1980 ccol2; /* Cursor colour2 */
1959 1981
1960 showcursor = (screen.flags & Screen_VisibleCursor); 1982 showcursor = (screen.flags & Screen_VisibleCursor);
1961#ifdef CURSOR_BLINK 1983#ifdef CURSOR_BLINK
1962 if (hidden_cursor) 1984 if (hidden_cursor)
1963 showcursor = 0; 1985 showcursor = 0;
1964#endif 1986#endif
1965 1987
1966 if (showcursor) 1988 if (showcursor)
1967 { 1989 {
1968 srp = & (screen.rend[screen.cur.row + TermWin.saveLines] 1990 srp = &(screen.rend[screen.cur.row + TermWin.saveLines][screen.cur.col]);
1969 [screen.cur.col]);
1970 1991
1971 if (showcursor && TermWin.focus) 1992 if (showcursor && TermWin.focus)
1972 { 1993 {
1973 *srp ^= RS_RVid; 1994 *srp ^= RS_RVid;
1974#ifndef NO_CURSORCOLOR 1995#ifndef NO_CURSORCOLOR
2002 if (screen.cur.row + TermWin.view_start != ocrow 2023 if (screen.cur.row + TermWin.view_start != ocrow
2003 || screen.cur.col != oldcursor.col) 2024 || screen.cur.col != oldcursor.col)
2004 { 2025 {
2005 if (ocrow < TermWin.nrow 2026 if (ocrow < TermWin.nrow
2006 && oldcursor.col < TermWin.ncol) 2027 && oldcursor.col < TermWin.ncol)
2007 {
2008 drawn_rend[ocrow][oldcursor.col] ^= (RS_RVid | RS_Uline); 2028 drawn_rend[ocrow][oldcursor.col] ^= (RS_RVid | RS_Uline);
2009 } 2029
2010 if (TermWin.focus || !showcursor) 2030 if (TermWin.focus || !showcursor)
2011 oldcursor.row = -1; 2031 oldcursor.row = -1;
2012 else 2032 else
2013 setoldcursor = 1; 2033 setoldcursor = 1;
2014 } 2034 }
2015 } 2035 }
2016 else if (!TermWin.focus) 2036 else if (!TermWin.focus)
2017 setoldcursor = 1; 2037 setoldcursor = 1;
2038
2018 if (setoldcursor) 2039 if (setoldcursor)
2019 { 2040 {
2020 if (screen.cur.row + TermWin.view_start >= TermWin.nrow) 2041 if (screen.cur.row + TermWin.view_start >= TermWin.nrow)
2021 oldcursor.row = -1; 2042 oldcursor.row = -1;
2022 else 2043 else
2034 */ 2055 */
2035 i = num_scr; 2056 i = num_scr;
2036 if (refresh_type == FAST_REFRESH && num_scr_allow && i 2057 if (refresh_type == FAST_REFRESH && num_scr_allow && i
2037 && abs (i) < TermWin.nrow && !must_clear) 2058 && abs (i) < TermWin.nrow && !must_clear)
2038 { 2059 {
2039 int16_t nits; 2060 int16_t nits;
2040 int j; 2061 int j;
2041 rend_t *drp2; 2062 rend_t *drp2;
2042 text_t *dtp2; 2063 text_t *dtp2;
2043 int len, wlen; 2064 int len, wlen;
2044 2065
2045 j = TermWin.nrow; 2066 j = TermWin.nrow;
2046 wlen = len = -1; 2067 wlen = len = -1;
2047 row = i > 0 ? 0 : j - 1; 2068 row = i > 0 ? 0 : j - 1;
2048 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2069 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2192 else 2213 else
2193 rvid = !rvid; 2214 rvid = !rvid;
2194 } 2215 }
2195 2216
2196 if (rend & RS_Uline) 2217 if (rend & RS_Uline)
2197 {
2198 if (ISSET_PIXCOLOR (Color_UL)) 2218 if (ISSET_PIXCOLOR (Color_UL))
2199 fore = Color_UL; 2219 fore = Color_UL;
2200 }
2201#endif 2220#endif
2202 2221
2203 if (rvid) 2222 if (rvid)
2204 { 2223 {
2205 SWAP_IT (fore, back, int); 2224 SWAP_IT (fore, back, int);
2502 { 2521 {
2503 n = min (len - i, PROP_SIZE); 2522 n = min (len - i, PROP_SIZE);
2504 MEMCPY (ds, data + i, n); 2523 MEMCPY (ds, data + i, n);
2505 2524
2506 for (j = 0; j < n; j++) 2525 for (j = 0; j < n; j++)
2507 if (ds[j] == '\n') 2526 if (ds[j] == C0_LF)
2508 ds[j] = '\r'; 2527 ds[j] = C0_CR;
2509 2528
2510 tt_write (ds, (int)n); 2529 tt_write (ds, (int)n);
2511 } 2530 }
2512 2531
2513 free (ds); 2532 free (ds);
2626void 2645void
2627rxvt_term::incr_cb (time_watcher &w) 2646rxvt_term::incr_cb (time_watcher &w)
2628{ 2647{
2629 selection_wait = Sel_none; 2648 selection_wait = Sel_none;
2630 2649
2631 rxvt_print_error ("data loss: timeout on INCR selection paste"); 2650 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2632} 2651}
2633 2652
2634/* 2653/*
2635 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za> 2654 * INCR support originally provided by Paul Sheer <psheer@obsidian.co.za>
2636 */ 2655 */
2715 { 2734 {
2716 int i; 2735 int i;
2717 2736
2718 selection_request_time = tm; 2737 selection_request_time = tm;
2719 selection_wait = Sel_normal; 2738 selection_wait = Sel_normal;
2739
2720 for (i = Sel_Primary; i <= Sel_Clipboard; i++) 2740 for (i = Sel_Primary; i <= Sel_Clipboard; i++)
2721 { 2741 {
2722#if X_HAVE_UTF8_STRING 2742#if X_HAVE_UTF8_STRING
2723 selection_type = Sel_UTF8String; 2743 selection_type = Sel_UTF8String;
2724 if (selection_request_other (xa[XA_UTF8_STRING], i)) 2744 if (selection_request_other (xa[XA_UTF8_STRING], i))
2778 want_refresh = 1; 2798 want_refresh = 1;
2779 free (selection.text); 2799 free (selection.text);
2780 selection.text = NULL; 2800 selection.text = NULL;
2781 selection.len = 0; 2801 selection.len = 0;
2782 CLEAR_SELECTION (); 2802 CLEAR_SELECTION ();
2803
2804 if (display->selection_owner == this)
2805 display->selection_owner = 0;
2783} 2806}
2784 2807
2785/* ------------------------------------------------------------------------- */ 2808/* ------------------------------------------------------------------------- */
2786/* 2809/*
2787 * Copy a selection into the cut buffer 2810 * Copy a selection into the cut buffer
2838 2861
2839 for (; col < end_col; col++) 2862 for (; col < end_col; col++)
2840 { 2863 {
2841 if (*t == NOCHAR) 2864 if (*t == NOCHAR)
2842 t++; 2865 t++;
2866#if ENABLE_COMBINING
2843 else if (IS_COMPOSE (*t)) 2867 else if (IS_COMPOSE (*t))
2844 { 2868 {
2845 int len = rxvt_composite.expand (*t, 0); 2869 int len = rxvt_composite.expand (*t, 0);
2846 2870
2847 extra -= (len - 1); 2871 extra -= (len - 1);
2853 new_selection_text = (wchar_t *)rxvt_realloc (new_selection_text, (i + 4) * sizeof (wchar_t)); 2877 new_selection_text = (wchar_t *)rxvt_realloc (new_selection_text, (i + 4) * sizeof (wchar_t));
2854 } 2878 }
2855 2879
2856 ofs += rxvt_composite.expand (*t++, new_selection_text + ofs); 2880 ofs += rxvt_composite.expand (*t++, new_selection_text + ofs);
2857 } 2881 }
2882#endif
2858 else 2883 else
2859 new_selection_text[ofs++] = *t++; 2884 new_selection_text[ofs++] = *t++;
2860 } 2885 }
2861 2886
2862 if (screen.tlen[row] != -1 && row != end_row) 2887 if (screen.tlen[row] != -1 && row != end_row)
2863 new_selection_text[ofs++] = L'\n'; 2888 new_selection_text[ofs++] = C0_LF;
2864 } 2889 }
2865 2890
2866#ifndef NO_OLD_SELECTION
2867 if (selection_style == OLD_SELECT)
2868 if (end_col == TermWin.ncol)
2869 new_selection_text[ofs++] = L'\n';
2870#endif
2871#ifndef NO_NEW_SELECTION
2872 if (selection_style != OLD_SELECT)
2873 if (end_col != selection.end.col) 2891 if (end_col != selection.end.col)
2874 new_selection_text[ofs++] = L'\n'; 2892 new_selection_text[ofs++] = C0_LF;
2875#endif 2893
2876 new_selection_text[ofs] = 0; 2894 new_selection_text[ofs] = 0;
2877 2895
2878 if (ofs == 0) 2896 if (ofs == 0)
2879 { 2897 {
2880 free (new_selection_text); 2898 free (new_selection_text);
2889 2907
2890 XSetSelectionOwner (display->display, XA_PRIMARY, TermWin.vt, tm); 2908 XSetSelectionOwner (display->display, XA_PRIMARY, TermWin.vt, tm);
2891 if (XGetSelectionOwner (display->display, XA_PRIMARY) == TermWin.vt) 2909 if (XGetSelectionOwner (display->display, XA_PRIMARY) == TermWin.vt)
2892 display->set_selection_owner (this); 2910 display->set_selection_owner (this);
2893 else 2911 else
2894 rxvt_print_error ("can't get primary selection"); 2912 rxvt_warn ("can't get primary selection, ignoring.\n");
2895 2913
2896#if 0 2914#if 0
2897 XTextProperty ct; 2915 XTextProperty ct;
2898 2916
2899 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 2917 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0)
2939rxvt_term::selection_start_colrow (int col, int row) 2957rxvt_term::selection_start_colrow (int col, int row)
2940{ 2958{
2941 want_refresh = 1; 2959 want_refresh = 1;
2942 selection.mark.col = col; 2960 selection.mark.col = col;
2943 selection.mark.row = row - TermWin.view_start; 2961 selection.mark.row = row - TermWin.view_start;
2962
2944 MAX_IT (selection.mark.row, - (int32_t)TermWin.nscrolled); 2963 MAX_IT (selection.mark.row, - (int32_t)TermWin.nscrolled);
2945 MIN_IT (selection.mark.row, (int32_t)TermWin.nrow - 1); 2964 MIN_IT (selection.mark.row, (int32_t)TermWin.nrow - 1);
2946 MAX_IT (selection.mark.col, 0); 2965 MAX_IT (selection.mark.col, 0);
2947 MIN_IT (selection.mark.col, (int32_t)TermWin.ncol - 1); 2966 MIN_IT (selection.mark.col, (int32_t)TermWin.ncol - 1);
2948 2967
2968 while (selection.mark.col > 0
2969 && screen.text[selection.mark.row + TermWin.saveLines][selection.mark.col] == NOCHAR)
2970 --selection.mark.col;
2971
2949 if (selection.op) 2972 if (selection.op)
2950 { /* clear the old selection */ 2973 { /* clear the old selection */
2951 selection.beg.row = selection.end.row = selection.mark.row; 2974 selection.beg.row = selection.end.row = selection.mark.row;
2952 selection.beg.col = selection.end.col = selection.mark.col; 2975 selection.beg.col = selection.end.col = selection.mark.col;
2953 } 2976 }
2977
2954 selection.op = SELECTION_INIT; 2978 selection.op = SELECTION_INIT;
2955 selection.screen = current_screen; 2979 selection.screen = current_screen;
2956} 2980}
2957 2981
2958/* ------------------------------------------------------------------------- */ 2982/* ------------------------------------------------------------------------- */
2960 * Word select: select text for 2 clicks 2984 * Word select: select text for 2 clicks
2961 * We now only find out the boundary in one direction 2985 * We now only find out the boundary in one direction
2962 */ 2986 */
2963 2987
2964/* what do we want: spaces/tabs are delimiters or cutchars or non-cutchars */ 2988/* what do we want: spaces/tabs are delimiters or cutchars or non-cutchars */
2965#define DELIMIT_TEXT(x) \ 2989#define DELIMIT_TEXT(x) \
2966 (((x) == ' ' || (x) == '\t') ? 2 : (STRCHR (rs[Rs_cutchars], (x)) != NULL)) 2990 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!STRCHR (rs[Rs_cutchars], (x)))
2967#define DELIMIT_REND(x) 1 2991#define DELIMIT_REND(x) 1
2968 2992
2969void 2993void
2970rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) 2994rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret)
2971{ 2995{
2972 int col, row, dirnadd, tcol, trow, w1, w2; 2996 int col, row, dirnadd, tcol, trow, w1, w2;
2973 row_col_t bound; 2997 row_col_t bound;
2974 text_t *stp; 2998 text_t *stp;
2975 rend_t *srp; 2999 rend_t *srp;
2976 3000
2977 if (dirn == UP) 3001 if (dirn == UP)
2978 { 3002 {
2979 bound.row = TermWin.saveLines - TermWin.nscrolled - 1; 3003 bound.row = TermWin.saveLines - TermWin.nscrolled - 1;
2980 bound.col = 0; 3004 bound.col = 0;
2984 { 3008 {
2985 bound.row = TermWin.saveLines + TermWin.nrow; 3009 bound.row = TermWin.saveLines + TermWin.nrow;
2986 bound.col = TermWin.ncol - 1; 3010 bound.col = TermWin.ncol - 1;
2987 dirnadd = 1; 3011 dirnadd = 1;
2988 } 3012 }
3013
2989 row = mark->row + TermWin.saveLines; 3014 row = mark->row + TermWin.saveLines;
2990 col = mark->col; 3015 col = mark->col;
2991 MAX_IT (col, 0); 3016 MAX_IT (col, 0);
2992 /* find the edge of a word */ 3017 /* find the edge of a word */
2993 stp = & (screen.text[row][col]); 3018 stp = & (screen.text[row][col]);
2994 w1 = DELIMIT_TEXT (*stp); 3019 w1 = DELIMIT_TEXT (*stp);
2995 3020
2996 if (selection_style != NEW_SELECT)
2997 {
2998 if (w1 == 1)
2999 {
3000 stp += dirnadd;
3001 if (DELIMIT_TEXT (*stp) == 1)
3002 goto Old_Word_Selection_You_Die;
3003 col += dirnadd;
3004 }
3005 w1 = 0;
3006 }
3007 srp = (&screen.rend[row][col]); 3021 srp = (&screen.rend[row][col]);
3008 w2 = DELIMIT_REND (*srp); 3022 w2 = DELIMIT_REND (*srp);
3009 3023
3010 for (;;) 3024 for (;;)
3011 { 3025 {
3012 for (; col != bound.col; col += dirnadd) 3026 for (; col != bound.col; col += dirnadd)
3013 { 3027 {
3014 stp += dirnadd; 3028 stp += dirnadd;
3029 srp += dirnadd;
3030
3031 if (*stp == NOCHAR)
3032 continue;
3033
3015 if (DELIMIT_TEXT (*stp) != w1) 3034 if (DELIMIT_TEXT (*stp) != w1)
3016 break; 3035 break;
3017 srp += dirnadd;
3018 if (DELIMIT_REND (*srp) != w2) 3036 if (DELIMIT_REND (*srp) != w2)
3019 break; 3037 break;
3020 } 3038 }
3039
3021 if ((col == bound.col) && (row != bound.row)) 3040 if ((col == bound.col) && (row != bound.row))
3022 { 3041 {
3023 if (screen.tlen[ (row - (dirn == UP ? 1 : 0))] == -1) 3042 if (screen.tlen[ (row - (dirn == UP ? 1 : 0))] == -1)
3024 { 3043 {
3025 trow = row + dirnadd; 3044 trow = row + dirnadd;
3026 tcol = dirn == UP ? TermWin.ncol - 1 : 0; 3045 tcol = dirn == UP ? TermWin.ncol - 1 : 0;
3046
3027 if (screen.text[trow] == NULL) 3047 if (screen.text[trow] == NULL)
3028 break; 3048 break;
3049
3029 stp = & (screen.text[trow][tcol]); 3050 stp = & (screen.text[trow][tcol]);
3030 srp = & (screen.rend[trow][tcol]); 3051 srp = & (screen.rend[trow][tcol]);
3052
3031 if (DELIMIT_TEXT (*stp) != w1 || DELIMIT_REND (*srp) != w2) 3053 if (DELIMIT_TEXT (*stp) != w1 || DELIMIT_REND (*srp) != w2)
3032 break; 3054 break;
3055
3033 row = trow; 3056 row = trow;
3034 col = tcol; 3057 col = tcol;
3035 continue; 3058 continue;
3036 } 3059 }
3037 } 3060 }
3038 break; 3061 break;
3039 } 3062 }
3063
3040Old_Word_Selection_You_Die: 3064Old_Word_Selection_You_Die:
3041 D_SELECT ((stderr, "rxvt_selection_delimit_word (%s,...) @ (r:%3d, c:%3d) has boundary (r:%3d, c:%3d)", (dirn == UP ? "up " : "down"), mark->row, mark->col, row - TermWin.saveLines, col)); 3065 D_SELECT ((stderr, "rxvt_selection_delimit_word (%s,...) @ (r:%3d, c:%3d) has boundary (r:%3d, c:%3d)", (dirn == UP ? "up " : "down"), mark->row, mark->col, row - TermWin.saveLines, col));
3042 3066
3043 if (dirn == DN) 3067 if (dirn == DN)
3044 col++; /* put us on one past the end */ 3068 col++; /* put us on one past the end */
3066 MAX_IT (row, 0); 3090 MAX_IT (row, 0);
3067 MIN_IT (row, (int)TermWin.nrow - 1); 3091 MIN_IT (row, (int)TermWin.nrow - 1);
3068 MAX_IT (col, 0); 3092 MAX_IT (col, 0);
3069 MIN_IT (col, (int)TermWin.ncol); 3093 MIN_IT (col, (int)TermWin.ncol);
3070 3094
3071#ifndef NO_NEW_SELECTION
3072 /* 3095 /*
3073 * If we're selecting characters (single click) then we must check first 3096 * If we're selecting characters (single click) then we must check first
3074 * if we are at the same place as the original mark. If we are then 3097 * if we are at the same place as the original mark. If we are then
3075 * select nothing. Otherwise, if we're to the right of the mark, you have to 3098 * select nothing. Otherwise, if we're to the right of the mark, you have to
3076 * be _past_ a character for it to be selected. 3099 * be _past_ a character for it to be selected.
3077 */ 3100 */
3078 if (selection_style != OLD_SELECT)
3079 {
3080 if (((selection.clicks % 3) == 1) && !flag 3101 if (((selection.clicks % 3) == 1) && !flag
3081 && (col == selection.mark.col 3102 && (col == selection.mark.col
3082 && (row == selection.mark.row + TermWin.view_start))) 3103 && (row == selection.mark.row + TermWin.view_start)))
3083 { 3104 {
3084 /* select nothing */ 3105 /* select nothing */
3085 selection.beg.row = selection.end.row = 0; 3106 selection.beg.row = selection.end.row = 0;
3086 selection.beg.col = selection.end.col = 0; 3107 selection.beg.col = selection.end.col = 0;
3087 selection.clicks = 4; 3108 selection.clicks = 4;
3088 want_refresh = 1; 3109 want_refresh = 1;
3089 D_SELECT ((stderr, "rxvt_selection_extend () selection.clicks = 4")); 3110 D_SELECT ((stderr, "rxvt_selection_extend () selection.clicks = 4"));
3090 return; 3111 return;
3091 }
3092 } 3112 }
3093#endif 3113
3094 if (selection.clicks == 4) 3114 if (selection.clicks == 4)
3095 selection.clicks = 1; 3115 selection.clicks = 1;
3096 3116
3097 selection_extend_colrow (col, row, !!flag, /* ? button 3 */ 3117 selection_extend_colrow (col, row, !!flag, /* ? button 3 */
3098 flag == 1 ? 1 : 0, /* ? button press */ 3118 flag == 1 ? 1 : 0, /* ? button press */
3104 * Extend the selection to the specified col/row 3124 * Extend the selection to the specified col/row
3105 */ 3125 */
3106void 3126void
3107rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) 3127rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange)
3108{ 3128{
3109 int16_t ncol = TermWin.ncol; 3129 int16_t ncol = TermWin.ncol;
3110 int end_col; 3130 int end_col;
3111 row_col_t pos; 3131 row_col_t pos;
3112 enum { 3132 enum {
3113 LEFT, RIGHT 3133 LEFT, RIGHT
3114 } closeto = RIGHT; 3134 } closeto = RIGHT;
3115 3135
3116 D_SELECT ((stderr, "rxvt_selection_extend_colrow (c:%d, r:%d, %d, %d) clicks:%d, op:%d", col, row, button3, buttonpress, selection.clicks, selection.op)); 3136 D_SELECT ((stderr, "rxvt_selection_extend_colrow (c:%d, r:%d, %d, %d) clicks:%d, op:%d", col, row, button3, buttonpress, selection.clicks, selection.op));
3152 pos.col = col; 3172 pos.col = col;
3153 pos.row = row; 3173 pos.row = row;
3154 3174
3155 pos.row -= TermWin.view_start; /* adjust for scroll */ 3175 pos.row -= TermWin.view_start; /* adjust for scroll */
3156 3176
3157#ifndef NO_OLD_SELECTION
3158 /*
3159 * This mimics some of the selection behaviour of version 2.20 and before.
3160 * There are no ``selection modes'', button3 is always character extension.
3161 * Note: button3 drag is always available, c.f. v2.20
3162 * Selection always terminates (left or right as appropriate) at the mark.
3163 */
3164 if (selection_style == OLD_SELECT)
3165 {
3166 if (selection.clicks == 1 || button3)
3167 {
3168 if (hate_those_clicks)
3169 {
3170 hate_those_clicks = 0;
3171 if (selection.clicks == 1)
3172 {
3173 selection.beg.row = selection.mark.row;
3174 selection.beg.col = selection.mark.col;
3175 }
3176 else
3177 {
3178 selection.mark.row = selection.beg.row;
3179 selection.mark.col = selection.beg.col;
3180 }
3181 }
3182 if (ROWCOL_IS_BEFORE (pos, selection.mark))
3183 {
3184 selection.end.row = selection.mark.row;
3185 selection.end.col = selection.mark.col + 1;
3186 selection.beg.row = pos.row;
3187 selection.beg.col = pos.col;
3188 }
3189 else
3190 {
3191 selection.beg.row = selection.mark.row;
3192 selection.beg.col = selection.mark.col;
3193 selection.end.row = pos.row;
3194 selection.end.col = pos.col + 1;
3195 }
3196 }
3197 else if (selection.clicks == 2)
3198 {
3199 selection_delimit_word (UP, & (selection.mark),
3200 & (selection.beg));
3201 selection_delimit_word (DN, & (selection.mark),
3202 & (selection.end));
3203 hate_those_clicks = 1;
3204 }
3205 else if (selection.clicks == 3)
3206 {
3207 selection.beg.row = selection.end.row = selection.mark.row;
3208 selection.beg.col = 0;
3209 selection.end.col = ncol;
3210 hate_those_clicks = 1;
3211 }
3212 D_SELECT ((stderr, "rxvt_selection_extend_colrow () EXIT b: (r:%d,c:%d) m: (r:%d,c:%d), e: (r:%d,c:%d)", selection.beg.row, selection.beg.col, selection.mark.row, selection.mark.col, selection.end.row, selection.end.col));
3213 return;
3214 }
3215#endif /* ! NO_OLD_SELECTION */
3216#ifndef NO_NEW_SELECTION
3217 /* selection_style must not be OLD_SELECT to get here */
3218 /* 3177 /*
3219 * This is mainly xterm style selection with a couple of differences, mainly 3178 * This is mainly xterm style selection with a couple of differences, mainly
3220 * in the way button3 drag extension works. 3179 * in the way button3 drag extension works.
3221 * We're either doing: button1 drag; button3 press; or button3 drag 3180 * We're either doing: button1 drag; button3 press; or button3 drag
3222 * a) button1 drag : select around a midpoint/word/line - that point/word/line 3181 * a) button1 drag : select around a midpoint/word/line - that point/word/line
3227 * a point/word/line which is either the start or end of the selection 3186 * a point/word/line which is either the start or end of the selection
3228 * and it was decided by whichever point/word/line was `fixed' at the 3187 * and it was decided by whichever point/word/line was `fixed' at the
3229 * time of the most recent button3 press 3188 * time of the most recent button3 press
3230 */ 3189 */
3231 if (button3 && buttonpress) 3190 if (button3 && buttonpress)
3232 { /* button3 press */ 3191 { /* button3 press */
3233 /* 3192 /*
3234 * first determine which edge of the selection we are closest to 3193 * first determine which edge of the selection we are closest to
3235 */ 3194 */
3236 if (ROWCOL_IS_BEFORE (pos, selection.beg) 3195 if (ROWCOL_IS_BEFORE (pos, selection.beg)
3237 || (!ROWCOL_IS_AFTER (pos, selection.end) 3196 || (!ROWCOL_IS_AFTER (pos, selection.end)
3238 && (((pos.col - selection.beg.col) 3197 && (((pos.col - selection.beg.col)
3239 + ((pos.row - selection.beg.row) * ncol)) 3198 + ((pos.row - selection.beg.row) * ncol))
3240 < ((selection.end.col - pos.col) 3199 < ((selection.end.col - pos.col)
3241 + ((selection.end.row - pos.row) * ncol))))) 3200 + ((selection.end.row - pos.row) * ncol)))))
3242 closeto = LEFT; 3201 closeto = LEFT;
3202
3243 if (closeto == LEFT) 3203 if (closeto == LEFT)
3244 { 3204 {
3245 selection.beg.row = pos.row; 3205 selection.beg.row = pos.row;
3246 selection.beg.col = pos.col; 3206 selection.beg.col = pos.col;
3247 selection.mark.row = selection.end.row; 3207 selection.mark.row = selection.end.row;
3248 selection.mark.col = selection.end.col 3208 selection.mark.col = selection.end.col - (selection.clicks == 2);
3249 - (selection.clicks == 2);
3250 } 3209 }
3251 else 3210 else
3252 { 3211 {
3253 selection.end.row = pos.row; 3212 selection.end.row = pos.row;
3254 selection.end.col = pos.col; 3213 selection.end.col = pos.col;
3255 selection.mark.row = selection.beg.row; 3214 selection.mark.row = selection.beg.row;
3256 selection.mark.col = selection.beg.col; 3215 selection.mark.col = selection.beg.col;
3257 } 3216 }
3258 } 3217 }
3259 else 3218 else
3260 { /* button1 drag or button3 drag */ 3219 { /* button1 drag or button3 drag */
3261 if (ROWCOL_IS_AFTER (selection.mark, pos)) 3220 if (ROWCOL_IS_AFTER (selection.mark, pos))
3262 { 3221 {
3263 if ((selection.mark.row == selection.end.row) 3222 if ((selection.mark.row == selection.end.row)
3264 && (selection.mark.col == selection.end.col) 3223 && (selection.mark.col == selection.end.col)
3265 && clickchange && selection.clicks == 2) 3224 && clickchange && selection.clicks == 2)
3266 selection.mark.col--; 3225 selection.mark.col--;
3226
3267 selection.beg.row = pos.row; 3227 selection.beg.row = pos.row;
3268 selection.beg.col = pos.col; 3228 selection.beg.col = pos.col;
3269 selection.end.row = selection.mark.row; 3229 selection.end.row = selection.mark.row;
3270 selection.end.col = selection.mark.col 3230 selection.end.col = selection.mark.col + (selection.clicks == 2);
3271 + (selection.clicks == 2);
3272 } 3231 }
3273 else 3232 else
3274 { 3233 {
3275 selection.beg.row = selection.mark.row; 3234 selection.beg.row = selection.mark.row;
3276 selection.beg.col = selection.mark.col; 3235 selection.beg.col = selection.mark.col;
3280 } 3239 }
3281 3240
3282 if (selection.clicks == 1) 3241 if (selection.clicks == 1)
3283 { 3242 {
3284 end_col = screen.tlen[selection.beg.row + TermWin.saveLines]; 3243 end_col = screen.tlen[selection.beg.row + TermWin.saveLines];
3244
3285 if (end_col != -1 && selection.beg.col > end_col) 3245 if (end_col != -1 && selection.beg.col > end_col)
3286 { 3246 {
3287#if 1 3247#if 1
3288 selection.beg.col = ncol; 3248 selection.beg.col = ncol;
3289#else 3249#else
3290 if (selection.beg.row != selection.end.row) 3250 if (selection.beg.row != selection.end.row)
3291 selection.beg.col = ncol; 3251 selection.beg.col = ncol;
3292 else 3252 else
3293 selection.beg.col = selection.mark.col; 3253 selection.beg.col = selection.mark.col;
3294#endif 3254#endif
3295
3296 } 3255 }
3256
3297 end_col = screen.tlen[selection.end.row + TermWin.saveLines]; 3257 end_col = screen.tlen[selection.end.row + TermWin.saveLines];
3258
3298 if (end_col != -1 && selection.end.col > end_col) 3259 if (end_col != -1 && selection.end.col > end_col)
3299 selection.end.col = ncol; 3260 selection.end.col = ncol;
3300
3301 } 3261 }
3302 else if (selection.clicks == 2) 3262 else if (selection.clicks == 2)
3303 { 3263 {
3304 if (ROWCOL_IS_AFTER (selection.end, selection.beg)) 3264 if (ROWCOL_IS_AFTER (selection.end, selection.beg))
3305 selection.end.col--; 3265 selection.end.col--;
3266
3306 selection_delimit_word (UP, & (selection.beg), 3267 selection_delimit_word (UP, & (selection.beg), & (selection.beg));
3307 & (selection.beg));
3308 selection_delimit_word (DN, & (selection.end), 3268 selection_delimit_word (DN, & (selection.end), & (selection.end));
3309 & (selection.end));
3310 } 3269 }
3311 else if (selection.clicks == 3) 3270 else if (selection.clicks == 3)
3312 { 3271 {
3313#ifndef NO_FRILLS 3272#ifndef NO_FRILLS
3314 if ((Options & Opt_tripleclickwords)) 3273 if ((Options & Opt_tripleclickwords))
3315 { 3274 {
3316 int end_row; 3275 int end_row;
3317 3276
3318 selection_delimit_word (UP, & (selection.beg), 3277 selection_delimit_word (UP, & (selection.beg), & (selection.beg));
3319 & (selection.beg));
3320 end_row = screen.tlen[selection.mark.row 3278 end_row = screen.tlen[selection.mark.row + TermWin.saveLines];
3321 + TermWin.saveLines]; 3279
3322 for (end_row = selection.mark.row; end_row < TermWin.nrow; 3280 for (end_row = selection.mark.row; end_row < TermWin.nrow; end_row++)
3323 end_row++)
3324 { 3281 {
3325 end_col = screen.tlen[end_row + TermWin.saveLines]; 3282 end_col = screen.tlen[end_row + TermWin.saveLines];
3283
3326 if (end_col != -1) 3284 if (end_col != -1)
3327 { 3285 {
3328 selection.end.row = end_row; 3286 selection.end.row = end_row;
3329 selection.end.col = end_col; 3287 selection.end.col = end_col;
3330 selection_remove_trailing_spaces (); 3288 selection_remove_trailing_spaces ();
3332 } 3290 }
3333 } 3291 }
3334 } 3292 }
3335 else 3293 else
3336#endif 3294#endif
3337
3338 { 3295 {
3339 if (ROWCOL_IS_AFTER (selection.mark, selection.beg)) 3296 if (ROWCOL_IS_AFTER (selection.mark, selection.beg))
3340 selection.mark.col++; 3297 selection.mark.col++;
3341 selection.beg.col = 0; 3298 selection.beg.col = 0;
3342 selection.end.col = ncol; 3299 selection.end.col = ncol;
3343 } 3300 }
3344 } 3301 }
3302
3345 if (button3 && buttonpress) 3303 if (button3 && buttonpress)
3346 { /* mark may need to be changed */ 3304 { /* mark may need to be changed */
3347 if (closeto == LEFT) 3305 if (closeto == LEFT)
3348 { 3306 {
3349 selection.mark.row = selection.end.row; 3307 selection.mark.row = selection.end.row;
3350 selection.mark.col = selection.end.col 3308 selection.mark.col = selection.end.col
3351 - (selection.clicks == 2); 3309 - (selection.clicks == 2);
3355 selection.mark.row = selection.beg.row; 3313 selection.mark.row = selection.beg.row;
3356 selection.mark.col = selection.beg.col; 3314 selection.mark.col = selection.beg.col;
3357 } 3315 }
3358 } 3316 }
3359 D_SELECT ((stderr, "rxvt_selection_extend_colrow () EXIT b: (r:%d,c:%d) m: (r:%d,c:%d), e: (r:%d,c:%d)", selection.beg.row, selection.beg.col, selection.mark.row, selection.mark.col, selection.end.row, selection.end.col)); 3317 D_SELECT ((stderr, "rxvt_selection_extend_colrow () EXIT b: (r:%d,c:%d) m: (r:%d,c:%d), e: (r:%d,c:%d)", selection.beg.row, selection.beg.col, selection.mark.row, selection.mark.col, selection.end.row, selection.end.col));
3360#endif /* ! NO_NEW_SELECTION */
3361} 3318}
3362 3319
3363#ifndef NO_FRILLS 3320#ifndef NO_FRILLS
3364void 3321void
3365rxvt_term::selection_remove_trailing_spaces () 3322rxvt_term::selection_remove_trailing_spaces ()
3464 /* TODO: Handle MULTIPLE */ 3421 /* TODO: Handle MULTIPLE */
3465 } 3422 }
3466 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3423 else if (rq.target == xa[XA_TIMESTAMP] && selection.text)
3467 { 3424 {
3468 XChangeProperty (display->display, rq.requestor, rq.property, XA_INTEGER, 3425 XChangeProperty (display->display, rq.requestor, rq.property, XA_INTEGER,
3469 (8 * sizeof (Time)), PropModeReplace, 3426 (8 * sizeof (Time)), PropModeReplace,
3470 (unsigned char *)&selection_time, 1); 3427 (unsigned char *)&selection_time, 1);
3471 ev.property = rq.property; 3428 ev.property = rq.property;
3472 } 3429 }
3473 else if (rq.target == XA_STRING 3430 else if (rq.target == XA_STRING
3474 || rq.target == xa[XA_TEXT] 3431 || rq.target == xa[XA_TEXT]
3475 || rq.target == xa[XA_COMPOUND_TEXT] 3432 || rq.target == xa[XA_COMPOUND_TEXT]

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines