Decrease margins on scrollbar

Hello,

Is there a way to decrease the padding on the sides of the scrollbar thumb? RIght now it looks like this:

As you can see, there is some padding between the “grey bar” and the scrollbar thumb, and at the edge as well. I’ve tried using setting the margin and padding CSS properties of the scrollbar to zero, but that does not seem to work.

For more context, this is the GTK4 GUI of Vim. The drawing area (where all the text editing happens) and the scrollbars are positioned using a GtkFixed like custom widget.

Hi,

IIRC the increased space was introduced to compensate the rounded corners.

You can reduce it with something like this:

scrollbar.overlay-indicator.bottom > range > trough,
scrollbar.overlay-indicator.bottom:not(.hovering) > range > trough {
	margin: 0 4px 2px 4px;
}

scrollbar.overlay-indicator.right > range > trough,
scrollbar.overlay-indicator.right:not(.hovering) > range > trough {
	margin: 4px 2px 4px 0;
}

Hm, that does not seem to work

Which gtk4 and libadwaita versions do you use?

Have you tried the gtk inspector to test the CSS? If it works there, then there may be an issue in the way you apply the CSS in your app.

I am using GTK 4.22.4 and libadwaita 1.9.1. However the app does not use libadwaita so I’m not sure if that matters.

I’ve been using GTK inspector for testing, this is the CSS I used (.vim-scrollbar is the CSS class for the GtkScrollbar widget).

.vim-scrollbar > range > trough,
.vim-scrollbar:not(.hovering) > range > trough {
	margin: 0px;
    padding: 0px;
}

BTW this is branch I’m testing on: Refactor gui_gtk4_f.c by 64-bitman · Pull Request #20375 · vim/vim · GitHub . You can enable the scrollbar with set guioptions+=l

Ah yes, my CSS was actually assuming to apply on top of the adwaita stylesheet.

Then it’s quite strange because the fallback gtk theme doesn’t add margins around the scrollbars…
You may have the env variable GTK_THEME set, or something inside your ~/.config/gtk-4.0/gtk.css, that interferes and adds margins.
Or it can also be an offset issue in the way the scrollbars are positioned in vim (looks like it uses some kind of Gtk.Fixed).

Is it possible to enable the gtk inspector in vim?
If yes you can use if to visualize widgets allocations and ensure the position is properly computed.

Looks like you’re not using overlay scrollbars, you can also try:

scrollbar > range > trough > slider {
	border-width: 0;
}

Actually it looks like the issue is with the GTK theme I’m using. On WSLg, the scrollbars look fine (no margins), I’m guessing thats the fallback GTK theme. I apologize for taking up your time. Thanks

No problem :slight_smile:
glad you could identify the issue.