2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-10-16 19:04:05 +00:00
|
|
|
static enum cmd_retval cmd_select_layout_exec(struct cmd *,
|
|
|
|
struct cmdq_item *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
const struct cmd_entry cmd_select_layout_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "select-layout",
|
|
|
|
.alias = "selectl",
|
|
|
|
|
|
|
|
.args = { "nopt:", 0, 1 },
|
|
|
|
.usage = "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
|
|
|
|
2015-12-14 00:31:54 +00:00
|
|
|
.tflag = CMD_WINDOW,
|
|
|
|
|
2016-10-14 22:14:22 +00:00
|
|
|
.flags = CMD_AFTERHOOK,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = 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 = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "next-layout",
|
|
|
|
.alias = "nextl",
|
|
|
|
|
|
|
|
.args = { "t:", 0, 0 },
|
|
|
|
.usage = CMD_TARGET_WINDOW_USAGE,
|
|
|
|
|
2015-12-14 00:31:54 +00:00
|
|
|
.tflag = CMD_WINDOW,
|
|
|
|
|
2016-10-14 22:14:22 +00:00
|
|
|
.flags = CMD_AFTERHOOK,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_select_layout_exec
|
2011-01-04 02:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct cmd_entry cmd_previous_layout_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "previous-layout",
|
|
|
|
.alias = "prevl",
|
|
|
|
|
|
|
|
.args = { "t:", 0, 0 },
|
|
|
|
.usage = CMD_TARGET_WINDOW_USAGE,
|
|
|
|
|
2015-12-14 00:31:54 +00:00
|
|
|
.tflag = CMD_WINDOW,
|
|
|
|
|
2016-10-14 22:14:22 +00:00
|
|
|
.flags = CMD_AFTERHOOK,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_select_layout_exec
|
2011-01-04 02:03:41 +00:00
|
|
|
};
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static enum cmd_retval
|
2016-10-16 19:04:05 +00:00
|
|
|
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2011-01-04 00:42:46 +00:00
|
|
|
struct args *args = self->args;
|
2016-10-16 19:04:05 +00:00
|
|
|
struct winlink *wl = item->state.tflag.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
|
|
|
|
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) {
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "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
|
|
|
}
|