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.215 by root, Sun Jan 8 06:35:23 2006 UTC vs.
Revision 1.252 by root, Wed Jan 25 21:09:21 2006 UTC

93 */ 93 */
94#define drawBuffer vt 94#define drawBuffer vt
95 95
96#define CLEAR_ROWS(row, num) \ 96#define CLEAR_ROWS(row, num) \
97 if (mapped) \ 97 if (mapped) \
98 XClearArea (display->display, drawBuffer, 0, \ 98 XClearArea (xdisp, drawBuffer, 0, \
99 Row2Pixel (row), (unsigned int)width, \ 99 Row2Pixel (row), (unsigned int)width, \
100 (unsigned int)Height2Pixel (num), False) 100 (unsigned int)Height2Pixel (num), False)
101 101
102#define CLEAR_CHARS(x, y, num) \ 102#define CLEAR_CHARS(x, y, num) \
103 if (mapped) \ 103 if (mapped) \
104 XClearArea (display->display, drawBuffer, x, y, \ 104 XClearArea (xdisp, drawBuffer, x, y, \
105 (unsigned int)Width2Pixel (num), \ 105 (unsigned int)Width2Pixel (num), \
106 (unsigned int)Height2Pixel (1), False) 106 (unsigned int)Height2Pixel (1), False)
107 107
108#define ERASE_ROWS(row, num) \ 108#define ERASE_ROWS(row, num) \
109 XFillRectangle (display->display, drawBuffer, gc, \ 109 XFillRectangle (xdisp, drawBuffer, gc, \
110 0, Row2Pixel (row), \ 110 0, Row2Pixel (row), \
111 (unsigned int)width, \ 111 (unsigned int)width, \
112 (unsigned int)Height2Pixel (num)) 112 (unsigned int)Height2Pixel (num))
113 113
114/* ------------------------------------------------------------------------- * 114/* ------------------------------------------------------------------------- *
115 * SCREEN `COMMON' ROUTINES * 115 * SCREEN `COMMON' ROUTINES *
116 * ------------------------------------------------------------------------- */ 116 * ------------------------------------------------------------------------- */
117 117
118/* Fill part/all of a line with blanks. */ 118/* Fill part/all of a line with blanks. */
119void 119void
120rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) 120rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) const NOTHROW
121{ 121{
122 if (!l.t) 122 if (!l.t)
123 { 123 {
124 lalloc (l); 124 lalloc (l);
125 col = 0; 125 col = 0;
142} 142}
143 143
144/* ------------------------------------------------------------------------- */ 144/* ------------------------------------------------------------------------- */
145/* Fill a full line with blanks - make sure it is allocated first */ 145/* Fill a full line with blanks - make sure it is allocated first */
146void 146void
147rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) 147rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) const NOTHROW
148{ 148{
149 scr_blank_line (l, 0, ncol, efs); 149 scr_blank_line (l, 0, ncol, efs);
150 150
151 l.l = 0; 151 l.l = 0;
152 l.f = 0; 152 l.f = 0;
173 nrow = 24; 173 nrow = 24;
174 174
175 if (ncol == prev_ncol && nrow == prev_nrow) 175 if (ncol == prev_ncol && nrow == prev_nrow)
176 return; 176 return;
177 177
178 if (current_screen != PRIMARY)
179 scr_swap_screen ();
180
178 // we need at least two lines for wrapping to work correctly 181 // we need at least two lines for wrapping to work correctly
179 if (nrow + saveLines < 2) 182 while (nrow + saveLines < 2)
180 { 183 {
181 //TODO//FIXME 184 //TODO//FIXME
182 saveLines++; 185 saveLines++;
183 prev_nrow--; 186 prev_nrow--;
184 nsaved++; 187 top_row--;
185 } 188 }
186 189
187 want_refresh = 1; 190 want_refresh = 1;
188 191
189 int prev_total_rows = prev_nrow + saveLines; 192 int prev_total_rows = prev_nrow + saveLines;
194 197
195 if (!row_buf) 198 if (!row_buf)
196 { 199 {
197 /* 200 /*
198 * first time called so just malloc everything: don't rely on realloc 201 * first time called so just malloc everything: don't rely on realloc
199 * Note: this is still needed so that all the scrollback lines are NULL
200 */ 202 */
201 nsaved = 0; /* no saved lines */ 203 top_row = 0;
202 term_start = 0; 204 term_start = 0;
203 205
204 talloc = new rxvt_salloc (ncol * sizeof (text_t)); 206 talloc = new rxvt_salloc (ncol * sizeof (text_t));
205 ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 207 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
206 208
207 row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 209 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t));
208 temp_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
209 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); 210 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
210 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); 211 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
211 212
212 for (int row = nrow; row--; ) 213 for (int row = nrow; row--; )
213 { 214 {
214 scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE); 215 scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE);
215 scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); 216 scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
236 selection.text = NULL; 237 selection.text = NULL;
237 selection.len = 0; 238 selection.len = 0;
238 selection.op = SELECTION_CLEAR; 239 selection.op = SELECTION_CLEAR;
239 selection.screen = PRIMARY; 240 selection.screen = PRIMARY;
240 selection.clicks = 0; 241 selection.clicks = 0;
241 CLEAR_ALL_SELECTION (); 242 rvideo_state = rvideo_mode = false;
242 rvideo = 0;
243 } 243 }
244 else 244 else
245 { 245 {
246 /* 246 /*
247 * add or delete rows as appropriate 247 * add or delete rows as appropriate
260 } 260 }
261 } 261 }
262#endif 262#endif
263 263
264 drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); 264 drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t));
265 temp_buf = (line_t *)rxvt_realloc (temp_buf , nrow * sizeof (line_t));
266 swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t)); 265 swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t));
267 266
268 for (int row = min (nrow, prev_nrow); row--; ) 267 for (int row = min (nrow, prev_nrow); row--; )
269 { 268 {
270 lresize (drawn_buf[row]); 269 lresize (drawn_buf[row]);
275 { 274 {
276 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);
277 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);
278 } 277 }
279 278
279 line_t *old_buf = row_buf;
280 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 280 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, 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 - nsaved , 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
286 if (nsaved) 286 if (top_row)
287 { 287 {
288 // re-wrap lines, this is rather ugly, possibly because I am too dumb 288 // Re-wrap lines. This is rather ugly, possibly because I am too dumb
289 // to come up with a lean and mean algorithm. 289 // to come up with a lean and mean algorithm.
290 290
291 row_col_t ocur = screen.cur; 291 row_col_t ocur = screen.cur;
292 ocur.row = MOD (term_start + ocur.row, prev_total_rows); 292 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
293 293
327 qline->l = ncol; 327 qline->l = ncol;
328 qline->is_longer (1); 328 qline->is_longer (1);
329 329
330 int qcol = 0; 330 int qcol = 0;
331 331
332 // see below for cursor adjustment rationale
333 if (p == ocur.row)
334 screen.cur.row = q - (total_rows - nrow);
335
332 // fill a single destination line 336 // fill a single destination line
333 while (lofs < llen && qcol < ncol) 337 while (lofs < llen && qcol < ncol)
334 { 338 {
335 int prow = lofs / prev_ncol; 339 int prow = lofs / prev_ncol;
336 int pcol = lofs % prev_ncol; 340 int pcol = lofs % prev_ncol;
346 350
347 line_t &pline = old_buf [prow]; 351 line_t &pline = old_buf [prow];
348 352
349 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 353 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
350 354
351 assert (len);
352 assert (pline.t);
353
354 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); 355 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
355 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); 356 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
356 357
357 lofs += len; 358 lofs += len;
358 qcol += len; 359 qcol += len;
364 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); 365 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
365 } 366 }
366 while (p != pend && q > 0); 367 while (p != pend && q > 0);
367 368
368 term_start = total_rows - nrow; 369 term_start = total_rows - nrow;
369 nsaved = term_start - q; 370 top_row = q - term_start;
370 371
371 // make sure all terminal lines exist 372 // make sure all terminal lines exist
372 while (nsaved < 0) 373 while (top_row > 0)
373 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); 374 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
374 } 375 }
375 else 376 else
376 { 377 {
377 // if no scrollback exists (yet), wing, instead of wrap 378 // if no scrollback exists (yet), wing, instead of wrap
378 379
391 } 392 }
392 393
393 term_start = 0; 394 term_start = 0;
394 } 395 }
395 396
396#ifdef DEBUG_STRICT //TODO: remove
397 for (int i = -nsaved; i < nrow; i++)
398 assert (ROW (i).t);
399#endif
400
401 free (old_buf); 397 free (old_buf);
402 delete old_ta; 398 delete old_ta;
403 delete old_ra; 399 delete old_ra;
404 400
405 clamp_it (screen.cur.row, 0, nrow - 1); 401 clamp_it (screen.cur.row, 0, nrow - 1);
406 clamp_it (screen.cur.col, 0, ncol - 1); 402 clamp_it (screen.cur.col, 0, ncol - 1);
407 403
408 if (tabs)
409 free (tabs); 404 free (tabs);
410 } 405 }
406
407 CLEAR_ALL_SELECTION ();
411 408
412 prev_nrow = nrow; 409 prev_nrow = nrow;
413 prev_ncol = ncol; 410 prev_ncol = ncol;
414 411
415 tabs = (char *)rxvt_malloc (ncol * sizeof (char)); 412 tabs = (char *)rxvt_malloc (ncol * sizeof (char));
416 413
417 for (int col = ncol; col--; ) 414 for (int col = ncol; col--; )
418 tabs [col] = col % TABSIZE == 0; 415 tabs [col] = col % TABSIZE == 0;
419 416
417 if (current_screen != PRIMARY)
418 scr_swap_screen ();
419
420 tt_winch (); 420 tt_winch ();
421 421
422 HOOK_INVOKE ((this, HOOK_RESET, DT_END)); 422 HOOK_INVOKE ((this, HOOK_RESET, DT_END));
423} 423}
424 424
425/* ------------------------------------------------------------------------- */ 425/* ------------------------------------------------------------------------- */
426/* 426/*
427 * Free everything. That way malloc debugging can find leakage. 427 * Free everything. That way malloc debugging can find leakage.
428 */ 428 */
429void 429void
430rxvt_term::scr_release () 430rxvt_term::scr_release () NOTHROW
431{ 431{
432 if (row_buf)
433 {
432 delete talloc; talloc = 0; 434 delete talloc; talloc = 0;
433 delete ralloc; ralloc = 0; 435 delete ralloc; ralloc = 0;
434 436
435 free (row_buf); 437 free (row_buf);
436 free (swap_buf); 438 free (swap_buf);
437 free (drawn_buf); 439 free (drawn_buf);
438 free (temp_buf);
439 free (tabs); 440 free (tabs);
440 441
441 row_buf = 0; // signal that we freed all the arrays 442 row_buf = 0; // signal that we freed all the arrays
443 }
442} 444}
443 445
444/* ------------------------------------------------------------------------- */ 446/* ------------------------------------------------------------------------- */
445/* 447/*
446 * Hard reset 448 * Hard reset
451 scr_release (); 453 scr_release ();
452 prev_nrow = prev_ncol = 0; 454 prev_nrow = prev_ncol = 0;
453 scr_reset (); 455 scr_reset ();
454 456
455 scr_clear (true); 457 scr_clear (true);
456 scr_refresh (SLOW_REFRESH); 458 scr_refresh ();
457} 459}
458 460
459/* ------------------------------------------------------------------------- * 461/* ------------------------------------------------------------------------- *
460 * PROCESS SCREEN COMMANDS * 462 * PROCESS SCREEN COMMANDS *
461 * ------------------------------------------------------------------------- */ 463 * ------------------------------------------------------------------------- */
463 * Save and Restore cursor 465 * Save and Restore cursor
464 * XTERM_SEQ: Save cursor : ESC 7 466 * XTERM_SEQ: Save cursor : ESC 7
465 * XTERM_SEQ: Restore cursor: ESC 8 467 * XTERM_SEQ: Restore cursor: ESC 8
466 */ 468 */
467void 469void
468rxvt_term::scr_cursor (int mode) 470rxvt_term::scr_cursor (cursor_mode mode) NOTHROW
469{ 471{
470 screen_t *s; 472 screen_t *s;
471 473
472#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR) 474#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR)
473 if (current_screen == SECONDARY) 475 if (current_screen == SECONDARY)
505 assert (s->cur.row >= 0); 507 assert (s->cur.row >= 0);
506 assert (s->cur.col >= 0); 508 assert (s->cur.col >= 0);
507#endif 509#endif
508} 510}
509 511
512void
513rxvt_term::scr_swap_screen ()
514{
515 if (!OPTION (Opt_secondaryScreen))
516 return;
517
518 for (int i = prev_nrow; i--; )
519 ::swap (ROW(i), swap_buf [i]);
520
521 ::swap (screen.cur, swap.cur);
522
523 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
524 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
525}
526
510/* ------------------------------------------------------------------------- */ 527/* ------------------------------------------------------------------------- */
511/* 528/*
512 * Swap between primary and secondary screens 529 * Swap between primary and secondary screens
513 * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h 530 * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h
514 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l 531 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l
515 */ 532 */
516int 533void
517rxvt_term::scr_change_screen (int scrn) 534rxvt_term::scr_change_screen (int scrn)
518{ 535{
536 if (scrn == current_screen)
537 return;
538
519 want_refresh = 1; 539 want_refresh = 1;
520 view_start = 0; 540 view_start = 0;
521 541
522 if (current_screen == scrn)
523 return scrn;
524
525 selection_check (2); /* check for boundary cross */ 542 selection_check (2); /* check for boundary cross */
526 543
527 int i = current_screen; current_screen = scrn; scrn = i; 544 int i = current_screen; current_screen = scrn; scrn = i;
528
529 ::swap (screen.cur.row, swap.cur.row);
530 ::swap (screen.cur.col, swap.cur.col);
531
532 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
533 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
534 545
535#if NSCREENS 546#if NSCREENS
536 if (OPTION (Opt_secondaryScreen)) 547 if (OPTION (Opt_secondaryScreen))
537 { 548 {
538 num_scr = 0; 549 num_scr = 0;
539 550
540 for (int i = prev_nrow; i--; ) 551 scr_swap_screen ();
541 ::swap (ROW(i), swap_buf [i]);
542 552
543 ::swap (screen.charset, swap.charset); 553 ::swap (screen.charset, swap.charset);
544 ::swap (screen.flags, swap.flags); 554 ::swap (screen.flags, swap.flags);
545 screen.flags |= Screen_VisibleCursor; 555 screen.flags |= Screen_VisibleCursor;
546 swap.flags |= Screen_VisibleCursor; 556 swap.flags |= Screen_VisibleCursor;
547 } 557 }
548 else 558 else
549#endif 559#endif
550 if (OPTION (Opt_secondaryScroll)) 560 if (OPTION (Opt_secondaryScroll))
551 scr_scroll_text (0, prev_nrow - 1, prev_nrow); 561 scr_scroll_text (0, prev_nrow - 1, prev_nrow);
552
553 return scrn;
554} 562}
555 563
556// clear WrapNext indicator, solidifying position on next line 564// clear WrapNext indicator, solidifying position on next line
557void 565void
558rxvt_term::scr_do_wrap () 566rxvt_term::scr_do_wrap () NOTHROW
559{ 567{
560 if (!(screen.flags & Screen_WrapNext)) 568 if (!(screen.flags & Screen_WrapNext))
561 return; 569 return;
562 570
563 screen.flags &= ~Screen_WrapNext; 571 screen.flags &= ~Screen_WrapNext;
573/* ------------------------------------------------------------------------- */ 581/* ------------------------------------------------------------------------- */
574/* 582/*
575 * Change the colour for following text 583 * Change the colour for following text
576 */ 584 */
577void 585void
578rxvt_term::scr_color (unsigned int color, int fgbg) 586rxvt_term::scr_color (unsigned int color, int fgbg) NOTHROW
579{ 587{
580 if (color > maxTermCOLOR) 588 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
581 color = fgbg; 589 color = fgbg;
582 590
583 if (fgbg == Color_fg) 591 if (fgbg == Color_fg)
584 rstyle = SET_FGCOLOR (rstyle, color); 592 rstyle = SET_FGCOLOR (rstyle, color);
585 else 593 else
589/* ------------------------------------------------------------------------- */ 597/* ------------------------------------------------------------------------- */
590/* 598/*
591 * Change the rendition style for following text 599 * Change the rendition style for following text
592 */ 600 */
593void 601void
594rxvt_term::scr_rendition (int set, int style) 602rxvt_term::scr_rendition (int set, int style) NOTHROW
595 { 603 {
596 if (set) 604 if (set)
597 rstyle |= style; 605 rstyle |= style;
598 else if (style == ~RS_None) 606 else if (style == ~RS_None)
599 rstyle = DEFAULT_RSTYLE; 607 rstyle = DEFAULT_RSTYLE;
606 * Scroll text between <row1> and <row2> inclusive, by <count> lines 614 * Scroll text between <row1> and <row2> inclusive, by <count> lines
607 * count positive ==> scroll up 615 * count positive ==> scroll up
608 * count negative ==> scroll down 616 * count negative ==> scroll down
609 */ 617 */
610int 618int
611rxvt_term::scr_scroll_text (int row1, int row2, int count) 619rxvt_term::scr_scroll_text (int row1, int row2, int count) NOTHROW
612{ 620{
613 if (count == 0 || (row1 > row2)) 621 if (count == 0 || (row1 > row2))
614 return 0; 622 return 0;
615 623
616 want_refresh = 1; 624 want_refresh = 1;
617 num_scr += count; 625 num_scr += count;
618 626
619 if (count > 0 627 if (count > 0
620 && row1 == 0 628 && row1 == 0
621 && row2 == nrow - 1
622 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll))) 629 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll)))
623 { 630 {
624 nsaved = min (nsaved + count, saveLines); 631 top_row = max (top_row - count, -saveLines);
625 632
626 HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, nsaved, DT_END)); 633 // scroll everything up 'count' lines
634 term_start = (term_start + count) % total_rows;
635
636 // sever bottommost line
637 {
638 line_t &l = ROW(row2 - count);
639 l.is_longer (0);
640 l.touch ();
641 }
642
643 // erase newly scrolled-in lines
644 for (int i = count; i--; )
645 {
646 // basically this is a slightly optimized scr_blank_screen_mem
647 // it is worth the effort on slower machines
648 line_t &l = ROW(nrow - 1 - i);
649
650 scr_blank_line (l, 0, l.l, rstyle);
651
652 l.l = 0;
653 l.f = 0;
654 }
655
656 // now copy lines below the scroll region bottom to the
657 // bottom of the screen again, so they look as if they
658 // hadn't moved.
659 for (int i = nrow; --i > row2; )
660 {
661 line_t &l1 = ROW(i - count);
662 line_t &l2 = ROW(i);
663
664 ::swap (l1, l2);
665 l2.touch ();
666 }
627 667
628 term_start = (term_start + count) % total_rows; 668 // move and/or clear selection, if any
629
630 if (selection.op && current_screen == selection.screen) 669 if (selection.op && current_screen == selection.screen)
631 { 670 {
632 selection.beg.row -= count; 671 selection.beg.row -= count;
633 selection.end.row -= count; 672 selection.end.row -= count;
634 selection.mark.row -= count; 673 selection.mark.row -= count;
635 674
636 if (selection.beg.row < -nsaved 675 if (selection.beg.row < top_row
637 || selection.end.row < -nsaved 676 || selection.end.row < top_row
638 || selection.mark.row < -nsaved) 677 || selection.mark.row < top_row)
639 { 678 {
640 CLEAR_ALL_SELECTION (); 679 CLEAR_ALL_SELECTION ();
641 selection.op = SELECTION_CLEAR; 680 selection.op = SELECTION_CLEAR;
642 } 681 }
643 } 682 }
644 683
645 for (int i = count; i--; ) 684 // finally move the view window, if desired
646 scr_blank_screen_mem (ROW(row2 - i), rstyle);
647
648 if (OPTION (Opt_scrollWithBuffer) 685 if (OPTION (Opt_scrollWithBuffer)
649 && view_start != 0 686 && view_start != 0
650 && view_start != saveLines) 687 && view_start != -saveLines)
651 scr_page (UP, count); 688 scr_page (UP, count);
689
690 if (SHOULD_INVOKE (HOOK_SCROLL_BACK))
691 HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, top_row, DT_END));
652 } 692 }
653 else 693 else
654 { 694 {
655 if (selection.op && current_screen == selection.screen) 695 if (selection.op && current_screen == selection.screen)
656 { 696 {
680 720
681 int rows = row2 - row1 + 1; 721 int rows = row2 - row1 + 1;
682 722
683 min_it (count, rows); 723 min_it (count, rows);
684 724
725 line_t *temp_buf = row_buf + total_rows;
726
685 for (int row = 0; row < rows; row++) 727 for (int row = 0; row < rows; row++)
686 { 728 {
687 temp_buf [row] = ROW(row1 + (row + count + rows) % rows); 729 temp_buf [row] = ROW(row1 + (row + count + rows) % rows);
688 730
689 if (!IN_RANGE_EXC (row + count, 0, rows)) 731 if (!IN_RANGE_EXC (row + count, 0, rows))
700/* ------------------------------------------------------------------------- */ 742/* ------------------------------------------------------------------------- */
701/* 743/*
702 * Add text given in <str> of length <len> to screen struct 744 * Add text given in <str> of length <len> to screen struct
703 */ 745 */
704void 746void
705rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) 747rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) NOTHROW
706{ 748{
707 if (len <= 0) /* sanity */ 749 if (len <= 0) /* sanity */
708 return; 750 return;
709 751
710 unsigned char checksel; 752 unsigned char checksel;
716 ZERO_SCROLLBACK (); 758 ZERO_SCROLLBACK ();
717 759
718 if (minlines > 0) 760 if (minlines > 0)
719 { 761 {
720 minlines += screen.cur.row - screen.bscroll; 762 minlines += screen.cur.row - screen.bscroll;
763 min_it (minlines, screen.cur.row - top_row);
721 764
722 if (minlines > 0 765 if (minlines > 0
723 && screen.tscroll == 0 766 && screen.tscroll == 0
724 && screen.bscroll == nrow - 1) 767 && screen.bscroll == nrow - 1)
725 { 768 {
730 } 773 }
731 774
732#ifdef DEBUG_STRICT 775#ifdef DEBUG_STRICT
733 assert (screen.cur.col < ncol); 776 assert (screen.cur.col < ncol);
734 assert (screen.cur.row < nrow 777 assert (screen.cur.row < nrow
735 && screen.cur.row >= -nsaved); 778 && screen.cur.row >= top_row);
736#endif 779#endif
737 int row = screen.cur.row; 780 int row = screen.cur.row;
738 781
739 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 782 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
740 783
786 CLEAR_SELECTION (); 829 CLEAR_SELECTION ();
787 } 830 }
788 831
789 if (screen.flags & Screen_WrapNext) 832 if (screen.flags & Screen_WrapNext)
790 { 833 {
791 max_it (line->l, ncol);
792 line->is_longer (1);
793
794 scr_do_wrap (); 834 scr_do_wrap ();
795 835
836 line->l = ncol;
837 line->is_longer (1);
838
796 row = screen.cur.row; 839 row = screen.cur.row;
797 line = &ROW(row); /* _must_ refresh */ 840 line = &ROW(row); /* _must_ refresh */
798 } 841 }
799 842
800 // some utf-8 decoders "decode" surrogate characters: let's fix this. 843 // some utf-8 decoders "decode" surrogate characters: let's fix this.
801 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 844 if (IN_RANGE_INC (c, 0xd800, 0xdfff))
802 c = 0xfffd; 845 c = 0xfffd;
803 846
804 // rely on wcwidth to tell us the character width, at least for non-latin1 847 // rely on wcwidth to tell us the character width, do wcwidth before
805 // do wcwidth before further replacements, as wcwidth might return -1 848 // further replacements, as wcwidth might return -1 for the line
806 // for the line drawing characters below as they might be invalid in the current 849 // drawing characters below as they might be invalid in the current
807 // locale. 850 // locale.
808 int width = c < 0x100 ? 1 : wcwidth (c); 851 int width = WCWIDTH (c);
809 852
810 if (charsets [screen.charset] == '0') // DEC SPECIAL 853 if (charsets [screen.charset] == '0') // DEC SPECIAL
811 { 854 {
812 // vt100 special graphics and line drawing 855 // vt100 special graphics and line drawing
813 // 5f-7e standard vt100 856 // 5f-7e standard vt100
964/* 1007/*
965 * Process Backspace. Move back the cursor back a position, wrap if have to 1008 * Process Backspace. Move back the cursor back a position, wrap if have to
966 * XTERM_SEQ: CTRL-H 1009 * XTERM_SEQ: CTRL-H
967 */ 1010 */
968void 1011void
969rxvt_term::scr_backspace () 1012rxvt_term::scr_backspace () NOTHROW
970{ 1013{
971 want_refresh = 1; 1014 want_refresh = 1;
972 1015
973 if (screen.cur.col == 0) 1016 if (screen.cur.col == 0)
974 { 1017 {
992 * Process Horizontal Tab 1035 * Process Horizontal Tab
993 * count: +ve = forward; -ve = backwards 1036 * count: +ve = forward; -ve = backwards
994 * XTERM_SEQ: CTRL-I 1037 * XTERM_SEQ: CTRL-I
995 */ 1038 */
996void 1039void
997rxvt_term::scr_tab (int count, bool ht) 1040rxvt_term::scr_tab (int count, bool ht) NOTHROW
998{ 1041{
999 int i, x; 1042 int i, x;
1000 1043
1001 want_refresh = 1; 1044 want_refresh = 1;
1002 i = x = screen.cur.col; 1045 i = x = screen.cur.col;
1069 * Move cursor left in row. If we're at the left boundary, shift everything 1112 * Move cursor left in row. If we're at the left boundary, shift everything
1070 * in that row right. Clear left column. 1113 * in that row right. Clear left column.
1071 */ 1114 */
1072#if ENABLE_FRILLS 1115#if ENABLE_FRILLS
1073void 1116void
1074rxvt_term::scr_backindex () 1117rxvt_term::scr_backindex () NOTHROW
1075{ 1118{
1076 if (screen.cur.col > 0) 1119 if (screen.cur.col > 0)
1077 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE); 1120 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
1078 else 1121 else
1079 scr_insdel_chars (1, INSERT); 1122 scr_insdel_chars (1, INSERT);
1086 * Move cursor right in row. If we're at the right boundary, shift everything 1129 * Move cursor right in row. If we're at the right boundary, shift everything
1087 * in that row left. Clear right column. 1130 * in that row left. Clear right column.
1088 */ 1131 */
1089#if ENABLE_FRILLS 1132#if ENABLE_FRILLS
1090void 1133void
1091rxvt_term::scr_forwardindex () 1134rxvt_term::scr_forwardindex () NOTHROW
1092{ 1135{
1093 if (screen.cur.col < ncol - 1) 1136 if (screen.cur.col < ncol - 1)
1094 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1137 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1095 else 1138 else
1096 { 1139 {
1109/* ------------------------------------------------------------------------- */ 1152/* ------------------------------------------------------------------------- */
1110/* 1153/*
1111 * Goto Row/Column 1154 * Goto Row/Column
1112 */ 1155 */
1113void 1156void
1114rxvt_term::scr_gotorc (int row, int col, int relative) 1157rxvt_term::scr_gotorc (int row, int col, int relative) NOTHROW
1115{ 1158{
1116 want_refresh = 1; 1159 want_refresh = 1;
1117 ZERO_SCROLLBACK (); 1160 ZERO_SCROLLBACK ();
1118 1161
1119 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col; 1162 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col;
1157/* ------------------------------------------------------------------------- */ 1200/* ------------------------------------------------------------------------- */
1158/* 1201/*
1159 * direction should be UP or DN 1202 * direction should be UP or DN
1160 */ 1203 */
1161void 1204void
1162rxvt_term::scr_index (enum page_dirn direction) 1205rxvt_term::scr_index (enum page_dirn direction) NOTHROW
1163{ 1206{
1164 int dirn; 1207 int dirn;
1165 1208
1166 want_refresh = 1; 1209 want_refresh = 1;
1167 ZERO_SCROLLBACK (); 1210 ZERO_SCROLLBACK ();
1186 * XTERM_SEQ: Clear line to right: ESC [ 0 K 1229 * XTERM_SEQ: Clear line to right: ESC [ 0 K
1187 * XTERM_SEQ: Clear line to left : ESC [ 1 K 1230 * XTERM_SEQ: Clear line to left : ESC [ 1 K
1188 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1231 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1189 */ 1232 */
1190void 1233void
1191rxvt_term::scr_erase_line (int mode) 1234rxvt_term::scr_erase_line (int mode) NOTHROW
1192{ 1235{
1193 unsigned int col, num; 1236 unsigned int col, num;
1194 1237
1195 want_refresh = 1; 1238 want_refresh = 1;
1196 ZERO_SCROLLBACK (); 1239 ZERO_SCROLLBACK ();
1240 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J 1283 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J
1241 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J 1284 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J
1242 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1285 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1243 */ 1286 */
1244void 1287void
1245rxvt_term::scr_erase_screen (int mode) 1288rxvt_term::scr_erase_screen (int mode) NOTHROW
1246{ 1289{
1247 int num; 1290 int num;
1248 int32_t row; 1291 int32_t row;
1249 rend_t ren; 1292 rend_t ren;
1250 XGCValues gcvalue; 1293 XGCValues gcvalue;
1295 } 1338 }
1296 else 1339 else
1297 { 1340 {
1298 ren = rstyle & (RS_fgMask | RS_bgMask); 1341 ren = rstyle & (RS_fgMask | RS_bgMask);
1299 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1342 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1300 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1343 XChangeGC (xdisp, gc, GCForeground, &gcvalue);
1301 ERASE_ROWS (row, num); 1344 ERASE_ROWS (row, num);
1302 gcvalue.foreground = pix_colors[Color_fg]; 1345 gcvalue.foreground = pix_colors[Color_fg];
1303 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1346 XChangeGC (xdisp, gc, GCForeground, &gcvalue);
1304 } 1347 }
1305 1348
1306 for (; num--; row++) 1349 for (; num--; row++)
1307 { 1350 {
1308 scr_blank_screen_mem (ROW(row), rstyle); 1351 scr_blank_screen_mem (ROW(row), rstyle);
1310 } 1353 }
1311} 1354}
1312 1355
1313#if ENABLE_FRILLS 1356#if ENABLE_FRILLS
1314void 1357void
1315rxvt_term::scr_erase_savelines () 1358rxvt_term::scr_erase_savelines () NOTHROW
1316{ 1359{
1317 want_refresh = 1; 1360 want_refresh = 1;
1318 ZERO_SCROLLBACK (); 1361 ZERO_SCROLLBACK ();
1319 1362
1320 nsaved = 0; 1363 top_row = 0;
1321} 1364}
1322#endif 1365#endif
1323 1366
1324/* ------------------------------------------------------------------------- */ 1367/* ------------------------------------------------------------------------- */
1325/* 1368/*
1326 * Fill the screen with `E's 1369 * Fill the screen with `E's
1327 * XTERM_SEQ: Screen Alignment Test: ESC # 8 1370 * XTERM_SEQ: Screen Alignment Test: ESC # 8
1328 */ 1371 */
1329void 1372void
1330rxvt_term::scr_E () 1373rxvt_term::scr_E () NOTHROW
1331{ 1374{
1332 rend_t fs; 1375 rend_t fs;
1333 1376
1334 want_refresh = 1; 1377 want_refresh = 1;
1335 ZERO_SCROLLBACK (); 1378 ZERO_SCROLLBACK ();
1356/* ------------------------------------------------------------------------- */ 1399/* ------------------------------------------------------------------------- */
1357/* 1400/*
1358 * Insert/Delete <count> lines 1401 * Insert/Delete <count> lines
1359 */ 1402 */
1360void 1403void
1361rxvt_term::scr_insdel_lines (int count, int insdel) 1404rxvt_term::scr_insdel_lines (int count, int insdel) NOTHROW
1362{ 1405{
1363 int end; 1406 int end;
1364 1407
1365 ZERO_SCROLLBACK (); 1408 ZERO_SCROLLBACK ();
1366 1409
1386/* ------------------------------------------------------------------------- */ 1429/* ------------------------------------------------------------------------- */
1387/* 1430/*
1388 * Insert/Delete <count> characters from the current position 1431 * Insert/Delete <count> characters from the current position
1389 */ 1432 */
1390void 1433void
1391rxvt_term::scr_insdel_chars (int count, int insdel) 1434rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW
1392{ 1435{
1393 int col, row; 1436 int col, row;
1394 rend_t tr; 1437 rend_t tr;
1395 1438
1396 want_refresh = 1; 1439 want_refresh = 1;
1484/* 1527/*
1485 * Set the scrolling region 1528 * Set the scrolling region
1486 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r 1529 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r
1487 */ 1530 */
1488void 1531void
1489rxvt_term::scr_scroll_region (int top, int bot) 1532rxvt_term::scr_scroll_region (int top, int bot) NOTHROW
1490{ 1533{
1491 max_it (top, 0); 1534 max_it (top, 0);
1492 min_it (bot, nrow - 1); 1535 min_it (bot, nrow - 1);
1493 1536
1494 if (top > bot) 1537 if (top > bot)
1504 * Make the cursor visible/invisible 1547 * Make the cursor visible/invisible
1505 * XTERM_SEQ: Make cursor visible : ESC [ ? 25 h 1548 * XTERM_SEQ: Make cursor visible : ESC [ ? 25 h
1506 * XTERM_SEQ: Make cursor invisible: ESC [ ? 25 l 1549 * XTERM_SEQ: Make cursor invisible: ESC [ ? 25 l
1507 */ 1550 */
1508void 1551void
1509rxvt_term::scr_cursor_visible (int mode) 1552rxvt_term::scr_cursor_visible (int mode) NOTHROW
1510{ 1553{
1511 want_refresh = 1; 1554 want_refresh = 1;
1512 1555
1513 if (mode) 1556 if (mode)
1514 screen.flags |= Screen_VisibleCursor; 1557 screen.flags |= Screen_VisibleCursor;
1521 * Set/unset automatic wrapping 1564 * Set/unset automatic wrapping
1522 * XTERM_SEQ: Set Wraparound : ESC [ ? 7 h 1565 * XTERM_SEQ: Set Wraparound : ESC [ ? 7 h
1523 * XTERM_SEQ: Unset Wraparound: ESC [ ? 7 l 1566 * XTERM_SEQ: Unset Wraparound: ESC [ ? 7 l
1524 */ 1567 */
1525void 1568void
1526rxvt_term::scr_autowrap (int mode) 1569rxvt_term::scr_autowrap (int mode) NOTHROW
1527{ 1570{
1528 if (mode) 1571 if (mode)
1529 screen.flags |= Screen_Autowrap; 1572 screen.flags |= Screen_Autowrap;
1530 else 1573 else
1531 screen.flags &= ~(Screen_Autowrap | Screen_WrapNext); 1574 screen.flags &= ~(Screen_Autowrap | Screen_WrapNext);
1540 * and the cursor cannot be moved outside. 1583 * and the cursor cannot be moved outside.
1541 * XTERM_SEQ: Set Absolute: ESC [ ? 6 h 1584 * XTERM_SEQ: Set Absolute: ESC [ ? 6 h
1542 * XTERM_SEQ: Set Relative: ESC [ ? 6 l 1585 * XTERM_SEQ: Set Relative: ESC [ ? 6 l
1543 */ 1586 */
1544void 1587void
1545rxvt_term::scr_relative_origin (int mode) 1588rxvt_term::scr_relative_origin (int mode) NOTHROW
1546{ 1589{
1547 if (mode) 1590 if (mode)
1548 screen.flags |= Screen_Relative; 1591 screen.flags |= Screen_Relative;
1549 else 1592 else
1550 screen.flags &= ~Screen_Relative; 1593 screen.flags &= ~Screen_Relative;
1557 * Set insert/replace mode 1600 * Set insert/replace mode
1558 * XTERM_SEQ: Set Insert mode : ESC [ ? 4 h 1601 * XTERM_SEQ: Set Insert mode : ESC [ ? 4 h
1559 * XTERM_SEQ: Set Replace mode: ESC [ ? 4 l 1602 * XTERM_SEQ: Set Replace mode: ESC [ ? 4 l
1560 */ 1603 */
1561void 1604void
1562rxvt_term::scr_insert_mode (int mode) 1605rxvt_term::scr_insert_mode (int mode) NOTHROW
1563{ 1606{
1564 if (mode) 1607 if (mode)
1565 screen.flags |= Screen_Insert; 1608 screen.flags |= Screen_Insert;
1566 else 1609 else
1567 screen.flags &= ~Screen_Insert; 1610 screen.flags &= ~Screen_Insert;
1573 * XTERM_SEQ: Set tab at current column : ESC H 1616 * XTERM_SEQ: Set tab at current column : ESC H
1574 * XTERM_SEQ: Clear tab at current column: ESC [ 0 g 1617 * XTERM_SEQ: Clear tab at current column: ESC [ 0 g
1575 * XTERM_SEQ: Clear all tabs : ESC [ 3 g 1618 * XTERM_SEQ: Clear all tabs : ESC [ 3 g
1576 */ 1619 */
1577void 1620void
1578rxvt_term::scr_set_tab (int mode) 1621rxvt_term::scr_set_tab (int mode) NOTHROW
1579{ 1622{
1580 if (mode < 0) 1623 if (mode < 0)
1581 memset (tabs, 0, ncol * sizeof (char)); 1624 memset (tabs, 0, ncol * sizeof (char));
1582 else if (screen.cur.col < ncol) 1625 else if (screen.cur.col < ncol)
1583 tabs [screen.cur.col] = !!mode; 1626 tabs [screen.cur.col] = !!mode;
1588 * Set reverse/normal video 1631 * Set reverse/normal video
1589 * XTERM_SEQ: Reverse video: ESC [ ? 5 h 1632 * XTERM_SEQ: Reverse video: ESC [ ? 5 h
1590 * XTERM_SEQ: Normal video : ESC [ ? 5 l 1633 * XTERM_SEQ: Normal video : ESC [ ? 5 l
1591 */ 1634 */
1592void 1635void
1593rxvt_term::scr_rvideo_mode (int mode) 1636rxvt_term::scr_rvideo_mode (bool on) NOTHROW
1594{ 1637{
1595 XGCValues gcvalue; 1638 rvideo_mode = on;
1596 1639
1640#ifndef NO_BELL
1641 on ^= rvideo_bell;
1642#endif
1643
1597 if (rvideo != mode) 1644 if (rvideo_state != on)
1598 { 1645 {
1599 rvideo = mode; 1646 rvideo_state = on;
1647
1600 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1648 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1601#if XPM_BACKGROUND 1649#if XPM_BACKGROUND
1602 if (bgPixmap.pixmap == None) 1650 if (bgPixmap.pixmap == None)
1603#endif 1651#endif
1604#if TRANSPARENT 1652#if TRANSPARENT
1605 if (! OPTION (Opt_transparent) || am_transparent == 0) 1653 if (!OPTION (Opt_transparent) || am_transparent == 0)
1606#endif 1654#endif
1607 XSetWindowBackground (display->display, vt, 1655 XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]);
1608 pix_colors[Color_bg]);
1609 1656
1657 XGCValues gcvalue;
1610 gcvalue.foreground = pix_colors[Color_fg]; 1658 gcvalue.foreground = pix_colors[Color_fg];
1611 gcvalue.background = pix_colors[Color_bg]; 1659 gcvalue.background = pix_colors[Color_bg];
1612 XChangeGC (display->display, gc, GCBackground | GCForeground, 1660 XChangeGC (xdisp, gc, GCBackground | GCForeground, &gcvalue);
1613 &gcvalue); 1661
1614 scr_clear (); 1662 scr_clear ();
1615 scr_touch (true); 1663 scr_touch (true);
1616 } 1664 }
1617} 1665}
1618 1666
1620/* 1668/*
1621 * Report current cursor position 1669 * Report current cursor position
1622 * XTERM_SEQ: Report position: ESC [ 6 n 1670 * XTERM_SEQ: Report position: ESC [ 6 n
1623 */ 1671 */
1624void 1672void
1625rxvt_term::scr_report_position () 1673rxvt_term::scr_report_position () NOTHROW
1626{ 1674{
1627 tt_printf ("\033[%d;%dR", screen.cur.row + 1, screen.cur.col + 1); 1675 tt_printf ("\033[%d;%dR", screen.cur.row + 1, screen.cur.col + 1);
1628} 1676}
1629 1677
1630/* ------------------------------------------------------------------------- * 1678/* ------------------------------------------------------------------------- *
1633 1681
1634/* 1682/*
1635 * Set font style 1683 * Set font style
1636 */ 1684 */
1637void 1685void
1638rxvt_term::set_font_style () 1686rxvt_term::set_font_style () NOTHROW
1639{ 1687{
1640#if 0 1688#if 0
1641 switch (charsets [screen.charset]) 1689 switch (charsets [screen.charset])
1642 { 1690 {
1643 case '0': /* DEC Special Character & Line Drawing Set */ 1691 case '0': /* DEC Special Character & Line Drawing Set */
1665 * XTERM_SEQ: Invoke G1 character set: CTRL-N 1713 * XTERM_SEQ: Invoke G1 character set: CTRL-N
1666 * XTERM_SEQ: Invoke G2 character set: ESC N 1714 * XTERM_SEQ: Invoke G2 character set: ESC N
1667 * XTERM_SEQ: Invoke G3 character set: ESC O 1715 * XTERM_SEQ: Invoke G3 character set: ESC O
1668 */ 1716 */
1669void 1717void
1670rxvt_term::scr_charset_choose (int set) 1718rxvt_term::scr_charset_choose (int set) NOTHROW
1671{ 1719{
1672 screen.charset = set; 1720 screen.charset = set;
1673 set_font_style (); 1721 set_font_style ();
1674} 1722}
1675 1723
1681 * XTERM_SEQ: Set G2 character set: ESC * <C> 1729 * XTERM_SEQ: Set G2 character set: ESC * <C>
1682 * XTERM_SEQ: Set G3 character set: ESC + <C> 1730 * XTERM_SEQ: Set G3 character set: ESC + <C>
1683 * See set_font_style for possible values for <C> 1731 * See set_font_style for possible values for <C>
1684 */ 1732 */
1685void 1733void
1686rxvt_term::scr_charset_set (int set, unsigned int ch) 1734rxvt_term::scr_charset_set (int set, unsigned int ch) NOTHROW
1687{ 1735{
1688 charsets[set] = (unsigned char)ch; 1736 charsets[set] = (unsigned char)ch;
1689 set_font_style (); 1737 set_font_style ();
1690} 1738}
1691 1739
1696 1744
1697/* 1745/*
1698 * refresh matching text. 1746 * refresh matching text.
1699 */ 1747 */
1700bool 1748bool
1701rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) 1749rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) NOTHROW
1702{ 1750{
1703 bool found = false; 1751 bool found = false;
1704 1752
1705 for (int i = 0; i < nrow; i++) 1753 for (int i = 0; i < nrow; i++)
1706 { 1754 {
1726 PART_END, 1774 PART_END,
1727 RC_COUNT 1775 RC_COUNT
1728}; 1776};
1729 1777
1730void 1778void
1731rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) 1779rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) NOTHROW
1732{ 1780{
1733 int i; 1781 int i;
1734 row_col_t rc[RC_COUNT]; 1782 row_col_t rc[RC_COUNT];
1735 1783
1736 if (!drawn_buf) /* sanity check */ 1784 if (!drawn_buf) /* sanity check */
1759 } 1807 }
1760 1808
1761 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1809 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1762 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); 1810 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1);
1763 1811
1812 num_scr_allow = 0;
1813
1764 if (refresh) 1814 if (refresh)
1765 scr_refresh (SLOW_REFRESH); 1815 scr_refresh ();
1766} 1816}
1767 1817
1768/* ------------------------------------------------------------------------- */ 1818/* ------------------------------------------------------------------------- */
1769/* 1819/*
1770 * Refresh the entire screen 1820 * Refresh the entire screen
1771 */ 1821 */
1772void 1822void
1773rxvt_term::scr_touch (bool refresh) 1823rxvt_term::scr_touch (bool refresh) NOTHROW
1774{ 1824{
1775 scr_expose (0, 0, width, height, refresh); 1825 scr_expose (0, 0, width, height, refresh);
1776} 1826}
1777 1827
1778/* ------------------------------------------------------------------------- */ 1828/* ------------------------------------------------------------------------- */
1779/* 1829/*
1780 * Move the display so that the line represented by scrollbar value Y is at 1830 * Move the display so that the line represented by scrollbar value Y is at
1781 * the top of the screen 1831 * the top of the screen
1782 */ 1832 */
1783int 1833void
1784rxvt_term::scr_move_to (int y, int len) 1834rxvt_term::scr_move_to (int y, int len) NOTHROW
1785{ 1835{
1786 long p = 0; 1836 scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1));
1787 unsigned int oldviewstart;
1788
1789 oldviewstart = view_start;
1790
1791 if (y < len)
1792 {
1793 p = (nrow + nsaved) * (len - y) / len;
1794 p -= (long) (nrow - 1);
1795 p = max (p, 0);
1796 }
1797
1798 view_start = (unsigned int)min (p, nsaved);
1799
1800 return scr_changeview (oldviewstart);
1801} 1837}
1802 1838
1803/* ------------------------------------------------------------------------- */ 1839/* ------------------------------------------------------------------------- */
1804/* 1840/*
1805 * Page the screen up/down nlines 1841 * Page the screen up/down nlines
1806 * direction should be UP or DN 1842 * direction should be UP or DN
1807 */ 1843 */
1808int 1844bool
1809rxvt_term::scr_page (enum page_dirn direction, int nlines) 1845rxvt_term::scr_page (enum page_dirn direction, int nlines) NOTHROW
1810{ 1846{
1811 int n; 1847 int new_view_start =
1812 unsigned int oldviewstart;
1813
1814 oldviewstart = view_start;
1815
1816 if (direction == UP)
1817 {
1818 n = view_start + nlines;
1819 view_start = min (n, nsaved);
1820 }
1821 else
1822 {
1823 n = view_start - nlines; 1848 direction == UP ? view_start - nlines
1824 view_start = max (n, 0); 1849 : view_start + nlines;
1825 }
1826 1850
1827 return scr_changeview (oldviewstart); 1851 return scr_changeview (new_view_start);
1828} 1852}
1829 1853
1830int 1854bool
1831rxvt_term::scr_changeview (unsigned int oldviewstart) 1855rxvt_term::scr_changeview (int new_view_start) NOTHROW
1832{ 1856{
1857 clamp_it (new_view_start, top_row, 0);
1858
1833 if (view_start != oldviewstart) 1859 if (new_view_start == view_start)
1834 { 1860 return false;
1861
1862 num_scr += new_view_start - view_start;
1863 view_start = new_view_start;
1864 want_refresh = 1;
1865
1835 HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END)); 1866 HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END));
1836 1867
1837 want_refresh = 1; 1868 return true;
1838 num_scr -= (view_start - oldviewstart);
1839 }
1840
1841 return (int)view_start - (int)oldviewstart;
1842} 1869}
1843 1870
1844/* ------------------------------------------------------------------------- */ 1871#ifndef NO_BELL
1845void 1872void
1873rxvt_term::bell_cb (time_watcher &w)
1874{
1875 rvideo_bell = false;
1876 scr_rvideo_mode (rvideo_mode);
1877}
1878#endif
1879
1880/* ------------------------------------------------------------------------- */
1881void
1846rxvt_term::scr_bell () 1882rxvt_term::scr_bell () NOTHROW
1847{ 1883{
1848#ifndef NO_BELL 1884#ifndef NO_BELL
1849 1885
1850# ifndef NO_MAPALERT 1886# ifndef NO_MAPALERT
1851# ifdef MAPALERT_OPTION 1887# ifdef MAPALERT_OPTION
1852 if (OPTION (Opt_mapAlert)) 1888 if (OPTION (Opt_mapAlert))
1853# endif 1889# endif
1854 XMapWindow (display->display, parent[0]); 1890 XMapWindow (xdisp, parent[0]);
1855# endif 1891# endif
1856 1892
1857 if (OPTION (Opt_visualBell)) 1893 if (OPTION (Opt_visualBell))
1858 { 1894 {
1859 scr_rvideo_mode (!rvideo); /* refresh also done */ 1895 rvideo_bell = true;
1860 rxvt_usleep (VISUAL_BELL_DURATION); 1896 scr_rvideo_mode (rvideo_mode);
1861 scr_rvideo_mode (!rvideo); /* refresh also done */ 1897 display->flush ();
1898
1899 bell_ev.start (NOW + VISUAL_BELL_DURATION);
1862 } 1900 }
1863 else 1901 else
1864 XBell (display->display, 0); 1902 XBell (xdisp, 0);
1865 1903
1866#endif 1904#endif
1867} 1905}
1868 1906
1869/* ------------------------------------------------------------------------- */ 1907/* ------------------------------------------------------------------------- */
1870/* ARGSUSED */ 1908/* ARGSUSED */
1871void 1909void
1872rxvt_term::scr_printscreen (int fullhist) 1910rxvt_term::scr_printscreen (int fullhist) NOTHROW
1873{ 1911{
1874#ifdef PRINTPIPE 1912#ifdef PRINTPIPE
1875 int nrows, row_start; 1913 int nrows, row_start;
1876 FILE *fd; 1914 FILE *fd;
1877 1915
1878 if ((fd = popen_printer ()) == NULL) 1916 if ((fd = popen_printer ()) == NULL)
1879 return; 1917 return;
1880 1918
1881 if (fullhist) 1919 if (fullhist)
1882 { 1920 {
1883 nrows = nrow + nsaved; 1921 nrows = nrow - top_row;
1884 row_start = -nsaved; 1922 row_start = top_row;
1885 } 1923 }
1886 else 1924 else
1887 { 1925 {
1888 nrows = nrow; 1926 nrows = nrow;
1889 row_start = -view_start; 1927 row_start = view_start;
1890 } 1928 }
1891 1929
1892 wctomb (0, 0); 1930 wctomb (0, 0);
1893 1931
1894 for (int r1 = 0; r1 < nrows; r1++) 1932 for (int r1 = 0; r1 < nrows; r1++)
1926 * Refresh the screen 1964 * Refresh the screen
1927 * drawn_text/drawn_rend contain the screen information before the update. 1965 * drawn_text/drawn_rend contain the screen information before the update.
1928 * screen.text/screen.rend contain what the screen will change to. 1966 * screen.text/screen.rend contain what the screen will change to.
1929 */ 1967 */
1930void 1968void
1931rxvt_term::scr_refresh (unsigned char refresh_type) 1969rxvt_term::scr_refresh () NOTHROW
1932{ 1970{
1933 unsigned char must_clear, /* use draw_string not draw_image_string */ 1971 unsigned char must_clear, /* use draw_string not draw_image_string */
1934 showcursor; /* show the cursor */ 1972 showcursor; /* show the cursor */
1935 int16_t col, row, /* column/row we're processing */ 1973 int16_t col, row, /* column/row we're processing */
1936 ocrow; /* old cursor row */ 1974 ocrow; /* old cursor row */
2022 2060
2023 /* make sure no outline cursor is left around */ 2061 /* make sure no outline cursor is left around */
2024 setoldcursor = 0; 2062 setoldcursor = 0;
2025 if (ocrow != -1) 2063 if (ocrow != -1)
2026 { 2064 {
2027 if (screen.cur.row + view_start != ocrow 2065 if (screen.cur.row - view_start != ocrow
2028 || screen.cur.col != oldcursor.col) 2066 || screen.cur.col != oldcursor.col)
2029 { 2067 {
2030 if (ocrow < nrow 2068 if (ocrow < nrow
2031 && oldcursor.col < ncol) 2069 && oldcursor.col < ncol)
2032 drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); 2070 drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline);
2040 else if (!focus) 2078 else if (!focus)
2041 setoldcursor = 1; 2079 setoldcursor = 1;
2042 2080
2043 if (setoldcursor) 2081 if (setoldcursor)
2044 { 2082 {
2045 if (screen.cur.row + view_start >= nrow) 2083 if (screen.cur.row - view_start >= nrow)
2046 oldcursor.row = -1; 2084 oldcursor.row = -1;
2047 else 2085 else
2048 { 2086 {
2049 oldcursor.row = screen.cur.row + view_start; 2087 oldcursor.row = screen.cur.row - view_start;
2050 oldcursor.col = screen.cur.col; 2088 oldcursor.col = screen.cur.col;
2051 } 2089 }
2052 } 2090 }
2053 } 2091 }
2054 2092
2060#ifndef NO_SLOW_LINK_SUPPORT 2098#ifndef NO_SLOW_LINK_SUPPORT
2061 /* 2099 /*
2062 * D: CopyArea pass - very useful for slower links 2100 * D: CopyArea pass - very useful for slower links
2063 * This has been deliberately kept simple. 2101 * This has been deliberately kept simple.
2064 */ 2102 */
2065 i = num_scr;
2066 if (!display->is_local 2103 if (!display->is_local
2067 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr 2104 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr
2068 && abs (num_scr) < nrow && !must_clear) 2105 && abs (num_scr) < nrow && !must_clear)
2069 { 2106 {
2070 int16_t nits; 2107 int16_t nits;
2071 int j; 2108 int j;
2072 int len, wlen; 2109 int len, wlen;
2110 dLocal (int, num_scr);
2073 2111
2074 j = nrow; 2112 j = nrow;
2075 wlen = len = -1; 2113 wlen = len = -1;
2076 row = i > 0 ? 0 : j - 1; 2114 row = i > 0 ? 0 : j - 1;
2077 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2115 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2078 { 2116 {
2079 if (row + i >= 0 && row + i < nrow && row + i != ocrow) 2117 if (row + i >= 0 && row + i < nrow && row + i != ocrow)
2080 { 2118 {
2081 line_t s = ROW(row - view_start); 2119 line_t s = ROW(view_start + row);
2082 line_t d = drawn_buf[row]; 2120 line_t d = drawn_buf[row];
2083 line_t d2 = drawn_buf[row + i]; 2121 line_t d2 = drawn_buf[row + i];
2084 2122
2085 for (nits = 0, col = ncol; col--; ) 2123 for (nits = 0, col = ncol; col--; )
2086 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col]) 2124 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col])
2108 { 2146 {
2109 /* also comes here at end if needed because of >= above */ 2147 /* also comes here at end if needed because of >= above */
2110 if (wlen < len) 2148 if (wlen < len)
2111 ::swap (wlen, len); 2149 ::swap (wlen, len);
2112 2150
2113 XCopyArea (display->display, vt, vt, 2151 XCopyArea (xdisp, vt, vt,
2114 gc, 0, Row2Pixel (len + i), 2152 gc, 0, Row2Pixel (len + i),
2115 (unsigned int)this->width, 2153 (unsigned int)this->width,
2116 (unsigned int)Height2Pixel (wlen - len + 1), 2154 (unsigned int)Height2Pixel (wlen - len + 1),
2117 0, Row2Pixel (len)); 2155 0, Row2Pixel (len));
2118 len = -1; 2156 len = -1;
2124 /* 2162 /*
2125 * E: main pass across every character 2163 * E: main pass across every character
2126 */ 2164 */
2127 for (row = 0; row < nrow; row++) 2165 for (row = 0; row < nrow; row++)
2128 { 2166 {
2129 text_t *stp = ROW(row - view_start).t; 2167 text_t *stp = ROW(view_start + row).t;
2130 rend_t *srp = ROW(row - view_start).r; 2168 rend_t *srp = ROW(view_start + row).r;
2131 text_t *dtp = drawn_buf[row].t; 2169 text_t *dtp = drawn_buf[row].t;
2132 rend_t *drp = drawn_buf[row].r; 2170 rend_t *drp = drawn_buf[row].r;
2133 2171
2134 /* 2172 /*
2135 * E2: OK, now the real pass 2173 * E2: OK, now the real pass
2206 2244
2207 // only do special processing if any attributes are set, which is unlikely 2245 // only do special processing if any attributes are set, which is unlikely
2208 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2246 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))
2209 { 2247 {
2210#if ENABLE_STYLES 2248#if ENABLE_STYLES
2211 // force redraw after "careful" characters to avoid pixel droppings 2249 // "careful" (too wide) character handling
2212 if (srp[col] & RS_Careful && col < ncol - 1 && 0)
2213 drp[col + 1] = ~srp[col + 1];
2214 2250
2215 // include previous careful character(s) if possible, looks nicer (best effort...) 2251 // include previous careful character(s) if possible, looks nicer (best effort...)
2216 while (text > stp 2252 while (text > stp
2217 && srp[text - stp - 1] & RS_Careful 2253 && srp[text - stp - 1] & RS_Careful
2218 && RS_SAME (rend, srp[text - stp - 1])) 2254 && RS_SAME (rend, srp[text - stp - 1]))
2219 text--, count++, xpixel -= fwidth; 2255 text--, count++, xpixel -= fwidth;
2256
2257 // force redraw after "careful" characters to avoid pixel droppings
2258 for (int i = 0; srp[col + i] & RS_Careful && col + i < ncol - 1; i++)
2259 drp[col + i + 1] = ~srp[col + i + 1];
2260
2261 // force redraw before "careful" characters to avoid pixel droppings
2262 for (int i = 0; srp[text - stp - i] & RS_Careful && text - i > stp; i++)
2263 drp[text - stp - i - 1] = ~srp[text - stp - i - 1];
2220#endif 2264#endif
2221 2265
2222 bool invert = rend & RS_RVid; 2266 bool invert = rend & RS_RVid;
2223 2267
2224#ifndef NO_BOLD_UNDERLINE_REVERSE 2268#ifndef NO_BOLD_UNDERLINE_REVERSE
2308 2352
2309 if (rend & RS_Uline && font->descent > 1 && fore != back) 2353 if (rend & RS_Uline && font->descent > 1 && fore != back)
2310 { 2354 {
2311#if ENABLE_FRILLS 2355#if ENABLE_FRILLS
2312 if (ISSET_PIXCOLOR (Color_underline)) 2356 if (ISSET_PIXCOLOR (Color_underline))
2313 XSetForeground (display->display, gc, pix_colors[Color_underline]); 2357 XSetForeground (xdisp, gc, pix_colors[Color_underline]);
2314 else 2358 else
2315#endif 2359#endif
2316 XSetForeground (display->display, gc, pix_colors[fore]); 2360 XSetForeground (xdisp, gc, pix_colors[fore]);
2317 2361
2318 XDrawLine (display->display, drawBuffer, gc, 2362 XDrawLine (xdisp, drawBuffer, gc,
2319 xpixel, ypixel + font->ascent + 1, 2363 xpixel, ypixel + font->ascent + 1,
2320 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2364 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2321 } 2365 }
2322 } /* for (col....) */ 2366 } /* for (col....) */
2323 } /* for (row....) */ 2367 } /* for (row....) */
2356 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR) 2400 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2357 cursorwidth++; 2401 cursorwidth++;
2358 2402
2359#ifndef NO_CURSORCOLOR 2403#ifndef NO_CURSORCOLOR
2360 if (ISSET_PIXCOLOR (Color_cursor)) 2404 if (ISSET_PIXCOLOR (Color_cursor))
2361 XSetForeground (display->display, gc, pix_colors[Color_cursor]); 2405 XSetForeground (xdisp, gc, pix_colors[Color_cursor]);
2362#endif 2406#endif
2363 2407
2364 XDrawRectangle (display->display, drawBuffer, gc, 2408 XDrawRectangle (xdisp, drawBuffer, gc,
2365 Col2Pixel (col), 2409 Col2Pixel (col),
2366 Row2Pixel (oldcursor.row), 2410 Row2Pixel (oldcursor.row),
2367 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2411 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2368 (unsigned int) (Height2Pixel (1) - lineSpace - 1)); 2412 (unsigned int) (Height2Pixel (1) - lineSpace - 1));
2369 } 2413 }
2372 /* 2416 /*
2373 * H: cleanup selection 2417 * H: cleanup selection
2374 */ 2418 */
2375 scr_reverse_selection (); 2419 scr_reverse_selection ();
2376 2420
2377 if (refresh_type & SMOOTH_REFRESH)
2378 XFlush (display->display);
2379
2380 num_scr = 0; 2421 num_scr = 0;
2381 num_scr_allow = 1; 2422 num_scr_allow = 1;
2382} 2423}
2383 2424
2384void 2425void
2385rxvt_term::scr_remap_chars (line_t &l) 2426rxvt_term::scr_remap_chars (line_t &l) NOTHROW
2386{ 2427{
2387 if (!l.t) 2428 if (!l.t)
2388 return; 2429 return;
2389 2430
2390 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant 2431 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant
2392 for (int i = ncol; i--; ) 2433 for (int i = ncol; i--; )
2393 l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i])); 2434 l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i]));
2394} 2435}
2395 2436
2396void 2437void
2397rxvt_term::scr_remap_chars () 2438rxvt_term::scr_remap_chars () NOTHROW
2398{ 2439{
2399 for (int i = total_rows; i--; ) 2440 for (int i = total_rows; i--; )
2400 scr_remap_chars (row_buf [i]); 2441 scr_remap_chars (row_buf [i]);
2401 2442
2402 for (int i = nrow; i--; ) 2443 for (int i = nrow; i--; )
2405 scr_remap_chars (swap_buf [i]); 2446 scr_remap_chars (swap_buf [i]);
2406 } 2447 }
2407} 2448}
2408 2449
2409void 2450void
2410rxvt_term::scr_recolour () 2451rxvt_term::scr_recolour () NOTHROW
2411{ 2452{
2412 if (1 2453 if (1
2413#if TRANSPARENT 2454#if TRANSPARENT
2414 && !am_transparent 2455 && !am_transparent
2415#endif 2456#endif
2416#if XPM_BACKGROUND 2457#if XPM_BACKGROUND
2417 && !bgPixmap.pixmap 2458 && !bgPixmap.pixmap
2418#endif 2459#endif
2419 ) 2460 )
2420 { 2461 {
2421 XSetWindowBackground (display->display, parent[0], pix_colors[Color_border]); 2462 XSetWindowBackground (xdisp, parent[0], pix_colors[Color_border]);
2422 XClearWindow (display->display, parent[0]); 2463 XClearWindow (xdisp, parent[0]);
2423 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); 2464 XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]);
2424#if HAVE_SCROLLBARS 2465#if HAVE_SCROLLBARS
2425 if (scrollBar.win) 2466 if (scrollBar.win)
2426 { 2467 {
2427 XSetWindowBackground (display->display, scrollBar.win, pix_colors[Color_border]); 2468 XSetWindowBackground (xdisp, scrollBar.win, pix_colors[Color_border]);
2428 scrollBar.setIdle (); 2469 scrollBar.setIdle ();
2429 scrollbar_show (0); 2470 scrollbar_show (0);
2430 } 2471 }
2431#endif 2472#endif
2432 } 2473 }
2436 want_refresh = 1; 2477 want_refresh = 1;
2437} 2478}
2438 2479
2439/* ------------------------------------------------------------------------- */ 2480/* ------------------------------------------------------------------------- */
2440void 2481void
2441rxvt_term::scr_clear (bool really) 2482rxvt_term::scr_clear (bool really) NOTHROW
2442{ 2483{
2443 if (!mapped) 2484 if (!mapped)
2444 return; 2485 return;
2445 2486
2446 num_scr_allow = 0; 2487 num_scr_allow = 0;
2447 want_refresh = 1; 2488 want_refresh = 1;
2448 2489
2449 if (really) 2490 if (really)
2450 XClearWindow (display->display, vt); 2491 XClearWindow (xdisp, vt);
2451} 2492}
2452 2493
2453/* ------------------------------------------------------------------------- */
2454void 2494void
2495rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) NOTHROW
2496{
2497 int view_end = view_start + nrow;
2498 int row, col;
2499
2500 for (row = max (beg_row, view_start); row <= min (end_row, view_end); row++)
2501 {
2502 text_t *stp = ROW(row).t;
2503 rend_t *srp = ROW(row).r;
2504
2505 for (col = beg_col; col < end_col; col++)
2506 srp[col] ^= rstyle1;
2507
2508 while (col-- > beg_col && (stp[col] == NOCHAR || unicode::is_space (stp[col])))
2509 srp[col] ^= rstyle2;
2510
2511 if (++col < end_col)
2512 srp[col] ^= rstyle2;
2513 }
2514}
2515
2516void
2517rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle) NOTHROW
2518{
2519 int view_end = view_start + nrow;
2520 int row, col;
2521
2522 if (beg_row >= view_start)
2523 {
2524 col = beg_col;
2525 row = beg_row;
2526 }
2527 else
2528 {
2529 col = 0;
2530 row = view_start;
2531 }
2532
2533 for (; row < min (end_row, view_end); row++, col = 0)
2534 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2535 srp[col] ^= rstyle;
2536
2537 if (row == end_row)
2538 for (rend_t *srp = ROW(row).r; col < end_col; col++)
2539 srp[col] ^= rstyle;
2540}
2541
2542/* ------------------------------------------------------------------------- */
2543void
2455rxvt_term::scr_reverse_selection () 2544rxvt_term::scr_reverse_selection () NOTHROW
2456{ 2545{
2457 if (selection.op 2546 if (selection.op
2458 && current_screen == selection.screen 2547 && current_screen == selection.screen
2459 && selection.end.row >= -view_start) 2548 && selection.end.row >= view_start)
2460 { 2549 {
2461 int view_end = -view_start + nrow;
2462 int row, col;
2463
2464#if ENABLE_FRILLS 2550#if ENABLE_FRILLS
2465 if (selection.rect) 2551 if (selection.rect)
2466 { 2552 scr_xor_rect (selection.beg.row, selection.beg.col,
2467 for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++) 2553 selection.end.row, selection.end.col,
2468 { 2554 RS_RVid, RS_RVid | RS_Uline);
2469 text_t *stp = ROW(row).t;
2470 rend_t *srp = ROW(row).r;
2471
2472 for (col = selection.beg.col; col < selection.end.col; col++)
2473 srp[col] ^= RS_RVid;
2474
2475 while (col-- > selection.beg.col && (stp[col] == NOCHAR || unicode::is_space (stp[col])))
2476 srp[col] ^= RS_RVid | RS_Uline;
2477
2478 if (++col < selection.end.col)
2479 srp[col] ^= RS_RVid | RS_Uline;
2480 }
2481 }
2482 else 2555 else
2483#endif 2556#endif
2484 { 2557 scr_xor_span (selection.beg.row, selection.beg.col,
2485 if (selection.beg.row >= -view_start) 2558 selection.end.row, selection.end.col,
2486 { 2559 RS_RVid);
2487 col = selection.beg.col;
2488 row = selection.beg.row;
2489 }
2490 else
2491 {
2492 col = 0;
2493 row = -view_start;
2494 }
2495
2496 for (; row < min (selection.end.row, view_end); row++, col = 0)
2497 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2498 srp[col] ^= RS_RVid;
2499
2500 if (row == selection.end.row)
2501 for (rend_t *srp = ROW(row).r; col < selection.end.col; col++)
2502 srp[col] ^= RS_RVid;
2503 }
2504 } 2560 }
2505} 2561}
2506 2562
2507/* ------------------------------------------------------------------------- */ 2563/* ------------------------------------------------------------------------- */
2508/* 2564/*
2509 * Dump the whole scrollback and screen to the passed filedescriptor. The 2565 * Dump the whole scrollback and screen to the passed filedescriptor. The
2510 * invoking routine must close the fd. 2566 * invoking routine must close the fd.
2511 */ 2567 */
2512#if 0 2568#if 0
2513void 2569void
2514rxvt_term::scr_dump (int fd) 2570rxvt_term::scr_dump (int fd) NOTHROW
2515{ 2571{
2516 int row, wrote; 2572 int row, wrote;
2517 unsigned int width, towrite; 2573 unsigned int width, towrite;
2518 char r1[] = "\n"; 2574 char r1[] = "\n";
2519 2575
2538 2594
2539/* ------------------------------------------------------------------------- * 2595/* ------------------------------------------------------------------------- *
2540 * CHARACTER SELECTION * 2596 * CHARACTER SELECTION *
2541 * ------------------------------------------------------------------------- */ 2597 * ------------------------------------------------------------------------- */
2542void 2598void
2543rxvt_term::selection_check (int check_more) 2599rxvt_term::selection_check (int check_more) NOTHROW
2544{ 2600{
2545 row_col_t pos; 2601 row_col_t pos;
2546 2602
2547 if (!selection.op) 2603 if (!selection.op)
2548 return; 2604 return;
2549 2605
2550 pos.row = pos.col = 0; 2606 pos.row = pos.col = 0;
2551 if (!IN_RANGE_EXC (selection.beg.row, -nsaved, nrow) 2607 if (!IN_RANGE_EXC (selection.beg.row, top_row, nrow)
2552 || !IN_RANGE_EXC (selection.mark.row, -nsaved, nrow) 2608 || !IN_RANGE_EXC (selection.mark.row, top_row, nrow)
2553 || !IN_RANGE_EXC (selection.end.row, -nsaved, nrow) 2609 || !IN_RANGE_EXC (selection.end.row, top_row, nrow)
2554 || (check_more == 1 2610 || (check_more == 1
2555 && current_screen == selection.screen 2611 && current_screen == selection.screen
2556 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 2612 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
2557 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 2613 && ROWCOL_IS_BEFORE (screen.cur, selection.end))
2558 || (check_more == 2 2614 || (check_more == 2
2569/* ------------------------------------------------------------------------- */ 2625/* ------------------------------------------------------------------------- */
2570/* 2626/*
2571 * Paste a selection direct to the command fd 2627 * Paste a selection direct to the command fd
2572 */ 2628 */
2573void 2629void
2574rxvt_term::paste (char *data, unsigned int len) 2630rxvt_term::paste (char *data, unsigned int len) NOTHROW
2575{ 2631{
2576 /* convert normal newline chars into common keyboard Return key sequence */ 2632 /* convert normal newline chars into common keyboard Return key sequence */
2577 for (unsigned int i = 0; i < len; i++) 2633 for (unsigned int i = 0; i < len; i++)
2578 if (data[i] == C0_LF) 2634 if (data[i] == C0_LF)
2579 data[i] = C0_CR; 2635 data[i] = C0_CR;
2585/* 2641/*
2586 * Respond to a notification that a primary selection has been sent 2642 * Respond to a notification that a primary selection has been sent
2587 * EXT: SelectionNotify 2643 * EXT: SelectionNotify
2588 */ 2644 */
2589void 2645void
2590rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) 2646rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) NOTHROW
2591{ 2647{
2592 if (prop == None) /* check for failed XConvertSelection */ 2648 if (prop == None) /* check for failed XConvertSelection */
2593 { 2649 {
2594 if ((selection_type & Sel_CompoundText)) 2650 if ((selection_type & Sel_CompoundText))
2595 { 2651 {
2615 } 2671 }
2616 2672
2617 unsigned long bytes_after; 2673 unsigned long bytes_after;
2618 XTextProperty ct; 2674 XTextProperty ct;
2619 2675
2620 if (XGetWindowProperty (display->display, win, prop, 2676 if (XGetWindowProperty (xdisp, win, prop,
2621 0, PROP_SIZE / 4, 2677 0, PROP_SIZE / 4,
2622 delete_prop, AnyPropertyType, 2678 delete_prop, AnyPropertyType,
2623 &ct.encoding, &ct.format, 2679 &ct.encoding, &ct.format,
2624 &ct.nitems, &bytes_after, 2680 &ct.nitems, &bytes_after,
2625 &ct.value) != Success) 2681 &ct.value) != Success)
2634 if (bytes_after) 2690 if (bytes_after)
2635 { 2691 {
2636 // fetch and append remaining data 2692 // fetch and append remaining data
2637 XTextProperty ct2; 2693 XTextProperty ct2;
2638 2694
2639 if (XGetWindowProperty (display->display, win, prop, 2695 if (XGetWindowProperty (xdisp, win, prop,
2640 ct.nitems / 4, (bytes_after + 3) / 4, 2696 ct.nitems / 4, (bytes_after + 3) / 4,
2641 delete_prop, AnyPropertyType, 2697 delete_prop, AnyPropertyType,
2642 &ct2.encoding, &ct2.format, 2698 &ct2.encoding, &ct2.format,
2643 &ct2.nitems, &bytes_after, 2699 &ct2.nitems, &bytes_after,
2644 &ct2.value) != Success) 2700 &ct2.value) != Success)
2657 2713
2658 if (ct.encoding == xa[XA_INCR]) 2714 if (ct.encoding == xa[XA_INCR])
2659 { 2715 {
2660 // INCR selection, start handshake 2716 // INCR selection, start handshake
2661 if (!delete_prop) 2717 if (!delete_prop)
2662 XDeleteProperty (display->display, win, prop); 2718 XDeleteProperty (xdisp, win, prop);
2663 2719
2664 selection_wait = Sel_incr; 2720 selection_wait = Sel_incr;
2665 incr_buf_fill = 0; 2721 incr_buf_fill = 0;
2666 incr_ev.start (NOW + 10); 2722 incr_ev.start (NOW + 10);
2667 2723
2728 paste (s, strlen (s)); 2784 paste (s, strlen (s));
2729 free (s); 2785 free (s);
2730 } 2786 }
2731 else 2787 else
2732#endif 2788#endif
2733 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 2789 if (XmbTextPropertyToTextList (xdisp, &ct, &cl, &cr) >= 0
2734 && cl) 2790 && cl)
2735 { 2791 {
2736 for (int i = 0; i < cr; i++) 2792 for (int i = 0; i < cr; i++)
2737 paste (cl[i], strlen (cl[i])); 2793 paste (cl[i], strlen (cl[i]));
2738 2794
2747 if (selection_wait == Sel_normal) 2803 if (selection_wait == Sel_normal)
2748 selection_wait = Sel_none; 2804 selection_wait = Sel_none;
2749} 2805}
2750 2806
2751void 2807void
2752rxvt_term::incr_cb (time_watcher &w) 2808rxvt_term::incr_cb (time_watcher &w) NOTHROW
2753{ 2809{
2754 selection_wait = Sel_none; 2810 selection_wait = Sel_none;
2755 2811
2756 incr_buf_size = 0; 2812 incr_buf_size = 0;
2757 free (incr_buf); 2813 free (incr_buf);
2758 2814
2759 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 2815 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2760} 2816}
2761 2817
2762void 2818void
2763rxvt_term::selection_property (Window win, Atom prop) 2819rxvt_term::selection_property (Window win, Atom prop) NOTHROW
2764{ 2820{
2765 if (prop == None || selection_wait != Sel_incr) 2821 if (prop == None || selection_wait != Sel_incr)
2766 return; 2822 return;
2767 2823
2768 selection_paste (win, prop, true); 2824 selection_paste (win, prop, true);
2777 * (+) if ownership is claimed but property is empty, rxvt_selection_paste () 2833 * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
2778 * will auto fallback to CUT_BUFFER0 2834 * will auto fallback to CUT_BUFFER0
2779 * EXT: button 2 release 2835 * EXT: button 2 release
2780 */ 2836 */
2781void 2837void
2782rxvt_term::selection_request (Time tm, int x, int y) 2838rxvt_term::selection_request (Time tm, int selnum) NOTHROW
2783{ 2839{
2784 if (x < 0 || x >= width || y < 0 || y >= height) 2840 if (selection.text && selnum == Sel_Primary)
2785 return; /* outside window */
2786
2787 if (selection.text)
2788 { /* internal selection */ 2841 { /* internal selection */
2789 char *str = rxvt_wcstombs (selection.text, selection.len); 2842 char *str = rxvt_wcstombs (selection.text, selection.len);
2790 paste (str, strlen (str)); 2843 paste (str, strlen (str));
2791 free (str); 2844 free (str);
2792 return; 2845 return;
2793 } 2846 }
2794 else 2847 else
2795 { 2848 {
2796 int i;
2797
2798 selection_request_time = tm; 2849 selection_request_time = tm;
2799 selection_wait = Sel_normal; 2850 selection_wait = Sel_normal;
2800 2851
2801 for (i = Sel_Primary; i <= Sel_Clipboard; i++)
2802 {
2803#if X_HAVE_UTF8_STRING 2852#if X_HAVE_UTF8_STRING
2804 selection_type = Sel_UTF8String; 2853 selection_type = Sel_UTF8String;
2805 if (selection_request_other (xa[XA_UTF8_STRING], i)) 2854 if (selection_request_other (xa[XA_UTF8_STRING], selnum))
2806 return; 2855 return;
2807#else 2856#else
2808 selection_type = Sel_CompoundText; 2857 selection_type = Sel_CompoundText;
2809 if (selection_request_other (xa[XA_COMPOUND_TEXT], i)) 2858 if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum))
2810 return; 2859 return;
2811#endif 2860#endif
2812 }
2813 } 2861 }
2814 2862
2815 selection_wait = Sel_none; /* don't loop in selection_paste () */ 2863 selection_wait = Sel_none; /* don't loop in selection_paste () */
2816 selection_paste (display->root, XA_CUT_BUFFER0, false); 2864 selection_paste (display->root, XA_CUT_BUFFER0, false);
2817} 2865}
2818 2866
2819int 2867int
2820rxvt_term::selection_request_other (Atom target, int selnum) 2868rxvt_term::selection_request_other (Atom target, int selnum) NOTHROW
2821{ 2869{
2822 Atom sel; 2870 Atom sel;
2823 2871
2824 selection_type |= selnum; 2872 selection_type |= selnum;
2825 2873
2828 else if (selnum == Sel_Secondary) 2876 else if (selnum == Sel_Secondary)
2829 sel = XA_SECONDARY; 2877 sel = XA_SECONDARY;
2830 else 2878 else
2831 sel = xa[XA_CLIPBOARD]; 2879 sel = xa[XA_CLIPBOARD];
2832 2880
2833 if (XGetSelectionOwner (display->display, sel) != None) 2881 if (XGetSelectionOwner (xdisp, sel) != None)
2834 { 2882 {
2835 XConvertSelection (display->display, sel, target, xa[XA_VT_SELECTION], 2883 XConvertSelection (xdisp, sel, target, xa[XA_VT_SELECTION],
2836 vt, selection_request_time); 2884 vt, selection_request_time);
2837 return 1; 2885 return 1;
2838 } 2886 }
2839 2887
2840 return 0; 2888 return 0;
2844/* 2892/*
2845 * Clear all selected text 2893 * Clear all selected text
2846 * EXT: SelectionClear 2894 * EXT: SelectionClear
2847 */ 2895 */
2848void 2896void
2849rxvt_term::selection_clear () 2897rxvt_term::selection_clear () NOTHROW
2850{ 2898{
2851 want_refresh = 1; 2899 want_refresh = 1;
2852 free (selection.text); 2900 free (selection.text);
2853 selection.text = NULL; 2901 selection.text = NULL;
2854 selection.len = 0; 2902 selection.len = 0;
2989 3037
2990 selection_grab (tm); 3038 selection_grab (tm);
2991} 3039}
2992 3040
2993bool 3041bool
2994rxvt_term::selection_grab (Time tm) 3042rxvt_term::selection_grab (Time tm) NOTHROW
2995{ 3043{
2996 selection_time = tm; 3044 selection_time = tm;
2997 3045
2998 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); 3046 XSetSelectionOwner (xdisp, XA_PRIMARY, vt, tm);
2999 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) 3047 if (XGetSelectionOwner (xdisp, XA_PRIMARY) == vt)
3000 { 3048 {
3001 display->set_selection_owner (this); 3049 display->set_selection_owner (this);
3002 return true; 3050 return true;
3003 } 3051 }
3004 else 3052 else
3053 {
3054 selection_clear ();
3005 return false; 3055 return false;
3056 }
3006 3057
3007#if 0 3058#if 0
3008 XTextProperty ct; 3059 XTextProperty ct;
3009 3060
3010 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3061 if (XwcTextListToTextProperty (xdisp, &selection.text, 1, XStringStyle, &ct) >= 0)
3011 { 3062 {
3012 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); 3063 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
3013 XFree (ct.value); 3064 XFree (ct.value);
3014 } 3065 }
3015#endif 3066#endif
3019/* 3070/*
3020 * Mark or select text based upon number of clicks: 1, 2, or 3 3071 * Mark or select text based upon number of clicks: 1, 2, or 3
3021 * EXT: button 1 press 3072 * EXT: button 1 press
3022 */ 3073 */
3023void 3074void
3024rxvt_term::selection_click (int clicks, int x, int y) 3075rxvt_term::selection_click (int clicks, int x, int y) NOTHROW
3025{ 3076{
3026 clicks = ((clicks - 1) % 3) + 1; 3077 clicks = ((clicks - 1) % 3) + 1;
3027 selection.clicks = clicks; /* save clicks so extend will work */ 3078 selection.clicks = clicks; /* save clicks so extend will work */
3028 3079
3080 if (clicks == 2 && !selection.rect
3081 && HOOK_INVOKE ((this, HOOK_SEL_EXTEND, DT_END)))
3082 {
3083 MEvent.clicks = 1; // what a mess
3084 selection.screen = current_screen;
3085 selection.op = SELECTION_CONT;
3086 return;
3087 }
3088
3029 selection_start_colrow (Pixel2Col (x), Pixel2Row (y)); 3089 selection_start_colrow (Pixel2Col (x), Pixel2Row (y));
3030 3090
3031 if (clicks == 2 || clicks == 3) 3091 if (clicks == 2 || clicks == 3)
3032 selection_extend_colrow (selection.mark.col, 3092 selection_extend_colrow (selection.mark.col,
3033 selection.mark.row + view_start, 3093 selection.mark.row - view_start,
3034 0, /* button 3 */ 3094 0, /* button 3 */
3035 1, /* button press */ 3095 1, /* button press */
3036 0); /* click change */ 3096 0); /* click change */
3037} 3097}
3038 3098
3039/* ------------------------------------------------------------------------- */ 3099/* ------------------------------------------------------------------------- */
3040/* 3100/*
3041 * Mark a selection at the specified col/row 3101 * Mark a selection at the specified col/row
3042 */ 3102 */
3043void 3103void
3044rxvt_term::selection_start_colrow (int col, int row) 3104rxvt_term::selection_start_colrow (int col, int row) NOTHROW
3045{ 3105{
3046 want_refresh = 1; 3106 want_refresh = 1;
3047 3107
3048 selection.mark.row = row - view_start; 3108 selection.mark.row = row + view_start;
3049 selection.mark.col = col; 3109 selection.mark.col = col;
3050 3110
3051 selection.mark.row = clamp (selection.mark.row, -nsaved, nrow - 1); 3111 selection.mark.row = clamp (selection.mark.row, top_row, nrow - 1);
3052 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); 3112 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1);
3053 3113
3054 while (selection.mark.col > 0 3114 while (selection.mark.col > 0
3055 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) 3115 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3056 --selection.mark.col; 3116 --selection.mark.col;
3075#define DELIMIT_TEXT(x) \ 3135#define DELIMIT_TEXT(x) \
3076 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x))) 3136 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x)))
3077#define DELIMIT_REND(x) 1 3137#define DELIMIT_REND(x) 1
3078 3138
3079void 3139void
3080rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) 3140rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) NOTHROW
3081{ 3141{
3082 int col, row, dirnadd, tcol, trow, w1, w2; 3142 int col, row, dirnadd, tcol, trow, w1, w2;
3083 row_col_t bound; 3143 row_col_t bound;
3084 text_t *stp; 3144 text_t *stp;
3085 rend_t *srp; 3145 rend_t *srp;
3086 3146
3087 if (dirn == UP) 3147 if (dirn == UP)
3088 { 3148 {
3089 bound.row = - nsaved - 1; 3149 bound.row = top_row - 1;
3090 bound.col = 0; 3150 bound.col = 0;
3091 dirnadd = -1; 3151 dirnadd = -1;
3092 } 3152 }
3093 else 3153 else
3094 { 3154 {
3159 * flag == 0 ==> button 1 3219 * flag == 0 ==> button 1
3160 * flag == 1 ==> button 3 press 3220 * flag == 1 ==> button 3 press
3161 * flag == 2 ==> button 3 motion 3221 * flag == 2 ==> button 3 motion
3162 */ 3222 */
3163void 3223void
3164rxvt_term::selection_extend (int x, int y, int flag) 3224rxvt_term::selection_extend (int x, int y, int flag) NOTHROW
3165{ 3225{
3166 int col = clamp (Pixel2Col (x), 0, ncol); 3226 int col = clamp (Pixel2Col (x), 0, ncol);
3167 int row = clamp (Pixel2Row (y), 0, nrow - 1); 3227 int row = clamp (Pixel2Row (y), 0, nrow - 1);
3168 3228
3169 /* 3229 /*
3172 * select nothing. Otherwise, if we're to the right of the mark, you have to 3232 * select nothing. Otherwise, if we're to the right of the mark, you have to
3173 * be _past_ a character for it to be selected. 3233 * be _past_ a character for it to be selected.
3174 */ 3234 */
3175 if (((selection.clicks % 3) == 1) && !flag 3235 if (((selection.clicks % 3) == 1) && !flag
3176 && (col == selection.mark.col 3236 && (col == selection.mark.col
3177 && (row == selection.mark.row + view_start))) 3237 && (row == selection.mark.row - view_start)))
3178 { 3238 {
3179 /* select nothing */ 3239 /* select nothing */
3180 selection.beg.row = selection.end.row = 0; 3240 selection.beg.row = selection.end.row = 0;
3181 selection.beg.col = selection.end.col = 0; 3241 selection.beg.col = selection.end.col = 0;
3182 selection.clicks = 4; 3242 selection.clicks = 4;
3195/* ------------------------------------------------------------------------- */ 3255/* ------------------------------------------------------------------------- */
3196/* 3256/*
3197 * Extend the selection to the specified col/row 3257 * Extend the selection to the specified col/row
3198 */ 3258 */
3199void 3259void
3200rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) 3260rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) NOTHROW
3201{ 3261{
3202 row_col_t pos; 3262 row_col_t pos;
3203 enum { 3263 enum {
3204 LEFT, RIGHT 3264 LEFT, RIGHT
3205 } closeto = RIGHT; 3265 } closeto = RIGHT;
3237 selection.beg.col = selection.end.col = selection.mark.col; 3297 selection.beg.col = selection.end.col = selection.mark.col;
3238 selection.beg.row = selection.end.row = selection.mark.row; 3298 selection.beg.row = selection.end.row = selection.mark.row;
3239 } 3299 }
3240 3300
3241 pos.col = col; 3301 pos.col = col;
3242 pos.row = row - view_start; 3302 pos.row = view_start + row;
3243 3303
3244 /* 3304 /*
3245 * This is mainly xterm style selection with a couple of differences, mainly 3305 * This is mainly xterm style selection with a couple of differences, mainly
3246 * in the way button3 drag extension works. 3306 * in the way button3 drag extension works.
3247 * We're either doing: button1 drag; button3 press; or button3 drag 3307 * We're either doing: button1 drag; button3 press; or button3 drag
3328 else if (selection.clicks == 2) 3388 else if (selection.clicks == 2)
3329 { 3389 {
3330 if (ROWCOL_IS_AFTER (selection.end, selection.beg)) 3390 if (ROWCOL_IS_AFTER (selection.end, selection.beg))
3331 selection.end.col--; 3391 selection.end.col--;
3332 3392
3333 if (!HOOK_INVOKE ((this, HOOK_SEL_EXTEND, DT_END)))
3334 {
3335 selection_delimit_word (UP, &selection.beg, &selection.beg); 3393 selection_delimit_word (UP, &selection.beg, &selection.beg);
3336 selection_delimit_word (DN, &selection.end, &selection.end); 3394 selection_delimit_word (DN, &selection.end, &selection.end);
3337 }
3338 } 3395 }
3339 else if (selection.clicks == 3) 3396 else if (selection.clicks == 3)
3340 { 3397 {
3341#if ENABLE_FRILLS 3398#if ENABLE_FRILLS
3342 if (OPTION (Opt_tripleclickwords)) 3399 if (OPTION (Opt_tripleclickwords))
3394#endif 3451#endif
3395} 3452}
3396 3453
3397#if ENABLE_FRILLS 3454#if ENABLE_FRILLS
3398void 3455void
3399rxvt_term::selection_remove_trailing_spaces () 3456rxvt_term::selection_remove_trailing_spaces () NOTHROW
3400{ 3457{
3401 int32_t end_col, end_row; 3458 int32_t end_col, end_row;
3402 text_t *stp; 3459 text_t *stp;
3403 3460
3404 end_col = selection.end.col; 3461 end_col = selection.end.col;
3442/* 3499/*
3443 * Double click on button 3 when already selected 3500 * Double click on button 3 when already selected
3444 * EXT: button 3 double click 3501 * EXT: button 3 double click
3445 */ 3502 */
3446void 3503void
3447rxvt_term::selection_rotate (int x, int y) 3504rxvt_term::selection_rotate (int x, int y) NOTHROW
3448{ 3505{
3449 selection.clicks = selection.clicks % 3 + 1; 3506 selection.clicks = selection.clicks % 3 + 1;
3450 selection_extend_colrow (Pixel2Col (x), Pixel2Row (y), 1, 0, 1); 3507 selection_extend_colrow (Pixel2Col (x), Pixel2Row (y), 1, 0, 1);
3451} 3508}
3452 3509
3454/* 3511/*
3455 * Respond to a request for our current selection 3512 * Respond to a request for our current selection
3456 * EXT: SelectionRequest 3513 * EXT: SelectionRequest
3457 */ 3514 */
3458void 3515void
3459rxvt_term::selection_send (const XSelectionRequestEvent &rq) 3516rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW
3460{ 3517{
3461 XSelectionEvent ev; 3518 XSelectionEvent ev;
3462 dDisp;
3463 3519
3464 ev.type = SelectionNotify; 3520 ev.type = SelectionNotify;
3465 ev.property = None; 3521 ev.property = None;
3466 ev.display = rq.display; 3522 ev.display = rq.display;
3467 ev.requestor = rq.requestor; 3523 ev.requestor = rq.requestor;
3481 *target++ = xa[XA_COMPOUND_TEXT]; 3537 *target++ = xa[XA_COMPOUND_TEXT];
3482#if X_HAVE_UTF8_STRING 3538#if X_HAVE_UTF8_STRING
3483 *target++ = xa[XA_UTF8_STRING]; 3539 *target++ = xa[XA_UTF8_STRING];
3484#endif 3540#endif
3485 3541
3486 XChangeProperty (disp, rq.requestor, rq.property, XA_ATOM, 3542 XChangeProperty (xdisp, rq.requestor, rq.property, XA_ATOM,
3487 32, PropModeReplace, 3543 32, PropModeReplace,
3488 (unsigned char *)target_list, target - target_list); 3544 (unsigned char *)target_list, target - target_list);
3489 ev.property = rq.property; 3545 ev.property = rq.property;
3490 } 3546 }
3491#if TODO // TODO 3547#if TODO // TODO
3494 /* TODO: Handle MULTIPLE */ 3550 /* TODO: Handle MULTIPLE */
3495 } 3551 }
3496#endif 3552#endif
3497 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3553 else if (rq.target == xa[XA_TIMESTAMP] && selection.text)
3498 { 3554 {
3499 XChangeProperty (disp, rq.requestor, rq.property, rq.target, 3555 XChangeProperty (xdisp, rq.requestor, rq.property, rq.target,
3500 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3556 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3501 ev.property = rq.property; 3557 ev.property = rq.property;
3502 } 3558 }
3503 else if (rq.target == XA_STRING 3559 else if (rq.target == XA_STRING
3504 || rq.target == xa[XA_TEXT] 3560 || rq.target == xa[XA_TEXT]
3562 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen); 3618 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen);
3563 ct.nitems = strlen ((char *)ct.value); 3619 ct.nitems = strlen ((char *)ct.value);
3564 } 3620 }
3565 else 3621 else
3566#endif 3622#endif
3567 if (XwcTextListToTextProperty (disp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) 3623 if (XwcTextListToTextProperty (xdisp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0)
3568 freect = 1; 3624 freect = 1;
3569 else 3625 else
3570 { 3626 {
3571 /* if we failed to convert then send it raw */ 3627 /* if we failed to convert then send it raw */
3572 ct.value = (unsigned char *)cl; 3628 ct.value = (unsigned char *)cl;
3573 ct.nitems = selectlen; 3629 ct.nitems = selectlen;
3574 ct.encoding = target; 3630 ct.encoding = target;
3575 } 3631 }
3576 3632
3577 XChangeProperty (disp, rq.requestor, rq.property, 3633 XChangeProperty (xdisp, rq.requestor, rq.property,
3578 ct.encoding, 8, PropModeReplace, 3634 ct.encoding, 8, PropModeReplace,
3579 ct.value, (int)ct.nitems); 3635 ct.value, (int)ct.nitems);
3580 ev.property = rq.property; 3636 ev.property = rq.property;
3581 3637
3582 if (freect) 3638 if (freect)
3583 XFree (ct.value); 3639 XFree (ct.value);
3584 } 3640 }
3585 3641
3586 XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev); 3642 XSendEvent (xdisp, rq.requestor, False, 0L, (XEvent *)&ev);
3587} 3643}
3588 3644
3589/* ------------------------------------------------------------------------- * 3645/* ------------------------------------------------------------------------- *
3590 * MOUSE ROUTINES * 3646 * MOUSE ROUTINES *
3591 * ------------------------------------------------------------------------- */ 3647 * ------------------------------------------------------------------------- */
3592 3648
3593/* 3649/*
3594 * return col/row values corresponding to x/y pixel values 3650 * return col/row values corresponding to x/y pixel values
3595 */ 3651 */
3596void 3652void
3597rxvt_term::pixel_position (int *x, int *y) 3653rxvt_term::pixel_position (int *x, int *y) NOTHROW
3598{ 3654{
3599 *x = Pixel2Col (*x); 3655 *x = Pixel2Col (*x);
3600 /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */ 3656 /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */
3601 *y = Pixel2Row (*y); 3657 *y = Pixel2Row (*y);
3602 /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */ 3658 /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */
3603} 3659}
3604 3660
3605/* ------------------------------------------------------------------------- */ 3661/* ------------------------------------------------------------------------- */
3606#ifdef USE_XIM 3662#ifdef USE_XIM
3607void 3663void
3608rxvt_term::im_set_position (XPoint &pos) 3664rxvt_term::im_set_position (XPoint &pos) NOTHROW
3609{ 3665{
3610 XWindowAttributes xwa; 3666 XWindowAttributes xwa;
3611 3667
3612 XGetWindowAttributes (display->display, vt, &xwa); 3668 XGetWindowAttributes (xdisp, vt, &xwa);
3613 3669
3614 pos.x = xwa.x + Col2Pixel (screen.cur.col); 3670 pos.x = xwa.x + Col2Pixel (screen.cur.col);
3615 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase; 3671 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase;
3616} 3672}
3617#endif 3673#endif
3618 3674
3619#if ENABLE_OVERLAY 3675#if ENABLE_OVERLAY
3620void 3676void
3621rxvt_term::scr_overlay_new (int x, int y, int w, int h) 3677rxvt_term::scr_overlay_new (int x, int y, int w, int h) NOTHROW
3622{ 3678{
3623 if (nrow < 1 || ncol < 1) 3679 if (nrow < 1 || ncol < 1)
3624 return; 3680 return;
3625 3681
3626 want_refresh = 1; 3682 want_refresh = 1;
3671 *rp = r; 3727 *rp = r;
3672 } 3728 }
3673} 3729}
3674 3730
3675void 3731void
3676rxvt_term::scr_overlay_off () 3732rxvt_term::scr_overlay_off () NOTHROW
3677{ 3733{
3678 if (!ov_text) 3734 if (!ov_text)
3679 return; 3735 return;
3680 3736
3681 want_refresh = 1; 3737 want_refresh = 1;
3689 delete [] ov_text; ov_text = 0; 3745 delete [] ov_text; ov_text = 0;
3690 delete [] ov_rend; ov_rend = 0; 3746 delete [] ov_rend; ov_rend = 0;
3691} 3747}
3692 3748
3693void 3749void
3694rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) 3750rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW
3695{ 3751{
3696 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2) 3752 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2)
3697 return; 3753 return;
3698 3754
3699 x++, y++; 3755 x++, y++;
3701 ov_text[y][x] = text; 3757 ov_text[y][x] = text;
3702 ov_rend[y][x] = rend; 3758 ov_rend[y][x] = rend;
3703} 3759}
3704 3760
3705void 3761void
3706rxvt_term::scr_overlay_set (int x, int y, const char *s) 3762rxvt_term::scr_overlay_set (int x, int y, const char *s) NOTHROW
3707{ 3763{
3708 while (*s) 3764 while (*s)
3709 scr_overlay_set (x++, y, *s++); 3765 scr_overlay_set (x++, y, *s++);
3710} 3766}
3711 3767
3712void 3768void
3713rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) 3769rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) NOTHROW
3714{ 3770{
3715 while (*s) 3771 while (*s)
3716 { 3772 {
3717 text_t t = *s++; 3773 text_t t = *s++;
3718 int width = wcwidth (t); 3774 int width = WCWIDTH (t);
3719 3775
3720 while (width--) 3776 while (width--)
3721 { 3777 {
3722 scr_overlay_set (x++, y, t); 3778 scr_overlay_set (x++, y, t);
3723 t = NOCHAR; 3779 t = NOCHAR;
3724 } 3780 }
3725 } 3781 }
3726} 3782}
3727 3783
3728void 3784void
3729rxvt_term::scr_swap_overlay () 3785rxvt_term::scr_swap_overlay () NOTHROW
3730{ 3786{
3731 if (!ov_text) 3787 if (!ov_text)
3732 return; 3788 return;
3733 3789
3734 // swap screen mem with overlay 3790 // swap screen mem with overlay
3735 for (int y = ov_h; y--; ) 3791 for (int y = ov_h; y--; )
3736 { 3792 {
3737 text_t *t1 = ov_text[y]; 3793 text_t *t1 = ov_text[y];
3738 rend_t *r1 = ov_rend[y]; 3794 rend_t *r1 = ov_rend[y];
3739 3795
3740 text_t *t2 = ROW(y + ov_y - view_start).t + ov_x; 3796 text_t *t2 = ROW(y + ov_y + view_start).t + ov_x;
3741 rend_t *r2 = ROW(y + ov_y - view_start).r + ov_x; 3797 rend_t *r2 = ROW(y + ov_y + view_start).r + ov_x;
3742 3798
3743 for (int x = ov_w; x--; ) 3799 for (int x = ov_w; x--; )
3744 { 3800 {
3745 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3801 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3746 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); 3802 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