Annotation of src/usr.bin/tmux/cmd-resize-pane.c, Revision 1.17
1.17 ! nicm 1: /* $OpenBSD: cmd-resize-pane.c,v 1.16 2013/10/10 12:00:22 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2009 Nicholas Marriott <nicm@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:
1.14 nicm 29: enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
1.1 nicm 30:
31: const struct cmd_entry cmd_resize_pane_entry = {
32: "resize-pane", "resizep",
1.15 nicm 33: "DLRt:Ux:y:Z", 0, 1,
34: "[-DLRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
1.9 nicm 35: 0,
36: cmd_resize_pane_exec
1.1 nicm 37: };
38:
1.11 nicm 39: enum cmd_retval
1.14 nicm 40: cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
1.1 nicm 41: {
1.9 nicm 42: struct args *args = self->args;
1.1 nicm 43: struct winlink *wl;
1.15 nicm 44: struct window *w;
1.1 nicm 45: const char *errstr;
1.13 nicm 46: char *cause;
1.1 nicm 47: struct window_pane *wp;
48: u_int adjust;
1.13 nicm 49: int x, y;
1.1 nicm 50:
1.14 nicm 51: if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
1.11 nicm 52: return (CMD_RETURN_ERROR);
1.15 nicm 53: w = wl->window;
54:
55: if (args_has(args, 'Z')) {
56: if (w->flags & WINDOW_ZOOMED)
57: window_unzoom(w);
58: else
59: window_zoom(wp);
60: server_redraw_window(w);
61: server_status_window(w);
62: return (CMD_RETURN_NORMAL);
63: }
64: server_unzoom_window(w);
1.1 nicm 65:
1.9 nicm 66: if (args->argc == 0)
1.1 nicm 67: adjust = 1;
68: else {
1.9 nicm 69: adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
1.1 nicm 70: if (errstr != NULL) {
1.14 nicm 71: cmdq_error(cmdq, "adjustment %s", errstr);
1.11 nicm 72: return (CMD_RETURN_ERROR);
1.1 nicm 73: }
1.13 nicm 74: }
75:
76: if (args_has(self->args, 'x')) {
77: x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
78: &cause);
79: if (cause != NULL) {
1.14 nicm 80: cmdq_error(cmdq, "width %s", cause);
1.13 nicm 81: free(cause);
82: return (CMD_RETURN_ERROR);
83: }
84: layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
85: }
86: if (args_has(self->args, 'y')) {
87: y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX,
88: &cause);
89: if (cause != NULL) {
1.14 nicm 90: cmdq_error(cmdq, "height %s", cause);
1.13 nicm 91: free(cause);
92: return (CMD_RETURN_ERROR);
93: }
94: layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
1.1 nicm 95: }
96:
1.9 nicm 97: if (args_has(self->args, 'L'))
1.7 nicm 98: layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
1.9 nicm 99: else if (args_has(self->args, 'R'))
1.3 nicm 100: layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
1.9 nicm 101: else if (args_has(self->args, 'U'))
1.7 nicm 102: layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
1.9 nicm 103: else if (args_has(self->args, 'D'))
1.3 nicm 104: layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
1.1 nicm 105: server_redraw_window(wl->window);
106:
1.11 nicm 107: return (CMD_RETURN_NORMAL);
1.1 nicm 108: }