cmd-resize-pane.c revision 1.1 1 /* $Id: cmd-resize-pane.c,v 1.1 2011/03/10 09:15:37 jmmv Exp $ */
2
3 /*
4 * Copyright (c) 2009 Nicholas Marriott <nicm (at) users.sourceforge.net>
5 *
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.
9 *
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.
17 */
18
19 #include <sys/types.h>
20
21 #include <stdlib.h>
22
23 #include "tmux.h"
24
25 /*
26 * Increase or decrease pane size.
27 */
28
29 void cmd_resize_pane_init(struct cmd *, int);
30 int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
31
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
41 };
42
43 void
44 cmd_resize_pane_init(struct cmd *self, int key)
45 {
46 struct cmd_target_data *data;
47
48 cmd_target_init(self, key);
49 data = self->data;
50
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');
59
60 if (key == (KEYC_UP | KEYC_ESCAPE)) {
61 cmd_set_flag(&data->chflags, 'U');
62 data->arg = xstrdup("5");
63 }
64 if (key == (KEYC_DOWN | KEYC_ESCAPE)) {
65 cmd_set_flag(&data->chflags, 'D');
66 data->arg = xstrdup("5");
67 }
68 if (key == (KEYC_LEFT | KEYC_ESCAPE)) {
69 cmd_set_flag(&data->chflags, 'L');
70 data->arg = xstrdup("5");
71 }
72 if (key == (KEYC_RIGHT | KEYC_ESCAPE)) {
73 cmd_set_flag(&data->chflags, 'R');
74 data->arg = xstrdup("5");
75 }
76 }
77
78 int
79 cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
80 {
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;
86
87 if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
88 return (-1);
89
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);
97 }
98 }
99
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);
109
110 return (0);
111 }
112