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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines