diff options
author | nicm <nicm> | 2019-10-15 08:25:37 +0000 |
---|---|---|
committer | nicm <nicm> | 2019-10-15 08:25:37 +0000 |
commit | 0c5e9c6efae5c3fae84c35f655754fef242c6acc (patch) | |
tree | 21d540dbb1e8c9e20b753ca100d9b0e7fb3afe87 /cmd-resize-pane.c | |
parent | b598bbcc2e8b26855e4d34dfff9c222c28080cd7 (diff) | |
download | rtmux-0c5e9c6efae5c3fae84c35f655754fef242c6acc.tar.gz rtmux-0c5e9c6efae5c3fae84c35f655754fef242c6acc.tar.bz2 rtmux-0c5e9c6efae5c3fae84c35f655754fef242c6acc.zip |
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.
Diffstat (limited to 'cmd-resize-pane.c')
-rw-r--r-- | cmd-resize-pane.c | 69 |
1 files changed, 54 insertions, 15 deletions
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); } |