Skip to content

Commit

Permalink
Merge branch 'obsd-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAdam committed Nov 15, 2024
2 parents 563ed05 + d6883c0 commit d35458e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 43 deletions.
7 changes: 2 additions & 5 deletions layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
struct window_pane *wp;
struct layout_cell *lc;
int status, scrollbars, sb_pos;
u_int sx, sy, mode;
u_int sx, sy;

status = options_get_number(w->options, "pane-border-status");
scrollbars = options_get_number(w->options, "pane-scrollbars");
Expand All @@ -313,10 +313,7 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
sy--;
}

mode = window_pane_mode(wp);
if (scrollbars == PANE_SCROLLBARS_ALWAYS ||
(scrollbars == PANE_SCROLLBARS_MODAL &&
mode != WINDOW_PANE_NO_MODE)) {
if (window_pane_show_scrollbar(wp, scrollbars)) {
if (sb_pos == PANE_SCROLLBARS_LEFT) {
sx = sx - PANE_SCROLLBARS_WIDTH;
wp->xoff = wp->xoff + PANE_SCROLLBARS_WIDTH;
Expand Down
33 changes: 5 additions & 28 deletions screen-redraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ screen_redraw_pane_border(struct screen_redraw_ctx *ctx, struct window_pane *wp,
}

/* Are scrollbars enabled? */
if (pane_scrollbars == PANE_SCROLLBARS_ALWAYS ||
(pane_scrollbars == PANE_SCROLLBARS_MODAL &&
window_pane_mode(wp) != WINDOW_PANE_NO_MODE))
if (window_pane_show_scrollbar(wp, pane_scrollbars))
sb_w = PANE_SCROLLBARS_WIDTH;

/*
Expand Down Expand Up @@ -364,9 +362,7 @@ screen_redraw_check_cell(struct screen_redraw_ctx *ctx, u_int px, u_int py,
*wpp = wp;

/* Check if CELL_SCROLLBAR */
if (pane_scrollbars == PANE_SCROLLBARS_ALWAYS ||
(pane_scrollbars == PANE_SCROLLBARS_MODAL &&
window_pane_mode(wp) != WINDOW_PANE_NO_MODE)) {
if (window_pane_show_scrollbar(wp, pane_scrollbars)) {

if (pane_status == PANE_STATUS_TOP)
line = wp->yoff - 1;
Expand Down Expand Up @@ -669,11 +665,9 @@ screen_redraw_pane(struct client *c, struct window_pane *wp,
int redraw_scrollbar_only)
{
struct screen_redraw_ctx ctx;
int pane_scrollbars, mode;

if (!window_pane_visible(wp))
return;
mode = window_pane_mode(wp);

screen_redraw_set_context(c, &ctx);
tty_sync_start(&c->tty);
Expand All @@ -682,15 +676,7 @@ screen_redraw_pane(struct client *c, struct window_pane *wp,
if (!redraw_scrollbar_only)
screen_redraw_draw_pane(&ctx, wp);

/*
* Redraw scrollbar if needed. Always redraw scrollbar in a mode because
* if redrawing a pane, it's because pane has scrolled.
*/
pane_scrollbars = ctx.pane_scrollbars;
if (pane_scrollbars == PANE_SCROLLBARS_MODAL &&
mode == WINDOW_PANE_NO_MODE)
pane_scrollbars = PANE_SCROLLBARS_OFF;
if (pane_scrollbars != PANE_SCROLLBARS_OFF)
if (window_pane_show_scrollbar(wp, ctx.pane_scrollbars))
screen_redraw_draw_pane_scrollbar(&ctx, wp);

tty_reset(&c->tty);
Expand Down Expand Up @@ -947,17 +933,8 @@ screen_redraw_draw_pane_scrollbars(struct screen_redraw_ctx *ctx)
log_debug("%s: %s @%u", __func__, c->name, w->id);

TAILQ_FOREACH(wp, &w->panes, entry) {
switch (ctx->pane_scrollbars) {
case PANE_SCROLLBARS_OFF:
return;
case PANE_SCROLLBARS_MODAL:
if (window_pane_mode(wp) == WINDOW_PANE_NO_MODE)
return;
break;
case PANE_SCROLLBARS_ALWAYS:
break;
}
if (window_pane_visible(wp))
if (window_pane_show_scrollbar(wp, ctx->pane_scrollbars) &&
window_pane_visible(wp))
screen_redraw_draw_pane_scrollbar(ctx, wp);
}
}
Expand Down
2 changes: 2 additions & 0 deletions screen-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,7 @@ screen_write_alternateon(struct screen_write_ctx *ctx, struct grid_cell *gc,

screen_write_collect_flush(ctx, 0, __func__);
screen_alternate_on(ctx->s, gc, cursor);
layout_fix_panes(wp->window, NULL);

screen_write_initctx(ctx, &ttyctx, 1);
if (ttyctx.redraw_cb != NULL)
Expand All @@ -2377,6 +2378,7 @@ screen_write_alternateoff(struct screen_write_ctx *ctx, struct grid_cell *gc,

screen_write_collect_flush(ctx, 0, __func__);
screen_alternate_off(ctx->s, gc, cursor);
layout_fix_panes(wp->window, NULL);

screen_write_initctx(ctx, &ttyctx, 1);
if (ttyctx.redraw_cb != NULL)
Expand Down
10 changes: 5 additions & 5 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ screen_reinit(struct screen *s)
if (options_get_number(global_options, "extended-keys") == 2)
s->mode = (s->mode & ~EXTENDED_KEY_MODES)|MODE_KEYS_EXTENDED;

if (s->saved_grid != NULL)
if (SCREEN_IS_ALTERNATE(s))
screen_alternate_off(s, NULL, 0);
s->saved_cx = UINT_MAX;
s->saved_cy = UINT_MAX;
Expand Down Expand Up @@ -155,7 +155,7 @@ screen_free(struct screen *s)
if (s->write_list != NULL)
screen_write_free_list(s);

if (s->saved_grid != NULL)
if (SCREEN_IS_ALTERNATE(s))
grid_destroy(s->saved_grid);
grid_destroy(s->grid);

Expand Down Expand Up @@ -628,7 +628,7 @@ screen_alternate_on(struct screen *s, struct grid_cell *gc, int cursor)
{
u_int sx, sy;

if (s->saved_grid != NULL)
if (SCREEN_IS_ALTERNATE(s))
return;
sx = screen_size_x(s);
sy = screen_size_y(s);
Expand Down Expand Up @@ -657,7 +657,7 @@ screen_alternate_off(struct screen *s, struct grid_cell *gc, int cursor)
* If the current size is different, temporarily resize to the old size
* before copying back.
*/
if (s->saved_grid != NULL)
if (SCREEN_IS_ALTERNATE(s))
screen_resize(s, s->saved_grid->sx, s->saved_grid->sy, 0);

/*
Expand All @@ -672,7 +672,7 @@ screen_alternate_off(struct screen *s, struct grid_cell *gc, int cursor)
}

/* If not in the alternate screen, do nothing more. */
if (s->saved_grid == NULL) {
if (!SCREEN_IS_ALTERNATE(s)) {
if (s->cx > screen_size_x(s) - 1)
s->cx = screen_size_x(s) - 1;
if (s->cy > screen_size_y(s) - 1)
Expand Down
8 changes: 3 additions & 5 deletions server-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,7 @@ server_client_check_mouse(struct client *c, struct key_event *event)

/* Try the scrollbar next to a pane. */
sb = options_get_number(wo, "pane-scrollbars");
sb_pos = options_get_number(wo,
"pane-scrollbars-position");
if (sb == PANE_SCROLLBARS_ALWAYS ||
(sb == PANE_SCROLLBARS_MODAL &&
window_pane_mode(wp) != WINDOW_PANE_NO_MODE))
if (window_pane_show_scrollbar(wp, sb))
sb_w = PANE_SCROLLBARS_WIDTH;
else
sb_w = 0;
Expand All @@ -802,6 +798,8 @@ server_client_check_mouse(struct client *c, struct key_event *event)
if ((pane_status != PANE_STATUS_OFF && py != line) ||
(wp->yoff == 0 && py < wp->sy) ||
(py >= wp->yoff && py < wp->yoff + wp->sy)) {
sb_pos = options_get_number(wo,
"pane-scrollbars-position");
if ((sb_pos == PANE_SCROLLBARS_RIGHT &&
(px >= wp->xoff + wp->sx &&
px < wp->xoff + wp->sx + sb_w)) ||
Expand Down
4 changes: 4 additions & 0 deletions tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,9 @@ TAILQ_HEAD(winlink_stack, winlink);
#define PANE_SCROLLBARS_WIDTH 1
#define PANE_SCROLLBARS_PADDING 0

/* True if screen in alternate screen. */
#define SCREEN_IS_ALTERNATE(s) ((s)->saved_grid != NULL)

/* Layout direction. */
enum layout_type {
LAYOUT_LEFTRIGHT,
Expand Down Expand Up @@ -3221,6 +3224,7 @@ void window_pane_update_used_data(struct window_pane *,
void window_set_fill_character(struct window *);
void window_pane_default_cursor(struct window_pane *);
int window_pane_mode(struct window_pane *);
int window_pane_show_scrollbar(struct window_pane *, int);

/* layout.c */
u_int layout_count_cells(struct layout_cell *);
Expand Down
13 changes: 13 additions & 0 deletions window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1736,3 +1736,16 @@ window_pane_mode(struct window_pane *wp)
}
return (WINDOW_PANE_NO_MODE);
}

/* Return 1 if scrollbar is or should be displayed. */
int
window_pane_show_scrollbar(struct window_pane *wp, int sb_option)
{
if (SCREEN_IS_ALTERNATE(wp->screen))
return (0);
if (sb_option == PANE_SCROLLBARS_ALWAYS ||
(sb_option == PANE_SCROLLBARS_MODAL &&
window_pane_mode(wp) != WINDOW_PANE_NO_MODE))
return (1);
return (0);
}

0 comments on commit d35458e

Please sign in to comment.