summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2018-06-15 23:15:10 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-08-09 08:19:01 +0000
commit04671a80db32bd7fce470c50934cf60f2e8ffa70 (patch)
treed51d914928f65e2a04e24bc7b0bf0c2c8e891c50 /src/plugins
parent490d461ab080777d6418dce97db632dc2270d218 (diff)
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>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.mm21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm
index 55b3805df3..79f7ebda54 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.mm
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm
@@ -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 &paramList)
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