From 07a989dcca7441262b8234774d01aa3ab9930feb Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Wed, 15 Apr 2026 21:40:29 +0200 Subject: [PATCH] [GTK3] Remove gtk_toolbar_set_show_arrow workaround Remove all gtk_toolbar_set_show_arrow usage from ToolBar: both the toggle in computeSizeInPixels (added in 2012 for Bug 46025) and the toggle in setBounds. WRAP is not supported on GTK and the show_arrow flag was being misused to work around a GTK3 sizing bug from the GTK 3.4 era that no longer applies on modern GTK 3.24. The workaround in computeSizeInPixels caused two GTK state transitions per measurement, each triggering gtk_widget_queue_resize -> gtk_widget_queue_draw -> gdk_window_invalidate_region. When a SWT.WRAP ToolBar sits inside a frequently-measured parent (e.g. CTabFolder.setTopRight), this created a self-sustaining ~60 Hz repaint loop that burns 10-25% CPU while idle. With no remaining callers, the gtk_toolbar_set_show_arrow native binding is removed from GTK3.java as well. Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/3236 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Eclipse SWT PI/gtk/library/gtk3.c | 10 ------- .../Eclipse SWT PI/gtk/library/gtk3_stats.h | 3 +- .../org/eclipse/swt/internal/gtk3/GTK3.java | 5 ---- .../gtk/org/eclipse/swt/widgets/ToolBar.java | 28 +------------------ 4 files changed, 2 insertions(+), 44 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c index 49e4ba6a30b..fb5589ef0bd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c @@ -1987,16 +1987,6 @@ JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1toolbar_1set_1icon_1size) } #endif -#ifndef NO_gtk_1toolbar_1set_1show_1arrow -JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1toolbar_1set_1show_1arrow) - (JNIEnv *env, jclass that, jlong arg0, jboolean arg1) -{ - GTK3_NATIVE_ENTER(env, that, gtk_1toolbar_1set_1show_1arrow_FUNC); - gtk_toolbar_set_show_arrow((GtkToolbar *)arg0, (gboolean)arg1); - GTK3_NATIVE_EXIT(env, that, gtk_1toolbar_1set_1show_1arrow_FUNC); -} -#endif - #ifndef NO_gtk_1toolbar_1set_1style JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1toolbar_1set_1style) (JNIEnv *env, jclass that, jlong arg0, jint arg1) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h index 1309731b018..3717124a82b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2025 IBM Corporation and others. + * Copyright (c) 2000, 2026 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -184,7 +184,6 @@ typedef enum { gtk_1toolbar_1insert_FUNC, gtk_1toolbar_1new_FUNC, gtk_1toolbar_1set_1icon_1size_FUNC, - gtk_1toolbar_1set_1show_1arrow_FUNC, gtk_1toolbar_1set_1style_FUNC, gtk_1tree_1view_1column_1cell_1get_1size_FUNC, gtk_1tree_1view_1get_1bin_1window_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java index 7efbd329111..5fabc897f37 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java @@ -702,11 +702,6 @@ public class GTK3 { * @param item cast=(GtkToolItem *) */ public static final native void gtk_toolbar_insert(long toolbar, long item, int pos); - /** - * @param toolbar cast=(GtkToolbar *) - * @param show_arrow cast=(gboolean) - */ - public static final native void gtk_toolbar_set_show_arrow(long toolbar, boolean show_arrow); /** * @param toolbar cast=(GtkToolbar *) * @param style cast=(GtkToolbarStyle) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java index 172568fe86e..4a9782a213c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java @@ -177,23 +177,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) { if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - Point size = null; - - if (GTK.GTK4) { - size = computeNativeSize (handle, wHint, hHint, changed); - } else { - /* - * Feature in GTK. Size of toolbar is calculated incorrectly - * and appears as just the overflow arrow, if the arrow is enabled - * to display. The fix is to disable it before the computation of - * size and enable it if WRAP style is set. - */ - GTK3.gtk_toolbar_set_show_arrow (handle, false); - size = computeNativeSize (handle, wHint, hHint, changed); - if ((style & SWT.WRAP) != 0) GTK3.gtk_toolbar_set_show_arrow (handle, true); - } - - return size; + return computeNativeSize (handle, wHint, hHint, changed); } @Override @@ -609,18 +593,8 @@ void reskinChildren (int flags) { @Override int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - if (!GTK.GTK4) GTK3.gtk_toolbar_set_show_arrow (handle, false); int result = super.setBounds (x, y, width, height, move, resize); if ((result & RESIZED) != 0) relayout (); - if ((style & SWT.WRAP) != 0) { - if (GTK.GTK4) { - /* TODO: GTK4 will require us to implement our own - * overflow menu. May require the use of the "toolbar" style class - * applied to the widget. */ - } else { - GTK3.gtk_toolbar_set_show_arrow (handle, true); - } - } return result; }