vcl/unx/gtk3/gtkinst.cxx | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-)
New commits: commit 40b45db8117735b41802a1bfe487f33164a4a1ff Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Tue Jun 1 09:20:05 2021 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Tue Jun 1 12:19:17 2021 +0200 gtk4: adapt to gtk_icon_theme_lookup_icon changes Change-Id: I32b99c29b68c4aaaa892b2ce4e51953efe8c3388 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116517 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 8b684ea95f5a..66881f44e222 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -4340,25 +4340,59 @@ namespace return pRet; } +#if GTK_CHECK_VERSION(4, 0, 0) + cairo_surface_t* render_paintable_to_surface(GdkPaintable *paintable, int nWidth, int nHeight) + { + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nWidth, nHeight); + + GtkSnapshot* snapshot = gtk_snapshot_new(); + gdk_paintable_snapshot(paintable, snapshot, nWidth, nHeight); + GskRenderNode* node = gtk_snapshot_free_to_node(snapshot); + + cairo_t* cr = cairo_create(surface); + gsk_render_node_draw(node, cr); + cairo_destroy(cr); + + gsk_render_node_unref(node); + + return surface; + } +#endif + GdkPixbuf* getPixbuf(const OUString& rIconName) { if (rIconName.isEmpty()) return nullptr; GdkPixbuf* pixbuf = nullptr; -#if !GTK_CHECK_VERSION(4, 0, 0) if (rIconName.lastIndexOf('.') != rIconName.getLength() - 4) { assert((rIconName== "dialog-warning" || rIconName== "dialog-error" || rIconName== "dialog-information") && "unknown stock image"); - GError *error = nullptr; +#if GTK_CHECK_VERSION(4, 0, 0) + GtkIconTheme *icon_theme = gtk_icon_theme_get_for_display(gdk_display_get_default()); + GtkIconPaintable *icon = gtk_icon_theme_lookup_icon(icon_theme, + OUStringToOString(rIconName, RTL_TEXTENCODING_UTF8).getStr(), + nullptr, + 16, + 1, + AllSettings::GetLayoutRTL() ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR, + static_cast<GtkIconLookupFlags>(0)); + GdkPaintable* paintable = GDK_PAINTABLE(icon); + int nWidth = gdk_paintable_get_intrinsic_width(paintable); + int nHeight = gdk_paintable_get_intrinsic_height(paintable); + cairo_surface_t* surface = render_paintable_to_surface(paintable, nWidth, nHeight); + pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, nWidth, nHeight); + cairo_surface_destroy(surface); +#else GtkIconTheme *icon_theme = gtk_icon_theme_get_default(); + GError *error = nullptr; pixbuf = gtk_icon_theme_load_icon(icon_theme, OUStringToOString(rIconName, RTL_TEXTENCODING_UTF8).getStr(), 16, GTK_ICON_LOOKUP_USE_BUILTIN, &error); +#endif } else -#endif { const AllSettings& rSettings = Application::GetSettings(); pixbuf = load_icon_by_name_theme_lang(rIconName, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits