8231438: [macOS] Dark mode for the desktop is not supported

Reviewed-by: prr, psadhukhan
This commit is contained in:
Sergey Bylokhov 2019-12-08 20:25:08 -08:00
parent 1a73baeb10
commit 3b1915a71f
2 changed files with 24 additions and 6 deletions
src/java.desktop/macosx/native/libosxapp
test/jdk/java/awt/Window/FullWindowContentTest

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -91,6 +91,25 @@ AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnv];
SEL appearanceSel = @selector(setAppearance:); // macOS 10.14+
if ([self respondsToSelector:appearanceSel]) {
NSString *appearanceProp = [PropertiesUtilities
javaSystemPropertyForKey:@"apple.awt.application.appearance"
withEnv:env];
if (![@"system" isEqual:appearanceProp]) {
// by default use light mode, because dark mode is not supported yet
NSAppearance *appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
if (appearanceProp != nil) {
NSAppearance *requested = [NSAppearance appearanceNamed:appearanceProp];
if (requested != nil) {
appearance = requested;
}
}
// [self setAppearance:appearance];
[self performSelector:appearanceSel withObject:appearance];
}
}
// Get default nib file location
// NOTE: This should learn about the current java.version. Probably best thru
// the Makefile system's -DFRAMEWORK_VERSION define. Need to be able to pass this

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,7 +31,7 @@
* @author Alan Snyder
* @run main FullWindowContentTest
* @requires (os.family == "mac")
*/
*/
import java.awt.AWTException;
import java.awt.Color;
@ -120,7 +120,7 @@ public class FullWindowContentTest
private void checkTranslucent() {
Color c = getTestPixel();
int delta = c.getRed() - c.getBlue();
if (delta < 50 || delta > 150) {
if (delta < 40 || delta > 150) {
throw new RuntimeException("Test failed: did not find translucent title bar color");
}
checkContent();
@ -129,7 +129,7 @@ public class FullWindowContentTest
private void checkNormal() {
Color c = getTestPixel();
int delta = c.getRed() - c.getBlue();
if (delta < -50 || delta > 50) {
if (delta < -40 || delta > 40) {
throw new RuntimeException("Test failed: did not find normal title bar color");
}
checkContent();
@ -202,7 +202,6 @@ public class FullWindowContentTest
try {
runSwing(() -> theTest = new FullWindowContentTest());
theTest.performTest();
;
} finally {
if (theTest != null) {
runSwing(() -> theTest.dispose());