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.189 by root, Thu Dec 22 15:28:15 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 while (p != pend && q > 0) 285 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 { 286 {
296 p = MOD (p - 1, prev_total_rows); 287 p = MOD (p - 1, prev_total_rows);
288#ifdef DEBUG_STRICT
289 assert (old_buf [MOD (p, prev_total_rows)].t);
290#endif
297 291
298 llen += prev_ncol; 292 int llen = old_buf [MOD (p, prev_total_rows)].l;
299 }
300 293
301 int qlines = llen / ncol + 1; 294 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
302 int lofs = 0;
303
304 q -= qlines;
305
306 int qrow = q;
307
308 for (; qlines--; qrow++)
309 {
310 if (qrow >= 0)
311 { 295 {
296 p = MOD (p - 1, prev_total_rows);
297
298 llen += prev_ncol;
299 }
300
301 int qlines = max (0, (llen - 1) / ncol) + 1;
302
303 // drop partial lines completely
304 if (q < qlines)
305 break;
306
307 q -= qlines;
308
309 int lofs = 0;
310 line_t *qline;
311
312 // re-assemble the full line by destination lines
313 for (int qrow = q; qlines--; qrow++)
314 {
312 line_t &qline = row_buf [qrow]; 315 qline = row_buf + qrow;
313
314 lalloc (qline); 316 lalloc (*qline);
315 qline.set_is_longer (); 317 qline->set_is_longer ();
316 318
317 int qcol = 0; 319 int qcol = 0;
318 320
319 for (;;) 321 // fill a single destination line
322 while (lofs < llen && qcol < ncol)
320 { 323 {
321 int prow = lofs / prev_ncol + p; 324 int prow = lofs / prev_ncol;
322 int pcol = lofs % prev_ncol; 325 int pcol = lofs % prev_ncol;
323 326
324 line_t &pline = old_buf [p]; 327 line_t &pline = old_buf [MOD (p + prow, prev_total_rows)];
325 328
326 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 329 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
327 330
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); 331 assert (len);
332 assert (pline.t);
338 333
339 memcpy (qline.t + qcol, pline.t + pcol, len * sizeof (text_t)); 334 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
340 memcpy (qline.r + qcol, pline.r + pcol, len * sizeof (rend_t)); 335 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
341 336
342 lofs += len; 337 lofs += len;
343 qcol += len; 338 qcol += len;
344
345 if (qcol == ncol)
346 break;
347 } 339 }
348 } 340 }
349 else 341
350 lofs += ncol; 342 qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1;
343 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
351 } 344 }
345
346 term_start = total_rows - nrow;
347 view_start = 0;
348 nsaved = term_start - q;
349
350 // make sure all terminal lines exist
351 while (nsaved < 0)
352 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
353
354 }
355 else
352 } 356 {
357 // if no scrollback exists (yet), wing, instead of wrap
358
359 for (int row = min (nrow, prev_nrow); row--; )
360 {
361 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
362 line_t &qline = row_buf [row];
363
364 qline = pline;
365 lresize (qline);
366 }
367
368 for (int row = prev_nrow; row < nrow; row++)
369 {
370 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
371 }
372
373 term_start = 0;
374 view_start = 0;
375 }
376
377#ifdef DEBUG_STRICT
378 for (int i = -nsaved; i < nrow; i++)
379 assert (ROW (i).t);
380#endif
353 381
354 free (old_buf); 382 free (old_buf);
355 delete old_ta; 383 delete old_ta;
356 delete old_ra; 384 delete old_ra;
357 385
358 min_it (screen.cur.row, nrow - 1); 386 clamp_it (screen.cur.row, 0, nrow - 1);
359 min_it (screen.cur.col, ncol - 1); 387 clamp_it (screen.cur.col, 0, ncol - 1);
360 388
361 if (tabs) 389 if (tabs)
362 free (tabs); 390 free (tabs);
363 } 391 }
364 392
386 free (row_buf); 414 free (row_buf);
387 free (swap_buf); 415 free (swap_buf);
388 free (drawn_buf); 416 free (drawn_buf);
389 free (temp_buf); 417 free (temp_buf);
390 free (tabs); 418 free (tabs);
419
420 row_buf = 0; // signal that we freed all the arrays
391} 421}
392 422
393/* ------------------------------------------------------------------------- */ 423/* ------------------------------------------------------------------------- */
394/* 424/*
395 * Hard reset 425 * Hard reset
451 min_it (s->cur.row, nrow - 1); 481 min_it (s->cur.row, nrow - 1);
452 min_it (s->cur.col, ncol - 1); 482 min_it (s->cur.col, ncol - 1);
453#ifdef DEBUG_STRICT 483#ifdef DEBUG_STRICT
454 assert (s->cur.row >= 0); 484 assert (s->cur.row >= 0);
455 assert (s->cur.col >= 0); 485 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 486#endif
460} 487}
461 488
462/* ------------------------------------------------------------------------- */ 489/* ------------------------------------------------------------------------- */
463/* 490/*
487#if NSCREENS 514#if NSCREENS
488 if (options & Opt_secondaryScreen) 515 if (options & Opt_secondaryScreen)
489 { 516 {
490 num_scr = 0; 517 num_scr = 0;
491 518
492 for (int i = nrow; i--; ) 519 for (int i = prev_nrow; i--; )
493 ::swap (ROW(i), swap_buf [i]); 520 ::swap (ROW(i), swap_buf [i]);
494 521
495 ::swap (screen.charset, swap.charset); 522 ::swap (screen.charset, swap.charset);
496 ::swap (screen.flags, swap.flags); 523 ::swap (screen.flags, swap.flags);
497 screen.flags |= Screen_VisibleCursor; 524 screen.flags |= Screen_VisibleCursor;
677 704
678#ifdef DEBUG_STRICT 705#ifdef DEBUG_STRICT
679 assert (screen.cur.col < last_col); 706 assert (screen.cur.col < last_col);
680 assert (screen.cur.row < nrow 707 assert (screen.cur.row < nrow
681 && screen.cur.row >= -nsaved); 708 && 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 709#endif
686 row = screen.cur.row; 710 row = screen.cur.row;
687 711
688 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 712 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
689 713
900 if (!line->is_longer ()) /* XXX: think about this */ 924 if (!line->is_longer ()) /* XXX: think about this */
901 max_it (line->l, screen.cur.col); 925 max_it (line->l, screen.cur.col);
902 926
903#ifdef DEBUG_STRICT 927#ifdef DEBUG_STRICT
904 assert (screen.cur.row >= 0); 928 assert (screen.cur.row >= 0);
905#else /* drive with your eyes closed */
906 max_it (screen.cur.row, 0);
907#endif 929#endif
908} 930}
909 931
910/* ------------------------------------------------------------------------- */ 932/* ------------------------------------------------------------------------- */
911/* 933/*
1691 y = 0; 1713 y = 0;
1692 eheight = height; 1714 eheight = height;
1693 } 1715 }
1694#endif 1716#endif
1695 1717
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 */ 1718 /* round down */
1705 rc[PART_BEG].col = Pixel2Col (x); 1719 rc[PART_BEG].col = Pixel2Col (x);
1706 rc[PART_BEG].row = Pixel2Row (y); 1720 rc[PART_BEG].row = Pixel2Row (y);
1707 /* round up */ 1721 /* round up */
1708 rc[PART_END].col = Pixel2Width (x + ewidth + fwidth - 1); 1722 rc[PART_END].col = Pixel2Width (x + ewidth + fwidth - 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines