ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/screen.C
(Generate patch)

Comparing rxvt-unicode/src/screen.C (file contents):
Revision 1.215 by root, Sun Jan 8 06:35:23 2006 UTC vs.
Revision 1.307 by root, Fri Jun 27 00:44:32 2008 UTC

1/*--------------------------------*-C-*--------------------------------------* 1/*---------------------------------------------------------------------------*
2 * File: screen.C 2 * File: screen.C
3 *---------------------------------------------------------------------------* 3 *---------------------------------------------------------------------------*
4 * 4 *
5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> 5 * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com>
6 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
26 26
27#include "../config.h" /* NECESSARY */ 27#include "../config.h" /* NECESSARY */
28#include "rxvt.h" /* NECESSARY */ 28#include "rxvt.h" /* NECESSARY */
29#include "rxvtperl.h" /* NECESSARY */ 29#include "rxvtperl.h" /* NECESSARY */
30 30
31#include <X11/Xmd.h> /* get the typedef for CARD32 */
32
33#include <inttypes.h> 31#include <inttypes.h>
34 32
35#include "salloc.C" // HACK, should be a seperate compile! 33#include "salloc.C" // HACK, should be a seperate compile!
36 34
37inline void fill_text (text_t *start, text_t value, int len) 35static inline void fill_text (text_t *start, text_t value, int len)
38{ 36{
39 while (len--) 37 while (len--)
40 *start++ = value; 38 *start++ = value;
41} 39}
42 40
47 45
48/* ------------------------------------------------------------------------- * 46/* ------------------------------------------------------------------------- *
49 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES * 47 * GENERAL SCREEN AND SELECTION UPDATE ROUTINES *
50 * ------------------------------------------------------------------------- */ 48 * ------------------------------------------------------------------------- */
51#define ZERO_SCROLLBACK() \ 49#define ZERO_SCROLLBACK() \
52 if (OPTION (Opt_scrollTtyOutput)) \ 50 if (option (Opt_scrollTtyOutput)) \
53 view_start = 0 51 view_start = 0
54#define CLEAR_SELECTION() \ 52#define CLEAR_SELECTION() \
55 selection.beg.row = selection.beg.col \ 53 selection.beg.row = selection.beg.col \
56 = selection.end.row = selection.end.col = 0 54 = selection.end.row = selection.end.col = 0
57#define CLEAR_ALL_SELECTION() \ 55#define CLEAR_ALL_SELECTION() \
85 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col) 83 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col)
86#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \ 84#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \
87 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col) 85 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col)
88 86
89/* 87/*
90 * CLEAR_ROWS : clear <num> rows starting from row <row>
91 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 88 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
92 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
93 */ 89 */
94#define drawBuffer vt
95
96#define CLEAR_ROWS(row, num) \
97 if (mapped) \
98 XClearArea (display->display, drawBuffer, 0, \
99 Row2Pixel (row), (unsigned int)width, \
100 (unsigned int)Height2Pixel (num), False)
101
102#define CLEAR_CHARS(x, y, num) \ 90#define CLEAR_CHARS(x, y, num) \
103 if (mapped) \ 91 if (mapped) \
104 XClearArea (display->display, drawBuffer, x, y, \ 92 XClearArea (dpy, vt, x, y, \
105 (unsigned int)Width2Pixel (num), \ 93 (unsigned int)Width2Pixel (num), \
106 (unsigned int)Height2Pixel (1), False) 94 (unsigned int)Height2Pixel (1), False)
107
108#define ERASE_ROWS(row, num) \
109 XFillRectangle (display->display, drawBuffer, gc, \
110 0, Row2Pixel (row), \
111 (unsigned int)width, \
112 (unsigned int)Height2Pixel (num))
113 95
114/* ------------------------------------------------------------------------- * 96/* ------------------------------------------------------------------------- *
115 * SCREEN `COMMON' ROUTINES * 97 * SCREEN `COMMON' ROUTINES *
116 * ------------------------------------------------------------------------- */ 98 * ------------------------------------------------------------------------- */
117 99
118/* Fill part/all of a line with blanks. */ 100/* Fill part/all of a line with blanks. */
119void 101void
120rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) 102rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) const NOTHROW
121{ 103{
122 if (!l.t) 104 if (!l.t)
123 { 105 {
124 lalloc (l); 106 lalloc (l);
125 col = 0; 107 col = 0;
126 width = ncol; 108 width = ncol;
127 } 109 }
128 110
129 l.touch (); 111 l.touch ();
130 112
131 efs &= ~RS_baseattrMask; 113 efs &= ~RS_baseattrMask; // remove italic etc. fontstyles
132 efs = SET_FONT (efs, FONTSET (efs)->find_font (' ')); 114 efs = SET_FONT (efs, FONTSET (efs)->find_font (' '));
133 115
134 text_t *et = l.t + col; 116 text_t *et = l.t + col;
135 rend_t *er = l.r + col; 117 rend_t *er = l.r + col;
136 118
142} 124}
143 125
144/* ------------------------------------------------------------------------- */ 126/* ------------------------------------------------------------------------- */
145/* Fill a full line with blanks - make sure it is allocated first */ 127/* Fill a full line with blanks - make sure it is allocated first */
146void 128void
147rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) 129rxvt_term::scr_blank_screen_mem (line_t &l, rend_t efs) const NOTHROW
148{ 130{
149 scr_blank_line (l, 0, ncol, efs); 131 scr_blank_line (l, 0, ncol, efs);
150 132
151 l.l = 0; 133 l.l = 0;
152 l.f = 0; 134 l.f = 0;
161{ 143{
162#if ENABLE_OVERLAY 144#if ENABLE_OVERLAY
163 scr_overlay_off (); 145 scr_overlay_off ();
164#endif 146#endif
165 147
148 rvideo_mode = false;
166 view_start = 0; 149 view_start = 0;
167 num_scr = 0; 150 num_scr = 0;
168 151
169 if (ncol == 0) 152 if (ncol == 0)
170 ncol = 80; 153 ncol = 80;
173 nrow = 24; 156 nrow = 24;
174 157
175 if (ncol == prev_ncol && nrow == prev_nrow) 158 if (ncol == prev_ncol && nrow == prev_nrow)
176 return; 159 return;
177 160
161 if (current_screen != PRIMARY)
162 scr_swap_screen ();
163
178 // we need at least two lines for wrapping to work correctly 164 // we need at least two lines for wrapping to work correctly
179 if (nrow + saveLines < 2) 165 while (nrow + saveLines < 2)
180 { 166 {
181 //TODO//FIXME 167 //TODO//FIXME
182 saveLines++; 168 saveLines++;
183 prev_nrow--; 169 prev_nrow--;
184 nsaved++; 170 top_row--;
185 } 171 }
186 172
187 want_refresh = 1; 173 want_refresh = 1;
188 174
189 int prev_total_rows = prev_nrow + saveLines; 175 int prev_total_rows = prev_nrow + saveLines;
194 180
195 if (!row_buf) 181 if (!row_buf)
196 { 182 {
197 /* 183 /*
198 * first time called so just malloc everything: don't rely on realloc 184 * first time called so just malloc everything: don't rely on realloc
199 * Note: this is still needed so that all the scrollback lines are NULL
200 */ 185 */
201 nsaved = 0; /* no saved lines */ 186 top_row = 0;
202 term_start = 0; 187 term_start = 0;
203 188
204 talloc = new rxvt_salloc (ncol * sizeof (text_t)); 189 talloc = new rxvt_salloc (ncol * sizeof (text_t));
205 ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 190 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
206 191
207 row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 192 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t));
208 temp_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
209 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); 193 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
210 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); 194 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
211 195
212 for (int row = nrow; row--; ) 196 for (int row = nrow; row--; )
213 { 197 {
214 scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE); 198 scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE);
215 scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); 199 scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
236 selection.text = NULL; 220 selection.text = NULL;
237 selection.len = 0; 221 selection.len = 0;
238 selection.op = SELECTION_CLEAR; 222 selection.op = SELECTION_CLEAR;
239 selection.screen = PRIMARY; 223 selection.screen = PRIMARY;
240 selection.clicks = 0; 224 selection.clicks = 0;
241 CLEAR_ALL_SELECTION ();
242 rvideo = 0;
243 } 225 }
244 else 226 else
245 { 227 {
246 /* 228 /*
247 * add or delete rows as appropriate 229 * add or delete rows as appropriate
260 } 242 }
261 } 243 }
262#endif 244#endif
263 245
264 drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); 246 drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t));
265 temp_buf = (line_t *)rxvt_realloc (temp_buf , nrow * sizeof (line_t));
266 swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t)); 247 swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t));
267 248
268 for (int row = min (nrow, prev_nrow); row--; ) 249 for (int row = min (nrow, prev_nrow); row--; )
269 { 250 {
270 lresize (drawn_buf[row]); 251 lresize (drawn_buf[row]);
275 { 256 {
276 swap_buf [row].clear (); scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); 257 swap_buf [row].clear (); scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
277 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 258 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
278 } 259 }
279 260
261 line_t *old_buf = row_buf;
280 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 262 row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t));
281 263
282 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 264 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
283 int pend = MOD (term_start - nsaved , prev_total_rows); 265 int pend = MOD (term_start + top_row , prev_total_rows);
284 int q = total_rows; // rewrapped row 266 int q = total_rows; // rewrapped row
285 267
286 if (nsaved) 268 if (top_row)
287 { 269 {
288 // re-wrap lines, this is rather ugly, possibly because I am too dumb 270 // Re-wrap lines. This is rather ugly, possibly because I am too dumb
289 // to come up with a lean and mean algorithm. 271 // to come up with a lean and mean algorithm.
290 272
291 row_col_t ocur = screen.cur; 273 row_col_t ocur = screen.cur;
292 ocur.row = MOD (term_start + ocur.row, prev_total_rows); 274 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
293 275
327 qline->l = ncol; 309 qline->l = ncol;
328 qline->is_longer (1); 310 qline->is_longer (1);
329 311
330 int qcol = 0; 312 int qcol = 0;
331 313
314 // see below for cursor adjustment rationale
315 if (p == ocur.row)
316 screen.cur.row = q - (total_rows - nrow);
317
332 // fill a single destination line 318 // fill a single destination line
333 while (lofs < llen && qcol < ncol) 319 while (lofs < llen && qcol < ncol)
334 { 320 {
335 int prow = lofs / prev_ncol; 321 int prow = lofs / prev_ncol;
336 int pcol = lofs % prev_ncol; 322 int pcol = lofs % prev_ncol;
346 332
347 line_t &pline = old_buf [prow]; 333 line_t &pline = old_buf [prow];
348 334
349 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 335 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
350 336
351 assert (len);
352 assert (pline.t);
353
354 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); 337 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
355 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); 338 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
356 339
357 lofs += len; 340 lofs += len;
358 qcol += len; 341 qcol += len;
364 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); 347 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
365 } 348 }
366 while (p != pend && q > 0); 349 while (p != pend && q > 0);
367 350
368 term_start = total_rows - nrow; 351 term_start = total_rows - nrow;
369 nsaved = term_start - q; 352 top_row = q - term_start;
370 353
371 // make sure all terminal lines exist 354 // make sure all terminal lines exist
372 while (nsaved < 0) 355 while (top_row > 0)
373 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); 356 scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
374 } 357 }
375 else 358 else
376 { 359 {
377 // if no scrollback exists (yet), wing, instead of wrap 360 // if no scrollback exists (yet), wing, instead of wrap
378 361
379 for (int row = min (nrow, prev_nrow); row--; ) 362 for (int row = min (nrow, prev_nrow); row--; )
380 { 363 {
381 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; 364 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
382 line_t &qline = row_buf [row]; 365 line_t &qline = row_buf [row];
383 366
391 } 374 }
392 375
393 term_start = 0; 376 term_start = 0;
394 } 377 }
395 378
396#ifdef DEBUG_STRICT //TODO: remove
397 for (int i = -nsaved; i < nrow; i++)
398 assert (ROW (i).t);
399#endif
400
401 free (old_buf); 379 free (old_buf);
402 delete old_ta; 380 delete old_ta;
403 delete old_ra; 381 delete old_ra;
404 382
405 clamp_it (screen.cur.row, 0, nrow - 1); 383 clamp_it (screen.cur.row, 0, nrow - 1);
406 clamp_it (screen.cur.col, 0, ncol - 1); 384 clamp_it (screen.cur.col, 0, ncol - 1);
407 385
408 if (tabs)
409 free (tabs); 386 free (tabs);
410 } 387 }
388
389 CLEAR_ALL_SELECTION ();
411 390
412 prev_nrow = nrow; 391 prev_nrow = nrow;
413 prev_ncol = ncol; 392 prev_ncol = ncol;
414 393
415 tabs = (char *)rxvt_malloc (ncol * sizeof (char)); 394 tabs = (char *)rxvt_malloc (ncol);
416 395
417 for (int col = ncol; col--; ) 396 for (int col = ncol; --col; )
418 tabs [col] = col % TABSIZE == 0; 397 tabs [col] = col % TABSIZE == 0;
419 398
399 if (current_screen != PRIMARY)
400 scr_swap_screen ();
401
420 tt_winch (); 402 tt_winch ();
421 403
422 HOOK_INVOKE ((this, HOOK_RESET, DT_END)); 404 HOOK_INVOKE ((this, HOOK_RESET, DT_END));
423} 405}
424 406
425/* ------------------------------------------------------------------------- */ 407/* ------------------------------------------------------------------------- */
426/* 408/*
427 * Free everything. That way malloc debugging can find leakage. 409 * Free everything. That way malloc debugging can find leakage.
428 */ 410 */
429void 411void
430rxvt_term::scr_release () 412rxvt_term::scr_release () NOTHROW
431{ 413{
414 if (row_buf)
415 {
432 delete talloc; talloc = 0; 416 delete talloc; talloc = 0;
433 delete ralloc; ralloc = 0; 417 delete ralloc; ralloc = 0;
434 418
435 free (row_buf); 419 free (row_buf);
436 free (swap_buf); 420 free (swap_buf);
437 free (drawn_buf); 421 free (drawn_buf);
438 free (temp_buf);
439 free (tabs); 422 free (tabs);
440 423
441 row_buf = 0; // signal that we freed all the arrays 424 row_buf = 0; // signal that we freed all the arrays
425 }
442} 426}
443 427
444/* ------------------------------------------------------------------------- */ 428/* ------------------------------------------------------------------------- */
445/* 429/*
446 * Hard reset 430 * Hard reset
451 scr_release (); 435 scr_release ();
452 prev_nrow = prev_ncol = 0; 436 prev_nrow = prev_ncol = 0;
453 scr_reset (); 437 scr_reset ();
454 438
455 scr_clear (true); 439 scr_clear (true);
456 scr_refresh (SLOW_REFRESH); 440 scr_refresh ();
457} 441}
458 442
459/* ------------------------------------------------------------------------- * 443/* ------------------------------------------------------------------------- *
460 * PROCESS SCREEN COMMANDS * 444 * PROCESS SCREEN COMMANDS *
461 * ------------------------------------------------------------------------- */ 445 * ------------------------------------------------------------------------- */
463 * Save and Restore cursor 447 * Save and Restore cursor
464 * XTERM_SEQ: Save cursor : ESC 7 448 * XTERM_SEQ: Save cursor : ESC 7
465 * XTERM_SEQ: Restore cursor: ESC 8 449 * XTERM_SEQ: Restore cursor: ESC 8
466 */ 450 */
467void 451void
468rxvt_term::scr_cursor (int mode) 452rxvt_term::scr_cursor (cursor_mode mode) NOTHROW
469{ 453{
470 screen_t *s; 454 screen_t *s;
471 455
472#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR) 456#if NSCREENS && !defined(NO_SECONDARY_SCREEN_CURSOR)
473 if (current_screen == SECONDARY) 457 if (current_screen == SECONDARY)
505 assert (s->cur.row >= 0); 489 assert (s->cur.row >= 0);
506 assert (s->cur.col >= 0); 490 assert (s->cur.col >= 0);
507#endif 491#endif
508} 492}
509 493
494void
495rxvt_term::scr_swap_screen ()
496{
497 if (!option (Opt_secondaryScreen))
498 return;
499
500 for (int i = prev_nrow; i--; )
501 ::swap (ROW(i), swap_buf [i]);
502
503 ::swap (screen.cur, swap.cur);
504
505 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
506 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
507}
508
510/* ------------------------------------------------------------------------- */ 509/* ------------------------------------------------------------------------- */
511/* 510/*
512 * Swap between primary and secondary screens 511 * Swap between primary and secondary screens
513 * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h 512 * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h
514 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l 513 * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l
515 */ 514 */
516int 515void
517rxvt_term::scr_change_screen (int scrn) 516rxvt_term::scr_change_screen (int scrn)
518{ 517{
518 if (scrn == current_screen)
519 return;
520
519 want_refresh = 1; 521 want_refresh = 1;
520 view_start = 0; 522 view_start = 0;
521 523
522 if (current_screen == scrn)
523 return scrn;
524
525 selection_check (2); /* check for boundary cross */ 524 selection_check (2); /* check for boundary cross */
526 525
527 int i = current_screen; current_screen = scrn; scrn = i; 526 int i = current_screen; current_screen = scrn; scrn = i;
528 527
529 ::swap (screen.cur.row, swap.cur.row);
530 ::swap (screen.cur.col, swap.cur.col);
531
532 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
533 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
534
535#if NSCREENS 528#if NSCREENS
536 if (OPTION (Opt_secondaryScreen)) 529 if (option (Opt_secondaryScreen))
537 { 530 {
538 num_scr = 0; 531 num_scr = 0;
539 532
540 for (int i = prev_nrow; i--; ) 533 scr_swap_screen ();
541 ::swap (ROW(i), swap_buf [i]);
542 534
543 ::swap (screen.charset, swap.charset); 535 ::swap (screen.charset, swap.charset);
544 ::swap (screen.flags, swap.flags); 536 ::swap (screen.flags, swap.flags);
545 screen.flags |= Screen_VisibleCursor; 537 screen.flags |= Screen_VisibleCursor;
546 swap.flags |= Screen_VisibleCursor; 538 swap.flags |= Screen_VisibleCursor;
547 } 539 }
548 else 540 else
549#endif 541#endif
550 if (OPTION (Opt_secondaryScroll)) 542 if (option (Opt_secondaryScroll))
551 scr_scroll_text (0, prev_nrow - 1, prev_nrow); 543 scr_scroll_text (0, prev_nrow - 1, prev_nrow);
552
553 return scrn;
554} 544}
555 545
556// clear WrapNext indicator, solidifying position on next line 546// clear WrapNext indicator, solidifying position on next line
557void 547void
558rxvt_term::scr_do_wrap () 548rxvt_term::scr_do_wrap () NOTHROW
559{ 549{
560 if (!(screen.flags & Screen_WrapNext)) 550 if (!(screen.flags & Screen_WrapNext))
561 return; 551 return;
562 552
563 screen.flags &= ~Screen_WrapNext; 553 screen.flags &= ~Screen_WrapNext;
573/* ------------------------------------------------------------------------- */ 563/* ------------------------------------------------------------------------- */
574/* 564/*
575 * Change the colour for following text 565 * Change the colour for following text
576 */ 566 */
577void 567void
578rxvt_term::scr_color (unsigned int color, int fgbg) 568rxvt_term::scr_color (unsigned int color, int fgbg) NOTHROW
579{ 569{
580 if (color > maxTermCOLOR) 570 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
581 color = fgbg; 571 color = fgbg;
582 572
583 if (fgbg == Color_fg) 573 if (fgbg == Color_fg)
584 rstyle = SET_FGCOLOR (rstyle, color); 574 rstyle = SET_FGCOLOR (rstyle, color);
585 else 575 else
589/* ------------------------------------------------------------------------- */ 579/* ------------------------------------------------------------------------- */
590/* 580/*
591 * Change the rendition style for following text 581 * Change the rendition style for following text
592 */ 582 */
593void 583void
594rxvt_term::scr_rendition (int set, int style) 584rxvt_term::scr_rendition (int set, int style) NOTHROW
595 { 585{
596 if (set) 586 if (set)
597 rstyle |= style; 587 rstyle |= style;
598 else if (style == ~RS_None) 588 else if (style == ~RS_None)
599 rstyle = DEFAULT_RSTYLE; 589 rstyle = DEFAULT_RSTYLE;
600 else 590 else
601 rstyle &= ~style; 591 rstyle &= ~style;
602 } 592}
603 593
604/* ------------------------------------------------------------------------- */ 594/* ------------------------------------------------------------------------- */
605/* 595/*
606 * Scroll text between <row1> and <row2> inclusive, by <count> lines 596 * Scroll text between <row1> and <row2> inclusive, by <count> lines
607 * count positive ==> scroll up 597 * count positive ==> scroll up
608 * count negative ==> scroll down 598 * count negative ==> scroll down
609 */ 599 */
610int 600int
611rxvt_term::scr_scroll_text (int row1, int row2, int count) 601rxvt_term::scr_scroll_text (int row1, int row2, int count) NOTHROW
612{ 602{
613 if (count == 0 || (row1 > row2)) 603 if (count == 0 || (row1 > row2))
614 return 0; 604 return 0;
615 605
616 want_refresh = 1; 606 want_refresh = 1;
617 num_scr += count; 607 num_scr += count;
618 608
619 if (count > 0 609 if (count > 0
620 && row1 == 0 610 && row1 == 0
621 && row2 == nrow - 1
622 && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll))) 611 && (current_screen == PRIMARY || option (Opt_secondaryScroll)))
623 { 612 {
624 nsaved = min (nsaved + count, saveLines); 613 top_row = max (top_row - count, -saveLines);
625 614
626 HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, nsaved, DT_END)); 615 // scroll everything up 'count' lines
627
628 term_start = (term_start + count) % total_rows; 616 term_start = (term_start + count) % total_rows;
629 617
618 // sever bottommost line
619 {
620 line_t &l = ROW(row2 - count);
621 l.is_longer (0);
622 l.touch ();
623 }
624
625 // erase newly scrolled-in lines
626 for (int i = count; i--; )
627 {
628 line_t &l = ROW(nrow - 1 - i);
629
630 // optimize if already cleared, can be significant on slow machines
631 // could be rolled into scr_blank_screen_mem
632 if (l.r && l.l < ncol - 1 && !((l.r[l.l + 1] ^ rstyle) & (RS_fgMask | RS_bgMask)))
633 {
634 scr_blank_line (l, 0, l.l, rstyle);
635 l.l = 0;
636 l.f = 0;
637 }
638 else
639 scr_blank_screen_mem (l, rstyle);
640 }
641
642 // now copy lines below the scroll region bottom to the
643 // bottom of the screen again, so they look as if they
644 // hadn't moved.
645 for (int i = nrow; --i > row2; )
646 {
647 line_t &l1 = ROW(i - count);
648 line_t &l2 = ROW(i);
649
650 ::swap (l1, l2);
651 l2.touch ();
652 }
653
654 // move and/or clear selection, if any
630 if (selection.op && current_screen == selection.screen) 655 if (selection.op && current_screen == selection.screen)
631 { 656 {
632 selection.beg.row -= count; 657 selection.beg.row -= count;
633 selection.end.row -= count; 658 selection.end.row -= count;
634 selection.mark.row -= count; 659 selection.mark.row -= count;
635 660
636 if (selection.beg.row < -nsaved 661 if (selection.beg.row < top_row
637 || selection.end.row < -nsaved 662 || selection.end.row < top_row
638 || selection.mark.row < -nsaved) 663 || selection.mark.row < top_row)
639 { 664 {
640 CLEAR_ALL_SELECTION (); 665 CLEAR_ALL_SELECTION ();
641 selection.op = SELECTION_CLEAR; 666 selection.op = SELECTION_CLEAR;
642 } 667 }
643 } 668 }
644 669
645 for (int i = count; i--; ) 670 // finally move the view window, if desired
646 scr_blank_screen_mem (ROW(row2 - i), rstyle);
647
648 if (OPTION (Opt_scrollWithBuffer) 671 if (option (Opt_scrollWithBuffer)
649 && view_start != 0 672 && view_start != 0
650 && view_start != saveLines) 673 && view_start != -saveLines)
651 scr_page (UP, count); 674 scr_page (UP, count);
675
676 if (SHOULD_INVOKE (HOOK_SCROLL_BACK))
677 HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, top_row, DT_END));
652 } 678 }
653 else 679 else
654 { 680 {
655 if (selection.op && current_screen == selection.screen) 681 if (selection.op && current_screen == selection.screen)
656 { 682 {
668 { 694 {
669 /* move selected region too */ 695 /* move selected region too */
670 selection.beg.row -= count; 696 selection.beg.row -= count;
671 selection.end.row -= count; 697 selection.end.row -= count;
672 selection.mark.row -= count; 698 selection.mark.row -= count;
673 699
674 selection_check (0); 700 selection_check (0);
675 } 701 }
676 } 702 }
677 703
678 // use a simple and robust scrolling algorithm, this 704 // use a simple and robust scrolling algorithm, this
680 706
681 int rows = row2 - row1 + 1; 707 int rows = row2 - row1 + 1;
682 708
683 min_it (count, rows); 709 min_it (count, rows);
684 710
711 line_t *temp_buf = row_buf + total_rows;
712
685 for (int row = 0; row < rows; row++) 713 for (int row = 0; row < rows; row++)
686 { 714 {
687 temp_buf [row] = ROW(row1 + (row + count + rows) % rows); 715 temp_buf [row] = ROW(row1 + (row + count + rows) % rows);
688 716
689 if (!IN_RANGE_EXC (row + count, 0, rows)) 717 if (!IN_RANGE_EXC (row + count, 0, rows))
700/* ------------------------------------------------------------------------- */ 728/* ------------------------------------------------------------------------- */
701/* 729/*
702 * Add text given in <str> of length <len> to screen struct 730 * Add text given in <str> of length <len> to screen struct
703 */ 731 */
704void 732void
705rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) 733rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines) NOTHROW
706{ 734{
707 if (len <= 0) /* sanity */ 735 if (len <= 0) /* sanity */
708 return; 736 return;
709 737
710 unsigned char checksel; 738 unsigned char checksel;
716 ZERO_SCROLLBACK (); 744 ZERO_SCROLLBACK ();
717 745
718 if (minlines > 0) 746 if (minlines > 0)
719 { 747 {
720 minlines += screen.cur.row - screen.bscroll; 748 minlines += screen.cur.row - screen.bscroll;
749 min_it (minlines, screen.cur.row - top_row);
721 750
722 if (minlines > 0 751 if (minlines > 0
723 && screen.tscroll == 0 752 && screen.tscroll == 0
724 && screen.bscroll == nrow - 1) 753 && screen.bscroll == nrow - 1)
725 { 754 {
730 } 759 }
731 760
732#ifdef DEBUG_STRICT 761#ifdef DEBUG_STRICT
733 assert (screen.cur.col < ncol); 762 assert (screen.cur.col < ncol);
734 assert (screen.cur.row < nrow 763 assert (screen.cur.row < nrow
735 && screen.cur.row >= -nsaved); 764 && screen.cur.row >= top_row);
736#endif 765#endif
737 int row = screen.cur.row; 766 int row = screen.cur.row;
738 767
739 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 768 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
740 769
786 CLEAR_SELECTION (); 815 CLEAR_SELECTION ();
787 } 816 }
788 817
789 if (screen.flags & Screen_WrapNext) 818 if (screen.flags & Screen_WrapNext)
790 { 819 {
820 scr_do_wrap ();
821
791 max_it (line->l, ncol); 822 line->l = ncol;
792 line->is_longer (1); 823 line->is_longer (1);
793 824
794 scr_do_wrap ();
795
796 row = screen.cur.row; 825 row = screen.cur.row;
797 line = &ROW(row); /* _must_ refresh */ 826 line = &ROW(row); /* _must_ refresh */
798 } 827 }
799 828
800 // some utf-8 decoders "decode" surrogate characters: let's fix this. 829 // some utf-8 decoders "decode" surrogate characters: let's fix this.
801 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 830 if (IN_RANGE_INC (c, 0xd800, 0xdfff))
802 c = 0xfffd; 831 c = 0xfffd;
803 832
804 // rely on wcwidth to tell us the character width, at least for non-latin1 833 // rely on wcwidth to tell us the character width, do wcwidth before
805 // do wcwidth before further replacements, as wcwidth might return -1 834 // further replacements, as wcwidth might return -1 for the line
806 // for the line drawing characters below as they might be invalid in the current 835 // drawing characters below as they might be invalid in the current
807 // locale. 836 // locale.
808 int width = c < 0x100 ? 1 : wcwidth (c); 837 int width = WCWIDTH (c);
809 838
810 if (charsets [screen.charset] == '0') // DEC SPECIAL 839 if (charsets [screen.charset] == '0') // DEC SPECIAL
811 { 840 {
812 // vt100 special graphics and line drawing 841 // vt100 special graphics and line drawing
813 // 5f-7e standard vt100 842 // 5f-7e standard vt100
964/* 993/*
965 * Process Backspace. Move back the cursor back a position, wrap if have to 994 * Process Backspace. Move back the cursor back a position, wrap if have to
966 * XTERM_SEQ: CTRL-H 995 * XTERM_SEQ: CTRL-H
967 */ 996 */
968void 997void
969rxvt_term::scr_backspace () 998rxvt_term::scr_backspace () NOTHROW
970{ 999{
971 want_refresh = 1;
972
973 if (screen.cur.col == 0) 1000 if (screen.cur.col == 0)
974 { 1001 {
975 if (screen.cur.row > 0) 1002 if (screen.cur.row > 0)
976 { 1003 {
977#ifdef TERMCAP_HAS_BW 1004#ifdef TERMCAP_HAS_BW
978 screen.cur.col = ncol - 1; 1005 screen.cur.col = ncol - 1;
979 screen.cur.row--; 1006 --screen.cur.row;
980 return; 1007
1008 want_refresh = 1;
981#endif 1009#endif
982 } 1010 }
983 } 1011 }
984 else if (!(screen.flags & Screen_WrapNext)) 1012 else
985 scr_gotorc (0, -1, RELATIVE); 1013 scr_gotorc (0, -1, RELATIVE);
986
987 screen.flags &= ~Screen_WrapNext;
988} 1014}
989 1015
990/* ------------------------------------------------------------------------- */ 1016/* ------------------------------------------------------------------------- */
991/* 1017/*
992 * Process Horizontal Tab 1018 * Process Horizontal Tab
993 * count: +ve = forward; -ve = backwards 1019 * count: +ve = forward; -ve = backwards
994 * XTERM_SEQ: CTRL-I 1020 * XTERM_SEQ: CTRL-I
995 */ 1021 */
996void 1022void
997rxvt_term::scr_tab (int count, bool ht) 1023rxvt_term::scr_tab (int count, bool ht) NOTHROW
998{ 1024{
999 int i, x; 1025 int i, x;
1000 1026
1001 want_refresh = 1; 1027 want_refresh = 1;
1002 i = x = screen.cur.col; 1028 i = x = screen.cur.col;
1015 x = i; 1041 x = i;
1016 1042
1017 if (!--count) 1043 if (!--count)
1018 break; 1044 break;
1019 } 1045 }
1020 else 1046 else
1021 ht &= l.t[i] == ' ' 1047 ht &= l.t[i] == ' '
1022 && RS_SAME (l.r[i], base_rend); 1048 && RS_SAME (l.r[i], base_rend);
1023 1049
1024 if (count) 1050 if (count)
1025 x = ncol - 1; 1051 x = ncol - 1;
1026 1052
1027 // store horizontal tab commands as characters inside the text 1053 // store horizontal tab commands as characters inside the text
1028 // buffer so they can be selected and pasted. 1054 // buffer so they can be selected and pasted.
1029 if (ht && OPTION (Opt_pastableTabs)) 1055 if (ht && option (Opt_pastableTabs))
1030 { 1056 {
1031 base_rend = SET_FONT (base_rend, 0); 1057 base_rend = SET_FONT (base_rend, 0);
1032 1058
1033 l.touch (x); 1059 l.touch (x);
1034 1060
1067 * Process DEC Back Index 1093 * Process DEC Back Index
1068 * XTERM_SEQ: ESC 6 1094 * XTERM_SEQ: ESC 6
1069 * Move cursor left in row. If we're at the left boundary, shift everything 1095 * Move cursor left in row. If we're at the left boundary, shift everything
1070 * in that row right. Clear left column. 1096 * in that row right. Clear left column.
1071 */ 1097 */
1072#if ENABLE_FRILLS 1098#if !ENABLE_MINIMAL
1073void 1099void
1074rxvt_term::scr_backindex () 1100rxvt_term::scr_backindex () NOTHROW
1075{ 1101{
1076 if (screen.cur.col > 0) 1102 if (screen.cur.col > 0)
1077 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE); 1103 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
1078 else 1104 else
1079 scr_insdel_chars (1, INSERT); 1105 scr_insdel_chars (1, INSERT);
1084 * Process DEC Forward Index 1110 * Process DEC Forward Index
1085 * XTERM_SEQ: ESC 9 1111 * XTERM_SEQ: ESC 9
1086 * Move cursor right in row. If we're at the right boundary, shift everything 1112 * Move cursor right in row. If we're at the right boundary, shift everything
1087 * in that row left. Clear right column. 1113 * in that row left. Clear right column.
1088 */ 1114 */
1089#if ENABLE_FRILLS 1115#if !ENABLE_MINIMAL
1090void 1116void
1091rxvt_term::scr_forwardindex () 1117rxvt_term::scr_forwardindex () NOTHROW
1092{ 1118{
1093 if (screen.cur.col < ncol - 1) 1119 if (screen.cur.col < ncol - 1)
1094 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1120 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1095 else 1121 else
1096 { 1122 {
1109/* ------------------------------------------------------------------------- */ 1135/* ------------------------------------------------------------------------- */
1110/* 1136/*
1111 * Goto Row/Column 1137 * Goto Row/Column
1112 */ 1138 */
1113void 1139void
1114rxvt_term::scr_gotorc (int row, int col, int relative) 1140rxvt_term::scr_gotorc (int row, int col, int relative) NOTHROW
1115{ 1141{
1116 want_refresh = 1; 1142 want_refresh = 1;
1117 ZERO_SCROLLBACK (); 1143 ZERO_SCROLLBACK ();
1118 1144
1119 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col; 1145 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col;
1141 } 1167 }
1142 } 1168 }
1143 else 1169 else
1144 { 1170 {
1145 if (screen.flags & Screen_Relative) 1171 if (screen.flags & Screen_Relative)
1172 {
1146 { /* relative origin mode */ 1173 /* relative origin mode */
1147 screen.cur.row = row + screen.tscroll; 1174 screen.cur.row = row + screen.tscroll;
1148 min_it (screen.cur.row, screen.bscroll); 1175 min_it (screen.cur.row, screen.bscroll);
1149 } 1176 }
1150 else 1177 else
1151 screen.cur.row = row; 1178 screen.cur.row = row;
1157/* ------------------------------------------------------------------------- */ 1184/* ------------------------------------------------------------------------- */
1158/* 1185/*
1159 * direction should be UP or DN 1186 * direction should be UP or DN
1160 */ 1187 */
1161void 1188void
1162rxvt_term::scr_index (enum page_dirn direction) 1189rxvt_term::scr_index (enum page_dirn direction) NOTHROW
1163{ 1190{
1164 int dirn; 1191 int dirn;
1165 1192
1166 want_refresh = 1; 1193 want_refresh = 1;
1167 ZERO_SCROLLBACK (); 1194 ZERO_SCROLLBACK ();
1184/* 1211/*
1185 * Erase part or whole of a line 1212 * Erase part or whole of a line
1186 * XTERM_SEQ: Clear line to right: ESC [ 0 K 1213 * XTERM_SEQ: Clear line to right: ESC [ 0 K
1187 * XTERM_SEQ: Clear line to left : ESC [ 1 K 1214 * XTERM_SEQ: Clear line to left : ESC [ 1 K
1188 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1215 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1216 * extension: clear to right unless wrapped: ESC [ 3 K
1189 */ 1217 */
1190void 1218void
1191rxvt_term::scr_erase_line (int mode) 1219rxvt_term::scr_erase_line (int mode) NOTHROW
1192{ 1220{
1193 unsigned int col, num; 1221 unsigned int col, num;
1194 1222
1195 want_refresh = 1; 1223 want_refresh = 1;
1196 ZERO_SCROLLBACK (); 1224 ZERO_SCROLLBACK ();
1202 line.touch (); 1230 line.touch ();
1203 line.is_longer (0); 1231 line.is_longer (0);
1204 1232
1205 switch (mode) 1233 switch (mode)
1206 { 1234 {
1235 case 3:
1236 if (screen.flags & Screen_WrapNext)
1237 return;
1238
1239 /* fall through */
1240
1207 case 0: /* erase to end of line */ 1241 case 0: /* erase to end of line */
1208 col = screen.cur.col; 1242 col = screen.cur.col;
1209 num = ncol - col; 1243 num = ncol - col;
1210 min_it (line.l, col); 1244 min_it (line.l, col);
1245
1211 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1246 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1212 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1247 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1213 CLEAR_SELECTION (); 1248 CLEAR_SELECTION ();
1214 break; 1249 break;
1250
1215 case 1: /* erase to beginning of line */ 1251 case 1: /* erase to beginning of line */
1216 col = 0; 1252 col = 0;
1217 num = screen.cur.col + 1; 1253 num = screen.cur.col + 1;
1254
1218 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur) 1255 if (ROWCOL_IN_ROW_AT_OR_BEFORE (selection.beg, screen.cur)
1219 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur)) 1256 || ROWCOL_IN_ROW_AT_OR_BEFORE (selection.end, screen.cur))
1220 CLEAR_SELECTION (); 1257 CLEAR_SELECTION ();
1221 break; 1258 break;
1259
1222 case 2: /* erase whole line */ 1260 case 2: /* erase whole line */
1223 col = 0; 1261 col = 0;
1224 num = ncol; 1262 num = ncol;
1225 line.l = 0; 1263 line.l = 0;
1226 if (selection.beg.row <= screen.cur.row 1264 if (selection.beg.row <= screen.cur.row
1240 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J 1278 * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J
1241 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J 1279 * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J
1242 * XTERM_SEQ: Clear whole screen : ESC [ 2 J 1280 * XTERM_SEQ: Clear whole screen : ESC [ 2 J
1243 */ 1281 */
1244void 1282void
1245rxvt_term::scr_erase_screen (int mode) 1283rxvt_term::scr_erase_screen (int mode) NOTHROW
1246{ 1284{
1247 int num; 1285 int num;
1248 int32_t row; 1286 int32_t row;
1249 rend_t ren; 1287 rend_t ren;
1250 XGCValues gcvalue; 1288 XGCValues gcvalue;
1284 if (row >= nrow) /* Out Of Bounds */ 1322 if (row >= nrow) /* Out Of Bounds */
1285 return; 1323 return;
1286 1324
1287 min_it (num, nrow - row); 1325 min_it (num, nrow - row);
1288 1326
1327 /*TODO: the xlceararea/xfillrectangle below don't take scroll offste into account, ask mikachu for details */
1289 if (rstyle & (RS_RVid | RS_Uline)) 1328 if (rstyle & (RS_RVid | RS_Uline))
1290 ren = (rend_t) ~RS_None; 1329 ren = (rend_t) ~RS_None;
1291 else if (GET_BASEBG (rstyle) == Color_bg) 1330 else if (GET_BASEBG (rstyle) == Color_bg)
1292 { 1331 {
1293 ren = DEFAULT_RSTYLE; 1332 ren = DEFAULT_RSTYLE;
1294 CLEAR_ROWS (row, num); 1333
1334 if (mapped)
1335 XClearArea (dpy, vt, 0,
1336 Row2Pixel (row), (unsigned int)width,
1337 (unsigned int)Height2Pixel (num), False);
1295 } 1338 }
1296 else 1339 else
1297 { 1340 {
1298 ren = rstyle & (RS_fgMask | RS_bgMask); 1341 ren = rstyle & (RS_fgMask | RS_bgMask);
1342
1299 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)]; 1343 gcvalue.foreground = pix_colors[bgcolor_of (rstyle)];
1300 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1344 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1301 ERASE_ROWS (row, num); 1345 XFillRectangle (dpy, vt, gc,
1346 0, Row2Pixel (row),
1347 (unsigned int)width,
1348 (unsigned int)Height2Pixel (num));
1302 gcvalue.foreground = pix_colors[Color_fg]; 1349 gcvalue.foreground = pix_colors[Color_fg];
1303 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1350 XChangeGC (dpy, gc, GCForeground, &gcvalue);
1304 } 1351 }
1305 1352
1306 for (; num--; row++) 1353 for (; num--; row++)
1307 { 1354 {
1308 scr_blank_screen_mem (ROW(row), rstyle); 1355 scr_blank_screen_mem (ROW(row), rstyle);
1309 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1356 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1310 } 1357 }
1311} 1358}
1312 1359
1313#if ENABLE_FRILLS 1360#if !ENABLE_MINIMAL
1314void 1361void
1315rxvt_term::scr_erase_savelines () 1362rxvt_term::scr_erase_savelines () NOTHROW
1316{ 1363{
1317 want_refresh = 1; 1364 want_refresh = 1;
1318 ZERO_SCROLLBACK (); 1365 ZERO_SCROLLBACK ();
1319 1366
1320 nsaved = 0; 1367 top_row = 0;
1321} 1368}
1322#endif 1369#endif
1323 1370
1324/* ------------------------------------------------------------------------- */ 1371/* ------------------------------------------------------------------------- */
1325/* 1372/*
1326 * Fill the screen with `E's 1373 * Fill the screen with `E's
1327 * XTERM_SEQ: Screen Alignment Test: ESC # 8 1374 * XTERM_SEQ: Screen Alignment Test: ESC # 8
1328 */ 1375 */
1329void 1376void
1330rxvt_term::scr_E () 1377rxvt_term::scr_E () NOTHROW
1331{ 1378{
1332 rend_t fs; 1379 rend_t fs;
1333 1380
1334 want_refresh = 1; 1381 want_refresh = 1;
1335 ZERO_SCROLLBACK (); 1382 ZERO_SCROLLBACK ();
1356/* ------------------------------------------------------------------------- */ 1403/* ------------------------------------------------------------------------- */
1357/* 1404/*
1358 * Insert/Delete <count> lines 1405 * Insert/Delete <count> lines
1359 */ 1406 */
1360void 1407void
1361rxvt_term::scr_insdel_lines (int count, int insdel) 1408rxvt_term::scr_insdel_lines (int count, int insdel) NOTHROW
1362{ 1409{
1363 int end; 1410 int end;
1364 1411
1365 ZERO_SCROLLBACK (); 1412 ZERO_SCROLLBACK ();
1366 1413
1386/* ------------------------------------------------------------------------- */ 1433/* ------------------------------------------------------------------------- */
1387/* 1434/*
1388 * Insert/Delete <count> characters from the current position 1435 * Insert/Delete <count> characters from the current position
1389 */ 1436 */
1390void 1437void
1391rxvt_term::scr_insdel_chars (int count, int insdel) 1438rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW
1392{ 1439{
1393 int col, row; 1440 int col, row;
1394 rend_t tr; 1441 rend_t tr;
1395 1442
1396 want_refresh = 1; 1443 want_refresh = 1;
1427 { 1474 {
1428 if (selection.end.row != screen.cur.row 1475 if (selection.end.row != screen.cur.row
1429 || (selection.end.col + count >= ncol)) 1476 || (selection.end.col + count >= ncol))
1430 CLEAR_SELECTION (); 1477 CLEAR_SELECTION ();
1431 else 1478 else
1479 {
1432 { /* shift selection */ 1480 /* shift selection */
1433 selection.beg.col += count; 1481 selection.beg.col += count;
1434 selection.mark.col += count; /* XXX: yes? */ 1482 selection.mark.col += count; /* XXX: yes? */
1435 selection.end.col += count; 1483 selection.end.col += count;
1436 } 1484 }
1437 } 1485 }
1484/* 1532/*
1485 * Set the scrolling region 1533 * Set the scrolling region
1486 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r 1534 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r
1487 */ 1535 */
1488void 1536void
1489rxvt_term::scr_scroll_region (int top, int bot) 1537rxvt_term::scr_scroll_region (int top, int bot) NOTHROW
1490{ 1538{
1491 max_it (top, 0); 1539 max_it (top, 0);
1492 min_it (bot, nrow - 1); 1540 min_it (bot, nrow - 1);
1493 1541
1494 if (top > bot) 1542 if (top > bot)
1504 * Make the cursor visible/invisible 1552 * Make the cursor visible/invisible
1505 * XTERM_SEQ: Make cursor visible : ESC [ ? 25 h 1553 * XTERM_SEQ: Make cursor visible : ESC [ ? 25 h
1506 * XTERM_SEQ: Make cursor invisible: ESC [ ? 25 l 1554 * XTERM_SEQ: Make cursor invisible: ESC [ ? 25 l
1507 */ 1555 */
1508void 1556void
1509rxvt_term::scr_cursor_visible (int mode) 1557rxvt_term::scr_cursor_visible (int mode) NOTHROW
1510{ 1558{
1511 want_refresh = 1; 1559 want_refresh = 1;
1512 1560
1513 if (mode) 1561 if (mode)
1514 screen.flags |= Screen_VisibleCursor; 1562 screen.flags |= Screen_VisibleCursor;
1521 * Set/unset automatic wrapping 1569 * Set/unset automatic wrapping
1522 * XTERM_SEQ: Set Wraparound : ESC [ ? 7 h 1570 * XTERM_SEQ: Set Wraparound : ESC [ ? 7 h
1523 * XTERM_SEQ: Unset Wraparound: ESC [ ? 7 l 1571 * XTERM_SEQ: Unset Wraparound: ESC [ ? 7 l
1524 */ 1572 */
1525void 1573void
1526rxvt_term::scr_autowrap (int mode) 1574rxvt_term::scr_autowrap (int mode) NOTHROW
1527{ 1575{
1528 if (mode) 1576 if (mode)
1529 screen.flags |= Screen_Autowrap; 1577 screen.flags |= Screen_Autowrap;
1530 else 1578 else
1531 screen.flags &= ~(Screen_Autowrap | Screen_WrapNext); 1579 screen.flags &= ~(Screen_Autowrap | Screen_WrapNext);
1540 * and the cursor cannot be moved outside. 1588 * and the cursor cannot be moved outside.
1541 * XTERM_SEQ: Set Absolute: ESC [ ? 6 h 1589 * XTERM_SEQ: Set Absolute: ESC [ ? 6 h
1542 * XTERM_SEQ: Set Relative: ESC [ ? 6 l 1590 * XTERM_SEQ: Set Relative: ESC [ ? 6 l
1543 */ 1591 */
1544void 1592void
1545rxvt_term::scr_relative_origin (int mode) 1593rxvt_term::scr_relative_origin (int mode) NOTHROW
1546{ 1594{
1547 if (mode) 1595 if (mode)
1548 screen.flags |= Screen_Relative; 1596 screen.flags |= Screen_Relative;
1549 else 1597 else
1550 screen.flags &= ~Screen_Relative; 1598 screen.flags &= ~Screen_Relative;
1557 * Set insert/replace mode 1605 * Set insert/replace mode
1558 * XTERM_SEQ: Set Insert mode : ESC [ ? 4 h 1606 * XTERM_SEQ: Set Insert mode : ESC [ ? 4 h
1559 * XTERM_SEQ: Set Replace mode: ESC [ ? 4 l 1607 * XTERM_SEQ: Set Replace mode: ESC [ ? 4 l
1560 */ 1608 */
1561void 1609void
1562rxvt_term::scr_insert_mode (int mode) 1610rxvt_term::scr_insert_mode (int mode) NOTHROW
1563{ 1611{
1564 if (mode) 1612 if (mode)
1565 screen.flags |= Screen_Insert; 1613 screen.flags |= Screen_Insert;
1566 else 1614 else
1567 screen.flags &= ~Screen_Insert; 1615 screen.flags &= ~Screen_Insert;
1573 * XTERM_SEQ: Set tab at current column : ESC H 1621 * XTERM_SEQ: Set tab at current column : ESC H
1574 * XTERM_SEQ: Clear tab at current column: ESC [ 0 g 1622 * XTERM_SEQ: Clear tab at current column: ESC [ 0 g
1575 * XTERM_SEQ: Clear all tabs : ESC [ 3 g 1623 * XTERM_SEQ: Clear all tabs : ESC [ 3 g
1576 */ 1624 */
1577void 1625void
1578rxvt_term::scr_set_tab (int mode) 1626rxvt_term::scr_set_tab (int mode) NOTHROW
1579{ 1627{
1580 if (mode < 0) 1628 if (mode < 0)
1581 memset (tabs, 0, ncol * sizeof (char)); 1629 memset (tabs, 0, ncol);
1582 else if (screen.cur.col < ncol) 1630 else if (screen.cur.col < ncol)
1583 tabs [screen.cur.col] = !!mode; 1631 tabs [screen.cur.col] = !!mode;
1584} 1632}
1585 1633
1586/* ------------------------------------------------------------------------- */ 1634/* ------------------------------------------------------------------------- */
1588 * Set reverse/normal video 1636 * Set reverse/normal video
1589 * XTERM_SEQ: Reverse video: ESC [ ? 5 h 1637 * XTERM_SEQ: Reverse video: ESC [ ? 5 h
1590 * XTERM_SEQ: Normal video : ESC [ ? 5 l 1638 * XTERM_SEQ: Normal video : ESC [ ? 5 l
1591 */ 1639 */
1592void 1640void
1593rxvt_term::scr_rvideo_mode (int mode) 1641rxvt_term::scr_rvideo_mode (bool on) NOTHROW
1594{ 1642{
1595 XGCValues gcvalue; 1643 rvideo_mode = on;
1596 1644
1645#ifndef NO_BELL
1646 on ^= rvideo_bell;
1647#endif
1648
1597 if (rvideo != mode) 1649 if (rvideo_state != on)
1598 { 1650 {
1599 rvideo = mode; 1651 rvideo_state = on;
1652
1600 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); 1653 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1601#if XPM_BACKGROUND 1654#ifdef HAVE_BG_PIXMAP
1602 if (bgPixmap.pixmap == None) 1655 if (bgPixmap.pixmap == None)
1603#endif 1656#endif
1604#if TRANSPARENT 1657 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
1605 if (! OPTION (Opt_transparent) || am_transparent == 0)
1606#endif
1607 XSetWindowBackground (display->display, vt,
1608 pix_colors[Color_bg]);
1609 1658
1659 XGCValues gcvalue;
1610 gcvalue.foreground = pix_colors[Color_fg]; 1660 gcvalue.foreground = pix_colors[Color_fg];
1611 gcvalue.background = pix_colors[Color_bg]; 1661 gcvalue.background = pix_colors[Color_bg];
1612 XChangeGC (display->display, gc, GCBackground | GCForeground, 1662 XChangeGC (dpy, gc, GCBackground | GCForeground, &gcvalue);
1613 &gcvalue); 1663
1614 scr_clear (); 1664 scr_clear ();
1615 scr_touch (true); 1665 scr_touch (true);
1616 } 1666 }
1617} 1667}
1618 1668
1620/* 1670/*
1621 * Report current cursor position 1671 * Report current cursor position
1622 * XTERM_SEQ: Report position: ESC [ 6 n 1672 * XTERM_SEQ: Report position: ESC [ 6 n
1623 */ 1673 */
1624void 1674void
1625rxvt_term::scr_report_position () 1675rxvt_term::scr_report_position () NOTHROW
1626{ 1676{
1627 tt_printf ("\033[%d;%dR", screen.cur.row + 1, screen.cur.col + 1); 1677 tt_printf ("\033[%d;%dR", screen.cur.row + 1, screen.cur.col + 1);
1628} 1678}
1629 1679
1630/* ------------------------------------------------------------------------- * 1680/* ------------------------------------------------------------------------- *
1633 1683
1634/* 1684/*
1635 * Set font style 1685 * Set font style
1636 */ 1686 */
1637void 1687void
1638rxvt_term::set_font_style () 1688rxvt_term::set_font_style () NOTHROW
1639{ 1689{
1640#if 0 1690#if 0
1641 switch (charsets [screen.charset]) 1691 switch (charsets [screen.charset])
1642 { 1692 {
1643 case '0': /* DEC Special Character & Line Drawing Set */ 1693 case '0': /* DEC Special Character & Line Drawing Set */
1665 * XTERM_SEQ: Invoke G1 character set: CTRL-N 1715 * XTERM_SEQ: Invoke G1 character set: CTRL-N
1666 * XTERM_SEQ: Invoke G2 character set: ESC N 1716 * XTERM_SEQ: Invoke G2 character set: ESC N
1667 * XTERM_SEQ: Invoke G3 character set: ESC O 1717 * XTERM_SEQ: Invoke G3 character set: ESC O
1668 */ 1718 */
1669void 1719void
1670rxvt_term::scr_charset_choose (int set) 1720rxvt_term::scr_charset_choose (int set) NOTHROW
1671{ 1721{
1672 screen.charset = set; 1722 screen.charset = set;
1673 set_font_style (); 1723 set_font_style ();
1674} 1724}
1675 1725
1681 * XTERM_SEQ: Set G2 character set: ESC * <C> 1731 * XTERM_SEQ: Set G2 character set: ESC * <C>
1682 * XTERM_SEQ: Set G3 character set: ESC + <C> 1732 * XTERM_SEQ: Set G3 character set: ESC + <C>
1683 * See set_font_style for possible values for <C> 1733 * See set_font_style for possible values for <C>
1684 */ 1734 */
1685void 1735void
1686rxvt_term::scr_charset_set (int set, unsigned int ch) 1736rxvt_term::scr_charset_set (int set, unsigned int ch) NOTHROW
1687{ 1737{
1688 charsets[set] = (unsigned char)ch; 1738 charsets[set] = (unsigned char)ch;
1689 set_font_style (); 1739 set_font_style ();
1690} 1740}
1691 1741
1696 1746
1697/* 1747/*
1698 * refresh matching text. 1748 * refresh matching text.
1699 */ 1749 */
1700bool 1750bool
1701rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) 1751rxvt_term::scr_refresh_rend (rend_t mask, rend_t value) NOTHROW
1702{ 1752{
1703 bool found = false; 1753 bool found = false;
1704 1754
1705 for (int i = 0; i < nrow; i++) 1755 for (int i = 0; i < nrow; i++)
1706 { 1756 {
1707 int col = 0;
1708 rend_t *drp = drawn_buf[i].r; 1757 rend_t *drp = drawn_buf[i].r;
1709 1758
1710 for (; col < ncol; col++, drp++) 1759 for (int col = 0; col < ncol; col++, drp++)
1711 if ((*drp & mask) == value) 1760 if ((*drp & mask) == value)
1712 { 1761 {
1713 found = true; 1762 found = true;
1714 *drp = ~value; 1763 *drp = ~value;
1715 } 1764 }
1726 PART_END, 1775 PART_END,
1727 RC_COUNT 1776 RC_COUNT
1728}; 1777};
1729 1778
1730void 1779void
1731rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) 1780rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) NOTHROW
1732{ 1781{
1733 int i; 1782 int i;
1734 row_col_t rc[RC_COUNT]; 1783 row_col_t rc[RC_COUNT];
1735 1784
1736 if (!drawn_buf) /* sanity check */ 1785 if (!drawn_buf) /* sanity check */
1755 for (i = PART_BEG; i < RC_COUNT; i++) 1804 for (i = PART_BEG; i < RC_COUNT; i++)
1756 { 1805 {
1757 min_it (rc[i].col, ncol - 1); 1806 min_it (rc[i].col, ncol - 1);
1758 min_it (rc[i].row, nrow - 1); 1807 min_it (rc[i].row, nrow - 1);
1759 } 1808 }
1760 1809// TODO: this line somehow causes segfault if scr_expose() is called just after resize
1761 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1810 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1762 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); 1811 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1);
1763 1812
1813 num_scr_allow = 0;
1814
1764 if (refresh) 1815 if (refresh)
1765 scr_refresh (SLOW_REFRESH); 1816 scr_refresh ();
1766} 1817}
1767 1818
1768/* ------------------------------------------------------------------------- */ 1819/* ------------------------------------------------------------------------- */
1769/* 1820/*
1770 * Refresh the entire screen 1821 * Refresh the entire screen
1771 */ 1822 */
1772void 1823void
1773rxvt_term::scr_touch (bool refresh) 1824rxvt_term::scr_touch (bool refresh) NOTHROW
1774{ 1825{
1775 scr_expose (0, 0, width, height, refresh); 1826 scr_expose (0, 0, width, height, refresh);
1776} 1827}
1777 1828
1778/* ------------------------------------------------------------------------- */ 1829/* ------------------------------------------------------------------------- */
1779/* 1830/*
1780 * Move the display so that the line represented by scrollbar value Y is at 1831 * Move the display so that the line represented by scrollbar value Y is at
1781 * the top of the screen 1832 * the top of the screen
1782 */ 1833 */
1783int 1834void
1784rxvt_term::scr_move_to (int y, int len) 1835rxvt_term::scr_move_to (int y, int len) NOTHROW
1785{ 1836{
1786 long p = 0; 1837 scr_changeview ((top_row - nrow) * (len - y) / len + (nrow - 1));
1787 unsigned int oldviewstart;
1788
1789 oldviewstart = view_start;
1790
1791 if (y < len)
1792 {
1793 p = (nrow + nsaved) * (len - y) / len;
1794 p -= (long) (nrow - 1);
1795 p = max (p, 0);
1796 }
1797
1798 view_start = (unsigned int)min (p, nsaved);
1799
1800 return scr_changeview (oldviewstart);
1801} 1838}
1802 1839
1803/* ------------------------------------------------------------------------- */ 1840/* ------------------------------------------------------------------------- */
1804/* 1841/*
1805 * Page the screen up/down nlines 1842 * Page the screen up/down nlines
1806 * direction should be UP or DN 1843 * direction should be UP or DN
1807 */ 1844 */
1808int 1845bool
1809rxvt_term::scr_page (enum page_dirn direction, int nlines) 1846rxvt_term::scr_page (enum page_dirn direction, int nlines) NOTHROW
1810{ 1847{
1811 int n; 1848 int new_view_start =
1812 unsigned int oldviewstart;
1813
1814 oldviewstart = view_start;
1815
1816 if (direction == UP)
1817 {
1818 n = view_start + nlines;
1819 view_start = min (n, nsaved);
1820 }
1821 else
1822 {
1823 n = view_start - nlines; 1849 direction == UP ? view_start - nlines
1824 view_start = max (n, 0); 1850 : view_start + nlines;
1825 }
1826 1851
1827 return scr_changeview (oldviewstart); 1852 return scr_changeview (new_view_start);
1828} 1853}
1829 1854
1830int 1855bool
1831rxvt_term::scr_changeview (unsigned int oldviewstart) 1856rxvt_term::scr_changeview (int new_view_start) NOTHROW
1832{ 1857{
1858 clamp_it (new_view_start, top_row, 0);
1859
1833 if (view_start != oldviewstart) 1860 if (new_view_start == view_start)
1834 { 1861 return false;
1862
1863 num_scr += new_view_start - view_start;
1864 view_start = new_view_start;
1865 want_refresh = 1;
1866
1835 HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END)); 1867 HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END));
1836 1868
1837 want_refresh = 1; 1869 return true;
1838 num_scr -= (view_start - oldviewstart);
1839 }
1840
1841 return (int)view_start - (int)oldviewstart;
1842} 1870}
1843 1871
1844/* ------------------------------------------------------------------------- */ 1872#ifndef NO_BELL
1845void 1873void
1874rxvt_term::bell_cb (ev::timer &w, int revents)
1875{
1876 rvideo_bell = false;
1877 scr_rvideo_mode (rvideo_mode);
1878 refresh_check ();
1879}
1880#endif
1881
1882/* ------------------------------------------------------------------------- */
1883void
1846rxvt_term::scr_bell () 1884rxvt_term::scr_bell () NOTHROW
1847{ 1885{
1848#ifndef NO_BELL 1886#ifndef NO_BELL
1849 1887
1850# ifndef NO_MAPALERT 1888# ifndef NO_MAPALERT
1851# ifdef MAPALERT_OPTION 1889# ifdef MAPALERT_OPTION
1852 if (OPTION (Opt_mapAlert)) 1890 if (option (Opt_mapAlert))
1853# endif 1891# endif
1854 XMapWindow (display->display, parent[0]); 1892 XMapWindow (dpy, parent[0]);
1855# endif 1893# endif
1856 1894
1857 if (OPTION (Opt_visualBell)) 1895# if ENABLE_FRILLS
1896 if (option (Opt_urgentOnBell))
1897 {
1898 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1899 {
1900 h->flags |= XUrgencyHint;
1901 XSetWMHints (dpy, parent[0], h);
1902 }
1858 { 1903 }
1859 scr_rvideo_mode (!rvideo); /* refresh also done */ 1904# endif
1905
1906 if (option (Opt_visualBell))
1907 {
1908 rvideo_bell = true;
1909 scr_rvideo_mode (rvideo_mode);
1910 flush ();
1911
1860 rxvt_usleep (VISUAL_BELL_DURATION); 1912 bell_ev.start (VISUAL_BELL_DURATION);
1861 scr_rvideo_mode (!rvideo); /* refresh also done */
1862 } 1913 }
1863 else 1914 else
1864 XBell (display->display, 0); 1915 XBell (dpy, 0);
1865
1866#endif 1916#endif
1867} 1917}
1868 1918
1869/* ------------------------------------------------------------------------- */ 1919/* ------------------------------------------------------------------------- */
1870/* ARGSUSED */ 1920/* ARGSUSED */
1871void 1921void
1872rxvt_term::scr_printscreen (int fullhist) 1922rxvt_term::scr_printscreen (int fullhist) NOTHROW
1873{ 1923{
1874#ifdef PRINTPIPE 1924#ifdef PRINTPIPE
1875 int nrows, row_start; 1925 int nrows, row_start;
1876 FILE *fd; 1926 FILE *fd;
1877 1927
1878 if ((fd = popen_printer ()) == NULL) 1928 if ((fd = popen_printer ()) == NULL)
1879 return; 1929 return;
1880 1930
1881 if (fullhist) 1931 if (fullhist)
1882 { 1932 {
1883 nrows = nrow + nsaved; 1933 nrows = nrow - top_row;
1884 row_start = -nsaved; 1934 row_start = top_row;
1885 } 1935 }
1886 else 1936 else
1887 { 1937 {
1888 nrows = nrow; 1938 nrows = nrow;
1889 row_start = -view_start; 1939 row_start = view_start;
1890 } 1940 }
1891 1941
1892 wctomb (0, 0); 1942 wctomb (0, 0);
1893 1943
1894 for (int r1 = 0; r1 < nrows; r1++) 1944 for (int r1 = 0; r1 < nrows; r1++)
1926 * Refresh the screen 1976 * Refresh the screen
1927 * drawn_text/drawn_rend contain the screen information before the update. 1977 * drawn_text/drawn_rend contain the screen information before the update.
1928 * screen.text/screen.rend contain what the screen will change to. 1978 * screen.text/screen.rend contain what the screen will change to.
1929 */ 1979 */
1930void 1980void
1931rxvt_term::scr_refresh (unsigned char refresh_type) 1981rxvt_term::scr_refresh () NOTHROW
1932{ 1982{
1933 unsigned char must_clear, /* use draw_string not draw_image_string */ 1983 unsigned char have_bg,
1934 showcursor; /* show the cursor */ 1984 showcursor; /* show the cursor */
1935 int16_t col, row, /* column/row we're processing */ 1985 int16_t col, row, /* column/row we're processing */
1936 ocrow; /* old cursor row */ 1986 ocrow; /* old cursor row */
1937 int i; /* tmp */ 1987 int i; /* tmp */
1938#ifndef NO_CURSORCOLOR 1988#ifndef NO_CURSORCOLOR
1939 rend_t cc1; /* store colours at cursor position (s) */ 1989 rend_t cc1; /* store colours at cursor position (s) */
1940#endif 1990#endif
1941 rend_t *crp; // cursor rendition pointer 1991 rend_t *crp; // cursor rendition pointer
1992 rend_t ccol1, /* Cursor colour */
1993 ccol2; /* Cursor colour2 */
1942 1994
1943 want_refresh = 0; /* screen is current */ 1995 want_refresh = 0; /* screen is current */
1944 1996
1945 if (refresh_type == NO_REFRESH || !mapped) 1997 if (refresh_type == NO_REFRESH || !mapped)
1946 return; 1998 return;
1947 1999
1948 /* 2000 /*
1949 * A: set up vars 2001 * A: set up vars
1950 */ 2002 */
1951 must_clear = 0;
1952 refresh_count = 0; 2003 refresh_count = 0;
1953 2004
1954#if XPM_BACKGROUND 2005 have_bg = 0;
2006#ifdef HAVE_BG_PIXMAP
1955 must_clear |= bgPixmap.pixmap != None; 2007 have_bg = bgPixmap.pixmap != None;
1956#endif
1957#if TRANSPARENT
1958 must_clear |= OPTION (Opt_transparent) && am_transparent;
1959#endif 2008#endif
1960 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */ 2009 ocrow = oldcursor.row; /* is there an old outline cursor on screen? */
1961 2010
1962 /* 2011 /*
1963 * B: reverse any characters which are selected 2012 * B: reverse any characters which are selected
1967 /* 2016 /*
1968 * C: set the cursor character (s) 2017 * C: set the cursor character (s)
1969 */ 2018 */
1970 { 2019 {
1971 unsigned char setoldcursor; 2020 unsigned char setoldcursor;
1972 rend_t ccol1, /* Cursor colour */
1973 ccol2; /* Cursor colour2 */
1974 2021
1975 showcursor = (screen.flags & Screen_VisibleCursor); 2022 showcursor = (screen.flags & Screen_VisibleCursor);
1976#ifdef CURSOR_BLINK 2023#ifdef CURSOR_BLINK
1977 if (hidden_cursor) 2024 if (hidden_cursor)
1978 showcursor = 0; 2025 showcursor = 0;
1985 while (col && ROW(screen.cur.row).t[col] == NOCHAR) 2032 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
1986 col--; 2033 col--;
1987 2034
1988 crp = &ROW(screen.cur.row).r[col]; 2035 crp = &ROW(screen.cur.row).r[col];
1989 2036
2037#ifndef NO_CURSORCOLOR
2038 cc1 = *crp & (RS_fgMask | RS_bgMask);
2039 if (ISSET_PIXCOLOR (Color_cursor))
2040 ccol1 = Color_cursor;
2041 else
2042#endif
2043#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2044 ccol1 = fgcolor_of (rstyle);
2045#else
2046 ccol1 = Color_fg;
2047#endif
2048
2049#ifndef NO_CURSORCOLOR
2050 if (ISSET_PIXCOLOR (Color_cursor2))
2051 ccol2 = Color_cursor2;
2052 else
2053#endif
2054#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2055 ccol2 = bgcolor_of (rstyle);
2056#else
2057 ccol2 = Color_bg;
2058#endif
2059
1990 if (showcursor && focus) 2060 if (showcursor && focus)
1991 { 2061 {
1992 if (OPTION (Opt_cursorUnderline)) 2062 if (option (Opt_cursorUnderline))
1993 *crp ^= RS_Uline; 2063 *crp ^= RS_Uline;
1994 else 2064 else
1995 { 2065 {
1996 *crp ^= RS_RVid; 2066 *crp ^= RS_RVid;
1997
1998#ifndef NO_CURSORCOLOR
1999 cc1 = *crp & (RS_fgMask | RS_bgMask);
2000 if (ISSET_PIXCOLOR (Color_cursor))
2001 ccol1 = Color_cursor;
2002 else
2003#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2004 ccol1 = fgcolor_of (rstyle);
2005#else
2006 ccol1 = Color_fg;
2007#endif
2008 if (ISSET_PIXCOLOR (Color_cursor2))
2009 ccol2 = Color_cursor2;
2010 else
2011#ifdef CURSOR_COLOR_IS_RENDITION_COLOR
2012 ccol2 = bgcolor_of (rstyle);
2013#else
2014 ccol2 = Color_bg;
2015#endif
2016 *crp = SET_FGCOLOR (*crp, ccol1); 2067 *crp = SET_FGCOLOR (*crp, ccol1);
2017 *crp = SET_BGCOLOR (*crp, ccol2); 2068 *crp = SET_BGCOLOR (*crp, ccol2);
2018#endif
2019 } 2069 }
2020 } 2070 }
2021 } 2071 }
2022 2072
2023 /* make sure no outline cursor is left around */ 2073 /* make sure no outline cursor is left around */
2024 setoldcursor = 0; 2074 setoldcursor = 0;
2025 if (ocrow != -1) 2075 if (ocrow != -1)
2026 { 2076 {
2027 if (screen.cur.row + view_start != ocrow 2077 if (screen.cur.row - view_start != ocrow
2028 || screen.cur.col != oldcursor.col) 2078 || screen.cur.col != oldcursor.col)
2029 { 2079 {
2030 if (ocrow < nrow 2080 if (ocrow < nrow
2031 && oldcursor.col < ncol) 2081 && oldcursor.col < ncol)
2032 drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); 2082 drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline);
2040 else if (!focus) 2090 else if (!focus)
2041 setoldcursor = 1; 2091 setoldcursor = 1;
2042 2092
2043 if (setoldcursor) 2093 if (setoldcursor)
2044 { 2094 {
2045 if (screen.cur.row + view_start >= nrow) 2095 if (screen.cur.row - view_start >= nrow)
2046 oldcursor.row = -1; 2096 oldcursor.row = -1;
2047 else 2097 else
2048 { 2098 {
2049 oldcursor.row = screen.cur.row + view_start; 2099 oldcursor.row = screen.cur.row - view_start;
2050 oldcursor.col = screen.cur.col; 2100 oldcursor.col = screen.cur.col;
2051 } 2101 }
2052 } 2102 }
2053 } 2103 }
2054 2104
2060#ifndef NO_SLOW_LINK_SUPPORT 2110#ifndef NO_SLOW_LINK_SUPPORT
2061 /* 2111 /*
2062 * D: CopyArea pass - very useful for slower links 2112 * D: CopyArea pass - very useful for slower links
2063 * This has been deliberately kept simple. 2113 * This has been deliberately kept simple.
2064 */ 2114 */
2065 i = num_scr;
2066 if (!display->is_local 2115 if (!display->is_local
2067 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr 2116 && refresh_type == FAST_REFRESH && num_scr_allow && num_scr
2068 && abs (num_scr) < nrow && !must_clear) 2117 && abs (num_scr) < nrow && !have_bg)
2069 { 2118 {
2070 int16_t nits; 2119 int16_t nits;
2120 int i = num_scr;
2071 int j; 2121 int j;
2072 int len, wlen; 2122 int len, wlen;
2123 dLocal (int, num_scr);
2073 2124
2074 j = nrow; 2125 j = nrow;
2075 wlen = len = -1; 2126 wlen = len = -1;
2076 row = i > 0 ? 0 : j - 1; 2127 row = i > 0 ? 0 : j - 1;
2128
2077 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2129 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2078 { 2130 {
2079 if (row + i >= 0 && row + i < nrow && row + i != ocrow) 2131 if (row + i >= 0 && row + i < nrow && row + i != ocrow)
2080 { 2132 {
2081 line_t s = ROW(row - view_start); 2133 line_t s = ROW(view_start + row);
2082 line_t d = drawn_buf[row]; 2134 line_t d = drawn_buf[row];
2083 line_t d2 = drawn_buf[row + i]; 2135 line_t d2 = drawn_buf[row + i];
2084 2136
2085 for (nits = 0, col = ncol; col--; ) 2137 for (nits = 0, col = ncol; col--; )
2086 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col]) 2138 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col])
2102 wlen = row; 2154 wlen = row;
2103 continue; 2155 continue;
2104 } 2156 }
2105 } 2157 }
2106 2158
2107 if (len != -1) 2159 if (len >= 0)
2108 { 2160 {
2109 /* also comes here at end if needed because of >= above */ 2161 /* also comes here at end if needed because of >= above */
2110 if (wlen < len) 2162 if (wlen < len)
2111 ::swap (wlen, len); 2163 ::swap (wlen, len);
2112 2164
2165 XGCValues gcv;
2166
2167 gcv.graphics_exposures = 1; XChangeGC (dpy, gc, GCGraphicsExposures, &gcv);
2113 XCopyArea (display->display, vt, vt, 2168 XCopyArea (dpy, vt, vt,
2114 gc, 0, Row2Pixel (len + i), 2169 gc, 0, Row2Pixel (len + i),
2115 (unsigned int)this->width, 2170 (unsigned int)this->width,
2116 (unsigned int)Height2Pixel (wlen - len + 1), 2171 (unsigned int)Height2Pixel (wlen - len + 1),
2117 0, Row2Pixel (len)); 2172 0, Row2Pixel (len));
2173 gcv.graphics_exposures = 0; XChangeGC (dpy, gc, GCGraphicsExposures, &gcv);
2174
2118 len = -1; 2175 len = -1;
2119 } 2176 }
2120 } 2177 }
2121 } 2178 }
2122#endif 2179#endif
2124 /* 2181 /*
2125 * E: main pass across every character 2182 * E: main pass across every character
2126 */ 2183 */
2127 for (row = 0; row < nrow; row++) 2184 for (row = 0; row < nrow; row++)
2128 { 2185 {
2129 text_t *stp = ROW(row - view_start).t; 2186 text_t *stp = ROW(view_start + row).t;
2130 rend_t *srp = ROW(row - view_start).r; 2187 rend_t *srp = ROW(view_start + row).r;
2131 text_t *dtp = drawn_buf[row].t; 2188 text_t *dtp = drawn_buf[row].t;
2132 rend_t *drp = drawn_buf[row].r; 2189 rend_t *drp = drawn_buf[row].r;
2133 2190
2134 /* 2191 /*
2135 * E2: OK, now the real pass 2192 * E2: OK, now the real pass
2178 count++; 2235 count++;
2179 2236
2180 if (stp[col] != dtp[col] 2237 if (stp[col] != dtp[col]
2181 || !RS_SAME (srp[col], drp[col])) 2238 || !RS_SAME (srp[col], drp[col]))
2182 { 2239 {
2183 if (must_clear && (i++ > count / 2)) 2240 if (have_bg && (i++ > count / 2))
2184 break; 2241 break;
2185 2242
2186 dtp[col] = stp[col]; 2243 dtp[col] = stp[col];
2187 drp[col] = rend; 2244 drp[col] = rend;
2188 i = 0; 2245 i = 0;
2189 } 2246 }
2190 else if (must_clear || (stp[col] != ' ' && ++i >= 16)) 2247 else if (have_bg || (stp[col] != ' ' && ++i >= 16))
2191 break; 2248 break;
2192 } 2249 }
2193 2250
2194 col--; /* went one too far. move back */ 2251 col--; /* went one too far. move back */
2195 count -= i; /* dump any matching trailing chars */ 2252 count -= i; /* dump any matching trailing chars */
2205 int back = bgcolor_of (rend); // desired background 2262 int back = bgcolor_of (rend); // desired background
2206 2263
2207 // only do special processing if any attributes are set, which is unlikely 2264 // only do special processing if any attributes are set, which is unlikely
2208 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2265 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))
2209 { 2266 {
2210#if ENABLE_STYLES
2211 // force redraw after "careful" characters to avoid pixel droppings
2212 if (srp[col] & RS_Careful && col < ncol - 1 && 0)
2213 drp[col + 1] = ~srp[col + 1];
2214
2215 // include previous careful character(s) if possible, looks nicer (best effort...)
2216 while (text > stp
2217 && srp[text - stp - 1] & RS_Careful
2218 && RS_SAME (rend, srp[text - stp - 1]))
2219 text--, count++, xpixel -= fwidth;
2220#endif
2221
2222 bool invert = rend & RS_RVid; 2267 bool invert = rend & RS_RVid;
2223 2268
2224#ifndef NO_BOLD_UNDERLINE_REVERSE 2269#ifndef NO_BOLD_UNDERLINE_REVERSE
2225 if (rend & RS_Bold
2226 && fore == Color_fg) 2270 if (rend & RS_Bold && fore == Color_fg)
2227 { 2271 {
2228 if (ISSET_PIXCOLOR (Color_BD)) 2272 if (ISSET_PIXCOLOR (Color_BD))
2229 fore = Color_BD; 2273 fore = Color_BD;
2230# if !ENABLE_STYLES 2274# if !ENABLE_STYLES
2231 else 2275 else
2232 invert = !invert; 2276 invert = !invert;
2233# endif 2277# endif
2234 } 2278 }
2235 2279
2236 if (rend & RS_Italic 2280 if (rend & RS_Italic && fore == Color_fg)
2237 && fore == Color_fg)
2238 { 2281 {
2239 if (ISSET_PIXCOLOR (Color_IT)) 2282 if (ISSET_PIXCOLOR (Color_IT))
2240 fore = Color_IT; 2283 fore = Color_IT;
2241# if !ENABLE_STYLES 2284# if !ENABLE_STYLES
2242 else 2285 else
2243 invert = !invert; 2286 invert = !invert;
2244# endif 2287# endif
2245 } 2288 }
2246 2289
2247 if (rend & RS_Uline && ISSET_PIXCOLOR (Color_UL)) 2290 if (rend & RS_Uline && fore == Color_fg && ISSET_PIXCOLOR (Color_UL))
2248 fore = Color_UL; 2291 fore = Color_UL;
2249#endif 2292#endif
2250 2293
2251 if (invert) 2294 if (invert)
2252 { 2295 {
2296#ifdef OPTION_HC
2297 if ((showcursor && row == screen.cur.row && text - stp == screen.cur.col)
2298 || !ISSET_PIXCOLOR (Color_HC))
2299#endif
2300 /* invert the column if no highlightColor is set or it is the
2301 * current cursor column */
2253 ::swap (fore, back); 2302 ::swap (fore, back);
2303#ifdef OPTION_HC
2304 else if (ISSET_PIXCOLOR (Color_HC))
2305 back = Color_HC;
2306#endif
2254 2307
2255#ifndef NO_BOLD_UNDERLINE_REVERSE 2308#ifndef NO_BOLD_UNDERLINE_REVERSE
2309# ifndef OPTION_HC
2256 if (ISSET_PIXCOLOR (Color_RV)) 2310 if (ISSET_PIXCOLOR (Color_RV))
2257 back = Color_RV; 2311 back = Color_RV;
2258 2312# endif
2259 if (fore == back) 2313 if (fore == back)
2260 { 2314 {
2261 fore = Color_bg; 2315 fore = Color_bg;
2262 back = Color_fg; 2316 back = Color_fg;
2263 } 2317 }
2265 } 2319 }
2266 2320
2267#ifdef TEXT_BLINK 2321#ifdef TEXT_BLINK
2268 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg)) 2322 if (rend & RS_Blink && (back == Color_bg || fore == Color_bg))
2269 { 2323 {
2270 if (!text_blink_ev.active) 2324 if (!text_blink_ev.is_active ())
2271 { 2325 {
2272 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 2326 text_blink_ev.again ();
2273 hidden_text = 0; 2327 hidden_text = 0;
2274 } 2328 }
2275 else if (hidden_text) 2329 else if (hidden_text)
2276 fore = back; 2330 fore = back;
2277 } 2331 }
2278#endif 2332#endif
2333
2334#if ENABLE_STYLES
2335 // "careful" (too wide) character handling
2336
2337 // include previous careful character(s) if possible, looks nicer (best effort...)
2338 while (text > stp
2339 && srp[text - stp - 1] & RS_Careful
2340 && RS_SAME (rend, srp[text - stp - 1]))
2341 text--, count++, xpixel -= fwidth;
2342
2343 // force redraw after "careful" characters to avoid pixel droppings
2344 for (int i = 0; srp[col + i] & RS_Careful && col + i < ncol - 1; i++)
2345 drp[col + i + 1] = srp[col + i + 1] ^ RS_redraw;
2346
2347 // force redraw before "careful" characters to avoid pixel droppings
2348 for (int i = 0; srp[text - stp - i] & RS_Careful && text - i > stp; i++)
2349 drp[text - stp - i - 1] = srp[text - stp - i - 1] ^ RS_redraw;
2350#endif
2279 } 2351 }
2280 2352
2281 /* 2353 /*
2282 * Actually do the drawing of the string here 2354 * Actually do the drawing of the string here
2283 */ 2355 */
2284 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2356 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2285 2357
2286 if (back == fore)
2287 font->clear_rect (*drawable, xpixel, ypixel,
2288 fwidth * count, fheight,
2289 back);
2290 else if (back == Color_bg) 2358 if (have_bg && back == Color_bg)
2291 { 2359 {
2292 if (must_clear) 2360 // this is very ugly, maybe push it into ->draw?
2293 {
2294 CLEAR_CHARS (xpixel, ypixel, count);
2295 2361
2296 for (i = 0; i < count; i++) /* don't draw empty strings */ 2362 for (i = 0; i < count; i++) /* don't draw empty strings */
2297 if (text[i] != ' ') 2363 if (text[i] != ' ')
2298 { 2364 {
2299 font->draw (*drawable, xpixel, ypixel, text, count, fore, -1); 2365 font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_transparent);
2300 break; 2366 goto did_clear;
2301 }
2302 } 2367 }
2303 else 2368
2304 font->draw (*drawable, xpixel, ypixel, text, count, fore, Color_bg); 2369 CLEAR_CHARS (xpixel, ypixel, count);
2370 did_clear: ;
2305 } 2371 }
2306 else 2372 else
2307 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2373 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2308 2374
2309 if (rend & RS_Uline && font->descent > 1 && fore != back) 2375 if (rend & RS_Uline && font->descent > 1 && fore != back)
2310 { 2376 {
2311#if ENABLE_FRILLS 2377#if ENABLE_FRILLS
2312 if (ISSET_PIXCOLOR (Color_underline)) 2378 if (ISSET_PIXCOLOR (Color_underline))
2313 XSetForeground (display->display, gc, pix_colors[Color_underline]); 2379 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2314 else 2380 else
2315#endif 2381#endif
2316 XSetForeground (display->display, gc, pix_colors[fore]); 2382 XSetForeground (dpy, gc, pix_colors[fore]);
2317 2383
2318 XDrawLine (display->display, drawBuffer, gc, 2384 XDrawLine (dpy, vt, gc,
2319 xpixel, ypixel + font->ascent + 1, 2385 xpixel, ypixel + font->ascent + 1,
2320 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1); 2386 xpixel + Width2Pixel (count) - 1, ypixel + font->ascent + 1);
2321 } 2387 }
2322 } /* for (col....) */ 2388 } /* for (col....) */
2323 } /* for (row....) */ 2389 } /* for (row....) */
2332 */ 2398 */
2333 if (showcursor) 2399 if (showcursor)
2334 { 2400 {
2335 if (focus) 2401 if (focus)
2336 { 2402 {
2337 if (OPTION (Opt_cursorUnderline)) 2403 if (option (Opt_cursorUnderline))
2338 *crp ^= RS_Uline; 2404 *crp ^= RS_Uline;
2339 else 2405 else
2340 { 2406 {
2341 *crp ^= RS_RVid; 2407 *crp ^= RS_RVid;
2342#ifndef NO_CURSORCOLOR 2408#ifndef NO_CURSORCOLOR
2356 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR) 2422 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2357 cursorwidth++; 2423 cursorwidth++;
2358 2424
2359#ifndef NO_CURSORCOLOR 2425#ifndef NO_CURSORCOLOR
2360 if (ISSET_PIXCOLOR (Color_cursor)) 2426 if (ISSET_PIXCOLOR (Color_cursor))
2361 XSetForeground (display->display, gc, pix_colors[Color_cursor]); 2427 XSetForeground (dpy, gc, pix_colors[Color_cursor]);
2428 else
2362#endif 2429#endif
2430 XSetForeground (dpy, gc, pix_colors[ccol1]);
2363 2431
2364 XDrawRectangle (display->display, drawBuffer, gc, 2432 XDrawRectangle (dpy, vt, gc,
2365 Col2Pixel (col), 2433 Col2Pixel (col),
2366 Row2Pixel (oldcursor.row), 2434 Row2Pixel (oldcursor.row),
2367 (unsigned int) (Width2Pixel (cursorwidth) - 1), 2435 (unsigned int) (Width2Pixel (cursorwidth) - 1),
2368 (unsigned int) (Height2Pixel (1) - lineSpace - 1)); 2436 (unsigned int) (Height2Pixel (1) - lineSpace - 1));
2369 } 2437 }
2372 /* 2440 /*
2373 * H: cleanup selection 2441 * H: cleanup selection
2374 */ 2442 */
2375 scr_reverse_selection (); 2443 scr_reverse_selection ();
2376 2444
2377 if (refresh_type & SMOOTH_REFRESH)
2378 XFlush (display->display);
2379
2380 num_scr = 0; 2445 num_scr = 0;
2381 num_scr_allow = 1; 2446 num_scr_allow = 1;
2382} 2447}
2383 2448
2384void 2449void
2385rxvt_term::scr_remap_chars (line_t &l) 2450rxvt_term::scr_remap_chars (line_t &l) NOTHROW
2386{ 2451{
2387 if (!l.t) 2452 if (!l.t)
2388 return; 2453 return;
2389 2454
2390 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant 2455 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant
2392 for (int i = ncol; i--; ) 2457 for (int i = ncol; i--; )
2393 l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i])); 2458 l.r[i] = SET_FONT (l.r[i], FONTSET (l.r[i])->find_font (l.t[i]));
2394} 2459}
2395 2460
2396void 2461void
2397rxvt_term::scr_remap_chars () 2462rxvt_term::scr_remap_chars () NOTHROW
2398{ 2463{
2399 for (int i = total_rows; i--; ) 2464 for (int i = total_rows; i--; )
2400 scr_remap_chars (row_buf [i]); 2465 scr_remap_chars (row_buf [i]);
2401 2466
2402 for (int i = nrow; i--; ) 2467 for (int i = nrow; i--; )
2405 scr_remap_chars (swap_buf [i]); 2470 scr_remap_chars (swap_buf [i]);
2406 } 2471 }
2407} 2472}
2408 2473
2409void 2474void
2410rxvt_term::scr_recolour () 2475rxvt_term::scr_recolour () NOTHROW
2411{ 2476{
2412 if (1 2477#ifdef HAVE_BG_PIXMAP
2413#if TRANSPARENT 2478 bgPixmap.apply ();
2414 && !am_transparent 2479#else
2415#endif 2480
2416#if XPM_BACKGROUND
2417 && !bgPixmap.pixmap
2418#endif
2419 )
2420 {
2421 XSetWindowBackground (display->display, parent[0], pix_colors[Color_border]); 2481 XSetWindowBackground (dpy, parent[0], pix_colors[Color_border]);
2422 XClearWindow (display->display, parent[0]); 2482 XClearWindow (dpy, parent[0]);
2423 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); 2483 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
2424#if HAVE_SCROLLBARS 2484
2425 if (scrollBar.win) 2485 if (scrollBar.win)
2426 { 2486 {
2427 XSetWindowBackground (display->display, scrollBar.win, pix_colors[Color_border]); 2487 XSetWindowBackground (dpy, scrollBar.win, pix_colors[Color_border]);
2428 scrollBar.setIdle (); 2488 scrollBar.state = STATE_IDLE;
2429 scrollbar_show (0); 2489 scrollBar.show (0);
2430 }
2431#endif
2432 } 2490 }
2433 2491
2492#endif
2493
2494 /* bgPixmap.apply () does not do the following : */
2434 scr_clear (); 2495 scr_clear ();
2435 scr_touch (true); 2496 scr_touch (true);
2436 want_refresh = 1; 2497 want_refresh = 1;
2437} 2498}
2438 2499
2439/* ------------------------------------------------------------------------- */ 2500/* ------------------------------------------------------------------------- */
2440void 2501void
2441rxvt_term::scr_clear (bool really) 2502rxvt_term::scr_clear (bool really) NOTHROW
2442{ 2503{
2443 if (!mapped) 2504 if (!mapped)
2444 return; 2505 return;
2445 2506
2446 num_scr_allow = 0; 2507 num_scr_allow = 0;
2447 want_refresh = 1; 2508 want_refresh = 1;
2448 2509
2449 if (really) 2510 if (really)
2450 XClearWindow (display->display, vt); 2511 XClearWindow (dpy, vt);
2451} 2512}
2452 2513
2453/* ------------------------------------------------------------------------- */
2454void 2514void
2515rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2) NOTHROW
2516{
2517 int view_end = view_start + nrow;
2518 int row, col;
2519
2520 for (row = max (beg_row, view_start); row <= min (end_row, view_end); row++)
2521 {
2522 text_t *stp = ROW(row).t;
2523 rend_t *srp = ROW(row).r;
2524
2525 for (col = beg_col; col < end_col; col++)
2526 srp[col] ^= rstyle1;
2527
2528 while (col-- > beg_col && (stp[col] == NOCHAR || unicode::is_space (stp[col])))
2529 srp[col] ^= rstyle2;
2530
2531 if (++col < end_col)
2532 srp[col] ^= rstyle2;
2533 }
2534}
2535
2536void
2537rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle) NOTHROW
2538{
2539 int view_end = view_start + nrow;
2540 int row, col;
2541
2542 if (beg_row >= view_start)
2543 {
2544 col = beg_col;
2545 row = beg_row;
2546 }
2547 else
2548 {
2549 col = 0;
2550 row = view_start;
2551 }
2552
2553 for (; row < min (end_row, view_end); row++, col = 0)
2554 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2555 srp[col] ^= rstyle;
2556
2557 if (row == end_row)
2558 for (rend_t *srp = ROW(row).r; col < end_col; col++)
2559 srp[col] ^= rstyle;
2560}
2561
2562/* ------------------------------------------------------------------------- */
2563void
2455rxvt_term::scr_reverse_selection () 2564rxvt_term::scr_reverse_selection () NOTHROW
2456{ 2565{
2457 if (selection.op 2566 if (selection.op
2458 && current_screen == selection.screen 2567 && current_screen == selection.screen
2459 && selection.end.row >= -view_start) 2568 && selection.end.row >= view_start)
2460 { 2569 {
2461 int view_end = -view_start + nrow; 2570#if !ENABLE_MINIMAL
2462 int row, col;
2463
2464#if ENABLE_FRILLS
2465 if (selection.rect) 2571 if (selection.rect)
2466 { 2572 scr_xor_rect (selection.beg.row, selection.beg.col,
2467 for (row = max (selection.beg.row, -view_start); row <= min (selection.end.row, view_end); row++) 2573 selection.end.row, selection.end.col,
2468 { 2574 RS_RVid, RS_RVid | RS_Uline);
2469 text_t *stp = ROW(row).t;
2470 rend_t *srp = ROW(row).r;
2471
2472 for (col = selection.beg.col; col < selection.end.col; col++)
2473 srp[col] ^= RS_RVid;
2474
2475 while (col-- > selection.beg.col && (stp[col] == NOCHAR || unicode::is_space (stp[col])))
2476 srp[col] ^= RS_RVid | RS_Uline;
2477
2478 if (++col < selection.end.col)
2479 srp[col] ^= RS_RVid | RS_Uline;
2480 }
2481 }
2482 else 2575 else
2483#endif 2576#endif
2484 { 2577 scr_xor_span (selection.beg.row, selection.beg.col,
2485 if (selection.beg.row >= -view_start) 2578 selection.end.row, selection.end.col,
2486 { 2579 RS_RVid);
2487 col = selection.beg.col;
2488 row = selection.beg.row;
2489 }
2490 else
2491 {
2492 col = 0;
2493 row = -view_start;
2494 }
2495
2496 for (; row < min (selection.end.row, view_end); row++, col = 0)
2497 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2498 srp[col] ^= RS_RVid;
2499
2500 if (row == selection.end.row)
2501 for (rend_t *srp = ROW(row).r; col < selection.end.col; col++)
2502 srp[col] ^= RS_RVid;
2503 }
2504 } 2580 }
2505} 2581}
2506 2582
2507/* ------------------------------------------------------------------------- */ 2583/* ------------------------------------------------------------------------- */
2508/* 2584/*
2509 * Dump the whole scrollback and screen to the passed filedescriptor. The 2585 * Dump the whole scrollback and screen to the passed filedescriptor. The
2510 * invoking routine must close the fd. 2586 * invoking routine must close the fd.
2511 */ 2587 */
2512#if 0 2588#if 0
2513void 2589void
2514rxvt_term::scr_dump (int fd) 2590rxvt_term::scr_dump (int fd) NOTHROW
2515{ 2591{
2516 int row, wrote; 2592 int row, wrote;
2517 unsigned int width, towrite; 2593 unsigned int width, towrite;
2518 char r1[] = "\n"; 2594 char r1[] = "\n";
2519 2595
2520 for (row = saveLines - nsaved; 2596 for (row = saveLines + top_row;
2521 row < saveLines + nrow - 1; row++) 2597 row < saveLines + nrow - 1; row++)
2522 { 2598 {
2523 width = row_buf[row].l >= 0 ? row_buf[row].l 2599 width = row_buf[row].l >= 0 ? row_buf[row].l
2524 : ncol; 2600 : ncol;
2525 for (towrite = width; towrite; towrite -= wrote) 2601 for (towrite = width; towrite; towrite -= wrote)
2538 2614
2539/* ------------------------------------------------------------------------- * 2615/* ------------------------------------------------------------------------- *
2540 * CHARACTER SELECTION * 2616 * CHARACTER SELECTION *
2541 * ------------------------------------------------------------------------- */ 2617 * ------------------------------------------------------------------------- */
2542void 2618void
2543rxvt_term::selection_check (int check_more) 2619rxvt_term::selection_check (int check_more) NOTHROW
2544{ 2620{
2545 row_col_t pos; 2621 row_col_t pos;
2546 2622
2547 if (!selection.op) 2623 if (!selection.op)
2548 return; 2624 return;
2549 2625
2550 pos.row = pos.col = 0; 2626 pos.row = pos.col = 0;
2551 if (!IN_RANGE_EXC (selection.beg.row, -nsaved, nrow) 2627 if (!IN_RANGE_EXC (selection.beg.row, top_row, nrow)
2552 || !IN_RANGE_EXC (selection.mark.row, -nsaved, nrow) 2628 || !IN_RANGE_EXC (selection.mark.row, top_row, nrow)
2553 || !IN_RANGE_EXC (selection.end.row, -nsaved, nrow) 2629 || !IN_RANGE_EXC (selection.end.row, top_row, nrow)
2554 || (check_more == 1 2630 || (check_more == 1
2555 && current_screen == selection.screen 2631 && current_screen == selection.screen
2556 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 2632 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
2557 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 2633 && ROWCOL_IS_BEFORE (screen.cur, selection.end))
2558 || (check_more == 2 2634 || (check_more == 2
2569/* ------------------------------------------------------------------------- */ 2645/* ------------------------------------------------------------------------- */
2570/* 2646/*
2571 * Paste a selection direct to the command fd 2647 * Paste a selection direct to the command fd
2572 */ 2648 */
2573void 2649void
2574rxvt_term::paste (char *data, unsigned int len) 2650rxvt_term::paste (char *data, unsigned int len) NOTHROW
2575{ 2651{
2576 /* convert normal newline chars into common keyboard Return key sequence */ 2652 /* convert normal newline chars into common keyboard Return key sequence */
2577 for (unsigned int i = 0; i < len; i++) 2653 for (unsigned int i = 0; i < len; i++)
2578 if (data[i] == C0_LF) 2654 if (data[i] == C0_LF)
2579 data[i] = C0_CR; 2655 data[i] = C0_CR;
2580 2656
2657 if (priv_modes & PrivMode_BracketPaste)
2658 tt_printf ("\e[200~");
2659
2581 tt_write (data, len); 2660 tt_write (data, len);
2661
2662 if (priv_modes & PrivMode_BracketPaste)
2663 tt_printf ("\e[201~");
2582} 2664}
2583 2665
2584/* ------------------------------------------------------------------------- */ 2666/* ------------------------------------------------------------------------- */
2585/* 2667/*
2586 * Respond to a notification that a primary selection has been sent 2668 * Respond to a notification that a primary selection has been sent
2587 * EXT: SelectionNotify 2669 * EXT: SelectionNotify
2588 */ 2670 */
2589void 2671void
2590rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) 2672rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop) NOTHROW
2591{ 2673{
2592 if (prop == None) /* check for failed XConvertSelection */ 2674 if (prop == None) /* check for failed XConvertSelection */
2593 { 2675 {
2594 if ((selection_type & Sel_CompoundText)) 2676 if ((selection_type & Sel_CompoundText))
2595 { 2677 {
2615 } 2697 }
2616 2698
2617 unsigned long bytes_after; 2699 unsigned long bytes_after;
2618 XTextProperty ct; 2700 XTextProperty ct;
2619 2701
2620 if (XGetWindowProperty (display->display, win, prop, 2702 if (XGetWindowProperty (dpy, win, prop,
2621 0, PROP_SIZE / 4, 2703 0, PROP_SIZE / 4,
2622 delete_prop, AnyPropertyType, 2704 delete_prop, AnyPropertyType,
2623 &ct.encoding, &ct.format, 2705 &ct.encoding, &ct.format,
2624 &ct.nitems, &bytes_after, 2706 &ct.nitems, &bytes_after,
2625 &ct.value) != Success) 2707 &ct.value) != Success)
2634 if (bytes_after) 2716 if (bytes_after)
2635 { 2717 {
2636 // fetch and append remaining data 2718 // fetch and append remaining data
2637 XTextProperty ct2; 2719 XTextProperty ct2;
2638 2720
2639 if (XGetWindowProperty (display->display, win, prop, 2721 if (XGetWindowProperty (dpy, win, prop,
2640 ct.nitems / 4, (bytes_after + 3) / 4, 2722 ct.nitems / 4, (bytes_after + 3) / 4,
2641 delete_prop, AnyPropertyType, 2723 delete_prop, AnyPropertyType,
2642 &ct2.encoding, &ct2.format, 2724 &ct2.encoding, &ct2.format,
2643 &ct2.nitems, &bytes_after, 2725 &ct2.nitems, &bytes_after,
2644 &ct2.value) != Success) 2726 &ct2.value) != Success)
2657 2739
2658 if (ct.encoding == xa[XA_INCR]) 2740 if (ct.encoding == xa[XA_INCR])
2659 { 2741 {
2660 // INCR selection, start handshake 2742 // INCR selection, start handshake
2661 if (!delete_prop) 2743 if (!delete_prop)
2662 XDeleteProperty (display->display, win, prop); 2744 XDeleteProperty (dpy, win, prop);
2663 2745
2664 selection_wait = Sel_incr; 2746 selection_wait = Sel_incr;
2665 incr_buf_fill = 0; 2747 incr_buf_fill = 0;
2666 incr_ev.start (NOW + 10); 2748 incr_ev.start (10);
2667 2749
2668 goto bailout; 2750 goto bailout;
2669 } 2751 }
2670 2752
2671 if (ct.nitems == 0) 2753 if (ct.nitems == 0)
2680 ct.nitems = incr_buf_fill; 2762 ct.nitems = incr_buf_fill;
2681 incr_buf = 0; 2763 incr_buf = 0;
2682 incr_buf_size = 0; 2764 incr_buf_size = 0;
2683 incr_ev.stop (); 2765 incr_ev.stop ();
2684 } 2766 }
2685 else 2767 else
2686 { 2768 {
2687 if (selection_wait == Sel_normal 2769 if (selection_wait == Sel_normal
2688 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion 2770 && (win != display->root || prop != XA_CUT_BUFFER0)) // avoid recursion
2689 { 2771 {
2690 /* 2772 /*
2697 goto bailout; 2779 goto bailout;
2698 } 2780 }
2699 } 2781 }
2700 else if (selection_wait == Sel_incr) 2782 else if (selection_wait == Sel_incr)
2701 { 2783 {
2702 incr_ev.start (NOW + 10); 2784 incr_ev.start (10);
2703 2785
2704 while (incr_buf_fill + ct.nitems > incr_buf_size) 2786 while (incr_buf_fill + ct.nitems > incr_buf_size)
2705 { 2787 {
2706 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024; 2788 incr_buf_size = incr_buf_size ? incr_buf_size * 2 : 128*1024;
2707 incr_buf = (char *)realloc (incr_buf, incr_buf_size); 2789 incr_buf = (char *)realloc (incr_buf, incr_buf_size);
2714 } 2796 }
2715 2797
2716 char **cl; 2798 char **cl;
2717 int cr; 2799 int cr;
2718 2800
2719#if ENABLE_FRILLS 2801#if !ENABLE_MINIMAL
2720 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 2802 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
2721 // so recode it manually 2803 // so recode it manually
2722 if (ct.encoding == xa[XA_UTF8_STRING]) 2804 if (ct.encoding == xa[XA_UTF8_STRING])
2723 { 2805 {
2724 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems); 2806 wchar_t *w = rxvt_utf8towcs ((const char *)ct.value, ct.nitems);
2728 paste (s, strlen (s)); 2810 paste (s, strlen (s));
2729 free (s); 2811 free (s);
2730 } 2812 }
2731 else 2813 else
2732#endif 2814#endif
2733 if (XmbTextPropertyToTextList (display->display, &ct, &cl, &cr) >= 0 2815 if (XmbTextPropertyToTextList (dpy, &ct, &cl, &cr) >= 0
2734 && cl) 2816 && cl)
2735 { 2817 {
2736 for (int i = 0; i < cr; i++) 2818 for (int i = 0; i < cr; i++)
2737 paste (cl[i], strlen (cl[i])); 2819 paste (cl[i], strlen (cl[i]));
2738 2820
2747 if (selection_wait == Sel_normal) 2829 if (selection_wait == Sel_normal)
2748 selection_wait = Sel_none; 2830 selection_wait = Sel_none;
2749} 2831}
2750 2832
2751void 2833void
2752rxvt_term::incr_cb (time_watcher &w) 2834rxvt_term::incr_cb (ev::timer &w, int revents) NOTHROW
2753{ 2835{
2754 selection_wait = Sel_none; 2836 selection_wait = Sel_none;
2755 2837
2756 incr_buf_size = 0; 2838 incr_buf_size = 0;
2757 free (incr_buf); 2839 free (incr_buf);
2758 2840
2759 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 2841 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
2760} 2842}
2761 2843
2762void 2844void
2763rxvt_term::selection_property (Window win, Atom prop) 2845rxvt_term::selection_property (Window win, Atom prop) NOTHROW
2764{ 2846{
2765 if (prop == None || selection_wait != Sel_incr) 2847 if (prop == None || selection_wait != Sel_incr)
2766 return; 2848 return;
2767 2849
2768 selection_paste (win, prop, true); 2850 selection_paste (win, prop, true);
2769} 2851}
2770 2852
2771/* ------------------------------------------------------------------------- */ 2853/* ------------------------------------------------------------------------- */
2772/* 2854/*
2773 * Request the current selection: 2855 * Request the current selection:
2774 * Order: > internal selection if available 2856 * Order: > internal selection if available
2775 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+) 2857 * > PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+)
2776 * > CUT_BUFFER0 2858 * > CUT_BUFFER0
2777 * (+) if ownership is claimed but property is empty, rxvt_selection_paste () 2859 * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
2778 * will auto fallback to CUT_BUFFER0 2860 * will auto fallback to CUT_BUFFER0
2779 * EXT: button 2 release 2861 * EXT: button 2 release
2780 */ 2862 */
2781void 2863void
2782rxvt_term::selection_request (Time tm, int x, int y) 2864rxvt_term::selection_request (Time tm, int selnum) NOTHROW
2783{ 2865{
2784 if (x < 0 || x >= width || y < 0 || y >= height) 2866 if (selection.text && selnum == Sel_Primary)
2785 return; /* outside window */ 2867 {
2786
2787 if (selection.text)
2788 { /* internal selection */ 2868 /* internal selection */
2789 char *str = rxvt_wcstombs (selection.text, selection.len); 2869 char *str = rxvt_wcstombs (selection.text, selection.len);
2790 paste (str, strlen (str)); 2870 paste (str, strlen (str));
2791 free (str); 2871 free (str);
2792 return; 2872 return;
2793 } 2873 }
2794 else 2874 else
2795 { 2875 {
2796 int i;
2797
2798 selection_request_time = tm; 2876 selection_request_time = tm;
2799 selection_wait = Sel_normal; 2877 selection_wait = Sel_normal;
2800 2878
2801 for (i = Sel_Primary; i <= Sel_Clipboard; i++)
2802 {
2803#if X_HAVE_UTF8_STRING 2879#if X_HAVE_UTF8_STRING
2804 selection_type = Sel_UTF8String; 2880 selection_type = Sel_UTF8String;
2805 if (selection_request_other (xa[XA_UTF8_STRING], i)) 2881 if (selection_request_other (xa[XA_UTF8_STRING], selnum))
2806 return; 2882 return;
2807#else 2883#else
2808 selection_type = Sel_CompoundText; 2884 selection_type = Sel_CompoundText;
2809 if (selection_request_other (xa[XA_COMPOUND_TEXT], i)) 2885 if (selection_request_other (xa[XA_COMPOUND_TEXT], selnum))
2810 return; 2886 return;
2811#endif 2887#endif
2812 }
2813 } 2888 }
2814 2889
2815 selection_wait = Sel_none; /* don't loop in selection_paste () */ 2890 selection_wait = Sel_none; /* don't loop in selection_paste () */
2816 selection_paste (display->root, XA_CUT_BUFFER0, false); 2891 selection_paste (display->root, XA_CUT_BUFFER0, false);
2817} 2892}
2818 2893
2819int 2894int
2820rxvt_term::selection_request_other (Atom target, int selnum) 2895rxvt_term::selection_request_other (Atom target, int selnum) NOTHROW
2821{ 2896{
2822 Atom sel; 2897 Atom sel;
2823 2898
2824 selection_type |= selnum; 2899 selection_type |= selnum;
2825 2900
2828 else if (selnum == Sel_Secondary) 2903 else if (selnum == Sel_Secondary)
2829 sel = XA_SECONDARY; 2904 sel = XA_SECONDARY;
2830 else 2905 else
2831 sel = xa[XA_CLIPBOARD]; 2906 sel = xa[XA_CLIPBOARD];
2832 2907
2833 if (XGetSelectionOwner (display->display, sel) != None) 2908 if (XGetSelectionOwner (dpy, sel) != None)
2834 { 2909 {
2835 XConvertSelection (display->display, sel, target, xa[XA_VT_SELECTION], 2910 XConvertSelection (dpy, sel, target, xa[XA_VT_SELECTION],
2836 vt, selection_request_time); 2911 vt, selection_request_time);
2837 return 1; 2912 return 1;
2838 } 2913 }
2839 2914
2840 return 0; 2915 return 0;
2844/* 2919/*
2845 * Clear all selected text 2920 * Clear all selected text
2846 * EXT: SelectionClear 2921 * EXT: SelectionClear
2847 */ 2922 */
2848void 2923void
2849rxvt_term::selection_clear () 2924rxvt_term::selection_clear () NOTHROW
2850{ 2925{
2851 want_refresh = 1; 2926 want_refresh = 1;
2852 free (selection.text); 2927 free (selection.text);
2853 selection.text = NULL; 2928 selection.text = NULL;
2854 selection.len = 0; 2929 selection.len = 0;
2903 2978
2904 int end_col; 2979 int end_col;
2905 2980
2906 for (; row <= selection.end.row; row++, col = 0) 2981 for (; row <= selection.end.row; row++, col = 0)
2907 { 2982 {
2908#if ENABLE_FRILLS 2983#if !ENABLE_MINIMAL
2909 if (selection.rect) 2984 if (selection.rect)
2910 { 2985 {
2911 col = selection.beg.col; 2986 col = selection.beg.col;
2912 end_col = ncol + 1; 2987 end_col = ncol + 1;
2913 } 2988 }
2916 end_col = ROW(row).l; 2991 end_col = ROW(row).l;
2917 2992
2918 col = max (col, 0); 2993 col = max (col, 0);
2919 2994
2920 if (row == selection.end.row 2995 if (row == selection.end.row
2921#if ENABLE_FRILLS 2996#if !ENABLE_MINIMAL
2922 || selection.rect 2997 || selection.rect
2923#endif 2998#endif
2924 ) 2999 )
2925 min_it (end_col, selection.end.col); 3000 min_it (end_col, selection.end.col);
2926 3001
2949#endif 3024#endif
2950 else 3025 else
2951 new_selection_text[ofs++] = *t++; 3026 new_selection_text[ofs++] = *t++;
2952 } 3027 }
2953 3028
2954#if ENABLE_FRILLS 3029#if !ENABLE_MINIMAL
2955 if (selection.rect) 3030 if (selection.rect)
2956 { 3031 {
2957 while (ofs 3032 while (ofs
2958 && new_selection_text[ofs - 1] != C0_LF 3033 && new_selection_text[ofs - 1] != C0_LF
2959 && unicode::is_space (new_selection_text[ofs - 1])) 3034 && unicode::is_space (new_selection_text[ofs - 1]))
2989 3064
2990 selection_grab (tm); 3065 selection_grab (tm);
2991} 3066}
2992 3067
2993bool 3068bool
2994rxvt_term::selection_grab (Time tm) 3069rxvt_term::selection_grab (Time tm) NOTHROW
2995{ 3070{
2996 selection_time = tm; 3071 selection_time = tm;
2997 3072
2998 XSetSelectionOwner (display->display, XA_PRIMARY, vt, tm); 3073 XSetSelectionOwner (dpy, XA_PRIMARY, vt, tm);
2999 if (XGetSelectionOwner (display->display, XA_PRIMARY) == vt) 3074 if (XGetSelectionOwner (dpy, XA_PRIMARY) == vt)
3000 { 3075 {
3001 display->set_selection_owner (this); 3076 display->set_selection_owner (this);
3002 return true; 3077 return true;
3003 } 3078 }
3004 else 3079 else
3080 {
3081 selection_clear ();
3005 return false; 3082 return false;
3083 }
3006 3084
3007#if 0 3085#if 0
3008 XTextProperty ct; 3086 XTextProperty ct;
3009 3087
3010 if (XwcTextListToTextProperty (display->display, &selection.text, 1, XStringStyle, &ct) >= 0) 3088 if (XwcTextListToTextProperty (dpy, &selection.text, 1, XStringStyle, &ct) >= 0)
3011 { 3089 {
3012 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems); 3090 set_string_property (XA_CUT_BUFFER0, ct.value, ct.nitems);
3013 XFree (ct.value); 3091 XFree (ct.value);
3014 } 3092 }
3015#endif 3093#endif
3019/* 3097/*
3020 * Mark or select text based upon number of clicks: 1, 2, or 3 3098 * Mark or select text based upon number of clicks: 1, 2, or 3
3021 * EXT: button 1 press 3099 * EXT: button 1 press
3022 */ 3100 */
3023void 3101void
3024rxvt_term::selection_click (int clicks, int x, int y) 3102rxvt_term::selection_click (int clicks, int x, int y) NOTHROW
3025{ 3103{
3026 clicks = ((clicks - 1) % 3) + 1; 3104 clicks = ((clicks - 1) % 3) + 1;
3027 selection.clicks = clicks; /* save clicks so extend will work */ 3105 selection.clicks = clicks; /* save clicks so extend will work */
3028 3106
3107 if (clicks == 2 && !selection.rect
3108 && HOOK_INVOKE ((this, HOOK_SEL_EXTEND, DT_END)))
3109 {
3110 MEvent.clicks = 1; // what a mess
3111 selection.screen = current_screen;
3112 selection.op = SELECTION_CONT;
3113 return;
3114 }
3115
3029 selection_start_colrow (Pixel2Col (x), Pixel2Row (y)); 3116 selection_start_colrow (Pixel2Col (x), Pixel2Row (y));
3030 3117
3031 if (clicks == 2 || clicks == 3) 3118 if (clicks == 2 || clicks == 3)
3032 selection_extend_colrow (selection.mark.col, 3119 selection_extend_colrow (selection.mark.col,
3033 selection.mark.row + view_start, 3120 selection.mark.row - view_start,
3034 0, /* button 3 */ 3121 0, /* button 3 */
3035 1, /* button press */ 3122 1, /* button press */
3036 0); /* click change */ 3123 0); /* click change */
3037} 3124}
3038 3125
3039/* ------------------------------------------------------------------------- */ 3126/* ------------------------------------------------------------------------- */
3040/* 3127/*
3041 * Mark a selection at the specified col/row 3128 * Mark a selection at the specified col/row
3042 */ 3129 */
3043void 3130void
3044rxvt_term::selection_start_colrow (int col, int row) 3131rxvt_term::selection_start_colrow (int col, int row) NOTHROW
3045{ 3132{
3046 want_refresh = 1; 3133 want_refresh = 1;
3047 3134
3048 selection.mark.row = row - view_start; 3135 selection.mark.row = row + view_start;
3049 selection.mark.col = col; 3136 selection.mark.col = col;
3050 3137
3051 selection.mark.row = clamp (selection.mark.row, -nsaved, nrow - 1); 3138 selection.mark.row = clamp (selection.mark.row, top_row, nrow - 1);
3052 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); 3139 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1);
3053 3140
3054 while (selection.mark.col > 0 3141 while (selection.mark.col > 0
3055 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) 3142 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3056 --selection.mark.col; 3143 --selection.mark.col;
3057 3144
3058 if (selection.op) 3145 if (selection.op)
3146 {
3059 { /* clear the old selection */ 3147 /* clear the old selection */
3060 selection.beg.row = selection.end.row = selection.mark.row; 3148 selection.beg.row = selection.end.row = selection.mark.row;
3061 selection.beg.col = selection.end.col = selection.mark.col; 3149 selection.beg.col = selection.end.col = selection.mark.col;
3062 } 3150 }
3063 3151
3064 selection.op = SELECTION_INIT; 3152 selection.op = SELECTION_INIT;
3075#define DELIMIT_TEXT(x) \ 3163#define DELIMIT_TEXT(x) \
3076 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x))) 3164 (unicode::is_space (x) ? 2 : (x) <= 0xff && !!strchr (rs[Rs_cutchars], (x)))
3077#define DELIMIT_REND(x) 1 3165#define DELIMIT_REND(x) 1
3078 3166
3079void 3167void
3080rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) 3168rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, row_col_t *ret) NOTHROW
3081{ 3169{
3082 int col, row, dirnadd, tcol, trow, w1, w2; 3170 int col, row, dirnadd, tcol, trow, w1, w2;
3083 row_col_t bound; 3171 row_col_t bound;
3084 text_t *stp; 3172 text_t *stp;
3085 rend_t *srp; 3173 rend_t *srp;
3086 3174
3087 if (dirn == UP) 3175 if (dirn == UP)
3088 { 3176 {
3089 bound.row = - nsaved - 1; 3177 bound.row = top_row - 1;
3090 bound.col = 0; 3178 bound.col = 0;
3091 dirnadd = -1; 3179 dirnadd = -1;
3092 } 3180 }
3093 else 3181 else
3094 { 3182 {
3159 * flag == 0 ==> button 1 3247 * flag == 0 ==> button 1
3160 * flag == 1 ==> button 3 press 3248 * flag == 1 ==> button 3 press
3161 * flag == 2 ==> button 3 motion 3249 * flag == 2 ==> button 3 motion
3162 */ 3250 */
3163void 3251void
3164rxvt_term::selection_extend (int x, int y, int flag) 3252rxvt_term::selection_extend (int x, int y, int flag) NOTHROW
3165{ 3253{
3166 int col = clamp (Pixel2Col (x), 0, ncol); 3254 int col = clamp (Pixel2Col (x), 0, ncol);
3167 int row = clamp (Pixel2Row (y), 0, nrow - 1); 3255 int row = clamp (Pixel2Row (y), 0, nrow - 1);
3168 3256
3169 /* 3257 /*
3172 * select nothing. Otherwise, if we're to the right of the mark, you have to 3260 * select nothing. Otherwise, if we're to the right of the mark, you have to
3173 * be _past_ a character for it to be selected. 3261 * be _past_ a character for it to be selected.
3174 */ 3262 */
3175 if (((selection.clicks % 3) == 1) && !flag 3263 if (((selection.clicks % 3) == 1) && !flag
3176 && (col == selection.mark.col 3264 && (col == selection.mark.col
3177 && (row == selection.mark.row + view_start))) 3265 && (row == selection.mark.row - view_start)))
3178 { 3266 {
3179 /* select nothing */ 3267 /* select nothing */
3180 selection.beg.row = selection.end.row = 0; 3268 selection.beg.row = selection.end.row = 0;
3181 selection.beg.col = selection.end.col = 0; 3269 selection.beg.col = selection.end.col = 0;
3182 selection.clicks = 4; 3270 selection.clicks = 4;
3195/* ------------------------------------------------------------------------- */ 3283/* ------------------------------------------------------------------------- */
3196/* 3284/*
3197 * Extend the selection to the specified col/row 3285 * Extend the selection to the specified col/row
3198 */ 3286 */
3199void 3287void
3200rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) 3288rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int buttonpress, int clickchange) NOTHROW
3201{ 3289{
3202 row_col_t pos; 3290 row_col_t pos;
3203 enum { 3291 enum {
3204 LEFT, RIGHT 3292 LEFT, RIGHT
3205 } closeto = RIGHT; 3293 } closeto = RIGHT;
3237 selection.beg.col = selection.end.col = selection.mark.col; 3325 selection.beg.col = selection.end.col = selection.mark.col;
3238 selection.beg.row = selection.end.row = selection.mark.row; 3326 selection.beg.row = selection.end.row = selection.mark.row;
3239 } 3327 }
3240 3328
3241 pos.col = col; 3329 pos.col = col;
3242 pos.row = row - view_start; 3330 pos.row = view_start + row;
3243 3331
3244 /* 3332 /*
3245 * This is mainly xterm style selection with a couple of differences, mainly 3333 * This is mainly xterm style selection with a couple of differences, mainly
3246 * in the way button3 drag extension works. 3334 * in the way button3 drag extension works.
3247 * We're either doing: button1 drag; button3 press; or button3 drag 3335 * We're either doing: button1 drag; button3 press; or button3 drag
3253 * a point/word/line which is either the start or end of the selection 3341 * a point/word/line which is either the start or end of the selection
3254 * and it was decided by whichever point/word/line was `fixed' at the 3342 * and it was decided by whichever point/word/line was `fixed' at the
3255 * time of the most recent button3 press 3343 * time of the most recent button3 press
3256 */ 3344 */
3257 if (button3 && buttonpress) 3345 if (button3 && buttonpress)
3346 {
3258 { /* button3 press */ 3347 /* button3 press */
3259 /* 3348 /*
3260 * first determine which edge of the selection we are closest to 3349 * first determine which edge of the selection we are closest to
3261 */ 3350 */
3262 if (ROWCOL_IS_BEFORE (pos, selection.beg) 3351 if (ROWCOL_IS_BEFORE (pos, selection.beg)
3263 || (!ROWCOL_IS_AFTER (pos, selection.end) 3352 || (!ROWCOL_IS_AFTER (pos, selection.end)
3281 selection.mark.row = selection.beg.row; 3370 selection.mark.row = selection.beg.row;
3282 selection.mark.col = selection.beg.col; 3371 selection.mark.col = selection.beg.col;
3283 } 3372 }
3284 } 3373 }
3285 else 3374 else
3375 {
3286 { /* button1 drag or button3 drag */ 3376 /* button1 drag or button3 drag */
3287 if (ROWCOL_IS_AFTER (selection.mark, pos)) 3377 if (ROWCOL_IS_AFTER (selection.mark, pos))
3288 { 3378 {
3289 if (selection.mark.row == selection.end.row 3379 if (selection.mark.row == selection.end.row
3290 && selection.mark.col == selection.end.col 3380 && selection.mark.col == selection.end.col
3291 && clickchange 3381 && clickchange
3308 3398
3309 if (selection.clicks == 1) 3399 if (selection.clicks == 1)
3310 { 3400 {
3311 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN 3401 if (selection.beg.col > ROW(selection.beg.row).l //TODO//FIXME//LEN
3312 && !ROW(selection.beg.row).is_longer () 3402 && !ROW(selection.beg.row).is_longer ()
3313#if ENABLE_FRILLS 3403#if !ENABLE_MINIMAL
3314 && !selection.rect 3404 && !selection.rect
3315#endif 3405#endif
3316 ) 3406 )
3317 selection.beg.col = ncol; 3407 selection.beg.col = ncol;
3318 3408
3319 if ( 3409 if (
3320 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN 3410 selection.end.col > ROW(selection.end.row).l //TODO//FIXME//LEN
3321 && !ROW(selection.end.row).is_longer () 3411 && !ROW(selection.end.row).is_longer ()
3322#if ENABLE_FRILLS 3412#if !ENABLE_MINIMAL
3323 && !selection.rect 3413 && !selection.rect
3324#endif 3414#endif
3325 ) 3415 )
3326 selection.end.col = ncol; 3416 selection.end.col = ncol;
3327 } 3417 }
3328 else if (selection.clicks == 2) 3418 else if (selection.clicks == 2)
3329 { 3419 {
3330 if (ROWCOL_IS_AFTER (selection.end, selection.beg)) 3420 if (ROWCOL_IS_AFTER (selection.end, selection.beg))
3331 selection.end.col--; 3421 selection.end.col--;
3332 3422
3333 if (!HOOK_INVOKE ((this, HOOK_SEL_EXTEND, DT_END)))
3334 {
3335 selection_delimit_word (UP, &selection.beg, &selection.beg); 3423 selection_delimit_word (UP, &selection.beg, &selection.beg);
3336 selection_delimit_word (DN, &selection.end, &selection.end); 3424 selection_delimit_word (DN, &selection.end, &selection.end);
3337 }
3338 } 3425 }
3339 else if (selection.clicks == 3) 3426 else if (selection.clicks == 3)
3340 { 3427 {
3341#if ENABLE_FRILLS 3428#if ENABLE_FRILLS
3342 if (OPTION (Opt_tripleclickwords)) 3429 if (option (Opt_tripleclickwords))
3343 { 3430 {
3344 selection_delimit_word (UP, &selection.beg, &selection.beg); 3431 selection_delimit_word (UP, &selection.beg, &selection.beg);
3345 3432
3346 for (int end_row = selection.mark.row; end_row < nrow; end_row++) 3433 for (int end_row = selection.mark.row; end_row < nrow; end_row++)
3347 { 3434 {
3348 if (!ROW(end_row).is_longer ()) 3435 if (!ROW(end_row).is_longer ())
3349 { 3436 {
3350 selection.end.row = end_row; 3437 selection.end.row = end_row;
3351 selection.end.col = ROW(end_row).l; 3438 selection.end.col = ROW(end_row).l;
3439# if !ENABLE_MINIMAL
3352 selection_remove_trailing_spaces (); 3440 selection_remove_trailing_spaces ();
3441# endif
3353 break; 3442 break;
3354 } 3443 }
3355 } 3444 }
3356 } 3445 }
3357 else 3446 else
3373 selection.end.row++; 3462 selection.end.row++;
3374 } 3463 }
3375 } 3464 }
3376 3465
3377 if (button3 && buttonpress) 3466 if (button3 && buttonpress)
3467 {
3378 { /* mark may need to be changed */ 3468 /* mark may need to be changed */
3379 if (closeto == LEFT) 3469 if (closeto == LEFT)
3380 { 3470 {
3381 selection.mark.row = selection.end.row; 3471 selection.mark.row = selection.end.row;
3382 selection.mark.col = selection.end.col - (selection.clicks == 2); 3472 selection.mark.col = selection.end.col - (selection.clicks == 2);
3383 } 3473 }
3386 selection.mark.row = selection.beg.row; 3476 selection.mark.row = selection.beg.row;
3387 selection.mark.col = selection.beg.col; 3477 selection.mark.col = selection.beg.col;
3388 } 3478 }
3389 } 3479 }
3390 3480
3391#if ENABLE_FRILLS 3481#if !ENABLE_MINIMAL
3392 if (selection.rect && selection.beg.col > selection.end.col) 3482 if (selection.rect && selection.beg.col > selection.end.col)
3393 ::swap (selection.beg.col, selection.end.col); 3483 ::swap (selection.beg.col, selection.end.col);
3394#endif 3484#endif
3395} 3485}
3396 3486
3397#if ENABLE_FRILLS 3487#if !ENABLE_MINIMAL
3398void 3488void
3399rxvt_term::selection_remove_trailing_spaces () 3489rxvt_term::selection_remove_trailing_spaces () NOTHROW
3400{ 3490{
3401 int32_t end_col, end_row; 3491 int32_t end_col, end_row;
3402 text_t *stp; 3492 text_t *stp;
3403 3493
3404 end_col = selection.end.col; 3494 end_col = selection.end.col;
3442/* 3532/*
3443 * Double click on button 3 when already selected 3533 * Double click on button 3 when already selected
3444 * EXT: button 3 double click 3534 * EXT: button 3 double click
3445 */ 3535 */
3446void 3536void
3447rxvt_term::selection_rotate (int x, int y) 3537rxvt_term::selection_rotate (int x, int y) NOTHROW
3448{ 3538{
3449 selection.clicks = selection.clicks % 3 + 1; 3539 selection.clicks = selection.clicks % 3 + 1;
3450 selection_extend_colrow (Pixel2Col (x), Pixel2Row (y), 1, 0, 1); 3540 selection_extend_colrow (Pixel2Col (x), Pixel2Row (y), 1, 0, 1);
3451} 3541}
3452 3542
3454/* 3544/*
3455 * Respond to a request for our current selection 3545 * Respond to a request for our current selection
3456 * EXT: SelectionRequest 3546 * EXT: SelectionRequest
3457 */ 3547 */
3458void 3548void
3459rxvt_term::selection_send (const XSelectionRequestEvent &rq) 3549rxvt_term::selection_send (const XSelectionRequestEvent &rq) NOTHROW
3460{ 3550{
3461 XSelectionEvent ev; 3551 XSelectionEvent ev;
3462 dDisp;
3463 3552
3464 ev.type = SelectionNotify; 3553 ev.type = SelectionNotify;
3465 ev.property = None; 3554 ev.property = None;
3466 ev.display = rq.display; 3555 ev.display = rq.display;
3467 ev.requestor = rq.requestor; 3556 ev.requestor = rq.requestor;
3481 *target++ = xa[XA_COMPOUND_TEXT]; 3570 *target++ = xa[XA_COMPOUND_TEXT];
3482#if X_HAVE_UTF8_STRING 3571#if X_HAVE_UTF8_STRING
3483 *target++ = xa[XA_UTF8_STRING]; 3572 *target++ = xa[XA_UTF8_STRING];
3484#endif 3573#endif
3485 3574
3486 XChangeProperty (disp, rq.requestor, rq.property, XA_ATOM, 3575 XChangeProperty (dpy, rq.requestor, rq.property, XA_ATOM,
3487 32, PropModeReplace, 3576 32, PropModeReplace,
3488 (unsigned char *)target_list, target - target_list); 3577 (unsigned char *)target_list, target - target_list);
3489 ev.property = rq.property; 3578 ev.property = rq.property;
3490 } 3579 }
3491#if TODO // TODO 3580#if TODO // TODO
3494 /* TODO: Handle MULTIPLE */ 3583 /* TODO: Handle MULTIPLE */
3495 } 3584 }
3496#endif 3585#endif
3497 else if (rq.target == xa[XA_TIMESTAMP] && selection.text) 3586 else if (rq.target == xa[XA_TIMESTAMP] && selection.text)
3498 { 3587 {
3499 XChangeProperty (disp, rq.requestor, rq.property, rq.target, 3588 XChangeProperty (dpy, rq.requestor, rq.property, rq.target,
3500 32, PropModeReplace, (unsigned char *)&selection_time, 1); 3589 32, PropModeReplace, (unsigned char *)&selection_time, 1);
3501 ev.property = rq.property; 3590 ev.property = rq.property;
3502 } 3591 }
3503 else if (rq.target == XA_STRING 3592 else if (rq.target == XA_STRING
3504 || rq.target == xa[XA_TEXT] 3593 || rq.target == xa[XA_TEXT]
3528 style = enc_string; 3617 style = enc_string;
3529 else if (target == xa[XA_TEXT]) 3618 else if (target == xa[XA_TEXT])
3530 style = enc_text; 3619 style = enc_text;
3531 else if (target == xa[XA_COMPOUND_TEXT]) 3620 else if (target == xa[XA_COMPOUND_TEXT])
3532 style = enc_compound_text; 3621 style = enc_compound_text;
3533#if ENABLE_FRILLS 3622#if !ENABLE_MINIMAL
3534 else if (target == xa[XA_UTF8_STRING]) 3623 else if (target == xa[XA_UTF8_STRING])
3535 style = enc_utf8; 3624 style = enc_utf8;
3536#endif 3625#endif
3537 else 3626 else
3538 { 3627 {
3549 { 3638 {
3550 cl = L""; 3639 cl = L"";
3551 selectlen = 0; 3640 selectlen = 0;
3552 } 3641 }
3553 3642
3554#if ENABLE_FRILLS 3643#if !ENABLE_MINIMAL
3555 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it 3644 // xlib is horribly broken with respect to UTF8_STRING, and nobody cares to fix it
3556 // so recode it manually 3645 // so recode it manually
3557 if (style == enc_utf8) 3646 if (style == enc_utf8)
3558 { 3647 {
3559 freect = 1; 3648 freect = 1;
3562 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen); 3651 ct.value = (unsigned char *)rxvt_wcstoutf8 (cl, selectlen);
3563 ct.nitems = strlen ((char *)ct.value); 3652 ct.nitems = strlen ((char *)ct.value);
3564 } 3653 }
3565 else 3654 else
3566#endif 3655#endif
3567 if (XwcTextListToTextProperty (disp, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0) 3656 if (XwcTextListToTextProperty (dpy, &cl, 1, (XICCEncodingStyle) style, &ct) >= 0)
3568 freect = 1; 3657 freect = 1;
3569 else 3658 else
3570 { 3659 {
3571 /* if we failed to convert then send it raw */ 3660 /* if we failed to convert then send it raw */
3572 ct.value = (unsigned char *)cl; 3661 ct.value = (unsigned char *)cl;
3573 ct.nitems = selectlen; 3662 ct.nitems = selectlen;
3574 ct.encoding = target; 3663 ct.encoding = target;
3575 } 3664 }
3576 3665
3577 XChangeProperty (disp, rq.requestor, rq.property, 3666 XChangeProperty (dpy, rq.requestor, rq.property,
3578 ct.encoding, 8, PropModeReplace, 3667 ct.encoding, 8, PropModeReplace,
3579 ct.value, (int)ct.nitems); 3668 ct.value, (int)ct.nitems);
3580 ev.property = rq.property; 3669 ev.property = rq.property;
3581 3670
3582 if (freect) 3671 if (freect)
3583 XFree (ct.value); 3672 XFree (ct.value);
3584 } 3673 }
3585 3674
3586 XSendEvent (disp, rq.requestor, False, 0L, (XEvent *)&ev); 3675 XSendEvent (dpy, rq.requestor, False, 0L, (XEvent *)&ev);
3587}
3588
3589/* ------------------------------------------------------------------------- *
3590 * MOUSE ROUTINES *
3591 * ------------------------------------------------------------------------- */
3592
3593/*
3594 * return col/row values corresponding to x/y pixel values
3595 */
3596void
3597rxvt_term::pixel_position (int *x, int *y)
3598{
3599 *x = Pixel2Col (*x);
3600 /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */
3601 *y = Pixel2Row (*y);
3602 /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */
3603} 3676}
3604 3677
3605/* ------------------------------------------------------------------------- */ 3678/* ------------------------------------------------------------------------- */
3606#ifdef USE_XIM 3679#ifdef USE_XIM
3607void 3680void
3608rxvt_term::im_set_position (XPoint &pos) 3681rxvt_term::im_set_position (XPoint &pos) NOTHROW
3609{ 3682{
3610 XWindowAttributes xwa; 3683 XWindowAttributes xwa;
3611 3684
3612 XGetWindowAttributes (display->display, vt, &xwa); 3685 XGetWindowAttributes (dpy, vt, &xwa);
3613 3686
3614 pos.x = xwa.x + Col2Pixel (screen.cur.col); 3687 pos.x = xwa.x + Col2Pixel (screen.cur.col);
3615 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase; 3688 pos.y = xwa.y + Height2Pixel (screen.cur.row) + fbase;
3616} 3689}
3617#endif 3690#endif
3618 3691
3619#if ENABLE_OVERLAY 3692#if ENABLE_OVERLAY
3620void 3693void
3621rxvt_term::scr_overlay_new (int x, int y, int w, int h) 3694rxvt_term::scr_overlay_new (int x, int y, int w, int h) NOTHROW
3622{ 3695{
3623 if (nrow < 1 || ncol < 1) 3696 if (nrow < 1 || ncol < 1)
3624 return; 3697 return;
3625 3698
3626 want_refresh = 1; 3699 want_refresh = 1;
3671 *rp = r; 3744 *rp = r;
3672 } 3745 }
3673} 3746}
3674 3747
3675void 3748void
3676rxvt_term::scr_overlay_off () 3749rxvt_term::scr_overlay_off () NOTHROW
3677{ 3750{
3678 if (!ov_text) 3751 if (!ov_text)
3679 return; 3752 return;
3680 3753
3681 want_refresh = 1; 3754 want_refresh = 1;
3689 delete [] ov_text; ov_text = 0; 3762 delete [] ov_text; ov_text = 0;
3690 delete [] ov_rend; ov_rend = 0; 3763 delete [] ov_rend; ov_rend = 0;
3691} 3764}
3692 3765
3693void 3766void
3694rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) 3767rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW
3695{ 3768{
3696 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2) 3769 if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2)
3697 return; 3770 return;
3698 3771
3699 x++, y++; 3772 x++, y++;
3701 ov_text[y][x] = text; 3774 ov_text[y][x] = text;
3702 ov_rend[y][x] = rend; 3775 ov_rend[y][x] = rend;
3703} 3776}
3704 3777
3705void 3778void
3706rxvt_term::scr_overlay_set (int x, int y, const char *s) 3779rxvt_term::scr_overlay_set (int x, int y, const char *s) NOTHROW
3707{ 3780{
3708 while (*s) 3781 while (*s)
3709 scr_overlay_set (x++, y, *s++); 3782 scr_overlay_set (x++, y, *s++);
3710} 3783}
3711 3784
3712void 3785void
3713rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) 3786rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) NOTHROW
3714{ 3787{
3715 while (*s) 3788 while (*s)
3716 { 3789 {
3717 text_t t = *s++; 3790 text_t t = *s++;
3718 int width = wcwidth (t); 3791 int width = WCWIDTH (t);
3719 3792
3720 while (width--) 3793 while (width--)
3721 { 3794 {
3722 scr_overlay_set (x++, y, t); 3795 scr_overlay_set (x++, y, t);
3723 t = NOCHAR; 3796 t = NOCHAR;
3724 } 3797 }
3725 } 3798 }
3726} 3799}
3727 3800
3728void 3801void
3729rxvt_term::scr_swap_overlay () 3802rxvt_term::scr_swap_overlay () NOTHROW
3730{ 3803{
3731 if (!ov_text) 3804 if (!ov_text)
3732 return; 3805 return;
3733 3806
3734 // swap screen mem with overlay 3807 // swap screen mem with overlay
3735 for (int y = ov_h; y--; ) 3808 for (int y = ov_h; y--; )
3736 { 3809 {
3737 text_t *t1 = ov_text[y]; 3810 text_t *t1 = ov_text[y];
3738 rend_t *r1 = ov_rend[y]; 3811 rend_t *r1 = ov_rend[y];
3739 3812
3740 text_t *t2 = ROW(y + ov_y - view_start).t + ov_x; 3813 text_t *t2 = ROW(y + ov_y + view_start).t + ov_x;
3741 rend_t *r2 = ROW(y + ov_y - view_start).r + ov_x; 3814 rend_t *r2 = ROW(y + ov_y + view_start).r + ov_x;
3742 3815
3743 for (int x = ov_w; x--; ) 3816 for (int x = ov_w; x--; )
3744 { 3817 {
3745 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3818 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3746 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); 3819 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines