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.309 by root, Mon Jul 21 16:51:31 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;
161{ 143{
162#if ENABLE_OVERLAY 144#if ENABLE_OVERLAY
163 scr_overlay_off (); 145 scr_overlay_off ();
164#endif 146#endif
165 147
148 rvideo_mode = false;
166 view_start = 0; 149 view_start = 0;
167 num_scr = 0; 150 num_scr = 0;
168 151
169 if (ncol == 0) 152 if (ncol == 0)
170 ncol = 80; 153 ncol = 80;
173 nrow = 24; 156 nrow = 24;
174 157
175 if (ncol == prev_ncol && nrow == prev_nrow) 158 if (ncol == prev_ncol && nrow == prev_nrow)
176 return; 159 return;
177 160
161 if (current_screen != PRIMARY)
162 scr_swap_screen ();
163
178 // we need at least two lines for wrapping to work correctly 164 // we need at least two lines for wrapping to work correctly
179 if (nrow + saveLines < 2) 165 while (nrow + saveLines < 2)
180 { 166 {
181 //TODO//FIXME 167 //TODO//FIXME
182 saveLines++; 168 saveLines++;
183 prev_nrow--; 169 prev_nrow--;
184 top_row--; 170 top_row--;
195 if (!row_buf) 181 if (!row_buf)
196 { 182 {
197 /* 183 /*
198 * first time called so just malloc everything: don't rely on realloc 184 * first time called so just malloc everything: don't rely on realloc
199 */ 185 */
200 top_row = 0; /* no saved lines */ 186 top_row = 0;
201 term_start = 0; 187 term_start = 0;
202 188
203 talloc = new rxvt_salloc (ncol * sizeof (text_t)); 189 talloc = new rxvt_salloc (ncol * sizeof (text_t));
204 ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 190 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
205 191
234 selection.text = NULL; 220 selection.text = NULL;
235 selection.len = 0; 221 selection.len = 0;
236 selection.op = SELECTION_CLEAR; 222 selection.op = SELECTION_CLEAR;
237 selection.screen = PRIMARY; 223 selection.screen = PRIMARY;
238 selection.clicks = 0; 224 selection.clicks = 0;
239 CLEAR_ALL_SELECTION ();
240 rvideo = 0;
241 } 225 }
242 else 226 else
243 { 227 {
244 /* 228 /*
245 * add or delete rows as appropriate 229 * add or delete rows as appropriate
274 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 258 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
275 } 259 }
276 260
277 line_t *old_buf = row_buf; 261 line_t *old_buf = row_buf;
278 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t)); 262 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t));
279 263
280 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 264 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
281 int pend = MOD (term_start + top_row , prev_total_rows); 265 int pend = MOD (term_start + top_row , prev_total_rows);
282 int q = total_rows; // rewrapped row 266 int q = total_rows; // rewrapped row
283 267
284 if (top_row) 268 if (top_row)
285 { 269 {
286 // re-wrap lines, this is rather ugly, possibly because I am too dumb 270 // Re-wrap lines. This is rather ugly, possibly because I am too dumb
287 // to come up with a lean and mean algorithm. 271 // to come up with a lean and mean algorithm.
288 272
289 row_col_t ocur = screen.cur; 273 row_col_t ocur = screen.cur;
290 ocur.row = MOD (term_start + ocur.row, prev_total_rows); 274 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
291 275
328 int qcol = 0; 312 int qcol = 0;
329 313
330 // see below for cursor adjustment rationale 314 // see below for cursor adjustment rationale
331 if (p == ocur.row) 315 if (p == ocur.row)
332 screen.cur.row = q - (total_rows - nrow); 316 screen.cur.row = q - (total_rows - nrow);
333 317
334 // fill a single destination line 318 // fill a single destination line
335 while (lofs < llen && qcol < ncol) 319 while (lofs < llen && qcol < ncol)
336 { 320 {
337 int prow = lofs / prev_ncol; 321 int prow = lofs / prev_ncol;
338 int pcol = lofs % prev_ncol; 322 int pcol = lofs % prev_ncol;
348 332
349 line_t &pline = old_buf [prow]; 333 line_t &pline = old_buf [prow];
350 334
351 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 335 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
352 336
353 assert (len);
354 assert (pline.t);
355
356 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); 337 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
357 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); 338 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
358 339
359 lofs += len; 340 lofs += len;
360 qcol += len; 341 qcol += len;
367 } 348 }
368 while (p != pend && q > 0); 349 while (p != pend && q > 0);
369 350
370 term_start = total_rows - nrow; 351 term_start = total_rows - nrow;
371 top_row = q - term_start; 352 top_row = q - term_start;
372 353
373 // make sure all terminal lines exist 354 // make sure all terminal lines exist
374 while (top_row > 0) 355 while (top_row > 0)
375 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE); 356 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
376 } 357 }
377 else 358 else
378 { 359 {
379 // if no scrollback exists (yet), wing, instead of wrap 360 // if no scrollback exists (yet), wing, instead of wrap
380 361
381 for (int row = min (nrow, prev_nrow); row--; ) 362 for (int row = min (nrow, prev_nrow); row--; )
382 { 363 {
383 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; 364 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
384 line_t &qline = row_buf [row]; 365 line_t &qline = row_buf [row];
385 366
400 delete old_ra; 381 delete old_ra;
401 382
402 clamp_it (screen.cur.row, 0, nrow - 1); 383 clamp_it (screen.cur.row, 0, nrow - 1);
403 clamp_it (screen.cur.col, 0, ncol - 1); 384 clamp_it (screen.cur.col, 0, ncol - 1);
404 385
405 if (tabs)
406 free (tabs); 386 free (tabs);
407 } 387 }
388
389 CLEAR_ALL_SELECTION ();
408 390
409 prev_nrow = nrow; 391 prev_nrow = nrow;
410 prev_ncol = ncol; 392 prev_ncol = ncol;
411 393
412 tabs = (char *)rxvt_malloc (ncol * sizeof (char)); 394 tabs = (char *)rxvt_malloc (ncol);
413 395
414 for (int col = ncol; col--; ) 396 for (int col = ncol; --col; )
415 tabs [col] = col % TABSIZE == 0; 397 tabs [col] = col % TABSIZE == 0;
416 398
399 if (current_screen != PRIMARY)
400 scr_swap_screen ();
401
417 tt_winch (); 402 tt_winch ();
418 403
419 HOOK_INVOKE ((this, HOOK_RESET, DT_END)); 404 HOOK_INVOKE ((this, HOOK_RESET, DT_END));
420} 405}
421 406
422/* ------------------------------------------------------------------------- */ 407/* ------------------------------------------------------------------------- */
423/* 408/*
424 * Free everything. That way malloc debugging can find leakage. 409 * Free everything. That way malloc debugging can find leakage.
425 */ 410 */
426void 411void
427rxvt_term::scr_release () 412rxvt_term::scr_release () NOTHROW
428{ 413{
414 if (row_buf)
415 {
429 delete talloc; talloc = 0; 416 delete talloc; talloc = 0;
430 delete ralloc; ralloc = 0; 417 delete ralloc; ralloc = 0;
431 418
432 free (row_buf); 419 free (row_buf);
433 free (swap_buf); 420 free (swap_buf);
434 free (drawn_buf); 421 free (drawn_buf);
435 free (tabs); 422 free (tabs);
436 423
437 row_buf = 0; // signal that we freed all the arrays 424 row_buf = 0; // signal that we freed all the arrays
425 }
438} 426}
439 427
440/* ------------------------------------------------------------------------- */ 428/* ------------------------------------------------------------------------- */
441/* 429/*
442 * Hard reset 430 * Hard reset
459 * Save and Restore cursor 447 * Save and Restore cursor
460 * XTERM_SEQ: Save cursor : ESC 7 448 * XTERM_SEQ: Save cursor : ESC 7
461 * XTERM_SEQ: Restore cursor: ESC 8 449 * XTERM_SEQ: Restore cursor: ESC 8
462 */ 450 */
463void 451void
464rxvt_term::scr_cursor (int mode) 452rxvt_term::scr_cursor (cursor_mode mode) NOTHROW
465{ 453{
466 screen_t *s; 454 screen_t *s;
467 455
468#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR) 456#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR)
469 if (current_screen == SECONDARY) 457 if (current_screen == SECONDARY)
501 assert (s->cur.row >= 0); 489 assert (s->cur.row >= 0);
502 assert (s->cur.col >= 0); 490 assert (s->cur.col >= 0);
503#endif 491#endif
504} 492}
505 493
494void
495rxvt_term::scr_swap_screen ()
496{
497 if (!option (Opt_secondaryScreen))
498 return;
499
500 for (int i = prev_nrow; i--; )
501 ::swap (ROW(i), swap_buf [i]);
502
503 ::swap (screen.cur, swap.cur);
504
505 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
506 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
507}
508
506/* ------------------------------------------------------------------------- */ 509/* ------------------------------------------------------------------------- */
507/* 510/*
508 * Swap between primary and secondary screens 511 * Swap between primary and secondary screens
509 * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h 512 * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h
510 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l 513 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l
511 */ 514 */
512int 515void
513rxvt_term::scr_change_screen (int scrn) 516rxvt_term::scr_change_screen (int scrn)
514{ 517{
518 if (scrn == current_screen)
519 return;
520
515 want_refresh = 1; 521 want_refresh = 1;
516 view_start = 0; 522 view_start = 0;
517 523
518 if (current_screen == scrn)
519 return scrn;
520
521 selection_check (2); /* check for boundary cross */ 524 selection_check (2); /* check for boundary cross */
522 525
523 int i = current_screen; current_screen = scrn; scrn = i; 526 int i = current_screen; current_screen = scrn; scrn = i;
524 527
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 528#if NSCREENS
532 if (OPTION (Opt_secondaryScreen)) 529 if (option (Opt_secondaryScreen))
533 { 530 {
534 num_scr = 0; 531 num_scr = 0;
535 532
536 for (int i = prev_nrow; i--; ) 533 scr_swap_screen ();
537 ::swap (ROW(i), swap_buf [i]);
538 534
539 ::swap (screen.charset, swap.charset); 535 ::swap (screen.charset, swap.charset);
540 ::swap (screen.flags, swap.flags); 536 ::swap (screen.flags, swap.flags);
541 screen.flags |= Screen_VisibleCursor; 537 screen.flags |= Screen_VisibleCursor;
542 swap.flags |= Screen_VisibleCursor; 538 swap.flags |= Screen_VisibleCursor;
543 } 539 }
544 else 540 else
545#endif 541#endif
546 if (OPTION (Opt_secondaryScroll)) 542 if (option (Opt_secondaryScroll))
547 scr_scroll_text (0, prev_nrow - 1, prev_nrow); 543 scr_scroll_text (0, prev_nrow - 1, prev_nrow);
548
549 return scrn;
550} 544}
551 545
552// clear WrapNext indicator, solidifying position on next line 546// clear WrapNext indicator, solidifying position on next line
553void 547void
554rxvt_term::scr_do_wrap () 548rxvt_term::scr_do_wrap () NOTHROW
555{ 549{
556 if (!(screen.flags & Screen_WrapNext)) 550 if (!(screen.flags & Screen_WrapNext))
557 return; 551 return;
558 552
559 screen.flags &= ~Screen_WrapNext; 553 screen.flags &= ~Screen_WrapNext;
569/* ------------------------------------------------------------------------- */ 563/* ------------------------------------------------------------------------- */
570/* 564/*
571 * Change the colour for following text 565 * Change the colour for following text
572 */ 566 */
573void 567void
574rxvt_term::scr_color (unsigned int color, int fgbg) 568rxvt_term::scr_color (unsigned int color, int fgbg) NOTHROW
575{ 569{
576 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) 570 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
577 color = fgbg; 571 color = fgbg;
578 572
579 if (fgbg == Color_fg) 573 if (fgbg == Color_fg)
585/* ------------------------------------------------------------------------- */ 579/* ------------------------------------------------------------------------- */
586/* 580/*
587 * Change the rendition style for following text 581 * Change the rendition style for following text
588 */ 582 */
589void 583void
590rxvt_term::scr_rendition (int set, int style) 584rxvt_term::scr_rendition (int set, int style) NOTHROW
591 { 585{
592 if (set) 586 if (set)
593 rstyle |= style; 587 rstyle |= style;
594 else if (style == ~RS_None) 588 else if (style == ~RS_None)
595 rstyle = DEFAULT_RSTYLE; 589 rstyle = DEFAULT_RSTYLE;
596 else 590 else
597 rstyle &= ~style; 591 rstyle &= ~style;
598 } 592}
599 593
600/* ------------------------------------------------------------------------- */ 594/* ------------------------------------------------------------------------- */
601/* 595/*
602 * Scroll text between <row1> and <row2> inclusive, by <count> lines 596 * Scroll text between <row1> and <row2> inclusive, by <count> lines
603 * count positive ==> scroll up 597 * count positive ==> scroll up
604 * count negative ==> scroll down 598 * count negative ==> scroll down
605 */ 599 */
606int 600int
607rxvt_term::scr_scroll_text (int row1, int row2, int count) 601rxvt_term::scr_scroll_text (int row1, int row2, int count) NOTHROW
608{ 602{
609 if (count == 0 || (row1 > row2)) 603 if (count == 0 || (row1 > row2))
610 return 0; 604 return 0;
611 605
612 want_refresh = 1; 606 want_refresh = 1;
613 num_scr += count; 607 num_scr += count;
614 608
615 if (count > 0 609 if (count > 0
616 && row1 == 0 610 && row1 == 0
617 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll))) 611 && (current_screen == PRIMARY || option (Opt_secondaryScroll)))
618 { 612 {
619 top_row = max (top_row - count, -saveLines); 613 top_row = max (top_row - count, -saveLines);
620 614
621 // scroll everything up 'count' lines 615 // scroll everything up 'count' lines
622 term_start = (term_start + count) % total_rows; 616 term_start = (term_start + count) % total_rows;
629 } 623 }
630 624
631 // erase newly scrolled-in lines 625 // erase newly scrolled-in lines
632 for (int i = count; i--; ) 626 for (int i = count; i--; )
633 { 627 {
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); 628 line_t &l = ROW(nrow - 1 - i);
637 629
630 // optimize if already cleared, can be significant on slow machines
631 // could be rolled into scr_blank_screen_mem
632 if (l.r && l.l < ncol - 1 && !((l.r[l.l + 1] ^ rstyle) & (RS_fgMask | RS_bgMask)))
633 {
638 scr_blank_line (l, 0, l.l, rstyle); 634 scr_blank_line (l, 0, l.l, rstyle);
639
640 l.l = 0; 635 l.l = 0;
641 l.f = 0; 636 l.f = 0;
637 }
638 else
639 scr_blank_screen_mem (l, rstyle);
642 } 640 }
643 641
644 // now copy lines below the scroll region bottom to the 642 // now copy lines below the scroll region bottom to the
645 // bottom of the screen again, so they look as if they 643 // bottom of the screen again, so they look as if they
646 // hadn't moved. 644 // hadn't moved.
650 line_t &l2 = ROW(i); 648 line_t &l2 = ROW(i);
651 649
652 ::swap (l1, l2); 650 ::swap (l1, l2);
653 l2.touch (); 651 l2.touch ();
654 } 652 }
655 653
656 // move and/or clear selection, if any 654 // move and/or clear selection, if any
657 if (selection.op && current_screen == selection.screen) 655 if (selection.op && current_screen == selection.screen)
658 { 656 {
659 selection.beg.row -= count; 657 selection.beg.row -= count;
660 selection.end.row -= count; 658 selection.end.row -= count;
668 selection.op = SELECTION_CLEAR; 666 selection.op = SELECTION_CLEAR;
669 } 667 }
670 } 668 }
671 669
672 // finally move the view window, if desired 670 // finally move the view window, if desired
673 if (OPTION (Opt_scrollWithBuffer) 671 if (option (Opt_scrollWithBuffer)
674 && view_start != 0 672 && view_start != 0
675 && view_start != -saveLines) 673 && view_start != -saveLines)
676 scr_page (UP, count); 674 scr_page (UP, count);
677 675
678 if (SHOULD_INVOKE (HOOK_SCROLL_BACK)) 676 if (SHOULD_INVOKE (HOOK_SCROLL_BACK))
696 { 694 {
697 /* move selected region too */ 695 /* move selected region too */
698 selection.beg.row -= count; 696 selection.beg.row -= count;
699 selection.end.row -= count; 697 selection.end.row -= count;
700 selection.mark.row -= count; 698 selection.mark.row -= count;
701 699
702 selection_check (0); 700 selection_check (0);
703 } 701 }
704 } 702 }
705 703
706 // use a simple and robust scrolling algorithm, this 704 // use a simple and robust scrolling algorithm, this
730/* ------------------------------------------------------------------------- */ 728/* ------------------------------------------------------------------------- */
731/* 729/*
732 * Add text given in <str> of length <len> to screen struct 730 * Add text given in <str> of length <len> to screen struct
733 */ 731 */
734void 732void
735rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) 733rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) NOTHROW
736{ 734{
737 if (len <= 0) /* sanity */ 735 if (len <= 0) /* sanity */
738 return; 736 return;
739 737
740 unsigned char checksel; 738 unsigned char checksel;
746 ZERO_SCROLLBACK (); 744 ZERO_SCROLLBACK ();
747 745
748 if (minlines > 0) 746 if (minlines > 0)
749 { 747 {
750 minlines += screen.cur.row - screen.bscroll; 748 minlines += screen.cur.row - screen.bscroll;
749 min_it (minlines, screen.cur.row - top_row);
751 750
752 if (minlines > 0 751 if (minlines > 0
753 && screen.tscroll == 0 752 && screen.tscroll == 0
754 && screen.bscroll == nrow - 1) 753 && screen.bscroll == nrow - 1)
755 { 754 {
772 771
773 while (str < strend) 772 while (str < strend)
774 { 773 {
775 c = (unicode_t)*str++; // convert to rxvt-unicodes representation 774 c = (unicode_t)*str++; // convert to rxvt-unicodes representation
776 775
777 if (c < 0x20) 776 if (expect_false (c < 0x20))
778 if (c == C0_LF) 777 if (c == C0_LF)
779 { 778 {
780 max_it (line->l, screen.cur.col); 779 max_it (line->l, screen.cur.col);
781 780
782 screen.flags &= ~Screen_WrapNext; 781 screen.flags &= ~Screen_WrapNext;
801 { 800 {
802 scr_tab (1, true); 801 scr_tab (1, true);
803 continue; 802 continue;
804 } 803 }
805 804
805 if (expect_false (
806 if (checksel /* see if we're writing within selection */ 806 checksel /* see if we're writing within selection */
807 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 807 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
808 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 808 && ROWCOL_IS_BEFORE (screen.cur, selection.end)
809 ))
809 { 810 {
810 checksel = 0; 811 checksel = 0;
811 /* 812 /*
812 * If we wrote anywhere in the selected area, kill the selection 813 * If we wrote anywhere in the selected area, kill the selection
813 * XXX: should we kill the mark too? Possibly, but maybe that 814 * XXX: should we kill the mark too? Possibly, but maybe that
814 * should be a similar check. 815 * should be a similar check.
815 */ 816 */
816 CLEAR_SELECTION (); 817 CLEAR_SELECTION ();
817 } 818 }
818 819
819 if (screen.flags & Screen_WrapNext) 820 if (expect_false (screen.flags & Screen_WrapNext))
820 { 821 {
821 scr_do_wrap (); 822 scr_do_wrap ();
822 823
823 line->l = ncol; 824 line->l = ncol;
824 line->is_longer (1); 825 line->is_longer (1);
825 826
826 row = screen.cur.row; 827 row = screen.cur.row;
827 line = &ROW(row); /* _must_ refresh */ 828 line = &ROW(row); /* _must_ refresh */
828 } 829 }
829 830
830 // some utf-8 decoders "decode" surrogate characters: let's fix this. 831 // some utf-8 decoders "decode" surrogate characters: let's fix this.
831 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 832 if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff)))
832 c = 0xfffd; 833 c = 0xfffd;
833 834
834 // rely on wcwidth to tell us the character width, at least for non-latin1 835 // rely on wcwidth to tell us the character width, do wcwidth before
835 // do wcwidth before further replacements, as wcwidth might return -1 836 // 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 837 // drawing characters below as they might be invalid in the current
837 // locale. 838 // locale.
838 int width = c < 0x100 ? 1 : wcwidth (c); 839 int width = WCWIDTH (c);
839 840
840 if (charsets [screen.charset] == '0') // DEC SPECIAL 841 if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL
841 { 842 {
842 // vt100 special graphics and line drawing 843 // vt100 special graphics and line drawing
843 // 5f-7e standard vt100 844 // 5f-7e standard vt100
844 // 40-5e rxvt extension for extra curses acs chars 845 // 40-5e rxvt extension for extra curses acs chars
845 static uint16_t vt100_0[62] = { // 41 .. 7e 846 static uint16_t vt100_0[62] = { // 41 .. 7e
858 c = vt100_0[c - 0x41]; 859 c = vt100_0[c - 0x41];
859 width = 1; // vt100 line drawing characters are always single-width 860 width = 1; // vt100 line drawing characters are always single-width
860 } 861 }
861 } 862 }
862 863
863 if (screen.flags & Screen_Insert) 864 if (expect_false (screen.flags & Screen_Insert))
864 scr_insdel_chars (width, INSERT); 865 scr_insdel_chars (width, INSERT);
865 866
866 if (width != 0) 867 if (width != 0)
867 { 868 {
868#if !UNICODE_3 869#if !UNICODE_3
874 c = 0xfffd; 875 c = 0xfffd;
875# endif 876# endif
876#endif 877#endif
877 878
878 // nuke the character at this position, if required 879 // nuke the character at this position, if required
880 if (expect_false (
879 if (line->t[screen.cur.col] == NOCHAR 881 line->t[screen.cur.col] == NOCHAR
880 || (screen.cur.col < ncol - 1 882 || (screen.cur.col < ncol - 1
881 && line->t[screen.cur.col + 1] == NOCHAR)) 883 && line->t[screen.cur.col + 1] == NOCHAR)
884 ))
882 { 885 {
883 int col = screen.cur.col; 886 int col = screen.cur.col;
884 887
885 // find begin 888 // find begin
886 while (col > 0 && line->t[col] == NOCHAR) 889 while (col > 0 && line->t[col] == NOCHAR)
897 } 900 }
898 901
899 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); 902 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
900 903
901 // if the character doesn't fit into the remaining columns... 904 // if the character doesn't fit into the remaining columns...
902 if (screen.cur.col > ncol - width && ncol >= width) 905 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
903 { 906 {
904 // ...output spaces 907 // ...output spaces
905 c = ' '; 908 c = ' ';
906 // and try the same character next loop iteration 909 // and try the same character next loop iteration
907 --str; 910 --str;
912 do 915 do
913 { 916 {
914 line->t[screen.cur.col] = c; 917 line->t[screen.cur.col] = c;
915 line->r[screen.cur.col] = rend; 918 line->r[screen.cur.col] = rend;
916 919
917 if (screen.cur.col < ncol - 1) 920 if (expect_true (screen.cur.col < ncol - 1))
918 screen.cur.col++; 921 screen.cur.col++;
919 else 922 else
920 { 923 {
921 line->l = ncol; 924 line->l = ncol;
922 if (screen.flags & Screen_Autowrap) 925 if (screen.flags & Screen_Autowrap)
924 break; 927 break;
925 } 928 }
926 929
927 c = NOCHAR; 930 c = NOCHAR;
928 } 931 }
929 while (--width > 0); 932 while (expect_false (--width > 0));
930 933
931 // pad with spaces when overwriting wide character with smaller one 934 // pad with spaces when overwriting wide character with smaller one
932 if (!width) 935 if (expect_false (!width))
933 { 936 {
934 line->touch (); 937 line->touch ();
935 938
936 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) 939 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
937 { 940 {
938 line->t[c] = ' '; 941 line->t[c] = ' ';
939 line->r[c] = rend; 942 line->r[c] = rend;
940 } 943 }
941 } 944 }
942 } 945 }
946#if ENABLE_COMBINING
943 else // width == 0 947 else // width == 0
944 { 948 {
945#if ENABLE_COMBINING 949 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 { 950 {
951 // handle combining characters
952 // we just tag the accent on the previous on-screen character.
953 // this is arguably not correct, but also arguably not wrong.
954 // we don't handle double-width characters nicely yet.
955 line_t *linep;
956 text_t *tp;
957 rend_t *rp;
958
959 if (screen.cur.col > 0)
960 {
956 linep = line; 961 linep = line;
957 tp = line->t + screen.cur.col - 1; 962 tp = line->t + screen.cur.col - 1;
958 rp = line->r + screen.cur.col - 1; 963 rp = line->r + screen.cur.col - 1;
964 }
965 else if (screen.cur.row > 0
966 && ROW(screen.cur.row - 1).is_longer ())
967 {
968 linep = &ROW(screen.cur.row - 1);
969 tp = line->t + ncol - 1;
970 rp = line->r + ncol - 1;
971 }
972 else
973 continue;
974
975 linep->touch ();
976
977 while (*tp == NOCHAR && tp > linep->t)
978 tp--, rp--;
979
980 // first try to find a precomposed character
981 unicode_t n = rxvt_compose (*tp, c);
982 if (n == NOCHAR)
983 n = rxvt_composite.compose (*tp, c);
984
985 *tp = n;
986 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
959 } 987 }
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 } 988 }
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 989#endif
983 }
984 } 990 }
985 991
986 max_it (line->l, screen.cur.col); 992 max_it (line->l, screen.cur.col);
987 993
988#ifdef DEBUG_STRICT 994#ifdef DEBUG_STRICT
994/* 1000/*
995 * Process Backspace. Move back the cursor back a position, wrap if have to 1001 * Process Backspace. Move back the cursor back a position, wrap if have to
996 * XTERM_SEQ: CTRL-H 1002 * XTERM_SEQ: CTRL-H
997 */ 1003 */
998void 1004void
999rxvt_term::scr_backspace () 1005rxvt_term::scr_backspace () NOTHROW
1000{ 1006{
1001 want_refresh = 1;
1002
1003 if (screen.cur.col == 0) 1007 if (screen.cur.col == 0)
1004 { 1008 {
1005 if (screen.cur.row > 0) 1009 if (screen.cur.row > 0)
1006 { 1010 {
1007#ifdef TERMCAP_HAS_BW 1011#ifdef TERMCAP_HAS_BW
1008 screen.cur.col = ncol - 1; 1012 screen.cur.col = ncol - 1;
1009 screen.cur.row--; 1013 --screen.cur.row;
1010 return; 1014
1015 want_refresh = 1;
1011#endif 1016#endif
1012 } 1017 }
1013 } 1018 }
1014 else if (!(screen.flags & Screen_WrapNext)) 1019 else
1015 scr_gotorc (0, -1, RELATIVE); 1020 scr_gotorc (0, -1, RELATIVE);
1016
1017 screen.flags &= ~Screen_WrapNext;
1018} 1021}
1019 1022
1020/* ------------------------------------------------------------------------- */ 1023/* ------------------------------------------------------------------------- */
1021/* 1024/*
1022 * Process Horizontal Tab 1025 * Process Horizontal Tab
1023 * count: +ve = forward; -ve = backwards 1026 * count: +ve = forward; -ve = backwards
1024 * XTERM_SEQ: CTRL-I 1027 * XTERM_SEQ: CTRL-I
1025 */ 1028 */
1026void 1029void
1027rxvt_term::scr_tab (int count, bool ht) 1030rxvt_term::scr_tab (int count, bool ht) NOTHROW
1028{ 1031{
1029 int i, x; 1032 int i, x;
1030 1033
1031 want_refresh = 1; 1034 want_refresh = 1;
1032 i = x = screen.cur.col; 1035 i = x = screen.cur.col;
1045 x = i; 1048 x = i;
1046 1049
1047 if (!--count) 1050 if (!--count)
1048 break; 1051 break;
1049 } 1052 }
1050 else 1053 else
1051 ht &= l.t[i] == ' ' 1054 ht &= l.t[i] == ' '
1052 && RS_SAME (l.r[i], base_rend); 1055 && RS_SAME (l.r[i], base_rend);
1053 1056
1054 if (count) 1057 if (count)
1055 x = ncol - 1; 1058 x = ncol - 1;
1056 1059
1057 // store horizontal tab commands as characters inside the text 1060 // store horizontal tab commands as characters inside the text
1058 // buffer so they can be selected and pasted. 1061 // buffer so they can be selected and pasted.
1059 if (ht && OPTION (Opt_pastableTabs)) 1062 if (ht && option (Opt_pastableTabs))
1060 { 1063 {
1061 base_rend = SET_FONT (base_rend, 0); 1064 base_rend = SET_FONT (base_rend, 0);
1062 1065
1063 l.touch (x); 1066 l.touch (x);
1064 1067
1097 * Process DEC Back Index 1100 * Process DEC Back Index
1098 * XTERM_SEQ: ESC 6 1101 * XTERM_SEQ: ESC 6
1099 * Move cursor left in row. If we're at the left boundary, shift everything 1102 * Move cursor left in row. If we're at the left boundary, shift everything
1100 * in that row right. Clear left column. 1103 * in that row right. Clear left column.
1101 */ 1104 */
1102#if ENABLE_FRILLS 1105#if !ENABLE_MINIMAL
1103void 1106void
1104rxvt_term::scr_backindex () 1107rxvt_term::scr_backindex () NOTHROW
1105{ 1108{
1106 if (screen.cur.col > 0) 1109 if (screen.cur.col > 0)
1107 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE); 1110 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
1108 else 1111 else
1109 scr_insdel_chars (1, INSERT); 1112 scr_insdel_chars (1, INSERT);
1114 * Process DEC Forward Index 1117 * Process DEC Forward Index
1115 * XTERM_SEQ: ESC 9 1118 * XTERM_SEQ: ESC 9
1116 * Move cursor right in row. If we're at the right boundary, shift everything 1119 * Move cursor right in row. If we're at the right boundary, shift everything
1117 * in that row left. Clear right column. 1120 * in that row left. Clear right column.
1118 */ 1121 */
1119#if ENABLE_FRILLS 1122#if !ENABLE_MINIMAL
1120void 1123void
1121rxvt_term::scr_forwardindex () 1124rxvt_term::scr_forwardindex () NOTHROW
1122{ 1125{
1123 if (screen.cur.col < ncol - 1) 1126 if (screen.cur.col < ncol - 1)
1124 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1127 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1125 else 1128 else
1126 { 1129 {
1139/* ------------------------------------------------------------------------- */ 1142/* ------------------------------------------------------------------------- */
1140/* 1143/*
1141 * Goto Row/Column 1144 * Goto Row/Column
1142 */ 1145 */
1143void 1146void
1144rxvt_term::scr_gotorc (int row, int col, int relative) 1147rxvt_term::scr_gotorc (int row, int col, int relative) NOTHROW
1145{ 1148{
1146 want_refresh = 1; 1149 want_refresh = 1;
1147 ZERO_SCROLLBACK (); 1150 ZERO_SCROLLBACK ();
1148 1151
1149 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col; 1152 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col;
1171 } 1174 }
1172 } 1175 }
1173 else 1176 else
1174 { 1177 {
1175 if (screen.flags & Screen_Relative) 1178 if (screen.flags & Screen_Relative)
1179 {
1176 { /* relative origin mode */ 1180 /* relative origin mode */
1177 screen.cur.row = row + screen.tscroll; 1181 screen.cur.row = row + screen.tscroll;
1178 min_it (screen.cur.row, screen.bscroll); 1182 min_it (screen.cur.row, screen.bscroll);
1179 } 1183 }
1180 else 1184 else
1181 screen.cur.row = row; 1185 screen.cur.row = row;
1187/* ------------------------------------------------------------------------- */ 1191/* ------------------------------------------------------------------------- */
1188/* 1192/*
1189 * direction should be UP or DN 1193 * direction should be UP or DN
1190 */ 1194 */
1191void 1195void
1192rxvt_term::scr_index (enum page_dirn direction) 1196rxvt_term::scr_index (enum page_dirn direction) NOTHROW
1193{ 1197{
1194 int dirn; 1198 int dirn;
1195 1199
1196 want_refresh = 1; 1200 want_refresh = 1;
1197 ZERO_SCROLLBACK (); 1201 ZERO_SCROLLBACK ();
1214/* 1218/*
1215 * Erase part or whole of a line 1219 * Erase part or whole of a line
1216 * XTERM_SEQ: Clear line to right: ESC [ 0 K 1220 * XTERM_SEQ: Clear line to right: ESC [ 0 K
1217 * XTERM_SEQ: Clear line to left : ESC [ 1 K 1221 * XTERM_SEQ: Clear line to left : ESC [ 1 K
1218 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1222 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1223 * extension: clear to right unless wrapped: ESC [ 3 K
1219 */ 1224 */
1220void 1225void
1221rxvt_term::scr_erase_line (int mode) 1226rxvt_term::scr_erase_line (int mode) NOTHROW
1222{ 1227{
1223 unsigned int col, num; 1228 unsigned int col, num;
1224 1229
1225 want_refresh = 1; 1230 want_refresh = 1;
1226 ZERO_SCROLLBACK (); 1231 ZERO_SCROLLBACK ();
1232 line.touch (); 1237 line.touch ();
1233 line.is_longer (0); 1238 line.is_longer (0);
1234 1239
1235 switch (mode) 1240 switch (mode)
1236 { 1241 {
1242 case 3:
1243 if (screen.flags & Screen_WrapNext)
1244 return;
1245
1246 /* fall through */
1247
1237 case 0: /* erase to end of line */ 1248 case 0: /* erase to end of line */
1238 col = screen.cur.col; 1249 col = screen.cur.col;
1239 num = ncol - col; 1250 num = ncol - col;
1240 min_it (line.l, col); 1251 min_it (line.l, col);
1252
1241 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1253 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1242 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1254 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1243 CLEAR_SELECTION (); 1255 CLEAR_SELECTION ();
1244 break; 1256 break;
1257
1245 case 1: /* erase to beginning of line */ 1258 case 1: /* erase to beginning of line */
1246 col = 0; 1259 col = 0;
1247 num = screen.cur.col + 1; 1260 num = screen.cur.col + 1;
1261
1248 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur) 1262 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur)
1249 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur)) 1263 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur))
1250 CLEAR_SELECTION (); 1264 CLEAR_SELECTION ();
1251 break; 1265 break;
1266
1252 case 2: /* erase whole line */ 1267 case 2: /* erase whole line */
1253 col = 0; 1268 col = 0;
1254 num = ncol; 1269 num = ncol;
1255 line.l = 0; 1270 line.l = 0;
1256 if (selection.beg.row <= screen.cur.row 1271 if (selection.beg.row <= screen.cur.row
1270 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J 1285 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J
1271 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J 1286 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J
1272 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1287 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1273 */ 1288 */
1274void 1289void
1275rxvt_term::scr_erase_screen (int mode) 1290rxvt_term::scr_erase_screen (int mode) NOTHROW
1276{ 1291{
1277 int num; 1292 int num;
1278 int32_t row; 1293 int32_t row;
1279 rend_t ren; 1294 rend_t ren;
1280 XGCValues gcvalue; 1295 XGCValues gcvalue;
1314 if (row >= nrow) /* Out Of Bounds */ 1329 if (row >= nrow) /* Out Of Bounds */
1315 return; 1330 return;
1316 1331
1317 min_it (num, nrow - row); 1332 min_it (num, nrow - row);
1318 1333
1334 /*TODO: the xlceararea/xfillrectangle below don't take scroll offste into account, ask mikachu for details */
1319 if (rstyle & (RS_RVid | RS_Uline)) 1335 if (rstyle & (RS_RVid | RS_Uline))
1320 ren = (rend_t) ~RS_None; 1336 ren = (rend_t) ~RS_None;
1321 else if (GET_BASEBG (rstyle) == Color_bg) 1337 else if (GET_BASEBG (rstyle) == Color_bg)
1322 { 1338 {
1323 ren = DEFAULT_RSTYLE; 1339 ren = DEFAULT_RSTYLE;
1324 CLEAR_ROWS (row, num); 1340
1341 if (mapped)
1342 XClearArea (dpy, vt, 0,
1343 Row2Pixel (row), (unsigned int)width,
1344 (unsigned int)Height2Pixel (num), False);
1325 } 1345 }
1326 else 1346 else
1327 { 1347 {
1328 ren = rstyle & (RS_fgMask | RS_bgMask); 1348 ren = rstyle & (RS_fgMask | RS_bgMask);
1349
1329 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1350 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1330 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1351 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1331 ERASE_ROWS (row, num); 1352 XFillRectangle (dpy, vt, gc,
1353 0, Row2Pixel (row),
1354 (unsigned int)width,
1355 (unsigned int)Height2Pixel (num));
1332 gcvalue.foreground = pix_colors[Color_fg]; 1356 gcvalue.foreground = pix_colors[Color_fg];
1333 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1357 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1334 } 1358 }
1335 1359
1336 for (; num--; row++) 1360 for (; num--; row++)
1337 { 1361 {
1338 scr_blank_screen_mem (ROW(row), rstyle); 1362 scr_blank_screen_mem (ROW(row), rstyle);
1339 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1363 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1340 } 1364 }
1341} 1365}
1342 1366
1343#if ENABLE_FRILLS 1367#if !ENABLE_MINIMAL
1344void 1368void
1345rxvt_term::scr_erase_savelines () 1369rxvt_term::scr_erase_savelines () NOTHROW
1346{ 1370{
1347 want_refresh = 1; 1371 want_refresh = 1;
1348 ZERO_SCROLLBACK (); 1372 ZERO_SCROLLBACK ();
1349 1373
1350 top_row = 0; 1374 top_row = 0;
1355/* 1379/*
1356 * Fill the screen with `E's 1380 * Fill the screen with `E's
1357 * XTERM_SEQ: Screen Alignment Test: ESC # 8 1381 * XTERM_SEQ: Screen Alignment Test: ESC # 8
1358 */ 1382 */
1359void 1383void
1360rxvt_term::scr_E () 1384rxvt_term::scr_E () NOTHROW
1361{ 1385{
1362 rend_t fs; 1386 rend_t fs;
1363 1387
1364 want_refresh = 1; 1388 want_refresh = 1;
1365 ZERO_SCROLLBACK (); 1389 ZERO_SCROLLBACK ();
1386/* ------------------------------------------------------------------------- */ 1410/* ------------------------------------------------------------------------- */
1387/* 1411/*
1388 * Insert/Delete <count> lines 1412 * Insert/Delete <count> lines
1389 */ 1413 */
1390void 1414void
1391rxvt_term::scr_insdel_lines (int count, int insdel) 1415rxvt_term::scr_insdel_lines (int count, int insdel) NOTHROW
1392{ 1416{
1393 int end; 1417 int end;
1394 1418
1395 ZERO_SCROLLBACK (); 1419 ZERO_SCROLLBACK ();
1396 1420
1416/* ------------------------------------------------------------------------- */ 1440/* ------------------------------------------------------------------------- */
1417/* 1441/*
1418 * Insert/Delete <count> characters from the current position 1442 * Insert/Delete <count> characters from the current position
1419 */ 1443 */
1420void 1444void
1421rxvt_term::scr_insdel_chars (int count, int insdel) 1445rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW
1422{ 1446{
1423 int col, row; 1447 int col, row;
1424 rend_t tr; 1448 rend_t tr;
1425 1449
1426 want_refresh = 1; 1450 want_refresh = 1;
1457 { 1481 {
1458 if (selection.end.row != screen.cur.row 1482 if (selection.end.row != screen.cur.row
1459 || (selection.end.col + count >= ncol)) 1483 || (selection.end.col + count >= ncol))
1460 CLEAR_SELECTION (); 1484 CLEAR_SELECTION ();
1461 else 1485 else
1486 {
1462 { /* shift selection */ 1487 /* shift selection */
1463 selection.beg.col += count; 1488 selection.beg.col += count;
1464 selection.mark.col += count; /* XXX: yes? */ 1489 selection.mark.col += count; /* XXX: yes? */
1465 selection.end.col += count; 1490 selection.end.col += count;
1466 } 1491 }
1467 } 1492 }
1514/* 1539/*
1515 * Set the scrolling region 1540 * Set the scrolling region
1516 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r 1541 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r
1517 */ 1542 */
1518void 1543void
1519rxvt_term::scr_scroll_region (int top, int bot) 1544rxvt_term::scr_scroll_region (int top, int bot) NOTHROW
1520{ 1545{
1521 max_it (top, 0); 1546 max_it (top, 0);
1522 min_it (bot, nrow - 1); 1547 min_it (bot, nrow - 1);
1523 1548
1524 if (top > bot) 1549 if (top > bot)
1534 * Make the cursor visible/invisible 1559 * Make the cursor visible/invisible
1535 * XTERM_SEQ: Make cursor visible : ESC [ ? 25 h 1560 * XTERM_SEQ: Make cursor visible : ESC [ ? 25 h
1536 * XTERM_SEQ: Make cursor invisible: ESC [ ? 25 l 1561 * XTERM_SEQ: Make cursor invisible: ESC [ ? 25 l
1537 */ 1562 */
1538void 1563void
1539rxvt_term::scr_cursor_visible (int mode) 1564rxvt_term::scr_cursor_visible (int mode) NOTHROW
1540{ 1565{
1541 want_refresh = 1; 1566 want_refresh = 1;
1542 1567
1543 if (mode) 1568 if (mode)
1544 screen.flags |= Screen_VisibleCursor; 1569 screen.flags |= Screen_VisibleCursor;
1551 * Set/unset automatic wrapping 1576 * Set/unset automatic wrapping
1552 * XTERM_SEQ: Set Wraparound : ESC [ ? 7 h 1577 * XTERM_SEQ: Set Wraparound : ESC [ ? 7 h
1553 * XTERM_SEQ: Unset Wraparound: ESC [ ? 7 l 1578 * XTERM_SEQ: Unset Wraparound: ESC [ ? 7 l
1554 */ 1579 */
1555void 1580void
1556rxvt_term::scr_autowrap (int mode) 1581rxvt_term::scr_autowrap (int mode) NOTHROW
1557{ 1582{
1558 if (mode) 1583 if (mode)
1559 screen.flags |= Screen_Autowrap; 1584 screen.flags |= Screen_Autowrap;
1560 else 1585 else
1561 screen.flags &= ~(Screen_Autowrap | Screen_WrapNext); 1586 screen.flags &= ~(Screen_Autowrap | Screen_WrapNext);
1570 * and the cursor cannot be moved outside. 1595 * and the cursor cannot be moved outside.
1571 * XTERM_SEQ: Set Absolute: ESC [ ? 6 h 1596 * XTERM_SEQ: Set Absolute: ESC [ ? 6 h
1572 * XTERM_SEQ: Set Relative: ESC [ ? 6 l 1597 * XTERM_SEQ: Set Relative: ESC [ ? 6 l
1573 */ 1598 */
1574void 1599void
1575rxvt_term::scr_relative_origin (int mode) 1600rxvt_term::scr_relative_origin (int mode) NOTHROW
1576{ 1601{
1577 if (mode) 1602 if (mode)
1578 screen.flags |= Screen_Relative; 1603 screen.flags |= Screen_Relative;
1579 else 1604 else
1580 screen.flags &= ~Screen_Relative; 1605 screen.flags &= ~Screen_Relative;
1587 * Set insert/replace mode 1612 * Set insert/replace mode
1588 * XTERM_SEQ: Set Insert mode : ESC [ ? 4 h 1613 * XTERM_SEQ: Set Insert mode : ESC [ ? 4 h
1589 * XTERM_SEQ: Set Replace mode: ESC [ ? 4 l 1614 * XTERM_SEQ: Set Replace mode: ESC [ ? 4 l
1590 */ 1615 */
1591void 1616void
1592rxvt_term::scr_insert_mode (int mode) 1617rxvt_term::scr_insert_mode (int mode) NOTHROW
1593{ 1618{
1594 if (mode) 1619 if (mode)
1595 screen.flags |= Screen_Insert; 1620 screen.flags |= Screen_Insert;
1596 else 1621 else
1597 screen.flags &= ~Screen_Insert; 1622 screen.flags &= ~Screen_Insert;
1603 * XTERM_SEQ: Set tab at current column : ESC H 1628 * XTERM_SEQ: Set tab at current column : ESC H
1604 * XTERM_SEQ: Clear tab at current column: ESC [ 0 g 1629 * XTERM_SEQ: Clear tab at current column: ESC [ 0 g
1605 * XTERM_SEQ: Clear all tabs : ESC [ 3 g 1630 * XTERM_SEQ: Clear all tabs : ESC [ 3 g
1606 */ 1631 */
1607void 1632void
1608rxvt_term::scr_set_tab (int mode) 1633rxvt_term::scr_set_tab (int mode) NOTHROW
1609{ 1634{
1610 if (mode < 0) 1635 if (mode < 0)
1611 memset (tabs, 0, ncol * sizeof (char)); 1636 memset (tabs, 0, ncol);
1612 else if (screen.cur.col < ncol) 1637 else if (screen.cur.col < ncol)
1613 tabs [screen.cur.col] = !!mode; 1638 tabs [screen.cur.col] = !!mode;
1614} 1639}
1615 1640
1616/* ------------------------------------------------------------------------- */ 1641/* ------------------------------------------------------------------------- */
1618 * Set reverse/normal video 1643 * Set reverse/normal video
1619 * XTERM_SEQ: Reverse video: ESC [ ? 5 h 1644 * XTERM_SEQ: Reverse video: ESC [ ? 5 h
1620 * XTERM_SEQ: Normal video : ESC [ ? 5 l 1645 * XTERM_SEQ: Normal video : ESC [ ? 5 l
1621 */ 1646 */
1622void 1647void
1623rxvt_term::scr_rvideo_mode (int mode) 1648rxvt_term::scr_rvideo_mode (bool on) NOTHROW
1624{ 1649{
1625 XGCValues gcvalue; 1650 rvideo_mode = on;
1626 1651
1652#ifndef NO_BELL
1653 on ^= rvideo_bell;
1654#endif
1655
1627 if (rvideo != mode) 1656 if (rvideo_state != on)
1628 { 1657 {
1629 rvideo = mode; 1658 rvideo_state = on;
1659
1630 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1660 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1631#if XPM_BACKGROUND 1661#ifdef HAVE_BG_PIXMAP
1632 if (bgPixmap.pixmap == None) 1662 if (bgPixmap.pixmap == None)
1633#endif 1663#endif
1634#if TRANSPARENT 1664 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 1665
1666 XGCValues gcvalue;
1640 gcvalue.foreground = pix_colors[Color_fg]; 1667 gcvalue.foreground = pix_colors[Color_fg];
1641 gcvalue.background = pix_colors[Color_bg]; 1668 gcvalue.background = pix_colors[Color_bg];
1642 XChangeGC (display->display, gc, GCBackground | GCForeground, 1669 XChangeGC (dpy, gc, GCBackground | GCForeground, &gcvalue);
1643 &gcvalue); 1670
1644 scr_clear (); 1671 scr_clear ();
1645 scr_touch (true); 1672 scr_touch (true);
1646 } 1673 }
1647} 1674}
1648 1675
1650/* 1677/*
1651 * Report current cursor position 1678 * Report current cursor position
1652 * XTERM_SEQ: Report position: ESC [ 6 n 1679 * XTERM_SEQ: Report position: ESC [ 6 n
1653 */ 1680 */
1654void 1681void
1655rxvt_term::scr_report_position () 1682rxvt_term::scr_report_position () NOTHROW
1656{ 1683{
1657 tt_printf ("\033[%d;%dR", screen.cur.row + 1, screen.cur.col + 1); 1684 tt_printf ("\033[%d;%dR", screen.cur.row + 1, screen.cur.col + 1);
1658} 1685}
1659 1686
1660/* ------------------------------------------------------------------------- * 1687/* ------------------------------------------------------------------------- *
1663 1690
1664/* 1691/*
1665 * Set font style 1692 * Set font style
1666 */ 1693 */
1667void 1694void
1668rxvt_term::set_font_style () 1695rxvt_term::set_font_style () NOTHROW
1669{ 1696{
1670#if 0 1697#if 0
1671 switch (charsets [screen.charset]) 1698 switch (charsets [screen.charset])
1672 { 1699 {
1673 case '0': /* DEC Special Character & Line Drawing Set */ 1700 case '0': /* DEC Special Character & Line Drawing Set */
1695 * XTERM_SEQ: Invoke G1 character set: CTRL-N 1722 * XTERM_SEQ: Invoke G1 character set: CTRL-N
1696 * XTERM_SEQ: Invoke G2 character set: ESC N 1723 * XTERM_SEQ: Invoke G2 character set: ESC N
1697 * XTERM_SEQ: Invoke G3 character set: ESC O 1724 * XTERM_SEQ: Invoke G3 character set: ESC O
1698 */ 1725 */
1699void 1726void
1700rxvt_term::scr_charset_choose (int set) 1727rxvt_term::scr_charset_choose (int set) NOTHROW
1701{ 1728{
1702 screen.charset = set; 1729 screen.charset = set;
1703 set_font_style (); 1730 set_font_style ();
1704} 1731}
1705 1732
1711 * XTERM_SEQ: Set G2 character set: ESC * <C> 1738 * XTERM_SEQ: Set G2 character set: ESC * <C>
1712 * XTERM_SEQ: Set G3 character set: ESC + <C> 1739 * XTERM_SEQ: Set G3 character set: ESC + <C>
1713 * See set_font_style for possible values for <C> 1740 * See set_font_style for possible values for <C>
1714 */ 1741 */
1715void 1742void
1716rxvt_term::scr_charset_set (int set, unsigned int ch) 1743rxvt_term::scr_charset_set (int set, unsigned int ch) NOTHROW
1717{ 1744{
1718 charsets[set] = (unsigned char)ch; 1745 charsets[set] = (unsigned char)ch;
1719 set_font_style (); 1746 set_font_style ();
1720} 1747}
1721 1748
1726 1753
1727/* 1754/*
1728 * refresh matching text. 1755 * refresh matching text.
1729 */ 1756 */
1730bool 1757bool
1731rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) 1758rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) NOTHROW
1732{ 1759{
1733 bool found = false; 1760 bool found = false;
1734 1761
1735 for (int i = 0; i < nrow; i++) 1762 for (int i = 0; i < nrow; i++)
1736 { 1763 {
1737 int col = 0;
1738 rend_t *drp = drawn_buf[i].r; 1764 rend_t *drp = drawn_buf[i].r;
1739 1765
1740 for (; col < ncol; col++, drp++) 1766 for (int col = 0; col < ncol; col++, drp++)
1741 if ((*drp & mask) == value) 1767 if ((*drp & mask) == value)
1742 { 1768 {
1743 found = true; 1769 found = true;
1744 *drp = ~value; 1770 *drp = ~value;
1745 } 1771 }
1756 PART_END, 1782 PART_END,
1757 RC_COUNT 1783 RC_COUNT
1758}; 1784};
1759 1785
1760void 1786void
1761rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) 1787rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) NOTHROW
1762{ 1788{
1763 int i; 1789 int i;
1764 row_col_t rc[RC_COUNT]; 1790 row_col_t rc[RC_COUNT];
1765 1791
1766 if (!drawn_buf) /* sanity check */ 1792 if (!drawn_buf) /* sanity check */
1785 for (i = PART_BEG; i < RC_COUNT; i++) 1811 for (i = PART_BEG; i < RC_COUNT; i++)
1786 { 1812 {
1787 min_it (rc[i].col, ncol - 1); 1813 min_it (rc[i].col, ncol - 1);
1788 min_it (rc[i].row, nrow - 1); 1814 min_it (rc[i].row, nrow - 1);
1789 } 1815 }
1790 1816// 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++) 1817 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); 1818 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1);
1793 1819
1794 num_scr_allow = 0; 1820 num_scr_allow = 0;
1795 1821
1800/* ------------------------------------------------------------------------- */ 1826/* ------------------------------------------------------------------------- */
1801/* 1827/*
1802 * Refresh the entire screen 1828 * Refresh the entire screen
1803 */ 1829 */
1804void 1830void
1805rxvt_term::scr_touch (bool refresh) 1831rxvt_term::scr_touch (bool refresh) NOTHROW
1806{ 1832{
1807 scr_expose (0, 0, width, height, refresh); 1833 scr_expose (0, 0, width, height, refresh);
1808} 1834}
1809 1835
1810/* ------------------------------------------------------------------------- */ 1836/* ------------------------------------------------------------------------- */
1811/* 1837/*
1812 * Move the display so that the line represented by scrollbar value Y is at 1838 * Move the display so that the line represented by scrollbar value Y is at
1813 * the top of the screen 1839 * the top of the screen
1814 */ 1840 */
1815void 1841void
1816rxvt_term::scr_move_to (int y, int len) 1842rxvt_term::scr_move_to (int y, int len) NOTHROW
1817{ 1843{
1818 scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1)); 1844 scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1));
1819} 1845}
1820 1846
1821/* ------------------------------------------------------------------------- */ 1847/* ------------------------------------------------------------------------- */
1822/* 1848/*
1823 * Page the screen up/down nlines 1849 * Page the screen up/down nlines
1824 * direction should be UP or DN 1850 * direction should be UP or DN
1825 */ 1851 */
1826bool 1852bool
1827rxvt_term::scr_page (enum page_dirn direction, int nlines) 1853rxvt_term::scr_page (enum page_dirn direction, int nlines) NOTHROW
1828{ 1854{
1829 int new_view_start = 1855 int new_view_start =
1830 direction == UP ? view_start - nlines 1856 direction == UP ? view_start - nlines
1831 : view_start + nlines; 1857 : view_start + nlines;
1832 1858
1833 return scr_changeview (new_view_start); 1859 return scr_changeview (new_view_start);
1834} 1860}
1835 1861
1836bool 1862bool
1837rxvt_term::scr_changeview (int new_view_start) 1863rxvt_term::scr_changeview (int new_view_start) NOTHROW
1838{ 1864{
1839 clamp_it (new_view_start, top_row, 0); 1865 clamp_it (new_view_start, top_row, 0);
1840 1866
1841 if (new_view_start == view_start) 1867 if (new_view_start == view_start)
1842 return false; 1868 return false;
1848 HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END)); 1874 HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END));
1849 1875
1850 return true; 1876 return true;
1851} 1877}
1852 1878
1853/* ------------------------------------------------------------------------- */ 1879#ifndef NO_BELL
1854void 1880void
1881rxvt_term::bell_cb (ev::timer &w, int revents)
1882{
1883 rvideo_bell = false;
1884 scr_rvideo_mode (rvideo_mode);
1885 refresh_check ();
1886}
1887#endif
1888
1889/* ------------------------------------------------------------------------- */
1890void
1855rxvt_term::scr_bell () 1891rxvt_term::scr_bell () NOTHROW
1856{ 1892{
1857#ifndef NO_BELL 1893#ifndef NO_BELL
1858 1894
1859# ifndef NO_MAPALERT 1895# ifndef NO_MAPALERT
1860# ifdef MAPALERT_OPTION 1896# ifdef MAPALERT_OPTION
1861 if (OPTION (Opt_mapAlert)) 1897 if (option (Opt_mapAlert))
1862# endif 1898# endif
1863 XMapWindow (display->display, parent[0]); 1899 XMapWindow (dpy, parent[0]);
1864# endif 1900# endif
1865 1901
1866 if (OPTION (Opt_visualBell)) 1902# if ENABLE_FRILLS
1903 if (option (Opt_urgentOnBell))
1904 {
1905 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1906 {
1907 h->flags |= XUrgencyHint;
1908 XSetWMHints (dpy, parent[0], h);
1909 }
1867 { 1910 }
1868 scr_rvideo_mode (!rvideo); /* refresh also done */ 1911# endif
1912
1913 if (option (Opt_visualBell))
1914 {
1915 rvideo_bell = true;
1916 scr_rvideo_mode (rvideo_mode);
1869 display->flush (); 1917 flush ();
1918
1870 rxvt_usleep (VISUAL_BELL_DURATION); 1919 bell_ev.start (VISUAL_BELL_DURATION);
1871 scr_rvideo_mode (!rvideo); /* refresh also done */
1872 } 1920 }
1873 else 1921 else
1874 XBell (display->display, 0); 1922 XBell (dpy, 0);
1875
1876#endif 1923#endif
1877} 1924}
1878 1925
1879/* ------------------------------------------------------------------------- */ 1926/* ------------------------------------------------------------------------- */
1880/* ARGSUSED */ 1927/* ARGSUSED */
1881void 1928void
1882rxvt_term::scr_printscreen (int fullhist) 1929rxvt_term::scr_printscreen (int fullhist) NOTHROW
1883{ 1930{
1884#ifdef PRINTPIPE 1931#ifdef PRINTPIPE
1885 int nrows, row_start; 1932 int nrows, row_start;
1886 FILE *fd; 1933 FILE *fd = popen_printer ();
1887 1934
1888 if ((fd = popen_printer ()) == NULL) 1935 if (!fd)
1889 return; 1936 return;
1890 1937
1891 if (fullhist) 1938 if (fullhist)
1892 { 1939 {
1893 nrows = nrow - top_row; 1940 nrows = nrow - top_row;
1936 * Refresh the screen 1983 * Refresh the screen
1937 * drawn_text/drawn_rend contain the screen information before the update. 1984 * drawn_text/drawn_rend contain the screen information before the update.
1938 * screen.text/screen.rend contain what the screen will change to. 1985 * screen.text/screen.rend contain what the screen will change to.
1939 */ 1986 */
1940void 1987void
1941rxvt_term::scr_refresh () 1988rxvt_term::scr_refresh () NOTHROW
1942{ 1989{
1943 unsigned char must_clear, /* use draw_string not draw_image_string */ 1990 unsigned char have_bg,
1944 showcursor; /* show the cursor */ 1991 showcursor; /* show the cursor */
1945 int16_t col, row, /* column/row we're processing */ 1992 int16_t col, row, /* column/row we're processing */
1946 ocrow; /* old cursor row */ 1993 ocrow; /* old cursor row */
1947 int i; /* tmp */ 1994 int i; /* tmp */
1948#ifndef NO_CURSORCOLOR 1995#ifndef NO_CURSORCOLOR
1949 rend_t cc1; /* store colours at cursor position (s) */ 1996 rend_t cc1; /* store colours at cursor position (s) */
1950#endif 1997#endif
1951 rend_t *crp; // cursor rendition pointer 1998 rend_t *crp; // cursor rendition pointer
1999 rend_t ccol1, /* Cursor colour */
2000 ccol2; /* Cursor colour2 */
1952 2001
1953 want_refresh = 0; /* screen is current */ 2002 want_refresh = 0; /* screen is current */
1954 2003
1955 if (refresh_type == NO_REFRESH || !mapped) 2004 if (refresh_type == NO_REFRESH || !mapped)
1956 return; 2005 return;
1957 2006
1958 /* 2007 /*
1959 * A: set up vars 2008 * A: set up vars
1960 */ 2009 */
1961 must_clear = 0;
1962 refresh_count = 0; 2010 refresh_count = 0;
1963 2011
1964#if XPM_BACKGROUND 2012 have_bg = 0;
2013#ifdef HAVE_BG_PIXMAP
1965 must_clear |= bgPixmap.pixmap != None; 2014 have_bg = bgPixmap.pixmap != None;
1966#endif
1967#if TRANSPARENT
1968 must_clear |= OPTION (Opt_transparent) && am_transparent;
1969#endif 2015#endif
1970 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2016 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1971 2017
1972 /* 2018 /*
1973 * B: reverse any characters which are selected 2019 * B: reverse any characters which are selected
1977 /* 2023 /*
1978 * C: set the cursor character (s) 2024 * C: set the cursor character (s)
1979 */ 2025 */
1980 { 2026 {
1981 unsigned char setoldcursor; 2027 unsigned char setoldcursor;
1982 rend_t ccol1, /* Cursor colour */
1983 ccol2; /* Cursor colour2 */
1984 2028
1985 showcursor = (screen.flags & Screen_VisibleCursor); 2029 showcursor = (screen.flags & Screen_VisibleCursor);
1986#ifdef CURSOR_BLINK 2030#ifdef CURSOR_BLINK
1987 if (hidden_cursor) 2031 if (hidden_cursor)
1988 showcursor = 0; 2032 showcursor = 0;
1995 while (col && ROW(screen.cur.row).t[col] == NOCHAR) 2039 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
1996 col--; 2040 col--;
1997 2041
1998 crp = &ROW(screen.cur.row).r[col]; 2042 crp = &ROW(screen.cur.row).r[col];
1999 2043
2044#ifndef NO_CURSORCOLOR
2045 cc1 = *crp & (RS_fgMask | RS_bgMask);
2046 if (ISSET_PIXCOLOR (Color_cursor))
2047 ccol1 = Color_cursor;
2048 else
2049#endif
2050#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2051 ccol1 = fgcolor_of (rstyle);
2052#else
2053 ccol1 = Color_fg;
2054#endif
2055
2056#ifndef NO_CURSORCOLOR
2057 if (ISSET_PIXCOLOR (Color_cursor2))
2058 ccol2 = Color_cursor2;
2059 else
2060#endif
2061#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2062 ccol2 = bgcolor_of (rstyle);
2063#else
2064 ccol2 = Color_bg;
2065#endif
2066
2000 if (showcursor && focus) 2067 if (showcursor && focus)
2001 { 2068 {
2002 if (OPTION (Opt_cursorUnderline)) 2069 if (option (Opt_cursorUnderline))
2003 *crp ^= RS_Uline; 2070 *crp ^= RS_Uline;
2004 else 2071 else
2005 { 2072 {
2006 *crp ^= RS_RVid; 2073 *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); 2074 *crp = SET_FGCOLOR (*crp, ccol1);
2027 *crp = SET_BGCOLOR (*crp, ccol2); 2075 *crp = SET_BGCOLOR (*crp, ccol2);
2028#endif
2029 } 2076 }
2030 } 2077 }
2031 } 2078 }
2032 2079
2033 /* make sure no outline cursor is left around */ 2080 /* make sure no outline cursor is left around */
2072 * D: CopyArea pass - very useful for slower links 2119 * D: CopyArea pass - very useful for slower links
2073 * This has been deliberately kept simple. 2120 * This has been deliberately kept simple.
2074 */ 2121 */
2075 if (!display->is_local 2122 if (!display->is_local
2076 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr 2123 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr
2077 && abs (num_scr) < nrow && !must_clear) 2124 && abs (num_scr) < nrow && !have_bg)
2078 { 2125 {
2079 int16_t nits; 2126 int16_t nits;
2127 int i = num_scr;
2080 int j; 2128 int j;
2081 int len, wlen; 2129 int len, wlen;
2082 dLocal (int, num_scr); 2130 dLocal (int, num_scr);
2083 2131
2084 j = nrow; 2132 j = nrow;
2085 wlen = len = -1; 2133 wlen = len = -1;
2086 row = i > 0 ? 0 : j - 1; 2134 row = i > 0 ? 0 : j - 1;
2135
2087 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2136 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2088 { 2137 {
2089 if (row + i >= 0 && row + i < nrow && row + i != ocrow) 2138 if (row + i >= 0 && row + i < nrow && row + i != ocrow)
2090 { 2139 {
2091 line_t s = ROW(view_start + row); 2140 line_t s = ROW(view_start + row);
2112 wlen = row; 2161 wlen = row;
2113 continue; 2162 continue;
2114 } 2163 }
2115 } 2164 }
2116 2165
2117 if (len != -1) 2166 if (len >= 0)
2118 { 2167 {
2119 /* also comes here at end if needed because of >= above */ 2168 /* also comes here at end if needed because of >= above */
2120 if (wlen < len) 2169 if (wlen < len)
2121 ::swap (wlen, len); 2170 ::swap (wlen, len);
2122 2171
2172 XGCValues gcv;
2173
2174 gcv.graphics_exposures = 1; XChangeGC (dpy, gc, GCGraphicsExposures, &gcv);
2123 XCopyArea (display->display, vt, vt, 2175 XCopyArea (dpy, vt, vt,
2124 gc, 0, Row2Pixel (len + i), 2176 gc, 0, Row2Pixel (len + i),
2125 (unsigned int)this->width, 2177 (unsigned int)this->width,
2126 (unsigned int)Height2Pixel (wlen - len + 1), 2178 (unsigned int)Height2Pixel (wlen - len + 1),
2127 0, Row2Pixel (len)); 2179 0, Row2Pixel (len));
2180 gcv.graphics_exposures = 0; XChangeGC (dpy, gc, GCGraphicsExposures, &gcv);
2181
2128 len = -1; 2182 len = -1;
2129 } 2183 }
2130 } 2184 }
2131 } 2185 }
2132#endif 2186#endif
2188 count++; 2242 count++;
2189 2243
2190 if (stp[col] != dtp[col] 2244 if (stp[col] != dtp[col]
2191 || !RS_SAME (srp[col], drp[col])) 2245 || !RS_SAME (srp[col], drp[col]))
2192 { 2246 {
2193 if (must_clear && (i++ > count / 2)) 2247 if (have_bg && (i++ > count / 2))
2194 break; 2248 break;
2195 2249
2196 dtp[col] = stp[col]; 2250 dtp[col] = stp[col];
2197 drp[col] = rend; 2251 drp[col] = rend;
2198 i = 0; 2252 i = 0;
2199 } 2253 }
2200 else if (must_clear || (stp[col] != ' ' && ++i >= 16)) 2254 else if (have_bg || (stp[col] != ' ' && ++i >= 16))
2201 break; 2255 break;
2202 } 2256 }
2203 2257
2204 col--; /* went one too far. move back */ 2258 col--; /* went one too far. move back */
2205 count -= i; /* dump any matching trailing chars */ 2259 count -= i; /* dump any matching trailing chars */
2215 int back = bgcolor_of (rend); // desired background 2269 int back = bgcolor_of (rend); // desired background
2216 2270
2217 // only do special processing if any attributes are set, which is unlikely 2271 // 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)) 2272 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))
2219 { 2273 {
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; 2274 bool invert = rend & RS_RVid;
2233 2275
2234#ifndef NO_BOLD_UNDERLINE_REVERSE 2276#ifndef NO_BOLD_UNDERLINE_REVERSE
2235 if (rend & RS_Bold
2236 && fore == Color_fg) 2277 if (rend & RS_Bold && fore == Color_fg)
2237 { 2278 {
2238 if (ISSET_PIXCOLOR (Color_BD)) 2279 if (ISSET_PIXCOLOR (Color_BD))
2239 fore = Color_BD; 2280 fore = Color_BD;
2240# if !ENABLE_STYLES 2281# if !ENABLE_STYLES
2241 else 2282 else
2242 invert = !invert; 2283 invert = !invert;
2243# endif 2284# endif
2244 } 2285 }
2245 2286
2246 if (rend & RS_Italic 2287 if (rend & RS_Italic && fore == Color_fg)
2247 && fore == Color_fg)
2248 { 2288 {
2249 if (ISSET_PIXCOLOR (Color_IT)) 2289 if (ISSET_PIXCOLOR (Color_IT))
2250 fore = Color_IT; 2290 fore = Color_IT;
2251# if !ENABLE_STYLES 2291# if !ENABLE_STYLES
2252 else 2292 else
2253 invert = !invert; 2293 invert = !invert;
2254# endif 2294# endif
2255 } 2295 }
2256 2296
2257 if (rend & RS_Uline && ISSET_PIXCOLOR (Color_UL)) 2297 if (rend & RS_Uline && fore == Color_fg && ISSET_PIXCOLOR (Color_UL))
2258 fore = Color_UL; 2298 fore = Color_UL;
2259#endif 2299#endif
2260 2300
2261 if (invert) 2301 if (invert)
2262 { 2302 {
2303#ifdef OPTION_HC
2304 if ((showcursor && row == screen.cur.row && text - stp == screen.cur.col)
2305 || !ISSET_PIXCOLOR (Color_HC))
2306#endif
2307 /* invert the column if no highlightColor is set or it is the
2308 * current cursor column */
2263 ::swap (fore, back); 2309 ::swap (fore, back);
2310#ifdef OPTION_HC
2311 else if (ISSET_PIXCOLOR (Color_HC))
2312 back = Color_HC;
2313#endif
2264 2314
2265#ifndef NO_BOLD_UNDERLINE_REVERSE 2315#ifndef NO_BOLD_UNDERLINE_REVERSE
2316# ifndef OPTION_HC
2266 if (ISSET_PIXCOLOR (Color_RV)) 2317 if (ISSET_PIXCOLOR (Color_RV))
2267 back = Color_RV; 2318 back = Color_RV;
2268 2319# endif
2269 if (fore == back) 2320 if (fore == back)
2270 { 2321 {
2271 fore = Color_bg; 2322 fore = Color_bg;
2272 back = Color_fg; 2323 back = Color_fg;
2273 } 2324 }
2275 } 2326 }
2276 2327
2277#ifdef TEXT_BLINK 2328#ifdef TEXT_BLINK
2278 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg)) 2329 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg))
2279 { 2330 {
2280 if (!text_blink_ev.active) 2331 if (!text_blink_ev.is_active ())
2281 { 2332 {
2282 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2333 text_blink_ev.again ();
2283 hidden_text = 0; 2334 hidden_text = 0;
2284 } 2335 }
2285 else if (hidden_text) 2336 else if (hidden_text)
2286 fore = back; 2337 fore = back;
2287 } 2338 }
2288#endif 2339#endif
2340
2341#if ENABLE_STYLES
2342 // "careful" (too wide) character handling
2343
2344 // include previous careful character(s) if possible, looks nicer (best effort...)
2345 while (text > stp
2346 && srp[text - stp - 1] & RS_Careful
2347 && RS_SAME (rend, srp[text - stp - 1]))
2348 text--, count++, xpixel -= fwidth;
2349
2350 // force redraw after "careful" characters to avoid pixel droppings
2351 for (int i = 0; srp[col + i] & RS_Careful && col + i < ncol - 1; i++)
2352 drp[col + i + 1] = srp[col + i + 1] ^ RS_redraw;
2353
2354 // force redraw before "careful" characters to avoid pixel droppings
2355 for (int i = 0; srp[text - stp - i] & RS_Careful && text - i > stp; i++)
2356 drp[text - stp - i - 1] = srp[text - stp - i - 1] ^ RS_redraw;
2357#endif
2289 } 2358 }
2290 2359
2291 /* 2360 /*
2292 * Actually do the drawing of the string here 2361 * Actually do the drawing of the string here
2293 */ 2362 */
2294 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2363 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2295 2364
2296 if (back == fore)
2297 font->clear_rect (*drawable, xpixel, ypixel,
2298 fwidth * count, fheight,
2299 back);
2300 else if (back == Color_bg) 2365 if (have_bg && back == Color_bg)
2301 { 2366 {
2302 if (must_clear) 2367 // this is very ugly, maybe push it into ->draw?
2303 {
2304 CLEAR_CHARS (xpixel, ypixel, count);
2305 2368
2306 for (i = 0; i < count; i++) /* don't draw empty strings */ 2369 for (i = 0; i < count; i++) /* don't draw empty strings */
2307 if (text[i] != ' ') 2370 if (text[i] != ' ')
2308 { 2371 {
2309 font->draw (*drawable, xpixel, ypixel, text, count, fore, -1); 2372 font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_transparent);
2310 break; 2373 goto did_clear;
2311 }
2312 } 2374 }
2313 else 2375
2314 font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_bg); 2376 CLEAR_CHARS (xpixel, ypixel, count);
2377 did_clear: ;
2315 } 2378 }
2316 else 2379 else
2317 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2380 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2318 2381
2319 if (rend & RS_Uline && font->descent > 1 && fore != back) 2382 if (rend & RS_Uline && font->descent > 1 && fore != back)
2320 { 2383 {
2321#if ENABLE_FRILLS 2384#if ENABLE_FRILLS
2322 if (ISSET_PIXCOLOR (Color_underline)) 2385 if (ISSET_PIXCOLOR (Color_underline))
2323 XSetForeground (display->display, gc, pix_colors[Color_underline]); 2386 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2324 else 2387 else
2325#endif 2388#endif
2326 XSetForeground (display->display, gc, pix_colors[fore]); 2389 XSetForeground (dpy, gc, pix_colors[fore]);
2327 2390
2328 XDrawLine (display->display, drawBuffer, gc, 2391 XDrawLine (dpy, vt, gc,
2329 xpixel, ypixel + font->ascent + 1, 2392 xpixel, ypixel + font->ascent + 1,
2330 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2393 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2331 } 2394 }
2332 } /* for (col....) */ 2395 } /* for (col....) */
2333 } /* for (row....) */ 2396 } /* for (row....) */
2342 */ 2405 */
2343 if (showcursor) 2406 if (showcursor)
2344 { 2407 {
2345 if (focus) 2408 if (focus)
2346 { 2409 {
2347 if (OPTION (Opt_cursorUnderline)) 2410 if (option (Opt_cursorUnderline))
2348 *crp ^= RS_Uline; 2411 *crp ^= RS_Uline;
2349 else 2412 else
2350 { 2413 {
2351 *crp ^= RS_RVid; 2414 *crp ^= RS_RVid;
2352#ifndef NO_CURSORCOLOR 2415#ifndef NO_CURSORCOLOR
2366 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR) 2429 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2367 cursorwidth++; 2430 cursorwidth++;
2368 2431
2369#ifndef NO_CURSORCOLOR 2432#ifndef NO_CURSORCOLOR
2370 if (ISSET_PIXCOLOR (Color_cursor)) 2433 if (ISSET_PIXCOLOR (Color_cursor))
2371 XSetForeground (display->display, gc, pix_colors[Color_cursor]); 2434 XSetForeground (dpy, gc, pix_colors[Color_cursor]);
2435 else
2372#endif 2436#endif
2437 XSetForeground (dpy, gc, pix_colors[ccol1]);
2373 2438
2374 XDrawRectangle (display->display, drawBuffer, gc, 2439 XDrawRectangle (dpy, vt, gc,
2375 Col2Pixel (col), 2440 Col2Pixel (col),
2376 Row2Pixel (oldcursor.row), 2441 Row2Pixel (oldcursor.row),
2377 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2442 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2378 (unsigned int) (Height2Pixel (1) - lineSpace - 1)); 2443 (unsigned int) (Height2Pixel (1) - lineSpace - 1));
2379 } 2444 }
2387 num_scr = 0; 2452 num_scr = 0;
2388 num_scr_allow = 1; 2453 num_scr_allow = 1;
2389} 2454}
2390 2455
2391void 2456void
2392rxvt_term::scr_remap_chars (line_t &l) 2457rxvt_term::scr_remap_chars (line_t &l) NOTHROW
2393{ 2458{
2394 if (!l.t) 2459 if (!l.t)
2395 return; 2460 return;
2396 2461
2397 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant 2462 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant
2399 for (int i = ncol; i--; ) 2464 for (int i = ncol; i--; )
2400 l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i])); 2465 l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i]));
2401} 2466}
2402 2467
2403void 2468void
2404rxvt_term::scr_remap_chars () 2469rxvt_term::scr_remap_chars () NOTHROW
2405{ 2470{
2406 for (int i = total_rows; i--; ) 2471 for (int i = total_rows; i--; )
2407 scr_remap_chars (row_buf [i]); 2472 scr_remap_chars (row_buf [i]);
2408 2473
2409 for (int i = nrow; i--; ) 2474 for (int i = nrow; i--; )
2412 scr_remap_chars (swap_buf [i]); 2477 scr_remap_chars (swap_buf [i]);
2413 } 2478 }
2414} 2479}
2415 2480
2416void 2481void
2417rxvt_term::scr_recolour () 2482rxvt_term::scr_recolour () NOTHROW
2418{ 2483{
2419 if (1 2484#ifdef HAVE_BG_PIXMAP
2420#if TRANSPARENT 2485 bgPixmap.apply ();
2421 && !am_transparent 2486#else
2422#endif 2487
2423#if XPM_BACKGROUND
2424 && !bgPixmap.pixmap
2425#endif
2426 )
2427 {
2428 XSetWindowBackground (display->display, parent[0], pix_colors[Color_border]); 2488 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]);
2429 XClearWindow (display->display, parent[0]); 2489 XClearWindow (dpy, parent[0]);
2430 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); 2490 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2431#if HAVE_SCROLLBARS 2491
2432 if (scrollBar.win) 2492 if (scrollBar.win)
2433 { 2493 {
2434 XSetWindowBackground (display->display, scrollBar.win, pix_colors[Color_border]); 2494 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2435 scrollBar.setIdle (); 2495 scrollBar.state = STATE_IDLE;
2436 scrollbar_show (0); 2496 scrollBar.show (0);
2437 }
2438#endif
2439 } 2497 }
2440 2498
2499#endif
2500
2501 /* bgPixmap.apply () does not do the following : */
2441 scr_clear (); 2502 scr_clear ();
2442 scr_touch (true); 2503 scr_touch (true);
2443 want_refresh = 1; 2504 want_refresh = 1;
2444} 2505}
2445 2506
2446/* ------------------------------------------------------------------------- */ 2507/* ------------------------------------------------------------------------- */
2447void 2508void
2448rxvt_term::scr_clear (bool really) 2509rxvt_term::scr_clear (bool really) NOTHROW
2449{ 2510{
2450 if (!mapped) 2511 if (!mapped)
2451 return; 2512 return;
2452 2513
2453 num_scr_allow = 0; 2514 num_scr_allow = 0;
2454 want_refresh = 1; 2515 want_refresh = 1;
2455 2516
2456 if (really) 2517 if (really)
2457 XClearWindow (display->display, vt); 2518 XClearWindow (dpy, vt);
2458} 2519}
2459 2520
2460void 2521void
2461rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) 2522rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) NOTHROW
2462{ 2523{
2463 int view_end = view_start + nrow; 2524 int view_end = view_start + nrow;
2464 int row, col; 2525 int row, col;
2465 2526
2466 for (row = max (beg_row, view_start); row <= min (end_row, view_end); row++) 2527 for (row = max (beg_row, view_start); row <= min (end_row, view_end); row++)
2478 srp[col] ^= rstyle2; 2539 srp[col] ^= rstyle2;
2479 } 2540 }
2480} 2541}
2481 2542
2482void 2543void
2483rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle) 2544rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle) NOTHROW
2484{ 2545{
2485 int view_end = view_start + nrow; 2546 int view_end = view_start + nrow;
2486 int row, col; 2547 int row, col;
2487 2548
2488 if (beg_row >= view_start) 2549 if (beg_row >= view_start)
2505 srp[col] ^= rstyle; 2566 srp[col] ^= rstyle;
2506} 2567}
2507 2568
2508/* ------------------------------------------------------------------------- */ 2569/* ------------------------------------------------------------------------- */
2509void 2570void
2510rxvt_term::scr_reverse_selection () 2571rxvt_term::scr_reverse_selection () NOTHROW
2511{ 2572{
2512 if (selection.op 2573 if (selection.op
2513 && current_screen == selection.screen 2574 && current_screen == selection.screen
2514 && selection.end.row >= view_start) 2575 && selection.end.row >= view_start)
2515 { 2576 {
2516#if ENABLE_FRILLS 2577#if !ENABLE_MINIMAL
2517 if (selection.rect) 2578 if (selection.rect)
2518 scr_xor_rect (selection.beg.row, selection.beg.col, 2579 scr_xor_rect (selection.beg.row, selection.beg.col,
2519 selection.end.row, selection.end.col, 2580 selection.end.row, selection.end.col,
2520 RS_RVid, RS_RVid | RS_Uline); 2581 RS_RVid, RS_RVid | RS_Uline);
2521 else 2582 else
2531 * Dump the whole scrollback and screen to the passed filedescriptor. The 2592 * Dump the whole scrollback and screen to the passed filedescriptor. The
2532 * invoking routine must close the fd. 2593 * invoking routine must close the fd.
2533 */ 2594 */
2534#if 0 2595#if 0
2535void 2596void
2536rxvt_term::scr_dump (int fd) 2597rxvt_term::scr_dump (int fd) NOTHROW
2537{ 2598{
2538 int row, wrote; 2599 int row, wrote;
2539 unsigned int width, towrite; 2600 unsigned int width, towrite;
2540 char r1[] = "\n"; 2601 char r1[] = "\n";
2541 2602
2542 for (row = saveLines - nsaved; 2603 for (row = saveLines + top_row;
2543 row < saveLines + nrow - 1; row++) 2604 row < saveLines + nrow - 1; row++)
2544 { 2605 {
2545 width = row_buf[row].l >= 0 ? row_buf[row].l 2606 width = row_buf[row].l >= 0 ? row_buf[row].l
2546 : ncol; 2607 : ncol;
2547 for (towrite = width; towrite; towrite -= wrote) 2608 for (towrite = width; towrite; towrite -= wrote)
2560 2621
2561/* ------------------------------------------------------------------------- * 2622/* ------------------------------------------------------------------------- *
2562 * CHARACTER SELECTION * 2623 * CHARACTER SELECTION *
2563 * ------------------------------------------------------------------------- */ 2624 * ------------------------------------------------------------------------- */
2564void 2625void
2565rxvt_term::selection_check (int check_more) 2626rxvt_term::selection_check (int check_more) NOTHROW
2566{ 2627{
2567 row_col_t pos; 2628 row_col_t pos;
2568 2629
2569 if (!selection.op) 2630 if (!selection.op)
2570 return; 2631 return;
2591/* ------------------------------------------------------------------------- */ 2652/* ------------------------------------------------------------------------- */
2592/* 2653/*
2593 * Paste a selection direct to the command fd 2654 * Paste a selection direct to the command fd
2594 */ 2655 */
2595void 2656void
2596rxvt_term::paste (char *data, unsigned int len) 2657rxvt_term::paste (char *data, unsigned int len) NOTHROW
2597{ 2658{
2598 /* convert normal newline chars into common keyboard Return key sequence */ 2659 /* convert normal newline chars into common keyboard Return key sequence */
2599 for (unsigned int i = 0; i < len; i++) 2660 for (unsigned int i = 0; i < len; i++)
2600 if (data[i] == C0_LF) 2661 if (data[i] == C0_LF)
2601 data[i] = C0_CR; 2662 data[i] = C0_CR;
2602 2663
2664 if (priv_modes & PrivMode_BracketPaste)
2665 tt_printf ("\e[200~");
2666
2603 tt_write (data, len); 2667 tt_write (data, len);
2668
2669 if (priv_modes & PrivMode_BracketPaste)
2670 tt_printf ("\e[201~");
2604} 2671}
2605 2672
2606/* ------------------------------------------------------------------------- */ 2673/* ------------------------------------------------------------------------- */
2607/* 2674/*
2608 * Respond to a notification that a primary selection has been sent 2675 * Respond to a notification that a primary selection has been sent
2609 * EXT: SelectionNotify 2676 * EXT: SelectionNotify
2610 */ 2677 */
2611void 2678void
2612rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) 2679rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) NOTHROW
2613{ 2680{
2614 if (prop == None) /* check for failed XConvertSelection */ 2681 if (prop == None) /* check for failed XConvertSelection */
2615 { 2682 {
2616 if ((selection_type & Sel_CompoundText)) 2683 if ((selection_type & Sel_CompoundText))
2617 { 2684 {
2637 } 2704 }
2638 2705
2639 unsigned long bytes_after; 2706 unsigned long bytes_after;
2640 XTextProperty ct; 2707 XTextProperty ct;
2641 2708
2642 if (XGetWindowProperty (display->display, win, prop, 2709 if (XGetWindowProperty (dpy, win, prop,
2643 0, PROP_SIZE / 4, 2710 0, PROP_SIZE / 4,
2644 delete_prop, AnyPropertyType, 2711 delete_prop, AnyPropertyType,
2645 &ct.encoding, &ct.format, 2712 &ct.encoding, &ct.format,
2646 &ct.nitems, &bytes_after, 2713 &ct.nitems, &bytes_after,
2647 &ct.value) != Success) 2714 &ct.value) != Success)
2656 if (bytes_after) 2723 if (bytes_after)
2657 { 2724 {
2658 // fetch and append remaining data 2725 // fetch and append remaining data
2659 XTextProperty ct2; 2726 XTextProperty ct2;
2660 2727
2661 if (XGetWindowProperty (display->display, win, prop, 2728 if (XGetWindowProperty (dpy, win, prop,
2662 ct.nitems / 4, (bytes_after + 3) / 4, 2729 ct.nitems / 4, (bytes_after + 3) / 4,
2663 delete_prop, AnyPropertyType, 2730 delete_prop, AnyPropertyType,
2664 &ct2.encoding, &ct2.format, 2731 &ct2.encoding, &ct2.format,
2665 &ct2.nitems, &bytes_after, 2732 &ct2.nitems, &bytes_after,
2666 &ct2.value) != Success) 2733 &ct2.value) != Success)
2679 2746
2680 if (ct.encoding == xa[XA_INCR]) 2747 if (ct.encoding == xa[XA_INCR])
2681 { 2748 {
2682 // INCR selection, start handshake 2749 // INCR selection, start handshake
2683 if (!delete_prop) 2750 if (!delete_prop)
2684 XDeleteProperty (display->display, win, prop); 2751 XDeleteProperty (dpy, win, prop);
2685 2752
2686 selection_wait = Sel_incr; 2753 selection_wait = Sel_incr;
2687 incr_buf_fill = 0; 2754 incr_buf_fill = 0;
2688 incr_ev.start (NOW + 10); 2755 incr_ev.start (10);
2689 2756
2690 goto bailout; 2757 goto bailout;
2691 } 2758 }
2692 2759
2693 if (ct.nitems == 0) 2760 if (ct.nitems == 0)
2702 ct.nitems = incr_buf_fill; 2769 ct.nitems = incr_buf_fill;
2703 incr_buf = 0; 2770 incr_buf = 0;
2704 incr_buf_size = 0; 2771 incr_buf_size = 0;
2705 incr_ev.stop (); 2772 incr_ev.stop ();
2706 } 2773 }
2707 else 2774 else
2708 { 2775 {
2709 if (selection_wait == Sel_normal 2776 if (selection_wait == Sel_normal
2710 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2777 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2711 { 2778 {
2712 /* 2779 /*
2719 goto bailout; 2786 goto bailout;
2720 } 2787 }
2721 } 2788 }
2722 else if (selection_wait == Sel_incr) 2789 else if (selection_wait == Sel_incr)
2723 { 2790 {
2724 incr_ev.start (NOW + 10); 2791 incr_ev.start (10);
2725 2792
2726 while (incr_buf_fill + ct.nitems > incr_buf_size) 2793 while (incr_buf_fill + ct.nitems > incr_buf_size)
2727 { 2794 {
2728 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024; 2795 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2729 incr_buf = (char *)realloc (incr_buf, incr_buf_size); 2796 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2736 } 2803 }
2737 2804
2738 char **cl; 2805 char **cl;
2739 int cr; 2806 int cr;
2740 2807
2741#if ENABLE_FRILLS 2808#if !ENABLE_MINIMAL
2742 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 2809 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2743 // so recode it manually 2810 // so recode it manually
2744 if (ct.encoding == xa[XA_UTF8_STRING]) 2811 if (ct.encoding == xa[XA_UTF8_STRING])
2745 { 2812 {
2746 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); 2813 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2750 paste (s, strlen (s)); 2817 paste (s, strlen (s));
2751 free (s); 2818 free (s);
2752 } 2819 }
2753 else 2820 else
2754#endif 2821#endif
2755 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 2822 if (XmbTextPropertyToTextList (dpy, &ct, &cl, &cr) >= 0
2756 && cl) 2823 && cl)
2757 { 2824 {
2758 for (int i = 0; i < cr; i++) 2825 for (int i = 0; i < cr; i++)
2759 paste (cl[i], strlen (cl[i])); 2826 paste (cl[i], strlen (cl[i]));
2760 2827
2769 if (selection_wait == Sel_normal) 2836 if (selection_wait == Sel_normal)
2770 selection_wait = Sel_none; 2837 selection_wait = Sel_none;
2771} 2838}
2772 2839
2773void 2840void
2774rxvt_term::incr_cb (time_watcher &w) 2841rxvt_term::incr_cb (ev::timer &w, int revents) NOTHROW
2775{ 2842{
2776 selection_wait = Sel_none; 2843 selection_wait = Sel_none;
2777 2844
2778 incr_buf_size = 0; 2845 incr_buf_size = 0;
2779 free (incr_buf); 2846 free (incr_buf);
2780 2847
2781 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 2848 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2782} 2849}
2783 2850
2784void 2851void
2785rxvt_term::selection_property (Window win, Atom prop) 2852rxvt_term::selection_property (Window win, Atom prop) NOTHROW
2786{ 2853{
2787 if (prop == None || selection_wait != Sel_incr) 2854 if (prop == None || selection_wait != Sel_incr)
2788 return; 2855 return;
2789 2856
2790 selection_paste (win, prop, true); 2857 selection_paste (win, prop, true);
2791} 2858}
2792 2859
2793/* ------------------------------------------------------------------------- */ 2860/* ------------------------------------------------------------------------- */
2794/* 2861/*
2795 * Request the current selection: 2862 * Request the current selection:
2796 * Order: > internal selection if available 2863 * Order: > internal selection if available
2797 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+) 2864 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+)
2798 * > CUT_BUFFER0 2865 * > CUT_BUFFER0
2799 * (+) if ownership is claimed but property is empty, rxvt_selection_paste () 2866 * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
2800 * will auto fallback to CUT_BUFFER0 2867 * will auto fallback to CUT_BUFFER0
2801 * EXT: button 2 release 2868 * EXT: button 2 release
2802 */ 2869 */
2803void 2870void
2804rxvt_term::selection_request (Time tm) 2871rxvt_term::selection_request (Time tm, int selnum) NOTHROW
2805{ 2872{
2806 if (selection.text) 2873 if (selection.text && selnum == Sel_Primary)
2874 {
2807 { /* internal selection */ 2875 /* internal selection */
2808 char *str = rxvt_wcstombs (selection.text, selection.len); 2876 char *str = rxvt_wcstombs (selection.text, selection.len);
2809 paste (str, strlen (str)); 2877 paste (str, strlen (str));
2810 free (str); 2878 free (str);
2811 return; 2879 return;
2812 } 2880 }
2813 else 2881 else
2814 { 2882 {
2815 int i;
2816
2817 selection_request_time = tm; 2883 selection_request_time = tm;
2818 selection_wait = Sel_normal; 2884 selection_wait = Sel_normal;
2819 2885
2820 for (i = Sel_Primary; i <= Sel_Clipboard; i++)
2821 {
2822#if X_HAVE_UTF8_STRING 2886#if X_HAVE_UTF8_STRING
2823 selection_type = Sel_UTF8String; 2887 selection_type = Sel_UTF8String;
2824 if (selection_request_other (xa[XA_UTF8_STRING], i)) 2888 if (selection_request_other (xa[XA_UTF8_STRING], selnum))
2825 return; 2889 return;
2826#else 2890#else
2827 selection_type = Sel_CompoundText; 2891 selection_type = Sel_CompoundText;
2828 if (selection_request_other (xa[XA_COMPOUND_TEXT], i)) 2892 if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum))
2829 return; 2893 return;
2830#endif 2894#endif
2831 }
2832 } 2895 }
2833 2896
2834 selection_wait = Sel_none; /* don't loop in selection_paste () */ 2897 selection_wait = Sel_none; /* don't loop in selection_paste () */
2835 selection_paste (display->root, XA_CUT_BUFFER0, false); 2898 selection_paste (display->root, XA_CUT_BUFFER0, false);
2836} 2899}
2837 2900
2838int 2901int
2839rxvt_term::selection_request_other (Atom target, int selnum) 2902rxvt_term::selection_request_other (Atom target, int selnum) NOTHROW
2840{ 2903{
2841 Atom sel; 2904 Atom sel;
2842 2905
2843 selection_type |= selnum; 2906 selection_type |= selnum;
2844 2907
2847 else if (selnum == Sel_Secondary) 2910 else if (selnum == Sel_Secondary)
2848 sel = XA_SECONDARY; 2911 sel = XA_SECONDARY;
2849 else 2912 else
2850 sel = xa[XA_CLIPBOARD]; 2913 sel = xa[XA_CLIPBOARD];
2851 2914
2852 if (XGetSelectionOwner (display->display, sel) != None) 2915 if (XGetSelectionOwner (dpy, sel) != None)
2853 { 2916 {
2854 XConvertSelection (display->display, sel, target, xa[XA_VT_SELECTION], 2917 XConvertSelection (dpy, sel, target, xa[XA_VT_SELECTION],
2855 vt, selection_request_time); 2918 vt, selection_request_time);
2856 return 1; 2919 return 1;
2857 } 2920 }
2858 2921
2859 return 0; 2922 return 0;
2863/* 2926/*
2864 * Clear all selected text 2927 * Clear all selected text
2865 * EXT: SelectionClear 2928 * EXT: SelectionClear
2866 */ 2929 */
2867void 2930void
2868rxvt_term::selection_clear () 2931rxvt_term::selection_clear () NOTHROW
2869{ 2932{
2870 want_refresh = 1; 2933 want_refresh = 1;
2871 free (selection.text); 2934 free (selection.text);
2872 selection.text = NULL; 2935 selection.text = NULL;
2873 selection.len = 0; 2936 selection.len = 0;
2922 2985
2923 int end_col; 2986 int end_col;
2924 2987
2925 for (; row <= selection.end.row; row++, col = 0) 2988 for (; row <= selection.end.row; row++, col = 0)
2926 { 2989 {
2927#if ENABLE_FRILLS 2990#if !ENABLE_MINIMAL
2928 if (selection.rect) 2991 if (selection.rect)
2929 { 2992 {
2930 col = selection.beg.col; 2993 col = selection.beg.col;
2931 end_col = ncol + 1; 2994 end_col = ncol + 1;
2932 } 2995 }
2935 end_col = ROW(row).l; 2998 end_col = ROW(row).l;
2936 2999
2937 col = max (col, 0); 3000 col = max (col, 0);
2938 3001
2939 if (row == selection.end.row 3002 if (row == selection.end.row
2940#if ENABLE_FRILLS 3003#if !ENABLE_MINIMAL
2941 || selection.rect 3004 || selection.rect
2942#endif 3005#endif
2943 ) 3006 )
2944 min_it (end_col, selection.end.col); 3007 min_it (end_col, selection.end.col);
2945 3008
2968#endif 3031#endif
2969 else 3032 else
2970 new_selection_text[ofs++] = *t++; 3033 new_selection_text[ofs++] = *t++;
2971 } 3034 }
2972 3035
2973#if ENABLE_FRILLS 3036#if !ENABLE_MINIMAL
2974 if (selection.rect) 3037 if (selection.rect)
2975 { 3038 {
2976 while (ofs 3039 while (ofs
2977 && new_selection_text[ofs - 1] != C0_LF 3040 && new_selection_text[ofs - 1] != C0_LF
2978 && unicode::is_space (new_selection_text[ofs - 1])) 3041 && unicode::is_space (new_selection_text[ofs - 1]))
3008 3071
3009 selection_grab (tm); 3072 selection_grab (tm);
3010} 3073}
3011 3074
3012bool 3075bool
3013rxvt_term::selection_grab (Time tm) 3076rxvt_term::selection_grab (Time tm) NOTHROW
3014{ 3077{
3015 selection_time = tm; 3078 selection_time = tm;
3016 3079
3017 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); 3080 XSetSelectionOwner (dpy, XA_PRIMARY, vt, tm);
3018 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) 3081 if (XGetSelectionOwner (dpy, XA_PRIMARY) == vt)
3019 { 3082 {
3020 display->set_selection_owner (this); 3083 display->set_selection_owner (this);
3021 return true; 3084 return true;
3022 } 3085 }
3023 else 3086 else
3027 } 3090 }
3028 3091
3029#if 0 3092#if 0
3030 XTextProperty ct; 3093 XTextProperty ct;
3031 3094
3032 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3095 if (XwcTextListToTextProperty (dpy, &selection.text, 1, XStringStyle, &ct) >= 0)
3033 { 3096 {
3034 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); 3097 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
3035 XFree (ct.value); 3098 XFree (ct.value);
3036 } 3099 }
3037#endif 3100#endif
3041/* 3104/*
3042 * Mark or select text based upon number of clicks: 1, 2, or 3 3105 * Mark or select text based upon number of clicks: 1, 2, or 3
3043 * EXT: button 1 press 3106 * EXT: button 1 press
3044 */ 3107 */
3045void 3108void
3046rxvt_term::selection_click (int clicks, int x, int y) 3109rxvt_term::selection_click (int clicks, int x, int y) NOTHROW
3047{ 3110{
3048 clicks = ((clicks - 1) % 3) + 1; 3111 clicks = ((clicks - 1) % 3) + 1;
3049 selection.clicks = clicks; /* save clicks so extend will work */ 3112 selection.clicks = clicks; /* save clicks so extend will work */
3050 3113
3051 if (clicks == 2 && !selection.rect 3114 if (clicks == 2 && !selection.rect
3070/* ------------------------------------------------------------------------- */ 3133/* ------------------------------------------------------------------------- */
3071/* 3134/*
3072 * Mark a selection at the specified col/row 3135 * Mark a selection at the specified col/row
3073 */ 3136 */
3074void 3137void
3075rxvt_term::selection_start_colrow (int col, int row) 3138rxvt_term::selection_start_colrow (int col, int row) NOTHROW
3076{ 3139{
3077 want_refresh = 1; 3140 want_refresh = 1;
3078 3141
3079 selection.mark.row = row + view_start; 3142 selection.mark.row = row + view_start;
3080 selection.mark.col = col; 3143 selection.mark.col = col;
3083 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); 3146 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1);
3084 3147
3085 while (selection.mark.col > 0 3148 while (selection.mark.col > 0
3086 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) 3149 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3087 --selection.mark.col; 3150 --selection.mark.col;
3088 3151
3089 if (selection.op) 3152 if (selection.op)
3153 {
3090 { /* clear the old selection */ 3154 /* clear the old selection */
3091 selection.beg.row = selection.end.row = selection.mark.row; 3155 selection.beg.row = selection.end.row = selection.mark.row;
3092 selection.beg.col = selection.end.col = selection.mark.col; 3156 selection.beg.col = selection.end.col = selection.mark.col;
3093 } 3157 }
3094 3158
3095 selection.op = SELECTION_INIT; 3159 selection.op = SELECTION_INIT;
3106#define DELIMIT_TEXT(x) \ 3170#define DELIMIT_TEXT(x) \
3107 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x))) 3171 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x)))
3108#define DELIMIT_REND(x) 1 3172#define DELIMIT_REND(x) 1
3109 3173
3110void 3174void
3111rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) 3175rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) NOTHROW
3112{ 3176{
3113 int col, row, dirnadd, tcol, trow, w1, w2; 3177 int col, row, dirnadd, tcol, trow, w1, w2;
3114 row_col_t bound; 3178 row_col_t bound;
3115 text_t *stp; 3179 text_t *stp;
3116 rend_t *srp; 3180 rend_t *srp;
3190 * flag == 0 ==> button 1 3254 * flag == 0 ==> button 1
3191 * flag == 1 ==> button 3 press 3255 * flag == 1 ==> button 3 press
3192 * flag == 2 ==> button 3 motion 3256 * flag == 2 ==> button 3 motion
3193 */ 3257 */
3194void 3258void
3195rxvt_term::selection_extend (int x, int y, int flag) 3259rxvt_term::selection_extend (int x, int y, int flag) NOTHROW
3196{ 3260{
3197 int col = clamp (Pixel2Col (x), 0, ncol); 3261 int col = clamp (Pixel2Col (x), 0, ncol);
3198 int row = clamp (Pixel2Row (y), 0, nrow - 1); 3262 int row = clamp (Pixel2Row (y), 0, nrow - 1);
3199 3263
3200 /* 3264 /*
3226/* ------------------------------------------------------------------------- */ 3290/* ------------------------------------------------------------------------- */
3227/* 3291/*
3228 * Extend the selection to the specified col/row 3292 * Extend the selection to the specified col/row
3229 */ 3293 */
3230void 3294void
3231rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) 3295rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) NOTHROW
3232{ 3296{
3233 row_col_t pos; 3297 row_col_t pos;
3234 enum { 3298 enum {
3235 LEFT, RIGHT 3299 LEFT, RIGHT
3236 } closeto = RIGHT; 3300 } closeto = RIGHT;
3284 * a point/word/line which is either the start or end of the selection 3348 * 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 3349 * and it was decided by whichever point/word/line was `fixed' at the
3286 * time of the most recent button3 press 3350 * time of the most recent button3 press
3287 */ 3351 */
3288 if (button3 && buttonpress) 3352 if (button3 && buttonpress)
3353 {
3289 { /* button3 press */ 3354 /* button3 press */
3290 /* 3355 /*
3291 * first determine which edge of the selection we are closest to 3356 * first determine which edge of the selection we are closest to
3292 */ 3357 */
3293 if (ROWCOL_IS_BEFORE (pos, selection.beg) 3358 if (ROWCOL_IS_BEFORE (pos, selection.beg)
3294 || (!ROWCOL_IS_AFTER (pos, selection.end) 3359 || (!ROWCOL_IS_AFTER (pos, selection.end)
3312 selection.mark.row = selection.beg.row; 3377 selection.mark.row = selection.beg.row;
3313 selection.mark.col = selection.beg.col; 3378 selection.mark.col = selection.beg.col;
3314 } 3379 }
3315 } 3380 }
3316 else 3381 else
3382 {
3317 { /* button1 drag or button3 drag */ 3383 /* button1 drag or button3 drag */
3318 if (ROWCOL_IS_AFTER (selection.mark, pos)) 3384 if (ROWCOL_IS_AFTER (selection.mark, pos))
3319 { 3385 {
3320 if (selection.mark.row == selection.end.row 3386 if (selection.mark.row == selection.end.row
3321 && selection.mark.col == selection.end.col 3387 && selection.mark.col == selection.end.col
3322 && clickchange 3388 && clickchange
3339 3405
3340 if (selection.clicks == 1) 3406 if (selection.clicks == 1)
3341 { 3407 {
3342 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN 3408 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN
3343 && !ROW(selection.beg.row).is_longer () 3409 && !ROW(selection.beg.row).is_longer ()
3344#if ENABLE_FRILLS 3410#if !ENABLE_MINIMAL
3345 && !selection.rect 3411 && !selection.rect
3346#endif 3412#endif
3347 ) 3413 )
3348 selection.beg.col = ncol; 3414 selection.beg.col = ncol;
3349 3415
3350 if ( 3416 if (
3351 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN 3417 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN
3352 && !ROW(selection.end.row).is_longer () 3418 && !ROW(selection.end.row).is_longer ()
3353#if ENABLE_FRILLS 3419#if !ENABLE_MINIMAL
3354 && !selection.rect 3420 && !selection.rect
3355#endif 3421#endif
3356 ) 3422 )
3357 selection.end.col = ncol; 3423 selection.end.col = ncol;
3358 } 3424 }
3365 selection_delimit_word (DN, &selection.end, &selection.end); 3431 selection_delimit_word (DN, &selection.end, &selection.end);
3366 } 3432 }
3367 else if (selection.clicks == 3) 3433 else if (selection.clicks == 3)
3368 { 3434 {
3369#if ENABLE_FRILLS 3435#if ENABLE_FRILLS
3370 if (OPTION (Opt_tripleclickwords)) 3436 if (option (Opt_tripleclickwords))
3371 { 3437 {
3372 selection_delimit_word (UP, &selection.beg, &selection.beg); 3438 selection_delimit_word (UP, &selection.beg, &selection.beg);
3373 3439
3374 for (int end_row = selection.mark.row; end_row < nrow; end_row++) 3440 for (int end_row = selection.mark.row; end_row < nrow; end_row++)
3375 { 3441 {
3376 if (!ROW(end_row).is_longer ()) 3442 if (!ROW(end_row).is_longer ())
3377 { 3443 {
3378 selection.end.row = end_row; 3444 selection.end.row = end_row;
3379 selection.end.col = ROW(end_row).l; 3445 selection.end.col = ROW(end_row).l;
3446# if !ENABLE_MINIMAL
3380 selection_remove_trailing_spaces (); 3447 selection_remove_trailing_spaces ();
3448# endif
3381 break; 3449 break;
3382 } 3450 }
3383 } 3451 }
3384 } 3452 }
3385 else 3453 else
3401 selection.end.row++; 3469 selection.end.row++;
3402 } 3470 }
3403 } 3471 }
3404 3472
3405 if (button3 && buttonpress) 3473 if (button3 && buttonpress)
3474 {
3406 { /* mark may need to be changed */ 3475 /* mark may need to be changed */
3407 if (closeto == LEFT) 3476 if (closeto == LEFT)
3408 { 3477 {
3409 selection.mark.row = selection.end.row; 3478 selection.mark.row = selection.end.row;
3410 selection.mark.col = selection.end.col - (selection.clicks == 2); 3479 selection.mark.col = selection.end.col - (selection.clicks == 2);
3411 } 3480 }
3414 selection.mark.row = selection.beg.row; 3483 selection.mark.row = selection.beg.row;
3415 selection.mark.col = selection.beg.col; 3484 selection.mark.col = selection.beg.col;
3416 } 3485 }
3417 } 3486 }
3418 3487
3419#if ENABLE_FRILLS 3488#if !ENABLE_MINIMAL
3420 if (selection.rect && selection.beg.col > selection.end.col) 3489 if (selection.rect && selection.beg.col > selection.end.col)
3421 ::swap (selection.beg.col, selection.end.col); 3490 ::swap (selection.beg.col, selection.end.col);
3422#endif 3491#endif
3423} 3492}
3424 3493
3425#if ENABLE_FRILLS 3494#if !ENABLE_MINIMAL
3426void 3495void
3427rxvt_term::selection_remove_trailing_spaces () 3496rxvt_term::selection_remove_trailing_spaces () NOTHROW
3428{ 3497{
3429 int32_t end_col, end_row; 3498 int32_t end_col, end_row;
3430 text_t *stp; 3499 text_t *stp;
3431 3500
3432 end_col = selection.end.col; 3501 end_col = selection.end.col;
3470/* 3539/*
3471 * Double click on button 3 when already selected 3540 * Double click on button 3 when already selected
3472 * EXT: button 3 double click 3541 * EXT: button 3 double click
3473 */ 3542 */
3474void 3543void
3475rxvt_term::selection_rotate (int x, int y) 3544rxvt_term::selection_rotate (int x, int y) NOTHROW
3476{ 3545{
3477 selection.clicks = selection.clicks % 3 + 1; 3546 selection.clicks = selection.clicks % 3 + 1;
3478 selection_extend_colrow (Pixel2Col (x), Pixel2Row (y), 1, 0, 1); 3547 selection_extend_colrow (Pixel2Col (x), Pixel2Row (y), 1, 0, 1);
3479} 3548}
3480 3549
3482/* 3551/*
3483 * Respond to a request for our current selection 3552 * Respond to a request for our current selection
3484 * EXT: SelectionRequest 3553 * EXT: SelectionRequest
3485 */ 3554 */
3486void 3555void
3487rxvt_term::selection_send (const XSelectionRequestEvent &rq) 3556rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW
3488{ 3557{
3489 XSelectionEvent ev; 3558 XSelectionEvent ev;
3490 dDisp;
3491 3559
3492 ev.type = SelectionNotify; 3560 ev.type = SelectionNotify;
3493 ev.property = None; 3561 ev.property = None;
3494 ev.display = rq.display; 3562 ev.display = rq.display;
3495 ev.requestor = rq.requestor; 3563 ev.requestor = rq.requestor;
3509 *target++ = xa[XA_COMPOUND_TEXT]; 3577 *target++ = xa[XA_COMPOUND_TEXT];
3510#if X_HAVE_UTF8_STRING 3578#if X_HAVE_UTF8_STRING
3511 *target++ = xa[XA_UTF8_STRING]; 3579 *target++ = xa[XA_UTF8_STRING];
3512#endif 3580#endif
3513 3581
3514 XChangeProperty (disp, rq.requestor, rq.property, XA_ATOM, 3582 XChangeProperty (dpy, rq.requestor, rq.property, XA_ATOM,
3515 32, PropModeReplace, 3583 32, PropModeReplace,
3516 (unsigned char *)target_list, target - target_list); 3584 (unsigned char *)target_list, target - target_list);
3517 ev.property = rq.property; 3585 ev.property = rq.property;
3518 } 3586 }
3519#if TODO // TODO 3587#if TODO // TODO
3522 /* TODO: Handle MULTIPLE */ 3590 /* TODO: Handle MULTIPLE */
3523 } 3591 }
3524#endif 3592#endif
3525 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3593 else if (rq.target == xa[XA_TIMESTAMP] && selection.text)
3526 { 3594 {
3527 XChangeProperty (disp, rq.requestor, rq.property, rq.target, 3595 XChangeProperty (dpy, rq.requestor, rq.property, rq.target,
3528 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3596 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3529 ev.property = rq.property; 3597 ev.property = rq.property;
3530 } 3598 }
3531 else if (rq.target == XA_STRING 3599 else if (rq.target == XA_STRING
3532 || rq.target == xa[XA_TEXT] 3600 || rq.target == xa[XA_TEXT]
3556 style = enc_string; 3624 style = enc_string;
3557 else if (target == xa[XA_TEXT]) 3625 else if (target == xa[XA_TEXT])
3558 style = enc_text; 3626 style = enc_text;
3559 else if (target == xa[XA_COMPOUND_TEXT]) 3627 else if (target == xa[XA_COMPOUND_TEXT])
3560 style = enc_compound_text; 3628 style = enc_compound_text;
3561#if ENABLE_FRILLS 3629#if !ENABLE_MINIMAL
3562 else if (target == xa[XA_UTF8_STRING]) 3630 else if (target == xa[XA_UTF8_STRING])
3563 style = enc_utf8; 3631 style = enc_utf8;
3564#endif 3632#endif
3565 else 3633 else
3566 { 3634 {
3577 { 3645 {
3578 cl = L""; 3646 cl = L"";
3579 selectlen = 0; 3647 selectlen = 0;
3580 } 3648 }
3581 3649
3582#if ENABLE_FRILLS 3650#if !ENABLE_MINIMAL
3583 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 3651 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
3584 // so recode it manually 3652 // so recode it manually
3585 if (style == enc_utf8) 3653 if (style == enc_utf8)
3586 { 3654 {
3587 freect = 1; 3655 freect = 1;
3590 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen); 3658 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen);
3591 ct.nitems = strlen ((char *)ct.value); 3659 ct.nitems = strlen ((char *)ct.value);
3592 } 3660 }
3593 else 3661 else
3594#endif 3662#endif
3595 if (XwcTextListToTextProperty (disp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) 3663 if (XwcTextListToTextProperty (dpy, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0)
3596 freect = 1; 3664 freect = 1;
3597 else 3665 else
3598 { 3666 {
3599 /* if we failed to convert then send it raw */ 3667 /* if we failed to convert then send it raw */
3600 ct.value = (unsigned char *)cl; 3668 ct.value = (unsigned char *)cl;
3601 ct.nitems = selectlen; 3669 ct.nitems = selectlen;
3602 ct.encoding = target; 3670 ct.encoding = target;
3603 } 3671 }
3604 3672
3605 XChangeProperty (disp, rq.requestor, rq.property, 3673 XChangeProperty (dpy, rq.requestor, rq.property,
3606 ct.encoding, 8, PropModeReplace, 3674 ct.encoding, 8, PropModeReplace,
3607 ct.value, (int)ct.nitems); 3675 ct.value, (int)ct.nitems);
3608 ev.property = rq.property; 3676 ev.property = rq.property;
3609 3677
3610 if (freect) 3678 if (freect)
3611 XFree (ct.value); 3679 XFree (ct.value);
3612 } 3680 }
3613 3681
3614 XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev); 3682 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} 3683}
3632 3684
3633/* ------------------------------------------------------------------------- */ 3685/* ------------------------------------------------------------------------- */
3634#ifdef USE_XIM 3686#ifdef USE_XIM
3635void 3687void
3636rxvt_term::im_set_position (XPoint &pos) 3688rxvt_term::im_set_position (XPoint &pos) NOTHROW
3637{ 3689{
3638 XWindowAttributes xwa; 3690 XWindowAttributes xwa;
3639 3691
3640 XGetWindowAttributes (display->display, vt, &xwa); 3692 XGetWindowAttributes (dpy, vt, &xwa);
3641 3693
3642 pos.x = xwa.x + Col2Pixel (screen.cur.col); 3694 pos.x = xwa.x + Col2Pixel (screen.cur.col);
3643 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase; 3695 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase;
3644} 3696}
3645#endif 3697#endif
3646 3698
3647#if ENABLE_OVERLAY 3699#if ENABLE_OVERLAY
3648void 3700void
3649rxvt_term::scr_overlay_new (int x, int y, int w, int h) 3701rxvt_term::scr_overlay_new (int x, int y, int w, int h) NOTHROW
3650{ 3702{
3651 if (nrow < 1 || ncol < 1) 3703 if (nrow < 1 || ncol < 1)
3652 return; 3704 return;
3653 3705
3654 want_refresh = 1; 3706 want_refresh = 1;
3699 *rp = r; 3751 *rp = r;
3700 } 3752 }
3701} 3753}
3702 3754
3703void 3755void
3704rxvt_term::scr_overlay_off () 3756rxvt_term::scr_overlay_off () NOTHROW
3705{ 3757{
3706 if (!ov_text) 3758 if (!ov_text)
3707 return; 3759 return;
3708 3760
3709 want_refresh = 1; 3761 want_refresh = 1;
3717 delete [] ov_text; ov_text = 0; 3769 delete [] ov_text; ov_text = 0;
3718 delete [] ov_rend; ov_rend = 0; 3770 delete [] ov_rend; ov_rend = 0;
3719} 3771}
3720 3772
3721void 3773void
3722rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) 3774rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW
3723{ 3775{
3724 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2) 3776 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2)
3725 return; 3777 return;
3726 3778
3727 x++, y++; 3779 x++, y++;
3729 ov_text[y][x] = text; 3781 ov_text[y][x] = text;
3730 ov_rend[y][x] = rend; 3782 ov_rend[y][x] = rend;
3731} 3783}
3732 3784
3733void 3785void
3734rxvt_term::scr_overlay_set (int x, int y, const char *s) 3786rxvt_term::scr_overlay_set (int x, int y, const char *s) NOTHROW
3735{ 3787{
3736 while (*s) 3788 while (*s)
3737 scr_overlay_set (x++, y, *s++); 3789 scr_overlay_set (x++, y, *s++);
3738} 3790}
3739 3791
3740void 3792void
3741rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) 3793rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) NOTHROW
3742{ 3794{
3743 while (*s) 3795 while (*s)
3744 { 3796 {
3745 text_t t = *s++; 3797 text_t t = *s++;
3746 int width = wcwidth (t); 3798 int width = WCWIDTH (t);
3747 3799
3748 while (width--) 3800 while (width--)
3749 { 3801 {
3750 scr_overlay_set (x++, y, t); 3802 scr_overlay_set (x++, y, t);
3751 t = NOCHAR; 3803 t = NOCHAR;
3752 } 3804 }
3753 } 3805 }
3754} 3806}
3755 3807
3756void 3808void
3757rxvt_term::scr_swap_overlay () 3809rxvt_term::scr_swap_overlay () NOTHROW
3758{ 3810{
3759 if (!ov_text) 3811 if (!ov_text)
3760 return; 3812 return;
3761 3813
3762 // swap screen mem with overlay 3814 // swap screen mem with overlay

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines