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