mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and deprecate -p. From Anindya Mukherjee.
This commit is contained in:
		@@ -21,6 +21,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <paths.h>
 | 
					#include <paths.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "tmux.h"
 | 
					#include "tmux.h"
 | 
				
			||||||
@@ -36,7 +37,7 @@ const struct cmd_entry cmd_join_pane_entry = {
 | 
				
			|||||||
	.alias = "joinp",
 | 
						.alias = "joinp",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.args = { "bdhvp:l:s:t:", 0, 0 },
 | 
						.args = { "bdhvp:l:s:t:", 0, 0 },
 | 
				
			||||||
	.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
 | 
						.usage = "[-bdhv] [-l size] " CMD_SRCDST_PANE_USAGE,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
 | 
						.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
 | 
				
			||||||
	.target = { 't', CMD_FIND_PANE, 0 },
 | 
						.target = { 't', CMD_FIND_PANE, 0 },
 | 
				
			||||||
@@ -68,11 +69,13 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
	struct winlink		*src_wl, *dst_wl;
 | 
						struct winlink		*src_wl, *dst_wl;
 | 
				
			||||||
	struct window		*src_w, *dst_w;
 | 
						struct window		*src_w, *dst_w;
 | 
				
			||||||
	struct window_pane	*src_wp, *dst_wp;
 | 
						struct window_pane	*src_wp, *dst_wp;
 | 
				
			||||||
	char			*cause;
 | 
						char			*cause, *copy;
 | 
				
			||||||
	int			 size, percentage, dst_idx;
 | 
						const char		*errstr, *p;
 | 
				
			||||||
 | 
						size_t			 plen;
 | 
				
			||||||
 | 
						int			 size, percentage, dst_idx, not_same_window;
 | 
				
			||||||
 | 
						int			 flags;
 | 
				
			||||||
	enum layout_type	 type;
 | 
						enum layout_type	 type;
 | 
				
			||||||
	struct layout_cell	*lc;
 | 
						struct layout_cell	*lc;
 | 
				
			||||||
	int			 not_same_window, flags;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (self->entry == &cmd_join_pane_entry)
 | 
						if (self->entry == &cmd_join_pane_entry)
 | 
				
			||||||
		not_same_window = 1;
 | 
							not_same_window = 1;
 | 
				
			||||||
@@ -105,13 +108,29 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
		type = LAYOUT_LEFTRIGHT;
 | 
							type = LAYOUT_LEFTRIGHT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size = -1;
 | 
						size = -1;
 | 
				
			||||||
	if (args_has(args, 'l')) {
 | 
						if ((p = args_get(args, 'l')) != NULL) {
 | 
				
			||||||
 | 
							plen = strlen(p);
 | 
				
			||||||
 | 
							if (p[plen - 1] == '%') {
 | 
				
			||||||
 | 
								copy = xstrdup(p);
 | 
				
			||||||
 | 
								copy[plen - 1] = '\0';
 | 
				
			||||||
 | 
								percentage = strtonum(copy, 0, INT_MAX, &errstr);
 | 
				
			||||||
 | 
								free(copy);
 | 
				
			||||||
 | 
								if (errstr != NULL) {
 | 
				
			||||||
 | 
									cmdq_error(item, "percentage %s", errstr);
 | 
				
			||||||
 | 
									return (CMD_RETURN_ERROR);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (type == LAYOUT_TOPBOTTOM)
 | 
				
			||||||
 | 
									size = (dst_wp->sy * percentage) / 100;
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									size = (dst_wp->sx * percentage) / 100;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
 | 
								size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
 | 
				
			||||||
			if (cause != NULL) {
 | 
								if (cause != NULL) {
 | 
				
			||||||
				cmdq_error(item, "size %s", cause);
 | 
									cmdq_error(item, "size %s", cause);
 | 
				
			||||||
				free(cause);
 | 
									free(cause);
 | 
				
			||||||
				return (CMD_RETURN_ERROR);
 | 
									return (CMD_RETURN_ERROR);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else if (args_has(args, 'p')) {
 | 
						} else if (args_has(args, 'p')) {
 | 
				
			||||||
		percentage = args_strtonum(args, 'p', 0, 100, &cause);
 | 
							percentage = args_strtonum(args, 'p', 0, 100, &cause);
 | 
				
			||||||
		if (cause != NULL) {
 | 
							if (cause != NULL) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@
 | 
				
			|||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "tmux.h"
 | 
					#include "tmux.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -55,10 +56,11 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
	struct window		*w = wl->window;
 | 
						struct window		*w = wl->window;
 | 
				
			||||||
	struct client		*c = item->client;
 | 
						struct client		*c = item->client;
 | 
				
			||||||
	struct session		*s = item->target.s;
 | 
						struct session		*s = item->target.s;
 | 
				
			||||||
	const char	       	*errstr;
 | 
						const char	       	*errstr, *p;
 | 
				
			||||||
	char			*cause;
 | 
						char			*cause, *copy;
 | 
				
			||||||
	u_int			 adjust;
 | 
						u_int			 adjust;
 | 
				
			||||||
	int			 x, y;
 | 
						int			 x, y, percentage;
 | 
				
			||||||
 | 
						size_t			 plen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (args_has(args, 'M')) {
 | 
						if (args_has(args, 'M')) {
 | 
				
			||||||
		if (cmd_mouse_window(&shared->mouse, &s) == NULL)
 | 
							if (cmd_mouse_window(&shared->mouse, &s) == NULL)
 | 
				
			||||||
@@ -91,22 +93,59 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (args_has(args, 'x')) {
 | 
						if ((p = args_get(args, 'x')) != NULL) {
 | 
				
			||||||
		x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX, &cause);
 | 
							plen = strlen(p);
 | 
				
			||||||
 | 
							if (p[plen - 1] == '%') {
 | 
				
			||||||
 | 
								copy = xstrdup(p);
 | 
				
			||||||
 | 
								copy[plen - 1] = '\0';
 | 
				
			||||||
 | 
								percentage = strtonum(copy, 0, INT_MAX, &errstr);
 | 
				
			||||||
 | 
								free(copy);
 | 
				
			||||||
 | 
								if (errstr != NULL) {
 | 
				
			||||||
 | 
									cmdq_error(item, "width %s", errstr);
 | 
				
			||||||
 | 
									return (CMD_RETURN_ERROR);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								x = (w->sx * percentage) / 100;
 | 
				
			||||||
 | 
								if (x < PANE_MINIMUM)
 | 
				
			||||||
 | 
									x = PANE_MINIMUM;
 | 
				
			||||||
 | 
								if (x > INT_MAX)
 | 
				
			||||||
 | 
									x = INT_MAX;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX,
 | 
				
			||||||
 | 
								    &cause);
 | 
				
			||||||
			if (cause != NULL) {
 | 
								if (cause != NULL) {
 | 
				
			||||||
				cmdq_error(item, "width %s", cause);
 | 
									cmdq_error(item, "width %s", cause);
 | 
				
			||||||
				free(cause);
 | 
									free(cause);
 | 
				
			||||||
				return (CMD_RETURN_ERROR);
 | 
									return (CMD_RETURN_ERROR);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
 | 
							layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (args_has(args, 'y')) {
 | 
						if ((p = args_get(args, 'y')) != NULL) {
 | 
				
			||||||
		y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX, &cause);
 | 
							plen = strlen(p);
 | 
				
			||||||
 | 
							if (p[plen - 1] == '%') {
 | 
				
			||||||
 | 
								copy = xstrdup(p);
 | 
				
			||||||
 | 
								copy[plen - 1] = '\0';
 | 
				
			||||||
 | 
								percentage = strtonum(copy, 0, INT_MAX, &errstr);
 | 
				
			||||||
 | 
								free(copy);
 | 
				
			||||||
 | 
								if (errstr != NULL) {
 | 
				
			||||||
 | 
									cmdq_error(item, "height %s", errstr);
 | 
				
			||||||
 | 
									return (CMD_RETURN_ERROR);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								y = (w->sy * percentage) / 100;
 | 
				
			||||||
 | 
								if (y < PANE_MINIMUM)
 | 
				
			||||||
 | 
									y = PANE_MINIMUM;
 | 
				
			||||||
 | 
								if (y > INT_MAX)
 | 
				
			||||||
 | 
									y = INT_MAX;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else {
 | 
				
			||||||
 | 
								y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX,
 | 
				
			||||||
 | 
								    &cause);
 | 
				
			||||||
			if (cause != NULL) {
 | 
								if (cause != NULL) {
 | 
				
			||||||
				cmdq_error(item, "height %s", cause);
 | 
									cmdq_error(item, "height %s", cause);
 | 
				
			||||||
				free(cause);
 | 
									free(cause);
 | 
				
			||||||
				return (CMD_RETURN_ERROR);
 | 
									return (CMD_RETURN_ERROR);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
 | 
							layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,8 +42,7 @@ const struct cmd_entry cmd_split_window_entry = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	.args = { "bc:de:fF:hIl:p:Pt:v", 0, -1 },
 | 
						.args = { "bc:de:fF:hIl:p:Pt:v", 0, -1 },
 | 
				
			||||||
	.usage = "[-bdefhIPv] [-c start-directory] [-e environment] "
 | 
						.usage = "[-bdefhIPv] [-c start-directory] [-e environment] "
 | 
				
			||||||
		 "[-F format] [-p percentage|-l size] " CMD_TARGET_PANE_USAGE
 | 
							 "[-F format] [-l size] " CMD_TARGET_PANE_USAGE " [command]",
 | 
				
			||||||
		 " [command]",
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.target = { 't', CMD_FIND_PANE, 0 },
 | 
						.target = { 't', CMD_FIND_PANE, 0 },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -65,21 +64,38 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
	struct layout_cell	*lc;
 | 
						struct layout_cell	*lc;
 | 
				
			||||||
	struct cmd_find_state	 fs;
 | 
						struct cmd_find_state	 fs;
 | 
				
			||||||
	int			 size, percentage, flags, input;
 | 
						int			 size, percentage, flags, input;
 | 
				
			||||||
	const char		*template, *add;
 | 
						const char		*template, *add, *errstr, *p;
 | 
				
			||||||
	char			*cause, *cp;
 | 
						char			*cause, *cp, *copy;
 | 
				
			||||||
 | 
						size_t			 plen;
 | 
				
			||||||
	struct args_value	*value;
 | 
						struct args_value	*value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (args_has(args, 'h'))
 | 
						if (args_has(args, 'h'))
 | 
				
			||||||
		type = LAYOUT_LEFTRIGHT;
 | 
							type = LAYOUT_LEFTRIGHT;
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		type = LAYOUT_TOPBOTTOM;
 | 
							type = LAYOUT_TOPBOTTOM;
 | 
				
			||||||
	if (args_has(args, 'l')) {
 | 
						if ((p = args_get(args, 'l')) != NULL) {
 | 
				
			||||||
 | 
							plen = strlen(p);
 | 
				
			||||||
 | 
							if (p[plen - 1] == '%') {
 | 
				
			||||||
 | 
								copy = xstrdup(p);
 | 
				
			||||||
 | 
								copy[plen - 1] = '\0';
 | 
				
			||||||
 | 
								percentage = strtonum(copy, 0, INT_MAX, &errstr);
 | 
				
			||||||
 | 
								free(copy);
 | 
				
			||||||
 | 
								if (errstr != NULL) {
 | 
				
			||||||
 | 
									cmdq_error(item, "percentage %s", errstr);
 | 
				
			||||||
 | 
									return (CMD_RETURN_ERROR);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (type == LAYOUT_TOPBOTTOM)
 | 
				
			||||||
 | 
									size = (wp->sy * percentage) / 100;
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									size = (wp->sx * percentage) / 100;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
 | 
								size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
 | 
				
			||||||
			if (cause != NULL) {
 | 
								if (cause != NULL) {
 | 
				
			||||||
			cmdq_error(item, "create pane failed: -l %s", cause);
 | 
									cmdq_error(item, "lines %s", cause);
 | 
				
			||||||
				free(cause);
 | 
									free(cause);
 | 
				
			||||||
				return (CMD_RETURN_ERROR);
 | 
									return (CMD_RETURN_ERROR);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else if (args_has(args, 'p')) {
 | 
						} else if (args_has(args, 'p')) {
 | 
				
			||||||
		percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
 | 
							percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
 | 
				
			||||||
		if (cause != NULL) {
 | 
							if (cause != NULL) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										32
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								tmux.1
									
									
									
									
									
								
							@@ -1891,9 +1891,7 @@ zooms the pane.
 | 
				
			|||||||
This command works only if at least one client is attached.
 | 
					This command works only if at least one client is attached.
 | 
				
			||||||
.It Xo Ic join-pane
 | 
					.It Xo Ic join-pane
 | 
				
			||||||
.Op Fl bdhv
 | 
					.Op Fl bdhv
 | 
				
			||||||
.Oo Fl l
 | 
					.Op Fl l Ar size
 | 
				
			||||||
.Ar size |
 | 
					 | 
				
			||||||
.Fl p Ar percentage Oc
 | 
					 | 
				
			||||||
.Op Fl s Ar src-pane
 | 
					.Op Fl s Ar src-pane
 | 
				
			||||||
.Op Fl t Ar dst-pane
 | 
					.Op Fl t Ar dst-pane
 | 
				
			||||||
.Xc
 | 
					.Xc
 | 
				
			||||||
@@ -2030,9 +2028,7 @@ flag, see the
 | 
				
			|||||||
section.
 | 
					section.
 | 
				
			||||||
.It Xo Ic move-pane
 | 
					.It Xo Ic move-pane
 | 
				
			||||||
.Op Fl bdhv
 | 
					.Op Fl bdhv
 | 
				
			||||||
.Oo Fl l
 | 
					.Op Fl l Ar size
 | 
				
			||||||
.Ar size |
 | 
					 | 
				
			||||||
.Fl p Ar percentage Oc
 | 
					 | 
				
			||||||
.Op Fl s Ar src-pane
 | 
					.Op Fl s Ar src-pane
 | 
				
			||||||
.Op Fl t Ar dst-pane
 | 
					.Op Fl t Ar dst-pane
 | 
				
			||||||
.Xc
 | 
					.Xc
 | 
				
			||||||
@@ -2241,8 +2237,14 @@ or
 | 
				
			|||||||
.Fl y .
 | 
					.Fl y .
 | 
				
			||||||
The
 | 
					The
 | 
				
			||||||
.Ar adjustment
 | 
					.Ar adjustment
 | 
				
			||||||
is given in lines or cells (the default is 1).
 | 
					is given in lines or columns (the default is 1);
 | 
				
			||||||
.Pp
 | 
					.Fl x
 | 
				
			||||||
 | 
					and
 | 
				
			||||||
 | 
					.Fl y
 | 
				
			||||||
 | 
					may be a given as a number of lines or columns or followed by
 | 
				
			||||||
 | 
					.Ql %
 | 
				
			||||||
 | 
					for a percentage of the window size (for example
 | 
				
			||||||
 | 
					.Ql -x 10% ) .
 | 
				
			||||||
With
 | 
					With
 | 
				
			||||||
.Fl Z ,
 | 
					.Fl Z ,
 | 
				
			||||||
the active pane is toggled between zoomed (occupying the whole of the window)
 | 
					the active pane is toggled between zoomed (occupying the whole of the window)
 | 
				
			||||||
@@ -2434,9 +2436,7 @@ the command behaves like
 | 
				
			|||||||
.Op Fl bdfhIvP
 | 
					.Op Fl bdfhIvP
 | 
				
			||||||
.Op Fl c Ar start-directory
 | 
					.Op Fl c Ar start-directory
 | 
				
			||||||
.Op Fl e Ar environment
 | 
					.Op Fl e Ar environment
 | 
				
			||||||
.Oo Fl l
 | 
					.Op Fl l Ar size
 | 
				
			||||||
.Ar size |
 | 
					 | 
				
			||||||
.Fl p Ar percentage Oc
 | 
					 | 
				
			||||||
.Op Fl t Ar target-pane
 | 
					.Op Fl t Ar target-pane
 | 
				
			||||||
.Op Ar shell-command
 | 
					.Op Ar shell-command
 | 
				
			||||||
.Op Fl F Ar format
 | 
					.Op Fl F Ar format
 | 
				
			||||||
@@ -2452,10 +2452,12 @@ a vertical split; if neither is specified,
 | 
				
			|||||||
is assumed.
 | 
					is assumed.
 | 
				
			||||||
The
 | 
					The
 | 
				
			||||||
.Fl l
 | 
					.Fl l
 | 
				
			||||||
and
 | 
					option specifies the size of the new pane in lines (for vertical split) or in
 | 
				
			||||||
.Fl p
 | 
					columns (for horizontal split);
 | 
				
			||||||
options specify the size of the new pane in lines (for vertical split) or in
 | 
					.Ar size
 | 
				
			||||||
cells (for horizontal split), or as a percentage, respectively.
 | 
					may be followed by
 | 
				
			||||||
 | 
					.Ql %
 | 
				
			||||||
 | 
					to specify a percentage of the available space.
 | 
				
			||||||
The
 | 
					The
 | 
				
			||||||
.Fl b
 | 
					.Fl b
 | 
				
			||||||
option causes the new pane to be created to the left of or above
 | 
					option causes the new pane to be created to the left of or above
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user