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

1.8     ! nicm        1: /* $OpenBSD: screen-redraw.c,v 1.7 2009/07/24 19:14:38 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/types.h>
                     20:
                     21: #include <string.h>
                     22:
                     23: #include "tmux.h"
                     24:
1.7       nicm       25: int    screen_redraw_cell_border(struct client *, u_int, u_int);
1.1       nicm       26: int    screen_redraw_check_cell(struct client *, u_int, u_int);
                     27:
1.6       nicm       28: #define CELL_INSIDE 0
1.7       nicm       29: #define CELL_LEFTRIGHT 1
                     30: #define CELL_TOPBOTTOM 2
                     31: #define CELL_TOPLEFT 3
                     32: #define CELL_TOPRIGHT 4
                     33: #define CELL_BOTTOMLEFT 5
                     34: #define CELL_BOTTOMRIGHT 6
                     35: #define CELL_TOPJOIN 7
                     36: #define CELL_BOTTOMJOIN 8
                     37: #define CELL_LEFTJOIN 9
                     38: #define CELL_RIGHTJOIN 10
                     39: #define CELL_JOIN 11
                     40: #define CELL_OUTSIDE 12
1.6       nicm       41:
1.7       nicm       42: /* Check if a cell is on the pane border. */
1.1       nicm       43: int
1.7       nicm       44: screen_redraw_cell_border(struct client *c, u_int px, u_int py)
1.1       nicm       45: {
                     46:        struct window           *w = c->session->curw->window;
                     47:        struct window_pane      *wp;
                     48:
1.7       nicm       49:        /* Check all the panes. */
1.1       nicm       50:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3       nicm       51:                if (!window_pane_visible(wp))
                     52:                        continue;
                     53:
1.1       nicm       54:                /* Inside pane. */
                     55:                if (px >= wp->xoff && px < wp->xoff + wp->sx &&
                     56:                    py >= wp->yoff && py < wp->yoff + wp->sy)
1.7       nicm       57:                        return (0);
1.1       nicm       58:
                     59:                /* Left/right borders. */
1.7       nicm       60:                if ((wp->yoff == 0 || py >= wp->yoff - 1) &&
                     61:                    py <= wp->yoff + wp->sy) {
1.1       nicm       62:                        if (wp->xoff != 0 && px == wp->xoff - 1)
1.7       nicm       63:                                return (1);
1.1       nicm       64:                        if (px == wp->xoff + wp->sx)
1.7       nicm       65:                                return (1);
1.1       nicm       66:                }
                     67:
                     68:                /* Top/bottom borders. */
1.7       nicm       69:                if ((wp->xoff == 0 || px >= wp->xoff - 1) &&
                     70:                    px <= wp->xoff + wp->sx) {
1.1       nicm       71:                        if (wp->yoff != 0 && py == wp->yoff - 1)
1.7       nicm       72:                                return (1);
1.1       nicm       73:                        if (py == wp->yoff + wp->sy)
1.7       nicm       74:                                return (1);
                     75:                }
                     76:        }
                     77:
                     78:        return (0);
                     79: }
                     80:
                     81: /* Check if cell inside a pane. */
                     82: int
                     83: screen_redraw_check_cell(struct client *c, u_int px, u_int py)
                     84: {
                     85:        struct window           *w = c->session->curw->window;
                     86:        struct window_pane      *wp;
                     87:        int                      borders;
                     88:
                     89:        if (px > w->sx || py > w->sy)
                     90:                return (CELL_OUTSIDE);
                     91:
                     92:        TAILQ_FOREACH(wp, &w->panes, entry) {
                     93:                if (!window_pane_visible(wp))
                     94:                        continue;
                     95:
                     96:                /* If outside the pane and its border, skip it. */
                     97:                if ((wp->xoff != 0 && px < wp->xoff - 1) ||
                     98:                    px > wp->xoff + wp->sx ||
                     99:                    (wp->yoff != 0 && py < wp->yoff - 1) ||
                    100:                    py > wp->yoff + wp->sy)
                    101:                        continue;
                    102:
                    103:                /* If definitely inside, return so. */
                    104:                if (!screen_redraw_cell_border(c, px, py))
                    105:                        return (CELL_INSIDE);
                    106:
                    107:                /*
                    108:                 * Construct a bitmask of whether the cells to the left (bit
                    109:                 * 4), right, top, and bottom (bit 1) of this cell are borders.
                    110:                 */
                    111:                borders = 0;
                    112:                if (px == 0 || screen_redraw_cell_border(c, px - 1, py))
                    113:                        borders |= 8;
                    114:                if (px <= w->sx && screen_redraw_cell_border(c, px + 1, py))
                    115:                        borders |= 4;
                    116:                if (py == 0 || screen_redraw_cell_border(c, px, py - 1))
                    117:                        borders |= 2;
                    118:                if (py <= w->sy && screen_redraw_cell_border(c, px, py + 1))
                    119:                        borders |= 1;
                    120:
                    121:                /*
                    122:                 * Figure out what kind of border this cell is. Only one bit
                    123:                 * set doesn't make sense (can't have a border cell with no
                    124:                 * others connected).
                    125:                 */
                    126:                switch (borders) {
                    127:                case 15:        /* 1111, left right top bottom */
                    128:                        return (CELL_JOIN);
                    129:                case 14:        /* 1110, left right top */
                    130:                        return (CELL_BOTTOMJOIN);
                    131:                case 13:        /* 1101, left right bottom */
                    132:                        return (CELL_TOPJOIN);
                    133:                case 12:        /* 1100, left right */
                    134:                        return (CELL_TOPBOTTOM);
                    135:                case 11:        /* 1011, left top bottom */
                    136:                        return (CELL_RIGHTJOIN);
                    137:                case 10:        /* 1010, left top */
                    138:                        return (CELL_BOTTOMRIGHT);
                    139:                case 9:         /* 1001, left bottom */
                    140:                        return (CELL_TOPRIGHT);
                    141:                case 7:         /* 0111, right top bottom */
                    142:                        return (CELL_LEFTJOIN);
                    143:                case 6:         /* 0110, right top */
                    144:                        return (CELL_BOTTOMLEFT);
                    145:                case 5:         /* 0101, right bottom */
                    146:                        return (CELL_TOPLEFT);
                    147:                case 3:         /* 0011, top bottom */
                    148:                        return (CELL_LEFTRIGHT);
1.1       nicm      149:                }
                    150:        }
                    151:
1.6       nicm      152:        return (CELL_OUTSIDE);
1.1       nicm      153: }
                    154:
