summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/layout.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2012-04-01 13:18:38 +0000
committernicm <nicm@openbsd.org>2012-04-01 13:18:38 +0000
commit1153997f8fb810ab327ebf6268218c96ae67f1d9 (patch)
tree79c0d2bff7300cc199b67d336170d65df00bfe8f /usr.bin/tmux/layout.c
parentUpdate termtypes.master to terminfo.src from ncurses-5.9-20120331. (diff)
downloadwireguard-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).
Diffstat (limited to 'usr.bin/tmux/layout.c')
-rw-r--r--usr.bin/tmux/layout.c74
1 files changed, 73 insertions, 1 deletions
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);
+}