]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: replace *.hover.bg.shape with *.hover.bg.corner-radius
authortokyo4j <hrak1529@gmail.com>
Sat, 12 Oct 2024 06:06:23 +0000 (15:06 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 13 Oct 2024 11:31:51 +0000 (12:31 +0100)
docs/labwc-theme.5.scd
docs/themerc
include/theme.h
src/theme.c

index 61d915fa3a117ab750ac11ef9d048ad29321a1aa..7ecabe7adfb92a828fb92d20f88d7ccb3a87d8e7 100644 (file)
@@ -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,
index 4ebccea9dfb5afa66bc41a06c1e6b7a3f11edbae..b3de250a240373b22785908827594fa495768d3f 100644 (file)
@@ -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
index e4c8c382305d83e5e224963fb1595a2e94f86a4b..2b6006766b2333a8c16352c55b7068d30a5b02d9 100644 (file)
@@ -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;
index 48c054eb3bb890cca361bdee82a601e9bf3c3f76..b813219d945ff8d19cb0ef0e65fd33ff468d2c3c 100644 (file)
@@ -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)",