1.4       nicm      155: /* Redraw entire screen. */
1.1       nicm      156: void
1.4       nicm      157: screen_redraw_screen(struct client *c, int status_only)
1.1       nicm      158: {
                    159:        struct window           *w = c->session->curw->window;
                    160:        struct tty              *tty = &c->tty;
                    161:        struct window_pane      *wp;
1.6       nicm      162:        u_int                    i, j, type;
                    163:        int                      status;
1.8     ! nicm      164:        const u_char            *base, *ptr;
        !           165:        u_char                   ch, border[20];
1.1       nicm      166:
                    167:        /* Get status line, er, status. */
1.4       nicm      168:        if (c->message_string != NULL || c->prompt_string != NULL)
                    169:                status = 1;
                    170:        else
                    171:                status = options_get_number(&c->session->options, "status");
                    172:
                    173:        /* If only drawing status and it is present, don't need the rest. */
                    174:        if (status_only && status) {
                    175:                tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1);
                    176:                return;
                    177:        }
1.1       nicm      178:
1.6       nicm      179:        /* Draw background and borders. */
                    180:        tty_reset(tty);
1.8     ! nicm      181:        strlcpy(border, " |-....--||+.", sizeof border);
1.1       nicm      182:        if (tty_term_has(tty->term, TTYC_ACSC)) {
1.8     ! nicm      183:                base = " xqlkmjwvtun~";
        !           184:                for (ptr = base; *ptr != '\0'; ptr++) {
        !           185:                        if ((ch = tty_get_acs(tty, *ptr)) != '\0')
        !           186:                                border[ptr - base] = ch;
        !           187:                }
1.1       nicm      188:                tty_putcode(tty, TTYC_SMACS);
1.8     ! nicm      189:        }
1.1       nicm      190:        for (j = 0; j < tty->sy - status; j++) {
1.4       nicm      191:                if (status_only && j != tty->sy - 1)
                    192:                        continue;
1.1       nicm      193:                for (i = 0; i < tty->sx; i++) {
1.6       nicm      194:                        type = screen_redraw_check_cell(c, i, j);
                    195:                        if (type != CELL_INSIDE) {
1.1       nicm      196:                                tty_cursor(tty, i, j, 0, 0);
1.6       nicm      197:                                tty_putc(tty, border[type]);
1.1       nicm      198:                        }
                    199:                }
                    200:        }
1.6       nicm      201:        tty_putcode(tty, TTYC_RMACS);
1.1       nicm      202:
                    203:        /* Draw the panes. */
                    204:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3       nicm      205:                if (!window_pane_visible(wp))
1.1       nicm      206:                        continue;
1.4       nicm      207:                for (i = 0; i < wp->sy; i++) {
1.5       nicm      208:                        if (status_only && wp->yoff + i != tty->sy - 1)
1.4       nicm      209:                                continue;
                    210:                        tty_draw_line(tty, wp->screen, i, wp->xoff, wp->yoff);
                    211:                }
1.1       nicm      212:        }
                    213:
                    214:        /* Draw the status line. */
1.4       nicm      215:        if (status)
                    216:                tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1);
1.1       nicm      217: }
                    218:
                    219: /* Draw a single pane. */
                    220: void
                    221: screen_redraw_pane(struct client *c, struct window_pane *wp)
                    222: {
                    223:        u_int   i;
                    224:
                    225:        for (i = 0; i < wp->sy; i++)
                    226:                tty_draw_line(&c->tty, wp->screen, i, wp->xoff, wp->yoff);
                    227: }