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.189 by root, Thu Dec 22 15:28:15 2005 UTC vs.
Revision 1.209 by root, Thu Jan 5 01:04:10 2006 UTC

24 * This file handles _all_ screen updates and selections 24 * This file handles _all_ screen updates and selections
25 */ 25 */
26 26
27#include "../config.h" /* NECESSARY */ 27#include "../config.h" /* NECESSARY */
28#include "rxvt.h" /* NECESSARY */ 28#include "rxvt.h" /* NECESSARY */
29#include "rxvtperl.h" /* NECESSARY */
29 30
30#include <X11/Xmd.h> /* get the typedef for CARD32 */ 31#include <X11/Xmd.h> /* get the typedef for CARD32 */
31 32
32#include <inttypes.h> 33#include <inttypes.h>
33 34
46 47
47/* ------------------------------------------------------------------------- * 48/* ------------------------------------------------------------------------- *
48 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 49 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
49 * ------------------------------------------------------------------------- */ 50 * ------------------------------------------------------------------------- */
50#define ZERO_SCROLLBACK() \ 51#define ZERO_SCROLLBACK() \
51 if (options & Opt_scrollTtyOutput) \ 52 if (OPTION (Opt_scrollTtyOutput)) \
52 view_start = 0 53 view_start = 0
53#define CLEAR_SELECTION() \ 54#define CLEAR_SELECTION() \
54 selection.beg.row = selection.beg.col \ 55 selection.beg.row = selection.beg.col \
55 = selection.end.row = selection.end.col = 0 56 = selection.end.row = selection.end.col = 0
56#define CLEAR_ALL_SELECTION() \ 57#define CLEAR_ALL_SELECTION() \
280 if (nsaved) 281 if (nsaved)
281 { 282 {
282 // 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
283 // to come up with a lean and mean algorithm. 284 // to come up with a lean and mean algorithm.
284 285
285 while (p != pend && q > 0) 286 row_col_t ocur = screen.cur;
287 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
288
289 do
286 { 290 {
287 p = MOD (p - 1, prev_total_rows); 291 p = MOD (p - 1, prev_total_rows);
288#ifdef DEBUG_STRICT 292#ifdef DEBUG_STRICT
289 assert (old_buf [MOD (p, prev_total_rows)].t); 293 assert (old_buf [MOD (p, prev_total_rows)].t);
290#endif 294#endif
291 295
296 int plines = 1;
292 int llen = old_buf [MOD (p, prev_total_rows)].l; 297 int llen = old_buf [MOD (p, prev_total_rows)].l;
293 298
294 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) 299 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
295 { 300 {
296 p = MOD (p - 1, prev_total_rows); 301 p = MOD (p - 1, prev_total_rows);
297 302
303 plines++;
298 llen += prev_ncol; 304 llen += prev_ncol;
299 } 305 }
300 306
301 int qlines = max (0, (llen - 1) / ncol) + 1; 307 int qlines = max (0, (llen - 1) / ncol) + 1;
302 308
322 while (lofs < llen && qcol < ncol) 328 while (lofs < llen && qcol < ncol)
323 { 329 {
324 int prow = lofs / prev_ncol; 330 int prow = lofs / prev_ncol;
325 int pcol = lofs % prev_ncol; 331 int pcol = lofs % prev_ncol;
326 332
327 line_t &pline = old_buf [MOD (p + prow, prev_total_rows)]; 333 prow = MOD (p + prow, prev_total_rows);
334
335 // we only adjust the cursor _row_ and put it into
336 // the topmost line of "long line" it was in, as
337 // this seems to upset applications/shells/readline
338 // least.
339 if (prow == ocur.row)
340 screen.cur.row = q - (total_rows - nrow);
341
342 line_t &pline = old_buf [prow];
328 343
329 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 344 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
330 345
331 assert (len); 346 assert (len);
332 assert (pline.t); 347 assert (pline.t);
337 lofs += len; 352 lofs += len;
338 qcol += len; 353 qcol += len;
339 } 354 }
340 } 355 }
341 356
342 qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1; 357 qline->l = llen ? MOD (llen - 1, ncol) + 1 : 0;
358#ifdef DEBUG_STRICT //TODO//FIXME//TEMPORARY
359 if (qline->l < 0)
360 {
361 fprintf (stderr, "ERROR, PLEASE REPORT to rxvt-unicode@plan9.de: qline->l %d = llen %d < ncol %d ? %d : MOD %d\n", qline->l,llen,ncol,llen,MOD (llen - 1, ncol) + 1);//D
362 qline->l = 0;
363 }
364#endif
343 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); 365 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
344 } 366 }
367 while (p != pend && q > 0);
345 368
346 term_start = total_rows - nrow; 369 term_start = total_rows - nrow;
347 view_start = 0;
348 nsaved = term_start - q; 370 nsaved = term_start - q;
349 371
350 // make sure all terminal lines exist 372 // make sure all terminal lines exist
351 while (nsaved < 0) 373 while (nsaved < 0)
352 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); 374 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
369 { 391 {
370 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE); 392 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
371 } 393 }
372 394
373 term_start = 0; 395 term_start = 0;
374 view_start = 0;
375 } 396 }
376 397
377#ifdef DEBUG_STRICT 398#ifdef DEBUG_STRICT //TODO: remove
378 for (int i = -nsaved; i < nrow; i++) 399 for (int i = -nsaved; i < nrow; i++)
379 assert (ROW (i).t); 400 assert (ROW (i).t);
380#endif 401#endif
381 402
382 free (old_buf); 403 free (old_buf);
397 418
398 for (int col = ncol; col--; ) 419 for (int col = ncol; col--; )
399 tabs [col] = col % TABSIZE == 0; 420 tabs [col] = col % TABSIZE == 0;
400 421
401 tt_winch (); 422 tt_winch ();
423
424 PERL_INVOKE ((this, HOOK_RESET, DT_END));
402} 425}
403 426
404/* ------------------------------------------------------------------------- */ 427/* ------------------------------------------------------------------------- */
405/* 428/*
406 * Free everything. That way malloc debugging can find leakage. 429 * Free everything. That way malloc debugging can find leakage.
510 533
511 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1); 534 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
512 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1); 535 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
513 536
514#if NSCREENS 537#if NSCREENS
515 if (options & Opt_secondaryScreen) 538 if (OPTION (Opt_secondaryScreen))
516 { 539 {
517 num_scr = 0; 540 num_scr = 0;
518 541
519 for (int i = prev_nrow; i--; ) 542 for (int i = prev_nrow; i--; )
520 ::swap (ROW(i), swap_buf [i]); 543 ::swap (ROW(i), swap_buf [i]);
524 screen.flags |= Screen_VisibleCursor; 547 screen.flags |= Screen_VisibleCursor;
525 swap.flags |= Screen_VisibleCursor; 548 swap.flags |= Screen_VisibleCursor;
526 } 549 }
527 else 550 else
528#endif 551#endif
529 if (options & Opt_secondaryScroll) 552 if (OPTION (Opt_secondaryScroll))
530 scr_scroll_text (0, prev_nrow - 1, prev_nrow); 553 scr_scroll_text (0, prev_nrow - 1, prev_nrow);
531 554
532 return scrn; 555 return scrn;
533} 556}
534 557
596 num_scr += count; 619 num_scr += count;
597 620
598 if (count > 0 621 if (count > 0
599 && row1 == 0 622 && row1 == 0
600 && row2 == nrow - 1 623 && row2 == nrow - 1
601 && (current_screen == PRIMARY || options & Opt_secondaryScroll)) 624 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll)))
602 { 625 {
603 nsaved = min (nsaved + count, saveLines); 626 nsaved = min (nsaved + count, saveLines);
627
628 PERL_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, nsaved, DT_END));
629
604 term_start = (term_start + count) % total_rows; 630 term_start = (term_start + count) % total_rows;
605 631
606 if (selection.op && current_screen == selection.screen) 632 if (selection.op && current_screen == selection.screen)
607 { 633 {
608 selection.beg.row -= count; 634 selection.beg.row -= count;
609 selection.end.row -= count; 635 selection.end.row -= count;
610 selection.mark.row -= count; 636 selection.mark.row -= count;
611 637
612 selection_check (0); 638 if (selection.beg.row < -nsaved
639 || selection.end.row < -nsaved
640 || selection.mark.row < -nsaved)
641 {
642 CLEAR_ALL_SELECTION ();
643 selection.op = SELECTION_CLEAR;
644 }
613 } 645 }
614 646
615 for (int i = count; i--; ) 647 for (int i = count; i--; )
648 {
649 ROW(row2 - i).l = 0;
616 scr_blank_screen_mem (ROW(row2 - i), rstyle); 650 scr_blank_screen_mem (ROW(row2 - i), rstyle);
651 }
617 652
618 if ((options & Opt_scrollWithBuffer) 653 if (OPTION (Opt_scrollWithBuffer)
619 && view_start != 0 654 && view_start != 0
620 && view_start != saveLines) 655 && view_start != saveLines)
621 scr_page (UP, count); 656 scr_page (UP, count);
622 } 657 }
623 else 658 else
624 { 659 {
625 if (selection.op && current_screen == selection.screen) 660 if (selection.op && current_screen == selection.screen)
626 { 661 {
627 int i = selection.beg.row; 662 if ((selection.beg.row < row1 && selection.end.row > row1)
628 int j = selection.end.row; 663 || (selection.beg.row < row2 && selection.end.row > row2)
629
630 if ((i < row1 && j > row1)
631 || (i < row2 && j > row2)
632 || (i - count < row1 && i >= row1) 664 || (selection.beg.row - count < row1 && selection.beg.row >= row1)
633 || (i - count > row2 && i <= row2) 665 || (selection.beg.row - count > row2 && selection.beg.row <= row2)
634 || (j - count < row1 && j >= row1) 666 || (selection.end.row - count < row1 && selection.end.row >= row1)
635 || (j - count > row2 && j <= row2)) 667 || (selection.end.row - count > row2 && selection.end.row <= row2))
636 { 668 {
637 CLEAR_ALL_SELECTION (); 669 CLEAR_ALL_SELECTION ();
638 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ 670 selection.op = SELECTION_CLEAR;
639 } 671 }
640 else if (j >= row1 && j <= row2) 672 else if (selection.end.row >= row1 && selection.end.row <= row2)
641 { 673 {
642 /* move selected region too */ 674 /* move selected region too */
643 selection.beg.row -= count; 675 selection.beg.row -= count;
644 selection.end.row -= count; 676 selection.end.row -= count;
645 selection.mark.row -= count; 677 selection.mark.row -= count;
680 if (len <= 0) /* sanity */ 712 if (len <= 0) /* sanity */
681 return; 713 return;
682 714
683 unsigned char checksel; 715 unsigned char checksel;
684 unicode_t c; 716 unicode_t c;
685 int row, last_col; 717 int last_col;
686 const unicode_t *strend = str + len; 718 const unicode_t *strend = str + len;
687 719
688 want_refresh = 1; 720 want_refresh = 1;
689 ZERO_SCROLLBACK (); 721 ZERO_SCROLLBACK ();
690 last_col = ncol; 722 last_col = ncol;
691 723
692 if (nlines > 0) 724 if (nlines > 0)
693 { 725 {
694 nlines += screen.cur.row - screen.bscroll; 726 nlines += screen.cur.row - screen.bscroll;
727
695 if (nlines > 0 728 if (nlines > 0
696 && screen.tscroll == 0 729 && screen.tscroll == 0
697 && screen.bscroll == (nrow - 1)) 730 && screen.bscroll == (nrow - 1))
698 { 731 {
699 /* _at least_ this many lines need to be scrolled */ 732 /* _at least_ this many lines need to be scrolled */
705#ifdef DEBUG_STRICT 738#ifdef DEBUG_STRICT
706 assert (screen.cur.col < last_col); 739 assert (screen.cur.col < last_col);
707 assert (screen.cur.row < nrow 740 assert (screen.cur.row < nrow
708 && screen.cur.row >= -nsaved); 741 && screen.cur.row >= -nsaved);
709#endif 742#endif
710 row = screen.cur.row; 743 int row = screen.cur.row;
711 744
712 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 745 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
713 746
714 line_t *line = &ROW(row); 747 line_t *line = &ROW(row);
715 748
717 { 750 {
718 c = *str++; 751 c = *str++;
719 752
720 if (c < 0x20) 753 if (c < 0x20)
721 if (c == C0_LF) 754 if (c == C0_LF)
722 { 755 {
723 if (!line->is_longer ()) /* XXX: think about this */ 756 if (!line->is_longer ()) /* XXX: think about this */
724 max_it (line->l, screen.cur.col); 757 max_it (line->l, screen.cur.col);
725 758
726 screen.flags &= ~Screen_WrapNext; 759 screen.flags &= ~Screen_WrapNext;
727 760
972 1005
973 if (count == 0) 1006 if (count == 0)
974 return; 1007 return;
975 else if (count > 0) 1008 else if (count > 0)
976 { 1009 {
977 int row = screen.cur.row;
978
979 line_t &l = ROW(row); 1010 line_t &l = ROW(screen.cur.row);
980 rend_t base_rend = l.r[i]; 1011 rend_t base_rend = l.r[i];
981 ht &= l.t[i] == ' '; 1012 ht &= l.t[i] == ' ';
982 1013
983 for (; ++i < ncol; ) 1014 for (; ++i < ncol; )
984 if (tabs[i]) 1015 if (tabs[i])
994 if (count) 1025 if (count)
995 x = ncol - 1; 1026 x = ncol - 1;
996 1027
997 // store horizontal tab commands as characters inside the text 1028 // store horizontal tab commands as characters inside the text
998 // buffer so they can be selected and pasted. 1029 // buffer so they can be selected and pasted.
999 if (ht && options & Opt_pastableTabs) 1030 if (ht && OPTION (Opt_pastableTabs))
1000 { 1031 {
1001 base_rend = SET_FONT (base_rend, 0); 1032 base_rend = SET_FONT (base_rend, 0);
1002 1033
1003 if (!l.is_longer ()) /* XXX: think about this */ 1034 if (!l.is_longer ()) /* XXX: think about this */
1004 max_it (l.l, x); 1035 max_it (l.l, x);
1059 */ 1090 */
1060#if ENABLE_FRILLS 1091#if ENABLE_FRILLS
1061void 1092void
1062rxvt_term::scr_forwardindex () 1093rxvt_term::scr_forwardindex ()
1063{ 1094{
1064 int row;
1065
1066 if (screen.cur.col < ncol - 1) 1095 if (screen.cur.col < ncol - 1)
1067 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1096 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1068 else 1097 else
1069 { 1098 {
1070 row = screen.cur.row;
1071
1072 if (ROW(row).is_longer ()) //TODO//FIXME//LEN 1099 if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN
1073 ROW(row).l = ncol; 1100 ROW(screen.cur.row).l = ncol;
1074 1101
1075 scr_gotorc (0, 0, R_RELATIVE); 1102 scr_gotorc (0, 0, R_RELATIVE);
1076 scr_insdel_chars (1, DELETE); 1103 scr_insdel_chars (1, DELETE);
1077 scr_gotorc (0, ncol - 1, R_RELATIVE); 1104 scr_gotorc (0, ncol - 1, R_RELATIVE);
1078 } 1105 }
1161 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1188 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1162 */ 1189 */
1163void 1190void
1164rxvt_term::scr_erase_line (int mode) 1191rxvt_term::scr_erase_line (int mode)
1165{ 1192{
1166 unsigned int row, col, num; 1193 unsigned int col, num;
1167 1194
1168 want_refresh = 1; 1195 want_refresh = 1;
1169 ZERO_SCROLLBACK (); 1196 ZERO_SCROLLBACK ();
1170 1197
1171 selection_check (1); 1198 selection_check (1);
1172 1199
1173 row = screen.cur.row; 1200 line_t &line = ROW(screen.cur.row);
1174 1201
1175 switch (mode) 1202 switch (mode)
1176 { 1203 {
1177 case 0: /* erase to end of line */ 1204 case 0: /* erase to end of line */
1178 col = screen.cur.col; 1205 col = screen.cur.col;
1179 num = ncol - col; 1206 num = ncol - col;
1180 min_it (ROW(row).l, col); 1207 min_it (line.l, col);
1181 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1208 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1182 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1209 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1183 CLEAR_SELECTION (); 1210 CLEAR_SELECTION ();
1184 break; 1211 break;
1185 case 1: /* erase to beginning of line */ 1212 case 1: /* erase to beginning of line */
1190 CLEAR_SELECTION (); 1217 CLEAR_SELECTION ();
1191 break; 1218 break;
1192 case 2: /* erase whole line */ 1219 case 2: /* erase whole line */
1193 col = 0; 1220 col = 0;
1194 num = ncol; 1221 num = ncol;
1195 ROW(row).l = 0; 1222 line.l = 0;
1196 if (selection.beg.row <= screen.cur.row 1223 if (selection.beg.row <= screen.cur.row
1197 && selection.end.row >= screen.cur.row) 1224 && selection.end.row >= screen.cur.row)
1198 CLEAR_SELECTION (); 1225 CLEAR_SELECTION ();
1199 break; 1226 break;
1200 default: 1227 default:
1201 return; 1228 return;
1202 } 1229 }
1203 1230
1204 scr_blank_line (ROW(row), col, num, rstyle); 1231 scr_blank_line (line, col, num, rstyle);
1205} 1232}
1206 1233
1207/* ------------------------------------------------------------------------- */ 1234/* ------------------------------------------------------------------------- */
1208/* 1235/*
1209 * Erase part of whole of the screen 1236 * Erase part of whole of the screen
1264 CLEAR_ROWS (row, num); 1291 CLEAR_ROWS (row, num);
1265 } 1292 }
1266 else 1293 else
1267 { 1294 {
1268 ren = rstyle & (RS_fgMask | RS_bgMask); 1295 ren = rstyle & (RS_fgMask | RS_bgMask);
1269 gcvalue.foreground = pix_colors[GET_BGCOLOR (rstyle)]; 1296 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1270 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1297 XChangeGC (display->display, gc, GCForeground, &gcvalue);
1271 ERASE_ROWS (row, num); 1298 ERASE_ROWS (row, num);
1272 gcvalue.foreground = pix_colors[Color_fg]; 1299 gcvalue.foreground = pix_colors[Color_fg];
1273 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1300 XChangeGC (display->display, gc, GCForeground, &gcvalue);
1274 } 1301 }
1275 1302
1276 for (; num--; row++) 1303 for (; num--; row++)
1277 { 1304 {
1305 ROW (row).l = 0;
1278 scr_blank_screen_mem (ROW (row), rstyle); 1306 scr_blank_screen_mem (ROW (row), rstyle);
1279 ROW (row).l = 0;
1280 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1307 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1281 } 1308 }
1282} 1309}
1283 1310
1284#if ENABLE_FRILLS 1311#if ENABLE_FRILLS
1573 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1600 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1574#if XPM_BACKGROUND 1601#if XPM_BACKGROUND
1575 if (bgPixmap.pixmap == None) 1602 if (bgPixmap.pixmap == None)
1576#endif 1603#endif
1577#if TRANSPARENT 1604#if TRANSPARENT
1578 if (! (options & Opt_transparent) || am_transparent == 0) 1605 if (! OPTION (Opt_transparent) || am_transparent == 0)
1579#endif 1606#endif
1580 XSetWindowBackground (display->display, vt, 1607 XSetWindowBackground (display->display, vt,
1581 pix_colors[Color_bg]); 1608 pix_colors[Color_bg]);
1582 1609
1583 gcvalue.foreground = pix_colors[Color_fg]; 1610 gcvalue.foreground = pix_colors[Color_fg];
1799} 1826}
1800 1827
1801int 1828int
1802rxvt_term::scr_changeview (unsigned int oldviewstart) 1829rxvt_term::scr_changeview (unsigned int oldviewstart)
1803{ 1830{
1831 PERL_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END));
1832
1804 if (view_start != oldviewstart) 1833 if (view_start != oldviewstart)
1805 { 1834 {
1806 want_refresh = 1; 1835 want_refresh = 1;
1807 num_scr -= (view_start - oldviewstart); 1836 num_scr -= (view_start - oldviewstart);
1808 } 1837 }
1816{ 1845{
1817#ifndef NO_BELL 1846#ifndef NO_BELL
1818 1847
1819# ifndef NO_MAPALERT 1848# ifndef NO_MAPALERT
1820# ifdef MAPALERT_OPTION 1849# ifdef MAPALERT_OPTION
1821 if (options & Opt_mapAlert) 1850 if (OPTION (Opt_mapAlert))
1822# endif 1851# endif
1823 XMapWindow (display->display, parent[0]); 1852 XMapWindow (display->display, parent[0]);
1824# endif 1853# endif
1825 1854
1826 if (options & Opt_visualBell) 1855 if (OPTION (Opt_visualBell))
1827 { 1856 {
1828 scr_rvideo_mode (!rvideo); /* refresh also done */ 1857 scr_rvideo_mode (!rvideo); /* refresh also done */
1829 rxvt_usleep (VISUAL_BELL_DURATION); 1858 rxvt_usleep (VISUAL_BELL_DURATION);
1830 scr_rvideo_mode (!rvideo); /* refresh also done */ 1859 scr_rvideo_mode (!rvideo); /* refresh also done */
1831 } 1860 }
1922 1951
1923#if XPM_BACKGROUND 1952#if XPM_BACKGROUND
1924 must_clear |= bgPixmap.pixmap != None; 1953 must_clear |= bgPixmap.pixmap != None;
1925#endif 1954#endif
1926#if TRANSPARENT 1955#if TRANSPARENT
1927 must_clear |= (options & Opt_transparent) && am_transparent; 1956 must_clear |= OPTION (Opt_transparent) && am_transparent;
1928#endif 1957#endif
1929 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 1958 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1930 1959
1931 /* 1960 /*
1932 * B: reverse any characters which are selected 1961 * B: reverse any characters which are selected
1956 1985
1957 crp = &ROW(screen.cur.row).r[col]; 1986 crp = &ROW(screen.cur.row).r[col];
1958 1987
1959 if (showcursor && focus) 1988 if (showcursor && focus)
1960 { 1989 {
1961 if (options & Opt_cursorUnderline) 1990 if (OPTION (Opt_cursorUnderline))
1962 *crp ^= RS_Uline; 1991 *crp ^= RS_Uline;
1963 else 1992 else
1964 { 1993 {
1965 *crp ^= RS_RVid; 1994 *crp ^= RS_RVid;
1966 1995
1968 cc1 = *crp & (RS_fgMask | RS_bgMask); 1997 cc1 = *crp & (RS_fgMask | RS_bgMask);
1969 if (ISSET_PIXCOLOR (Color_cursor)) 1998 if (ISSET_PIXCOLOR (Color_cursor))
1970 ccol1 = Color_cursor; 1999 ccol1 = Color_cursor;
1971 else 2000 else
1972#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 2001#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1973 ccol1 = GET_FGCOLOR (rstyle); 2002 ccol1 = fgcolor_of (rstyle);
1974#else 2003#else
1975 ccol1 = Color_fg; 2004 ccol1 = Color_fg;
1976#endif 2005#endif
1977 if (ISSET_PIXCOLOR (Color_cursor2)) 2006 if (ISSET_PIXCOLOR (Color_cursor2))
1978 ccol2 = Color_cursor2; 2007 ccol2 = Color_cursor2;
1979 else 2008 else
1980#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 2009#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1981 ccol2 = GET_BGCOLOR (rstyle); 2010 ccol2 = bgcolor_of (rstyle);
1982#else 2011#else
1983 ccol2 = Color_bg; 2012 ccol2 = Color_bg;
1984#endif 2013#endif
1985 *crp = SET_FGCOLOR (*crp, ccol1); 2014 *crp = SET_FGCOLOR (*crp, ccol1);
1986 *crp = SET_BGCOLOR (*crp, ccol2); 2015 *crp = SET_BGCOLOR (*crp, ccol2);
2019 oldcursor.col = screen.cur.col; 2048 oldcursor.col = screen.cur.col;
2020 } 2049 }
2021 } 2050 }
2022 } 2051 }
2023 2052
2053 PERL_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
2024#if ENABLE_OVERLAY 2054#if ENABLE_OVERLAY
2025 scr_swap_overlay (); 2055 scr_swap_overlay ();
2026#endif 2056#endif
2027 2057
2028#ifndef NO_SLOW_LINK_SUPPORT 2058#ifndef NO_SLOW_LINK_SUPPORT
2078 if (wlen < len) 2108 if (wlen < len)
2079 ::swap (wlen, len); 2109 ::swap (wlen, len);
2080 2110
2081 XCopyArea (display->display, vt, vt, 2111 XCopyArea (display->display, vt, vt,
2082 gc, 0, Row2Pixel (len + i), 2112 gc, 0, Row2Pixel (len + i),
2083 (unsigned int)TermWin_TotalWidth (), 2113 (unsigned int)this->width,
2084 (unsigned int)Height2Pixel (wlen - len + 1), 2114 (unsigned int)Height2Pixel (wlen - len + 1),
2085 0, Row2Pixel (len)); 2115 0, Row2Pixel (len));
2086 len = -1; 2116 len = -1;
2087 } 2117 }
2088 } 2118 }
2167 count++, i--; 2197 count++, i--;
2168 2198
2169 /* 2199 /*
2170 * Determine the attributes for the string 2200 * Determine the attributes for the string
2171 */ 2201 */
2172 int fore = GET_FGCOLOR (rend); // desired foreground 2202 int fore = fgcolor_of (rend); // desired foreground
2173 int back = GET_BGCOLOR (rend); // desired background 2203 int back = bgcolor_of (rend); // desired background
2174 2204
2175 // only do special processing if any attributes are set, which is rare 2205 // only do special processing if any attributes are set, which is unlikely
2176 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2206 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))
2177 { 2207 {
2178#if ENABLE_STYLES 2208#if ENABLE_STYLES
2179 // force redraw after "careful" characters to avoid pixel droppings 2209 // force redraw after "careful" characters to avoid pixel droppings
2180 if (srp[col] & RS_Careful && col < ncol - 1 && 0) 2210 if (srp[col] & RS_Careful && col < ncol - 1 && 0)
2291 } /* for (row....) */ 2321 } /* for (row....) */
2292 2322
2293#if ENABLE_OVERLAY 2323#if ENABLE_OVERLAY
2294 scr_swap_overlay (); 2324 scr_swap_overlay ();
2295#endif 2325#endif
2326 PERL_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2296 2327
2297 /* 2328 /*
2298 * G: cleanup cursor and display outline cursor if necessary 2329 * G: cleanup cursor and display outline cursor if necessary
2299 */ 2330 */
2300 if (showcursor) 2331 if (showcursor)
2301 { 2332 {
2302 if (focus) 2333 if (focus)
2303 { 2334 {
2304 if (options & Opt_cursorUnderline) 2335 if (OPTION (Opt_cursorUnderline))
2305 *crp ^= RS_Uline; 2336 *crp ^= RS_Uline;
2306 else 2337 else
2307 { 2338 {
2308 *crp ^= RS_RVid; 2339 *crp ^= RS_RVid;
2309#ifndef NO_CURSORCOLOR 2340#ifndef NO_CURSORCOLOR
2428 2459
2429#if ENABLE_FRILLS 2460#if ENABLE_FRILLS
2430 if (selection.rect) 2461 if (selection.rect)
2431 { 2462 {
2432 for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++) 2463 for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++)
2464 {
2465 text_t *stp = ROW(row).t;
2466 rend_t *srp = ROW(row).r;
2467
2433 for (rend_t *srp = ROW(row).r, col = selection.beg.col; col < selection.end.col; col++) 2468 for (col = selection.beg.col; col < selection.end.col; col++)
2434 srp[col] ^= RS_RVid; 2469 srp[col] ^= RS_RVid;
2470
2471 while (col-- > selection.beg.col && (stp[col] == NOCHAR || unicode::is_space (stp[col])))
2472 srp[col] ^= RS_RVid | RS_Uline;
2473
2474 if (++col < selection.end.col)
2475 srp[col] ^= RS_RVid | RS_Uline;
2476 }
2435 } 2477 }
2436 else 2478 else
2437#endif 2479#endif
2438 { 2480 {
2439 if (selection.beg.row >= -view_start) 2481 if (selection.beg.row >= -view_start)
2442 row = selection.beg.row; 2484 row = selection.beg.row;
2443 } 2485 }
2444 else 2486 else
2445 { 2487 {
2446 col = 0; 2488 col = 0;
2447 row = view_start; 2489 row = -view_start;
2448 } 2490 }
2449 2491
2450 for (; row < min (selection.end.row, view_end); row++, col = 0) 2492 for (; row < min (selection.end.row, view_end); row++, col = 0)
2451 for (rend_t *srp = ROW(row).r; col < ncol; col++) 2493 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2452 srp[col] ^= RS_RVid; 2494 srp[col] ^= RS_RVid;
2523/* ------------------------------------------------------------------------- */ 2565/* ------------------------------------------------------------------------- */
2524/* 2566/*
2525 * Paste a selection direct to the command fd 2567 * Paste a selection direct to the command fd
2526 */ 2568 */
2527void 2569void
2528rxvt_term::paste (unsigned char *data, unsigned int len) 2570rxvt_term::paste (char *data, unsigned int len)
2529{ 2571{
2530 /* convert normal newline chars into common keyboard Return key sequence */ 2572 /* convert normal newline chars into common keyboard Return key sequence */
2531 for (unsigned int i = 0; i < len; i++) 2573 for (unsigned int i = 0; i < len; i++)
2532 if (data[i] == C0_LF) 2574 if (data[i] == C0_LF)
2533 data[i] = C0_CR; 2575 data[i] = C0_CR;
2677 { 2719 {
2678 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); 2720 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2679 char *s = rxvt_wcstombs (w); 2721 char *s = rxvt_wcstombs (w);
2680 free (w); 2722 free (w);
2681 // TODO: strlen == only the first element will be converted. well... 2723 // TODO: strlen == only the first element will be converted. well...
2682 paste ((unsigned char *)s, strlen (s)); 2724 paste (s, strlen (s));
2683 free (s); 2725 free (s);
2684 } 2726 }
2685 else 2727 else
2686#endif 2728#endif
2687 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 2729 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0
2688 && cl) 2730 && cl)
2689 { 2731 {
2690 for (int i = 0; i < cr; i++) 2732 for (int i = 0; i < cr; i++)
2691 paste ((unsigned char *)cl[i], strlen (cl[i])); 2733 paste (cl[i], strlen (cl[i]));
2692 2734
2693 XFreeStringList (cl); 2735 XFreeStringList (cl);
2694 } 2736 }
2695 else 2737 else
2696 paste (ct.value, ct.nitems); // paste raw 2738 paste ((char *)ct.value, ct.nitems); // paste raw
2697 2739
2698bailout: 2740bailout:
2699 XFree (ct.value); 2741 XFree (ct.value);
2700 2742
2701 if (selection_wait == Sel_normal) 2743 if (selection_wait == Sel_normal)
2739 return; /* outside window */ 2781 return; /* outside window */
2740 2782
2741 if (selection.text) 2783 if (selection.text)
2742 { /* internal selection */ 2784 { /* internal selection */
2743 char *str = rxvt_wcstombs (selection.text, selection.len); 2785 char *str = rxvt_wcstombs (selection.text, selection.len);
2744 paste ((unsigned char *)str, strlen (str)); 2786 paste (str, strlen (str));
2745 free (str); 2787 free (str);
2746 return; 2788 return;
2747 } 2789 }
2748 else 2790 else
2749 { 2791 {
2841 selection.op = SELECTION_DONE; 2883 selection.op = SELECTION_DONE;
2842 2884
2843 if (selection.clicks == 4) 2885 if (selection.clicks == 4)
2844 return; /* nothing selected, go away */ 2886 return; /* nothing selected, go away */
2845 2887
2888 if (PERL_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END)))
2889 return;
2890
2846 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); 2891 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1);
2847 new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t)); 2892 new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t));
2848 2893
2849 int ofs = 0; 2894 int ofs = 0;
2850 int extra = 0; 2895 int extra = 0;
2866#endif 2911#endif
2867 end_col = ROW(row).is_longer () ? ncol : ROW(row).l; //TODO//FIXME//LEN 2912 end_col = ROW(row).is_longer () ? ncol : ROW(row).l; //TODO//FIXME//LEN
2868 2913
2869 col = max (col, 0); 2914 col = max (col, 0);
2870 2915
2871 if (row == selection.end.row || selection.rect) 2916 if (row == selection.end.row
2917#if ENABLE_FRILLS
2918 || selection.rect
2919#endif
2920 )
2872 end_col = min (end_col, selection.end.col); 2921 min_it (end_col, selection.end.col);
2873 2922
2874 t = ROW(row).t + col; 2923 t = ROW(row).t + col;
2875 for (; col < end_col; col++) 2924 for (; col < end_col; col++)
2876 { 2925 {
2877 if (*t == NOCHAR) 2926 if (*t == NOCHAR)
2895#endif 2944#endif
2896 else 2945 else
2897 new_selection_text[ofs++] = *t++; 2946 new_selection_text[ofs++] = *t++;
2898 } 2947 }
2899 2948
2949#if ENABLE_FRILLS
2950 if (selection.rect)
2951 {
2952 while (ofs
2953 && new_selection_text[ofs - 1] != C0_LF
2954 && unicode::is_space (new_selection_text[ofs - 1]))
2955 --ofs;
2956
2957 new_selection_text[ofs++] = C0_LF;
2958 }
2959 else
2960#endif
2900 if (!ROW(row).is_longer () && row != selection.end.row) 2961 if (!ROW(row).is_longer () && row != selection.end.row)
2901 new_selection_text[ofs++] = C0_LF; 2962 new_selection_text[ofs++] = C0_LF;
2902 } 2963 }
2903 2964
2904 if (end_col != selection.end.col) 2965 if (end_col != selection.end.col)
2905 new_selection_text[ofs++] = C0_LF; 2966 new_selection_text[ofs++] = C0_LF;
2906 2967
2916 2977
2917 // we usually allocate much more than necessary, so realloc it smaller again 2978 // we usually allocate much more than necessary, so realloc it smaller again
2918 selection.len = ofs; 2979 selection.len = ofs;
2919 selection.text = (wchar_t *)rxvt_realloc (new_selection_text, (ofs + 1) * sizeof (wchar_t)); 2980 selection.text = (wchar_t *)rxvt_realloc (new_selection_text, (ofs + 1) * sizeof (wchar_t));
2920 2981
2982 if (PERL_INVOKE ((this, HOOK_SEL_GRAB, DT_LONG, (long)tm, DT_END)))
2983 return;
2984
2985 selection_grab (tm);
2986}
2987
2988bool
2989rxvt_term::selection_grab (Time tm)
2990{
2991 selection_time = tm;
2992
2921 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); 2993 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm);
2922 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) 2994 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt)
2995 {
2923 display->set_selection_owner (this); 2996 display->set_selection_owner (this);
2997 return true;
2998 }
2924 else 2999 else
2925 rxvt_warn ("can't get primary selection, ignoring.\n"); 3000 return false;
2926 3001
2927#if 0 3002#if 0
2928 XTextProperty ct; 3003 XTextProperty ct;
2929 3004
2930 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3005 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0)
2931 { 3006 {
2932 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); 3007 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
2933 XFree (ct.value); 3008 XFree (ct.value);
2934 } 3009 }
2935#endif 3010#endif
2936
2937 selection_time = tm;
2938} 3011}
2939 3012
2940/* ------------------------------------------------------------------------- */ 3013/* ------------------------------------------------------------------------- */
2941/* 3014/*
2942 * Mark or select text based upon number of clicks: 1, 2, or 3 3015 * Mark or select text based upon number of clicks: 1, 2, or 3
3064 } 3137 }
3065 } 3138 }
3066 break; 3139 break;
3067 } 3140 }
3068 3141
3069Old_Word_Selection_You_Die:
3070 if (dirn == DN) 3142 if (dirn == DN)
3071 col++; /* put us on one past the end */ 3143 col++; /* put us on one past the end */
3072 3144
3073 /* Poke the values back in */ 3145 /* Poke the values back in */
3074 ret->row = row; 3146 ret->row = row;
3251 else if (selection.clicks == 2) 3323 else if (selection.clicks == 2)
3252 { 3324 {
3253 if (ROWCOL_IS_AFTER (selection.end, selection.beg)) 3325 if (ROWCOL_IS_AFTER (selection.end, selection.beg))
3254 selection.end.col--; 3326 selection.end.col--;
3255 3327
3328 if (!PERL_INVOKE ((this, HOOK_SEL_EXTEND, DT_END)))
3329 {
3256 selection_delimit_word (UP, &selection.beg, &selection.beg); 3330 selection_delimit_word (UP, &selection.beg, &selection.beg);
3257 selection_delimit_word (DN, &selection.end, &selection.end); 3331 selection_delimit_word (DN, &selection.end, &selection.end);
3332 }
3258 } 3333 }
3259 else if (selection.clicks == 3) 3334 else if (selection.clicks == 3)
3260 { 3335 {
3261#if ENABLE_FRILLS 3336#if ENABLE_FRILLS
3262 if (options & Opt_tripleclickwords) 3337 if (OPTION (Opt_tripleclickwords))
3263 { 3338 {
3264 selection_delimit_word (UP, &selection.beg, &selection.beg); 3339 selection_delimit_word (UP, &selection.beg, &selection.beg);
3265 3340
3266 for (int end_row = selection.mark.row; end_row < nrow; end_row++) 3341 for (int end_row = selection.mark.row; end_row < nrow; end_row++)
3267 { 3342 {
3328 { 3403 {
3329 stp = ROW(end_row).t; 3404 stp = ROW(end_row).t;
3330 3405
3331 while (--end_col >= 0) 3406 while (--end_col >= 0)
3332 { 3407 {
3333 if (stp[end_col] != ' ' 3408 if (stp[end_col] != NOCHAR
3334 && stp[end_col] != '\t' 3409 && !unicode::is_space (stp[end_col]))
3335 && stp[end_col] != NOCHAR)
3336 break; 3410 break;
3337 } 3411 }
3338 3412
3339 if (end_col >= 0 3413 if (end_col >= 0
3340 || !ROW(end_row - 1).is_longer ()) 3414 || !ROW(end_row - 1).is_longer ())
3539 3613
3540#if ENABLE_OVERLAY 3614#if ENABLE_OVERLAY
3541void 3615void
3542rxvt_term::scr_overlay_new (int x, int y, int w, int h) 3616rxvt_term::scr_overlay_new (int x, int y, int w, int h)
3543{ 3617{
3544 if (nrow < 3 || ncol < 3) 3618 if (nrow < 1 || ncol < 1)
3545 return; 3619 return;
3546 3620
3547 want_refresh = 1; 3621 want_refresh = 1;
3548 3622
3549 scr_overlay_off (); 3623 scr_overlay_off ();
3656 for (int y = ov_h; y--; ) 3730 for (int y = ov_h; y--; )
3657 { 3731 {
3658 text_t *t1 = ov_text[y]; 3732 text_t *t1 = ov_text[y];
3659 rend_t *r1 = ov_rend[y]; 3733 rend_t *r1 = ov_rend[y];
3660 3734
3661 text_t *t2 = ROW(y - view_start).t + ov_x; 3735 text_t *t2 = ROW(y + ov_y - view_start).t + ov_x;
3662 rend_t *r2 = ROW(y - view_start).r + ov_x; 3736 rend_t *r2 = ROW(y + ov_y - view_start).r + ov_x;
3663 3737
3664 for (int x = ov_w; x--; ) 3738 for (int x = ov_w; x--; )
3665 { 3739 {
3666 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3740 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3667 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); 3741 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines