mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Add resize-pane -x and -y for absolute pane size.
This commit is contained in:
		@@ -31,8 +31,8 @@ enum cmd_retval	 cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
 | 
			
		||||
 | 
			
		||||
const struct cmd_entry cmd_resize_pane_entry = {
 | 
			
		||||
	"resize-pane", "resizep",
 | 
			
		||||
	"DLRt:U", 0, 1,
 | 
			
		||||
	"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
 | 
			
		||||
	"DLRt:Ux:y:", 0, 1,
 | 
			
		||||
	"[-DLRU] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
 | 
			
		||||
	0,
 | 
			
		||||
	cmd_resize_pane_key_binding,
 | 
			
		||||
	NULL,
 | 
			
		||||
@@ -87,8 +87,10 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
	struct args		*args = self->args;
 | 
			
		||||
	struct winlink		*wl;
 | 
			
		||||
	const char	       	*errstr;
 | 
			
		||||
	char			*cause;
 | 
			
		||||
	struct window_pane	*wp;
 | 
			
		||||
	u_int			 adjust;
 | 
			
		||||
	int			 x, y;
 | 
			
		||||
 | 
			
		||||
	if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
 | 
			
		||||
		return (CMD_RETURN_ERROR);
 | 
			
		||||
@@ -103,6 +105,27 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (args_has(self->args, 'x')) {
 | 
			
		||||
		x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
 | 
			
		||||
		    &cause);
 | 
			
		||||
		if (cause != NULL) {
 | 
			
		||||
			ctx->error(ctx, "width %s", cause);
 | 
			
		||||
			free(cause);
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
		layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
 | 
			
		||||
	}
 | 
			
		||||
	if (args_has(self->args, 'y')) {
 | 
			
		||||
		y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX,
 | 
			
		||||
		    &cause);
 | 
			
		||||
		if (cause != NULL) {
 | 
			
		||||
			ctx->error(ctx, "height %s", cause);
 | 
			
		||||
			free(cause);
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
		layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (args_has(self->args, 'L'))
 | 
			
		||||
		layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
 | 
			
		||||
	else if (args_has(self->args, 'R'))
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								layout.c
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								layout.c
									
									
									
									
									
								
							@@ -443,6 +443,39 @@ layout_resize(struct window *w, u_int sx, u_int sy)
 | 
			
		||||
	layout_fix_panes(w, sx, sy);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Resize a pane to an absolute size. */
 | 
			
		||||
void
 | 
			
		||||
layout_resize_pane_to(struct window_pane *wp, enum layout_type type,
 | 
			
		||||
    u_int new_size)
 | 
			
		||||
{
 | 
			
		||||
	struct layout_cell     *lc, *lcparent;
 | 
			
		||||
	int			change, size;
 | 
			
		||||
 | 
			
		||||
	lc = wp->layout_cell;
 | 
			
		||||
 | 
			
		||||
	/* Find next parent of the same type. */
 | 
			
		||||
	lcparent = lc->parent;
 | 
			
		||||
	while (lcparent != NULL && lcparent->type != type) {
 | 
			
		||||
		lc = lcparent;
 | 
			
		||||
		lcparent = lc->parent;
 | 
			
		||||
	}
 | 
			
		||||
	if (lcparent == NULL)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	/* Work out the size adjustment. */
 | 
			
		||||
	if (type == LAYOUT_LEFTRIGHT)
 | 
			
		||||
		size = lc->sx;
 | 
			
		||||
	else
 | 
			
		||||
		size = lc->sy;
 | 
			
		||||
	if (lc == TAILQ_LAST(&lcparent->cells, layout_cells))
 | 
			
		||||
		change = size - new_size;
 | 
			
		||||
	else
 | 
			
		||||
		change = new_size - size;
 | 
			
		||||
 | 
			
		||||
	/* Resize the pane. */
 | 
			
		||||
	layout_resize_pane(wp, type, change);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Resize a single pane within the layout. */
 | 
			
		||||
void
 | 
			
		||||
layout_resize_pane(struct window_pane *wp, enum layout_type type, int change)
 | 
			
		||||
@@ -486,6 +519,7 @@ layout_resize_pane(struct window_pane *wp, enum layout_type type, int change)
 | 
			
		||||
	notify_window_layout_changed(wp->window);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Resize pane based on mouse events. */
 | 
			
		||||
void
 | 
			
		||||
layout_resize_pane_mouse(struct client *c)
 | 
			
		||||
{
 | 
			
		||||
@@ -534,6 +568,7 @@ layout_resize_pane_mouse(struct client *c)
 | 
			
		||||
		m->flags &= ~MOUSE_RESIZE_PANE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Helper function to grow pane. */
 | 
			
		||||
int
 | 
			
		||||
layout_resize_pane_grow(
 | 
			
		||||
    struct layout_cell *lc, enum layout_type type, int needed)
 | 
			
		||||
@@ -574,6 +609,7 @@ layout_resize_pane_grow(
 | 
			
		||||
	return (size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Helper function to shrink pane. */
 | 
			
		||||
int
 | 
			
		||||
layout_resize_pane_shrink(
 | 
			
		||||
    struct layout_cell *lc, enum layout_type type, int needed)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								tmux.1
									
									
									
									
									
								
							@@ -1557,17 +1557,25 @@ if specified, to
 | 
			
		||||
.It Xo Ic resize-pane
 | 
			
		||||
.Op Fl DLRU
 | 
			
		||||
.Op Fl t Ar target-pane
 | 
			
		||||
.Op Fl x Ar width
 | 
			
		||||
.Op Fl y Ar height
 | 
			
		||||
.Op Ar adjustment
 | 
			
		||||
.Xc
 | 
			
		||||
.D1 (alias: Ic resizep )
 | 
			
		||||
Resize a pane, upward with
 | 
			
		||||
.Fl U
 | 
			
		||||
(the default), downward with
 | 
			
		||||
Resize a pane, up, down, left or right by
 | 
			
		||||
.Ar adjustment
 | 
			
		||||
with
 | 
			
		||||
.Fl U ,
 | 
			
		||||
.Fl D ,
 | 
			
		||||
to the left with
 | 
			
		||||
.Fl L
 | 
			
		||||
and to the right with
 | 
			
		||||
.Fl R .
 | 
			
		||||
or
 | 
			
		||||
.Fl R ,
 | 
			
		||||
or
 | 
			
		||||
to an absolute size
 | 
			
		||||
with
 | 
			
		||||
.Fl x
 | 
			
		||||
or
 | 
			
		||||
.Fl y .
 | 
			
		||||
The
 | 
			
		||||
.Ar adjustment
 | 
			
		||||
is given in lines or cells (the default is 1).
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1167,7 +1167,7 @@ struct mouse_event {
 | 
			
		||||
 | 
			
		||||
	u_int   sgr;		/* whether the input arrived in SGR format */
 | 
			
		||||
	u_int   sgr_xb;		/* only for SGR: the unmangled button */
 | 
			
		||||
	u_int   sgr_rel;	/* only for SGR: whether it is a release event */
 | 
			
		||||
	u_int   sgr_rel;	/* only for SGR: if it is a release event */
 | 
			
		||||
 | 
			
		||||
	u_int	button;
 | 
			
		||||
	u_int	clicks;
 | 
			
		||||
@@ -2163,9 +2163,11 @@ void		 layout_resize_adjust(
 | 
			
		||||
void		 layout_init(struct window *);
 | 
			
		||||
void		 layout_free(struct window *);
 | 
			
		||||
void		 layout_resize(struct window *, u_int, u_int);
 | 
			
		||||
void		 layout_resize_pane(
 | 
			
		||||
		     struct window_pane *, enum layout_type, int);
 | 
			
		||||
void		 layout_resize_pane_mouse(struct client *c);
 | 
			
		||||
void		 layout_resize_pane(struct window_pane *, enum layout_type,
 | 
			
		||||
		     int);
 | 
			
		||||
void		 layout_resize_pane_to(struct window_pane *, enum layout_type,
 | 
			
		||||
		     u_int);
 | 
			
		||||
void		 layout_resize_pane_mouse(struct client *);
 | 
			
		||||
void		 layout_assign_pane(struct layout_cell *, struct window_pane *);
 | 
			
		||||
struct layout_cell *layout_split_pane(
 | 
			
		||||
		     struct window_pane *, enum layout_type, int, int);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user