4 * Copyright (c) 2018 Nicholas Marriott <nicholas.marriott@gmail.com>
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 window size.
29 static enum cmd_retval
cmd_resize_window_exec(struct cmd
*,
32 const struct cmd_entry cmd_resize_window_entry
= {
33 .name
= "resize-window",
36 .args
= { "aADLRt:Ux:y:", 0, 1, NULL
},
37 .usage
= "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE
" "
40 .target
= { 't', CMD_FIND_WINDOW
, 0 },
42 .flags
= CMD_AFTERHOOK
,
43 .exec
= cmd_resize_window_exec
46 static enum cmd_retval
47 cmd_resize_window_exec(struct cmd
*self
, struct cmdq_item
*item
)
49 struct args
*args
= cmd_get_args(self
);
50 struct cmd_find_state
*target
= cmdq_get_target(item
);
51 struct winlink
*wl
= target
->wl
;
52 struct window
*w
= wl
->window
;
53 struct session
*s
= target
->s
;
56 u_int adjust
, sx
, sy
, xpixel
= 0, ypixel
= 0;
58 if (args_count(args
) == 0)
61 adjust
= strtonum(args_string(args
, 0), 1, INT_MAX
, &errstr
);
63 cmdq_error(item
, "adjustment %s", errstr
);
64 return (CMD_RETURN_ERROR
);
71 if (args_has(args
, 'x')) {
72 sx
= args_strtonum(args
, 'x', WINDOW_MINIMUM
, WINDOW_MAXIMUM
,
75 cmdq_error(item
, "width %s", cause
);
77 return (CMD_RETURN_ERROR
);
80 if (args_has(args
, 'y')) {
81 sy
= args_strtonum(args
, 'y', WINDOW_MINIMUM
, WINDOW_MAXIMUM
,
84 cmdq_error(item
, "height %s", cause
);
86 return (CMD_RETURN_ERROR
);
90 if (args_has(args
, 'L')) {
93 } else if (args_has(args
, 'R'))
95 else if (args_has(args
, 'U')) {
98 } else if (args_has(args
, 'D'))
101 if (args_has(args
, 'A')) {
102 default_window_size(NULL
, s
, w
, &sx
, &sy
, &xpixel
, &ypixel
,
103 WINDOW_SIZE_LARGEST
);
104 } else if (args_has(args
, 'a')) {
105 default_window_size(NULL
, s
, w
, &sx
, &sy
, &xpixel
, &ypixel
,
106 WINDOW_SIZE_SMALLEST
);
109 options_set_number(w
->options
, "window-size", WINDOW_SIZE_MANUAL
);
112 recalculate_size(w
, 1);
114 return (CMD_RETURN_NORMAL
);