From 08a172ab1e272c72f42929849409bf861433ca24 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: Fri, 17 Apr 2026 12:55:22 +0300 Subject: [PATCH] [Gtk4] Fix COLOR_LINK_FOREGROUND_RGBA value Use button (instead of link as is on gtk 3) and add "link" css class so correct color can be retrieved. --- .../gtk/org/eclipse/swt/widgets/Display.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index d87e9e88154..e87e66156c9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -3299,36 +3299,36 @@ void initializeSystemColorsTitle(long shellContext) { } private void initializeSystemColorsLink() { - /* - * Note: GTK has two types of link at least: - * - * 1) GtkLabel with HTML-like markup - * 2) GtkLinkButton - * - * The 'HighContrast' theme has different colors for these. - * GtkLabel is easier to work with, and obtained color matches color in previous SWT versions. - */ - - // The 'Clearlooks-Phenix' theme sets 'color:' for 'window {' css node, so a stand-alone label is not enough - long window; - if (GTK.GTK4) { - window = GTK4.gtk_window_new(); - } else { - window = GTK3.gtk_window_new (GTK.GTK_WINDOW_TOPLEVEL); - } - long label = GTK.gtk_label_new(null); if (GTK.GTK4) { - GTK4.gtk_window_set_child(window, label); - } else { - GTK3.gtk_container_add(window, label); - } + /* + * GTK 4 needs the "link" CSS class to retrieve the correct link color. + */ + long window = GTK4.gtk_window_new(); + long button = GTK.gtk_button_new(); + GTK4.gtk_window_set_child(window, button); + GTK.gtk_widget_add_css_class(button, Converter.wcsToMbcs("link", true)); - long styleContextLink = GTK.gtk_widget_get_style_context (label); - COLOR_LINK_FOREGROUND_RGBA = styleContextGetColor (styleContextLink, GTK.GTK_STATE_FLAG_LINK); + long styleContextButton = GTK.gtk_widget_get_style_context(button); + COLOR_LINK_FOREGROUND_RGBA = styleContextGetColor(styleContextButton, GTK.GTK_STATE_FLAG_LINK); - if (GTK.GTK4) { GTK4.gtk_window_destroy(window); } else { + /* + * Note: GTK has two types of link at least: + * + * 1) GtkLabel with HTML-like markup + * 2) GtkLinkButton + * + * GtkLabel is easier to work with, and obtained color matches color in previous SWT versions. + */ + // The 'Clearlooks-Phenix' theme sets 'color:' for 'window {' css node, so a stand-alone label is not enough + long window = GTK3.gtk_window_new(GTK.GTK_WINDOW_TOPLEVEL); + long label = GTK.gtk_label_new(null); + GTK3.gtk_container_add(window, label); + + long styleContextLink = GTK.gtk_widget_get_style_context(label); + COLOR_LINK_FOREGROUND_RGBA = styleContextGetColor(styleContextLink, GTK.GTK_STATE_FLAG_LINK); + GTK3.gtk_widget_destroy(window); } }