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.179 by root, Tue Dec 20 22:47:14 2005 UTC vs.
Revision 1.196 by root, Mon Dec 26 23:12:59 2005 UTC

147} 147}
148 148
149/* ------------------------------------------------------------------------- * 149/* ------------------------------------------------------------------------- *
150 * SCREEN INITIALISATION * 150 * SCREEN INITIALISATION *
151 * ------------------------------------------------------------------------- */ 151 * ------------------------------------------------------------------------- */
152
152void 153void
153rxvt_term::scr_reset () 154rxvt_term::scr_reset ()
154{ 155{
155 unsigned int p, q;
156 int k;
157
158#if ENABLE_OVERLAY 156#if ENABLE_OVERLAY
159 scr_overlay_off (); 157 scr_overlay_off ();
160#endif 158#endif
161 159
162 view_start = 0; 160 view_start = 0;
172 return; 170 return;
173 171
174 // we need at least two lines for wrapping to work correctly 172 // we need at least two lines for wrapping to work correctly
175 if (nrow + saveLines < 2) 173 if (nrow + saveLines < 2)
176 { 174 {
175 //TODO//FIXME
177 saveLines++; 176 saveLines++;
178 prev_nrow--; 177 prev_nrow--;
179 nsaved++; 178 nsaved++;
180 } 179 }
181 180
185 total_rows = nrow + saveLines; 184 total_rows = nrow + saveLines;
186 185
187 screen.tscroll = 0; 186 screen.tscroll = 0;
188 screen.bscroll = nrow - 1; 187 screen.bscroll = nrow - 1;
189 188
190 if (!save) 189 if (!row_buf)
191 { 190 {
192 /* 191 /*
193 * 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
194 * 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
195 */ 194 */
197 term_start = 0; 196 term_start = 0;
198 197
199 talloc = new rxvt_salloc (ncol * sizeof (text_t)); 198 talloc = new rxvt_salloc (ncol * sizeof (text_t));
200 ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 199 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
201 200
202 save = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
203 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));
204 drawn = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); 203 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
205 swap_save = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); 204 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
206 205
207 for (p = nrow; p--; ) 206 for (int row = nrow; row--; )
208 { 207 {
209 scr_blank_screen_mem (ROW(p), DEFAULT_RSTYLE); 208 scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE);
210 scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); 209 scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
211 scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE); 210 scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
212 } 211 }
213 212
214 memset (charsets, 'B', sizeof (charsets)); 213 memset (charsets, 'B', sizeof (charsets));
215 rstyle = DEFAULT_RSTYLE; 214 rstyle = DEFAULT_RSTYLE;
216 screen.flags = Screen_DefaultFlags; 215 screen.flags = Screen_DefaultFlags;
240 { 239 {
241 /* 240 /*
242 * add or delete rows as appropriate 241 * add or delete rows as appropriate
243 */ 242 */
244 243
245 rxvt_salloc *old_ta; 244 rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t));
246 rxvt_salloc *old_ra; 245 rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
247 246
247#if 0
248 if (nrow < prev_nrow) 248 if (nrow < prev_nrow)
249 { 249 {
250 /* delete rows */
251 k = min (nsaved, prev_nrow - nrow);
252 // k = max (0, - ( (nrow - 1) - r->screen.cur.row)); // mmc's http://maruska.dyndns.org/wiki/scrolling-bug //make configurable? //D TODO
253 scr_scroll_text (0, (int)prev_nrow - 1, k);
254
255 for (p = nrow; p < prev_nrow; p++) 250 for (int row = nrow; row < prev_nrow; row++)
256 { 251 {
257 lfree (ROW(p));
258 lfree (swap_save[p]); 252 lfree (swap_buf [row]);
259 lfree (drawn[p]); 253 lfree (drawn_buf[row]);
260 } 254 }
255 }
256#endif
261 257
262 /* we have fewer rows so fix up cursor position */ 258 drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t));
263 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));
264 261
265 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));
266 } 275
267 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
268 { 288 do
269 /* add rows */
270 scr_reset_realloc (); /* realloc _first_ */
271
272 int ocol = ncol;
273 ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this
274
275 k = min (nsaved, nrow - prev_nrow);
276
277 for (p = prev_total_rows; p < total_rows; p++)
278 save[p].clear ();
279
280 for (p = prev_total_rows; p < total_rows - k; p++)
281 scr_blank_screen_mem (save[p], DEFAULT_RSTYLE);
282
283 for (p = prev_nrow; p < nrow; p++)
284 { 289 {
285 swap_save[p].clear (); scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); 290 p = MOD (p - 1, prev_total_rows);
286 drawn[p].clear (); scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE);
287 }
288
289 if (k > 0)
290 {
291 scr_scroll_text (0, (int)nrow - 1, -k);
292 screen.cur.row += k;
293 screen.s_cur.row += k;
294 nsaved -= k;
295 }
296
297#ifdef DEBUG_STRICT 291#ifdef DEBUG_STRICT
298 assert (screen.cur.row < nrow); 292 assert (old_buf [MOD (p, prev_total_rows)].t);
299#else /* drive with your eyes closed */
300 MIN_IT (screen.cur.row, nrow - 1);
301#endif 293#endif
302 ncol = ocol; // save b/c scr_blank_screen_mem uses this
303 }
304 294
305 /* resize columns */
306 if (ncol != prev_ncol)
307 {
308 old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t));
309 old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
310
311 for (p = total_rows; p--; )
312 lresize (save[p]);
313
314 for (p = nrow; p--; )
315 {
316 lresize (drawn[p]);
317 lresize (swap_save[p]);
318 }
319
320 MIN_IT (screen.cur.col, (int16_t)ncol - 1);
321
322 delete old_ta;
323 delete old_ra;
324 }
325
326#if 0
327 // re-wrap lines, this is rather ugly, possibly because I am too dumb
328 // to come up with a lean and mean algorithm.
329 rxvt_salloc *ta = new rxvt_salloc (ncol * sizeof (text_t));
330 rxvt_salloc *ra = new rxvt_salloc (ncol * sizeof (rend_t));
331
332 text_t **tp = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *));
333 rend_t **rp = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *));
334 tlen_t *tl = (tlen_t *) rxvt_calloc (total_rows, sizeof (tlen_t));
335
336 for (p = 0; p < prev_total_rows; p++) printf ("P %p %d\n", save[p].t, save[p].l);//D
337
338 p = prev_total_rows;
339 q = total_rows;
340
341 while (p > 0 && q > 0)
342 {
343 --p;
344
345 printf ("pq %d:%d\n", p, q);
346 if (save[p].t)
347 {
348 int llen = save[p].l; 295 int plines = 1;
296 int llen = old_buf [MOD (p, prev_total_rows)].l;
349 297
350 assert (llen >= 0); 298 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
351
352 while (p && save[p - 1].l < 0)
353 { 299 {
300 p = MOD (p - 1, prev_total_rows);
301
354 --p; 302 plines++;
355 llen += prev_ncol; 303 llen += prev_ncol;
356 } 304 }
357 305
358 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
359 int lofs = 0; 314 int lofs = 0;
315 line_t *qline;
360 316
361 q -= qlines; 317 // re-assemble the full line by destination lines
362
363 int qrow = q;
364
365 printf ("QL %d llen %d\n", qlines, llen);//D
366 for (; qlines--; qrow++) 318 for (int qrow = q; qlines--; qrow++)
367 { 319 {
320 qline = row_buf + qrow;
321 lalloc (*qline);
322 qline->set_is_longer ();
323
368 if (qrow >= 0) 324 int qcol = 0;
325
326 // fill a single destination line
327 while (lofs < llen && qcol < ncol)
369 { 328 {
370 tp [qrow] = (text_t *)ta->alloc ();
371 rp [qrow] = (rend_t *)ra->alloc ();
372 tl [qrow] = LINE_CONT1;
373
374 int qcol = 0;
375
376 for (;;)
377 {
378 int prow = lofs / prev_ncol + p; 329 int prow = lofs / prev_ncol;
379 int pcol = lofs % prev_ncol; 330 int pcol = lofs % prev_ncol;
380 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
381 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 343 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
382 344
383 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);
384
385 if (len <= 0)
386 {
387 tl [qrow] = qcol;
388
389 TODO
390 scr_blank_line (tp [qrow] + qcol, rp [qrow] + qcol,
391 ncol - qcol, DEFAULT_RSTYLE);
392
393 break;
394 }
395
396 assert (lofs < 1000); 345 assert (len);
346 assert (pline.t);
397 347
398 memcpy (tp [qrow] + qcol, save[prow].t + pcol, len * sizeof (text_t)); 348 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
399 memcpy (rp [qrow] + qcol, save[prow].r + pcol, len * sizeof (rend_t)); 349 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
400 350
401 lofs += len; 351 lofs += len;
402 qcol += len; 352 qcol += len;
403
404 if (qcol == ncol)
405 break;
406 }
407 } 353 }
408 else
409 lofs += ncol;
410 } 354 }
355
356 qline->l = llen ? MOD (llen - 1, ncol) + 1 : 0;
357#ifdef DEBUG_STRICT //TODO//FIXME//TEMPORARY
358 if (qline->l < 0)
359 {
360 fprintf (stderr, "ERROR, PLEASE REPORT to rxvt-unicode@plan9.de: qline->l %d = llen %d < ncol %d ? %d : MOD %d\n", qline->l,llen,ncol,llen,MOD (llen - 1, ncol) + 1);//D
361 qline->l = 0;
362 }
363#endif
364 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
411 } 365 }
366 while (p != pend && q > 0);
367
368 term_start = total_rows - nrow;
369 nsaved = term_start - q;
370
371 // make sure all terminal lines exist
372 while (nsaved < 0)
373 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
374
375 }
376 else
412 } 377 {
378 // if no scrollback exists (yet), wing, instead of wrap
379
380 for (int row = min (nrow, prev_nrow); row--; )
381 {
382 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
383 line_t &qline = row_buf [row];
413 384
414 free (screen.text); screen.text = tp; 385 qline = pline;
415 free (screen.rend); screen.rend = rp; 386 lresize (qline);
416 free (screen.tlen); screen.tlen = tl; 387 }
417 388
418 for (p = 0; p < total_rows; p++) printf ("P %p %d\n", save[p].t, save[p].l);//D 389 for (int row = prev_nrow; row < nrow; row++)
390 {
391 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
392 }
393
394 term_start = 0;
395 }
396
397#ifdef DEBUG_STRICT //TODO: remove
398 for (int i = -nsaved; i < nrow; i++)
399 assert (ROW (i).t);
419#endif 400#endif
401
402 free (old_buf);
403 delete old_ta;
404 delete old_ra;
405
406 clamp_it (screen.cur.row, 0, nrow - 1);
407 clamp_it (screen.cur.col, 0, ncol - 1);
420 408
421 if (tabs) 409 if (tabs)
422 free (tabs); 410 free (tabs);
423 } 411 }
424 412
425 prev_nrow = nrow; 413 prev_nrow = nrow;
426 prev_ncol = ncol; 414 prev_ncol = ncol;
427 415
428 tabs = (char *)rxvt_malloc (ncol * sizeof (char)); 416 tabs = (char *)rxvt_malloc (ncol * sizeof (char));
429 417
430 for (p = 0; p < ncol; p++) 418 for (int col = ncol; col--; )
431 tabs[p] = (p % TABSIZE == 0) ? 1 : 0; 419 tabs [col] = col % TABSIZE == 0;
432 420
433 tt_winch (); 421 tt_winch ();
434}
435
436void
437rxvt_term::scr_reset_realloc ()
438{
439 swap_save = (line_t *) rxvt_realloc (swap_save , nrow * sizeof (line_t));
440 drawn = (line_t *) rxvt_realloc (drawn , nrow * sizeof (line_t));
441 buf = (line_t *) rxvt_realloc (buf , nrow * sizeof (line_t));
442 save = (line_t *) rxvt_realloc (save , total_rows * sizeof (line_t));
443} 422}
444 423
445/* ------------------------------------------------------------------------- */ 424/* ------------------------------------------------------------------------- */
446/* 425/*
447 * Free everything. That way malloc debugging can find leakage. 426 * Free everything. That way malloc debugging can find leakage.
450rxvt_term::scr_release () 429rxvt_term::scr_release ()
451{ 430{
452 delete talloc; talloc = 0; 431 delete talloc; talloc = 0;
453 delete ralloc; ralloc = 0; 432 delete ralloc; ralloc = 0;
454 433
455 free (save); 434 free (row_buf);
456 free (swap_save); 435 free (swap_buf);
457 free (drawn); 436 free (drawn_buf);
458 free (buf); 437 free (temp_buf);
459 free (tabs); 438 free (tabs);
439
440 row_buf = 0; // signal that we freed all the arrays
460} 441}
461 442
462/* ------------------------------------------------------------------------- */ 443/* ------------------------------------------------------------------------- */
463/* 444/*
464 * Hard reset 445 * Hard reset
515 set_font_style (); 496 set_font_style ();
516 break; 497 break;
517 } 498 }
518 499
519 /* boundary check in case screen size changed between SAVE and RESTORE */ 500 /* boundary check in case screen size changed between SAVE and RESTORE */
520 MIN_IT (s->cur.row, nrow - 1); 501 min_it (s->cur.row, nrow - 1);
521 MIN_IT (s->cur.col, ncol - 1); 502 min_it (s->cur.col, ncol - 1);
522#ifdef DEBUG_STRICT 503#ifdef DEBUG_STRICT
523 assert (s->cur.row >= 0); 504 assert (s->cur.row >= 0);
524 assert (s->cur.col >= 0); 505 assert (s->cur.col >= 0);
525#else /* drive with your eyes closed */
526 MAX_IT (s->cur.row, 0);
527 MAX_IT (s->cur.col, 0);
528#endif 506#endif
529} 507}
530 508
531/* ------------------------------------------------------------------------- */ 509/* ------------------------------------------------------------------------- */
532/* 510/*
543 if (current_screen == scrn) 521 if (current_screen == scrn)
544 return scrn; 522 return scrn;
545 523
546 selection_check (2); /* check for boundary cross */ 524 selection_check (2); /* check for boundary cross */
547 525
548 SWAP_IT (scrn, current_screen, int); 526 int i = current_screen; current_screen = scrn; scrn = i;
549 527
550 SWAP_IT (screen.cur.row, swap.cur.row, int16_t); 528 ::swap (screen.cur.row, swap.cur.row);
551 SWAP_IT (screen.cur.col, swap.cur.col, int16_t); 529 ::swap (screen.cur.col, swap.cur.col);
552 MAX_IT (screen.cur.row, 0); 530
553 MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); 531 screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1);
554 MAX_IT (screen.cur.col, 0); 532 screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1);
555 MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1);
556 533
557#if NSCREENS 534#if NSCREENS
558 if (options & Opt_secondaryScreen) 535 if (options & Opt_secondaryScreen)
559 { 536 {
560 num_scr = 0; 537 num_scr = 0;
561 538
562 for (int i = nrow; i--; ) 539 for (int i = prev_nrow; i--; )
563 SWAP_IT (ROW(i), swap_save[i], line_t); 540 ::swap (ROW(i), swap_buf [i]);
564 541
565 SWAP_IT (screen.charset, swap.charset, int16_t); 542 ::swap (screen.charset, swap.charset);
566 SWAP_IT (screen.flags, swap.flags, int); 543 ::swap (screen.flags, swap.flags);
567 screen.flags |= Screen_VisibleCursor; 544 screen.flags |= Screen_VisibleCursor;
568 swap.flags |= Screen_VisibleCursor; 545 swap.flags |= Screen_VisibleCursor;
569 } 546 }
570 else 547 else
571#endif 548#endif
650 { 627 {
651 selection.beg.row -= count; 628 selection.beg.row -= count;
652 selection.end.row -= count; 629 selection.end.row -= count;
653 selection.mark.row -= count; 630 selection.mark.row -= count;
654 631
655 selection_check (0); 632 if (selection.beg.row < -nsaved
633 || selection.end.row < -nsaved
634 || selection.mark.row < -nsaved)
635 {
636 CLEAR_ALL_SELECTION ();
637 selection.op = SELECTION_CLEAR;
638 }
656 } 639 }
657 640
658 for (int i = count; i--; ) 641 for (int i = count; i--; )
642 {
643 ROW(row2 - i).l = 0;
659 scr_blank_screen_mem (ROW(row2 - i), rstyle); 644 scr_blank_screen_mem (ROW(row2 - i), rstyle);
645 }
660 646
661 if ((options & Opt_scrollWithBuffer) 647 if ((options & Opt_scrollWithBuffer)
662 && view_start != 0 648 && view_start != 0
663 && view_start != saveLines) 649 && view_start != saveLines)
664 scr_page (UP, count); 650 scr_page (UP, count);
665 } 651 }
666 else 652 else
667 { 653 {
668 if (selection.op && current_screen == selection.screen) 654 if (selection.op && current_screen == selection.screen)
669 { 655 {
670 int i = selection.beg.row; 656 if ((selection.beg.row < row1 && selection.end.row > row1)
671 int j = selection.end.row; 657 || (selection.beg.row < row2 && selection.end.row > row2)
672
673 if ((i < row1 && j > row1)
674 || (i < row2 && j > row2)
675 || (i - count < row1 && i >= row1) 658 || (selection.beg.row - count < row1 && selection.beg.row >= row1)
676 || (i - count > row2 && i <= row2) 659 || (selection.beg.row - count > row2 && selection.beg.row <= row2)
677 || (j - count < row1 && j >= row1) 660 || (selection.end.row - count < row1 && selection.end.row >= row1)
678 || (j - count > row2 && j <= row2)) 661 || (selection.end.row - count > row2 && selection.end.row <= row2))
679 { 662 {
680 CLEAR_ALL_SELECTION (); 663 CLEAR_ALL_SELECTION ();
681 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ 664 selection.op = SELECTION_CLEAR;
682 } 665 }
683 else if (j >= row1 && j <= row2) 666 else if (selection.end.row >= row1 && selection.end.row <= row2)
684 { 667 {
685 /* move selected region too */ 668 /* move selected region too */
686 selection.beg.row -= count; 669 selection.beg.row -= count;
687 selection.end.row -= count; 670 selection.end.row -= count;
688 selection.mark.row -= count; 671 selection.mark.row -= count;
694 // use a simple and robust scrolling algorithm, this 677 // use a simple and robust scrolling algorithm, this
695 // part of scr_scroll_text is not time-critical. 678 // part of scr_scroll_text is not time-critical.
696 679
697 int rows = row2 - row1 + 1; 680 int rows = row2 - row1 + 1;
698 681
682 min_it (count, rows);
683
699 for (int row = 0; row < rows; row++) 684 for (int row = 0; row < rows; row++)
700 { 685 {
701 buf [row] = ROW(row1 + (row + count + rows) % rows); 686 temp_buf [row] = ROW(row1 + (row + count + rows) % rows);
702 687
703 if (!IN_RANGE_EXC (row + count, 0, rows)) 688 if (!IN_RANGE_EXC (row + count, 0, rows))
704 scr_blank_screen_mem (buf [row], rstyle); 689 scr_blank_screen_mem (temp_buf [row], rstyle);
705 } 690 }
706 691
707 for (int row = 0; row < rows; row++) 692 for (int row = 0; row < rows; row++)
708 ROW(row1 + row) = buf [row]; 693 ROW(row1 + row) = temp_buf [row];
709 } 694 }
710 695
711 return count; 696 return count;
712} 697}
713 698
721 if (len <= 0) /* sanity */ 706 if (len <= 0) /* sanity */
722 return; 707 return;
723 708
724 unsigned char checksel; 709 unsigned char checksel;
725 unicode_t c; 710 unicode_t c;
726 int row, last_col; 711 int last_col;
727 const unicode_t *strend = str + len; 712 const unicode_t *strend = str + len;
728 713
729 want_refresh = 1; 714 want_refresh = 1;
730 ZERO_SCROLLBACK (); 715 ZERO_SCROLLBACK ();
731 last_col = ncol; 716 last_col = ncol;
732 717
733 if (nlines > 0) 718 if (nlines > 0)
734 { 719 {
735 nlines += screen.cur.row - screen.bscroll; 720 nlines += screen.cur.row - screen.bscroll;
736 if ((nlines > 0) 721 if (nlines > 0
737 && (screen.tscroll == 0) 722 && screen.tscroll == 0
738 && (screen.bscroll == (nrow - 1))) 723 && screen.bscroll == (nrow - 1))
739 { 724 {
740 /* _at least_ this many lines need to be scrolled */ 725 /* _at least_ this many lines need to be scrolled */
741 scr_scroll_text (screen.tscroll, screen.bscroll, nlines); 726 scr_scroll_text (screen.tscroll, screen.bscroll, nlines);
742 screen.cur.row -= nlines; 727 screen.cur.row -= nlines;
743 } 728 }
744 } 729 }
745 730
746#ifdef DEBUG_STRICT 731#ifdef DEBUG_STRICT
747 assert (screen.cur.col < last_col); 732 assert (screen.cur.col < last_col);
748 assert ((screen.cur.row < nrow) 733 assert (screen.cur.row < nrow
749 && (screen.cur.row >= - (int32_t)nsaved)); 734 && screen.cur.row >= -nsaved);
750#else /* drive with your eyes closed */
751 MIN_IT (screen.cur.col, last_col - 1);
752 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
753 MAX_IT (screen.cur.row, - (int32_t)nsaved);
754#endif 735#endif
755 row = screen.cur.row; 736 int row = screen.cur.row;
756 737
757 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 738 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
758 739
759 line_t *line = &ROW(row); 740 line_t *line = &ROW(row);
760 741
762 { 743 {
763 c = *str++; 744 c = *str++;
764 745
765 if (c < 0x20) 746 if (c < 0x20)
766 if (c == C0_LF) 747 if (c == C0_LF)
767 { 748 {
768 if (!line->is_longer ()) /* XXX: think about this */ 749 if (!line->is_longer ()) /* XXX: think about this */
769 MAX_IT (line->l, screen.cur.col); 750 max_it (line->l, screen.cur.col);
770 751
771 screen.flags &= ~Screen_WrapNext; 752 screen.flags &= ~Screen_WrapNext;
772 753
773 if (screen.cur.row == screen.bscroll) 754 if (screen.cur.row == screen.bscroll)
774 scr_scroll_text (screen.tscroll, screen.bscroll, 1); 755 scr_scroll_text (screen.tscroll, screen.bscroll, 1);
779 continue; 760 continue;
780 } 761 }
781 else if (c == C0_CR) 762 else if (c == C0_CR)
782 { 763 {
783 if (!line->is_longer ()) /* XXX: think about this */ 764 if (!line->is_longer ()) /* XXX: think about this */
784 MAX_IT (line->l, screen.cur.col); 765 max_it (line->l, screen.cur.col);
785 766
786 screen.flags &= ~Screen_WrapNext; 767 screen.flags &= ~Screen_WrapNext;
787 screen.cur.col = 0; 768 screen.cur.col = 0;
788 continue; 769 continue;
789 } 770 }
965#endif 946#endif
966 } 947 }
967 } 948 }
968 949
969 if (!line->is_longer ()) /* XXX: think about this */ 950 if (!line->is_longer ()) /* XXX: think about this */
970 MAX_IT (line->l, screen.cur.col); 951 max_it (line->l, screen.cur.col);
971 952
972#ifdef DEBUG_STRICT 953#ifdef DEBUG_STRICT
973 assert (screen.cur.row >= 0); 954 assert (screen.cur.row >= 0);
974#else /* drive with your eyes closed */
975 MAX_IT (screen.cur.row, 0);
976#endif 955#endif
977} 956}
978 957
979/* ------------------------------------------------------------------------- */ 958/* ------------------------------------------------------------------------- */
980/* 959/*
1019 998
1020 if (count == 0) 999 if (count == 0)
1021 return; 1000 return;
1022 else if (count > 0) 1001 else if (count > 0)
1023 { 1002 {
1024 int row = screen.cur.row;
1025
1026 line_t &l = ROW(row); 1003 line_t &l = ROW(screen.cur.row);
1027 rend_t base_rend = l.r[i]; 1004 rend_t base_rend = l.r[i];
1028 ht &= l.t[i] == ' '; 1005 ht &= l.t[i] == ' ';
1029 1006
1030 for (; ++i < ncol; ) 1007 for (; ++i < ncol; )
1031 if (tabs[i]) 1008 if (tabs[i])
1046 if (ht && options & Opt_pastableTabs) 1023 if (ht && options & Opt_pastableTabs)
1047 { 1024 {
1048 base_rend = SET_FONT (base_rend, 0); 1025 base_rend = SET_FONT (base_rend, 0);
1049 1026
1050 if (!l.is_longer ()) /* XXX: think about this */ 1027 if (!l.is_longer ()) /* XXX: think about this */
1051 MAX_IT (l.l, x); 1028 max_it (l.l, x);
1052 1029
1053 i = screen.cur.col; 1030 i = screen.cur.col;
1054 1031
1055 l.t[i] = '\t'; 1032 l.t[i] = '\t';
1056 l.r[i] = base_rend; 1033 l.r[i] = base_rend;
1106 */ 1083 */
1107#if ENABLE_FRILLS 1084#if ENABLE_FRILLS
1108void 1085void
1109rxvt_term::scr_forwardindex () 1086rxvt_term::scr_forwardindex ()
1110{ 1087{
1111 int row;
1112
1113 if (screen.cur.col < ncol - 1) 1088 if (screen.cur.col < ncol - 1)
1114 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1089 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1115 else 1090 else
1116 { 1091 {
1117 row = screen.cur.row;
1118
1119 if (ROW(row).is_longer ()) //TODO//FIXME//LEN 1092 if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN
1120 ROW(row).l = ncol; 1093 ROW(screen.cur.row).l = ncol;
1121 1094
1122 scr_gotorc (0, 0, R_RELATIVE); 1095 scr_gotorc (0, 0, R_RELATIVE);
1123 scr_insdel_chars (1, DELETE); 1096 scr_insdel_chars (1, DELETE);
1124 scr_gotorc (0, ncol - 1, R_RELATIVE); 1097 scr_gotorc (0, ncol - 1, R_RELATIVE);
1125 } 1098 }
1135{ 1108{
1136 want_refresh = 1; 1109 want_refresh = 1;
1137 ZERO_SCROLLBACK (); 1110 ZERO_SCROLLBACK ();
1138 1111
1139 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col; 1112 screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col;
1140 MAX_IT (screen.cur.col, 0); 1113 clamp_it (screen.cur.col, 0, ncol - 1);
1141 MIN_IT (screen.cur.col, (int32_t)ncol - 1);
1142 1114
1143 screen.flags &= ~Screen_WrapNext; 1115 screen.flags &= ~Screen_WrapNext;
1144 1116
1145 if (relative & R_RELATIVE) 1117 if (relative & R_RELATIVE)
1146 { 1118 {
1164 else 1136 else
1165 { 1137 {
1166 if (screen.flags & Screen_Relative) 1138 if (screen.flags & Screen_Relative)
1167 { /* relative origin mode */ 1139 { /* relative origin mode */
1168 screen.cur.row = row + screen.tscroll; 1140 screen.cur.row = row + screen.tscroll;
1169 MIN_IT (screen.cur.row, screen.bscroll); 1141 min_it (screen.cur.row, screen.bscroll);
1170 } 1142 }
1171 else 1143 else
1172 screen.cur.row = row; 1144 screen.cur.row = row;
1173 } 1145 }
1174 1146
1175 MAX_IT (screen.cur.row, 0); 1147 clamp_it (screen.cur.row, 0, nrow - 1);
1176 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
1177} 1148}
1178 1149
1179/* ------------------------------------------------------------------------- */ 1150/* ------------------------------------------------------------------------- */
1180/* 1151/*
1181 * direction should be UP or DN 1152 * direction should be UP or DN
1196 || (screen.cur.row == screen.tscroll && direction == DN)) 1167 || (screen.cur.row == screen.tscroll && direction == DN))
1197 scr_scroll_text (screen.tscroll, screen.bscroll, dirn); 1168 scr_scroll_text (screen.tscroll, screen.bscroll, dirn);
1198 else 1169 else
1199 screen.cur.row += dirn; 1170 screen.cur.row += dirn;
1200 1171
1201 MAX_IT (screen.cur.row, 0); 1172 clamp_it (screen.cur.row, 0, nrow - 1);
1202 MIN_IT (screen.cur.row, (int32_t)nrow - 1);
1203 selection_check (0); 1173 selection_check (0);
1204} 1174}
1205 1175
1206/* ------------------------------------------------------------------------- */ 1176/* ------------------------------------------------------------------------- */
1207/* 1177/*
1211 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1181 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1212 */ 1182 */
1213void 1183void
1214rxvt_term::scr_erase_line (int mode) 1184rxvt_term::scr_erase_line (int mode)
1215{ 1185{
1216 unsigned int row, col, num; 1186 unsigned int col, num;
1217 1187
1218 want_refresh = 1; 1188 want_refresh = 1;
1219 ZERO_SCROLLBACK (); 1189 ZERO_SCROLLBACK ();
1220 1190
1221 selection_check (1); 1191 selection_check (1);
1222 1192
1223 row = screen.cur.row; 1193 line_t &line = ROW(screen.cur.row);
1224 1194
1225 switch (mode) 1195 switch (mode)
1226 { 1196 {
1227 case 0: /* erase to end of line */ 1197 case 0: /* erase to end of line */
1228 col = screen.cur.col; 1198 col = screen.cur.col;
1229 num = ncol - col; 1199 num = ncol - col;
1230 MIN_IT (ROW(row).l, (int16_t)col); 1200 min_it (line.l, col);
1231 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1201 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1232 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1202 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1233 CLEAR_SELECTION (); 1203 CLEAR_SELECTION ();
1234 break; 1204 break;
1235 case 1: /* erase to beginning of line */ 1205 case 1: /* erase to beginning of line */
1240 CLEAR_SELECTION (); 1210 CLEAR_SELECTION ();
1241 break; 1211 break;
1242 case 2: /* erase whole line */ 1212 case 2: /* erase whole line */
1243 col = 0; 1213 col = 0;
1244 num = ncol; 1214 num = ncol;
1245 ROW(row).l = 0; 1215 line.l = 0;
1246 if (selection.beg.row <= screen.cur.row 1216 if (selection.beg.row <= screen.cur.row
1247 && selection.end.row >= screen.cur.row) 1217 && selection.end.row >= screen.cur.row)
1248 CLEAR_SELECTION (); 1218 CLEAR_SELECTION ();
1249 break; 1219 break;
1250 default: 1220 default:
1251 return; 1221 return;
1252 } 1222 }
1253 1223
1254 scr_blank_line (ROW(row), col, num, rstyle); 1224 scr_blank_line (line, col, num, rstyle);
1255} 1225}
1256 1226
1257/* ------------------------------------------------------------------------- */ 1227/* ------------------------------------------------------------------------- */
1258/* 1228/*
1259 * Erase part of whole of the screen 1229 * Erase part of whole of the screen
1302 CLEAR_SELECTION (); 1272 CLEAR_SELECTION ();
1303 1273
1304 if (row >= nrow) /* Out Of Bounds */ 1274 if (row >= nrow) /* Out Of Bounds */
1305 return; 1275 return;
1306 1276
1307 MIN_IT (num, (nrow - row)); 1277 min_it (num, nrow - row);
1308 1278
1309 if (rstyle & (RS_RVid | RS_Uline)) 1279 if (rstyle & (RS_RVid | RS_Uline))
1310 ren = (rend_t) ~RS_None; 1280 ren = (rend_t) ~RS_None;
1311 else if (GET_BASEBG (rstyle) == Color_bg) 1281 else if (GET_BASEBG (rstyle) == Color_bg)
1312 { 1282 {
1323 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1293 XChangeGC (display->display, gc, GCForeground, &gcvalue);
1324 } 1294 }
1325 1295
1326 for (; num--; row++) 1296 for (; num--; row++)
1327 { 1297 {
1298 ROW (row).l = 0;
1328 scr_blank_screen_mem (ROW (row), rstyle); 1299 scr_blank_screen_mem (ROW (row), rstyle);
1329 ROW (row).l = 0;
1330 scr_blank_line (drawn[row], 0, ncol, ren); 1300 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1331 } 1301 }
1332} 1302}
1333 1303
1334#if ENABLE_FRILLS 1304#if ENABLE_FRILLS
1335void 1305void
1420 return; 1390 return;
1421 1391
1422 scr_do_wrap (); 1392 scr_do_wrap ();
1423 1393
1424 selection_check (1); 1394 selection_check (1);
1425 MIN_IT (count, (ncol - screen.cur.col)); 1395 min_it (count, ncol - screen.cur.col);
1426 1396
1427 row = screen.cur.row; 1397 row = screen.cur.row;
1428 1398
1429 line_t *line = &ROW(row); 1399 line_t *line = &ROW(row);
1430 1400
1438 } 1408 }
1439 1409
1440 if (!line->is_longer ()) 1410 if (!line->is_longer ())
1441 { 1411 {
1442 line->l += count; 1412 line->l += count;
1443 MIN_IT (line->l, ncol); 1413 min_it (line->l, ncol);
1444 } 1414 }
1445 1415
1446 if (selection.op && current_screen == selection.screen 1416 if (selection.op && current_screen == selection.screen
1447 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1417 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1448 { 1418 {
1509 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r 1479 * XTERM_SEQ: Set region <top> - <bot> inclusive: ESC [ <top> ; <bot> r
1510 */ 1480 */
1511void 1481void
1512rxvt_term::scr_scroll_region (int top, int bot) 1482rxvt_term::scr_scroll_region (int top, int bot)
1513{ 1483{
1514 MAX_IT (top, 0); 1484 max_it (top, 0);
1515 MIN_IT (bot, (int)nrow - 1); 1485 min_it (bot, nrow - 1);
1516 1486
1517 if (top > bot) 1487 if (top > bot)
1518 return; 1488 return;
1519 1489
1520 screen.tscroll = top; 1490 screen.tscroll = top;
1618 XGCValues gcvalue; 1588 XGCValues gcvalue;
1619 1589
1620 if (rvideo != mode) 1590 if (rvideo != mode)
1621 { 1591 {
1622 rvideo = mode; 1592 rvideo = mode;
1623 SWAP_IT (pix_colors[Color_fg], pix_colors[Color_bg], rxvt_color); 1593 ::swap (pix_colors[Color_fg], pix_colors[Color_bg]);
1624#if XPM_BACKGROUND 1594#if XPM_BACKGROUND
1625 if (bgPixmap.pixmap == None) 1595 if (bgPixmap.pixmap == None)
1626#endif 1596#endif
1627#if TRANSPARENT 1597#if TRANSPARENT
1628 if (! (options & Opt_transparent) || am_transparent == 0) 1598 if (! (options & Opt_transparent) || am_transparent == 0)
1724 bool found = false; 1694 bool found = false;
1725 1695
1726 for (int i = 0; i < nrow; i++) 1696 for (int i = 0; i < nrow; i++)
1727 { 1697 {
1728 int col = 0; 1698 int col = 0;
1729 rend_t *drp = drawn[i].r; 1699 rend_t *drp = drawn_buf[i].r;
1730 1700
1731 for (; col < ncol; col++, drp++) 1701 for (; col < ncol; col++, drp++)
1732 if ((*drp & mask) == value) 1702 if ((*drp & mask) == value)
1733 { 1703 {
1734 found = true; 1704 found = true;
1752rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh) 1722rxvt_term::scr_expose (int x, int y, int ewidth, int eheight, bool refresh)
1753{ 1723{
1754 int i; 1724 int i;
1755 row_col_t rc[RC_COUNT]; 1725 row_col_t rc[RC_COUNT];
1756 1726
1757 if (!drawn) /* sanity check */ 1727 if (!drawn_buf) /* sanity check */
1758 return; 1728 return;
1759 1729
1760#ifndef NO_SLOW_LINK_SUPPORT 1730#ifndef NO_SLOW_LINK_SUPPORT
1761 if (refresh_type == FAST_REFRESH && !display->is_local) 1731 if (refresh_type == FAST_REFRESH && !display->is_local)
1762 { 1732 {
1763 y = 0; 1733 y = 0;
1764 eheight = height; 1734 eheight = height;
1765 } 1735 }
1766#endif
1767
1768#ifdef DEBUG_STRICT
1769 x = max (x, 0);
1770 x = min (x, (int)width);
1771 y = max (y, 0);
1772 y = min (y, (int)height);
1773#endif 1736#endif
1774 1737
1775 /* round down */ 1738 /* round down */
1776 rc[PART_BEG].col = Pixel2Col (x); 1739 rc[PART_BEG].col = Pixel2Col (x);
1777 rc[PART_BEG].row = Pixel2Row (y); 1740 rc[PART_BEG].row = Pixel2Row (y);
1780 rc[PART_END].row = Pixel2Row (y + eheight + fheight - 1); 1743 rc[PART_END].row = Pixel2Row (y + eheight + fheight - 1);
1781 1744
1782 /* sanity checks */ 1745 /* sanity checks */
1783 for (i = PART_BEG; i < RC_COUNT; i++) 1746 for (i = PART_BEG; i < RC_COUNT; i++)
1784 { 1747 {
1785 MIN_IT (rc[i].col, ncol - 1); 1748 min_it (rc[i].col, ncol - 1);
1786 MIN_IT (rc[i].row, nrow - 1); 1749 min_it (rc[i].row, nrow - 1);
1787 } 1750 }
1788 1751
1789 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) 1752 for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++)
1790 fill_text (&drawn[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); 1753 fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1);
1791 1754
1792 if (refresh) 1755 if (refresh)
1793 scr_refresh (SLOW_REFRESH); 1756 scr_refresh (SLOW_REFRESH);
1794} 1757}
1795 1758
2053 if (screen.cur.row + view_start != ocrow 2016 if (screen.cur.row + view_start != ocrow
2054 || screen.cur.col != oldcursor.col) 2017 || screen.cur.col != oldcursor.col)
2055 { 2018 {
2056 if (ocrow < nrow 2019 if (ocrow < nrow
2057 && oldcursor.col < ncol) 2020 && oldcursor.col < ncol)
2058 drawn[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); 2021 drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline);
2059 2022
2060 if (focus || !showcursor) 2023 if (focus || !showcursor)
2061 oldcursor.row = -1; 2024 oldcursor.row = -1;
2062 else 2025 else
2063 setoldcursor = 1; 2026 setoldcursor = 1;
2102 for (; j-- >= 0; row += (i > 0 ? 1 : -1)) 2065 for (; j-- >= 0; row += (i > 0 ? 1 : -1))
2103 { 2066 {
2104 if (row + i >= 0 && row + i < nrow && row + i != ocrow) 2067 if (row + i >= 0 && row + i < nrow && row + i != ocrow)
2105 { 2068 {
2106 line_t s = ROW(row - view_start); 2069 line_t s = ROW(row - view_start);
2107 line_t d = drawn[row]; 2070 line_t d = drawn_buf[row];
2108 line_t d2 = drawn[row + i]; 2071 line_t d2 = drawn_buf[row + i];
2109 2072
2110 for (nits = 0, col = ncol; col--; ) 2073 for (nits = 0, col = ncol; col--; )
2111 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col]) 2074 if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col])
2112 nits--; 2075 nits--;
2113 else if (s.t[col] != d.t[col] || s.r[col] != d.r[col]) 2076 else if (s.t[col] != d.t[col] || s.r[col] != d.r[col])
2131 2094
2132 if (len != -1) 2095 if (len != -1)
2133 { 2096 {
2134 /* also comes here at end if needed because of >= above */ 2097 /* also comes here at end if needed because of >= above */
2135 if (wlen < len) 2098 if (wlen < len)
2136 SWAP_IT (wlen, len, int); 2099 ::swap (wlen, len);
2137 2100
2138 XCopyArea (display->display, vt, vt, 2101 XCopyArea (display->display, vt, vt,
2139 gc, 0, Row2Pixel (len + i), 2102 gc, 0, Row2Pixel (len + i),
2140 (unsigned int)TermWin_TotalWidth (), 2103 (unsigned int)TermWin_TotalWidth (),
2141 (unsigned int)Height2Pixel (wlen - len + 1), 2104 (unsigned int)Height2Pixel (wlen - len + 1),
2151 */ 2114 */
2152 for (row = 0; row < nrow; row++) 2115 for (row = 0; row < nrow; row++)
2153 { 2116 {
2154 text_t *stp = ROW(row - view_start).t; 2117 text_t *stp = ROW(row - view_start).t;
2155 rend_t *srp = ROW(row - view_start).r; 2118 rend_t *srp = ROW(row - view_start).r;
2156 text_t *dtp = drawn[row].t; 2119 text_t *dtp = drawn_buf[row].t;
2157 rend_t *drp = drawn[row].r; 2120 rend_t *drp = drawn_buf[row].r;
2158 2121
2159 /* 2122 /*
2160 * E2: OK, now the real pass 2123 * E2: OK, now the real pass
2161 */ 2124 */
2162 int ypixel = (int)Row2Pixel (row); 2125 int ypixel = (int)Row2Pixel (row);
2273 fore = Color_UL; 2236 fore = Color_UL;
2274#endif 2237#endif
2275 2238
2276 if (invert) 2239 if (invert)
2277 { 2240 {
2278 SWAP_IT (fore, back, int); 2241 ::swap (fore, back);
2279 2242
2280#ifndef NO_BOLD_UNDERLINE_REVERSE 2243#ifndef NO_BOLD_UNDERLINE_REVERSE
2281 if (ISSET_PIXCOLOR (Color_RV)) 2244 if (ISSET_PIXCOLOR (Color_RV))
2282 back = Color_RV; 2245 back = Color_RV;
2283 2246
2375 2338
2376 while (col && ROW(screen.cur.row).t[col] == NOCHAR) 2339 while (col && ROW(screen.cur.row).t[col] == NOCHAR)
2377 col--; 2340 col--;
2378 2341
2379 while (col + cursorwidth < ncol 2342 while (col + cursorwidth < ncol
2380 && drawn[oldcursor.row].t[col + cursorwidth] == NOCHAR) 2343 && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR)
2381 cursorwidth++; 2344 cursorwidth++;
2382 2345
2383#ifndef NO_CURSORCOLOR 2346#ifndef NO_CURSORCOLOR
2384 if (ISSET_PIXCOLOR (Color_cursor)) 2347 if (ISSET_PIXCOLOR (Color_cursor))
2385 XSetForeground (display->display, gc, pix_colors[Color_cursor]); 2348 XSetForeground (display->display, gc, pix_colors[Color_cursor]);
2417 2380
2418void 2381void
2419rxvt_term::scr_remap_chars () 2382rxvt_term::scr_remap_chars ()
2420{ 2383{
2421 for (int i = total_rows; i--; ) 2384 for (int i = total_rows; i--; )
2422 scr_remap_chars (save[i]); 2385 scr_remap_chars (row_buf [i]);
2423 2386
2424 for (int i = nrow; i--; ) 2387 for (int i = nrow; i--; )
2425 { 2388 {
2426 scr_remap_chars (drawn[i]); 2389 scr_remap_chars (drawn_buf [i]);
2427 scr_remap_chars (swap_save[i]); 2390 scr_remap_chars (swap_buf [i]);
2428 } 2391 }
2429} 2392}
2430 2393
2431void 2394void
2432rxvt_term::scr_recolour () 2395rxvt_term::scr_recolour ()
2499 row = selection.beg.row; 2462 row = selection.beg.row;
2500 } 2463 }
2501 else 2464 else
2502 { 2465 {
2503 col = 0; 2466 col = 0;
2504 row = view_start; 2467 row = -view_start;
2505 } 2468 }
2506 2469
2507 for (; row < min (selection.end.row, view_end); row++, col = 0) 2470 for (; row < min (selection.end.row, view_end); row++, col = 0)
2508 for (rend_t *srp = ROW(row).r; col < ncol; col++) 2471 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2509 srp[col] ^= RS_RVid; 2472 srp[col] ^= RS_RVid;
2529 char r1[] = "\n"; 2492 char r1[] = "\n";
2530 2493
2531 for (row = saveLines - nsaved; 2494 for (row = saveLines - nsaved;
2532 row < saveLines + nrow - 1; row++) 2495 row < saveLines + nrow - 1; row++)
2533 { 2496 {
2534 width = save[row].l >= 0 ? save[row].l 2497 width = row_buf[row].l >= 0 ? row_buf[row].l
2535 : ncol; 2498 : ncol;
2536 for (towrite = width; towrite; towrite -= wrote) 2499 for (towrite = width; towrite; towrite -= wrote)
2537 { 2500 {
2538 wrote = write (fd, & (save[row].t[width - towrite]), 2501 wrote = write (fd, & (row_buf[row].t[width - towrite]),
2539 towrite); 2502 towrite);
2540 if (wrote < 0) 2503 if (wrote < 0)
2541 return; /* XXX: death, no report */ 2504 return; /* XXX: death, no report */
2542 } 2505 }
2543 if (save[row].l >= 0) 2506 if (row_buf[row].l >= 0)
2544 if (write (fd, r1, 1) <= 0) 2507 if (write (fd, r1, 1) <= 0)
2545 return; /* XXX: death, no report */ 2508 return; /* XXX: death, no report */
2546 } 2509 }
2547} 2510}
2548#endif 2511#endif
3025 want_refresh = 1; 2988 want_refresh = 1;
3026 2989
3027 selection.mark.row = row - view_start; 2990 selection.mark.row = row - view_start;
3028 selection.mark.col = col; 2991 selection.mark.col = col;
3029 2992
3030 selection.mark.row = min (max (selection.mark.row, -nsaved), nrow - 1); 2993 selection.mark.row = clamp (selection.mark.row, -nsaved, nrow - 1);
3031 selection.mark.col = min (max (selection.mark.col, 0), ncol - 1); 2994 selection.mark.col = clamp (selection.mark.col, 0, ncol - 1);
3032 2995
3033 while (selection.mark.col > 0 2996 while (selection.mark.col > 0
3034 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) 2997 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR)
3035 --selection.mark.col; 2998 --selection.mark.col;
3036 2999
3141 * flag == 2 ==> button 3 motion 3104 * flag == 2 ==> button 3 motion
3142 */ 3105 */
3143void 3106void
3144rxvt_term::selection_extend (int x, int y, int flag) 3107rxvt_term::selection_extend (int x, int y, int flag)
3145{ 3108{
3146 int col = min (max (Pixel2Col (x), 0), ncol); 3109 int col = clamp (Pixel2Col (x), 0, ncol);
3147 int row = min (max (Pixel2Row (y), 0), nrow - 1); 3110 int row = clamp (Pixel2Row (y), 0, nrow - 1);
3148 3111
3149 /* 3112 /*
3150 * If we're selecting characters (single click) then we must check first 3113 * If we're selecting characters (single click) then we must check first
3151 * if we are at the same place as the original mark. If we are then 3114 * if we are at the same place as the original mark. If we are then
3152 * select nothing. Otherwise, if we're to the right of the mark, you have to 3115 * select nothing. Otherwise, if we're to the right of the mark, you have to
3365 } 3328 }
3366 } 3329 }
3367 3330
3368#if ENABLE_FRILLS 3331#if ENABLE_FRILLS
3369 if (selection.rect && selection.beg.col > selection.end.col) 3332 if (selection.rect && selection.beg.col > selection.end.col)
3370 SWAP_IT (selection.beg.col, selection.end.col, int); 3333 ::swap (selection.beg.col, selection.end.col);
3371#endif 3334#endif
3372} 3335}
3373 3336
3374#if ENABLE_FRILLS 3337#if ENABLE_FRILLS
3375void 3338void
3573 */ 3536 */
3574void 3537void
3575rxvt_term::pixel_position (int *x, int *y) 3538rxvt_term::pixel_position (int *x, int *y)
3576{ 3539{
3577 *x = Pixel2Col (*x); 3540 *x = Pixel2Col (*x);
3578 /* MAX_IT (*x, 0); MIN_IT (*x, (int)ncol - 1); */ 3541 /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */
3579 *y = Pixel2Row (*y); 3542 *y = Pixel2Row (*y);
3580 /* MAX_IT (*y, 0); MIN_IT (*y, (int)nrow - 1); */ 3543 /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */
3581} 3544}
3582 3545
3583/* ------------------------------------------------------------------------- */ 3546/* ------------------------------------------------------------------------- */
3584#ifdef USE_XIM 3547#ifdef USE_XIM
3585void 3548void
3607 3570
3608 if (x < 0) x = ncol - w; 3571 if (x < 0) x = ncol - w;
3609 if (y < 0) y = nrow - h; 3572 if (y < 0) y = nrow - h;
3610 3573
3611 // make space for border 3574 // make space for border
3612 w += 2; MIN_IT (w, ncol); 3575 w += 2; min_it (w, ncol);
3613 h += 2; MIN_IT (h, nrow); 3576 h += 2; min_it (h, nrow);
3614 3577
3615 x -= 1; MAX_IT (x, 0); 3578 x -= 1; clamp_it (x, 0, ncol - w);
3616 y -= 1; MAX_IT (y, 0); 3579 y -= 1; clamp_it (y, 0, nrow - h);
3617
3618 MIN_IT (x, ncol - w);
3619 MIN_IT (y, nrow - h);
3620 3580
3621 ov_x = x; ov_y = y; 3581 ov_x = x; ov_y = y;
3622 ov_w = w; ov_h = h; 3582 ov_w = w; ov_h = h;
3623 3583
3624 ov_text = new text_t *[h]; 3584 ov_text = new text_t *[h];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines