summaryrefslogtreecommitdiffstats
path: root/cmd-split-window.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2022-06-07 14:01:09 +0100
committerThomas Adam <thomas@xteddy.org>2022-06-07 14:01:09 +0100
commitbe2eb57d6295a72b870841bbb85e65d624c5d87c (patch)
tree3fde58f40fefb97cbf42a10fa961ebdaafe02769 /cmd-split-window.c
parentafb3a5fe7180f73457346cf12d096497d93aa642 (diff)
parentc07d582e2476db075252998388305f11302a8b23 (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'cmd-split-window.c')
-rw-r--r--cmd-split-window.c79
1 files changed, 29 insertions, 50 deletions
diff --git a/cmd-split-window.c b/cmd-split-window.c
index 9947dfd3..637bad30 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -65,67 +65,46 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
enum layout_type type;
struct layout_cell *lc;
struct cmd_find_state fs;
- int size, percentage, flags, input;
- const char *template, *errstr, *p;
- char *cause, *cp, *copy;
- size_t plen;
+ int size, flags, input;
+ const char *template;
+ char *cause = NULL, *cp;
struct args_value *av;
- u_int count = args_count(args);
+ u_int count = args_count(args), curval = 0;
+ type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
type = LAYOUT_LEFTRIGHT;
- else
- type = LAYOUT_TOPBOTTOM;
- 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 (args_has(args, 'f')) {
- if (type == LAYOUT_TOPBOTTOM)
- size = (w->sy * percentage) / 100;
- else
- size = (w->sx * percentage) / 100;
- } else {
- 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);
- if (cause != NULL) {
- cmdq_error(item, "create pane failed: -p %s", cause);
- free(cause);
- return (CMD_RETURN_ERROR);
- }
+
+ /* If the 'p' flag is dropped then this bit can be moved into 'l'. */
+ if (args_has(args, 'l') || args_has(args, 'p')) {
if (args_has(args, 'f')) {
if (type == LAYOUT_TOPBOTTOM)
- size = (w->sy * percentage) / 100;
+ curval = w->sy;
else
- size = (w->sx * percentage) / 100;
+ curval = w->sx;
} else {
if (type == LAYOUT_TOPBOTTOM)
- size = (wp->sy * percentage) / 100;
+ curval = wp->sy;
else
- size = (wp->sx * percentage) / 100;
+ curval = wp->sx;
}
- } else
- size = -1;
+ }
+
+ size = -1;
+ if (args_has(args, 'l')) {
+ size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
+ item, &cause);
+ } else if (args_has(args, 'p')) {
+ size = args_strtonum_and_expand(args, 'l', 0, 100, item,
+ &cause);
+ if (cause == NULL)
+ size = curval * size / 100;
+ }
+ if (cause != NULL) {
+ cmdq_error(item, "size %s", cause);
+ free(cause);
+ return (CMD_RETURN_ERROR);
+ }
window_push_zoom(wp->window, 1, args_has(args, 'Z'));
input = (args_has(args, 'I') && count == 0);