Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scrollbar] Add theming for rounded corners #2108

Merged
merged 2 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/rofi-theme.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ The following properties are currently supported:
- **handle-width**: distance
- **handle-color**: color
- **border-color**: color
- **handle-rounded-corners**: boolean for rounded scrollbar

### box

Expand Down
26 changes: 22 additions & 4 deletions source/widgets/scrollbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,26 @@ static void scrollbar_draw(widget *wid, cairo_t *draw) {
// Cap length;
rofi_theme_get_color(WIDGET(sb), "handle-color", draw);

cairo_rectangle(draw, widget_padding_get_left(wid),
widget_padding_get_top(wid) + y,
widget_padding_get_remaining_width(wid), height);
cairo_fill(draw);
if (rofi_theme_get_boolean(WIDGET(sb), "handle-rounded-corners", FALSE)) {
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

// Draw rounded rectangle
cairo_new_sub_path(draw);
cairo_arc(draw, x + width - radius, y + radius, radius, -G_PI_2, 0);
cairo_arc(draw, x + width - radius, y + height - radius, radius, 0, G_PI_2);
cairo_arc(draw, x + radius, y + height - radius, radius, G_PI_2, G_PI);
cairo_arc(draw, x + radius, y + radius, radius, G_PI, 1.5 * G_PI);
cairo_close_path(draw);

cairo_fill(draw);
}
else {
cairo_rectangle(draw, widget_padding_get_left(wid),
widget_padding_get_top(wid) + y,
widget_padding_get_remaining_width(wid), height);
cairo_fill(draw);
}
}