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.247 by root, Sun Jan 22 20:39:47 2006 UTC vs.
Revision 1.309 by root, Mon Jul 21 16:51:31 2008 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*---------------------------------------------------------------------------*
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-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
26 26
27#include "../config.h" /* NECESSARY */ 27#include "../config.h" /* NECESSARY */
28#include "rxvt.h" /* NECESSARY */ 28#include "rxvt.h" /* NECESSARY */
29#include "rxvtperl.h" /* NECESSARY */ 29#include "rxvtperl.h" /* NECESSARY */
30 30
31#include <X11/Xmd.h> /* get the typedef for CARD32 */
32
33#include <inttypes.h> 31#include <inttypes.h>
34 32
35#include "salloc.C" // HACK, should be a seperate compile! 33#include "salloc.C" // HACK, should be a seperate compile!
36 34
37inline void fill_text (text_t *start, text_t value, int len) 35static inline void fill_text (text_t *start, text_t value, int len)
38{ 36{
39 while (len--) 37 while (len--)
40 *start++ = value; 38 *start++ = value;
41} 39}
42 40
47 45
48/* ------------------------------------------------------------------------- * 46/* ------------------------------------------------------------------------- *
49 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 47 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
50 * ------------------------------------------------------------------------- */ 48 * ------------------------------------------------------------------------- */
51#define ZERO_SCROLLBACK() \ 49#define ZERO_SCROLLBACK() \
52 if (OPTION (Opt_scrollTtyOutput)) \ 50 if (option (Opt_scrollTtyOutput)) \
53 view_start = 0 51 view_start = 0
54#define CLEAR_SELECTION() \ 52#define CLEAR_SELECTION() \
55 selection.beg.row = selection.beg.col \ 53 selection.beg.row = selection.beg.col \
56 = selection.end.row = selection.end.col = 0 54 = selection.end.row = selection.end.col = 0
57#define CLEAR_ALL_SELECTION() \ 55#define CLEAR_ALL_SELECTION() \
85 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col) 83 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col)
86#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \ 84#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \
87 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col) 85 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col)
88 86
89/* 87/*
90 * CLEAR_ROWS : clear <num> rows starting from row <row>
91 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 88 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
92 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
93 */ 89 */
94#define drawBuffer vt
95
96#define CLEAR_ROWS(row, num) \
97 if (mapped) \
98 XClearArea (display->display, drawBuffer, 0, \
99 Row2Pixel (row), (unsigned int)width, \
100 (unsigned int)Height2Pixel (num), False)
101
102#define CLEAR_CHARS(x, y, num) \ 90#define CLEAR_CHARS(x, y, num) \
103 if (mapped) \ 91 if (mapped) \
104 XClearArea (display->display, drawBuffer, x, y, \ 92 XClearArea (dpy, vt, x, y, \
105 (unsigned int)Width2Pixel (num), \ 93 (unsigned int)Width2Pixel (num), \
106 (unsigned int)Height2Pixel (1), False) 94 (unsigned int)Height2Pixel (1), False)
107
108#define ERASE_ROWS(row, num) \
109 XFillRectangle (display->display, drawBuffer, gc, \
110 0, Row2Pixel (row), \
111 (unsigned int)width, \
112 (unsigned int)Height2Pixel (num))
113 95
114/* ------------------------------------------------------------------------- * 96/* ------------------------------------------------------------------------- *
115 * SCREEN `COMMON' ROUTINES * 97 * SCREEN `COMMON' ROUTINES *
116 * ------------------------------------------------------------------------- */ 98 * ------------------------------------------------------------------------- */
117 99
126 width = ncol; 108 width = ncol;
127 } 109 }
128 110
129 l.touch (); 111 l.touch ();
130 112
131 efs &= ~RS_baseattrMask; 113 efs &= ~RS_baseattrMask; // remove italic etc. fontstyles
132 efs = SET_FONT (efs, FONTSET (efs)->find_font (' ')); 114 efs = SET_FONT (efs, FONTSET (efs)->find_font (' '));
133 115
134 text_t *et = l.t + col; 116 text_t *et = l.t + col;
135 rend_t *er = l.r + col; 117 rend_t *er = l.r + col;
136 118
161{ 143{
162#if ENABLE_OVERLAY 144#if ENABLE_OVERLAY
163 scr_overlay_off (); 145 scr_overlay_off ();
164#endif 146#endif
165 147
148 rvideo_mode = false;
166 view_start = 0; 149 view_start = 0;
167 num_scr = 0; 150 num_scr = 0;
168 151
169 if (ncol == 0) 152 if (ncol == 0)
170 ncol = 80; 153 ncol = 80;
237 selection.text = NULL; 220 selection.text = NULL;
238 selection.len = 0; 221 selection.len = 0;
239 selection.op = SELECTION_CLEAR; 222 selection.op = SELECTION_CLEAR;
240 selection.screen = PRIMARY; 223 selection.screen = PRIMARY;
241 selection.clicks = 0; 224 selection.clicks = 0;
242 rvideo_state = rvideo_mode = false;
243 } 225 }
244 else 226 else
245 { 227 {
246 /* 228 /*
247 * add or delete rows as appropriate 229 * add or delete rows as appropriate
276 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 258 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
277 } 259 }
278 260
279 line_t *old_buf = row_buf; 261 line_t *old_buf = row_buf;
280 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t)); 262 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t));
281 263
282 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 264 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
283 int pend = MOD (term_start + top_row , prev_total_rows); 265 int pend = MOD (term_start + top_row , prev_total_rows);
284 int q = total_rows; // rewrapped row 266 int q = total_rows; // rewrapped row
285 267
286 if (top_row) 268 if (top_row)
330 int qcol = 0; 312 int qcol = 0;
331 313
332 // see below for cursor adjustment rationale 314 // see below for cursor adjustment rationale
333 if (p == ocur.row) 315 if (p == ocur.row)
334 screen.cur.row = q - (total_rows - nrow); 316 screen.cur.row = q - (total_rows - nrow);
335 317
336 // fill a single destination line 318 // fill a single destination line
337 while (lofs < llen && qcol < ncol) 319 while (lofs < llen && qcol < ncol)
338 { 320 {
339 int prow = lofs / prev_ncol; 321 int prow = lofs / prev_ncol;
340 int pcol = lofs % prev_ncol; 322 int pcol = lofs % prev_ncol;
366 } 348 }
367 while (p != pend && q > 0); 349 while (p != pend && q > 0);
368 350
369 term_start = total_rows - nrow; 351 term_start = total_rows - nrow;
370 top_row = q - term_start; 352 top_row = q - term_start;
371 353
372 // make sure all terminal lines exist 354 // make sure all terminal lines exist
373 while (top_row > 0) 355 while (top_row > 0)
374 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE); 356 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
375 } 357 }
376 else 358 else
377 { 359 {
378 // if no scrollback exists (yet), wing, instead of wrap 360 // if no scrollback exists (yet), wing, instead of wrap
379 361
380 for (int row = min (nrow, prev_nrow); row--; ) 362 for (int row = min (nrow, prev_nrow); row--; )
381 { 363 {
382 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; 364 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
383 line_t &qline = row_buf [row]; 365 line_t &qline = row_buf [row];
384 366
407 CLEAR_ALL_SELECTION (); 389 CLEAR_ALL_SELECTION ();
408 390
409 prev_nrow = nrow; 391 prev_nrow = nrow;
410 prev_ncol = ncol; 392 prev_ncol = ncol;
411 393
412 tabs = (char *)rxvt_malloc (ncol * sizeof (char)); 394 tabs = (char *)rxvt_malloc (ncol);
413 395
414 for (int col = ncol; col--; ) 396 for (int col = ncol; --col; )
415 tabs [col] = col % TABSIZE == 0; 397 tabs [col] = col % TABSIZE == 0;
416 398
417 if (current_screen != PRIMARY) 399 if (current_screen != PRIMARY)
418 scr_swap_screen (); 400 scr_swap_screen ();
419 401
510} 492}
511 493
512void 494void
513rxvt_term::scr_swap_screen () 495rxvt_term::scr_swap_screen ()
514{ 496{
515 if (!OPTION (Opt_secondaryScreen)) 497 if (!option (Opt_secondaryScreen))
516 return; 498 return;
517 499
518 for (int i = prev_nrow; i--; ) 500 for (int i = prev_nrow; i--; )
519 ::swap (ROW(i), swap_buf [i]); 501 ::swap (ROW(i), swap_buf [i]);
520 502
542 selection_check (2); /* check for boundary cross */ 524 selection_check (2); /* check for boundary cross */
543 525
544 int i = current_screen; current_screen = scrn; scrn = i; 526 int i = current_screen; current_screen = scrn; scrn = i;
545 527
546#if NSCREENS 528#if NSCREENS
547 if (OPTION (Opt_secondaryScreen)) 529 if (option (Opt_secondaryScreen))
548 { 530 {
549 num_scr = 0; 531 num_scr = 0;
550 532
551 scr_swap_screen (); 533 scr_swap_screen ();
552 534
555 screen.flags |= Screen_VisibleCursor; 537 screen.flags |= Screen_VisibleCursor;
556 swap.flags |= Screen_VisibleCursor; 538 swap.flags |= Screen_VisibleCursor;
557 } 539 }
558 else 540 else
559#endif 541#endif
560 if (OPTION (Opt_secondaryScroll)) 542 if (option (Opt_secondaryScroll))
561 scr_scroll_text (0, prev_nrow - 1, prev_nrow); 543 scr_scroll_text (0, prev_nrow - 1, prev_nrow);
562} 544}
563 545
564// clear WrapNext indicator, solidifying position on next line 546// clear WrapNext indicator, solidifying position on next line
565void 547void
598/* 580/*
599 * Change the rendition style for following text 581 * Change the rendition style for following text
600 */ 582 */
601void 583void
602rxvt_term::scr_rendition (int set, int style) NOTHROW 584rxvt_term::scr_rendition (int set, int style) NOTHROW
603 { 585{
604 if (set) 586 if (set)
605 rstyle |= style; 587 rstyle |= style;
606 else if (style == ~RS_None) 588 else if (style == ~RS_None)
607 rstyle = DEFAULT_RSTYLE; 589 rstyle = DEFAULT_RSTYLE;
608 else 590 else
609 rstyle &= ~style; 591 rstyle &= ~style;
610 } 592}
611 593
612/* ------------------------------------------------------------------------- */ 594/* ------------------------------------------------------------------------- */
613/* 595/*
614 * Scroll text between <row1> and <row2> inclusive, by <count> lines 596 * Scroll text between <row1> and <row2> inclusive, by <count> lines
615 * count positive ==> scroll up 597 * count positive ==> scroll up
624 want_refresh = 1; 606 want_refresh = 1;
625 num_scr += count; 607 num_scr += count;
626 608
627 if (count > 0 609 if (count > 0
628 && row1 == 0 610 && row1 == 0
629 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll))) 611 && (current_screen == PRIMARY || option (Opt_secondaryScroll)))
630 { 612 {
631 top_row = max (top_row - count, -saveLines); 613 top_row = max (top_row - count, -saveLines);
632 614
633 // scroll everything up 'count' lines 615 // scroll everything up 'count' lines
634 term_start = (term_start + count) % total_rows; 616 term_start = (term_start + count) % total_rows;
641 } 623 }
642 624
643 // erase newly scrolled-in lines 625 // erase newly scrolled-in lines
644 for (int i = count; i--; ) 626 for (int i = count; i--; )
645 { 627 {
646 // basically this is a slightly optimized scr_blank_screen_mem
647 // it is worth the effort on slower machines
648 line_t &l = ROW(nrow - 1 - i); 628 line_t &l = ROW(nrow - 1 - i);
649 629
630 // optimize if already cleared, can be significant on slow machines
631 // could be rolled into scr_blank_screen_mem
632 if (l.r && l.l < ncol - 1 && !((l.r[l.l + 1] ^ rstyle) & (RS_fgMask | RS_bgMask)))
633 {
650 scr_blank_line (l, 0, l.l, rstyle); 634 scr_blank_line (l, 0, l.l, rstyle);
651
652 l.l = 0; 635 l.l = 0;
653 l.f = 0; 636 l.f = 0;
637 }
638 else
639 scr_blank_screen_mem (l, rstyle);
654 } 640 }
655 641
656 // now copy lines below the scroll region bottom to the 642 // now copy lines below the scroll region bottom to the
657 // bottom of the screen again, so they look as if they 643 // bottom of the screen again, so they look as if they
658 // hadn't moved. 644 // hadn't moved.
662 line_t &l2 = ROW(i); 648 line_t &l2 = ROW(i);
663 649
664 ::swap (l1, l2); 650 ::swap (l1, l2);
665 l2.touch (); 651 l2.touch ();
666 } 652 }
667 653
668 // move and/or clear selection, if any 654 // move and/or clear selection, if any
669 if (selection.op && current_screen == selection.screen) 655 if (selection.op && current_screen == selection.screen)
670 { 656 {
671 selection.beg.row -= count; 657 selection.beg.row -= count;
672 selection.end.row -= count; 658 selection.end.row -= count;
680 selection.op = SELECTION_CLEAR; 666 selection.op = SELECTION_CLEAR;
681 } 667 }
682 } 668 }
683 669
684 // finally move the view window, if desired 670 // finally move the view window, if desired
685 if (OPTION (Opt_scrollWithBuffer) 671 if (option (Opt_scrollWithBuffer)
686 && view_start != 0 672 && view_start != 0
687 && view_start != -saveLines) 673 && view_start != -saveLines)
688 scr_page (UP, count); 674 scr_page (UP, count);
689 675
690 if (SHOULD_INVOKE (HOOK_SCROLL_BACK)) 676 if (SHOULD_INVOKE (HOOK_SCROLL_BACK))
708 { 694 {
709 /* move selected region too */ 695 /* move selected region too */
710 selection.beg.row -= count; 696 selection.beg.row -= count;
711 selection.end.row -= count; 697 selection.end.row -= count;
712 selection.mark.row -= count; 698 selection.mark.row -= count;
713 699
714 selection_check (0); 700 selection_check (0);
715 } 701 }
716 } 702 }
717 703
718 // use a simple and robust scrolling algorithm, this 704 // use a simple and robust scrolling algorithm, this
758 ZERO_SCROLLBACK (); 744 ZERO_SCROLLBACK ();
759 745
760 if (minlines > 0) 746 if (minlines > 0)
761 { 747 {
762 minlines += screen.cur.row - screen.bscroll; 748 minlines += screen.cur.row - screen.bscroll;
749 min_it (minlines, screen.cur.row - top_row);
763 750
764 if (minlines > 0 751 if (minlines > 0
765 && screen.tscroll == 0 752 && screen.tscroll == 0
766 && screen.bscroll == nrow - 1) 753 && screen.bscroll == nrow - 1)
767 { 754 {
784 771
785 while (str < strend) 772 while (str < strend)
786 { 773 {
787 c = (unicode_t)*str++; // convert to rxvt-unicodes representation 774 c = (unicode_t)*str++; // convert to rxvt-unicodes representation
788 775
789 if (c < 0x20) 776 if (expect_false (c < 0x20))
790 if (c == C0_LF) 777 if (c == C0_LF)
791 { 778 {
792 max_it (line->l, screen.cur.col); 779 max_it (line->l, screen.cur.col);
793 780
794 screen.flags &= ~Screen_WrapNext; 781 screen.flags &= ~Screen_WrapNext;
813 { 800 {
814 scr_tab (1, true); 801 scr_tab (1, true);
815 continue; 802 continue;
816 } 803 }
817 804
805 if (expect_false (
818 if (checksel /* see if we're writing within selection */ 806 checksel /* see if we're writing within selection */
819 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 807 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
820 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 808 && ROWCOL_IS_BEFORE (screen.cur, selection.end)
809 ))
821 { 810 {
822 checksel = 0; 811 checksel = 0;
823 /* 812 /*
824 * If we wrote anywhere in the selected area, kill the selection 813 * If we wrote anywhere in the selected area, kill the selection
825 * XXX: should we kill the mark too? Possibly, but maybe that 814 * XXX: should we kill the mark too? Possibly, but maybe that
826 * should be a similar check. 815 * should be a similar check.
827 */ 816 */
828 CLEAR_SELECTION (); 817 CLEAR_SELECTION ();
829 } 818 }
830 819
831 if (screen.flags & Screen_WrapNext) 820 if (expect_false (screen.flags & Screen_WrapNext))
832 { 821 {
833 scr_do_wrap (); 822 scr_do_wrap ();
834 823
835 line->l = ncol; 824 line->l = ncol;
836 line->is_longer (1); 825 line->is_longer (1);
837 826
838 row = screen.cur.row; 827 row = screen.cur.row;
839 line = &ROW(row); /* _must_ refresh */ 828 line = &ROW(row); /* _must_ refresh */
840 } 829 }
841 830
842 // some utf-8 decoders "decode" surrogate characters: let's fix this. 831 // some utf-8 decoders "decode" surrogate characters: let's fix this.
843 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 832 if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff)))
844 c = 0xfffd; 833 c = 0xfffd;
845 834
846 // rely on wcwidth to tell us the character width, at least for non-latin1 835 // rely on wcwidth to tell us the character width, do wcwidth before
847 // do wcwidth before further replacements, as wcwidth might return -1 836 // further replacements, as wcwidth might return -1 for the line
848 // for the line drawing characters below as they might be invalid in the current 837 // drawing characters below as they might be invalid in the current
849 // locale. 838 // locale.
850 int width = c < 0x100 ? 1 : wcwidth (c); 839 int width = WCWIDTH (c);
851 840
852 if (charsets [screen.charset] == '0') // DEC SPECIAL 841 if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL
853 { 842 {
854 // vt100 special graphics and line drawing 843 // vt100 special graphics and line drawing
855 // 5f-7e standard vt100 844 // 5f-7e standard vt100
856 // 40-5e rxvt extension for extra curses acs chars 845 // 40-5e rxvt extension for extra curses acs chars
857 static uint16_t vt100_0[62] = { // 41 .. 7e 846 static uint16_t vt100_0[62] = { // 41 .. 7e
870 c = vt100_0[c - 0x41]; 859 c = vt100_0[c - 0x41];
871 width = 1; // vt100 line drawing characters are always single-width 860 width = 1; // vt100 line drawing characters are always single-width
872 } 861 }
873 } 862 }
874 863
875 if (screen.flags & Screen_Insert) 864 if (expect_false (screen.flags & Screen_Insert))
876 scr_insdel_chars (width, INSERT); 865 scr_insdel_chars (width, INSERT);
877 866
878 if (width != 0) 867 if (width != 0)
879 { 868 {
880#if !UNICODE_3 869#if !UNICODE_3
886 c = 0xfffd; 875 c = 0xfffd;
887# endif 876# endif
888#endif 877#endif
889 878
890 // nuke the character at this position, if required 879 // nuke the character at this position, if required
880 if (expect_false (
891 if (line->t[screen.cur.col] == NOCHAR 881 line->t[screen.cur.col] == NOCHAR
892 || (screen.cur.col < ncol - 1 882 || (screen.cur.col < ncol - 1
893 && line->t[screen.cur.col + 1] == NOCHAR)) 883 && line->t[screen.cur.col + 1] == NOCHAR)
884 ))
894 { 885 {
895 int col = screen.cur.col; 886 int col = screen.cur.col;
896 887
897 // find begin 888 // find begin
898 while (col > 0 && line->t[col] == NOCHAR) 889 while (col > 0 && line->t[col] == NOCHAR)
909 } 900 }
910 901
911 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); 902 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
912 903
913 // if the character doesn't fit into the remaining columns... 904 // if the character doesn't fit into the remaining columns...
914 if (screen.cur.col > ncol - width && ncol >= width) 905 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
915 { 906 {
916 // ...output spaces 907 // ...output spaces
917 c = ' '; 908 c = ' ';
918 // and try the same character next loop iteration 909 // and try the same character next loop iteration
919 --str; 910 --str;
924 do 915 do
925 { 916 {
926 line->t[screen.cur.col] = c; 917 line->t[screen.cur.col] = c;
927 line->r[screen.cur.col] = rend; 918 line->r[screen.cur.col] = rend;
928 919
929 if (screen.cur.col < ncol - 1) 920 if (expect_true (screen.cur.col < ncol - 1))
930 screen.cur.col++; 921 screen.cur.col++;
931 else 922 else
932 { 923 {
933 line->l = ncol; 924 line->l = ncol;
934 if (screen.flags & Screen_Autowrap) 925 if (screen.flags & Screen_Autowrap)
936 break; 927 break;
937 } 928 }
938 929
939 c = NOCHAR; 930 c = NOCHAR;
940 } 931 }
941 while (--width > 0); 932 while (expect_false (--width > 0));
942 933
943 // pad with spaces when overwriting wide character with smaller one 934 // pad with spaces when overwriting wide character with smaller one
944 if (!width) 935 if (expect_false (!width))
945 { 936 {
946 line->touch (); 937 line->touch ();
947 938
948 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) 939 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
949 { 940 {
950 line->t[c] = ' '; 941 line->t[c] = ' ';
951 line->r[c] = rend; 942 line->r[c] = rend;
952 } 943 }
953 } 944 }
954 } 945 }
946#if ENABLE_COMBINING
955 else // width == 0 947 else // width == 0
956 { 948 {
957#if ENABLE_COMBINING 949 if (c != 0xfeff) // ignore BOM
958 // handle combining characters
959 // we just tag the accent on the previous on-screen character.
960 // this is arguably not correct, but also arguably not wrong.
961 // we don't handle double-width characters nicely yet.
962 line_t *linep;
963 text_t *tp;
964 rend_t *rp;
965
966 if (screen.cur.col > 0)
967 { 950 {
951 // handle combining characters
952 // we just tag the accent on the previous on-screen character.
953 // this is arguably not correct, but also arguably not wrong.
954 // we don't handle double-width characters nicely yet.
955 line_t *linep;
956 text_t *tp;
957 rend_t *rp;
958
959 if (screen.cur.col > 0)
960 {
968 linep = line; 961 linep = line;
969 tp = line->t + screen.cur.col - 1; 962 tp = line->t + screen.cur.col - 1;
970 rp = line->r + screen.cur.col - 1; 963 rp = line->r + screen.cur.col - 1;
964 }
965 else if (screen.cur.row > 0
966 && ROW(screen.cur.row - 1).is_longer ())
967 {
968 linep = &ROW(screen.cur.row - 1);
969 tp = line->t + ncol - 1;
970 rp = line->r + ncol - 1;
971 }
972 else
973 continue;
974
975 linep->touch ();
976
977 while (*tp == NOCHAR && tp > linep->t)
978 tp--, rp--;
979
980 // first try to find a precomposed character
981 unicode_t n = rxvt_compose (*tp, c);
982 if (n == NOCHAR)
983 n = rxvt_composite.compose (*tp, c);
984
985 *tp = n;
986 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
971 } 987 }
972 else if (screen.cur.row > 0
973 && ROW(screen.cur.row - 1).is_longer ())
974 {
975 linep = &ROW(screen.cur.row - 1);
976 tp = line->t + ncol - 1;
977 rp = line->r + ncol - 1;
978 } 988 }
979 else
980 continue;
981
982 linep->touch ();
983
984 while (*tp == NOCHAR && tp > linep->t)
985 tp--, rp--;
986
987 // first try to find a precomposed character
988 unicode_t n = rxvt_compose (*tp, c);
989 if (n == NOCHAR)
990 n = rxvt_composite.compose (*tp, c);
991
992 *tp = n;
993 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
994#endif 989#endif
995 }
996 } 990 }
997 991
998 max_it (line->l, screen.cur.col); 992 max_it (line->l, screen.cur.col);
999 993
1000#ifdef DEBUG_STRICT 994#ifdef DEBUG_STRICT
1008 * XTERM_SEQ: CTRL-H 1002 * XTERM_SEQ: CTRL-H
1009 */ 1003 */
1010void 1004void
1011rxvt_term::scr_backspace () NOTHROW 1005rxvt_term::scr_backspace () NOTHROW
1012{ 1006{
1013 want_refresh = 1;
1014
1015 if (screen.cur.col == 0) 1007 if (screen.cur.col == 0)
1016 { 1008 {
1017 if (screen.cur.row > 0) 1009 if (screen.cur.row > 0)
1018 { 1010 {
1019#ifdef TERMCAP_HAS_BW 1011#ifdef TERMCAP_HAS_BW
1020 screen.cur.col = ncol - 1; 1012 screen.cur.col = ncol - 1;
1021 screen.cur.row--; 1013 --screen.cur.row;
1022 return; 1014
1015 want_refresh = 1;
1023#endif 1016#endif
1024 } 1017 }
1025 } 1018 }
1026 else if (!(screen.flags & Screen_WrapNext)) 1019 else
1027 scr_gotorc (0, -1, RELATIVE); 1020 scr_gotorc (0, -1, RELATIVE);
1028
1029 screen.flags &= ~Screen_WrapNext;
1030} 1021}
1031 1022
1032/* ------------------------------------------------------------------------- */ 1023/* ------------------------------------------------------------------------- */
1033/* 1024/*
1034 * Process Horizontal Tab 1025 * Process Horizontal Tab
1057 x = i; 1048 x = i;
1058 1049
1059 if (!--count) 1050 if (!--count)
1060 break; 1051 break;
1061 } 1052 }
1062 else 1053 else
1063 ht &= l.t[i] == ' ' 1054 ht &= l.t[i] == ' '
1064 && RS_SAME (l.r[i], base_rend); 1055 && RS_SAME (l.r[i], base_rend);
1065 1056
1066 if (count) 1057 if (count)
1067 x = ncol - 1; 1058 x = ncol - 1;
1068 1059
1069 // store horizontal tab commands as characters inside the text 1060 // store horizontal tab commands as characters inside the text
1070 // buffer so they can be selected and pasted. 1061 // buffer so they can be selected and pasted.
1071 if (ht && OPTION (Opt_pastableTabs)) 1062 if (ht && option (Opt_pastableTabs))
1072 { 1063 {
1073 base_rend = SET_FONT (base_rend, 0); 1064 base_rend = SET_FONT (base_rend, 0);
1074 1065
1075 l.touch (x); 1066 l.touch (x);
1076 1067
1109 * Process DEC Back Index 1100 * Process DEC Back Index
1110 * XTERM_SEQ: ESC 6 1101 * XTERM_SEQ: ESC 6
1111 * Move cursor left in row. If we're at the left boundary, shift everything 1102 * Move cursor left in row. If we're at the left boundary, shift everything
1112 * in that row right. Clear left column. 1103 * in that row right. Clear left column.
1113 */ 1104 */
1114#if ENABLE_FRILLS 1105#if !ENABLE_MINIMAL
1115void 1106void
1116rxvt_term::scr_backindex () NOTHROW 1107rxvt_term::scr_backindex () NOTHROW
1117{ 1108{
1118 if (screen.cur.col > 0) 1109 if (screen.cur.col > 0)
1119 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE); 1110 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
1126 * Process DEC Forward Index 1117 * Process DEC Forward Index
1127 * XTERM_SEQ: ESC 9 1118 * XTERM_SEQ: ESC 9
1128 * Move cursor right in row. If we're at the right boundary, shift everything 1119 * Move cursor right in row. If we're at the right boundary, shift everything
1129 * in that row left. Clear right column. 1120 * in that row left. Clear right column.
1130 */ 1121 */
1131#if ENABLE_FRILLS 1122#if !ENABLE_MINIMAL
1132void 1123void
1133rxvt_term::scr_forwardindex () NOTHROW 1124rxvt_term::scr_forwardindex () NOTHROW
1134{ 1125{
1135 if (screen.cur.col < ncol - 1) 1126 if (screen.cur.col < ncol - 1)
1136 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1127 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1183 } 1174 }
1184 } 1175 }
1185 else 1176 else
1186 { 1177 {
1187 if (screen.flags & Screen_Relative) 1178 if (screen.flags & Screen_Relative)
1179 {
1188 { /* relative origin mode */ 1180 /* relative origin mode */
1189 screen.cur.row = row + screen.tscroll; 1181 screen.cur.row = row + screen.tscroll;
1190 min_it (screen.cur.row, screen.bscroll); 1182 min_it (screen.cur.row, screen.bscroll);
1191 } 1183 }
1192 else 1184 else
1193 screen.cur.row = row; 1185 screen.cur.row = row;
1226/* 1218/*
1227 * Erase part or whole of a line 1219 * Erase part or whole of a line
1228 * XTERM_SEQ: Clear line to right: ESC [ 0 K 1220 * XTERM_SEQ: Clear line to right: ESC [ 0 K
1229 * XTERM_SEQ: Clear line to left : ESC [ 1 K 1221 * XTERM_SEQ: Clear line to left : ESC [ 1 K
1230 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1222 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1223 * extension: clear to right unless wrapped: ESC [ 3 K
1231 */ 1224 */
1232void 1225void
1233rxvt_term::scr_erase_line (int mode) NOTHROW 1226rxvt_term::scr_erase_line (int mode) NOTHROW
1234{ 1227{
1235 unsigned int col, num; 1228 unsigned int col, num;
1244 line.touch (); 1237 line.touch ();
1245 line.is_longer (0); 1238 line.is_longer (0);
1246 1239
1247 switch (mode) 1240 switch (mode)
1248 { 1241 {
1242 case 3:
1243 if (screen.flags & Screen_WrapNext)
1244 return;
1245
1246 /* fall through */
1247
1249 case 0: /* erase to end of line */ 1248 case 0: /* erase to end of line */
1250 col = screen.cur.col; 1249 col = screen.cur.col;
1251 num = ncol - col; 1250 num = ncol - col;
1252 min_it (line.l, col); 1251 min_it (line.l, col);
1252
1253 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1253 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1254 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1254 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1255 CLEAR_SELECTION (); 1255 CLEAR_SELECTION ();
1256 break; 1256 break;
1257
1257 case 1: /* erase to beginning of line */ 1258 case 1: /* erase to beginning of line */
1258 col = 0; 1259 col = 0;
1259 num = screen.cur.col + 1; 1260 num = screen.cur.col + 1;
1261
1260 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur) 1262 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur)
1261 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur)) 1263 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur))
1262 CLEAR_SELECTION (); 1264 CLEAR_SELECTION ();
1263 break; 1265 break;
1266
1264 case 2: /* erase whole line */ 1267 case 2: /* erase whole line */
1265 col = 0; 1268 col = 0;
1266 num = ncol; 1269 num = ncol;
1267 line.l = 0; 1270 line.l = 0;
1268 if (selection.beg.row <= screen.cur.row 1271 if (selection.beg.row <= screen.cur.row
1326 if (row >= nrow) /* Out Of Bounds */ 1329 if (row >= nrow) /* Out Of Bounds */
1327 return; 1330 return;
1328 1331
1329 min_it (num, nrow - row); 1332 min_it (num, nrow - row);
1330 1333
1334 /*TODO: the xlceararea/xfillrectangle below don't take scroll offste into account, ask mikachu for details */
1331 if (rstyle & (RS_RVid | RS_Uline)) 1335 if (rstyle & (RS_RVid | RS_Uline))
1332 ren = (rend_t) ~RS_None; 1336 ren = (rend_t) ~RS_None;
1333 else if (GET_BASEBG (rstyle) == Color_bg) 1337 else if (GET_BASEBG (rstyle) == Color_bg)
1334 { 1338 {
1335 ren = DEFAULT_RSTYLE; 1339 ren = DEFAULT_RSTYLE;
1336 CLEAR_ROWS (row, num); 1340
1341 if (mapped)
1342 XClearArea (dpy, vt, 0,
1343 Row2Pixel (row), (unsigned int)width,
1344 (unsigned int)Height2Pixel (num), False);
1337 } 1345 }
1338 else 1346 else
1339 { 1347 {
1340 ren = rstyle & (RS_fgMask | RS_bgMask); 1348 ren = rstyle & (RS_fgMask | RS_bgMask);
1349
1341 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1350 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1342 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1351 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1343 ERASE_ROWS (row, num); 1352 XFillRectangle (dpy, vt, gc,
1353 0, Row2Pixel (row),
1354 (unsigned int)width,
1355 (unsigned int)Height2Pixel (num));
1344 gcvalue.foreground = pix_colors[Color_fg]; 1356 gcvalue.foreground = pix_colors[Color_fg];
1345 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1357 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1346 } 1358 }
1347 1359
1348 for (; num--; row++) 1360 for (; num--; row++)
1349 { 1361 {
1350 scr_blank_screen_mem (ROW(row), rstyle); 1362 scr_blank_screen_mem (ROW(row), rstyle);
1351 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1363 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1352 } 1364 }
1353} 1365}
1354 1366
1355#if ENABLE_FRILLS 1367#if !ENABLE_MINIMAL
1356void 1368void
1357rxvt_term::scr_erase_savelines () NOTHROW 1369rxvt_term::scr_erase_savelines () NOTHROW
1358{ 1370{
1359 want_refresh = 1; 1371 want_refresh = 1;
1360 ZERO_SCROLLBACK (); 1372 ZERO_SCROLLBACK ();
1469 { 1481 {
1470 if (selection.end.row != screen.cur.row 1482 if (selection.end.row != screen.cur.row
1471 || (selection.end.col + count >= ncol)) 1483 || (selection.end.col + count >= ncol))
1472 CLEAR_SELECTION (); 1484 CLEAR_SELECTION ();
1473 else 1485 else
1486 {
1474 { /* shift selection */ 1487 /* shift selection */
1475 selection.beg.col += count; 1488 selection.beg.col += count;
1476 selection.mark.col += count; /* XXX: yes? */ 1489 selection.mark.col += count; /* XXX: yes? */
1477 selection.end.col += count; 1490 selection.end.col += count;
1478 } 1491 }
1479 } 1492 }
1618 */ 1631 */
1619void 1632void
1620rxvt_term::scr_set_tab (int mode) NOTHROW 1633rxvt_term::scr_set_tab (int mode) NOTHROW
1621{ 1634{
1622 if (mode < 0) 1635 if (mode < 0)
1623 memset (tabs, 0, ncol * sizeof (char)); 1636 memset (tabs, 0, ncol);
1624 else if (screen.cur.col < ncol) 1637 else if (screen.cur.col < ncol)
1625 tabs [screen.cur.col] = !!mode; 1638 tabs [screen.cur.col] = !!mode;
1626} 1639}
1627 1640
1628/* ------------------------------------------------------------------------- */ 1641/* ------------------------------------------------------------------------- */
1643 if (rvideo_state != on) 1656 if (rvideo_state != on)
1644 { 1657 {
1645 rvideo_state = on; 1658 rvideo_state = on;
1646 1659
1647 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1660 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1648#if XPM_BACKGROUND 1661#ifdef HAVE_BG_PIXMAP
1649 if (bgPixmap.pixmap == None) 1662 if (bgPixmap.pixmap == None)
1650#endif 1663#endif
1651#if TRANSPARENT
1652 if (!OPTION (Opt_transparent) || am_transparent == 0)
1653#endif
1654 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); 1664 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
1655 1665
1656 XGCValues gcvalue; 1666 XGCValues gcvalue;
1657 gcvalue.foreground = pix_colors[Color_fg]; 1667 gcvalue.foreground = pix_colors[Color_fg];
1658 gcvalue.background = pix_colors[Color_bg]; 1668 gcvalue.background = pix_colors[Color_bg];
1659 XChangeGC (display->display, gc, GCBackground | GCForeground, &gcvalue); 1669 XChangeGC (dpy, gc, GCBackground | GCForeground, &gcvalue);
1660 1670
1661 scr_clear (); 1671 scr_clear ();
1662 scr_touch (true); 1672 scr_touch (true);
1663 } 1673 }
1664} 1674}
1749{ 1759{
1750 bool found = false; 1760 bool found = false;
1751 1761
1752 for (int i = 0; i < nrow; i++) 1762 for (int i = 0; i < nrow; i++)
1753 { 1763 {
1754 int col = 0;
1755 rend_t *drp = drawn_buf[i].r; 1764 rend_t *drp = drawn_buf[i].r;
1756 1765
1757 for (; col < ncol; col++, drp++) 1766 for (int col = 0; col < ncol; col++, drp++)
1758 if ((*drp & mask) == value) 1767 if ((*drp & mask) == value)
1759 { 1768 {
1760 found = true; 1769 found = true;
1761 *drp = ~value; 1770 *drp = ~value;
1762 } 1771 }
1802 for (i = PART_BEG; i < RC_COUNT; i++) 1811 for (i = PART_BEG; i < RC_COUNT; i++)
1803 { 1812 {
1804 min_it (rc[i].col, ncol - 1); 1813 min_it (rc[i].col, ncol - 1);
1805 min_it (rc[i].row, nrow - 1); 1814 min_it (rc[i].row, nrow - 1);
1806 } 1815 }
1807 1816// TODO: this line somehow causes segfault if scr_expose() is called just after resize
1808 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1817 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1809 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); 1818 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1);
1810 1819
1811 num_scr_allow = 0; 1820 num_scr_allow = 0;
1812 1821
1867 return true; 1876 return true;
1868} 1877}
1869 1878
1870#ifndef NO_BELL 1879#ifndef NO_BELL
1871void 1880void
1872rxvt_term::bell_cb (time_watcher &w) 1881rxvt_term::bell_cb (ev::timer &w, int revents)
1873{ 1882{
1874 rvideo_bell = false; 1883 rvideo_bell = false;
1875 scr_rvideo_mode (rvideo_mode); 1884 scr_rvideo_mode (rvideo_mode);
1885 refresh_check ();
1876} 1886}
1877#endif 1887#endif
1878 1888
1879/* ------------------------------------------------------------------------- */ 1889/* ------------------------------------------------------------------------- */
1880void 1890void
1882{ 1892{
1883#ifndef NO_BELL 1893#ifndef NO_BELL
1884 1894
1885# ifndef NO_MAPALERT 1895# ifndef NO_MAPALERT
1886# ifdef MAPALERT_OPTION 1896# ifdef MAPALERT_OPTION
1887 if (OPTION (Opt_mapAlert)) 1897 if (option (Opt_mapAlert))
1888# endif 1898# endif
1889 XMapWindow (display->display, parent[0]); 1899 XMapWindow (dpy, parent[0]);
1890# endif 1900# endif
1891 1901
1902# if ENABLE_FRILLS
1903 if (option (Opt_urgentOnBell))
1904 {
1905 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1906 {
1907 h->flags |= XUrgencyHint;
1908 XSetWMHints (dpy, parent[0], h);
1909 }
1910 }
1911# endif
1912
1892 if (OPTION (Opt_visualBell)) 1913 if (option (Opt_visualBell))
1893 { 1914 {
1894 rvideo_bell = true; 1915 rvideo_bell = true;
1895 scr_rvideo_mode (rvideo_mode); 1916 scr_rvideo_mode (rvideo_mode);
1896 display->flush (); 1917 flush ();
1897 1918
1898 bell_ev.start (NOW + VISUAL_BELL_DURATION); 1919 bell_ev.start (VISUAL_BELL_DURATION);
1899 } 1920 }
1900 else 1921 else
1901 XBell (display->display, 0); 1922 XBell (dpy, 0);
1902
1903#endif 1923#endif
1904} 1924}
1905 1925
1906/* ------------------------------------------------------------------------- */ 1926/* ------------------------------------------------------------------------- */
1907/* ARGSUSED */ 1927/* ARGSUSED */
1908void 1928void
1909rxvt_term::scr_printscreen (int fullhist) NOTHROW 1929rxvt_term::scr_printscreen (int fullhist) NOTHROW
1910{ 1930{
1911#ifdef PRINTPIPE 1931#ifdef PRINTPIPE
1912 int nrows, row_start; 1932 int nrows, row_start;
1913 FILE *fd; 1933 FILE *fd = popen_printer ();
1914 1934
1915 if ((fd = popen_printer ()) == NULL) 1935 if (!fd)
1916 return; 1936 return;
1917 1937
1918 if (fullhist) 1938 if (fullhist)
1919 { 1939 {
1920 nrows = nrow - top_row; 1940 nrows = nrow - top_row;
1965 * screen.text/screen.rend contain what the screen will change to. 1985 * screen.text/screen.rend contain what the screen will change to.
1966 */ 1986 */
1967void 1987void
1968rxvt_term::scr_refresh () NOTHROW 1988rxvt_term::scr_refresh () NOTHROW
1969{ 1989{
1970 unsigned char must_clear, /* use draw_string not draw_image_string */ 1990 unsigned char have_bg,
1971 showcursor; /* show the cursor */ 1991 showcursor; /* show the cursor */
1972 int16_t col, row, /* column/row we're processing */ 1992 int16_t col, row, /* column/row we're processing */
1973 ocrow; /* old cursor row */ 1993 ocrow; /* old cursor row */
1974 int i; /* tmp */ 1994 int i; /* tmp */
1975#ifndef NO_CURSORCOLOR 1995#ifndef NO_CURSORCOLOR
1976 rend_t cc1; /* store colours at cursor position (s) */ 1996 rend_t cc1; /* store colours at cursor position (s) */
1977#endif 1997#endif
1978 rend_t *crp; // cursor rendition pointer 1998 rend_t *crp; // cursor rendition pointer
1999 rend_t ccol1, /* Cursor colour */
2000 ccol2; /* Cursor colour2 */
1979 2001
1980 want_refresh = 0; /* screen is current */ 2002 want_refresh = 0; /* screen is current */
1981 2003
1982 if (refresh_type == NO_REFRESH || !mapped) 2004 if (refresh_type == NO_REFRESH || !mapped)
1983 return; 2005 return;
1984 2006
1985 /* 2007 /*
1986 * A: set up vars 2008 * A: set up vars
1987 */ 2009 */
1988 must_clear = 0;
1989 refresh_count = 0; 2010 refresh_count = 0;
1990 2011
1991#if XPM_BACKGROUND 2012 have_bg = 0;
2013#ifdef HAVE_BG_PIXMAP
1992 must_clear |= bgPixmap.pixmap != None; 2014 have_bg = bgPixmap.pixmap != None;
1993#endif
1994#if TRANSPARENT
1995 must_clear |= OPTION (Opt_transparent) && am_transparent;
1996#endif 2015#endif
1997 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2016 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1998 2017
1999 /* 2018 /*
2000 * B: reverse any characters which are selected 2019 * B: reverse any characters which are selected
2004 /* 2023 /*
2005 * C: set the cursor character (s) 2024 * C: set the cursor character (s)
2006 */ 2025 */
2007 { 2026 {
2008 unsigned char setoldcursor; 2027 unsigned char setoldcursor;
2009 rend_t ccol1, /* Cursor colour */
2010 ccol2; /* Cursor colour2 */
2011 2028
2012 showcursor = (screen.flags & Screen_VisibleCursor); 2029 showcursor = (screen.flags & Screen_VisibleCursor);
2013#ifdef CURSOR_BLINK 2030#ifdef CURSOR_BLINK
2014 if (hidden_cursor) 2031 if (hidden_cursor)
2015 showcursor = 0; 2032 showcursor = 0;
2022 while (col && ROW(screen.cur.row).t[col] == NOCHAR) 2039 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
2023 col--; 2040 col--;
2024 2041
2025 crp = &ROW(screen.cur.row).r[col]; 2042 crp = &ROW(screen.cur.row).r[col];
2026 2043
2044#ifndef NO_CURSORCOLOR
2045 cc1 = *crp & (RS_fgMask | RS_bgMask);
2046 if (ISSET_PIXCOLOR (Color_cursor))
2047 ccol1 = Color_cursor;
2048 else
2049#endif
2050#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2051 ccol1 = fgcolor_of (rstyle);
2052#else
2053 ccol1 = Color_fg;
2054#endif
2055
2056#ifndef NO_CURSORCOLOR
2057 if (ISSET_PIXCOLOR (Color_cursor2))
2058 ccol2 = Color_cursor2;
2059 else
2060#endif
2061#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2062 ccol2 = bgcolor_of (rstyle);
2063#else
2064 ccol2 = Color_bg;
2065#endif
2066
2027 if (showcursor && focus) 2067 if (showcursor && focus)
2028 { 2068 {
2029 if (OPTION (Opt_cursorUnderline)) 2069 if (option (Opt_cursorUnderline))
2030 *crp ^= RS_Uline; 2070 *crp ^= RS_Uline;
2031 else 2071 else
2032 { 2072 {
2033 *crp ^= RS_RVid; 2073 *crp ^= RS_RVid;
2034
2035#ifndef NO_CURSORCOLOR
2036 cc1 = *crp & (RS_fgMask | RS_bgMask);
2037 if (ISSET_PIXCOLOR (Color_cursor))
2038 ccol1 = Color_cursor;
2039 else
2040#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2041 ccol1 = fgcolor_of (rstyle);
2042#else
2043 ccol1 = Color_fg;
2044#endif
2045 if (ISSET_PIXCOLOR (Color_cursor2))
2046 ccol2 = Color_cursor2;
2047 else
2048#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2049 ccol2 = bgcolor_of (rstyle);
2050#else
2051 ccol2 = Color_bg;
2052#endif
2053 *crp = SET_FGCOLOR (*crp, ccol1); 2074 *crp = SET_FGCOLOR (*crp, ccol1);
2054 *crp = SET_BGCOLOR (*crp, ccol2); 2075 *crp = SET_BGCOLOR (*crp, ccol2);
2055#endif
2056 } 2076 }
2057 } 2077 }
2058 } 2078 }
2059 2079
2060 /* make sure no outline cursor is left around */ 2080 /* make sure no outline cursor is left around */
2099 * D: CopyArea pass - very useful for slower links 2119 * D: CopyArea pass - very useful for slower links
2100 * This has been deliberately kept simple. 2120 * This has been deliberately kept simple.
2101 */ 2121 */
2102 if (!display->is_local 2122 if (!display->is_local
2103 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr 2123 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr
2104 && abs (num_scr) < nrow && !must_clear) 2124 && abs (num_scr) < nrow && !have_bg)
2105 { 2125 {
2106 int16_t nits; 2126 int16_t nits;
2127 int i = num_scr;
2107 int j; 2128 int j;
2108 int len, wlen; 2129 int len, wlen;
2109 dLocal (int, num_scr); 2130 dLocal (int, num_scr);
2110 2131
2111 j = nrow; 2132 j = nrow;
2112 wlen = len = -1; 2133 wlen = len = -1;
2113 row = i > 0 ? 0 : j - 1; 2134 row = i > 0 ? 0 : j - 1;
2135
2114 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2136 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2115 { 2137 {
2116 if (row + i >= 0 && row + i < nrow && row + i != ocrow) 2138 if (row + i >= 0 && row + i < nrow && row + i != ocrow)
2117 { 2139 {
2118 line_t s = ROW(view_start + row); 2140 line_t s = ROW(view_start + row);
2139 wlen = row; 2161 wlen = row;
2140 continue; 2162 continue;
2141 } 2163 }
2142 } 2164 }
2143 2165
2144 if (len != -1) 2166 if (len >= 0)
2145 { 2167 {
2146 /* also comes here at end if needed because of >= above */ 2168 /* also comes here at end if needed because of >= above */
2147 if (wlen < len) 2169 if (wlen < len)
2148 ::swap (wlen, len); 2170 ::swap (wlen, len);
2149 2171
2172 XGCValues gcv;
2173
2174 gcv.graphics_exposures = 1; XChangeGC (dpy, gc, GCGraphicsExposures, &gcv);
2150 XCopyArea (display->display, vt, vt, 2175 XCopyArea (dpy, vt, vt,
2151 gc, 0, Row2Pixel (len + i), 2176 gc, 0, Row2Pixel (len + i),
2152 (unsigned int)this->width, 2177 (unsigned int)this->width,
2153 (unsigned int)Height2Pixel (wlen - len + 1), 2178 (unsigned int)Height2Pixel (wlen - len + 1),
2154 0, Row2Pixel (len)); 2179 0, Row2Pixel (len));
2180 gcv.graphics_exposures = 0; XChangeGC (dpy, gc, GCGraphicsExposures, &gcv);
2181
2155 len = -1; 2182 len = -1;
2156 } 2183 }
2157 } 2184 }
2158 } 2185 }
2159#endif 2186#endif
2215 count++; 2242 count++;
2216 2243
2217 if (stp[col] != dtp[col] 2244 if (stp[col] != dtp[col]
2218 || !RS_SAME (srp[col], drp[col])) 2245 || !RS_SAME (srp[col], drp[col]))
2219 { 2246 {
2220 if (must_clear && (i++ > count / 2)) 2247 if (have_bg && (i++ > count / 2))
2221 break; 2248 break;
2222 2249
2223 dtp[col] = stp[col]; 2250 dtp[col] = stp[col];
2224 drp[col] = rend; 2251 drp[col] = rend;
2225 i = 0; 2252 i = 0;
2226 } 2253 }
2227 else if (must_clear || (stp[col] != ' ' && ++i >= 16)) 2254 else if (have_bg || (stp[col] != ' ' && ++i >= 16))
2228 break; 2255 break;
2229 } 2256 }
2230 2257
2231 col--; /* went one too far. move back */ 2258 col--; /* went one too far. move back */
2232 count -= i; /* dump any matching trailing chars */ 2259 count -= i; /* dump any matching trailing chars */
2242 int back = bgcolor_of (rend); // desired background 2269 int back = bgcolor_of (rend); // desired background
2243 2270
2244 // only do special processing if any attributes are set, which is unlikely 2271 // only do special processing if any attributes are set, which is unlikely
2245 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2272 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))
2246 { 2273 {
2247#if ENABLE_STYLES
2248 // force redraw after "careful" characters to avoid pixel droppings
2249 if (srp[col] & RS_Careful && col < ncol - 1 && 0)
2250 drp[col + 1] = ~srp[col + 1];
2251
2252 // include previous careful character(s) if possible, looks nicer (best effort...)
2253 while (text > stp
2254 && srp[text - stp - 1] & RS_Careful
2255 && RS_SAME (rend, srp[text - stp - 1]))
2256 text--, count++, xpixel -= fwidth;
2257#endif
2258
2259 bool invert = rend & RS_RVid; 2274 bool invert = rend & RS_RVid;
2260 2275
2261#ifndef NO_BOLD_UNDERLINE_REVERSE 2276#ifndef NO_BOLD_UNDERLINE_REVERSE
2262 if (rend & RS_Bold
2263 && fore == Color_fg) 2277 if (rend & RS_Bold && fore == Color_fg)
2264 { 2278 {
2265 if (ISSET_PIXCOLOR (Color_BD)) 2279 if (ISSET_PIXCOLOR (Color_BD))
2266 fore = Color_BD; 2280 fore = Color_BD;
2267# if !ENABLE_STYLES 2281# if !ENABLE_STYLES
2268 else 2282 else
2269 invert = !invert; 2283 invert = !invert;
2270# endif 2284# endif
2271 } 2285 }
2272 2286
2273 if (rend & RS_Italic 2287 if (rend & RS_Italic && fore == Color_fg)
2274 && fore == Color_fg)
2275 { 2288 {
2276 if (ISSET_PIXCOLOR (Color_IT)) 2289 if (ISSET_PIXCOLOR (Color_IT))
2277 fore = Color_IT; 2290 fore = Color_IT;
2278# if !ENABLE_STYLES 2291# if !ENABLE_STYLES
2279 else 2292 else
2280 invert = !invert; 2293 invert = !invert;
2281# endif 2294# endif
2282 } 2295 }
2283 2296
2284 if (rend & RS_Uline && ISSET_PIXCOLOR (Color_UL)) 2297 if (rend & RS_Uline && fore == Color_fg && ISSET_PIXCOLOR (Color_UL))
2285 fore = Color_UL; 2298 fore = Color_UL;
2286#endif 2299#endif
2287 2300
2288 if (invert) 2301 if (invert)
2289 { 2302 {
2303#ifdef OPTION_HC
2304 if ((showcursor && row == screen.cur.row && text - stp == screen.cur.col)
2305 || !ISSET_PIXCOLOR (Color_HC))
2306#endif
2307 /* invert the column if no highlightColor is set or it is the
2308 * current cursor column */
2290 ::swap (fore, back); 2309 ::swap (fore, back);
2310#ifdef OPTION_HC
2311 else if (ISSET_PIXCOLOR (Color_HC))
2312 back = Color_HC;
2313#endif
2291 2314
2292#ifndef NO_BOLD_UNDERLINE_REVERSE 2315#ifndef NO_BOLD_UNDERLINE_REVERSE
2316# ifndef OPTION_HC
2293 if (ISSET_PIXCOLOR (Color_RV)) 2317 if (ISSET_PIXCOLOR (Color_RV))
2294 back = Color_RV; 2318 back = Color_RV;
2295 2319# endif
2296 if (fore == back) 2320 if (fore == back)
2297 { 2321 {
2298 fore = Color_bg; 2322 fore = Color_bg;
2299 back = Color_fg; 2323 back = Color_fg;
2300 } 2324 }
2302 } 2326 }
2303 2327
2304#ifdef TEXT_BLINK 2328#ifdef TEXT_BLINK
2305 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg)) 2329 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg))
2306 { 2330 {
2307 if (!text_blink_ev.active) 2331 if (!text_blink_ev.is_active ())
2308 { 2332 {
2309 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2333 text_blink_ev.again ();
2310 hidden_text = 0; 2334 hidden_text = 0;
2311 } 2335 }
2312 else if (hidden_text) 2336 else if (hidden_text)
2313 fore = back; 2337 fore = back;
2314 } 2338 }
2315#endif 2339#endif
2340
2341#if ENABLE_STYLES
2342 // "careful" (too wide) character handling
2343
2344 // include previous careful character(s) if possible, looks nicer (best effort...)
2345 while (text > stp
2346 && srp[text - stp - 1] & RS_Careful
2347 && RS_SAME (rend, srp[text - stp - 1]))
2348 text--, count++, xpixel -= fwidth;
2349
2350 // force redraw after "careful" characters to avoid pixel droppings
2351 for (int i = 0; srp[col + i] & RS_Careful && col + i < ncol - 1; i++)
2352 drp[col + i + 1] = srp[col + i + 1] ^ RS_redraw;
2353
2354 // force redraw before "careful" characters to avoid pixel droppings
2355 for (int i = 0; srp[text - stp - i] & RS_Careful && text - i > stp; i++)
2356 drp[text - stp - i - 1] = srp[text - stp - i - 1] ^ RS_redraw;
2357#endif
2316 } 2358 }
2317 2359
2318 /* 2360 /*
2319 * Actually do the drawing of the string here 2361 * Actually do the drawing of the string here
2320 */ 2362 */
2321 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2363 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2322 2364
2323 if (back == fore)
2324 font->clear_rect (*drawable, xpixel, ypixel,
2325 fwidth * count, fheight,
2326 back);
2327 else if (back == Color_bg) 2365 if (have_bg && back == Color_bg)
2328 { 2366 {
2329 if (must_clear) 2367 // this is very ugly, maybe push it into ->draw?
2330 {
2331 CLEAR_CHARS (xpixel, ypixel, count);
2332 2368
2333 for (i = 0; i < count; i++) /* don't draw empty strings */ 2369 for (i = 0; i < count; i++) /* don't draw empty strings */
2334 if (text[i] != ' ') 2370 if (text[i] != ' ')
2335 { 2371 {
2336 font->draw (*drawable, xpixel, ypixel, text, count, fore, -1); 2372 font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_transparent);
2337 break; 2373 goto did_clear;
2338 }
2339 } 2374 }
2340 else 2375
2341 font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_bg); 2376 CLEAR_CHARS (xpixel, ypixel, count);
2377 did_clear: ;
2342 } 2378 }
2343 else 2379 else
2344 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2380 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2345 2381
2346 if (rend & RS_Uline && font->descent > 1 && fore != back) 2382 if (rend & RS_Uline && font->descent > 1 && fore != back)
2347 { 2383 {
2348#if ENABLE_FRILLS 2384#if ENABLE_FRILLS
2349 if (ISSET_PIXCOLOR (Color_underline)) 2385 if (ISSET_PIXCOLOR (Color_underline))
2350 XSetForeground (display->display, gc, pix_colors[Color_underline]); 2386 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2351 else 2387 else
2352#endif 2388#endif
2353 XSetForeground (display->display, gc, pix_colors[fore]); 2389 XSetForeground (dpy, gc, pix_colors[fore]);
2354 2390
2355 XDrawLine (display->display, drawBuffer, gc, 2391 XDrawLine (dpy, vt, gc,
2356 xpixel, ypixel + font->ascent + 1, 2392 xpixel, ypixel + font->ascent + 1,
2357 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2393 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2358 } 2394 }
2359 } /* for (col....) */ 2395 } /* for (col....) */
2360 } /* for (row....) */ 2396 } /* for (row....) */
2369 */ 2405 */
2370 if (showcursor) 2406 if (showcursor)
2371 { 2407 {
2372 if (focus) 2408 if (focus)
2373 { 2409 {
2374 if (OPTION (Opt_cursorUnderline)) 2410 if (option (Opt_cursorUnderline))
2375 *crp ^= RS_Uline; 2411 *crp ^= RS_Uline;
2376 else 2412 else
2377 { 2413 {
2378 *crp ^= RS_RVid; 2414 *crp ^= RS_RVid;
2379#ifndef NO_CURSORCOLOR 2415#ifndef NO_CURSORCOLOR
2393 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR) 2429 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2394 cursorwidth++; 2430 cursorwidth++;
2395 2431
2396#ifndef NO_CURSORCOLOR 2432#ifndef NO_CURSORCOLOR
2397 if (ISSET_PIXCOLOR (Color_cursor)) 2433 if (ISSET_PIXCOLOR (Color_cursor))
2398 XSetForeground (display->display, gc, pix_colors[Color_cursor]); 2434 XSetForeground (dpy, gc, pix_colors[Color_cursor]);
2435 else
2399#endif 2436#endif
2437 XSetForeground (dpy, gc, pix_colors[ccol1]);
2400 2438
2401 XDrawRectangle (display->display, drawBuffer, gc, 2439 XDrawRectangle (dpy, vt, gc,
2402 Col2Pixel (col), 2440 Col2Pixel (col),
2403 Row2Pixel (oldcursor.row), 2441 Row2Pixel (oldcursor.row),
2404 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2442 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2405 (unsigned int) (Height2Pixel (1) - lineSpace - 1)); 2443 (unsigned int) (Height2Pixel (1) - lineSpace - 1));
2406 } 2444 }
2441} 2479}
2442 2480
2443void 2481void
2444rxvt_term::scr_recolour () NOTHROW 2482rxvt_term::scr_recolour () NOTHROW
2445{ 2483{
2446 if (1 2484#ifdef HAVE_BG_PIXMAP
2447#if TRANSPARENT 2485 bgPixmap.apply ();
2448 && !am_transparent 2486#else
2449#endif 2487
2450#if XPM_BACKGROUND
2451 && !bgPixmap.pixmap
2452#endif
2453 )
2454 {
2455 XSetWindowBackground (display->display, parent[0], pix_colors[Color_border]); 2488 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]);
2456 XClearWindow (display->display, parent[0]); 2489 XClearWindow (dpy, parent[0]);
2457 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); 2490 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2458#if HAVE_SCROLLBARS 2491
2459 if (scrollBar.win) 2492 if (scrollBar.win)
2460 { 2493 {
2461 XSetWindowBackground (display->display, scrollBar.win, pix_colors[Color_border]); 2494 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2462 scrollBar.setIdle (); 2495 scrollBar.state = STATE_IDLE;
2463 scrollbar_show (0); 2496 scrollBar.show (0);
2464 }
2465#endif
2466 } 2497 }
2467 2498
2499#endif
2500
2501 /* bgPixmap.apply () does not do the following : */
2468 scr_clear (); 2502 scr_clear ();
2469 scr_touch (true); 2503 scr_touch (true);
2470 want_refresh = 1; 2504 want_refresh = 1;
2471} 2505}
2472 2506
2479 2513
2480 num_scr_allow = 0; 2514 num_scr_allow = 0;
2481 want_refresh = 1; 2515 want_refresh = 1;
2482 2516
2483 if (really) 2517 if (really)
2484 XClearWindow (display->display, vt); 2518 XClearWindow (dpy, vt);
2485} 2519}
2486 2520
2487void 2521void
2488rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) NOTHROW 2522rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) NOTHROW
2489{ 2523{
2538{ 2572{
2539 if (selection.op 2573 if (selection.op
2540 && current_screen == selection.screen 2574 && current_screen == selection.screen
2541 && selection.end.row >= view_start) 2575 && selection.end.row >= view_start)
2542 { 2576 {
2543#if ENABLE_FRILLS 2577#if !ENABLE_MINIMAL
2544 if (selection.rect) 2578 if (selection.rect)
2545 scr_xor_rect (selection.beg.row, selection.beg.col, 2579 scr_xor_rect (selection.beg.row, selection.beg.col,
2546 selection.end.row, selection.end.col, 2580 selection.end.row, selection.end.col,
2547 RS_RVid, RS_RVid | RS_Uline); 2581 RS_RVid, RS_RVid | RS_Uline);
2548 else 2582 else
2564{ 2598{
2565 int row, wrote; 2599 int row, wrote;
2566 unsigned int width, towrite; 2600 unsigned int width, towrite;
2567 char r1[] = "\n"; 2601 char r1[] = "\n";
2568 2602
2569 for (row = saveLines - nsaved; 2603 for (row = saveLines + top_row;
2570 row < saveLines + nrow - 1; row++) 2604 row < saveLines + nrow - 1; row++)
2571 { 2605 {
2572 width = row_buf[row].l >= 0 ? row_buf[row].l 2606 width = row_buf[row].l >= 0 ? row_buf[row].l
2573 : ncol; 2607 : ncol;
2574 for (towrite = width; towrite; towrite -= wrote) 2608 for (towrite = width; towrite; towrite -= wrote)
2625 /* convert normal newline chars into common keyboard Return key sequence */ 2659 /* convert normal newline chars into common keyboard Return key sequence */
2626 for (unsigned int i = 0; i < len; i++) 2660 for (unsigned int i = 0; i < len; i++)
2627 if (data[i] == C0_LF) 2661 if (data[i] == C0_LF)
2628 data[i] = C0_CR; 2662 data[i] = C0_CR;
2629 2663
2664 if (priv_modes & PrivMode_BracketPaste)
2665 tt_printf ("\e[200~");
2666
2630 tt_write (data, len); 2667 tt_write (data, len);
2668
2669 if (priv_modes & PrivMode_BracketPaste)
2670 tt_printf ("\e[201~");
2631} 2671}
2632 2672
2633/* ------------------------------------------------------------------------- */ 2673/* ------------------------------------------------------------------------- */
2634/* 2674/*
2635 * Respond to a notification that a primary selection has been sent 2675 * Respond to a notification that a primary selection has been sent
2664 } 2704 }
2665 2705
2666 unsigned long bytes_after; 2706 unsigned long bytes_after;
2667 XTextProperty ct; 2707 XTextProperty ct;
2668 2708
2669 if (XGetWindowProperty (display->display, win, prop, 2709 if (XGetWindowProperty (dpy, win, prop,
2670 0, PROP_SIZE / 4, 2710 0, PROP_SIZE / 4,
2671 delete_prop, AnyPropertyType, 2711 delete_prop, AnyPropertyType,
2672 &ct.encoding, &ct.format, 2712 &ct.encoding, &ct.format,
2673 &ct.nitems, &bytes_after, 2713 &ct.nitems, &bytes_after,
2674 &ct.value) != Success) 2714 &ct.value) != Success)
2683 if (bytes_after) 2723 if (bytes_after)
2684 { 2724 {
2685 // fetch and append remaining data 2725 // fetch and append remaining data
2686 XTextProperty ct2; 2726 XTextProperty ct2;
2687 2727
2688 if (XGetWindowProperty (display->display, win, prop, 2728 if (XGetWindowProperty (dpy, win, prop,
2689 ct.nitems / 4, (bytes_after + 3) / 4, 2729 ct.nitems / 4, (bytes_after + 3) / 4,
2690 delete_prop, AnyPropertyType, 2730 delete_prop, AnyPropertyType,
2691 &ct2.encoding, &ct2.format, 2731 &ct2.encoding, &ct2.format,
2692 &ct2.nitems, &bytes_after, 2732 &ct2.nitems, &bytes_after,
2693 &ct2.value) != Success) 2733 &ct2.value) != Success)
2706 2746
2707 if (ct.encoding == xa[XA_INCR]) 2747 if (ct.encoding == xa[XA_INCR])
2708 { 2748 {
2709 // INCR selection, start handshake 2749 // INCR selection, start handshake
2710 if (!delete_prop) 2750 if (!delete_prop)
2711 XDeleteProperty (display->display, win, prop); 2751 XDeleteProperty (dpy, win, prop);
2712 2752
2713 selection_wait = Sel_incr; 2753 selection_wait = Sel_incr;
2714 incr_buf_fill = 0; 2754 incr_buf_fill = 0;
2715 incr_ev.start (NOW + 10); 2755 incr_ev.start (10);
2716 2756
2717 goto bailout; 2757 goto bailout;
2718 } 2758 }
2719 2759
2720 if (ct.nitems == 0) 2760 if (ct.nitems == 0)
2729 ct.nitems = incr_buf_fill; 2769 ct.nitems = incr_buf_fill;
2730 incr_buf = 0; 2770 incr_buf = 0;
2731 incr_buf_size = 0; 2771 incr_buf_size = 0;
2732 incr_ev.stop (); 2772 incr_ev.stop ();
2733 } 2773 }
2734 else 2774 else
2735 { 2775 {
2736 if (selection_wait == Sel_normal 2776 if (selection_wait == Sel_normal
2737 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2777 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2738 { 2778 {
2739 /* 2779 /*
2746 goto bailout; 2786 goto bailout;
2747 } 2787 }
2748 } 2788 }
2749 else if (selection_wait == Sel_incr) 2789 else if (selection_wait == Sel_incr)
2750 { 2790 {
2751 incr_ev.start (NOW + 10); 2791 incr_ev.start (10);
2752 2792
2753 while (incr_buf_fill + ct.nitems > incr_buf_size) 2793 while (incr_buf_fill + ct.nitems > incr_buf_size)
2754 { 2794 {
2755 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024; 2795 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2756 incr_buf = (char *)realloc (incr_buf, incr_buf_size); 2796 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2763 } 2803 }
2764 2804
2765 char **cl; 2805 char **cl;
2766 int cr; 2806 int cr;
2767 2807
2768#if ENABLE_FRILLS 2808#if !ENABLE_MINIMAL
2769 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 2809 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2770 // so recode it manually 2810 // so recode it manually
2771 if (ct.encoding == xa[XA_UTF8_STRING]) 2811 if (ct.encoding == xa[XA_UTF8_STRING])
2772 { 2812 {
2773 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); 2813 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2777 paste (s, strlen (s)); 2817 paste (s, strlen (s));
2778 free (s); 2818 free (s);
2779 } 2819 }
2780 else 2820 else
2781#endif 2821#endif
2782 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 2822 if (XmbTextPropertyToTextList (dpy, &ct, &cl, &cr) >= 0
2783 && cl) 2823 && cl)
2784 { 2824 {
2785 for (int i = 0; i < cr; i++) 2825 for (int i = 0; i < cr; i++)
2786 paste (cl[i], strlen (cl[i])); 2826 paste (cl[i], strlen (cl[i]));
2787 2827
2796 if (selection_wait == Sel_normal) 2836 if (selection_wait == Sel_normal)
2797 selection_wait = Sel_none; 2837 selection_wait = Sel_none;
2798} 2838}
2799 2839
2800void 2840void
2801rxvt_term::incr_cb (time_watcher &w) NOTHROW 2841rxvt_term::incr_cb (ev::timer &w, int revents) NOTHROW
2802{ 2842{
2803 selection_wait = Sel_none; 2843 selection_wait = Sel_none;
2804 2844
2805 incr_buf_size = 0; 2845 incr_buf_size = 0;
2806 free (incr_buf); 2846 free (incr_buf);
2817 selection_paste (win, prop, true); 2857 selection_paste (win, prop, true);
2818} 2858}
2819 2859
2820/* ------------------------------------------------------------------------- */ 2860/* ------------------------------------------------------------------------- */
2821/* 2861/*
2822 * Request the current selection: 2862 * Request the current selection:
2823 * Order: > internal selection if available 2863 * Order: > internal selection if available
2824 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+) 2864 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+)
2825 * > CUT_BUFFER0 2865 * > CUT_BUFFER0
2826 * (+) if ownership is claimed but property is empty, rxvt_selection_paste () 2866 * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
2827 * will auto fallback to CUT_BUFFER0 2867 * will auto fallback to CUT_BUFFER0
2829 */ 2869 */
2830void 2870void
2831rxvt_term::selection_request (Time tm, int selnum) NOTHROW 2871rxvt_term::selection_request (Time tm, int selnum) NOTHROW
2832{ 2872{
2833 if (selection.text && selnum == Sel_Primary) 2873 if (selection.text && selnum == Sel_Primary)
2874 {
2834 { /* internal selection */ 2875 /* internal selection */
2835 char *str = rxvt_wcstombs (selection.text, selection.len); 2876 char *str = rxvt_wcstombs (selection.text, selection.len);
2836 paste (str, strlen (str)); 2877 paste (str, strlen (str));
2837 free (str); 2878 free (str);
2838 return; 2879 return;
2839 } 2880 }
2869 else if (selnum == Sel_Secondary) 2910 else if (selnum == Sel_Secondary)
2870 sel = XA_SECONDARY; 2911 sel = XA_SECONDARY;
2871 else 2912 else
2872 sel = xa[XA_CLIPBOARD]; 2913 sel = xa[XA_CLIPBOARD];
2873 2914
2874 if (XGetSelectionOwner (display->display, sel) != None) 2915 if (XGetSelectionOwner (dpy, sel) != None)
2875 { 2916 {
2876 XConvertSelection (display->display, sel, target, xa[XA_VT_SELECTION], 2917 XConvertSelection (dpy, sel, target, xa[XA_VT_SELECTION],
2877 vt, selection_request_time); 2918 vt, selection_request_time);
2878 return 1; 2919 return 1;
2879 } 2920 }
2880 2921
2881 return 0; 2922 return 0;
2944 2985
2945 int end_col; 2986 int end_col;
2946 2987
2947 for (; row <= selection.end.row; row++, col = 0) 2988 for (; row <= selection.end.row; row++, col = 0)
2948 { 2989 {
2949#if ENABLE_FRILLS 2990#if !ENABLE_MINIMAL
2950 if (selection.rect) 2991 if (selection.rect)
2951 { 2992 {
2952 col = selection.beg.col; 2993 col = selection.beg.col;
2953 end_col = ncol + 1; 2994 end_col = ncol + 1;
2954 } 2995 }
2957 end_col = ROW(row).l; 2998 end_col = ROW(row).l;
2958 2999
2959 col = max (col, 0); 3000 col = max (col, 0);
2960 3001
2961 if (row == selection.end.row 3002 if (row == selection.end.row
2962#if ENABLE_FRILLS 3003#if !ENABLE_MINIMAL
2963 || selection.rect 3004 || selection.rect
2964#endif 3005#endif
2965 ) 3006 )
2966 min_it (end_col, selection.end.col); 3007 min_it (end_col, selection.end.col);
2967 3008
2990#endif 3031#endif
2991 else 3032 else
2992 new_selection_text[ofs++] = *t++; 3033 new_selection_text[ofs++] = *t++;
2993 } 3034 }
2994 3035
2995#if ENABLE_FRILLS 3036#if !ENABLE_MINIMAL
2996 if (selection.rect) 3037 if (selection.rect)
2997 { 3038 {
2998 while (ofs 3039 while (ofs
2999 && new_selection_text[ofs - 1] != C0_LF 3040 && new_selection_text[ofs - 1] != C0_LF
3000 && unicode::is_space (new_selection_text[ofs - 1])) 3041 && unicode::is_space (new_selection_text[ofs - 1]))
3034bool 3075bool
3035rxvt_term::selection_grab (Time tm) NOTHROW 3076rxvt_term::selection_grab (Time tm) NOTHROW
3036{ 3077{
3037 selection_time = tm; 3078 selection_time = tm;
3038 3079
3039 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); 3080 XSetSelectionOwner (dpy, XA_PRIMARY, vt, tm);
3040 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) 3081 if (XGetSelectionOwner (dpy, XA_PRIMARY) == vt)
3041 { 3082 {
3042 display->set_selection_owner (this); 3083 display->set_selection_owner (this);
3043 return true; 3084 return true;
3044 } 3085 }
3045 else 3086 else
3049 } 3090 }
3050 3091
3051#if 0 3092#if 0
3052 XTextProperty ct; 3093 XTextProperty ct;
3053 3094
3054 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3095 if (XwcTextListToTextProperty (dpy, &selection.text, 1, XStringStyle, &ct) >= 0)
3055 { 3096 {
3056 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); 3097 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
3057 XFree (ct.value); 3098 XFree (ct.value);
3058 } 3099 }
3059#endif 3100#endif
3105 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); 3146 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1);
3106 3147
3107 while (selection.mark.col > 0 3148 while (selection.mark.col > 0
3108 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) 3149 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3109 --selection.mark.col; 3150 --selection.mark.col;
3110 3151
3111 if (selection.op) 3152 if (selection.op)
3153 {
3112 { /* clear the old selection */ 3154 /* clear the old selection */
3113 selection.beg.row = selection.end.row = selection.mark.row; 3155 selection.beg.row = selection.end.row = selection.mark.row;
3114 selection.beg.col = selection.end.col = selection.mark.col; 3156 selection.beg.col = selection.end.col = selection.mark.col;
3115 } 3157 }
3116 3158
3117 selection.op = SELECTION_INIT; 3159 selection.op = SELECTION_INIT;
3306 * a point/word/line which is either the start or end of the selection 3348 * a point/word/line which is either the start or end of the selection
3307 * and it was decided by whichever point/word/line was `fixed' at the 3349 * and it was decided by whichever point/word/line was `fixed' at the
3308 * time of the most recent button3 press 3350 * time of the most recent button3 press
3309 */ 3351 */
3310 if (button3 && buttonpress) 3352 if (button3 && buttonpress)
3353 {
3311 { /* button3 press */ 3354 /* button3 press */
3312 /* 3355 /*
3313 * first determine which edge of the selection we are closest to 3356 * first determine which edge of the selection we are closest to
3314 */ 3357 */
3315 if (ROWCOL_IS_BEFORE (pos, selection.beg) 3358 if (ROWCOL_IS_BEFORE (pos, selection.beg)
3316 || (!ROWCOL_IS_AFTER (pos, selection.end) 3359 || (!ROWCOL_IS_AFTER (pos, selection.end)
3334 selection.mark.row = selection.beg.row; 3377 selection.mark.row = selection.beg.row;
3335 selection.mark.col = selection.beg.col; 3378 selection.mark.col = selection.beg.col;
3336 } 3379 }
3337 } 3380 }
3338 else 3381 else
3382 {
3339 { /* button1 drag or button3 drag */ 3383 /* button1 drag or button3 drag */
3340 if (ROWCOL_IS_AFTER (selection.mark, pos)) 3384 if (ROWCOL_IS_AFTER (selection.mark, pos))
3341 { 3385 {
3342 if (selection.mark.row == selection.end.row 3386 if (selection.mark.row == selection.end.row
3343 && selection.mark.col == selection.end.col 3387 && selection.mark.col == selection.end.col
3344 && clickchange 3388 && clickchange
3361 3405
3362 if (selection.clicks == 1) 3406 if (selection.clicks == 1)
3363 { 3407 {
3364 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN 3408 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN
3365 && !ROW(selection.beg.row).is_longer () 3409 && !ROW(selection.beg.row).is_longer ()
3366#if ENABLE_FRILLS 3410#if !ENABLE_MINIMAL
3367 && !selection.rect 3411 && !selection.rect
3368#endif 3412#endif
3369 ) 3413 )
3370 selection.beg.col = ncol; 3414 selection.beg.col = ncol;
3371 3415
3372 if ( 3416 if (
3373 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN 3417 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN
3374 && !ROW(selection.end.row).is_longer () 3418 && !ROW(selection.end.row).is_longer ()
3375#if ENABLE_FRILLS 3419#if !ENABLE_MINIMAL
3376 && !selection.rect 3420 && !selection.rect
3377#endif 3421#endif
3378 ) 3422 )
3379 selection.end.col = ncol; 3423 selection.end.col = ncol;
3380 } 3424 }
3387 selection_delimit_word (DN, &selection.end, &selection.end); 3431 selection_delimit_word (DN, &selection.end, &selection.end);
3388 } 3432 }
3389 else if (selection.clicks == 3) 3433 else if (selection.clicks == 3)
3390 { 3434 {
3391#if ENABLE_FRILLS 3435#if ENABLE_FRILLS
3392 if (OPTION (Opt_tripleclickwords)) 3436 if (option (Opt_tripleclickwords))
3393 { 3437 {
3394 selection_delimit_word (UP, &selection.beg, &selection.beg); 3438 selection_delimit_word (UP, &selection.beg, &selection.beg);
3395 3439
3396 for (int end_row = selection.mark.row; end_row < nrow; end_row++) 3440 for (int end_row = selection.mark.row; end_row < nrow; end_row++)
3397 { 3441 {
3398 if (!ROW(end_row).is_longer ()) 3442 if (!ROW(end_row).is_longer ())
3399 { 3443 {
3400 selection.end.row = end_row; 3444 selection.end.row = end_row;
3401 selection.end.col = ROW(end_row).l; 3445 selection.end.col = ROW(end_row).l;
3446# if !ENABLE_MINIMAL
3402 selection_remove_trailing_spaces (); 3447 selection_remove_trailing_spaces ();
3448# endif
3403 break; 3449 break;
3404 } 3450 }
3405 } 3451 }
3406 } 3452 }
3407 else 3453 else
3423 selection.end.row++; 3469 selection.end.row++;
3424 } 3470 }
3425 } 3471 }
3426 3472
3427 if (button3 && buttonpress) 3473 if (button3 && buttonpress)
3474 {
3428 { /* mark may need to be changed */ 3475 /* mark may need to be changed */
3429 if (closeto == LEFT) 3476 if (closeto == LEFT)
3430 { 3477 {
3431 selection.mark.row = selection.end.row; 3478 selection.mark.row = selection.end.row;
3432 selection.mark.col = selection.end.col - (selection.clicks == 2); 3479 selection.mark.col = selection.end.col - (selection.clicks == 2);
3433 } 3480 }
3436 selection.mark.row = selection.beg.row; 3483 selection.mark.row = selection.beg.row;
3437 selection.mark.col = selection.beg.col; 3484 selection.mark.col = selection.beg.col;
3438 } 3485 }
3439 } 3486 }
3440 3487
3441#if ENABLE_FRILLS 3488#if !ENABLE_MINIMAL
3442 if (selection.rect && selection.beg.col > selection.end.col) 3489 if (selection.rect && selection.beg.col > selection.end.col)
3443 ::swap (selection.beg.col, selection.end.col); 3490 ::swap (selection.beg.col, selection.end.col);
3444#endif 3491#endif
3445} 3492}
3446 3493
3447#if ENABLE_FRILLS 3494#if !ENABLE_MINIMAL
3448void 3495void
3449rxvt_term::selection_remove_trailing_spaces () NOTHROW 3496rxvt_term::selection_remove_trailing_spaces () NOTHROW
3450{ 3497{
3451 int32_t end_col, end_row; 3498 int32_t end_col, end_row;
3452 text_t *stp; 3499 text_t *stp;
3507 */ 3554 */
3508void 3555void
3509rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW 3556rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW
3510{ 3557{
3511 XSelectionEvent ev; 3558 XSelectionEvent ev;
3512 dDisp;
3513 3559
3514 ev.type = SelectionNotify; 3560 ev.type = SelectionNotify;
3515 ev.property = None; 3561 ev.property = None;
3516 ev.display = rq.display; 3562 ev.display = rq.display;
3517 ev.requestor = rq.requestor; 3563 ev.requestor = rq.requestor;
3531 *target++ = xa[XA_COMPOUND_TEXT]; 3577 *target++ = xa[XA_COMPOUND_TEXT];
3532#if X_HAVE_UTF8_STRING 3578#if X_HAVE_UTF8_STRING
3533 *target++ = xa[XA_UTF8_STRING]; 3579 *target++ = xa[XA_UTF8_STRING];
3534#endif 3580#endif
3535 3581
3536 XChangeProperty (disp, rq.requestor, rq.property, XA_ATOM, 3582 XChangeProperty (dpy, rq.requestor, rq.property, XA_ATOM,
3537 32, PropModeReplace, 3583 32, PropModeReplace,
3538 (unsigned char *)target_list, target - target_list); 3584 (unsigned char *)target_list, target - target_list);
3539 ev.property = rq.property; 3585 ev.property = rq.property;
3540 } 3586 }
3541#if TODO // TODO 3587#if TODO // TODO
3544 /* TODO: Handle MULTIPLE */ 3590 /* TODO: Handle MULTIPLE */
3545 } 3591 }
3546#endif 3592#endif
3547 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3593 else if (rq.target == xa[XA_TIMESTAMP] && selection.text)
3548 { 3594 {
3549 XChangeProperty (disp, rq.requestor, rq.property, rq.target, 3595 XChangeProperty (dpy, rq.requestor, rq.property, rq.target,
3550 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3596 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3551 ev.property = rq.property; 3597 ev.property = rq.property;
3552 } 3598 }
3553 else if (rq.target == XA_STRING 3599 else if (rq.target == XA_STRING
3554 || rq.target == xa[XA_TEXT] 3600 || rq.target == xa[XA_TEXT]
3578 style = enc_string; 3624 style = enc_string;
3579 else if (target == xa[XA_TEXT]) 3625 else if (target == xa[XA_TEXT])
3580 style = enc_text; 3626 style = enc_text;
3581 else if (target == xa[XA_COMPOUND_TEXT]) 3627 else if (target == xa[XA_COMPOUND_TEXT])
3582 style = enc_compound_text; 3628 style = enc_compound_text;
3583#if ENABLE_FRILLS 3629#if !ENABLE_MINIMAL
3584 else if (target == xa[XA_UTF8_STRING]) 3630 else if (target == xa[XA_UTF8_STRING])
3585 style = enc_utf8; 3631 style = enc_utf8;
3586#endif 3632#endif
3587 else 3633 else
3588 { 3634 {
3599 { 3645 {
3600 cl = L""; 3646 cl = L"";
3601 selectlen = 0; 3647 selectlen = 0;
3602 } 3648 }
3603 3649
3604#if ENABLE_FRILLS 3650#if !ENABLE_MINIMAL
3605 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 3651 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
3606 // so recode it manually 3652 // so recode it manually
3607 if (style == enc_utf8) 3653 if (style == enc_utf8)
3608 { 3654 {
3609 freect = 1; 3655 freect = 1;
3612 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen); 3658 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen);
3613 ct.nitems = strlen ((char *)ct.value); 3659 ct.nitems = strlen ((char *)ct.value);
3614 } 3660 }
3615 else 3661 else
3616#endif 3662#endif
3617 if (XwcTextListToTextProperty (disp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) 3663 if (XwcTextListToTextProperty (dpy, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0)
3618 freect = 1; 3664 freect = 1;
3619 else 3665 else
3620 { 3666 {
3621 /* if we failed to convert then send it raw */ 3667 /* if we failed to convert then send it raw */
3622 ct.value = (unsigned char *)cl; 3668 ct.value = (unsigned char *)cl;
3623 ct.nitems = selectlen; 3669 ct.nitems = selectlen;
3624 ct.encoding = target; 3670 ct.encoding = target;
3625 } 3671 }
3626 3672
3627 XChangeProperty (disp, rq.requestor, rq.property, 3673 XChangeProperty (dpy, rq.requestor, rq.property,
3628 ct.encoding, 8, PropModeReplace, 3674 ct.encoding, 8, PropModeReplace,
3629 ct.value, (int)ct.nitems); 3675 ct.value, (int)ct.nitems);
3630 ev.property = rq.property; 3676 ev.property = rq.property;
3631 3677
3632 if (freect) 3678 if (freect)
3633 XFree (ct.value); 3679 XFree (ct.value);
3634 } 3680 }
3635 3681
3636 XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev); 3682 XSendEvent (dpy, rq.requestor, False, 0L, (XEvent *)&ev);
3637}
3638
3639/* ------------------------------------------------------------------------- *
3640 * MOUSE ROUTINES *
3641 * ------------------------------------------------------------------------- */
3642
3643/*
3644 * return col/row values corresponding to x/y pixel values
3645 */
3646void
3647rxvt_term::pixel_position (int *x, int *y) NOTHROW
3648{
3649 *x = Pixel2Col (*x);
3650 /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */
3651 *y = Pixel2Row (*y);
3652 /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */
3653} 3683}
3654 3684
3655/* ------------------------------------------------------------------------- */ 3685/* ------------------------------------------------------------------------- */
3656#ifdef USE_XIM 3686#ifdef USE_XIM
3657void 3687void
3658rxvt_term::im_set_position (XPoint &pos) NOTHROW 3688rxvt_term::im_set_position (XPoint &pos) NOTHROW
3659{ 3689{
3660 XWindowAttributes xwa; 3690 XWindowAttributes xwa;
3661 3691
3662 XGetWindowAttributes (display->display, vt, &xwa); 3692 XGetWindowAttributes (dpy, vt, &xwa);
3663 3693
3664 pos.x = xwa.x + Col2Pixel (screen.cur.col); 3694 pos.x = xwa.x + Col2Pixel (screen.cur.col);
3665 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase; 3695 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase;
3666} 3696}
3667#endif 3697#endif
3763rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) NOTHROW 3793rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) NOTHROW
3764{ 3794{
3765 while (*s) 3795 while (*s)
3766 { 3796 {
3767 text_t t = *s++; 3797 text_t t = *s++;
3768 int width = wcwidth (t); 3798 int width = WCWIDTH (t);
3769 3799
3770 while (width--) 3800 while (width--)
3771 { 3801 {
3772 scr_overlay_set (x++, y, t); 3802 scr_overlay_set (x++, y, t);
3773 t = NOCHAR; 3803 t = NOCHAR;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines