You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qt6-base/debian/patches/fix_qgtk3interface_fileicon...

73 lines
3.2 KiB

Description: QGtk3Theme: fix QGtk3Interface::fileIcon
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
Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=277d77029d7fe8f4
Last-Update: 2024-08-02
--- a/src/plugins/platformthemes/gtk3/qgtk3interface.cpp
+++ b/src/plugins/platformthemes/gtk3/qgtk3interface.cpp
@@ -296,8 +296,10 @@ QImage QGtk3Interface::qt_convert_gdk_pi
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 QFi
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 QFi
}
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 QFi
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));
}