diff --git a/source/widgets/scrollbar.c b/source/widgets/scrollbar.c index e3388559..8c10336d 100644 --- a/source/widgets/scrollbar.c +++ b/source/widgets/scrollbar.c @@ -33,6 +33,8 @@ #include "theme.h" +#include + /** The default width of the scrollbar */ #define DEFAULT_SCROLLBAR_WIDTH 8 @@ -65,7 +67,7 @@ guint scrollbar_scroll_get_line(const scrollbar *sb, int y) { y -= half_handle; y = MIN(MAX(0, y), sb->widget.h - 2 * half_handle); - unsigned int sel = ((y) / sec); + unsigned int sel = round((y) / sec); return MIN(sel, sb->length - 1); } @@ -178,7 +180,8 @@ static void scrollbar_draw(widget *wid, cairo_t *draw) { float x = widget_padding_get_left(wid); float width = widget_padding_get_remaining_width(wid); - float radius = ((width < height) ? width : height) / 2; // Limit radius to prevent overlap + float radius = ((width < height) ? width : height) / + 2; // Limit radius to prevent overlap // Draw rounded rectangle cairo_new_sub_path(draw); @@ -189,8 +192,7 @@ static void scrollbar_draw(widget *wid, cairo_t *draw) { cairo_close_path(draw); cairo_fill(draw); - } - else { + } else { cairo_rectangle(draw, widget_padding_get_left(wid), widget_padding_get_top(wid) + y, widget_padding_get_remaining_width(wid), height); diff --git a/test/scrollbar-test.c b/test/scrollbar-test.c index f3bed973..a01d616e 100644 --- a/test/scrollbar-test.c +++ b/test/scrollbar-test.c @@ -25,8 +25,8 @@ * */ -#include "helper.h" #include "display.h" +#include "helper.h" #include "rofi-icon-fetcher.h" #include "rofi.h" #include "xrmoptions.h" @@ -132,9 +132,9 @@ int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) { TASSERTE(cl, 9999u); scrollbar_set_handle_length(sb, 1000); cl = scrollbar_scroll_get_line(sb, 10); - TASSERTE(cl, 555u); + TASSERTE(cl, 556u); cl = scrollbar_scroll_get_line(sb, 20); - TASSERTE(cl, 1666u); + TASSERTE(cl, 1667u); cl = scrollbar_scroll_get_line(sb, 0); TASSERTE(cl, 0u); cl = scrollbar_scroll_get_line(sb, 99);