2011-07-09 11:42:33 +02:00
|
|
|
/* $Id$ */
|
2010-01-08 17:31:35 +01:00
|
|
|
|
|
|
|
/*
|
2012-03-03 10:19:40 +01:00
|
|
|
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
|
2010-01-08 17:31:35 +01:00
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
2012-03-03 10:19:40 +01:00
|
|
|
* Join or move a pane into another (like split/swap/kill).
|
2010-01-08 17:31:35 +01:00
|
|
|
*/
|
|
|
|
|
2012-07-11 21:37:32 +02:00
|
|
|
void cmd_join_pane_key_binding(struct cmd *, int);
|
2013-02-23 23:25:58 +01:00
|
|
|
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *);
|
2010-01-08 17:31:35 +01:00
|
|
|
|
2013-02-23 23:25:58 +01:00
|
|
|
enum cmd_retval join_pane(struct cmd *, struct cmd_q *, int);
|
2012-03-03 10:19:40 +01:00
|
|
|
|
2010-01-08 17:31:35 +01:00
|
|
|
const struct cmd_entry cmd_join_pane_entry = {
|
|
|
|
"join-pane", "joinp",
|
2012-03-03 10:19:40 +01:00
|
|
|
"bdhvp:l:s:t:", 0, 0,
|
|
|
|
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
2011-01-07 15:45:34 +01:00
|
|
|
0,
|
|
|
|
cmd_join_pane_key_binding,
|
|
|
|
cmd_join_pane_exec
|
2010-01-08 17:31:35 +01:00
|
|
|
};
|
|
|
|
|
2012-03-03 10:19:40 +01:00
|
|
|
const struct cmd_entry cmd_move_pane_entry = {
|
|
|
|
"move-pane", "movep",
|
|
|
|
"bdhvp:l:s:t:", 0, 0,
|
|
|
|
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
cmd_join_pane_exec
|
|
|
|
};
|
|
|
|
|
2010-01-08 17:31:35 +01:00
|
|
|
void
|
2011-01-07 15:45:34 +01:00
|
|
|
cmd_join_pane_key_binding(struct cmd *self, int key)
|
2010-01-08 17:31:35 +01:00
|
|
|
{
|
|
|
|
switch (key) {
|
|
|
|
case '%':
|
2011-01-07 15:45:34 +01:00
|
|
|
self->args = args_create(0);
|
|
|
|
args_set(self->args, 'h', NULL);
|
2010-01-08 17:31:35 +01:00
|
|
|
break;
|
2011-01-07 15:45:34 +01:00
|
|
|
default:
|
|
|
|
self->args = args_create(0);
|
2010-01-08 17:31:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-11 21:37:32 +02:00
|
|
|
enum cmd_retval
|
2013-02-23 23:25:58 +01:00
|
|
|
cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
2012-03-03 10:19:40 +01:00
|
|
|
{
|
2013-02-23 23:25:58 +01:00
|
|
|
return (join_pane(self, cmdq, self->entry == &cmd_join_pane_entry));
|
2012-03-03 10:19:40 +01:00
|
|
|
}
|
|
|
|
|
2012-07-11 21:37:32 +02:00
|
|
|
enum cmd_retval
|
2013-02-23 23:25:58 +01:00
|
|
|
join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
2010-01-08 17:31:35 +01:00
|
|
|
{
|
2011-01-07 15:45:34 +01:00
|
|
|
struct args *args = self->args;
|
|
|
|
struct session *dst_s;
|
|
|
|
struct winlink *src_wl, *dst_wl;
|
|
|
|
struct window *src_w, *dst_w;
|
|
|
|
struct window_pane *src_wp, *dst_wp;
|
|
|
|
char *cause;
|
|
|
|
int size, percentage, dst_idx;
|
|
|
|
enum layout_type type;
|
|
|
|
struct layout_cell *lc;
|
|
|
|
|
2013-02-23 23:25:58 +01:00
|
|
|
dst_wl = cmd_find_pane(cmdq, args_get(args, 't'), &dst_s, &dst_wp);
|
2011-01-07 15:45:34 +01:00
|
|
|
if (dst_wl == NULL)
|
2012-07-11 21:37:32 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2010-01-08 17:31:35 +01:00
|
|
|
dst_w = dst_wl->window;
|
2010-04-09 09:09:37 +02:00
|
|
|
dst_idx = dst_wl->idx;
|
2013-02-24 01:25:03 +01:00
|
|
|
server_unzoom_window(dst_w);
|
2010-01-08 17:31:35 +01:00
|
|
|
|
2013-02-23 23:25:58 +01:00
|
|
|
src_wl = cmd_find_pane(cmdq, args_get(args, 's'), NULL, &src_wp);
|
2011-01-07 15:45:34 +01:00
|
|
|
if (src_wl == NULL)
|
2012-07-11 21:37:32 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2010-01-08 17:31:35 +01:00
|
|
|
src_w = src_wl->window;
|
2013-02-24 01:25:03 +01:00
|
|
|
server_unzoom_window(src_w);
|
2010-01-08 17:31:35 +01:00
|
|
|
|
2012-03-03 10:19:40 +01:00
|
|
|
if (not_same_window && src_w == dst_w) {
|
2013-02-23 23:25:58 +01:00
|
|
|
cmdq_error(cmdq, "can't join a pane to its own window");
|
2012-07-11 21:37:32 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2010-01-08 17:31:35 +01:00
|
|
|
}
|
2012-03-03 10:19:40 +01:00
|
|
|
if (!not_same_window && src_wp == dst_wp) {
|
2013-02-23 23:25:58 +01:00
|
|
|
cmdq_error(cmdq, "source and target panes must be different");
|
2012-07-11 21:37:32 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2012-03-03 10:19:40 +01:00
|
|
|
}
|
2010-01-08 17:31:35 +01:00
|
|
|
|
|
|
|
type = LAYOUT_TOPBOTTOM;
|
2011-01-07 15:45:34 +01:00
|
|
|
if (args_has(args, 'h'))
|
2010-01-08 17:31:35 +01:00
|
|
|
type = LAYOUT_LEFTRIGHT;
|
|
|
|
|
|
|
|
size = -1;
|
2011-01-23 16:47:31 +01:00
|
|
|
if (args_has(args, 'l')) {
|
|
|
|
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
2011-01-07 15:45:34 +01:00
|
|
|
if (cause != NULL) {
|
2013-02-23 23:25:58 +01:00
|
|
|
cmdq_error(cmdq, "size %s", cause);
|
2012-07-11 21:34:16 +02:00
|
|
|
free(cause);
|
2012-07-11 21:37:32 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2011-01-07 15:45:34 +01:00
|
|
|
}
|
|
|
|
} else if (args_has(args, 'p')) {
|
2011-01-23 16:49:32 +01:00
|
|
|
percentage = args_strtonum(args, 'p', 0, 100, &cause);
|
2011-01-07 15:45:34 +01:00
|
|
|
if (cause != NULL) {
|
2013-02-23 23:25:58 +01:00
|
|
|
cmdq_error(cmdq, "percentage %s", cause);
|
2012-07-11 21:34:16 +02:00
|
|
|
free(cause);
|
2012-07-11 21:37:32 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2011-01-07 15:45:34 +01:00
|
|
|
}
|
2010-01-08 17:31:35 +01:00
|
|
|
if (type == LAYOUT_TOPBOTTOM)
|
2011-01-07 15:45:34 +01:00
|
|
|
size = (dst_wp->sy * percentage) / 100;
|
2010-01-08 17:31:35 +01:00
|
|
|
else
|
2011-01-07 15:45:34 +01:00
|
|
|
size = (dst_wp->sx * percentage) / 100;
|
2010-01-08 17:31:35 +01:00
|
|
|
}
|
2012-03-03 10:19:40 +01:00
|
|
|
lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'));
|
|
|
|
if (lc == NULL) {
|
2013-02-23 23:25:58 +01:00
|
|
|
cmdq_error(cmdq, "create pane failed: pane too small");
|
2012-07-11 21:37:32 +02:00
|
|
|
return (CMD_RETURN_ERROR);
|
2010-01-08 17:31:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
layout_close_pane(src_wp);
|
|
|
|
|
2014-04-17 11:13:13 +02:00
|
|
|
window_lost_pane(src_w, src_wp);
|
2010-01-08 17:31:35 +01:00
|
|
|
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
|
|
|
|
|
|
|
|
if (window_count_panes(src_w) == 0)
|
|
|
|
server_kill_window(src_w);
|
2012-03-18 03:22:09 +01:00
|
|
|
else
|
|
|
|
notify_window_layout_changed(src_w);
|
2010-01-08 17:31:35 +01:00
|
|
|
|
|
|
|
src_wp->window = dst_w;
|
|
|
|
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
|
|
|
layout_assign_pane(lc, src_wp);
|
|
|
|
|
|
|
|
recalculate_sizes();
|
|
|
|
|
|
|
|
server_redraw_window(src_w);
|
|
|
|
server_redraw_window(dst_w);
|
|
|
|
|
2011-01-07 15:45:34 +01:00
|
|
|
if (!args_has(args, 'd')) {
|
2010-01-08 17:31:35 +01:00
|
|
|
window_set_active_pane(dst_w, src_wp);
|
2010-04-09 09:09:37 +02:00
|
|
|
session_select(dst_s, dst_idx);
|
2010-01-08 17:31:35 +01:00
|
|
|
server_redraw_session(dst_s);
|
|
|
|
} else
|
|
|
|
server_status_session(dst_s);
|
|
|
|
|
2012-03-18 03:22:09 +01:00
|
|
|
notify_window_layout_changed(dst_w);
|
2012-07-11 21:37:32 +02:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2010-01-08 17:31:35 +01:00
|
|
|
}
|