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.275 by sasha, Wed Aug 15 22:41:52 2007 UTC vs.
Revision 1.319 by root, Tue Nov 4 23:08:44 2008 UTC

1/*---------------------------------------------------------------------------* 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.
30 30
31#include <inttypes.h> 31#include <inttypes.h>
32 32
33#include "salloc.C" // HACK, should be a seperate compile! 33#include "salloc.C" // HACK, should be a seperate compile!
34 34
35inline void fill_text (text_t *start, text_t value, int len) 35static inline void fill_text (text_t *start, text_t value, int len)
36{ 36{
37 while (len--) 37 while (len--)
38 *start++ = value; 38 *start++ = value;
39} 39}
40 40
83 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)
84#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \ 84#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \
85 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)
86 86
87/* 87/*
88 * CLEAR_ROWS : clear <num> rows starting from row <row>
89 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 88 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
90 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
91 */ 89 */
92#define drawBuffer vt
93
94#define CLEAR_ROWS(row, num) \
95 if (mapped) \
96 XClearArea (dpy, drawBuffer, 0, \
97 Row2Pixel (row), (unsigned int)width, \
98 (unsigned int)Height2Pixel (num), False)
99
100#define CLEAR_CHARS(x, y, num) \ 90#define CLEAR_CHARS(x, y, num) \
101 if (mapped) \ 91 if (mapped) \
102 XClearArea (dpy, drawBuffer, x, y, \ 92 XClearArea (dpy, vt, x, y, \
103 (unsigned int)Width2Pixel (num), \ 93 (unsigned int)Width2Pixel (num), \
104 (unsigned int)Height2Pixel (1), False) 94 (unsigned int)Height2Pixel (1), False)
105
106#define ERASE_ROWS(row, num) \
107 XFillRectangle (dpy, drawBuffer, gc, \
108 0, Row2Pixel (row), \
109 (unsigned int)width, \
110 (unsigned int)Height2Pixel (num))
111 95
112/* ------------------------------------------------------------------------- * 96/* ------------------------------------------------------------------------- *
113 * SCREEN `COMMON' ROUTINES * 97 * SCREEN `COMMON' ROUTINES *
114 * ------------------------------------------------------------------------- */ 98 * ------------------------------------------------------------------------- */
115 99
148 132
149 l.l = 0; 133 l.l = 0;
150 l.f = 0; 134 l.f = 0;
151} 135}
152 136
137// nuke a single wide character at the given column
138void
139rxvt_term::scr_kill_char (line_t &l, int col) const NOTHROW
140{
141 // find begin
142 while (col > 0 && l.t[col] == NOCHAR)
143 col--;
144
145 rend_t rend = l.r[col] & ~RS_baseattrMask;
146 rend = SET_FONT (rend, FONTSET (rend)->find_font (' '));
147
148 // found start, nuke
149 do {
150 l.t[col] = ' ';
151 l.r[col] = rend;
152 col++;
153 } while (col < ncol && l.t[col] == NOCHAR);
154}
155
153/* ------------------------------------------------------------------------- * 156/* ------------------------------------------------------------------------- *
154 * SCREEN INITIALISATION * 157 * SCREEN INITIALISATION *
155 * ------------------------------------------------------------------------- */ 158 * ------------------------------------------------------------------------- */
156 159
157void 160void
158rxvt_term::scr_reset () 161rxvt_term::scr_reset ()
159{ 162{
160#if ENABLE_OVERLAY
161 scr_overlay_off ();
162#endif
163
164 rvideo_mode = false;
165 view_start = 0; 163 view_start = 0;
166 num_scr = 0; 164 num_scr = 0;
167 165
168 if (ncol == 0) 166 if (ncol == 0)
169 ncol = 80; 167 ncol = 80;
171 if (nrow == 0) 169 if (nrow == 0)
172 nrow = 24; 170 nrow = 24;
173 171
174 if (ncol == prev_ncol && nrow == prev_nrow) 172 if (ncol == prev_ncol && nrow == prev_nrow)
175 return; 173 return;
176
177 if (current_screen != PRIMARY)
178 scr_swap_screen ();
179 174
180 // we need at least two lines for wrapping to work correctly 175 // we need at least two lines for wrapping to work correctly
181 while (nrow + saveLines < 2) 176 while (nrow + saveLines < 2)
182 { 177 {
183 //TODO//FIXME 178 //TODO//FIXME
274 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 269 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
275 } 270 }
276 271
277 line_t *old_buf = row_buf; 272 line_t *old_buf = row_buf;
278 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t)); 273 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t));
279 274
280 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 275 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
281 int pend = MOD (term_start + top_row , prev_total_rows); 276 int pend = MOD (term_start + top_row , prev_total_rows);
282 int q = total_rows; // rewrapped row 277 int q = total_rows; // rewrapped row
283 278
284 if (top_row) 279 if (top_row)
328 int qcol = 0; 323 int qcol = 0;
329 324
330 // see below for cursor adjustment rationale 325 // see below for cursor adjustment rationale
331 if (p == ocur.row) 326 if (p == ocur.row)
332 screen.cur.row = q - (total_rows - nrow); 327 screen.cur.row = q - (total_rows - nrow);
333 328
334 // fill a single destination line 329 // fill a single destination line
335 while (lofs < llen && qcol < ncol) 330 while (lofs < llen && qcol < ncol)
336 { 331 {
337 int prow = lofs / prev_ncol; 332 int prow = lofs / prev_ncol;
338 int pcol = lofs % prev_ncol; 333 int pcol = lofs % prev_ncol;
364 } 359 }
365 while (p != pend && q > 0); 360 while (p != pend && q > 0);
366 361
367 term_start = total_rows - nrow; 362 term_start = total_rows - nrow;
368 top_row = q - term_start; 363 top_row = q - term_start;
369 364
370 // make sure all terminal lines exist 365 // make sure all terminal lines exist
371 while (top_row > 0) 366 while (top_row > 0)
372 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE); 367 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
373 } 368 }
374 else 369 else
375 { 370 {
376 // if no scrollback exists (yet), wing, instead of wrap 371 // if no scrollback exists (yet), wing, instead of wrap
377 372
378 for (int row = min (nrow, prev_nrow); row--; ) 373 for (int row = min (nrow, prev_nrow); row--; )
379 { 374 {
380 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; 375 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
381 line_t &qline = row_buf [row]; 376 line_t &qline = row_buf [row];
382 377
396 delete old_ta; 391 delete old_ta;
397 delete old_ra; 392 delete old_ra;
398 393
399 clamp_it (screen.cur.row, 0, nrow - 1); 394 clamp_it (screen.cur.row, 0, nrow - 1);
400 clamp_it (screen.cur.col, 0, ncol - 1); 395 clamp_it (screen.cur.col, 0, ncol - 1);
401
402 free (tabs);
403 } 396 }
404 397
405 CLEAR_ALL_SELECTION (); 398 CLEAR_ALL_SELECTION ();
406 399
407 prev_nrow = nrow; 400 prev_nrow = nrow;
408 prev_ncol = ncol; 401 prev_ncol = ncol;
409
410 tabs = (char *)rxvt_malloc (ncol * sizeof (char));
411
412 for (int col = ncol; --col; )
413 tabs [col] = col % TABSIZE == 0;
414
415 if (current_screen != PRIMARY)
416 scr_swap_screen ();
417 402
418 tt_winch (); 403 tt_winch ();
419 404
420 HOOK_INVOKE ((this, HOOK_RESET, DT_END)); 405 HOOK_INVOKE ((this, HOOK_RESET, DT_END));
421} 406}
433 delete ralloc; ralloc = 0; 418 delete ralloc; ralloc = 0;
434 419
435 free (row_buf); 420 free (row_buf);
436 free (swap_buf); 421 free (swap_buf);
437 free (drawn_buf); 422 free (drawn_buf);
423 row_buf = 0; // signal that we freed all the arrays above
424
438 free (tabs); 425 free (tabs);
439 426 tabs = 0;
440 row_buf = 0; // signal that we freed all the arrays
441 } 427 }
442} 428}
443 429
444/* ------------------------------------------------------------------------- */ 430/* ------------------------------------------------------------------------- */
445/* 431/*
446 * Hard reset 432 * Hard/Soft reset
447 */ 433 */
448void 434void
449rxvt_term::scr_poweron () 435rxvt_term::scr_poweron ()
450{ 436{
451 scr_release (); 437 scr_release ();
452 prev_nrow = prev_ncol = 0; 438 prev_nrow = prev_ncol = 0;
439 scr_soft_reset ();
453 scr_reset (); 440 scr_reset ();
454 441
455 scr_clear (true); 442 scr_clear (true);
456 scr_refresh (); 443 scr_refresh ();
444}
445
446void
447rxvt_term::scr_soft_reset ()
448{
449 /* only affects modes, nothing drastic such as clearing the screen */
450#if ENABLE_OVERLAY
451 scr_overlay_off ();
452#endif
453
454 rvideo_mode = false;
455
456 if (current_screen != PRIMARY)
457 scr_swap_screen ();
458
459 free (tabs);
460 tabs = (char *)rxvt_malloc (ncol);
461
462 for (int col = ncol; --col; )
463 tabs [col] = col % TABSIZE == 0;
464
465 scr_scroll_region (0, MAX_ROWS - 1);
466 scr_rendition (0, ~RS_None);
467 scr_insert_mode (0);
457} 468}
458 469
459/* ------------------------------------------------------------------------- * 470/* ------------------------------------------------------------------------- *
460 * PROCESS SCREEN COMMANDS * 471 * PROCESS SCREEN COMMANDS *
461 * ------------------------------------------------------------------------- */ 472 * ------------------------------------------------------------------------- */
596/* 607/*
597 * Change the rendition style for following text 608 * Change the rendition style for following text
598 */ 609 */
599void 610void
600rxvt_term::scr_rendition (int set, int style) NOTHROW 611rxvt_term::scr_rendition (int set, int style) NOTHROW
601 { 612{
602 if (set) 613 if (set)
603 rstyle |= style; 614 rstyle |= style;
604 else if (style == ~RS_None) 615 else if (style == ~RS_None)
605 rstyle = DEFAULT_RSTYLE; 616 rstyle = DEFAULT_RSTYLE;
606 else 617 else
607 rstyle &= ~style; 618 rstyle &= ~style;
608 } 619}
609 620
610/* ------------------------------------------------------------------------- */ 621/* ------------------------------------------------------------------------- */
611/* 622/*
612 * Scroll text between <row1> and <row2> inclusive, by <count> lines 623 * Scroll text between <row1> and <row2> inclusive, by <count> lines
613 * count positive ==> scroll up 624 * count positive ==> scroll up
664 line_t &l2 = ROW(i); 675 line_t &l2 = ROW(i);
665 676
666 ::swap (l1, l2); 677 ::swap (l1, l2);
667 l2.touch (); 678 l2.touch ();
668 } 679 }
669 680
670 // move and/or clear selection, if any 681 // move and/or clear selection, if any
671 if (selection.op && current_screen == selection.screen) 682 if (selection.op && current_screen == selection.screen)
672 { 683 {
673 selection.beg.row -= count; 684 selection.beg.row -= count;
674 selection.end.row -= count; 685 selection.end.row -= count;
710 { 721 {
711 /* move selected region too */ 722 /* move selected region too */
712 selection.beg.row -= count; 723 selection.beg.row -= count;
713 selection.end.row -= count; 724 selection.end.row -= count;
714 selection.mark.row -= count; 725 selection.mark.row -= count;
715 726
716 selection_check (0); 727 selection_check (0);
717 } 728 }
718 } 729 }
719 730
720 // use a simple and robust scrolling algorithm, this 731 // use a simple and robust scrolling algorithm, this
787 798
788 while (str < strend) 799 while (str < strend)
789 { 800 {
790 c = (unicode_t)*str++; // convert to rxvt-unicodes representation 801 c = (unicode_t)*str++; // convert to rxvt-unicodes representation
791 802
792 if (c < 0x20) 803 if (expect_false (c < 0x20))
793 if (c == C0_LF) 804 if (c == C0_LF)
794 { 805 {
795 max_it (line->l, screen.cur.col); 806 max_it (line->l, screen.cur.col);
796 807
797 screen.flags &= ~Screen_WrapNext; 808 screen.flags &= ~Screen_WrapNext;
816 { 827 {
817 scr_tab (1, true); 828 scr_tab (1, true);
818 continue; 829 continue;
819 } 830 }
820 831
832 if (expect_false (
821 if (checksel /* see if we're writing within selection */ 833 checksel /* see if we're writing within selection */
822 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 834 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
823 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 835 && ROWCOL_IS_BEFORE (screen.cur, selection.end)
836 ))
824 { 837 {
825 checksel = 0; 838 checksel = 0;
826 /* 839 /*
827 * If we wrote anywhere in the selected area, kill the selection 840 * If we wrote anywhere in the selected area, kill the selection
828 * XXX: should we kill the mark too? Possibly, but maybe that 841 * XXX: should we kill the mark too? Possibly, but maybe that
829 * should be a similar check. 842 * should be a similar check.
830 */ 843 */
831 CLEAR_SELECTION (); 844 CLEAR_SELECTION ();
832 } 845 }
833 846
834 if (screen.flags & Screen_WrapNext) 847 if (expect_false (screen.flags & Screen_WrapNext))
835 { 848 {
836 scr_do_wrap (); 849 scr_do_wrap ();
837 850
838 line->l = ncol; 851 line->l = ncol;
839 line->is_longer (1); 852 line->is_longer (1);
840 853
841 row = screen.cur.row; 854 row = screen.cur.row;
842 line = &ROW(row); /* _must_ refresh */ 855 line = &ROW(row); /* _must_ refresh */
843 } 856 }
844 857
845 // some utf-8 decoders "decode" surrogate characters: let's fix this. 858 // some utf-8 decoders "decode" surrogate characters: let's fix this.
846 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 859 if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff)))
847 c = 0xfffd; 860 c = 0xfffd;
848 861
849 // rely on wcwidth to tell us the character width, do wcwidth before 862 // rely on wcwidth to tell us the character width, do wcwidth before
850 // further replacements, as wcwidth might return -1 for the line 863 // further replacements, as wcwidth might return -1 for the line
851 // drawing characters below as they might be invalid in the current 864 // drawing characters below as they might be invalid in the current
852 // locale. 865 // locale.
853 int width = WCWIDTH (c); 866 int width = WCWIDTH (c);
854 867
855 if (charsets [screen.charset] == '0') // DEC SPECIAL 868 if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL
856 { 869 {
857 // vt100 special graphics and line drawing 870 // vt100 special graphics and line drawing
858 // 5f-7e standard vt100 871 // 5f-7e standard vt100
859 // 40-5e rxvt extension for extra curses acs chars 872 // 40-5e rxvt extension for extra curses acs chars
860 static uint16_t vt100_0[62] = { // 41 .. 7e 873 static uint16_t vt100_0[62] = { // 41 .. 7e
873 c = vt100_0[c - 0x41]; 886 c = vt100_0[c - 0x41];
874 width = 1; // vt100 line drawing characters are always single-width 887 width = 1; // vt100 line drawing characters are always single-width
875 } 888 }
876 } 889 }
877 890
878 if (screen.flags & Screen_Insert) 891 if (expect_false (screen.flags & Screen_Insert))
879 scr_insdel_chars (width, INSERT); 892 scr_insdel_chars (width, INSERT);
880 893
881 if (width != 0) 894 if (width != 0)
882 { 895 {
883#if !UNICODE_3 896#if !UNICODE_3
889 c = 0xfffd; 902 c = 0xfffd;
890# endif 903# endif
891#endif 904#endif
892 905
893 // nuke the character at this position, if required 906 // nuke the character at this position, if required
907 if (expect_false (
894 if (line->t[screen.cur.col] == NOCHAR 908 line->t[screen.cur.col] == NOCHAR
895 || (screen.cur.col < ncol - 1 909 || (screen.cur.col < ncol - 1
896 && line->t[screen.cur.col + 1] == NOCHAR)) 910 && line->t[screen.cur.col + 1] == NOCHAR)
911 ))
912 scr_kill_char (*line, screen.cur.col);
913
914 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
915
916 // if the character doesn't fit into the remaining columns...
917 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
897 { 918 {
898 int col = screen.cur.col; 919 // ... artificially enlargen the previous one
899
900 // find begin
901 while (col > 0 && line->t[col] == NOCHAR)
902 col--;
903
904 rend_t rend = SET_FONT (line->r[col], FONTSET (line->r[col])->find_font (' '));
905
906 // found begin, nuke
907 do {
908 line->t[col] = ' ';
909 line->r[col] = rend;
910 col++;
911 } while (col < ncol && line->t[col] == NOCHAR);
912 }
913
914 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
915
916 // if the character doesn't fit into the remaining columns...
917 if (screen.cur.col > ncol - width && ncol >= width)
918 {
919 // ...output spaces
920 c = ' '; 920 c = NOCHAR;
921 // and try the same character next loop iteration 921 // and try the same character next loop iteration
922 --str; 922 --str;
923 } 923 }
924 924
925 line->touch (); 925 line->touch ();
927 do 927 do
928 { 928 {
929 line->t[screen.cur.col] = c; 929 line->t[screen.cur.col] = c;
930 line->r[screen.cur.col] = rend; 930 line->r[screen.cur.col] = rend;
931 931
932 if (screen.cur.col < ncol - 1) 932 if (expect_true (screen.cur.col < ncol - 1))
933 screen.cur.col++; 933 screen.cur.col++;
934 else 934 else
935 { 935 {
936 line->l = ncol; 936 line->l = ncol;
937 if (screen.flags & Screen_Autowrap) 937 if (screen.flags & Screen_Autowrap)
939 break; 939 break;
940 } 940 }
941 941
942 c = NOCHAR; 942 c = NOCHAR;
943 } 943 }
944 while (--width > 0); 944 while (expect_false (--width > 0));
945 945
946 // pad with spaces when overwriting wide character with smaller one 946 // pad with spaces when overwriting wide character with smaller one
947 if (!width) 947 if (expect_false (!width))
948 { 948 {
949 line->touch (); 949 line->touch ();
950 950
951 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) 951 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
952 { 952 {
953 line->t[c] = ' '; 953 line->t[c] = ' ';
954 line->r[c] = rend; 954 line->r[c] = rend;
955 } 955 }
956 } 956 }
957 } 957 }
958#if ENABLE_COMBINING
958 else // width == 0 959 else // width == 0
959 { 960 {
960#if ENABLE_COMBINING 961 if (c != 0xfeff) // ignore BOM
961 // handle combining characters
962 // we just tag the accent on the previous on-screen character.
963 // this is arguably not correct, but also arguably not wrong.
964 // we don't handle double-width characters nicely yet.
965 line_t *linep;
966 text_t *tp;
967 rend_t *rp;
968
969 if (screen.cur.col > 0)
970 { 962 {
963 // handle combining characters
964 // we just tag the accent on the previous on-screen character.
965 // this is arguably not correct, but also arguably not wrong.
966 // we don't handle double-width characters nicely yet.
967 line_t *linep;
968 text_t *tp;
969 rend_t *rp;
970
971 if (screen.cur.col > 0)
972 {
971 linep = line; 973 linep = line;
972 tp = line->t + screen.cur.col - 1; 974 tp = line->t + screen.cur.col - 1;
973 rp = line->r + screen.cur.col - 1; 975 rp = line->r + screen.cur.col - 1;
976 }
977 else if (screen.cur.row > 0
978 && ROW(screen.cur.row - 1).is_longer ())
979 {
980 linep = &ROW(screen.cur.row - 1);
981 tp = line->t + ncol - 1;
982 rp = line->r + ncol - 1;
983 }
984 else
985 continue;
986
987 linep->touch ();
988
989 while (*tp == NOCHAR && tp > linep->t)
990 tp--, rp--;
991
992 // first try to find a precomposed character
993 unicode_t n = rxvt_compose (*tp, c);
994 if (n == NOCHAR)
995 n = rxvt_composite.compose (*tp, c);
996
997 *tp = n;
998 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
974 } 999 }
975 else if (screen.cur.row > 0
976 && ROW(screen.cur.row - 1).is_longer ())
977 {
978 linep = &ROW(screen.cur.row - 1);
979 tp = line->t + ncol - 1;
980 rp = line->r + ncol - 1;
981 } 1000 }
982 else
983 continue;
984
985 linep->touch ();
986
987 while (*tp == NOCHAR && tp > linep->t)
988 tp--, rp--;
989
990 // first try to find a precomposed character
991 unicode_t n = rxvt_compose (*tp, c);
992 if (n == NOCHAR)
993 n = rxvt_composite.compose (*tp, c);
994
995 *tp = n;
996 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
997#endif 1001#endif
998 }
999 } 1002 }
1000 1003
1001 max_it (line->l, screen.cur.col); 1004 max_it (line->l, screen.cur.col);
1002 1005
1003#ifdef DEBUG_STRICT 1006#ifdef DEBUG_STRICT
1011 * XTERM_SEQ: CTRL-H 1014 * XTERM_SEQ: CTRL-H
1012 */ 1015 */
1013void 1016void
1014rxvt_term::scr_backspace () NOTHROW 1017rxvt_term::scr_backspace () NOTHROW
1015{ 1018{
1016 want_refresh = 1;
1017
1018 if (screen.cur.col == 0) 1019 if (screen.cur.col == 0)
1019 { 1020 {
1020 if (screen.cur.row > 0) 1021 if (screen.cur.row > 0)
1021 { 1022 {
1022#ifdef TERMCAP_HAS_BW 1023#ifdef TERMCAP_HAS_BW
1023 screen.cur.col = ncol - 1; 1024 screen.cur.col = ncol - 1;
1024 screen.cur.row--; 1025 --screen.cur.row;
1025 return; 1026
1027 want_refresh = 1;
1026#endif 1028#endif
1027 } 1029 }
1028 } 1030 }
1029 else if (!(screen.flags & Screen_WrapNext)) 1031 else
1030 scr_gotorc (0, -1, RELATIVE); 1032 scr_gotorc (0, -1, RELATIVE);
1031
1032 screen.flags &= ~Screen_WrapNext;
1033} 1033}
1034 1034
1035/* ------------------------------------------------------------------------- */ 1035/* ------------------------------------------------------------------------- */
1036/* 1036/*
1037 * Process Horizontal Tab 1037 * Process Horizontal Tab
1060 x = i; 1060 x = i;
1061 1061
1062 if (!--count) 1062 if (!--count)
1063 break; 1063 break;
1064 } 1064 }
1065 else 1065 else
1066 ht &= l.t[i] == ' ' 1066 ht &= l.t[i] == ' '
1067 && RS_SAME (l.r[i], base_rend); 1067 && RS_SAME (l.r[i], base_rend);
1068 1068
1069 if (count) 1069 if (count)
1070 x = ncol - 1; 1070 x = ncol - 1;
1186 } 1186 }
1187 } 1187 }
1188 else 1188 else
1189 { 1189 {
1190 if (screen.flags & Screen_Relative) 1190 if (screen.flags & Screen_Relative)
1191 {
1191 { /* relative origin mode */ 1192 /* relative origin mode */
1192 screen.cur.row = row + screen.tscroll; 1193 screen.cur.row = row + screen.tscroll;
1193 min_it (screen.cur.row, screen.bscroll); 1194 min_it (screen.cur.row, screen.bscroll);
1194 } 1195 }
1195 else 1196 else
1196 screen.cur.row = row; 1197 screen.cur.row = row;
1229/* 1230/*
1230 * Erase part or whole of a line 1231 * Erase part or whole of a line
1231 * XTERM_SEQ: Clear line to right: ESC [ 0 K 1232 * XTERM_SEQ: Clear line to right: ESC [ 0 K
1232 * XTERM_SEQ: Clear line to left : ESC [ 1 K 1233 * XTERM_SEQ: Clear line to left : ESC [ 1 K
1233 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1234 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1235 * extension: clear to right unless wrapped: ESC [ 3 K
1234 */ 1236 */
1235void 1237void
1236rxvt_term::scr_erase_line (int mode) NOTHROW 1238rxvt_term::scr_erase_line (int mode) NOTHROW
1237{ 1239{
1238 unsigned int col, num; 1240 unsigned int col, num;
1247 line.touch (); 1249 line.touch ();
1248 line.is_longer (0); 1250 line.is_longer (0);
1249 1251
1250 switch (mode) 1252 switch (mode)
1251 { 1253 {
1254 case 3:
1255 if (screen.flags & Screen_WrapNext)
1256 return;
1257
1258 /* fall through */
1259
1252 case 0: /* erase to end of line */ 1260 case 0: /* erase to end of line */
1253 col = screen.cur.col; 1261 col = screen.cur.col;
1254 num = ncol - col; 1262 num = ncol - col;
1255 min_it (line.l, col); 1263 min_it (line.l, col);
1264
1256 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1265 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1257 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1266 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1258 CLEAR_SELECTION (); 1267 CLEAR_SELECTION ();
1259 break; 1268 break;
1269
1260 case 1: /* erase to beginning of line */ 1270 case 1: /* erase to beginning of line */
1261 col = 0; 1271 col = 0;
1262 num = screen.cur.col + 1; 1272 num = screen.cur.col + 1;
1273
1263 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur) 1274 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur)
1264 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur)) 1275 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur))
1265 CLEAR_SELECTION (); 1276 CLEAR_SELECTION ();
1266 break; 1277 break;
1278
1267 case 2: /* erase whole line */ 1279 case 2: /* erase whole line */
1268 col = 0; 1280 col = 0;
1269 num = ncol; 1281 num = ncol;
1270 line.l = 0; 1282 line.l = 0;
1271 if (selection.beg.row <= screen.cur.row 1283 if (selection.beg.row <= screen.cur.row
1329 if (row >= nrow) /* Out Of Bounds */ 1341 if (row >= nrow) /* Out Of Bounds */
1330 return; 1342 return;
1331 1343
1332 min_it (num, nrow - row); 1344 min_it (num, nrow - row);
1333 1345
1346 /*TODO: the xlceararea/xfillrectangle below don't take scroll offste into account, ask mikachu for details */
1334 if (rstyle & (RS_RVid | RS_Uline)) 1347 if (rstyle & (RS_RVid | RS_Uline))
1335 ren = (rend_t) ~RS_None; 1348 ren = (rend_t) ~RS_None;
1336 else if (GET_BASEBG (rstyle) == Color_bg) 1349 else if (GET_BASEBG (rstyle) == Color_bg)
1337 { 1350 {
1338 ren = DEFAULT_RSTYLE; 1351 ren = DEFAULT_RSTYLE;
1339 CLEAR_ROWS (row, num); 1352
1353 if (mapped)
1354 XClearArea (dpy, vt, 0,
1355 Row2Pixel (row), (unsigned int)width,
1356 (unsigned int)Height2Pixel (num), False);
1340 } 1357 }
1341 else 1358 else
1342 { 1359 {
1343 ren = rstyle & (RS_fgMask | RS_bgMask); 1360 ren = rstyle & (RS_fgMask | RS_bgMask);
1361
1344 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1362 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1345 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1363 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1346 ERASE_ROWS (row, num); 1364 XFillRectangle (dpy, vt, gc,
1365 0, Row2Pixel (row),
1366 (unsigned int)width,
1367 (unsigned int)Height2Pixel (num));
1347 gcvalue.foreground = pix_colors[Color_fg]; 1368 gcvalue.foreground = pix_colors[Color_fg];
1348 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1369 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1349 } 1370 }
1350 1371
1351 for (; num--; row++) 1372 for (; num--; row++)
1433 * Insert/Delete <count> characters from the current position 1454 * Insert/Delete <count> characters from the current position
1434 */ 1455 */
1435void 1456void
1436rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW 1457rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW
1437{ 1458{
1438 int col, row;
1439 rend_t tr;
1440
1441 want_refresh = 1; 1459 want_refresh = 1;
1442 ZERO_SCROLLBACK (); 1460 ZERO_SCROLLBACK ();
1443 1461
1444 if (count <= 0) 1462 if (count <= 0)
1445 return; 1463 return;
1447 scr_do_wrap (); 1465 scr_do_wrap ();
1448 1466
1449 selection_check (1); 1467 selection_check (1);
1450 min_it (count, ncol - screen.cur.col); 1468 min_it (count, ncol - screen.cur.col);
1451 1469
1452 row = screen.cur.row; 1470 int row = screen.cur.row;
1453 1471
1454 line_t *line = &ROW(row); 1472 line_t *line = &ROW(row);
1455 1473
1456 line->touch (); 1474 line->touch ();
1457 line->is_longer (0); 1475 line->is_longer (0);
1458 1476
1477 // nuke wide spanning the start
1478 if (line->t[screen.cur.col] == NOCHAR)
1479 scr_kill_char (*line, screen.cur.col);
1480
1459 switch (insdel) 1481 switch (insdel)
1460 { 1482 {
1461 case INSERT: 1483 case INSERT:
1462 for (col = ncol - 1; (col - count) >= screen.cur.col; col--) 1484 line->l = min (line->l + count, ncol);
1485
1486 if (line->t[screen.cur.col] == NOCHAR)
1487 scr_kill_char (*line, screen.cur.col);
1488
1489 for (int col = ncol - 1; (col - count) >= screen.cur.col; col--)
1463 { 1490 {
1464 line->t[col] = line->t[col - count]; 1491 line->t[col] = line->t[col - count];
1465 line->r[col] = line->r[col - count]; 1492 line->r[col] = line->r[col - count];
1466 } 1493 }
1467
1468 line->l = min (line->l + count, ncol);
1469 1494
1470 if (selection.op && current_screen == selection.screen 1495 if (selection.op && current_screen == selection.screen
1471 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1496 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1472 { 1497 {
1473 if (selection.end.row != screen.cur.row 1498 if (selection.end.row != screen.cur.row
1474 || (selection.end.col + count >= ncol)) 1499 || (selection.end.col + count >= ncol))
1475 CLEAR_SELECTION (); 1500 CLEAR_SELECTION ();
1476 else 1501 else
1502 {
1477 { /* shift selection */ 1503 /* shift selection */
1478 selection.beg.col += count; 1504 selection.beg.col += count;
1479 selection.mark.col += count; /* XXX: yes? */ 1505 selection.mark.col += count; /* XXX: yes? */
1480 selection.end.col += count; 1506 selection.end.col += count;
1481 } 1507 }
1482 } 1508 }
1487 case ERASE: 1513 case ERASE:
1488 screen.cur.col += count; /* don't worry if > ncol */ 1514 screen.cur.col += count; /* don't worry if > ncol */
1489 selection_check (1); 1515 selection_check (1);
1490 screen.cur.col -= count; 1516 screen.cur.col -= count;
1491 1517
1492 line->l = max (line->l - count, 0); 1518 // nuke wide char after the end
1519 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1520 scr_kill_char (*line, screen.cur.col + count);
1521
1493 scr_blank_line (*line, screen.cur.col, count, rstyle); 1522 scr_blank_line (*line, screen.cur.col, count, rstyle);
1494 break; 1523 break;
1495 1524
1496 case DELETE: 1525 case DELETE:
1497 tr = line->r[ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask); 1526 line->l = max (line->l - count, 0);
1498 1527
1528 // nuke wide char spanning the end
1529 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1530 scr_kill_char (*line, screen.cur.col + count);
1531
1499 for (col = screen.cur.col; (col + count) < ncol; col++) 1532 for (int col = screen.cur.col; (col + count) < ncol; col++)
1500 { 1533 {
1501 line->t[col] = line->t[col + count]; 1534 line->t[col] = line->t[col + count];
1502 line->r[col] = line->r[col + count]; 1535 line->r[col] = line->r[col + count];
1503 } 1536 }
1504 1537
1505 line->l = max (line->l - count, 0);
1506 scr_blank_line (*line, ncol - count, count, tr); 1538 scr_blank_line (*line, ncol - count, count,
1539 line->r[ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask));
1507 1540
1508 if (selection.op && current_screen == selection.screen 1541 if (selection.op && current_screen == selection.screen
1509 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1542 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1510 { 1543 {
1511 if (selection.end.row != screen.cur.row 1544 if (selection.end.row != screen.cur.row
1621 */ 1654 */
1622void 1655void
1623rxvt_term::scr_set_tab (int mode) NOTHROW 1656rxvt_term::scr_set_tab (int mode) NOTHROW
1624{ 1657{
1625 if (mode < 0) 1658 if (mode < 0)
1626 memset (tabs, 0, ncol * sizeof (char)); 1659 memset (tabs, 0, ncol);
1627 else if (screen.cur.col < ncol) 1660 else if (screen.cur.col < ncol)
1628 tabs [screen.cur.col] = !!mode; 1661 tabs [screen.cur.col] = !!mode;
1629} 1662}
1630 1663
1631/* ------------------------------------------------------------------------- */ 1664/* ------------------------------------------------------------------------- */
1866 return true; 1899 return true;
1867} 1900}
1868 1901
1869#ifndef NO_BELL 1902#ifndef NO_BELL
1870void 1903void
1871rxvt_term::bell_cb (time_watcher &w) 1904rxvt_term::bell_cb (ev::timer &w, int revents)
1872{ 1905{
1873 rvideo_bell = false; 1906 rvideo_bell = false;
1874 scr_rvideo_mode (rvideo_mode); 1907 scr_rvideo_mode (rvideo_mode);
1908 refresh_check ();
1875} 1909}
1876#endif 1910#endif
1877 1911
1878/* ------------------------------------------------------------------------- */ 1912/* ------------------------------------------------------------------------- */
1879void 1913void
1885# ifdef MAPALERT_OPTION 1919# ifdef MAPALERT_OPTION
1886 if (option (Opt_mapAlert)) 1920 if (option (Opt_mapAlert))
1887# endif 1921# endif
1888 XMapWindow (dpy, parent[0]); 1922 XMapWindow (dpy, parent[0]);
1889# endif 1923# endif
1924
1890# if ENABLE_FRILLS 1925# if ENABLE_FRILLS
1891 if (option (Opt_urgentOnBell)) 1926 if (option (Opt_urgentOnBell))
1892 { 1927 set_urgency (1);
1893 XWMHints *h;
1894
1895 h = XGetWMHints(dpy, parent[0]);
1896 if (h != NULL)
1897 {
1898 h->flags |= XUrgencyHint;
1899 XSetWMHints(dpy, parent[0], h);
1900 }
1901 }
1902# endif 1928# endif
1903 1929
1904 if (option (Opt_visualBell)) 1930 if (option (Opt_visualBell))
1905 { 1931 {
1906 rvideo_bell = true; 1932 rvideo_bell = true;
1907 scr_rvideo_mode (rvideo_mode); 1933 scr_rvideo_mode (rvideo_mode);
1908 display->flush (); 1934 flush ();
1909 1935
1910 bell_ev.start (NOW + VISUAL_BELL_DURATION); 1936 bell_ev.start (VISUAL_BELL_DURATION);
1911 } 1937 }
1912 else 1938 else
1913 XBell (dpy, 0); 1939 XBell (dpy, 0);
1914#endif 1940#endif
1915} 1941}
1919void 1945void
1920rxvt_term::scr_printscreen (int fullhist) NOTHROW 1946rxvt_term::scr_printscreen (int fullhist) NOTHROW
1921{ 1947{
1922#ifdef PRINTPIPE 1948#ifdef PRINTPIPE
1923 int nrows, row_start; 1949 int nrows, row_start;
1924 FILE *fd; 1950 FILE *fd = popen_printer ();
1925 1951
1926 if ((fd = popen_printer ()) == NULL) 1952 if (!fd)
1927 return; 1953 return;
1928 1954
1929 if (fullhist) 1955 if (fullhist)
1930 { 1956 {
1931 nrows = nrow - top_row; 1957 nrows = nrow - top_row;
1996 return; 2022 return;
1997 2023
1998 /* 2024 /*
1999 * A: set up vars 2025 * A: set up vars
2000 */ 2026 */
2027 refresh_count = 0;
2028
2001 have_bg = 0; 2029 have_bg = 0;
2002 refresh_count = 0;
2003
2004#ifdef HAVE_BG_PIXMAP 2030#ifdef HAVE_BG_PIXMAP
2005 have_bg |= bgPixmap.pixmap != None; 2031 have_bg = bgPixmap.pixmap != None;
2006#endif 2032#endif
2007 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2033 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
2008 2034
2009 /* 2035 /*
2010 * B: reverse any characters which are selected 2036 * B: reverse any characters which are selected
2201 continue; 2227 continue;
2202 2228
2203 // redraw one or more characters 2229 // redraw one or more characters
2204 2230
2205 // seek to the beginning of wide characters 2231 // seek to the beginning of wide characters
2206 while (stp[col] == NOCHAR && col > 0) 2232 while (expect_false (stp[col] == NOCHAR && col > 0))
2207 --col; 2233 --col;
2208 2234
2209 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2235 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2210 text_t *text = stp + col; 2236 text_t *text = stp + col;
2211 int count = 1; 2237 int count = 1;
2248 2274
2249 col--; /* went one too far. move back */ 2275 col--; /* went one too far. move back */
2250 count -= i; /* dump any matching trailing chars */ 2276 count -= i; /* dump any matching trailing chars */
2251 2277
2252 // sometimes we optimize away the trailing NOCHAR's, add them back 2278 // sometimes we optimize away the trailing NOCHAR's, add them back
2253 while (i && text[count] == NOCHAR) 2279 while (expect_false (i && text[count] == NOCHAR))
2254 count++, i--; 2280 count++, i--;
2255 2281
2256 /* 2282 /*
2257 * Determine the attributes for the string 2283 * Determine the attributes for the string
2258 */ 2284 */
2259 int fore = fgcolor_of (rend); // desired foreground 2285 int fore = fgcolor_of (rend); // desired foreground
2260 int back = bgcolor_of (rend); // desired background 2286 int back = bgcolor_of (rend); // desired background
2261 2287
2262 // only do special processing if any attributes are set, which is unlikely 2288 // only do special processing if any attributes are set, which is unlikely
2263 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2289 if (expect_false (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)))
2264 { 2290 {
2265 bool invert = rend & RS_RVid; 2291 bool invert = rend & RS_RVid;
2266 2292
2267#ifndef NO_BOLD_UNDERLINE_REVERSE 2293#ifndef NO_BOLD_UNDERLINE_REVERSE
2268 if (rend & RS_Bold
2269 && fore == Color_fg) 2294 if (rend & RS_Bold && fore == Color_fg)
2270 { 2295 {
2271 if (ISSET_PIXCOLOR (Color_BD)) 2296 if (ISSET_PIXCOLOR (Color_BD))
2272 fore = Color_BD; 2297 fore = Color_BD;
2273# if !ENABLE_STYLES 2298# if !ENABLE_STYLES
2274 else 2299 else
2275 invert = !invert; 2300 invert = !invert;
2276# endif 2301# endif
2277 } 2302 }
2278 2303
2279 if (rend & RS_Italic 2304 if (rend & RS_Italic && fore == Color_fg)
2280 && fore == Color_fg)
2281 { 2305 {
2282 if (ISSET_PIXCOLOR (Color_IT)) 2306 if (ISSET_PIXCOLOR (Color_IT))
2283 fore = Color_IT; 2307 fore = Color_IT;
2284# if !ENABLE_STYLES 2308# if !ENABLE_STYLES
2285 else 2309 else
2319 } 2343 }
2320 2344
2321#ifdef TEXT_BLINK 2345#ifdef TEXT_BLINK
2322 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg)) 2346 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg))
2323 { 2347 {
2324 if (!text_blink_ev.active) 2348 if (!text_blink_ev.is_active ())
2325 { 2349 {
2326 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2350 text_blink_ev.again ();
2327 hidden_text = 0; 2351 hidden_text = 0;
2328 } 2352 }
2329 else if (hidden_text) 2353 else if (hidden_text)
2330 fore = back; 2354 fore = back;
2331 } 2355 }
2353 /* 2377 /*
2354 * Actually do the drawing of the string here 2378 * Actually do the drawing of the string here
2355 */ 2379 */
2356 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2380 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2357 2381
2358 if (have_bg && back == Color_bg) 2382 if (expect_true (have_bg && back == Color_bg))
2359 { 2383 {
2360 // this is very ugly, maybe push it into ->draw? 2384 // this is very ugly, maybe push it into ->draw?
2361 2385
2362 for (i = 0; i < count; i++) /* don't draw empty strings */ 2386 for (i = 0; i < count; i++) /* don't draw empty strings */
2363 if (text[i] != ' ') 2387 if (text[i] != ' ')
2370 did_clear: ; 2394 did_clear: ;
2371 } 2395 }
2372 else 2396 else
2373 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2397 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2374 2398
2375 if (rend & RS_Uline && font->descent > 1 && fore != back) 2399 if (expect_false (rend & RS_Uline && font->descent > 1 && fore != back))
2376 { 2400 {
2377#if ENABLE_FRILLS 2401#if ENABLE_FRILLS
2378 if (ISSET_PIXCOLOR (Color_underline)) 2402 if (ISSET_PIXCOLOR (Color_underline))
2379 XSetForeground (dpy, gc, pix_colors[Color_underline]); 2403 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2380 else 2404 else
2381#endif 2405#endif
2382 XSetForeground (dpy, gc, pix_colors[fore]); 2406 XSetForeground (dpy, gc, pix_colors[fore]);
2383 2407
2384 XDrawLine (dpy, drawBuffer, gc, 2408 XDrawLine (dpy, vt, gc,
2385 xpixel, ypixel + font->ascent + 1, 2409 xpixel, ypixel + font->ascent + 1,
2386 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2410 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2387 } 2411 }
2388 } /* for (col....) */ 2412 } /* for (col....) */
2389 } /* for (row....) */ 2413 } /* for (row....) */
2427 XSetForeground (dpy, gc, pix_colors[Color_cursor]); 2451 XSetForeground (dpy, gc, pix_colors[Color_cursor]);
2428 else 2452 else
2429#endif 2453#endif
2430 XSetForeground (dpy, gc, pix_colors[ccol1]); 2454 XSetForeground (dpy, gc, pix_colors[ccol1]);
2431 2455
2432 XDrawRectangle (dpy, drawBuffer, gc, 2456 XDrawRectangle (dpy, vt, gc,
2433 Col2Pixel (col), 2457 Col2Pixel (col),
2434 Row2Pixel (oldcursor.row), 2458 Row2Pixel (oldcursor.row),
2435 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2459 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2436 (unsigned int) (Height2Pixel (1) - lineSpace - 1)); 2460 (unsigned int) (Height2Pixel (1) - lineSpace - 1));
2437 } 2461 }
2475rxvt_term::scr_recolour () NOTHROW 2499rxvt_term::scr_recolour () NOTHROW
2476{ 2500{
2477#ifdef HAVE_BG_PIXMAP 2501#ifdef HAVE_BG_PIXMAP
2478 bgPixmap.apply (); 2502 bgPixmap.apply ();
2479#else 2503#else
2504
2480 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]); 2505 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]);
2481 XClearWindow (dpy, parent[0]); 2506 XClearWindow (dpy, parent[0]);
2482 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 2507 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2483# if HAVE_SCROLLBARS 2508
2484 if (scrollBar.win) 2509 if (scrollBar.win)
2485 { 2510 {
2486 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); 2511 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2487 scrollBar.setIdle (); 2512 scrollBar.state = STATE_IDLE;
2488 scrollbar_show (0); 2513 scrollBar.show (0);
2489 } 2514 }
2515
2490# endif 2516#endif
2491#endif 2517
2492 2518 /* bgPixmap.apply () does not do the following : */
2493 scr_clear (); 2519 scr_clear ();
2494 scr_touch (true); 2520 scr_touch (true);
2495 want_refresh = 1; 2521 want_refresh = 1;
2496} 2522}
2497 2523
2589{ 2615{
2590 int row, wrote; 2616 int row, wrote;
2591 unsigned int width, towrite; 2617 unsigned int width, towrite;
2592 char r1[] = "\n"; 2618 char r1[] = "\n";
2593 2619
2594 for (row = saveLines - nsaved; 2620 for (row = saveLines + top_row;
2595 row < saveLines + nrow - 1; row++) 2621 row < saveLines + nrow - 1; row++)
2596 { 2622 {
2597 width = row_buf[row].l >= 0 ? row_buf[row].l 2623 width = row_buf[row].l >= 0 ? row_buf[row].l
2598 : ncol; 2624 : ncol;
2599 for (towrite = width; towrite; towrite -= wrote) 2625 for (towrite = width; towrite; towrite -= wrote)
2650 /* convert normal newline chars into common keyboard Return key sequence */ 2676 /* convert normal newline chars into common keyboard Return key sequence */
2651 for (unsigned int i = 0; i < len; i++) 2677 for (unsigned int i = 0; i < len; i++)
2652 if (data[i] == C0_LF) 2678 if (data[i] == C0_LF)
2653 data[i] = C0_CR; 2679 data[i] = C0_CR;
2654 2680
2681 if (priv_modes & PrivMode_BracketPaste)
2682 tt_printf ("\e[200~");
2683
2655 tt_write (data, len); 2684 tt_write (data, len);
2685
2686 if (priv_modes & PrivMode_BracketPaste)
2687 tt_printf ("\e[201~");
2656} 2688}
2657 2689
2658/* ------------------------------------------------------------------------- */ 2690/* ------------------------------------------------------------------------- */
2659/* 2691/*
2660 * Respond to a notification that a primary selection has been sent 2692 * Respond to a notification that a primary selection has been sent
2735 if (!delete_prop) 2767 if (!delete_prop)
2736 XDeleteProperty (dpy, win, prop); 2768 XDeleteProperty (dpy, win, prop);
2737 2769
2738 selection_wait = Sel_incr; 2770 selection_wait = Sel_incr;
2739 incr_buf_fill = 0; 2771 incr_buf_fill = 0;
2740 incr_ev.start (NOW + 10); 2772 incr_ev.start (10);
2741 2773
2742 goto bailout; 2774 goto bailout;
2743 } 2775 }
2744 2776
2745 if (ct.nitems == 0) 2777 if (ct.nitems == 0)
2754 ct.nitems = incr_buf_fill; 2786 ct.nitems = incr_buf_fill;
2755 incr_buf = 0; 2787 incr_buf = 0;
2756 incr_buf_size = 0; 2788 incr_buf_size = 0;
2757 incr_ev.stop (); 2789 incr_ev.stop ();
2758 } 2790 }
2759 else 2791 else
2760 { 2792 {
2761 if (selection_wait == Sel_normal 2793 if (selection_wait == Sel_normal
2762 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2794 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2763 { 2795 {
2764 /* 2796 /*
2771 goto bailout; 2803 goto bailout;
2772 } 2804 }
2773 } 2805 }
2774 else if (selection_wait == Sel_incr) 2806 else if (selection_wait == Sel_incr)
2775 { 2807 {
2776 incr_ev.start (NOW + 10); 2808 incr_ev.start (10);
2777 2809
2778 while (incr_buf_fill + ct.nitems > incr_buf_size) 2810 while (incr_buf_fill + ct.nitems > incr_buf_size)
2779 { 2811 {
2780 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024; 2812 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2781 incr_buf = (char *)realloc (incr_buf, incr_buf_size); 2813 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2821 if (selection_wait == Sel_normal) 2853 if (selection_wait == Sel_normal)
2822 selection_wait = Sel_none; 2854 selection_wait = Sel_none;
2823} 2855}
2824 2856
2825void 2857void
2826rxvt_term::incr_cb (time_watcher &w) NOTHROW 2858rxvt_term::incr_cb (ev::timer &w, int revents) NOTHROW
2827{ 2859{
2828 selection_wait = Sel_none; 2860 selection_wait = Sel_none;
2829 2861
2830 incr_buf_size = 0; 2862 incr_buf_size = 0;
2831 free (incr_buf); 2863 free (incr_buf);
2842 selection_paste (win, prop, true); 2874 selection_paste (win, prop, true);
2843} 2875}
2844 2876
2845/* ------------------------------------------------------------------------- */ 2877/* ------------------------------------------------------------------------- */
2846/* 2878/*
2847 * Request the current selection: 2879 * Request the current selection:
2848 * Order: > internal selection if available 2880 * Order: > internal selection if available
2849 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+) 2881 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+)
2850 * > CUT_BUFFER0 2882 * > CUT_BUFFER0
2851 * (+) if ownership is claimed but property is empty, rxvt_selection_paste () 2883 * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
2852 * will auto fallback to CUT_BUFFER0 2884 * will auto fallback to CUT_BUFFER0
2854 */ 2886 */
2855void 2887void
2856rxvt_term::selection_request (Time tm, int selnum) NOTHROW 2888rxvt_term::selection_request (Time tm, int selnum) NOTHROW
2857{ 2889{
2858 if (selection.text && selnum == Sel_Primary) 2890 if (selection.text && selnum == Sel_Primary)
2891 {
2859 { /* internal selection */ 2892 /* internal selection */
2860 char *str = rxvt_wcstombs (selection.text, selection.len); 2893 char *str = rxvt_wcstombs (selection.text, selection.len);
2861 paste (str, strlen (str)); 2894 paste (str, strlen (str));
2862 free (str); 2895 free (str);
2863 return; 2896 return;
2864 } 2897 }
3130 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); 3163 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1);
3131 3164
3132 while (selection.mark.col > 0 3165 while (selection.mark.col > 0
3133 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) 3166 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3134 --selection.mark.col; 3167 --selection.mark.col;
3135 3168
3136 if (selection.op) 3169 if (selection.op)
3170 {
3137 { /* clear the old selection */ 3171 /* clear the old selection */
3138 selection.beg.row = selection.end.row = selection.mark.row; 3172 selection.beg.row = selection.end.row = selection.mark.row;
3139 selection.beg.col = selection.end.col = selection.mark.col; 3173 selection.beg.col = selection.end.col = selection.mark.col;
3140 } 3174 }
3141 3175
3142 selection.op = SELECTION_INIT; 3176 selection.op = SELECTION_INIT;
3331 * a point/word/line which is either the start or end of the selection 3365 * a point/word/line which is either the start or end of the selection
3332 * and it was decided by whichever point/word/line was `fixed' at the 3366 * and it was decided by whichever point/word/line was `fixed' at the
3333 * time of the most recent button3 press 3367 * time of the most recent button3 press
3334 */ 3368 */
3335 if (button3 && buttonpress) 3369 if (button3 && buttonpress)
3370 {
3336 { /* button3 press */ 3371 /* button3 press */
3337 /* 3372 /*
3338 * first determine which edge of the selection we are closest to 3373 * first determine which edge of the selection we are closest to
3339 */ 3374 */
3340 if (ROWCOL_IS_BEFORE (pos, selection.beg) 3375 if (ROWCOL_IS_BEFORE (pos, selection.beg)
3341 || (!ROWCOL_IS_AFTER (pos, selection.end) 3376 || (!ROWCOL_IS_AFTER (pos, selection.end)
3359 selection.mark.row = selection.beg.row; 3394 selection.mark.row = selection.beg.row;
3360 selection.mark.col = selection.beg.col; 3395 selection.mark.col = selection.beg.col;
3361 } 3396 }
3362 } 3397 }
3363 else 3398 else
3399 {
3364 { /* button1 drag or button3 drag */ 3400 /* button1 drag or button3 drag */
3365 if (ROWCOL_IS_AFTER (selection.mark, pos)) 3401 if (ROWCOL_IS_AFTER (selection.mark, pos))
3366 { 3402 {
3367 if (selection.mark.row == selection.end.row 3403 if (selection.mark.row == selection.end.row
3368 && selection.mark.col == selection.end.col 3404 && selection.mark.col == selection.end.col
3369 && clickchange 3405 && clickchange
3450 selection.end.row++; 3486 selection.end.row++;
3451 } 3487 }
3452 } 3488 }
3453 3489
3454 if (button3 && buttonpress) 3490 if (button3 && buttonpress)
3491 {
3455 { /* mark may need to be changed */ 3492 /* mark may need to be changed */
3456 if (closeto == LEFT) 3493 if (closeto == LEFT)
3457 { 3494 {
3458 selection.mark.row = selection.end.row; 3495 selection.mark.row = selection.end.row;
3459 selection.mark.col = selection.end.col - (selection.clicks == 2); 3496 selection.mark.col = selection.end.col - (selection.clicks == 2);
3460 } 3497 }
3659 XFree (ct.value); 3696 XFree (ct.value);
3660 } 3697 }
3661 3698
3662 XSendEvent (dpy, rq.requestor, False, 0L, (XEvent *)&ev); 3699 XSendEvent (dpy, rq.requestor, False, 0L, (XEvent *)&ev);
3663} 3700}
3664
3665/* ------------------------------------------------------------------------- *
3666 * MOUSE ROUTINES *
3667 * ------------------------------------------------------------------------- */
3668
3669/*
3670 * return col/row values corresponding to x/y pixel values
3671 */
3672void
3673rxvt_term::pixel_position (int *x, int *y) NOTHROW
3674{
3675 *x = Pixel2Col (*x);
3676 /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */
3677 *y = Pixel2Row (*y);
3678 /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */
3679}
3680 3701
3681/* ------------------------------------------------------------------------- */ 3702/* ------------------------------------------------------------------------- */
3682#ifdef USE_XIM 3703#ifdef USE_XIM
3683void 3704void
3684rxvt_term::im_set_position (XPoint &pos) NOTHROW 3705rxvt_term::im_set_position (XPoint &pos) NOTHROW

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines