macOS: Force light theme on macOS 10.14+
Until we can properly fix QPalette and QMacStyle, we should disable dark appearance in Qt applications. Disable by setting NSApp.appearance to Aqua, unless dark mode support has been requested via Info.plist or environment variable. Read the NSRequiresAquaSystemAppearance Info.plist key, don’t set NSApp.appearance if its value is false. Also check the QT_MAC_REQUIRES_AQUA_SYSTEM_APPEARANCE environment variable and apply similar logic. You then enable dark mode support by setting: QT_MAC_REQUIRES_AQUA_SYSTEM_APPEARANCE=0 which is slightly awkward, but matches Info.plist behavior. Task-number: QTBUG-68891 Change-Id: I86dc6cf3dee951d46c953396c57d2c31f2e4afcc Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
490d461ab0
commit
04671a80db
@ -70,6 +70,12 @@
|
||||
|
||||
#include <IOKit/graphics/IOGraphicsLib.h>
|
||||
|
||||
#if !QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14)
|
||||
@interface NSApplication (MojaveForwardDeclarations)
|
||||
@property (strong) NSAppearance *appearance NS_AVAILABLE_MAC(10_14);
|
||||
@end
|
||||
#endif
|
||||
|
||||
static void initResources()
|
||||
{
|
||||
Q_INIT_RESOURCE(qcocoaresources);
|
||||
@ -131,6 +137,21 @@ QCocoaIntegration::QCocoaIntegration(const QStringList ¶mList)
|
||||
NSApplication *cocoaApplication = [QNSApplication sharedApplication];
|
||||
qt_redirectNSApplicationSendEvent();
|
||||
|
||||
if (__builtin_available(macOS 10.14, *)) {
|
||||
// Disable dark appearance, unless the Info.plist or environment requests that it should be enabled
|
||||
bool plistEnablesDarkAppearance = [[[NSBundle mainBundle] objectForInfoDictionaryKey:
|
||||
@"NSRequiresAquaSystemAppearance"] boolValue];
|
||||
|
||||
bool hasEnvironmentRequiresAquaAppearance;
|
||||
int environmentRequiresAquaAppearance = qEnvironmentVariableIntValue(
|
||||
"QT_MAC_REQUIRES_AQUA_SYSTEM_APPEARANCE", &hasEnvironmentRequiresAquaAppearance);
|
||||
bool environmentEnablesDarkAppearance = hasEnvironmentRequiresAquaAppearance
|
||||
&& environmentRequiresAquaAppearance == 0;
|
||||
|
||||
if (!(plistEnablesDarkAppearance || environmentEnablesDarkAppearance))
|
||||
NSApp.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
|
||||
}
|
||||
|
||||
if (qEnvironmentVariableIsEmpty("QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM")) {
|
||||
// Applications launched from plain executables (without an app
|
||||
// bundle) are "background" applications that does not take keybaord
|
||||
|
Loading…
Reference in New Issue
Block a user