问题
Starting with macOS (10.16 "Beta"/11.0) "Big Sur", the menu-bar and system tray no longer honor the Desktop dark-mode preference, making it difficult to properly theme a system tray icon for this Desktop.
Previously, using a shell command default read
, the dark mode could be detected:
defaults read -g AppleInterfaceStyle
# "Dark"
This still works great for detecting the Window theme, but it does not work for the menu-bar and system tray theme.
Since this area seems to be driven by the wallpaper brightness/whiteness/luminosity, how do we detect a dark system tray?
How to detect this in (e.g.) Objective-C/C++? Any solution is welcome, as most can be adapted.
Question also posted to Apple Developer forums: https://developer.apple.com/forums/thread/652540
Qt5.6 has a feature called setIsMask(...) which allows the OS to handle this automatically. This is effectively an alias for NSImage::setTemplate:Yes
More references to macOS "Dark Mode":
- How to detect if OS X is in dark mode?
- MenuBar Icon for Dark Mode on OS X in Java
AdoptOpenJDK upstream bug report:
- https://github.com/AdoptOpenJDK/openjdk-support/issues/146
Keywords: NSStatusBar
, Menu Bar Extras
来源:https://stackoverflow.com/questions/62685948/macos-big-sur-detect-dark-menu-bar-system-tray