]> git.mdlowis.com Git - proto/labwc.git/commitdiff
ssd: scale down button icons if necessary
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Fri, 23 Dec 2022 21:59:27 +0000 (22:59 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 29 Dec 2022 22:19:13 +0000 (22:19 +0000)
This allows using large XBM button icons (larger than
the button width / height) for high and mixed DPI usecases.

Instead of scaling up the low pixel icons when moving a window to a
high DPI output we scale the icons down when moving to a non-scaled
output. The user is still responsible to create / use larger XBM
icons for their theme.

Partly fixes #609

src/ssd/ssd_part.c

index 8a87239e56270a3b5ac790380db16357464e4250..d7cf19c5db608d00f2ef2d2c7a2133cf0ee979dc 100644 (file)
@@ -112,6 +112,34 @@ add_scene_button_corner(struct wl_list *part_list, enum ssd_part_type type,
        return button_root;
 }
 
+static struct wlr_box
+get_scale_box(struct wlr_buffer *buffer, double container_width,
+               double container_height)
+{
+       struct wlr_box icon_geo = {
+               .width = buffer->width,
+               .height = buffer->height
+       };
+
+       /* Scale down buffer if required */
+       if (icon_geo.width && icon_geo.height) {
+               #define MIN(a, b) ((a) < (b) ? (a) : (b))
+               double scale = MIN(container_width / icon_geo.width,
+                       container_height / icon_geo.height);
+               #undef MIN
+               if (scale < 1.0f) {
+                       icon_geo.width = (double)icon_geo.width * scale;
+                       icon_geo.height = (double)icon_geo.height * scale;
+               }
+       }
+
+       /* Center buffer on both axis */
+       icon_geo.x = (container_width - icon_geo.width) / 2;
+       icon_geo.y = (container_height - icon_geo.height) / 2;
+
+       return icon_geo;
+}
+
 struct ssd_part *
 add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
                struct wlr_scene_tree *parent, float *bg_color,
@@ -130,9 +158,15 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
                BUTTON_WIDTH, rc.theme->title_height, 0, 0, bg_color);
 
        /* Icon */
-       add_scene_buffer(part_list, type, parent, icon_buffer,
-               (BUTTON_WIDTH - icon_buffer->width) / 2,
-               (rc.theme->title_height - icon_buffer->height) / 2);
+       struct wlr_box icon_geo = get_scale_box(icon_buffer,
+               BUTTON_WIDTH, rc.theme->title_height);
+       struct ssd_part *icon_part = add_scene_buffer(part_list, type,
+               parent, icon_buffer, icon_geo.x, icon_geo.y);
+
+       /* Make sure big icons are scaled down if necessary */
+       wlr_scene_buffer_set_dest_size(
+               wlr_scene_buffer_from_node(icon_part->node),
+               icon_geo.width, icon_geo.height);
 
        /* Hover overlay */
        hover = add_scene_rect(part_list, type, parent, BUTTON_WIDTH,