Turn off scrollbar when pane is in alternate screen, from Michael Grant,

GitHub issue 4231.
This commit is contained in:
nicm 2024-11-15 09:01:16 +00:00
parent f527412d9b
commit d6883c0266
7 changed files with 34 additions and 43 deletions

View File

@ -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");
@ -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;

View File

@ -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;
/*
@ -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;
@ -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);
@ -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);
@ -943,17 +929,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);
}
}

View File

@ -2204,6 +2204,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)
@ -2223,6 +2224,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)

View File

@ -111,7 +111,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;
@ -147,7 +147,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);
@ -612,7 +612,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);
@ -641,7 +641,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);
/*
@ -656,7 +656,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)

View File

@ -783,11 +783,7 @@ have_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;
@ -806,6 +802,8 @@ have_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)) ||

4
tmux.h
View File

@ -1272,6 +1272,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,
@ -3173,6 +3176,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 *);

View File

@ -1726,3 +1726,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);
}