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.176 by root, Tue Dec 20 20:58:31 2005 UTC vs.
Revision 1.193 by root, Thu Dec 22 19:39:29 2005 UTC

83#define ROWCOL_IN_ROW_AT_OR_AFTER(X, Y) \ 83#define ROWCOL_IN_ROW_AT_OR_AFTER(X, Y) \
84 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col) 84 ROW_AND_COL_IN_ROW_AT_OR_AFTER ((X).row, (X).col, (Y).row, (Y).col)
85#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \ 85#define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \
86 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col) 86 ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col)
87 87
88#define LINENO(n) (((n) + term_start + total_rows) % total_rows)
89#define ROW(n) (save [LINENO (n)])
90
91/* 88/*
92 * CLEAR_ROWS : clear <num> rows starting from row <row> 89 * CLEAR_ROWS : clear <num> rows starting from row <row>
93 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y> 90 * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
94 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour 91 * ERASE_ROWS : set <num> rows starting from row <row> to the foreground colour
95 */ 92 */
150} 147}
151 148
152/* ------------------------------------------------------------------------- * 149/* ------------------------------------------------------------------------- *
153 * SCREEN INITIALISATION * 150 * SCREEN INITIALISATION *
154 * ------------------------------------------------------------------------- */ 151 * ------------------------------------------------------------------------- */
152
155void 153void
156rxvt_term::scr_reset () 154rxvt_term::scr_reset ()
157{ 155{
158 unsigned int p, q;
159 int k;
160
161#if ENABLE_OVERLAY 156#if ENABLE_OVERLAY
162 scr_overlay_off (); 157 scr_overlay_off ();
163#endif 158#endif
164 159
165 view_start = 0; 160 view_start = 0;
175 return; 170 return;
176 171
177 // we need at least two lines for wrapping to work correctly 172 // we need at least two lines for wrapping to work correctly
178 if (nrow + saveLines < 2) 173 if (nrow + saveLines < 2)
179 { 174 {
175 //TODO//FIXME
180 saveLines++; 176 saveLines++;
181 prev_nrow--; 177 prev_nrow--;
182 nsaved++; 178 nsaved++;
183 } 179 }
184 180
188 total_rows = nrow + saveLines; 184 total_rows = nrow + saveLines;
189 185
190 screen.tscroll = 0; 186 screen.tscroll = 0;
191 screen.bscroll = nrow - 1; 187 screen.bscroll = nrow - 1;
192 188
193 if (!save) 189 if (!row_buf)
194 { 190 {
195 /* 191 /*
196 * first time called so just malloc everything: don't rely on realloc 192 * first time called so just malloc everything: don't rely on realloc
197 * Note: this is still needed so that all the scrollback lines are NULL 193 * Note: this is still needed so that all the scrollback lines are NULL
198 */ 194 */
200 term_start = 0; 196 term_start = 0;
201 197
202 talloc = new rxvt_salloc (ncol * sizeof (text_t)); 198 talloc = new rxvt_salloc (ncol * sizeof (text_t));
203 ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 199 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
204 200
205 save = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
206 buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 201 row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
202 temp_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
207 drawn = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); 203 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
208 swap_save = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); 204 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
209 205
210 for (p = nrow; p--; ) 206 for (int row = nrow; row--; )
211 { 207 {
212 scr_blank_screen_mem (ROW(p), DEFAULT_RSTYLE); 208 scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE);
213 scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); 209 scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
214 scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE); 210 scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
215 } 211 }
216 212
217 memset (charsets, 'B', sizeof (charsets)); 213 memset (charsets, 'B', sizeof (charsets));
218 rstyle = DEFAULT_RSTYLE; 214 rstyle = DEFAULT_RSTYLE;
219 screen.flags = Screen_DefaultFlags; 215 screen.flags = Screen_DefaultFlags;
243 { 239 {
244 /* 240 /*
245 * add or delete rows as appropriate 241 * add or delete rows as appropriate
246 */ 242 */
247 243
248 rxvt_salloc *old_ta; 244 rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t));
249 rxvt_salloc *old_ra; 245 rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
250 246
247#if 0
251 if (nrow < prev_nrow) 248 if (nrow < prev_nrow)
252 { 249 {
253 /* delete rows */
254 k = min (nsaved, prev_nrow - nrow);
255 // k = max (0, - ( (nrow - 1) - r->screen.cur.row)); // mmc's http://maruska.dyndns.org/wiki/scrolling-bug //make configurable? //D TODO
256 scr_scroll_text (0, (int)prev_nrow - 1, k);
257
258 for (p = nrow; p < prev_nrow; p++) 250 for (int row = nrow; row < prev_nrow; row++)
259 { 251 {
260 lfree (ROW(p));
261 lfree (swap_save[p]); 252 lfree (swap_buf [row]);
262 lfree (drawn[p]); 253 lfree (drawn_buf[row]);
263 } 254 }
255 }
256#endif
264 257
265 /* we have fewer rows so fix up cursor position */ 258 drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t));
266 MIN_IT (screen.cur.row, (int32_t)nrow - 1); 259 temp_buf = (line_t *)rxvt_realloc (temp_buf , nrow * sizeof (line_t));
260 swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t));
267 261
268 scr_reset_realloc (); /* realloc _last_ */ 262 for (int row = min (nrow, prev_nrow); row--; )
263 {
264 lresize (drawn_buf[row]);
265 lresize (swap_buf [row]);
266 }
267
268 for (int row = prev_nrow; row < nrow; row++)
269 {
270 swap_buf [row].clear (); scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
271 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
272 }
273
274 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
269 } 275
270 else if (nrow > prev_nrow) 276 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
277 int pend = MOD (term_start - nsaved , prev_total_rows);
278 int q = total_rows; // rewrapped row
279
280 if (nsaved)
281 {
282 // re-wrap lines, this is rather ugly, possibly because I am too dumb
283 // to come up with a lean and mean algorithm.
284
285 row_col_t ocur = screen.cur;
286 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
287
271 { 288 do
272 /* add rows */
273 scr_reset_realloc (); /* realloc _first_ */
274
275 int ocol = ncol;
276 ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this
277
278 k = min (nsaved, nrow - prev_nrow);
279
280 for (p = prev_total_rows; p < total_rows; p++)
281 save[p].clear ();
282
283 for (p = prev_total_rows; p < total_rows - k; p++)
284 scr_blank_screen_mem (save[p], DEFAULT_RSTYLE);
285
286 for (p = prev_nrow; p < nrow; p++)
287 { 289 {
288 swap_save[p].clear (); scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); 290 p = MOD (p - 1, prev_total_rows);
289 drawn[p].clear (); scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE);
290 }
291
292 if (k > 0)
293 {
294 scr_scroll_text (0, (int)nrow - 1, -k);
295 screen.cur.row += k;
296 screen.s_cur.row += k;
297 nsaved -= k;
298 }
299
300#ifdef DEBUG_STRICT 291#ifdef DEBUG_STRICT
301 assert (screen.cur.row < nrow); 292 assert (old_buf [MOD (p, prev_total_rows)].t);
302#else /* drive with your eyes closed */
303 MIN_IT (screen.cur.row, nrow - 1);
304#endif 293#endif
305 ncol = ocol; // save b/c scr_blank_screen_mem uses this
306 }
307 294
308 /* resize columns */
309 if (ncol != prev_ncol)
310 {
311 old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t));
312 old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
313
314 for (p = total_rows; p--; )
315 lresize (save[p]);
316
317 for (p = nrow; p--; )
318 {
319 lresize (drawn[p]);
320 lresize (swap_save[p]);
321 }
322
323 MIN_IT (screen.cur.col, (int16_t)ncol - 1);
324
325 delete old_ta;
326 delete old_ra;
327 }
328
329#if 0
330 // re-wrap lines, this is rather ugly, possibly because I am too dumb
331 // to come up with a lean and mean algorithm.
332 rxvt_salloc *ta = new rxvt_salloc (ncol * sizeof (text_t));
333 rxvt_salloc *ra = new rxvt_salloc (ncol * sizeof (rend_t));
334
335 text_t **tp = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *));
336 rend_t **rp = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *));
337 tlen_t *tl = (tlen_t *) rxvt_calloc (total_rows, sizeof (tlen_t));
338
339 for (p = 0; p < prev_total_rows; p++) printf ("P %p %d\n", save[p].t, save[p].l);//D
340
341 p = prev_total_rows;
342 q = total_rows;
343
344 while (p > 0 && q > 0)
345 {
346 --p;
347
348 printf ("pq %d:%d\n", p, q);
349 if (save[p].t)
350 {
351 int llen = save[p].l; 295 int plines = 1;
296 int llen = old_buf [MOD (p, prev_total_rows)].l;
352 297
353 assert (llen >= 0); 298 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
354
355 while (p && save[p - 1].l < 0)
356 { 299 {
300 p = MOD (p - 1, prev_total_rows);
301
357 --p; 302 plines++;
358 llen += prev_ncol; 303 llen += prev_ncol;
359 } 304 }
360 305
361 int qlines = llen / ncol + 1; 306 int qlines = max (0, (llen - 1) / ncol) + 1;
307
308 // drop partial lines completely
309 if (q < qlines)
310 break;
311
312 q -= qlines;
313
362 int lofs = 0; 314 int lofs = 0;
315 line_t *qline;
363 316
364 q -= qlines; 317 // re-assemble the full line by destination lines
365
366 int qrow = q;
367
368 printf ("QL %d llen %d\n", qlines, llen);//D
369 for (; qlines--; qrow++) 318 for (int qrow = q; qlines--; qrow++)
370 { 319 {
320 qline = row_buf + qrow;
321 lalloc (*qline);
322 qline->set_is_longer ();
323
371 if (qrow >= 0) 324 int qcol = 0;
325
326 // fill a single destination line
327 while (lofs < llen && qcol < ncol)
372 { 328 {
373 tp [qrow] = (text_t *)ta->alloc ();
374 rp [qrow] = (rend_t *)ra->alloc ();
375 tl [qrow] = LINE_CONT1;
376
377 int qcol = 0;
378
379 for (;;)
380 {
381 int prow = lofs / prev_ncol + p; 329 int prow = lofs / prev_ncol;
382 int pcol = lofs % prev_ncol; 330 int pcol = lofs % prev_ncol;
383 331
332 prow = MOD (p + prow, prev_total_rows);
333
334 // we only adjust the cursor _row_ and put it into
335 // the topmost line of "long line" it was in, as
336 // this seems to upset applications/shells/readline
337 // least.
338 if (prow == ocur.row)
339 screen.cur.row = q - (total_rows - nrow);
340
341 line_t &pline = old_buf [prow];
342
384 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 343 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
385 344
386 printf ("q %d lofs %d>%d len %d pq %d:%d p %d:%d q :%d\n", q, llen, lofs, len, prev_ncol, ncol, prow, pcol, qcol);
387
388 if (len <= 0)
389 {
390 tl [qrow] = qcol;
391
392 TODO
393 scr_blank_line (tp [qrow] + qcol, rp [qrow] + qcol,
394 ncol - qcol, DEFAULT_RSTYLE);
395
396 break;
397 }
398
399 assert (lofs < 1000); 345 assert (len);
346 assert (pline.t);
400 347
401 memcpy (tp [qrow] + qcol, save[prow].t + pcol, len * sizeof (text_t)); 348 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
402 memcpy (rp [qrow] + qcol, save[prow].r + pcol, len * sizeof (rend_t)); 349 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
403 350
404 lofs += len; 351 lofs += len;
405 qcol += len; 352 qcol += len;
406
407 if (qcol == ncol)
408 break;
409 }
410 } 353 }
411 else
412 lofs += ncol;
413 } 354 }
355
356 qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1;
357 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
414 } 358 }
359 while (p != pend && q > 0);
360
361 term_start = total_rows - nrow;
362 nsaved = term_start - q;
363
364 // make sure all terminal lines exist
365 while (nsaved < 0)
366 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
367
368 }
369 else
415 } 370 {
371 // if no scrollback exists (yet), wing, instead of wrap
372
373 for (int row = min (nrow, prev_nrow); row--; )
374 {
375 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
376 line_t &qline = row_buf [row];
416 377
417 free (screen.text); screen.text = tp; 378 qline = pline;
418 free (screen.rend); screen.rend = rp; 379 lresize (qline);
419 free (screen.tlen); screen.tlen = tl; 380 }
420 381
421 for (p = 0; p < total_rows; p++) printf ("P %p %d\n", save[p].t, save[p].l);//D 382 for (int row = prev_nrow; row < nrow; row++)
383 {
384 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
385 }
386
387 term_start = 0;
388 }
389
390#ifdef DEBUG_STRICT //TODO: remove
391 for (int i = -nsaved; i < nrow; i++)
392 assert (ROW (i).t);
422#endif 393#endif
394
395 free (old_buf);
396 delete old_ta;
397 delete old_ra;
398
399 clamp_it (screen.cur.row, 0, nrow - 1);
400 clamp_it (screen.cur.col, 0, ncol - 1);
423 401
424 if (tabs) 402 if (tabs)
425 free (tabs); 403 free (tabs);
426 } 404 }
427 405
428 prev_nrow = nrow; 406 prev_nrow = nrow;
429 prev_ncol = ncol; 407 prev_ncol = ncol;
430 408
431 tabs = (char *)rxvt_malloc (ncol * sizeof (char)); 409 tabs = (char *)rxvt_malloc (ncol * sizeof (char));
432 410
433 for (p = 0; p < ncol; p++) 411 for (int col = ncol; col--; )
434 tabs[p] = (p % TABSIZE == 0) ? 1 : 0; 412 tabs [col] = col % TABSIZE == 0;
435 413
436 tt_winch (); 414 tt_winch ();
437}
438
439void
440rxvt_term::scr_reset_realloc ()
441{
442 swap_save = (line_t *) rxvt_realloc (swap_save , nrow * sizeof (line_t));
443 drawn = (line_t *) rxvt_realloc (drawn , nrow * sizeof (line_t));
444 buf = (line_t *) rxvt_realloc (buf , nrow * sizeof (line_t));
445 save = (line_t *) rxvt_realloc (save , total_rows * sizeof (line_t));
446} 415}
447 416
448/* ------------------------------------------------------------------------- */ 417/* ------------------------------------------------------------------------- */
449/* 418/*
450 * Free everything. That way malloc debugging can find leakage. 419 * Free everything. That way malloc debugging can find leakage.
453rxvt_term::scr_release () 422rxvt_term::scr_release ()
454{ 423{
455 delete talloc; talloc = 0; 424 delete talloc; talloc = 0;
456 delete ralloc; ralloc = 0; 425 delete ralloc; ralloc = 0;
457 426
458 free (save); 427 free (row_buf);
459 free (swap_save); 428 free (swap_buf);
460 free (drawn); 429 free (drawn_buf);
461 free (buf); 430 free (temp_buf);
462 free (tabs); 431 free (tabs);
432
433 row_buf = 0; // signal that we freed all the arrays
463} 434}
464 435
465/* ------------------------------------------------------------------------- */ 436/* ------------------------------------------------------------------------- */
466/* 437/*
467 * Hard reset 438 * Hard reset
518 set_font_style (); 489 set_font_style ();
519 break; 490 break;
520 } 491 }
521 492
522 /* boundary check in case screen size changed between SAVE and RESTORE */ 493 /* boundary check in case screen size changed between SAVE and RESTORE */
523 MIN_IT (s->cur.row, nrow - 1); 494 min_it (s->cur.row, nrow - 1);
524 MIN_IT (s->cur.col, ncol - 1); 495 min_it (s->cur.col, ncol - 1);
525#ifdef DEBUG_STRICT 496#ifdef DEBUG_STRICT
526 assert (s->cur.row >= 0); 497 assert (s->cur.row >= 0);
527 assert (s->cur.col >= 0); 498 assert (s->cur.col >= 0);
528#else /* drive with your eyes closed */
529 MAX_IT (s->cur.row, 0);
530 MAX_IT (s->cur.col, 0);
531#endif 499#endif
532} 500}
533 501
534/* ------------------------------------------------------------------------- */ 502/* ------------------------------------------------------------------------- */
535/* 503/*
546 if (current_screen == scrn) 514 if (current_screen == scrn)
547 return scrn; 515 return scrn;
548 516
549 selection_check (2); /* check for boundary cross */ 517 selection_check (2); /* check for boundary cross */
550 518
551 SWAP_IT (scrn, current_screen, int); 519 int i = current_screen; current_screen = scrn; scrn = i;
552 520
553 SWAP_IT (screen.cur.row, swap.cur.row, int16_t); 521 ::swap (screen.cur.row, swap.cur.row);
554 SWAP_IT (screen.cur.col, swap.cur.col, int16_t); 522 ::swap (screen.cur.col, swap.cur.col);
555 MAX_IT (screen.cur.row, 0); 523
556 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); 524 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
557 MAX_IT (screen.cur.col, 0); 525 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
558 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1);
559 526
560#if NSCREENS 527#if NSCREENS
561 if (options & Opt_secondaryScreen) 528 if (options & Opt_secondaryScreen)
562 { 529 {
563 num_scr = 0; 530 num_scr = 0;
564 531
565 for (int i = nrow; i--; ) 532 for (int i = prev_nrow; i--; )
566 SWAP_IT (ROW(i), swap_save[i], line_t); 533 ::swap (ROW(i), swap_buf [i]);
567 534
568 SWAP_IT (screen.charset, swap.charset, int16_t); 535 ::swap (screen.charset, swap.charset);
569 SWAP_IT (screen.flags, swap.flags, int); 536 ::swap (screen.flags, swap.flags);
570 screen.flags |= Screen_VisibleCursor; 537 screen.flags |= Screen_VisibleCursor;
571 swap.flags |= Screen_VisibleCursor; 538 swap.flags |= Screen_VisibleCursor;
572 } 539 }
573 else 540 else
574#endif 541#endif
639 return 0; 606 return 0;
640 607
641 want_refresh = 1; 608 want_refresh = 1;
642 num_scr += count; 609 num_scr += count;
643 610
644 if (row1 == 0 && count > 0 611 if (count > 0
612 && row1 == 0
613 && row2 == nrow - 1
645 && (current_screen == PRIMARY || options & Opt_secondaryScroll)) 614 && (current_screen == PRIMARY || options & Opt_secondaryScroll))
646 { 615 {
647 nsaved = min (nsaved + count, saveLines); 616 nsaved = min (nsaved + count, saveLines);
648 term_start = (term_start + count) % total_rows; 617 term_start = (term_start + count) % total_rows;
649 618
695 // use a simple and robust scrolling algorithm, this 664 // use a simple and robust scrolling algorithm, this
696 // part of scr_scroll_text is not time-critical. 665 // part of scr_scroll_text is not time-critical.
697 666
698 int rows = row2 - row1 + 1; 667 int rows = row2 - row1 + 1;
699 668
669 min_it (count, rows);
670
700 for (int row = 0; row < rows; row++) 671 for (int row = 0; row < rows; row++)
701 { 672 {
702 buf [row] = ROW(row1 + (row + count + rows) % rows); 673 temp_buf [row] = ROW(row1 + (row + count + rows) % rows);
703 674
704 if (!IN_RANGE_EXC (row + count, 0, rows)) 675 if (!IN_RANGE_EXC (row + count, 0, rows))
705 scr_blank_screen_mem (buf [row], rstyle); 676 scr_blank_screen_mem (temp_buf [row], rstyle);
706 } 677 }
707 678
708 for (int row = 0; row < rows; row++) 679 for (int row = 0; row < rows; row++)
709 ROW(row1 + row) = buf [row]; 680 ROW(row1 + row) = temp_buf [row];
710 } 681 }
711 682
712 return count; 683 return count;
713} 684}
714 685
722 if (len <= 0) /* sanity */ 693 if (len <= 0) /* sanity */
723 return; 694 return;
724 695
725 unsigned char checksel; 696 unsigned char checksel;
726 unicode_t c; 697 unicode_t c;
727 int row, last_col; 698 int last_col;
728 const unicode_t *strend = str + len; 699 const unicode_t *strend = str + len;
729 700
730 want_refresh = 1; 701 want_refresh = 1;
731 ZERO_SCROLLBACK (); 702 ZERO_SCROLLBACK ();
732 last_col = ncol; 703 last_col = ncol;
733 704
734 if (nlines > 0) 705 if (nlines > 0)
735 { 706 {
736 nlines += screen.cur.row - screen.bscroll; 707 nlines += screen.cur.row - screen.bscroll;
737 if ((nlines > 0) 708 if (nlines > 0
738 && (screen.tscroll == 0) 709 && screen.tscroll == 0
739 && (screen.bscroll == (nrow - 1))) 710 && screen.bscroll == (nrow - 1))
740 { 711 {
741 /* _at least_ this many lines need to be scrolled */ 712 /* _at least_ this many lines need to be scrolled */
742 scr_scroll_text (screen.tscroll, screen.bscroll, nlines); 713 scr_scroll_text (screen.tscroll, screen.bscroll, nlines);
743 screen.cur.row -= nlines; 714 screen.cur.row -= nlines;
744 } 715 }
745 } 716 }
746 717
747#ifdef DEBUG_STRICT 718#ifdef DEBUG_STRICT
748 assert (screen.cur.col < last_col); 719 assert (screen.cur.col < last_col);
749 assert ((screen.cur.row < nrow) 720 assert (screen.cur.row < nrow
750 && (screen.cur.row >= - (int32_t)nsaved)); 721 && screen.cur.row >= -nsaved);
751#else /* drive with your eyes closed */
752 MIN_IT (screen.cur.col, last_col - 1);
753 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
754 MAX_IT (screen.cur.row, - (int32_t)nsaved);
755#endif 722#endif
756 row = screen.cur.row; 723 int row = screen.cur.row;
757 724
758 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 725 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
759 726
760 line_t *line = &ROW(row); 727 line_t *line = &ROW(row);
761 728
765 732
766 if (c < 0x20) 733 if (c < 0x20)
767 if (c == C0_LF) 734 if (c == C0_LF)
768 { 735 {
769 if (!line->is_longer ()) /* XXX: think about this */ 736 if (!line->is_longer ()) /* XXX: think about this */
770 MAX_IT (line->l, screen.cur.col); 737 max_it (line->l, screen.cur.col);
771 738
772 screen.flags &= ~Screen_WrapNext; 739 screen.flags &= ~Screen_WrapNext;
773 740
774 if (screen.cur.row == screen.bscroll) 741 if (screen.cur.row == screen.bscroll)
775 scr_scroll_text (screen.tscroll, screen.bscroll, 1); 742 scr_scroll_text (screen.tscroll, screen.bscroll, 1);
780 continue; 747 continue;
781 } 748 }
782 else if (c == C0_CR) 749 else if (c == C0_CR)
783 { 750 {
784 if (!line->is_longer ()) /* XXX: think about this */ 751 if (!line->is_longer ()) /* XXX: think about this */
785 MAX_IT (line->l, screen.cur.col); 752 max_it (line->l, screen.cur.col);
786 753
787 screen.flags &= ~Screen_WrapNext; 754 screen.flags &= ~Screen_WrapNext;
788 screen.cur.col = 0; 755 screen.cur.col = 0;
789 continue; 756 continue;
790 } 757 }
966#endif 933#endif
967 } 934 }
968 } 935 }
969 936
970 if (!line->is_longer ()) /* XXX: think about this */ 937 if (!line->is_longer ()) /* XXX: think about this */
971 MAX_IT (line->l, screen.cur.col); 938 max_it (line->l, screen.cur.col);
972 939
973#ifdef DEBUG_STRICT 940#ifdef DEBUG_STRICT
974 assert (screen.cur.row >= 0); 941 assert (screen.cur.row >= 0);
975#else /* drive with your eyes closed */
976 MAX_IT (screen.cur.row, 0);
977#endif 942#endif
978} 943}
979 944
980/* ------------------------------------------------------------------------- */ 945/* ------------------------------------------------------------------------- */
981/* 946/*
1020 985
1021 if (count == 0) 986 if (count == 0)
1022 return; 987 return;
1023 else if (count > 0) 988 else if (count > 0)
1024 { 989 {
1025 int row = screen.cur.row;
1026
1027 line_t &l = ROW(row); 990 line_t &l = ROW(screen.cur.row);
1028 rend_t base_rend = l.r[i]; 991 rend_t base_rend = l.r[i];
1029 ht &= l.t[i] == ' '; 992 ht &= l.t[i] == ' ';
1030 993
1031 for (; ++i < ncol; ) 994 for (; ++i < ncol; )
1032 if (tabs[i]) 995 if (tabs[i])
1047 if (ht && options & Opt_pastableTabs) 1010 if (ht && options & Opt_pastableTabs)
1048 { 1011 {
1049 base_rend = SET_FONT (base_rend, 0); 1012 base_rend = SET_FONT (base_rend, 0);
1050 1013
1051 if (!l.is_longer ()) /* XXX: think about this */ 1014 if (!l.is_longer ()) /* XXX: think about this */
1052 MAX_IT (l.l, x); 1015 max_it (l.l, x);
1053 1016
1054 i = screen.cur.col; 1017 i = screen.cur.col;
1055 1018
1056 l.t[i] = '\t'; 1019 l.t[i] = '\t';
1057 l.r[i] = base_rend; 1020 l.r[i] = base_rend;
1107 */ 1070 */
1108#if ENABLE_FRILLS 1071#if ENABLE_FRILLS
1109void 1072void
1110rxvt_term::scr_forwardindex () 1073rxvt_term::scr_forwardindex ()
1111{ 1074{
1112 int row;
1113
1114 if (screen.cur.col < ncol - 1) 1075 if (screen.cur.col < ncol - 1)
1115 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1076 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1116 else 1077 else
1117 { 1078 {
1118 row = screen.cur.row;
1119
1120 if (ROW(row).is_longer ()) //TODO//FIXME//LEN 1079 if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN
1121 ROW(row).l = ncol; 1080 ROW(screen.cur.row).l = ncol;
1122 1081
1123 scr_gotorc (0, 0, R_RELATIVE); 1082 scr_gotorc (0, 0, R_RELATIVE);
1124 scr_insdel_chars (1, DELETE); 1083 scr_insdel_chars (1, DELETE);
1125 scr_gotorc (0, ncol - 1, R_RELATIVE); 1084 scr_gotorc (0, ncol - 1, R_RELATIVE);
1126 } 1085 }
1136{ 1095{
1137 want_refresh = 1; 1096 want_refresh = 1;
1138 ZERO_SCROLLBACK (); 1097 ZERO_SCROLLBACK ();
1139 1098
1140 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col; 1099 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col;
1141 MAX_IT (screen.cur.col, 0); 1100 clamp_it (screen.cur.col, 0, ncol - 1);
1142 MIN_IT (screen.cur.col, (int32_t)ncol - 1);
1143 1101
1144 screen.flags &= ~Screen_WrapNext; 1102 screen.flags &= ~Screen_WrapNext;
1145 1103
1146 if (relative & R_RELATIVE) 1104 if (relative & R_RELATIVE)
1147 { 1105 {
1165 else 1123 else
1166 { 1124 {
1167 if (screen.flags & Screen_Relative) 1125 if (screen.flags & Screen_Relative)
1168 { /* relative origin mode */ 1126 { /* relative origin mode */
1169 screen.cur.row = row + screen.tscroll; 1127 screen.cur.row = row + screen.tscroll;
1170 MIN_IT (screen.cur.row, screen.bscroll); 1128 min_it (screen.cur.row, screen.bscroll);
1171 } 1129 }
1172 else 1130 else
1173 screen.cur.row = row; 1131 screen.cur.row = row;
1174 } 1132 }
1175 1133
1176 MAX_IT (screen.cur.row, 0); 1134 clamp_it (screen.cur.row, 0, nrow - 1);
1177 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
1178} 1135}
1179 1136
1180/* ------------------------------------------------------------------------- */ 1137/* ------------------------------------------------------------------------- */
1181/* 1138/*
1182 * direction should be UP or DN 1139 * direction should be UP or DN
1197 || (screen.cur.row == screen.tscroll && direction == DN)) 1154 || (screen.cur.row == screen.tscroll && direction == DN))
1198 scr_scroll_text (screen.tscroll, screen.bscroll, dirn); 1155 scr_scroll_text (screen.tscroll, screen.bscroll, dirn);
1199 else 1156 else
1200 screen.cur.row += dirn; 1157 screen.cur.row += dirn;
1201 1158
1202 MAX_IT (screen.cur.row, 0); 1159 clamp_it (screen.cur.row, 0, nrow - 1);
1203 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
1204 selection_check (0); 1160 selection_check (0);
1205} 1161}
1206 1162
1207/* ------------------------------------------------------------------------- */ 1163/* ------------------------------------------------------------------------- */
1208/* 1164/*
1212 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1168 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1213 */ 1169 */
1214void 1170void
1215rxvt_term::scr_erase_line (int mode) 1171rxvt_term::scr_erase_line (int mode)
1216{ 1172{
1217 unsigned int row, col, num; 1173 unsigned int col, num;
1218 1174
1219 want_refresh = 1; 1175 want_refresh = 1;
1220 ZERO_SCROLLBACK (); 1176 ZERO_SCROLLBACK ();
1221 1177
1222 selection_check (1); 1178 selection_check (1);
1223 1179
1224 row = screen.cur.row; 1180 line_t &line = ROW(screen.cur.row);
1225 1181
1226 switch (mode) 1182 switch (mode)
1227 { 1183 {
1228 case 0: /* erase to end of line */ 1184 case 0: /* erase to end of line */
1229 col = screen.cur.col; 1185 col = screen.cur.col;
1230 num = ncol - col; 1186 num = ncol - col;
1231 MIN_IT (ROW(row).l, (int16_t)col); 1187 min_it (line.l, col);
1232 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1188 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1233 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1189 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1234 CLEAR_SELECTION (); 1190 CLEAR_SELECTION ();
1235 break; 1191 break;
1236 case 1: /* erase to beginning of line */ 1192 case 1: /* erase to beginning of line */
1241 CLEAR_SELECTION (); 1197 CLEAR_SELECTION ();
1242 break; 1198 break;
1243 case 2: /* erase whole line */ 1199 case 2: /* erase whole line */
1244 col = 0; 1200 col = 0;
1245 num = ncol; 1201 num = ncol;
1246 ROW(row).l = 0; 1202 line.l = 0;
1247 if (selection.beg.row <= screen.cur.row 1203 if (selection.beg.row <= screen.cur.row
1248 && selection.end.row >= screen.cur.row) 1204 && selection.end.row >= screen.cur.row)
1249 CLEAR_SELECTION (); 1205 CLEAR_SELECTION ();
1250 break; 1206 break;
1251 default: 1207 default:
1252 return; 1208 return;
1253 } 1209 }
1254 1210
1255 scr_blank_line (ROW(row), col, num, rstyle); 1211 scr_blank_line (line, col, num, rstyle);
1256} 1212}
1257 1213
1258/* ------------------------------------------------------------------------- */ 1214/* ------------------------------------------------------------------------- */
1259/* 1215/*
1260 * Erase part of whole of the screen 1216 * Erase part of whole of the screen
1303 CLEAR_SELECTION (); 1259 CLEAR_SELECTION ();
1304 1260
1305 if (row >= nrow) /* Out Of Bounds */ 1261 if (row >= nrow) /* Out Of Bounds */
1306 return; 1262 return;
1307 1263
1308 MIN_IT (num, (nrow - row)); 1264 min_it (num, nrow - row);
1309 1265
1310 if (rstyle & (RS_RVid | RS_Uline)) 1266 if (rstyle & (RS_RVid | RS_Uline))
1311 ren = (rend_t) ~RS_None; 1267 ren = (rend_t) ~RS_None;
1312 else if (GET_BASEBG (rstyle) == Color_bg) 1268 else if (GET_BASEBG (rstyle) == Color_bg)
1313 { 1269 {
1326 1282
1327 for (; num--; row++) 1283 for (; num--; row++)
1328 { 1284 {
1329 scr_blank_screen_mem (ROW (row), rstyle); 1285 scr_blank_screen_mem (ROW (row), rstyle);
1330 ROW (row).l = 0; 1286 ROW (row).l = 0;
1331 scr_blank_line (drawn[row], 0, ncol, ren); 1287 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1332 } 1288 }
1333} 1289}
1334 1290
1335#if ENABLE_FRILLS 1291#if ENABLE_FRILLS
1336void 1292void
1421 return; 1377 return;
1422 1378
1423 scr_do_wrap (); 1379 scr_do_wrap ();
1424 1380
1425 selection_check (1); 1381 selection_check (1);
1426 MIN_IT (count, (ncol - screen.cur.col)); 1382 min_it (count, ncol - screen.cur.col);
1427 1383
1428 row = screen.cur.row; 1384 row = screen.cur.row;
1429 1385
1430 line_t *line = &ROW(row); 1386 line_t *line = &ROW(row);
1431 1387
1439 } 1395 }
1440 1396
1441 if (!line->is_longer ()) 1397 if (!line->is_longer ())
1442 { 1398 {
1443 line->l += count; 1399 line->l += count;
1444 MIN_IT (line->l, ncol); 1400 min_it (line->l, ncol);
1445 } 1401 }
1446 1402
1447 if (selection.op && current_screen == selection.screen 1403 if (selection.op && current_screen == selection.screen
1448 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1404 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1449 { 1405 {
1510 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r 1466 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r
1511 */ 1467 */
1512void 1468void
1513rxvt_term::scr_scroll_region (int top, int bot) 1469rxvt_term::scr_scroll_region (int top, int bot)
1514{ 1470{
1515 MAX_IT (top, 0); 1471 max_it (top, 0);
1516 MIN_IT (bot, (int)nrow - 1); 1472 min_it (bot, nrow - 1);
1517 1473
1518 if (top > bot) 1474 if (top > bot)
1519 return; 1475 return;
1520 1476
1521 screen.tscroll = top; 1477 screen.tscroll = top;
1619 XGCValues gcvalue; 1575 XGCValues gcvalue;
1620 1576
1621 if (rvideo != mode) 1577 if (rvideo != mode)
1622 { 1578 {
1623 rvideo = mode; 1579 rvideo = mode;
1624 SWAP_IT (pix_colors[Color_fg], pix_colors[Color_bg], rxvt_color); 1580 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1625#if XPM_BACKGROUND 1581#if XPM_BACKGROUND
1626 if (bgPixmap.pixmap == None) 1582 if (bgPixmap.pixmap == None)
1627#endif 1583#endif
1628#if TRANSPARENT 1584#if TRANSPARENT
1629 if (! (options & Opt_transparent) || am_transparent == 0) 1585 if (! (options & Opt_transparent) || am_transparent == 0)
1725 bool found = false; 1681 bool found = false;
1726 1682
1727 for (int i = 0; i < nrow; i++) 1683 for (int i = 0; i < nrow; i++)
1728 { 1684 {
1729 int col = 0; 1685 int col = 0;
1730 rend_t *drp = drawn[i].r; 1686 rend_t *drp = drawn_buf[i].r;
1731 1687
1732 for (; col < ncol; col++, drp++) 1688 for (; col < ncol; col++, drp++)
1733 if ((*drp & mask) == value) 1689 if ((*drp & mask) == value)
1734 { 1690 {
1735 found = true; 1691 found = true;
1753rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) 1709rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh)
1754{ 1710{
1755 int i; 1711 int i;
1756 row_col_t rc[RC_COUNT]; 1712 row_col_t rc[RC_COUNT];
1757 1713
1758 if (!drawn) /* sanity check */ 1714 if (!drawn_buf) /* sanity check */
1759 return; 1715 return;
1760 1716
1761#ifndef NO_SLOW_LINK_SUPPORT 1717#ifndef NO_SLOW_LINK_SUPPORT
1762 if (refresh_type == FAST_REFRESH && !display->is_local) 1718 if (refresh_type == FAST_REFRESH && !display->is_local)
1763 { 1719 {
1764 y = 0; 1720 y = 0;
1765 eheight = height; 1721 eheight = height;
1766 } 1722 }
1767#endif
1768
1769#ifdef DEBUG_STRICT
1770 x = max (x, 0);
1771 x = min (x, (int)width);
1772 y = max (y, 0);
1773 y = min (y, (int)height);
1774#endif 1723#endif
1775 1724
1776 /* round down */ 1725 /* round down */
1777 rc[PART_BEG].col = Pixel2Col (x); 1726 rc[PART_BEG].col = Pixel2Col (x);
1778 rc[PART_BEG].row = Pixel2Row (y); 1727 rc[PART_BEG].row = Pixel2Row (y);
1781 rc[PART_END].row = Pixel2Row (y + eheight + fheight - 1); 1730 rc[PART_END].row = Pixel2Row (y + eheight + fheight - 1);
1782 1731
1783 /* sanity checks */ 1732 /* sanity checks */
1784 for (i = PART_BEG; i < RC_COUNT; i++) 1733 for (i = PART_BEG; i < RC_COUNT; i++)
1785 { 1734 {
1786 MIN_IT (rc[i].col, ncol - 1); 1735 min_it (rc[i].col, ncol - 1);
1787 MIN_IT (rc[i].row, nrow - 1); 1736 min_it (rc[i].row, nrow - 1);
1788 } 1737 }
1789 1738
1790 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1739 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1791 fill_text (&drawn[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); 1740 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1);
1792 1741
1793 if (refresh) 1742 if (refresh)
1794 scr_refresh (SLOW_REFRESH); 1743 scr_refresh (SLOW_REFRESH);
1795} 1744}
1796 1745
1959{ 1908{
1960 unsigned char must_clear, /* use draw_string not draw_image_string */ 1909 unsigned char must_clear, /* use draw_string not draw_image_string */
1961 showcursor; /* show the cursor */ 1910 showcursor; /* show the cursor */
1962 int16_t col, row, /* column/row we're processing */ 1911 int16_t col, row, /* column/row we're processing */
1963 ocrow; /* old cursor row */ 1912 ocrow; /* old cursor row */
1964 int i, /* tmp */ 1913 int i; /* tmp */
1965 row_offset; /* basic offset in screen structure */
1966#ifndef NO_CURSORCOLOR 1914#ifndef NO_CURSORCOLOR
1967 rend_t cc1; /* store colours at cursor position (s) */ 1915 rend_t cc1; /* store colours at cursor position (s) */
1968#endif 1916#endif
1969 rend_t *crp; // cursor rendition pointer 1917 rend_t *crp; // cursor rendition pointer
1970 1918
1976 /* 1924 /*
1977 * A: set up vars 1925 * A: set up vars
1978 */ 1926 */
1979 must_clear = 0; 1927 must_clear = 0;
1980 refresh_count = 0; 1928 refresh_count = 0;
1981
1982 row_offset = term_start - view_start;
1983 1929
1984#if XPM_BACKGROUND 1930#if XPM_BACKGROUND
1985 must_clear |= bgPixmap.pixmap != None; 1931 must_clear |= bgPixmap.pixmap != None;
1986#endif 1932#endif
1987#if TRANSPARENT 1933#if TRANSPARENT
2057 if (screen.cur.row + view_start != ocrow 2003 if (screen.cur.row + view_start != ocrow
2058 || screen.cur.col != oldcursor.col) 2004 || screen.cur.col != oldcursor.col)
2059 { 2005 {
2060 if (ocrow < nrow 2006 if (ocrow < nrow
2061 && oldcursor.col < ncol) 2007 && oldcursor.col < ncol)
2062 drawn[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); 2008 drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline);
2063 2009
2064 if (focus || !showcursor) 2010 if (focus || !showcursor)
2065 oldcursor.row = -1; 2011 oldcursor.row = -1;
2066 else 2012 else
2067 setoldcursor = 1; 2013 setoldcursor = 1;
2105 row = i > 0 ? 0 : j - 1; 2051 row = i > 0 ? 0 : j - 1;
2106 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2052 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2107 { 2053 {
2108 if (row + i >= 0 && row + i < nrow && row + i != ocrow) 2054 if (row + i >= 0 && row + i < nrow && row + i != ocrow)
2109 { 2055 {
2110 line_t s = save[(row + row_offset) % total_rows]; 2056 line_t s = ROW(row - view_start);
2111 line_t d = drawn[row]; 2057 line_t d = drawn_buf[row];
2112 line_t d2 = drawn[row + i]; 2058 line_t d2 = drawn_buf[row + i];
2113 2059
2114 for (nits = 0, col = ncol; col--; ) 2060 for (nits = 0, col = ncol; col--; )
2115 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col]) 2061 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col])
2116 nits--; 2062 nits--;
2117 else if (s.t[col] != d.t[col] || s.r[col] != d.r[col]) 2063 else if (s.t[col] != d.t[col] || s.r[col] != d.r[col])
2135 2081
2136 if (len != -1) 2082 if (len != -1)
2137 { 2083 {
2138 /* also comes here at end if needed because of >= above */ 2084 /* also comes here at end if needed because of >= above */
2139 if (wlen < len) 2085 if (wlen < len)
2140 SWAP_IT (wlen, len, int); 2086 ::swap (wlen, len);
2141 2087
2142 XCopyArea (display->display, vt, vt, 2088 XCopyArea (display->display, vt, vt,
2143 gc, 0, Row2Pixel (len + i), 2089 gc, 0, Row2Pixel (len + i),
2144 (unsigned int)TermWin_TotalWidth (), 2090 (unsigned int)TermWin_TotalWidth (),
2145 (unsigned int)Height2Pixel (wlen - len + 1), 2091 (unsigned int)Height2Pixel (wlen - len + 1),
2153 /* 2099 /*
2154 * E: main pass across every character 2100 * E: main pass across every character
2155 */ 2101 */
2156 for (row = 0; row < nrow; row++) 2102 for (row = 0; row < nrow; row++)
2157 { 2103 {
2158 text_t *stp = save[(row + row_offset) % total_rows].t; 2104 text_t *stp = ROW(row - view_start).t;
2159 rend_t *srp = save[(row + row_offset) % total_rows].r; 2105 rend_t *srp = ROW(row - view_start).r;
2160 text_t *dtp = drawn[row].t; 2106 text_t *dtp = drawn_buf[row].t;
2161 rend_t *drp = drawn[row].r; 2107 rend_t *drp = drawn_buf[row].r;
2162 2108
2163 /* 2109 /*
2164 * E2: OK, now the real pass 2110 * E2: OK, now the real pass
2165 */ 2111 */
2166 int ypixel = (int)Row2Pixel (row); 2112 int ypixel = (int)Row2Pixel (row);
2277 fore = Color_UL; 2223 fore = Color_UL;
2278#endif 2224#endif
2279 2225
2280 if (invert) 2226 if (invert)
2281 { 2227 {
2282 SWAP_IT (fore, back, int); 2228 ::swap (fore, back);
2283 2229
2284#ifndef NO_BOLD_UNDERLINE_REVERSE 2230#ifndef NO_BOLD_UNDERLINE_REVERSE
2285 if (ISSET_PIXCOLOR (Color_RV)) 2231 if (ISSET_PIXCOLOR (Color_RV))
2286 back = Color_RV; 2232 back = Color_RV;
2287 2233
2379 2325
2380 while (col && ROW(screen.cur.row).t[col] == NOCHAR) 2326 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
2381 col--; 2327 col--;
2382 2328
2383 while (col + cursorwidth < ncol 2329 while (col + cursorwidth < ncol
2384 && drawn[oldcursor.row].t[col + cursorwidth] == NOCHAR) 2330 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2385 cursorwidth++; 2331 cursorwidth++;
2386 2332
2387#ifndef NO_CURSORCOLOR 2333#ifndef NO_CURSORCOLOR
2388 if (ISSET_PIXCOLOR (Color_cursor)) 2334 if (ISSET_PIXCOLOR (Color_cursor))
2389 XSetForeground (display->display, gc, pix_colors[Color_cursor]); 2335 XSetForeground (display->display, gc, pix_colors[Color_cursor]);
2421 2367
2422void 2368void
2423rxvt_term::scr_remap_chars () 2369rxvt_term::scr_remap_chars ()
2424{ 2370{
2425 for (int i = total_rows; i--; ) 2371 for (int i = total_rows; i--; )
2426 scr_remap_chars (save[i]); 2372 scr_remap_chars (row_buf [i]);
2427 2373
2428 for (int i = nrow; i--; ) 2374 for (int i = nrow; i--; )
2429 { 2375 {
2430 scr_remap_chars (drawn[i]); 2376 scr_remap_chars (drawn_buf [i]);
2431 scr_remap_chars (swap_save[i]); 2377 scr_remap_chars (swap_buf [i]);
2432 } 2378 }
2433} 2379}
2434 2380
2435void 2381void
2436rxvt_term::scr_recolour () 2382rxvt_term::scr_recolour ()
2533 char r1[] = "\n"; 2479 char r1[] = "\n";
2534 2480
2535 for (row = saveLines - nsaved; 2481 for (row = saveLines - nsaved;
2536 row < saveLines + nrow - 1; row++) 2482 row < saveLines + nrow - 1; row++)
2537 { 2483 {
2538 width = save[row].l >= 0 ? save[row].l 2484 width = row_buf[row].l >= 0 ? row_buf[row].l
2539 : ncol; 2485 : ncol;
2540 for (towrite = width; towrite; towrite -= wrote) 2486 for (towrite = width; towrite; towrite -= wrote)
2541 { 2487 {
2542 wrote = write (fd, & (save[row].t[width - towrite]), 2488 wrote = write (fd, & (row_buf[row].t[width - towrite]),
2543 towrite); 2489 towrite);
2544 if (wrote < 0) 2490 if (wrote < 0)
2545 return; /* XXX: death, no report */ 2491 return; /* XXX: death, no report */
2546 } 2492 }
2547 if (save[row].l >= 0) 2493 if (row_buf[row].l >= 0)
2548 if (write (fd, r1, 1) <= 0) 2494 if (write (fd, r1, 1) <= 0)
2549 return; /* XXX: death, no report */ 2495 return; /* XXX: death, no report */
2550 } 2496 }
2551} 2497}
2552#endif 2498#endif
3029 want_refresh = 1; 2975 want_refresh = 1;
3030 2976
3031 selection.mark.row = row - view_start; 2977 selection.mark.row = row - view_start;
3032 selection.mark.col = col; 2978 selection.mark.col = col;
3033 2979
3034 selection.mark.row = min (max (selection.mark.row, -nsaved), nrow - 1); 2980 selection.mark.row = clamp (selection.mark.row, -nsaved, nrow - 1);
3035 selection.mark.col = min (max (selection.mark.col, 0), ncol - 1); 2981 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1);
3036 2982
3037 while (selection.mark.col > 0 2983 while (selection.mark.col > 0
3038 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) 2984 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3039 --selection.mark.col; 2985 --selection.mark.col;
3040 2986
3145 * flag == 2 ==> button 3 motion 3091 * flag == 2 ==> button 3 motion
3146 */ 3092 */
3147void 3093void
3148rxvt_term::selection_extend (int x, int y, int flag) 3094rxvt_term::selection_extend (int x, int y, int flag)
3149{ 3095{
3150 int col = min (max (Pixel2Col (x), 0), nrow - 1); 3096 int col = clamp (Pixel2Col (x), 0, ncol);
3151 int row = min (max (Pixel2Row (y), 0), ncol); 3097 int row = clamp (Pixel2Row (y), 0, nrow - 1);
3152 3098
3153 /* 3099 /*
3154 * If we're selecting characters (single click) then we must check first 3100 * If we're selecting characters (single click) then we must check first
3155 * if we are at the same place as the original mark. If we are then 3101 * if we are at the same place as the original mark. If we are then
3156 * select nothing. Otherwise, if we're to the right of the mark, you have to 3102 * select nothing. Otherwise, if we're to the right of the mark, you have to
3369 } 3315 }
3370 } 3316 }
3371 3317
3372#if ENABLE_FRILLS 3318#if ENABLE_FRILLS
3373 if (selection.rect && selection.beg.col > selection.end.col) 3319 if (selection.rect && selection.beg.col > selection.end.col)
3374 SWAP_IT (selection.beg.col, selection.end.col, int); 3320 ::swap (selection.beg.col, selection.end.col);
3375#endif 3321#endif
3376} 3322}
3377 3323
3378#if ENABLE_FRILLS 3324#if ENABLE_FRILLS
3379void 3325void
3577 */ 3523 */
3578void 3524void
3579rxvt_term::pixel_position (int *x, int *y) 3525rxvt_term::pixel_position (int *x, int *y)
3580{ 3526{
3581 *x = Pixel2Col (*x); 3527 *x = Pixel2Col (*x);
3582 /* MAX_IT (*x, 0); MIN_IT (*x, (int)ncol - 1); */ 3528 /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */
3583 *y = Pixel2Row (*y); 3529 *y = Pixel2Row (*y);
3584 /* MAX_IT (*y, 0); MIN_IT (*y, (int)nrow - 1); */ 3530 /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */
3585} 3531}
3586 3532
3587/* ------------------------------------------------------------------------- */ 3533/* ------------------------------------------------------------------------- */
3588#ifdef USE_XIM 3534#ifdef USE_XIM
3589void 3535void
3611 3557
3612 if (x < 0) x = ncol - w; 3558 if (x < 0) x = ncol - w;
3613 if (y < 0) y = nrow - h; 3559 if (y < 0) y = nrow - h;
3614 3560
3615 // make space for border 3561 // make space for border
3616 w += 2; MIN_IT (w, ncol); 3562 w += 2; min_it (w, ncol);
3617 h += 2; MIN_IT (h, nrow); 3563 h += 2; min_it (h, nrow);
3618 3564
3619 x -= 1; MAX_IT (x, 0); 3565 x -= 1; clamp_it (x, 0, ncol - w);
3620 y -= 1; MAX_IT (y, 0); 3566 y -= 1; clamp_it (y, 0, nrow - h);
3621
3622 MIN_IT (x, ncol - w);
3623 MIN_IT (y, nrow - h);
3624 3567
3625 ov_x = x; ov_y = y; 3568 ov_x = x; ov_y = y;
3626 ov_w = w; ov_h = h; 3569 ov_w = w; ov_h = h;
3627 3570
3628 ov_text = new text_t *[h]; 3571 ov_text = new text_t *[h];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines