Annotation of src/usr.bin/tmux/screen-redraw.c, Revision 1.77
1.77 ! nicm 1: /* $OpenBSD: screen-redraw.c,v 1.76 2020/05/16 15:34:08 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;
1.77 ! nicm 245: struct window_pane *wp, *active;
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.77 ! nicm 257: active = wp = server_client_get_pane(c);
1.75 nicm 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);
1.77 ! nicm 275: } while (wp != active);
1.36 nicm 276: }
277:
1.77 ! nicm 278: active = wp = server_client_get_pane(c);
1.75 nicm 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);
1.77 ! nicm 299: } while (wp != 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.77 ! nicm 333: if (wp == server_client_get_pane(c))
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.76 nicm 349: screen_write_start(&ctx, &wp->status_screen);
1.59 nicm 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.76 nicm 426: tty_draw_line(tty, s, i, 0, width, x, yoff - ctx->oy,
427: &grid_default_cell, NULL);
1.36 nicm 428: }
429: tty_cursor(tty, 0, 0);
1.24 nicm 430: }
431:
1.38 nicm 432: /* Update status line and change flags if unchanged. */
1.54 nicm 433: static int
434: screen_redraw_update(struct client *c, int flags)
1.38 nicm 435: {
436: struct window *w = c->session->curw->window;
437: struct window_pane *wp;
438: struct options *wo = w->options;
439: int redraw;
440:
441: if (c->message_string != NULL)
442: redraw = status_message_redraw(c);
443: else if (c->prompt_string != NULL)
444: redraw = status_prompt_redraw(c);
445: else
446: redraw = status_redraw(c);
1.54 nicm 447: if (!redraw && (~flags & CLIENT_REDRAWSTATUSALWAYS))
448: flags &= ~CLIENT_REDRAWSTATUS;
1.38 nicm 449:
1.63 nicm 450: if (c->overlay_draw != NULL)
451: flags |= CLIENT_REDRAWOVERLAY;
452:
1.64 nicm 453: if (options_get_number(wo, "pane-border-status") != PANE_STATUS_OFF) {
1.38 nicm 454: redraw = 0;
455: TAILQ_FOREACH(wp, &w->panes, entry) {
456: if (screen_redraw_make_pane_status(c, w, wp))
457: redraw = 1;
458: }
459: if (redraw)
1.54 nicm 460: flags |= CLIENT_REDRAWBORDERS;
1.38 nicm 461: }
1.54 nicm 462: return (flags);
1.38 nicm 463: }
464:
1.52 nicm 465: /* Set up redraw context. */
466: static void
467: screen_redraw_set_context(struct client *c, struct screen_redraw_ctx *ctx)
468: {
1.53 nicm 469: struct session *s = c->session;
470: struct options *oo = s->options;
471: struct window *w = s->curw->window;
472: struct options *wo = w->options;
1.61 nicm 473: u_int lines;
1.52 nicm 474:
475: memset(ctx, 0, sizeof *ctx);
476: ctx->c = c;
477:
1.61 nicm 478: lines = status_line_size(c);
1.55 nicm 479: if (c->message_string != NULL || c->prompt_string != NULL)
1.61 nicm 480: lines = (lines == 0) ? 1 : lines;
481: if (lines != 0 && options_get_number(oo, "status-position") == 0)
482: ctx->statustop = 1;
483: ctx->statuslines = lines;
484:
1.52 nicm 485: ctx->pane_status = options_get_number(wo, "pane-border-status");
486:
1.55 nicm 487: tty_window_offset(&c->tty, &ctx->ox, &ctx->oy, &ctx->sx, &ctx->sy);
488:
489: log_debug("%s: %s @%u ox=%u oy=%u sx=%u sy=%u %u/%d", __func__, c->name,
1.61 nicm 490: w->id, ctx->ox, ctx->oy, ctx->sx, ctx->sy, ctx->statuslines,
491: ctx->statustop);
1.52 nicm 492: }
493:
1.4 nicm 494: /* Redraw entire screen. */
1.1 nicm 495: void
1.53 nicm 496: screen_redraw_screen(struct client *c)
1.1 nicm 497: {
1.53 nicm 498: struct screen_redraw_ctx ctx;
1.54 nicm 499: int flags;
1.18 nicm 500:
501: if (c->flags & CLIENT_SUSPENDED)
502: return;
1.1 nicm 503:
1.54 nicm 504: flags = screen_redraw_update(c, c->flags);
1.74 nicm 505: if ((flags & CLIENT_ALLREDRAWFLAGS) == 0)
506: return;
507:
1.52 nicm 508: screen_redraw_set_context(c, &ctx);
1.74 nicm 509: tty_update_mode(&c->tty, c->tty.mode, NULL);
1.67 nicm 510: tty_sync_start(&c->tty);
1.51 nicm 511:
1.54 nicm 512: if (flags & (CLIENT_REDRAWWINDOW|CLIENT_REDRAWBORDERS)) {
1.70 nicm 513: log_debug("%s: redrawing borders", c->name);
1.64 nicm 514: if (ctx.pane_status != PANE_STATUS_OFF)
1.53 nicm 515: screen_redraw_draw_pane_status(&ctx);
1.50 nicm 516: screen_redraw_draw_borders(&ctx);
1.53 nicm 517: }
1.70 nicm 518: if (flags & CLIENT_REDRAWWINDOW) {
519: log_debug("%s: redrawing panes", c->name);
1.50 nicm 520: screen_redraw_draw_panes(&ctx);
1.70 nicm 521: }
1.61 nicm 522: if (ctx.statuslines != 0 &&
1.70 nicm 523: (flags & (CLIENT_REDRAWSTATUS|CLIENT_REDRAWSTATUSALWAYS))) {
524: log_debug("%s: redrawing status", c->name);
1.50 nicm 525: screen_redraw_draw_status(&ctx);
1.70 nicm 526: }
527: if (c->overlay_draw != NULL && (flags & CLIENT_REDRAWOVERLAY)) {
528: log_debug("%s: redrawing overlay", c->name);
1.61 nicm 529: c->overlay_draw(c, &ctx);
1.70 nicm 530: }
1.67 nicm 531:
1.52 nicm 532: tty_reset(&c->tty);
1.26 nicm 533: }
1.4 nicm 534:
1.55 nicm 535: /* Redraw a single pane. */
1.26 nicm 536: void
537: screen_redraw_pane(struct client *c, struct window_pane *wp)
538: {
1.55 nicm 539: struct screen_redraw_ctx ctx;
1.26 nicm 540:
1.63 nicm 541: if (c->overlay_draw != NULL || !window_pane_visible(wp))
1.4 nicm 542: return;
1.1 nicm 543:
1.55 nicm 544: screen_redraw_set_context(c, &ctx);
1.74 nicm 545: tty_update_mode(&c->tty, c->tty.mode, NULL);
1.67 nicm 546: tty_sync_start(&c->tty);
1.26 nicm 547:
1.55 nicm 548: screen_redraw_draw_pane(&ctx, wp);
1.67 nicm 549:
1.26 nicm 550: tty_reset(&c->tty);
551: }
552:
1.75 nicm 553: /* Get border cell style. */
554: static const struct grid_cell *
555: screen_redraw_draw_borders_style(struct screen_redraw_ctx *ctx, u_int x,
556: u_int y, struct window_pane *wp)
557: {
558: struct client *c = ctx->c;
559: struct session *s = c->session;
560: struct window *w = s->curw->window;
1.77 ! nicm 561: struct window_pane *active = server_client_get_pane(c);
1.75 nicm 562: struct options *oo = w->options;
563: struct grid_cell *gc;
564: struct format_tree *ft;
565:
566: if (wp->border_gc_set)
567: return (&wp->border_gc);
568: wp->border_gc_set = 1;
569:
570: ft = format_create_defaults(NULL, c, s, s->curw, wp);
571: gc = &wp->border_gc;
572:
1.77 ! nicm 573: if (screen_redraw_check_is(x, y, ctx->pane_status, active)) {
1.75 nicm 574: style_apply(gc, oo, "pane-active-border-style", ft);
575: gc->attr |= GRID_ATTR_CHARSET;
576: } else {
577: style_apply(gc, oo, "pane-border-style", ft);
578: gc->attr |= GRID_ATTR_CHARSET;
579: }
580:
581: format_free(ft);
582: return (gc);
583: }
584:
1.50 nicm 585: /* Draw a border cell. */
586: static void
1.75 nicm 587: screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
1.50 nicm 588: {
1.53 nicm 589: struct client *c = ctx->c;
590: struct session *s = c->session;
591: struct tty *tty = &c->tty;
592: struct window_pane *wp;
1.55 nicm 593: u_int type, x = ctx->ox + i, y = ctx->oy + j;
1.75 nicm 594: int pane_status = ctx->pane_status;
595: const struct grid_cell *gc;
596: struct grid_cell copy;
1.50 nicm 597:
1.66 nicm 598: if (c->overlay_check != NULL && !c->overlay_check(c, x, y))
599: return;
1.75 nicm 600:
1.50 nicm 601: type = screen_redraw_check_cell(c, x, y, pane_status, &wp);
602: if (type == CELL_INSIDE)
603: return;
604:
1.75 nicm 605: if (wp == NULL)
606: gc = &screen_redraw_border_cell;
607: else {
608: gc = screen_redraw_draw_borders_style(ctx, x, y, wp);
609: if (gc == NULL)
610: return;
611:
612: if (server_is_marked(s, s->curw, marked_pane.wp) &&
613: screen_redraw_check_is(x, y, pane_status, marked_pane.wp)) {
614: memcpy(©, gc, sizeof copy);
615: copy.attr ^= GRID_ATTR_REVERSE;
616: gc = ©
617: }
618: }
619:
1.76 nicm 620: tty_attributes(tty, gc, &grid_default_cell, NULL);
1.61 nicm 621: if (ctx->statustop)
622: tty_cursor(tty, i, ctx->statuslines + j);
1.50 nicm 623: else
1.55 nicm 624: tty_cursor(tty, i, j);
1.50 nicm 625: tty_putc(tty, CELL_BORDERS[type]);
626: }
627:
1.26 nicm 628: /* Draw the borders. */
1.39 nicm 629: static void
1.50 nicm 630: screen_redraw_draw_borders(struct screen_redraw_ctx *ctx)
1.26 nicm 631: {
1.50 nicm 632: struct client *c = ctx->c;
1.32 nicm 633: struct session *s = c->session;
634: struct window *w = s->curw->window;
1.75 nicm 635: struct window_pane *wp;
1.55 nicm 636: u_int i, j;
637:
638: log_debug("%s: %s @%u", __func__, c->name, w->id);
1.26 nicm 639:
1.75 nicm 640: TAILQ_FOREACH(wp, &w->panes, entry)
641: wp->border_gc_set = 0;
642:
643: for (j = 0; j < c->tty.sy - ctx->statuslines; j++) {
644: for (i = 0; i < c->tty.sx; i++)
645: screen_redraw_draw_borders_cell(ctx, i, j);
1.28 nicm 646: }
1.26 nicm 647: }
1.1 nicm 648:
1.26 nicm 649: /* Draw the panes. */
1.39 nicm 650: static void
1.50 nicm 651: screen_redraw_draw_panes(struct screen_redraw_ctx *ctx)
1.26 nicm 652: {
1.50 nicm 653: struct client *c = ctx->c;
1.26 nicm 654: struct window *w = c->session->curw->window;
655: struct window_pane *wp;
1.47 nicm 656:
1.55 nicm 657: log_debug("%s: %s @%u", __func__, c->name, w->id);
658:
1.1 nicm 659: TAILQ_FOREACH(wp, &w->panes, entry) {
1.61 nicm 660: if (window_pane_visible(wp))
661: screen_redraw_draw_pane(ctx, wp);
1.1 nicm 662: }
663: }
664:
1.26 nicm 665: /* Draw the status line. */
1.39 nicm 666: static void
1.50 nicm 667: screen_redraw_draw_status(struct screen_redraw_ctx *ctx)
1.1 nicm 668: {
1.50 nicm 669: struct client *c = ctx->c;
1.55 nicm 670: struct window *w = c->session->curw->window;
1.26 nicm 671: struct tty *tty = &c->tty;
1.58 nicm 672: struct screen *s = c->status.active;
1.47 nicm 673: u_int i, y;
1.23 nicm 674:
1.55 nicm 675: log_debug("%s: %s @%u", __func__, c->name, w->id);
676:
1.61 nicm 677: if (ctx->statustop)
1.47 nicm 678: y = 0;
1.26 nicm 679: else
1.61 nicm 680: y = c->tty.sy - ctx->statuslines;
1.76 nicm 681: for (i = 0; i < ctx->statuslines; i++) {
682: tty_draw_line(tty, s, 0, i, UINT_MAX, 0, y + i,
683: &grid_default_cell, NULL);
684: }
1.55 nicm 685: }
686:
687: /* Draw one pane. */
688: static void
689: screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp)
690: {
691: struct client *c = ctx->c;
692: struct window *w = c->session->curw->window;
693: struct tty *tty = &c->tty;
694: struct screen *s;
1.76 nicm 695: struct grid_cell defaults;
1.55 nicm 696: u_int i, j, top, x, y, width;
697:
698: log_debug("%s: %s @%u %%%u", __func__, c->name, w->id, wp->id);
699:
700: if (wp->xoff + wp->sx <= ctx->ox || wp->xoff >= ctx->ox + ctx->sx)
701: return;
1.61 nicm 702: if (ctx->statustop)
703: top = ctx->statuslines;
1.55 nicm 704: else
705: top = 0;
706:
707: s = wp->screen;
708: for (j = 0; j < wp->sy; j++) {
709: if (wp->yoff + j < ctx->oy || wp->yoff + j >= ctx->oy + ctx->sy)
710: continue;
711: y = top + wp->yoff + j - ctx->oy;
712:
713: if (wp->xoff >= ctx->ox &&
714: wp->xoff + wp->sx <= ctx->ox + ctx->sx) {
715: /* All visible. */
716: i = 0;
717: x = wp->xoff - ctx->ox;
718: width = wp->sx;
719: } else if (wp->xoff < ctx->ox &&
720: wp->xoff + wp->sx > ctx->ox + ctx->sx) {
721: /* Both left and right not visible. */
722: i = ctx->ox;
723: x = 0;
724: width = ctx->sx;
725: } else if (wp->xoff < ctx->ox) {
726: /* Left not visible. */
727: i = ctx->ox - wp->xoff;
728: x = 0;
729: width = wp->sx - i;
730: } else {
731: /* Right not visible. */
732: i = 0;
733: x = wp->xoff - ctx->ox;
734: width = ctx->sx - x;
735: }
736: log_debug("%s: %s %%%u line %u,%u at %u,%u, width %u",
737: __func__, c->name, wp->id, i, j, x, y, width);
738:
1.76 nicm 739: tty_default_colours(&defaults, wp);
740: tty_draw_line(tty, s, i, j, width, x, y, &defaults,
741: wp->palette);
1.55 nicm 742: }
1.1 nicm 743: }