Skip to content
Permalink
Browse files

Support HiDpi icons

Port the rendering of icons to cairo surfaces, so that we can apply the
GDK scale factor when rendering icons.

origin commit:
https://gitlab.gnome.org/GNOME/nautilus/commit/0d4555d7
  • Loading branch information...
cosimoc authored and lukefromdc committed Aug 2, 2013
1 parent 779e0af commit bc1405c9f54e19e74f973581130229ef1053ff9c
@@ -469,7 +469,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
GtkListStore *list_store;
GtkTreeIter iter;
GdkPixbuf *pixbuf;
int icon_size;
int icon_size, icon_scale;
int set_active;
int n;
int num_apps;
@@ -485,6 +485,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;

icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
icon_scale = gtk_widget_get_scale_factor (combo_box);

set_active = -1;
data = NULL;
@@ -594,7 +595,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
*/

icon = g_app_info_get_icon (app_info);
icon_info = caja_icon_info_lookup (icon, icon_size);
icon_info = caja_icon_info_lookup (icon, icon_size, icon_scale);
pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
g_object_unref (icon_info);

@@ -935,7 +936,7 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
GIcon *icon;
GdkPixbuf *pixbuf;
CajaIconInfo *icon_info;
int icon_size;
int icon_size, icon_scale;
gboolean user_forced_dialog;
gboolean pref_ask;
gboolean pref_start_app;
@@ -999,7 +1000,8 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto

icon = g_mount_get_icon (mount);
icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG);
icon_info = caja_icon_info_lookup (icon, icon_size);
icon_scale = gtk_widget_get_scale_factor (dialog);
icon_info = caja_icon_info_lookup (icon, icon_size, icon_scale);
pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
g_object_unref (icon_info);
g_object_unref (icon);
@@ -220,7 +220,7 @@ caja_bookmark_get_pixbuf (CajaBookmark *bookmark,
GdkPixbuf *result;
GIcon *icon;
CajaIconInfo *info;
int pixel_size;
int pixel_size, pixel_scale;


g_return_val_if_fail (CAJA_IS_BOOKMARK (bookmark), NULL);
@@ -232,7 +232,8 @@ caja_bookmark_get_pixbuf (CajaBookmark *bookmark,
}

pixel_size = caja_get_icon_size_for_stock_size (stock_size);
info = caja_icon_info_lookup (icon, pixel_size);
pixel_scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());
info = caja_icon_info_lookup (icon, pixel_size, pixel_scale);
result = caja_icon_info_get_pixbuf_at_size (info, pixel_size);
g_object_unref (info);

