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.239 by root, Thu Jan 19 17:14:46 2006 UTC vs.
Revision 1.327 by root, Wed Nov 5 14:43:54 2008 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*---------------------------------------------------------------------------*
2 * File: screen.C 2 * File: screen.C
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * 4 *
5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> 5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com>
6 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
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#include "rxvtperl.h" /* NECESSARY */
30 30
31#include <X11/Xmd.h> /* get the typedef for CARD32 */
32
33#include <inttypes.h> 31#include <inttypes.h>
34 32
35#include "salloc.C" // HACK, should be a seperate compile! 33#include "salloc.C" // HACK, should be a seperate compile!
36 34
37inline void fill_text (text_t *start, text_t value, int len) 35static inline void fill_text (text_t *start, text_t value, int len)
38{ 36{
39 while (len--) 37 while (len--)
40 *start++ = value; 38 *start++ = value;
41} 39}
42 40
47 45
48/* ------------------------------------------------------------------------- * 46/* ------------------------------------------------------------------------- *
49 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 47 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
50 * ------------------------------------------------------------------------- */ 48 * ------------------------------------------------------------------------- */
51#define ZERO_SCROLLBACK() \ 49#define ZERO_SCROLLBACK() \
52 if (OPTION (Opt_scrollTtyOutput)) \ 50 if (option (Opt_scrollTtyOutput)) \
53 view_start = 0 51 view_start = 0
54#define CLEAR_SELECTION() \ 52#define CLEAR_SELECTION() \
55 selection.beg.row = selection.beg.col \ 53 selection.beg.row = selection.beg.col \
56 = selection.end.row = selection.end.col = 0 54 = selection.end.row = selection.end.col = 0
57#define CLEAR_ALL_SELECTION() \ 55#define CLEAR_ALL_SELECTION() \
85 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col) 83 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col)
86#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \ 84#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \
87 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col) 85 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col)
88 86
89/* 87/*
90 * CLEAR_ROWS : clear <num> rows starting from row <row>
91 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 88 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
92 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
93 */ 89 */
94#define drawBuffer vt
95
96#define CLEAR_ROWS(row, num) \
97 if (mapped) \
98 XClearArea (display->display, drawBuffer, 0, \
99 Row2Pixel (row), (unsigned int)width, \
100 (unsigned int)Height2Pixel (num), False)
101
102#define CLEAR_CHARS(x, y, num) \ 90#define CLEAR_CHARS(x, y, num) \
103 if (mapped) \ 91 if (mapped) \
104 XClearArea (display->display, drawBuffer, x, y, \ 92 XClearArea (dpy, vt, x, y, \
105 (unsigned int)Width2Pixel (num), \ 93 (unsigned int)Width2Pixel (num), \
106 (unsigned int)Height2Pixel (1), False) 94 (unsigned int)Height2Pixel (1), False)
107
108#define ERASE_ROWS(row, num) \
109 XFillRectangle (display->display, drawBuffer, gc, \
110 0, Row2Pixel (row), \
111 (unsigned int)width, \
112 (unsigned int)Height2Pixel (num))
113 95
114/* ------------------------------------------------------------------------- * 96/* ------------------------------------------------------------------------- *
115 * SCREEN `COMMON' ROUTINES * 97 * SCREEN `COMMON' ROUTINES *
116 * ------------------------------------------------------------------------- */ 98 * ------------------------------------------------------------------------- */
117 99
118/* Fill part/all of a line with blanks. */ 100/* Fill part/all of a line with blanks. */
119void 101void
120rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) const 102rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) const NOTHROW
121{ 103{
122 if (!l.t) 104 if (!l.t)
123 { 105 {
124 lalloc (l); 106 lalloc (l);
125 col = 0; 107 col = 0;
126 width = ncol; 108 width = ncol;
127 } 109 }
128 110
129 l.touch (); 111 l.touch ();
130 112
131 efs &= ~RS_baseattrMask; 113 efs &= ~RS_baseattrMask; // remove italic etc. fontstyles
132 efs = SET_FONT (efs, FONTSET (efs)->find_font (' ')); 114 efs = SET_FONT (efs, FONTSET (efs)->find_font (' '));
133 115
134 text_t *et = l.t + col; 116 text_t *et = l.t + col;
135 rend_t *er = l.r + col; 117 rend_t *er = l.r + col;
136 118
142} 124}
143 125
144/* ------------------------------------------------------------------------- */ 126/* ------------------------------------------------------------------------- */
145/* Fill a full line with blanks - make sure it is allocated first */ 127/* Fill a full line with blanks - make sure it is allocated first */
146void 128void
147rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) const 129rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) const NOTHROW
148{ 130{
149 scr_blank_line (l, 0, ncol, efs); 131 scr_blank_line (l, 0, ncol, efs);
150 132
151 l.l = 0; 133 l.l = 0;
152 l.f = 0; 134 l.f = 0;
135}
136
137// nuke a single wide character at the given column
138void
139rxvt_term::scr_kill_char (line_t &l, int col) const NOTHROW
140{
141 // find begin
142 while (col > 0 && l.t[col] == NOCHAR)
143 col--;
144
145 rend_t rend = l.r[col] & ~RS_baseattrMask;
146 rend = SET_FONT (rend, FONTSET (rend)->find_font (' '));
147
148 // found start, nuke
149 do {
150 l.t[col] = ' ';
151 l.r[col] = rend;
152 col++;
153 } while (col < ncol && l.t[col] == NOCHAR);
153} 154}
154 155
155/* ------------------------------------------------------------------------- * 156/* ------------------------------------------------------------------------- *
156 * SCREEN INITIALISATION * 157 * SCREEN INITIALISATION *
157 * ------------------------------------------------------------------------- */ 158 * ------------------------------------------------------------------------- */
158 159
159void 160void
160rxvt_term::scr_reset () 161rxvt_term::scr_reset ()
161{ 162{
162#if ENABLE_OVERLAY
163 scr_overlay_off ();
164#endif
165
166 view_start = 0; 163 view_start = 0;
167 num_scr = 0; 164 num_scr = 0;
168 165
169 if (ncol == 0) 166 if (ncol == 0)
170 ncol = 80; 167 ncol = 80;
174 171
175 if (ncol == prev_ncol && nrow == prev_nrow) 172 if (ncol == prev_ncol && nrow == prev_nrow)
176 return; 173 return;
177 174
178 // we need at least two lines for wrapping to work correctly 175 // we need at least two lines for wrapping to work correctly
179 if (nrow + saveLines < 2) 176 while (nrow + saveLines < 2)
180 { 177 {
181 //TODO//FIXME 178 //TODO//FIXME
182 saveLines++; 179 saveLines++;
183 prev_nrow--; 180 prev_nrow--;
184 top_row--; 181 top_row--;
195 if (!row_buf) 192 if (!row_buf)
196 { 193 {
197 /* 194 /*
198 * first time called so just malloc everything: don't rely on realloc 195 * first time called so just malloc everything: don't rely on realloc
199 */ 196 */
200 top_row = 0; /* no saved lines */ 197 top_row = 0;
201 term_start = 0; 198 term_start = 0;
202 199
203 talloc = new rxvt_salloc (ncol * sizeof (text_t)); 200 talloc = new rxvt_salloc (ncol * sizeof (text_t));
204 ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 201 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
205 202
234 selection.text = NULL; 231 selection.text = NULL;
235 selection.len = 0; 232 selection.len = 0;
236 selection.op = SELECTION_CLEAR; 233 selection.op = SELECTION_CLEAR;
237 selection.screen = PRIMARY; 234 selection.screen = PRIMARY;
238 selection.clicks = 0; 235 selection.clicks = 0;
239 CLEAR_ALL_SELECTION ();
240 rvideo = 0;
241 } 236 }
242 else 237 else
243 { 238 {
244 /* 239 /*
245 * add or delete rows as appropriate 240 * add or delete rows as appropriate
274 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 269 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
275 } 270 }
276 271
277 line_t *old_buf = row_buf; 272 line_t *old_buf = row_buf;
278 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t)); 273 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t));
279 274
280 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 275 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
281 int pend = MOD (term_start + top_row , prev_total_rows); 276 int pend = MOD (term_start + top_row , prev_total_rows);
282 int q = total_rows; // rewrapped row 277 int q = total_rows; // rewrapped row
283 278
284 if (top_row) 279 if (top_row)
285 { 280 {
286 // re-wrap lines, this is rather ugly, possibly because I am too dumb 281 // Re-wrap lines. This is rather ugly, possibly because I am too dumb
287 // to come up with a lean and mean algorithm. 282 // to come up with a lean and mean algorithm.
283 // TODO: maybe optimise when width didn't change
288 284
289 row_col_t ocur = screen.cur; 285 row_col_t ocur = screen.cur;
290 ocur.row = MOD (term_start + ocur.row, prev_total_rows); 286 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
291 287
292 do 288 do
328 int qcol = 0; 324 int qcol = 0;
329 325
330 // see below for cursor adjustment rationale 326 // see below for cursor adjustment rationale
331 if (p == ocur.row) 327 if (p == ocur.row)
332 screen.cur.row = q - (total_rows - nrow); 328 screen.cur.row = q - (total_rows - nrow);
333 329
334 // fill a single destination line 330 // fill a single destination line
335 while (lofs < llen && qcol < ncol) 331 while (lofs < llen && qcol < ncol)
336 { 332 {
337 int prow = lofs / prev_ncol; 333 int prow = lofs / prev_ncol;
338 int pcol = lofs % prev_ncol; 334 int pcol = lofs % prev_ncol;
348 344
349 line_t &pline = old_buf [prow]; 345 line_t &pline = old_buf [prow];
350 346
351 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 347 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
352 348
353 assert (len);
354 assert (pline.t);
355
356 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); 349 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
357 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); 350 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
358 351
359 lofs += len; 352 lofs += len;
360 qcol += len; 353 qcol += len;
367 } 360 }
368 while (p != pend && q > 0); 361 while (p != pend && q > 0);
369 362
370 term_start = total_rows - nrow; 363 term_start = total_rows - nrow;
371 top_row = q - term_start; 364 top_row = q - term_start;
372 365
373 // make sure all terminal lines exist 366 // make sure all terminal lines exist
374 while (top_row > 0) 367 while (top_row > 0)
375 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE); 368 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
376 } 369 }
377 else 370 else
378 { 371 {
379 // if no scrollback exists (yet), wing, instead of wrap 372 // if no scrollback exists (yet), wing, instead of wrap
380 373
381 for (int row = min (nrow, prev_nrow); row--; ) 374 for (int row = min (nrow, prev_nrow); row--; )
382 { 375 {
383 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; 376 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
384 line_t &qline = row_buf [row]; 377 line_t &qline = row_buf [row];
385 378
399 delete old_ta; 392 delete old_ta;
400 delete old_ra; 393 delete old_ra;
401 394
402 clamp_it (screen.cur.row, 0, nrow - 1); 395 clamp_it (screen.cur.row, 0, nrow - 1);
403 clamp_it (screen.cur.col, 0, ncol - 1); 396 clamp_it (screen.cur.col, 0, ncol - 1);
397 }
404 398
405 if (tabs)
406 free (tabs); 399 free (tabs);
407 } 400 tabs = (char *)rxvt_malloc (ncol);
401
402 for (int col = ncol; --col; )
403 tabs [col] = col % TABSIZE == 0;
404
405 CLEAR_ALL_SELECTION ();
408 406
409 prev_nrow = nrow; 407 prev_nrow = nrow;
410 prev_ncol = ncol; 408 prev_ncol = ncol;
411 409
412 tabs = (char *)rxvt_malloc (ncol * sizeof (char));
413
414 for (int col = ncol; col--; )
415 tabs [col] = col % TABSIZE == 0;
416
417 tt_winch (); 410 tt_winch ();
418 411
419 HOOK_INVOKE ((this, HOOK_RESET, DT_END)); 412 HOOK_INVOKE ((this, HOOK_RESET, DT_END));
420} 413}
421 414
422/* ------------------------------------------------------------------------- */ 415/* ------------------------------------------------------------------------- */
423/* 416/*
424 * Free everything. That way malloc debugging can find leakage. 417 * Free everything. That way malloc debugging can find leakage.
425 */ 418 */
426void 419void
427rxvt_term::scr_release () 420rxvt_term::scr_release () NOTHROW
428{ 421{
422 if (row_buf)
423 {
429 delete talloc; talloc = 0; 424 delete talloc; talloc = 0;
430 delete ralloc; ralloc = 0; 425 delete ralloc; ralloc = 0;
431 426
432 free (row_buf); 427 free (row_buf);
433 free (swap_buf); 428 free (swap_buf);
434 free (drawn_buf); 429 free (drawn_buf);
435 free (tabs);
436
437 row_buf = 0; // signal that we freed all the arrays 430 row_buf = 0; // signal that we freed all the arrays above
438}
439 431
432 free (tabs);
433 tabs = 0;
434 }
435}
436
440/* ------------------------------------------------------------------------- */ 437/* ------------------------------------------------------------------------- */
441/* 438/*
442 * Hard reset 439 * Hard/Soft reset
443 */ 440 */
444void 441void
445rxvt_term::scr_poweron () 442rxvt_term::scr_poweron ()
446{ 443{
447 scr_release (); 444 scr_release ();
448 prev_nrow = prev_ncol = 0; 445 prev_nrow = prev_ncol = 0;
446 rvideo_mode = false;
447 scr_soft_reset ();
449 scr_reset (); 448 scr_reset ();
450 449
451 scr_clear (true); 450 scr_clear (true);
452 scr_refresh (); 451 scr_refresh ();
452}
453
454void
455rxvt_term::scr_soft_reset ()
456{
457 /* only affects modes, nothing drastic such as clearing the screen */
458#if ENABLE_OVERLAY
459 scr_overlay_off ();
460#endif
461
462 if (current_screen != PRIMARY)
463 scr_swap_screen ();
464
465 scr_scroll_region (0, MAX_ROWS - 1);
466 scr_rendition (0, ~RS_None);
467 scr_insert_mode (0);
453} 468}
454 469
455/* ------------------------------------------------------------------------- * 470/* ------------------------------------------------------------------------- *
456 * PROCESS SCREEN COMMANDS * 471 * PROCESS SCREEN COMMANDS *
457 * ------------------------------------------------------------------------- */ 472 * ------------------------------------------------------------------------- */
459 * Save and Restore cursor 474 * Save and Restore cursor
460 * XTERM_SEQ: Save cursor : ESC 7 475 * XTERM_SEQ: Save cursor : ESC 7
461 * XTERM_SEQ: Restore cursor: ESC 8 476 * XTERM_SEQ: Restore cursor: ESC 8
462 */ 477 */
463void 478void
464rxvt_term::scr_cursor (int mode) 479rxvt_term::scr_cursor (cursor_mode mode) NOTHROW
465{ 480{
466 screen_t *s; 481 screen_t *s;
467 482
468#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR) 483#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR)
469 if (current_screen == SECONDARY) 484 if (current_screen == SECONDARY)
501 assert (s->cur.row >= 0); 516 assert (s->cur.row >= 0);
502 assert (s->cur.col >= 0); 517 assert (s->cur.col >= 0);
503#endif 518#endif
504} 519}
505 520
521void
522rxvt_term::scr_swap_screen ()
523{
524 if (!option (Opt_secondaryScreen))
525 return;
526
527 for (int i = prev_nrow; i--; )
528 ::swap (ROW(i), swap_buf [i]);
529
530 ::swap (screen.cur, swap.cur);
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}
535
506/* ------------------------------------------------------------------------- */ 536/* ------------------------------------------------------------------------- */
507/* 537/*
508 * Swap between primary and secondary screens 538 * Swap between primary and secondary screens
509 * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h 539 * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h
510 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l 540 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l
511 */ 541 */
512int 542void
513rxvt_term::scr_change_screen (int scrn) 543rxvt_term::scr_change_screen (int scrn)
514{ 544{
545 if (scrn == current_screen)
546 return;
547
515 want_refresh = 1; 548 want_refresh = 1;
516 view_start = 0; 549 view_start = 0;
517 550
518 if (current_screen == scrn)
519 return scrn;
520
521 selection_check (2); /* check for boundary cross */ 551 selection_check (2); /* check for boundary cross */
522 552
523 int i = current_screen; current_screen = scrn; scrn = i; 553 int i = current_screen; current_screen = scrn; scrn = i;
524 554
525 ::swap (screen.cur.row, swap.cur.row);
526 ::swap (screen.cur.col, swap.cur.col);
527
528 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
529 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
530
531#if NSCREENS 555#if NSCREENS
532 if (OPTION (Opt_secondaryScreen)) 556 if (option (Opt_secondaryScreen))
533 { 557 {
534 num_scr = 0; 558 num_scr = 0;
535 559
536 for (int i = prev_nrow; i--; ) 560 scr_swap_screen ();
537 ::swap (ROW(i), swap_buf [i]);
538 561
539 ::swap (screen.charset, swap.charset); 562 ::swap (screen.charset, swap.charset);
540 ::swap (screen.flags, swap.flags); 563 ::swap (screen.flags, swap.flags);
541 screen.flags |= Screen_VisibleCursor; 564 screen.flags |= Screen_VisibleCursor;
542 swap.flags |= Screen_VisibleCursor; 565 swap.flags |= Screen_VisibleCursor;
543 } 566 }
544 else 567 else
545#endif 568#endif
546 if (OPTION (Opt_secondaryScroll)) 569 if (option (Opt_secondaryScroll))
547 scr_scroll_text (0, prev_nrow - 1, prev_nrow); 570 scr_scroll_text (0, prev_nrow - 1, prev_nrow);
548
549 return scrn;
550} 571}
551 572
552// clear WrapNext indicator, solidifying position on next line 573// clear WrapNext indicator, solidifying position on next line
553void 574void
554rxvt_term::scr_do_wrap () 575rxvt_term::scr_do_wrap () NOTHROW
555{ 576{
556 if (!(screen.flags & Screen_WrapNext)) 577 if (!(screen.flags & Screen_WrapNext))
557 return; 578 return;
558 579
559 screen.flags &= ~Screen_WrapNext; 580 screen.flags &= ~Screen_WrapNext;
569/* ------------------------------------------------------------------------- */ 590/* ------------------------------------------------------------------------- */
570/* 591/*
571 * Change the colour for following text 592 * Change the colour for following text
572 */ 593 */
573void 594void
574rxvt_term::scr_color (unsigned int color, int fgbg) 595rxvt_term::scr_color (unsigned int color, int fgbg) NOTHROW
575{ 596{
576 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) 597 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
577 color = fgbg; 598 color = fgbg;
578 599
579 if (fgbg == Color_fg) 600 if (fgbg == Color_fg)
585/* ------------------------------------------------------------------------- */ 606/* ------------------------------------------------------------------------- */
586/* 607/*
587 * Change the rendition style for following text 608 * Change the rendition style for following text
588 */ 609 */
589void 610void
590rxvt_term::scr_rendition (int set, int style) 611rxvt_term::scr_rendition (int set, int style) NOTHROW
591 { 612{
592 if (set) 613 if (set)
593 rstyle |= style; 614 rstyle |= style;
594 else if (style == ~RS_None) 615 else if (style == ~RS_None)
595 rstyle = DEFAULT_RSTYLE; 616 rstyle = DEFAULT_RSTYLE;
596 else 617 else
597 rstyle &= ~style; 618 rstyle &= ~style;
598 } 619}
599 620
600/* ------------------------------------------------------------------------- */ 621/* ------------------------------------------------------------------------- */
601/* 622/*
602 * Scroll text between <row1> and <row2> inclusive, by <count> lines 623 * Scroll text between <row1> and <row2> inclusive, by <count> lines
603 * count positive ==> scroll up 624 * count positive ==> scroll up
604 * count negative ==> scroll down 625 * count negative ==> scroll down
605 */ 626 */
606int 627int
607rxvt_term::scr_scroll_text (int row1, int row2, int count) 628rxvt_term::scr_scroll_text (int row1, int row2, int count) NOTHROW
608{ 629{
609 if (count == 0 || (row1 > row2)) 630 if (count == 0 || (row1 > row2))
610 return 0; 631 return 0;
611 632
612 want_refresh = 1; 633 want_refresh = 1;
613 num_scr += count; 634 num_scr += count;
614 635
615 if (count > 0 636 if (count > 0
616 && row1 == 0 637 && row1 == 0
617 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll))) 638 && (current_screen == PRIMARY || option (Opt_secondaryScroll)))
618 { 639 {
619 top_row = max (top_row - count, -saveLines); 640 top_row = max (top_row - count, -saveLines);
620 641
621 // scroll everything up 'count' lines 642 // scroll everything up 'count' lines
622 term_start = (term_start + count) % total_rows; 643 term_start = (term_start + count) % total_rows;
629 } 650 }
630 651
631 // erase newly scrolled-in lines 652 // erase newly scrolled-in lines
632 for (int i = count; i--; ) 653 for (int i = count; i--; )
633 { 654 {
634 // basically this is a slightly optimized scr_blank_screen_mem
635 // it is worth the effort on slower machines
636 line_t &l = ROW(nrow - 1 - i); 655 line_t &l = ROW(nrow - 1 - i);
637 656
657 // optimize if already cleared, can be significant on slow machines
658 // could be rolled into scr_blank_screen_mem
659 if (l.r && l.l < ncol - 1 && !((l.r[l.l + 1] ^ rstyle) & (RS_fgMask | RS_bgMask)))
660 {
638 scr_blank_line (l, 0, l.l, rstyle); 661 scr_blank_line (l, 0, l.l, rstyle);
639
640 l.l = 0; 662 l.l = 0;
641 l.f = 0; 663 l.f = 0;
664 }
665 else
666 scr_blank_screen_mem (l, rstyle);
642 } 667 }
643 668
644 // now copy lines below the scroll region bottom to the 669 // now copy lines below the scroll region bottom to the
645 // bottom of the screen again, so they look as if they 670 // bottom of the screen again, so they look as if they
646 // hadn't moved. 671 // hadn't moved.
650 line_t &l2 = ROW(i); 675 line_t &l2 = ROW(i);
651 676
652 ::swap (l1, l2); 677 ::swap (l1, l2);
653 l2.touch (); 678 l2.touch ();
654 } 679 }
655 680
656 // move and/or clear selection, if any 681 // move and/or clear selection, if any
657 if (selection.op && current_screen == selection.screen) 682 if (selection.op && current_screen == selection.screen)
658 { 683 {
659 selection.beg.row -= count; 684 selection.beg.row -= count;
660 selection.end.row -= count; 685 selection.end.row -= count;
668 selection.op = SELECTION_CLEAR; 693 selection.op = SELECTION_CLEAR;
669 } 694 }
670 } 695 }
671 696
672 // finally move the view window, if desired 697 // finally move the view window, if desired
673 if (OPTION (Opt_scrollWithBuffer) 698 if (option (Opt_scrollWithBuffer)
674 && view_start != 0 699 && view_start != 0
675 && view_start != -saveLines) 700 && view_start != -saveLines)
676 scr_page (UP, count); 701 scr_page (UP, count);
677 702
678 if (SHOULD_INVOKE (HOOK_SCROLL_BACK)) 703 if (SHOULD_INVOKE (HOOK_SCROLL_BACK))
696 { 721 {
697 /* move selected region too */ 722 /* move selected region too */
698 selection.beg.row -= count; 723 selection.beg.row -= count;
699 selection.end.row -= count; 724 selection.end.row -= count;
700 selection.mark.row -= count; 725 selection.mark.row -= count;
701 726
702 selection_check (0); 727 selection_check (0);
703 } 728 }
704 } 729 }
705 730
706 // use a simple and robust scrolling algorithm, this 731 // use a simple and robust scrolling algorithm, this
730/* ------------------------------------------------------------------------- */ 755/* ------------------------------------------------------------------------- */
731/* 756/*
732 * Add text given in <str> of length <len> to screen struct 757 * Add text given in <str> of length <len> to screen struct
733 */ 758 */
734void 759void
735rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) 760rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) NOTHROW
736{ 761{
737 if (len <= 0) /* sanity */ 762 if (len <= 0) /* sanity */
738 return; 763 return;
739 764
740 unsigned char checksel; 765 unsigned char checksel;
746 ZERO_SCROLLBACK (); 771 ZERO_SCROLLBACK ();
747 772
748 if (minlines > 0) 773 if (minlines > 0)
749 { 774 {
750 minlines += screen.cur.row - screen.bscroll; 775 minlines += screen.cur.row - screen.bscroll;
776 min_it (minlines, screen.cur.row - top_row);
751 777
752 if (minlines > 0 778 if (minlines > 0
753 && screen.tscroll == 0 779 && screen.tscroll == 0
754 && screen.bscroll == nrow - 1) 780 && screen.bscroll == nrow - 1)
755 { 781 {
772 798
773 while (str < strend) 799 while (str < strend)
774 { 800 {
775 c = (unicode_t)*str++; // convert to rxvt-unicodes representation 801 c = (unicode_t)*str++; // convert to rxvt-unicodes representation
776 802
777 if (c < 0x20) 803 if (expect_false (c < 0x20))
778 if (c == C0_LF) 804 if (c == C0_LF)
779 { 805 {
780 max_it (line->l, screen.cur.col); 806 max_it (line->l, screen.cur.col);
781 807
782 screen.flags &= ~Screen_WrapNext; 808 screen.flags &= ~Screen_WrapNext;
801 { 827 {
802 scr_tab (1, true); 828 scr_tab (1, true);
803 continue; 829 continue;
804 } 830 }
805 831
832 if (expect_false (
806 if (checksel /* see if we're writing within selection */ 833 checksel /* see if we're writing within selection */
807 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 834 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
808 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 835 && ROWCOL_IS_BEFORE (screen.cur, selection.end)
836 ))
809 { 837 {
810 checksel = 0; 838 checksel = 0;
811 /* 839 /*
812 * If we wrote anywhere in the selected area, kill the selection 840 * If we wrote anywhere in the selected area, kill the selection
813 * XXX: should we kill the mark too? Possibly, but maybe that 841 * XXX: should we kill the mark too? Possibly, but maybe that
814 * should be a similar check. 842 * should be a similar check.
815 */ 843 */
816 CLEAR_SELECTION (); 844 CLEAR_SELECTION ();
817 } 845 }
818 846
819 if (screen.flags & Screen_WrapNext) 847 if (expect_false (screen.flags & Screen_WrapNext))
820 { 848 {
821 scr_do_wrap (); 849 scr_do_wrap ();
822 850
823 line->l = ncol; 851 line->l = ncol;
824 line->is_longer (1); 852 line->is_longer (1);
825 853
826 row = screen.cur.row; 854 row = screen.cur.row;
827 line = &ROW(row); /* _must_ refresh */ 855 line = &ROW(row); /* _must_ refresh */
828 } 856 }
829 857
830 // some utf-8 decoders "decode" surrogate characters: let's fix this. 858 // some utf-8 decoders "decode" surrogate characters: let's fix this.
831 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 859 if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff)))
832 c = 0xfffd; 860 c = 0xfffd;
833 861
834 // rely on wcwidth to tell us the character width, at least for non-latin1 862 // rely on wcwidth to tell us the character width, do wcwidth before
835 // do wcwidth before further replacements, as wcwidth might return -1 863 // further replacements, as wcwidth might return -1 for the line
836 // for the line drawing characters below as they might be invalid in the current 864 // drawing characters below as they might be invalid in the current
837 // locale. 865 // locale.
838 int width = c < 0x100 ? 1 : wcwidth (c); 866 int width = WCWIDTH (c);
839 867
840 if (charsets [screen.charset] == '0') // DEC SPECIAL 868 if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL
841 { 869 {
842 // vt100 special graphics and line drawing 870 // vt100 special graphics and line drawing
843 // 5f-7e standard vt100 871 // 5f-7e standard vt100
844 // 40-5e rxvt extension for extra curses acs chars 872 // 40-5e rxvt extension for extra curses acs chars
845 static uint16_t vt100_0[62] = { // 41 .. 7e 873 static uint16_t vt100_0[62] = { // 41 .. 7e
858 c = vt100_0[c - 0x41]; 886 c = vt100_0[c - 0x41];
859 width = 1; // vt100 line drawing characters are always single-width 887 width = 1; // vt100 line drawing characters are always single-width
860 } 888 }
861 } 889 }
862 890
863 if (screen.flags & Screen_Insert) 891 if (expect_false (screen.flags & Screen_Insert))
864 scr_insdel_chars (width, INSERT); 892 scr_insdel_chars (width, INSERT);
865 893
866 if (width != 0) 894 if (width != 0)
867 { 895 {
868#if !UNICODE_3 896#if !UNICODE_3
874 c = 0xfffd; 902 c = 0xfffd;
875# endif 903# endif
876#endif 904#endif
877 905
878 // nuke the character at this position, if required 906 // nuke the character at this position, if required
907 if (expect_false (
879 if (line->t[screen.cur.col] == NOCHAR 908 line->t[screen.cur.col] == NOCHAR
880 || (screen.cur.col < ncol - 1 909 || (screen.cur.col < ncol - 1
881 && line->t[screen.cur.col + 1] == NOCHAR)) 910 && line->t[screen.cur.col + 1] == NOCHAR)
911 ))
912 scr_kill_char (*line, screen.cur.col);
913
914 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
915
916 // if the character doesn't fit into the remaining columns...
917 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
882 { 918 {
883 int col = screen.cur.col; 919 // ... artificially enlargen the previous one
884
885 // find begin
886 while (col > 0 && line->t[col] == NOCHAR)
887 col--;
888
889 rend_t rend = SET_FONT (line->r[col], FONTSET (line->r[col])->find_font (' '));
890
891 // found begin, nuke
892 do {
893 line->t[col] = ' ';
894 line->r[col] = rend;
895 col++;
896 } while (col < ncol && line->t[col] == NOCHAR);
897 }
898
899 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
900
901 // if the character doesn't fit into the remaining columns...
902 if (screen.cur.col > ncol - width && ncol >= width)
903 {
904 // ...output spaces
905 c = ' '; 920 c = NOCHAR;
906 // and try the same character next loop iteration 921 // and try the same character next loop iteration
907 --str; 922 --str;
908 } 923 }
909 924
910 line->touch (); 925 line->touch ();
912 do 927 do
913 { 928 {
914 line->t[screen.cur.col] = c; 929 line->t[screen.cur.col] = c;
915 line->r[screen.cur.col] = rend; 930 line->r[screen.cur.col] = rend;
916 931
917 if (screen.cur.col < ncol - 1) 932 if (expect_true (screen.cur.col < ncol - 1))
918 screen.cur.col++; 933 screen.cur.col++;
919 else 934 else
920 { 935 {
921 line->l = ncol; 936 line->l = ncol;
922 if (screen.flags & Screen_Autowrap) 937 if (screen.flags & Screen_Autowrap)
924 break; 939 break;
925 } 940 }
926 941
927 c = NOCHAR; 942 c = NOCHAR;
928 } 943 }
929 while (--width > 0); 944 while (expect_false (--width > 0));
930 945
931 // pad with spaces when overwriting wide character with smaller one 946 // pad with spaces when overwriting wide character with smaller one
932 if (!width) 947 if (expect_false (!width))
933 { 948 {
934 line->touch (); 949 line->touch ();
935 950
936 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) 951 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
937 { 952 {
938 line->t[c] = ' '; 953 line->t[c] = ' ';
939 line->r[c] = rend; 954 line->r[c] = rend;
940 } 955 }
941 } 956 }
942 } 957 }
958#if ENABLE_COMBINING
943 else // width == 0 959 else // width == 0
944 { 960 {
945#if ENABLE_COMBINING 961 if (c != 0xfeff) // ignore BOM
946 // handle combining characters
947 // we just tag the accent on the previous on-screen character.
948 // this is arguably not correct, but also arguably not wrong.
949 // we don't handle double-width characters nicely yet.
950 line_t *linep;
951 text_t *tp;
952 rend_t *rp;
953
954 if (screen.cur.col > 0)
955 { 962 {
963 // handle combining characters
964 // we just tag the accent on the previous on-screen character.
965 // this is arguably not correct, but also arguably not wrong.
966 // we don't handle double-width characters nicely yet.
967 line_t *linep;
968 text_t *tp;
969 rend_t *rp;
970
971 if (screen.cur.col > 0)
972 {
956 linep = line; 973 linep = line;
957 tp = line->t + screen.cur.col - 1; 974 tp = line->t + screen.cur.col - 1;
958 rp = line->r + screen.cur.col - 1; 975 rp = line->r + screen.cur.col - 1;
976 }
977 else if (screen.cur.row > 0
978 && ROW(screen.cur.row - 1).is_longer ())
979 {
980 linep = &ROW(screen.cur.row - 1);
981 tp = line->t + ncol - 1;
982 rp = line->r + ncol - 1;
983 }
984 else
985 continue;
986
987 linep->touch ();
988
989 while (*tp == NOCHAR && tp > linep->t)
990 tp--, rp--;
991
992 // first try to find a precomposed character
993 unicode_t n = rxvt_compose (*tp, c);
994 if (n == NOCHAR)
995 n = rxvt_composite.compose (*tp, c);
996
997 *tp = n;
998 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
959 } 999 }
960 else if (screen.cur.row > 0
961 && ROW(screen.cur.row - 1).is_longer ())
962 {
963 linep = &ROW(screen.cur.row - 1);
964 tp = line->t + ncol - 1;
965 rp = line->r + ncol - 1;
966 } 1000 }
967 else
968 continue;
969
970 linep->touch ();
971
972 while (*tp == NOCHAR && tp > linep->t)
973 tp--, rp--;
974
975 // first try to find a precomposed character
976 unicode_t n = rxvt_compose (*tp, c);
977 if (n == NOCHAR)
978 n = rxvt_composite.compose (*tp, c);
979
980 *tp = n;
981 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
982#endif 1001#endif
983 }
984 } 1002 }
985 1003
986 max_it (line->l, screen.cur.col); 1004 max_it (line->l, screen.cur.col);
987 1005
988#ifdef DEBUG_STRICT 1006#ifdef DEBUG_STRICT
994/* 1012/*
995 * Process Backspace. Move back the cursor back a position, wrap if have to 1013 * Process Backspace. Move back the cursor back a position, wrap if have to
996 * XTERM_SEQ: CTRL-H 1014 * XTERM_SEQ: CTRL-H
997 */ 1015 */
998void 1016void
999rxvt_term::scr_backspace () 1017rxvt_term::scr_backspace () NOTHROW
1000{ 1018{
1001 want_refresh = 1;
1002
1003 if (screen.cur.col == 0) 1019 if (screen.cur.col == 0)
1004 { 1020 {
1005 if (screen.cur.row > 0) 1021 if (screen.cur.row > 0)
1006 { 1022 {
1007#ifdef TERMCAP_HAS_BW 1023#ifdef TERMCAP_HAS_BW
1008 screen.cur.col = ncol - 1; 1024 screen.cur.col = ncol - 1;
1009 screen.cur.row--; 1025 --screen.cur.row;
1010 return; 1026
1027 want_refresh = 1;
1011#endif 1028#endif
1012 } 1029 }
1013 } 1030 }
1014 else if (!(screen.flags & Screen_WrapNext)) 1031 else
1015 scr_gotorc (0, -1, RELATIVE); 1032 scr_gotorc (0, -1, RELATIVE);
1016
1017 screen.flags &= ~Screen_WrapNext;
1018} 1033}
1019 1034
1020/* ------------------------------------------------------------------------- */ 1035/* ------------------------------------------------------------------------- */
1021/* 1036/*
1022 * Process Horizontal Tab 1037 * Process Horizontal Tab
1023 * count: +ve = forward; -ve = backwards 1038 * count: +ve = forward; -ve = backwards
1024 * XTERM_SEQ: CTRL-I 1039 * XTERM_SEQ: CTRL-I
1025 */ 1040 */
1026void 1041void
1027rxvt_term::scr_tab (int count, bool ht) 1042rxvt_term::scr_tab (int count, bool ht) NOTHROW
1028{ 1043{
1029 int i, x; 1044 int i, x;
1030 1045
1031 want_refresh = 1; 1046 want_refresh = 1;
1032 i = x = screen.cur.col; 1047 i = x = screen.cur.col;
1045 x = i; 1060 x = i;
1046 1061
1047 if (!--count) 1062 if (!--count)
1048 break; 1063 break;
1049 } 1064 }
1050 else 1065 else
1051 ht &= l.t[i] == ' ' 1066 ht &= l.t[i] == ' '
1052 && RS_SAME (l.r[i], base_rend); 1067 && RS_SAME (l.r[i], base_rend);
1053 1068
1054 if (count) 1069 if (count)
1055 x = ncol - 1; 1070 x = ncol - 1;
1056 1071
1057 // store horizontal tab commands as characters inside the text 1072 // store horizontal tab commands as characters inside the text
1058 // buffer so they can be selected and pasted. 1073 // buffer so they can be selected and pasted.
1059 if (ht && OPTION (Opt_pastableTabs)) 1074 if (ht && option (Opt_pastableTabs))
1060 { 1075 {
1061 base_rend = SET_FONT (base_rend, 0); 1076 base_rend = SET_FONT (base_rend, 0);
1062 1077
1063 l.touch (x); 1078 l.touch (x);
1064 1079
1097 * Process DEC Back Index 1112 * Process DEC Back Index
1098 * XTERM_SEQ: ESC 6 1113 * XTERM_SEQ: ESC 6
1099 * Move cursor left in row. If we're at the left boundary, shift everything 1114 * Move cursor left in row. If we're at the left boundary, shift everything
1100 * in that row right. Clear left column. 1115 * in that row right. Clear left column.
1101 */ 1116 */
1102#if ENABLE_FRILLS 1117#if !ENABLE_MINIMAL
1103void 1118void
1104rxvt_term::scr_backindex () 1119rxvt_term::scr_backindex () NOTHROW
1105{ 1120{
1106 if (screen.cur.col > 0) 1121 if (screen.cur.col > 0)
1107 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE); 1122 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
1108 else 1123 else
1109 scr_insdel_chars (1, INSERT); 1124 scr_insdel_chars (1, INSERT);
1114 * Process DEC Forward Index 1129 * Process DEC Forward Index
1115 * XTERM_SEQ: ESC 9 1130 * XTERM_SEQ: ESC 9
1116 * Move cursor right in row. If we're at the right boundary, shift everything 1131 * Move cursor right in row. If we're at the right boundary, shift everything
1117 * in that row left. Clear right column. 1132 * in that row left. Clear right column.
1118 */ 1133 */
1119#if ENABLE_FRILLS 1134#if !ENABLE_MINIMAL
1120void 1135void
1121rxvt_term::scr_forwardindex () 1136rxvt_term::scr_forwardindex () NOTHROW
1122{ 1137{
1123 if (screen.cur.col < ncol - 1) 1138 if (screen.cur.col < ncol - 1)
1124 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1139 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1125 else 1140 else
1126 { 1141 {
1139/* ------------------------------------------------------------------------- */ 1154/* ------------------------------------------------------------------------- */
1140/* 1155/*
1141 * Goto Row/Column 1156 * Goto Row/Column
1142 */ 1157 */
1143void 1158void
1144rxvt_term::scr_gotorc (int row, int col, int relative) 1159rxvt_term::scr_gotorc (int row, int col, int relative) NOTHROW
1145{ 1160{
1146 want_refresh = 1; 1161 want_refresh = 1;
1147 ZERO_SCROLLBACK (); 1162 ZERO_SCROLLBACK ();
1148 1163
1149 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col; 1164 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col;
1171 } 1186 }
1172 } 1187 }
1173 else 1188 else
1174 { 1189 {
1175 if (screen.flags & Screen_Relative) 1190 if (screen.flags & Screen_Relative)
1191 {
1176 { /* relative origin mode */ 1192 /* relative origin mode */
1177 screen.cur.row = row + screen.tscroll; 1193 screen.cur.row = row + screen.tscroll;
1178 min_it (screen.cur.row, screen.bscroll); 1194 min_it (screen.cur.row, screen.bscroll);
1179 } 1195 }
1180 else 1196 else
1181 screen.cur.row = row; 1197 screen.cur.row = row;
1187/* ------------------------------------------------------------------------- */ 1203/* ------------------------------------------------------------------------- */
1188/* 1204/*
1189 * direction should be UP or DN 1205 * direction should be UP or DN
1190 */ 1206 */
1191void 1207void
1192rxvt_term::scr_index (enum page_dirn direction) 1208rxvt_term::scr_index (enum page_dirn direction) NOTHROW
1193{ 1209{
1194 int dirn; 1210 int dirn;
1195 1211
1196 want_refresh = 1; 1212 want_refresh = 1;
1197 ZERO_SCROLLBACK (); 1213 ZERO_SCROLLBACK ();
1214/* 1230/*
1215 * Erase part or whole of a line 1231 * Erase part or whole of a line
1216 * XTERM_SEQ: Clear line to right: ESC [ 0 K 1232 * XTERM_SEQ: Clear line to right: ESC [ 0 K
1217 * XTERM_SEQ: Clear line to left : ESC [ 1 K 1233 * XTERM_SEQ: Clear line to left : ESC [ 1 K
1218 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1234 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1235 * extension: clear to right unless wrapped: ESC [ 3 K
1219 */ 1236 */
1220void 1237void
1221rxvt_term::scr_erase_line (int mode) 1238rxvt_term::scr_erase_line (int mode) NOTHROW
1222{ 1239{
1223 unsigned int col, num; 1240 unsigned int col, num;
1224 1241
1225 want_refresh = 1; 1242 want_refresh = 1;
1226 ZERO_SCROLLBACK (); 1243 ZERO_SCROLLBACK ();
1232 line.touch (); 1249 line.touch ();
1233 line.is_longer (0); 1250 line.is_longer (0);
1234 1251
1235 switch (mode) 1252 switch (mode)
1236 { 1253 {
1254 case 3:
1255 if (screen.flags & Screen_WrapNext)
1256 return;
1257
1258 /* fall through */
1259
1237 case 0: /* erase to end of line */ 1260 case 0: /* erase to end of line */
1238 col = screen.cur.col; 1261 col = screen.cur.col;
1239 num = ncol - col; 1262 num = ncol - col;
1240 min_it (line.l, col); 1263 min_it (line.l, col);
1264
1241 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1265 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1242 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1266 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1243 CLEAR_SELECTION (); 1267 CLEAR_SELECTION ();
1244 break; 1268 break;
1269
1245 case 1: /* erase to beginning of line */ 1270 case 1: /* erase to beginning of line */
1246 col = 0; 1271 col = 0;
1247 num = screen.cur.col + 1; 1272 num = screen.cur.col + 1;
1273
1248 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur) 1274 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur)
1249 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur)) 1275 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur))
1250 CLEAR_SELECTION (); 1276 CLEAR_SELECTION ();
1251 break; 1277 break;
1278
1252 case 2: /* erase whole line */ 1279 case 2: /* erase whole line */
1253 col = 0; 1280 col = 0;
1254 num = ncol; 1281 num = ncol;
1255 line.l = 0; 1282 line.l = 0;
1256 if (selection.beg.row <= screen.cur.row 1283 if (selection.beg.row <= screen.cur.row
1270 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J 1297 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J
1271 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J 1298 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J
1272 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1299 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1273 */ 1300 */
1274void 1301void
1275rxvt_term::scr_erase_screen (int mode) 1302rxvt_term::scr_erase_screen (int mode) NOTHROW
1276{ 1303{
1277 int num; 1304 int num;
1278 int32_t row; 1305 int32_t row;
1279 rend_t ren; 1306 rend_t ren;
1280 XGCValues gcvalue; 1307 XGCValues gcvalue;
1314 if (row >= nrow) /* Out Of Bounds */ 1341 if (row >= nrow) /* Out Of Bounds */
1315 return; 1342 return;
1316 1343
1317 min_it (num, nrow - row); 1344 min_it (num, nrow - row);
1318 1345
1346 // TODO: the code below does not work when view_start != 0
1347 // the workaround is to disable the clear and use a normal refresh
1348 // when view_start != 0. mysterious.
1319 if (rstyle & (RS_RVid | RS_Uline)) 1349 if (rstyle & (RS_RVid | RS_Uline))
1320 ren = (rend_t) ~RS_None; 1350 ren = (rend_t) ~RS_None;
1321 else if (GET_BASEBG (rstyle) == Color_bg) 1351 else if (GET_BASEBG (rstyle) == Color_bg)
1322 { 1352 {
1323 ren = DEFAULT_RSTYLE; 1353 ren = DEFAULT_RSTYLE;
1324 CLEAR_ROWS (row, num); 1354
1355 if (mapped && !view_start)
1356 XClearArea (dpy, vt, 0,
1357 Row2Pixel (row - view_start), (unsigned int)width,
1358 (unsigned int)Height2Pixel (num), False);
1325 } 1359 }
1326 else 1360 else
1327 { 1361 {
1328 ren = rstyle & (RS_fgMask | RS_bgMask); 1362 ren = rstyle & (RS_fgMask | RS_bgMask);
1363
1364 if (mapped && !view_start)
1365 {
1329 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1366 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1330 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1367 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1331 ERASE_ROWS (row, num); 1368 XFillRectangle (dpy, vt, gc,
1369 0, Row2Pixel (row - view_start),
1370 (unsigned int)width,
1371 (unsigned int)Height2Pixel (num));
1332 gcvalue.foreground = pix_colors[Color_fg]; 1372 gcvalue.foreground = pix_colors[Color_fg];
1333 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1373 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1374 }
1334 } 1375 }
1335 1376
1336 for (; num--; row++) 1377 for (; num--; row++)
1337 { 1378 {
1338 scr_blank_screen_mem (ROW(row), rstyle); 1379 scr_blank_screen_mem (ROW(row), rstyle);
1380
1381 if (!view_start)
1339 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1382 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1340 } 1383 }
1341} 1384}
1342 1385
1343#if ENABLE_FRILLS 1386#if !ENABLE_MINIMAL
1344void 1387void
1345rxvt_term::scr_erase_savelines () 1388rxvt_term::scr_erase_savelines () NOTHROW
1346{ 1389{
1347 want_refresh = 1; 1390 want_refresh = 1;
1348 ZERO_SCROLLBACK (); 1391 ZERO_SCROLLBACK ();
1349 1392
1350 top_row = 0; 1393 top_row = 0;
1355/* 1398/*
1356 * Fill the screen with `E's 1399 * Fill the screen with `E's
1357 * XTERM_SEQ: Screen Alignment Test: ESC # 8 1400 * XTERM_SEQ: Screen Alignment Test: ESC # 8
1358 */ 1401 */
1359void 1402void
1360rxvt_term::scr_E () 1403rxvt_term::scr_E () NOTHROW
1361{ 1404{
1362 rend_t fs; 1405 rend_t fs;
1363 1406
1364 want_refresh = 1; 1407 want_refresh = 1;
1365 ZERO_SCROLLBACK (); 1408 ZERO_SCROLLBACK ();
1386/* ------------------------------------------------------------------------- */ 1429/* ------------------------------------------------------------------------- */
1387/* 1430/*
1388 * Insert/Delete <count> lines 1431 * Insert/Delete <count> lines
1389 */ 1432 */
1390void 1433void
1391rxvt_term::scr_insdel_lines (int count, int insdel) 1434rxvt_term::scr_insdel_lines (int count, int insdel) NOTHROW
1392{ 1435{
1393 int end; 1436 int end;
1394 1437
1395 ZERO_SCROLLBACK (); 1438 ZERO_SCROLLBACK ();
1396 1439
1416/* ------------------------------------------------------------------------- */ 1459/* ------------------------------------------------------------------------- */
1417/* 1460/*
1418 * Insert/Delete <count> characters from the current position 1461 * Insert/Delete <count> characters from the current position
1419 */ 1462 */
1420void 1463void
1421rxvt_term::scr_insdel_chars (int count, int insdel) 1464rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW
1422{ 1465{
1423 int col, row;
1424 rend_t tr;
1425
1426 want_refresh = 1; 1466 want_refresh = 1;
1427 ZERO_SCROLLBACK (); 1467 ZERO_SCROLLBACK ();
1428 1468
1429 if (count <= 0) 1469 if (count <= 0)
1430 return; 1470 return;
1432 scr_do_wrap (); 1472 scr_do_wrap ();
1433 1473
1434 selection_check (1); 1474 selection_check (1);
1435 min_it (count, ncol - screen.cur.col); 1475 min_it (count, ncol - screen.cur.col);
1436 1476
1437 row = screen.cur.row; 1477 int row = screen.cur.row;
1438 1478
1439 line_t *line = &ROW(row); 1479 line_t *line = &ROW(row);
1440 1480
1441 line->touch (); 1481 line->touch ();
1442 line->is_longer (0); 1482 line->is_longer (0);
1443 1483
1484 // nuke wide spanning the start
1485 if (line->t[screen.cur.col] == NOCHAR)
1486 scr_kill_char (*line, screen.cur.col);
1487
1444 switch (insdel) 1488 switch (insdel)
1445 { 1489 {
1446 case INSERT: 1490 case INSERT:
1447 for (col = ncol - 1; (col - count) >= screen.cur.col; col--) 1491 line->l = min (line->l + count, ncol);
1492
1493 if (line->t[screen.cur.col] == NOCHAR)
1494 scr_kill_char (*line, screen.cur.col);
1495
1496 for (int col = ncol - 1; (col - count) >= screen.cur.col; col--)
1448 { 1497 {
1449 line->t[col] = line->t[col - count]; 1498 line->t[col] = line->t[col - count];
1450 line->r[col] = line->r[col - count]; 1499 line->r[col] = line->r[col - count];
1451 } 1500 }
1452
1453 line->l = min (line->l + count, ncol);
1454 1501
1455 if (selection.op && current_screen == selection.screen 1502 if (selection.op && current_screen == selection.screen
1456 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1503 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1457 { 1504 {
1458 if (selection.end.row != screen.cur.row 1505 if (selection.end.row != screen.cur.row
1459 || (selection.end.col + count >= ncol)) 1506 || (selection.end.col + count >= ncol))
1460 CLEAR_SELECTION (); 1507 CLEAR_SELECTION ();
1461 else 1508 else
1509 {
1462 { /* shift selection */ 1510 /* shift selection */
1463 selection.beg.col += count; 1511 selection.beg.col += count;
1464 selection.mark.col += count; /* XXX: yes? */ 1512 selection.mark.col += count; /* XXX: yes? */
1465 selection.end.col += count; 1513 selection.end.col += count;
1466 } 1514 }
1467 } 1515 }
1472 case ERASE: 1520 case ERASE:
1473 screen.cur.col += count; /* don't worry if > ncol */ 1521 screen.cur.col += count; /* don't worry if > ncol */
1474 selection_check (1); 1522 selection_check (1);
1475 screen.cur.col -= count; 1523 screen.cur.col -= count;
1476 1524
1477 line->l = max (line->l - count, 0); 1525 // nuke wide char after the end
1526 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1527 scr_kill_char (*line, screen.cur.col + count);
1528
1478 scr_blank_line (*line, screen.cur.col, count, rstyle); 1529 scr_blank_line (*line, screen.cur.col, count, rstyle);
1479 break; 1530 break;
1480 1531
1481 case DELETE: 1532 case DELETE:
1482 tr = line->r[ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask); 1533 line->l = max (line->l - count, 0);
1483 1534
1535 // nuke wide char spanning the end
1536 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1537 scr_kill_char (*line, screen.cur.col + count);
1538
1484 for (col = screen.cur.col; (col + count) < ncol; col++) 1539 for (int col = screen.cur.col; (col + count) < ncol; col++)
1485 { 1540 {
1486 line->t[col] = line->t[col + count]; 1541 line->t[col] = line->t[col + count];
1487 line->r[col] = line->r[col + count]; 1542 line->r[col] = line->r[col + count];
1488 } 1543 }
1489 1544
1490 line->l = max (line->l - count, 0);
1491 scr_blank_line (*line, ncol - count, count, tr); 1545 scr_blank_line (*line, ncol - count, count, rstyle);
1492 1546
1493 if (selection.op && current_screen == selection.screen 1547 if (selection.op && current_screen == selection.screen
1494 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1548 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1495 { 1549 {
1496 if (selection.end.row != screen.cur.row 1550 if (selection.end.row != screen.cur.row
1514/* 1568/*
1515 * Set the scrolling region 1569 * Set the scrolling region
1516 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r 1570 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r
1517 */ 1571 */
1518void 1572void
1519rxvt_term::scr_scroll_region (int top, int bot) 1573rxvt_term::scr_scroll_region (int top, int bot) NOTHROW
1520{ 1574{
1521 max_it (top, 0); 1575 max_it (top, 0);
1522 min_it (bot, nrow - 1); 1576 min_it (bot, nrow - 1);
1523 1577
1524 if (top > bot) 1578 if (top > bot)
1534 * Make the cursor visible/invisible 1588 * Make the cursor visible/invisible
1535 * XTERM_SEQ: Make cursor visible : ESC [ ? 25 h 1589 * XTERM_SEQ: Make cursor visible : ESC [ ? 25 h
1536 * XTERM_SEQ: Make cursor invisible: ESC [ ? 25 l 1590 * XTERM_SEQ: Make cursor invisible: ESC [ ? 25 l
1537 */ 1591 */
1538void 1592void
1539rxvt_term::scr_cursor_visible (int mode) 1593rxvt_term::scr_cursor_visible (int mode) NOTHROW
1540{ 1594{
1541 want_refresh = 1; 1595 want_refresh = 1;
1542 1596
1543 if (mode) 1597 if (mode)
1544 screen.flags |= Screen_VisibleCursor; 1598 screen.flags |= Screen_VisibleCursor;
1551 * Set/unset automatic wrapping 1605 * Set/unset automatic wrapping
1552 * XTERM_SEQ: Set Wraparound : ESC [ ? 7 h 1606 * XTERM_SEQ: Set Wraparound : ESC [ ? 7 h
1553 * XTERM_SEQ: Unset Wraparound: ESC [ ? 7 l 1607 * XTERM_SEQ: Unset Wraparound: ESC [ ? 7 l
1554 */ 1608 */
1555void 1609void
1556rxvt_term::scr_autowrap (int mode) 1610rxvt_term::scr_autowrap (int mode) NOTHROW
1557{ 1611{
1558 if (mode) 1612 if (mode)
1559 screen.flags |= Screen_Autowrap; 1613 screen.flags |= Screen_Autowrap;
1560 else 1614 else
1561 screen.flags &= ~(Screen_Autowrap | Screen_WrapNext); 1615 screen.flags &= ~(Screen_Autowrap | Screen_WrapNext);
1570 * and the cursor cannot be moved outside. 1624 * and the cursor cannot be moved outside.
1571 * XTERM_SEQ: Set Absolute: ESC [ ? 6 h 1625 * XTERM_SEQ: Set Absolute: ESC [ ? 6 h
1572 * XTERM_SEQ: Set Relative: ESC [ ? 6 l 1626 * XTERM_SEQ: Set Relative: ESC [ ? 6 l
1573 */ 1627 */
1574void 1628void
1575rxvt_term::scr_relative_origin (int mode) 1629rxvt_term::scr_relative_origin (int mode) NOTHROW
1576{ 1630{
1577 if (mode) 1631 if (mode)
1578 screen.flags |= Screen_Relative; 1632 screen.flags |= Screen_Relative;
1579 else 1633 else
1580 screen.flags &= ~Screen_Relative; 1634 screen.flags &= ~Screen_Relative;
1587 * Set insert/replace mode 1641 * Set insert/replace mode
1588 * XTERM_SEQ: Set Insert mode : ESC [ ? 4 h 1642 * XTERM_SEQ: Set Insert mode : ESC [ ? 4 h
1589 * XTERM_SEQ: Set Replace mode: ESC [ ? 4 l 1643 * XTERM_SEQ: Set Replace mode: ESC [ ? 4 l
1590 */ 1644 */
1591void 1645void
1592rxvt_term::scr_insert_mode (int mode) 1646rxvt_term::scr_insert_mode (int mode) NOTHROW
1593{ 1647{
1594 if (mode) 1648 if (mode)
1595 screen.flags |= Screen_Insert; 1649 screen.flags |= Screen_Insert;
1596 else 1650 else
1597 screen.flags &= ~Screen_Insert; 1651 screen.flags &= ~Screen_Insert;
1603 * XTERM_SEQ: Set tab at current column : ESC H 1657 * XTERM_SEQ: Set tab at current column : ESC H
1604 * XTERM_SEQ: Clear tab at current column: ESC [ 0 g 1658 * XTERM_SEQ: Clear tab at current column: ESC [ 0 g
1605 * XTERM_SEQ: Clear all tabs : ESC [ 3 g 1659 * XTERM_SEQ: Clear all tabs : ESC [ 3 g
1606 */ 1660 */
1607void 1661void
1608rxvt_term::scr_set_tab (int mode) 1662rxvt_term::scr_set_tab (int mode) NOTHROW
1609{ 1663{
1610 if (mode < 0) 1664 if (mode < 0)
1611 memset (tabs, 0, ncol * sizeof (char)); 1665 memset (tabs, 0, ncol);
1612 else if (screen.cur.col < ncol) 1666 else if (screen.cur.col < ncol)
1613 tabs [screen.cur.col] = !!mode; 1667 tabs [screen.cur.col] = !!mode;
1614} 1668}
1615 1669
1616/* ------------------------------------------------------------------------- */ 1670/* ------------------------------------------------------------------------- */
1618 * Set reverse/normal video 1672 * Set reverse/normal video
1619 * XTERM_SEQ: Reverse video: ESC [ ? 5 h 1673 * XTERM_SEQ: Reverse video: ESC [ ? 5 h
1620 * XTERM_SEQ: Normal video : ESC [ ? 5 l 1674 * XTERM_SEQ: Normal video : ESC [ ? 5 l
1621 */ 1675 */
1622void 1676void
1623rxvt_term::scr_rvideo_mode (int mode) 1677rxvt_term::scr_rvideo_mode (bool on) NOTHROW
1624{ 1678{
1625 XGCValues gcvalue; 1679 rvideo_mode = on;
1626 1680
1681#ifndef NO_BELL
1682 on ^= rvideo_bell;
1683#endif
1684
1627 if (rvideo != mode) 1685 if (rvideo_state != on)
1628 { 1686 {
1629 rvideo = mode; 1687 rvideo_state = on;
1688
1630 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1689 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1631#if XPM_BACKGROUND 1690#ifdef HAVE_BG_PIXMAP
1632 if (bgPixmap.pixmap == None) 1691 if (bgPixmap.pixmap == None)
1633#endif 1692#endif
1634#if TRANSPARENT 1693 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
1635 if (! OPTION (Opt_transparent) || am_transparent == 0)
1636#endif
1637 XSetWindowBackground (display->display, vt,
1638 pix_colors[Color_bg]);
1639 1694
1695 XGCValues gcvalue;
1640 gcvalue.foreground = pix_colors[Color_fg]; 1696 gcvalue.foreground = pix_colors[Color_fg];
1641 gcvalue.background = pix_colors[Color_bg]; 1697 gcvalue.background = pix_colors[Color_bg];
1642 XChangeGC (display->display, gc, GCBackground | GCForeground, 1698 XChangeGC (dpy, gc, GCBackground | GCForeground, &gcvalue);
1643 &gcvalue); 1699
1644 scr_clear (); 1700 scr_clear ();
1645 scr_touch (true); 1701 scr_touch (true);
1646 } 1702 }
1647} 1703}
1648 1704
1650/* 1706/*
1651 * Report current cursor position 1707 * Report current cursor position
1652 * XTERM_SEQ: Report position: ESC [ 6 n 1708 * XTERM_SEQ: Report position: ESC [ 6 n
1653 */ 1709 */
1654void 1710void
1655rxvt_term::scr_report_position () 1711rxvt_term::scr_report_position () NOTHROW
1656{ 1712{
1657 tt_printf ("\033[%d;%dR", screen.cur.row + 1, screen.cur.col + 1); 1713 tt_printf ("\033[%d;%dR", screen.cur.row + 1, screen.cur.col + 1);
1658} 1714}
1659 1715
1660/* ------------------------------------------------------------------------- * 1716/* ------------------------------------------------------------------------- *
1663 1719
1664/* 1720/*
1665 * Set font style 1721 * Set font style
1666 */ 1722 */
1667void 1723void
1668rxvt_term::set_font_style () 1724rxvt_term::set_font_style () NOTHROW
1669{ 1725{
1670#if 0 1726#if 0
1671 switch (charsets [screen.charset]) 1727 switch (charsets [screen.charset])
1672 { 1728 {
1673 case '0': /* DEC Special Character & Line Drawing Set */ 1729 case '0': /* DEC Special Character & Line Drawing Set */
1695 * XTERM_SEQ: Invoke G1 character set: CTRL-N 1751 * XTERM_SEQ: Invoke G1 character set: CTRL-N
1696 * XTERM_SEQ: Invoke G2 character set: ESC N 1752 * XTERM_SEQ: Invoke G2 character set: ESC N
1697 * XTERM_SEQ: Invoke G3 character set: ESC O 1753 * XTERM_SEQ: Invoke G3 character set: ESC O
1698 */ 1754 */
1699void 1755void
1700rxvt_term::scr_charset_choose (int set) 1756rxvt_term::scr_charset_choose (int set) NOTHROW
1701{ 1757{
1702 screen.charset = set; 1758 screen.charset = set;
1703 set_font_style (); 1759 set_font_style ();
1704} 1760}
1705 1761
1711 * XTERM_SEQ: Set G2 character set: ESC * <C> 1767 * XTERM_SEQ: Set G2 character set: ESC * <C>
1712 * XTERM_SEQ: Set G3 character set: ESC + <C> 1768 * XTERM_SEQ: Set G3 character set: ESC + <C>
1713 * See set_font_style for possible values for <C> 1769 * See set_font_style for possible values for <C>
1714 */ 1770 */
1715void 1771void
1716rxvt_term::scr_charset_set (int set, unsigned int ch) 1772rxvt_term::scr_charset_set (int set, unsigned int ch) NOTHROW
1717{ 1773{
1718 charsets[set] = (unsigned char)ch; 1774 charsets[set] = (unsigned char)ch;
1719 set_font_style (); 1775 set_font_style ();
1720} 1776}
1721 1777
1726 1782
1727/* 1783/*
1728 * refresh matching text. 1784 * refresh matching text.
1729 */ 1785 */
1730bool 1786bool
1731rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) 1787rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) NOTHROW
1732{ 1788{
1733 bool found = false; 1789 bool found = false;
1734 1790
1735 for (int i = 0; i < nrow; i++) 1791 for (int i = 0; i < nrow; i++)
1736 { 1792 {
1737 int col = 0;
1738 rend_t *drp = drawn_buf[i].r; 1793 rend_t *drp = drawn_buf[i].r;
1739 1794
1740 for (; col < ncol; col++, drp++) 1795 for (int col = 0; col < ncol; col++, drp++)
1741 if ((*drp & mask) == value) 1796 if ((*drp & mask) == value)
1742 { 1797 {
1743 found = true; 1798 found = true;
1744 *drp = ~value; 1799 *drp = ~value;
1745 } 1800 }
1756 PART_END, 1811 PART_END,
1757 RC_COUNT 1812 RC_COUNT
1758}; 1813};
1759 1814
1760void 1815void
1761rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) 1816rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) NOTHROW
1762{ 1817{
1763 int i; 1818 int i;
1764 row_col_t rc[RC_COUNT]; 1819 row_col_t rc[RC_COUNT];
1765 1820
1766 if (!drawn_buf) /* sanity check */ 1821 if (!drawn_buf) /* sanity check */
1785 for (i = PART_BEG; i < RC_COUNT; i++) 1840 for (i = PART_BEG; i < RC_COUNT; i++)
1786 { 1841 {
1787 min_it (rc[i].col, ncol - 1); 1842 min_it (rc[i].col, ncol - 1);
1788 min_it (rc[i].row, nrow - 1); 1843 min_it (rc[i].row, nrow - 1);
1789 } 1844 }
1790 1845// TODO: this line somehow causes segfault if scr_expose() is called just after resize
1791 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1846 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1792 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); 1847 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1);
1793 1848
1794 num_scr_allow = 0; 1849 num_scr_allow = 0;
1795 1850
1800/* ------------------------------------------------------------------------- */ 1855/* ------------------------------------------------------------------------- */
1801/* 1856/*
1802 * Refresh the entire screen 1857 * Refresh the entire screen
1803 */ 1858 */
1804void 1859void
1805rxvt_term::scr_touch (bool refresh) 1860rxvt_term::scr_touch (bool refresh) NOTHROW
1806{ 1861{
1807 scr_expose (0, 0, width, height, refresh); 1862 scr_expose (0, 0, width, height, refresh);
1808} 1863}
1809 1864
1810/* ------------------------------------------------------------------------- */ 1865/* ------------------------------------------------------------------------- */
1811/* 1866/*
1812 * Move the display so that the line represented by scrollbar value Y is at 1867 * Move the display so that the line represented by scrollbar value Y is at
1813 * the top of the screen 1868 * the top of the screen
1814 */ 1869 */
1815void 1870void
1816rxvt_term::scr_move_to (int y, int len) 1871rxvt_term::scr_move_to (int y, int len) NOTHROW
1817{ 1872{
1818 scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1)); 1873 scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1));
1819} 1874}
1820 1875
1821/* ------------------------------------------------------------------------- */ 1876/* ------------------------------------------------------------------------- */
1822/* 1877/*
1823 * Page the screen up/down nlines 1878 * Page the screen up/down nlines
1824 * direction should be UP or DN 1879 * direction should be UP or DN
1825 */ 1880 */
1826bool 1881bool
1827rxvt_term::scr_page (enum page_dirn direction, int nlines) 1882rxvt_term::scr_page (enum page_dirn direction, int nlines) NOTHROW
1828{ 1883{
1829 int new_view_start = 1884 int new_view_start =
1830 direction == UP ? view_start - nlines 1885 direction == UP ? view_start - nlines
1831 : view_start + nlines; 1886 : view_start + nlines;
1832 1887
1833 return scr_changeview (new_view_start); 1888 return scr_changeview (new_view_start);
1834} 1889}
1835 1890
1836bool 1891bool
1837rxvt_term::scr_changeview (int new_view_start) 1892rxvt_term::scr_changeview (int new_view_start) NOTHROW
1838{ 1893{
1839 clamp_it (new_view_start, top_row, 0); 1894 clamp_it (new_view_start, top_row, 0);
1840 1895
1841 if (new_view_start == view_start) 1896 if (new_view_start == view_start)
1842 return false; 1897 return false;
1848 HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END)); 1903 HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END));
1849 1904
1850 return true; 1905 return true;
1851} 1906}
1852 1907
1853/* ------------------------------------------------------------------------- */ 1908#ifndef NO_BELL
1854void 1909void
1910rxvt_term::bell_cb (ev::timer &w, int revents)
1911{
1912 rvideo_bell = false;
1913 scr_rvideo_mode (rvideo_mode);
1914 refresh_check ();
1915}
1916#endif
1917
1918/* ------------------------------------------------------------------------- */
1919void
1855rxvt_term::scr_bell () 1920rxvt_term::scr_bell () NOTHROW
1856{ 1921{
1857#ifndef NO_BELL 1922#ifndef NO_BELL
1858 1923
1859# ifndef NO_MAPALERT 1924# ifndef NO_MAPALERT
1860# ifdef MAPALERT_OPTION 1925# ifdef MAPALERT_OPTION
1861 if (OPTION (Opt_mapAlert)) 1926 if (option (Opt_mapAlert))
1862# endif 1927# endif
1863 XMapWindow (display->display, parent[0]); 1928 XMapWindow (dpy, parent[0]);
1864# endif 1929# endif
1865 1930
1931# if ENABLE_FRILLS
1932 if (option (Opt_urgentOnBell))
1933 set_urgency (1);
1934# endif
1935
1866 if (OPTION (Opt_visualBell)) 1936 if (option (Opt_visualBell))
1867 { 1937 {
1868 scr_rvideo_mode (!rvideo); /* refresh also done */ 1938 rvideo_bell = true;
1939 scr_rvideo_mode (rvideo_mode);
1869 display->flush (); 1940 flush ();
1941
1870 rxvt_usleep (VISUAL_BELL_DURATION); 1942 bell_ev.start (VISUAL_BELL_DURATION);
1871 scr_rvideo_mode (!rvideo); /* refresh also done */
1872 } 1943 }
1873 else 1944 else
1874 XBell (display->display, 0); 1945 XBell (dpy, 0);
1875
1876#endif 1946#endif
1877} 1947}
1878 1948
1879/* ------------------------------------------------------------------------- */ 1949/* ------------------------------------------------------------------------- */
1880/* ARGSUSED */ 1950/* ARGSUSED */
1881void 1951void
1882rxvt_term::scr_printscreen (int fullhist) 1952rxvt_term::scr_printscreen (int fullhist) NOTHROW
1883{ 1953{
1884#ifdef PRINTPIPE 1954#ifdef PRINTPIPE
1885 int nrows, row_start; 1955 int nrows, row_start;
1886 FILE *fd; 1956 FILE *fd = popen_printer ();
1887 1957
1888 if ((fd = popen_printer ()) == NULL) 1958 if (!fd)
1889 return; 1959 return;
1890 1960
1891 if (fullhist) 1961 if (fullhist)
1892 { 1962 {
1893 nrows = nrow - top_row; 1963 nrows = nrow - top_row;
1936 * Refresh the screen 2006 * Refresh the screen
1937 * drawn_text/drawn_rend contain the screen information before the update. 2007 * drawn_text/drawn_rend contain the screen information before the update.
1938 * screen.text/screen.rend contain what the screen will change to. 2008 * screen.text/screen.rend contain what the screen will change to.
1939 */ 2009 */
1940void 2010void
1941rxvt_term::scr_refresh () 2011rxvt_term::scr_refresh () NOTHROW
1942{ 2012{
1943 unsigned char must_clear, /* use draw_string not draw_image_string */
1944 showcursor; /* show the cursor */
1945 int16_t col, row, /* column/row we're processing */ 2013 int16_t col, row, /* column/row we're processing */
1946 ocrow; /* old cursor row */ 2014 ocrow; /* old cursor row */
1947 int i; /* tmp */ 2015 int i; /* tmp */
1948#ifndef NO_CURSORCOLOR 2016#ifndef NO_CURSORCOLOR
1949 rend_t cc1; /* store colours at cursor position (s) */ 2017 rend_t cc1; /* store colours at cursor position (s) */
1950#endif 2018#endif
1951 rend_t *crp; // cursor rendition pointer 2019 rend_t *crp; // cursor rendition pointer
2020 rend_t ccol1, /* Cursor colour */
2021 ccol2; /* Cursor colour2 */
1952 2022
1953 want_refresh = 0; /* screen is current */ 2023 want_refresh = 0; /* screen is current */
1954 2024
1955 if (refresh_type == NO_REFRESH || !mapped) 2025 if (refresh_type == NO_REFRESH || !mapped)
1956 return; 2026 return;
1957 2027
1958 /* 2028 /*
1959 * A: set up vars 2029 * A: set up vars
1960 */ 2030 */
1961 must_clear = 0;
1962 refresh_count = 0; 2031 refresh_count = 0;
1963 2032
1964#if XPM_BACKGROUND 2033 unsigned int old_screen_flags = screen.flags;
2034 char have_bg = 0;
2035#ifdef HAVE_BG_PIXMAP
1965 must_clear |= bgPixmap.pixmap != None; 2036 have_bg = bgPixmap.pixmap != None;
1966#endif
1967#if TRANSPARENT
1968 must_clear |= OPTION (Opt_transparent) && am_transparent;
1969#endif 2037#endif
1970 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2038 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1971 2039
1972 /* 2040 /*
1973 * B: reverse any characters which are selected 2041 * B: reverse any characters which are selected
1974 */ 2042 */
1975 scr_reverse_selection (); 2043 scr_reverse_selection ();
2044
2045 HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
2046#if ENABLE_OVERLAY
2047 scr_swap_overlay ();
2048#endif
2049
2050 char showcursor = screen.flags & Screen_VisibleCursor;
1976 2051
1977 /* 2052 /*
1978 * C: set the cursor character (s) 2053 * C: set the cursor character (s)
1979 */ 2054 */
1980 { 2055 {
1981 unsigned char setoldcursor; 2056 unsigned char setoldcursor;
1982 rend_t ccol1, /* Cursor colour */
1983 ccol2; /* Cursor colour2 */
1984 2057
1985 showcursor = (screen.flags & Screen_VisibleCursor);
1986#ifdef CURSOR_BLINK 2058#ifdef CURSOR_BLINK
1987 if (hidden_cursor) 2059 if (hidden_cursor)
1988 showcursor = 0; 2060 showcursor = 0;
1989#endif 2061#endif
1990 2062
1995 while (col && ROW(screen.cur.row).t[col] == NOCHAR) 2067 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
1996 col--; 2068 col--;
1997 2069
1998 crp = &ROW(screen.cur.row).r[col]; 2070 crp = &ROW(screen.cur.row).r[col];
1999 2071
2072#ifndef NO_CURSORCOLOR
2073 cc1 = *crp & (RS_fgMask | RS_bgMask);
2074 if (ISSET_PIXCOLOR (Color_cursor))
2075 ccol1 = Color_cursor;
2076 else
2077#endif
2078#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2079 ccol1 = fgcolor_of (rstyle);
2080#else
2081 ccol1 = Color_fg;
2082#endif
2083
2084#ifndef NO_CURSORCOLOR
2085 if (ISSET_PIXCOLOR (Color_cursor2))
2086 ccol2 = Color_cursor2;
2087 else
2088#endif
2089#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2090 ccol2 = bgcolor_of (rstyle);
2091#else
2092 ccol2 = Color_bg;
2093#endif
2094
2000 if (showcursor && focus) 2095 if (showcursor && focus)
2001 { 2096 {
2002 if (OPTION (Opt_cursorUnderline)) 2097 if (option (Opt_cursorUnderline))
2003 *crp ^= RS_Uline; 2098 *crp ^= RS_Uline;
2004 else 2099 else
2005 { 2100 {
2006 *crp ^= RS_RVid; 2101 *crp ^= RS_RVid;
2007
2008#ifndef NO_CURSORCOLOR
2009 cc1 = *crp & (RS_fgMask | RS_bgMask);
2010 if (ISSET_PIXCOLOR (Color_cursor))
2011 ccol1 = Color_cursor;
2012 else
2013#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2014 ccol1 = fgcolor_of (rstyle);
2015#else
2016 ccol1 = Color_fg;
2017#endif
2018 if (ISSET_PIXCOLOR (Color_cursor2))
2019 ccol2 = Color_cursor2;
2020 else
2021#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2022 ccol2 = bgcolor_of (rstyle);
2023#else
2024 ccol2 = Color_bg;
2025#endif
2026 *crp = SET_FGCOLOR (*crp, ccol1); 2102 *crp = SET_FGCOLOR (*crp, ccol1);
2027 *crp = SET_BGCOLOR (*crp, ccol2); 2103 *crp = SET_BGCOLOR (*crp, ccol2);
2028#endif
2029 } 2104 }
2030 } 2105 }
2031 } 2106 }
2032 2107
2033 /* make sure no outline cursor is left around */ 2108 /* make sure no outline cursor is left around */
2060 oldcursor.col = screen.cur.col; 2135 oldcursor.col = screen.cur.col;
2061 } 2136 }
2062 } 2137 }
2063 } 2138 }
2064 2139
2065 HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END));
2066#if ENABLE_OVERLAY
2067 scr_swap_overlay ();
2068#endif
2069
2070#ifndef NO_SLOW_LINK_SUPPORT 2140#ifndef NO_SLOW_LINK_SUPPORT
2071 /* 2141 /*
2072 * D: CopyArea pass - very useful for slower links 2142 * D: CopyArea pass - very useful for slower links
2073 * This has been deliberately kept simple. 2143 * This has been deliberately kept simple.
2074 */ 2144 */
2075 if (!display->is_local 2145 if (!display->is_local
2076 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr 2146 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr
2077 && abs (num_scr) < nrow && !must_clear) 2147 && abs (num_scr) < nrow && !have_bg)
2078 { 2148 {
2079 int16_t nits; 2149 int16_t nits;
2150 int i = num_scr;
2080 int j; 2151 int j;
2081 int len, wlen; 2152 int len, wlen;
2082 dLocal (int, num_scr); 2153 dLocal (int, num_scr);
2083 2154
2084 j = nrow; 2155 j = nrow;
2085 wlen = len = -1; 2156 wlen = len = -1;
2086 row = i > 0 ? 0 : j - 1; 2157 row = i > 0 ? 0 : j - 1;
2158
2087 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2159 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2088 { 2160 {
2089 if (row + i >= 0 && row + i < nrow && row + i != ocrow) 2161 if (row + i >= 0 && row + i < nrow && row + i != ocrow)
2090 { 2162 {
2091 line_t s = ROW(view_start + row); 2163 line_t s = ROW(view_start + row);
2112 wlen = row; 2184 wlen = row;
2113 continue; 2185 continue;
2114 } 2186 }
2115 } 2187 }
2116 2188
2117 if (len != -1) 2189 if (len >= 0)
2118 { 2190 {
2119 /* also comes here at end if needed because of >= above */ 2191 /* also comes here at end if needed because of >= above */
2120 if (wlen < len) 2192 if (wlen < len)
2121 ::swap (wlen, len); 2193 ::swap (wlen, len);
2122 2194
2195 XGCValues gcv;
2196
2197 gcv.graphics_exposures = 1; XChangeGC (dpy, gc, GCGraphicsExposures, &gcv);
2123 XCopyArea (display->display, vt, vt, 2198 XCopyArea (dpy, vt, vt,
2124 gc, 0, Row2Pixel (len + i), 2199 gc, 0, Row2Pixel (len + i),
2125 (unsigned int)this->width, 2200 (unsigned int)this->width,
2126 (unsigned int)Height2Pixel (wlen - len + 1), 2201 (unsigned int)Height2Pixel (wlen - len + 1),
2127 0, Row2Pixel (len)); 2202 0, Row2Pixel (len));
2203 gcv.graphics_exposures = 0; XChangeGC (dpy, gc, GCGraphicsExposures, &gcv);
2204
2128 len = -1; 2205 len = -1;
2129 } 2206 }
2130 } 2207 }
2131 } 2208 }
2132#endif 2209#endif
2156 continue; 2233 continue;
2157 2234
2158 // redraw one or more characters 2235 // redraw one or more characters
2159 2236
2160 // seek to the beginning of wide characters 2237 // seek to the beginning of wide characters
2161 while (stp[col] == NOCHAR && col > 0) 2238 while (expect_false (stp[col] == NOCHAR && col > 0))
2162 --col; 2239 --col;
2163 2240
2164 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2241 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2165 text_t *text = stp + col; 2242 text_t *text = stp + col;
2166 int count = 1; 2243 int count = 1;
2188 count++; 2265 count++;
2189 2266
2190 if (stp[col] != dtp[col] 2267 if (stp[col] != dtp[col]
2191 || !RS_SAME (srp[col], drp[col])) 2268 || !RS_SAME (srp[col], drp[col]))
2192 { 2269 {
2193 if (must_clear && (i++ > count / 2)) 2270 if (have_bg && (i++ > count / 2))
2194 break; 2271 break;
2195 2272
2196 dtp[col] = stp[col]; 2273 dtp[col] = stp[col];
2197 drp[col] = rend; 2274 drp[col] = rend;
2198 i = 0; 2275 i = 0;
2199 } 2276 }
2200 else if (must_clear || (stp[col] != ' ' && ++i >= 16)) 2277 else if (have_bg || (stp[col] != ' ' && ++i >= 16))
2201 break; 2278 break;
2202 } 2279 }
2203 2280
2204 col--; /* went one too far. move back */ 2281 col--; /* went one too far. move back */
2205 count -= i; /* dump any matching trailing chars */ 2282 count -= i; /* dump any matching trailing chars */
2206 2283
2207 // sometimes we optimize away the trailing NOCHAR's, add them back 2284 // sometimes we optimize away the trailing NOCHAR's, add them back
2208 while (i && text[count] == NOCHAR) 2285 while (expect_false (i && text[count] == NOCHAR))
2209 count++, i--; 2286 count++, i--;
2210 2287
2211 /* 2288 /*
2212 * Determine the attributes for the string 2289 * Determine the attributes for the string
2213 */ 2290 */
2214 int fore = fgcolor_of (rend); // desired foreground 2291 int fore = fgcolor_of (rend); // desired foreground
2215 int back = bgcolor_of (rend); // desired background 2292 int back = bgcolor_of (rend); // desired background
2216 2293
2217 // only do special processing if any attributes are set, which is unlikely 2294 // only do special processing if any attributes are set, which is unlikely
2218 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2295 if (expect_false (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)))
2219 { 2296 {
2220#if ENABLE_STYLES
2221 // force redraw after "careful" characters to avoid pixel droppings
2222 if (srp[col] & RS_Careful && col < ncol - 1 && 0)
2223 drp[col + 1] = ~srp[col + 1];
2224
2225 // include previous careful character(s) if possible, looks nicer (best effort...)
2226 while (text > stp
2227 && srp[text - stp - 1] & RS_Careful
2228 && RS_SAME (rend, srp[text - stp - 1]))
2229 text--, count++, xpixel -= fwidth;
2230#endif
2231
2232 bool invert = rend & RS_RVid; 2297 bool invert = rend & RS_RVid;
2233 2298
2234#ifndef NO_BOLD_UNDERLINE_REVERSE 2299#ifndef NO_BOLD_UNDERLINE_REVERSE
2235 if (rend & RS_Bold
2236 && fore == Color_fg) 2300 if (rend & RS_Bold && fore == Color_fg)
2237 { 2301 {
2238 if (ISSET_PIXCOLOR (Color_BD)) 2302 if (ISSET_PIXCOLOR (Color_BD))
2239 fore = Color_BD; 2303 fore = Color_BD;
2240# if !ENABLE_STYLES 2304# if !ENABLE_STYLES
2241 else 2305 else
2242 invert = !invert; 2306 invert = !invert;
2243# endif 2307# endif
2244 } 2308 }
2245 2309
2246 if (rend & RS_Italic 2310 if (rend & RS_Italic && fore == Color_fg)
2247 && fore == Color_fg)
2248 { 2311 {
2249 if (ISSET_PIXCOLOR (Color_IT)) 2312 if (ISSET_PIXCOLOR (Color_IT))
2250 fore = Color_IT; 2313 fore = Color_IT;
2251# if !ENABLE_STYLES 2314# if !ENABLE_STYLES
2252 else 2315 else
2253 invert = !invert; 2316 invert = !invert;
2254# endif 2317# endif
2255 } 2318 }
2256 2319
2257 if (rend & RS_Uline && ISSET_PIXCOLOR (Color_UL)) 2320 if (rend & RS_Uline && fore == Color_fg && ISSET_PIXCOLOR (Color_UL))
2258 fore = Color_UL; 2321 fore = Color_UL;
2259#endif 2322#endif
2260 2323
2261 if (invert) 2324 if (invert)
2262 { 2325 {
2326#ifdef OPTION_HC
2327 if ((showcursor && row == screen.cur.row && text - stp == screen.cur.col)
2328 || !ISSET_PIXCOLOR (Color_HC))
2329#endif
2330 /* invert the column if no highlightColor is set or it is the
2331 * current cursor column */
2263 ::swap (fore, back); 2332 ::swap (fore, back);
2333#ifdef OPTION_HC
2334 else if (ISSET_PIXCOLOR (Color_HC))
2335 back = Color_HC;
2336#endif
2264 2337
2265#ifndef NO_BOLD_UNDERLINE_REVERSE 2338#ifndef NO_BOLD_UNDERLINE_REVERSE
2339# ifndef OPTION_HC
2266 if (ISSET_PIXCOLOR (Color_RV)) 2340 if (ISSET_PIXCOLOR (Color_RV))
2267 back = Color_RV; 2341 back = Color_RV;
2268 2342# endif
2269 if (fore == back) 2343 if (fore == back)
2270 { 2344 {
2271 fore = Color_bg; 2345 fore = Color_bg;
2272 back = Color_fg; 2346 back = Color_fg;
2273 } 2347 }
2275 } 2349 }
2276 2350
2277#ifdef TEXT_BLINK 2351#ifdef TEXT_BLINK
2278 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg)) 2352 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg))
2279 { 2353 {
2280 if (!text_blink_ev.active) 2354 if (!text_blink_ev.is_active ())
2281 { 2355 {
2282 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2356 text_blink_ev.again ();
2283 hidden_text = 0; 2357 hidden_text = 0;
2284 } 2358 }
2285 else if (hidden_text) 2359 else if (hidden_text)
2286 fore = back; 2360 fore = back;
2287 } 2361 }
2288#endif 2362#endif
2363
2364#if ENABLE_STYLES
2365 // "careful" (too wide) character handling
2366
2367 // include previous careful character(s) if possible, looks nicer (best effort...)
2368 while (text > stp
2369 && srp[text - stp - 1] & RS_Careful
2370 && RS_SAME (rend, srp[text - stp - 1]))
2371 text--, count++, xpixel -= fwidth;
2372
2373 // force redraw after "careful" characters to avoid pixel droppings
2374 for (int i = 0; srp[col + i] & RS_Careful && col + i < ncol - 1; i++)
2375 drp[col + i + 1] = srp[col + i + 1] ^ RS_redraw;
2376
2377 // force redraw before "careful" characters to avoid pixel droppings
2378 for (int i = 0; srp[text - stp - i] & RS_Careful && text - i > stp; i++)
2379 drp[text - stp - i - 1] = srp[text - stp - i - 1] ^ RS_redraw;
2380#endif
2289 } 2381 }
2290 2382
2291 /* 2383 /*
2292 * Actually do the drawing of the string here 2384 * Actually do the drawing of the string here
2293 */ 2385 */
2294 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2386 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2295 2387
2296 if (back == fore) 2388 if (expect_true (have_bg && back == Color_bg))
2297 font->clear_rect (*drawable, xpixel, ypixel,
2298 fwidth * count, fheight,
2299 back);
2300 else if (back == Color_bg)
2301 { 2389 {
2302 if (must_clear) 2390 // this is very ugly, maybe push it into ->draw?
2303 {
2304 CLEAR_CHARS (xpixel, ypixel, count);
2305 2391
2306 for (i = 0; i < count; i++) /* don't draw empty strings */ 2392 for (i = 0; i < count; i++) /* don't draw empty strings */
2307 if (text[i] != ' ') 2393 if (text[i] != ' ')
2308 { 2394 {
2309 font->draw (*drawable, xpixel, ypixel, text, count, fore, -1); 2395 font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_transparent);
2310 break; 2396 goto did_clear;
2311 }
2312 } 2397 }
2313 else 2398
2314 font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_bg); 2399 CLEAR_CHARS (xpixel, ypixel, count);
2400 did_clear: ;
2315 } 2401 }
2316 else 2402 else
2317 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2403 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2318 2404
2319 if (rend & RS_Uline && font->descent > 1 && fore != back) 2405 if (expect_false (rend & RS_Uline && font->descent > 1 && fore != back))
2320 { 2406 {
2321#if ENABLE_FRILLS 2407#if ENABLE_FRILLS
2322 if (ISSET_PIXCOLOR (Color_underline)) 2408 if (ISSET_PIXCOLOR (Color_underline))
2323 XSetForeground (display->display, gc, pix_colors[Color_underline]); 2409 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2324 else 2410 else
2325#endif 2411#endif
2326 XSetForeground (display->display, gc, pix_colors[fore]); 2412 XSetForeground (dpy, gc, pix_colors[fore]);
2327 2413
2328 XDrawLine (display->display, drawBuffer, gc, 2414 XDrawLine (dpy, vt, gc,
2329 xpixel, ypixel + font->ascent + 1, 2415 xpixel, ypixel + font->ascent + 1,
2330 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2416 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2331 } 2417 }
2332 } /* for (col....) */ 2418 } /* for (col....) */
2333 } /* for (row....) */ 2419 } /* for (row....) */
2334 2420
2335#if ENABLE_OVERLAY
2336 scr_swap_overlay ();
2337#endif
2338 HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2339
2340 /* 2421 /*
2341 * G: cleanup cursor and display outline cursor if necessary 2422 * G: cleanup cursor and display outline cursor if necessary
2342 */ 2423 */
2343 if (showcursor) 2424 if (showcursor)
2344 { 2425 {
2345 if (focus) 2426 if (focus)
2346 { 2427 {
2347 if (OPTION (Opt_cursorUnderline)) 2428 if (option (Opt_cursorUnderline))
2348 *crp ^= RS_Uline; 2429 *crp ^= RS_Uline;
2349 else 2430 else
2350 { 2431 {
2351 *crp ^= RS_RVid; 2432 *crp ^= RS_RVid;
2352#ifndef NO_CURSORCOLOR 2433#ifndef NO_CURSORCOLOR
2366 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR) 2447 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2367 cursorwidth++; 2448 cursorwidth++;
2368 2449
2369#ifndef NO_CURSORCOLOR 2450#ifndef NO_CURSORCOLOR
2370 if (ISSET_PIXCOLOR (Color_cursor)) 2451 if (ISSET_PIXCOLOR (Color_cursor))
2371 XSetForeground (display->display, gc, pix_colors[Color_cursor]); 2452 XSetForeground (dpy, gc, pix_colors[Color_cursor]);
2453 else
2372#endif 2454#endif
2455 XSetForeground (dpy, gc, pix_colors[ccol1]);
2373 2456
2374 XDrawRectangle (display->display, drawBuffer, gc, 2457 XDrawRectangle (dpy, vt, gc,
2375 Col2Pixel (col), 2458 Col2Pixel (col),
2376 Row2Pixel (oldcursor.row), 2459 Row2Pixel (oldcursor.row),
2377 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2460 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2378 (unsigned int) (Height2Pixel (1) - lineSpace - 1)); 2461 (unsigned int) (Height2Pixel (1) - lineSpace - 1));
2379 } 2462 }
2380 } 2463 }
2381 2464
2382 /* 2465 /*
2383 * H: cleanup selection 2466 * H: cleanup selection
2384 */ 2467 */
2468#if ENABLE_OVERLAY
2469 scr_swap_overlay ();
2470#endif
2471 HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END));
2472
2385 scr_reverse_selection (); 2473 scr_reverse_selection ();
2386 2474
2475 screen.flags = old_screen_flags;
2387 num_scr = 0; 2476 num_scr = 0;
2388 num_scr_allow = 1; 2477 num_scr_allow = 1;
2389} 2478}
2390 2479
2391void 2480void
2392rxvt_term::scr_remap_chars (line_t &l) 2481rxvt_term::scr_remap_chars (line_t &l) NOTHROW
2393{ 2482{
2394 if (!l.t) 2483 if (!l.t)
2395 return; 2484 return;
2396 2485
2397 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant 2486 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant
2399 for (int i = ncol; i--; ) 2488 for (int i = ncol; i--; )
2400 l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i])); 2489 l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i]));
2401} 2490}
2402 2491
2403void 2492void
2404rxvt_term::scr_remap_chars () 2493rxvt_term::scr_remap_chars () NOTHROW
2405{ 2494{
2406 for (int i = total_rows; i--; ) 2495 for (int i = total_rows; i--; )
2407 scr_remap_chars (row_buf [i]); 2496 scr_remap_chars (row_buf [i]);
2408 2497
2409 for (int i = nrow; i--; ) 2498 for (int i = nrow; i--; )
2412 scr_remap_chars (swap_buf [i]); 2501 scr_remap_chars (swap_buf [i]);
2413 } 2502 }
2414} 2503}
2415 2504
2416void 2505void
2417rxvt_term::scr_recolour () 2506rxvt_term::scr_recolour () NOTHROW
2418{ 2507{
2419 if (1 2508#ifdef HAVE_BG_PIXMAP
2420#if TRANSPARENT 2509 bgPixmap.apply ();
2421 && !am_transparent 2510#else
2422#endif 2511
2423#if XPM_BACKGROUND
2424 && !bgPixmap.pixmap
2425#endif
2426 )
2427 {
2428 XSetWindowBackground (display->display, parent[0], pix_colors[Color_border]); 2512 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]);
2429 XClearWindow (display->display, parent[0]); 2513 XClearWindow (dpy, parent[0]);
2430 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); 2514 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2431#if HAVE_SCROLLBARS 2515
2432 if (scrollBar.win) 2516 if (scrollBar.win)
2433 { 2517 {
2434 XSetWindowBackground (display->display, scrollBar.win, pix_colors[Color_border]); 2518 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2435 scrollBar.setIdle (); 2519 scrollBar.state = STATE_IDLE;
2436 scrollbar_show (0); 2520 scrollBar.show (0);
2437 }
2438#endif
2439 } 2521 }
2440 2522
2523#endif
2524
2525 /* bgPixmap.apply () does not do the following : */
2441 scr_clear (); 2526 scr_clear ();
2442 scr_touch (true); 2527 scr_touch (true);
2443 want_refresh = 1; 2528 want_refresh = 1;
2444} 2529}
2445 2530
2446/* ------------------------------------------------------------------------- */ 2531/* ------------------------------------------------------------------------- */
2447void 2532void
2448rxvt_term::scr_clear (bool really) 2533rxvt_term::scr_clear (bool really) NOTHROW
2449{ 2534{
2450 if (!mapped) 2535 if (!mapped)
2451 return; 2536 return;
2452 2537
2453 num_scr_allow = 0; 2538 num_scr_allow = 0;
2454 want_refresh = 1; 2539 want_refresh = 1;
2455 2540
2456 if (really) 2541 if (really)
2457 XClearWindow (display->display, vt); 2542 XClearWindow (dpy, vt);
2458} 2543}
2459 2544
2460void 2545void
2461rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) 2546rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) NOTHROW
2462{ 2547{
2463 int view_end = view_start + nrow; 2548 int view_end = view_start + nrow;
2464 int row, col; 2549 int row, col;
2465 2550
2466 for (row = max (beg_row, view_start); row <= min (end_row, view_end); row++) 2551 for (row = max (beg_row, view_start); row <= min (end_row, view_end); row++)
2478 srp[col] ^= rstyle2; 2563 srp[col] ^= rstyle2;
2479 } 2564 }
2480} 2565}
2481 2566
2482void 2567void
2483rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle) 2568rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle) NOTHROW
2484{ 2569{
2485 int view_end = view_start + nrow; 2570 int view_end = view_start + nrow;
2486 int row, col; 2571 int row, col;
2487 2572
2488 if (beg_row >= view_start) 2573 if (beg_row >= view_start)
2505 srp[col] ^= rstyle; 2590 srp[col] ^= rstyle;
2506} 2591}
2507 2592
2508/* ------------------------------------------------------------------------- */ 2593/* ------------------------------------------------------------------------- */
2509void 2594void
2510rxvt_term::scr_reverse_selection () 2595rxvt_term::scr_reverse_selection () NOTHROW
2511{ 2596{
2512 if (selection.op 2597 if (selection.op
2513 && current_screen == selection.screen 2598 && current_screen == selection.screen
2514 && selection.end.row >= view_start) 2599 && selection.end.row >= view_start)
2515 { 2600 {
2516#if ENABLE_FRILLS 2601#if !ENABLE_MINIMAL
2517 if (selection.rect) 2602 if (selection.rect)
2518 scr_xor_rect (selection.beg.row, selection.beg.col, 2603 scr_xor_rect (selection.beg.row, selection.beg.col,
2519 selection.end.row, selection.end.col, 2604 selection.end.row, selection.end.col,
2520 RS_RVid, RS_RVid | RS_Uline); 2605 RS_RVid, RS_RVid | RS_Uline);
2521 else 2606 else
2531 * Dump the whole scrollback and screen to the passed filedescriptor. The 2616 * Dump the whole scrollback and screen to the passed filedescriptor. The
2532 * invoking routine must close the fd. 2617 * invoking routine must close the fd.
2533 */ 2618 */
2534#if 0 2619#if 0
2535void 2620void
2536rxvt_term::scr_dump (int fd) 2621rxvt_term::scr_dump (int fd) NOTHROW
2537{ 2622{
2538 int row, wrote; 2623 int row, wrote;
2539 unsigned int width, towrite; 2624 unsigned int width, towrite;
2540 char r1[] = "\n"; 2625 char r1[] = "\n";
2541 2626
2542 for (row = saveLines - nsaved; 2627 for (row = saveLines + top_row;
2543 row < saveLines + nrow - 1; row++) 2628 row < saveLines + nrow - 1; row++)
2544 { 2629 {
2545 width = row_buf[row].l >= 0 ? row_buf[row].l 2630 width = row_buf[row].l >= 0 ? row_buf[row].l
2546 : ncol; 2631 : ncol;
2547 for (towrite = width; towrite; towrite -= wrote) 2632 for (towrite = width; towrite; towrite -= wrote)
2560 2645
2561/* ------------------------------------------------------------------------- * 2646/* ------------------------------------------------------------------------- *
2562 * CHARACTER SELECTION * 2647 * CHARACTER SELECTION *
2563 * ------------------------------------------------------------------------- */ 2648 * ------------------------------------------------------------------------- */
2564void 2649void
2565rxvt_term::selection_check (int check_more) 2650rxvt_term::selection_check (int check_more) NOTHROW
2566{ 2651{
2567 row_col_t pos; 2652 row_col_t pos;
2568 2653
2569 if (!selection.op) 2654 if (!selection.op)
2570 return; 2655 return;
2591/* ------------------------------------------------------------------------- */ 2676/* ------------------------------------------------------------------------- */
2592/* 2677/*
2593 * Paste a selection direct to the command fd 2678 * Paste a selection direct to the command fd
2594 */ 2679 */
2595void 2680void
2596rxvt_term::paste (char *data, unsigned int len) 2681rxvt_term::paste (char *data, unsigned int len) NOTHROW
2597{ 2682{
2598 /* convert normal newline chars into common keyboard Return key sequence */ 2683 /* convert normal newline chars into common keyboard Return key sequence */
2599 for (unsigned int i = 0; i < len; i++) 2684 for (unsigned int i = 0; i < len; i++)
2600 if (data[i] == C0_LF) 2685 if (data[i] == C0_LF)
2601 data[i] = C0_CR; 2686 data[i] = C0_CR;
2602 2687
2688 if (priv_modes & PrivMode_BracketPaste)
2689 tt_printf ("\e[200~");
2690
2603 tt_write (data, len); 2691 tt_write (data, len);
2692
2693 if (priv_modes & PrivMode_BracketPaste)
2694 tt_printf ("\e[201~");
2604} 2695}
2605 2696
2606/* ------------------------------------------------------------------------- */ 2697/* ------------------------------------------------------------------------- */
2607/* 2698/*
2608 * Respond to a notification that a primary selection has been sent 2699 * Respond to a notification that a primary selection has been sent
2609 * EXT: SelectionNotify 2700 * EXT: SelectionNotify
2610 */ 2701 */
2611void 2702void
2612rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) 2703rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) NOTHROW
2613{ 2704{
2614 if (prop == None) /* check for failed XConvertSelection */ 2705 if (prop == None) /* check for failed XConvertSelection */
2615 { 2706 {
2616 if ((selection_type & Sel_CompoundText)) 2707 if ((selection_type & Sel_CompoundText))
2617 { 2708 {
2637 } 2728 }
2638 2729
2639 unsigned long bytes_after; 2730 unsigned long bytes_after;
2640 XTextProperty ct; 2731 XTextProperty ct;
2641 2732
2642 if (XGetWindowProperty (display->display, win, prop, 2733 if (XGetWindowProperty (dpy, win, prop,
2643 0, PROP_SIZE / 4, 2734 0, PROP_SIZE / 4,
2644 delete_prop, AnyPropertyType, 2735 delete_prop, AnyPropertyType,
2645 &ct.encoding, &ct.format, 2736 &ct.encoding, &ct.format,
2646 &ct.nitems, &bytes_after, 2737 &ct.nitems, &bytes_after,
2647 &ct.value) != Success) 2738 &ct.value) != Success)
2656 if (bytes_after) 2747 if (bytes_after)
2657 { 2748 {
2658 // fetch and append remaining data 2749 // fetch and append remaining data
2659 XTextProperty ct2; 2750 XTextProperty ct2;
2660 2751
2661 if (XGetWindowProperty (display->display, win, prop, 2752 if (XGetWindowProperty (dpy, win, prop,
2662 ct.nitems / 4, (bytes_after + 3) / 4, 2753 ct.nitems / 4, (bytes_after + 3) / 4,
2663 delete_prop, AnyPropertyType, 2754 delete_prop, AnyPropertyType,
2664 &ct2.encoding, &ct2.format, 2755 &ct2.encoding, &ct2.format,
2665 &ct2.nitems, &bytes_after, 2756 &ct2.nitems, &bytes_after,
2666 &ct2.value) != Success) 2757 &ct2.value) != Success)
2679 2770
2680 if (ct.encoding == xa[XA_INCR]) 2771 if (ct.encoding == xa[XA_INCR])
2681 { 2772 {
2682 // INCR selection, start handshake 2773 // INCR selection, start handshake
2683 if (!delete_prop) 2774 if (!delete_prop)
2684 XDeleteProperty (display->display, win, prop); 2775 XDeleteProperty (dpy, win, prop);
2685 2776
2686 selection_wait = Sel_incr; 2777 selection_wait = Sel_incr;
2687 incr_buf_fill = 0; 2778 incr_buf_fill = 0;
2688 incr_ev.start (NOW + 10); 2779 incr_ev.start (10);
2689 2780
2690 goto bailout; 2781 goto bailout;
2691 } 2782 }
2692 2783
2693 if (ct.nitems == 0) 2784 if (ct.nitems == 0)
2702 ct.nitems = incr_buf_fill; 2793 ct.nitems = incr_buf_fill;
2703 incr_buf = 0; 2794 incr_buf = 0;
2704 incr_buf_size = 0; 2795 incr_buf_size = 0;
2705 incr_ev.stop (); 2796 incr_ev.stop ();
2706 } 2797 }
2707 else 2798 else
2708 { 2799 {
2709 if (selection_wait == Sel_normal 2800 if (selection_wait == Sel_normal
2710 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2801 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2711 { 2802 {
2712 /* 2803 /*
2719 goto bailout; 2810 goto bailout;
2720 } 2811 }
2721 } 2812 }
2722 else if (selection_wait == Sel_incr) 2813 else if (selection_wait == Sel_incr)
2723 { 2814 {
2724 incr_ev.start (NOW + 10); 2815 incr_ev.start (10);
2725 2816
2726 while (incr_buf_fill + ct.nitems > incr_buf_size) 2817 while (incr_buf_fill + ct.nitems > incr_buf_size)
2727 { 2818 {
2728 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024; 2819 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2729 incr_buf = (char *)realloc (incr_buf, incr_buf_size); 2820 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2736 } 2827 }
2737 2828
2738 char **cl; 2829 char **cl;
2739 int cr; 2830 int cr;
2740 2831
2741#if ENABLE_FRILLS 2832#if !ENABLE_MINIMAL
2742 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 2833 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2743 // so recode it manually 2834 // so recode it manually
2744 if (ct.encoding == xa[XA_UTF8_STRING]) 2835 if (ct.encoding == xa[XA_UTF8_STRING])
2745 { 2836 {
2746 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); 2837 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2750 paste (s, strlen (s)); 2841 paste (s, strlen (s));
2751 free (s); 2842 free (s);
2752 } 2843 }
2753 else 2844 else
2754#endif 2845#endif
2755 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 2846 if (XmbTextPropertyToTextList (dpy, &ct, &cl, &cr) >= 0
2756 && cl) 2847 && cl)
2757 { 2848 {
2758 for (int i = 0; i < cr; i++) 2849 for (int i = 0; i < cr; i++)
2759 paste (cl[i], strlen (cl[i])); 2850 paste (cl[i], strlen (cl[i]));
2760 2851
2769 if (selection_wait == Sel_normal) 2860 if (selection_wait == Sel_normal)
2770 selection_wait = Sel_none; 2861 selection_wait = Sel_none;
2771} 2862}
2772 2863
2773void 2864void
2774rxvt_term::incr_cb (time_watcher &w) 2865rxvt_term::incr_cb (ev::timer &w, int revents) NOTHROW
2775{ 2866{
2776 selection_wait = Sel_none; 2867 selection_wait = Sel_none;
2777 2868
2778 incr_buf_size = 0; 2869 incr_buf_size = 0;
2779 free (incr_buf); 2870 free (incr_buf);
2780 2871
2781 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 2872 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2782} 2873}
2783 2874
2784void 2875void
2785rxvt_term::selection_property (Window win, Atom prop) 2876rxvt_term::selection_property (Window win, Atom prop) NOTHROW
2786{ 2877{
2787 if (prop == None || selection_wait != Sel_incr) 2878 if (prop == None || selection_wait != Sel_incr)
2788 return; 2879 return;
2789 2880
2790 selection_paste (win, prop, true); 2881 selection_paste (win, prop, true);
2791} 2882}
2792 2883
2793/* ------------------------------------------------------------------------- */ 2884/* ------------------------------------------------------------------------- */
2794/* 2885/*
2795 * Request the current selection: 2886 * Request the current selection:
2796 * Order: > internal selection if available 2887 * Order: > internal selection if available
2797 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+) 2888 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+)
2798 * > CUT_BUFFER0 2889 * > CUT_BUFFER0
2799 * (+) if ownership is claimed but property is empty, rxvt_selection_paste () 2890 * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
2800 * will auto fallback to CUT_BUFFER0 2891 * will auto fallback to CUT_BUFFER0
2801 * EXT: button 2 release 2892 * EXT: button 2 release
2802 */ 2893 */
2803void 2894void
2804rxvt_term::selection_request (Time tm) 2895rxvt_term::selection_request (Time tm, int selnum) NOTHROW
2805{ 2896{
2806 if (selection.text) 2897 if (selection.text && selnum == Sel_Primary)
2898 {
2807 { /* internal selection */ 2899 /* internal selection */
2808 char *str = rxvt_wcstombs (selection.text, selection.len); 2900 char *str = rxvt_wcstombs (selection.text, selection.len);
2809 paste (str, strlen (str)); 2901 paste (str, strlen (str));
2810 free (str); 2902 free (str);
2811 return; 2903 return;
2812 } 2904 }
2813 else 2905 else
2814 { 2906 {
2815 int i;
2816
2817 selection_request_time = tm; 2907 selection_request_time = tm;
2818 selection_wait = Sel_normal; 2908 selection_wait = Sel_normal;
2819 2909
2820 for (i = Sel_Primary; i <= Sel_Clipboard; i++)
2821 {
2822#if X_HAVE_UTF8_STRING 2910#if X_HAVE_UTF8_STRING
2823 selection_type = Sel_UTF8String; 2911 selection_type = Sel_UTF8String;
2824 if (selection_request_other (xa[XA_UTF8_STRING], i)) 2912 if (selection_request_other (xa[XA_UTF8_STRING], selnum))
2825 return; 2913 return;
2826#else 2914#else
2827 selection_type = Sel_CompoundText; 2915 selection_type = Sel_CompoundText;
2828 if (selection_request_other (xa[XA_COMPOUND_TEXT], i)) 2916 if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum))
2829 return; 2917 return;
2830#endif 2918#endif
2831 }
2832 } 2919 }
2833 2920
2834 selection_wait = Sel_none; /* don't loop in selection_paste () */ 2921 selection_wait = Sel_none; /* don't loop in selection_paste () */
2835 selection_paste (display->root, XA_CUT_BUFFER0, false); 2922 selection_paste (display->root, XA_CUT_BUFFER0, false);
2836} 2923}
2837 2924
2838int 2925int
2839rxvt_term::selection_request_other (Atom target, int selnum) 2926rxvt_term::selection_request_other (Atom target, int selnum) NOTHROW
2840{ 2927{
2841 Atom sel; 2928 Atom sel;
2842 2929
2843 selection_type |= selnum; 2930 selection_type |= selnum;
2844 2931
2847 else if (selnum == Sel_Secondary) 2934 else if (selnum == Sel_Secondary)
2848 sel = XA_SECONDARY; 2935 sel = XA_SECONDARY;
2849 else 2936 else
2850 sel = xa[XA_CLIPBOARD]; 2937 sel = xa[XA_CLIPBOARD];
2851 2938
2852 if (XGetSelectionOwner (display->display, sel) != None) 2939 if (XGetSelectionOwner (dpy, sel) != None)
2853 { 2940 {
2854 XConvertSelection (display->display, sel, target, xa[XA_VT_SELECTION], 2941 XConvertSelection (dpy, sel, target, xa[XA_VT_SELECTION],
2855 vt, selection_request_time); 2942 vt, selection_request_time);
2856 return 1; 2943 return 1;
2857 } 2944 }
2858 2945
2859 return 0; 2946 return 0;
2863/* 2950/*
2864 * Clear all selected text 2951 * Clear all selected text
2865 * EXT: SelectionClear 2952 * EXT: SelectionClear
2866 */ 2953 */
2867void 2954void
2868rxvt_term::selection_clear () 2955rxvt_term::selection_clear () NOTHROW
2869{ 2956{
2870 want_refresh = 1; 2957 want_refresh = 1;
2871 free (selection.text); 2958 free (selection.text);
2872 selection.text = NULL; 2959 selection.text = NULL;
2873 selection.len = 0; 2960 selection.len = 0;
2922 3009
2923 int end_col; 3010 int end_col;
2924 3011
2925 for (; row <= selection.end.row; row++, col = 0) 3012 for (; row <= selection.end.row; row++, col = 0)
2926 { 3013 {
2927#if ENABLE_FRILLS 3014#if !ENABLE_MINIMAL
2928 if (selection.rect) 3015 if (selection.rect)
2929 { 3016 {
2930 col = selection.beg.col; 3017 col = selection.beg.col;
2931 end_col = ncol + 1; 3018 end_col = ncol + 1;
2932 } 3019 }
2935 end_col = ROW(row).l; 3022 end_col = ROW(row).l;
2936 3023
2937 col = max (col, 0); 3024 col = max (col, 0);
2938 3025
2939 if (row == selection.end.row 3026 if (row == selection.end.row
2940#if ENABLE_FRILLS 3027#if !ENABLE_MINIMAL
2941 || selection.rect 3028 || selection.rect
2942#endif 3029#endif
2943 ) 3030 )
2944 min_it (end_col, selection.end.col); 3031 min_it (end_col, selection.end.col);
2945 3032
2968#endif 3055#endif
2969 else 3056 else
2970 new_selection_text[ofs++] = *t++; 3057 new_selection_text[ofs++] = *t++;
2971 } 3058 }
2972 3059
2973#if ENABLE_FRILLS 3060#if !ENABLE_MINIMAL
2974 if (selection.rect) 3061 if (selection.rect)
2975 { 3062 {
2976 while (ofs 3063 while (ofs
2977 && new_selection_text[ofs - 1] != C0_LF 3064 && new_selection_text[ofs - 1] != C0_LF
2978 && unicode::is_space (new_selection_text[ofs - 1])) 3065 && unicode::is_space (new_selection_text[ofs - 1]))
3008 3095
3009 selection_grab (tm); 3096 selection_grab (tm);
3010} 3097}
3011 3098
3012bool 3099bool
3013rxvt_term::selection_grab (Time tm) 3100rxvt_term::selection_grab (Time tm) NOTHROW
3014{ 3101{
3015 selection_time = tm; 3102 selection_time = tm;
3016 3103
3017 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); 3104 XSetSelectionOwner (dpy, XA_PRIMARY, vt, tm);
3018 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) 3105 if (XGetSelectionOwner (dpy, XA_PRIMARY) == vt)
3019 { 3106 {
3020 display->set_selection_owner (this); 3107 display->set_selection_owner (this);
3021 return true; 3108 return true;
3022 } 3109 }
3023 else 3110 else
3027 } 3114 }
3028 3115
3029#if 0 3116#if 0
3030 XTextProperty ct; 3117 XTextProperty ct;
3031 3118
3032 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3119 if (XwcTextListToTextProperty (dpy, &selection.text, 1, XStringStyle, &ct) >= 0)
3033 { 3120 {
3034 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); 3121 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
3035 XFree (ct.value); 3122 XFree (ct.value);
3036 } 3123 }
3037#endif 3124#endif
3041/* 3128/*
3042 * Mark or select text based upon number of clicks: 1, 2, or 3 3129 * Mark or select text based upon number of clicks: 1, 2, or 3
3043 * EXT: button 1 press 3130 * EXT: button 1 press
3044 */ 3131 */
3045void 3132void
3046rxvt_term::selection_click (int clicks, int x, int y) 3133rxvt_term::selection_click (int clicks, int x, int y) NOTHROW
3047{ 3134{
3048 clicks = ((clicks - 1) % 3) + 1; 3135 clicks = ((clicks - 1) % 3) + 1;
3049 selection.clicks = clicks; /* save clicks so extend will work */ 3136 selection.clicks = clicks; /* save clicks so extend will work */
3050 3137
3051 if (clicks == 2 && !selection.rect 3138 if (clicks == 2 && !selection.rect
3070/* ------------------------------------------------------------------------- */ 3157/* ------------------------------------------------------------------------- */
3071/* 3158/*
3072 * Mark a selection at the specified col/row 3159 * Mark a selection at the specified col/row
3073 */ 3160 */
3074void 3161void
3075rxvt_term::selection_start_colrow (int col, int row) 3162rxvt_term::selection_start_colrow (int col, int row) NOTHROW
3076{ 3163{
3077 want_refresh = 1; 3164 want_refresh = 1;
3078 3165
3079 selection.mark.row = row + view_start; 3166 selection.mark.row = row + view_start;
3080 selection.mark.col = col; 3167 selection.mark.col = col;
3083 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); 3170 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1);
3084 3171
3085 while (selection.mark.col > 0 3172 while (selection.mark.col > 0
3086 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) 3173 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3087 --selection.mark.col; 3174 --selection.mark.col;
3088 3175
3089 if (selection.op) 3176 if (selection.op)
3177 {
3090 { /* clear the old selection */ 3178 /* clear the old selection */
3091 selection.beg.row = selection.end.row = selection.mark.row; 3179 selection.beg.row = selection.end.row = selection.mark.row;
3092 selection.beg.col = selection.end.col = selection.mark.col; 3180 selection.beg.col = selection.end.col = selection.mark.col;
3093 } 3181 }
3094 3182
3095 selection.op = SELECTION_INIT; 3183 selection.op = SELECTION_INIT;
3106#define DELIMIT_TEXT(x) \ 3194#define DELIMIT_TEXT(x) \
3107 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x))) 3195 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x)))
3108#define DELIMIT_REND(x) 1 3196#define DELIMIT_REND(x) 1
3109 3197
3110void 3198void
3111rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) 3199rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) NOTHROW
3112{ 3200{
3113 int col, row, dirnadd, tcol, trow, w1, w2; 3201 int col, row, dirnadd, tcol, trow, w1, w2;
3114 row_col_t bound; 3202 row_col_t bound;
3115 text_t *stp; 3203 text_t *stp;
3116 rend_t *srp; 3204 rend_t *srp;
3190 * flag == 0 ==> button 1 3278 * flag == 0 ==> button 1
3191 * flag == 1 ==> button 3 press 3279 * flag == 1 ==> button 3 press
3192 * flag == 2 ==> button 3 motion 3280 * flag == 2 ==> button 3 motion
3193 */ 3281 */
3194void 3282void
3195rxvt_term::selection_extend (int x, int y, int flag) 3283rxvt_term::selection_extend (int x, int y, int flag) NOTHROW
3196{ 3284{
3197 int col = clamp (Pixel2Col (x), 0, ncol); 3285 int col = clamp (Pixel2Col (x), 0, ncol);
3198 int row = clamp (Pixel2Row (y), 0, nrow - 1); 3286 int row = clamp (Pixel2Row (y), 0, nrow - 1);
3199 3287
3200 /* 3288 /*
3226/* ------------------------------------------------------------------------- */ 3314/* ------------------------------------------------------------------------- */
3227/* 3315/*
3228 * Extend the selection to the specified col/row 3316 * Extend the selection to the specified col/row
3229 */ 3317 */
3230void 3318void
3231rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) 3319rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) NOTHROW
3232{ 3320{
3233 row_col_t pos; 3321 row_col_t pos;
3234 enum { 3322 enum {
3235 LEFT, RIGHT 3323 LEFT, RIGHT
3236 } closeto = RIGHT; 3324 } closeto = RIGHT;
3284 * a point/word/line which is either the start or end of the selection 3372 * a point/word/line which is either the start or end of the selection
3285 * and it was decided by whichever point/word/line was `fixed' at the 3373 * and it was decided by whichever point/word/line was `fixed' at the
3286 * time of the most recent button3 press 3374 * time of the most recent button3 press
3287 */ 3375 */
3288 if (button3 && buttonpress) 3376 if (button3 && buttonpress)
3377 {
3289 { /* button3 press */ 3378 /* button3 press */
3290 /* 3379 /*
3291 * first determine which edge of the selection we are closest to 3380 * first determine which edge of the selection we are closest to
3292 */ 3381 */
3293 if (ROWCOL_IS_BEFORE (pos, selection.beg) 3382 if (ROWCOL_IS_BEFORE (pos, selection.beg)
3294 || (!ROWCOL_IS_AFTER (pos, selection.end) 3383 || (!ROWCOL_IS_AFTER (pos, selection.end)
3312 selection.mark.row = selection.beg.row; 3401 selection.mark.row = selection.beg.row;
3313 selection.mark.col = selection.beg.col; 3402 selection.mark.col = selection.beg.col;
3314 } 3403 }
3315 } 3404 }
3316 else 3405 else
3406 {
3317 { /* button1 drag or button3 drag */ 3407 /* button1 drag or button3 drag */
3318 if (ROWCOL_IS_AFTER (selection.mark, pos)) 3408 if (ROWCOL_IS_AFTER (selection.mark, pos))
3319 { 3409 {
3320 if (selection.mark.row == selection.end.row 3410 if (selection.mark.row == selection.end.row
3321 && selection.mark.col == selection.end.col 3411 && selection.mark.col == selection.end.col
3322 && clickchange 3412 && clickchange
3339 3429
3340 if (selection.clicks == 1) 3430 if (selection.clicks == 1)
3341 { 3431 {
3342 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN 3432 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN
3343 && !ROW(selection.beg.row).is_longer () 3433 && !ROW(selection.beg.row).is_longer ()
3344#if ENABLE_FRILLS 3434#if !ENABLE_MINIMAL
3345 && !selection.rect 3435 && !selection.rect
3346#endif 3436#endif
3347 ) 3437 )
3348 selection.beg.col = ncol; 3438 selection.beg.col = ncol;
3349 3439
3350 if ( 3440 if (
3351 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN 3441 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN
3352 && !ROW(selection.end.row).is_longer () 3442 && !ROW(selection.end.row).is_longer ()
3353#if ENABLE_FRILLS 3443#if !ENABLE_MINIMAL
3354 && !selection.rect 3444 && !selection.rect
3355#endif 3445#endif
3356 ) 3446 )
3357 selection.end.col = ncol; 3447 selection.end.col = ncol;
3358 } 3448 }
3365 selection_delimit_word (DN, &selection.end, &selection.end); 3455 selection_delimit_word (DN, &selection.end, &selection.end);
3366 } 3456 }
3367 else if (selection.clicks == 3) 3457 else if (selection.clicks == 3)
3368 { 3458 {
3369#if ENABLE_FRILLS 3459#if ENABLE_FRILLS
3370 if (OPTION (Opt_tripleclickwords)) 3460 if (option (Opt_tripleclickwords))
3371 { 3461 {
3372 selection_delimit_word (UP, &selection.beg, &selection.beg); 3462 selection_delimit_word (UP, &selection.beg, &selection.beg);
3373 3463
3374 for (int end_row = selection.mark.row; end_row < nrow; end_row++) 3464 for (int end_row = selection.mark.row; end_row < nrow; end_row++)
3375 { 3465 {
3376 if (!ROW(end_row).is_longer ()) 3466 if (!ROW(end_row).is_longer ())
3377 { 3467 {
3378 selection.end.row = end_row; 3468 selection.end.row = end_row;
3379 selection.end.col = ROW(end_row).l; 3469 selection.end.col = ROW(end_row).l;
3470# if !ENABLE_MINIMAL
3380 selection_remove_trailing_spaces (); 3471 selection_remove_trailing_spaces ();
3472# endif
3381 break; 3473 break;
3382 } 3474 }
3383 } 3475 }
3384 } 3476 }
3385 else 3477 else
3401 selection.end.row++; 3493 selection.end.row++;
3402 } 3494 }
3403 } 3495 }
3404 3496
3405 if (button3 && buttonpress) 3497 if (button3 && buttonpress)
3498 {
3406 { /* mark may need to be changed */ 3499 /* mark may need to be changed */
3407 if (closeto == LEFT) 3500 if (closeto == LEFT)
3408 { 3501 {
3409 selection.mark.row = selection.end.row; 3502 selection.mark.row = selection.end.row;
3410 selection.mark.col = selection.end.col - (selection.clicks == 2); 3503 selection.mark.col = selection.end.col - (selection.clicks == 2);
3411 } 3504 }
3414 selection.mark.row = selection.beg.row; 3507 selection.mark.row = selection.beg.row;
3415 selection.mark.col = selection.beg.col; 3508 selection.mark.col = selection.beg.col;
3416 } 3509 }
3417 } 3510 }
3418 3511
3419#if ENABLE_FRILLS 3512#if !ENABLE_MINIMAL
3420 if (selection.rect && selection.beg.col > selection.end.col) 3513 if (selection.rect && selection.beg.col > selection.end.col)
3421 ::swap (selection.beg.col, selection.end.col); 3514 ::swap (selection.beg.col, selection.end.col);
3422#endif 3515#endif
3423} 3516}
3424 3517
3425#if ENABLE_FRILLS 3518#if !ENABLE_MINIMAL
3426void 3519void
3427rxvt_term::selection_remove_trailing_spaces () 3520rxvt_term::selection_remove_trailing_spaces () NOTHROW
3428{ 3521{
3429 int32_t end_col, end_row; 3522 int32_t end_col, end_row;
3430 text_t *stp; 3523 text_t *stp;
3431 3524
3432 end_col = selection.end.col; 3525 end_col = selection.end.col;
3470/* 3563/*
3471 * Double click on button 3 when already selected 3564 * Double click on button 3 when already selected
3472 * EXT: button 3 double click 3565 * EXT: button 3 double click
3473 */ 3566 */
3474void 3567void
3475rxvt_term::selection_rotate (int x, int y) 3568rxvt_term::selection_rotate (int x, int y) NOTHROW
3476{ 3569{
3477 selection.clicks = selection.clicks % 3 + 1; 3570 selection.clicks = selection.clicks % 3 + 1;
3478 selection_extend_colrow (Pixel2Col (x), Pixel2Row (y), 1, 0, 1); 3571 selection_extend_colrow (Pixel2Col (x), Pixel2Row (y), 1, 0, 1);
3479} 3572}
3480 3573
3482/* 3575/*
3483 * Respond to a request for our current selection 3576 * Respond to a request for our current selection
3484 * EXT: SelectionRequest 3577 * EXT: SelectionRequest
3485 */ 3578 */
3486void 3579void
3487rxvt_term::selection_send (const XSelectionRequestEvent &rq) 3580rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW
3488{ 3581{
3489 XSelectionEvent ev; 3582 XSelectionEvent ev;
3490 dDisp;
3491 3583
3492 ev.type = SelectionNotify; 3584 ev.type = SelectionNotify;
3493 ev.property = None; 3585 ev.property = None;
3494 ev.display = rq.display; 3586 ev.display = rq.display;
3495 ev.requestor = rq.requestor; 3587 ev.requestor = rq.requestor;
3509 *target++ = xa[XA_COMPOUND_TEXT]; 3601 *target++ = xa[XA_COMPOUND_TEXT];
3510#if X_HAVE_UTF8_STRING 3602#if X_HAVE_UTF8_STRING
3511 *target++ = xa[XA_UTF8_STRING]; 3603 *target++ = xa[XA_UTF8_STRING];
3512#endif 3604#endif
3513 3605
3514 XChangeProperty (disp, rq.requestor, rq.property, XA_ATOM, 3606 XChangeProperty (dpy, rq.requestor, rq.property, XA_ATOM,
3515 32, PropModeReplace, 3607 32, PropModeReplace,
3516 (unsigned char *)target_list, target - target_list); 3608 (unsigned char *)target_list, target - target_list);
3517 ev.property = rq.property; 3609 ev.property = rq.property;
3518 } 3610 }
3519#if TODO // TODO 3611#if TODO // TODO
3522 /* TODO: Handle MULTIPLE */ 3614 /* TODO: Handle MULTIPLE */
3523 } 3615 }
3524#endif 3616#endif
3525 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3617 else if (rq.target == xa[XA_TIMESTAMP] && selection.text)
3526 { 3618 {
3527 XChangeProperty (disp, rq.requestor, rq.property, rq.target, 3619 XChangeProperty (dpy, rq.requestor, rq.property, rq.target,
3528 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3620 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3529 ev.property = rq.property; 3621 ev.property = rq.property;
3530 } 3622 }
3531 else if (rq.target == XA_STRING 3623 else if (rq.target == XA_STRING
3532 || rq.target == xa[XA_TEXT] 3624 || rq.target == xa[XA_TEXT]
3556 style = enc_string; 3648 style = enc_string;
3557 else if (target == xa[XA_TEXT]) 3649 else if (target == xa[XA_TEXT])
3558 style = enc_text; 3650 style = enc_text;
3559 else if (target == xa[XA_COMPOUND_TEXT]) 3651 else if (target == xa[XA_COMPOUND_TEXT])
3560 style = enc_compound_text; 3652 style = enc_compound_text;
3561#if ENABLE_FRILLS 3653#if !ENABLE_MINIMAL
3562 else if (target == xa[XA_UTF8_STRING]) 3654 else if (target == xa[XA_UTF8_STRING])
3563 style = enc_utf8; 3655 style = enc_utf8;
3564#endif 3656#endif
3565 else 3657 else
3566 { 3658 {
3577 { 3669 {
3578 cl = L""; 3670 cl = L"";
3579 selectlen = 0; 3671 selectlen = 0;
3580 } 3672 }
3581 3673
3582#if ENABLE_FRILLS 3674#if !ENABLE_MINIMAL
3583 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 3675 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
3584 // so recode it manually 3676 // so recode it manually
3585 if (style == enc_utf8) 3677 if (style == enc_utf8)
3586 { 3678 {
3587 freect = 1; 3679 freect = 1;
3590 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen); 3682 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen);
3591 ct.nitems = strlen ((char *)ct.value); 3683 ct.nitems = strlen ((char *)ct.value);
3592 } 3684 }
3593 else 3685 else
3594#endif 3686#endif
3595 if (XwcTextListToTextProperty (disp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) 3687 if (XwcTextListToTextProperty (dpy, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0)
3596 freect = 1; 3688 freect = 1;
3597 else 3689 else
3598 { 3690 {
3599 /* if we failed to convert then send it raw */ 3691 /* if we failed to convert then send it raw */
3600 ct.value = (unsigned char *)cl; 3692 ct.value = (unsigned char *)cl;
3601 ct.nitems = selectlen; 3693 ct.nitems = selectlen;
3602 ct.encoding = target; 3694 ct.encoding = target;
3603 } 3695 }
3604 3696
3605 XChangeProperty (disp, rq.requestor, rq.property, 3697 XChangeProperty (dpy, rq.requestor, rq.property,
3606 ct.encoding, 8, PropModeReplace, 3698 ct.encoding, 8, PropModeReplace,
3607 ct.value, (int)ct.nitems); 3699 ct.value, (int)ct.nitems);
3608 ev.property = rq.property; 3700 ev.property = rq.property;
3609 3701
3610 if (freect) 3702 if (freect)
3611 XFree (ct.value); 3703 XFree (ct.value);
3612 } 3704 }
3613 3705
3614 XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev); 3706 XSendEvent (dpy, rq.requestor, False, 0L, (XEvent *)&ev);
3615}
3616
3617/* ------------------------------------------------------------------------- *
3618 * MOUSE ROUTINES *
3619 * ------------------------------------------------------------------------- */
3620
3621/*
3622 * return col/row values corresponding to x/y pixel values
3623 */
3624void
3625rxvt_term::pixel_position (int *x, int *y)
3626{
3627 *x = Pixel2Col (*x);
3628 /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */
3629 *y = Pixel2Row (*y);
3630 /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */
3631} 3707}
3632 3708
3633/* ------------------------------------------------------------------------- */ 3709/* ------------------------------------------------------------------------- */
3634#ifdef USE_XIM 3710#ifdef USE_XIM
3635void 3711void
3636rxvt_term::im_set_position (XPoint &pos) 3712rxvt_term::im_set_position (XPoint &pos) NOTHROW
3637{ 3713{
3638 XWindowAttributes xwa; 3714 XWindowAttributes xwa;
3639 3715
3640 XGetWindowAttributes (display->display, vt, &xwa); 3716 XGetWindowAttributes (dpy, vt, &xwa);
3641 3717
3642 pos.x = xwa.x + Col2Pixel (screen.cur.col); 3718 pos.x = xwa.x + Col2Pixel (screen.cur.col);
3643 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase; 3719 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase;
3644} 3720}
3645#endif 3721#endif
3646 3722
3647#if ENABLE_OVERLAY 3723#if ENABLE_OVERLAY
3648void 3724void
3649rxvt_term::scr_overlay_new (int x, int y, int w, int h) 3725rxvt_term::scr_overlay_new (int x, int y, int w, int h) NOTHROW
3650{ 3726{
3651 if (nrow < 1 || ncol < 1) 3727 if (nrow < 1 || ncol < 1)
3652 return; 3728 return;
3653 3729
3654 want_refresh = 1; 3730 want_refresh = 1;
3663 h += 2; min_it (h, nrow); 3739 h += 2; min_it (h, nrow);
3664 3740
3665 x -= 1; clamp_it (x, 0, ncol - w); 3741 x -= 1; clamp_it (x, 0, ncol - w);
3666 y -= 1; clamp_it (y, 0, nrow - h); 3742 y -= 1; clamp_it (y, 0, nrow - h);
3667 3743
3668 ov_x = x; ov_y = y; 3744 ov.x = x; ov.y = y;
3669 ov_w = w; ov_h = h; 3745 ov.w = w; ov.h = h;
3670 3746
3671 ov_text = new text_t *[h]; 3747 ov.text = new text_t *[h];
3672 ov_rend = new rend_t *[h]; 3748 ov.rend = new rend_t *[h];
3673 3749
3674 for (y = 0; y < h; y++) 3750 for (y = 0; y < h; y++)
3675 { 3751 {
3676 text_t *tp = ov_text[y] = new text_t[w]; 3752 text_t *tp = ov.text[y] = new text_t[w];
3677 rend_t *rp = ov_rend[y] = new rend_t[w]; 3753 rend_t *rp = ov.rend[y] = new rend_t[w];
3678 3754
3679 text_t t0, t1, t2; 3755 text_t t0, t1, t2;
3680 rend_t r = OVERLAY_RSTYLE; 3756 rend_t r = OVERLAY_RSTYLE;
3681 3757
3682 if (y == 0) 3758 if (y == 0)
3699 *rp = r; 3775 *rp = r;
3700 } 3776 }
3701} 3777}
3702 3778
3703void 3779void
3704rxvt_term::scr_overlay_off () 3780rxvt_term::scr_overlay_off () NOTHROW
3705{ 3781{
3706 if (!ov_text) 3782 if (!ov.text)
3707 return; 3783 return;
3708 3784
3709 want_refresh = 1; 3785 want_refresh = 1;
3710 3786
3711 for (int y = 0; y < ov_h; y++) 3787 for (int y = 0; y < ov.h; y++)
3712 { 3788 {
3713 delete [] ov_text[y]; 3789 delete [] ov.text[y];
3714 delete [] ov_rend[y]; 3790 delete [] ov.rend[y];
3715 } 3791 }
3716 3792
3717 delete [] ov_text; ov_text = 0; 3793 delete [] ov.text; ov.text = 0;
3718 delete [] ov_rend; ov_rend = 0; 3794 delete [] ov.rend; ov.rend = 0;
3719} 3795}
3720 3796
3721void 3797void
3722rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) 3798rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW
3723{ 3799{
3724 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2) 3800 if (!ov.text || x >= ov.w - 2 || y >= ov.h - 2)
3725 return; 3801 return;
3726 3802
3727 x++, y++; 3803 x++, y++;
3728 3804
3729 ov_text[y][x] = text; 3805 ov.text[y][x] = text;
3730 ov_rend[y][x] = rend; 3806 ov.rend[y][x] = rend;
3731} 3807}
3732 3808
3733void 3809void
3734rxvt_term::scr_overlay_set (int x, int y, const char *s) 3810rxvt_term::scr_overlay_set (int x, int y, const char *s) NOTHROW
3735{ 3811{
3736 while (*s) 3812 while (*s)
3737 scr_overlay_set (x++, y, *s++); 3813 scr_overlay_set (x++, y, *s++);
3738} 3814}
3739 3815
3740void 3816void
3741rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) 3817rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) NOTHROW
3742{ 3818{
3743 while (*s) 3819 while (*s)
3744 { 3820 {
3745 text_t t = *s++; 3821 text_t t = *s++;
3746 int width = wcwidth (t); 3822 int width = WCWIDTH (t);
3747 3823
3748 while (width--) 3824 while (width--)
3749 { 3825 {
3750 scr_overlay_set (x++, y, t); 3826 scr_overlay_set (x++, y, t);
3751 t = NOCHAR; 3827 t = NOCHAR;
3752 } 3828 }
3753 } 3829 }
3754} 3830}
3755 3831
3756void 3832void
3757rxvt_term::scr_swap_overlay () 3833rxvt_term::scr_swap_overlay () NOTHROW
3758{ 3834{
3759 if (!ov_text) 3835 if (!ov.text)
3760 return; 3836 return;
3761 3837
3838 // hide cursor if it is within the overlay area
3839 if (IN_RANGE_EXC (screen.cur.col - ov.x, 0, ov.w)
3840 && IN_RANGE_EXC (screen.cur.row - ov.y, 0, ov.h))
3841 screen.flags &= ~Screen_VisibleCursor;
3842
3762 // swap screen mem with overlay 3843 // swap screen mem with overlay
3763 for (int y = ov_h; y--; ) 3844 for (int y = ov.h; y--; )
3764 { 3845 {
3765 text_t *t1 = ov_text[y]; 3846 text_t *t1 = ov.text[y];
3766 rend_t *r1 = ov_rend[y]; 3847 rend_t *r1 = ov.rend[y];
3767 3848
3768 text_t *t2 = ROW(y + ov_y + view_start).t + ov_x; 3849 text_t *t2 = ROW(y + ov.y + view_start).t + ov.x;
3769 rend_t *r2 = ROW(y + ov_y + view_start).r + ov_x; 3850 rend_t *r2 = ROW(y + ov.y + view_start).r + ov.x;
3770 3851
3771 for (int x = ov_w; x--; ) 3852 for (int x = ov.w; x--; )
3772 { 3853 {
3773 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3854 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3774 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); 3855 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t));
3775 } 3856 }
3776 } 3857 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines