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>
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]",
44 cmd_resize_pane_init(struct cmd
*self
, int key
)
46 struct cmd_target_data
*data
;
48 cmd_target_init(self
, key
);
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");
79 cmd_resize_pane_exec(struct cmd
*self
, struct cmd_ctx
*ctx
)
81 struct cmd_target_data
*data
= self
->data
;
84 struct window_pane
*wp
;
87 if ((wl
= cmd_find_pane(ctx
, data
->target
, NULL
, &wp
)) == NULL
)
90 if (data
->arg
== NULL
)
93 adjust
= strtonum(data
->arg
, 1, INT_MAX
, &errstr
);
95 ctx
->error(ctx
, "adjustment %s: %s", errstr
, data
->arg
);
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
);