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

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