Skip to content

Commit

Permalink
8231438: [macOS] Dark mode for the desktop is not supported
Browse files Browse the repository at this point in the history
Reviewed-by: prr, psadhukhan
  • Loading branch information
mrserb committed Dec 9, 2019
1 parent 1a73bae commit 3b1915a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
21 changes: 20 additions & 1 deletion src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m
@@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -91,6 +91,25 @@ - (void)finishLaunching


JNIEnv *env = [ThreadUtilities getJNIEnv]; 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 // Get default nib file location
// NOTE: This should learn about the current java.version. Probably best thru // 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 // the Makefile system's -DFRAMEWORK_VERSION define. Need to be able to pass this
Expand Down
@@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,7 +31,7 @@
* @author Alan Snyder * @author Alan Snyder
* @run main FullWindowContentTest * @run main FullWindowContentTest
* @requires (os.family == "mac") * @requires (os.family == "mac")
*/ */


import java.awt.AWTException; import java.awt.AWTException;
import java.awt.Color; import java.awt.Color;
Expand Down Expand Up @@ -120,7 +120,7 @@ private void checkTransparent() {
private void checkTranslucent() { private void checkTranslucent() {
Color c = getTestPixel(); Color c = getTestPixel();
int delta = c.getRed() - c.getBlue(); 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"); throw new RuntimeException("Test failed: did not find translucent title bar color");
} }
checkContent(); checkContent();
Expand All @@ -129,7 +129,7 @@ private void checkTranslucent() {
private void checkNormal() { private void checkNormal() {
Color c = getTestPixel(); Color c = getTestPixel();
int delta = c.getRed() - c.getBlue(); 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"); throw new RuntimeException("Test failed: did not find normal title bar color");
} }
checkContent(); checkContent();
Expand Down Expand Up @@ -202,7 +202,6 @@ public static void main(String[] args) {
try { try {
runSwing(() -> theTest = new FullWindowContentTest()); runSwing(() -> theTest = new FullWindowContentTest());
theTest.performTest(); theTest.performTest();
;
} finally { } finally {
if (theTest != null) { if (theTest != null) {
runSwing(() -> theTest.dispose()); runSwing(() -> theTest.dispose());
Expand Down

0 comments on commit 3b1915a

Please sign in to comment.