diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-02-18 17:00:35 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-02-18 17:00:35 +0000 |
commit | e4bb87032eb851338aa77bceb3e4581da3281a1d (patch) | |
tree | 2f3d1e4231f7e644615113753f1aec7f286d992b | |
parent | a6c4c2cca0d44e0cec9d4a0cc041290a263826fb (diff) |
Add resize-pane -x and -y for absolute pane size.
-rw-r--r-- | cmd-resize-pane.c | 27 | ||||
-rw-r--r-- | layout.c | 36 | ||||
-rw-r--r-- | tmux.1 | 20 | ||||
-rw-r--r-- | tmux.h | 10 |
4 files changed, 81 insertions, 12 deletions
diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index 74f6354c..328e1b4d 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -31,8 +31,8 @@ enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_resize_pane_entry = { "resize-pane", "resizep", - "DLRt:U", 0, 1, - "[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]", + "DLRt:Ux:y:", 0, 1, + "[-DLRU] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]", 0, cmd_resize_pane_key_binding, NULL, @@ -87,8 +87,10 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx) struct args *args = self->args; struct winlink *wl; const char *errstr; + char *cause; struct window_pane *wp; u_int adjust; + int x, y; if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) return (CMD_RETURN_ERROR); @@ -103,6 +105,27 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx) } } + if (args_has(self->args, 'x')) { + x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX, + &cause); + if (cause != NULL) { + ctx->error(ctx, "width %s", cause); + free(cause); + return (CMD_RETURN_ERROR); + } + layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x); + } + if (args_has(self->args, 'y')) { + y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX, + &cause); + if (cause != NULL) { + ctx->error(ctx, "height %s", cause); + free(cause); + return (CMD_RETURN_ERROR); + } + layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y); + } + if (args_has(self->args, 'L')) layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust); else if (args_has(self->args, 'R')) @@ -443,6 +443,39 @@ layout_resize(struct window *w, u_int sx, u_int sy) layout_fix_panes(w, sx, sy); } +/* Resize a pane to an absolute size. */ +void +layout_resize_pane_to(struct window_pane *wp, enum layout_type type, + u_int new_size) +{ + struct layout_cell *lc, *lcparent; + int change, size; + + lc = wp->layout_cell; + + /* Find next parent of the same type. */ + lcparent = lc->parent; + while (lcparent != NULL && lcparent->type != type) { + lc = lcparent; + lcparent = lc->parent; + } + if (lcparent == NULL) + return; + + /* Work out the size adjustment. */ + if (type == LAYOUT_LEFTRIGHT) + size = lc->sx; + else + size = lc->sy; + if (lc == TAILQ_LAST(&lcparent->cells, layout_cells)) + change = size - new_size; + else + change = new_size - size; + + /* Resize the pane. */ + layout_resize_pane(wp, type, change); +} + /* Resize a single pane within the layout. */ void layout_resize_pane(struct window_pane *wp, enum layout_type type, int change) @@ -486,6 +519,7 @@ layout_resize_pane(struct window_pane *wp, enum layout_type type, int change) notify_window_layout_changed(wp->window); } +/* Resize pane based on mouse events. */ void layout_resize_pane_mouse(struct client *c) { @@ -534,6 +568,7 @@ layout_resize_pane_mouse(struct client *c) m->flags &= ~MOUSE_RESIZE_PANE; } +/* Helper function to grow pane. */ int layout_resize_pane_grow( struct layout_cell *lc, enum layout_type type, int needed) @@ -574,6 +609,7 @@ layout_resize_pane_grow( return (size); } +/* Helper function to shrink pane. */ int layout_resize_pane_shrink( struct layout_cell *lc, enum layout_type type, int needed) @@ -1557,17 +1557,25 @@ if specified, to .It Xo Ic resize-pane .Op Fl DLRU .Op Fl t Ar target-pane +.Op Fl x Ar width +.Op Fl y Ar height .Op Ar adjustment .Xc .D1 (alias: Ic resizep ) -Resize a pane, upward with -.Fl U -(the default), downward with +Resize a pane, up, down, left or right by +.Ar adjustment +with +.Fl U , .Fl D , -to the left with .Fl L -and to the right with -.Fl R . +or +.Fl R , +or +to an absolute size +with +.Fl x +or +.Fl y . The .Ar adjustment is given in lines or cells (the default is 1). @@ -1167,7 +1167,7 @@ struct mouse_event { u_int sgr; /* whether the input arrived in SGR format */ u_int sgr_xb; /* only for SGR: the unmangled button */ - u_int sgr_rel; /* only for SGR: whether it is a release event */ + u_int sgr_rel; /* only for SGR: if it is a release event */ u_int button; u_int clicks; @@ -2163,9 +2163,11 @@ void layout_resize_adjust( void layout_init(struct window *); void layout_free(struct window *); void layout_resize(struct window *, u_int, u_int); -void layout_resize_pane( - struct window_pane *, enum layout_type, int); -void layout_resize_pane_mouse(struct client *c); +void layout_resize_pane(struct window_pane *, enum layout_type, + int); +void layout_resize_pane_to(struct window_pane *, enum layout_type, + u_int); +void layout_resize_pane_mouse(struct client *); void layout_assign_pane(struct layout_cell *, struct window_pane *); struct layout_cell *layout_split_pane( struct window_pane *, enum layout_type, int, int); |