Skip to content

Commit

Permalink
[scrollbar] Add theming for rounded corners (#2108)
Browse files Browse the repository at this point in the history
* [scrollbar] Add theming for rounded corners

* rename "rounded-corners" to "handle-rounded-corners"
  • Loading branch information
J0hannes101 authored Mar 8, 2025
1 parent a993cea commit 56fd08e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
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);
}
}

0 comments on commit 56fd08e

Please sign in to comment.