[nautilus/wip/antoniof/hidpi-and-icons-cleanup: 9/11] file: Support HiDPI icons




commit ca15ae9d878ac8e8a6d0f39f4b4ac40326a2fb6a
Author: António Fernandes <antoniof gnome org>
Date:   Mon Aug 8 00:23:22 2022 +0100

    file: Support HiDPI icons
    
    This brings back a feature originally introduced by commit 0d4555d76f86ba2d49f48836b7eea11f1adfb2fd
    
    Back then, it used gdk_cairo_surface_create_from_pixbuf() to apply the
    scaling factor, but in GTK 4 we can no longer consume cairo surfaces
    directly. Instead, we are to use paintables.
    
    For themed icons we already use GtkIconPaintable, which just works.
    
    For thumbnails, which we get in the form of GdkPixbuf, we need to
    snapshot them into the final logical area. For that, divide the
    snapshot height and width by the scale factor.

 src/nautilus-file.c      | 11 ++++-------
 src/nautilus-grid-cell.c |  4 +++-
 src/nautilus-name-cell.c |  4 +++-
 3 files changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index dafc9a915..62980f6c4 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -5143,24 +5143,21 @@ nautilus_file_get_thumbnail_icon (NautilusFile          *file,
                                   NautilusFileIconFlags  flags)
 {
     g_autoptr (GdkPaintable) paintable = NULL;
-    int modified_size;
     NautilusIconInfo *icon;
 
     icon = NULL;
 
-    modified_size = size * scale;
-
     if (file->details->thumbnail != NULL)
     {
         GdkPixbuf *pixbuf = file->details->thumbnail;
-        double width = gdk_pixbuf_get_width (pixbuf);
-        double height = gdk_pixbuf_get_height (pixbuf);
+        double width = gdk_pixbuf_get_width (pixbuf) / scale;
+        double height = gdk_pixbuf_get_height (pixbuf) / scale;
         g_autoptr (GdkTexture) texture = gdk_texture_new_for_pixbuf (pixbuf);
         g_autoptr (GtkSnapshot) snapshot = gtk_snapshot_new ();
 
-        if (MAX (width, height) > modified_size)
+        if (MAX (width, height) > size)
         {
-            float scale_down_factor = MAX (width, height) / modified_size;
+            float scale_down_factor = MAX (width, height) / size;
 
             width = width / scale_down_factor;
             height = height / scale_down_factor;
diff --git a/src/nautilus-grid-cell.c b/src/nautilus-grid-cell.c
index 63d9dc576..a6361d88d 100644
--- a/src/nautilus-grid-cell.c
+++ b/src/nautilus-grid-cell.c
@@ -34,15 +34,17 @@ update_icon (NautilusGridCell *self)
     GtkStyleContext *style_context;
     NautilusFile *file;
     guint icon_size;
+    gint scale_factor;
     g_autofree gchar *thumbnail_path = NULL;
 
     item = nautilus_view_cell_get_item (NAUTILUS_VIEW_CELL (self));
     g_return_if_fail (item != NULL);
     file = nautilus_view_item_get_file (item);
     icon_size = nautilus_view_item_get_icon_size (item);
+    scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
     flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS;
 
-    icon_paintable = nautilus_file_get_icon_paintable (file, icon_size, 1, flags);
+    icon_paintable = nautilus_file_get_icon_paintable (file, icon_size, scale_factor, flags);
     gtk_picture_set_paintable (GTK_PICTURE (self->icon), icon_paintable);
 
     /* Set the same height and width for all icons regardless of aspect ratio.
diff --git a/src/nautilus-name-cell.c b/src/nautilus-name-cell.c
index bab99561b..a58415f9e 100644
--- a/src/nautilus-name-cell.c
+++ b/src/nautilus-name-cell.c
@@ -128,6 +128,7 @@ update_icon (NautilusNameCell *self)
     NautilusViewItem *item;
     NautilusFile *file;
     guint icon_size;
+    gint scale_factor;
     int icon_height;
     int extra_margin;
     g_autofree gchar *thumbnail_path = NULL;
@@ -137,9 +138,10 @@ update_icon (NautilusNameCell *self)
 
     file = nautilus_view_item_get_file (item);
     icon_size = nautilus_view_item_get_icon_size (item);
+    scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
     flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS;
 
-    icon_paintable = nautilus_file_get_icon_paintable (file, icon_size, 1, flags);
+    icon_paintable = nautilus_file_get_icon_paintable (file, icon_size, scale_factor, flags);
     gtk_picture_set_paintable (GTK_PICTURE (self->icon), icon_paintable);
 
     /* Set the same width for all icons regardless of aspect ratio.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]