@@ -80,6 +80,7 @@ file_icons_changed (CajaFile *file,
pixbuf = caja_file_get_icon_pixbuf (fcd->details->destination,
CAJA_ICON_SIZE_LARGE,
TRUE,
gtk_widget_get_scale_factor (fcd->details->dest_image),
CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS);

gtk_image_set_from_pixbuf (GTK_IMAGE (fcd->details->dest_image), pixbuf);
@@ -88,6 +89,7 @@ file_icons_changed (CajaFile *file,
pixbuf = caja_file_get_icon_pixbuf (fcd->details->source,
CAJA_ICON_SIZE_LARGE,
TRUE,
gtk_widget_get_scale_factor (fcd->details->src_image),
CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS);

gtk_image_set_from_pixbuf (GTK_IMAGE (fcd->details->src_image), pixbuf);
@@ -239,6 +241,7 @@ file_list_ready_cb (GList *files,
pixbuf = caja_file_get_icon_pixbuf (dest,
CAJA_ICON_SIZE_LARGE,
TRUE,
gtk_widget_get_scale_factor (fcd->details->titles_vbox),
CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS);
details->dest_image = gtk_image_new_from_pixbuf (pixbuf);
gtk_box_pack_start (GTK_BOX (details->first_hbox),
@@ -249,6 +252,7 @@ file_list_ready_cb (GList *files,
pixbuf = caja_file_get_icon_pixbuf (src,
CAJA_ICON_SIZE_LARGE,
TRUE,
gtk_widget_get_scale_factor (fcd->details->titles_vbox),
CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS);
details->src_image = gtk_image_new_from_pixbuf (pixbuf);
gtk_box_pack_start (GTK_BOX (details->second_hbox),
@@ -4288,6 +4288,7 @@ get_default_file_icon (CajaFileIconFlags flags)
CajaIconInfo *
caja_file_get_icon (CajaFile *file,
int size,
int scale,
CajaFileIconFlags flags)
{
CajaIconInfo *icon;
@@ -4303,7 +4304,7 @@ caja_file_get_icon (CajaFile *file,
if (gicon) {
GdkPixbuf *pixbuf;

icon = caja_icon_info_lookup (gicon, size);
icon = caja_icon_info_lookup (gicon, size, scale);
g_object_unref (gicon);

pixbuf = caja_icon_info_get_pixbuf (icon);
@@ -4313,7 +4314,7 @@ caja_file_get_icon (CajaFile *file,
}
g_object_unref (icon);

icon = caja_icon_info_new_for_pixbuf (pixbuf);
icon = caja_icon_info_new_for_pixbuf (pixbuf, scale);
g_object_unref (pixbuf);
}

@@ -4329,7 +4330,7 @@ caja_file_get_icon (CajaFile *file,
caja_file_should_show_thumbnail (file)) {
if (file->details->thumbnail) {
int w, h, s;
double scale;
double thumb_scale;

raw_pixbuf = g_object_ref (file->details->thumbnail);

@@ -4339,19 +4340,19 @@ caja_file_get_icon (CajaFile *file,
s = MAX (w, h);
/* Don't scale up small thumbnails in the standard view */
if (s <= cached_thumbnail_size) {
scale = (double)size / CAJA_ICON_SIZE_STANDARD;
thumb_scale = (double)size / CAJA_ICON_SIZE_STANDARD;
}
else {
scale = (double)modified_size / s;
thumb_scale = (double)modified_size / s;
}
/* Make sure that icons don't get smaller than CAJA_ICON_SIZE_SMALLEST */
if (s*scale <= CAJA_ICON_SIZE_SMALLEST) {
scale = (double) CAJA_ICON_SIZE_SMALLEST / s;
if (s*thumb_scale <= CAJA_ICON_SIZE_SMALLEST) {
thumb_scale = (double) CAJA_ICON_SIZE_SMALLEST / s;
}

scaled_pixbuf = gdk_pixbuf_scale_simple (raw_pixbuf,
MAX (w * scale, 1),
MAX (h * scale, 1),
MAX (w * thumb_scale, 1),
MAX (h * thumb_scale, 1),
GDK_INTERP_BILINEAR);

/* Render frames only for thumbnails of non-image files
@@ -4377,7 +4378,7 @@ caja_file_get_icon (CajaFile *file,
caja_file_invalidate_attributes (file, CAJA_FILE_ATTRIBUTE_THUMBNAIL);
}

icon = caja_icon_info_new_for_pixbuf (scaled_pixbuf);
icon = caja_icon_info_new_for_pixbuf (scaled_pixbuf, scale);
g_object_unref (scaled_pixbuf);
return icon;
} else if (file->details->thumbnail_path == NULL &&
@@ -4397,28 +4398,29 @@ caja_file_get_icon (CajaFile *file,
gicon = caja_file_get_gicon (file, flags);

if (gicon) {
icon = caja_icon_info_lookup (gicon, size);
icon = caja_icon_info_lookup (gicon, size, scale);
if (caja_icon_info_is_fallback (icon)) {
g_object_unref (icon);
icon = caja_icon_info_lookup (get_default_file_icon (flags), size);
icon = caja_icon_info_lookup (get_default_file_icon (flags), size, scale);
}
g_object_unref (gicon);
return icon;
} else {
return caja_icon_info_lookup (get_default_file_icon (flags), size);
return caja_icon_info_lookup (get_default_file_icon (flags), size, scale);
}
}

GdkPixbuf *
caja_file_get_icon_pixbuf (CajaFile *file,
int size,
gboolean force_size,
int scale,
CajaFileIconFlags flags)
{
CajaIconInfo *info;
GdkPixbuf *pixbuf;

info = caja_file_get_icon (file, size, flags);
info = caja_file_get_icon (file, size, scale, flags);
if (force_size) {
pixbuf = caja_icon_info_get_pixbuf_at_size (info, size);
} else {
@@ -6719,7 +6721,7 @@ caja_file_get_emblem_pixbufs (CajaFile *file,
for (l = icons; l != NULL; l = l->next) {
icon = l->data;

icon_info = caja_icon_info_lookup (icon, size);
icon_info = caja_icon_info_lookup (icon, size, 1);
if (force_size) {
pixbuf = caja_icon_info_get_pixbuf_nodefault_at_size (icon_info, size);
} else {
@@ -453,10 +453,12 @@ GIcon * caja_file_get_gicon (CajaFile
CajaFileIconFlags flags);
CajaIconInfo * caja_file_get_icon (CajaFile *file,
int size,
int scale,
CajaFileIconFlags flags);
GdkPixbuf * caja_file_get_icon_pixbuf (CajaFile *file,
int size,
gboolean force_size,
int scale,
CajaFileIconFlags flags);

gboolean caja_file_has_open_window (CajaFile *file);
Oops, something went wrong.

0 comments on commit bc1405c

Please sign in to comment.
You can’t perform that action at this time.