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

Annotation of src/usr.bin/tmux/screen-redraw.c, Revision 1.50

1.50    ! nicm        1: /* $OpenBSD: screen-redraw.c,v 1.49 2018/02/05 08:21:54 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.35      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:
1.48      nicm       21: #include <stdlib.h>
1.1       nicm       22: #include <string.h>
                     23:
                     24: #include "tmux.h"
                     25:
1.50    ! nicm       26: struct screen_redraw_ctx {
        !            27:        struct client   *c;
        !            28:
        !            29:        u_int            lines;
        !            30:        int              top;
        !            31:
        !            32:        int              pane_status;
        !            33: };
        !            34:
1.39      nicm       35: static int     screen_redraw_cell_border1(struct window_pane *, u_int, u_int);
                     36: static int     screen_redraw_cell_border(struct client *, u_int, u_int);
                     37: static int     screen_redraw_check_cell(struct client *, u_int, u_int, int,
                     38:                    struct window_pane **);
                     39: static int     screen_redraw_check_is(u_int, u_int, int, int, struct window *,
                     40:                    struct window_pane *, struct window_pane *);
                     41:
                     42: static int     screen_redraw_make_pane_status(struct client *, struct window *,
                     43:                    struct window_pane *);
                     44: static void    screen_redraw_draw_pane_status(struct client *, int);
                     45:
1.50    ! nicm       46: static void    screen_redraw_draw_borders(struct screen_redraw_ctx *);
        !            47: static void    screen_redraw_draw_panes(struct screen_redraw_ctx *);
        !            48: static void    screen_redraw_draw_status(struct screen_redraw_ctx *);
        !            49: static void    screen_redraw_draw_number(struct screen_redraw_ctx *,
        !            50:                    struct window_pane *);
1.1       nicm       51:
1.6       nicm       52: #define CELL_INSIDE 0
1.7       nicm       53: #define CELL_LEFTRIGHT 1
                     54: #define CELL_TOPBOTTOM 2
                     55: #define CELL_TOPLEFT 3
                     56: #define CELL_TOPRIGHT 4
                     57: #define CELL_BOTTOMLEFT 5
                     58: #define CELL_BOTTOMRIGHT 6
                     59: #define CELL_TOPJOIN 7
                     60: #define CELL_BOTTOMJOIN 8
                     61: #define CELL_LEFTJOIN 9
                     62: #define CELL_RIGHTJOIN 10
                     63: #define CELL_JOIN 11
                     64: #define CELL_OUTSIDE 12
1.6       nicm       65:
1.17      nicm       66: #define CELL_BORDERS " xqlkmjwvtun~"
                     67:
1.36      nicm       68: #define CELL_STATUS_OFF 0
                     69: #define CELL_STATUS_TOP 1
                     70: #define CELL_STATUS_BOTTOM 2
                     71:
1.15      nicm       72: /* Check if cell is on the border of a particular pane. */
1.39      nicm       73: static int
1.15      nicm       74: screen_redraw_cell_border1(struct window_pane *wp, u_int px, u_int py)
                     75: {
                     76:        /* Inside pane. */
                     77:        if (px >= wp->xoff && px < wp->xoff + wp->sx &&
                     78:            py >= wp->yoff && py < wp->yoff + wp->sy)
                     79:                return (0);
                     80:
                     81:        /* Left/right borders. */
                     82:        if ((wp->yoff == 0 || py >= wp->yoff - 1) && py <= wp->yoff + wp->sy) {
                     83:                if (wp->xoff != 0 && px == wp->xoff - 1)
                     84:                        return (1);
                     85:                if (px == wp->xoff + wp->sx)
1.36      nicm       86:                        return (2);
1.15      nicm       87:        }
                     88:
                     89:        /* Top/bottom borders. */
                     90:        if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= wp->xoff + wp->sx) {
                     91:                if (wp->yoff != 0 && py == wp->yoff - 1)
1.36      nicm       92:                        return (3);
1.15      nicm       93:                if (py == wp->yoff + wp->sy)
1.36      nicm       94:                        return (4);
1.15      nicm       95:        }
                     96:
                     97:        /* Outside pane. */
                     98:        return (-1);
                     99: }
                    100:
