From f13238312b282dbbe34621fc8418e90120373a69 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Wed, 30 Mar 2022 14:15:12 +0800 Subject: [PATCH] win32: fix dark mode detection global dark mode was first introduced in Win10 1607, not 1809 1809 was the first version that file explorer supported dark mode really sorry for the wrong information Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- include/FramelessHelper/Core/utils.h | 2 +- src/core/framelesshelper_win.cpp | 2 +- src/core/utils_win.cpp | 20 +++++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/FramelessHelper/Core/utils.h b/include/FramelessHelper/Core/utils.h index 30aba44..d93f158 100644 --- a/include/FramelessHelper/Core/utils.h +++ b/include/FramelessHelper/Core/utils.h @@ -57,7 +57,7 @@ FRAMELESSHELPER_CORE_API void moveWindowToDesktopCenter( [[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8OrGreater(); [[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8Point1OrGreater(); [[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10OrGreater(); -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin101809OrGreater(); +[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin101607OrGreater(); [[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin11OrGreater(); [[nodiscard]] FRAMELESSHELPER_CORE_API bool isDwmCompositionEnabled(); FRAMELESSHELPER_CORE_API void triggerFrameChange(const WId windowId); diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index 90c4406..b16efbe 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -677,7 +677,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me } } const bool themeSettingChanged = [uMsg, wParam, lParam]() -> bool { - if (Utils::isWin10OrGreater()) { + if (Utils::isWin101607OrGreater()) { if (uMsg == WM_SETTINGCHANGE) { if ((wParam == 0) && (QString::fromWCharArray(reinterpret_cast(lParam)) .compare(QU8Str(kThemeSettingChangeEventName), Qt::CaseInsensitive) == 0)) { diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 02013f0..c7f8f28 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -455,8 +455,8 @@ QColor Utils::getDwmColorizationColor() bool Utils::shouldAppsUseDarkMode() { - // The global dark mode was first introduced in Windows 10 1809. - if (!isWin101809OrGreater()) { + // The global dark mode was first introduced in Windows 10 1607. + if (!isWin101607OrGreater()) { return false; } const auto resultFromRegistry = []() -> bool { @@ -684,14 +684,12 @@ void Utils::syncWmPaintWithDwm() } } -bool Utils::isWin101809OrGreater() +bool Utils::isWin101607OrGreater() { -#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10_1809); -#elif (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 17763)); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) + static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 14393)); #else - static const bool result = isWindowsVersionOrGreater(10, 0, 17763); + static const bool result = isWindowsVersionOrGreater(10, 0, 14393); #endif return result; } @@ -880,8 +878,8 @@ void Utils::updateWindowFrameBorderColor(const WId windowId, const bool dark) if (!windowId) { return; } - // There's no global dark theme before Win10 1809. - if (!isWin101809OrGreater()) { + // There's no global dark theme before Win10 1607. + if (!isWin101607OrGreater()) { return; } static const auto pDwmSetWindowAttribute = @@ -1188,7 +1186,7 @@ SystemTheme Utils::getSystemTheme() if (isHighContrastModeEnabled()) { return SystemTheme::HighContrast; } - if (isWin101809OrGreater() && shouldAppsUseDarkMode()) { + if (isWin101607OrGreater() && shouldAppsUseDarkMode()) { return SystemTheme::Dark; } return SystemTheme::Light;