From 6fa51a641ed8a7de7f087a327e4cd96bce410d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Mon, 25 May 2026 15:15:29 +0300 Subject: [PATCH] [Gtk4] Fix Button image size by using GtkPicture instead of GtkImage Gtk 4 works in logical points while Cairo works in pixel thus this is needed for proper size of the pixbuf scale to the original image size. This makes Button consistent with Label, which already uses GtkPicture for the same reason (see commit https://github.com/eclipse-platform/eclipse.platform.swt/pull/2766 ). Also fix a memory leak in Label where the GdkTexture created by gdk_texture_new_for_pixbuf() was not unreffed after being handed to gtk_picture_set_paintable(). --- .../gtk/org/eclipse/swt/widgets/Button.java | 11 ++++++++--- .../gtk/org/eclipse/swt/widgets/Label.java | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java index 3d03725768e..0771a49c492 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java @@ -385,7 +385,11 @@ void createHandle (int index) { labelHandle = GTK.gtk_label_new_with_mnemonic(null); if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES); - imageHandle = GTK.gtk_image_new(); + if (GTK.GTK4) { + imageHandle = GTK4.gtk_picture_new(); + } else { + imageHandle = GTK.gtk_image_new(); + } if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES); if (GTK.GTK4) { @@ -1156,13 +1160,14 @@ private void _setImage (Image image) { long pixbuf = ImageList.createPixbuf(image); long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf); OS.g_object_unref(pixbuf); - GTK4.gtk_image_set_from_paintable(imageHandle, texture); + GTK4.gtk_picture_set_paintable(imageHandle, texture); + OS.g_object_unref(texture); } else { GTK3.gtk_image_set_from_surface(imageHandle, image.surface); } } else { if (GTK.GTK4) { - GTK4.gtk_image_set_from_paintable(imageHandle, 0); + GTK4.gtk_picture_set_paintable(imageHandle, 0); } else { GTK3.gtk_image_set_from_surface(imageHandle, 0); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java index 730536e17e5..12806dfee32 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java @@ -651,6 +651,7 @@ public void setImage (Image image) { long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf); OS.g_object_unref(pixbuf); GTK4.gtk_picture_set_paintable(imageHandle, texture); + OS.g_object_unref(texture); } else { GTK3.gtk_image_set_from_surface(imageHandle, image.surface); }