Skip to content

Commit 329ed24

Browse files
committed
[GTK4] Fix gtk_widget_measure warning
There is a flood of "(SWT:64178): Gtk-WARNING **: 12:04:34.730: Trying to measure GtkHeaderBar 0x7fb13846ca30 for width of 0, but it needs at least 137" like messages when developing. The issue is that gtk_widget_measure is being called with for_size=0 param which happens to be below the minimum size for many widgets. The documentation clearly states "If no size is known, -1 can be passed." and so is done now.
1 parent c79f530 commit 329ed24

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -855,14 +855,14 @@ Point computeNativeSize (long h, int wHint, int hHint, boolean changed) {
855855
int [] natural_size = new int [1];
856856
if (wHint == SWT.DEFAULT) {
857857
if (GTK.GTK4) {
858-
GTK4.gtk_widget_measure(h, GTK.GTK_ORIENTATION_HORIZONTAL, height, null, natural_size, null, null);
858+
GTK4.gtk_widget_measure(h, GTK.GTK_ORIENTATION_HORIZONTAL, height>0?height:-1, null, natural_size, null, null);
859859
} else {
860860
GTK3.gtk_widget_get_preferred_width_for_height (h, height, null, natural_size);
861861
}
862862
width = natural_size [0];
863863
} else {
864864
if (GTK.GTK4) {
865-
GTK4.gtk_widget_measure(h, GTK.GTK_ORIENTATION_VERTICAL, width, null, natural_size, null, null);
865+
GTK4.gtk_widget_measure(h, GTK.GTK_ORIENTATION_VERTICAL, width>0?width:-1, null, natural_size, null, null);
866866
} else {
867867
GTK3.gtk_widget_get_preferred_height_for_width (h, width, null, natural_size);
868868
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,7 @@ long gtk_size_allocate (long widget, long allocation) {
18621862
GDK.gdk_monitor_get_geometry(monitor, monitorSize);
18631863
long header = GTK4.gtk_widget_get_next_sibling(GTK4.gtk_widget_get_first_child(shellHandle));
18641864
int[] headerNaturalHeight = new int[1];
1865-
GTK4.gtk_widget_measure(header, GTK.GTK_ORIENTATION_VERTICAL, 0, null, headerNaturalHeight, null, null);
1865+
GTK4.gtk_widget_measure(header, GTK.GTK_ORIENTATION_VERTICAL, -1, null, headerNaturalHeight, null, null);
18661866
widthA[0] = monitorSize.width;
18671867
heightA[0] = monitorSize.height - headerNaturalHeight[0];
18681868
}
@@ -2377,7 +2377,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
23772377
*/
23782378
long header = GTK4.gtk_widget_get_next_sibling(GTK4.gtk_widget_get_first_child(shellHandle));
23792379
int[] headerNaturalHeight = new int[1];
2380-
GTK4.gtk_widget_measure(header, GTK.GTK_ORIENTATION_VERTICAL, 0, null, headerNaturalHeight, null, null);
2380+
GTK4.gtk_widget_measure(header, GTK.GTK_ORIENTATION_VERTICAL, -1, null, headerNaturalHeight, null, null);
23812381
GTK.gtk_window_set_default_size(shellHandle, width, height + headerNaturalHeight[0]);
23822382
} else {
23832383
GTK3.gtk_window_resize (shellHandle, width, height);
@@ -2544,7 +2544,7 @@ void setInitialBounds() {
25442544
long header = GTK4.gtk_window_get_titlebar(shellHandle);
25452545
int[] headerNaturalHeight = new int[1];
25462546
if (header != 0) {
2547-
GTK4.gtk_widget_measure(header, GTK.GTK_ORIENTATION_VERTICAL, 0, null, headerNaturalHeight, null, null);
2547+
GTK4.gtk_widget_measure(header, GTK.GTK_ORIENTATION_VERTICAL, -1, null, headerNaturalHeight, null, null);
25482548
}
25492549

25502550
GTK.gtk_window_set_default_size(shellHandle, width, height + headerNaturalHeight[0]);

0 commit comments

Comments
 (0)