forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -79,6 +79,16 @@ static void maybeForceMacOSLight(Theme *theme)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool macOSSystemIsDark()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
static bool systemIsDark = Internal::currentAppearanceIsDark();
|
||||||
|
return systemIsDark;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void setCreatorTheme(Theme *theme)
|
void setCreatorTheme(Theme *theme)
|
||||||
{
|
{
|
||||||
if (m_creatorTheme == theme)
|
if (m_creatorTheme == theme)
|
||||||
@@ -257,6 +267,8 @@ bool Theme::systemUsesDarkMode()
|
|||||||
bool ok;
|
bool ok;
|
||||||
const auto setting = QSettings(regkey, QSettings::NativeFormat).value("AppsUseLightTheme").toInt(&ok);
|
const auto setting = QSettings(regkey, QSettings::NativeFormat).value("AppsUseLightTheme").toInt(&ok);
|
||||||
return ok && setting == 0;
|
return ok && setting == 0;
|
||||||
|
} else if (HostOsInfo::isMacHost()) {
|
||||||
|
return macOSSystemIsDark();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -278,6 +290,7 @@ static QPalette copyPalette(const QPalette &p)
|
|||||||
|
|
||||||
void Theme::setInitialPalette(Theme *initTheme)
|
void Theme::setInitialPalette(Theme *initTheme)
|
||||||
{
|
{
|
||||||
|
macOSSystemIsDark(); // initialize value for system mode
|
||||||
maybeForceMacOSLight(initTheme);
|
maybeForceMacOSLight(initTheme);
|
||||||
initialPalette();
|
initialPalette();
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,7 @@ namespace Utils {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
void forceMacOSLightAquaApperance();
|
void forceMacOSLightAquaApperance();
|
||||||
|
bool currentAppearanceIsDark();
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
} // Utils
|
} // Utils
|
||||||
|
@@ -49,5 +49,17 @@ void forceMacOSLightAquaApperance()
|
|||||||
NSApp.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
|
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
|
} // Internal
|
||||||
} // Utils
|
} // Utils
|
||||||
|
Reference in New Issue
Block a user