summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2019-10-01 04:11:14 -0400
committerraveit65 <[email protected]>2019-10-02 19:02:00 +0200
commita4fd9bb2b5693b6b57888938567212c46612c240 (patch)
tree7fbc2701de01247d0e57aadd9f732ae66f2accdf
parent042e80fe9d19810ca8154e8ffcede708c0cdc114 (diff)
downloadmate-control-center-a4fd9bb2b5693b6b57888938567212c46612c240.tar.bz2
mate-control-center-a4fd9bb2b5693b6b57888938567212c46612c240.tar.xz
icons: Force uniform size on icons (#505)
Also scale properly for HiDPI displays
-rw-r--r--libslab/mate-utils.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/libslab/mate-utils.c b/libslab/mate-utils.c
index 8dafe11a..e42d02c4 100644
--- a/libslab/mate-utils.c
+++ b/libslab/mate-utils.c
@@ -3,11 +3,12 @@
#include <string.h>
gboolean
-load_image_by_id (GtkImage * image, GtkIconSize size, const gchar * image_id)
+load_image_by_id (GtkImage *image, GtkIconSize size, const gchar *image_id)
{
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
gint width;
gint height;
+ gint scale_factor;
GtkIconTheme *icon_theme;
@@ -19,20 +20,25 @@ load_image_by_id (GtkImage * image, GtkIconSize size, const gchar * image_id)
return FALSE;
id = g_strdup (image_id);
+ scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (image));
gtk_icon_size_lookup (size, &width, &height);
gtk_image_set_pixel_size (image, width);
if (g_path_is_absolute (id))
{
- pixbuf = gdk_pixbuf_new_from_file_at_size (id, width, height, NULL);
+ GdkPixbuf *pixbuf;
+
+ pixbuf = gdk_pixbuf_new_from_file_at_size (id, width * scale_factor, height * scale_factor, NULL);
icon_exists = (pixbuf != NULL);
if (icon_exists)
{
- gtk_image_set_from_pixbuf (image, pixbuf);
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL);
+ gtk_image_set_from_surface (image, surface);
+ cairo_surface_destroy (surface);
g_object_unref (pixbuf);
}
else
@@ -55,11 +61,15 @@ load_image_by_id (GtkImage * image, GtkIconSize size, const gchar * image_id)
else
icon_theme = gtk_icon_theme_get_default ();
- pixbuf = gtk_icon_theme_load_icon (icon_theme, id, width, 0, NULL);
- icon_exists = (pixbuf != NULL);
+ surface = gtk_icon_theme_load_surface (icon_theme, id,
+ width, scale_factor,
+ NULL,
+ GTK_ICON_LOOKUP_FORCE_SIZE,
+ NULL);
+ icon_exists = (surface != NULL);
if (icon_exists) {
- gtk_image_set_from_pixbuf (image, pixbuf);
- g_object_unref (pixbuf);
+ gtk_image_set_from_surface (image, surface);
+ cairo_surface_destroy (surface);
}
else
gtk_image_set_from_icon_name (image, "image-missing", size);