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