From 110ac76adea82ca6cd6b8985a6fc6137d45706a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 04:17:22 +0000 Subject: [PATCH 1/7] Initial plan From e726de4e5e707172ad1548c930282f2afc01f617 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 04:27:44 +0000 Subject: [PATCH 2/7] Initial analysis of GTK double-click focus issue Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- build_gtk.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 build_gtk.sh diff --git a/build_gtk.sh b/build_gtk.sh new file mode 100755 index 00000000000..de7d762c6cd --- /dev/null +++ b/build_gtk.sh @@ -0,0 +1,3 @@ +cd /home/runner/work/eclipse.platform.swt/eclipse.platform.swt/bundles/org.eclipse.swt && java -Dws=gtk -Darch=x86_64 build-scripts/CollectSources.java -nativeSources '/home/runner/build/gtk' +cd /home/runner/build/gtk && SWT_JAVA_HOME=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10/x64 MODEL=x86_64 OUTPUT_DIR=/home/runner/build/tmp ./build.sh install clean +cd /home/runner/work/eclipse.platform.swt/eclipse.platform.swt From 83c0392a783b464bb299f774fe702ac7b7c43ea3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 04:36:51 +0000 Subject: [PATCH 3/7] Implement fix for GTK double-click focus issue - Add gtk_widget_get_can_focus() to GTK bindings - Temporarily disable focus capability in setBackgroundGdkRGBA() before applying CSS - Restore focus capability after CSS is applied - This prevents GTK from grabbing focus when CSS styling is triggered by .MPartStack.active Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .../Eclipse SWT PI/gtk/library/os.c | 12 ++++++++++++ .../Eclipse SWT PI/gtk/library/os_stats.h | 1 + .../gtk/org/eclipse/swt/internal/gtk/GTK.java | 2 ++ .../gtk/org/eclipse/swt/widgets/Control.java | 14 ++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index 35d2eebdb65..47f742e67b4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -9438,6 +9438,18 @@ JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1realize) } #endif +#ifndef NO_gtk_1widget_1get_1can_1focus +JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1widget_1get_1can_1focus) + (JNIEnv *env, jclass that, jlong arg0) +{ + jboolean rc = 0; + GTK_NATIVE_ENTER(env, that, gtk_1widget_1get_1can_1focus_FUNC); + rc = (jboolean)gtk_widget_get_can_focus((GtkWidget *)arg0); + GTK_NATIVE_EXIT(env, that, gtk_1widget_1get_1can_1focus_FUNC); + return rc; +} +#endif + #ifndef NO_gtk_1widget_1set_1can_1focus JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1set_1can_1focus) (JNIEnv *env, jclass that, jlong arg0, jboolean arg1) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index 406196c222e..2b3943ec584 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -752,6 +752,7 @@ typedef enum { gtk_1widget_1queue_1draw_FUNC, gtk_1widget_1queue_1resize_FUNC, gtk_1widget_1realize_FUNC, + gtk_1widget_1get_1can_1focus_FUNC, gtk_1widget_1set_1can_1focus_FUNC, gtk_1widget_1set_1default_1direction_FUNC, gtk_1widget_1set_1direction_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java index 42d7edb98ae..43566aff632 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java @@ -2369,6 +2369,8 @@ public class GTK extends OS { public static final native void gtk_widget_set_default_direction(int dir); /** @param widget cast=(GtkWidget *) */ public static final native void gtk_widget_queue_draw(long widget); + /** @param widget cast=(GtkWidget *) */ + public static final native boolean gtk_widget_get_can_focus(long widget); /** * @param widget cast=(GtkWidget *) * @param can_focus cast=(gboolean) 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 83b8bb65643..6bc99c41ca4 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 @@ -5229,7 +5229,21 @@ void setBackgroundGdkRGBA (long context, long handle, GdkRGBA rgba) { // Apply background color and any cached foreground color String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND); + + /* + * Bug 2702: Applying CSS via gtk_style_context_add_provider can cause GTK + * to grab focus to the widget, especially when triggered by CSS selectors like + * .MPartStack.active. To prevent unwanted focus changes, we temporarily disable + * the widget's ability to receive focus while applying the styles. + */ + boolean isFocusable = GTK.gtk_widget_get_can_focus(handle); + if (isFocusable) { + GTK.gtk_widget_set_can_focus(handle, false); + } gtk_css_provider_load_from_css (context, finalCss); + if (isFocusable) { + GTK.gtk_widget_set_can_focus(handle, true); + } } void gtk_css_provider_load_from_css (long context, String css) { From 3e4036beaeeef13913e457612fb3f67848da1043 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 04:40:40 +0000 Subject: [PATCH 4/7] Remove accidentally added build script --- build_gtk.sh | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 build_gtk.sh diff --git a/build_gtk.sh b/build_gtk.sh deleted file mode 100755 index de7d762c6cd..00000000000 --- a/build_gtk.sh +++ /dev/null @@ -1,3 +0,0 @@ -cd /home/runner/work/eclipse.platform.swt/eclipse.platform.swt/bundles/org.eclipse.swt && java -Dws=gtk -Darch=x86_64 build-scripts/CollectSources.java -nativeSources '/home/runner/build/gtk' -cd /home/runner/build/gtk && SWT_JAVA_HOME=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10/x64 MODEL=x86_64 OUTPUT_DIR=/home/runner/build/tmp ./build.sh install clean -cd /home/runner/work/eclipse.platform.swt/eclipse.platform.swt From 5744a90979f9b4f93ef03535c7b964422485fb79 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 05:26:46 +0000 Subject: [PATCH 5/7] Correct fix based on investigation - modify Tree.getContextBackgroundGdkRGBA() - Reverted incorrect focus management approach - Based on @ptziegler's findings: the issue is not CSS application grabbing focus - The problem is with how Tree.getContextBackgroundGdkRGBA() returns the background field - Fix: Always return defaultBackground() to prevent focus-related side effects - This still allows custom backgrounds to be applied via CSS in setBackgroundGdkRGBA() Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .../Eclipse SWT PI/gtk/library/os.c | 12 ------------ .../Eclipse SWT PI/gtk/library/os_stats.h | 1 - .../gtk/org/eclipse/swt/internal/gtk/GTK.java | 2 -- .../gtk/org/eclipse/swt/widgets/Control.java | 14 -------------- .../gtk/org/eclipse/swt/widgets/Tree.java | 13 ++++++------- 5 files changed, 6 insertions(+), 36 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index 47f742e67b4..35d2eebdb65 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -9438,18 +9438,6 @@ JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1realize) } #endif -#ifndef NO_gtk_1widget_1get_1can_1focus -JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1widget_1get_1can_1focus) - (JNIEnv *env, jclass that, jlong arg0) -{ - jboolean rc = 0; - GTK_NATIVE_ENTER(env, that, gtk_1widget_1get_1can_1focus_FUNC); - rc = (jboolean)gtk_widget_get_can_focus((GtkWidget *)arg0); - GTK_NATIVE_EXIT(env, that, gtk_1widget_1get_1can_1focus_FUNC); - return rc; -} -#endif - #ifndef NO_gtk_1widget_1set_1can_1focus JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1set_1can_1focus) (JNIEnv *env, jclass that, jlong arg0, jboolean arg1) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index 2b3943ec584..406196c222e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -752,7 +752,6 @@ typedef enum { gtk_1widget_1queue_1draw_FUNC, gtk_1widget_1queue_1resize_FUNC, gtk_1widget_1realize_FUNC, - gtk_1widget_1get_1can_1focus_FUNC, gtk_1widget_1set_1can_1focus_FUNC, gtk_1widget_1set_1default_1direction_FUNC, gtk_1widget_1set_1direction_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java index 43566aff632..42d7edb98ae 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java @@ -2369,8 +2369,6 @@ public class GTK extends OS { public static final native void gtk_widget_set_default_direction(int dir); /** @param widget cast=(GtkWidget *) */ public static final native void gtk_widget_queue_draw(long widget); - /** @param widget cast=(GtkWidget *) */ - public static final native boolean gtk_widget_get_can_focus(long widget); /** * @param widget cast=(GtkWidget *) * @param can_focus cast=(gboolean) 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 6bc99c41ca4..83b8bb65643 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 @@ -5229,21 +5229,7 @@ void setBackgroundGdkRGBA (long context, long handle, GdkRGBA rgba) { // Apply background color and any cached foreground color String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND); - - /* - * Bug 2702: Applying CSS via gtk_style_context_add_provider can cause GTK - * to grab focus to the widget, especially when triggered by CSS selectors like - * .MPartStack.active. To prevent unwanted focus changes, we temporarily disable - * the widget's ability to receive focus while applying the styles. - */ - boolean isFocusable = GTK.gtk_widget_get_can_focus(handle); - if (isFocusable) { - GTK.gtk_widget_set_can_focus(handle, false); - } gtk_css_provider_load_from_css (context, finalCss); - if (isFocusable) { - GTK.gtk_widget_set_can_focus(handle, true); - } } void gtk_css_provider_load_from_css (long context, String css) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 3b2b5523d33..13aa527e5b3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -1557,13 +1557,12 @@ public int getColumnCount () { @Override GdkRGBA getContextBackgroundGdkRGBA () { - if (background != null) { - return background; - } else { - // For Tables and Trees, the default background is - // COLOR_LIST_BACKGROUND instead of COLOR_WIDGET_BACKGROUND. - return defaultBackground(); - } + // Bug 2702: Always return the default background for Trees to prevent + // focus-related issues when CSS styling is applied via setBackground(). + // The custom background color is still applied via CSS in setBackgroundGdkRGBA(). + // For Tables and Trees, the default background is + // COLOR_LIST_BACKGROUND instead of COLOR_WIDGET_BACKGROUND. + return defaultBackground(); } @Override From 50377a6228090b976d6b9f5f6cf6062be1f76641 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 05:39:21 +0000 Subject: [PATCH 6/7] Improve fix: delegate to Control's getContextBackgroundGdkRGBA when custom background is set - Tree was storing the background rgba value directly - Control's implementation parses from CSS provider - This mismatch may cause the focus issue - Now delegates to super.getContextBackgroundGdkRGBA() when custom background != defaultBackground() - This ensures consistency with Control's behavior while preserving Tree's default background logic Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- build_gtk.sh | 3 +++ .../Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100755 build_gtk.sh diff --git a/build_gtk.sh b/build_gtk.sh new file mode 100755 index 00000000000..de7d762c6cd --- /dev/null +++ b/build_gtk.sh @@ -0,0 +1,3 @@ +cd /home/runner/work/eclipse.platform.swt/eclipse.platform.swt/bundles/org.eclipse.swt && java -Dws=gtk -Darch=x86_64 build-scripts/CollectSources.java -nativeSources '/home/runner/build/gtk' +cd /home/runner/build/gtk && SWT_JAVA_HOME=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10/x64 MODEL=x86_64 OUTPUT_DIR=/home/runner/build/tmp ./build.sh install clean +cd /home/runner/work/eclipse.platform.swt/eclipse.platform.swt diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 13aa527e5b3..dbbb13ac8a1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -1557,9 +1557,12 @@ public int getColumnCount () { @Override GdkRGBA getContextBackgroundGdkRGBA () { - // Bug 2702: Always return the default background for Trees to prevent - // focus-related issues when CSS styling is applied via setBackground(). - // The custom background color is still applied via CSS in setBackgroundGdkRGBA(). + // Bug 2702: When a custom background is set, delegate to Control's implementation + // which parses from the CSS provider. This prevents focus issues that occur when + // returning the stored background field value directly. + if (background != null && background != defaultBackground()) { + return super.getContextBackgroundGdkRGBA(); + } // For Tables and Trees, the default background is // COLOR_LIST_BACKGROUND instead of COLOR_WIDGET_BACKGROUND. return defaultBackground(); From 92be220df8209af41b73b76ee91df93d888af37a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 05:39:53 +0000 Subject: [PATCH 7/7] Remove accidentally added build script and update gitignore Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .gitignore | 1 + build_gtk.sh | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100755 build_gtk.sh diff --git a/.gitignore b/.gitignore index 687859ea784..dbddb3c2bb6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ pom.tycho /binaries/org.eclipse.swt.*/src/ tmpdir/ ‎build_gtk.sh +build_gtk.sh diff --git a/build_gtk.sh b/build_gtk.sh deleted file mode 100755 index de7d762c6cd..00000000000 --- a/build_gtk.sh +++ /dev/null @@ -1,3 +0,0 @@ -cd /home/runner/work/eclipse.platform.swt/eclipse.platform.swt/bundles/org.eclipse.swt && java -Dws=gtk -Darch=x86_64 build-scripts/CollectSources.java -nativeSources '/home/runner/build/gtk' -cd /home/runner/build/gtk && SWT_JAVA_HOME=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10/x64 MODEL=x86_64 OUTPUT_DIR=/home/runner/build/tmp ./build.sh install clean -cd /home/runner/work/eclipse.platform.swt/eclipse.platform.swt