1.7       nicm      101: /* Check if a cell is on the pane border. */
1.39      nicm      102: static int
1.7       nicm      103: screen_redraw_cell_border(struct client *c, u_int px, u_int py)
1.1       nicm      104: {
                    105:        struct window           *w = c->session->curw->window;
                    106:        struct window_pane      *wp;
1.15      nicm      107:        int                      retval;
1.1       nicm      108:
1.7       nicm      109:        /* Check all the panes. */
1.1       nicm      110:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3       nicm      111:                if (!window_pane_visible(wp))
                    112:                        continue;
1.15      nicm      113:                if ((retval = screen_redraw_cell_border1(wp, px, py)) != -1)
1.36      nicm      114:                        return (!!retval);
1.7       nicm      115:        }
                    116:
                    117:        return (0);
                    118: }
                    119:
                    120: /* Check if cell inside a pane. */
1.39      nicm      121: static int
1.36      nicm      122: screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
1.24      nicm      123:     struct window_pane **wpp)
1.7       nicm      124: {
                    125:        struct window           *w = c->session->curw->window;
                    126:        struct window_pane      *wp;
                    127:        int                      borders;
1.36      nicm      128:        u_int                    right, line;
1.7       nicm      129:
1.39      nicm      130:        *wpp = NULL;
                    131:
1.7       nicm      132:        if (px > w->sx || py > w->sy)
                    133:                return (CELL_OUTSIDE);
                    134:
1.36      nicm      135:        if (pane_status != CELL_STATUS_OFF) {
                    136:                TAILQ_FOREACH(wp, &w->panes, entry) {
                    137:                        if (!window_pane_visible(wp))
                    138:                                continue;
                    139:
                    140:                        if (pane_status == CELL_STATUS_TOP)
                    141:                                line = wp->yoff - 1;
                    142:                        else
                    143:                                line = wp->yoff + wp->sy;
                    144:                        right = wp->xoff + 2 + wp->status_size - 1;
                    145:
                    146:                        if (py == line && px >= wp->xoff + 2 && px <= right)
                    147:                                return (CELL_INSIDE);
                    148:                }
                    149:        }
                    150:
1.7       nicm      151:        TAILQ_FOREACH(wp, &w->panes, entry) {
                    152:                if (!window_pane_visible(wp))
                    153:                        continue;
1.24      nicm      154:                *wpp = wp;
1.7       nicm      155:
                    156:                /* If outside the pane and its border, skip it. */
                    157:                if ((wp->xoff != 0 && px < wp->xoff - 1) ||
                    158:                    px > wp->xoff + wp->sx ||
                    159:                    (wp->yoff != 0 && py < wp->yoff - 1) ||
                    160:                    py > wp->yoff + wp->sy)
                    161:                        continue;
                    162:
                    163:                /* If definitely inside, return so. */
                    164:                if (!screen_redraw_cell_border(c, px, py))
                    165:                        return (CELL_INSIDE);
                    166:
1.14      nicm      167:                /*
1.7       nicm      168:                 * Construct a bitmask of whether the cells to the left (bit
                    169:                 * 4), right, top, and bottom (bit 1) of this cell are borders.
                    170:                 */
                    171:                borders = 0;
                    172:                if (px == 0 || screen_redraw_cell_border(c, px - 1, py))
                    173:                        borders |= 8;
                    174:                if (px <= w->sx && screen_redraw_cell_border(c, px + 1, py))
                    175:                        borders |= 4;
1.36      nicm      176:                if (pane_status == CELL_STATUS_TOP) {
                    177:                        if (py != 0 && screen_redraw_cell_border(c, px, py - 1))
                    178:                                borders |= 2;
                    179:                } else {
                    180:                        if (py == 0 || screen_redraw_cell_border(c, px, py - 1))
                    181:                                borders |= 2;
                    182:                }
1.7       nicm      183:                if (py <= w->sy && screen_redraw_cell_border(c, px, py + 1))
                    184:                        borders |= 1;
                    185:
1.14      nicm      186:                /*
1.7       nicm      187:                 * Figure out what kind of border this cell is. Only one bit
                    188:                 * set doesn't make sense (can't have a border cell with no
                    189:                 * others connected).
                    190:                 */
                    191:                switch (borders) {
                    192:                case 15:        /* 1111, left right top bottom */
                    193:                        return (CELL_JOIN);
                    194:                case 14:        /* 1110, left right top */
                    195:                        return (CELL_BOTTOMJOIN);
                    196:                case 13:        /* 1101, left right bottom */
                    197:                        return (CELL_TOPJOIN);
                    198:                case 12:        /* 1100, left right */
                    199:                        return (CELL_TOPBOTTOM);
                    200:                case 11:        /* 1011, left top bottom */
                    201:                        return (CELL_RIGHTJOIN);
                    202:                case 10:        /* 1010, left top */
                    203:                        return (CELL_BOTTOMRIGHT);
                    204:                case 9:         /* 1001, left bottom */
                    205:                        return (CELL_TOPRIGHT);
                    206:                case 7:         /* 0111, right top bottom */
                    207:                        return (CELL_LEFTJOIN);
                    208:                case 6:         /* 0110, right top */
                    209:                        return (CELL_BOTTOMLEFT);
                    210:                case 5:         /* 0101, right bottom */
                    211:                        return (CELL_TOPLEFT);
                    212:                case 3:         /* 0011, top bottom */
                    213:                        return (CELL_LEFTRIGHT);
1.1       nicm      214:                }
                    215:        }
                    216:
1.6       nicm      217:        return (CELL_OUTSIDE);
1.1       nicm      218: }
                    219:
