summaryrefslogtreecommitdiffstats
path: root/cmd-join-pane.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-03-03 08:31:18 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-03-03 08:31:18 +0000
commit07ac16807f85d7bd5e7c7570f2b11250c65b6228 (patch)
tree8409a155ccc48f26d4ebf7c5fe5ba45fdf4e44fa /cmd-join-pane.c
parent4d9ccd322909334b896d6a0420ea747898799385 (diff)
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.
Diffstat (limited to 'cmd-join-pane.c')
-rw-r--r--cmd-join-pane.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/cmd-join-pane.c b/cmd-join-pane.c
index 0bfefd2f..03fb4317 100644
--- a/cmd-join-pane.c
+++ b/cmd-join-pane.c
@@ -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)
{
@@ -58,6 +71,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;
struct winlink *src_wl, *dst_wl;
@@ -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);
}