diff options
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 77 |
1 files changed, 76 insertions, 1 deletions
@@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.126 2010-02-08 18:10:07 tcunha Exp $ */ +/* $Id: window.c,v 1.127 2010-03-15 12:51:23 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -630,6 +630,81 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy) fatal("ioctl failed"); } +/* + * Enter alternative screen mode. A copy of the visible screen is saved and the + * history is not updated + */ +void +window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc) +{ + struct screen *s = &wp->base; + u_int sx, sy; + + if (wp->saved_grid != NULL) + return; + if (!options_get_number(&wp->window->options, "alternate-screen")) + return; + sx = screen_size_x(s); + sy = screen_size_y(s); + + wp->saved_grid = grid_create(sx, sy, 0); + grid_duplicate_lines(wp->saved_grid, 0, s->grid, screen_hsize(s), sy); + wp->saved_cx = s->cx; + wp->saved_cy = s->cy; + memcpy(&wp->saved_cell, gc, sizeof wp->saved_cell); + + grid_view_clear(s->grid, 0, 0, sx, sy); + + wp->base.grid->flags &= ~GRID_HISTORY; + + wp->flags |= PANE_REDRAW; +} + +/* Exit alternate screen mode and restore the copied grid. */ +void +window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc) +{ + struct screen *s = &wp->base; + u_int sx, sy; + + if (wp->saved_grid == NULL) + return; + if (!options_get_number(&wp->window->options, "alternate-screen")) + return; + sx = screen_size_x(s); + sy = screen_size_y(s); + + /* + * If the current size is bigger, temporarily resize to the old size + * before copying back. + */ + if (sy > wp->saved_grid->sy) + screen_resize(s, sx, wp->saved_grid->sy); + + /* Restore the grid, cursor position and cell. */ + grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy); + s->cx = wp->saved_cx; + if (s->cx > screen_size_x(s) - 1) + s->cx = screen_size_x(s) - 1; + s->cy = wp->saved_cy; + if (s->cy > screen_size_y(s) - 1) + s->cy = screen_size_y(s) - 1; + memcpy(gc, &wp->saved_cell, sizeof *gc); + + /* + * Turn history back on (so resize can use it) and then resize back to + * the current size. + */ + wp->base.grid->flags |= GRID_HISTORY; + if (sy > wp->saved_grid->sy) + screen_resize(s, sx, sy); + + grid_destroy(wp->saved_grid); + wp->saved_grid = NULL; + + wp->flags |= PANE_REDRAW; +} + int window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode) { |