This commit was manufactured by cvs2svn to create tag 'TMUX_1_2'.
[tmux.git] / cmd-resize-pane.c
bloba608c5e5531c913788b48a006675fa9f1bdf9a0c
1 /* $Id: cmd-resize-pane.c,v 1.14 2009-12-04 22:14:47 tcunha Exp $ */
3 /*
4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
21 #include <stdlib.h>
23 #include "tmux.h"
26 * Increase or decrease pane size.
29 void cmd_resize_pane_init(struct cmd *, int);
30 int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
32 const struct cmd_entry cmd_resize_pane_entry = {
33 "resize-pane", "resizep",
34 "[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
35 CMD_ARG01, "DLRU",
36 cmd_resize_pane_init,
37 cmd_target_parse,
38 cmd_resize_pane_exec,
39 cmd_target_free,
40 cmd_target_print
43 void
44 cmd_resize_pane_init(struct cmd *self, int key)
46 struct cmd_target_data *data;
48 cmd_target_init(self, key);
49 data = self->data;
51 if (key == (KEYC_UP | KEYC_CTRL))
52 cmd_set_flag(&data->chflags, 'U');
53 if (key == (KEYC_DOWN | KEYC_CTRL))
54 cmd_set_flag(&data->chflags, 'D');
55 if (key == (KEYC_LEFT | KEYC_CTRL))
56 cmd_set_flag(&data->chflags, 'L');
57 if (key == (KEYC_RIGHT | KEYC_CTRL))
58 cmd_set_flag(&data->chflags, 'R');
60 if (key == (KEYC_UP | KEYC_ESCAPE)) {
61 cmd_set_flag(&data->chflags, 'U');
62 data->arg = xstrdup("5");
64 if (key == (KEYC_DOWN | KEYC_ESCAPE)) {
65 cmd_set_flag(&data->chflags, 'D');
66 data->arg = xstrdup("5");
68 if (key == (KEYC_LEFT | KEYC_ESCAPE)) {
69 cmd_set_flag(&data->chflags, 'L');
70 data->arg = xstrdup("5");
72 if (key == (KEYC_RIGHT | KEYC_ESCAPE)) {
73 cmd_set_flag(&data->chflags, 'R');
74 data->arg = xstrdup("5");
78 int
79 cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
81 struct cmd_target_data *data = self->data;
82 struct winlink *wl;
83 const char *errstr;
84 struct window_pane *wp;
85 u_int adjust;
87 if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
88 return (-1);
90 if (data->arg == NULL)
91 adjust = 1;
92 else {
93 adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
94 if (errstr != NULL) {
95 ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
96 return (-1);
100 if (cmd_check_flag(data->chflags, 'L'))
101 layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
102 else if (cmd_check_flag(data->chflags, 'R'))
103 layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
104 else if (cmd_check_flag(data->chflags, 'U'))
105 layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
106 else if (cmd_check_flag(data->chflags, 'D'))
107 layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
108 server_redraw_window(wl->window);
110 return (0);