Skip to content

Commit bd1cdd6

Browse files
ptzieglerakurtakov
authored andcommitted
[GTK4] Fix GtkWidget warning when calculating initial shell bounds
It might be possible that no (custom) titlebar is set for the newly created shell. In such a case, gtk_widget_measure() must not be called with the NULL handle, in order to avoid the following error: > gtk_widget_measure: assertion 'GTK_IS_WIDGET (widget)' failed Furthermore, the header is now retrieved via gtk_window_get_titlebar(), rather than assuming that it's the second child of the shell handle.
1 parent 5d535ce commit bd1cdd6

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 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
@@ -1870,6 +1870,18 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1window_1get_1icon_1name)
18701870
}
18711871
#endif
18721872

1873+
#ifndef NO_gtk_1window_1get_1titlebar
1874+
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1window_1get_1titlebar)
1875+
(JNIEnv *env, jclass that, jlong arg0)
1876+
{
1877+
jlong rc = 0;
1878+
GTK4_NATIVE_ENTER(env, that, gtk_1window_1get_1titlebar_FUNC);
1879+
rc = (jlong)gtk_window_get_titlebar((GtkWindow *)arg0);
1880+
GTK4_NATIVE_EXIT(env, that, gtk_1window_1get_1titlebar_FUNC);
1881+
return rc;
1882+
}
1883+
#endif
1884+
18731885
#ifndef NO_gtk_1window_1is_1maximized
18741886
JNIEXPORT jboolean JNICALL GTK4_NATIVE(gtk_1window_1is_1maximized)
18751887
(JNIEnv *env, jclass that, jlong arg0)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 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
@@ -164,6 +164,7 @@ typedef enum {
164164
gtk_1widget_1translate_1coordinates_FUNC,
165165
gtk_1window_1destroy_FUNC,
166166
gtk_1window_1get_1icon_1name_FUNC,
167+
gtk_1window_1get_1titlebar_FUNC,
167168
gtk_1window_1is_1maximized_FUNC,
168169
gtk_1window_1maximize_FUNC,
169170
gtk_1window_1minimize_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ public class GTK4 {
324324
* @param name cast=(const char *)
325325
* */
326326
public static final native void gtk_window_set_icon_name(long window, long name);
327+
/** @param window cast=(GtkWindow *) */
328+
public static final native long gtk_window_get_titlebar(long window);
327329

328330
/* GtkShortcutController */
329331
public static final native long gtk_shortcut_controller_new();

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 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
@@ -2541,9 +2541,11 @@ void setInitialBounds() {
25412541
* On GTK4, GtkWindow size includes the header bar. In order to keep window size allocation of the client area
25422542
* consistent with previous versions of SWT, we need to include the header bar height in addition to the given height value.
25432543
*/
2544-
long header = GTK4.gtk_widget_get_next_sibling(GTK4.gtk_widget_get_first_child(shellHandle));
2544+
long header = GTK4.gtk_window_get_titlebar(shellHandle);
25452545
int[] headerNaturalHeight = new int[1];
2546-
GTK4.gtk_widget_measure(header, GTK.GTK_ORIENTATION_VERTICAL, 0, null, headerNaturalHeight, null, null);
2546+
if (header != 0) {
2547+
GTK4.gtk_widget_measure(header, GTK.GTK_ORIENTATION_VERTICAL, 0, null, headerNaturalHeight, null, null);
2548+
}
25472549

25482550
GTK.gtk_window_set_default_size(shellHandle, width, height + headerNaturalHeight[0]);
25492551
}

0 commit comments

Comments
 (0)