2007-12-06 10:46:23 +01:00
|
|
|
/* $Id: resize.c,v 1.9 2007-12-06 09:46:22 nicm Exp $ */
|
2007-10-04 21:03:52 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Recalculate window and session sizes.
|
|
|
|
*
|
|
|
|
* Every session has the size of the smallest client it is attached to and
|
|
|
|
* every window the size of the smallest session it is attached to.
|
|
|
|
*
|
|
|
|
* So, when a client is resized or a session attached to or detached from a
|
|
|
|
* client, the window sizes must be recalculated. For each session, find the
|
|
|
|
* smallest client it is attached to, and resize it to that size. Then for
|
|
|
|
* every window, find the smallest session it is attached to, resize it to that
|
|
|
|
* size and clear and redraw every client with it as the current window.
|
2007-12-06 10:46:23 +01:00
|
|
|
*
|
2007-10-04 21:03:52 +02:00
|
|
|
* This is quite inefficient - better/additional data structures are needed
|
|
|
|
* to make it better.
|
2007-10-05 20:25:05 +02:00
|
|
|
*
|
|
|
|
* As a side effect, this function updates the SESSION_UNATTACHED flag. This
|
|
|
|
* flag is necessary to make sure unattached sessions do not limit the size of
|
|
|
|
* windows that are attached both to them and to other sessions which are
|
|
|
|
* attached.
|
2007-10-04 21:03:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
recalculate_sizes(void)
|
|
|
|
{
|
|
|
|
struct session *s;
|
|
|
|
struct client *c;
|
|
|
|
struct window *w;
|
|
|
|
u_int i, j, ssx, ssy;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-10-04 21:03:52 +02:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
|
|
|
s = ARRAY_ITEM(&sessions, i);
|
|
|
|
if (s == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ssx = ssy = UINT_MAX;
|
|
|
|
for (j = 0; j < ARRAY_LENGTH(&clients); j++) {
|
|
|
|
c = ARRAY_ITEM(&clients, j);
|
2007-10-05 20:25:05 +02:00
|
|
|
if (c == NULL)
|
2007-10-04 21:03:52 +02:00
|
|
|
continue;
|
2007-10-05 20:25:05 +02:00
|
|
|
if (c->session == s) {
|
|
|
|
if (c->sx < ssx)
|
|
|
|
ssx = c->sx;
|
|
|
|
if (c->sy < ssy)
|
|
|
|
ssy = c->sy;
|
|
|
|
}
|
2007-10-04 21:03:52 +02:00
|
|
|
}
|
2007-10-05 20:25:05 +02:00
|
|
|
if (ssx == UINT_MAX || ssy == UINT_MAX) {
|
|
|
|
s->flags |= SESSION_UNATTACHED;
|
2007-10-04 22:01:10 +02:00
|
|
|
continue;
|
2007-10-05 20:25:05 +02:00
|
|
|
}
|
|
|
|
s->flags &= ~SESSION_UNATTACHED;
|
|
|
|
|
2007-10-04 21:03:52 +02:00
|
|
|
if (ssy < status_lines)
|
|
|
|
ssy = status_lines + 1;
|
|
|
|
ssy -= status_lines;
|
|
|
|
if (s->sx == ssx && s->sy == ssy)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
log_debug(
|
|
|
|
"session size %u,%u (was %u,%u)", ssx, ssy, s->sx, s->sy);
|
|
|
|
|
|
|
|
s->sx = ssx;
|
|
|
|
s->sy = ssy;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
|
|
|
w = ARRAY_ITEM(&windows, i);
|
|
|
|
if (w == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ssx = ssy = UINT_MAX;
|
|
|
|
for (j = 0; j < ARRAY_LENGTH(&sessions); j++) {
|
|
|
|
s = ARRAY_ITEM(&sessions, j);
|
2007-10-05 20:25:05 +02:00
|
|
|
if (s == NULL || s->flags & SESSION_UNATTACHED)
|
2007-10-04 21:03:52 +02:00
|
|
|
continue;
|
2007-10-05 20:25:05 +02:00
|
|
|
if (session_has(s, w)) {
|
|
|
|
if (s->sx < ssx)
|
|
|
|
ssx = s->sx;
|
|
|
|
if (s->sy < ssy)
|
|
|
|
ssy = s->sy;
|
|
|
|
}
|
2007-10-04 21:03:52 +02:00
|
|
|
}
|
2007-11-21 14:11:41 +01:00
|
|
|
if (ssx == UINT_MAX || ssy == UINT_MAX) {
|
2007-12-06 10:46:23 +01:00
|
|
|
w->flags |= WINDOW_HIDDEN;
|
2007-10-04 22:01:10 +02:00
|
|
|
continue;
|
2007-11-21 14:11:41 +01:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
w->flags &= ~WINDOW_HIDDEN;
|
2007-10-05 20:25:05 +02:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
if (screen_size_x(&w->base) == ssx &&
|
|
|
|
screen_size_y(&w->base) == ssy)
|
2007-10-04 21:03:52 +02:00
|
|
|
continue;
|
|
|
|
|
2007-11-20 22:42:29 +01:00
|
|
|
log_debug("window size %u,%u (was %u,%u)", ssx, ssy,
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_size_x(&w->base), screen_size_y(&w->base));
|
2007-10-04 21:03:52 +02:00
|
|
|
|
2007-11-27 20:23:34 +01:00
|
|
|
server_clear_window(w);
|
2007-12-03 00:00:22 +01:00
|
|
|
window_resize(w, ssx, ssy);
|
2007-11-27 20:23:34 +01:00
|
|
|
server_redraw_window(w);
|
2007-10-04 21:03:52 +02:00
|
|
|
}
|
|
|
|
}
|