From: Debian Qt/KDE Maintainers Date: Fri, 2 Aug 2024 15:24:23 +0000 (+0300) Subject: QGtk3Theme: fix QGtk3Interface::fileIcon X-Git-Tag: archive/raspbian/6.6.2+dfsg-11+rpi1^2~15 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=32096e7cd187f4e861c69ba5d5d6f8b1447214dd;p=qt6-base.git QGtk3Theme: fix QGtk3Interface::fileIcon Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=277d77029d7fe8f4 Last-Update: 2024-08-02 By failing to set the G_FILE_ATTRIBUTE_STANDARD_ICON attribute, the "icon" returned by g_file_info_get_icon was always null and a GLib-GIO-CRITICAL warning was output to the console (at least since glib 2.76.0)[1]. After adding the necessary attribute, the code was crashing, because now a valid icon was returned, however the icon should not be freed[2], which is why I removed the "g_object_unref(icon)". Now it was no longer crashing, but the size of the icons was off. It was passing GTK_ICON_SIZE_BUTTON (4) to gtk_icon_theme_lookup_by_gicon where a size in pixels was expected. I chose 16 because that's the pixel size associated with GTK_ICON_SIZE_BUTTON[3]. Finally I noticed the returned icons had the wrong color. It seems that a GdkPixbuf uses RGBA8888 format[4]. Adding an explicit conversion to ARGB32 made the icons look correct for me. [1] https://gitlab.gnome.org/GNOME/glib/-/commit/ed8e86a7d41a0900d8fa57edc64264d04cf8135b [2] https://docs.gtk.org/gio/method.FileInfo.get_icon.html [3] https://docs.gtk.org/gtk3/enum.IconSize.html#button [4] https://docs.gtk.org/gdk-pixbuf/class.Pixbuf.html#image-data Gbp-Pq: Name fix_qgtk3interface_fileicon.patch --- diff --git a/src/plugins/platformthemes/gtk3/qgtk3interface.cpp b/src/plugins/platformthemes/gtk3/qgtk3interface.cpp index 5229cb73..18c6c5e3 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3interface.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3interface.cpp @@ -296,8 +296,10 @@ QImage QGtk3Interface::qt_convert_gdk_pixbuf(GdkPixbuf *buf) const const int width = gdk_pixbuf_get_width(buf); const int height = gdk_pixbuf_get_height(buf); const int bpl = gdk_pixbuf_get_rowstride(buf); - QImage converted(data, width, height, bpl, QImage::Format_ARGB32); - return converted.copy(); // detatch to survive lifetime of buf + QImage converted(data, width, height, bpl, QImage::Format_RGBA8888); + + // convert to more optimal format and detach to survive lifetime of buf + return converted.convertToFormat(QImage::Format_ARGB32_Premultiplied); } /*! @@ -666,7 +668,7 @@ QIcon QGtk3Interface::fileIcon(const QFileInfo &fileInfo) const if (!file) return QIcon(); - GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, nullptr, nullptr); if (!info) { g_object_unref(file); @@ -681,12 +683,11 @@ QIcon QGtk3Interface::fileIcon(const QFileInfo &fileInfo) const } GtkIconTheme *theme = gtk_icon_theme_get_default(); - GtkIconInfo *iconInfo = gtk_icon_theme_lookup_by_gicon(theme, icon, GTK_ICON_SIZE_BUTTON, + GtkIconInfo *iconInfo = gtk_icon_theme_lookup_by_gicon(theme, icon, 16, GTK_ICON_LOOKUP_FORCE_SIZE); if (!iconInfo) { g_object_unref(file); g_object_unref(info); - g_object_unref(icon); return QIcon(); } @@ -694,7 +695,6 @@ QIcon QGtk3Interface::fileIcon(const QFileInfo &fileInfo) const QImage image = qt_convert_gdk_pixbuf(buf); g_object_unref(file); g_object_unref(info); - g_object_unref(icon); g_object_unref(buf); return QIcon(QPixmap::fromImage(image)); }