Skip to content

Commit 79a4a01

Browse files
author
Pankaj Bansal
committedAug 9, 2020
8247753: UIManager.getSytemLookAndFeelClassName() returns wrong value on Fedora 32
Reviewed-by: prr, psadhukhan
1 parent 0615eac commit 79a4a01

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed
 

‎src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,19 @@ public static int getDatatransferTimeout() {
9595

9696
@Override
9797
public String getDesktop() {
98+
String gnome = "gnome";
9899
String gsi = AccessController.doPrivileged(
99100
(PrivilegedAction<String>) ()
100101
-> System.getenv("GNOME_DESKTOP_SESSION_ID"));
101-
return (gsi != null) ? "gnome" : null;
102+
if (gsi != null) {
103+
return gnome;
104+
}
105+
106+
String desktop = AccessController.doPrivileged(
107+
(PrivilegedAction<String>) ()
108+
-> System.getenv("XDG_CURRENT_DESKTOP"));
109+
return (desktop != null && desktop.toLowerCase().contains(gnome))
110+
? gnome : null;
102111
}
103112

104113
/**

‎test/jdk/javax/swing/LookAndFeel/SystemLookAndFeel/SystemLookAndFeelTest.java

+23-20
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
* questions.
2222
*/
2323

24-
/*
24+
/*
2525
* @test
26-
* @bug 8226783
26+
* @bug 8226783 8247753
2727
* @key headful
2828
* @summary Verify System L&F
2929
*/
@@ -52,23 +52,26 @@ public static void main(String[] args) {
5252
} else if (os.contains("macos")) {
5353
expLAF = "com.apple.laf.AquaLookAndFeel";
5454
} else if (os.contains("linux")) {
55-
/*
56-
* The implementation keys off the following desktop setting to
57-
* decide if GTK is an appropriate system L&F.
58-
* In its absence, there probably isn't support for the GTK L&F
59-
* anyway. It does not tell us if the GTK libraries are available
60-
* but they really should be if this is a gnome session.
61-
* If it proves necessary the test can perhaps be updated to see
62-
* if the GTK LAF is listed as installed and can be instantiated.
63-
*/
64-
String gnome = System.getenv("GNOME_DESKTOP_SESSION_ID");
65-
System.out.println("Gnome desktop session ID is " + gnome);
66-
if (gnome != null) {
67-
expLAF = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
68-
} else if (os.contains("linux")) {
69-
expLAF = "javax.swing.plaf.metal.MetalLookAndFeel";
70-
}
71-
}
55+
/*
56+
* The implementation keys off the following desktop setting to
57+
* decide if GTK is an appropriate system L&F.
58+
* In its absence, there probably isn't support for the GTK L&F
59+
* anyway. It does not tell us if the GTK libraries are available
60+
* but they really should be if this is a gnome session.
61+
* If it proves necessary the test can perhaps be updated to see
62+
* if the GTK LAF is listed as installed and can be instantiated.
63+
*/
64+
String gnome = System.getenv("GNOME_DESKTOP_SESSION_ID");
65+
String desktop = System.getenv("XDG_CURRENT_DESKTOP");
66+
System.out.println("Gnome desktop session ID is " + gnome);
67+
System.out.println("XDG_CURRENT_DESKTOP is set to " + desktop);
68+
if (gnome != null ||
69+
(desktop != null && desktop.toLowerCase().contains("gnome"))) {
70+
expLAF = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
71+
} else {
72+
expLAF = "javax.swing.plaf.metal.MetalLookAndFeel";
73+
}
74+
}
7275
System.out.println("Expected System LAF is " + expLAF);
7376
if (expLAF == null) {
7477
System.out.println("No match for expected LAF, unknown OS ?");
@@ -77,5 +80,5 @@ public static void main(String[] args) {
7780
if (!(laf.equals(expLAF))) {
7881
throw new RuntimeException("LAF not as expected");
7982
}
80-
}
83+
}
8184
}

0 commit comments

Comments
 (0)
Please sign in to comment.