]> git.mdlowis.com Git - proto/labwc.git/commitdiff
img: remove padding_x from lab_img_render()
authortokyo4j <hrak1529@gmail.com>
Thu, 9 Jan 2025 08:20:08 +0000 (17:20 +0900)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Fri, 24 Jan 2025 22:27:21 +0000 (07:27 +0900)
padding_x in lab_img_render() was just to make sure window icons in the
titlebar doesn't get too close to adjacent buttons and it didn't felt
clean. To remove it from lab_img, this commit changes the size of window
icon buffers from (window.button.width)x(window.button.height) to
(window.button.width * 0.8)x(window.button.height) and horizontally
slide it by (window.button.width * 0.1) to keep the horizontal padding.

Note that the size of the hitbox for a window icon is kept the same and
nothing is changed from user's perspective.

include/common/scaled-img-buffer.h
include/img/img-svg.h
include/img/img.h
src/common/scaled-img-buffer.c
src/img/img-svg.c
src/img/img.c
src/ssd/ssd-part.c
src/ssd/ssd-titlebar.c

index d6ae02db96f3196bec946d75b347698606829010..27569a243be7892b3a709a3e8fb11c1386a52f47 100644 (file)
@@ -15,7 +15,6 @@ struct scaled_img_buffer {
        struct lab_img *img;
        int width;
        int height;
-       int padding;
 };
 
 /*
@@ -65,11 +64,11 @@ struct scaled_img_buffer {
  * free to destroy it.
  */
 struct scaled_img_buffer *scaled_img_buffer_create(struct wlr_scene_tree *parent,
-       struct lab_img *img, int width, int height, int padding);
+       struct lab_img *img, int width, int height);
 
-/* Update image, width, height and padding of the scaled_img_buffer */
+/* Update image, width and height of the scaled_img_buffer */
 void scaled_img_buffer_update(struct scaled_img_buffer *self,
-       struct lab_img *img, int width, int height, int padding);
+       struct lab_img *img, int width, int height);
 
 /* Obtain scaled_img_buffer from wlr_scene_node */
 struct scaled_img_buffer *scaled_img_buffer_from_node(struct wlr_scene_node *node);
index 8790c268f9793604a134f761c29aa0ec83a71a09..33293314735ffc88d442497ce46620d93546e7e5 100644 (file)
@@ -9,6 +9,6 @@ struct lab_data_buffer;
 RsvgHandle *img_svg_load(const char *filename);
 
 struct lab_data_buffer *img_svg_render(RsvgHandle *svg, int w, int h,
-       int padding, double scale);
+       double scale);
 
 #endif /* LABWC_IMG_SVG_H */
index 5ad7c737e1deb75920774529a420555a197c9fd8..f299335ed68ca53e9e003c5e738de9289266e8a0 100644 (file)
@@ -59,11 +59,10 @@ void lab_img_add_modifier(struct lab_img *img, lab_img_modifier_func_t modifier)
  * @img: source image
  * @width: width of the created buffer
  * @height: height of the created buffer
