xref: /netbsd-src/external/bsd/tmux/dist/resize.c (revision 890b6d91a44b7fcb2dfbcbc1e93463086e462d2d)
15494e770Schristos /* $OpenBSD$ */
2698d5317Sjmmv 
3698d5317Sjmmv /*
4ed4e6cd4Schristos  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5698d5317Sjmmv  *
6698d5317Sjmmv  * Permission to use, copy, modify, and distribute this software for any
7698d5317Sjmmv  * purpose with or without fee is hereby granted, provided that the above
8698d5317Sjmmv  * copyright notice and this permission notice appear in all copies.
9698d5317Sjmmv  *
10698d5317Sjmmv  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11698d5317Sjmmv  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12698d5317Sjmmv  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13698d5317Sjmmv  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14698d5317Sjmmv  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15698d5317Sjmmv  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16698d5317Sjmmv  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17698d5317Sjmmv  */
18698d5317Sjmmv 
19698d5317Sjmmv #include <sys/types.h>
20698d5317Sjmmv 
21698d5317Sjmmv #include <string.h>
22698d5317Sjmmv 
23698d5317Sjmmv #include "tmux.h"
24698d5317Sjmmv 
25ef36e747Schristos void
26aa83ff61Schristos resize_window(struct window *w, u_int sx, u_int sy, int xpixel, int ypixel)
27ef36e747Schristos {
28ef36e747Schristos 	int	zoomed;
29ef36e747Schristos 
30ef36e747Schristos 	/* Check size limits. */
31ef36e747Schristos 	if (sx < WINDOW_MINIMUM)
32ef36e747Schristos 		sx = WINDOW_MINIMUM;
33ef36e747Schristos 	if (sx > WINDOW_MAXIMUM)
34ef36e747Schristos 		sx = WINDOW_MAXIMUM;
35ef36e747Schristos 	if (sy < WINDOW_MINIMUM)
36ef36e747Schristos 		sy = WINDOW_MINIMUM;
37ef36e747Schristos 	if (sy > WINDOW_MAXIMUM)
38ef36e747Schristos 		sy = WINDOW_MAXIMUM;
39ef36e747Schristos 
40ef36e747Schristos 	/* If the window is zoomed, unzoom. */
41ef36e747Schristos 	zoomed = w->flags & WINDOW_ZOOMED;
42ef36e747Schristos 	if (zoomed)
43*890b6d91Swiz 		window_unzoom(w, 1);
44ef36e747Schristos 
45ef36e747Schristos 	/* Resize the layout first. */
46ef36e747Schristos 	layout_resize(w, sx, sy);
47ef36e747Schristos 
48ef36e747Schristos 	/* Resize the window, it can be no smaller than the layout. */
49ef36e747Schristos 	if (sx < w->layout_root->sx)
50ef36e747Schristos 		sx = w->layout_root->sx;
51ef36e747Schristos 	if (sy < w->layout_root->sy)
52ef36e747Schristos 		sy = w->layout_root->sy;
53aa83ff61Schristos 	window_resize(w, sx, sy, xpixel, ypixel);
5446548964Swiz 	log_debug("%s: @%u resized to %ux%u; layout %ux%u", __func__, w->id,
55ef36e747Schristos 	    sx, sy, w->layout_root->sx, w->layout_root->sy);
56ef36e747Schristos 
57ef36e747Schristos 	/* Restore the window zoom state. */
58ef36e747Schristos 	if (zoomed)
59ef36e747Schristos 		window_zoom(w->active);
60ef36e747Schristos 
61ef36e747Schristos 	tty_update_window_offset(w);
62ef36e747Schristos 	server_redraw_window(w);
63ef36e747Schristos 	notify_window("window-layout-changed", w);
6446548964Swiz 	notify_window("window-resized", w);
65e271dbb8Schristos 	w->flags &= ~WINDOW_RESIZE;
66ef36e747Schristos }
67ef36e747Schristos 
68ef36e747Schristos static int
69ef36e747Schristos ignore_client_size(struct client *c)
70ef36e747Schristos {
71aa83ff61Schristos 	struct client	*loop;
72aa83ff61Schristos 
73ef36e747Schristos 	if (c->session == NULL)
74ef36e747Schristos 		return (1);
75ef36e747Schristos 	if (c->flags & CLIENT_NOSIZEFLAGS)
76ef36e747Schristos 		return (1);
77e271dbb8Schristos 	if (c->flags & CLIENT_IGNORESIZE) {
78aa83ff61Schristos 		/*
79e271dbb8Schristos 		 * Ignore flagged clients if there are any attached clients
80e271dbb8Schristos 		 * that aren't flagged.
81aa83ff61Schristos 		 */
82aa83ff61Schristos 		TAILQ_FOREACH (loop, &clients, entry) {
83aa83ff61Schristos 			if (loop->session == NULL)
84aa83ff61Schristos 				continue;
85aa83ff61Schristos 			if (loop->flags & CLIENT_NOSIZEFLAGS)
86aa83ff61Schristos 				continue;
87e271dbb8Schristos 			if (~loop->flags & CLIENT_IGNORESIZE)
88aa83ff61Schristos 				return (1);
89aa83ff61Schristos 		}
90aa83ff61Schristos 	}
9146548964Swiz 	if ((c->flags & CLIENT_CONTROL) &&
9246548964Swiz 	    (~c->flags & CLIENT_SIZECHANGED) &&
9346548964Swiz 	    (~c->flags & CLIENT_WINDOWSIZECHANGED))
94ef36e747Schristos 		return (1);
95ef36e747Schristos 	return (0);
96ef36e747Schristos }
97ef36e747Schristos 
98e271dbb8Schristos static u_int
99e271dbb8Schristos clients_with_window(struct window *w)
100ef36e747Schristos {
101aa83ff61Schristos 	struct client	*loop;
102e271dbb8Schristos 	u_int		 n = 0;
103ef36e747Schristos 
104e271dbb8Schristos 	TAILQ_FOREACH(loop, &clients, entry) {
105e271dbb8Schristos 		if (ignore_client_size(loop) || !session_has(loop->session, w))
106e271dbb8Schristos 			continue;
107e271dbb8Schristos 		if (++n > 1)
108e271dbb8Schristos 			break;
109e271dbb8Schristos 	}
110e271dbb8Schristos 	return (n);
111e271dbb8Schristos }
112e271dbb8Schristos 
113e271dbb8Schristos static int
11459b94b2cSchristos clients_calculate_size(int type, int current, struct client *c,
11559b94b2cSchristos     struct session *s, struct window *w, int (*skip_client)(struct client *,
11659b94b2cSchristos     int, int, struct session *, struct window *), u_int *sx, u_int *sy,
11759b94b2cSchristos     u_int *xpixel, u_int *ypixel)
118e271dbb8Schristos {
119e271dbb8Schristos 	struct client		*loop;
12046548964Swiz 	struct client_window	*cw;
121e271dbb8Schristos 	u_int			 cx, cy, n = 0;
122e271dbb8Schristos 
123e271dbb8Schristos 	/*
124e271dbb8Schristos 	 * Start comparing with 0 for largest and UINT_MAX for smallest or
125e271dbb8Schristos 	 * latest.
126e271dbb8Schristos 	 */
12746548964Swiz 	if (type == WINDOW_SIZE_LARGEST) {
12846548964Swiz 		*sx = 0;
12946548964Swiz 		*sy = 0;
13046548964Swiz 	} else if (type == WINDOW_SIZE_MANUAL) {
13146548964Swiz 		*sx = w->manual_sx;
13246548964Swiz 		*sy = w->manual_sy;
13346548964Swiz 		log_debug("%s: manual size %ux%u", __func__, *sx, *sy);
13446548964Swiz 	} else {
13546548964Swiz 		*sx = UINT_MAX;
13646548964Swiz 		*sy = UINT_MAX;
13746548964Swiz 	}
138aa83ff61Schristos 	*xpixel = *ypixel = 0;
139e271dbb8Schristos 
140e271dbb8Schristos 	/*
141e271dbb8Schristos 	 * For latest, count the number of clients with this window. We only
142e271dbb8Schristos 	 * care if there is more than one.
143e271dbb8Schristos 	 */
14459b94b2cSchristos 	if (type == WINDOW_SIZE_LATEST && w != NULL)
145e271dbb8Schristos 		n = clients_with_window(w);
146e271dbb8Schristos 
14746548964Swiz 	/* Skip setting the size if manual */
14846548964Swiz 	if (type == WINDOW_SIZE_MANUAL)
14946548964Swiz 		goto skip;
15046548964Swiz 
151e271dbb8Schristos 	/* Loop over the clients and work out the size. */
152aa83ff61Schristos 	TAILQ_FOREACH(loop, &clients, entry) {
15359b94b2cSchristos 		if (loop != c && ignore_client_size(loop)) {
15446548964Swiz 			log_debug("%s: ignoring %s (1)", __func__, loop->name);
155ef36e747Schristos 			continue;
15659b94b2cSchristos 		}
15759b94b2cSchristos 		if (loop != c && skip_client(loop, type, current, s, w)) {
15846548964Swiz 			log_debug("%s: skipping %s (1)", __func__, loop->name);
159ef36e747Schristos 			continue;
16059b94b2cSchristos 		}
161ef36e747Schristos 
162e271dbb8Schristos 		/*
163e271dbb8Schristos 		 * If there are multiple clients attached, only accept the
164e271dbb8Schristos 		 * latest client; otherwise let the only client be chosen as
165e271dbb8Schristos 		 * for smallest.
166e271dbb8Schristos 		 */
16759b94b2cSchristos 		if (type == WINDOW_SIZE_LATEST && n > 1 && loop != w->latest) {
16859b94b2cSchristos 			log_debug("%s: %s is not latest", __func__, loop->name);
169e271dbb8Schristos 			continue;
17059b94b2cSchristos 		}
171e271dbb8Schristos 
17246548964Swiz 		/*
17346548964Swiz 		 * If the client has a per-window size, use this instead if it is
17446548964Swiz 		 * smaller.
17546548964Swiz 		 */
17646548964Swiz 		if (w != NULL)
17746548964Swiz 			cw = server_client_get_client_window(loop, w->id);
17846548964Swiz 		else
17946548964Swiz 			cw = NULL;
18046548964Swiz 
181e271dbb8Schristos 		/* Work out this client's size. */
18246548964Swiz 		if (cw != NULL && cw->sx != 0 && cw->sy != 0) {
18346548964Swiz 			cx = cw->sx;
18446548964Swiz 			cy = cw->sy;
18546548964Swiz 		} else {
186aa83ff61Schristos 			cx = loop->tty.sx;
187aa83ff61Schristos 			cy = loop->tty.sy - status_line_size(loop);
18846548964Swiz 		}
189ef36e747Schristos 
190e271dbb8Schristos 		/*
191e271dbb8Schristos 		 * If it is larger or smaller than the best so far, update the
192e271dbb8Schristos 		 * new size.
193e271dbb8Schristos 		 */
194e271dbb8Schristos 		if (type == WINDOW_SIZE_LARGEST) {
195ef36e747Schristos 			if (cx > *sx)
196ef36e747Schristos 				*sx = cx;
197ef36e747Schristos 			if (cy > *sy)
198ef36e747Schristos 				*sy = cy;
199e271dbb8Schristos 		} else {
200ef36e747Schristos 			if (cx < *sx)
201ef36e747Schristos 				*sx = cx;
202ef36e747Schristos 			if (cy < *sy)
203ef36e747Schristos 				*sy = cy;
204e271dbb8Schristos 		}
205e271dbb8Schristos 		if (loop->tty.xpixel > *xpixel && loop->tty.ypixel > *ypixel) {
206aa83ff61Schristos 			*xpixel = loop->tty.xpixel;
207aa83ff61Schristos 			*ypixel = loop->tty.ypixel;
208aa83ff61Schristos 		}
20959b94b2cSchristos 		log_debug("%s: after %s (%ux%u), size is %ux%u", __func__,
21059b94b2cSchristos 		    loop->name, cx, cy, *sx, *sy);
211ef36e747Schristos 	}
21246548964Swiz 	if (*sx != UINT_MAX && *sy != UINT_MAX)
21346548964Swiz 		log_debug("%s: calculated size %ux%u", __func__, *sx, *sy);
21446548964Swiz 	else
21546548964Swiz 		log_debug("%s: no calculated size", __func__);
21646548964Swiz 
21746548964Swiz skip:
21846548964Swiz 	/*
21946548964Swiz 	 * Do not allow any size to be larger than the per-client window size
22046548964Swiz 	 * if one exists.
22146548964Swiz 	 */
22246548964Swiz 	if (w != NULL) {
22346548964Swiz 		TAILQ_FOREACH(loop, &clients, entry) {
22446548964Swiz 			if (loop != c && ignore_client_size(loop))
22546548964Swiz 				continue;
22646548964Swiz 			if (loop != c && skip_client(loop, type, current, s, w))
22746548964Swiz 				continue;
22846548964Swiz 
22946548964Swiz 			/* Look up per-window size if any. */
23046548964Swiz 			if (~loop->flags & CLIENT_WINDOWSIZECHANGED)
23146548964Swiz 				continue;
23246548964Swiz 			cw = server_client_get_client_window(loop, w->id);
23346548964Swiz 			if (cw == NULL)
23446548964Swiz 				continue;
23546548964Swiz 
23646548964Swiz 			/* Clamp the size. */
23746548964Swiz 			log_debug("%s: %s size for @%u is %ux%u", __func__,
23846548964Swiz 			    loop->name, w->id, cw->sx, cw->sy);
23946548964Swiz 			if (cw->sx != 0 && *sx > cw->sx)
24046548964Swiz 				*sx = cw->sx;
24146548964Swiz 			if (cw->sy != 0 && *sy > cw->sy)
24246548964Swiz 				*sy = cw->sy;
24346548964Swiz 		}
24446548964Swiz 	}
24546548964Swiz 	if (*sx != UINT_MAX && *sy != UINT_MAX)
24646548964Swiz 		log_debug("%s: calculated size %ux%u", __func__, *sx, *sy);
24746548964Swiz 	else
24846548964Swiz 		log_debug("%s: no calculated size", __func__);
249e271dbb8Schristos 
250e271dbb8Schristos 	/* Return whether a suitable size was found. */
25146548964Swiz 	if (type == WINDOW_SIZE_MANUAL) {
25246548964Swiz 		log_debug("%s: type is manual", __func__);
25346548964Swiz 		return (1);
25446548964Swiz 	}
25559b94b2cSchristos 	if (type == WINDOW_SIZE_LARGEST) {
25659b94b2cSchristos 		log_debug("%s: type is largest", __func__);
257e271dbb8Schristos 		return (*sx != 0 && *sy != 0);
25859b94b2cSchristos 	}
25959b94b2cSchristos 	if (type == WINDOW_SIZE_LATEST)
26059b94b2cSchristos 		log_debug("%s: type is latest", __func__);
26159b94b2cSchristos 	else
26259b94b2cSchristos 		log_debug("%s: type is smallest", __func__);
263e271dbb8Schristos 	return (*sx != UINT_MAX && *sy != UINT_MAX);
264e271dbb8Schristos }
265e271dbb8Schristos 
266e271dbb8Schristos static int
267e271dbb8Schristos default_window_size_skip_client(struct client *loop, int type,
268e271dbb8Schristos     __unused int current, struct session *s, struct window *w)
269e271dbb8Schristos {
270e271dbb8Schristos 	/*
271e271dbb8Schristos 	 * Latest checks separately, so do not check here. Otherwise only
272e271dbb8Schristos 	 * include clients where the session contains the window or where the
273e271dbb8Schristos 	 * session is the given session.
274e271dbb8Schristos 	 */
275e271dbb8Schristos 	if (type == WINDOW_SIZE_LATEST)
276e271dbb8Schristos 		return (0);
277e271dbb8Schristos 	if (w != NULL && !session_has(loop->session, w))
278e271dbb8Schristos 		return (1);
279e271dbb8Schristos 	if (w == NULL && loop->session != s)
280e271dbb8Schristos 		return (1);
281e271dbb8Schristos 	return (0);
282e271dbb8Schristos }
283e271dbb8Schristos 
284e271dbb8Schristos void
285e271dbb8Schristos default_window_size(struct client *c, struct session *s, struct window *w,
286e271dbb8Schristos 	u_int *sx, u_int *sy, u_int *xpixel, u_int *ypixel, int type)
287e271dbb8Schristos {
288e271dbb8Schristos 	const char	*value;
289e271dbb8Schristos 
290e271dbb8Schristos 	/* Get type if not provided. */
291e271dbb8Schristos 	if (type == -1)
292e271dbb8Schristos 		type = options_get_number(global_w_options, "window-size");
293e271dbb8Schristos 
294e271dbb8Schristos 	/*
295e271dbb8Schristos 	 * Latest clients can use the given client if suitable. If there is no
296e271dbb8Schristos 	 * client and no window, use the default size as for manual type.
297e271dbb8Schristos 	 */
29846548964Swiz 	if (type == WINDOW_SIZE_LATEST && c != NULL && !ignore_client_size(c)) {
299aa83ff61Schristos 		*sx = c->tty.sx;
300aa83ff61Schristos 		*sy = c->tty.sy - status_line_size(c);
301aa83ff61Schristos 		*xpixel = c->tty.xpixel;
302aa83ff61Schristos 		*ypixel = c->tty.ypixel;
30359b94b2cSchristos 		log_debug("%s: using %ux%u from %s", __func__, *sx, *sy,
30459b94b2cSchristos 		    c->name);
305ef36e747Schristos 		goto done;
306e271dbb8Schristos 	}
30746548964Swiz 
30846548964Swiz         /*
30946548964Swiz          * Ignore the given client if it is a control client - the creating
31046548964Swiz          * client should only affect the size if it is not a control client.
31146548964Swiz          */
31246548964Swiz         if (c != NULL && (c->flags & CLIENT_CONTROL))
31346548964Swiz                 c = NULL;
314ef36e747Schristos 
315e271dbb8Schristos 	/*
316e271dbb8Schristos 	 * Look for a client to base the size on. If none exists (or the type
317e271dbb8Schristos 	 * is manual), use the default-size option.
318e271dbb8Schristos 	 */
31959b94b2cSchristos 	if (!clients_calculate_size(type, 0, c, s, w,
320e271dbb8Schristos 	    default_window_size_skip_client, sx, sy, xpixel, ypixel)) {
321ef36e747Schristos 		value = options_get_string(s->options, "default-size");
322ef36e747Schristos 		if (sscanf(value, "%ux%u", sx, sy) != 2) {
323ef36e747Schristos 			*sx = 80;
324ef36e747Schristos 			*sy = 24;
325ef36e747Schristos 		}
32659b94b2cSchristos 		log_debug("%s: using %ux%u from default-size", __func__, *sx,
32759b94b2cSchristos 		    *sy);
328e271dbb8Schristos 	}
329ef36e747Schristos 
330ef36e747Schristos done:
331e271dbb8Schristos 	/* Make sure the limits are enforced. */
332ef36e747Schristos 	if (*sx < WINDOW_MINIMUM)
333ef36e747Schristos 		*sx = WINDOW_MINIMUM;
334ef36e747Schristos 	if (*sx > WINDOW_MAXIMUM)
335ef36e747Schristos 		*sx = WINDOW_MAXIMUM;
336ef36e747Schristos 	if (*sy < WINDOW_MINIMUM)
337ef36e747Schristos 		*sy = WINDOW_MINIMUM;
338ef36e747Schristos 	if (*sy > WINDOW_MAXIMUM)
339ef36e747Schristos 		*sy = WINDOW_MAXIMUM;
34059b94b2cSchristos 	log_debug("%s: resulting size is %ux%u", __func__, *sx, *sy);
341ef36e747Schristos }
342698d5317Sjmmv 
343e271dbb8Schristos static int
344e271dbb8Schristos recalculate_size_skip_client(struct client *loop, __unused int type,
345e271dbb8Schristos     int current, __unused struct session *s, struct window *w)
346698d5317Sjmmv {
347e271dbb8Schristos 	/*
348e271dbb8Schristos 	 * If the current flag is set, then skip any client where this window
349e271dbb8Schristos 	 * is not the current window - this is used for aggressive-resize.
350e271dbb8Schristos 	 * Otherwise skip any session that doesn't contain the window.
351e271dbb8Schristos 	 */
35246548964Swiz 	if (loop->session->curw == NULL)
35346548964Swiz 		return (1);
354e271dbb8Schristos 	if (current)
355e271dbb8Schristos 		return (loop->session->curw->window != w);
356e271dbb8Schristos 	return (session_has(loop->session, w) == 0);
357e271dbb8Schristos }
358698d5317Sjmmv 
359e271dbb8Schristos void
360e271dbb8Schristos recalculate_size(struct window *w, int now)
361e271dbb8Schristos {
362e271dbb8Schristos 	u_int	sx, sy, xpixel = 0, ypixel = 0;
363e271dbb8Schristos 	int	type, current, changed;
364e271dbb8Schristos 
365e271dbb8Schristos 	/*
366e271dbb8Schristos 	 * Do not attempt to resize windows which have no pane, they must be on
367e271dbb8Schristos 	 * the way to destruction.
368e271dbb8Schristos 	 */
3695494e770Schristos 	if (w->active == NULL)
370aa83ff61Schristos 		return;
37146548964Swiz 	log_debug("%s: @%u is %ux%u", __func__, w->id, w->sx, w->sy);
372698d5317Sjmmv 
373e271dbb8Schristos 	/*
374e271dbb8Schristos 	 * Type is manual, smallest, largest, latest. Current is the
375e271dbb8Schristos 	 * aggressive-resize option (do not resize based on clients where the
376e271dbb8Schristos 	 * window is not the current window).
377e271dbb8Schristos 	 */
378ef36e747Schristos 	type = options_get_number(w->options, "window-size");
379ef36e747Schristos 	current = options_get_number(w->options, "aggressive-resize");
380ef36e747Schristos 
381e271dbb8Schristos 	/* Look for a suitable client and get the new size. */
38259b94b2cSchristos 	changed = clients_calculate_size(type, current, NULL, NULL, w,
383e271dbb8Schristos 	    recalculate_size_skip_client, &sx, &sy, &xpixel, &ypixel);
384ef36e747Schristos 
385e271dbb8Schristos 	/*
386e271dbb8Schristos 	 * Make sure the size has actually changed. If the window has already
387e271dbb8Schristos 	 * got a resize scheduled, then use the new size; otherwise the old.
388e271dbb8Schristos 	 */
389e271dbb8Schristos 	if (w->flags & WINDOW_RESIZE) {
390e271dbb8Schristos 		if (!now && changed && w->new_sx == sx && w->new_sy == sy)
391ef36e747Schristos 			changed = 0;
392e271dbb8Schristos 	} else {
393e271dbb8Schristos 		if (!now && changed && w->sx == sx && w->sy == sy)
394ef36e747Schristos 			changed = 0;
395ef36e747Schristos 	}
396aa83ff61Schristos 
397e271dbb8Schristos 	/*
398e271dbb8Schristos 	 * If the size hasn't changed, update the window offset but not the
399e271dbb8Schristos 	 * size.
400e271dbb8Schristos 	 */
401ef36e747Schristos 	if (!changed) {
40246548964Swiz 		log_debug("%s: @%u no size change", __func__, w->id);
403ef36e747Schristos 		tty_update_window_offset(w);
404aa83ff61Schristos 		return;
405aa83ff61Schristos 	}
406e271dbb8Schristos 
407e271dbb8Schristos 	/*
408e271dbb8Schristos 	 * If the now flag is set or if the window is sized manually, change
409e271dbb8Schristos 	 * the size immediately. Otherwise set the flag and it will be done
410e271dbb8Schristos 	 * later.
411e271dbb8Schristos 	 */
41246548964Swiz 	log_debug("%s: @%u new size %ux%u", __func__, w->id, sx, sy);
413e271dbb8Schristos 	if (now || type == WINDOW_SIZE_MANUAL)
414aa83ff61Schristos 		resize_window(w, sx, sy, xpixel, ypixel);
415e271dbb8Schristos 	else {
416e271dbb8Schristos 		w->new_sx = sx;
417e271dbb8Schristos 		w->new_sy = sy;
418e271dbb8Schristos 		w->new_xpixel = xpixel;
419e271dbb8Schristos 		w->new_ypixel = ypixel;
420e271dbb8Schristos 
421e271dbb8Schristos 		w->flags |= WINDOW_RESIZE;
422e271dbb8Schristos 		tty_update_window_offset(w);
423e271dbb8Schristos 	}
424aa83ff61Schristos }
425aa83ff61Schristos 
426aa83ff61Schristos void
427aa83ff61Schristos recalculate_sizes(void)
428aa83ff61Schristos {
429e271dbb8Schristos 	recalculate_sizes_now(0);
430e271dbb8Schristos }
431e271dbb8Schristos 
432e271dbb8Schristos void
433e271dbb8Schristos recalculate_sizes_now(int now)
434e271dbb8Schristos {
435aa83ff61Schristos 	struct session	*s;
436aa83ff61Schristos 	struct client	*c;
437aa83ff61Schristos 	struct window	*w;
438aa83ff61Schristos 
439aa83ff61Schristos 	/*
440aa83ff61Schristos 	 * Clear attached count and update saved status line information for
441aa83ff61Schristos 	 * each session.
442aa83ff61Schristos 	 */
443aa83ff61Schristos 	RB_FOREACH(s, sessions, &sessions) {
444aa83ff61Schristos 		s->attached = 0;
445aa83ff61Schristos 		status_update_cache(s);
446aa83ff61Schristos 	}
447aa83ff61Schristos 
448aa83ff61Schristos 	/*
449aa83ff61Schristos 	 * Increment attached count and check the status line size for each
450aa83ff61Schristos 	 * client.
451aa83ff61Schristos 	 */
452aa83ff61Schristos 	TAILQ_FOREACH(c, &clients, entry) {
453aa83ff61Schristos 		s = c->session;
454aa83ff61Schristos 		if (s != NULL && !(c->flags & CLIENT_UNATTACHEDFLAGS))
455aa83ff61Schristos 			s->attached++;
456aa83ff61Schristos 		if (ignore_client_size(c))
457ef36e747Schristos 			continue;
458aa83ff61Schristos 		if (c->tty.sy <= s->statuslines || (c->flags & CLIENT_CONTROL))
459aa83ff61Schristos 			c->flags |= CLIENT_STATUSOFF;
460aa83ff61Schristos 		else
461aa83ff61Schristos 			c->flags &= ~CLIENT_STATUSOFF;
462ef36e747Schristos 	}
463aa83ff61Schristos 
464aa83ff61Schristos 	/* Walk each window and adjust the size. */
465aa83ff61Schristos 	RB_FOREACH(w, windows, &windows)
466e271dbb8Schristos 		recalculate_size(w, now);
467698d5317Sjmmv }
468