1.32      nicm      220: /* Check if the border of a particular pane. */
1.39      nicm      221: static int
1.36      nicm      222: screen_redraw_check_is(u_int px, u_int py, int type, int pane_status,
                    223:     struct window *w, struct window_pane *wantwp, struct window_pane *wp)
1.24      nicm      224: {
1.36      nicm      225:        int     border;
                    226:
1.24      nicm      227:        /* Is this off the active pane border? */
1.36      nicm      228:        border = screen_redraw_cell_border1(wantwp, px, py);
                    229:        if (border == 0 || border == -1)
                    230:                return (0);
                    231:        if (pane_status == CELL_STATUS_TOP && border == 4)
                    232:                return (0);
                    233:        if (pane_status == CELL_STATUS_BOTTOM && border == 3)
1.24      nicm      234:                return (0);
                    235:
                    236:        /* If there are more than two panes, that's enough. */
                    237:        if (window_count_panes(w) != 2)
                    238:                return (1);
                    239:
                    240:        /* Else if the cell is not a border cell, forget it. */
                    241:        if (wp == NULL || (type == CELL_OUTSIDE || type == CELL_INSIDE))
                    242:                return (1);
                    243:
1.36      nicm      244:        /* With status lines mark the entire line. */
                    245:        if (pane_status != CELL_STATUS_OFF)
                    246:                return (1);
                    247:
1.24      nicm      248:        /* Check if the pane covers the whole width. */
                    249:        if (wp->xoff == 0 && wp->sx == w->sx) {
                    250:                /* This can either be the top pane or the bottom pane. */
                    251:                if (wp->yoff == 0) { /* top pane */
1.32      nicm      252:                        if (wp == wantwp)
1.24      nicm      253:                                return (px <= wp->sx / 2);
                    254:                        return (px > wp->sx / 2);
                    255:                }
                    256:                return (0);
                    257:        }
                    258:
                    259:        /* Check if the pane covers the whole height. */
                    260:        if (wp->yoff == 0 && wp->sy == w->sy) {
                    261:                /* This can either be the left pane or the right pane. */
                    262:                if (wp->xoff == 0) { /* left pane */
1.32      nicm      263:                        if (wp == wantwp)
1.24      nicm      264:                                return (py <= wp->sy / 2);
                    265:                        return (py > wp->sy / 2);
                    266:                }
                    267:                return (0);
                    268:        }
                    269:
1.36      nicm      270:        return (1);
                    271: }
                    272:
                    273: /* Update pane status. */
