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.387 by root, Thu Jul 7 23:18:13 2011 UTC vs.
Revision 1.414 by sf-exg, Tue Jan 24 17:05:05 2012 UTC

203 term_start = 0; 203 term_start = 0;
204 204
205 talloc = new rxvt_salloc (ncol * sizeof (text_t)); 205 talloc = new rxvt_salloc (ncol * sizeof (text_t));
206 ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 206 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
207 207
208 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t)); 208 row_buf = (line_t *)rxvt_calloc (total_rows , sizeof (line_t));
209 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); 209 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
210 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); 210 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
211 211
212 for (int row = nrow; row--; ) 212 for (int row = nrow; row--; )
213 { 213 {
275 swap_buf [row].clear (); scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); 275 swap_buf [row].clear (); scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
276 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 276 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
277 } 277 }
278 278
279 line_t *old_buf = row_buf; 279 line_t *old_buf = row_buf;
280 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t)); 280 row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
281 281
282 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 282 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
283 int pend = MOD (term_start + top_row , prev_total_rows); 283 int pend = MOD (term_start + top_row , prev_total_rows);
284 int q = total_rows; // rewrapped row 284 int q = total_rows; // rewrapped row
285 285
455 scr_clear (true); 455 scr_clear (true);
456 scr_refresh (); 456 scr_refresh ();
457} 457}
458 458
459void 459void
460rxvt_term::scr_soft_reset () 460rxvt_term::scr_soft_reset () NOTHROW
461{ 461{
462 /* only affects modes, nothing drastic such as clearing the screen */ 462 /* only affects modes, nothing drastic such as clearing the screen */
463#if ENABLE_OVERLAY 463#if ENABLE_OVERLAY
464 scr_overlay_off (); 464 scr_overlay_off ();
465#endif 465#endif
520 assert (s->cur.row >= 0); 520 assert (s->cur.row >= 0);
521 assert (s->cur.col >= 0); 521 assert (s->cur.col >= 0);
522} 522}
523 523
524void 524void
525rxvt_term::scr_swap_screen () 525rxvt_term::scr_swap_screen () NOTHROW
526{ 526{
527 if (!option (Opt_secondaryScreen)) 527 if (!option (Opt_secondaryScreen))
528 return; 528 return;
529 529
530 for (int i = prev_nrow; i--; ) 530 for (int i = prev_nrow; i--; )
549 return; 549 return;
550 550
551 want_refresh = 1; 551 want_refresh = 1;
552 view_start = 0; 552 view_start = 0;
553 553
554 selection_check (2); /* check for boundary cross */ 554 /* check for boundary cross */
555 row_col_t pos;
556 pos.row = pos.col = 0;
557 if (ROWCOL_IS_BEFORE (selection.beg, pos)
558 && ROWCOL_IS_AFTER (selection.end, pos))
559 CLEAR_SELECTION ();
555 560
556 current_screen = scrn; 561 current_screen = scrn;
557 562
558#if NSCREENS 563#if NSCREENS
559 if (option (Opt_secondaryScreen)) 564 if (option (Opt_secondaryScreen))
638 643
639 if (count > 0 644 if (count > 0
640 && row1 == 0 645 && row1 == 0
641 && (current_screen == PRIMARY || option (Opt_secondaryScroll))) 646 && (current_screen == PRIMARY || option (Opt_secondaryScroll)))
642 { 647 {
643 min_it (count, row2 + total_rows); 648 min_it (count, total_rows - (nrow - (row2 + 1)));
644 649
645 top_row = max (top_row - count, -saveLines); 650 top_row = max (top_row - count, -saveLines);
646
647 // scroll everything up 'count' lines
648 term_start = (term_start + count) % total_rows;
649 651
650 // sever bottommost line 652 // sever bottommost line
651 { 653 {
652 line_t &l = ROW(row2 - count); 654 line_t &l = ROW(row2);
653 l.is_longer (0); 655 l.is_longer (0);
654 l.touch (); 656 l.touch ();
655 } 657 }
656 658
659 // scroll everything up 'count' lines
660 term_start = (term_start + count) % total_rows;
661
662 // now copy lines below the scroll region bottom to the
663 // bottom of the screen again, so they look as if they
664 // hadn't moved.
665 for (int i = nrow; --i > row2; )
666 {
667 line_t &l1 = ROW(i - count);
668 line_t &l2 = ROW(i);
669
670 ::swap (l1, l2);
671 l2.touch ();
672 }
673
657 // erase newly scrolled-in lines 674 // erase newly scrolled-in lines
658 for (int i = count; i--; ) 675 for (int i = count; i--; )
659 { 676 {
660 line_t &l = ROW(nrow - 1 - i); 677 line_t &l = ROW(row2 - i);
661 678
662 // optimise if already cleared, can be significant on slow machines 679 // optimise if already cleared, can be significant on slow machines
663 // could be rolled into scr_blank_screen_mem 680 // could be rolled into scr_blank_screen_mem
664 if (l.r && l.l < ncol - 1 && !((l.r[l.l + 1] ^ rstyle) & (RS_fgMask | RS_bgMask))) 681 if (l.r && l.l < ncol - 1 && !((l.r[l.l + 1] ^ rstyle) & (RS_fgMask | RS_bgMask)))
665 { 682 {
669 } 686 }
670 else 687 else
671 scr_blank_screen_mem (l, rstyle); 688 scr_blank_screen_mem (l, rstyle);
672 } 689 }
673 690
674 // now copy lines below the scroll region bottom to the
675 // bottom of the screen again, so they look as if they
676 // hadn't moved.
677 for (int i = nrow; --i > row2; )
678 {
679 line_t &l1 = ROW(i - count);
680 line_t &l2 = ROW(i);
681
682 ::swap (l1, l2);
683 l2.touch ();
684 }
685
686 // move and/or clear selection, if any 691 // move and/or clear selection, if any
687 if (selection.op && current_screen == selection.screen) 692 if (selection.op && current_screen == selection.screen
693 && selection.beg.row <= row2)
688 { 694 {
689 selection.beg.row -= count; 695 selection.beg.row -= count;
690 selection.end.row -= count; 696 selection.end.row -= count;
691 selection.mark.row -= count; 697 selection.mark.row -= count;
692 698
693 if (selection.beg.row < top_row 699 selection_check (0);
694 || selection.end.row < top_row
695 || selection.mark.row < top_row)
696 {
697 CLEAR_ALL_SELECTION ();
698 selection.op = SELECTION_CLEAR;
699 }
700 } 700 }
701 701
702 // finally move the view window, if desired 702 // finally move the view window, if desired
703 if (option (Opt_scrollWithBuffer) 703 if (option (Opt_scrollWithBuffer)
704 && view_start != 0 704 && view_start != 0
734 } 734 }
735 735
736 // use a simple and robust scrolling algorithm, this 736 // use a simple and robust scrolling algorithm, this
737 // part of scr_scroll_text is not time-critical. 737 // part of scr_scroll_text is not time-critical.
738 738
739 // sever line above scroll region
740 if (row1)
741 {
742 line_t &l = ROW(row1 - 1);
743 l.is_longer (0);
744 l.touch ();
745 }
746
739 int rows = row2 - row1 + 1; 747 int rows = row2 - row1 + 1;
740 748
741 min_it (count, rows); 749 min_it (count, rows);
742 750
743 line_t *temp_buf = row_buf + total_rows; 751 line_t *temp_buf = rxvt_temp_buf<line_t> (rows);
744 752
745 for (int row = 0; row < rows; row++) 753 for (int row = 0; row < rows; row++)
746 { 754 {
747 temp_buf [row] = ROW(row1 + (row + count + rows) % rows); 755 temp_buf [row] = ROW(row1 + (row + count + rows) % rows);
748 756
750 scr_blank_screen_mem (temp_buf [row], rstyle); 758 scr_blank_screen_mem (temp_buf [row], rstyle);
751 } 759 }
752 760
753 for (int row = 0; row < rows; row++) 761 for (int row = 0; row < rows; row++)
754 ROW(row1 + row) = temp_buf [row]; 762 ROW(row1 + row) = temp_buf [row];
763
764 // sever bottommost line
765 {
766 line_t &l = ROW(row2);
767 l.is_longer (0);
768 l.touch ();
769 }
755 } 770 }
756 771
757 return count; 772 return count;
758} 773}
759 774
765rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) NOTHROW 780rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) NOTHROW
766{ 781{
767 if (len <= 0) /* sanity */ 782 if (len <= 0) /* sanity */
768 return; 783 return;
769 784
770 unsigned char checksel; 785 bool checksel;
771 unicode_t c; 786 unicode_t c;
772 int ncol = this->ncol; 787 int ncol = this->ncol;
773 const wchar_t *strend = str + len; 788 const wchar_t *strend = str + len;
774 789
775 want_refresh = 1; 790 want_refresh = 1;
1297 scr_blank_line (line, col, num, rstyle); 1312 scr_blank_line (line, col, num, rstyle);
1298} 1313}
1299 1314
1300/* ------------------------------------------------------------------------- */ 1315/* ------------------------------------------------------------------------- */
1301/* 1316/*
1302 * Erase part of whole of the screen 1317 * Erase part or whole of the screen
1303 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J 1318 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J
1304 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J 1319 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J
1305 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1320 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1306 */ 1321 */
1307void 1322void
1316 ZERO_SCROLLBACK (); 1331 ZERO_SCROLLBACK ();
1317 1332
1318 switch (mode) 1333 switch (mode)
1319 { 1334 {
1320 case 0: /* erase to end of screen */ 1335 case 0: /* erase to end of screen */
1321 selection_check (1);
1322 scr_erase_line (0); 1336 scr_erase_line (0);
1323 row = screen.cur.row + 1; /* possible OOB */ 1337 row = screen.cur.row + 1; /* possible OOB */
1324 num = nrow - row; 1338 num = nrow - row;
1325 break; 1339 break;
1326 case 1: /* erase to beginning of screen */ 1340 case 1: /* erase to beginning of screen */
1327 selection_check (3);
1328 scr_erase_line (1); 1341 scr_erase_line (1);
1329 row = 0; 1342 row = 0;
1330 num = screen.cur.row; 1343 num = screen.cur.row;
1331 break; 1344 break;
1332 case 2: /* erase whole screen */ 1345 case 2: /* erase whole screen */
1333 selection_check (3);
1334 row = 0; 1346 row = 0;
1335 num = nrow; 1347 num = nrow;
1336 break; 1348 break;
1337 default: 1349 default:
1338 return; 1350 return;
1355 { 1367 {
1356 ren = DEFAULT_RSTYLE; 1368 ren = DEFAULT_RSTYLE;
1357 1369
1358 if (mapped) 1370 if (mapped)
1359 XClearArea (dpy, vt, 0, 1371 XClearArea (dpy, vt, 0,
1360 Row2Pixel (row - view_start), (unsigned int)width, 1372 Row2Pixel (row - view_start), (unsigned int)vt_width,
1361 (unsigned int)Height2Pixel (num), False); 1373 (unsigned int)Height2Pixel (num), False);
1362 } 1374 }
1363 else 1375 else
1364 { 1376 {
1365 ren = rstyle & (RS_fgMask | RS_bgMask); 1377 ren = rstyle & (RS_fgMask | RS_bgMask);
1368 { 1380 {
1369 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1381 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1370 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1382 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1371 XFillRectangle (dpy, vt, gc, 1383 XFillRectangle (dpy, vt, gc,
1372 0, Row2Pixel (row - view_start), 1384 0, Row2Pixel (row - view_start),
1373 (unsigned int)width, 1385 (unsigned int)vt_width,
1374 (unsigned int)Height2Pixel (num)); 1386 (unsigned int)Height2Pixel (num));
1375 gcvalue.foreground = pix_colors[Color_fg]; 1387 gcvalue.foreground = pix_colors[Color_fg];
1376 XChangeGC (dpy, gc, GCForeground, &gcvalue); 1388 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1377 } 1389 }
1378 } 1390 }
1409 1421
1410 want_refresh = 1; 1422 want_refresh = 1;
1411 ZERO_SCROLLBACK (); 1423 ZERO_SCROLLBACK ();
1412 1424
1413 num_scr_allow = 0; 1425 num_scr_allow = 0;
1414 selection_check (3); 1426
1427 row_col_t pos;
1428 pos.row = pos.col = 0;
1429 if (ROWCOL_IS_AFTER (selection.end, pos))
1430 CLEAR_SELECTION ();
1415 1431
1416 fs = SET_FONT (rstyle, FONTSET (rstyle)->find_font ('E')); 1432 fs = SET_FONT (rstyle, FONTSET (rstyle)->find_font ('E'));
1417 for (int row = nrow; row--; ) 1433 for (int row = nrow; row--; )
1418 { 1434 {
1419 line_t &line = ROW(row); 1435 line_t &line = ROW(row);
1860 * Refresh the entire screen 1876 * Refresh the entire screen
1861 */ 1877 */
1862void 1878void
1863rxvt_term::scr_touch (bool refresh) NOTHROW 1879rxvt_term::scr_touch (bool refresh) NOTHROW
1864{ 1880{
1865 scr_expose (0, 0, width, height, refresh); 1881 scr_expose (0, 0, vt_width, vt_height, refresh);
1866} 1882}
1867 1883
1868/* ------------------------------------------------------------------------- */ 1884/* ------------------------------------------------------------------------- */
1869/* 1885/*
1870 * Move the display so that the line represented by scrollbar value Y is at 1886 * Move the display so that the line represented by scrollbar value Y is at
2032 * A: set up vars 2048 * A: set up vars
2033 */ 2049 */
2034 refresh_count = 0; 2050 refresh_count = 0;
2035 2051
2036 unsigned int old_screen_flags = screen.flags; 2052 unsigned int old_screen_flags = screen.flags;
2037 char have_bg = 0; 2053 bool have_bg = 0;
2038#ifdef HAVE_BG_PIXMAP 2054#ifdef HAVE_BG_PIXMAP
2039 have_bg = bg_pixmap != None; 2055 have_bg = bg_pixmap != None;
2040#endif 2056#endif
2041 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2057 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
2042 2058
2048 HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); 2064 HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
2049#if ENABLE_OVERLAY 2065#if ENABLE_OVERLAY
2050 scr_swap_overlay (); 2066 scr_swap_overlay ();
2051#endif 2067#endif
2052 2068
2053 char showcursor = screen.flags & Screen_VisibleCursor; 2069 bool showcursor = screen.flags & Screen_VisibleCursor;
2054 2070
2055 /* 2071 /*
2056 * C: set the cursor character (s) 2072 * C: set the cursor character (s)
2057 */ 2073 */
2058 { 2074 {
2059 unsigned char setoldcursor; 2075 bool setoldcursor;
2060 2076
2061#ifdef CURSOR_BLINK 2077#ifdef CURSOR_BLINK
2062 if (hidden_cursor) 2078 if (hidden_cursor)
2063 showcursor = 0; 2079 showcursor = 0;
2064#endif 2080#endif
2151 { 2167 {
2152 int16_t nits; 2168 int16_t nits;
2153 int i = num_scr; 2169 int i = num_scr;
2154 int j; 2170 int j;
2155 int len, wlen; 2171 int len, wlen;
2156 dLocal (int, num_scr);
2157 2172
2158 j = nrow; 2173 j = nrow;
2159 wlen = len = -1; 2174 wlen = len = -1;
2160 row = i > 0 ? 0 : j - 1; 2175 row = i > 0 ? 0 : j - 1;
2161 2176
2466 2481
2467 XDrawRectangle (dpy, vt, gc, 2482 XDrawRectangle (dpy, vt, gc,
2468 Col2Pixel (col), 2483 Col2Pixel (col),
2469 Row2Pixel (oldcursor.row), 2484 Row2Pixel (oldcursor.row),
2470 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2485 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2471 (unsigned int) (Height2Pixel (1) - lineSpace - 1)); 2486 (unsigned int) (Height2Pixel (1) - 1));
2472 } 2487 }
2473 } 2488 }
2474 2489
2475 /* 2490 /*
2476 * H: cleanup selection 2491 * H: cleanup selection
2548 { 2563 {
2549 if (transparent) 2564 if (transparent)
2550 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); 2565 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
2551 else 2566 else
2552 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]); 2567 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2553 scrollBar.state = STATE_IDLE; 2568 scrollBar.state = SB_STATE_IDLE;
2554 scrollBar.show (0); 2569 scrollBar.show (0);
2555 } 2570 }
2556 2571
2557 if (refresh) 2572 if (refresh)
2558 { 2573 {
2652 */ 2667 */
2653#if 0 2668#if 0
2654void 2669void
2655rxvt_term::scr_dump (int fd) NOTHROW 2670rxvt_term::scr_dump (int fd) NOTHROW
2656{ 2671{
2657 int row, wrote; 2672 // if this method is needed, it can be implemented by factoring the
2658 unsigned int width, towrite; 2673 // relevant code in scr_printscreen
2659 const char r1[] = "\n";
2660
2661 for (row = saveLines + top_row;
2662 row < saveLines + nrow - 1; row++)
2663 {
2664 width = row_buf[row].l >= 0 ? row_buf[row].l
2665 : ncol;
2666 for (towrite = width; towrite; towrite -= wrote)
2667 {
2668 wrote = write (fd, & (row_buf[row].t[width - towrite]),
2669 towrite);
2670 if (wrote < 0)
2671 return; /* XXX: death, no report */
2672 }
2673 if (row_buf[row].l >= 0)
2674 if (write (fd, r1, 1) <= 0)
2675 return; /* XXX: death, no report */
2676 }
2677} 2674}
2678#endif 2675#endif
2679 2676
2680/* ------------------------------------------------------------------------- * 2677/* ------------------------------------------------------------------------- *
2681 * CHARACTER SELECTION * 2678 * CHARACTER SELECTION *
2682 * ------------------------------------------------------------------------- */ 2679 * ------------------------------------------------------------------------- */
2683void 2680void
2684rxvt_term::selection_check (int check_more) NOTHROW 2681rxvt_term::selection_check (int check_more) NOTHROW
2685{ 2682{
2686 row_col_t pos;
2687
2688 if (!selection.op) 2683 if (!selection.op)
2689 return; 2684 return;
2690 2685
2691 pos.row = pos.col = 0;
2692 if (!IN_RANGE_EXC (selection.beg.row, top_row, nrow) 2686 if (!IN_RANGE_EXC (selection.beg.row, top_row, nrow)
2693 || !IN_RANGE_EXC (selection.mark.row, top_row, nrow) 2687 || !IN_RANGE_EXC (selection.mark.row, top_row, nrow)
2694 || !IN_RANGE_EXC (selection.end.row, top_row, nrow) 2688 || !IN_RANGE_EXC (selection.end.row, top_row, nrow)
2695 || (check_more == 1 2689 || (check_more == 1
2696 && current_screen == selection.screen 2690 && current_screen == selection.screen
2697 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 2691 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
2698 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 2692 && ROWCOL_IS_BEFORE (screen.cur, selection.end)))
2699 || (check_more == 2
2700 && ROWCOL_IS_BEFORE (selection.beg, pos)
2701 && ROWCOL_IS_AFTER (selection.end, pos))
2702 || (check_more == 3
2703 && ROWCOL_IS_AFTER (selection.end, pos))
2704 || (check_more == 4 /* screen width change */
2705 && (selection.beg.row != selection.end.row
2706 || selection.end.col > ncol)))
2707 CLEAR_SELECTION (); 2693 CLEAR_ALL_SELECTION ();
2708} 2694}
2709 2695
2710/* ------------------------------------------------------------------------- */ 2696/* ------------------------------------------------------------------------- */
2711/* 2697/*
2712 * Paste a selection direct to the command fd 2698 * Paste a selection direct to the command fd
2718 for (unsigned int i = 0; i < len; i++) 2704 for (unsigned int i = 0; i < len; i++)
2719 if (data[i] == C0_LF) 2705 if (data[i] == C0_LF)
2720 data[i] = C0_CR; 2706 data[i] = C0_CR;
2721 2707
2722 if (priv_modes & PrivMode_BracketPaste) 2708 if (priv_modes & PrivMode_BracketPaste)
2723 tt_printf ("\e[200~"); 2709 tt_printf ("\x1b[200~");
2724 2710
2725 tt_write (data, len); 2711 tt_write (data, len);
2726 2712
2727 if (priv_modes & PrivMode_BracketPaste) 2713 if (priv_modes & PrivMode_BracketPaste)
2728 tt_printf ("\e[201~"); 2714 tt_printf ("\x1b[201~");
2729} 2715}
2730 2716
2731void 2717void
2732rxvt_term::paste (char *data, unsigned int len) NOTHROW 2718rxvt_term::paste (char *data, unsigned int len) NOTHROW
2733{ 2719{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines