[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.53

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