]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: round the corner button correctly
authortokyo4j <hrak1529@gmail.com>
Tue, 8 Oct 2024 21:41:52 +0000 (06:41 +0900)
committertokyo4j <hrak1529@gmail.com>
Tue, 8 Oct 2024 21:51:32 +0000 (06:51 +0900)
The rounded mask buffer to be applied to the corner button buffer should
be resized and shifted when there's a vertical gap between the button
and the window border.

src/theme.c

index 4e573c348ded7267b8c7e00d29d643ccd7b2c7d2..48c054eb3bb890cca361bdee82a601e9bf3c3f76 100644 (file)
@@ -174,14 +174,16 @@ create_rounded_buffer(struct theme *theme, enum corner corner,
        int height = theme->window_button_height;
 
        /*
-        * Round the hover overlay of corner buttons by
-        * cropping the region within the window border.
+        * Round the corner button by cropping the region within the window
+        * border. See the picture in #2189 for reference.
         */
+       int margin_x = theme->window_titlebar_padding_width;
+       int margin_y = (theme->title_height - theme->window_button_height) / 2;
        float white[4] = {1, 1, 1, 1};
        struct rounded_corner_ctx rounded_ctx = {
                .box = &(struct wlr_box){
-                       .width = theme->window_titlebar_padding_width + width,
-                       .height = height,
+                       .width = margin_x + width,
+                       .height = margin_y + height,
                },
                .radius = rc.corner_radius,
                .line_width = theme->border_width,
@@ -189,16 +191,11 @@ create_rounded_buffer(struct theme *theme, enum corner corner,
                .border_color = white,
                .corner = corner,
        };
-       int mask_offset;
-       if (corner == LAB_CORNER_TOP_LEFT) {
-               mask_offset = -theme->window_titlebar_padding_width;
-       } else {
-               mask_offset = 0;
-       }
        struct lab_data_buffer *mask_buffer = rounded_rect(&rounded_ctx);
        cairo_set_operator(cairo, CAIRO_OPERATOR_DEST_IN);
-       cairo_set_source_surface(cairo,
-               cairo_get_target(mask_buffer->cairo), mask_offset, 0);
+       cairo_set_source_surface(cairo, cairo_get_target(mask_buffer->cairo),
+               (corner == LAB_CORNER_TOP_LEFT) ? -margin_x : 0,
+               -margin_y);
        cairo_paint(cairo);
 
        cairo_surface_flush(cairo_get_target(cairo));