-/* $OpenBSD: cmd-select-layout.c,v 1.24 2014/10/20 22:34:31 nicm Exp $ */
+/* $OpenBSD: cmd-select-layout.c,v 1.25 2015/04/28 10:43:13 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
#include <sys/types.h>
+#include <stdlib.h>
+
#include "tmux.h"
/*
const struct cmd_entry cmd_select_layout_entry = {
"select-layout", "selectl",
- "npt:", 0, 1,
- "[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
+ "nopt:", 0, 1,
+ "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
0,
cmd_select_layout_exec
};
{
struct args *args = self->args;
struct winlink *wl;
+ struct window *w;
const char *layoutname;
+ char *oldlayout;
int next, previous, layout;
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
- server_unzoom_window(wl->window);
+ w = wl->window;
+
+ server_unzoom_window(w);
next = self->entry == &cmd_next_layout_entry;
- if (args_has(self->args, 'n'))
+ if (args_has(args, 'n'))
next = 1;
previous = self->entry == &cmd_previous_layout_entry;
- if (args_has(self->args, 'p'))
+ if (args_has(args, 'p'))
previous = 1;
+ oldlayout = w->old_layout;
+ w->old_layout = layout_dump(w->layout_root);
+
if (next || previous) {
if (next)
- layout = layout_set_next(wl->window);
+ layout_set_next(w);
else
- layout = layout_set_previous(wl->window);
- server_redraw_window(wl->window);
- return (CMD_RETURN_NORMAL);
+ layout_set_previous(w);
+ goto changed;
}
- if (args->argc == 0)
- layout = wl->window->lastlayout;
- else
- layout = layout_set_lookup(args->argv[0]);
- if (layout != -1) {
- layout = layout_set_select(wl->window, layout);
- server_redraw_window(wl->window);
- return (CMD_RETURN_NORMAL);
+ if (!args_has(args, 'o')) {
+ if (args->argc == 0)
+ layout = w->lastlayout;
+ else
+ layout = layout_set_lookup(args->argv[0]);
+ if (layout != -1) {
+ layout_set_select(w, layout);
+ goto changed;
+ }
}
- if (args->argc != 0) {
+ if (args->argc != 0)
layoutname = args->argv[0];
- if (layout_parse(wl->window, layoutname) == -1) {
+ else if (args_has(args, 'o'))
+ layoutname = oldlayout;
+ else
+ layoutname = NULL;
+
+ if (layoutname != NULL) {
+ if (layout_parse(w, layoutname) == -1) {
cmdq_error(cmdq, "can't set layout: %s", layoutname);
- return (CMD_RETURN_ERROR);
+ goto error;
}
- server_redraw_window(wl->window);
+ goto changed;
}
+
+ free(oldlayout);
return (CMD_RETURN_NORMAL);
+
+changed:
+ free(oldlayout);
+ server_redraw_window(w);
+ return (CMD_RETURN_NORMAL);
+
+error:
+ free(w->old_layout);
+ w->old_layout = oldlayout;
+ return (CMD_RETURN_ERROR);
}
-.\" $OpenBSD: tmux.1,v 1.423 2015/04/27 16:25:57 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.424 2015/04/28 10:43:14 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 27 2015 $
+.Dd $Mdocdate: April 28 2015 $
.Dt TMUX 1
.Os
.Sh NAME
.Em session
is chosen.
.Pp
-The following special tokens are available to indicate particular windows. Each
-has a single-character alternative form.
+The following special tokens are available to indicate particular windows.
+Each has a single-character alternative form.
.Bl -column "XXXXXXXXXX" "X"
.It Sy "Token" Ta Sy "" Ta Sy "Meaning"
.It Li "{start}" Ta "^" Ta "The lowest-numbered window"
.Fl U
or downward (numerically higher).
.It Xo Ic select-layout
-.Op Fl np
+.Op Fl nop
.Op Fl t Ar target-window
.Op Ar layout-name
.Xc
and
.Ic previous-layout
commands.
+.Fl o
+applies the last set layout if possible (undoes the most recent layout change).
.It Xo Ic select-pane
.Op Fl DdegLlRU
.Op Fl P Ar style