diff options
author | Eike Ziller <eike.ziller@qt.io> | 2021-10-25 17:00:44 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2021-10-26 13:03:00 +0000 |
commit | 74e29eaa26c56b0cb3c70bf5de8a23c571c2a174 (patch) | |
tree | 084e1c0b5f402082c10c49bb2f13bc08720398e7 | |
parent | d977db303ddd47ca3565f50bcc2423d53990b1ea (diff) |
macOS: By default use dark theme in system dark mode
Like already done for Windows.
Change-Id: I7919ecb92da5d4baeedf2068f09c341d39728ecc
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/libs/utils/theme/theme.cpp | 13 | ||||
-rw-r--r-- | src/libs/utils/theme/theme_mac.h | 1 | ||||
-rw-r--r-- | src/libs/utils/theme/theme_mac.mm | 12 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/libs/utils/theme/theme.cpp b/src/libs/utils/theme/theme.cpp index 3cb43de469..463f01e43d 100644 --- a/src/libs/utils/theme/theme.cpp +++ b/src/libs/utils/theme/theme.cpp @@ -79,6 +79,16 @@ static void maybeForceMacOSLight(Theme *theme) #endif } +static bool macOSSystemIsDark() +{ +#ifdef Q_OS_MACOS + static bool systemIsDark = Internal::currentAppearanceIsDark(); + return systemIsDark; +#else + return false; +#endif +} + void setCreatorTheme(Theme *theme) { if (m_creatorTheme == theme) @@ -257,6 +267,8 @@ bool Theme::systemUsesDarkMode() bool ok; const auto setting = QSettings(regkey, QSettings::NativeFormat).value("AppsUseLightTheme").toInt(&ok); return ok && setting == 0; + } else if (HostOsInfo::isMacHost()) { + return macOSSystemIsDark(); } return false; } @@ -278,6 +290,7 @@ static QPalette copyPalette(const QPalette &p) void Theme::setInitialPalette(Theme *initTheme) { + macOSSystemIsDark(); // initialize value for system mode maybeForceMacOSLight(initTheme); initialPalette(); } diff --git a/src/libs/utils/theme/theme_mac.h b/src/libs/utils/theme/theme_mac.h index 55e6d12bc0..8c48e52734 100644 --- a/src/libs/utils/theme/theme_mac.h +++ b/src/libs/utils/theme/theme_mac.h @@ -29,6 +29,7 @@ namespace Utils { namespace Internal { void forceMacOSLightAquaApperance(); +bool currentAppearanceIsDark(); } // Internal } // Utils diff --git a/src/libs/utils/theme/theme_mac.mm b/src/libs/utils/theme/theme_mac.mm index 8d95c88630..d1d623e3a8 100644 --- a/src/libs/utils/theme/theme_mac.mm +++ b/src/libs/utils/theme/theme_mac.mm @@ -49,5 +49,17 @@ void forceMacOSLightAquaApperance() NSApp.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; } +bool currentAppearanceIsDark() +{ +#if __has_builtin(__builtin_available) + if (__builtin_available(macOS 10.14, *)) { + auto appearance = [NSApp.effectiveAppearance + bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; + return [appearance isEqualToString:NSAppearanceNameDarkAqua]; + } +#endif + return false; +} + } // Internal } // Utils |