Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2018-05-02 16:05:36 +0000
committerEric Williams2018-05-02 18:02:32 +0000
commit28eadb40942449b5b13e2a2cfce263f140e9d4f4 (patch)
tree122d77bfa64d60ec307e243c7ff83d317f2c7fbd
parent6f7c898268e4449ff992db1dc518e7df9420ae6e (diff)
downloadeclipse.platform.swt-28eadb40942449b5b13e2a2cfce263f140e9d4f4.tar.gz
eclipse.platform.swt-28eadb40942449b5b13e2a2cfce263f140e9d4f4.tar.xz
eclipse.platform.swt-28eadb40942449b5b13e2a2cfce263f140e9d4f4.zip
Bug 534007: [GTK3] Support for detecting themes like in 4.7.3 (but
without the memory leaks) Check for the presence of the GTK_THEME environment variable. When loading system colors from the GTK CSS theme, we can make use of this information to load the proper theme information and dark variants, if necessary. Tested with the Adwaita and Arc themes (and their dark variants) on GTK3.22, X11 and Wayland. No AllNonBrowser JUnit tests fail. Change-Id: If3697495a941ac4e26fb2d714d4b221da65325a1 Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java37
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java12
2 files changed, 46 insertions, 3 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index 7b7685e406..b83491e7ba 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -691,6 +691,28 @@ public class OS extends C {
*/
public static final boolean SWT_MENU_LOCATION_DEBUGGING;
+ /*
+ * Check for the GTK_THEME environment variable. If set, parse
+ * it to get the theme name and check if a dark variant is specified.
+ * We can make use of this information when loading SWT system colors.
+ * See bug 534007.
+ */
+ /**
+ * True if the GTK_THEME environment variable is specified
+ * and is non-empty.
+ */
+ public static final boolean GTK_THEME_SET;
+ /**
+ * A string containing the theme name supplied via the GTK_THEME
+ * environment variable. Otherwise this will contain an empty string.
+ */
+ public static final String GTK_THEME_NAME;
+ /**
+ * True if GTK_THEME_SET is true, and if the dark variant was
+ * specified via the GTK_THEME environment variable.
+ */
+ public static final boolean GTK_THEME_DARK;
+
/* Feature in Gtk: with the switch to GtkMenuItems from GtkImageMenuItems
* in Gtk3 came a small Gtk shortfall: a small amount of padding on the left hand
* side of MenuItems was added. This padding is not accessible to the developer,
@@ -720,6 +742,21 @@ public class OS extends C {
}
SWT_MENU_LOCATION_DEBUGGING = menuLocationDebuggingEnabled;
+ String gtkThemeProperty = "GTK_THEME";
+ String gtkThemeCheck = getEnvironmentalVariable(gtkThemeProperty);
+ boolean gtkThemeSet = false;
+ String gtkThemeName = "";
+ boolean gtkThemeDark = false;
+ if (gtkThemeCheck != null && !gtkThemeCheck.isEmpty()) {
+ gtkThemeSet = true;
+ gtkThemeDark = gtkThemeCheck.contains(":dark") ? true : false;
+ String [] themeNameSplit = gtkThemeCheck.split(":");
+ gtkThemeName = themeNameSplit[0];
+ }
+ GTK_THEME_SET = gtkThemeSet;
+ GTK_THEME_NAME = gtkThemeName;
+ GTK_THEME_DARK = gtkThemeDark;
+
System.setProperty("org.eclipse.swt.internal.gtk.version",
(GTK.GTK_VERSION >>> 16) + "." + (GTK.GTK_VERSION >>> 8 & 0xFF) + "." + (GTK.GTK_VERSION & 0xFF));
// set GDK backend if we are on X11
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 a5e08f6653..425c55f55c 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
@@ -1925,16 +1925,22 @@ String gtk_css_create_css_color_string (String background, String foreground, in
* directly
*/
String gtk_css_default_theme_values (int swt) {
- // Find CSS theme name
+ /*
+ * Find current GTK theme: either use the system theme,
+ * or one provided using the GTK_THEME environment variable.
+ * See bug 534007.
+ */
int length;
long /*int*/ str;
- byte [] buffer = OS.getThemeNameBytes();
+ byte [] buffer = OS.GTK_THEME_SET ? Converter.wcsToMbcs (OS.GTK_THEME_NAME, true) : OS.getThemeNameBytes();
+ // Load the dark variant if specified
+ byte [] darkBuffer = OS.GTK_THEME_DARK ? darkBuffer = Converter.wcsToMbcs ("dark", true) : null;
if (buffer == null || buffer.length == 0) {
return "";
}
// Fetch the actual theme in char/string format
- long /*int*/ themeProvider = GTK.gtk_css_provider_get_named(buffer, null);
+ long /*int*/ themeProvider = GTK.gtk_css_provider_get_named(buffer, darkBuffer);
str = GTK.gtk_css_provider_to_string (themeProvider);
length = C.strlen (str);
if (length == 0) {

Back to the top