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.300 by ayin, Sun Jan 27 22:48:33 2008 UTC vs.
Revision 1.333 by sf-exg, Sun Jan 24 21:53:13 2010 UTC

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 CLEAR_ROWS(row, num) \
93 if (mapped) \
94 XClearArea (dpy, vt, 0, \
95 Row2Pixel (row), (unsigned int)width, \
96 (unsigned int)Height2Pixel (num), False)
97
98#define CLEAR_CHARS(x, y, num) \ 90#define CLEAR_CHARS(x, y, num) \
99 if (mapped) \ 91 if (mapped) \
100 XClearArea (dpy, vt, x, y, \ 92 XClearArea (dpy, vt, x, y, \
101 (unsigned int)Width2Pixel (num), \ 93 (unsigned int)Width2Pixel (num), \
102 (unsigned int)Height2Pixel (1), False) 94 (unsigned int)Height2Pixel (1), False)
103 95
104#define ERASE_ROWS(row, num) \
105 XFillRectangle (dpy, vt, gc, \
106 0, Row2Pixel (row), \
107 (unsigned int)width, \
108 (unsigned int)Height2Pixel (num))
109
110/* ------------------------------------------------------------------------- * 96/* ------------------------------------------------------------------------- *
111 * SCREEN `COMMON' ROUTINES * 97 * SCREEN `COMMON' ROUTINES *
112 * ------------------------------------------------------------------------- */ 98 * ------------------------------------------------------------------------- */
113 99
114/* Fill part/all of a line with blanks. */ 100/* Fill part/all of a line with blanks. */
146 132
147 l.l = 0; 133 l.l = 0;
148 l.f = 0; 134 l.f = 0;
149} 135}
150 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
151/* ------------------------------------------------------------------------- * 156/* ------------------------------------------------------------------------- *
152 * SCREEN INITIALISATION * 157 * SCREEN INITIALISATION *
153 * ------------------------------------------------------------------------- */ 158 * ------------------------------------------------------------------------- */
154 159
155void 160void
156rxvt_term::scr_reset () 161rxvt_term::scr_reset ()
157{ 162{
158#if ENABLE_OVERLAY
159 scr_overlay_off ();
160#endif
161
162 rvideo_mode = false;
163 view_start = 0; 163 view_start = 0;
164 num_scr = 0; 164 num_scr = 0;
165 165
166 if (ncol == 0) 166 if (ncol == 0)
167 ncol = 80; 167 ncol = 80;
169 if (nrow == 0) 169 if (nrow == 0)
170 nrow = 24; 170 nrow = 24;
171 171
172 if (ncol == prev_ncol && nrow == prev_nrow) 172 if (ncol == prev_ncol && nrow == prev_nrow)
173 return; 173 return;
174
175 if (current_screen != PRIMARY)
176 scr_swap_screen ();
177 174
178 // we need at least two lines for wrapping to work correctly 175 // we need at least two lines for wrapping to work correctly
179 while (nrow + saveLines < 2) 176 while (nrow + saveLines < 2)
180 { 177 {
181 //TODO//FIXME 178 //TODO//FIXME
234 selection.text = NULL; 231 selection.text = NULL;
235 selection.len = 0; 232 selection.len = 0;
236 selection.op = SELECTION_CLEAR; 233 selection.op = SELECTION_CLEAR;
237 selection.screen = PRIMARY; 234 selection.screen = PRIMARY;
238 selection.clicks = 0; 235 selection.clicks = 0;
236 selection.clip_text = NULL;
237 selection.clip_len = 0;
239 } 238 }
240 else 239 else
241 { 240 {
242 /* 241 /*
243 * add or delete rows as appropriate 242 * add or delete rows as appropriate
281 280
282 if (top_row) 281 if (top_row)
283 { 282 {
284 // Re-wrap lines. This is rather ugly, possibly because I am too dumb 283 // Re-wrap lines. This is rather ugly, possibly because I am too dumb
285 // to come up with a lean and mean algorithm. 284 // to come up with a lean and mean algorithm.
285 // TODO: maybe optimise when width didn't change
286 286
287 row_col_t ocur = screen.cur; 287 row_col_t ocur = screen.cur;
288 ocur.row = MOD (term_start + ocur.row, prev_total_rows); 288 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
289 289
290 do 290 do
291 { 291 {
292 p = MOD (p - 1, prev_total_rows); 292 p = MOD (p - 1, prev_total_rows);
293#ifdef DEBUG_STRICT
294 assert (old_buf [MOD (p, prev_total_rows)].t); 293 assert (old_buf [MOD (p, prev_total_rows)].t);
295#endif
296 int plines = 1; 294 int plines = 1;
297 int llen = old_buf [MOD (p, prev_total_rows)].l; 295 int llen = old_buf [MOD (p, prev_total_rows)].l;
298 296
299 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) 297 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
300 { 298 {
394 delete old_ta; 392 delete old_ta;
395 delete old_ra; 393 delete old_ra;
396 394
397 clamp_it (screen.cur.row, 0, nrow - 1); 395 clamp_it (screen.cur.row, 0, nrow - 1);
398 clamp_it (screen.cur.col, 0, ncol - 1); 396 clamp_it (screen.cur.col, 0, ncol - 1);
397 }
399 398
400 free (tabs); 399 free (tabs);
401 } 400 tabs = (char *)rxvt_malloc (ncol);
401
402 for (int col = ncol; --col; )
403 tabs [col] = col % TABSIZE == 0;
402 404
403 CLEAR_ALL_SELECTION (); 405 CLEAR_ALL_SELECTION ();
404 406
405 prev_nrow = nrow; 407 prev_nrow = nrow;
406 prev_ncol = ncol; 408 prev_ncol = ncol;
407
408 tabs = (char *)rxvt_malloc (ncol);
409
410 for (int col = ncol; --col; )
411 tabs [col] = col % TABSIZE == 0;
412
413 if (current_screen != PRIMARY)
414 scr_swap_screen ();
415 409
416 tt_winch (); 410 tt_winch ();
417 411
418 HOOK_INVOKE ((this, HOOK_RESET, DT_END)); 412 HOOK_INVOKE ((this, HOOK_RESET, DT_END));
419} 413}
431 delete ralloc; ralloc = 0; 425 delete ralloc; ralloc = 0;
432 426
433 free (row_buf); 427 free (row_buf);
434 free (swap_buf); 428 free (swap_buf);
435 free (drawn_buf); 429 free (drawn_buf);
430 row_buf = 0; // signal that we freed all the arrays above
431
436 free (tabs); 432 free (tabs);
437 433 tabs = 0;
438 row_buf = 0; // signal that we freed all the arrays
439 } 434 }
440} 435}
441 436
442/* ------------------------------------------------------------------------- */ 437/* ------------------------------------------------------------------------- */
443/* 438/*
444 * Hard reset 439 * Hard/Soft reset
445 */ 440 */
446void 441void
447rxvt_term::scr_poweron () 442rxvt_term::scr_poweron ()
448{ 443{
449 scr_release (); 444 scr_release ();
450 prev_nrow = prev_ncol = 0; 445 prev_nrow = prev_ncol = 0;
446 rvideo_mode = false;
447 scr_soft_reset ();
451 scr_reset (); 448 scr_reset ();
452 449
453 scr_clear (true); 450 scr_clear (true);
454 scr_refresh (); 451 scr_refresh ();
452}
453
454void
455rxvt_term::scr_soft_reset ()
456{
457 /* only affects modes, nothing drastic such as clearing the screen */
458#if ENABLE_OVERLAY
459 scr_overlay_off ();
460#endif
461
462 if (current_screen != PRIMARY)
463 scr_swap_screen ();
464
465 scr_scroll_region (0, MAX_ROWS - 1);
466 scr_rendition (0, ~RS_None);
467 scr_insert_mode (0);
455} 468}
456 469
457/* ------------------------------------------------------------------------- * 470/* ------------------------------------------------------------------------- *
458 * PROCESS SCREEN COMMANDS * 471 * PROCESS SCREEN COMMANDS *
459 * ------------------------------------------------------------------------- */ 472 * ------------------------------------------------------------------------- */
497 } 510 }
498 511
499 /* boundary check in case screen size changed between SAVE and RESTORE */ 512 /* boundary check in case screen size changed between SAVE and RESTORE */
500 min_it (s->cur.row, nrow - 1); 513 min_it (s->cur.row, nrow - 1);
501 min_it (s->cur.col, ncol - 1); 514 min_it (s->cur.col, ncol - 1);
502#ifdef DEBUG_STRICT
503 assert (s->cur.row >= 0); 515 assert (s->cur.row >= 0);
504 assert (s->cur.col >= 0); 516 assert (s->cur.col >= 0);
505#endif
506} 517}
507 518
508void 519void
509rxvt_term::scr_swap_screen () 520rxvt_term::scr_swap_screen ()
510{ 521{
535 want_refresh = 1; 546 want_refresh = 1;
536 view_start = 0; 547 view_start = 0;
537 548
538 selection_check (2); /* check for boundary cross */ 549 selection_check (2); /* check for boundary cross */
539 550
540 int i = current_screen; current_screen = scrn; scrn = i; 551 current_screen = scrn;
541 552
542#if NSCREENS 553#if NSCREENS
543 if (option (Opt_secondaryScreen)) 554 if (option (Opt_secondaryScreen))
544 { 555 {
545 num_scr = 0; 556 num_scr = 0;
770 scr_scroll_text (screen.tscroll, screen.bscroll, minlines); 781 scr_scroll_text (screen.tscroll, screen.bscroll, minlines);
771 screen.cur.row -= minlines; 782 screen.cur.row -= minlines;
772 } 783 }
773 } 784 }
774 785
775#ifdef DEBUG_STRICT
776 assert (screen.cur.col < ncol); 786 assert (screen.cur.col < ncol);
777 assert (screen.cur.row < nrow 787 assert (screen.cur.row < nrow
778 && screen.cur.row >= top_row); 788 && screen.cur.row >= top_row);
779#endif
780 int row = screen.cur.row; 789 int row = screen.cur.row;
781 790
782 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 791 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
783 792
784 line_t *line = &ROW(row); 793 line_t *line = &ROW(row);
785 794
786 while (str < strend) 795 while (str < strend)
787 { 796 {
788 c = (unicode_t)*str++; // convert to rxvt-unicodes representation 797 c = (unicode_t)*str++; // convert to rxvt-unicodes representation
789 798
790 if (c < 0x20) 799 if (expect_false (c < 0x20))
791 if (c == C0_LF) 800 if (c == C0_LF)
792 { 801 {
793 max_it (line->l, screen.cur.col); 802 max_it (line->l, screen.cur.col);
794 803
795 screen.flags &= ~Screen_WrapNext; 804 screen.flags &= ~Screen_WrapNext;
814 { 823 {
815 scr_tab (1, true); 824 scr_tab (1, true);
816 continue; 825 continue;
817 } 826 }
818 827
828 if (expect_false (
819 if (checksel /* see if we're writing within selection */ 829 checksel /* see if we're writing within selection */
820 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 830 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
821 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 831 && ROWCOL_IS_BEFORE (screen.cur, selection.end)
832 ))
822 { 833 {
823 checksel = 0; 834 checksel = 0;
824 /* 835 /*
825 * If we wrote anywhere in the selected area, kill the selection 836 * If we wrote anywhere in the selected area, kill the selection
826 * XXX: should we kill the mark too? Possibly, but maybe that 837 * XXX: should we kill the mark too? Possibly, but maybe that
827 * should be a similar check. 838 * should be a similar check.
828 */ 839 */
829 CLEAR_SELECTION (); 840 CLEAR_SELECTION ();
830 } 841 }
831 842
832 if (screen.flags & Screen_WrapNext) 843 if (expect_false (screen.flags & Screen_WrapNext))
833 { 844 {
834 scr_do_wrap (); 845 scr_do_wrap ();
835 846
836 line->l = ncol; 847 line->l = ncol;
837 line->is_longer (1); 848 line->is_longer (1);
839 row = screen.cur.row; 850 row = screen.cur.row;
840 line = &ROW(row); /* _must_ refresh */ 851 line = &ROW(row); /* _must_ refresh */
841 } 852 }
842 853
843 // some utf-8 decoders "decode" surrogate characters: let's fix this. 854 // some utf-8 decoders "decode" surrogate characters: let's fix this.
844 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 855 if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff)))
845 c = 0xfffd; 856 c = 0xfffd;
846 857
847 // rely on wcwidth to tell us the character width, do wcwidth before 858 // rely on wcwidth to tell us the character width, do wcwidth before
848 // further replacements, as wcwidth might return -1 for the line 859 // further replacements, as wcwidth might return -1 for the line
849 // drawing characters below as they might be invalid in the current 860 // drawing characters below as they might be invalid in the current
850 // locale. 861 // locale.
851 int width = WCWIDTH (c); 862 int width = WCWIDTH (c);
852 863
853 if (charsets [screen.charset] == '0') // DEC SPECIAL 864 if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL
854 { 865 {
855 // vt100 special graphics and line drawing 866 // vt100 special graphics and line drawing
856 // 5f-7e standard vt100 867 // 5f-7e standard vt100
857 // 40-5e rxvt extension for extra curses acs chars 868 // 40-5e rxvt extension for extra curses acs chars
858 static uint16_t vt100_0[62] = { // 41 .. 7e 869 static uint16_t vt100_0[62] = { // 41 .. 7e
871 c = vt100_0[c - 0x41]; 882 c = vt100_0[c - 0x41];
872 width = 1; // vt100 line drawing characters are always single-width 883 width = 1; // vt100 line drawing characters are always single-width
873 } 884 }
874 } 885 }
875 886
876 if (screen.flags & Screen_Insert) 887 if (expect_false (screen.flags & Screen_Insert))
877 scr_insdel_chars (width, INSERT); 888 scr_insdel_chars (width, INSERT);
878 889
879 if (width != 0) 890 if (width != 0)
880 { 891 {
881#if !UNICODE_3 892#if !UNICODE_3
887 c = 0xfffd; 898 c = 0xfffd;
888# endif 899# endif
889#endif 900#endif
890 901
891 // nuke the character at this position, if required 902 // nuke the character at this position, if required
903 if (expect_false (
892 if (line->t[screen.cur.col] == NOCHAR 904 line->t[screen.cur.col] == NOCHAR
893 || (screen.cur.col < ncol - 1 905 || (screen.cur.col < ncol - 1
894 && line->t[screen.cur.col + 1] == NOCHAR)) 906 && line->t[screen.cur.col + 1] == NOCHAR)
907 ))
908 scr_kill_char (*line, screen.cur.col);
909
910 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
911
912 // if the character doesn't fit into the remaining columns...
913 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
895 { 914 {
896 int col = screen.cur.col; 915 // ... artificially enlargen the previous one
897
898 // find begin
899 while (col > 0 && line->t[col] == NOCHAR)
900 col--;
901
902 rend_t rend = SET_FONT (line->r[col], FONTSET (line->r[col])->find_font (' '));
903
904 // found begin, nuke
905 do {
906 line->t[col] = ' ';
907 line->r[col] = rend;
908 col++;
909 } while (col < ncol && line->t[col] == NOCHAR);
910 }
911
912 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
913
914 // if the character doesn't fit into the remaining columns...
915 if (screen.cur.col > ncol - width && ncol >= width)
916 {
917 // ...output spaces
918 c = ' '; 916 c = NOCHAR;
919 // and try the same character next loop iteration 917 // and try the same character next loop iteration
920 --str; 918 --str;
921 } 919 }
922 920
923 line->touch (); 921 line->touch ();
925 do 923 do
926 { 924 {
927 line->t[screen.cur.col] = c; 925 line->t[screen.cur.col] = c;
928 line->r[screen.cur.col] = rend; 926 line->r[screen.cur.col] = rend;
929 927
930 if (screen.cur.col < ncol - 1) 928 if (expect_true (screen.cur.col < ncol - 1))
931 screen.cur.col++; 929 screen.cur.col++;
932 else 930 else
933 { 931 {
934 line->l = ncol; 932 line->l = ncol;
935 if (screen.flags & Screen_Autowrap) 933 if (screen.flags & Screen_Autowrap)
937 break; 935 break;
938 } 936 }
939 937
940 c = NOCHAR; 938 c = NOCHAR;
941 } 939 }
942 while (--width > 0); 940 while (expect_false (--width > 0));
943 941
944 // pad with spaces when overwriting wide character with smaller one 942 // pad with spaces when overwriting wide character with smaller one
945 if (!width) 943 if (expect_false (!width))
946 { 944 {
947 line->touch (); 945 line->touch ();
948 946
949 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) 947 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
950 { 948 {
951 line->t[c] = ' '; 949 line->t[c] = ' ';
952 line->r[c] = rend; 950 line->r[c] = rend;
953 } 951 }
954 } 952 }
955 } 953 }
954#if ENABLE_COMBINING
956 else // width == 0 955 else // width == 0
957 { 956 {
958#if ENABLE_COMBINING 957 if (c != 0xfeff) // ignore BOM
959 // handle combining characters
960 // we just tag the accent on the previous on-screen character.
961 // this is arguably not correct, but also arguably not wrong.
962 // we don't handle double-width characters nicely yet.
963 line_t *linep;
964 text_t *tp;
965 rend_t *rp;
966
967 if (screen.cur.col > 0)
968 { 958 {
959 // handle combining characters
960 // we just tag the accent on the previous on-screen character.
961 // this is arguably not correct, but also arguably not wrong.
962 // we don't handle double-width characters nicely yet.
963 line_t *linep;
964 text_t *tp;
965 rend_t *rp;
966
967 if (screen.cur.col > 0)
968 {
969 linep = line; 969 linep = line;
970 tp = line->t + screen.cur.col - 1; 970 tp = line->t + screen.cur.col - 1;
971 rp = line->r + screen.cur.col - 1; 971 rp = line->r + screen.cur.col - 1;
972 }
973 else if (screen.cur.row > 0
974 && ROW(screen.cur.row - 1).is_longer ())
975 {
976 linep = &ROW(screen.cur.row - 1);
977 tp = line->t + ncol - 1;
978 rp = line->r + ncol - 1;
979 }
980 else
981 continue;
982
983 linep->touch ();
984
985 while (*tp == NOCHAR && tp > linep->t)
986 tp--, rp--;
987
988 // first try to find a precomposed character
989 unicode_t n = rxvt_compose (*tp, c);
990 if (n == NOCHAR)
991 n = rxvt_composite.compose (*tp, c);
992
993 *tp = n;
994 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
972 } 995 }
973 else if (screen.cur.row > 0
974 && ROW(screen.cur.row - 1).is_longer ())
975 {
976 linep = &ROW(screen.cur.row - 1);
977 tp = line->t + ncol - 1;
978 rp = line->r + ncol - 1;
979 } 996 }
980 else
981 continue;
982
983 linep->touch ();
984
985 while (*tp == NOCHAR && tp > linep->t)
986 tp--, rp--;
987
988 // first try to find a precomposed character
989 unicode_t n = rxvt_compose (*tp, c);
990 if (n == NOCHAR)
991 n = rxvt_composite.compose (*tp, c);
992
993 *tp = n;
994 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
995#endif 997#endif
996 }
997 } 998 }
998 999
999 max_it (line->l, screen.cur.col); 1000 max_it (line->l, screen.cur.col);
1000 1001
1001#ifdef DEBUG_STRICT
1002 assert (screen.cur.row >= 0); 1002 assert (screen.cur.row >= 0);
1003#endif
1004} 1003}
1005 1004
1006/* ------------------------------------------------------------------------- */ 1005/* ------------------------------------------------------------------------- */
1007/* 1006/*
1008 * Process Backspace. Move back the cursor back a position, wrap if have to 1007 * Process Backspace. Move back the cursor back a position, wrap if have to
1225/* 1224/*
1226 * Erase part or whole of a line 1225 * Erase part or whole of a line
1227 * XTERM_SEQ: Clear line to right: ESC [ 0 K 1226 * XTERM_SEQ: Clear line to right: ESC [ 0 K
1228 * XTERM_SEQ: Clear line to left : ESC [ 1 K 1227 * XTERM_SEQ: Clear line to left : ESC [ 1 K
1229 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1228 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1229 * extension: clear to right unless wrapped: ESC [ 3 K
1230 */ 1230 */
1231void 1231void
1232rxvt_term::scr_erase_line (int mode) NOTHROW 1232rxvt_term::scr_erase_line (int mode) NOTHROW
1233{ 1233{
1234 unsigned int col, num; 1234 unsigned int col, num;
1243 line.touch (); 1243 line.touch ();
1244 line.is_longer (0); 1244 line.is_longer (0);
1245 1245
1246 switch (mode) 1246 switch (mode)
1247 { 1247 {
1248 case 3:
1249 if (screen.flags & Screen_WrapNext)
1250 return;
1251
1252 /* fall through */
1253
1248 case 0: /* erase to end of line */ 1254 case 0: /* erase to end of line */
1249 col = screen.cur.col; 1255 col = screen.cur.col;
1250 num = ncol - col; 1256 num = ncol - col;
1251 min_it (line.l, col); 1257 min_it (line.l, col);
1258
1252 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1259 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1253 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1260 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1254 CLEAR_SELECTION (); 1261 CLEAR_SELECTION ();
1255 break; 1262 break;
1263
1256 case 1: /* erase to beginning of line */ 1264 case 1: /* erase to beginning of line */
1257 col = 0; 1265 col = 0;
1258 num = screen.cur.col + 1; 1266 num = screen.cur.col + 1;
1267
1259 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur) 1268 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur)
1260 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur)) 1269 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur))
1261 CLEAR_SELECTION (); 1270 CLEAR_SELECTION ();
1262 break; 1271 break;
1272
1263 case 2: /* erase whole line */ 1273 case 2: /* erase whole line */
1264 col = 0; 1274 col = 0;
1265 num = ncol; 1275 num = ncol;
1266 line.l = 0; 1276 line.l = 0;
1267 if (selection.beg.row <= screen.cur.row 1277 if (selection.beg.row <= screen.cur.row
1325 if (row >= nrow) /* Out Of Bounds */ 1335 if (row >= nrow) /* Out Of Bounds */
1326 return; 1336 return;
1327 1337
1328 min_it (num, nrow - row); 1338 min_it (num, nrow - row);
1329 1339
1340 // TODO: the code below does not work when view_start != 0
1341 // the workaround is to disable the clear and use a normal refresh
1342 // when view_start != 0. mysterious.
1330 if (rstyle & (RS_RVid | RS_Uline)) 1343 if (rstyle & (RS_RVid | RS_Uline))
1331 ren = (rend_t) ~RS_None; 1344 ren = (rend_t) ~RS_None;
1332 else if (GET_BASEBG (rstyle) == Color_bg) 1345 else if (GET_BASEBG (rstyle) == Color_bg)
1333 { 1346 {
1334 ren = DEFAULT_RSTYLE; 1347 ren = DEFAULT_RSTYLE;
1335 CLEAR_ROWS (row, num); 1348
1349 if (mapped && !view_start)
1350 XClearArea (dpy, vt, 0,
1351 Row2Pixel (row - view_start), (unsigned int)width,
1352 (unsigned int)Height2Pixel (num), False);
1336 } 1353 }
1337 else 1354 else
1338 { 1355 {
1339 ren = rstyle & (RS_fgMask | RS_bgMask); 1356 ren = rstyle & (RS_fgMask | RS_bgMask);
1357
1358 if (mapped && !view_start)
1359 {
1340 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1360 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1341 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1361 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1342 ERASE_ROWS (row, num); 1362 XFillRectangle (dpy, vt, gc,
1363 0, Row2Pixel (row - view_start),
1364 (unsigned int)width,
1365 (unsigned int)Height2Pixel (num));
1343 gcvalue.foreground = pix_colors[Color_fg]; 1366 gcvalue.foreground = pix_colors[Color_fg];
1344 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1367 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1368 }
1345 } 1369 }
1346 1370
1347 for (; num--; row++) 1371 for (; num--; row++)
1348 { 1372 {
1349 scr_blank_screen_mem (ROW(row), rstyle); 1373 scr_blank_screen_mem (ROW(row), rstyle);
1374
1375 if (!view_start)
1350 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1376 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1351 } 1377 }
1352} 1378}
1353 1379
1354#if !ENABLE_MINIMAL 1380#if !ENABLE_MINIMAL
1355void 1381void
1429 * Insert/Delete <count> characters from the current position 1455 * Insert/Delete <count> characters from the current position
1430 */ 1456 */
1431void 1457void
1432rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW 1458rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW
1433{ 1459{
1434 int col, row;
1435 rend_t tr;
1436
1437 want_refresh = 1; 1460 want_refresh = 1;
1438 ZERO_SCROLLBACK (); 1461 ZERO_SCROLLBACK ();
1439 1462
1440 if (count <= 0) 1463 if (count <= 0)
1441 return; 1464 return;
1443 scr_do_wrap (); 1466 scr_do_wrap ();
1444 1467
1445 selection_check (1); 1468 selection_check (1);
1446 min_it (count, ncol - screen.cur.col); 1469 min_it (count, ncol - screen.cur.col);
1447 1470
1448 row = screen.cur.row; 1471 int row = screen.cur.row;
1449 1472
1450 line_t *line = &ROW(row); 1473 line_t *line = &ROW(row);
1451 1474
1452 line->touch (); 1475 line->touch ();
1453 line->is_longer (0); 1476 line->is_longer (0);
1454 1477
1478 // nuke wide spanning the start
1479 if (line->t[screen.cur.col] == NOCHAR)
1480 scr_kill_char (*line, screen.cur.col);
1481
1455 switch (insdel) 1482 switch (insdel)
1456 { 1483 {
1457 case INSERT: 1484 case INSERT:
1458 for (col = ncol - 1; (col - count) >= screen.cur.col; col--) 1485 line->l = min (line->l + count, ncol);
1486
1487 if (line->t[screen.cur.col] == NOCHAR)
1488 scr_kill_char (*line, screen.cur.col);
1489
1490 for (int col = ncol - 1; (col - count) >= screen.cur.col; col--)
1459 { 1491 {
1460 line->t[col] = line->t[col - count]; 1492 line->t[col] = line->t[col - count];
1461 line->r[col] = line->r[col - count]; 1493 line->r[col] = line->r[col - count];
1462 } 1494 }
1463
1464 line->l = min (line->l + count, ncol);
1465 1495
1466 if (selection.op && current_screen == selection.screen 1496 if (selection.op && current_screen == selection.screen
1467 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1497 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1468 { 1498 {
1469 if (selection.end.row != screen.cur.row 1499 if (selection.end.row != screen.cur.row
1484 case ERASE: 1514 case ERASE:
1485 screen.cur.col += count; /* don't worry if > ncol */ 1515 screen.cur.col += count; /* don't worry if > ncol */
1486 selection_check (1); 1516 selection_check (1);
1487 screen.cur.col -= count; 1517 screen.cur.col -= count;
1488 1518
1489 line->l = max (line->l - count, 0); 1519 // nuke wide char after the end
1520 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1521 scr_kill_char (*line, screen.cur.col + count);
1522
1490 scr_blank_line (*line, screen.cur.col, count, rstyle); 1523 scr_blank_line (*line, screen.cur.col, count, rstyle);
1491 break; 1524 break;
1492 1525
1493 case DELETE: 1526 case DELETE:
1494 tr = line->r[ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask); 1527 line->l = max (line->l - count, 0);
1495 1528
1529 // nuke wide char spanning the end
1530 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1531 scr_kill_char (*line, screen.cur.col + count);
1532
1496 for (col = screen.cur.col; (col + count) < ncol; col++) 1533 for (int col = screen.cur.col; (col + count) < ncol; col++)
1497 { 1534 {
1498 line->t[col] = line->t[col + count]; 1535 line->t[col] = line->t[col + count];
1499 line->r[col] = line->r[col + count]; 1536 line->r[col] = line->r[col + count];
1500 } 1537 }
1501 1538
1502 line->l = max (line->l - count, 0);
1503 scr_blank_line (*line, ncol - count, count, tr); 1539 scr_blank_line (*line, ncol - count, count, rstyle);
1504 1540
1505 if (selection.op && current_screen == selection.screen 1541 if (selection.op && current_screen == selection.screen
1506 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1542 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1507 { 1543 {
1508 if (selection.end.row != screen.cur.row 1544 if (selection.end.row != screen.cur.row
1886 XMapWindow (dpy, parent[0]); 1922 XMapWindow (dpy, parent[0]);
1887# endif 1923# endif
1888 1924
1889# if ENABLE_FRILLS 1925# if ENABLE_FRILLS
1890 if (option (Opt_urgentOnBell)) 1926 if (option (Opt_urgentOnBell))
1891 { 1927 set_urgency (1);
1892 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1893 {
1894 h->flags |= XUrgencyHint;
1895 XSetWMHints (dpy, parent[0], h);
1896 }
1897 }
1898# endif 1928# endif
1899 1929
1900 if (option (Opt_visualBell)) 1930 if (option (Opt_visualBell))
1901 { 1931 {
1902 rvideo_bell = true; 1932 rvideo_bell = true;
1905 1935
1906 bell_ev.start (VISUAL_BELL_DURATION); 1936 bell_ev.start (VISUAL_BELL_DURATION);
1907 } 1937 }
1908 else 1938 else
1909 XBell (dpy, 0); 1939 XBell (dpy, 0);
1940 HOOK_INVOKE ((this, HOOK_BELL, DT_END));
1910#endif 1941#endif
1911} 1942}
1912 1943
1913/* ------------------------------------------------------------------------- */ 1944/* ------------------------------------------------------------------------- */
1914/* ARGSUSED */ 1945/* ARGSUSED */
1915void 1946void
1916rxvt_term::scr_printscreen (int fullhist) NOTHROW 1947rxvt_term::scr_printscreen (int fullhist) NOTHROW
1917{ 1948{
1918#ifdef PRINTPIPE 1949#ifdef PRINTPIPE
1919 int nrows, row_start; 1950 int nrows, row_start;
1920 FILE *fd; 1951 FILE *fd = popen_printer ();
1921 1952
1922 if ((fd = popen_printer ()) == NULL) 1953 if (!fd)
1923 return; 1954 return;
1924 1955
1925 if (fullhist) 1956 if (fullhist)
1926 { 1957 {
1927 nrows = nrow - top_row; 1958 nrows = nrow - top_row;
1933 row_start = view_start; 1964 row_start = view_start;
1934 } 1965 }
1935 1966
1936 wctomb (0, 0); 1967 wctomb (0, 0);
1937 1968
1938 for (int r1 = 0; r1 < nrows; r1++) 1969 for (int r1 = row_start; r1 < row_start + nrows; r1++)
1939 { 1970 {
1940 text_t *tp = ROW(r1).t; 1971 text_t *tp = ROW(r1).t;
1941 int len = ROW(r1).l; 1972 int len = ROW(r1).l;
1942 1973
1943 for (int i = len >= 0 ? len : ncol - 1; i--; ) //TODO//FIXME//LEN 1974 for (int i = len >= 0 ? len : ncol - 1; i--; ) //TODO//FIXME//LEN
1972 * screen.text/screen.rend contain what the screen will change to. 2003 * screen.text/screen.rend contain what the screen will change to.
1973 */ 2004 */
1974void 2005void
1975rxvt_term::scr_refresh () NOTHROW 2006rxvt_term::scr_refresh () NOTHROW
1976{ 2007{
1977 unsigned char have_bg,
1978 showcursor; /* show the cursor */
1979 int16_t col, row, /* column/row we're processing */ 2008 int16_t col, row, /* column/row we're processing */
1980 ocrow; /* old cursor row */ 2009 ocrow; /* old cursor row */
1981 int i; /* tmp */ 2010 int i; /* tmp */
1982#ifndef NO_CURSORCOLOR 2011#ifndef NO_CURSORCOLOR
1983 rend_t cc1; /* store colours at cursor position (s) */ 2012 rend_t cc1; /* store colours at cursor position (s) */
1992 return; 2021 return;
1993 2022
1994 /* 2023 /*
1995 * A: set up vars 2024 * A: set up vars
1996 */ 2025 */
1997 have_bg = 0;
1998 refresh_count = 0; 2026 refresh_count = 0;
1999 2027
2028 unsigned int old_screen_flags = screen.flags;
2029 char have_bg = 0;
2000#ifdef HAVE_BG_PIXMAP 2030#ifdef HAVE_BG_PIXMAP
2001 have_bg |= bgPixmap.pixmap != None; 2031 have_bg = bgPixmap.pixmap != None;
2002#endif 2032#endif
2003 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2033 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
2004 2034
2005 /* 2035 /*
2006 * B: reverse any characters which are selected 2036 * B: reverse any characters which are selected
2007 */ 2037 */
2008 scr_reverse_selection (); 2038 scr_reverse_selection ();
2039
2040 HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
2041#if ENABLE_OVERLAY
2042 scr_swap_overlay ();
2043#endif
2044
2045 char showcursor = screen.flags & Screen_VisibleCursor;
2009 2046
2010 /* 2047 /*
2011 * C: set the cursor character (s) 2048 * C: set the cursor character (s)
2012 */ 2049 */
2013 { 2050 {
2014 unsigned char setoldcursor; 2051 unsigned char setoldcursor;
2015 2052
2016 showcursor = (screen.flags & Screen_VisibleCursor);
2017#ifdef CURSOR_BLINK 2053#ifdef CURSOR_BLINK
2018 if (hidden_cursor) 2054 if (hidden_cursor)
2019 showcursor = 0; 2055 showcursor = 0;
2020#endif 2056#endif
2021 2057
2094 oldcursor.col = screen.cur.col; 2130 oldcursor.col = screen.cur.col;
2095 } 2131 }
2096 } 2132 }
2097 } 2133 }
2098 2134
2099 HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
2100#if ENABLE_OVERLAY
2101 scr_swap_overlay ();
2102#endif
2103
2104#ifndef NO_SLOW_LINK_SUPPORT 2135#ifndef NO_SLOW_LINK_SUPPORT
2105 /* 2136 /*
2106 * D: CopyArea pass - very useful for slower links 2137 * D: CopyArea pass - very useful for slower links
2107 * This has been deliberately kept simple. 2138 * This has been deliberately kept simple.
2108 */ 2139 */
2197 continue; 2228 continue;
2198 2229
2199 // redraw one or more characters 2230 // redraw one or more characters
2200 2231
2201 // seek to the beginning of wide characters 2232 // seek to the beginning of wide characters
2202 while (stp[col] == NOCHAR && col > 0) 2233 while (expect_false (stp[col] == NOCHAR && col > 0))
2203 --col; 2234 --col;
2204 2235
2205 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2236 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2206 text_t *text = stp + col; 2237 text_t *text = stp + col;
2207 int count = 1; 2238 int count = 1;
2214 for (i = 0; ++col < ncol; ) 2245 for (i = 0; ++col < ncol; )
2215 { 2246 {
2216 if (stp[col] == NOCHAR) 2247 if (stp[col] == NOCHAR)
2217 { 2248 {
2218 dtp[col] = stp[col]; 2249 dtp[col] = stp[col];
2219 drp[col] = rend; 2250 drp[col] = srp[col];
2251
2220 count++; 2252 count++;
2221 i++; 2253 i++;
2222 2254
2223 continue; 2255 continue;
2224 } 2256 }
2244 2276
2245 col--; /* went one too far. move back */ 2277 col--; /* went one too far. move back */
2246 count -= i; /* dump any matching trailing chars */ 2278 count -= i; /* dump any matching trailing chars */
2247 2279
2248 // sometimes we optimize away the trailing NOCHAR's, add them back 2280 // sometimes we optimize away the trailing NOCHAR's, add them back
2249 while (i && text[count] == NOCHAR) 2281 while (expect_false (i && text[count] == NOCHAR))
2250 count++, i--; 2282 count++, i--;
2251 2283
2252 /* 2284 /*
2253 * Determine the attributes for the string 2285 * Determine the attributes for the string
2254 */ 2286 */
2255 int fore = fgcolor_of (rend); // desired foreground 2287 int fore = fgcolor_of (rend); // desired foreground
2256 int back = bgcolor_of (rend); // desired background 2288 int back = bgcolor_of (rend); // desired background
2257 2289
2258 // only do special processing if any attributes are set, which is unlikely 2290 // only do special processing if any attributes are set, which is unlikely
2259 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2291 if (expect_false (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)))
2260 { 2292 {
2261 bool invert = rend & RS_RVid; 2293 bool invert = rend & RS_RVid;
2262 2294
2263#ifndef NO_BOLD_UNDERLINE_REVERSE 2295#ifndef NO_BOLD_UNDERLINE_REVERSE
2264 if (rend & RS_Bold && fore == Color_fg) 2296 if (rend & RS_Bold && fore == Color_fg)
2347 /* 2379 /*
2348 * Actually do the drawing of the string here 2380 * Actually do the drawing of the string here
2349 */ 2381 */
2350 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2382 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2351 2383
2352 if (have_bg && back == Color_bg) 2384 if (expect_true (have_bg && back == Color_bg))
2353 { 2385 {
2354 // this is very ugly, maybe push it into ->draw? 2386 // this is very ugly, maybe push it into ->draw?
2355 2387
2356 for (i = 0; i < count; i++) /* don't draw empty strings */ 2388 for (i = 0; i < count; i++) /* don't draw empty strings */
2357 if (text[i] != ' ') 2389 if (text[i] != ' ')
2364 did_clear: ; 2396 did_clear: ;
2365 } 2397 }
2366 else 2398 else
2367 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2399 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2368 2400
2369 if (rend & RS_Uline && font->descent > 1 && fore != back) 2401 if (expect_false (rend & RS_Uline && font->descent > 1 && fore != back))
2370 { 2402 {
2371#if ENABLE_FRILLS 2403#if ENABLE_FRILLS
2372 if (ISSET_PIXCOLOR (Color_underline)) 2404 if (ISSET_PIXCOLOR (Color_underline))
2373 XSetForeground (dpy, gc, pix_colors[Color_underline]); 2405 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2374 else 2406 else
2379 xpixel, ypixel + font->ascent + 1, 2411 xpixel, ypixel + font->ascent + 1,
2380 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2412 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2381 } 2413 }
2382 } /* for (col....) */ 2414 } /* for (col....) */
2383 } /* for (row....) */ 2415 } /* for (row....) */
2384
2385#if ENABLE_OVERLAY
2386 scr_swap_overlay ();
2387#endif
2388 HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2389 2416
2390 /* 2417 /*
2391 * G: cleanup cursor and display outline cursor if necessary 2418 * G: cleanup cursor and display outline cursor if necessary
2392 */ 2419 */
2393 if (showcursor) 2420 if (showcursor)
2432 } 2459 }
2433 2460
2434 /* 2461 /*
2435 * H: cleanup selection 2462 * H: cleanup selection
2436 */ 2463 */
2464#if ENABLE_OVERLAY
2465 scr_swap_overlay ();
2466#endif
2467 HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2468
2437 scr_reverse_selection (); 2469 scr_reverse_selection ();
2438 2470
2471 screen.flags = old_screen_flags;
2439 num_scr = 0; 2472 num_scr = 0;
2440 num_scr_allow = 1; 2473 num_scr_allow = 1;
2441} 2474}
2442 2475
2443void 2476void
2477 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 2510 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2478 2511
2479 if (scrollBar.win) 2512 if (scrollBar.win)
2480 { 2513 {
2481 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); 2514 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2482 scrollBar.setIdle (); 2515 scrollBar.state = STATE_IDLE;
2483 scrollbar_show (0); 2516 scrollBar.show (0);
2484 } 2517 }
2485 2518
2519#endif
2520
2521 /* bgPixmap.apply () does not do the following : */
2486 scr_clear (); 2522 scr_clear ();
2487 scr_touch (true); 2523 scr_touch (true);
2488 want_refresh = 1; 2524 want_refresh = 1;
2489
2490#endif
2491} 2525}
2492 2526
2493/* ------------------------------------------------------------------------- */ 2527/* ------------------------------------------------------------------------- */
2494void 2528void
2495rxvt_term::scr_clear (bool really) NOTHROW 2529rxvt_term::scr_clear (bool really) NOTHROW
2584{ 2618{
2585 int row, wrote; 2619 int row, wrote;
2586 unsigned int width, towrite; 2620 unsigned int width, towrite;
2587 char r1[] = "\n"; 2621 char r1[] = "\n";
2588 2622
2589 for (row = saveLines - nsaved; 2623 for (row = saveLines + top_row;
2590 row < saveLines + nrow - 1; row++) 2624 row < saveLines + nrow - 1; row++)
2591 { 2625 {
2592 width = row_buf[row].l >= 0 ? row_buf[row].l 2626 width = row_buf[row].l >= 0 ? row_buf[row].l
2593 : ncol; 2627 : ncol;
2594 for (towrite = width; towrite; towrite -= wrote) 2628 for (towrite = width; towrite; towrite -= wrote)
2912/* 2946/*
2913 * Clear all selected text 2947 * Clear all selected text
2914 * EXT: SelectionClear 2948 * EXT: SelectionClear
2915 */ 2949 */
2916void 2950void
2917rxvt_term::selection_clear () NOTHROW 2951rxvt_term::selection_clear (bool clipboard) NOTHROW
2918{ 2952{
2953 if (!clipboard)
2954 {
2919 want_refresh = 1; 2955 want_refresh = 1;
2920 free (selection.text); 2956 free (selection.text);
2921 selection.text = NULL; 2957 selection.text = NULL;
2922 selection.len = 0; 2958 selection.len = 0;
2923 CLEAR_SELECTION (); 2959 CLEAR_SELECTION ();
2924 2960
2925 if (display->selection_owner == this) 2961 if (display->selection_owner == this)
2926 display->selection_owner = 0; 2962 display->selection_owner = 0;
2963 }
2964 else
2965 {
2966 free (selection.clip_text);
2967 selection.clip_text = NULL;
2968 selection.clip_len = 0;
2969
2970 if (display->clipboard_owner == this)
2971 display->clipboard_owner = 0;
2972 }
2973}
2974
2975void
2976rxvt_term::clipboard_copy (Time tm)
2977{
2978 if (selection.len > 0)
2979 {
2980 free (selection.clip_text);
2981 selection.clip_len = selection.len;
2982 selection.clip_text = (wchar_t *) malloc (sizeof (wchar_t) * selection.clip_len);
2983 memcpy (selection.clip_text, selection.text,
2984 sizeof (wchar_t) * selection.clip_len);
2985 selection_grab (tm, true);
2986 }
2927} 2987}
2928 2988
2929/* ------------------------------------------------------------------------- */ 2989/* ------------------------------------------------------------------------- */
2930/* 2990/*
2931 * Copy a selection into the cut buffer 2991 * Copy a selection into the cut buffer
3057 3117
3058 selection_grab (tm); 3118 selection_grab (tm);
3059} 3119}
3060 3120
3061bool 3121bool
3062rxvt_term::selection_grab (Time tm) NOTHROW 3122rxvt_term::selection_grab (Time tm, bool clipboard) NOTHROW
3063{ 3123{
3124 Atom sel;
3125
3126 if (!clipboard)
3127 {
3064 selection_time = tm; 3128 selection_time = tm;
3129 sel = XA_PRIMARY;
3130 }
3131 else
3132 {
3133 clipboard_time = tm;
3134 sel = xa[XA_CLIPBOARD];
3135 }
3065 3136
3066 XSetSelectionOwner (dpy, XA_PRIMARY, vt, tm); 3137 XSetSelectionOwner (dpy, sel, vt, tm);
3067 if (XGetSelectionOwner (dpy, XA_PRIMARY) == vt) 3138 if (XGetSelectionOwner (dpy, sel) == vt)
3068 { 3139 {
3069 display->set_selection_owner (this); 3140 display->set_selection_owner (this, clipboard);
3070 return true; 3141 return true;
3071 } 3142 }
3072 else 3143 else
3073 { 3144 {
3074 selection_clear (); 3145 selection_clear (clipboard);
3075 return false; 3146 return false;
3076 } 3147 }
3077 3148
3078#if 0 3149#if 0
3079 XTextProperty ct; 3150 XTextProperty ct;
3574 else if (rq.target == xa[XA_MULTIPLE]) 3645 else if (rq.target == xa[XA_MULTIPLE])
3575 { 3646 {
3576 /* TODO: Handle MULTIPLE */ 3647 /* TODO: Handle MULTIPLE */
3577 } 3648 }
3578#endif 3649#endif
3579 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3650 else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == XA_PRIMARY && selection.text)
3580 { 3651 {
3581 XChangeProperty (dpy, rq.requestor, rq.property, rq.target, 3652 XChangeProperty (dpy, rq.requestor, rq.property, rq.target,
3582 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3653 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3654 ev.property = rq.property;
3655 }
3656 else if (rq.target == xa[XA_TIMESTAMP] && rq.selection == xa[XA_CLIPBOARD] && selection.clip_text)
3657 {
3658 XChangeProperty (dpy, rq.requestor, rq.property, rq.target,
3659 32, PropModeReplace, (unsigned char *)&clipboard_time, 1);
3583 ev.property = rq.property; 3660 ev.property = rq.property;
3584 } 3661 }
3585 else if (rq.target == XA_STRING 3662 else if (rq.target == XA_STRING
3586 || rq.target == xa[XA_TEXT] 3663 || rq.target == xa[XA_TEXT]
3587 || rq.target == xa[XA_COMPOUND_TEXT] 3664 || rq.target == xa[XA_COMPOUND_TEXT]
3620 { 3697 {
3621 target = xa[XA_COMPOUND_TEXT]; 3698 target = xa[XA_COMPOUND_TEXT];
3622 style = enc_compound_text; 3699 style = enc_compound_text;
3623 } 3700 }
3624 3701
3625 if (selection.text) 3702 if (rq.selection == XA_PRIMARY && selection.text)
3626 { 3703 {
3627 cl = selection.text; 3704 cl = selection.text;
3628 selectlen = selection.len; 3705 selectlen = selection.len;
3706 }
3707 else if (rq.selection == xa[XA_CLIPBOARD] && selection.clip_text)
3708 {
3709 cl = selection.clip_text;
3710 selectlen = selection.clip_len;
3629 } 3711 }
3630 else 3712 else
3631 { 3713 {
3632 cl = L""; 3714 cl = L"";
3633 selectlen = 0; 3715 selectlen = 0;
3701 h += 2; min_it (h, nrow); 3783 h += 2; min_it (h, nrow);
3702 3784
3703 x -= 1; clamp_it (x, 0, ncol - w); 3785 x -= 1; clamp_it (x, 0, ncol - w);
3704 y -= 1; clamp_it (y, 0, nrow - h); 3786 y -= 1; clamp_it (y, 0, nrow - h);
3705 3787
3706 ov_x = x; ov_y = y; 3788 ov.x = x; ov.y = y;
3707 ov_w = w; ov_h = h; 3789 ov.w = w; ov.h = h;
3708 3790
3709 ov_text = new text_t *[h]; 3791 ov.text = new text_t *[h];
3710 ov_rend = new rend_t *[h]; 3792 ov.rend = new rend_t *[h];
3711 3793
3712 for (y = 0; y < h; y++) 3794 for (y = 0; y < h; y++)
3713 { 3795 {
3714 text_t *tp = ov_text[y] = new text_t[w]; 3796 text_t *tp = ov.text[y] = new text_t[w];
3715 rend_t *rp = ov_rend[y] = new rend_t[w]; 3797 rend_t *rp = ov.rend[y] = new rend_t[w];
3716 3798
3717 text_t t0, t1, t2; 3799 text_t t0, t1, t2;
3718 rend_t r = OVERLAY_RSTYLE; 3800 rend_t r = OVERLAY_RSTYLE;
3719 3801
3720 if (y == 0) 3802 if (y == 0)
3739} 3821}
3740 3822
3741void 3823void
3742rxvt_term::scr_overlay_off () NOTHROW 3824rxvt_term::scr_overlay_off () NOTHROW
3743{ 3825{
3744 if (!ov_text) 3826 if (!ov.text)
3745 return; 3827 return;
3746 3828
3747 want_refresh = 1; 3829 want_refresh = 1;
3748 3830
3749 for (int y = 0; y < ov_h; y++) 3831 for (int y = 0; y < ov.h; y++)
3750 { 3832 {
3751 delete [] ov_text[y]; 3833 delete [] ov.text[y];
3752 delete [] ov_rend[y]; 3834 delete [] ov.rend[y];
3753 } 3835 }
3754 3836
3755 delete [] ov_text; ov_text = 0; 3837 delete [] ov.text; ov.text = 0;
3756 delete [] ov_rend; ov_rend = 0; 3838 delete [] ov.rend; ov.rend = 0;
3757} 3839}
3758 3840
3759void 3841void
3760rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW 3842rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW
3761{ 3843{
3762 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2) 3844 if (!ov.text || x >= ov.w - 2 || y >= ov.h - 2)
3763 return; 3845 return;
3764 3846
3765 x++, y++; 3847 x++, y++;
3766 3848
3767 ov_text[y][x] = text; 3849 ov.text[y][x] = text;
3768 ov_rend[y][x] = rend; 3850 ov.rend[y][x] = rend;
3769} 3851}
3770 3852
3771void 3853void
3772rxvt_term::scr_overlay_set (int x, int y, const char *s) NOTHROW 3854rxvt_term::scr_overlay_set (int x, int y, const char *s) NOTHROW
3773{ 3855{
3792} 3874}
3793 3875
3794void 3876void
3795rxvt_term::scr_swap_overlay () NOTHROW 3877rxvt_term::scr_swap_overlay () NOTHROW
3796{ 3878{
3797 if (!ov_text) 3879 if (!ov.text)
3798 return; 3880 return;
3799 3881
3882 // hide cursor if it is within the overlay area
3883 if (IN_RANGE_EXC (screen.cur.col - ov.x, 0, ov.w)
3884 && IN_RANGE_EXC (screen.cur.row - ov.y, 0, ov.h))
3885 screen.flags &= ~Screen_VisibleCursor;
3886
3800 // swap screen mem with overlay 3887 // swap screen mem with overlay
3801 for (int y = ov_h; y--; ) 3888 for (int y = ov.h; y--; )
3802 { 3889 {
3803 text_t *t1 = ov_text[y]; 3890 text_t *t1 = ov.text[y];
3804 rend_t *r1 = ov_rend[y]; 3891 rend_t *r1 = ov.rend[y];
3805 3892
3806 text_t *t2 = ROW(y + ov_y + view_start).t + ov_x; 3893 text_t *t2 = ROW(y + ov.y + view_start).t + ov.x;
3807 rend_t *r2 = ROW(y + ov_y + view_start).r + ov_x; 3894 rend_t *r2 = ROW(y + ov.y + view_start).r + ov.x;
3808 3895
3809 for (int x = ov_w; x--; ) 3896 for (int x = ov.w; x--; )
3810 { 3897 {
3811 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3898 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3812 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); 3899 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t));
3813 } 3900 }
3814 } 3901 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines