Annotation of src/usr.bin/tmux/screen-redraw.c, Revision 1.71
1.71 ! nicm 1: /* $OpenBSD: screen-redraw.c,v 1.70 2020/04/18 06:20:50 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.70 nicm 441: log_debug("%s: redrawing borders", c->name);
1.64 nicm 442: if (ctx.pane_status != PANE_STATUS_OFF)
1.53 nicm 443: screen_redraw_draw_pane_status(&ctx);
1.50 nicm 444: screen_redraw_draw_borders(&ctx);
1.53 nicm 445: }
1.70 nicm 446: if (flags & CLIENT_REDRAWWINDOW) {
447: log_debug("%s: redrawing panes", c->name);
1.50 nicm 448: screen_redraw_draw_panes(&ctx);
1.70 nicm 449: }
1.61 nicm 450: if (ctx.statuslines != 0 &&
1.70 nicm 451: (flags & (CLIENT_REDRAWSTATUS|CLIENT_REDRAWSTATUSALWAYS))) {
452: log_debug("%s: redrawing status", c->name);
1.50 nicm 453: screen_redraw_draw_status(&ctx);
1.70 nicm 454: }
455: if (c->overlay_draw != NULL && (flags & CLIENT_REDRAWOVERLAY)) {
456: log_debug("%s: redrawing overlay", c->name);
1.61 nicm 457: c->overlay_draw(c, &ctx);
1.70 nicm 458: }
1.67 nicm 459:
1.52 nicm 460: tty_reset(&c->tty);
1.67 nicm 461: tty_sync_end(&c->tty);
1.26 nicm 462: }
1.4 nicm 463:
1.55 nicm 464: /* Redraw a single pane. */
1.26 nicm 465: void
466: screen_redraw_pane(struct client *c, struct window_pane *wp)
467: {
1.55 nicm 468: struct screen_redraw_ctx ctx;
1.26 nicm 469:
1.63 nicm 470: if (c->overlay_draw != NULL || !window_pane_visible(wp))
1.4 nicm 471: return;
1.1 nicm 472:
1.55 nicm 473: screen_redraw_set_context(c, &ctx);
1.67 nicm 474: tty_sync_start(&c->tty);
1.26 nicm 475:
1.55 nicm 476: screen_redraw_draw_pane(&ctx, wp);
1.71 ! nicm 477: wp->flags &= ~PANE_REDRAW;
1.67 nicm 478:
1.26 nicm 479: tty_reset(&c->tty);
1.67 nicm 480: tty_sync_end(&c->tty);
1.26 nicm 481: }
482:
1.50 nicm 483: /* Draw a border cell. */
484: static void
1.55 nicm 485: screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j,
486: struct grid_cell *m_active_gc, struct grid_cell *active_gc,
487: struct grid_cell *m_other_gc, struct grid_cell *other_gc)
1.50 nicm 488: {
1.53 nicm 489: struct client *c = ctx->c;
490: struct session *s = c->session;
491: struct window *w = s->curw->window;
492: struct tty *tty = &c->tty;
493: struct window_pane *wp;
494: struct window_pane *active = w->active;
495: struct window_pane *marked = marked_pane.wp;
1.55 nicm 496: u_int type, x = ctx->ox + i, y = ctx->oy + j;
1.53 nicm 497: int flag, pane_status = ctx->pane_status;
1.50 nicm 498:
1.66 nicm 499: if (c->overlay_check != NULL && !c->overlay_check(c, x, y))
500: return;
1.50 nicm 501: type = screen_redraw_check_cell(c, x, y, pane_status, &wp);
502: if (type == CELL_INSIDE)
503: return;
504: flag = screen_redraw_check_is(x, y, type, pane_status, w, active, wp);
505:
506: if (server_is_marked(s, s->curw, marked_pane.wp) &&
507: screen_redraw_check_is(x, y, type, pane_status, w, marked, wp)) {
508: if (flag)
509: tty_attributes(tty, m_active_gc, NULL);
510: else
511: tty_attributes(tty, m_other_gc, NULL);
512: } else if (flag)
513: tty_attributes(tty, active_gc, NULL);
514: else
515: tty_attributes(tty, other_gc, NULL);
1.61 nicm 516: if (ctx->statustop)
517: tty_cursor(tty, i, ctx->statuslines + j);
1.50 nicm 518: else
1.55 nicm 519: tty_cursor(tty, i, j);
1.50 nicm 520: tty_putc(tty, CELL_BORDERS[type]);
521: }
522:
1.26 nicm 523: /* Draw the borders. */
1.39 nicm 524: static void
1.50 nicm 525: screen_redraw_draw_borders(struct screen_redraw_ctx *ctx)
1.26 nicm 526: {
1.50 nicm 527: struct client *c = ctx->c;
1.32 nicm 528: struct session *s = c->session;
529: struct window *w = s->curw->window;
1.55 nicm 530: struct tty *tty = &c->tty;
1.33 nicm 531: struct options *oo = w->options;
1.32 nicm 532: struct grid_cell m_active_gc, active_gc, m_other_gc, other_gc;
1.55 nicm 533: u_int i, j;
534:
535: log_debug("%s: %s @%u", __func__, c->name, w->id);
1.26 nicm 536:
1.25 nicm 537: style_apply(&other_gc, oo, "pane-border-style");
538: style_apply(&active_gc, oo, "pane-active-border-style");
1.26 nicm 539: active_gc.attr = other_gc.attr = GRID_ATTR_CHARSET;
1.15 nicm 540:
1.32 nicm 541: memcpy(&m_other_gc, &other_gc, sizeof m_other_gc);
542: m_other_gc.attr ^= GRID_ATTR_REVERSE;
543: memcpy(&m_active_gc, &active_gc, sizeof m_active_gc);
544: m_active_gc.attr ^= GRID_ATTR_REVERSE;
545:
1.61 nicm 546: for (j = 0; j < tty->sy - ctx->statuslines; j++) {
1.55 nicm 547: for (i = 0; i < tty->sx; i++) {
548: screen_redraw_draw_borders_cell(ctx, i, j,
549: &m_active_gc, &active_gc, &m_other_gc, &other_gc);
1.1 nicm 550: }
1.28 nicm 551: }
1.26 nicm 552: }
1.1 nicm 553:
1.26 nicm 554: /* Draw the panes. */
1.39 nicm 555: static void
1.50 nicm 556: screen_redraw_draw_panes(struct screen_redraw_ctx *ctx)
1.26 nicm 557: {
1.50 nicm 558: struct client *c = ctx->c;
1.26 nicm 559: struct window *w = c->session->curw->window;
560: struct window_pane *wp;
1.47 nicm 561:
1.55 nicm 562: log_debug("%s: %s @%u", __func__, c->name, w->id);
563:
1.1 nicm 564: TAILQ_FOREACH(wp, &w->panes, entry) {
1.61 nicm 565: if (window_pane_visible(wp))
566: screen_redraw_draw_pane(ctx, wp);
1.71 ! nicm 567: wp->flags &= ~PANE_REDRAW;
1.1 nicm 568: }
569: }
570:
1.26 nicm 571: /* Draw the status line. */
1.39 nicm 572: static void
1.50 nicm 573: screen_redraw_draw_status(struct screen_redraw_ctx *ctx)
1.1 nicm 574: {
1.50 nicm 575: struct client *c = ctx->c;
1.55 nicm 576: struct window *w = c->session->curw->window;
1.26 nicm 577: struct tty *tty = &c->tty;
1.58 nicm 578: struct screen *s = c->status.active;
1.47 nicm 579: u_int i, y;
1.23 nicm 580:
1.55 nicm 581: log_debug("%s: %s @%u", __func__, c->name, w->id);
582:
1.61 nicm 583: if (ctx->statustop)
1.47 nicm 584: y = 0;
1.26 nicm 585: else
1.61 nicm 586: y = c->tty.sy - ctx->statuslines;
587: for (i = 0; i < ctx->statuslines; i++)
1.55 nicm 588: tty_draw_line(tty, NULL, s, 0, i, UINT_MAX, 0, y + i);
589: }
590:
591: /* Draw one pane. */
592: static void
593: screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp)
594: {
595: struct client *c = ctx->c;
596: struct window *w = c->session->curw->window;
597: struct tty *tty = &c->tty;
598: struct screen *s;
599: u_int i, j, top, x, y, width;
600:
601: log_debug("%s: %s @%u %%%u", __func__, c->name, w->id, wp->id);
602:
603: if (wp->xoff + wp->sx <= ctx->ox || wp->xoff >= ctx->ox + ctx->sx)
604: return;
1.61 nicm 605: if (ctx->statustop)
606: top = ctx->statuslines;
1.55 nicm 607: else
608: top = 0;
609:
610: s = wp->screen;
611: for (j = 0; j < wp->sy; j++) {
612: if (wp->yoff + j < ctx->oy || wp->yoff + j >= ctx->oy + ctx->sy)
613: continue;
614: y = top + wp->yoff + j - ctx->oy;
615:
616: if (wp->xoff >= ctx->ox &&
617: wp->xoff + wp->sx <= ctx->ox + ctx->sx) {
618: /* All visible. */
619: i = 0;
620: x = wp->xoff - ctx->ox;
621: width = wp->sx;
622: } else if (wp->xoff < ctx->ox &&
623: wp->xoff + wp->sx > ctx->ox + ctx->sx) {
624: /* Both left and right not visible. */
625: i = ctx->ox;
626: x = 0;
627: width = ctx->sx;
628: } else if (wp->xoff < ctx->ox) {
629: /* Left not visible. */
630: i = ctx->ox - wp->xoff;
631: x = 0;
632: width = wp->sx - i;
633: } else {
634: /* Right not visible. */
635: i = 0;
636: x = wp->xoff - ctx->ox;
637: width = ctx->sx - x;
638: }
639: log_debug("%s: %s %%%u line %u,%u at %u,%u, width %u",
640: __func__, c->name, wp->id, i, j, x, y, width);
641:
642: tty_draw_line(tty, wp, s, i, j, width, x, y);
643: }
1.1 nicm 644: }