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",
|
|
|
|
|
2021-08-21 10:22:38 +00:00
|
|
|
.args = { "Enopt:", 0, 1, NULL },
|
2017-11-15 19:59:27 +00:00
|
|
|
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
2015-12-13 21:53:57 +00:00
|
|
|
|
2017-11-15 19:59:27 +00:00
|
|
|
.target = { 't', CMD_FIND_PANE, 0 },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
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",
|
|
|
|
|
2021-08-21 10:22:38 +00:00
|
|
|
.args = { "t:", 0, 0, NULL },
|
2015-12-13 21:53:57 +00:00
|
|
|
.usage = CMD_TARGET_WINDOW_USAGE,
|
|
|
|
|
2017-04-22 10:22:39 +00:00
|
|
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
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",
|
|
|
|
|
2021-08-21 10:22:38 +00:00
|
|
|
.args = { "t:", 0, 0, NULL },
|
2015-12-13 21:53:57 +00:00
|
|
|
.usage = CMD_TARGET_WINDOW_USAGE,
|
|
|
|
|
2017-04-22 10:22:39 +00:00
|
|
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
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
|
|
|
{
|
2020-04-13 08:26:27 +00:00
|
|
|
struct args *args = cmd_get_args(self);
|
2020-04-13 10:59:58 +00:00
|
|
|
struct cmd_find_state *target = cmdq_get_target(item);
|
|
|
|
struct winlink *wl = target->wl;
|
2017-11-15 19:59:27 +00:00
|
|
|
struct window *w = wl->window;
|
2020-04-13 10:59:58 +00:00
|
|
|
struct window_pane *wp = target->wp;
|
2017-11-15 19:59:27 +00:00
|
|
|
const char *layoutname;
|
|
|
|
char *oldlayout;
|
|
|
|
int next, previous, layout;
|
|
|
|
|
2015-04-28 10:43:13 +00:00
|
|
|
server_unzoom_window(w);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-04-13 08:26:27 +00:00
|
|
|
next = (cmd_get_entry(self) == &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;
|
2020-04-13 08:26:27 +00:00
|
|
|
previous = (cmd_get_entry(self) == &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
|
|
|
}
|
|
|
|
|
2017-11-15 19:59:27 +00:00
|
|
|
if (args_has(args, 'E')) {
|
|
|
|
layout_spread_out(wp);
|
|
|
|
goto changed;
|
|
|
|
}
|
|
|
|
|
2021-08-20 19:50:16 +00:00
|
|
|
if (args_count(args) != 0)
|
|
|
|
layoutname = args_string(args, 0);
|
|
|
|
else if (args_has(args, 'o'))
|
|
|
|
layoutname = oldlayout;
|
|
|
|
else
|
|
|
|
layoutname = NULL;
|
|
|
|
|
2015-04-28 10:43:13 +00:00
|
|
|
if (!args_has(args, 'o')) {
|
2021-08-20 19:50:16 +00:00
|
|
|
if (layoutname == NULL)
|
2015-04-28 10:43:13 +00:00
|
|
|
layout = w->lastlayout;
|
|
|
|
else
|
2021-08-20 19:50:16 +00:00
|
|
|
layout = layout_set_lookup(layoutname);
|
2015-04-28 10:43:13 +00:00
|
|
|
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 (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);
|
2019-04-17 14:43:49 +00:00
|
|
|
recalculate_sizes();
|
2015-04-28 10:43:13 +00:00
|
|
|
server_redraw_window(w);
|
2018-07-02 12:39:14 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2015-04-28 10:43:13 +00:00
|
|
|
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
|
|
|
}
|