mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-03 17:24:18 +00:00 
			
		
		
		
	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:
		@@ -1,6 +1,7 @@
 | 
				
			|||||||
/* $OpenBSD$ */
 | 
					/* $OpenBSD$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2011 George Nachman <tmux@georgester.com>
 | 
				
			||||||
 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Permission to use, copy, modify, and distribute this software for any
 | 
					 * Permission to use, copy, modify, and distribute this software for any
 | 
				
			||||||
@@ -25,22 +26,34 @@
 | 
				
			|||||||
#include "tmux.h"
 | 
					#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);
 | 
					void	cmd_join_pane_key_binding(struct cmd *, int);
 | 
				
			||||||
int	cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
 | 
					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 = {
 | 
					const struct cmd_entry cmd_join_pane_entry = {
 | 
				
			||||||
	"join-pane", "joinp",
 | 
						"join-pane", "joinp",
 | 
				
			||||||
	"dhvp:l:s:t:", 0, 0,
 | 
						"bdhvp:l:s:t:", 0, 0,
 | 
				
			||||||
	"[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
 | 
						"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
 | 
				
			||||||
	0,
 | 
						0,
 | 
				
			||||||
	cmd_join_pane_key_binding,
 | 
						cmd_join_pane_key_binding,
 | 
				
			||||||
	NULL,
 | 
						NULL,
 | 
				
			||||||
	cmd_join_pane_exec
 | 
						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
 | 
					void
 | 
				
			||||||
cmd_join_pane_key_binding(struct cmd *self, int key)
 | 
					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
 | 
					int
 | 
				
			||||||
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
					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 args		*args = self->args;
 | 
				
			||||||
	struct session		*dst_s;
 | 
						struct session		*dst_s;
 | 
				
			||||||
@@ -79,10 +98,14 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
		return (-1);
 | 
							return (-1);
 | 
				
			||||||
	src_w = src_wl->window;
 | 
						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");
 | 
							ctx->error(ctx, "can't join a pane to its own window");
 | 
				
			||||||
		return (-1);
 | 
							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;
 | 
						type = LAYOUT_TOPBOTTOM;
 | 
				
			||||||
	if (args_has(args, 'h'))
 | 
						if (args_has(args, 'h'))
 | 
				
			||||||
@@ -108,8 +131,8 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
		else
 | 
							else
 | 
				
			||||||
			size = (dst_wp->sx * percentage) / 100;
 | 
								size = (dst_wp->sx * percentage) / 100;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'));
 | 
				
			||||||
	if ((lc = layout_split_pane(dst_wp, type, size)) == NULL) {
 | 
						if (lc == NULL) {
 | 
				
			||||||
		ctx->error(ctx, "create pane failed: pane too small");
 | 
							ctx->error(ctx, "create pane failed: pane too small");
 | 
				
			||||||
		return (-1);
 | 
							return (-1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -113,7 +113,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	if (*shell == '\0' || areshell(shell))
 | 
						if (*shell == '\0' || areshell(shell))
 | 
				
			||||||
		shell = _PATH_BSHELL;
 | 
							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");
 | 
							cause = xstrdup("pane too small");
 | 
				
			||||||
		goto error;
 | 
							goto error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								cmd.c
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								cmd.c
									
									
									
									
									
								
							@@ -68,6 +68,7 @@ const struct cmd_entry *cmd_table[] = {
 | 
				
			|||||||
	&cmd_lock_client_entry,
 | 
						&cmd_lock_client_entry,
 | 
				
			||||||
	&cmd_lock_server_entry,
 | 
						&cmd_lock_server_entry,
 | 
				
			||||||
	&cmd_lock_session_entry,
 | 
						&cmd_lock_session_entry,
 | 
				
			||||||
 | 
						&cmd_move_pane_entry,
 | 
				
			||||||
	&cmd_move_window_entry,
 | 
						&cmd_move_window_entry,
 | 
				
			||||||
	&cmd_new_session_entry,
 | 
						&cmd_new_session_entry,
 | 
				
			||||||
	&cmd_new_window_entry,
 | 
						&cmd_new_window_entry,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										33
									
								
								layout.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								layout.c
									
									
									
									
									
								
							@@ -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!
 | 
					 * split. This must be followed by layout_assign_pane before much else happens!
 | 
				
			||||||
 **/
 | 
					 **/
 | 
				
			||||||
