summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-capture-pane.c4
-rw-r--r--usr.bin/tmux/format.c10
-rw-r--r--usr.bin/tmux/input.c10
-rw-r--r--usr.bin/tmux/screen.c86
-rw-r--r--usr.bin/tmux/server-client.c4
-rw-r--r--usr.bin/tmux/tmux.h17
-rw-r--r--usr.bin/tmux/window.c81
7 files changed, 117 insertions, 95 deletions
diff --git a/usr.bin/tmux/cmd-capture-pane.c b/usr.bin/tmux/cmd-capture-pane.c
index cba0fb11061..3d45c3565ff 100644
--- a/usr.bin/tmux/cmd-capture-pane.c
+++ b/usr.bin/tmux/cmd-capture-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-capture-pane.c,v 1.50 2020/03/19 14:03:48 nicm Exp $ */
+/* $OpenBSD: cmd-capture-pane.c,v 1.51 2020/03/31 07:00:34 nicm Exp $ */
/*
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
@@ -118,7 +118,7 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
sx = screen_size_x(&wp->base);
if (args_has(args, 'a')) {
- gd = wp->saved_grid;
+ gd = wp->base.saved_grid;
if (gd == NULL) {
if (!args_has(args, 'q')) {
cmdq_error(item, "no alternate screen");
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 1bb60f13603..e5b01411955 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.230 2020/03/28 09:39:27 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.231 2020/03/31 07:00:34 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2729,9 +2729,11 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "scroll_region_upper", "%u", wp->base.rupper);
format_add(ft, "scroll_region_lower", "%u", wp->base.rlower);
- format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
- format_add(ft, "alternate_saved_x", "%u", wp->saved_cx);
- format_add(ft, "alternate_saved_y", "%u", wp->saved_cy);
+ format_add(ft, "alternate_on", "%d", wp->base.saved_grid != NULL);
+ if (wp->base.saved_cx != UINT_MAX)
+ format_add(ft, "alternate_saved_x", "%u", wp->base.saved_cx);
+ if (wp->base.saved_cy != UINT_MAX)
+ format_add(ft, "alternate_saved_y", "%u", wp->base.saved_cy);
format_add(ft, "cursor_flag", "%d",
!!(wp->base.mode & MODE_CURSOR));
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c
index fe94e34418f..c3325f5f24d 100644
--- a/usr.bin/tmux/input.c
+++ b/usr.bin/tmux/input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input.c,v 1.172 2020/03/31 06:35:38 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.173 2020/03/31 07:00:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1679,10 +1679,14 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
case 1047:
if (wp != NULL)
window_pane_alternate_off(wp, gc, 0);
+ else
+ screen_alternate_off(sctx->s, gc, 0);
break;
case 1049:
if (wp != NULL)
window_pane_alternate_off(wp, gc, 1);
+ else
+ screen_alternate_off(sctx->s, gc, 1);
break;
case 2004:
screen_write_mode_clear(sctx, MODE_BRACKETPASTE);
@@ -1780,10 +1784,14 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
case 1047:
if (wp != NULL)
window_pane_alternate_on(wp, gc, 0);
+ else
+ screen_alternate_on(sctx->s, gc, 0);
break;
case 1049:
if (wp != NULL)
window_pane_alternate_on(wp, gc, 1);
+ else
+ screen_alternate_on(sctx->s, gc, 1);
break;
case 2004:
screen_write_mode_set(sctx, MODE_BRACKETPASTE);
diff --git a/usr.bin/tmux/screen.c b/usr.bin/tmux/screen.c
index eeac3bf762b..e7437795c14 100644
--- a/usr.bin/tmux/screen.c
+++ b/usr.bin/tmux/screen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: screen.c,v 1.58 2020/02/05 13:06:49 nicm Exp $ */
+/* $OpenBSD: screen.c,v 1.59 2020/03/31 07:00:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -76,6 +76,8 @@ void
screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit)
{
s->grid = grid_create(sx, sy, hlimit);
+ s->saved_grid = NULL;
+
s->title = xstrdup("");
s->titles = NULL;
@@ -99,6 +101,11 @@ screen_reinit(struct screen *s)
s->mode = MODE_CURSOR | MODE_WRAP;
+ if (s->saved_grid != NULL)
+ screen_alternate_off(s, NULL, 0);
+ s->saved_cx = UINT_MAX;
+ s->saved_cy = UINT_MAX;
+
screen_reset_tabs(s);
grid_clear_lines(s->grid, s->grid->hsize, s->grid->sy, 8);
@@ -116,6 +123,8 @@ screen_free(struct screen *s)
free(s->title);
free(s->ccolour);
+ if (s->saved_grid != NULL)
+ grid_destroy(s->saved_grid);
grid_destroy(s->grid);
screen_free_titles(s);
@@ -502,3 +511,78 @@ screen_reflow(struct screen *s, u_int new_x)
log_debug("%s: reflow took %llu.%06u seconds", __func__,
(unsigned long long)tv.tv_sec, (u_int)tv.tv_usec);
}
+
+/*
+ * Enter alternative screen mode. A copy of the visible screen is saved and the
+ * history is not updated.
+ */
+void
+screen_alternate_on(struct screen *s, struct grid_cell *gc, int cursor)
+{
+ u_int sx, sy;
+
+ if (s->saved_grid != NULL)
+ return;
+ sx = screen_size_x(s);
+ sy = screen_size_y(s);
+
+ s->saved_grid = grid_create(sx, sy, 0);
+ grid_duplicate_lines(s->saved_grid, 0, s->grid, screen_hsize(s), sy);
+ if (cursor) {
+ s->saved_cx = s->cx;
+ s->saved_cy = s->cy;
+ }
+ memcpy(&s->saved_cell, gc, sizeof s->saved_cell);
+
+ grid_view_clear(s->grid, 0, 0, sx, sy, 8);
+
+ s->grid->flags &= ~GRID_HISTORY;
+}
+
+/* Exit alternate screen mode and restore the copied grid. */
+void
+screen_alternate_off(struct screen *s, struct grid_cell *gc, int cursor)
+{
+ u_int sx, sy;
+
+ /*
+ * Restore the cursor position and cell. This happens even if not
+ * currently in the alternate screen.
+ */
+ if (cursor && s->saved_cx != UINT_MAX && s->saved_cy != UINT_MAX) {
+ s->cx = s->saved_cx;
+ if (s->cx > screen_size_x(s) - 1)
+ s->cx = screen_size_x(s) - 1;
+ s->cy = s->saved_cy;
+ if (s->cy > screen_size_y(s) - 1)
+ s->cy = screen_size_y(s) - 1;
+ if (gc != NULL)
+ memcpy(gc, &s->saved_cell, sizeof *gc);
+ }
+
+ if (s->saved_grid == NULL)
+ 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 > s->saved_grid->sy)
+ screen_resize(s, sx, s->saved_grid->sy, 1);
+
+ /* Restore the saved grid. */
+ grid_duplicate_lines(s->grid, screen_hsize(s), s->saved_grid, 0, sy);
+
+ /*
+ * Turn history back on (so resize can use it) and then resize back to
+ * the current size.
+ */
+ s->grid->flags |= GRID_HISTORY;
+ if (sy > s->saved_grid->sy || sx != s->saved_grid->sx)
+ screen_resize(s, sx, sy, 1);
+
+ grid_destroy(s->saved_grid);
+ s->saved_grid = NULL;
+}
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index cf5a0a52791..7811df2b3a8 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.309 2020/03/24 08:09:44 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.310 2020/03/31 07:00:34 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1400,7 +1400,7 @@ server_client_resize_event(__unused int fd, __unused short events, void *data)
log_debug("%s: %%%u timer fired (was%s resized)", __func__, wp->id,
(wp->flags & PANE_RESIZED) ? "" : " not");
- if (wp->saved_grid == NULL && (wp->flags & PANE_RESIZED)) {
+ if (wp->base.saved_grid == NULL && (wp->flags & PANE_RESIZED)) {
log_debug("%s: %%%u deferring timer", __func__, wp->id);
server_client_start_resize_timer(wp);
} else if (!server_client_resize_force(wp)) {
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index fd7d74f16b6..36a0bb87b08 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.968 2020/03/31 06:35:38 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.969 2020/03/31 07:00:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -754,8 +754,12 @@ struct screen {
int mode;
- bitstr_t *tabs;
+ u_int saved_cx;
+ u_int saved_cy;
+ struct grid *saved_grid;
+ struct grid_cell saved_cell;
+ bitstr_t *tabs;
struct screen_sel *sel;
};
@@ -917,12 +921,6 @@ struct window_pane {
struct screen status_screen;
size_t status_size;
- /* Saved in alternative screen mode. */
- u_int saved_cx;
- u_int saved_cy;
- struct grid *saved_grid;
- struct grid_cell saved_cell;
-
TAILQ_HEAD (, window_mode_entry) modes;
struct event modetimer;
time_t modelast;
@@ -2459,6 +2457,9 @@ void screen_hide_selection(struct screen *);
int screen_check_selection(struct screen *, u_int, u_int);
void screen_select_cell(struct screen *, struct grid_cell *,
const struct grid_cell *);
+void screen_alternate_on(struct screen *, struct grid_cell *, int);
+void screen_alternate_off(struct screen *, struct grid_cell *, int);
+
/* window.c */
extern struct windows windows;
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index f93696b92f8..697f0cc03cc 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.251 2020/03/31 06:35:38 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.252 2020/03/31 07:00:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -879,10 +879,6 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->pipe_off = 0;
wp->pipe_event = NULL;
- wp->saved_grid = NULL;
- wp->saved_cx = UINT_MAX;
- wp->saved_cy = UINT_MAX;
-
screen_init(&wp->base, sx, sy, hlimit);
wp->screen = &wp->base;
@@ -910,8 +906,6 @@ window_pane_destroy(struct window_pane *wp)
screen_free(&wp->status_screen);
screen_free(&wp->base);
- if (wp->saved_grid != NULL)
- grid_destroy(wp->saved_grid);
if (wp->pipe_fd != -1) {
bufferevent_free(wp->pipe_event);
@@ -989,7 +983,7 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
wp->sy = sy;
log_debug("%s: %%%u resize %ux%u", __func__, wp->id, sx, sy);
- screen_resize(&wp->base, sx, sy, wp->saved_grid == NULL);
+ screen_resize(&wp->base, sx, sy, wp->base.saved_grid == NULL);
wme = TAILQ_FIRST(&wp->modes);
if (wme != NULL && wme->mode->resize != NULL)
@@ -998,90 +992,23 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
wp->flags |= (PANE_RESIZE|PANE_RESIZED);
}
-/*
- * 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,
int cursor)
{
- struct screen *s = &wp->base;
- u_int sx, sy;
-
- if (wp->saved_grid != NULL)
- return;
if (!options_get_number(wp->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);
- if (cursor) {
- 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, 8);
-
- wp->base.grid->flags &= ~GRID_HISTORY;
-
+ screen_alternate_on(&wp->base, gc, cursor);
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,
int cursor)
{
- struct screen *s = &wp->base;
- u_int sx, sy;
-
if (!options_get_number(wp->options, "alternate-screen"))
return;
-
- /*
- * Restore the cursor position and cell. This happens even if not
- * currently in the alternate screen.
- */
- if (cursor && wp->saved_cx != UINT_MAX && wp->saved_cy != UINT_MAX) {
- 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);
- }
-
- if (wp->saved_grid == NULL)
- 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, 1);
-
- /* Restore the saved grid. */
- grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy);
-
- /*
- * 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 || sx != wp->saved_grid->sx)
- screen_resize(s, sx, sy, 1);
-
- grid_destroy(wp->saved_grid);
- wp->saved_grid = NULL;
-
+ screen_alternate_off(&wp->base, gc, cursor);
wp->flags |= PANE_REDRAW;
}