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

1.5     ! nicm        1: /* $OpenBSD: screen-redraw.c,v 1.4 2009/07/14 19:03:16 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:
                     25: int    screen_redraw_check_cell(struct client *, u_int, u_int);
                     26:
                     27: /* Check if cell inside a pane. */
                     28: int
                     29: screen_redraw_check_cell(struct client *c, u_int px, u_int py)
                     30: {
                     31:        struct window           *w = c->session->curw->window;
                     32:        struct window_pane      *wp;
                     33:
                     34:        if (px > w->sx || py > w->sy)
                     35:                return (0);
                     36:
                     37:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3       nicm       38:                if (!window_pane_visible(wp))
                     39:                        continue;
                     40:
1.1       nicm       41:                /* Inside pane. */
                     42:                if (px >= wp->xoff && px < wp->xoff + wp->sx &&
                     43:                    py >= wp->yoff && py < wp->yoff + wp->sy)
                     44:                        return (1);
                     45:
                     46:                /* Left/right borders. */
                     47:                if (py >= wp->yoff && py < wp->yoff + wp->sy) {
                     48:                        if (wp->xoff != 0 && px == wp->xoff - 1)
                     49:                                return (1);
                     50:                        if (px == wp->xoff + wp->sx)
                     51:                                return (1);
                     52:                }
                     53:
                     54:                /* Top/bottom borders. */
                     55:                if (px >= wp->xoff && px < wp->xoff + wp->sx) {
                     56:                        if (wp->yoff != 0 && py == wp->yoff - 1)
                     57:                                return (1);
                     58:                        if (py == wp->yoff + wp->sy)
                     59:                                return (1);
                     60:                }
                     61:        }
                     62:
                     63:        return (0);
                     64: }
                     65:
1.4       nicm       66: /* Redraw entire screen. */
1.1       nicm       67: void
1.4       nicm       68: screen_redraw_screen(struct client *c, int status_only)
1.1       nicm       69: {
                     70:        struct window           *w = c->session->curw->window;
                     71:        struct tty              *tty = &c->tty;
                     72:        struct window_pane      *wp;
                     73:        u_int                    i, j, sx, sy;
                     74:        int                      status, has_acs;
                     75:        u_char                   choriz, cvert, cbackg;
                     76:
                     77:        /* Get status line, er, status. */
1.4       nicm       78:        if (c->message_string != NULL || c->prompt_string != NULL)
                     79:                status = 1;
                     80:        else
                     81:                status = options_get_number(&c->session->options, "status");
                     82:
                     83:        /* If only drawing status and it is present, don't need the rest. */
                     84:        if (status_only && status) {
                     85:                tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1);
                     86:                return;
                     87:        }
1.1       nicm       88:
                     89:        /* Work out ACS characters. */
                     90:        if (tty_term_has(tty->term, TTYC_ACSC)) {
                     91:                has_acs = 1;
                     92:                choriz = tty_get_acs(tty, 'q');
                     93:                cvert = tty_get_acs(tty, 'x');
                     94:                cbackg = tty_get_acs(tty, '~');
                     95:        } else {
                     96:                has_acs = 0;
                     97:                choriz = '-';
                     98:                cvert = '|';
                     99:                cbackg = '.';
                    100:        }
                    101:
                    102:        /* Clear the screen. */
                    103:        tty_reset(tty);
                    104:        if (has_acs)
                    105:                tty_putcode(tty, TTYC_SMACS);
                    106:        for (j = 0; j < tty->sy - status; j++) {
1.4       nicm      107:                if (status_only && j != tty->sy - 1)
                    108:                        continue;
1.1       nicm      109:                for (i = 0; i < tty->sx; i++) {
                    110:                        if (!screen_redraw_check_cell(c, i, j)) {
                    111:                                tty_cursor(tty, i, j, 0, 0);
                    112:                                tty_putc(tty, cbackg);
                    113:                        }
                    114:                }
                    115:        }
                    116:        if (has_acs)
                    117:                tty_putcode(tty, TTYC_RMACS);
                    118:
                    119:        /* Draw the panes. */
                    120:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3       nicm      121:                if (!window_pane_visible(wp))
1.1       nicm      122:                        continue;
                    123:
                    124:                tty_reset(tty);
                    125:
                    126:                sx = wp->sx;
                    127:                sy = wp->sy;
                    128:
                    129:                /* Draw left and right borders. */
                    130:                if (has_acs)
                    131:                        tty_putcode(tty, TTYC_SMACS);
                    132:                if (wp->xoff > 0) {
                    133:                        for (i = wp->yoff; i < wp->yoff + sy; i++) {
1.4       nicm      134:                                if (status_only && i != tty->sy - 1)
                    135:                                        continue;
1.1       nicm      136:                                tty_cursor(tty, wp->xoff - 1, i, 0, 0);
                    137:                                tty_putc(tty, cvert);
                    138:                        }
                    139:                }
                    140:                if (wp->xoff + sx < tty->sx) {
                    141:                        for (i = wp->yoff; i < wp->yoff + sy; i++) {
1.4       nicm      142:                                if (status_only && i != tty->sy - 1)
                    143:                                        continue;
1.1       nicm      144:                                tty_cursor(tty, wp->xoff + sx, i, 0, 0);
                    145:                                tty_putc(&c->tty, cvert);
                    146:                        }
                    147:                }
                    148:
                    149:                /* Draw top and bottom borders. */
                    150:                if (wp->yoff > 0) {
1.4       nicm      151:                        if (!status_only || wp->yoff - 1 == tty->sy - 1) {
                    152:                                tty_cursor(tty, wp->xoff, wp->yoff - 1, 0, 0);
                    153:                                for (i = 0; i < sx; i++)
                    154:                                        tty_putc(tty, choriz);
                    155:                        }
1.1       nicm      156:                }
                    157:                if (wp->yoff + sy < tty->sy - status) {
1.4       nicm      158:                        if (!status_only || wp->yoff + sy == tty->sy - 1) {
                    159:                                tty_cursor(tty, wp->xoff, wp->yoff + sy, 0, 0);
                    160:                                for (i = 0; i < sx; i++)
                    161:                                        tty_putc(tty, choriz);
                    162:                        }
1.1       nicm      163:                }
                    164:                if (has_acs)
                    165:                        tty_putcode(tty, TTYC_RMACS);
                    166:
                    167:                /* Draw the pane. */
1.4       nicm      168:                for (i = 0; i < wp->sy; i++) {
1.5     ! nicm      169:                        if (status_only && wp->yoff + i != tty->sy - 1)
1.4       nicm      170:                                continue;
                    171:                        tty_draw_line(tty, wp->screen, i, wp->xoff, wp->yoff);
                    172:                }
1.1       nicm      173:        }
                    174:
                    175:        /* Draw the status line. */
1.4       nicm      176:        if (status)
                    177:                tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1);
1.1       nicm      178: }
                    179:
                    180: /* Draw a single pane. */
                    181: void
                    182: screen_redraw_pane(struct client *c, struct window_pane *wp)
                    183: {
                    184:        u_int   i;
                    185:
                    186:        for (i = 0; i < wp->sy; i++)
                    187:                tty_draw_line(&c->tty, wp->screen, i, wp->xoff, wp->yoff);
                    188: }