/src/tmux/cmd-resize-window.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* $OpenBSD$ */ |
2 | | |
3 | | /* |
4 | | * Copyright (c) 2018 Nicholas Marriott <nicholas.marriott@gmail.com> |
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 window size. |
27 | | */ |
28 | | |
29 | | static enum cmd_retval cmd_resize_window_exec(struct cmd *, |
30 | | struct cmdq_item *); |
31 | | |
32 | | const struct cmd_entry cmd_resize_window_entry = { |
33 | | .name = "resize-window", |
34 | | .alias = "resizew", |
35 | | |
36 | | .args = { "aADLRt:Ux:y:", 0, 1, NULL }, |
37 | | .usage = "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE " " |
38 | | "[adjustment]", |
39 | | |
40 | | .target = { 't', CMD_FIND_WINDOW, 0 }, |
41 | | |
42 | | .flags = CMD_AFTERHOOK, |
43 | | .exec = cmd_resize_window_exec |
44 | | }; |
45 | | |
46 | | static enum cmd_retval |
47 | | cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item) |
48 | 0 | { |
49 | 0 | struct args *args = cmd_get_args(self); |
50 | 0 | struct cmd_find_state *target = cmdq_get_target(item); |
51 | 0 | struct winlink *wl = target->wl; |
52 | 0 | struct window *w = wl->window; |
53 | 0 | struct session *s = target->s; |
54 | 0 | const char *errstr; |
55 | 0 | char *cause; |
56 | 0 | u_int adjust, sx, sy; |
57 | 0 | int xpixel = -1, ypixel = -1; |
58 | |
|
59 | 0 | if (args_count(args) == 0) |
60 | 0 | adjust = 1; |
61 | 0 | else { |
62 | 0 | adjust = strtonum(args_string(args, 0), 1, INT_MAX, &errstr); |
63 | 0 | if (errstr != NULL) { |
64 | 0 | cmdq_error(item, "adjustment %s", errstr); |
65 | 0 | return (CMD_RETURN_ERROR); |
66 | 0 | } |
67 | 0 | } |
68 | | |
69 | 0 | sx = w->sx; |
70 | 0 | sy = w->sy; |
71 | |
|
72 | 0 | if (args_has(args, 'x')) { |
73 | 0 | sx = args_strtonum(args, 'x', WINDOW_MINIMUM, WINDOW_MAXIMUM, |
74 | 0 | &cause); |
75 | 0 | if (cause != NULL) { |
76 | 0 | cmdq_error(item, "width %s", cause); |
77 | 0 | free(cause); |
78 | 0 | return (CMD_RETURN_ERROR); |
79 | 0 | } |
80 | 0 | } |
81 | 0 | if (args_has(args, 'y')) { |
82 | 0 | sy = args_strtonum(args, 'y', WINDOW_MINIMUM, WINDOW_MAXIMUM, |
83 | 0 | &cause); |
84 | 0 | if (cause != NULL) { |
85 | 0 | cmdq_error(item, "height %s", cause); |
86 | 0 | free(cause); |
87 | 0 | return (CMD_RETURN_ERROR); |
88 | 0 | } |
89 | 0 | } |
90 | | |
91 | 0 | if (args_has(args, 'L')) { |
92 | 0 | if (sx >= adjust) |
93 | 0 | sx -= adjust; |
94 | 0 | } else if (args_has(args, 'R')) |
95 | 0 | sx += adjust; |
96 | 0 | else if (args_has(args, 'U')) { |
97 | 0 | if (sy >= adjust) |
98 | 0 | sy -= adjust; |
99 | 0 | } else if (args_has(args, 'D')) |
100 | 0 | sy += adjust; |
101 | |
|
102 | 0 | if (args_has(args, 'A')) { |
103 | 0 | default_window_size(NULL, s, w, &sx, &sy, &xpixel, &ypixel, |
104 | 0 | WINDOW_SIZE_LARGEST); |
105 | 0 | } else if (args_has(args, 'a')) { |
106 | 0 | default_window_size(NULL, s, w, &sx, &sy, &xpixel, &ypixel, |
107 | 0 | WINDOW_SIZE_SMALLEST); |
108 | 0 | } |
109 | |
|
110 | 0 | options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL); |
111 | 0 | w->manual_sx = sx; |
112 | 0 | w->manual_sy = sy; |
113 | 0 | recalculate_size(w, 1); |
114 | |
|
115 | 0 | return (CMD_RETURN_NORMAL); |
116 | 0 | } |