mirror of
https://github.com/tmux/tmux.git
synced 2026-06-21 17:55:21 +00:00
Add scrollbar auto-hide feature.
This commit is contained in:
110
window.c
110
window.c
@@ -71,6 +71,7 @@ struct window_pane_input_data {
|
||||
static struct window_pane *window_pane_create(struct window *, u_int, u_int,
|
||||
u_int);
|
||||
static void window_pane_destroy(struct window_pane *);
|
||||
static void window_pane_scrollbar_timer(int, short, void *);
|
||||
static void window_pane_full_size_offset(struct window_pane *wp,
|
||||
int *xoff, int *yoff, u_int *sx, u_int *sy);
|
||||
|
||||
@@ -1101,6 +1102,7 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
|
||||
|
||||
screen_init(&wp->status_screen, 1, 1, 0);
|
||||
style_ranges_init(&wp->border_status_line.ranges);
|
||||
evtimer_set(&wp->sb_auto_timer, window_pane_scrollbar_timer, wp);
|
||||
|
||||
if (gethostname(host, sizeof host) == 0)
|
||||
screen_set_title(&wp->base, host, 0);
|
||||
@@ -1132,6 +1134,31 @@ window_pane_wait_finish(struct window_pane *wp)
|
||||
cmdq_continue(item);
|
||||
}
|
||||
|
||||
static void
|
||||
window_pane_scrollbar_timer(__unused int fd, __unused short events, void *arg)
|
||||
{
|
||||
struct window_pane *wp = arg;
|
||||
|
||||
if (wp->sb_auto_hover)
|
||||
return;
|
||||
window_pane_scrollbar_hide(wp);
|
||||
}
|
||||
|
||||
static int
|
||||
window_pane_scrollbar_auto_hide(struct window_pane *wp)
|
||||
{
|
||||
return (options_get_number(wp->window->options,
|
||||
"pane-scrollbars-auto-hide"));
|
||||
}
|
||||
|
||||
static void
|
||||
window_pane_scrollbar_redraw(struct window_pane *wp)
|
||||
{
|
||||
redraw_invalidate_scene(wp->window);
|
||||
wp->flags |= PANE_REDRAW;
|
||||
server_redraw_window(wp->window);
|
||||
}
|
||||
|
||||
static void
|
||||
window_pane_destroy(struct window_pane *wp)
|
||||
{
|
||||
@@ -1164,6 +1191,8 @@ window_pane_destroy(struct window_pane *wp)
|
||||
event_del(&wp->resize_timer);
|
||||
if (event_initialized(&wp->sync_timer))
|
||||
event_del(&wp->sync_timer);
|
||||
if (event_initialized(&wp->sb_auto_timer))
|
||||
event_del(&wp->sb_auto_timer);
|
||||
window_pane_clear_resizes(wp, NULL);
|
||||
|
||||
RB_REMOVE(window_pane_tree, &all_window_panes, wp);
|
||||
@@ -1540,7 +1569,7 @@ window_pane_full_size_offset(struct window_pane *wp, int *xoff, int *yoff,
|
||||
pane_scrollbars = options_get_number(w->options, "pane-scrollbars");
|
||||
sb_pos = options_get_number(w->options, "pane-scrollbars-position");
|
||||
|
||||
if (window_pane_show_scrollbar(wp, pane_scrollbars))
|
||||
if (window_pane_scrollbar_reserve(wp, pane_scrollbars))
|
||||
sb_w = wp->scrollbar_style.width + wp->scrollbar_style.pad;
|
||||
else
|
||||
sb_w = 0;
|
||||
@@ -1973,6 +2002,85 @@ window_pane_show_scrollbar(struct window_pane *wp, int sb_option)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
window_pane_scrollbar_reserve(struct window_pane *wp, int sb_option)
|
||||
{
|
||||
if (!window_pane_show_scrollbar(wp, sb_option))
|
||||
return (0);
|
||||
return (!window_pane_scrollbar_auto_hide(wp));
|
||||
}
|
||||
|
||||
int
|
||||
window_pane_scrollbar_overlay(struct window_pane *wp, int sb_option)
|
||||
{
|
||||
if (!window_pane_show_scrollbar(wp, sb_option))
|
||||
return (0);
|
||||
return (window_pane_scrollbar_auto_hide(wp));
|
||||
}
|
||||
|
||||
int
|
||||
window_pane_scrollbar_visible(struct window_pane *wp, int sb_option)
|
||||
{
|
||||
if (!window_pane_show_scrollbar(wp, sb_option))
|
||||
return (0);
|
||||
if (!window_pane_scrollbar_auto_hide(wp))
|
||||
return (1);
|
||||
return (wp->sb_auto_visible);
|
||||
}
|
||||
|
||||
void
|
||||
window_pane_scrollbar_start_timer(struct window_pane *wp)
|
||||
{
|
||||
struct timeval tv;
|
||||
u_int delay;
|
||||
|
||||
if (!window_pane_scrollbar_auto_hide(wp) || !wp->sb_auto_visible)
|
||||
return;
|
||||
if (wp->sb_auto_hover)
|
||||
return;
|
||||
|
||||
delay = options_get_number(wp->window->options,
|
||||
"pane-scrollbars-auto-hide-timeout");
|
||||
tv.tv_sec = delay / 1000;
|
||||
tv.tv_usec = (delay % 1000) * 1000L;
|
||||
evtimer_del(&wp->sb_auto_timer);
|
||||
evtimer_add(&wp->sb_auto_timer, &tv);
|
||||
}
|
||||
|
||||
void
|
||||
window_pane_scrollbar_show(struct window_pane *wp, int start_timer)
|
||||
{
|
||||
int changed = 0;
|
||||
int sb;
|
||||
|
||||
if (!window_pane_scrollbar_auto_hide(wp))
|
||||
return;
|
||||
sb = options_get_number(wp->window->options, "pane-scrollbars");
|
||||
if (!window_pane_show_scrollbar(wp, sb))
|
||||
return;
|
||||
if (!wp->sb_auto_visible) {
|
||||
wp->sb_auto_visible = 1;
|
||||
changed = 1;
|
||||
}
|
||||
evtimer_del(&wp->sb_auto_timer);
|
||||
if (start_timer)
|
||||
window_pane_scrollbar_start_timer(wp);
|
||||
if (changed)
|
||||
window_pane_scrollbar_redraw(wp);
|
||||
}
|
||||
|
||||
void
|
||||
window_pane_scrollbar_hide(struct window_pane *wp)
|
||||
{
|
||||
if (event_initialized(&wp->sb_auto_timer))
|
||||
evtimer_del(&wp->sb_auto_timer);
|
||||
wp->sb_auto_hover = 0;
|
||||
if (!wp->sb_auto_visible)
|
||||
return;
|
||||
wp->sb_auto_visible = 0;
|
||||
window_pane_scrollbar_redraw(wp);
|
||||
}
|
||||
|
||||
int
|
||||
window_pane_get_bg(struct window_pane *wp)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user