diff options
-rw-r--r-- | cmd-join-pane.c | 39 | ||||
-rw-r--r-- | cmd-resize-pane.c | 69 | ||||
-rw-r--r-- | cmd-split-window.c | 36 | ||||
-rw-r--r-- | tmux.1 | 32 |
4 files changed, 126 insertions, 50 deletions
diff --git a/cmd-join-pane.c b/cmd-join-pane.c index 4a0c7339..b6eff0fe 100644 --- a/cmd-join-pane.c +++ b/cmd-join-pane.c @@ -21,6 +21,7 @@ #include <paths.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include "tmux.h" @@ -36,7 +37,7 @@ const struct cmd_entry cmd_join_pane_entry = { .alias = "joinp", .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 }, .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 window *src_w, *dst_w; struct window_pane *src_wp, *dst_wp; - char *cause; - int size, percentage, dst_idx; + char *cause, *copy; + const char *errstr, *p; + size_t plen; + int size, percentage, dst_idx, not_same_window; + int flags; enum layout_type type; struct layout_cell *lc; - int not_same_window, flags; if (self->entry == &cmd_join_pane_entry) not_same_window = 1; @@ -105,12 +108,28 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) type = LAYOUT_LEFTRIGHT; size = -1; - if (args_has(args, 'l')) { - size = args_strtonum(args, 'l', 0, INT_MAX, &cause); - if (cause != NULL) { - cmdq_error(item, "size %s", cause); - free(cause); - return (CMD_RETURN_ERROR); + 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); + if (cause != NULL) { + cmdq_error(item, "size %s", cause); + free(cause); + return (CMD_RETURN_ERROR); + } } } else if (args_has(args, 'p')) { percentage = args_strtonum(args, 'p', 0, 100, &cause); diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index 8d35d96f..3962546d 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -19,6 +19,7 @@ #include <sys/types.h> #include <stdlib.h> +#include <string.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 client *c = item->client; struct session *s = item->target.s; - const char *errstr; - char *cause; + const char *errstr, *p; + char *cause, *copy; u_int adjust; - int x, y; + int x, y, percentage; + size_t plen; if (args_has(args, 'M')) { if (cmd_mouse_window(&shared->mouse, &s) == NULL) @@ -91,21 +93,58 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) } } - if (args_has(args, 'x')) { - x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX, &cause); - if (cause != NULL) { - cmdq_error(item, "width %s", cause); - free(cause); - return (CMD_RETURN_ERROR); + if ((p = args_get(args, 'x')) != 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, "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) { + cmdq_error(item, "width %s", cause); + free(cause); + return (CMD_RETURN_ERROR); + } } layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x); } - if (args_has(args, 'y')) { - y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX, &cause); - if (cause != NULL) { - cmdq_error(item, "height %s", cause); - free(cause); - return (CMD_RETURN_ERROR); + if ((p = args_get(args, 'y')) != 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, "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) { + cmdq_error(item, "height %s", cause); + free(cause); + return (CMD_RETURN_ERROR); + } } layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y); } diff --git a/cmd-split-window.c b/cmd-split-window.c index d004aa95..748ae49b 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -42,8 +42,7 @@ const struct cmd_entry cmd_split_window_entry = { .args = { "bc:de:fF:hIl:p:Pt:v", 0, -1 }, .usage = "[-bdefhIPv] [-c start-directory] [-e environment] " - "[-F format] [-p percentage|-l size] " CMD_TARGET_PANE_USAGE - " [command]", + "[-F format] [-l size] " CMD_TARGET_PANE_USAGE " [command]", .target = { 't', CMD_FIND_PANE, 0 }, @@ -65,20 +64,37 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) struct layout_cell *lc; struct cmd_find_state fs; int size, percentage, flags, input; - const char *template, *add; - char *cause, *cp; + const char *template, *add, *errstr, *p; + char *cause, *cp, *copy; + size_t plen; struct args_value *value; if (args_has(args, 'h')) type = LAYOUT_LEFTRIGHT; else type = LAYOUT_TOPBOTTOM; - if (args_has(args, 'l')) { - size = args_strtonum(args, 'l', 0, INT_MAX, &cause); - if (cause != NULL) { - cmdq_error(item, "create pane failed: -l %s", cause); - free(cause); - return (CMD_RETURN_ERROR); + 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); + if (cause != NULL) { + cmdq_error(item, "lines %s", cause); + free(cause); + return (CMD_RETURN_ERROR); + } } } else if (args_has(args, 'p')) { percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause); @@ -1891,9 +1891,7 @@ zooms the pane. This command works only if at least one client is attached. .It Xo Ic join-pane .Op Fl bdhv -.Oo Fl l -.Ar size | -.Fl p Ar percentage Oc +.Op Fl l Ar size .Op Fl s Ar src-pane .Op Fl t Ar dst-pane .Xc @@ -2030,9 +2028,7 @@ flag, see the section. .It Xo Ic move-pane .Op Fl bdhv -.Oo Fl l -.Ar size | -.Fl p Ar percentage Oc +.Op Fl l Ar size .Op Fl s Ar src-pane .Op Fl t Ar dst-pane .Xc @@ -2241,8 +2237,14 @@ or .Fl y . The .Ar adjustment -is given in lines or cells (the default is 1). -.Pp +is given in lines or columns (the default is 1); +.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 .Fl Z , 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 c Ar start-directory .Op Fl e Ar environment -.Oo Fl l -.Ar size | -.Fl p Ar percentage Oc +.Op Fl l Ar size .Op Fl t Ar target-pane .Op Ar shell-command .Op Fl F Ar format @@ -2452,10 +2452,12 @@ a vertical split; if neither is specified, is assumed. The .Fl l -and -.Fl p -options specify the size of the new pane in lines (for vertical split) or in -cells (for horizontal split), or as a percentage, respectively. +option specifies the size of the new pane in lines (for vertical split) or in +columns (for horizontal split); +.Ar size +may be followed by +.Ql % +to specify a percentage of the available space. The .Fl b option causes the new pane to be created to the left of or above |