1.39      nicm      274: static int
1.36      nicm      275: screen_redraw_make_pane_status(struct client *c, struct window *w,
                    276:     struct window_pane *wp)
                    277: {
                    278:        struct grid_cell         gc;
                    279:        const char              *fmt;
                    280:        struct format_tree      *ft;
                    281:        char                    *out;
1.40      nicm      282:        size_t                   outlen;
1.36      nicm      283:        struct screen_write_ctx  ctx;
1.40      nicm      284:        struct screen            old;
1.36      nicm      285:
                    286:        if (wp == w->active)
                    287:                style_apply(&gc, w->options, "pane-active-border-style");
                    288:        else
                    289:                style_apply(&gc, w->options, "pane-border-style");
                    290:
                    291:        fmt = options_get_string(w->options, "pane-border-format");
                    292:
1.46      nicm      293:        ft = format_create(c, NULL, FORMAT_PANE|wp->id, 0);
1.36      nicm      294:        format_defaults(ft, c, NULL, NULL, wp);
                    295:
1.40      nicm      296:        memcpy(&old, &wp->status_screen, sizeof old);
1.36      nicm      297:        screen_init(&wp->status_screen, wp->sx, 1, 0);
                    298:        wp->status_screen.mode = 0;
                    299:
                    300:        out = format_expand(ft, fmt);
                    301:        outlen = screen_write_cstrlen("%s", out);
                    302:        if (outlen > wp->sx - 4)
                    303:                outlen = wp->sx - 4;
                    304:        screen_resize(&wp->status_screen, outlen, 1, 0);
                    305:
                    306:        screen_write_start(&ctx, NULL, &wp->status_screen);
                    307:        screen_write_cursormove(&ctx, 0, 0);
1.41      nicm      308:        screen_write_clearline(&ctx, 8);
1.36      nicm      309:        screen_write_cnputs(&ctx, outlen, &gc, "%s", out);
                    310:        screen_write_stop(&ctx);
                    311:
1.48      nicm      312:        free(out);
1.36      nicm      313:        format_free(ft);
                    314:
                    315:        wp->status_size = outlen;
1.40      nicm      316:
                    317:        if (grid_compare(wp->status_screen.grid, old.grid) == 0) {
                    318:                screen_free(&old);
                    319:                return (0);
                    320:        }
                    321:        screen_free(&old);
                    322:        return (1);
1.36      nicm      323: }
                    324:
                    325: /* Draw pane status. */
1.39      nicm      326: static void
1.36      nicm      327: screen_redraw_draw_pane_status(struct client *c, int pane_status)
                    328: {
                    329:        struct window           *w = c->session->curw->window;
                    330:        struct options          *oo = c->session->options;
                    331:        struct tty              *tty = &c->tty;
                    332:        struct window_pane      *wp;
                    333:        int                      spos;
                    334:        u_int                    yoff;
                    335:
                    336:        spos = options_get_number(oo, "status-position");
                    337:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.40      nicm      338:                if (!window_pane_visible(wp))
                    339:                        continue;
1.36      nicm      340:                if (pane_status == CELL_STATUS_TOP)
                    341:                        yoff = wp->yoff - 1;
                    342:                else
                    343:                        yoff = wp->yoff + wp->sy;
                    344:                if (spos == 0)
                    345:                        yoff += 1;
                    346:
                    347:                tty_draw_line(tty, NULL, &wp->status_screen, 0, wp->xoff + 2,
                    348:                    yoff);
                    349:        }
                    350:        tty_cursor(tty, 0, 0);
1.24      nicm      351: }
                    352:
1.38      nicm      353: /* Update status line and change flags if unchanged. */
                    354: void
                    355: screen_redraw_update(struct client *c)
                    356: {
                    357:        struct window           *w = c->session->curw->window;
                    358:        struct window_pane      *wp;
                    359:        struct options          *wo = w->options;
                    360:        int                      redraw;
                    361:
                    362:        if (c->message_string != NULL)
                    363:                redraw = status_message_redraw(c);
                    364:        else if (c->prompt_string != NULL)
                    365:                redraw = status_prompt_redraw(c);
                    366:        else
                    367:                redraw = status_redraw(c);
                    368:        if (!redraw)
                    369:                c->flags &= ~CLIENT_STATUS;
                    370:
                    371:        if (options_get_number(wo, "pane-border-status") != CELL_STATUS_OFF) {
                    372:                redraw = 0;
                    373:                TAILQ_FOREACH(wp, &w->panes, entry) {
                    374:                        if (screen_redraw_make_pane_status(c, w, wp))
                    375:                                redraw = 1;
                    376:                }
                    377:                if (redraw)
                    378:                        c->flags |= CLIENT_BORDERS;
                    379:        }
                    380: }
                    381:
