diff options
author | nicm <nicm> | 2020-03-21 13:16:15 +0000 |
---|---|---|
committer | nicm <nicm> | 2020-03-21 13:16:15 +0000 |
commit | 8828b958f04747cbf6126ec3443007b29570413a (patch) | |
tree | 898ba815452b7b40b15fc798dd41b46dab655091 /cmd-resize-pane.c | |
parent | 5aeab5ab4075c7740c223678df1548dc4a402d83 (diff) | |
download | rtmux-8828b958f04747cbf6126ec3443007b29570413a.tar.gz rtmux-8828b958f04747cbf6126ec3443007b29570413a.tar.bz2 rtmux-8828b958f04747cbf6126ec3443007b29570413a.zip |
Break code to convert an argument as a percentage into a common function.
Diffstat (limited to 'cmd-resize-pane.c')
-rw-r--r-- | cmd-resize-pane.c | 68 |
1 files changed, 15 insertions, 53 deletions
diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index 3962546d..b0aa2756 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -56,11 +56,10 @@ 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, *p; - char *cause, *copy; + const char *errstr; + char *cause; u_int adjust; - int x, y, percentage; - size_t plen; + int x, y; if (args_has(args, 'M')) { if (cmd_mouse_window(&shared->mouse, &s) == NULL) @@ -93,58 +92,21 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) } } - 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); - } + if (args_has(args, 'x')) { + x = args_percentage(args, 'x', 0, INT_MAX, w->sx, &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 ((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); - } + if (args_has(args, 'y')) { + y = args_percentage(args, 'y', 0, INT_MAX, w->sy, &cause); + if (cause != NULL) { + cmdq_error(item, "width %s", cause); + free(cause); + return (CMD_RETURN_ERROR); } layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y); } |