- * @padding_x: horizontal padding around the rendered image in the buffer
  * @scale: scale of the created buffer
  */
 struct lab_data_buffer *lab_img_render(struct lab_img *img,
-       int width, int height, int padding_x, double scale);
+       int width, int height, double scale);
 
 /**
  * lab_img_destroy() - destroy lab_img
index ed5d02768c2fde2747e22bbd3b13c6e446b8778e..99ab7b24398ffafe18ca971c95ebe768b2d273e7 100644 (file)
@@ -15,7 +15,7 @@ _create_buffer(struct scaled_scene_buffer *scaled_buffer, double scale)
 {
        struct scaled_img_buffer *self = scaled_buffer->data;
        struct lab_data_buffer *buffer = lab_img_render(self->img,
-               self->width, self->height, self->padding, scale);
+               self->width, self->height, scale);
        return buffer;
 }
 
@@ -36,8 +36,7 @@ _equal(struct scaled_scene_buffer *scaled_buffer_a,
 
        return lab_img_equal(a->img, b->img)
                && a->width == b->width
-               && a->height == b->height
-               && a->padding == b->padding;
+               && a->height == b->height;
 }
 
 static struct scaled_scene_buffer_impl impl = {
@@ -48,7 +47,7 @@ static struct scaled_scene_buffer_impl impl = {
 
 struct scaled_img_buffer *
 scaled_img_buffer_create(struct wlr_scene_tree *parent, struct lab_img *img,
-       int width, int height, int padding)
+       int width, int height)
 {
        assert(img);
        struct scaled_scene_buffer *scaled_buffer = scaled_scene_buffer_create(
@@ -59,7 +58,6 @@ scaled_img_buffer_create(struct wlr_scene_tree *parent, struct lab_img *img,
        self->img = lab_img_copy(img);
        self->width = width;
        self->height = height;
-       self->padding = padding;
 
        scaled_buffer->data = self;
 
@@ -70,14 +68,13 @@ scaled_img_buffer_create(struct wlr_scene_tree *parent, struct lab_img *img,
 
 void
 scaled_img_buffer_update(struct scaled_img_buffer *self, struct lab_img *img,
-       int width, int height, int padding)
+       int width, int height)
 {
        assert(img);
        lab_img_destroy(self->img);
        self->img = lab_img_copy(img);
        self->width = width;
        self->height = height;
-       self->padding = padding;
        scaled_scene_buffer_request_update(self->scaled_buffer, width, height);
 }
 
index b7274d0f5aadeb6d6d37b79d0e127379472af330..b5bf8670df7666947145725c180d92ccb154e755 100644 (file)
@@ -36,7 +36,7 @@ img_svg_load(const char *filename)
 }
 
 struct lab_data_buffer *
-img_svg_render(RsvgHandle *svg, int w, int h, int padding_x, double scale)
+img_svg_render(RsvgHandle *svg, int w, int h, double scale)
 {
        struct lab_data_buffer *buffer = buffer_create_cairo(w, h, scale);
        cairo_surface_t *image = buffer->surface;
@@ -44,9 +44,7 @@ img_svg_render(RsvgHandle *svg, int w, int h, int padding_x, double scale)
        GError *err = NULL;
 
        RsvgRectangle viewport = {
-               .x = padding_x,
-               .y = 0,
-               .width = w - 2 * padding_x,
+               .width = w,
                .height = h,
        };
        rsvg_handle_render_document(svg, cr, &viewport, &err);
index 8a7fe2f5591b280101a7bf50c6d5c33b9ea47e44..5e4b473feab5973cc269618d0e211856ba80f0b0 100644 (file)
@@ -119,7 +119,7 @@ lab_img_add_modifier(struct lab_img *img,  lab_img_modifier_func_t modifier)
  */
 static struct lab_data_buffer *
 render_cairo_surface(cairo_surface_t *surface, int width, int height,
-       int padding_x, double scale)
+       double scale)
 {
        assert(surface);
        int src_w = cairo_image_surface_get_width(surface);
@@ -130,9 +130,7 @@ render_cairo_surface(cairo_surface_t *surface, int width, int height,
        cairo_t *cairo = cairo_create(buffer->surface);
 
        struct wlr_box container = {
-               .x = padding_x,
-               .y = 0,
-               .width = width - 2 * padding_x,
+               .width = width,
                .height = height,
        };
 
@@ -151,8 +149,7 @@ render_cairo_surface(cairo_surface_t *surface, int width, int height,
 }
 
 struct lab_data_buffer *
-lab_img_render(struct lab_img *img, int width, int height, int padding,
-       double scale)
+lab_img_render(struct lab_img *img, int width, int height, double scale)
 {
        struct lab_data_buffer *buffer = NULL;
 
@@ -162,12 +159,12 @@ lab_img_render(struct lab_img *img, int width, int height, int padding,
        case LAB_IMG_XBM:
        case LAB_IMG_XPM:
                buffer = render_cairo_surface(img->data->buffer->surface,
-                       width, height, padding, scale);
+                       width, height, scale);
                break;
 #if HAVE_RSVG
        case LAB_IMG_SVG:
                buffer = img_svg_render(img->data->svg, width, height,
-                       padding, scale);
+                       scale);
                break;
 #endif
        default:
index b9c09c3e2051af66d1441c996fd99a33304b9aa4..37176cd71f4654391154db3cfe07ec0b109014c6 100644 (file)
@@ -108,7 +108,7 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
                struct ssd_part *icon_part = add_scene_part(part_list, type);
                struct scaled_img_buffer *img_buffer = scaled_img_buffer_create(
                        parent, imgs[state_set], rc.theme->window_button_width,
-                       rc.theme->window_button_height, /* padding_x */ 0);
+                       rc.theme->window_button_height);
                assert(img_buffer);
                icon_part->node = &img_buffer->scene_buffer->node;
                wlr_scene_node_set_enabled(icon_part->node, false);
index 6220cb8a525d854f361dd73340669c6039f84ab9..6ffb1ce136c41128f3e225d696d40948c09331f9 100644 (file)
@@ -632,9 +632,9 @@ ssd_update_window_icon(struct ssd *ssd)
                                struct scaled_img_buffer *img_buffer =
                                        scaled_img_buffer_from_node(node);
                                scaled_img_buffer_update(img_buffer, icon_img,
-                                       theme->window_button_width,
-                                       theme->window_button_height,
-                                       icon_padding);
+                                       theme->window_button_width - 2 * icon_padding,
+                                       theme->window_button_height);
+                               wlr_scene_node_set_position(node, icon_padding, 0);
                        }
                }
        } FOR_EACH_END