2010-01-07 20:52:18 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2012-03-03 08:31:18 +00:00
|
|
|
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2010-01-07 20:52:18 +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>
|
|
|
|
|
|
|
|
#include <paths.h>
|
|
|
|
#include <stdlib.h>
|
2019-10-15 08:25:37 +00:00
|
|
|
#include <string.h>
|
2010-01-07 20:52:18 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
2012-03-03 08:31:18 +00:00
|
|
|
* Join or move a pane into another (like split/swap/kill).
|
2010-01-07 20:52:18 +00:00
|
|
|
*/
|
|
|
|
|
2016-10-16 19:04:05 +00:00
|
|
|
static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmdq_item *);
|
2012-03-03 08:31:18 +00:00
|
|
|
|
2010-01-07 20:52:18 +00:00
|
|
|
const struct cmd_entry cmd_join_pane_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "join-pane",
|
|
|
|
.alias = "joinp",
|
|
|
|
|
2021-08-21 10:22:38 +00:00
|
|
|
.args = { "bdfhvp:l:s:t:", 0, 0, NULL },
|
2019-11-18 09:43:31 +00:00
|
|
|
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
2015-12-13 21:53:57 +00:00
|
|
|
|
2017-04-22 10:22:39 +00:00
|
|
|
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
|
|
|
.target = { 't', CMD_FIND_PANE, 0 },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
|
|
|
.flags = 0,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_join_pane_exec
|
2010-01-07 20:52:18 +00:00
|
|
|
};
|
|
|
|
|
2012-03-03 08:31:18 +00:00
|
|
|
const struct cmd_entry cmd_move_pane_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "move-pane",
|
|
|
|
.alias = "movep",
|
|
|
|
|
2021-08-21 10:22:38 +00:00
|
|
|
.args = { "bdfhvp:l:s:t:", 0, 0, NULL },
|
2020-04-22 21:15:33 +00:00
|
|
|
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
2015-12-13 21:53:57 +00:00
|
|
|
|
2020-01-02 13:44:17 +00:00
|
|
|
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
2017-04-22 10:22:39 +00:00
|
|
|
.target = { 't', CMD_FIND_PANE, 0 },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
|
|
|
.flags = 0,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_join_pane_exec
|
2012-03-03 08:31:18 +00:00
|
|
|
};
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static enum cmd_retval
|
2016-10-16 19:04:05 +00:00
|
|
|
cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
2010-01-07 20:52:18 +00:00
|
|
|
{
|
2020-04-13 08:26:27 +00:00
|
|
|
struct args *args = cmd_get_args(self);
|
2020-04-13 14:46:04 +00:00
|
|
|
struct cmd_find_state *current = cmdq_get_current(item);
|
2020-04-13 10:59:58 +00:00
|
|
|
struct cmd_find_state *target = cmdq_get_target(item);
|
|
|
|
struct cmd_find_state *source = cmdq_get_source(item);
|
2011-01-04 00:42:46 +00:00
|
|
|
struct session *dst_s;
|
|
|
|
struct winlink *src_wl, *dst_wl;
|
|
|
|
struct window *src_w, *dst_w;
|
|
|
|
struct window_pane *src_wp, *dst_wp;
|
2020-03-21 13:16:15 +00:00
|
|
|
char *cause = NULL;
|
2022-06-07 10:02:19 +00:00
|
|
|
int size, dst_idx;
|
2019-10-15 08:25:37 +00:00
|
|
|
int flags;
|
2011-01-04 00:42:46 +00:00
|
|
|
enum layout_type type;
|
|
|
|
struct layout_cell *lc;
|
2022-06-07 10:02:19 +00:00
|
|
|
u_int curval = 0;
|
2016-10-10 21:51:39 +00:00
|
|
|
|
2020-04-13 10:59:58 +00:00
|
|
|
dst_s = target->s;
|
|
|
|
dst_wl = target->wl;
|
|
|
|
dst_wp = target->wp;
|
2010-01-07 20:52:18 +00:00
|
|
|
dst_w = dst_wl->window;
|
2010-04-17 23:14:17 +00:00
|
|
|
dst_idx = dst_wl->idx;
|
2013-03-24 09:57:59 +00:00
|
|
|
server_unzoom_window(dst_w);
|
2010-01-07 20:52:18 +00:00
|
|
|
|
2020-04-13 10:59:58 +00:00
|
|
|
src_wl = source->wl;
|
|
|
|
src_wp = source->wp;
|
2010-01-07 20:52:18 +00:00
|
|
|
src_w = src_wl->window;
|
2013-03-24 09:57:59 +00:00
|
|
|
server_unzoom_window(src_w);
|
2010-01-07 20:52:18 +00:00
|
|
|
|
2020-04-22 21:15:33 +00:00
|
|
|
if (src_wp == dst_wp) {
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "source and target panes must be different");
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2012-03-03 08:31:18 +00:00
|
|
|
}
|
2010-01-07 20:52:18 +00:00
|
|
|
|
|
|
|
type = LAYOUT_TOPBOTTOM;
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(args, 'h'))
|
2010-01-07 20:52:18 +00:00
|
|
|
type = LAYOUT_LEFTRIGHT;
|
|
|
|
|
2022-06-07 10:02:19 +00:00
|
|
|
/* If the 'p' flag is dropped then this bit can be moved into 'l'. */
|
|
|
|
if (args_has(args, 'l') || args_has(args, 'p')) {
|
|
|
|
if (args_has(args, 'f')) {
|
|
|
|
if (type == LAYOUT_TOPBOTTOM)
|
|
|
|
curval = dst_w->sy;
|
|
|
|
else
|
|
|
|
curval = dst_w->sx;
|
2019-10-15 08:25:37 +00:00
|
|
|
} else {
|
2020-03-21 13:16:15 +00:00
|
|
|
if (type == LAYOUT_TOPBOTTOM)
|
2022-06-07 10:02:19 +00:00
|
|
|
curval = dst_wp->sy;
|
2020-03-21 13:16:15 +00:00
|
|
|
else
|
2022-06-07 10:02:19 +00:00
|
|
|
curval = dst_wp->sx;
|
2011-01-04 00:42:46 +00:00
|
|
|
}
|
2020-03-21 13:16:15 +00:00
|
|
|
}
|
2022-06-07 10:02:19 +00:00
|
|
|
|
|
|
|
size = -1;
|
|
|
|
if (args_has(args, 'l')) {
|
|
|
|
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
|
|
|
|
item, &cause);
|
|
|
|
} else if (args_has(args, 'p')) {
|
|
|
|
size = args_strtonum_and_expand(args, 'l', 0, 100, item,
|
|
|
|
&cause);
|
|
|
|
if (cause == NULL)
|
|
|
|
size = curval * size / 100;
|
|
|
|
}
|
2020-03-21 13:16:15 +00:00
|
|
|
if (cause != NULL) {
|
|
|
|
cmdq_error(item, "size %s", cause);
|
|
|
|
free(cause);
|
|
|
|
return (CMD_RETURN_ERROR);
|
2010-01-07 20:52:18 +00:00
|
|
|
}
|
2019-11-18 09:43:31 +00:00
|
|
|
|
|
|
|
flags = 0;
|
2019-04-17 14:37:48 +00:00
|
|
|
if (args_has(args, 'b'))
|
2019-11-18 09:43:31 +00:00
|
|
|
flags |= SPAWN_BEFORE;
|
|
|
|
if (args_has(args, 'f'))
|
|
|
|
flags |= SPAWN_FULLSIZE;
|
|
|
|
|
2019-04-17 14:37:48 +00:00
|
|
|
lc = layout_split_pane(dst_wp, type, size, flags);
|
2012-03-03 08:31:18 +00:00
|
|
|
if (lc == NULL) {
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "create pane failed: pane too small");
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2010-01-07 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
layout_close_pane(src_wp);
|
|
|
|
|
2020-05-16 16:20:59 +00:00
|
|
|
server_client_remove_pane(src_wp);
|
2014-04-17 09:13:13 +00:00
|
|
|
window_lost_pane(src_w, src_wp);
|
2010-01-07 20:52:18 +00:00
|
|
|
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
|
|
|
|
|
|
|
src_wp->window = dst_w;
|
2019-06-20 11:59:59 +00:00
|
|
|
options_set_parent(src_wp->options, dst_w->options);
|
|
|
|
src_wp->flags |= PANE_STYLECHANGED;
|
2021-01-06 07:32:23 +00:00
|
|
|
if (flags & SPAWN_BEFORE)
|
|
|
|
TAILQ_INSERT_BEFORE(dst_wp, src_wp, entry);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
2021-03-11 06:31:05 +00:00
|
|
|
layout_assign_pane(lc, src_wp, 0);
|
2023-01-17 06:50:55 +00:00
|
|
|
colour_palette_from_option(&src_wp->palette, src_wp->options);
|
2010-01-07 20:52:18 +00:00
|
|
|
|
|
|
|
recalculate_sizes();
|
|
|
|
|
|
|
|
server_redraw_window(src_w);
|
|
|
|
server_redraw_window(dst_w);
|
|
|
|
|
2011-01-04 00:42:46 +00:00
|
|
|
if (!args_has(args, 'd')) {
|
2019-04-17 14:37:48 +00:00
|
|
|
window_set_active_pane(dst_w, src_wp, 1);
|
2010-04-17 23:14:17 +00:00
|
|
|
session_select(dst_s, dst_idx);
|
2017-08-30 10:33:57 +00:00
|
|
|
cmd_find_from_session(current, dst_s, 0);
|
2010-01-07 20:52:18 +00:00
|
|
|
server_redraw_session(dst_s);
|
|
|
|
} else
|
|
|
|
server_status_session(dst_s);
|
|
|
|
|
2016-08-27 23:35:00 +00:00
|
|
|
if (window_count_panes(src_w) == 0)
|
2020-07-04 14:24:02 +00:00
|
|
|
server_kill_window(src_w, 1);
|
2016-08-27 23:35:00 +00:00
|
|
|
else
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_window("window-layout-changed", src_w);
|
|
|
|
notify_window("window-layout-changed", dst_w);
|
2016-08-27 23:35:00 +00:00
|
|
|
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2010-01-07 20:52:18 +00:00
|
|
|
}
|