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.206 by root, Tue Jan 3 17:34:44 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;
678#ifdef DEBUG_STRICT 737#ifdef DEBUG_STRICT
679 assert (screen.cur.col < last_col); 738 assert (screen.cur.col < last_col);
680 assert (screen.cur.row < nrow 739 assert (screen.cur.row < nrow
681 && screen.cur.row >= -nsaved); 740 && screen.cur.row >= -nsaved);
682#endif 741#endif
683 row = screen.cur.row; 742 int row = screen.cur.row;
684 743
685 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 744 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
686 745
687 line_t *line = &ROW(row); 746 line_t *line = &ROW(row);
688 747
690 { 749 {
691 c = *str++; 750 c = *str++;
692 751
693 if (c < 0x20) 752 if (c < 0x20)
694 if (c == C0_LF) 753 if (c == C0_LF)
695 { 754 {
696 if (!line->is_longer ()) /* XXX: think about this */ 755 if (!line->is_longer ()) /* XXX: think about this */
697 max_it (line->l, screen.cur.col); 756 max_it (line->l, screen.cur.col);
698 757
699 screen.flags &= ~Screen_WrapNext; 758 screen.flags &= ~Screen_WrapNext;
700 759
945 1004
946 if (count == 0) 1005 if (count == 0)
947 return; 1006 return;
948 else if (count > 0) 1007 else if (count > 0)
949 { 1008 {
950 int row = screen.cur.row;
951
952 line_t &l = ROW(row); 1009 line_t &l = ROW(screen.cur.row);
953 rend_t base_rend = l.r[i]; 1010 rend_t base_rend = l.r[i];
954 ht &= l.t[i] == ' '; 1011 ht &= l.t[i] == ' ';
955 1012
956 for (; ++i < ncol; ) 1013 for (; ++i < ncol; )
957 if (tabs[i]) 1014 if (tabs[i])
967 if (count) 1024 if (count)
968 x = ncol - 1; 1025 x = ncol - 1;
969 1026
970 // store horizontal tab commands as characters inside the text 1027 // store horizontal tab commands as characters inside the text
971 // buffer so they can be selected and pasted. 1028 // buffer so they can be selected and pasted.
972 if (ht && options & Opt_pastableTabs) 1029 if (ht && OPTION (Opt_pastableTabs))
973 { 1030 {
974 base_rend = SET_FONT (base_rend, 0); 1031 base_rend = SET_FONT (base_rend, 0);
975 1032
976 if (!l.is_longer ()) /* XXX: think about this */ 1033 if (!l.is_longer ()) /* XXX: think about this */
977 max_it (l.l, x); 1034 max_it (l.l, x);
1032 */ 1089 */
1033#if ENABLE_FRILLS 1090#if ENABLE_FRILLS
1034void 1091void
1035rxvt_term::scr_forwardindex () 1092rxvt_term::scr_forwardindex ()
1036{ 1093{
1037 int row;
1038
1039 if (screen.cur.col < ncol - 1) 1094 if (screen.cur.col < ncol - 1)
1040 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1095 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1041 else 1096 else
1042 { 1097 {
1043 row = screen.cur.row;
1044
1045 if (ROW(row).is_longer ()) //TODO//FIXME//LEN 1098 if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN
1046 ROW(row).l = ncol; 1099 ROW(screen.cur.row).l = ncol;
1047 1100
1048 scr_gotorc (0, 0, R_RELATIVE); 1101 scr_gotorc (0, 0, R_RELATIVE);
1049 scr_insdel_chars (1, DELETE); 1102 scr_insdel_chars (1, DELETE);
1050 scr_gotorc (0, ncol - 1, R_RELATIVE); 1103 scr_gotorc (0, ncol - 1, R_RELATIVE);
1051 } 1104 }
1134 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1187 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1135 */ 1188 */
1136void 1189void
1137rxvt_term::scr_erase_line (int mode) 1190rxvt_term::scr_erase_line (int mode)
1138{ 1191{
1139 unsigned int row, col, num; 1192 unsigned int col, num;
1140 1193
1141 want_refresh = 1; 1194 want_refresh = 1;
1142 ZERO_SCROLLBACK (); 1195 ZERO_SCROLLBACK ();
1143 1196
1144 selection_check (1); 1197 selection_check (1);
1145 1198
1146 row = screen.cur.row; 1199 line_t &line = ROW(screen.cur.row);
1147 1200
1148 switch (mode) 1201 switch (mode)
1149 { 1202 {
1150 case 0: /* erase to end of line */ 1203 case 0: /* erase to end of line */
1151 col = screen.cur.col; 1204 col = screen.cur.col;
1152 num = ncol - col; 1205 num = ncol - col;
1153 min_it (ROW(row).l, col); 1206 min_it (line.l, col);
1154 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1207 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1155 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1208 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1156 CLEAR_SELECTION (); 1209 CLEAR_SELECTION ();
1157 break; 1210 break;
1158 case 1: /* erase to beginning of line */ 1211 case 1: /* erase to beginning of line */
1163 CLEAR_SELECTION (); 1216 CLEAR_SELECTION ();
1164 break; 1217 break;
1165 case 2: /* erase whole line */ 1218 case 2: /* erase whole line */
1166 col = 0; 1219 col = 0;
1167 num = ncol; 1220 num = ncol;
1168 ROW(row).l = 0; 1221 line.l = 0;
1169 if (selection.beg.row <= screen.cur.row 1222 if (selection.beg.row <= screen.cur.row
1170 && selection.end.row >= screen.cur.row) 1223 && selection.end.row >= screen.cur.row)
1171 CLEAR_SELECTION (); 1224 CLEAR_SELECTION ();
1172 break; 1225 break;
1173 default: 1226 default:
1174 return; 1227 return;
1175 } 1228 }
1176 1229
1177 scr_blank_line (ROW(row), col, num, rstyle); 1230 scr_blank_line (line, col, num, rstyle);
1178} 1231}
1179 1232
1180/* ------------------------------------------------------------------------- */ 1233/* ------------------------------------------------------------------------- */
1181/* 1234/*
1182 * Erase part of whole of the screen 1235 * Erase part of whole of the screen
1237 CLEAR_ROWS (row, num); 1290 CLEAR_ROWS (row, num);
1238 } 1291 }
1239 else 1292 else
1240 { 1293 {
1241 ren = rstyle & (RS_fgMask | RS_bgMask); 1294 ren = rstyle & (RS_fgMask | RS_bgMask);
1242 gcvalue.foreground = pix_colors[GET_BGCOLOR (rstyle)]; 1295 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1243 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1296 XChangeGC (display->display, gc, GCForeground, &gcvalue);
1244 ERASE_ROWS (row, num); 1297 ERASE_ROWS (row, num);
1245 gcvalue.foreground = pix_colors[Color_fg]; 1298 gcvalue.foreground = pix_colors[Color_fg];
1246 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1299 XChangeGC (display->display, gc, GCForeground, &gcvalue);
1247 } 1300 }
1248 1301
1249 for (; num--; row++) 1302 for (; num--; row++)
1250 { 1303 {
1304 ROW (row).l = 0;
1251 scr_blank_screen_mem (ROW (row), rstyle); 1305 scr_blank_screen_mem (ROW (row), rstyle);
1252 ROW (row).l = 0;
1253 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1306 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1254 } 1307 }
1255} 1308}
1256 1309
1257#if ENABLE_FRILLS 1310#if ENABLE_FRILLS
1546 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1599 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1547#if XPM_BACKGROUND 1600#if XPM_BACKGROUND
1548 if (bgPixmap.pixmap == None) 1601 if (bgPixmap.pixmap == None)
1549#endif 1602#endif
1550#if TRANSPARENT 1603#if TRANSPARENT
1551 if (! (options & Opt_transparent) || am_transparent == 0) 1604 if (! OPTION (Opt_transparent) || am_transparent == 0)
1552#endif 1605#endif
1553 XSetWindowBackground (display->display, vt, 1606 XSetWindowBackground (display->display, vt,
1554 pix_colors[Color_bg]); 1607 pix_colors[Color_bg]);
1555 1608
1556 gcvalue.foreground = pix_colors[Color_fg]; 1609 gcvalue.foreground = pix_colors[Color_fg];
1772} 1825}
1773 1826
1774int 1827int
1775rxvt_term::scr_changeview (unsigned int oldviewstart) 1828rxvt_term::scr_changeview (unsigned int oldviewstart)
1776{ 1829{
1830 PERL_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END));
1831
1777 if (view_start != oldviewstart) 1832 if (view_start != oldviewstart)
1778 { 1833 {
1779 want_refresh = 1; 1834 want_refresh = 1;
1780 num_scr -= (view_start - oldviewstart); 1835 num_scr -= (view_start - oldviewstart);
1781 } 1836 }
1789{ 1844{
1790#ifndef NO_BELL 1845#ifndef NO_BELL
1791 1846
1792# ifndef NO_MAPALERT 1847# ifndef NO_MAPALERT
1793# ifdef MAPALERT_OPTION 1848# ifdef MAPALERT_OPTION
1794 if (options & Opt_mapAlert) 1849 if (OPTION (Opt_mapAlert))
1795# endif 1850# endif
1796 XMapWindow (display->display, parent[0]); 1851 XMapWindow (display->display, parent[0]);
1797# endif 1852# endif
1798 1853
1799 if (options & Opt_visualBell) 1854 if (OPTION (Opt_visualBell))
1800 { 1855 {
1801 scr_rvideo_mode (!rvideo); /* refresh also done */ 1856 scr_rvideo_mode (!rvideo); /* refresh also done */
1802 rxvt_usleep (VISUAL_BELL_DURATION); 1857 rxvt_usleep (VISUAL_BELL_DURATION);
1803 scr_rvideo_mode (!rvideo); /* refresh also done */ 1858 scr_rvideo_mode (!rvideo); /* refresh also done */
1804 } 1859 }
1895 1950
1896#if XPM_BACKGROUND 1951#if XPM_BACKGROUND
1897 must_clear |= bgPixmap.pixmap != None; 1952 must_clear |= bgPixmap.pixmap != None;
1898#endif 1953#endif
1899#if TRANSPARENT 1954#if TRANSPARENT
1900 must_clear |= (options & Opt_transparent) && am_transparent; 1955 must_clear |= OPTION (Opt_transparent) && am_transparent;
1901#endif 1956#endif
1902 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 1957 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1903 1958
1904 /* 1959 /*
1905 * B: reverse any characters which are selected 1960 * B: reverse any characters which are selected
1929 1984
1930 crp = &ROW(screen.cur.row).r[col]; 1985 crp = &ROW(screen.cur.row).r[col];
1931 1986
1932 if (showcursor && focus) 1987 if (showcursor && focus)
1933 { 1988 {
1934 if (options & Opt_cursorUnderline) 1989 if (OPTION (Opt_cursorUnderline))
1935 *crp ^= RS_Uline; 1990 *crp ^= RS_Uline;
1936 else 1991 else
1937 { 1992 {
1938 *crp ^= RS_RVid; 1993 *crp ^= RS_RVid;
1939 1994
1941 cc1 = *crp & (RS_fgMask | RS_bgMask); 1996 cc1 = *crp & (RS_fgMask | RS_bgMask);
1942 if (ISSET_PIXCOLOR (Color_cursor)) 1997 if (ISSET_PIXCOLOR (Color_cursor))
1943 ccol1 = Color_cursor; 1998 ccol1 = Color_cursor;
1944 else 1999 else
1945#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 2000#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1946 ccol1 = GET_FGCOLOR (rstyle); 2001 ccol1 = fgcolor_of (rstyle);
1947#else 2002#else
1948 ccol1 = Color_fg; 2003 ccol1 = Color_fg;
1949#endif 2004#endif
1950 if (ISSET_PIXCOLOR (Color_cursor2)) 2005 if (ISSET_PIXCOLOR (Color_cursor2))
1951 ccol2 = Color_cursor2; 2006 ccol2 = Color_cursor2;
1952 else 2007 else
1953#ifdef CURSOR_COLOR_IS_RENDITION_COLOR 2008#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
1954 ccol2 = GET_BGCOLOR (rstyle); 2009 ccol2 = bgcolor_of (rstyle);
1955#else 2010#else
1956 ccol2 = Color_bg; 2011 ccol2 = Color_bg;
1957#endif 2012#endif
1958 *crp = SET_FGCOLOR (*crp, ccol1); 2013 *crp = SET_FGCOLOR (*crp, ccol1);
1959 *crp = SET_BGCOLOR (*crp, ccol2); 2014 *crp = SET_BGCOLOR (*crp, ccol2);
1992 oldcursor.col = screen.cur.col; 2047 oldcursor.col = screen.cur.col;
1993 } 2048 }
1994 } 2049 }
1995 } 2050 }
1996 2051
2052 PERL_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
1997#if ENABLE_OVERLAY 2053#if ENABLE_OVERLAY
1998 scr_swap_overlay (); 2054 scr_swap_overlay ();
1999#endif 2055#endif
2000 2056
2001#ifndef NO_SLOW_LINK_SUPPORT 2057#ifndef NO_SLOW_LINK_SUPPORT
2140 count++, i--; 2196 count++, i--;
2141 2197
2142 /* 2198 /*
2143 * Determine the attributes for the string 2199 * Determine the attributes for the string
2144 */ 2200 */
2145 int fore = GET_FGCOLOR (rend); // desired foreground 2201 int fore = fgcolor_of (rend); // desired foreground
2146 int back = GET_BGCOLOR (rend); // desired background 2202 int back = bgcolor_of (rend); // desired background
2147 2203
2148 // only do special processing if any attributes are set, which is rare 2204 // 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)) 2205 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))
2150 { 2206 {
2151#if ENABLE_STYLES 2207#if ENABLE_STYLES
2152 // force redraw after "careful" characters to avoid pixel droppings 2208 // force redraw after "careful" characters to avoid pixel droppings
2153 if (srp[col] & RS_Careful && col < ncol - 1 && 0) 2209 if (srp[col] & RS_Careful && col < ncol - 1 && 0)
2264 } /* for (row....) */ 2320 } /* for (row....) */
2265 2321
2266#if ENABLE_OVERLAY 2322#if ENABLE_OVERLAY
2267 scr_swap_overlay (); 2323 scr_swap_overlay ();
2268#endif 2324#endif
2325 PERL_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2269 2326
2270 /* 2327 /*
2271 * G: cleanup cursor and display outline cursor if necessary 2328 * G: cleanup cursor and display outline cursor if necessary
2272 */ 2329 */
2273 if (showcursor) 2330 if (showcursor)
2274 { 2331 {
2275 if (focus) 2332 if (focus)
2276 { 2333 {
2277 if (options & Opt_cursorUnderline) 2334 if (OPTION (Opt_cursorUnderline))
2278 *crp ^= RS_Uline; 2335 *crp ^= RS_Uline;
2279 else 2336 else
2280 { 2337 {
2281 *crp ^= RS_RVid; 2338 *crp ^= RS_RVid;
2282#ifndef NO_CURSORCOLOR 2339#ifndef NO_CURSORCOLOR
2401 2458
2402#if ENABLE_FRILLS 2459#if ENABLE_FRILLS
2403 if (selection.rect) 2460 if (selection.rect)
2404 { 2461 {
2405 for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++) 2462 for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++)
2463 {
2464 text_t *stp = ROW(row).t;
2465 rend_t *srp = ROW(row).r;
2466
2406 for (rend_t *srp = ROW(row).r, col = selection.beg.col; col < selection.end.col; col++) 2467 for (col = selection.beg.col; col < selection.end.col; col++)
2407 srp[col] ^= RS_RVid; 2468 srp[col] ^= RS_RVid;
2469
2470 while (col-- > selection.beg.col && (stp[col] == NOCHAR || unicode::is_space (stp[col])))
2471 srp[col] ^= RS_RVid | RS_Uline;
2472
2473 if (++col < selection.end.col)
2474 srp[col] ^= RS_RVid | RS_Uline;
2475 }
2408 } 2476 }
2409 else 2477 else
2410#endif 2478#endif
2411 { 2479 {
2412 if (selection.beg.row >= -view_start) 2480 if (selection.beg.row >= -view_start)
2415 row = selection.beg.row; 2483 row = selection.beg.row;
2416 } 2484 }
2417 else 2485 else
2418 { 2486 {
2419 col = 0; 2487 col = 0;
2420 row = view_start; 2488 row = -view_start;
2421 } 2489 }
2422 2490
2423 for (; row < min (selection.end.row, view_end); row++, col = 0) 2491 for (; row < min (selection.end.row, view_end); row++, col = 0)
2424 for (rend_t *srp = ROW(row).r; col < ncol; col++) 2492 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2425 srp[col] ^= RS_RVid; 2493 srp[col] ^= RS_RVid;
2814 selection.op = SELECTION_DONE; 2882 selection.op = SELECTION_DONE;
2815 2883
2816 if (selection.clicks == 4) 2884 if (selection.clicks == 4)
2817 return; /* nothing selected, go away */ 2885 return; /* nothing selected, go away */
2818 2886
2887 if (PERL_INVOKE ((this, HOOK_SEL_MAKE, DT_LONG, (long)tm, DT_END)))
2888 return;
2889
2819 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1); 2890 i = (selection.end.row - selection.beg.row + 1) * (ncol + 1);
2820 new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t)); 2891 new_selection_text = (wchar_t *)rxvt_malloc ((i + 4) * sizeof (wchar_t));
2821 2892
2822 int ofs = 0; 2893 int ofs = 0;
2823 int extra = 0; 2894 int extra = 0;
2839#endif 2910#endif
2840 end_col = ROW(row).is_longer () ? ncol : ROW(row).l; //TODO//FIXME//LEN 2911 end_col = ROW(row).is_longer () ? ncol : ROW(row).l; //TODO//FIXME//LEN
2841 2912
2842 col = max (col, 0); 2913 col = max (col, 0);
2843 2914
2844 if (row == selection.end.row || selection.rect) 2915 if (row == selection.end.row
2916#if ENABLE_FRILLS
2917 || selection.rect
2918#endif
2919 )
2845 end_col = min (end_col, selection.end.col); 2920 min_it (end_col, selection.end.col);
2846 2921
2847 t = ROW(row).t + col; 2922 t = ROW(row).t + col;
2848 for (; col < end_col; col++) 2923 for (; col < end_col; col++)
2849 { 2924 {
2850 if (*t == NOCHAR) 2925 if (*t == NOCHAR)
2868#endif 2943#endif
2869 else 2944 else
2870 new_selection_text[ofs++] = *t++; 2945 new_selection_text[ofs++] = *t++;
2871 } 2946 }
2872 2947
2948#if ENABLE_FRILLS
2949 if (selection.rect)
2950 {
2951 while (ofs
2952 && new_selection_text[ofs - 1] != C0_LF
2953 && unicode::is_space (new_selection_text[ofs - 1]))
2954 --ofs;
2955
2956 new_selection_text[ofs++] = C0_LF;
2957 }
2958 else
2959#endif
2873 if (!ROW(row).is_longer () && row != selection.end.row) 2960 if (!ROW(row).is_longer () && row != selection.end.row)
2874 new_selection_text[ofs++] = C0_LF; 2961 new_selection_text[ofs++] = C0_LF;
2875 } 2962 }
2876 2963
2877 if (end_col != selection.end.col) 2964 if (end_col != selection.end.col)
2878 new_selection_text[ofs++] = C0_LF; 2965 new_selection_text[ofs++] = C0_LF;
2879 2966
2889 2976
2890 // we usually allocate much more than necessary, so realloc it smaller again 2977 // we usually allocate much more than necessary, so realloc it smaller again
2891 selection.len = ofs; 2978 selection.len = ofs;
2892 selection.text = (wchar_t *)rxvt_realloc (new_selection_text, (ofs + 1) * sizeof (wchar_t)); 2979 selection.text = (wchar_t *)rxvt_realloc (new_selection_text, (ofs + 1) * sizeof (wchar_t));
2893 2980
2981 if (PERL_INVOKE ((this, HOOK_SEL_GRAB, DT_LONG, (long)tm, DT_END)))
2982 return;
2983
2984 selection_grab (tm);
2985}
2986
2987bool
2988rxvt_term::selection_grab (Time tm)
2989{
2990 selection_time = tm;
2991
2894 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); 2992 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm);
2895 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) 2993 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt)
2994 {
2896 display->set_selection_owner (this); 2995 display->set_selection_owner (this);
2996 return true;
2997 }
2897 else 2998 else
2898 rxvt_warn ("can't get primary selection, ignoring.\n"); 2999 return false;
2899 3000
2900#if 0 3001#if 0
2901 XTextProperty ct; 3002 XTextProperty ct;
2902 3003
2903 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3004 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0)
2904 { 3005 {
2905 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); 3006 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
2906 XFree (ct.value); 3007 XFree (ct.value);
2907 } 3008 }
2908#endif 3009#endif
2909
2910 selection_time = tm;
2911} 3010}
2912 3011
2913/* ------------------------------------------------------------------------- */ 3012/* ------------------------------------------------------------------------- */
2914/* 3013/*
2915 * Mark or select text based upon number of clicks: 1, 2, or 3 3014 * Mark or select text based upon number of clicks: 1, 2, or 3
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