summaryrefslogtreecommitdiffstats
path: root/cmd-split-window.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-10-15 10:01:28 +0100
committerThomas Adam <thomas@xteddy.org>2019-10-15 10:01:28 +0100
commitfb7ce5b5d509db244111e130224f366ced28b228 (patch)
tree7359b965c7b1bd25e19256dba1c3318dca6359c4 /cmd-split-window.c
parenteb57cbcc296b10d8d9ea41930ab402717c800f9c (diff)
parent9fd62efcf0392cda0ddd1b7836e98da08d0a6f9f (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'cmd-split-window.c')
-rw-r--r--cmd-split-window.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/cmd-split-window.c b/cmd-split-window.c
index 8d63473f..eaf1f74c 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -41,8 +41,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 },
@@ -64,20 +63,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);