From f0efa576e002e77dc6363e0a5bc41d0c0649c946 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 22 Mar 2013 10:37:39 +0000 Subject: Add resize-pane -x and -y for absolute pane size (much requested). --- cmd-resize-pane.c | 27 +++++++++++++++++++++++++-- layout.c | 36 ++++++++++++++++++++++++++++++++++++ tmux.1 | 20 ++++++++++++++------ tmux.h | 10 ++++++---- 4 files changed, 81 insertions(+), 12 deletions(-) diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index c200ee10..dbcebbcf 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')) diff --git a/layout.c b/layout.c index 7c13b539..f08580b7 100644 --- a/layout.c +++ b/layout.c @@ -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) diff --git a/tmux.1 b/tmux.1 index acb1a4c1..674b6506 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1553,17 +1553,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). diff --git a/tmux.h b/tmux.h index 192a386f..c5090c9f 100644 --- a/tmux.h +++ b/tmux.h @@ -1171,7 +1171,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; @@ -2167,9 +2167,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); -- cgit v1.2.3