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
= wp
->scrollbar_style
.width
+ wp
->scrollbar_style
.pad
;
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
< ex
+ sb_w
))) {
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
< ex
+ sb_w
))) {
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
;
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 sb_w
= wp
->scrollbar_style
.width
+
378 wp
->scrollbar_style
.pad
;
379 if ((pane_status
&& py
!= line
) ||
380 (wp
->yoff
== 0 && py
< wp
->sy
) ||
381 (py
>= wp
->yoff
&& py
< wp
->yoff
+ wp
->sy
)) {
382 /* Check if px lies within a scrollbar. */
383 if ((sb_pos
== PANE_SCROLLBARS_RIGHT
&&
384 (px
>= wp
->xoff
+ wp
->sx
&&
385 px
< wp
->xoff
+ wp
->sx
+ sb_w
)) ||
386 (sb_pos
== PANE_SCROLLBARS_LEFT
&&
387 (px
>= wp
->xoff
- sb_w
&&
389 return (CELL_SCROLLBAR
);
394 * If definitely inside, return. If not on border, skip.
395 * Otherwise work out the cell.
397 border
= screen_redraw_pane_border(ctx
, wp
, px
, py
);
398 if (border
== SCREEN_REDRAW_INSIDE
)
399 return (CELL_INSIDE
);
400 if (border
== SCREEN_REDRAW_OUTSIDE
)
402 return (screen_redraw_type_of_cell(ctx
, px
, py
));
405 wp
= TAILQ_NEXT(wp
, entry
);
407 wp
= TAILQ_FIRST(&w
->panes
);
408 } while (wp
!= active
);
410 return (CELL_OUTSIDE
);
413 /* Check if the border of a particular pane. */
415 screen_redraw_check_is(struct screen_redraw_ctx
*ctx
, u_int px
, u_int py
,
416 struct window_pane
*wp
)
418 enum screen_redraw_border_type border
;
420 border
= screen_redraw_pane_border(ctx
, wp
, px
, py
);
421 if (border
!= SCREEN_REDRAW_INSIDE
&& border
!= SCREEN_REDRAW_OUTSIDE
)
426 /* Update pane status. */
428 screen_redraw_make_pane_status(struct client
*c
, struct window_pane
*wp
,
429 struct screen_redraw_ctx
*rctx
, enum pane_lines pane_lines
)
431 struct window
*w
= wp
->window
;
434 struct format_tree
*ft
;
436 int pane_status
= rctx
->pane_status
;
437 u_int width
, i
, cell_type
, px
, py
;
438 struct screen_write_ctx ctx
;
441 ft
= format_create(c
, NULL
, FORMAT_PANE
|wp
->id
, FORMAT_STATUS
);
442 format_defaults(ft
, c
, c
->session
, c
->session
->curw
, wp
);
444 if (wp
== server_client_get_pane(c
))
445 style_apply(&gc
, w
->options
, "pane-active-border-style", ft
);
447 style_apply(&gc
, w
->options
, "pane-border-style", ft
);
448 fmt
= options_get_string(wp
->options
, "pane-border-format");
450 expanded
= format_expand_time(ft
, fmt
);
452 wp
->status_size
= width
= 0;
454 wp
->status_size
= width
= wp
->sx
- 4;
456 memcpy(&old
, &wp
->status_screen
, sizeof old
);
457 screen_init(&wp
->status_screen
, width
, 1, 0);
458 wp
->status_screen
.mode
= 0;
460 screen_write_start(&ctx
, &wp
->status_screen
);
462 for (i
= 0; i
< width
; i
++) {
463 px
= wp
->xoff
+ 2 + i
;
464 if (pane_status
== PANE_STATUS_TOP
)
467 py
= wp
->yoff
+ wp
->sy
;
468 cell_type
= screen_redraw_type_of_cell(rctx
, px
, py
);
469 screen_redraw_border_set(w
, wp
, pane_lines
, cell_type
, &gc
);
470 screen_write_cell(&ctx
, &gc
);
472 gc
.attr
&= ~GRID_ATTR_CHARSET
;
474 screen_write_cursormove(&ctx
, 0, 0, 0);
475 format_draw(&ctx
, &gc
, width
, expanded
, NULL
, 0);
476 screen_write_stop(&ctx
);
481 if (grid_compare(wp
->status_screen
.grid
, old
.grid
) == 0) {
489 /* Draw pane status. */
491 screen_redraw_draw_pane_status(struct screen_redraw_ctx
*ctx
)
493 struct client
*c
= ctx
->c
;
494 struct window
*w
= c
->session
->curw
->window
;
495 struct tty
*tty
= &c
->tty
;
496 struct window_pane
*wp
;
498 u_int i
, x
, width
, xoff
, yoff
, size
;
500 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
502 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
503 if (!window_pane_visible(wp
))
505 s
= &wp
->status_screen
;
507 size
= wp
->status_size
;
508 if (ctx
->pane_status
== PANE_STATUS_TOP
)
511 yoff
= wp
->yoff
+ wp
->sy
;
514 if (xoff
+ size
<= ctx
->ox
||
515 xoff
>= ctx
->ox
+ ctx
->sx
||
517 yoff
>= ctx
->oy
+ ctx
->sy
)
520 if (xoff
>= ctx
->ox
&& xoff
+ size
<= ctx
->ox
+ ctx
->sx
) {
525 } else if (xoff
< ctx
->ox
&& xoff
+ size
> ctx
->ox
+ ctx
->sx
) {
526 /* Both left and right not visible. */
530 } else if (xoff
< ctx
->ox
) {
531 /* Left not visible. */
536 /* Right not visible. */
543 yoff
+= ctx
->statuslines
;
544 tty_draw_line(tty
, s
, i
, 0, width
, x
, yoff
- ctx
->oy
,
545 &grid_default_cell
, NULL
);
547 tty_cursor(tty
, 0, 0);
550 /* Update status line and change flags if unchanged. */
552 screen_redraw_update(struct screen_redraw_ctx
*ctx
, uint64_t flags
)
554 struct client
*c
= ctx
->c
;
555 struct window
*w
= c
->session
->curw
->window
;
556 struct window_pane
*wp
;
558 enum pane_lines lines
;
560 if (c
->message_string
!= NULL
)
561 redraw
= status_message_redraw(c
);
562 else if (c
->prompt_string
!= NULL
)
563 redraw
= status_prompt_redraw(c
);
565 redraw
= status_redraw(c
);
566 if (!redraw
&& (~flags
& CLIENT_REDRAWSTATUSALWAYS
))
567 flags
&= ~CLIENT_REDRAWSTATUS
;
569 if (c
->overlay_draw
!= NULL
)
570 flags
|= CLIENT_REDRAWOVERLAY
;
572 if (ctx
->pane_status
!= PANE_STATUS_OFF
) {
573 lines
= ctx
->pane_lines
;
575 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
576 if (screen_redraw_make_pane_status(c
, wp
, ctx
, lines
))
580 flags
|= CLIENT_REDRAWBORDERS
;
586 /* Set up redraw context. */
588 screen_redraw_set_context(struct client
*c
, struct screen_redraw_ctx
*ctx
)
590 struct session
*s
= c
->session
;
591 struct options
*oo
= s
->options
;
592 struct window
*w
= s
->curw
->window
;
593 struct options
*wo
= w
->options
;
596 memset(ctx
, 0, sizeof *ctx
);
599 lines
= status_line_size(c
);
600 if (c
->message_string
!= NULL
|| c
->prompt_string
!= NULL
)
601 lines
= (lines
== 0) ? 1 : lines
;
602 if (lines
!= 0 && options_get_number(oo
, "status-position") == 0)
604 ctx
->statuslines
= lines
;
606 ctx
->pane_status
= options_get_number(wo
, "pane-border-status");
607 ctx
->pane_lines
= options_get_number(wo
, "pane-border-lines");
609 ctx
->pane_scrollbars
= options_get_number(wo
, "pane-scrollbars");
610 ctx
->pane_scrollbars_pos
= options_get_number(wo
,
611 "pane-scrollbars-position");
613 tty_window_offset(&c
->tty
, &ctx
->ox
, &ctx
->oy
, &ctx
->sx
, &ctx
->sy
);
615 log_debug("%s: %s @%u ox=%u oy=%u sx=%u sy=%u %u/%d", __func__
, c
->name
,
616 w
->id
, ctx
->ox
, ctx
->oy
, ctx
->sx
, ctx
->sy
, ctx
->statuslines
,
620 /* Redraw entire screen. */
622 screen_redraw_screen(struct client
*c
)
624 struct screen_redraw_ctx ctx
;
627 if (c
->flags
& CLIENT_SUSPENDED
)
630 screen_redraw_set_context(c
, &ctx
);
632 flags
= screen_redraw_update(&ctx
, c
->flags
);
633 if ((flags
& CLIENT_ALLREDRAWFLAGS
) == 0)
636 tty_sync_start(&c
->tty
);
637 tty_update_mode(&c
->tty
, c
->tty
.mode
, NULL
);
639 if (flags
& (CLIENT_REDRAWWINDOW
|CLIENT_REDRAWBORDERS
)) {
640 log_debug("%s: redrawing borders", c
->name
);
641 screen_redraw_draw_borders(&ctx
);
642 if (ctx
.pane_status
!= PANE_STATUS_OFF
)
643 screen_redraw_draw_pane_status(&ctx
);
644 screen_redraw_draw_pane_scrollbars(&ctx
);
646 if (flags
& CLIENT_REDRAWWINDOW
) {
647 log_debug("%s: redrawing panes", c
->name
);
648 screen_redraw_draw_panes(&ctx
);
649 screen_redraw_draw_pane_scrollbars(&ctx
);
651 if (ctx
.statuslines
!= 0 &&
652 (flags
& (CLIENT_REDRAWSTATUS
|CLIENT_REDRAWSTATUSALWAYS
))) {
653 log_debug("%s: redrawing status", c
->name
);
654 screen_redraw_draw_status(&ctx
);
656 if (c
->overlay_draw
!= NULL
&& (flags
& CLIENT_REDRAWOVERLAY
)) {
657 log_debug("%s: redrawing overlay", c
->name
);
658 c
->overlay_draw(c
, c
->overlay_data
, &ctx
);
664 /* Redraw a single pane and its scrollbar. */
666 screen_redraw_pane(struct client
*c
, struct window_pane
*wp
,
667 int redraw_scrollbar_only
)
669 struct screen_redraw_ctx ctx
;
671 if (!window_pane_visible(wp
))
674 screen_redraw_set_context(c
, &ctx
);
675 tty_sync_start(&c
->tty
);
676 tty_update_mode(&c
->tty
, c
->tty
.mode
, NULL
);
678 if (!redraw_scrollbar_only
)
679 screen_redraw_draw_pane(&ctx
, wp
);
681 if (window_pane_show_scrollbar(wp
, ctx
.pane_scrollbars
))
682 screen_redraw_draw_pane_scrollbar(&ctx
, wp
);
687 /* Get border cell style. */
688 static const struct grid_cell
*
689 screen_redraw_draw_borders_style(struct screen_redraw_ctx
*ctx
, u_int x
,
690 u_int y
, struct window_pane
*wp
)
692 struct client
*c
= ctx
->c
;
693 struct session
*s
= c
->session
;
694 struct window
*w
= s
->curw
->window
;
695 struct window_pane
*active
= server_client_get_pane(c
);
696 struct options
*oo
= w
->options
;
697 struct format_tree
*ft
;
699 if (wp
->border_gc_set
)
700 return (&wp
->border_gc
);
701 wp
->border_gc_set
= 1;
703 ft
= format_create_defaults(NULL
, c
, s
, s
->curw
, wp
);
704 if (screen_redraw_check_is(ctx
, x
, y
, active
))
705 style_apply(&wp
->border_gc
, oo
, "pane-active-border-style", ft
);
707 style_apply(&wp
->border_gc
, oo
, "pane-border-style", ft
);
710 return (&wp
->border_gc
);
713 /* Draw a border cell. */
715 screen_redraw_draw_borders_cell(struct screen_redraw_ctx
*ctx
, u_int i
, u_int j
)
717 struct client
*c
= ctx
->c
;
718 struct session
*s
= c
->session
;
719 struct window
*w
= s
->curw
->window
;
720 struct options
*oo
= w
->options
;
721 struct tty
*tty
= &c
->tty
;
722 struct format_tree
*ft
;
723 struct window_pane
*wp
, *active
= server_client_get_pane(c
);
725 const struct grid_cell
*tmp
;
726 struct overlay_ranges r
;
727 u_int cell_type
, x
= ctx
->ox
+ i
, y
= ctx
->oy
+ j
;
728 int arrows
= 0, border
, isolates
;
730 if (c
->overlay_check
!= NULL
) {
731 c
->overlay_check(c
, c
->overlay_data
, x
, y
, 1, &r
);
732 if (r
.nx
[0] + r
.nx
[1] == 0)
736 cell_type
= screen_redraw_check_cell(ctx
, x
, y
, &wp
);
737 if (cell_type
== CELL_INSIDE
|| cell_type
== CELL_SCROLLBAR
)
741 if (!ctx
->no_pane_gc_set
) {
742 ft
= format_create_defaults(NULL
, c
, s
, s
->curw
, NULL
);
743 memcpy(&ctx
->no_pane_gc
, &grid_default_cell
, sizeof gc
);
744 style_add(&ctx
->no_pane_gc
, oo
, "pane-border-style",
747 ctx
->no_pane_gc_set
= 1;
749 memcpy(&gc
, &ctx
->no_pane_gc
, sizeof gc
);
751 tmp
= screen_redraw_draw_borders_style(ctx
, x
, y
, wp
);
754 memcpy(&gc
, tmp
, sizeof gc
);
756 if (server_is_marked(s
, s
->curw
, marked_pane
.wp
) &&
757 screen_redraw_check_is(ctx
, x
, y
, marked_pane
.wp
))
758 gc
.attr
^= GRID_ATTR_REVERSE
;
760 screen_redraw_border_set(w
, wp
, ctx
->pane_lines
, cell_type
, &gc
);
762 if (cell_type
== CELL_TOPBOTTOM
&&
763 (c
->flags
& CLIENT_UTF8
) &&
764 tty_term_has(tty
->term
, TTYC_BIDI
))
770 tty_cursor(tty
, i
, ctx
->statuslines
+ j
);
772 tty_cursor(tty
, i
, j
);
774 tty_puts(tty
, END_ISOLATE
);
776 switch (options_get_number(oo
, "pane-border-indicators")) {
777 case PANE_BORDER_ARROWS
:
778 case PANE_BORDER_BOTH
:
783 if (wp
!= NULL
&& arrows
) {
784 border
= screen_redraw_pane_border(ctx
, active
, x
, y
);
785 if (((i
== wp
->xoff
+ 1 &&
786 (cell_type
== CELL_LEFTRIGHT
||
787 (cell_type
== CELL_TOPJOIN
&&
788 border
== SCREEN_REDRAW_BORDER_BOTTOM
) ||
789 (cell_type
== CELL_BOTTOMJOIN
&&
790 border
== SCREEN_REDRAW_BORDER_TOP
))) ||
791 (j
== wp
->yoff
+ 1 &&
792 (cell_type
== CELL_TOPBOTTOM
||
793 (cell_type
== CELL_LEFTJOIN
&&
794 border
== SCREEN_REDRAW_BORDER_RIGHT
) ||
795 (cell_type
== CELL_RIGHTJOIN
&&
796 border
== SCREEN_REDRAW_BORDER_LEFT
)))) &&
797 screen_redraw_check_is(ctx
, x
, y
, active
)) {
798 gc
.attr
|= GRID_ATTR_CHARSET
;
799 utf8_set(&gc
.data
, BORDER_MARKERS
[border
]);
803 tty_cell(tty
, &gc
, &grid_default_cell
, NULL
, NULL
);
805 tty_puts(tty
, START_ISOLATE
);
808 /* Draw the borders. */
810 screen_redraw_draw_borders(struct screen_redraw_ctx
*ctx
)
812 struct client
*c
= ctx
->c
;
813 struct session
*s
= c
->session
;
814 struct window
*w
= s
->curw
->window
;
815 struct window_pane
*wp
;
818 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
820 TAILQ_FOREACH(wp
, &w
->panes
, entry
)
821 wp
->border_gc_set
= 0;
823 for (j
= 0; j
< c
->tty
.sy
- ctx
->statuslines
; j
++) {
824 for (i
= 0; i
< c
->tty
.sx
; i
++)
825 screen_redraw_draw_borders_cell(ctx
, i
, j
);
829 /* Draw the panes. */
831 screen_redraw_draw_panes(struct screen_redraw_ctx
*ctx
)
833 struct client
*c
= ctx
->c
;
834 struct window
*w
= c
->session
->curw
->window
;
835 struct window_pane
*wp
;
837 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
839 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
840 if (window_pane_visible(wp
))
841 screen_redraw_draw_pane(ctx
, wp
);
845 /* Draw the status line. */
847 screen_redraw_draw_status(struct screen_redraw_ctx
*ctx
)
849 struct client
*c
= ctx
->c
;
850 struct window
*w
= c
->session
->curw
->window
;
851 struct tty
*tty
= &c
->tty
;
852 struct screen
*s
= c
->status
.active
;
855 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
860 y
= c
->tty
.sy
- ctx
->statuslines
;
861 for (i
= 0; i
< ctx
->statuslines
; i
++) {
862 tty_draw_line(tty
, s
, 0, i
, UINT_MAX
, 0, y
+ i
,
863 &grid_default_cell
, NULL
);
869 screen_redraw_draw_pane(struct screen_redraw_ctx
*ctx
, struct window_pane
*wp
)
871 struct client
*c
= ctx
->c
;
872 struct window
*w
= c
->session
->curw
->window
;
873 struct tty
*tty
= &c
->tty
;
874 struct screen
*s
= wp
->screen
;
875 struct colour_palette
*palette
= &wp
->palette
;
876 struct grid_cell defaults
;
877 u_int i
, j
, top
, x
, y
, width
;
879 log_debug("%s: %s @%u %%%u", __func__
, c
->name
, w
->id
, wp
->id
);
881 if (wp
->xoff
+ wp
->sx
<= ctx
->ox
|| wp
->xoff
>= ctx
->ox
+ ctx
->sx
)
884 top
= ctx
->statuslines
;
887 for (j
= 0; j
< wp
->sy
; j
++) {
888 if (wp
->yoff
+ j
< ctx
->oy
|| wp
->yoff
+ j
>= ctx
->oy
+ ctx
->sy
)
890 y
= top
+ wp
->yoff
+ j
- ctx
->oy
;
892 if (wp
->xoff
>= ctx
->ox
&&
893 wp
->xoff
+ wp
->sx
<= ctx
->ox
+ ctx
->sx
) {
896 x
= wp
->xoff
- ctx
->ox
;
898 } else if (wp
->xoff
< ctx
->ox
&&
899 wp
->xoff
+ wp
->sx
> ctx
->ox
+ ctx
->sx
) {
900 /* Both left and right not visible. */
904 } else if (wp
->xoff
< ctx
->ox
) {
905 /* Left not visible. */
906 i
= ctx
->ox
- wp
->xoff
;
910 /* Right not visible. */
912 x
= wp
->xoff
- ctx
->ox
;
915 log_debug("%s: %s %%%u line %u,%u at %u,%u, width %u",
916 __func__
, c
->name
, wp
->id
, i
, j
, x
, y
, width
);
918 tty_default_colours(&defaults
, wp
);
919 tty_draw_line(tty
, s
, i
, j
, width
, x
, y
, &defaults
, palette
);
923 tty_draw_images(c
, wp
, s
);
927 /* Draw the panes scrollbars */
929 screen_redraw_draw_pane_scrollbars(struct screen_redraw_ctx
*ctx
)
931 struct client
*c
= ctx
->c
;
932 struct window
*w
= c
->session
->curw
->window
;
933 struct window_pane
*wp
;
935 log_debug("%s: %s @%u", __func__
, c
->name
, w
->id
);
937 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
938 if (window_pane_show_scrollbar(wp
, ctx
->pane_scrollbars
) &&
939 window_pane_visible(wp
))
940 screen_redraw_draw_pane_scrollbar(ctx
, wp
);
944 /* Draw pane scrollbar. */
946 screen_redraw_draw_pane_scrollbar(struct screen_redraw_ctx
*ctx
,
947 struct window_pane
*wp
)
949 struct screen
*s
= wp
->screen
;
951 u_int sb
= ctx
->pane_scrollbars
, total_height
, sb_h
= wp
->sy
;
952 u_int sb_pos
= ctx
->pane_scrollbars_pos
, slider_h
, slider_y
;
953 int sb_w
= wp
->scrollbar_style
.width
;
954 int sb_pad
= wp
->scrollbar_style
.pad
;
955 int cm_y
, cm_size
, xoff
= wp
->xoff
, ox
= ctx
->ox
;
956 int sb_x
, sb_y
= (int)(wp
->yoff
- ctx
->oy
); /* sb top */
958 if (window_pane_mode(wp
) == WINDOW_PANE_NO_MODE
) {
959 if (sb
== PANE_SCROLLBARS_MODAL
)
961 /* Show slider at the bottom of the scrollbar. */
962 total_height
= screen_size_y(s
) + screen_hsize(s
);
963 percent_view
= (double)sb_h
/ total_height
;
964 slider_h
= (double)sb_h
* percent_view
;
965 slider_y
= sb_h
- slider_h
;
967 if (TAILQ_FIRST(&wp
->modes
) == NULL
)
969 if (window_copy_get_current_offset(wp
, &cm_y
, &cm_size
) == 0)
971 total_height
= cm_size
+ sb_h
;
972 percent_view
= (double)sb_h
/ (cm_size
+ sb_h
);
973 slider_h
= (double)sb_h
* percent_view
;
974 slider_y
= (sb_h
+ 1) * ((double)cm_y
/ total_height
);
977 if (sb_pos
== PANE_SCROLLBARS_LEFT
)
978 sb_x
= xoff
- sb_w
- sb_pad
- ox
;
980 sb_x
= xoff
+ wp
->sx
- ox
;
984 if (slider_y
>= sb_h
)
987 screen_redraw_draw_scrollbar(ctx
, wp
, sb_pos
, sb_x
, sb_y
, sb_h
,
990 /* Store current position and height of the slider */
991 wp
->sb_slider_y
= slider_y
; /* top of slider y pos in scrollbar */
992 wp
->sb_slider_h
= slider_h
; /* height of slider */
996 screen_redraw_draw_scrollbar(struct screen_redraw_ctx
*ctx
,
997 struct window_pane
*wp
, int sb_pos
, int sb_x
, int sb_y
, u_int sb_h
,
998 u_int slider_h
, u_int slider_y
)
1000 struct client
*c
= ctx
->c
;
1001 struct tty
*tty
= &c
->tty
;
1002 struct grid_cell gc
, slgc
, *gcp
;
1003 struct style
*sb_style
= &wp
->scrollbar_style
;
1004 u_int i
, j
, imax
, jmax
;
1005 u_int sb_w
= sb_style
->width
, sb_pad
= sb_style
->pad
;
1006 int px
, py
, ox
= ctx
->ox
, oy
= ctx
->oy
;
1007 int sx
= ctx
->sx
, sy
= ctx
->sy
, xoff
= wp
->xoff
;
1008 int yoff
= wp
->yoff
;
1010 /* Set up style for slider. */
1012 memcpy(&slgc
, &gc
, sizeof slgc
);
1016 imax
= sb_w
+ sb_pad
;
1017 if ((int)imax
+ sb_x
> sx
)
1020 if ((int)jmax
+ sb_y
> sy
)
1023 for (j
= 0; j
< jmax
; j
++) {
1025 for (i
= 0; i
< imax
; i
++) {
1027 if (px
< xoff
- ox
- (int)sb_w
- (int)sb_pad
||
1028 px
>= sx
|| px
< 0 ||
1029 py
< yoff
- oy
- 1 ||
1032 tty_cursor(tty
, px
, py
);
1033 if ((sb_pos
== PANE_SCROLLBARS_LEFT
&&
1034 i
>= sb_w
&& i
< sb_w
+ sb_pad
) ||
1035 (sb_pos
== PANE_SCROLLBARS_RIGHT
&&
1037 tty_cell(tty
, &grid_default_cell
,
1038 &grid_default_cell
, NULL
, NULL
);
1040 if (j
>= slider_y
&& j
< slider_y
+ slider_h
)
1044 tty_cell(tty
, gcp
, &grid_default_cell
, NULL
,