[BACK]Return to resize.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/resize.c, Revision 1.26

1.26    ! nicm        1: /* $OpenBSD: resize.c,v 1.25 2017/10/16 19:30:53 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.19      nicm        4:  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        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 <string.h>
                     22:
                     23: #include "tmux.h"
                     24:
                     25: /*
                     26:  * Recalculate window and session sizes.
                     27:  *
                     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.
                     30:  *
                     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.
                     36:  *
                     37:  * This is quite inefficient - better/additional data structures are needed
                     38:  * to make it better.
                     39:  */
                     40:
                     41: void
                     42: recalculate_sizes(void)
                     43: {
                     44:        struct session          *s;
                     45:        struct client           *c;
                     46:        struct window           *w;
1.2       nicm       47:        struct window_pane      *wp;
1.25      nicm       48:        u_int                    ssx, ssy, has, limit, lines;
                     49:        int                      flag, is_zoomed, forced;
1.1       nicm       50:
1.7       nicm       51:        RB_FOREACH(s, sessions, &sessions) {
1.25      nicm       52:                lines = status_line_size(s);
1.9       nicm       53:
1.12      nicm       54:                s->attached = 0;
1.1       nicm       55:                ssx = ssy = UINT_MAX;
1.17      nicm       56:                TAILQ_FOREACH(c, &clients, entry) {
                     57:                        if (c->flags & CLIENT_SUSPENDED)
1.23      nicm       58:                                continue;
                     59:                        if ((c->flags & (CLIENT_CONTROL|CLIENT_SIZECHANGED)) ==
                     60:                            CLIENT_CONTROL)
1.1       nicm       61:                                continue;
                     62:                        if (c->session == s) {
                     63:                                if (c->tty.sx < ssx)
                     64:                                        ssx = c->tty.sx;
1.25      nicm       65:                                c->flags &= ~CLIENT_STATUSOFF;
                     66:                                if (lines != 0 && lines + PANE_MINIMUM > c->tty.sy)
                     67:                                        c->flags |= CLIENT_STATUSOFF;
                     68:                                if ((~c->flags & CLIENT_STATUSOFF) &&
1.9       nicm       69:                                    !(c->flags & CLIENT_CONTROL) &&
1.25      nicm       70:                                    c->tty.sy > lines &&
                     71:                                    c->tty.sy - lines < ssy)
                     72:                                        ssy = c->tty.sy - lines;
1.9       nicm       73:                                else if (c->tty.sy < ssy)
1.1       nicm       74:                                        ssy = c->tty.sy;
1.12      nicm       75:                                s->attached++;
1.1       nicm       76:                        }
                     77:                }
1.26    ! nicm       78:                if (ssx == UINT_MAX || ssy == UINT_MAX)
1.1       nicm       79:                        continue;
                     80:
1.25      nicm       81:                if (lines != 0 && ssy == 0)
                     82:                        ssy = lines;
1.9       nicm       83:
1.1       nicm       84:                if (s->sx == ssx && s->sy == ssy)
                     85:                        continue;
                     86:
1.22      nicm       87:                log_debug("session $%u size %u,%u (was %u,%u)", s->id, ssx, ssy,
                     88:                    s->sx, s->sy);
1.1       nicm       89:
                     90:                s->sx = ssx;
                     91:                s->sy = ssy;
1.21      nicm       92:
                     93:                status_update_saved(s);
1.1       nicm       94:        }
                     95:
1.15      nicm       96:        RB_FOREACH(w, windows, &windows) {
                     97:                if (w->active == NULL)
1.1       nicm       98:                        continue;
1.18      nicm       99:                flag = options_get_number(w->options, "aggressive-resize");
1.1       nicm      100:
                    101:                ssx = ssy = UINT_MAX;
1.7       nicm      102:                RB_FOREACH(s, sessions, &sessions) {
1.26    ! nicm      103:                        if (s->attached == 0)
1.1       nicm      104:                                continue;
                    105:                        if (flag)
                    106:                                has = s->curw->window == w;
                    107:                        else
1.16      nicm      108:                                has = session_has(s, w);
1.1       nicm      109:                        if (has) {
                    110:                                if (s->sx < ssx)
                    111:                                        ssx = s->sx;
                    112:                                if (s->sy < ssy)
                    113:                                        ssy = s->sy;
                    114:                        }
                    115:                }
1.6       nicm      116:                if (ssx == UINT_MAX || ssy == UINT_MAX)
1.1       nicm      117:                        continue;
                    118:
1.14      nicm      119:                forced = 0;
1.18      nicm      120:                limit = options_get_number(w->options, "force-width");
1.14      nicm      121:                if (limit >= PANE_MINIMUM && ssx > limit) {
1.1       nicm      122:                        ssx = limit;
1.14      nicm      123:                        forced |= WINDOW_FORCEWIDTH;
                    124:                }
1.18      nicm      125:                limit = options_get_number(w->options, "force-height");
1.14      nicm      126:                if (limit >= PANE_MINIMUM && ssy > limit) {
1.1       nicm      127:                        ssy = limit;
1.14      nicm      128:                        forced |= WINDOW_FORCEHEIGHT;
                    129:                }
1.1       nicm      130:
                    131:                if (w->sx == ssx && w->sy == ssy)
                    132:                        continue;
1.22      nicm      133:                log_debug("window @%u size %u,%u (was %u,%u)", w->id, ssx, ssy,
                    134:                    w->sx, w->sy);
1.14      nicm      135:
                    136:                w->flags &= ~(WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT);
                    137:                w->flags |= forced;
1.1       nicm      138:
1.10      nicm      139:                is_zoomed = w->flags & WINDOW_ZOOMED;
                    140:                if (is_zoomed)
                    141:                        window_unzoom(w);
1.3       nicm      142:                layout_resize(w, ssx, ssy);
1.1       nicm      143:                window_resize(w, ssx, ssy);
1.10      nicm      144:                if (is_zoomed && window_pane_visible(w->active))
                    145:                        window_zoom(w->active);
1.2       nicm      146:
                    147:                /*
                    148:                 * If the current pane is now not visible, move to the next
                    149:                 * that is.
                    150:                 */
                    151:                wp = w->active;
                    152:                while (!window_pane_visible(w->active)) {
                    153:                        w->active = TAILQ_PREV(w->active, window_panes, entry);
                    154:                        if (w->active == NULL)
                    155:                                w->active = TAILQ_LAST(&w->panes, window_panes);
                    156:                        if (w->active == wp)
                    157:                               break;
                    158:                }
1.24      nicm      159:                if (w->active == w->last)
                    160:                        w->last = NULL;
1.2       nicm      161:
1.1       nicm      162:                server_redraw_window(w);
1.20      nicm      163:                notify_window("window-layout-changed", w);
1.1       nicm      164:        }
                    165: }