1.4       nicm      382: /* Redraw entire screen. */
1.1       nicm      383: void
1.26      nicm      384: screen_redraw_screen(struct client *c, int draw_panes, int draw_status,
                    385:     int draw_borders)
1.1       nicm      386: {
1.50    ! nicm      387:        struct options                  *oo = c->session->options;
        !           388:        struct tty                      *tty = &c->tty;
        !           389:        struct window                   *w = c->session->curw->window;
        !           390:        struct options                  *wo = w->options;
        !           391:        struct screen_redraw_ctx         ctx;
1.18      nicm      392:
                    393:        if (c->flags & CLIENT_SUSPENDED)
                    394:                return;
1.1       nicm      395:
1.50    ! nicm      396:        memset (&ctx, 0, sizeof ctx);
        !           397:        ctx.c = c;
        !           398:
1.47      nicm      399:        if (c->flags & CLIENT_STATUSOFF)
1.50    ! nicm      400:                ctx.lines = 0;
1.47      nicm      401:        else
1.50    ! nicm      402:                ctx.lines = status_line_size(c->session);
1.4       nicm      403:        if (c->message_string != NULL || c->prompt_string != NULL)
1.50    ! nicm      404:                ctx.lines = (ctx.lines == 0) ? 1 : ctx.lines;
1.47      nicm      405:
1.50    ! nicm      406:        if (ctx.lines != 0 && options_get_number(oo, "status-position") == 0)
        !           407:                ctx.top = 1;
        !           408:        ctx.pane_status = options_get_number(wo, "pane-border-status");
1.47      nicm      409:
1.50    ! nicm      410:        if (ctx.lines == 0)
1.26      nicm      411:                draw_status = 0;
                    412:
1.38      nicm      413:        if (draw_borders) {
1.50    ! nicm      414:                if (ctx.pane_status != CELL_STATUS_OFF)
        !           415:                        screen_redraw_draw_pane_status(c, ctx.pane_status);
        !           416:                screen_redraw_draw_borders(&ctx);
1.38      nicm      417:        }
1.26      nicm      418:        if (draw_panes)
1.50    ! nicm      419:                screen_redraw_draw_panes(&ctx);
1.26      nicm      420:        if (draw_status)
1.50    ! nicm      421:                screen_redraw_draw_status(&ctx);
1.26      nicm      422:        tty_reset(tty);
                    423: }
1.4       nicm      424:
1.26      nicm      425: /* Draw a single pane. */
                    426: void
                    427: screen_redraw_pane(struct client *c, struct window_pane *wp)
                    428: {
                    429:        u_int   i, yoff;
                    430:
                    431:        if (!window_pane_visible(wp))
1.4       nicm      432:                return;
1.1       nicm      433:
1.26      nicm      434:        yoff = wp->yoff;
                    435:        if (status_at_line(c) == 0)
1.47      nicm      436:                yoff += status_line_size(c->session);
1.44      nicm      437:
1.45      nicm      438:        log_debug("%s: redraw pane %%%u (at %u,%u)", c->name, wp->id,
1.44      nicm      439:            wp->xoff, yoff);
1.26      nicm      440:
                    441:        for (i = 0; i < wp->sy; i++)
1.30      nicm      442:                tty_draw_pane(&c->tty, wp, i, wp->xoff, yoff);
1.26      nicm      443:        tty_reset(&c->tty);
                    444: }
                    445:
