changeset 57349:dae610645225

8231438: [macOS] Dark mode for the desktop is not supported Reviewed-by: prr, psadhukhan
author serb
date Sun, 08 Dec 2019 20:25:08 -0800
parents 221a47a6f6d3
children 434c10d551c7
files src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m test/jdk/java/awt/Window/FullWindowContentTest/FullWindowContentTest.java
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m	Fri Dec 06 12:06:09 2019 -0800
+++ b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m	Sun Dec 08 20:25:08 2019 -0800
@@ -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 @@
 
     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
--- a/test/jdk/java/awt/Window/FullWindowContentTest/FullWindowContentTest.java	Fri Dec 06 12:06:09 2019 -0800
+++ b/test/jdk/java/awt/Window/FullWindowContentTest/FullWindowContentTest.java	Sun Dec 08 20:25:08 2019 -0800
@@ -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 @@
     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 @@
     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 @@
         try {
             runSwing(() -> theTest = new FullWindowContentTest());
             theTest.performTest();
-            ;
         } finally {
             if (theTest != null) {
                 runSwing(() -> theTest.dispose());