2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2015-04-28 10:43:13 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch window to selected layout.
|
|
|
|
*/
|
|
|
|
|
2013-03-24 09:54:10 +00:00
|
|
|
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
const struct cmd_entry cmd_select_layout_entry = {
|
|
|
|
"select-layout", "selectl",
|
2015-04-28 10:43:13 +00:00
|
|
|
"nopt:", 0, 1,
|
|
|
|
"[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
2014-10-20 22:34:31 +00:00
|
|
|
0,
|
2011-01-04 00:42:46 +00:00
|
|
|
cmd_select_layout_exec
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2011-01-04 02:03:41 +00:00
|
|
|
const struct cmd_entry cmd_next_layout_entry = {
|
|
|
|
"next-layout", "nextl",
|
|
|
|
"t:", 0, 0,
|
|
|
|
CMD_TARGET_WINDOW_USAGE,
|
|
|
|
0,
|
|
|
|
cmd_select_layout_exec
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct cmd_entry cmd_previous_layout_entry = {
|
|
|
|
"previous-layout", "prevl",
|
|
|
|
"t:", 0, 0,
|
|
|
|
CMD_TARGET_WINDOW_USAGE,
|
|
|
|
0,
|
|
|
|
cmd_select_layout_exec
|
|
|
|
};
|
|
|
|
|
2012-07-11 07:10:15 +00:00
|
|
|
enum cmd_retval
|
2013-03-24 09:54:10 +00:00
|
|
|
cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2011-01-04 00:42:46 +00:00
|
|
|
struct args *args = self->args;
|
|
|
|
struct winlink *wl;
|
2015-04-28 10:43:13 +00:00
|
|
|
struct window *w;
|
2011-01-04 00:42:46 +00:00
|
|
|
const char *layoutname;
|
2015-04-28 10:43:13 +00:00
|
|
|
char *oldlayout;
|
2011-01-04 02:03:41 +00:00
|
|
|
int next, previous, layout;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2013-03-24 09:54:10 +00:00
|
|
|
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2015-04-28 10:43:13 +00:00
|
|
|
w = wl->window;
|
|
|
|
|
|
|
|
server_unzoom_window(w);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2011-01-04 02:03:41 +00:00
|
|
|
next = self->entry == &cmd_next_layout_entry;
|
2015-04-28 10:43:13 +00:00
|
|
|
if (args_has(args, 'n'))
|
2011-01-04 02:03:41 +00:00
|
|
|
next = 1;
|
|
|
|
previous = self->entry == &cmd_previous_layout_entry;
|
2015-04-28 10:43:13 +00:00
|
|
|
if (args_has(args, 'p'))
|
2011-01-04 02:03:41 +00:00
|
|
|
previous = 1;
|
|
|
|
|
2015-04-28 10:43:13 +00:00
|
|
|
oldlayout = w->old_layout;
|
|
|
|
w->old_layout = layout_dump(w->layout_root);
|
|
|
|
|
2011-01-04 02:03:41 +00:00
|
|
|
if (next || previous) {
|
|
|
|
if (next)
|
2015-04-28 10:43:13 +00:00
|
|
|
layout_set_next(w);
|
2011-01-04 02:03:41 +00:00
|
|
|
else
|
2015-04-28 10:43:13 +00:00
|
|
|
layout_set_previous(w);
|
|
|
|
goto changed;
|
2011-01-04 02:03:41 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 10:43:13 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-01-04 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 10:43:13 +00:00
|
|
|
if (args->argc != 0)
|
2013-01-17 00:11:22 +00:00
|
|
|
layoutname = args->argv[0];
|
2015-04-28 10:43:13 +00:00
|
|
|
else if (args_has(args, 'o'))
|
|
|
|
layoutname = oldlayout;
|
|
|
|
else
|
|
|
|
layoutname = NULL;
|
|
|
|
|
|
|
|
if (layoutname != NULL) {
|
|
|
|
if (layout_parse(w, layoutname) == -1) {
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_error(cmdq, "can't set layout: %s", layoutname);
|
2015-04-28 10:43:13 +00:00
|
|
|
goto error;
|
2013-01-17 00:11:22 +00:00
|
|
|
}
|
2015-04-28 10:43:13 +00:00
|
|
|
goto changed;
|
2012-04-01 13:18:38 +00:00
|
|
|
}
|
2015-04-28 10:43:13 +00:00
|
|
|
|
|
|
|
free(oldlayout);
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2015-04-28 10:43:13 +00:00
|
|
|
|
|
|
|
changed:
|
|
|
|
free(oldlayout);
|
|
|
|
server_redraw_window(w);
|
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
|
|
|
|
error:
|
|
|
|
free(w->old_layout);
|
|
|
|
w->old_layout = oldlayout;
|
|
|
|
return (CMD_RETURN_ERROR);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|