diff options
author | Thomas Adam <thomas@xteddy.org> | 2019-10-15 10:01:28 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2019-10-15 10:01:28 +0100 |
commit | fb7ce5b5d509db244111e130224f366ced28b228 (patch) | |
tree | 7359b965c7b1bd25e19256dba1c3318dca6359c4 | |
parent | eb57cbcc296b10d8d9ea41930ab402717c800f9c (diff) | |
parent | 9fd62efcf0392cda0ddd1b7836e98da08d0a6f9f (diff) | |
download | rtmux-fb7ce5b5d509db244111e130224f366ced28b228.tar.gz rtmux-fb7ce5b5d509db244111e130224f366ced28b228.tar.bz2 rtmux-fb7ce5b5d509db244111e130224f366ced28b228.zip |
Merge branch 'obsd-master'
-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-- | options.c | 53 | ||||
-rw-r--r-- | tmux.1 | 32 | ||||
-rw-r--r-- | window-tree.c | 4 |
6 files changed, 163 insertions, 70 deletions
diff --git a/cmd-join-pane.c b/cmd-join-pane.c index 5d0e0d6a..b97e5f8d 100644 --- a/cmd-join-pane.c +++ b/cmd-join-pane.c @@ -20,6 +20,7 @@ #include <sys/types.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include "tmux.h" @@ -35,7 +36,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 }, @@ -67,11 +68,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; @@ -104,12 +107,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 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); @@ -321,6 +321,17 @@ options_array_item(struct options_entry *o, u_int idx) return (RB_FIND(options_array, &o->value.array, &a)); } +static struct options_array_item * +options_array_new(struct options_entry *o, u_int idx) +{ + struct options_array_item *a; + + a = xcalloc(1, sizeof *a); + a->index = idx; + RB_INSERT(options_array, &o->value.array, a); + return (a); +} + static void options_array_free(struct options_entry *o, struct options_array_item *a) { @@ -368,7 +379,14 @@ options_array_set(struct options_entry *o, u_int idx, const char *value, return (-1); } - if (OPTIONS_IS_COMMAND(o) && value != NULL) { + if (value == NULL) { + a = options_array_item(o, idx); + if (a != NULL) + options_array_free(o, a); + return (0); + } + + if (OPTIONS_IS_COMMAND(o)) { pr = cmd_parse_from_string(value, NULL); switch (pr->status) { case CMD_PARSE_EMPTY: @@ -384,34 +402,33 @@ options_array_set(struct options_entry *o, u_int idx, const char *value, case CMD_PARSE_SUCCESS: break; } - } - a = options_array_item(o, idx); - if (value == NULL) { - if (a != NULL) - options_array_free(o, a); + a = options_array_item(o, idx); + if (a == NULL) + a = options_array_new(o, idx); + else + options_value_free(o, &a->value); + a->value.cmdlist = pr->cmdlist; return (0); } if (OPTIONS_IS_STRING(o)) { + a = options_array_item(o, idx); if (a != NULL && append) xasprintf(&new, "%s%s", a->value.string, value); else new = xstrdup(value); + if (a == NULL) + a = options_array_new(o, idx); + else + options_value_free(o, &a->value); + a->value.string = new; + return (0); } - if (a == NULL) { - a = xcalloc(1, sizeof *a); - a->index = idx; - RB_INSERT(options_array, &o->value.array, a); - } else - options_value_free(o, &a->value); - - if (OPTIONS_IS_STRING(o)) - a->value.string = new; - else if (OPTIONS_IS_COMMAND(o)) - a->value.cmdlist = pr->cmdlist; - return (0); + if (cause != NULL) + *cause = xstrdup("wrong array type"); + return (-1); } int @@ -1896,9 +1896,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 @@ -2035,9 +2033,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 @@ -2246,8 +2242,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) @@ -2439,9 +2441,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 @@ -2457,10 +2457,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 diff --git a/window-tree.c b/window-tree.c index 9909036c..4f4cbaab 100644 --- a/window-tree.c +++ b/window-tree.c @@ -191,7 +191,7 @@ window_tree_cmp_session(const void *a0, const void *b0) const struct session *const *b = b0; const struct session *sa = *a; const struct session *sb = *b; - int result; + int result = 0; switch (window_tree_sort->field) { case WINDOW_TREE_BY_INDEX: @@ -226,7 +226,7 @@ window_tree_cmp_window(const void *a0, const void *b0) const struct winlink *wlb = *b; struct window *wa = wla->window; struct window *wb = wlb->window; - int result; + int result = 0; switch (window_tree_sort->field) { case WINDOW_TREE_BY_INDEX: |