From 2c61610db7bbd197ecfd22567212d04506011a3a 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: Wed, 27 May 2026 07:56:55 +0300 Subject: [PATCH] [Gtk4] Keep allocation after show-allocate hack in Control.setBounds On Gtk 4 gtk_widget_hide() resets the widget's allocation to 0x0. If the SWT widget is no longer in the HIDDEN state but visibility hasn't propagated in GTK 4, leave it visible on the GTK side so its allocation (and the propagated allocations of its children) survive. Otherwise children of a Composite that was made visible right before this setBounds call would be left at size 0x0 and miss Resize events. Skip the trailing gtk_widget_hide() on GTK4 when the SWT widget is not in the HIDDEN state, so the allocation survives. GTK3 behaviour is unchanged. Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/3330 --- .../gtk/org/eclipse/swt/widgets/Control.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index 88f7a051de..3c702a557b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -1175,7 +1175,18 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize gtk_widget_show(topHandle); gtk_widget_get_preferred_size (topHandle, requisition); gtk_widget_size_allocate(topHandle, allocation, -1); - gtk_widget_hide(topHandle); + /* + * On Gtk 4 gtk_widget_hide() resets the widget's allocation to 0x0. If the SWT + * widget is no longer in the HIDDEN state but visibility hasn't propagated in + * GTK 4, leave it visible on the GTK side so its allocation (and the propagated + * allocations of its children) survive. Otherwise children of a Composite that + * was made visible right before this setBounds call would be left at size 0x0 + * and miss Resize events. See + * https://github.com/eclipse-platform/eclipse.platform.swt/issues/3330 + */ + if (!GTK.GTK4 || (state & HIDDEN) != 0) { + gtk_widget_hide(topHandle); + } /* Bug 540002: Showing and hiding widget causes original focused control to loose focus, * Reset focus to original focused control after dealing with allocation. */ @@ -1184,6 +1195,8 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize } } else { if (GTK.GTK4) { + // Prevent GTK+ allocation warnings, preferred size should be retrieved before setting allocation size. + GTK.gtk_widget_get_preferred_size(topHandle, null, null); GTK4.gtk_widget_size_allocate (topHandle, allocation, -1); } else { // Prevent GTK+ allocation warnings, preferred size should be retrieved before setting allocation size.