Annotation of src/usr.bin/tmux/screen-redraw.c, Revision 1.2
1.2 ! nicm 1: /* $OpenBSD: screen-redraw.c,v 1.1 2009/06/01 22:58:49 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) {
38: /* Inside pane. */
39: if (px >= wp->xoff && px < wp->xoff + wp->sx &&
40: py >= wp->yoff && py < wp->yoff + wp->sy)
41: return (1);
42:
43: /* Left/right borders. */
44: if (py >= wp->yoff && py < wp->yoff + wp->sy) {
45: if (wp->xoff != 0 && px == wp->xoff - 1)
46: return (1);
47: if (px == wp->xoff + wp->sx)
48: return (1);
49: }
50:
51: /* Top/bottom borders. */
52: if (px >= wp->xoff && px < wp->xoff + wp->sx) {
53: if (wp->yoff != 0 && py == wp->yoff - 1)
54: return (1);
55: if (py == wp->yoff + wp->sy)
56: return (1);
57: }
58: }
59:
60: return (0);
61: }
62:
63: /* Redraw entire screen.. */
64: void
65: screen_redraw_screen(struct client *c)
66: {
67: struct window *w = c->session->curw->window;
68: struct tty *tty = &c->tty;
69: struct window_pane *wp;
70: u_int i, j, sx, sy;
71: int status, has_acs;
72: u_char choriz, cvert, cbackg;
73:
74: /* Get status line, er, status. */
75: status = options_get_number(&c->session->options, "status");
76:
77: /* Work out ACS characters. */
78: if (tty_term_has(tty->term, TTYC_ACSC)) {
79: has_acs = 1;
80: choriz = tty_get_acs(tty, 'q');
81: cvert = tty_get_acs(tty, 'x');
82: cbackg = tty_get_acs(tty, '~');
83: } else {
84: has_acs = 0;
85: choriz = '-';
86: cvert = '|';
87: cbackg = '.';
88: }
89:
90: /* Clear the screen. */
91: tty_reset(tty);
92: if (has_acs)
93: tty_putcode(tty, TTYC_SMACS);
94: for (j = 0; j < tty->sy - status; j++) {
95: for (i = 0; i < tty->sx; i++) {
96: if (!screen_redraw_check_cell(c, i, j)) {
97: tty_cursor(tty, i, j, 0, 0);
98: tty_putc(tty, cbackg);
99: }
100: }
101: }
102: if (has_acs)
103: tty_putcode(tty, TTYC_RMACS);
104:
105: /* Draw the panes. */
106: TAILQ_FOREACH(wp, &w->panes, entry) {
107: if (wp->flags & PANE_HIDDEN)
108: continue;
109:
110: tty_reset(tty);
111:
112: sx = wp->sx;
113: sy = wp->sy;
114:
115: /* Draw left and right borders. */
116: if (has_acs)
117: tty_putcode(tty, TTYC_SMACS);
118: if (wp->xoff > 0) {
119: for (i = wp->yoff; i < wp->yoff + sy; i++) {
120: tty_cursor(tty, wp->xoff - 1, i, 0, 0);
121: tty_putc(tty, cvert);
122: }
123: }
124: if (wp->xoff + sx < tty->sx) {
125: for (i = wp->yoff; i < wp->yoff + sy; i++) {
126: tty_cursor(tty, wp->xoff + sx, i, 0, 0);
127: tty_putc(&c->tty, cvert);
128: }
129: }
130:
131: /* Draw top and bottom borders. */
132: if (wp->yoff > 0) {
133: tty_cursor(tty, wp->xoff, wp->yoff - 1, 0, 0);
134: for (i = 0; i < sx; i++)
135: tty_putc(tty, choriz);
136: }
137: if (wp->yoff + sy < tty->sy - status) {
138: tty_cursor(tty, wp->xoff, wp->yoff + sy, 0, 0);
139: for (i = 0; i < sx; i++)
140: tty_putc(tty, choriz);
141: }
142: if (has_acs)
143: tty_putcode(tty, TTYC_RMACS);
144:
145: /* Draw the pane. */
146: screen_redraw_pane(c, wp);
147: }
148:
149: /* Draw the status line. */
150: screen_redraw_status(c);
151: }
152:
153: /* Draw a single pane. */
154: void
155: screen_redraw_pane(struct client *c, struct window_pane *wp)
156: {
157: u_int i;
158:
159: for (i = 0; i < wp->sy; i++)
160: tty_draw_line(&c->tty, wp->screen, i, wp->xoff, wp->yoff);
161: }
162:
163:
164: /* Draw the status line. */
165: void
166: screen_redraw_status(struct client *c)
167: {
168: tty_draw_line(&c->tty, &c->status, 0, 0, c->tty.sy - 1);
169: }