diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 7251b1fd6..d44fb3418 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -10518,6 +10518,56 @@ get_visible_range (GtkTreePath **start, GtkTreePath **end, g_assert_not_reached (); } +/* Hidden files and backups are shown with a dimmed icon, as in file + * managers: half transparent. The dimmed icon is made once and kept in + * the model like any other, so drawing it costs nothing more; the name + * stays as readable as the others. */ +static GdkPixbuf * +file_icon_dim (GtkWidget *widget, + GdkPixbuf *pixbuf) +{ + GdkPixbuf *dimmed; + guchar *pixels; + gint width, height, rowstride, x, y; + + if (pixbuf == NULL) + return NULL; + + dimmed = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0); + g_object_unref (pixbuf); + if (dimmed == NULL) + return NULL; + + pixels = gdk_pixbuf_get_pixels (dimmed); + width = gdk_pixbuf_get_width (dimmed); + height = gdk_pixbuf_get_height (dimmed); + rowstride = gdk_pixbuf_get_rowstride (dimmed); + + for (y = 0; y < height; y++) + { + guchar *p = pixels + y * rowstride + 3; + + for (x = 0; x < width; x++, p += 4) + *p >>= 1; + } + + return dimmed; +} + +static GdkPixbuf * +file_icon_dim_if_hidden (GtkFileChooserDefault *impl, + GFileInfo *info, + GdkPixbuf *pixbuf) +{ + if ((g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) && + g_file_info_get_is_hidden (info)) || + (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP) && + g_file_info_get_is_backup (info))) + return file_icon_dim (GTK_WIDGET (impl), pixbuf); + + return pixbuf; +} + static gboolean file_system_model_set (GtkFileSystemModel *model, GFile *file, @@ -10609,7 +10659,8 @@ file_system_model_set (GtkFileSystemModel *model, icon_size = FALLBACK_LIST_VIEW_ICON_SIZE; } - g_value_take_object (value, _gtk_file_info_render_icon (info, GTK_WIDGET (impl), icon_size)); + g_value_take_object (value, file_icon_dim_if_hidden (impl, info, + _gtk_file_info_render_icon (info, GTK_WIDGET (impl), icon_size))); return TRUE; }