4 * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
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.
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.
19 #include <sys/types.h>
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
*);
29 static void screen_redraw_draw_pane(struct screen_redraw_ctx
*,
30 struct window_pane
*);
31 static void screen_redraw_set_context(struct client
*,
32 struct screen_redraw_ctx
*);
33 static void screen_redraw_draw_pane_scrollbars(struct screen_redraw_ctx
*);
34 static void screen_redraw_draw_scrollbar(struct screen_redraw_ctx
*,
35 struct window_pane
*, int, int, int, u_int
, u_int
, u_int
);
36 static void screen_redraw_draw_pane_scrollbar(struct screen_redraw_ctx
*,
37 struct window_pane
*);
39 #define START_ISOLATE "\342\201\246"
40 #define END_ISOLATE "\342\201\251"
42 /* Border in relation to a pane. */
43 enum screen_redraw_border_type
{
44 SCREEN_REDRAW_OUTSIDE
,
46 SCREEN_REDRAW_BORDER_LEFT
,
47 SCREEN_REDRAW_BORDER_RIGHT
,
48 SCREEN_REDRAW_BORDER_TOP
,
49 SCREEN_REDRAW_BORDER_BOTTOM
51 #define BORDER_MARKERS " +,.-"
53 /* Get cell border character. */
55 screen_redraw_border_set(struct window
*w
, struct window_pane
*wp
,
56 enum pane_lines pane_lines
, int cell_type
, struct grid_cell
*gc
)
60 if (cell_type
== CELL_OUTSIDE
&& w
->fill_character
!= NULL
) {
61 utf8_copy(&gc
->data
, &w
->fill_character
[0]);
66 case PANE_LINES_NUMBER
:
67 if (cell_type
== CELL_OUTSIDE
) {
68 gc
->attr
|= GRID_ATTR_CHARSET
;
69 utf8_set(&gc
->data
, CELL_BORDERS
[CELL_OUTSIDE
]);
72 gc
->attr
&= ~GRID_ATTR_CHARSET
;
73 if (wp
!= NULL
&& window_pane_index(wp
, &idx
) == 0)
74 utf8_set(&gc
->data
, '0' + (idx
% 10));
76 utf8_set(&gc
->data
, '*');
78 case PANE_LINES_DOUBLE
:
79 gc
->attr
&= ~GRID_ATTR_CHARSET
;
80 utf8_copy(&gc
->data
, tty_acs_double_borders(cell_type
));
82 case PANE_LINES_HEAVY
:
83 gc
->attr
&= ~GRID_ATTR_CHARSET
;
84 utf8_copy(&gc
->data
, tty_acs_heavy_borders(cell_type
));
86 case PANE_LINES_SIMPLE
:
87 gc
->attr
&= ~GRID_ATTR_CHARSET
;
88 utf8_set(&gc
->data
, SIMPLE_BORDERS
[cell_type
]);
91 gc
->attr
|= GRID_ATTR_CHARSET
;
92 utf8_set(&gc
->data
, CELL_BORDERS
[cell_type
]);
97 /* Return if window has only two panes. */
99 screen_redraw_two_panes(struct window
*w
, int direction
)
101 struct window_pane
*wp
;
103 wp
= TAILQ_NEXT(TAILQ_FIRST(&w
->panes
), entry
);
105 return (0); /* one pane */
106 if (TAILQ_NEXT(wp
, entry
) != NULL
)
107 return (0); /* more than two panes */
108 if (direction
== 0 && wp
->xoff
== 0)
110 if (direction
== 1 && wp
->yoff
== 0)
115 /* Check if cell is on the border of a pane. */
116 static enum screen_redraw_border_type
117 screen_redraw_pane_border(struct screen_redraw_ctx
*ctx
, struct window_pane
*wp
,
120 struct options
*oo
= wp
->window
->options
;
121 u_int ex
= wp
->xoff
+ wp
->sx
, ey
= wp
->yoff
+ wp
->sy
;
122 int hsplit
= 0, vsplit
= 0, pane_status
= ctx
->pane_status
;
123 int pane_scrollbars
= ctx
->pane_scrollbars
, sb_w
= 0;
124 int sb_pos
= ctx
->pane_scrollbars_pos
;
127 if (px
>= wp
->xoff
&& px
< ex
&& py
>= wp
->yoff
&& py
< ey
)
128 return (SCREEN_REDRAW_INSIDE
);
130 /* Get pane indicator. */
131 switch (options_get_number(oo
, "pane-border-indicators")) {
132 case PANE_BORDER_COLOUR
:
133 case PANE_BORDER_BOTH
:
134 hsplit
= screen_redraw_two_panes(wp
->window
, 0);
135 vsplit
= screen_redraw_two_panes(wp
->window
, 1);
139 /* Are scrollbars enabled? */
140 if (window_pane_show_scrollbar(wp
, pane_scrollbars
))
141 sb_w
= PANE_SCROLLBARS_WIDTH
;
144 * Left/right borders. The wp->sy / 2 test is to colour only half the
145 * active window's border when there are two panes.
147 if ((wp
->yoff
== 0 || py
>= wp
->yoff
- 1) && py
<= ey
) {
148 if (sb_pos
== PANE_SCROLLBARS_LEFT
) {
149 if (wp
->xoff
- sb_w
== 0 && px
== wp
->sx
+ sb_w
)
150 if (!hsplit
|| (hsplit
&& py
<= wp
->sy
/ 2))
151 return (SCREEN_REDRAW_BORDER_RIGHT
);
152 if (wp
->xoff
- sb_w
!= 0 && px
== wp
->xoff
- sb_w
- 1)
153 if (!hsplit
|| (hsplit
&& py
> wp
->sy
/ 2))
154 return (SCREEN_REDRAW_BORDER_LEFT
);
155 } else { /* sb_pos == PANE_SCROLLBARS_RIGHT */
156 if (wp
->xoff
== 0 && px
== wp
->sx
+ sb_w
)
157 if (!hsplit
|| (hsplit
&& py
<= wp
->sy
/ 2))
158 return (SCREEN_REDRAW_BORDER_RIGHT
);
159 if (wp
->xoff
!= 0 && px
== wp
->xoff
- 1)
160 if (!hsplit
|| (hsplit
&& py
> wp
->sy
/ 2))
161 return (SCREEN_REDRAW_BORDER_LEFT
);
165 /* Top/bottom borders. */
166 if (vsplit
&& pane_status
== PANE_STATUS_OFF
&& sb_w
== 0) {
167 if (wp
->yoff
== 0 && py
== wp
->sy
&& px
<= wp
->sx
/ 2)
168 return (SCREEN_REDRAW_BORDER_BOTTOM
);
169 if (wp
->yoff
!= 0 && py
== wp
->yoff
- 1 && px
> wp
->sx
/ 2)
170 return (SCREEN_REDRAW_BORDER_TOP
);
172 if (sb_pos
== PANE_SCROLLBARS_LEFT
) {
173 if ((wp
->xoff
- sb_w
== 0 || px
>= wp
->xoff
- sb_w
) &&
174 (px
<= ex
|| (sb_w
!= 0 && px
- 1 == ex
))) {
175 if (wp
->yoff
!= 0 && py
== wp
->yoff
- 1)
176 return (SCREEN_REDRAW_BORDER_TOP
);
178 return (SCREEN_REDRAW_BORDER_BOTTOM
);
180 } else { /* sb_pos == PANE_SCROLLBARS_RIGHT */
181 if ((wp
->xoff
== 0 || px
>= wp
->xoff
) &&
182 (px
<= ex
|| (sb_w
!= 0 && px
- 1 == ex
))) {
183 if (wp
->yoff
!= 0 && py
== wp
->yoff
- 1)
184 return (SCREEN_REDRAW_BORDER_TOP
);
186 return (SCREEN_REDRAW_BORDER_BOTTOM
);
192 return (SCREEN_REDRAW_OUTSIDE
);
195 /* Check if a cell is on a border. */
197 screen_redraw_cell_border(struct screen_redraw_ctx
*ctx
, u_int px
, u_int py
)
199 struct client
*c
= ctx
->c
;
200 struct window
*w
= c
->session
->curw
->window
;
201 struct window_pane
*wp
;
204 if (ctx
->pane_status
== PANE_STATUS_BOTTOM
)
207 /* Outside the window? */
208 if (px
> w
->sx
|| py
> sy
)
211 /* On the window border? */
212 if (px
== w
->sx
|| py
== sy
)
215 /* Check all the panes. */
216 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
217 if (!window_pane_visible(wp
))
219 switch (screen_redraw_pane_border(ctx
, wp
, px
, py
)) {
220 case SCREEN_REDRAW_INSIDE
:
222 case SCREEN_REDRAW_OUTSIDE
:
232 /* Work out type of border cell from surrounding cells. */
234 screen_redraw_type_of_cell(struct screen_redraw_ctx
*ctx
, u_int px
, u_int py
)
236 struct client
*c
= ctx
->c
;
237 int pane_status
= ctx
->pane_status
;
238 struct window
*w
= c
->session
->curw
->window
;
239 u_int sx
= w
->sx
, sy
= w
->sy
;
242 if (pane_status
== PANE_STATUS_BOTTOM
)
245 /* Is this outside the window? */
246 if (px
> sx
|| py
> sy
)
247 return (CELL_OUTSIDE
);
250 * Construct a bitmask of whether the cells to the left (bit 8), right,
251 * top, and bottom (bit 1) of this cell are borders.
257 if (px
== 0 || screen_redraw_cell_border(ctx
, px
- 1, py
))
259 if (px
<= sx
&& screen_redraw_cell_border(ctx
, px
+ 1, py
))
261 if (pane_status
== PANE_STATUS_TOP
) {
263 screen_redraw_cell_border(ctx
, px
, py
- 1))
265 if (screen_redraw_cell_border(ctx
, px
, py
+ 1))
267 } else if (pane_status
== PANE_STATUS_BOTTOM
) {
269 screen_redraw_cell_border(ctx
, px
, py
- 1))
272 screen_redraw_cell_border(ctx
, px
, py
+ 1))
276 screen_redraw_cell_border(ctx
, px
, py
- 1))
278 if (screen_redraw_cell_border(ctx
, px
, py
+ 1))
283 * Figure out what kind of border this cell is. Only one bit set
284 * doesn't make sense (can't have a border cell with no others
288 case 15: /* 1111, left right top bottom */
290 case 14: /* 1110, left right top */
291 return (CELL_BOTTOMJOIN
);
292 case 13: /* 1101, left right bottom */
293 return (CELL_TOPJOIN
);
294 case 12: /* 1100, left right */
295 return (CELL_LEFTRIGHT
);
296 case 11: /* 1011, left top bottom */
297 return (CELL_RIGHTJOIN
);
298 case 10: /* 1010, left top */
299 return (CELL_BOTTOMRIGHT
);
300 case 9: /* 1001, left bottom */
301 return (CELL_TOPRIGHT
);
302 case 7: /* 0111, right top bottom */
303 return (CELL_LEFTJOIN
);
304 case 6: /* 0110, right top */
305 return (CELL_BOTTOMLEFT
);
306 case 5: /* 0101, right bottom */
307 return (CELL_TOPLEFT
);
308 case 3: /* 0011, top bottom */
309 return (CELL_TOPBOTTOM
);
311 return (CELL_OUTSIDE
);
314 /* Check if cell inside a pane. */
316 screen_redraw_check_cell(struct screen_redraw_ctx
*ctx
, u_int px
, u_int py
,
317 struct window_pane
**wpp
)
319 struct client
*c
= ctx
->c
;
320 struct window
*w
= c
->session
->curw
->window
;
321 struct window_pane
*wp
, *active
;
322 int pane_status
= ctx
->pane_status
;
323 u_int sx
= w
->sx
, sy
= w
->sy
;
324 int border
, pane_scrollbars
= ctx
->pane_scrollbars
;
326 int sb_pos
= ctx
->pane_scrollbars_pos
;
327 int sb_w
= PANE_SCROLLBARS_WIDTH
;
331 if (px
> sx
|| py
> sy
)
332 return (CELL_OUTSIDE
);
333 if (px
== sx
|| py
== sy
) /* window border */
334 return (screen_redraw_type_of_cell(ctx
, px
, py
));
336 if (pane_status
!= PANE_STATUS_OFF
) {
337 active
= wp
= server_client_get_pane(c
);
339 if (!window_pane_visible(wp
))
342 if (pane_status
== PANE_STATUS_TOP
)
345 line
= wp
->yoff
+ sy
;
346 right
= wp
->xoff
+ 2 + wp
->status_size
- 1;
348 if (py
== line
&& px
>= wp
->xoff
+ 2 && px
<= right
)
349 return (CELL_INSIDE
);
352 wp
= TAILQ_NEXT(wp
, entry
);
354 wp
= TAILQ_FIRST(&w
->panes
);
355 } while (wp
!= active
);
358 active
= wp
= server_client_get_pane(c
);
360 if (!window_pane_visible(wp
))
364 /* Check if CELL_SCROLLBAR */
365 if (window_pane_show_scrollbar(wp
, pane_scrollbars
)) {
367 if (pane_status
== PANE_STATUS_TOP
)
370 line
= wp
->yoff
+ wp
->sy
;
373 * Check if py could lie within a scrollbar. If the
374 * pane is at the top then py == 0 to sy; if the pane
375 * is not at the top, then yoff to yoff + sy.
377 if ((pane_status
&& py
!= line
) ||
378 (wp
->yoff
== 0 && py
< wp
->sy
) ||
379 (py
>= wp
->yoff
&& py
< wp
->yoff
+ wp
->sy
)) {
380 /* Check if px lies within a scrollbar. */
381 if ((sb_pos
== PANE_SCROLLBARS_RIGHT
&&
382 (px
>= wp
->xoff
+ wp
->sx
&&
383 px
< wp
->xoff
+ wp
->sx
+ sb_w
)) ||
384 (sb_pos
== PANE_SCROLLBARS_LEFT
&&
385 (px
>= wp
->xoff
- sb_w
&&
387 return (CELL_SCROLLBAR
);
392 * If definitely inside, return. If not on border, skip.
393 * Otherwise work out the cell.
395 border
= screen_redraw_pane_border(ctx
, wp
, px
, py
);
396 if (border
== SCREEN_REDRAW_INSIDE
)
397 return (CELL_INSIDE
);
398 if (border
== SCREEN_REDRAW_OUTSIDE
)
400 return (screen_redraw_type_of_cell(ctx
, px
, py
));
403 wp
= TAILQ_NEXT(wp
, entry
);
405 wp
= TAILQ_FIRST(&w
->panes
);
406 } while (wp
!= active
);
408 return (CELL_OUTSIDE
);
411 /* Check if the border of a particular pane. */
413 screen_redraw_check_is(struct screen_redraw_ctx
*ctx
, u_int px
, u_int py
,
414 struct window_pane
*wp
)
416 enum screen_redraw_border_type border
;
418 border
= screen_redraw_pane_border(ctx
, wp
, px
, py
);
419 if (border
!= SCREEN_REDRAW_INSIDE
&& border
!= SCREEN_REDRAW_OUTSIDE
)
424 /* Update pane status. */
426 screen_redraw_make_pane_status(struct client
*c
, struct window_pane
*wp
,
427 struct screen_redraw_ctx
*rctx
, enum pane_lines pane_lines
)
429 struct window
*w
= wp
->window
;
432 struct format_tree
*ft
;
434 int pane_status
= rctx
->pane_status
;
435 u_int width
, i
, cell_type
, px
, py
;
436 struct screen_write_ctx ctx
;
439 ft
= format_create(c
, NULL
, FORMAT_PANE
|wp
->id
, FORMAT_STATUS
);
440 format_defaults(ft
, c
, c
->session
, c
->session
->curw
, wp
);
442 if (wp
== server_client_get_pane(c
))
443 style_apply(&gc
, w
->options
, "pane-active-border-style", ft
);
445 style_apply(&gc
, w
->options
, "pane-border-style", ft
);
446 fmt
= options_get_string(wp
->options
, "pane-border-format");
448 expanded
= format_expand_time(ft
, fmt
);
450 wp
->status_size
= width
= 0;
452 wp
->status_size
= width
= wp
->sx
- 4;
454 memcpy(&old
, &wp
->status_screen
, sizeof old
);
455 screen_init(&wp
->status_screen
, width
, 1, 0);
456 wp
->status_screen
.mode
= 0;
458 screen_write_start(&ctx
, &wp
->status_screen
);
460 for (i
= 0; i
< width
; i
++) {
461 px
= wp
->xoff
+ 2 + i
;
462 if (pane_status
== PANE_STATUS_TOP
)
465 py
= wp
->yoff
+ wp
->sy
;
466 cell_type
= screen_redraw_type_of_cell(rctx
, px
, py
);
467 screen_redraw_border_set(w
, wp
, pane_lines
, cell_type
, &gc
);
468 screen_write_cell(&ctx
, &gc
);
470 gc
.attr
&= ~GRID_ATTR_CHARSET
;
472 screen_write_cursormove(&ctx
, 0, 0, 0);
473 format_draw(&ctx
, &gc
, width
, expanded
, NULL
, 0);
474 screen_write_stop(&ctx
);
479 if (grid_compare(wp
->status_screen
.grid
, old
.grid
) == 0) {
487 /* Draw pane status. */
489 screen_redraw_draw_pane_status(struct screen_redraw_ctx
*ctx
)
491 struct client
*c
= ctx
->c
;
492 struct window
*w
= c
->session
->curw
->window
;
493 struct tty
*tty
= &c
->tty
;
494 struct window_pane
*wp
;
496 u_int i
, x
, width
, xoff
, yoff
, size
;
498 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
500 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
501 if (!window_pane_visible(wp
))
503 s
= &wp
->status_screen
;
505 size
= wp
->status_size
;
506 if (ctx
->pane_status
== PANE_STATUS_TOP
)
509 yoff
= wp
->yoff
+ wp
->sy
;
512 if (xoff
+ size
<= ctx
->ox
||
513 xoff
>= ctx
->ox
+ ctx
->sx
||
515 yoff
>= ctx
->oy
+ ctx
->sy
)
518 if (xoff
>= ctx
->ox
&& xoff
+ size
<= ctx
->ox
+ ctx
->sx
) {
523 } else if (xoff
< ctx
->ox
&& xoff
+ size
> ctx
->ox
+ ctx
->sx
) {
524 /* Both left and right not visible. */
528 } else if (xoff
< ctx
->ox
) {
529 /* Left not visible. */
534 /* Right not visible. */
541 yoff
+= ctx
->statuslines
;
542 tty_draw_line(tty
, s
, i
, 0, width
, x
, yoff
- ctx
->oy
,
543 &grid_default_cell
, NULL
);
545 tty_cursor(tty
, 0, 0);
548 /* Update status line and change flags if unchanged. */
550 screen_redraw_update(struct screen_redraw_ctx
*ctx
, uint64_t flags
)
552 struct client
*c
= ctx
->c
;
553 struct window
*w
= c
->session
->curw
->window
;
554 struct window_pane
*wp
;
556 enum pane_lines lines
;
558 if (c
->message_string
!= NULL
)
559 redraw
= status_message_redraw(c
);
560 else if (c
->prompt_string
!= NULL
)
561 redraw
= status_prompt_redraw(c
);
563 redraw
= status_redraw(c
);
564 if (!redraw
&& (~flags
& CLIENT_REDRAWSTATUSALWAYS
))
565 flags
&= ~CLIENT_REDRAWSTATUS
;
567 if (c
->overlay_draw
!= NULL
)
568 flags
|= CLIENT_REDRAWOVERLAY
;
570 if (ctx
->pane_status
!= PANE_STATUS_OFF
) {
571 lines
= ctx
->pane_lines
;
573 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
574 if (screen_redraw_make_pane_status(c
, wp
, ctx
, lines
))
578 flags
|= CLIENT_REDRAWBORDERS
;
584 /* Set up redraw context. */
586 screen_redraw_set_context(struct client
*c
, struct screen_redraw_ctx
*ctx
)
588 struct session
*s
= c
->session
;
589 struct options
*oo
= s
->options
;
590 struct window
*w
= s
->curw
->window
;
591 struct options
*wo
= w
->options
;
594 memset(ctx
, 0, sizeof *ctx
);
597 lines
= status_line_size(c
);
598 if (c
->message_string
!= NULL
|| c
->prompt_string
!= NULL
)
599 lines
= (lines
== 0) ? 1 : lines
;
600 if (lines
!= 0 && options_get_number(oo
, "status-position") == 0)
602 ctx
->statuslines
= lines
;
604 ctx
->pane_status
= options_get_number(wo
, "pane-border-status");
605 ctx
->pane_lines
= options_get_number(wo
, "pane-border-lines");
607 ctx
->pane_scrollbars
= options_get_number(wo
, "pane-scrollbars");
608 ctx
->pane_scrollbars_pos
= options_get_number(wo
,
609 "pane-scrollbars-position");
611 tty_window_offset(&c
->tty
, &ctx
->ox
, &ctx
->oy
, &ctx
->sx
, &ctx
->sy
);
613 log_debug("%s: %s @%u ox=%u oy=%u sx=%u sy=%u %u/%d", __func__
, c
->name
,
614 w
->id
, ctx
->ox
, ctx
->oy
, ctx
->sx
, ctx
->sy
, ctx
->statuslines
,
618 /* Redraw entire screen. */
620 screen_redraw_screen(struct client
*c
)
622 struct screen_redraw_ctx ctx
;
625 if (c
->flags
& CLIENT_SUSPENDED
)
628 screen_redraw_set_context(c
, &ctx
);
630 flags
= screen_redraw_update(&ctx
, c
->flags
);
631 if ((flags
& CLIENT_ALLREDRAWFLAGS
) == 0)
634 tty_sync_start(&c
->tty
);
635 tty_update_mode(&c
->tty
, c
->tty
.mode
, NULL
);
637 if (flags
& (CLIENT_REDRAWWINDOW
|CLIENT_REDRAWBORDERS
)) {
638 log_debug("%s: redrawing borders", c
->name
);
639 screen_redraw_draw_borders(&ctx
);
640 if (ctx
.pane_status
!= PANE_STATUS_OFF
)
641 screen_redraw_draw_pane_status(&ctx
);
642 screen_redraw_draw_pane_scrollbars(&ctx
);
644 if (flags
& CLIENT_REDRAWWINDOW
) {
645 log_debug("%s: redrawing panes", c
->name
);
646 screen_redraw_draw_panes(&ctx
);
647 screen_redraw_draw_pane_scrollbars(&ctx
);
649 if (ctx
.statuslines
!= 0 &&
650 (flags
& (CLIENT_REDRAWSTATUS
|CLIENT_REDRAWSTATUSALWAYS
))) {
651 log_debug("%s: redrawing status", c
->name
);
652 screen_redraw_draw_status(&ctx
);
654 if (c
->overlay_draw
!= NULL
&& (flags
& CLIENT_REDRAWOVERLAY
)) {
655 log_debug("%s: redrawing overlay", c
->name
);
656 c
->overlay_draw(c
, c
->overlay_data
, &ctx
);
662 /* Redraw a single pane and its scrollbar. */
664 screen_redraw_pane(struct client
*c
, struct window_pane
*wp
,
665 int redraw_scrollbar_only
)
667 struct screen_redraw_ctx ctx
;
669 if (!window_pane_visible(wp
))
672 screen_redraw_set_context(c
, &ctx
);
673 tty_sync_start(&c
->tty
);
674 tty_update_mode(&c
->tty
, c
->tty
.mode
, NULL
);
676 if (!redraw_scrollbar_only
)
677 screen_redraw_draw_pane(&ctx
, wp
);
679 if (window_pane_show_scrollbar(wp
, ctx
.pane_scrollbars
))
680 screen_redraw_draw_pane_scrollbar(&ctx
, wp
);
685 /* Get border cell style. */
686 static const struct grid_cell
*
687 screen_redraw_draw_borders_style(struct screen_redraw_ctx
*ctx
, u_int x
,
688 u_int y
, struct window_pane
*wp
)
690 struct client
*c
= ctx
->c
;
691 struct session
*s
= c
->session
;
692 struct window
*w
= s
->curw
->window
;
693 struct window_pane
*active
= server_client_get_pane(c
);
694 struct options
*oo
= w
->options
;
695 struct format_tree
*ft
;
697 if (wp
->border_gc_set
)
698 return (&wp
->border_gc
);
699 wp
->border_gc_set
= 1;
701 ft
= format_create_defaults(NULL
, c
, s
, s
->curw
, wp
);
702 if (screen_redraw_check_is(ctx
, x
, y
, active
))
703 style_apply(&wp
->border_gc
, oo
, "pane-active-border-style", ft
);
705 style_apply(&wp
->border_gc
, oo
, "pane-border-style", ft
);
708 return (&wp
->border_gc
);
711 /* Draw a border cell. */
713 screen_redraw_draw_borders_cell(struct screen_redraw_ctx
*ctx
, u_int i
, u_int j
)
715 struct client
*c
= ctx
->c
;
716 struct session
*s
= c
->session
;
717 struct window
*w
= s
->curw
->window
;
718 struct options
*oo
= w
->options
;
719 struct tty
*tty
= &c
->tty
;
720 struct format_tree
*ft
;
721 struct window_pane
*wp
, *active
= server_client_get_pane(c
);
723 const struct grid_cell
*tmp
;
724 struct overlay_ranges r
;
725 u_int cell_type
, x
= ctx
->ox
+ i
, y
= ctx
->oy
+ j
;
726 int arrows
= 0, border
, isolates
;
728 if (c
->overlay_check
!= NULL
) {
729 c
->overlay_check(c
, c
->overlay_data
, x
, y
, 1, &r
);
730 if (r
.nx
[0] + r
.nx
[1] == 0)
734 cell_type
= screen_redraw_check_cell(ctx
, x
, y
, &wp
);
735 if (cell_type
== CELL_INSIDE
|| cell_type
== CELL_SCROLLBAR
)
739 if (!ctx
->no_pane_gc_set
) {
740 ft
= format_create_defaults(NULL
, c
, s
, s
->curw
, NULL
);
741 memcpy(&ctx
->no_pane_gc
, &grid_default_cell
, sizeof gc
);
742 style_add(&ctx
->no_pane_gc
, oo
, "pane-border-style",
745 ctx
->no_pane_gc_set
= 1;
747 memcpy(&gc
, &ctx
->no_pane_gc
, sizeof gc
);
749 tmp
= screen_redraw_draw_borders_style(ctx
, x
, y
, wp
);
752 memcpy(&gc
, tmp
, sizeof gc
);
754 if (server_is_marked(s
, s
->curw
, marked_pane
.wp
) &&
755 screen_redraw_check_is(ctx
, x
, y
, marked_pane
.wp
))
756 gc
.attr
^= GRID_ATTR_REVERSE
;
758 screen_redraw_border_set(w
, wp
, ctx
->pane_lines
, cell_type
, &gc
);
760 if (cell_type
== CELL_TOPBOTTOM
&&
761 (c
->flags
& CLIENT_UTF8
) &&
762 tty_term_has(tty
->term
, TTYC_BIDI
))
768 tty_cursor(tty
, i
, ctx
->statuslines
+ j
);
770 tty_cursor(tty
, i
, j
);
772 tty_puts(tty
, END_ISOLATE
);
774 switch (options_get_number(oo
, "pane-border-indicators")) {
775 case PANE_BORDER_ARROWS
:
776 case PANE_BORDER_BOTH
:
781 if (wp
!= NULL
&& arrows
) {
782 border
= screen_redraw_pane_border(ctx
, active
, x
, y
);
783 if (((i
== wp
->xoff
+ 1 &&
784 (cell_type
== CELL_LEFTRIGHT
||
785 (cell_type
== CELL_TOPJOIN
&&
786 border
== SCREEN_REDRAW_BORDER_BOTTOM
) ||
787 (cell_type
== CELL_BOTTOMJOIN
&&
788 border
== SCREEN_REDRAW_BORDER_TOP
))) ||
789 (j
== wp
->yoff
+ 1 &&
790 (cell_type
== CELL_TOPBOTTOM
||
791 (cell_type
== CELL_LEFTJOIN
&&
792 border
== SCREEN_REDRAW_BORDER_RIGHT
) ||
793 (cell_type
== CELL_RIGHTJOIN
&&
794 border
== SCREEN_REDRAW_BORDER_LEFT
)))) &&
795 screen_redraw_check_is(ctx
, x
, y
, active
)) {
796 gc
.attr
|= GRID_ATTR_CHARSET
;
797 utf8_set(&gc
.data
, BORDER_MARKERS
[border
]);
801 tty_cell(tty
, &gc
, &grid_default_cell
, NULL
, NULL
);
803 tty_puts(tty
, START_ISOLATE
);
806 /* Draw the borders. */
808 screen_redraw_draw_borders(struct screen_redraw_ctx
*ctx
)
810 struct client
*c
= ctx
->c
;
811 struct session
*s
= c
->session
;
812 struct window
*w
= s
->curw
->window
;
813 struct window_pane
*wp
;
816 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
818 TAILQ_FOREACH(wp
, &w
->panes
, entry
)
819 wp
->border_gc_set
= 0;
821 for (j
= 0; j
< c
->tty
.sy
- ctx
->statuslines
; j
++) {
822 for (i
= 0; i
< c
->tty
.sx
; i
++)
823 screen_redraw_draw_borders_cell(ctx
, i
, j
);
827 /* Draw the panes. */
829 screen_redraw_draw_panes(struct screen_redraw_ctx
*ctx
)
831 struct client
*c
= ctx
->c
;
832 struct window
*w
= c
->session
->curw
->window
;
833 struct window_pane
*wp
;
835 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
837 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
838 if (window_pane_visible(wp
))
839 screen_redraw_draw_pane(ctx
, wp
);
843 /* Draw the status line. */
845 screen_redraw_draw_status(struct screen_redraw_ctx
*ctx
)
847 struct client
*c
= ctx
->c
;
848 struct window
*w
= c
->session
->curw
->window
;
849 struct tty
*tty
= &c
->tty
;
850 struct screen
*s
= c
->status
.active
;
853 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
858 y
= c
->tty
.sy
- ctx
->statuslines
;
859 for (i
= 0; i
< ctx
->statuslines
; i
++) {
860 tty_draw_line(tty
, s
, 0, i
, UINT_MAX
, 0, y
+ i
,
861 &grid_default_cell
, NULL
);
867 screen_redraw_draw_pane(struct screen_redraw_ctx
*ctx
, struct window_pane
*wp
)
869 struct client
*c
= ctx
->c
;
870 struct window
*w
= c
->session
->curw
->window
;
871 struct tty
*tty
= &c
->tty
;
872 struct screen
*s
= wp
->screen
;
873 struct colour_palette
*palette
= &wp
->palette
;
874 struct grid_cell defaults
;
875 u_int i
, j
, top
, x
, y
, width
;
877 log_debug("%s: %s @%u %%%u", __func__
, c
->name
, w
->id
, wp
->id
);
879 if (wp
->xoff
+ wp
->sx
<= ctx
->ox
|| wp
->xoff
>= ctx
->ox
+ ctx
->sx
)
882 top
= ctx
->statuslines
;
885 for (j
= 0; j
< wp
->sy
; j
++) {
886 if (wp
->yoff
+ j
< ctx
->oy
|| wp
->yoff
+ j
>= ctx
->oy
+ ctx
->sy
)
888 y
= top
+ wp
->yoff
+ j
- ctx
->oy
;
890 if (wp
->xoff
>= ctx
->ox
&&
891 wp
->xoff
+ wp
->sx
<= ctx
->ox
+ ctx
->sx
) {
894 x
= wp
->xoff
- ctx
->ox
;
896 } else if (wp
->xoff
< ctx
->ox
&&
897 wp
->xoff
+ wp
->sx
> ctx
->ox
+ ctx
->sx
) {
898 /* Both left and right not visible. */
902 } else if (wp
->xoff
< ctx
->ox
) {
903 /* Left not visible. */
904 i
= ctx
->ox
- wp
->xoff
;
908 /* Right not visible. */
910 x
= wp
->xoff
- ctx
->ox
;
913 log_debug("%s: %s %%%u line %u,%u at %u,%u, width %u",
914 __func__
, c
->name
, wp
->id
, i
, j
, x
, y
, width
);
916 tty_default_colours(&defaults
, wp
);
917 tty_draw_line(tty
, s
, i
, j
, width
, x
, y
, &defaults
, palette
);
921 tty_draw_images(c
, wp
, s
);
925 /* Draw the panes scrollbars */
927 screen_redraw_draw_pane_scrollbars(struct screen_redraw_ctx
*ctx
)
929 struct client
*c
= ctx
->c
;
930 struct window
*w
= c
->session
->curw
->window
;
931 struct window_pane
*wp
;
933 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
935 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
936 if (window_pane_show_scrollbar(wp
, ctx
->pane_scrollbars
) &&
937 window_pane_visible(wp
))
938 screen_redraw_draw_pane_scrollbar(ctx
, wp
);
942 /* Draw pane scrollbar. */
944 screen_redraw_draw_pane_scrollbar(struct screen_redraw_ctx
*ctx
,
945 struct window_pane
*wp
)
947 struct screen
*s
= wp
->screen
;
949 u_int sb
= ctx
->pane_scrollbars
, total_height
, sb_h
= wp
->sy
;
950 u_int sb_pos
= ctx
->pane_scrollbars_pos
, slider_h
, slider_y
;
951 u_int sb_w
= PANE_SCROLLBARS_WIDTH
, cm_y
, cm_size
;
952 int sb_x
, sb_y
= (int)(wp
->yoff
- ctx
->oy
); /* sb top */
954 if (window_pane_mode(wp
) == WINDOW_PANE_NO_MODE
) {
955 if (sb
== PANE_SCROLLBARS_MODAL
)
957 /* Show slider at the bottom of the scrollbar. */
958 total_height
= screen_size_y(s
) + screen_hsize(s
);
959 percent_view
= (double)sb_h
/ total_height
;
960 slider_h
= (double)sb_h
* percent_view
;
961 slider_y
= sb_h
- slider_h
;
963 if (TAILQ_FIRST(&wp
->modes
) == NULL
)
965 if (window_copy_get_current_offset(wp
, &cm_y
, &cm_size
) == 0)
967 total_height
= cm_size
+ sb_h
;
968 percent_view
= (double)sb_h
/ (cm_size
+ sb_h
);
969 slider_h
= (double)sb_h
* percent_view
;
970 slider_y
= (sb_h
+ 1) * ((double)cm_y
/ total_height
);
973 if (sb_pos
== PANE_SCROLLBARS_LEFT
)
974 sb_x
= (int)wp
->xoff
- sb_w
- ctx
->ox
;
976 sb_x
= (int)wp
->xoff
+ wp
->sx
- ctx
->ox
;
980 if (slider_y
>= sb_h
)
983 screen_redraw_draw_scrollbar(ctx
, wp
, sb_pos
, sb_x
, sb_y
, sb_h
,
986 /* Store current position and height of the slider */
987 wp
->sb_slider_y
= slider_y
; /* top of slider y pos in scrollbar */
988 wp
->sb_slider_h
= slider_h
; /* height of slider */
992 screen_redraw_draw_scrollbar(struct screen_redraw_ctx
*ctx
,
993 struct window_pane
*wp
, int sb_pos
, int sb_x
, int sb_y
, u_int sb_h
,
994 u_int slider_h
, u_int slider_y
)
996 struct client
*c
= ctx
->c
;
997 struct window
*w
= wp
->window
;
998 struct tty
*tty
= &c
->tty
;
999 struct grid_cell gc
, slgc
, *gcp
;
1000 u_int i
, j
, sb_w
= PANE_SCROLLBARS_WIDTH
;
1002 int px
, py
, ox
= ctx
->ox
, oy
= ctx
->oy
;
1003 int sb_pad
= PANE_SCROLLBARS_PADDING
, sx
= ctx
->sx
;
1004 int sy
= ctx
->sy
, xoff
= wp
->xoff
, yoff
= wp
->yoff
;
1006 /* Set up default style. */
1007 style_apply(&gc
, w
->options
, "pane-scrollbars-style", NULL
);
1008 utf8_set(&gc
.data
, ' ');
1010 /* Set up style for slider. */
1011 memcpy(&slgc
, &gc
, sizeof slgc
);
1015 if (sb_pos
== PANE_SCROLLBARS_RIGHT
)
1021 for (i
= 0; i
< sb_w
; i
++) {
1022 for (j
= 0; j
< sb_h
; j
++) {
1025 if (px
< xoff
- ox
- 1 || px
>= sx
|| px
< 0 ||
1026 py
< yoff
- oy
- 1 || py
>= sy
|| py
< 0)
1028 tty_cursor(tty
, px
, py
);
1029 if (sb_pad
&& i
== pad_col
) {
1030 tty_cell(tty
, &grid_default_cell
,
1031 &grid_default_cell
, NULL
, NULL
);
1033 if (j
>= slider_y
&& j
< slider_y
+ slider_h
)
1037 tty_cell(tty
, gcp
, &grid_default_cell
, NULL
,