scrollbar: add scrolled-or-hovered option

This commit is contained in:
Pavel 2026-08-11 13:17:33 +02:00
parent 5734bb5a58
commit 64663fee62
6 changed files with 11 additions and 5 deletions

View file

@ -138,7 +138,7 @@ typedef enum MouseShapes {
/* end mouse shapes */
} MouseShape;
typedef enum { NONE, MENUBAR, WINDOW, ALL } WindowTitleIn;
typedef enum { SCROLLBAR_NEVER, SCROLLBAR_ON_SCROLLED, SCROLLBAR_ON_HOVERED, SCROLLBAR_ON_SCROLL_AND_HOVER, SCROLLBAR_ALWAYS } ScrollbarVisibilityPolicy;
typedef enum { SCROLLBAR_NEVER, SCROLLBAR_ON_SCROLLED, SCROLLBAR_ON_HOVERED, SCROLLBAR_ON_SCROLL_AND_HOVER, SCROLLBAR_ON_SCROLL_OR_HOVER, SCROLLBAR_ALWAYS } ScrollbarVisibilityPolicy;
typedef enum { PROGRESS_BAR_HIDDEN, PROGRESS_BAR_LEFT, PROGRESS_BAR_RIGHT, PROGRESS_BAR_TOP, PROGRESS_BAR_BOTTOM } ProgressBarPosition;
typedef enum { PROGRESS_STATE_UNSET, PROGRESS_STATE_SET, PROGRESS_STATE_ERROR, PROGRESS_STATE_INDETERMINATE, PROGRESS_STATE_PAUSED } ProgressBarState;
typedef enum { TILING, SCALED, MIRRORED, CLAMPED, CENTER_CLAMPED, CENTER_SCALED } BackgroundImageLayout;

View file

@ -531,7 +531,7 @@ opt(
'scrollbar',
'scrolled',
ctype='scrollbar',
choices=('scrolled', 'always', 'never', 'hovered', 'scrolled-and-hovered'),
choices=('scrolled', 'always', 'never', 'hovered', 'scrolled-and-hovered', 'scrolled-or-hovered'),
long_text="""\
Control when the scrollbar is displayed.
@ -541,6 +541,8 @@ Control when the scrollbar is displayed.
means when the mouse is hovering on the right edge of the window.
:code:`scrolled-and-hovered`
means when the mouse is over the scrollbar region *and* scrolling backwards has started.
:code:`scrolled-or-hovered`
means when the mouse is over the scrollbar region *or* scrolling backwards has started.
:code:`always`
means whenever any scrollback is present
:code:`never`

View file

@ -1278,7 +1278,7 @@ class Parser:
raise ValueError(f"The value {val} is not a valid choice for scrollbar")
ans["scrollbar"] = val
choices_for_scrollbar = frozenset(('scrolled', 'always', 'never', 'hovered', 'scrolled-and-hovered'))
choices_for_scrollbar = frozenset(('scrolled', 'always', 'never', 'hovered', 'scrolled-and-hovered', 'scrolled-or-hovered'))
def scrollbar_gap(self, val: str, ans: dict[str, typing.Any]) -> None:
ans['scrollbar_gap'] = positive_float(val)

View file

@ -79,7 +79,10 @@ scrollbar(PyObject *src) {
case 'a': return SCROLLBAR_ALWAYS;
case 'n': return SCROLLBAR_NEVER;
case 'h': return SCROLLBAR_ON_HOVERED;
case 's': return strcmp(q, "scrolled") == 0 ? SCROLLBAR_ON_SCROLLED : SCROLLBAR_ON_SCROLL_AND_HOVER;
case 's':
if (strcmp(q, "scrolled") == 0) return SCROLLBAR_ON_SCROLLED;
if (strcmp(q, "scrolled-or-hovered") == 0) return SCROLLBAR_ON_SCROLL_OR_HOVER;
return SCROLLBAR_ON_SCROLL_AND_HOVER;
}
return SCROLLBAR_ON_SCROLLED;
}

View file

@ -31,7 +31,7 @@ choices_for_palette_generate = typing.Literal['fixed', 'semantic', 'legacy']
choices_for_placement_strategy = typing.Literal['top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right']
choices_for_pointer_shape_when_grabbed = choices_for_default_pointer_shape
choices_for_progress_bar = typing.Literal['left', 'right', 'top', 'bottom', 'hidden']
choices_for_scrollbar = typing.Literal['scrolled', 'always', 'never', 'hovered', 'scrolled-and-hovered']
choices_for_scrollbar = typing.Literal['scrolled', 'always', 'never', 'hovered', 'scrolled-and-hovered', 'scrolled-or-hovered']
choices_for_strip_trailing_spaces = typing.Literal['always', 'never', 'smart']
choices_for_tab_bar_align = typing.Literal['start', 'center', 'end', 'left', 'right']
choices_for_tab_bar_style = typing.Literal['fade', 'hidden', 'powerline', 'separator', 'slant', 'custom']

View file

@ -1204,6 +1204,7 @@ has_scrollbar(Window *w, Screen *screen) {
case SCROLLBAR_ON_SCROLLED: return screen->scrolled_by > 0;
case SCROLLBAR_ON_HOVERED: return w->scrollbar.is_hovering;
case SCROLLBAR_ON_SCROLL_AND_HOVER: return screen->scrolled_by > 0 && w->scrollbar.is_hovering;
case SCROLLBAR_ON_SCROLL_OR_HOVER: return screen->scrolled_by > 0 || w->scrollbar.is_hovering;
}
return false;
}