diff --git a/include/FramelessHelper/Core/framelesshelpercore_global.h b/include/FramelessHelper/Core/framelesshelpercore_global.h index b8036727..df2b2bb0 100644 --- a/include/FramelessHelper/Core/framelesshelpercore_global.h +++ b/include/FramelessHelper/Core/framelesshelpercore_global.h @@ -281,6 +281,98 @@ enum class ButtonState }; Q_ENUM_NS(ButtonState) +enum class WindowsVersion +{ + _2000 = 0, + _XP = 1, + _XP_64 = 2, + _Vista = 3, + _Vista_SP1 = 4, + _Vista_SP2 = 5, + _7 = 6, + _7_SP1 = 7, + _8 = 8, + _8_1 = 9, + _8_1_Update1 = 10, + _10_1507 = 11, + _10_1511 = 12, + _10_1607 = 13, + _10_1703 = 14, + _10_1709 = 15, + _10_1803 = 16, + _10_1809 = 17, + _10_1903 = 18, + _10_1909 = 19, + _10_2004 = 20, + _10_20H2 = 21, + _10_21H1 = 22, + _10_21H2 = 23, + _11_21H2 = 24 +}; +Q_ENUM_NS(WindowsVersion) + +struct VersionNumber +{ + int major = 0; + int minor = 0; + int patch = 0; + int tweak = 0; + + [[nodiscard]] friend bool operator==(const VersionNumber &lhs, const VersionNumber &rhs) noexcept + { + return ((lhs.major == rhs.major) && (lhs.minor == rhs.minor) && (lhs.patch == rhs.patch) && (lhs.tweak == rhs.tweak)); + } + + [[nodiscard]] friend bool operator!=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept + { + return !(lhs == rhs); + } + + [[nodiscard]] friend bool operator>(const VersionNumber &lhs, const VersionNumber &rhs) noexcept + { + if (lhs.major > rhs.major) { + return true; + } + if (lhs.major < rhs.major) { + return false; + } + if (lhs.minor > rhs.minor) { + return true; + } + if (lhs.minor < rhs.minor) { + return false; + } + if (lhs.patch > rhs.patch) { + return true; + } + if (lhs.patch < rhs.patch) { + return false; + } + if (lhs.tweak > rhs.tweak) { + return true; + } + if (lhs.tweak < rhs.tweak) { + return false; + } + return false; + } + + [[nodiscard]] friend bool operator<(const VersionNumber &lhs, const VersionNumber &rhs) noexcept + { + return ((lhs != rhs) && !(lhs > rhs)); + } + + [[nodiscard]] friend bool operator>=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept + { + return ((lhs > rhs) || (lhs == rhs)); + } + + [[nodiscard]] friend bool operator<=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept + { + return ((lhs < rhs) || (lhs == rhs)); + } +}; + using GetWindowFlagsCallback = std::function; using SetWindowFlagsCallback = std::function; @@ -361,6 +453,25 @@ struct SystemParameters [[nodiscard]] inline bool isValid() const { + Q_ASSERT(getWindowFlags); + Q_ASSERT(setWindowFlags); + Q_ASSERT(getWindowSize); + Q_ASSERT(setWindowSize); + Q_ASSERT(getWindowPosition); + Q_ASSERT(setWindowPosition); + Q_ASSERT(getWindowScreen); + Q_ASSERT(isWindowFixedSize); + Q_ASSERT(setWindowFixedSize); + Q_ASSERT(getWindowState); + Q_ASSERT(setWindowState); + Q_ASSERT(getWindowHandle); + Q_ASSERT(windowToScreen); + Q_ASSERT(screenToWindow); + Q_ASSERT(isInsideSystemButtons); + Q_ASSERT(isInsideTitleBarDraggableArea); + Q_ASSERT(getWindowDevicePixelRatio); + Q_ASSERT(setSystemButtonState); + Q_ASSERT(getWindowId); return (getWindowFlags && setWindowFlags && getWindowSize && setWindowSize && getWindowPosition && setWindowPosition && getWindowScreen && isWindowFixedSize && setWindowFixedSize @@ -371,6 +482,36 @@ struct SystemParameters } }; +[[maybe_unused]] static constexpr const VersionNumber WindowsVersions[] = +{ + { 5, 0, 2195}, // Windows 2000 + { 5, 1, 2600}, // Windows XP + { 5, 2, 3790}, // Windows XP x64 Edition or Windows Server 2003 + { 6, 0, 6000}, // Windows Vista + { 6, 0, 6001}, // Windows Vista with Service Pack 1 or Windows Server 2008 + { 6, 0, 6002}, // Windows Vista with Service Pack 2 + { 6, 1, 7600}, // Windows 7 or Windows Server 2008 R2 + { 6, 1, 7601}, // Windows 7 with Service Pack 1 or Windows Server 2008 R2 with Service Pack 1 + { 6, 2, 9200}, // Windows 8 or Windows Server 2012 + { 6, 3, 9200}, // Windows 8.1 or Windows Server 2012 R2 + { 6, 3, 9600}, // Windows 8.1 with Update 1 + {10, 0, 10240}, // Windows 10 Version 1507 (TH1) + {10, 0, 10586}, // Windows 10 Version 1511 (November Update) (TH2) + {10, 0, 14393}, // Windows 10 Version 1607 (Anniversary Update) (RS1) or Windows Server 2016 + {10, 0, 15063}, // Windows 10 Version 1703 (Creators Update) (RS2) + {10, 0, 16299}, // Windows 10 Version 1709 (Fall Creators Update) (RS3) + {10, 0, 17134}, // Windows 10 Version 1803 (April 2018 Update) (RS4) + {10, 0, 17763}, // Windows 10 Version 1809 (October 2018 Update) (RS5) or Windows Server 2019 + {10, 0, 18362}, // Windows 10 Version 1903 (May 2019 Update) (19H1) + {10, 0, 18363}, // Windows 10 Version 1909 (November 2019 Update) (19H2) + {10, 0, 19041}, // Windows 10 Version 2004 (May 2020 Update) (20H1) + {10, 0, 19042}, // Windows 10 Version 20H2 (October 2020 Update) (20H2) + {10, 0, 19043}, // Windows 10 Version 21H1 (May 2021 Update) (21H1) + {10, 0, 19044}, // Windows 10 Version 21H2 (November 2021 Update) (21H2) + {10, 0, 22000}, // Windows 11 Version 21H2 (21H2) +}; +static_assert((sizeof(WindowsVersions) / sizeof(WindowsVersions[0])) == (static_cast(WindowsVersion::_11_21H2) + 1)); + } // namespace Global namespace FramelessHelper::Core @@ -380,5 +521,6 @@ FRAMELESSHELPER_CORE_API void initialize(const Global::Options options = {}); FRAMELESSHELPER_END_NAMESPACE -Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global::UserSettings)) -Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global::SystemParameters)) +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionNumber) +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::UserSettings) +Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::SystemParameters) diff --git a/include/FramelessHelper/Core/utils.h b/include/FramelessHelper/Core/utils.h index fa330458..8b8a30f8 100644 --- a/include/FramelessHelper/Core/utils.h +++ b/include/FramelessHelper/Core/utils.h @@ -58,14 +58,7 @@ FRAMELESSHELPER_CORE_API void moveWindowToDesktopCenter( [[nodiscard]] FRAMELESSHELPER_CORE_API bool isTitleBarColorized(); #ifdef Q_OS_WINDOWS -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8OrGreater(); -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8Point1OrGreater(); -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10OrGreater(); -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10_1607OrGreater(); -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10_1809OrGreater(); -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10_1903OrGreater(); -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10_2004OrGreater(); -[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin11OrGreater(); +[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWindowsVersionOrGreater(const Global::WindowsVersion version); [[nodiscard]] FRAMELESSHELPER_CORE_API bool isDwmCompositionEnabled(); FRAMELESSHELPER_CORE_API void triggerFrameChange(const WId windowId); FRAMELESSHELPER_CORE_API void updateWindowFrameMargins(const WId windowId, const bool reset); diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index e0ed7376..614479a8 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -245,16 +245,16 @@ void FramelessHelperWin::addWindow(const UserSettings &settings, const SystemPar } Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true); Utils::updateWindowFrameMargins(windowId, false); - if (Utils::isWin10_1607OrGreater()) { + if (Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607)) { const bool dark = Utils::shouldAppsUseDarkMode(); if (!(settings.options & Option::DontTouchWindowFrameBorderColor)) { Utils::updateWindowFrameBorderColor(windowId, dark); } - if (Utils::isWin10_1809OrGreater()) { + if (Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809)) { if (settings.options & Option::SyncNativeControlsThemeWithSystem) { Utils::updateGlobalWin32ControlsTheme(windowId, dark); } - if (Utils::isWin11OrGreater()) { + if (Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2)) { if (settings.options & Option::MaximizeButtonDocking) { const auto hwnd = reinterpret_cast(windowId); SetLastError(ERROR_SUCCESS); @@ -458,7 +458,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me // Due to ABM_GETAUTOHIDEBAREX only exists from Win8.1, // we have to use another way to judge this if we are // running on Windows 7 or Windows 8. - if (Utils::isWin8Point1OrGreater()) { + if (Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1)) { MONITORINFO monitorInfo; SecureZeroMemory(&monitorInfo, sizeof(monitorInfo)); monitorInfo.cbSize = sizeof(monitorInfo); @@ -821,7 +821,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me } bool systemThemeChanged = ((uMsg == WM_THEMECHANGED) || (uMsg == WM_SYSCOLORCHANGE) || (uMsg == WM_DWMCOLORIZATIONCOLORCHANGED)); - if (Utils::isWin10_1607OrGreater()) { + if (Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607)) { if (uMsg == WM_SETTINGCHANGE) { if ((wParam == 0) && (QString::fromWCharArray(reinterpret_cast(lParam)) .compare(qThemeSettingChangeEventName, Qt::CaseInsensitive) == 0)) { @@ -830,7 +830,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me if (!(data.settings.options & Option::DontTouchWindowFrameBorderColor)) { Utils::updateWindowFrameBorderColor(windowId, dark); } - if (Utils::isWin10_1809OrGreater()) { + if (Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809)) { if (data.settings.options & Option::SyncNativeControlsThemeWithSystem) { Utils::updateGlobalWin32ControlsTheme(windowId, dark); } diff --git a/src/core/framelesswindowsmanager.cpp b/src/core/framelesswindowsmanager.cpp index e6362aac..d8367fa9 100644 --- a/src/core/framelesswindowsmanager.cpp +++ b/src/core/framelesswindowsmanager.cpp @@ -310,6 +310,8 @@ void FramelessHelper::Core::initialize(const Options options) qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); } diff --git a/src/core/utils_linux.cpp b/src/core/utils_linux.cpp index e99fdbef..61eed3bb 100644 --- a/src/core/utils_linux.cpp +++ b/src/core/utils_linux.cpp @@ -127,7 +127,7 @@ static inline void xcb_button_release_event_t xev; memset(&xev, 0, sizeof(xev)); xev.response_type = XCB_BUTTON_RELEASE; - xev.time = XCB_CURRENT_TIME; + xev.time = QX11Info::appTime(); xev.root = rootWindow; xev.root_x = globalPos.x(); xev.root_y = globalPos.y(); @@ -135,7 +135,7 @@ static inline void xev.event_x = localPos.x(); xev.event_y = localPos.y(); xev.same_screen = true; - xcb_send_event(connection, false, rootWindow, XCB_EVENT_MASK_BUTTON_RELEASE, + xcb_send_event(connection, false, rootWindow, XCB_EVENT_MASK_STRUCTURE_NOTIFY, reinterpret_cast(&xev)); xcb_flush(connection); } @@ -174,13 +174,26 @@ static inline void xev.data.data32[3] = XCB_BUTTON_INDEX_1; // First we need to ungrab the pointer that may have been // automatically grabbed by Qt on ButtonPressEvent. - xcb_ungrab_pointer(connection, XCB_CURRENT_TIME); + xcb_ungrab_pointer(connection, QX11Info::appTime()); xcb_send_event(connection, false, rootWindow, (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY), reinterpret_cast(&xev)); xcb_flush(connection); } +static inline void sendMouseReleaseEvent(QWindow *window, const QPoint &globalPos) +{ + Q_ASSERT(window); + if (!window) { + return; + } + const qreal dpr = window->devicePixelRatio(); + const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * dpr).toPoint(); + const QPoint logicalLocalPos = window->mapFromGlobal(globalPos); + const QPoint deviceLocalPos = QPointF(QPointF(logicalLocalPos) * dpr).toPoint(); + emulateMouseButtonRelease(window->winId(), deviceGlobalPos, deviceLocalPos); +} + SystemTheme Utils::getSystemTheme() { // ### TODO: how to detect high contrast mode on Linux? @@ -193,17 +206,13 @@ void Utils::startSystemMove(QWindow *window, const QPoint &globalPos) if (!window) { return; } - const WId windowId = window->winId(); - const qreal dpr = window->devicePixelRatio(); - const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * dpr).toPoint(); - const QPoint logicalLocalPos = window->mapFromGlobal(globalPos); - const QPoint deviceLocalPos = QPointF(QPointF(logicalLocalPos) * dpr).toPoint(); // Before we start the dragging we need to tell Qt that the mouse is released. - emulateMouseButtonRelease(windowId, deviceGlobalPos, deviceLocalPos); + sendMouseReleaseEvent(window, globalPos); #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) window->startSystemMove(); #else - doStartSystemMoveResize(windowId, deviceGlobalPos, _NET_WM_MOVERESIZE_MOVE); + const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * window->devicePixelRatio()).toPoint(); + doStartSystemMoveResize(window->winId(), deviceGlobalPos, _NET_WM_MOVERESIZE_MOVE); #endif } @@ -216,13 +225,8 @@ void Utils::startSystemResize(QWindow *window, const Qt::Edges edges, const QPoi if (edges == Qt::Edges{}) { return; } - const WId windowId = window->winId(); - const qreal dpr = window->devicePixelRatio(); - const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * dpr).toPoint(); - const QPoint logicalLocalPos = window->mapFromGlobal(globalPos); - const QPoint deviceLocalPos = QPointF(QPointF(logicalLocalPos) * dpr).toPoint(); // Before we start the resizing we need to tell Qt that the mouse is released. - emulateMouseButtonRelease(windowId, deviceGlobalPos, deviceLocalPos); + sendMouseReleaseEvent(window, globalPos); #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) window->startSystemResize(edges); #else @@ -230,7 +234,8 @@ void Utils::startSystemResize(QWindow *window, const Qt::Edges edges, const QPoi if (section < 0) { return; } - doStartSystemMoveResize(windowId, deviceGlobalPos, section); + const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * window->devicePixelRatio()).toPoint(); + doStartSystemMoveResize(window->winId(), deviceGlobalPos, section); #endif } diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index fcee7466..76d73c75 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -29,11 +29,6 @@ #include #include #include -#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) -# include -#else -# include -#endif #include #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) # include @@ -130,8 +125,8 @@ FRAMELESSHELPER_STRING_CONSTANT(SetMenuDefaultItem) FRAMELESSHELPER_STRING_CONSTANT(HiliteMenuItem) FRAMELESSHELPER_STRING_CONSTANT(TrackPopupMenu) -[[maybe_unused]] [[nodiscard]] static inline bool - isWindowsVersionOrGreater(const DWORD dwMajor, const DWORD dwMinor, const DWORD dwBuild) +[[nodiscard]] static inline bool + doCompareWindowsVersion(const DWORD dwMajor, const DWORD dwMinor, const DWORD dwBuild) { OSVERSIONINFOEXW osvi; SecureZeroMemory(&osvi, sizeof(osvi)); @@ -263,7 +258,7 @@ FRAMELESSHELPER_STRING_CONSTANT(TrackPopupMenu) return titleBarHeight; } const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true); - if (Utils::isWin11OrGreater()) { + if (Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2)) { if (maxOrFull) { return (titleBarHeight + frameSizeY); } @@ -319,52 +314,16 @@ FRAMELESSHELPER_STRING_CONSTANT(TrackPopupMenu) } } -bool Utils::isWin8OrGreater() -{ -#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8); -#else - static const bool result = (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8); -#endif - return result; -} - -bool Utils::isWin8Point1OrGreater() -{ -#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8_1); -#else - static const bool result = (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8_1); -#endif - return result; -} - -bool Utils::isWin10OrGreater() -{ -#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10); -#else - static const bool result = (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS10); -#endif - return result; -} - -bool Utils::isWin11OrGreater() +bool Utils::isWindowsVersionOrGreater(const WindowsVersion version) { -#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11); -#elif (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 22000)); -#else - static const bool result = isWindowsVersionOrGreater(10, 0, 22000); -#endif - return result; + const VersionNumber ver = WindowsVersions[static_cast(version)]; + return doCompareWindowsVersion(ver.major, ver.minor, ver.patch); } bool Utils::isDwmCompositionEnabled() { // DWM composition is always enabled and can't be disabled since Windows 8. - if (isWin8OrGreater()) { + if (isWindowsVersionOrGreater(WindowsVersion::_8)) { return true; } const auto resultFromRegistry = []() -> bool { @@ -512,7 +471,7 @@ QColor Utils::getDwmColorizationColor() DwmColorizationArea Utils::getDwmColorizationArea() { // It's a Win10 only feature. (TO BE VERIFIED) - if (!isWin10OrGreater()) { + if (!isWindowsVersionOrGreater(WindowsVersion::_10_1507)) { return DwmColorizationArea::None_; } const QWinRegistryKey themeRegistry(HKEY_CURRENT_USER, qPersonalizeRegistryKey); @@ -720,52 +679,6 @@ void Utils::syncWmPaintWithDwm() } } -bool Utils::isWin10_1607OrGreater() -{ -#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, 14393); -#endif - return result; -} - -bool Utils::isWin10_1809OrGreater() -{ -#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)); -#else - static const bool result = isWindowsVersionOrGreater(10, 0, 17763); -#endif - return result; -} - -bool Utils::isWin10_1903OrGreater() -{ -#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10_1903); -#elif (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 18362)); -#else - static const bool result = isWindowsVersionOrGreater(10, 0, 18362); -#endif - return result; -} - -bool Utils::isWin10_2004OrGreater() -{ -#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10_2004); -#elif (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) - static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 19041)); -#else - static const bool result = isWindowsVersionOrGreater(10, 0, 19041); -#endif - return result; -} - bool Utils::isHighContrastModeEnabled() { HIGHCONTRASTW hc; @@ -925,7 +838,7 @@ quint32 Utils::getFrameBorderThickness(const WId windowId, const bool scaled) return 0; } // There's no window frame border before Windows 10. - if (!isWin10OrGreater()) { + if (!isWindowsVersionOrGreater(WindowsVersion::_10_1507)) { return 0; } static const auto pDwmGetWindowAttribute = @@ -951,7 +864,7 @@ QColor Utils::getFrameBorderColor(const bool active) { // There's no window frame border before Windows 10. // So we just return a default value which is based on most window managers. - if (!isWin10OrGreater()) { + if (!isWindowsVersionOrGreater(WindowsVersion::_10_1507)) { return (active ? kDefaultBlackColor : kDefaultDarkGrayColor); } const bool dark = shouldAppsUseDarkMode(); @@ -973,7 +886,7 @@ void Utils::updateWindowFrameBorderColor(const WId windowId, const bool dark) return; } // There's no global dark theme before Win10 1607. - if (!isWin10_1607OrGreater()) { + if (!isWindowsVersionOrGreater(WindowsVersion::_10_1607)) { return; } static const auto pDwmSetWindowAttribute = @@ -983,7 +896,7 @@ void Utils::updateWindowFrameBorderColor(const WId windowId, const bool dark) return; } const auto hwnd = reinterpret_cast(windowId); - const DWORD mode = (isWin10_2004OrGreater() ? _DWMWA_USE_IMMERSIVE_DARK_MODE : _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1); + const DWORD mode = (isWindowsVersionOrGreater(WindowsVersion::_10_2004) ? _DWMWA_USE_IMMERSIVE_DARK_MODE : _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1); const BOOL value = (dark ? TRUE : FALSE); const HRESULT hr = pDwmSetWindowAttribute(hwnd, mode, &value, sizeof(value)); if (FAILED(hr)) { @@ -1106,7 +1019,7 @@ bool Utils::isWindowFrameBorderVisible() if (settings.value(kForceHideFrameBorderKeyPath, false).toBool()) { return false; } - return isWin10OrGreater(); + return isWindowsVersionOrGreater(WindowsVersion::_10_1507); }(); return result; } @@ -1114,7 +1027,7 @@ bool Utils::isWindowFrameBorderVisible() bool Utils::isTitleBarColorized() { // CHECK: is it supported on win7? - if (!isWin10OrGreater()) { + if (!isWindowsVersionOrGreater(WindowsVersion::_10_1507)) { return false; } const DwmColorizationArea area = getDwmColorizationArea(); @@ -1325,7 +1238,7 @@ SystemTheme Utils::getSystemTheme() if (isHighContrastModeEnabled()) { return SystemTheme::HighContrast; } - if (isWin10_1607OrGreater() && shouldAppsUseDarkMode()) { + if (isWindowsVersionOrGreater(WindowsVersion::_10_1607) && shouldAppsUseDarkMode()) { return SystemTheme::Dark; } return SystemTheme::Light; @@ -1338,7 +1251,7 @@ void Utils::updateGlobalWin32ControlsTheme(const WId windowId, const bool dark) return; } // There's no global dark theme for common Win32 controls before Win10 1809. - if (!isWin10_1809OrGreater()) { + if (!isWindowsVersionOrGreater(WindowsVersion::_10_1809)) { return; } static const auto pSetWindowTheme = @@ -1357,7 +1270,7 @@ void Utils::updateGlobalWin32ControlsTheme(const WId windowId, const bool dark) bool Utils::shouldAppsUseDarkMode_windows() { // The global dark mode was first introduced in Windows 10 1607. - if (!isWin10_1607OrGreater()) { + if (!isWindowsVersionOrGreater(WindowsVersion::_10_1607)) { return false; } const auto resultFromRegistry = []() -> bool { @@ -1368,7 +1281,7 @@ bool Utils::shouldAppsUseDarkMode_windows() static const auto pShouldAppsUseDarkMode = reinterpret_cast( QSystemLibrary::resolve(kuxtheme, MAKEINTRESOURCEA(132))); - if (pShouldAppsUseDarkMode && !isWin10_1903OrGreater()) { + if (pShouldAppsUseDarkMode && !isWindowsVersionOrGreater(WindowsVersion::_10_1903)) { return (pShouldAppsUseDarkMode() != FALSE); } // Starting from Windows 10 1903, "ShouldAppsUseDarkMode()" always return "TRUE" diff --git a/src/quick/framelessquickutils.cpp b/src/quick/framelessquickutils.cpp index 45fb4aca..f31bc250 100644 --- a/src/quick/framelessquickutils.cpp +++ b/src/quick/framelessquickutils.cpp @@ -56,7 +56,7 @@ qreal FramelessQuickUtils::titleBarHeight() bool FramelessQuickUtils::frameBorderVisible() { #ifdef Q_OS_WINDOWS - return (Utils::isWindowFrameBorderVisible() && !Utils::isWin11OrGreater()); + return (Utils::isWindowFrameBorderVisible() && !Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2)); #else return false; #endif diff --git a/src/quick/framelessquickwindow.cpp b/src/quick/framelessquickwindow.cpp index b0df6a56..b3ad12f4 100644 --- a/src/quick/framelessquickwindow.cpp +++ b/src/quick/framelessquickwindow.cpp @@ -641,7 +641,7 @@ bool FramelessQuickWindowPrivate::shouldIgnoreMouseEvents(const QPoint &pos) con bool FramelessQuickWindowPrivate::shouldDrawFrameBorder() const { #ifdef Q_OS_WINDOWS - return (Utils::isWindowFrameBorderVisible() && !Utils::isWin11OrGreater() + return (Utils::isWindowFrameBorderVisible() && !Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2) && !(m_settings.options & Option::DontDrawTopWindowFrameBorder)); #else return false; diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index e11b27b1..e5bb133e 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -660,7 +660,7 @@ bool FramelessWidgetsHelper::isInTitleBarDraggableArea(const QPoint &pos) const bool FramelessWidgetsHelper::shouldDrawFrameBorder() const { #ifdef Q_OS_WINDOWS - return (Utils::isWindowFrameBorderVisible() && !Utils::isWin11OrGreater() + return (Utils::isWindowFrameBorderVisible() && !Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2) && isNormal() && !(m_settings.options & Option::DontDrawTopWindowFrameBorder)); #else return false;