1 /* $Id: resize.c,v 1.24 2009-09-25 17:47:42 tcunha Exp $ */
4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
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 * Recalculate window and session sizes.
28 * Every session has the size of the smallest client it is attached to and
29 * every window the size of the smallest session it is attached to.
31 * So, when a client is resized or a session attached to or detached from a
32 * client, the window sizes must be recalculated. For each session, find the
33 * smallest client it is attached to, and resize it to that size. Then for
34 * every window, find the smallest session it is attached to, resize it to that
35 * size and clear and redraw every client with it as the current window.
37 * This is quite inefficient - better/additional data structures are needed
40 * As a side effect, this function updates the SESSION_UNATTACHED flag. This
41 * flag is necessary to make sure unattached sessions do not limit the size of
42 * windows that are attached both to them and to other (attached) sessions.
46 recalculate_sizes(void)
51 struct window_pane
*wp
;
52 u_int i
, j
, ssx
, ssy
, has
, limit
;
55 for (i
= 0; i
< ARRAY_LENGTH(&sessions
); i
++) {
56 s
= ARRAY_ITEM(&sessions
, i
);
61 for (j
= 0; j
< ARRAY_LENGTH(&clients
); j
++) {
62 c
= ARRAY_ITEM(&clients
, j
);
63 if (c
== NULL
|| c
->flags
& CLIENT_SUSPENDED
)
65 if (c
->session
== s
) {
72 if (ssx
== UINT_MAX
|| ssy
== UINT_MAX
) {
73 s
->flags
|= SESSION_UNATTACHED
;
76 s
->flags
&= ~SESSION_UNATTACHED
;
78 if (options_get_number(&s
->options
, "status")) {
84 if (s
->sx
== ssx
&& s
->sy
== ssy
)
88 "session size %u,%u (was %u,%u)", ssx
, ssy
, s
->sx
, s
->sy
);
94 for (i
= 0; i
< ARRAY_LENGTH(&windows
); i
++) {
95 w
= ARRAY_ITEM(&windows
, i
);
98 flag
= options_get_number(&w
->options
, "aggressive-resize");
100 ssx
= ssy
= UINT_MAX
;
101 for (j
= 0; j
< ARRAY_LENGTH(&sessions
); j
++) {
102 s
= ARRAY_ITEM(&sessions
, j
);
103 if (s
== NULL
|| s
->flags
& SESSION_UNATTACHED
)
106 has
= s
->curw
->window
== w
;
108 has
= session_has(s
, w
);
116 if (ssx
== UINT_MAX
|| ssy
== UINT_MAX
) {
117 w
->flags
|= WINDOW_HIDDEN
;
120 w
->flags
&= ~WINDOW_HIDDEN
;
122 limit
= options_get_number(&w
->options
, "force-width");
123 if (limit
!= 0 && ssx
> limit
)
125 limit
= options_get_number(&w
->options
, "force-height");
126 if (limit
!= 0 && ssy
> limit
)
129 if (w
->sx
== ssx
&& w
->sy
== ssy
)
133 "window size %u,%u (was %u,%u)", ssx
, ssy
, w
->sx
, w
->sy
);
135 layout_resize(w
, ssx
, ssy
);
136 window_resize(w
, ssx
, ssy
);
139 * If the current pane is now not visible, move to the next
143 while (!window_pane_visible(w
->active
)) {
144 w
->active
= TAILQ_PREV(w
->active
, window_panes
, entry
);
145 if (w
->active
== NULL
)
146 w
->active
= TAILQ_LAST(&w
->panes
, window_panes
);
151 server_redraw_window(w
);