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.293 by root, Mon Dec 24 08:00:18 2007 UTC vs.
Revision 1.349 by root, Thu Oct 14 23:12:11 2010 UTC

28#include "rxvt.h" /* NECESSARY */ 28#include "rxvt.h" /* NECESSARY */
29#include "rxvtperl.h" /* NECESSARY */ 29#include "rxvtperl.h" /* NECESSARY */
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 separate compile!
34 34
35static inline void
35static inline void fill_text (text_t *start, text_t value, int len) 36fill_text (text_t *start, text_t value, int len)
36{ 37{
37 while (len--) 38 while (len--)
38 *start++ = value; 39 *start++ = value;
39} 40}
40 41
83 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col) 84 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) \ 85#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) 86 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col)
86 87
87/* 88/*
88 * CLEAR_ROWS : clear <num> rows starting from row <row>
89 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 89 * 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 */ 90 */
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) \ 91#define CLEAR_CHARS(x, y, num) \
101 if (mapped) \ 92 if (mapped) \
102 XClearArea (dpy, drawBuffer, x, y, \ 93 XClearArea (dpy, vt, x, y, \
103 (unsigned int)Width2Pixel (num), \ 94 (unsigned int)Width2Pixel (num), \
104 (unsigned int)Height2Pixel (1), False) 95 (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 96
112/* ------------------------------------------------------------------------- * 97/* ------------------------------------------------------------------------- *
113 * SCREEN `COMMON' ROUTINES * 98 * SCREEN `COMMON' ROUTINES *
114 * ------------------------------------------------------------------------- */ 99 * ------------------------------------------------------------------------- */
115 100
148 133
149 l.l = 0; 134 l.l = 0;
150 l.f = 0; 135 l.f = 0;
151} 136}
152 137
138// nuke a single wide character at the given column
139void
140rxvt_term::scr_kill_char (line_t &l, int col) const NOTHROW
141{
142 // find begin
143 while (col > 0 && l.t[col] == NOCHAR)
144 col--;
145
146 rend_t rend = l.r[col] & ~RS_baseattrMask;
147 rend = SET_FONT (rend, FONTSET (rend)->find_font (' '));
148
149 // found start, nuke
150 do {
151 l.t[col] = ' ';
152 l.r[col] = rend;
153 col++;
154 } while (col < ncol && l.t[col] == NOCHAR);
155}
156
153/* ------------------------------------------------------------------------- * 157/* ------------------------------------------------------------------------- *
154 * SCREEN INITIALISATION * 158 * SCREEN INITIALISATION *
155 * ------------------------------------------------------------------------- */ 159 * ------------------------------------------------------------------------- */
156 160
157void 161void
158rxvt_term::scr_reset () 162rxvt_term::scr_reset ()
159{ 163{
160#if ENABLE_OVERLAY
161 scr_overlay_off ();
162#endif
163
164 rvideo_mode = false;
165 view_start = 0; 164 view_start = 0;
166 num_scr = 0; 165 num_scr = 0;
167 166
168 if (ncol == 0) 167 if (ncol == 0)
169 ncol = 80; 168 ncol = 80;
171 if (nrow == 0) 170 if (nrow == 0)
172 nrow = 24; 171 nrow = 24;
173 172
174 if (ncol == prev_ncol && nrow == prev_nrow) 173 if (ncol == prev_ncol && nrow == prev_nrow)
175 return; 174 return;
176
177 if (current_screen != PRIMARY)
178 scr_swap_screen ();
179 175
180 // we need at least two lines for wrapping to work correctly 176 // we need at least two lines for wrapping to work correctly
181 while (nrow + saveLines < 2) 177 while (nrow + saveLines < 2)
182 { 178 {
183 //TODO//FIXME 179 //TODO//FIXME
236 selection.text = NULL; 232 selection.text = NULL;
237 selection.len = 0; 233 selection.len = 0;
238 selection.op = SELECTION_CLEAR; 234 selection.op = SELECTION_CLEAR;
239 selection.screen = PRIMARY; 235 selection.screen = PRIMARY;
240 selection.clicks = 0; 236 selection.clicks = 0;
237 selection.clip_text = NULL;
238 selection.clip_len = 0;
241 } 239 }
242 else 240 else
243 { 241 {
244 /* 242 /*
245 * add or delete rows as appropriate 243 * add or delete rows as appropriate
283 281
284 if (top_row) 282 if (top_row)
285 { 283 {
286 // Re-wrap lines. This is rather ugly, possibly because I am too dumb 284 // Re-wrap lines. This is rather ugly, possibly because I am too dumb
287 // to come up with a lean and mean algorithm. 285 // to come up with a lean and mean algorithm.
286 // TODO: maybe optimise when width didn't change
288 287
289 row_col_t ocur = screen.cur; 288 row_col_t ocur = screen.cur;
290 ocur.row = MOD (term_start + ocur.row, prev_total_rows); 289 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
291 290
292 do 291 do
293 { 292 {
294 p = MOD (p - 1, prev_total_rows); 293 p = MOD (p - 1, prev_total_rows);
295#ifdef DEBUG_STRICT
296 assert (old_buf [MOD (p, prev_total_rows)].t); 294 assert (old_buf [MOD (p, prev_total_rows)].t);
297#endif
298 int plines = 1; 295 int plines = 1;
299 int llen = old_buf [MOD (p, prev_total_rows)].l; 296 int llen = old_buf [MOD (p, prev_total_rows)].l;
300 297
301 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) 298 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
302 { 299 {
396 delete old_ta; 393 delete old_ta;
397 delete old_ra; 394 delete old_ra;
398 395
399 clamp_it (screen.cur.row, 0, nrow - 1); 396 clamp_it (screen.cur.row, 0, nrow - 1);
400 clamp_it (screen.cur.col, 0, ncol - 1); 397 clamp_it (screen.cur.col, 0, ncol - 1);
398 }
401 399
402 free (tabs); 400 free (tabs);
403 } 401 tabs = (char *)rxvt_malloc (ncol);
402
403 for (int col = ncol; --col; )
404 tabs [col] = col % TABSIZE == 0;
404 405
405 CLEAR_ALL_SELECTION (); 406 CLEAR_ALL_SELECTION ();
406 407
407 prev_nrow = nrow; 408 prev_nrow = nrow;
408 prev_ncol = ncol; 409 prev_ncol = ncol;
409
410 tabs = (char *)rxvt_malloc (ncol);
411
412 for (int col = ncol; --col; )
413 tabs [col] = col % TABSIZE == 0;
414
415 if (current_screen != PRIMARY)
416 scr_swap_screen ();
417 410
418 tt_winch (); 411 tt_winch ();
419 412
420 HOOK_INVOKE ((this, HOOK_RESET, DT_END)); 413 HOOK_INVOKE ((this, HOOK_RESET, DT_END));
421} 414}
433 delete ralloc; ralloc = 0; 426 delete ralloc; ralloc = 0;
434 427
435 free (row_buf); 428 free (row_buf);
436 free (swap_buf); 429 free (swap_buf);
437 free (drawn_buf); 430 free (drawn_buf);
431 row_buf = 0; // signal that we freed all the arrays above
432
438 free (tabs); 433 free (tabs);
439 434 tabs = 0;
440 row_buf = 0; // signal that we freed all the arrays
441 } 435 }
442} 436}
443 437
444/* ------------------------------------------------------------------------- */ 438/* ------------------------------------------------------------------------- */
445/* 439/*
446 * Hard reset 440 * Hard/Soft reset
447 */ 441 */
448void 442void
449rxvt_term::scr_poweron () 443rxvt_term::scr_poweron ()
450{ 444{
451 scr_release (); 445 scr_release ();
452 prev_nrow = prev_ncol = 0; 446 prev_nrow = prev_ncol = 0;
447 rvideo_mode = false;
448 scr_soft_reset ();
453 scr_reset (); 449 scr_reset ();
454 450
455 scr_clear (true); 451 scr_clear (true);
456 scr_refresh (); 452 scr_refresh ();
453}
454
455void
456rxvt_term::scr_soft_reset ()
457{
458 /* only affects modes, nothing drastic such as clearing the screen */
459#if ENABLE_OVERLAY
460 scr_overlay_off ();
461#endif
462
463 if (current_screen != PRIMARY)
464 scr_swap_screen ();
465
466 scr_scroll_region (0, MAX_ROWS - 1);
467 scr_rendition (0, ~RS_None);
468 scr_insert_mode (0);
457} 469}
458 470
459/* ------------------------------------------------------------------------- * 471/* ------------------------------------------------------------------------- *
460 * PROCESS SCREEN COMMANDS * 472 * PROCESS SCREEN COMMANDS *
461 * ------------------------------------------------------------------------- */ 473 * ------------------------------------------------------------------------- */
499 } 511 }
500 512
501 /* boundary check in case screen size changed between SAVE and RESTORE */ 513 /* boundary check in case screen size changed between SAVE and RESTORE */
502 min_it (s->cur.row, nrow - 1); 514 min_it (s->cur.row, nrow - 1);
503 min_it (s->cur.col, ncol - 1); 515 min_it (s->cur.col, ncol - 1);
504#ifdef DEBUG_STRICT
505 assert (s->cur.row >= 0); 516 assert (s->cur.row >= 0);
506 assert (s->cur.col >= 0); 517 assert (s->cur.col >= 0);
507#endif
508} 518}
509 519
510void 520void
511rxvt_term::scr_swap_screen () 521rxvt_term::scr_swap_screen ()
512{ 522{
537 want_refresh = 1; 547 want_refresh = 1;
538 view_start = 0; 548 view_start = 0;
539 549
540 selection_check (2); /* check for boundary cross */ 550 selection_check (2); /* check for boundary cross */
541 551
542 int i = current_screen; current_screen = scrn; scrn = i; 552 current_screen = scrn;
543 553
544#if NSCREENS 554#if NSCREENS
545 if (option (Opt_secondaryScreen)) 555 if (option (Opt_secondaryScreen))
546 { 556 {
547 num_scr = 0; 557 num_scr = 0;
772 scr_scroll_text (screen.tscroll, screen.bscroll, minlines); 782 scr_scroll_text (screen.tscroll, screen.bscroll, minlines);
773 screen.cur.row -= minlines; 783 screen.cur.row -= minlines;
774 } 784 }
775 } 785 }
776 786
777#ifdef DEBUG_STRICT
778 assert (screen.cur.col < ncol); 787 assert (screen.cur.col < ncol);
779 assert (screen.cur.row < nrow 788 assert (screen.cur.row < nrow
780 && screen.cur.row >= top_row); 789 && screen.cur.row >= top_row);
781#endif
782 int row = screen.cur.row; 790 int row = screen.cur.row;
783 791
784 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 792 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
785 793
786 line_t *line = &ROW(row); 794 line_t *line = &ROW(row);
787 795
788 while (str < strend) 796 while (str < strend)
789 { 797 {
790 c = (unicode_t)*str++; // convert to rxvt-unicodes representation 798 c = (unicode_t)*str++; // convert to rxvt-unicodes representation
791 799
792 if (c < 0x20) 800 if (expect_false (c < 0x20))
793 if (c == C0_LF) 801 if (c == C0_LF)
794 { 802 {
795 max_it (line->l, screen.cur.col); 803 max_it (line->l, screen.cur.col);
796 804
797 screen.flags &= ~Screen_WrapNext; 805 screen.flags &= ~Screen_WrapNext;
816 { 824 {
817 scr_tab (1, true); 825 scr_tab (1, true);
818 continue; 826 continue;
819 } 827 }
820 828
829 if (expect_false (
821 if (checksel /* see if we're writing within selection */ 830 checksel /* see if we're writing within selection */
822 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 831 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
823 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 832 && ROWCOL_IS_BEFORE (screen.cur, selection.end)
833 ))
824 { 834 {
825 checksel = 0; 835 checksel = 0;
826 /* 836 /*
827 * If we wrote anywhere in the selected area, kill the selection 837 * If we wrote anywhere in the selected area, kill the selection
828 * XXX: should we kill the mark too? Possibly, but maybe that 838 * XXX: should we kill the mark too? Possibly, but maybe that
829 * should be a similar check. 839 * should be a similar check.
830 */ 840 */
831 CLEAR_SELECTION (); 841 CLEAR_SELECTION ();
832 } 842 }
833 843
834 if (screen.flags & Screen_WrapNext) 844 if (expect_false (screen.flags & Screen_WrapNext))
835 { 845 {
836 scr_do_wrap (); 846 scr_do_wrap ();
837 847
838 line->l = ncol; 848 line->l = ncol;
839 line->is_longer (1); 849 line->is_longer (1);
841 row = screen.cur.row; 851 row = screen.cur.row;
842 line = &ROW(row); /* _must_ refresh */ 852 line = &ROW(row); /* _must_ refresh */
843 } 853 }
844 854
845 // some utf-8 decoders "decode" surrogate characters: let's fix this. 855 // some utf-8 decoders "decode" surrogate characters: let's fix this.
846 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 856 if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff)))
847 c = 0xfffd; 857 c = 0xfffd;
848 858
849 // rely on wcwidth to tell us the character width, do wcwidth before 859 // rely on wcwidth to tell us the character width, do wcwidth before
850 // further replacements, as wcwidth might return -1 for the line 860 // further replacements, as wcwidth might return -1 for the line
851 // drawing characters below as they might be invalid in the current 861 // drawing characters below as they might be invalid in the current
852 // locale. 862 // locale.
853 int width = WCWIDTH (c); 863 int width = WCWIDTH (c);
854 864
855 if (charsets [screen.charset] == '0') // DEC SPECIAL 865 if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL
856 { 866 {
857 // vt100 special graphics and line drawing 867 // vt100 special graphics and line drawing
858 // 5f-7e standard vt100 868 // 5f-7e standard vt100
859 // 40-5e rxvt extension for extra curses acs chars 869 // 40-5e rxvt extension for extra curses acs chars
860 static uint16_t vt100_0[62] = { // 41 .. 7e 870 static uint16_t vt100_0[62] = { // 41 .. 7e
873 c = vt100_0[c - 0x41]; 883 c = vt100_0[c - 0x41];
874 width = 1; // vt100 line drawing characters are always single-width 884 width = 1; // vt100 line drawing characters are always single-width
875 } 885 }
876 } 886 }
877 887
878 if (screen.flags & Screen_Insert) 888 if (expect_false (screen.flags & Screen_Insert))
879 scr_insdel_chars (width, INSERT); 889 scr_insdel_chars (width, INSERT);
880 890
881 if (width != 0) 891 if (width != 0)
882 { 892 {
883#if !UNICODE_3 893#if !UNICODE_3
889 c = 0xfffd; 899 c = 0xfffd;
890# endif 900# endif
891#endif 901#endif
892 902
893 // nuke the character at this position, if required 903 // nuke the character at this position, if required
904 if (expect_false (
894 if (line->t[screen.cur.col] == NOCHAR 905 line->t[screen.cur.col] == NOCHAR
895 || (screen.cur.col < ncol - 1 906 || (screen.cur.col < ncol - 1
896 && line->t[screen.cur.col + 1] == NOCHAR)) 907 && line->t[screen.cur.col + 1] == NOCHAR)
908 ))
909 scr_kill_char (*line, screen.cur.col);
910
911 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
912
913 // if the character doesn't fit into the remaining columns...
914 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
897 { 915 {
898 int col = screen.cur.col; 916 if (screen.flags & Screen_Autowrap)
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 { 917 {
908 line->t[col] = ' '; 918 // ... artificially enlargen the previous one
909 line->r[col] = rend; 919 c = NOCHAR;
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 = ' ';
921 // and try the same character next loop iteration 920 // and try the same character next loop iteration
922 --str; 921 --str;
922 }
923 else
924 screen.cur.col = ncol - width;
923 } 925 }
924 926
925 line->touch (); 927 line->touch ();
926 928
927 do 929 do
928 { 930 {
929 line->t[screen.cur.col] = c; 931 line->t[screen.cur.col] = c;
930 line->r[screen.cur.col] = rend; 932 line->r[screen.cur.col] = rend;
931 933
932 if (screen.cur.col < ncol - 1) 934 if (expect_true (screen.cur.col < ncol - 1))
933 screen.cur.col++; 935 screen.cur.col++;
934 else 936 else
935 { 937 {
936 line->l = ncol; 938 line->l = ncol;
937 if (screen.flags & Screen_Autowrap) 939 if (screen.flags & Screen_Autowrap)
939 break; 941 break;
940 } 942 }
941 943
942 c = NOCHAR; 944 c = NOCHAR;
943 } 945 }
944 while (--width > 0); 946 while (expect_false (--width > 0));
945 947
946 // pad with spaces when overwriting wide character with smaller one 948 // pad with spaces when overwriting wide character with smaller one
947 if (!width) 949 if (expect_false (!width))
948 { 950 {
949 line->touch (); 951 line->touch ();
950 952
951 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) 953 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
952 { 954 {
953 line->t[c] = ' '; 955 line->t[c] = ' ';
954 line->r[c] = rend; 956 line->r[c] = rend;
955 } 957 }
956 } 958 }
957 } 959 }
960#if ENABLE_COMBINING
958 else // width == 0 961 else // width == 0
959 { 962 {
960#if ENABLE_COMBINING 963 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 { 964 {
965 // handle combining characters
966 // we just tag the accent on the previous on-screen character.
967 // this is arguably not correct, but also arguably not wrong.
968 // we don't handle double-width characters nicely yet.
969 line_t *linep;
970 text_t *tp;
971 rend_t *rp;
972
973 if (screen.cur.col > 0)
974 {
971 linep = line; 975 linep = line;
972 tp = line->t + screen.cur.col - 1; 976 tp = line->t + screen.cur.col - 1;
973 rp = line->r + screen.cur.col - 1; 977 rp = line->r + screen.cur.col - 1;
978 }
979 else if (screen.cur.row > 0
980 && ROW(screen.cur.row - 1).is_longer ())
981 {
982 linep = &ROW(screen.cur.row - 1);
983 tp = line->t + ncol - 1;
984 rp = line->r + ncol - 1;
985 }
986 else
987 continue;
988
989 linep->touch ();
990
991 while (*tp == NOCHAR && tp > linep->t)
992 tp--, rp--;
993
994 // first try to find a precomposed character
995 unicode_t n = rxvt_compose (*tp, c);
996 if (n == NOCHAR)
997 n = rxvt_composite.compose (*tp, c);
998
999 *tp = n;
1000 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
974 } 1001 }
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 } 1002 }
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 1003#endif
998 }
999 } 1004 }
1000 1005
1001 max_it (line->l, screen.cur.col); 1006 max_it (line->l, screen.cur.col);
1002 1007
1003#ifdef DEBUG_STRICT
1004 assert (screen.cur.row >= 0); 1008 assert (screen.cur.row >= 0);
1005#endif
1006} 1009}
1007 1010
1008/* ------------------------------------------------------------------------- */ 1011/* ------------------------------------------------------------------------- */
1009/* 1012/*
1010 * Process Backspace. Move back the cursor back a position, wrap if have to 1013 * Process Backspace. Move back the cursor back a position, wrap if have to
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 }
1031#ifdef TERMCAP_HAS_BW
1029 else if (!(screen.flags & Screen_WrapNext)) 1032 else if (screen.flags & Screen_WrapNext)
1033 screen.flags &= ~Screen_WrapNext;
1034#endif
1035 else
1030 scr_gotorc (0, -1, RELATIVE); 1036 scr_gotorc (0, -1, RELATIVE);
1031
1032 screen.flags &= ~Screen_WrapNext;
1033} 1037}
1034 1038
1035/* ------------------------------------------------------------------------- */ 1039/* ------------------------------------------------------------------------- */
1036/* 1040/*
1037 * Process Horizontal Tab 1041 * Process Horizontal Tab
1230/* 1234/*
1231 * Erase part or whole of a line 1235 * Erase part or whole of a line
1232 * XTERM_SEQ: Clear line to right: ESC [ 0 K 1236 * XTERM_SEQ: Clear line to right: ESC [ 0 K
1233 * XTERM_SEQ: Clear line to left : ESC [ 1 K 1237 * XTERM_SEQ: Clear line to left : ESC [ 1 K
1234 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1238 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1239 * extension: clear to right unless wrapped: ESC [ 3 K
1235 */ 1240 */
1236void 1241void
1237rxvt_term::scr_erase_line (int mode) NOTHROW 1242rxvt_term::scr_erase_line (int mode) NOTHROW
1238{ 1243{
1239 unsigned int col, num; 1244 unsigned int col, num;
1248 line.touch (); 1253 line.touch ();
1249 line.is_longer (0); 1254 line.is_longer (0);
1250 1255
1251 switch (mode) 1256 switch (mode)
1252 { 1257 {
1258 case 3:
1259 if (screen.flags & Screen_WrapNext)
1260 return;
1261
1262 /* fall through */
1263
1253 case 0: /* erase to end of line */ 1264 case 0: /* erase to end of line */
1254 col = screen.cur.col; 1265 col = screen.cur.col;
1255 num = ncol - col; 1266 num = ncol - col;
1256 min_it (line.l, col); 1267 min_it (line.l, col);
1268
1257 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1269 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1258 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1270 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1259 CLEAR_SELECTION (); 1271 CLEAR_SELECTION ();
1260 break; 1272 break;
1273
1261 case 1: /* erase to beginning of line */ 1274 case 1: /* erase to beginning of line */
1262 col = 0; 1275 col = 0;
1263 num = screen.cur.col + 1; 1276 num = screen.cur.col + 1;
1277
1264 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur) 1278 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur)
1265 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur)) 1279 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur))
1266 CLEAR_SELECTION (); 1280 CLEAR_SELECTION ();
1267 break; 1281 break;
1282
1268 case 2: /* erase whole line */ 1283 case 2: /* erase whole line */
1269 col = 0; 1284 col = 0;
1270 num = ncol; 1285 num = ncol;
1271 line.l = 0; 1286 line.l = 0;
1272 if (selection.beg.row <= screen.cur.row 1287 if (selection.beg.row <= screen.cur.row
1330 if (row >= nrow) /* Out Of Bounds */ 1345 if (row >= nrow) /* Out Of Bounds */
1331 return; 1346 return;
1332 1347
1333 min_it (num, nrow - row); 1348 min_it (num, nrow - row);
1334 1349
1335 if (rstyle & (RS_RVid | RS_Uline)) 1350 if (rstyle & (RS_Blink | RS_RVid | RS_Uline))
1336 ren = (rend_t) ~RS_None; 1351 ren = (rend_t) ~RS_None;
1337 else if (GET_BASEBG (rstyle) == Color_bg) 1352 else if (GET_BASEBG (rstyle) == Color_bg)
1338 { 1353 {
1339 ren = DEFAULT_RSTYLE; 1354 ren = DEFAULT_RSTYLE;
1340 CLEAR_ROWS (row, num); 1355
1356 if (mapped)
1357 XClearArea (dpy, vt, 0,
1358 Row2Pixel (row - view_start), (unsigned int)width,
1359 (unsigned int)Height2Pixel (num), False);
1341 } 1360 }
1342 else 1361 else
1343 { 1362 {
1344 ren = rstyle & (RS_fgMask | RS_bgMask); 1363 ren = rstyle & (RS_fgMask | RS_bgMask);
1364
1365 if (mapped)
1366 {
1345 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1367 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1346 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1368 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1347 ERASE_ROWS (row, num); 1369 XFillRectangle (dpy, vt, gc,
1370 0, Row2Pixel (row - view_start),
1371 (unsigned int)width,
1372 (unsigned int)Height2Pixel (num));
1348 gcvalue.foreground = pix_colors[Color_fg]; 1373 gcvalue.foreground = pix_colors[Color_fg];
1349 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1374 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1375 }
1350 } 1376 }
1351 1377
1352 for (; num--; row++) 1378 for (; num--; row++)
1353 { 1379 {
1354 scr_blank_screen_mem (ROW(row), rstyle); 1380 scr_blank_screen_mem (ROW(row), rstyle);
1381
1382 if (row - view_start < nrow)
1355 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1383 scr_blank_line (drawn_buf [row - view_start], 0, ncol, ren);
1356 } 1384 }
1357} 1385}
1358 1386
1359#if !ENABLE_MINIMAL 1387#if !ENABLE_MINIMAL
1360void 1388void
1434 * Insert/Delete <count> characters from the current position 1462 * Insert/Delete <count> characters from the current position
1435 */ 1463 */
1436void 1464void
1437rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW 1465rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW
1438{ 1466{
1439 int col, row;
1440 rend_t tr;
1441
1442 want_refresh = 1; 1467 want_refresh = 1;
1443 ZERO_SCROLLBACK (); 1468 ZERO_SCROLLBACK ();
1444 1469
1445 if (count <= 0) 1470 if (count <= 0)
1446 return; 1471 return;
1448 scr_do_wrap (); 1473 scr_do_wrap ();
1449 1474
1450 selection_check (1); 1475 selection_check (1);
1451 min_it (count, ncol - screen.cur.col); 1476 min_it (count, ncol - screen.cur.col);
1452 1477
1453 row = screen.cur.row; 1478 int row = screen.cur.row;
1454 1479
1455 line_t *line = &ROW(row); 1480 line_t *line = &ROW(row);
1456 1481
1457 line->touch (); 1482 line->touch ();
1458 line->is_longer (0); 1483 line->is_longer (0);
1459 1484
1485 // nuke wide spanning the start
1486 if (line->t[screen.cur.col] == NOCHAR)
1487 scr_kill_char (*line, screen.cur.col);
1488
1460 switch (insdel) 1489 switch (insdel)
1461 { 1490 {
1462 case INSERT: 1491 case INSERT:
1463 for (col = ncol - 1; (col - count) >= screen.cur.col; col--) 1492 line->l = min (line->l + count, ncol);
1493
1494 if (line->t[screen.cur.col] == NOCHAR)
1495 scr_kill_char (*line, screen.cur.col);
1496
1497 for (int col = ncol - 1; (col - count) >= screen.cur.col; col--)
1464 { 1498 {
1465 line->t[col] = line->t[col - count]; 1499 line->t[col] = line->t[col - count];
1466 line->r[col] = line->r[col - count]; 1500 line->r[col] = line->r[col - count];
1467 } 1501 }
1468
1469 line->l = min (line->l + count, ncol);
1470 1502
1471 if (selection.op && current_screen == selection.screen 1503 if (selection.op && current_screen == selection.screen
1472 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1504 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1473 { 1505 {
1474 if (selection.end.row != screen.cur.row 1506 if (selection.end.row != screen.cur.row
1489 case ERASE: 1521 case ERASE:
1490 screen.cur.col += count; /* don't worry if > ncol */ 1522 screen.cur.col += count; /* don't worry if > ncol */
1491 selection_check (1); 1523 selection_check (1);
1492 screen.cur.col -= count; 1524 screen.cur.col -= count;
1493 1525
1494 line->l = max (line->l - count, 0); 1526 // nuke wide char after the end
1527 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1528 scr_kill_char (*line, screen.cur.col + count);
1529
1495 scr_blank_line (*line, screen.cur.col, count, rstyle); 1530 scr_blank_line (*line, screen.cur.col, count, rstyle);
1496 break; 1531 break;
1497 1532
1498 case DELETE: 1533 case DELETE:
1499 tr = line->r[ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask); 1534 line->l = max (line->l - count, 0);
1500 1535
1536 // nuke wide char spanning the end
1537 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1538 scr_kill_char (*line, screen.cur.col + count);
1539
1501 for (col = screen.cur.col; (col + count) < ncol; col++) 1540 for (int col = screen.cur.col; (col + count) < ncol; col++)
1502 { 1541 {
1503 line->t[col] = line->t[col + count]; 1542 line->t[col] = line->t[col + count];
1504 line->r[col] = line->r[col + count]; 1543 line->r[col] = line->r[col + count];
1505 } 1544 }
1506 1545
1507 line->l = max (line->l - count, 0);
1508 scr_blank_line (*line, ncol - count, count, tr); 1546 scr_blank_line (*line, ncol - count, count, rstyle);
1509 1547
1510 if (selection.op && current_screen == selection.screen 1548 if (selection.op && current_screen == selection.screen
1511 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1549 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1512 { 1550 {
1513 if (selection.end.row != screen.cur.row 1551 if (selection.end.row != screen.cur.row
1803 for (i = PART_BEG; i < RC_COUNT; i++) 1841 for (i = PART_BEG; i < RC_COUNT; i++)
1804 { 1842 {
1805 min_it (rc[i].col, ncol - 1); 1843 min_it (rc[i].col, ncol - 1);
1806 min_it (rc[i].row, nrow - 1); 1844 min_it (rc[i].row, nrow - 1);
1807 } 1845 }
1808// TODO: this line somehow causes segfault if scr_expose() is called just after resize 1846
1809 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1847 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1810 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); 1848 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1);
1811 1849
1812 num_scr_allow = 0; 1850 num_scr_allow = 0;
1813 1851
1891 XMapWindow (dpy, parent[0]); 1929 XMapWindow (dpy, parent[0]);
1892# endif 1930# endif
1893 1931
1894# if ENABLE_FRILLS 1932# if ENABLE_FRILLS
1895 if (option (Opt_urgentOnBell)) 1933 if (option (Opt_urgentOnBell))
1896 { 1934 set_urgency (1);
1897 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1898 {
1899 h->flags |= XUrgencyHint;
1900 XSetWMHints (dpy, parent[0], h);
1901 }
1902 }
1903# endif 1935# endif
1904 1936
1905 if (option (Opt_visualBell)) 1937 if (option (Opt_visualBell))
1906 { 1938 {
1907 rvideo_bell = true; 1939 rvideo_bell = true;
1910 1942
1911 bell_ev.start (VISUAL_BELL_DURATION); 1943 bell_ev.start (VISUAL_BELL_DURATION);
1912 } 1944 }
1913 else 1945 else
1914 XBell (dpy, 0); 1946 XBell (dpy, 0);
1947 HOOK_INVOKE ((this, HOOK_BELL, DT_END));
1915#endif 1948#endif
1916} 1949}
1917 1950
1918/* ------------------------------------------------------------------------- */ 1951/* ------------------------------------------------------------------------- */
1919/* ARGSUSED */ 1952/* ARGSUSED */
1920void 1953void
1921rxvt_term::scr_printscreen (int fullhist) NOTHROW 1954rxvt_term::scr_printscreen (int fullhist) NOTHROW
1922{ 1955{
1923#ifdef PRINTPIPE 1956#ifdef PRINTPIPE
1924 int nrows, row_start; 1957 int nrows, row_start;
1925 FILE *fd; 1958 FILE *fd = popen_printer ();
1926 1959
1927 if ((fd = popen_printer ()) == NULL) 1960 if (!fd)
1928 return; 1961 return;
1929 1962
1930 if (fullhist) 1963 if (fullhist)
1931 { 1964 {
1932 nrows = nrow - top_row; 1965 nrows = nrow - top_row;
1938 row_start = view_start; 1971 row_start = view_start;
1939 } 1972 }
1940 1973
1941 wctomb (0, 0); 1974 wctomb (0, 0);
1942 1975
1943 for (int r1 = 0; r1 < nrows; r1++) 1976 for (int r1 = row_start; r1 < row_start + nrows; r1++)
1944 { 1977 {
1945 text_t *tp = ROW(r1).t; 1978 text_t *tp = ROW(r1).t;
1946 int len = ROW(r1).l; 1979 int len = ROW(r1).l;
1947 1980
1948 for (int i = len >= 0 ? len : ncol - 1; i--; ) //TODO//FIXME//LEN 1981 for (int i = len >= 0 ? len : ncol - 1; i--; ) //TODO//FIXME//LEN
1977 * screen.text/screen.rend contain what the screen will change to. 2010 * screen.text/screen.rend contain what the screen will change to.
1978 */ 2011 */
1979void 2012void
1980rxvt_term::scr_refresh () NOTHROW 2013rxvt_term::scr_refresh () NOTHROW
1981{ 2014{
1982 unsigned char have_bg,
1983 showcursor; /* show the cursor */
1984 int16_t col, row, /* column/row we're processing */ 2015 int16_t col, row, /* column/row we're processing */
1985 ocrow; /* old cursor row */ 2016 ocrow; /* old cursor row */
1986 int i; /* tmp */ 2017 int i; /* tmp */
1987#ifndef NO_CURSORCOLOR 2018#ifndef NO_CURSORCOLOR
1988 rend_t cc1; /* store colours at cursor position (s) */ 2019 rend_t cc1; /* store colours at cursor position (s) */
1997 return; 2028 return;
1998 2029
1999 /* 2030 /*
2000 * A: set up vars 2031 * A: set up vars
2001 */ 2032 */
2002 have_bg = 0;
2003 refresh_count = 0; 2033 refresh_count = 0;
2004 2034
2035 unsigned int old_screen_flags = screen.flags;
2036 char have_bg = 0;
2005#ifdef HAVE_BG_PIXMAP 2037#ifdef HAVE_BG_PIXMAP
2006 have_bg |= bgPixmap.pixmap != None; 2038 have_bg = bgPixmap.pixmap != None;
2007#endif 2039#endif
2008 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2040 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
2009 2041
2010 /* 2042 /*
2011 * B: reverse any characters which are selected 2043 * B: reverse any characters which are selected
2012 */ 2044 */
2013 scr_reverse_selection (); 2045 scr_reverse_selection ();
2046
2047 HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
2048#if ENABLE_OVERLAY
2049 scr_swap_overlay ();
2050#endif
2051
2052 char showcursor = screen.flags & Screen_VisibleCursor;
2014 2053
2015 /* 2054 /*
2016 * C: set the cursor character (s) 2055 * C: set the cursor character (s)
2017 */ 2056 */
2018 { 2057 {
2019 unsigned char setoldcursor; 2058 unsigned char setoldcursor;
2020 2059
2021 showcursor = (screen.flags & Screen_VisibleCursor);
2022#ifdef CURSOR_BLINK 2060#ifdef CURSOR_BLINK
2023 if (hidden_cursor) 2061 if (hidden_cursor)
2024 showcursor = 0; 2062 showcursor = 0;
2025#endif 2063#endif
2026 2064
2054 ccol2 = bgcolor_of (rstyle); 2092 ccol2 = bgcolor_of (rstyle);
2055#else 2093#else
2056 ccol2 = Color_bg; 2094 ccol2 = Color_bg;
2057#endif 2095#endif
2058 2096
2059 if (showcursor && focus) 2097 if (focus)
2060 { 2098 {
2061 if (option (Opt_cursorUnderline)) 2099 if (option (Opt_cursorUnderline))
2062 *crp ^= RS_Uline; 2100 *crp ^= RS_Uline;
2063 else 2101 else
2064 { 2102 {
2099 oldcursor.col = screen.cur.col; 2137 oldcursor.col = screen.cur.col;
2100 } 2138 }
2101 } 2139 }
2102 } 2140 }
2103 2141
2104 HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
2105#if ENABLE_OVERLAY
2106 scr_swap_overlay ();
2107#endif
2108
2109#ifndef NO_SLOW_LINK_SUPPORT 2142#ifndef NO_SLOW_LINK_SUPPORT
2110 /* 2143 /*
2111 * D: CopyArea pass - very useful for slower links 2144 * D: CopyArea pass - very useful for slower links
2112 * This has been deliberately kept simple. 2145 * This has been deliberately kept simple.
2113 */ 2146 */
2202 continue; 2235 continue;
2203 2236
2204 // redraw one or more characters 2237 // redraw one or more characters
2205 2238
2206 // seek to the beginning of wide characters 2239 // seek to the beginning of wide characters
2207 while (stp[col] == NOCHAR && col > 0) 2240 while (expect_false (stp[col] == NOCHAR && col > 0))
2208 --col; 2241 --col;
2209 2242
2210 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2243 rend_t rend = srp[col]; /* screen rendition (target rendition) */
2211 text_t *text = stp + col; 2244 text_t *text = stp + col;
2212 int count = 1; 2245 int count = 1;
2213 2246
2214 dtp[col] = stp[col]; 2247 dtp[col] = stp[col];
2215 drp[col] = rend; 2248 drp[col] = rend;
2219 for (i = 0; ++col < ncol; ) 2252 for (i = 0; ++col < ncol; )
2220 { 2253 {
2221 if (stp[col] == NOCHAR) 2254 if (stp[col] == NOCHAR)
2222 { 2255 {
2223 dtp[col] = stp[col]; 2256 dtp[col] = stp[col];
2224 drp[col] = rend; 2257 drp[col] = srp[col];
2258
2225 count++; 2259 count++;
2226 i++; 2260 i++;
2227 2261
2228 continue; 2262 continue;
2229 } 2263 }
2249 2283
2250 col--; /* went one too far. move back */ 2284 col--; /* went one too far. move back */
2251 count -= i; /* dump any matching trailing chars */ 2285 count -= i; /* dump any matching trailing chars */
2252 2286
2253 // sometimes we optimize away the trailing NOCHAR's, add them back 2287 // sometimes we optimize away the trailing NOCHAR's, add them back
2254 while (i && text[count] == NOCHAR) 2288 while (expect_false (i && text[count] == NOCHAR))
2255 count++, i--; 2289 count++, i--;
2256 2290
2257 /* 2291 /*
2258 * Determine the attributes for the string 2292 * Determine the attributes for the string
2259 */ 2293 */
2260 int fore = fgcolor_of (rend); // desired foreground 2294 int fore = fgcolor_of (rend); // desired foreground
2261 int back = bgcolor_of (rend); // desired background 2295 int back = bgcolor_of (rend); // desired background
2262 2296
2263 // only do special processing if any attributes are set, which is unlikely 2297 // only do special processing if any attributes are set, which is unlikely
2264 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2298 if (expect_false (rend & (RS_baseattrMask | RS_Careful | RS_Sel)))
2265 { 2299 {
2266 bool invert = rend & RS_RVid; 2300 bool invert = rend & RS_RVid;
2267 2301
2268#ifndef NO_BOLD_UNDERLINE_REVERSE 2302#ifndef NO_BOLD_UNDERLINE_REVERSE
2269 if (rend & RS_Bold && fore == Color_fg) 2303 if (rend & RS_Bold && fore == Color_fg)
2288 2322
2289 if (rend & RS_Uline && fore == Color_fg && ISSET_PIXCOLOR (Color_UL)) 2323 if (rend & RS_Uline && fore == Color_fg && ISSET_PIXCOLOR (Color_UL))
2290 fore = Color_UL; 2324 fore = Color_UL;
2291#endif 2325#endif
2292 2326
2327#ifdef OPTION_HC
2328 if (rend & RS_Sel)
2329 {
2330 /* invert the column if no highlightColor is set or it is the
2331 * current cursor column */
2332 if (!(showcursor && row == screen.cur.row && text - stp == screen.cur.col)
2333 && ISSET_PIXCOLOR (Color_HC))
2334 {
2335 if (ISSET_PIXCOLOR (Color_HTC))
2336 fore = Color_HTC;
2337 // if invert is 0 reverse video is set so we use bg color as fg color
2338 else if (!invert)
2339 fore = back;
2340
2341 back = Color_HC;
2342 invert = 0;
2343 }
2344 }
2345#endif
2346
2293 if (invert) 2347 if (invert)
2294 { 2348 {
2295#ifdef OPTION_HC
2296 if ((showcursor && row == screen.cur.row && text - stp == screen.cur.col)
2297 || !ISSET_PIXCOLOR (Color_HC))
2298#endif
2299 /* invert the column if no highlightColor is set or it is the
2300 * current cursor column */
2301 ::swap (fore, back); 2349 ::swap (fore, back);
2302#ifdef OPTION_HC
2303 else if (ISSET_PIXCOLOR (Color_HC))
2304 back = Color_HC;
2305#endif
2306 2350
2307#ifndef NO_BOLD_UNDERLINE_REVERSE 2351#ifndef NO_BOLD_UNDERLINE_REVERSE
2308# ifndef OPTION_HC
2309 if (ISSET_PIXCOLOR (Color_RV))
2310 back = Color_RV;
2311# endif
2312 if (fore == back) 2352 if (fore == back)
2313 { 2353 {
2314 fore = Color_bg; 2354 fore = Color_bg;
2315 back = Color_fg; 2355 back = Color_fg;
2316 } 2356 }
2352 /* 2392 /*
2353 * Actually do the drawing of the string here 2393 * Actually do the drawing of the string here
2354 */ 2394 */
2355 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2395 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2356 2396
2357 if (have_bg && back == Color_bg) 2397 if (expect_true (have_bg && back == Color_bg))
2358 { 2398 {
2359 // this is very ugly, maybe push it into ->draw? 2399 // this is very ugly, maybe push it into ->draw?
2360 2400
2361 for (i = 0; i < count; i++) /* don't draw empty strings */ 2401 for (i = 0; i < count; i++) /* don't draw empty strings */
2362 if (text[i] != ' ') 2402 if (text[i] != ' ')
2369 did_clear: ; 2409 did_clear: ;
2370 } 2410 }
2371 else 2411 else
2372 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2412 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2373 2413
2374 if (rend & RS_Uline && font->descent > 1 && fore != back) 2414 if (expect_false (rend & RS_Uline && font->descent > 1 && fore != back))
2375 { 2415 {
2376#if ENABLE_FRILLS 2416#if ENABLE_FRILLS
2377 if (ISSET_PIXCOLOR (Color_underline)) 2417 if (ISSET_PIXCOLOR (Color_underline))
2378 XSetForeground (dpy, gc, pix_colors[Color_underline]); 2418 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2379 else 2419 else
2380#endif 2420#endif
2381 XSetForeground (dpy, gc, pix_colors[fore]); 2421 XSetForeground (dpy, gc, pix_colors[fore]);
2382 2422
2383 XDrawLine (dpy, drawBuffer, gc, 2423 XDrawLine (dpy, vt, gc,
2384 xpixel, ypixel + font->ascent + 1, 2424 xpixel, ypixel + font->ascent + 1,
2385 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2425 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2386 } 2426 }
2387 } /* for (col....) */ 2427 } /* for (col....) */
2388 } /* for (row....) */ 2428 } /* for (row....) */
2389
2390#if ENABLE_OVERLAY
2391 scr_swap_overlay ();
2392#endif
2393 HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2394 2429
2395 /* 2430 /*
2396 * G: cleanup cursor and display outline cursor if necessary 2431 * G: cleanup cursor and display outline cursor if necessary
2397 */ 2432 */
2398 if (showcursor) 2433 if (showcursor)
2426 XSetForeground (dpy, gc, pix_colors[Color_cursor]); 2461 XSetForeground (dpy, gc, pix_colors[Color_cursor]);
2427 else 2462 else
2428#endif 2463#endif
2429 XSetForeground (dpy, gc, pix_colors[ccol1]); 2464 XSetForeground (dpy, gc, pix_colors[ccol1]);
2430 2465
2431 XDrawRectangle (dpy, drawBuffer, gc, 2466 XDrawRectangle (dpy, vt, gc,
2432 Col2Pixel (col), 2467 Col2Pixel (col),
2433 Row2Pixel (oldcursor.row), 2468 Row2Pixel (oldcursor.row),
2434 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2469 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2435 (unsigned int) (Height2Pixel (1) - lineSpace - 1)); 2470 (unsigned int) (Height2Pixel (1) - lineSpace - 1));
2436 } 2471 }
2437 } 2472 }
2438 2473
2439 /* 2474 /*
2440 * H: cleanup selection 2475 * H: cleanup selection
2441 */ 2476 */
2477#if ENABLE_OVERLAY
2478 scr_swap_overlay ();
2479#endif
2480 HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2481
2442 scr_reverse_selection (); 2482 scr_reverse_selection ();
2443 2483
2484 screen.flags = old_screen_flags;
2444 num_scr = 0; 2485 num_scr = 0;
2445 num_scr_allow = 1; 2486 num_scr_allow = 1;
2446} 2487}
2447 2488
2448void 2489void
2479 2520
2480 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]); 2521 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]);
2481 XClearWindow (dpy, parent[0]); 2522 XClearWindow (dpy, parent[0]);
2482 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 2523 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2483 2524
2484# if HAVE_SCROLLBARS
2485 if (scrollBar.win) 2525 if (scrollBar.win)
2486 { 2526 {
2487 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); 2527 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2488 scrollBar.setIdle (); 2528 scrollBar.state = STATE_IDLE;
2489 scrollbar_show (0); 2529 scrollBar.show (0);
2490 } 2530 }
2531
2491# endif 2532#endif
2492 2533
2534 /* bgPixmap.apply () does not do the following : */
2493 scr_clear (); 2535 scr_clear ();
2494 scr_touch (true); 2536 scr_touch (true);
2495 want_refresh = 1; 2537 want_refresh = 1;
2496
2497#endif
2498} 2538}
2499 2539
2500/* ------------------------------------------------------------------------- */ 2540/* ------------------------------------------------------------------------- */
2501void 2541void
2502rxvt_term::scr_clear (bool really) NOTHROW 2542rxvt_term::scr_clear (bool really) NOTHROW
2569 { 2609 {
2570#if !ENABLE_MINIMAL 2610#if !ENABLE_MINIMAL
2571 if (selection.rect) 2611 if (selection.rect)
2572 scr_xor_rect (selection.beg.row, selection.beg.col, 2612 scr_xor_rect (selection.beg.row, selection.beg.col,
2573 selection.end.row, selection.end.col, 2613 selection.end.row, selection.end.col,
2574 RS_RVid, RS_RVid | RS_Uline); 2614 RS_Sel | RS_RVid, RS_Sel | RS_RVid | RS_Uline);
2575 else 2615 else
2576#endif 2616#endif
2577 scr_xor_span (selection.beg.row, selection.beg.col, 2617 scr_xor_span (selection.beg.row, selection.beg.col,
2578 selection.end.row, selection.end.col, 2618 selection.end.row, selection.end.col,
2579 RS_RVid); 2619 RS_Sel | RS_RVid);
2580 } 2620 }
2581} 2621}
2582 2622
2583/* ------------------------------------------------------------------------- */ 2623/* ------------------------------------------------------------------------- */
2584/* 2624/*
2591{ 2631{
2592 int row, wrote; 2632 int row, wrote;
2593 unsigned int width, towrite; 2633 unsigned int width, towrite;
2594 char r1[] = "\n"; 2634 char r1[] = "\n";
2595 2635
2596 for (row = saveLines - nsaved; 2636 for (row = saveLines + top_row;
2597 row < saveLines + nrow - 1; row++) 2637 row < saveLines + nrow - 1; row++)
2598 { 2638 {
2599 width = row_buf[row].l >= 0 ? row_buf[row].l 2639 width = row_buf[row].l >= 0 ? row_buf[row].l
2600 : ncol; 2640 : ncol;
2601 for (towrite = width; towrite; towrite -= wrote) 2641 for (towrite = width; towrite; towrite -= wrote)
2645/* ------------------------------------------------------------------------- */ 2685/* ------------------------------------------------------------------------- */
2646/* 2686/*
2647 * Paste a selection direct to the command fd 2687 * Paste a selection direct to the command fd
2648 */ 2688 */
2649void 2689void
2650rxvt_term::paste (char *data, unsigned int len) NOTHROW 2690rxvt_term::tt_paste (char *data, unsigned int len) NOTHROW
2651{ 2691{
2652 /* convert normal newline chars into common keyboard Return key sequence */ 2692 /* convert normal newline chars into common keyboard Return key sequence */
2653 for (unsigned int i = 0; i < len; i++) 2693 for (unsigned int i = 0; i < len; i++)
2654 if (data[i] == C0_LF) 2694 if (data[i] == C0_LF)
2655 data[i] = C0_CR; 2695 data[i] = C0_CR;
2656 2696
2697 if (priv_modes & PrivMode_BracketPaste)
2698 tt_printf ("\e[200~");
2699
2657 tt_write (data, len); 2700 tt_write (data, len);
2701
2702 if (priv_modes & PrivMode_BracketPaste)
2703 tt_printf ("\e[201~");
2704}
2705
2706void
2707rxvt_term::paste (char *data, unsigned int len) NOTHROW
2708{
2709 if (HOOK_INVOKE ((this, HOOK_TT_PASTE, DT_STR_LEN, data, len, DT_END)))
2710 return;
2711
2712 tt_paste (data, len);
2658} 2713}
2659 2714
2660/* ------------------------------------------------------------------------- */ 2715/* ------------------------------------------------------------------------- */
2661/* 2716/*
2662 * Respond to a notification that a primary selection has been sent 2717 * Respond to a notification that a primary selection has been sent
2871 selection_wait = Sel_normal; 2926 selection_wait = Sel_normal;
2872 2927
2873#if X_HAVE_UTF8_STRING 2928#if X_HAVE_UTF8_STRING
2874 selection_type = Sel_UTF8String; 2929 selection_type = Sel_UTF8String;
2875 if (selection_request_other (xa[XA_UTF8_STRING], selnum)) 2930 if (selection_request_other (xa[XA_UTF8_STRING], selnum))
2876 return; 2931 return;
2877#else 2932#else
2878 selection_type = Sel_CompoundText; 2933 selection_type = Sel_CompoundText;
2879 if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum)) 2934 if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum))
2880 return; 2935 return;
2881#endif 2936#endif
2882 } 2937 }
2883 2938
2884 selection_wait = Sel_none; /* don't loop in selection_paste () */ 2939 selection_wait = Sel_none; /* don't loop in selection_paste () */
2885 selection_paste (display->root, XA_CUT_BUFFER0, false); 2940 selection_paste (display->root, XA_CUT_BUFFER0, false);
2913/* 2968/*
2914 * Clear all selected text 2969 * Clear all selected text
2915 * EXT: SelectionClear 2970 * EXT: SelectionClear
2916 */ 2971 */
2917void 2972void
2918rxvt_term::selection_clear () NOTHROW 2973rxvt_term::selection_clear (bool clipboard) NOTHROW
2919{ 2974{
2975 if (!clipboard)
2976 {
2920 want_refresh = 1; 2977 want_refresh = 1;
2921 free (selection.text); 2978 free (selection.text);
2922 selection.text = NULL; 2979 selection.text = NULL;
2923 selection.len = 0; 2980 selection.len = 0;
2924 CLEAR_SELECTION (); 2981 CLEAR_SELECTION ();
2925 2982
2926 if (display->selection_owner == this) 2983 if (display->selection_owner == this)
2927 display->selection_owner = 0; 2984 display->selection_owner = 0;
2985 }
2986 else
2987 {
2988 free (selection.clip_text);
2989 selection.clip_text = NULL;
2990 selection.clip_len = 0;
2991
2992 if (display->clipboard_owner == this)
2993 display->clipboard_owner = 0;
2994 }
2928} 2995}
2929 2996
2930/* ------------------------------------------------------------------------- */ 2997/* ------------------------------------------------------------------------- */
2931/* 2998/*
2932 * Copy a selection into the cut buffer 2999 * Copy a selection into the cut buffer
3058 3125
3059 selection_grab (tm); 3126 selection_grab (tm);
3060} 3127}
3061 3128
3062bool 3129bool
3063rxvt_term::selection_grab (Time tm) NOTHROW 3130rxvt_term::selection_grab (Time tm, bool clipboard) NOTHROW
3064{ 3131{
3132 Atom sel;
3133
3134 if (!clipboard)
3135 {
3065 selection_time = tm; 3136 selection_time = tm;
3137 sel = XA_PRIMARY;
3138 }
3139 else
3140 {
3141 clipboard_time = tm;
3142 sel = xa[XA_CLIPBOARD];
3143 }
3066 3144
3067 XSetSelectionOwner (dpy, XA_PRIMARY, vt, tm); 3145 XSetSelectionOwner (dpy, sel, vt, tm);
3068 if (XGetSelectionOwner (dpy, XA_PRIMARY) == vt) 3146 if (XGetSelectionOwner (dpy, sel) == vt)
3069 { 3147 {
3070 display->set_selection_owner (this); 3148 display->set_selection_owner (this, clipboard);
3071 return true; 3149 return true;
3072 } 3150 }
3073 else 3151 else
3074 { 3152 {
3075 selection_clear (); 3153 selection_clear (clipboard);
3076 return false; 3154 return false;
3077 } 3155 }
3078 3156
3079#if 0 3157#if 0
3080 XTextProperty ct; 3158 XTextProperty ct;
3575 else if (rq.target == xa[XA_MULTIPLE]) 3653 else if (rq.target == xa[XA_MULTIPLE])
3576 { 3654 {
3577 /* TODO: Handle MULTIPLE */ 3655 /* TODO: Handle MULTIPLE */
3578 } 3656 }
3579#endif 3657#endif
3580 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3658 else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == XA_PRIMARY && selection.text)
3581 { 3659 {
3582 XChangeProperty (dpy, rq.requestor, rq.property, rq.target, 3660 XChangeProperty (dpy, rq.requestor, rq.property, rq.target,
3583 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3661 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3662 ev.property = rq.property;
3663 }
3664 else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == xa[XA_CLIPBOARD] && selection.clip_text)
3665 {
3666 XChangeProperty (dpy, rq.requestor, rq.property, rq.target,
3667 32, PropModeReplace, (unsigned char *)&clipboard_time, 1);
3584 ev.property = rq.property; 3668 ev.property = rq.property;
3585 } 3669 }
3586 else if (rq.target == XA_STRING 3670 else if (rq.target == XA_STRING
3587 || rq.target == xa[XA_TEXT] 3671 || rq.target == xa[XA_TEXT]
3588 || rq.target == xa[XA_COMPOUND_TEXT] 3672 || rq.target == xa[XA_COMPOUND_TEXT]
3621 { 3705 {
3622 target = xa[XA_COMPOUND_TEXT]; 3706 target = xa[XA_COMPOUND_TEXT];
3623 style = enc_compound_text; 3707 style = enc_compound_text;
3624 } 3708 }
3625 3709
3626 if (selection.text) 3710 if (rq.selection == XA_PRIMARY && selection.text)
3627 { 3711 {
3628 cl = selection.text; 3712 cl = selection.text;
3629 selectlen = selection.len; 3713 selectlen = selection.len;
3714 }
3715 else if (rq.selection == xa[XA_CLIPBOARD] && selection.clip_text)
3716 {
3717 cl = selection.clip_text;
3718 selectlen = selection.clip_len;
3630 } 3719 }
3631 else 3720 else
3632 { 3721 {
3633 cl = L""; 3722 cl = L"";
3634 selectlen = 0; 3723 selectlen = 0;
3702 h += 2; min_it (h, nrow); 3791 h += 2; min_it (h, nrow);
3703 3792
3704 x -= 1; clamp_it (x, 0, ncol - w); 3793 x -= 1; clamp_it (x, 0, ncol - w);
3705 y -= 1; clamp_it (y, 0, nrow - h); 3794 y -= 1; clamp_it (y, 0, nrow - h);
3706 3795
3707 ov_x = x; ov_y = y; 3796 ov.x = x; ov.y = y;
3708 ov_w = w; ov_h = h; 3797 ov.w = w; ov.h = h;
3709 3798
3710 ov_text = new text_t *[h]; 3799 ov.text = new text_t *[h];
3711 ov_rend = new rend_t *[h]; 3800 ov.rend = new rend_t *[h];
3712 3801
3713 for (y = 0; y < h; y++) 3802 for (y = 0; y < h; y++)
3714 { 3803 {
3715 text_t *tp = ov_text[y] = new text_t[w]; 3804 text_t *tp = ov.text[y] = new text_t[w];
3716 rend_t *rp = ov_rend[y] = new rend_t[w]; 3805 rend_t *rp = ov.rend[y] = new rend_t[w];
3717 3806
3718 text_t t0, t1, t2; 3807 text_t t0, t1, t2;
3719 rend_t r = OVERLAY_RSTYLE; 3808 rend_t r = OVERLAY_RSTYLE;
3720 3809
3721 if (y == 0) 3810 if (y == 0)
3740} 3829}
3741 3830
3742void 3831void
3743rxvt_term::scr_overlay_off () NOTHROW 3832rxvt_term::scr_overlay_off () NOTHROW
3744{ 3833{
3745 if (!ov_text) 3834 if (!ov.text)
3746 return; 3835 return;
3747 3836
3748 want_refresh = 1; 3837 want_refresh = 1;
3749 3838
3750 for (int y = 0; y < ov_h; y++) 3839 for (int y = 0; y < ov.h; y++)
3751 { 3840 {
3752 delete [] ov_text[y]; 3841 delete [] ov.text[y];
3753 delete [] ov_rend[y]; 3842 delete [] ov.rend[y];
3754 } 3843 }
3755 3844
3756 delete [] ov_text; ov_text = 0; 3845 delete [] ov.text; ov.text = 0;
3757 delete [] ov_rend; ov_rend = 0; 3846 delete [] ov.rend; ov.rend = 0;
3758} 3847}
3759 3848
3760void 3849void
3761rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW 3850rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW
3762{ 3851{
3763 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2) 3852 if (!ov.text || x >= ov.w - 2 || y >= ov.h - 2)
3764 return; 3853 return;
3765 3854
3766 x++, y++; 3855 x++, y++;
3767 3856
3768 ov_text[y][x] = text; 3857 ov.text[y][x] = text;
3769 ov_rend[y][x] = rend; 3858 ov.rend[y][x] = rend;
3770} 3859}
3771 3860
3772void 3861void
3773rxvt_term::scr_overlay_set (int x, int y, const char *s) NOTHROW 3862rxvt_term::scr_overlay_set (int x, int y, const char *s) NOTHROW
3774{ 3863{
3793} 3882}
3794 3883
3795void 3884void
3796rxvt_term::scr_swap_overlay () NOTHROW 3885rxvt_term::scr_swap_overlay () NOTHROW
3797{ 3886{
3798 if (!ov_text) 3887 if (!ov.text)
3799 return; 3888 return;
3800 3889
3890 // hide cursor if it is within the overlay area
3891 if (IN_RANGE_EXC (screen.cur.col - ov.x, 0, ov.w)
3892 && IN_RANGE_EXC (screen.cur.row - ov.y, 0, ov.h))
3893 screen.flags &= ~Screen_VisibleCursor;
3894
3801 // swap screen mem with overlay 3895 // swap screen mem with overlay
3802 for (int y = ov_h; y--; ) 3896 for (int y = ov.h; y--; )
3803 { 3897 {
3804 text_t *t1 = ov_text[y]; 3898 text_t *t1 = ov.text[y];
3805 rend_t *r1 = ov_rend[y]; 3899 rend_t *r1 = ov.rend[y];
3806 3900
3807 text_t *t2 = ROW(y + ov_y + view_start).t + ov_x; 3901 text_t *t2 = ROW(y + ov.y + view_start).t + ov.x;
3808 rend_t *r2 = ROW(y + ov_y + view_start).r + ov_x; 3902 rend_t *r2 = ROW(y + ov.y + view_start).r + ov.x;
3809 3903
3810 for (int x = ov_w; x--; ) 3904 for (int x = ov.w; x--; )
3811 { 3905 {
3812 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3906 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3813 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); 3907 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t));
3814 } 3908 }
3815 } 3909 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines