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.188 by root, Thu Dec 22 00:07:47 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() \
271 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 272 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
272 } 273 }
273 274
274 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 275 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
275 276
276 // re-wrap lines, this is rather ugly, possibly because I am too dumb
277 // to come up with a lean and mean algorithm.
278
279 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 277 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
280 int pend = MOD (term_start - nsaved , prev_total_rows); 278 int pend = MOD (term_start - nsaved , prev_total_rows);
281 int q = total_rows; // rewrapped row 279 int q = total_rows; // rewrapped row
282 280
283 while (p != pend && q > 0) 281 if (nsaved)
282 {
283 // re-wrap lines, this is rather ugly, possibly because I am too dumb
284 // to come up with a lean and mean algorithm.
285
286 row_col_t ocur = screen.cur;
287 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
288
284 { 289 do
285 p = MOD (p - 1, prev_total_rows);
286#ifdef DEBUG_STRICT
287 assert (old_buf [MOD (p, prev_total_rows)].t);
288#endif
289
290 int llen = old_buf [MOD (p, prev_total_rows)].l;
291
292 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
293 { 290 {
294 p = MOD (p - 1, prev_total_rows); 291 p = MOD (p - 1, prev_total_rows);
292#ifdef DEBUG_STRICT
293 assert (old_buf [MOD (p, prev_total_rows)].t);
294#endif
295 295
296 int plines = 1;
297 int llen = old_buf [MOD (p, prev_total_rows)].l;
298
299 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
300 {
301 p = MOD (p - 1, prev_total_rows);
302
303 plines++;
296 llen += prev_ncol; 304 llen += prev_ncol;
305 }
306
307 int qlines = max (0, (llen - 1) / ncol) + 1;
308
309 // drop partial lines completely
310 if (q < qlines)
311 break;
312
313 q -= qlines;
314
315 int lofs = 0;
316 line_t *qline;
317
318 // re-assemble the full line by destination lines
319 for (int qrow = q; qlines--; qrow++)
320 {
321 qline = row_buf + qrow;
322 lalloc (*qline);
323 qline->set_is_longer ();
324
325 int qcol = 0;
326
327 // fill a single destination line
328 while (lofs < llen && qcol < ncol)
329 {
330 int prow = lofs / prev_ncol;
331 int pcol = lofs % prev_ncol;
332
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];
343
344 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
345
346 assert (len);
347 assert (pline.t);
348
349 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
350 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
351
352 lofs += len;
353 qcol += len;
354 }
355 }
356
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
365 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
297 } 366 }
367 while (p != pend && q > 0);
298 368
299 int qlines = max (0, (llen - 1) / ncol) + 1; 369 term_start = total_rows - nrow;
370 nsaved = term_start - q;
371
372 // make sure all terminal lines exist
373 while (nsaved < 0)
374 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
300 375
301 // drop partial lines completely 376 }
302 if (q < qlines) 377 else
303 break; 378 {
304 379 // if no scrollback exists (yet), wing, instead of wrap
305 q -= qlines; 380
306 381 for (int row = min (nrow, prev_nrow); row--; )
307 int lofs = 0;
308 line_t *qline;
309
310 // re-assemble the full line by destination lines
311 for (int qrow = q; qlines--; qrow++)
312 { 382 {
313 qline = row_buf + qrow;
314 lalloc (*qline);
315 qline->set_is_longer ();
316
317 int qcol = 0;
318
319 // fill a single destination line
320 while (lofs < llen && qcol < ncol)
321 {
322 int prow = lofs / prev_ncol;
323 int pcol = lofs % prev_ncol;
324
325 line_t &pline = old_buf [MOD (p + prow, prev_total_rows)]; 383 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
384 line_t &qline = row_buf [row];
326 385
327 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 386 qline = pline;
328 387 lresize (qline);
329 assert (len);
330 assert (pline.t);
331
332 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
333 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
334
335 lofs += len;
336 qcol += len;
337 }
338 } 388 }
339 389
340 qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1; 390 for (int row = prev_nrow; row < nrow; row++)
341 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); 391 {
392 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
342 } 393 }
343 394
344 term_start = total_rows - nrow;
345 view_start = 0; 395 term_start = 0;
346 nsaved = term_start - q; 396 }
347 397
348 // make sure all terminal lines exist 398#ifdef DEBUG_STRICT //TODO: remove
349 while (nsaved < 0)
350 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
351
352 for (int i = -nsaved; i < nrow; i++) 399 for (int i = -nsaved; i < nrow; i++)
353 assert (ROW (i).t);//D 400 assert (ROW (i).t);
401#endif
354 402
355 free (old_buf); 403 free (old_buf);
356 delete old_ta; 404 delete old_ta;
357 delete old_ra; 405 delete old_ra;
358 406
359 min_it (screen.cur.row, nrow - 1); 407 clamp_it (screen.cur.row, 0, nrow - 1);
360 min_it (screen.cur.col, ncol - 1); 408 clamp_it (screen.cur.col, 0, ncol - 1);
361 409
362 if (tabs) 410 if (tabs)
363 free (tabs); 411 free (tabs);
364 } 412 }
365 413
370 418
371 for (int col = ncol; col--; ) 419 for (int col = ncol; col--; )
372 tabs [col] = col % TABSIZE == 0; 420 tabs [col] = col % TABSIZE == 0;
373 421
374 tt_winch (); 422 tt_winch ();
423
424 PERL_INVOKE ((this, HOOK_RESET, DT_END));
375} 425}
376 426
377/* ------------------------------------------------------------------------- */ 427/* ------------------------------------------------------------------------- */
378/* 428/*
379 * Free everything. That way malloc debugging can find leakage. 429 * Free everything. That way malloc debugging can find leakage.
483 533
484 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1); 534 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
485 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1); 535 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
486 536
487#if NSCREENS 537#if NSCREENS
488 if (options & Opt_secondaryScreen) 538 if (OPTION (Opt_secondaryScreen))
489 { 539 {
490 num_scr = 0; 540 num_scr = 0;
491 541
492 for (int i = prev_nrow; i--; ) 542 for (int i = prev_nrow; i--; )
493 ::swap (ROW(i), swap_buf [i]); 543 ::swap (ROW(i), swap_buf [i]);
497 screen.flags |= Screen_VisibleCursor; 547 screen.flags |= Screen_VisibleCursor;
498 swap.flags |= Screen_VisibleCursor; 548 swap.flags |= Screen_VisibleCursor;
499 } 549 }
500 else 550 else
501#endif 551#endif
502 if (options & Opt_secondaryScroll) 552 if (OPTION (Opt_secondaryScroll))
503 scr_scroll_text (0, prev_nrow - 1, prev_nrow); 553 scr_scroll_text (0, prev_nrow - 1, prev_nrow);
504 554
505 return scrn; 555 return scrn;
506} 556}
507 557
569 num_scr += count; 619 num_scr += count;
570 620
571 if (count > 0 621 if (count > 0
572 && row1 == 0 622 && row1 == 0
573 && row2 == nrow - 1 623 && row2 == nrow - 1
574 && (current_screen == PRIMARY || options & Opt_secondaryScroll)) 624 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll)))
575 { 625 {
576 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
577 term_start = (term_start + count) % total_rows; 630 term_start = (term_start + count) % total_rows;
578 631
579 if (selection.op && current_screen == selection.screen) 632 if (selection.op && current_screen == selection.screen)
580 { 633 {
581 selection.beg.row -= count; 634 selection.beg.row -= count;
582 selection.end.row -= count; 635 selection.end.row -= count;
583 selection.mark.row -= count; 636 selection.mark.row -= count;
584 637
585 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 }
586 } 645 }
587 646
588 for (int i = count; i--; ) 647 for (int i = count; i--; )
648 {
649 ROW(row2 - i).l = 0;
589 scr_blank_screen_mem (ROW(row2 - i), rstyle); 650 scr_blank_screen_mem (ROW(row2 - i), rstyle);
651 }
590 652
591 if ((options & Opt_scrollWithBuffer) 653 if (OPTION (Opt_scrollWithBuffer)
592 && view_start != 0 654 && view_start != 0
593 && view_start != saveLines) 655 && view_start != saveLines)
594 scr_page (UP, count); 656 scr_page (UP, count);
595 } 657 }
596 else 658 else
597 { 659 {
598 if (selection.op && current_screen == selection.screen) 660 if (selection.op && current_screen == selection.screen)
599 { 661 {
600 int i = selection.beg.row; 662 if ((selection.beg.row < row1 && selection.end.row > row1)
601 int j = selection.end.row; 663 || (selection.beg.row < row2 && selection.end.row > row2)
602
603 if ((i < row1 && j > row1)
604 || (i < row2 && j > row2)
605 || (i - count < row1 && i >= row1) 664 || (selection.beg.row - count < row1 && selection.beg.row >= row1)
606 || (i - count > row2 && i <= row2) 665 || (selection.beg.row - count > row2 && selection.beg.row <= row2)
607 || (j - count < row1 && j >= row1) 666 || (selection.end.row - count < row1 && selection.end.row >= row1)
608 || (j - count > row2 && j <= row2)) 667 || (selection.end.row - count > row2 && selection.end.row <= row2))
609 { 668 {
610 CLEAR_ALL_SELECTION (); 669 CLEAR_ALL_SELECTION ();
611 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ 670 selection.op = SELECTION_CLEAR;
612 } 671 }
613 else if (j >= row1 && j <= row2) 672 else if (selection.end.row >= row1 && selection.end.row <= row2)
614 { 673 {
615 /* move selected region too */ 674 /* move selected region too */
616 selection.beg.row -= count; 675 selection.beg.row -= count;
617 selection.end.row -= count; 676 selection.end.row -= count;
618 selection.mark.row -= count; 677 selection.mark.row -= count;
653 if (len <= 0) /* sanity */ 712 if (len <= 0) /* sanity */
654 return; 713 return;
655 714
656 unsigned char checksel; 715 unsigned char checksel;
657 unicode_t c; 716 unicode_t c;
658 int row, last_col; 717 int last_col;
659 const unicode_t *strend = str + len; 718 const unicode_t *strend = str + len;
660 719
661 want_refresh = 1; 720 want_refresh = 1;
662 ZERO_SCROLLBACK (); 721 ZERO_SCROLLBACK ();
663 last_col = ncol; 722 last_col = ncol;
664 723
665 if (nlines > 0) 724 if (nlines > 0)
666 { 725 {
667 nlines += screen.cur.row - screen.bscroll; 726 nlines += screen.cur.row - screen.bscroll;
727
668 if (nlines > 0 728 if (nlines > 0
669 && screen.tscroll == 0 729 && screen.tscroll == 0
670 && screen.bscroll == (nrow - 1)) 730 && screen.bscroll == (nrow - 1))
671 { 731 {
672 /* _at least_ this many lines need to be scrolled */ 732 /* _at least_ this many lines need to be scrolled */
678#ifdef DEBUG_STRICT 738#ifdef DEBUG_STRICT
679 assert (screen.cur.col < last_col); 739 assert (screen.cur.col < last_col);
680 assert (screen.cur.row < nrow 740 assert (screen.cur.row < nrow
681 && screen.cur.row >= -nsaved); 741 && screen.cur.row >= -nsaved);
682#endif 742#endif
683 row = screen.cur.row; 743 int row = screen.cur.row;
684 744
685 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 745 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
686 746
687 line_t *line = &ROW(row); 747 line_t *line = &ROW(row);
688 748
690 { 750 {
691 c = *str++; 751 c = *str++;
692 752
693 if (c < 0x20) 753 if (c < 0x20)
694 if (c == C0_LF) 754 if (c == C0_LF)
695 { 755 {
696 if (!line->is_longer ()) /* XXX: think about this */ 756 if (!line->is_longer ()) /* XXX: think about this */
697 max_it (line->l, screen.cur.col); 757 max_it (line->l, screen.cur.col);
698 758
699 screen.flags &= ~Screen_WrapNext; 759 screen.flags &= ~Screen_WrapNext;
700 760
945 1005
946 if (count == 0) 1006 if (count == 0)
947 return; 1007 return;
948 else if (count > 0) 1008 else if (count > 0)
949 { 1009 {
950 int row = screen.cur.row;
951
952 line_t &l = ROW(row); 1010 line_t &l = ROW(screen.cur.row);
953 rend_t base_rend = l.r[i]; 1011 rend_t base_rend = l.r[i];
954 ht &= l.t[i] == ' '; 1012 ht &= l.t[i] == ' ';
955 1013
956 for (; ++i < ncol; ) 1014 for (; ++i < ncol; )
957 if (tabs[i]) 1015 if (tabs[i])
967 if (count) 1025 if (count)
968 x = ncol - 1; 1026 x = ncol - 1;
969 1027
970 // store horizontal tab commands as characters inside the text 1028 // store horizontal tab commands as characters inside the text
971 // buffer so they can be selected and pasted. 1029 // buffer so they can be selected and pasted.
972 if (ht && options & Opt_pastableTabs) 1030 if (ht && OPTION (Opt_pastableTabs))
973 { 1031 {
974 base_rend = SET_FONT (base_rend, 0); 1032 base_rend = SET_FONT (base_rend, 0);
975 1033
976 if (!l.is_longer ()) /* XXX: think about this */ 1034 if (!l.is_longer ()) /* XXX: think about this */
977 max_it (l.l, x); 1035 max_it (l.l, x);
1032 */ 1090 */
1033#if ENABLE_FRILLS 1091#if ENABLE_FRILLS
1034void 1092void
1035rxvt_term::scr_forwardindex () 1093rxvt_term::scr_forwardindex ()
1036{ 1094{
1037 int row;
1038
1039 if (screen.cur.col < ncol - 1) 1095 if (screen.cur.col < ncol - 1)
1040 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1096 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1041 else 1097 else
1042 { 1098 {
1043 row = screen.cur.row;
1044
1045 if (ROW(row).is_longer ()) //TODO//FIXME//LEN 1099 if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN
1046 ROW(row).l = ncol; 1100 ROW(screen.cur.row).l = ncol;
1047 1101
1048 scr_gotorc (0, 0, R_RELATIVE); 1102 scr_gotorc (0, 0, R_RELATIVE);
1049 scr_insdel_chars (1, DELETE); 1103 scr_insdel_chars (1, DELETE);
1050 scr_gotorc (0, ncol - 1, R_RELATIVE); 1104 scr_gotorc (0, ncol - 1, R_RELATIVE);
1051 } 1105 }
1134 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1188 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1135 */ 1189 */
1136void 1190void
1137rxvt_term::scr_erase_line (int mode) 1191rxvt_term::scr_erase_line (int mode)
1138{ 1192{
1139 unsigned int row, col, num; 1193 unsigned int col, num;
1140 1194
1141 want_refresh = 1; 1195 want_refresh = 1;
1142 ZERO_SCROLLBACK (); 1196 ZERO_SCROLLBACK ();
1143 1197
1144 selection_check (1); 1198 selection_check (1);
1145 1199
1146 row = screen.cur.row; 1200 line_t &line = ROW(screen.cur.row);
1147 1201
1148 switch (mode) 1202 switch (mode)
1149 { 1203 {
1150 case 0: /* erase to end of line */ 1204 case 0: /* erase to end of line */
1151 col = screen.cur.col; 1205 col = screen.cur.col;
1152 num = ncol - col; 1206 num = ncol - col;
1153 min_it (ROW(row).l, col); 1207 min_it (line.l, col);
1154 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1208 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1155 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1209 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1156 CLEAR_SELECTION (); 1210 CLEAR_SELECTION ();
1157 break; 1211 break;
1158 case 1: /* erase to beginning of line */ 1212 case 1: /* erase to beginning of line */
1163 CLEAR_SELECTION (); 1217 CLEAR_SELECTION ();
1164 break; 1218 break;
1165 case 2: /* erase whole line */ 1219 case 2: /* erase whole line */
1166 col = 0; 1220 col = 0;
1167 num = ncol; 1221 num = ncol;
1168 ROW(row).l = 0; 1222 line.l = 0;
1169 if (selection.beg.row <= screen.cur.row 1223 if (selection.beg.row <= screen.cur.row
1170 && selection.end.row >= screen.cur.row) 1224 && selection.end.row >= screen.cur.row)
1171 CLEAR_SELECTION (); 1225 CLEAR_SELECTION ();
1172 break; 1226 break;
1173 default: 1227 default:
1174 return; 1228 return;
1175 } 1229 }
1176 1230
1177 scr_blank_line (ROW(row), col, num, rstyle); 1231 scr_blank_line (line, col, num, rstyle);
1178} 1232}
1179 1233
1180/* ------------------------------------------------------------------------- */ 1234/* ------------------------------------------------------------------------- */
1181/* 1235/*
1182 * Erase part of whole of the screen 1236 * Erase part of whole of the screen
1237 CLEAR_ROWS (row, num); 1291 CLEAR_ROWS (row, num);
1238 } 1292 }
1239 else 1293 else
1240 { 1294 {
1241 ren = rstyle & (RS_fgMask | RS_bgMask); 1295 ren = rstyle & (RS_fgMask | RS_bgMask);
1242 gcvalue.foreground = pix_colors[GET_BGCOLOR (rstyle)]; 1296 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1243 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1297 XChangeGC (display->display, gc, GCForeground, &gcvalue);
1244 ERASE_ROWS (row, num); 1298 ERASE_ROWS (row, num);
1245 gcvalue.foreground = pix_colors[Color_fg]; 1299 gcvalue.foreground = pix_colors[Color_fg];
1246 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1300 XChangeGC (display->display, gc, GCForeground, &gcvalue);
1247 } 1301 }
1248 1302
1249 for (; num--; row++) 1303 for (; num--; row++)
1250 { 1304 {
1305 ROW (row).l = 0;
1251 scr_blank_screen_mem (ROW (row), rstyle); 1306 scr_blank_screen_mem (ROW (row), rstyle);
1252 ROW (row).l = 0;
1253 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1307 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1254 } 1308 }
1255} 1309}
1256 1310
1257#if ENABLE_FRILLS 1311#if ENABLE_FRILLS
1546 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1600 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1547#if XPM_BACKGROUND 1601#if XPM_BACKGROUND
1548 if (bgPixmap.pixmap == None) 1602 if (bgPixmap.pixmap == None)
1549#endif 1603#endif
1550#if TRANSPARENT 1604#if TRANSPARENT
1551 if (! (options & Opt_transparent) || am_transparent == 0) 1605 if (! OPTION (Opt_transparent) || am_transparent == 0)
1552#endif 1606#endif
1553 XSetWindowBackground (display->display, vt, 1607 XSetWindowBackground (display->display, vt,
1554 pix_colors[Color_bg]); 1608 pix_colors[Color_bg]);
1555 1609
1556 gcvalue.foreground = pix_colors[Color_fg]; 1610 gcvalue.foreground = pix_colors[Color_fg];
1772} 1826}
1773 1827
1774int 1828int
1775rxvt_term::scr_changeview (unsigned int oldviewstart) 1829rxvt_term::scr_changeview (unsigned int oldviewstart)
1776{ 1830{
1831 PERL_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END));
1832
1777 if (view_start != oldviewstart) 1833 if (view_start != oldviewstart)
1778 { 1834 {
1779 want_refresh = 1; 1835 want_refresh = 1;
1780 num_scr -= (view_start - oldviewstart); 1836 num_scr -= (view_start - oldviewstart);
1781 } 1837 }
1789{ 1845{
1790#ifndef NO_BELL 1846#ifndef NO_BELL
1791 1847
1792# ifndef NO_MAPALERT 1848# ifndef NO_MAPALERT
1793# ifdef MAPALERT_OPTION 1849# ifdef MAPALERT_OPTION
1794 if (options & Opt_mapAlert) 1850 if (OPTION (Opt_mapAlert))
1795# endif 1851# endif
1796 XMapWindow (display->display, parent[0]); 1852 XMapWindow (display->display, parent[0]);
1797# endif 1853# endif
1798 1854
1799 if (options & Opt_visualBell) 1855 if (OPTION (Opt_visualBell))
1800 { 1856 {
1801 scr_rvideo_mode (!rvideo); /* refresh also done */ 1857 scr_rvideo_mode (!rvideo); /* refresh also done */
1802 rxvt_usleep (VISUAL_BELL_DURATION); 1858 rxvt_usleep (VISUAL_BELL_DURATION);
1803 scr_rvideo_mode (!rvideo); /* refresh also done */ 1859 scr_rvideo_mode (!rvideo); /* refresh also done */
1804 } 1860 }
1895 1951
1896#if XPM_BACKGROUND 1952#if XPM_BACKGROUND
1897 must_clear |= bgPixmap.pixmap != None; 1953 must_clear |= bgPixmap.pixmap != None;
1898#endif 1954#endif
1899#if TRANSPARENT 1955#if TRANSPARENT
1900 must_clear |= (options & Opt_transparent) && am_transparent; 1956 must_clear |= OPTION (Opt_transparent) && am_transparent;
1901#endif 1957#endif
1902 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 1958 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1903 1959
1904 /* 1960 /*
1905 * B: reverse any characters which are selected 1961 * B: reverse any characters which are selected
1929 1985
1930 crp = &ROW(screen.cur.row).r[col]; 1986 crp = &ROW(screen.cur.row).r[col];
1931 1987
1932 if (showcursor && focus) 1988 if (showcursor && focus)
1933 { 1989 {
1934 if (options & Opt_cursorUnderline) 1990 if (OPTION (Opt_cursorUnderline))
1935 *crp ^= RS_Uline; 1991 *crp ^= RS_Uline;
1936 else 1992 else
1937 { 1993 {
1938 *crp ^= RS_RVid; 1994 *crp ^= RS_RVid;
1939 1995
1941 cc1 = *crp & (RS_fgMask | RS_bgMask); 1997 cc1 = *crp & (RS_fgMask | RS_bgMask);
1942 if (ISSET_PIXCOLOR (Color_cursor)) 1998 if (ISSET_PIXCOLOR (Color_cursor))
1943 ccol1 = Color_cursor; 1999 ccol1 = Color_cursor;
1944 else 2000 else
1945#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 2001#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1946 ccol1 = GET_FGCOLOR (rstyle); 2002 ccol1 = fgcolor_of (rstyle);
1947#else 2003#else
1948 ccol1 = Color_fg; 2004 ccol1 = Color_fg;
1949#endif 2005#endif
1950 if (ISSET_PIXCOLOR (Color_cursor2)) 2006 if (ISSET_PIXCOLOR (Color_cursor2))
1951 ccol2 = Color_cursor2; 2007 ccol2 = Color_cursor2;
1952 else 2008 else
1953#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 2009#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1954 ccol2 = GET_BGCOLOR (rstyle); 2010 ccol2 = bgcolor_of (rstyle);
1955#else 2011#else
1956 ccol2 = Color_bg; 2012 ccol2 = Color_bg;
1957#endif 2013#endif
1958 *crp = SET_FGCOLOR (*crp, ccol1); 2014 *crp = SET_FGCOLOR (*crp, ccol1);
1959 *crp = SET_BGCOLOR (*crp, ccol2); 2015 *crp = SET_BGCOLOR (*crp, ccol2);
1992 oldcursor.col = screen.cur.col; 2048 oldcursor.col = screen.cur.col;
1993 } 2049 }
1994 } 2050 }
1995 } 2051 }
1996 2052
2053 PERL_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
1997#if ENABLE_OVERLAY 2054#if ENABLE_OVERLAY
1998 scr_swap_overlay (); 2055 scr_swap_overlay ();
1999#endif 2056#endif
2000 2057
2001#ifndef NO_SLOW_LINK_SUPPORT 2058#ifndef NO_SLOW_LINK_SUPPORT
2051 if (wlen < len) 2108 if (wlen < len)
2052 ::swap (wlen, len); 2109 ::swap (wlen, len);
2053 2110
2054 XCopyArea (display->display, vt, vt, 2111 XCopyArea (display->display, vt, vt,
2055 gc, 0, Row2Pixel (len + i), 2112 gc, 0, Row2Pixel (len + i),
2056 (unsigned int)TermWin_TotalWidth (), 2113 (unsigned int)this->width,
2057 (unsigned int)Height2Pixel (wlen - len + 1), 2114 (unsigned int)Height2Pixel (wlen - len + 1),
2058 0, Row2Pixel (len)); 2115 0, Row2Pixel (len));
2059 len = -1; 2116 len = -1;
2060 } 2117 }
2061 } 2118 }
2140 count++, i--; 2197 count++, i--;
2141 2198
2142 /* 2199 /*
2143 * Determine the attributes for the string 2200 * Determine the attributes for the string
2144 */ 2201 */
2145 int fore = GET_FGCOLOR (rend); // desired foreground 2202 int fore = fgcolor_of (rend); // desired foreground
2146 int back = GET_BGCOLOR (rend); // desired background 2203 int back = bgcolor_of (rend); // desired background
2147 2204
2148 // 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
2149 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))
2150 { 2207 {
2151#if ENABLE_STYLES 2208#if ENABLE_STYLES
2152 // force redraw after "careful" characters to avoid pixel droppings 2209 // force redraw after "careful" characters to avoid pixel droppings
2153 if (srp[col] & RS_Careful && col < ncol - 1 && 0) 2210 if (srp[col] & RS_Careful && col < ncol - 1 && 0)
2264 } /* for (row....) */ 2321 } /* for (row....) */
2265 2322
2266#if ENABLE_OVERLAY 2323#if ENABLE_OVERLAY
2267 scr_swap_overlay (); 2324 scr_swap_overlay ();
2268#endif 2325#endif
2326 PERL_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2269 2327
2270 /* 2328 /*
2271 * G: cleanup cursor and display outline cursor if necessary 2329 * G: cleanup cursor and display outline cursor if necessary
2272 */ 2330 */
2273 if (showcursor) 2331 if (showcursor)
2274 { 2332 {
2275 if (focus) 2333 if (focus)
2276 { 2334 {
2277 if (options & Opt_cursorUnderline) 2335 if (OPTION (Opt_cursorUnderline))
2278 *crp ^= RS_Uline; 2336 *crp ^= RS_Uline;
2279 else 2337 else
2280 { 2338 {
2281 *crp ^= RS_RVid; 2339 *crp ^= RS_RVid;
2282#ifndef NO_CURSORCOLOR 2340#ifndef NO_CURSORCOLOR
2401 2459
2402#if ENABLE_FRILLS 2460#if ENABLE_FRILLS
2403 if (selection.rect) 2461 if (selection.rect)
2404 { 2462 {
2405 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
2406 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++)
2407 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 }
2408 } 2477 }
2409 else 2478 else
2410#endif 2479#endif
2411 { 2480 {
2412 if (selection.beg.row >= -view_start) 2481 if (selection.beg.row >= -view_start)
2415 row = selection.beg.row; 2484 row = selection.beg.row;
2416 } 2485 }
2417 else 2486 else
2418 { 2487 {
2419 col = 0; 2488 col = 0;
2420 row = view_start; 2489 row = -view_start;
2421 } 2490 }
2422 2491
2423 for (; row < min (selection.end.row, view_end); row++, col = 0) 2492 for (; row < min (selection.end.row, view_end); row++, col = 0)
2424 for (rend_t *srp = ROW(row).r; col < ncol; col++) 2493 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2425 srp[col] ^= RS_RVid; 2494 srp[col] ^= RS_RVid;
2496/* ------------------------------------------------------------------------- */ 2565/* ------------------------------------------------------------------------- */
2497/* 2566/*
2498 * Paste a selection direct to the command fd 2567 * Paste a selection direct to the command fd
2499 */ 2568 */
2500void 2569void
2501rxvt_term::paste (unsigned char *data, unsigned int len) 2570rxvt_term::paste (char *data, unsigned int len)
2502{ 2571{
2503 /* convert normal newline chars into common keyboard Return key sequence */ 2572 /* convert normal newline chars into common keyboard Return key sequence */
2504 for (unsigned int i = 0; i < len; i++) 2573 for (unsigned int i = 0; i < len; i++)
2505 if (data[i] == C0_LF) 2574 if (data[i] == C0_LF)
2506 data[i] = C0_CR; 2575 data[i] = C0_CR;
2650 { 2719 {
2651 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); 2720 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2652 char *s = rxvt_wcstombs (w); 2721 char *s = rxvt_wcstombs (w);
2653 free (w); 2722 free (w);
2654 // TODO: strlen == only the first element will be converted. well... 2723 // TODO: strlen == only the first element will be converted. well...
2655 paste ((unsigned char *)s, strlen (s)); 2724 paste (s, strlen (s));
2656 free (s); 2725 free (s);
2657 } 2726 }
2658 else 2727 else
2659#endif 2728#endif
2660 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 2729 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0
2661 && cl) 2730 && cl)
2662 { 2731 {
2663 for (int i = 0; i < cr; i++) 2732 for (int i = 0; i < cr; i++)
2664 paste ((unsigned char *)cl[i], strlen (cl[i])); 2733 paste (cl[i], strlen (cl[i]));
2665 2734
2666 XFreeStringList (cl); 2735 XFreeStringList (cl);
2667 } 2736 }
2668 else 2737 else
2669 paste (ct.value, ct.nitems); // paste raw 2738 paste ((char *)ct.value, ct.nitems); // paste raw
2670 2739
2671bailout: 2740bailout:
2672 XFree (ct.value); 2741 XFree (ct.value);
2673 2742
2674 if (selection_wait == Sel_normal) 2743 if (selection_wait == Sel_normal)
2712 return; /* outside window */ 2781 return; /* outside window */
2713 2782
2714 if (selection.text) 2783 if (selection.text)
2715 { /* internal selection */ 2784 { /* internal selection */
2716 char *str = rxvt_wcstombs (selection.text, selection.len); 2785 char *str = rxvt_wcstombs (selection.text, selection.len);
2717 paste ((unsigned char *)str, strlen (str)); 2786 paste (str, strlen (str));
2718 free (str); 2787 free (str);
2719 return; 2788 return;
2720 } 2789 }
2721 else 2790 else
2722 { 2791 {
2814 selection.op = SELECTION_DONE; 2883 selection.op = SELECTION_DONE;
2815 2884
2816 if (selection.clicks == 4) 2885 if (selection.clicks == 4)
2817 return; /* nothing selected, go away */ 2886 return; /* nothing selected, go away */
2818 2887
2888 if (PERL_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END)))
2889 return;
2890
2819 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); 2891 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1);
2820 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));
2821 2893
2822 int ofs = 0; 2894 int ofs = 0;
2823 int extra = 0; 2895 int extra = 0;
2839#endif 2911#endif
2840 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
2841 2913
2842 col = max (col, 0); 2914 col = max (col, 0);
2843 2915
2844 if (row == selection.end.row || selection.rect) 2916 if (row == selection.end.row
2917#if ENABLE_FRILLS
2918 || selection.rect
2919#endif
2920 )
2845 end_col = min (end_col, selection.end.col); 2921 min_it (end_col, selection.end.col);
2846 2922
2847 t = ROW(row).t + col; 2923 t = ROW(row).t + col;
2848 for (; col < end_col; col++) 2924 for (; col < end_col; col++)
2849 { 2925 {
2850 if (*t == NOCHAR) 2926 if (*t == NOCHAR)
2868#endif 2944#endif
2869 else 2945 else
2870 new_selection_text[ofs++] = *t++; 2946 new_selection_text[ofs++] = *t++;
2871 } 2947 }
2872 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
2873 if (!ROW(row).is_longer () && row != selection.end.row) 2961 if (!ROW(row).is_longer () && row != selection.end.row)
2874 new_selection_text[ofs++] = C0_LF; 2962 new_selection_text[ofs++] = C0_LF;
2875 } 2963 }
2876 2964
2877 if (end_col != selection.end.col) 2965 if (end_col != selection.end.col)
2878 new_selection_text[ofs++] = C0_LF; 2966 new_selection_text[ofs++] = C0_LF;
2879 2967
2889 2977
2890 // 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
2891 selection.len = ofs; 2979 selection.len = ofs;
2892 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));
2893 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
2894 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); 2993 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm);
2895 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) 2994 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt)
2995 {
2896 display->set_selection_owner (this); 2996 display->set_selection_owner (this);
2997 return true;
2998 }
2897 else 2999 else
2898 rxvt_warn ("can't get primary selection, ignoring.\n"); 3000 return false;
2899 3001
2900#if 0 3002#if 0
2901 XTextProperty ct; 3003 XTextProperty ct;
2902 3004
2903 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3005 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0)
2904 { 3006 {
2905 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); 3007 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
2906 XFree (ct.value); 3008 XFree (ct.value);
2907 } 3009 }
2908#endif 3010#endif
2909
2910 selection_time = tm;
2911} 3011}
2912 3012
2913/* ------------------------------------------------------------------------- */ 3013/* ------------------------------------------------------------------------- */
2914/* 3014/*
2915 * 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
3037 } 3137 }
3038 } 3138 }
3039 break; 3139 break;
3040 } 3140 }
3041 3141
3042Old_Word_Selection_You_Die:
3043 if (dirn == DN) 3142 if (dirn == DN)
3044 col++; /* put us on one past the end */ 3143 col++; /* put us on one past the end */
3045 3144
3046 /* Poke the values back in */ 3145 /* Poke the values back in */
3047 ret->row = row; 3146 ret->row = row;
3224 else if (selection.clicks == 2) 3323 else if (selection.clicks == 2)
3225 { 3324 {
3226 if (ROWCOL_IS_AFTER (selection.end, selection.beg)) 3325 if (ROWCOL_IS_AFTER (selection.end, selection.beg))
3227 selection.end.col--; 3326 selection.end.col--;
3228 3327
3328 if (!PERL_INVOKE ((this, HOOK_SEL_EXTEND, DT_END)))
3329 {
3229 selection_delimit_word (UP, &selection.beg, &selection.beg); 3330 selection_delimit_word (UP, &selection.beg, &selection.beg);
3230 selection_delimit_word (DN, &selection.end, &selection.end); 3331 selection_delimit_word (DN, &selection.end, &selection.end);
3332 }
3231 } 3333 }
3232 else if (selection.clicks == 3) 3334 else if (selection.clicks == 3)
3233 { 3335 {
3234#if ENABLE_FRILLS 3336#if ENABLE_FRILLS
3235 if (options & Opt_tripleclickwords) 3337 if (OPTION (Opt_tripleclickwords))
3236 { 3338 {
3237 selection_delimit_word (UP, &selection.beg, &selection.beg); 3339 selection_delimit_word (UP, &selection.beg, &selection.beg);
3238 3340
3239 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++)
3240 { 3342 {
3301 { 3403 {
3302 stp = ROW(end_row).t; 3404 stp = ROW(end_row).t;
3303 3405
3304 while (--end_col >= 0) 3406 while (--end_col >= 0)
3305 { 3407 {
3306 if (stp[end_col] != ' ' 3408 if (stp[end_col] != NOCHAR
3307 && stp[end_col] != '\t' 3409 && !unicode::is_space (stp[end_col]))
3308 && stp[end_col] != NOCHAR)
3309 break; 3410 break;
3310 } 3411 }
3311 3412
3312 if (end_col >= 0 3413 if (end_col >= 0
3313 || !ROW(end_row - 1).is_longer ()) 3414 || !ROW(end_row - 1).is_longer ())
3512 3613
3513#if ENABLE_OVERLAY 3614#if ENABLE_OVERLAY
3514void 3615void
3515rxvt_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)
3516{ 3617{
3517 if (nrow < 3 || ncol < 3) 3618 if (nrow < 1 || ncol < 1)
3518 return; 3619 return;
3519 3620
3520 want_refresh = 1; 3621 want_refresh = 1;
3521 3622
3522 scr_overlay_off (); 3623 scr_overlay_off ();
3629 for (int y = ov_h; y--; ) 3730 for (int y = ov_h; y--; )
3630 { 3731 {
3631 text_t *t1 = ov_text[y]; 3732 text_t *t1 = ov_text[y];
3632 rend_t *r1 = ov_rend[y]; 3733 rend_t *r1 = ov_rend[y];
3633 3734
3634 text_t *t2 = ROW(y - view_start).t + ov_x; 3735 text_t *t2 = ROW(y + ov_y - view_start).t + ov_x;
3635 rend_t *r2 = ROW(y - view_start).r + ov_x; 3736 rend_t *r2 = ROW(y + ov_y - view_start).r + ov_x;
3636 3737
3637 for (int x = ov_w; x--; ) 3738 for (int x = ov_w; x--; )
3638 { 3739 {
3639 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3740 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3640 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