diff options
author | 2012-04-01 13:18:38 +0000 | |
---|---|---|
committer | 2012-04-01 13:18:38 +0000 | |
commit | 1153997f8fb810ab327ebf6268218c96ae67f1d9 (patch) | |
tree | 79c0d2bff7300cc199b67d336170d65df00bfe8f | |
parent | Update termtypes.master to terminfo.src from ncurses-5.9-20120331. (diff) | |
download | wireguard-openbsd-1153997f8fb810ab327ebf6268218c96ae67f1d9.tar.xz wireguard-openbsd-1153997f8fb810ab327ebf6268218c96ae67f1d9.zip |
Add a layout history which can be stepped through with select-layout -u
and -U commands (bound to 'u' and 'U' by default).
-rw-r--r-- | usr.bin/tmux/cmd-resize-pane.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-select-layout.c | 49 | ||||
-rw-r--r-- | usr.bin/tmux/key-bindings.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/layout.c | 74 | ||||
-rw-r--r-- | usr.bin/tmux/options-table.c | 9 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 18 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 18 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 3 |
8 files changed, 157 insertions, 21 deletions
diff --git a/usr.bin/tmux/cmd-resize-pane.c b/usr.bin/tmux/cmd-resize-pane.c index 200d0edf7fd..5e17324e93b 100644 --- a/usr.bin/tmux/cmd-resize-pane.c +++ b/usr.bin/tmux/cmd-resize-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-resize-pane.c,v 1.9 2011/01/04 00:42:47 nicm Exp $ */ +/* $OpenBSD: cmd-resize-pane.c,v 1.10 2012/04/01 13:18:38 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -103,6 +103,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx) } } + layout_list_add(wp->window); if (args_has(self->args, 'L')) layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust); else if (args_has(self->args, 'R')) diff --git a/usr.bin/tmux/cmd-select-layout.c b/usr.bin/tmux/cmd-select-layout.c index 66a1e94176f..722ef3ec825 100644 --- a/usr.bin/tmux/cmd-select-layout.c +++ b/usr.bin/tmux/cmd-select-layout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-select-layout.c,v 1.13 2012/01/30 20:57:02 nicm Exp $ */ +/* $OpenBSD: cmd-select-layout.c,v 1.14 2012/04/01 13:18:38 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -29,8 +29,8 @@ int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_select_layout_entry = { "select-layout", "selectl", - "npt:", 0, 1, - "[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]", + "nprut:", 0, 1, + "[-npUu] " CMD_TARGET_WINDOW_USAGE " [layout-name]", 0, cmd_select_layout_key_binding, NULL, @@ -76,6 +76,14 @@ cmd_select_layout_key_binding(struct cmd *self, int key) case '5' | KEYC_ESCAPE: self->args = args_create(1, "tiled"); break; + case 'u': + self->args = args_create(0); + args_set(self->args, 'u', NULL); + break; + case 'U': + self->args = args_create(0); + args_set(self->args, 'U', NULL); + break; default: self->args = args_create(0); break; @@ -87,11 +95,13 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct winlink *wl; + struct window *w; const char *layoutname; int next, previous, layout; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (-1); + w = wl->window; next = self->entry == &cmd_next_layout_entry; if (args_has(self->args, 'n')) @@ -100,6 +110,21 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(self->args, 'p')) previous = 1; + layout_list_add(w); + if (args_has(self->args, 'U')) { + if ((layoutname = layout_list_redo(w)) == NULL) { + ctx->error(ctx, "no more layout history"); + return (-1); + } + goto set_layout; + } else if (args_has(self->args, 'u')) { + if ((layoutname = layout_list_undo(w)) == NULL) { + ctx->error(ctx, "no more layout history"); + return (-1); + } + goto set_layout; + } + if (next || previous) { if (next) layout = layout_set_next(wl->window); @@ -121,16 +146,16 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx) return (0); } - if (args->argc != 0) { - layoutname = args->argv[0]; - if (layout_parse(wl->window, layoutname) == -1) { - ctx->error(ctx, "can't set layout: %s", layoutname); - return (-1); - } - server_redraw_window(wl->window); - ctx->info(ctx, "arranging in: %s", layoutname); + if (args->argc == 0) return (0); - } + layoutname = args->argv[0]; +set_layout: + if (layout_parse(wl->window, layoutname) == -1) { + ctx->error(ctx, "can't set layout: %s", layoutname); + return (-1); + } + server_redraw_window(wl->window); + ctx->info(ctx, "arranging in: %s", layoutname); return (0); } diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c index fb9268427c1..3413f247663 100644 --- a/usr.bin/tmux/key-bindings.c +++ b/usr.bin/tmux/key-bindings.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key-bindings.c,v 1.29 2012/01/21 11:12:13 nicm Exp $ */ +/* $OpenBSD: key-bindings.c,v 1.30 2012/04/01 13:18:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -130,6 +130,7 @@ key_bindings_init(void) { '?', 0, &cmd_list_keys_entry }, { 'D', 0, &cmd_choose_client_entry }, { 'L', 0, &cmd_switch_client_entry }, + { 'U', 1, &cmd_select_layout_entry }, { '[', 0, &cmd_copy_mode_entry }, { '\'', 0, &cmd_command_prompt_entry }, { '\002', /* C-b */ 0, &cmd_send_prefix_entry }, @@ -148,6 +149,7 @@ key_bindings_init(void) { 'r', 0, &cmd_refresh_client_entry }, { 's', 0, &cmd_choose_session_entry }, { 't', 0, &cmd_clock_mode_entry }, + { 'u', 1, &cmd_select_layout_entry }, { 'w', 0, &cmd_choose_window_entry }, { 'x', 0, &cmd_confirm_before_entry }, { '{', 0, &cmd_swap_pane_entry }, diff --git a/usr.bin/tmux/layout.c b/usr.bin/tmux/layout.c index 80dbe373aa2..69e1a3215ee 100644 --- a/usr.bin/tmux/layout.c +++ b/usr.bin/tmux/layout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: layout.c,v 1.10 2012/03/17 22:35:09 nicm Exp $ */ +/* $OpenBSD: layout.c,v 1.11 2012/04/01 13:18:38 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -19,6 +19,7 @@ #include <sys/types.h> #include <stdlib.h> +#include <string.h> #include "tmux.h" @@ -745,3 +746,74 @@ layout_close_pane(struct window_pane *wp) } notify_window_layout_changed(wp->window); } + +/* Add layout to list. */ +void +layout_list_add(struct window *w) +{ + struct last_layout *ll, *ll_last; + char *layout; + u_int limit; + + layout = layout_dump(w); + + ll_last = w->layout_list_last; + if (ll_last != NULL && strcmp(ll_last->layout, layout) == 0) { + free(layout); + return; + } + + ll = xmalloc(sizeof *ll); + ll->layout = layout; + if (ll_last == NULL) + TAILQ_INSERT_TAIL(&w->layout_list, ll, entry); + else + TAILQ_INSERT_AFTER(&w->layout_list, ll_last, ll, entry); + w->layout_list_size++; + w->layout_list_last = ll; + + limit = options_get_number(&w->options, "layout-history"); + while (w->layout_list_size > limit) { + ll = TAILQ_LAST(&w->layout_list, last_layouts); + if (ll == w->layout_list_last) + ll = TAILQ_FIRST(&w->layout_list); + + TAILQ_REMOVE(&w->layout_list, ll, entry); + w->layout_list_size--; + + xfree(ll->layout); + xfree(ll); + } +} + +/* Apply next layout from list. */ +const char * +layout_list_redo(struct window *w) +{ + struct last_layout *ll, *ll_last; + + ll_last = w->layout_list_last; + if (ll_last == NULL) + return (NULL); + ll = TAILQ_NEXT(ll_last, entry); + if (ll == NULL) + return (NULL); + w->layout_list_last = ll; + return (ll->layout); +} + +/* Apply previous layout from list. */ +const char * +layout_list_undo(struct window *w) +{ + struct last_layout *ll, *ll_last; + + ll_last = w->layout_list_last; + if (ll_last == NULL) + return (NULL); + ll = TAILQ_PREV(ll_last, last_layouts, entry); + if (ll == NULL) + return (NULL); + w->layout_list_last = ll; + return (ll->layout); +} diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index eba6278d9e8..0b754747f90 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.26 2012/03/20 11:23:12 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.27 2012/04/01 13:18:38 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net> @@ -505,6 +505,13 @@ const struct options_table_entry window_options_table[] = { .default_num = 0 }, + { .name = "layout-history-limit", + .type = OPTIONS_TABLE_NUMBER, + .minimum = 1, + .maximum = USHRT_MAX, + .default_num = 20 + }, + { .name = "main-pane-height", .type = OPTIONS_TABLE_NUMBER, .minimum = 1, diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 91e33ac70d0..dfac587acdf 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.287 2012/04/01 10:42:39 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.288 2012/04/01 13:18:38 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -1451,7 +1451,7 @@ lower) with .Fl U or downward (numerically higher). .It Xo Ic select-layout -.Op Fl np +.Op Fl npUu .Op Fl t Ar target-window .Op Ar layout-name .Xc @@ -1468,6 +1468,13 @@ are equivalent to the and .Ic previous-layout commands. +.Pp +.Fl U +and +.Fl u +step forward and back through previous layouts, up to the maximum set by the +.Ic layout-history-limit +option. .It Xo Ic select-pane .Op Fl lDLRU .Op Fl t Ar target-pane @@ -2509,6 +2516,13 @@ or .Ar height . A value of zero restores the default unlimited setting. .Pp +.It Ic layout-history-limit Ar limit +Set the number of previous layouts stored for recovery with +.Ic select-layout +.Fl U +and +.Fl u . +.Pp .It Ic main-pane-height Ar height .It Ic main-pane-width Ar width Set the width or height of the main (left or top) pane in the diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 1eeda60fabf..de14db1a5c2 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.325 2012/03/20 11:01:00 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.326 2012/04/01 13:18:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -851,6 +851,13 @@ struct window_pane { TAILQ_HEAD(window_panes, window_pane); RB_HEAD(window_pane_tree, window_pane); +/* Window last layout. */ +struct last_layout { + char *layout; + + TAILQ_ENTRY(last_layout) entry; +}; + /* Window structure. */ struct window { u_int id; @@ -864,6 +871,9 @@ struct window { int lastlayout; struct layout_cell *layout_root; + TAILQ_HEAD(last_layouts, last_layout) layout_list; + u_int layout_list_size; + struct last_layout *layout_list_last; u_int sx; u_int sy; @@ -1998,7 +2008,8 @@ u_int layout_count_cells(struct layout_cell *); struct layout_cell *layout_create_cell(struct layout_cell *); void layout_free_cell(struct layout_cell *); void layout_print_cell(struct layout_cell *, const char *, u_int); -void layout_destroy_cell(struct layout_cell *, struct layout_cell **); +void layout_destroy_cell( + struct layout_cell *, struct layout_cell **); void layout_set_size( struct layout_cell *, u_int, u_int, u_int, u_int); void layout_make_leaf( @@ -2020,6 +2031,9 @@ void layout_assign_pane(struct layout_cell *, struct window_pane *); struct layout_cell *layout_split_pane( struct window_pane *, enum layout_type, int, int); void layout_close_pane(struct window_pane *); +void layout_list_add(struct window *); +const char *layout_list_redo(struct window *); +const char *layout_list_undo(struct window *); /* layout-custom.c */ char *layout_dump(struct window *); diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 0291ee1532b..94a059dc4d6 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.76 2012/03/20 14:06:44 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.77 2012/04/01 13:18:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -292,6 +292,7 @@ window_create1(u_int sx, u_int sy) w->lastlayout = -1; w->layout_root = NULL; + TAILQ_INIT(&w->layout_list); w->sx = sx; w->sy = sy; |