From fe6b3c1c35d9bdbb92359c829c05236d6d72bec8 Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Sat, 12 Oct 2024 15:06:23 +0900 Subject: [PATCH] theme: replace *.hover.bg.shape with *.hover.bg.corner-radius --- docs/labwc-theme.5.scd | 10 ++++++--- docs/themerc | 2 +- include/theme.h | 9 ++------- src/theme.c | 46 +++++++++++++++++++----------------------- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/docs/labwc-theme.5.scd b/docs/labwc-theme.5.scd index 61d915fa..7ecabe7a 100644 --- a/docs/labwc-theme.5.scd +++ b/docs/labwc-theme.5.scd @@ -126,9 +126,13 @@ labwc-config(5). Space between titlebar buttons, in pixels. Default is 0. -*window.button.hover.bg.shape* - The shape of the hover effect of a titlebar button: "rectangle" or "circle". - Default is "rectangle". +*window.button.hover.bg.corner-radius* + Radius of the hover effect of a titlebar button, in pixels. + Default is 0. + + Note: for a circular hover effect, set *window.button.width* and + *window.button.height* equal and *window.button.hover.bg.corner-radius* half + of them. *window.active.button.unpressed.image.color* Color of the images in titlebar buttons in their default, unpressed, diff --git a/docs/themerc b/docs/themerc index 4ebccea9..b3de250a 100644 --- a/docs/themerc +++ b/docs/themerc @@ -36,7 +36,7 @@ window.button.width: 26 window.button.spacing: 0 # window button hover effect -window.button.hover.bg.shape: rectangle +window.button.hover.bg.corner-radius: 0 # window buttons window.active.button.unpressed.image.color: #000000 diff --git a/include/theme.h b/include/theme.h index e4c8c382..2b600676 100644 --- a/include/theme.h +++ b/include/theme.h @@ -18,11 +18,6 @@ enum lab_justification { LAB_JUSTIFY_RIGHT, }; -enum lab_shape { - LAB_RECTANGLE, - LAB_CIRCLE, -}; - struct theme_snapping_overlay { bool bg_enabled; bool border_enabled; @@ -72,8 +67,8 @@ struct theme { int window_button_height; int window_button_spacing; - /* the shape of the hover effect */ - enum lab_shape window_button_hover_bg_shape; + /* the corner radius of the hover effect */ + int window_button_hover_bg_corner_radius; int menu_item_padding_x; int menu_item_padding_y; diff --git a/src/theme.c b/src/theme.c index 48c054eb..b813219d 100644 --- a/src/theme.c +++ b/src/theme.c @@ -147,18 +147,19 @@ create_hover_fallback(struct theme *theme, /* Overlay (pre-multiplied alpha) */ float overlay_color[4] = { 0.15f, 0.15f, 0.15f, 0.3f}; set_cairo_color(cairo, overlay_color); - int radius = MIN(width, height) / 2; - - switch (theme->window_button_hover_bg_shape) { - case LAB_CIRCLE: - cairo_arc(cairo, width / 2, height / 2, radius, 0 * deg, 360 * deg); - break; - case LAB_RECTANGLE: - cairo_rectangle(cairo, 0, 0, width, height); - break; - } + int radius = theme->window_button_hover_bg_corner_radius; + cairo_new_sub_path(cairo); + cairo_arc(cairo, radius, radius, radius, 180 * deg, 270 * deg); + cairo_line_to(cairo, width - radius, 0); + cairo_arc(cairo, width - radius, radius, radius, -90 * deg, 0 * deg); + cairo_line_to(cairo, width, height - radius); + cairo_arc(cairo, width - radius, height - radius, radius, 0 * deg, 90 * deg); + cairo_line_to(cairo, radius, height); + cairo_arc(cairo, radius, height - radius, radius, 90 * deg, 180 * deg); + cairo_close_path(cairo); cairo_fill(cairo); + cairo_surface_flush(cairo_get_target(cairo)); } @@ -542,18 +543,6 @@ parse_justification(const char *str) } } -static enum lab_shape -parse_shape(const char *str) -{ - if (!strcasecmp(str, "Rectangle")) { - return LAB_RECTANGLE; - } else if (!strcasecmp(str, "Circle")) { - return LAB_CIRCLE; - } else { - return LAB_RECTANGLE; - } -} - /* * We generally use Openbox defaults, but if no theme file can be found it's * better to populate the theme variables with some sane values as no-one @@ -592,7 +581,7 @@ theme_builtin(struct theme *theme, struct server *server) theme->window_button_width = 26; theme->window_button_height = 26; theme->window_button_spacing = 0; - theme->window_button_hover_bg_shape = LAB_RECTANGLE; + theme->window_button_hover_bg_corner_radius = 0; for (enum ssd_part_type type = LAB_SSD_BUTTON_FIRST; type <= LAB_SSD_BUTTON_LAST; type++) { @@ -785,8 +774,9 @@ entry(struct theme *theme, const char *key, const char *value) theme->window_button_spacing = get_int_if_positive( value, "window.button.spacing"); } - if (match_glob(key, "window.button.hover.bg.shape")) { - theme->window_button_hover_bg_shape = parse_shape(value); + if (match_glob(key, "window.button.hover.bg.corner-radius")) { + theme->window_button_hover_bg_corner_radius = get_int_if_positive( + value, "window.button.hover.bg.corner-radius"); } /* universal button */ @@ -1491,6 +1481,12 @@ post_processing(struct theme *theme) rc.corner_radius = theme->title_height - 1; } + int min_button_hover_radius = + MIN(theme->window_button_width, theme->window_button_height) / 2; + if (theme->window_button_hover_bg_corner_radius > min_button_hover_radius) { + theme->window_button_hover_bg_corner_radius = min_button_hover_radius; + } + if (theme->menu_max_width < theme->menu_min_width) { wlr_log(WLR_ERROR, "Adjusting menu.width.max: .max (%d) lower than .min (%d)", -- 2.52.0