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.186 by root, Wed Dec 21 19:50:17 2005 UTC vs.
Revision 1.190 by root, Thu Dec 22 15:52:57 2005 UTC

239 { 239 {
240 /* 240 /*
241 * add or delete rows as appropriate 241 * add or delete rows as appropriate
242 */ 242 */
243 243
244 printf ("resize %d:%d => %d:%d\n", prev_nrow, prev_ncol, nrow, ncol);//D
245
246 rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t)); 244 rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t));
247 rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); 245 rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
248 246
249#if 0 247#if 0
250 if (nrow < prev_nrow) 248 if (nrow < prev_nrow)
255 lfree (drawn_buf[row]); 253 lfree (drawn_buf[row]);
256 } 254 }
257 } 255 }
258#endif 256#endif
259 257
260 drawn_buf = (line_t *) rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); 258 drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t));
261 temp_buf = (line_t *) rxvt_realloc (temp_buf , nrow * sizeof (line_t)); 259 temp_buf = (line_t *)rxvt_realloc (temp_buf , nrow * sizeof (line_t));
262 swap_buf = (line_t *) rxvt_realloc (swap_buf , nrow * sizeof (line_t)); 260 swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t));
263 261
264 for (int row = min (nrow, prev_nrow); row--; ) 262 for (int row = min (nrow, prev_nrow); row--; )
265 { 263 {
266 lresize (drawn_buf[row]); 264 lresize (drawn_buf[row]);
267 lresize (swap_buf [row]); 265 lresize (swap_buf [row]);
273 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 271 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
274 } 272 }
275 273
276 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 274 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
277 275
278 // re-wrap lines, this is rather ugly, possibly because I am too dumb
279 // to come up with a lean and mean algorithm.
280
281 int p = MOD (term_start + nrow , prev_total_rows); // previous row 276 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
282 int pend = MOD (term_start - nsaved, prev_total_rows); 277 int pend = MOD (term_start - nsaved , prev_total_rows);
283 int q = total_rows; // rewrapped row 278 int q = total_rows; // rewrapped row
284 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
285 while (p != pend && q > 0) 288 while (p != pend && q > 0)
286 {
287 p = MOD (p - 1, prev_total_rows);
288
289 assert (old_buf [MOD (p, prev_total_rows)].t);
290 assert (!old_buf [MOD (p, prev_total_rows)].is_longer ());
291
292 int llen = old_buf [MOD (p, prev_total_rows)].l;
293
294 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
295 { 289 {
296 p = MOD (p - 1, prev_total_rows); 290 p = MOD (p - 1, prev_total_rows);
291#ifdef DEBUG_STRICT
292 assert (old_buf [MOD (p, prev_total_rows)].t);
293#endif
297 294
298 llen += prev_ncol;
299 }
300
301 int qlines = llen / ncol + 1;
302 int lofs = 0; 295 int plines = 1;
296 int llen = old_buf [MOD (p, prev_total_rows)].l;
303 297
304 q -= qlines; 298 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
305
306 int qrow = q;
307
308 for (; qlines--; qrow++)
309 {
310 if (qrow >= 0)
311 { 299 {
300 p = MOD (p - 1, prev_total_rows);
301
302 plines++;
303 llen += prev_ncol;
304 }
305
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
314 int lofs = 0;
315 line_t *qline;
316
317 // re-assemble the full line by destination lines
318 for (int qrow = q; qlines--; qrow++)
319 {
312 line_t &qline = row_buf [qrow]; 320 qline = row_buf + qrow;
313
314 lalloc (qline); 321 lalloc (*qline);
315 qline.set_is_longer (); 322 qline->set_is_longer ();
316 323
317 int qcol = 0; 324 int qcol = 0;
318 325
319 for (;;) 326 // fill a single destination line
327 while (lofs < llen && qcol < ncol)
320 { 328 {
321 int prow = lofs / prev_ncol + p; 329 int prow = lofs / prev_ncol;
322 int pcol = lofs % prev_ncol; 330 int pcol = lofs % prev_ncol;
323 331
332 prow = MOD (p + prow, prev_total_rows);
333
334 // we only adjust the cursor _row_, as this seems to upset
335 // applications/shells/readline least.
336 if (prow == ocur.row)
337 screen.cur.row = qrow - (total_rows - nrow);
338
324 line_t &pline = old_buf [p]; 339 line_t &pline = old_buf [prow];
325 340
326 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 341 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
327 342
328 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);
329
330 if (len <= 0)
331 {
332 qline.l = qcol;
333 scr_blank_line (qline, qcol, ncol - qcol, DEFAULT_RSTYLE);
334 break;
335 }
336
337 assert (lofs < 1000); 343 assert (len);
344 assert (pline.t);
338 345
339 memcpy (qline.t + qcol, pline.t + pcol, len * sizeof (text_t)); 346 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
340 memcpy (qline.r + qcol, pline.r + pcol, len * sizeof (rend_t)); 347 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
341 348
342 lofs += len; 349 lofs += len;
343 qcol += len; 350 qcol += len;
344
345 if (qcol == ncol)
346 break;
347 } 351 }
348 } 352 }
349 else 353
350 lofs += ncol; 354 qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1;
355 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
351 } 356 }
357
358 term_start = total_rows - nrow;
359 view_start = 0;
360 nsaved = term_start - q;
361
362 // make sure all terminal lines exist
363 while (nsaved < 0)
364 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
365
366 }
367 else
352 } 368 {
369 // if no scrollback exists (yet), wing, instead of wrap
370
371 for (int row = min (nrow, prev_nrow); row--; )
372 {
373 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
374 line_t &qline = row_buf [row];
375
376 qline = pline;
377 lresize (qline);
378 }
379
380 for (int row = prev_nrow; row < nrow; row++)
381 {
382 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
383 }
384
385 term_start = 0;
386 view_start = 0;
387 }
388
389#ifdef DEBUG_STRICT
390 for (int i = -nsaved; i < nrow; i++)
391 assert (ROW (i).t);
392#endif
353 393
354 free (old_buf); 394 free (old_buf);
355 delete old_ta; 395 delete old_ta;
356 delete old_ra; 396 delete old_ra;
357 397
358 min_it (screen.cur.row, nrow - 1); 398 clamp_it (screen.cur.row, 0, nrow - 1);
359 min_it (screen.cur.col, ncol - 1); 399 clamp_it (screen.cur.col, 0, ncol - 1);
360 400
361 if (tabs) 401 if (tabs)
362 free (tabs); 402 free (tabs);
363 } 403 }
364 404
386 free (row_buf); 426 free (row_buf);
387 free (swap_buf); 427 free (swap_buf);
388 free (drawn_buf); 428 free (drawn_buf);
389 free (temp_buf); 429 free (temp_buf);
390 free (tabs); 430 free (tabs);
431
432 row_buf = 0; // signal that we freed all the arrays
391} 433}
392 434
393/* ------------------------------------------------------------------------- */ 435/* ------------------------------------------------------------------------- */
394/* 436/*
395 * Hard reset 437 * Hard reset
451 min_it (s->cur.row, nrow - 1); 493 min_it (s->cur.row, nrow - 1);
452 min_it (s->cur.col, ncol - 1); 494 min_it (s->cur.col, ncol - 1);
453#ifdef DEBUG_STRICT 495#ifdef DEBUG_STRICT
454 assert (s->cur.row >= 0); 496 assert (s->cur.row >= 0);
455 assert (s->cur.col >= 0); 497 assert (s->cur.col >= 0);
456#else /* drive with your eyes closed */
457 max_it (s->cur.row, 0);
458 max_it (s->cur.col, 0);
459#endif 498#endif
460} 499}
461 500
462/* ------------------------------------------------------------------------- */ 501/* ------------------------------------------------------------------------- */
463/* 502/*
487#if NSCREENS 526#if NSCREENS
488 if (options & Opt_secondaryScreen) 527 if (options & Opt_secondaryScreen)
489 { 528 {
490 num_scr = 0; 529 num_scr = 0;
491 530
492 for (int i = nrow; i--; ) 531 for (int i = prev_nrow; i--; )
493 ::swap (ROW(i), swap_buf [i]); 532 ::swap (ROW(i), swap_buf [i]);
494 533
495 ::swap (screen.charset, swap.charset); 534 ::swap (screen.charset, swap.charset);
496 ::swap (screen.flags, swap.flags); 535 ::swap (screen.flags, swap.flags);
497 screen.flags |= Screen_VisibleCursor; 536 screen.flags |= Screen_VisibleCursor;
677 716
678#ifdef DEBUG_STRICT 717#ifdef DEBUG_STRICT
679 assert (screen.cur.col < last_col); 718 assert (screen.cur.col < last_col);
680 assert (screen.cur.row < nrow 719 assert (screen.cur.row < nrow
681 && screen.cur.row >= -nsaved); 720 && screen.cur.row >= -nsaved);
682#else /* drive with your eyes closed */
683 min_it (screen.cur.col, last_col - 1);
684 clamp_it (screen.cur.row, -nsaved, nrow - 1);
685#endif 721#endif
686 row = screen.cur.row; 722 row = screen.cur.row;
687 723
688 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 724 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
689 725
900 if (!line->is_longer ()) /* XXX: think about this */ 936 if (!line->is_longer ()) /* XXX: think about this */
901 max_it (line->l, screen.cur.col); 937 max_it (line->l, screen.cur.col);
902 938
903#ifdef DEBUG_STRICT 939#ifdef DEBUG_STRICT
904 assert (screen.cur.row >= 0); 940 assert (screen.cur.row >= 0);
905#else /* drive with your eyes closed */
906 max_it (screen.cur.row, 0);
907#endif 941#endif
908} 942}
909 943
910/* ------------------------------------------------------------------------- */ 944/* ------------------------------------------------------------------------- */
911/* 945/*
1691 y = 0; 1725 y = 0;
1692 eheight = height; 1726 eheight = height;
1693 } 1727 }
1694#endif 1728#endif
1695 1729
1696#ifdef DEBUG_STRICT
1697#if 0
1698 // that's not debugging //TODO //FIXME
1699 clamp_it (x, 0, width);
1700 clamp_it (y, 0, height);
1701#endif
1702#endif
1703
1704 /* round down */ 1730 /* round down */
1705 rc[PART_BEG].col = Pixel2Col (x); 1731 rc[PART_BEG].col = Pixel2Col (x);
1706 rc[PART_BEG].row = Pixel2Row (y); 1732 rc[PART_BEG].row = Pixel2Row (y);
1707 /* round up */ 1733 /* round up */
1708 rc[PART_END].col = Pixel2Width (x + ewidth + fwidth - 1); 1734 rc[PART_END].col = Pixel2Width (x + ewidth + fwidth - 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines