From 2af58e997025f3605f26fffb98446881cb35defc Mon Sep 17 00:00:00 2001 From: tresf Date: Wed, 8 Jul 2020 18:20:10 -0400 Subject: [PATCH] Add a very crude luminosity screen-reader to find out what color the icon should be --- src/qz/utils/MacUtilities.java | 16 +++++++++++++++- src/qz/utils/SystemUtilities.java | 12 +++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/qz/utils/MacUtilities.java b/src/qz/utils/MacUtilities.java index 7bfc1c12b..516c8cc41 100644 --- a/src/qz/utils/MacUtilities.java +++ b/src/qz/utils/MacUtilities.java @@ -21,6 +21,7 @@ import qz.ui.component.IconCache; import java.awt.*; +import java.awt.image.BufferedImage; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -107,10 +108,23 @@ public static void registerQuitHandler(TrayManager trayManager) { * Runs a shell command to determine if "Dark" desktop theme is enabled * @return true if enabled, false if not */ - public static boolean isDarkMode() { + public static boolean isDarkDesktop() { return !ShellUtilities.execute(new String[] { "defaults", "read", "-g", "AppleInterfaceStyle" }, new String[] { "Dark" }, true, true).isEmpty(); } + public static boolean isDarkTaskbar() { + try { + Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); + Rectangle topCorner = new Rectangle(rectangle.x, rectangle.y, 1, 1); + BufferedImage pixel = new Robot().createScreenCapture(topCorner); + Color color = new Color(pixel.getRGB(0, 0)); + return (color.getRed() * 0.299) + (color.getGreen() * 0.587) + (color.getBlue() * 0.114) <= 174; + } catch(AWTException e) { + log.warn("Unable to detect dark taskbar: {}", e.getMessage()); + } + return false; + } + public static int getScaleFactor() { // Java 9+ per JDK-8172962 if (Constants.JAVA_VERSION.greaterThanOrEqualTo(Version.valueOf("9.0.0"))) { diff --git a/src/qz/utils/SystemUtilities.java b/src/qz/utils/SystemUtilities.java index 178b66087..397e0de2c 100644 --- a/src/qz/utils/SystemUtilities.java +++ b/src/qz/utils/SystemUtilities.java @@ -313,11 +313,13 @@ public static boolean isDarkTaskbar() { public static boolean isDarkTaskbar(boolean recheck) { if(darkTaskbar == null || recheck) { - if (!isWindows()) { - // Mac and Linux don't differentiate; return the cached darkDesktop value - darkTaskbar = isDarkDesktop(); - } else { + if (isWindows()) { darkTaskbar = WindowsUtilities.isDarkTaskbar(); + } else if(isMac()) { + darkTaskbar = MacUtilities.isDarkTaskbar(); + } else { + // Linux doesn't differentiate; return the cached darkDesktop value + darkTaskbar = isDarkDesktop(); } } return darkTaskbar.booleanValue(); @@ -331,7 +333,7 @@ public static boolean isDarkDesktop(boolean recheck) { if (darkDesktop == null || recheck) { // Check for Dark Mode on MacOS if (isMac()) { - darkDesktop = MacUtilities.isDarkMode(); + darkDesktop = MacUtilities.isDarkDesktop(); } else if (isWindows()) { darkDesktop = WindowsUtilities.isDarkDesktop(); } else {