Add move-pane command (like join-pane but allows the same window). Also

-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.
This commit is contained in:
Nicholas Marriott
2012-03-03 08:31:18 +00:00
parent 4d9ccd3229
commit 07ac16807f
6 changed files with 80 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -25,22 +26,34 @@
#include "tmux.h"
/*
* Join a pane into another (like split/swap/kill).
* Join or move a pane into another (like split/swap/kill).
*/
void cmd_join_pane_key_binding(struct cmd *, int);
int cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
int join_pane(struct cmd *, struct cmd_ctx *, int);
const struct cmd_entry cmd_join_pane_entry = {
"join-pane", "joinp",
"dhvp:l:s:t:", 0, 0,
"[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
"bdhvp:l:s:t:", 0, 0,
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
0,
cmd_join_pane_key_binding,
NULL,
cmd_join_pane_exec
};
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,
NULL,
cmd_join_pane_exec
};
void
cmd_join_pane_key_binding(struct cmd *self, int key)
{
@@ -57,6 +70,12 @@ cmd_join_pane_key_binding(struct cmd *self, int key)
int
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{
return join_pane(self, ctx, self->entry == &cmd_join_pane_entry);
}
int
join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
{
struct args *args = self->args;
struct session *dst_s;
@@ -79,10 +98,14 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
src_w = src_wl->window;
if (src_w == dst_w) {
if (not_same_window && src_w == dst_w) {
ctx->error(ctx, "can't join a pane to its own window");
return (-1);
}
if (!not_same_window && src_wp == dst_wp) {
ctx->error(ctx, "source and target panes must be different");
return (-1);
}
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
@@ -108,8 +131,8 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
else
size = (dst_wp->sx * percentage) / 100;
}
if ((lc = layout_split_pane(dst_wp, type, size)) == NULL) {
lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'));
if (lc == NULL) {
ctx->error(ctx, "create pane failed: pane too small");
return (-1);
}