1.50    ! nicm      446: /* Draw a border cell. */
        !           447: static void
        !           448: screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int x, u_int y,
        !           449:     int small, u_int msgx, u_int msgy, struct grid_cell *m_active_gc,
        !           450:     struct grid_cell *active_gc, struct grid_cell *m_other_gc,
        !           451:     struct grid_cell *other_gc)
        !           452: {
        !           453:        struct client           *c = ctx->c;
        !           454:        struct session          *s = c->session;
        !           455:        struct window           *w = s->curw->window;
        !           456:        struct tty              *tty = &c->tty;
        !           457:        struct window_pane      *wp;
        !           458:        struct window_pane      *active = w->active;
        !           459:        struct window_pane      *marked = marked_pane.wp;
        !           460:        u_int                    type;
        !           461:        int                      flag, pane_status = ctx->pane_status;
        !           462:
        !           463:        type = screen_redraw_check_cell(c, x, y, pane_status, &wp);
        !           464:        if (type == CELL_INSIDE)
        !           465:                return;
        !           466:        if (type == CELL_OUTSIDE && small && x > msgx && y == msgy)
        !           467:                return;
        !           468:        flag = screen_redraw_check_is(x, y, type, pane_status, w, active, wp);
        !           469:
        !           470:        if (server_is_marked(s, s->curw, marked_pane.wp) &&
        !           471:            screen_redraw_check_is(x, y, type, pane_status, w, marked, wp)) {
        !           472:                if (flag)
        !           473:                        tty_attributes(tty, m_active_gc, NULL);
        !           474:                else
        !           475:                        tty_attributes(tty, m_other_gc, NULL);
        !           476:        } else if (flag)
        !           477:                tty_attributes(tty, active_gc, NULL);
        !           478:        else
        !           479:                tty_attributes(tty, other_gc, NULL);
        !           480:        if (ctx->top)
        !           481:                tty_cursor(tty, x, ctx->lines + y);
        !           482:        else
        !           483:                tty_cursor(tty, x, y);
        !           484:        tty_putc(tty, CELL_BORDERS[type]);
        !           485: }
        !           486:
