cmd-resize-window.c revision 1.1 1 1.1 christos /* $OpenBSD$ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 2018 Nicholas Marriott <nicholas.marriott (at) gmail.com>
5 1.1 christos *
6 1.1 christos * Permission to use, copy, modify, and distribute this software for any
7 1.1 christos * purpose with or without fee is hereby granted, provided that the above
8 1.1 christos * copyright notice and this permission notice appear in all copies.
9 1.1 christos *
10 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 1.1 christos * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 1.1 christos * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 1.1 christos */
18 1.1 christos
19 1.1 christos #include <sys/types.h>
20 1.1 christos
21 1.1 christos #include <stdlib.h>
22 1.1 christos
23 1.1 christos #include "tmux.h"
24 1.1 christos
25 1.1 christos /*
26 1.1 christos * Increase or decrease window size.
27 1.1 christos */
28 1.1 christos
29 1.1 christos static enum cmd_retval cmd_resize_window_exec(struct cmd *,
30 1.1 christos struct cmdq_item *);
31 1.1 christos
32 1.1 christos const struct cmd_entry cmd_resize_window_entry = {
33 1.1 christos .name = "resize-window",
34 1.1 christos .alias = "resizew",
35 1.1 christos
36 1.1 christos .args = { "aADLRt:Ux:y:", 0, 1 },
37 1.1 christos .usage = "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE " "
38 1.1 christos "[adjustment]",
39 1.1 christos
40 1.1 christos .target = { 't', CMD_FIND_WINDOW, 0 },
41 1.1 christos
42 1.1 christos .flags = CMD_AFTERHOOK,
43 1.1 christos .exec = cmd_resize_window_exec
44 1.1 christos };
45 1.1 christos
46 1.1 christos static enum cmd_retval
47 1.1 christos cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
48 1.1 christos {
49 1.1 christos struct args *args = self->args;
50 1.1 christos struct winlink *wl = item->target.wl;
51 1.1 christos struct window *w = wl->window;
52 1.1 christos struct session *s = item->target.s;
53 1.1 christos const char *errstr;
54 1.1 christos char *cause;
55 1.1 christos u_int adjust, sx, sy;
56 1.1 christos
57 1.1 christos if (args->argc == 0)
58 1.1 christos adjust = 1;
59 1.1 christos else {
60 1.1 christos adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
61 1.1 christos if (errstr != NULL) {
62 1.1 christos cmdq_error(item, "adjustment %s", errstr);
63 1.1 christos return (CMD_RETURN_ERROR);
64 1.1 christos }
65 1.1 christos }
66 1.1 christos
67 1.1 christos sx = w->sx;
68 1.1 christos sy = w->sy;
69 1.1 christos
70 1.1 christos if (args_has(args, 'x')) {
71 1.1 christos sx = args_strtonum(args, 'x', WINDOW_MINIMUM, WINDOW_MAXIMUM,
72 1.1 christos &cause);
73 1.1 christos if (cause != NULL) {
74 1.1 christos cmdq_error(item, "width %s", cause);
75 1.1 christos free(cause);
76 1.1 christos return (CMD_RETURN_ERROR);
77 1.1 christos }
78 1.1 christos }
79 1.1 christos if (args_has(args, 'y')) {
80 1.1 christos sy = args_strtonum(args, 'y', WINDOW_MINIMUM, WINDOW_MAXIMUM,
81 1.1 christos &cause);
82 1.1 christos if (cause != NULL) {
83 1.1 christos cmdq_error(item, "height %s", cause);
84 1.1 christos free(cause);
85 1.1 christos return (CMD_RETURN_ERROR);
86 1.1 christos }
87 1.1 christos }
88 1.1 christos
89 1.1 christos if (args_has(args, 'L')) {
90 1.1 christos if (sx >= adjust)
91 1.1 christos sx -= adjust;
92 1.1 christos } else if (args_has(args, 'R'))
93 1.1 christos sx += adjust;
94 1.1 christos else if (args_has(args, 'U')) {
95 1.1 christos if (sy >= adjust)
96 1.1 christos sy -= adjust;
97 1.1 christos } else if (args_has(args, 'D'))
98 1.1 christos sy += adjust;
99 1.1 christos
100 1.1 christos if (args_has(args, 'A'))
101 1.1 christos default_window_size(s, w, &sx, &sy, WINDOW_SIZE_LARGEST);
102 1.1 christos else if (args_has(args, 'a'))
103 1.1 christos default_window_size(s, w, &sx, &sy, WINDOW_SIZE_SMALLEST);
104 1.1 christos
105 1.1 christos options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL);
106 1.1 christos resize_window(w, sx, sy);
107 1.1 christos
108 1.1 christos return (CMD_RETURN_NORMAL);
109 1.1 christos }
110