diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-03-03 08:31:19 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-03-03 08:31:19 +0000 |
commit | 9c860108cb4b13cf21d9eac066059b3fe483b26d (patch) | |
tree | 62fdc4afc31f255af883290f1fc31ccff729fb45 | |
parent | da6ee612f9cc5cf7a0d1d9c97c01ae3815ed28fd (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.
-rw-r--r-- | usr.bin/tmux/cmd-join-pane.c | 37 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-split-window.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/cmd.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/layout.c | 35 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 28 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 5 |
6 files changed, 87 insertions, 25 deletions
diff --git a/usr.bin/tmux/cmd-join-pane.c b/usr.bin/tmux/cmd-join-pane.c index d9becf9a1ce..ef14728632e 100644 --- a/usr.bin/tmux/cmd-join-pane.c +++ b/usr.bin/tmux/cmd-join-pane.c @@ -1,6 +1,7 @@ -/* $OpenBSD: cmd-join-pane.c,v 1.7 2011/01/23 15:49:10 nicm Exp $ */ +/* $OpenBSD: cmd-join-pane.c,v 1.8 2012/03/03 08:31:18 nicm Exp $ */ /* + * 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); } diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index b6466d6f641..0f87e19443c 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.28 2012/01/31 15:52:21 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.29 2012/03/03 08:31:18 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -113,7 +113,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (*shell == '\0' || areshell(shell)) shell = _PATH_BSHELL; - if ((lc = layout_split_pane(wp, type, size)) == NULL) { + if ((lc = layout_split_pane(wp, type, size, 0)) == NULL) { cause = xstrdup("pane too small"); goto error; } diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index 183a5e1588e..08744ed651e 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.62 2012/02/06 17:29:29 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.63 2012/03/03 08:31:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -68,6 +68,7 @@ const struct cmd_entry *cmd_table[] = { &cmd_lock_client_entry, &cmd_lock_server_entry, &cmd_lock_session_entry, + &cmd_move_pane_entry, &cmd_move_window_entry, &cmd_new_session_entry, &cmd_new_window_entry, diff --git a/usr.bin/tmux/layout.c b/usr.bin/tmux/layout.c index b6bd6040e87..def54d444fe 100644 --- a/usr.bin/tmux/layout.c +++ b/usr.bin/tmux/layout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: layout.c,v 1.8 2012/01/29 09:37:02 nicm Exp $ */ +/* $OpenBSD: layout.c,v 1.9 2012/03/03 08:31:18 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -616,9 +616,10 @@ layout_assign_pane(struct layout_cell *lc, struct window_pane *wp) * split. This must be followed by layout_assign_pane before much else happens! **/ struct layout_cell * -layout_split_pane(struct window_pane *wp, enum layout_type type, int size) +layout_split_pane( + struct window_pane *wp, enum layout_type type, int size, int insert_before) { - struct layout_cell *lc, *lcparent, *lcnew; + struct layout_cell *lc, *lcparent, *lcnew, *lc1, *lc2; u_int sx, sy, xoff, yoff, size1, size2; lc = wp->layout_cell; @@ -650,8 +651,12 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size) */ /* Create the new child cell. */ - lcnew = layout_create_cell(lc->parent); - TAILQ_INSERT_AFTER(&lc->parent->cells, lc, lcnew, entry); + lcparent = lc->parent; + lcnew = layout_create_cell(lcparent); + if (insert_before) + TAILQ_INSERT_BEFORE(lc, lcnew, entry); + else + TAILQ_INSERT_AFTER(&lcparent->cells, lc, lcnew, entry); } else { /* * Otherwise create a new parent and insert it. @@ -672,7 +677,17 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size) /* Create the new child cell. */ lcnew = layout_create_cell(lcparent); - TAILQ_INSERT_TAIL(&lcparent->cells, lcnew, entry); + if (insert_before) + TAILQ_INSERT_HEAD(&lcparent->cells, lcnew, entry); + else + TAILQ_INSERT_TAIL(&lcparent->cells, lcnew, entry); + } + if (insert_before) { + lc1 = lcnew; + lc2 = lc; + } else { + lc1 = lc; + lc2 = lcnew; } /* Set new cell sizes. size is the target size or -1 for middle split, @@ -689,8 +704,8 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size) else if (size2 > sx - 2) size2 = sx - 2; size1 = sx - 1 - size2; - layout_set_size(lc, size1, sy, xoff, yoff); - layout_set_size(lcnew, size2, sy, xoff + lc->sx + 1, yoff); + layout_set_size(lc1, size1, sy, xoff, yoff); + layout_set_size(lc2, size2, sy, xoff + lc1->sx + 1, yoff); break; case LAYOUT_TOPBOTTOM: if (size < 0) @@ -702,8 +717,8 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size) else if (size2 > sy - 2) size2 = sy - 2; size1 = sy - 1 - size2; - layout_set_size(lc, sx, size1, xoff, yoff); - layout_set_size(lcnew, sx, size2, xoff, yoff + lc->sy + 1); + layout_set_size(lc1, sx, size1, xoff, yoff); + layout_set_size(lc2, sx, size2, xoff, yoff + lc1->sy + 1); break; default: fatalx("bad layout type"); diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 640f535e2c6..171ba93ced1 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.276 2012/02/25 12:57:42 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.277 2012/03/03 08:31:18 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: February 25 2012 $ +.Dd $Mdocdate: March 3 2012 $ .Dt TMUX 1 .Os .Sh NAME @@ -1105,7 +1105,7 @@ choice list is shown. This command only works from inside .Nm . .It Xo Ic join-pane -.Op Fl dhv +.Op Fl bdhv .Oo Fl l .Ar size | .Fl p Ar percentage Oc @@ -1122,6 +1122,12 @@ and creating a new pane, split it and move into the space. This can be used to reverse .Ic break-pane . +The +.Fl b +option causes +.Ar src-pane +to be joined to left of or above +.Ar dst-pane . .It Xo Ic kill-pane .Op Fl a .Op Fl t Ar target-pane @@ -1210,6 +1216,22 @@ For the meaning of the flag, see the .Sx FORMATS section. +.It Xo Ic move-pane +.Op Fl bdhv +.Oo Fl l +.Ar size | +.Fl p Ar percentage Oc +.Op Fl s Ar src-pane +.Op Fl t Ar dst-pane +.Xc +.D1 (alias: Ic movep ) +Like +.Ic join-pane , +but +.Ar src-pane +and +.Ar dst-pane +may belong to the same window. .It Xo Ic move-window .Op Fl dk .Op Fl s Ar src-window diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index a62976f9c5b..d34fd78ed1f 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.314 2012/03/02 11:16:44 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.315 2012/03/03 08:31:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1605,6 +1605,7 @@ extern const struct cmd_entry cmd_load_buffer_entry; extern const struct cmd_entry cmd_lock_client_entry; extern const struct cmd_entry cmd_lock_server_entry; extern const struct cmd_entry cmd_lock_session_entry; +extern const struct cmd_entry cmd_move_pane_entry; extern const struct cmd_entry cmd_move_window_entry; extern const struct cmd_entry cmd_new_session_entry; extern const struct cmd_entry cmd_new_window_entry; @@ -1999,7 +2000,7 @@ void layout_resize_pane_mouse( struct client *c, struct mouse_event *mouse); void layout_assign_pane(struct layout_cell *, struct window_pane *); struct layout_cell *layout_split_pane( - struct window_pane *, enum layout_type, int); + struct window_pane *, enum layout_type, int, int); void layout_close_pane(struct window_pane *); /* layout-custom.c */ |