1.26      nicm      487: /* Draw the borders. */
1.39      nicm      488: static void
1.50    ! nicm      489: screen_redraw_draw_borders(struct screen_redraw_ctx *ctx)
1.26      nicm      490: {
1.50    ! nicm      491:        struct client           *c = ctx->c;
1.32      nicm      492:        struct session          *s = c->session;
                    493:        struct window           *w = s->curw->window;
1.33      nicm      494:        struct options          *oo = w->options;
1.26      nicm      495:        struct tty              *tty = &c->tty;
1.32      nicm      496:        struct grid_cell         m_active_gc, active_gc, m_other_gc, other_gc;
                    497:        struct grid_cell         msg_gc;
1.50    ! nicm      498:        u_int                    i, j, msgx = 0, msgy = 0;
        !           499:        int                      small, flags;
1.28      nicm      500:        char                     msg[256];
                    501:        const char              *tmp;
                    502:        size_t                   msglen = 0;
                    503:
1.50    ! nicm      504:        small = (tty->sy - ctx->lines + ctx->top > w->sy) || (tty->sx > w->sx);
1.28      nicm      505:        if (small) {
                    506:                flags = w->flags & (WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT);
                    507:                if (flags == (WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT))
                    508:                        tmp = "force-width, force-height";
                    509:                else if (flags == WINDOW_FORCEWIDTH)
                    510:                        tmp = "force-width";
                    511:                else if (flags == WINDOW_FORCEHEIGHT)
                    512:                        tmp = "force-height";
1.47      nicm      513:                else if (c->flags & CLIENT_STATUSOFF)
                    514:                        tmp = "status line";
1.28      nicm      515:                else
                    516:                        tmp = "a smaller client";
                    517:                xsnprintf(msg, sizeof msg, "(size %ux%u from %s)",
                    518:                    w->sx, w->sy, tmp);
                    519:                msglen = strlen(msg);
                    520:
1.50    ! nicm      521:                if (tty->sy - 1 - ctx->lines + ctx->top > w->sy &&
        !           522:                    tty->sx >= msglen) {
1.28      nicm      523:                        msgx = tty->sx - msglen;
1.50    ! nicm      524:                        msgy = tty->sy - 1 - ctx->lines + ctx->top;
1.28      nicm      525:                } else if (tty->sx - w->sx > msglen) {
                    526:                        msgx = tty->sx - msglen;
1.50    ! nicm      527:                        msgy = tty->sy - 1 - ctx->lines + ctx->top;
1.28      nicm      528:                } else
                    529:                        small = 0;
                    530:        }
1.26      nicm      531:
1.25      nicm      532:        style_apply(&other_gc, oo, "pane-border-style");
                    533:        style_apply(&active_gc, oo, "pane-active-border-style");
1.26      nicm      534:        active_gc.attr = other_gc.attr = GRID_ATTR_CHARSET;
1.15      nicm      535:
1.32      nicm      536:        memcpy(&m_other_gc, &other_gc, sizeof m_other_gc);
                    537:        m_other_gc.attr ^= GRID_ATTR_REVERSE;
                    538:        memcpy(&m_active_gc, &active_gc, sizeof m_active_gc);
                    539:        m_active_gc.attr ^= GRID_ATTR_REVERSE;
                    540:
1.50    ! nicm      541:        for (j = 0; j < tty->sy - ctx->lines; j++) {
1.1       nicm      542:                for (i = 0; i < tty->sx; i++) {
1.50    ! nicm      543:                        screen_redraw_draw_borders_cell(ctx, i, j, small,
        !           544:                            msgx, msgy, &m_active_gc, &active_gc, &m_other_gc,
        !           545:                            &other_gc);
1.1       nicm      546:                }
1.28      nicm      547:        }
                    548:
                    549:        if (small) {
                    550:                memcpy(&msg_gc, &grid_default_cell, sizeof msg_gc);
1.30      nicm      551:                tty_attributes(tty, &msg_gc, NULL);
1.28      nicm      552:                tty_cursor(tty, msgx, msgy);
                    553:                tty_puts(tty, msg);
1.1       nicm      554:        }
1.26      nicm      555: }
1.1       nicm      556:
1.26      nicm      557: /* Draw the panes. */
1.39      nicm      558: static void
1.50    ! nicm      559: screen_redraw_draw_panes(struct screen_redraw_ctx *ctx)
1.26      nicm      560: {
1.50    ! nicm      561:        struct client           *c = ctx->c;
1.26      nicm      562:        struct window           *w = c->session->curw->window;
                    563:        struct tty              *tty = &c->tty;
                    564:        struct window_pane      *wp;
1.47      nicm      565:        u_int                    i, y;
                    566:
1.50    ! nicm      567:        if (ctx->top)
        !           568:                y = ctx->lines;
1.47      nicm      569:        else
                    570:                y = 0;
1.1       nicm      571:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3       nicm      572:                if (!window_pane_visible(wp))
1.1       nicm      573:                        continue;
1.26      nicm      574:                for (i = 0; i < wp->sy; i++)
1.47      nicm      575:                        tty_draw_pane(tty, wp, i, wp->xoff, y + wp->yoff);
1.10      nicm      576:                if (c->flags & CLIENT_IDENTIFY)
1.50    ! nicm      577:                        screen_redraw_draw_number(ctx, wp);
1.1       nicm      578:        }
                    579: }
                    580:
1.26      nicm      581: /* Draw the status line. */
1.39      nicm      582: static void
1.50    ! nicm      583: screen_redraw_draw_status(struct screen_redraw_ctx *ctx)
1.1       nicm      584: {
1.50    ! nicm      585:        struct client   *c = ctx->c;
1.26      nicm      586:        struct tty      *tty = &c->tty;
1.47      nicm      587:        u_int            i, y;
1.23      nicm      588:
1.50    ! nicm      589:        if (ctx->top)
1.47      nicm      590:                y = 0;
1.26      nicm      591:        else
1.50    ! nicm      592:                y = tty->sy - ctx->lines;
        !           593:        for (i = 0; i < ctx->lines; i++)
1.49      nicm      594:                tty_draw_line(tty, NULL, &c->status.status, i, 0, y);
1.10      nicm      595: }
                    596:
                    597: /* Draw number on a pane. */
