Extends former behavior to include loading of icons if they are

specified as an absolute path. Fixes size selection for SVG (scalable)
icons relying on whose nominal size read via gdk-pixbuf loader may not
correctly indicate that they can be scaled to neatly fill the available
scale e.g., symbolic icons from Adwaita specify a nominal size of 16x16.
This commit is contained in:
myrslint 2025-04-30 02:32:07 +00:00
parent aeeb99c5a3
commit 17dc5071fd
4 changed files with 50 additions and 23 deletions

View file

@ -104,11 +104,27 @@ static cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(
}
#endif // HAVE_GDK_PIXBUF
cairo_surface_t *load_image(const char *path) {
cairo_surface_t *load_image(const char *path, int target_size, int scale) {
cairo_surface_t *image;
#if HAVE_GDK_PIXBUF
GError *err = NULL;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &err);
GdkPixbuf *pixbuf = NULL;
// svg images should be loaded at target size. the size read from an svg
// file is only nominal and can lead to an image too small for the avaialble
// space compared to bitmap icons selected at the nearest available size
int i = strlen(path) - 1;
// this is naive and assumes ascii, utf-8, or another encoding
// that encodes these letters as single bytes
if ((i > 2) &&
(path[i] == 'g' || path[i] == 'G') && \
(path[i - 1] == 'v' || path[i - 1] == 'V') && \
(path[i - 2] == 's' || path[i - 2] == 'S') && \
(path[i - 3] == '.' )) {
pixbuf = gdk_pixbuf_new_from_file_at_scale(path, -1, target_size, \
true, &err);
} else {
pixbuf = gdk_pixbuf_new_from_file(path, &err);
}
if (!pixbuf) {
sway_log(SWAY_ERROR, "Failed to load background image (%s).",
err->message);