struct layout_cell *
 | 
					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;
 | 
						u_int			sx, sy, xoff, yoff, size1, size2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lc = wp->layout_cell;
 | 
						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. */
 | 
							/* Create the new child cell. */
 | 
				
			||||||
		lcnew = layout_create_cell(lc->parent);
 | 
							lcparent = lc->parent;
 | 
				
			||||||
		TAILQ_INSERT_AFTER(&lc->parent->cells, lc, lcnew, entry);
 | 
							lcnew = layout_create_cell(lcparent);
 | 
				
			||||||
 | 
							if (insert_before)
 | 
				
			||||||
 | 
								TAILQ_INSERT_BEFORE(lc, lcnew, entry);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								TAILQ_INSERT_AFTER(&lcparent->cells, lc, lcnew, entry);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Otherwise create a new parent and insert it.
 | 
							 * 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. */
 | 
							/* Create the new child cell. */
 | 
				
			||||||
		lcnew = layout_create_cell(lcparent);
 | 
							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,
 | 
						/* 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)
 | 
							else if (size2 > sx - 2)
 | 
				
			||||||
			size2 = sx - 2;
 | 
								size2 = sx - 2;
 | 
				
			||||||
		size1 = sx - 1 - size2;
 | 
							size1 = sx - 1 - size2;
 | 
				
			||||||
		layout_set_size(lc, size1, sy, xoff, yoff);
 | 
							layout_set_size(lc1, size1, sy, xoff, yoff);
 | 
				
			||||||
		layout_set_size(lcnew, size2, sy, xoff + lc->sx + 1, yoff);
 | 
							layout_set_size(lc2, size2, sy, xoff + lc1->sx + 1, yoff);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case LAYOUT_TOPBOTTOM:
 | 
						case LAYOUT_TOPBOTTOM:
 | 
				
			||||||
		if (size < 0)
 | 
							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)
 | 
							else if (size2 > sy - 2)
 | 
				
			||||||
			size2 = sy - 2;
 | 
								size2 = sy - 2;
 | 
				
			||||||
		size1 = sy - 1 - size2;
 | 
							size1 = sy - 1 - size2;
 | 
				
			||||||
		layout_set_size(lc, sx, size1, xoff, yoff);
 | 
							layout_set_size(lc1, sx, size1, xoff, yoff);
 | 
				
			||||||
		layout_set_size(lcnew, sx, size2, xoff, yoff + lc->sy + 1);
 | 
							layout_set_size(lc2, sx, size2, xoff, yoff + lc1->sy + 1);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		fatalx("bad layout type");
 | 
							fatalx("bad layout type");
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								tmux.1
									
									
									
									
									
								
							@@ -1105,7 +1105,7 @@ choice list is shown.
 | 
				
			|||||||
This command only works from inside
 | 
					This command only works from inside
 | 
				
			||||||
.Nm .
 | 
					.Nm .
 | 
				
			||||||
.It Xo Ic join-pane
 | 
					.It Xo Ic join-pane
 | 
				
			||||||
.Op Fl dhv
 | 
					.Op Fl bdhv
 | 
				
			||||||
.Oo Fl l
 | 
					.Oo Fl l
 | 
				
			||||||
.Ar size |
 | 
					.Ar size |
 | 
				
			||||||
.Fl p Ar percentage Oc
 | 
					.Fl p Ar percentage Oc
 | 
				
			||||||
@@ -1122,6 +1122,12 @@ and creating a new pane, split it and move
 | 
				
			|||||||
into the space.
 | 
					into the space.
 | 
				
			||||||
This can be used to reverse
 | 
					This can be used to reverse
 | 
				
			||||||
.Ic break-pane .
 | 
					.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
 | 
					.It Xo Ic kill-pane
 | 
				
			||||||
.Op Fl a
 | 
					.Op Fl a
 | 
				
			||||||
.Op Fl t Ar target-pane
 | 
					.Op Fl t Ar target-pane
 | 
				
			||||||
@@ -1210,6 +1216,22 @@ For the meaning of the
 | 
				
			|||||||
flag, see the
 | 
					flag, see the
 | 
				
			||||||
.Sx FORMATS
 | 
					.Sx FORMATS
 | 
				
			||||||
section.
 | 
					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
 | 
					.It Xo Ic move-window
 | 
				
			||||||
.Op Fl dk
 | 
					.Op Fl dk
 | 
				
			||||||
.Op Fl s Ar src-window
 | 
					.Op Fl s Ar src-window
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								tmux.h
									
									
									
									
									
								
							@@ -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_client_entry;
 | 
				
			||||||
extern const struct cmd_entry cmd_lock_server_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_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_move_window_entry;
 | 
				
			||||||
extern const struct cmd_entry cmd_new_session_entry;
 | 
					extern const struct cmd_entry cmd_new_session_entry;
 | 
				
			||||||
extern const struct cmd_entry cmd_new_window_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);
 | 
							     struct client *c, struct mouse_event *mouse);
 | 
				
			||||||
void		 layout_assign_pane(struct layout_cell *, struct window_pane *);
 | 
					void		 layout_assign_pane(struct layout_cell *, struct window_pane *);
 | 
				
			||||||
struct layout_cell *layout_split_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 *);
 | 
					void		 layout_close_pane(struct window_pane *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* layout-custom.c */
 | 
					/* layout-custom.c */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user