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

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