1.39      nicm      598: static void
1.50    ! nicm      599: screen_redraw_draw_number(struct screen_redraw_ctx *ctx, struct window_pane *wp)
1.10      nicm      600: {
1.50    ! nicm      601:        struct client           *c = ctx->c;
1.10      nicm      602:        struct tty              *tty = &c->tty;
                    603:        struct session          *s = c->session;
1.33      nicm      604:        struct options          *oo = s->options;
1.16      nicm      605:        struct window           *w = wp->window;
1.10      nicm      606:        struct grid_cell         gc;
1.12      nicm      607:        u_int                    idx, px, py, i, j, xoff, yoff;
1.16      nicm      608:        int                      colour, active_colour;
1.10      nicm      609:        char                     buf[16], *ptr;
                    610:        size_t                   len;
                    611:
1.19      nicm      612:        if (window_pane_index(wp, &idx) != 0)
                    613:                fatalx("index not found");
1.10      nicm      614:        len = xsnprintf(buf, sizeof buf, "%u", idx);
                    615:
                    616:        if (wp->sx < len)
                    617:                return;
1.16      nicm      618:        colour = options_get_number(oo, "display-panes-colour");
                    619:        active_colour = options_get_number(oo, "display-panes-active-colour");
1.10      nicm      620:
1.12      nicm      621:        px = wp->sx / 2; py = wp->sy / 2;
                    622:        xoff = wp->xoff; yoff = wp->yoff;
1.31      nicm      623:
1.50    ! nicm      624:        if (ctx->top)
        !           625:                yoff += ctx->lines;
1.12      nicm      626:
1.10      nicm      627:        if (wp->sx < len * 6 || wp->sy < 5) {
1.12      nicm      628:                tty_cursor(tty, xoff + px - len / 2, yoff + py);
1.20      nicm      629:                goto draw_text;
1.10      nicm      630:        }
1.14      nicm      631:
1.10      nicm      632:        px -= len * 3;
                    633:        py -= 2;
                    634:
1.25      nicm      635:        memcpy(&gc, &grid_default_cell, sizeof gc);
1.16      nicm      636:        if (w->active == wp)
1.37      nicm      637:                gc.bg = active_colour;
1.16      nicm      638:        else
1.37      nicm      639:                gc.bg = colour;
1.42      nicm      640:        gc.flags |= GRID_FLAG_NOPALETTE;
                    641:
1.30      nicm      642:        tty_attributes(tty, &gc, wp);
1.10      nicm      643:        for (ptr = buf; *ptr != '\0'; ptr++) {
                    644:                if (*ptr < '0' || *ptr > '9')
                    645:                        continue;
                    646:                idx = *ptr - '0';
1.14      nicm      647:
1.10      nicm      648:                for (j = 0; j < 5; j++) {
                    649:                        for (i = px; i < px + 5; i++) {
1.12      nicm      650:                                tty_cursor(tty, xoff + i, yoff + py + j);
1.27      nicm      651:                                if (window_clock_table[idx][j][i - px])
1.11      nicm      652:                                        tty_putc(tty, ' ');
1.10      nicm      653:                        }
                    654:                }
                    655:                px += 6;
                    656:        }
1.20      nicm      657:
                    658:        len = xsnprintf(buf, sizeof buf, "%ux%u", wp->sx, wp->sy);
                    659:        if (wp->sx < len || wp->sy < 6)
                    660:                return;
                    661:        tty_cursor(tty, xoff + wp->sx - len, yoff);
                    662:
                    663: draw_text:
1.25      nicm      664:        memcpy(&gc, &grid_default_cell, sizeof gc);
1.20      nicm      665:        if (w->active == wp)
1.37      nicm      666:                gc.fg = active_colour;
1.20      nicm      667:        else
1.37      nicm      668:                gc.fg = colour;
1.42      nicm      669:        gc.flags |= GRID_FLAG_NOPALETTE;
                    670:
1.30      nicm      671:        tty_attributes(tty, &gc, wp);
1.20      nicm      672:        tty_puts(tty, buf);
                    673:
                    674:        tty_cursor(tty, 0, 0);
1.1       nicm      675: }