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