win: refactor & simplify

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-09-26 11:18:13 +08:00
parent f97f000cc7
commit 07101273bd
12 changed files with 310 additions and 38 deletions

View File

@ -0,0 +1,65 @@
/*
* MIT License
*
* Copyright (C) 2022 by wangwenx190 (Yuhang Zhao)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include "framelesshelpercore_global.h"
FRAMELESSHELPER_BEGIN_NAMESPACE
namespace WindowsVersionHelper
{
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin2KOrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinXPOrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinXP64OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinVistaOrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinVistaSP1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinVistaSP2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin7OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin7SP1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8Point1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8Point1Update1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10TH1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10TH2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS3OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS4OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS5OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1019H1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1019H2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1020H1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1020H2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin21H1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin21H2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin11OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1121H2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1122H2OrGreater();
} // namespace WindowsVersionHelper
FRAMELESSHELPER_END_NAMESPACE

View File

@ -30,7 +30,6 @@ HEADERS += \
$$CORE_PRIV_INC_DIR/framelessconfig_p.h \ $$CORE_PRIV_INC_DIR/framelessconfig_p.h \
$$CORE_PRIV_INC_DIR/framelessmanager_p.h \ $$CORE_PRIV_INC_DIR/framelessmanager_p.h \
$$CORE_PRIV_INC_DIR/micamaterial_p.h \ $$CORE_PRIV_INC_DIR/micamaterial_p.h \
$$CORE_PRIV_INC_DIR/registrykey_p.h \
$$CORE_PRIV_INC_DIR/sysapiloader_p.h $$CORE_PRIV_INC_DIR/sysapiloader_p.h
SOURCES += \ SOURCES += \
@ -40,7 +39,6 @@ SOURCES += \
$$CORE_SRC_DIR/framelessmanager.cpp \ $$CORE_SRC_DIR/framelessmanager.cpp \
$$CORE_SRC_DIR/framelesshelpercore_global.cpp \ $$CORE_SRC_DIR/framelesshelpercore_global.cpp \
$$CORE_SRC_DIR/micamaterial.cpp \ $$CORE_SRC_DIR/micamaterial.cpp \
$$CORE_SRC_DIR/registrykey.cpp \
$$CORE_SRC_DIR/sysapiloader.cpp \ $$CORE_SRC_DIR/sysapiloader.cpp \
$$CORE_SRC_DIR/utils.cpp $$CORE_SRC_DIR/utils.cpp
@ -50,10 +48,14 @@ RESOURCES += \
win32 { win32 {
HEADERS += \ HEADERS += \
$$CORE_PUB_INC_DIR/framelesshelper_win.h \ $$CORE_PUB_INC_DIR/framelesshelper_win.h \
$$CORE_PUB_INC_DIR/framelesshelper_windows.h $$CORE_PUB_INC_DIR/framelesshelper_windows.h \
$$CORE_PRIV_INC_DIR/registrykey_p.h \
$$CORE_PRIV_INC_DIR/winverhelper_p.h
SOURCES += \ SOURCES += \
$$CORE_SRC_DIR/framelesshelper_win.cpp \ $$CORE_SRC_DIR/framelesshelper_win.cpp \
$$CORE_SRC_DIR/utils_win.cpp $$CORE_SRC_DIR/utils_win.cpp \
$$CORE_SRC_DIR/registrykey.cpp \
$$CORE_SRC_DIR/winverhelper.cpp
LIBS += -luser32 -lgdi32 LIBS += -luser32 -lgdi32
} }

View File

@ -86,11 +86,13 @@ if(WIN32)
) )
list(APPEND PRIVATE_HEADERS list(APPEND PRIVATE_HEADERS
${INCLUDE_PREFIX}/private/registrykey_p.h ${INCLUDE_PREFIX}/private/registrykey_p.h
${INCLUDE_PREFIX}/private/winverhelper_p.h
) )
list(APPEND SOURCES list(APPEND SOURCES
registrykey.cpp registrykey.cpp
utils_win.cpp utils_win.cpp
framelesshelper_win.cpp framelesshelper_win.cpp
winverhelper.cpp
) )
elseif(APPLE) elseif(APPLE)
list(APPEND SOURCES utils_mac.mm) list(APPEND SOURCES utils_mac.mm)

View File

@ -33,6 +33,7 @@
#include "framelessmanager_p.h" #include "framelessmanager_p.h"
#include "framelessconfig_p.h" #include "framelessconfig_p.h"
#include "utils.h" #include "utils.h"
#include "winverhelper_p.h"
#include "framelesshelper_windows.h" #include "framelesshelper_windows.h"
#include <optional> #include <optional>
@ -392,8 +393,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
if (!parentWindowId) { if (!parentWindowId) {
return false; return false;
} }
static const bool isWin10OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507); if (!WindowsVersionHelper::isWin10OrGreater()) {
if (!isWin10OrGreater) {
WARNING << "The fallback title bar window is only supported on Windows 10 and onwards."; WARNING << "The fallback title bar window is only supported on Windows 10 and onwards.";
return false; return false;
} }
@ -522,22 +522,19 @@ void FramelessHelperWin::addWindow(const SystemParameters &params)
Utils::updateWindowFrameMargins(windowId, false); Utils::updateWindowFrameMargins(windowId, false);
// Tell DWM we don't use the window icon/caption/sysmenu, don't draw them. // Tell DWM we don't use the window icon/caption/sysmenu, don't draw them.
Utils::disableOriginalTitleBarFunctionalities(windowId); Utils::disableOriginalTitleBarFunctionalities(windowId);
static const bool isWin10RS1OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607); if (WindowsVersionHelper::isWin10RS1OrGreater()) {
if (isWin10RS1OrGreater) {
// Tell DWM we may need dark theme non-client area (title bar & frame border). // Tell DWM we may need dark theme non-client area (title bar & frame border).
FramelessHelper::Core::setApplicationOSThemeAware(); FramelessHelper::Core::setApplicationOSThemeAware();
const bool dark = Utils::shouldAppsUseDarkMode(); const bool dark = Utils::shouldAppsUseDarkMode();
Utils::updateWindowFrameBorderColor(windowId, dark); Utils::updateWindowFrameBorderColor(windowId, dark);
static const bool isWin10RS5OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809); if (WindowsVersionHelper::isWin10RS5OrGreater()) {
if (isWin10RS5OrGreater) {
static const bool isQtQuickApplication = (params.getCurrentApplicationType() == ApplicationType::Quick); static const bool isQtQuickApplication = (params.getCurrentApplicationType() == ApplicationType::Quick);
if (isQtQuickApplication) { if (isQtQuickApplication) {
// Tell UXTheme we may need dark theme controls. // Tell UXTheme we may need dark theme controls.
// Causes some QtWidgets paint incorrectly, so only apply to Qt Quick applications. // Causes some QtWidgets paint incorrectly, so only apply to Qt Quick applications.
Utils::updateGlobalWin32ControlsTheme(windowId, dark); Utils::updateGlobalWin32ControlsTheme(windowId, dark);
} }
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2); if (WindowsVersionHelper::isWin11OrGreater()) {
if (isWin11OrGreater) {
const FramelessConfig * const config = FramelessConfig::instance(); const FramelessConfig * const config = FramelessConfig::instance();
// Set the frame corner style, only Win11 provides official public API to do it. // Set the frame corner style, only Win11 provides official public API to do it.
// On Win7~Win10, you'll need to use SetWindowRgn(), which will break the frame shadow. // On Win7~Win10, you'll need to use SetWindowRgn(), which will break the frame shadow.
@ -772,8 +769,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// Due to ABM_GETAUTOHIDEBAREX was introduced in Windows 8.1, // Due to ABM_GETAUTOHIDEBAREX was introduced in Windows 8.1,
// we have to use another way to judge this if we are running // we have to use another way to judge this if we are running
// on Windows 7 or Windows 8. // on Windows 7 or Windows 8.
static const bool isWin8Point1OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1); if (WindowsVersionHelper::isWin8Point1OrGreater()) {
if (isWin8Point1OrGreater) {
MONITORINFO monitorInfo; MONITORINFO monitorInfo;
SecureZeroMemory(&monitorInfo, sizeof(monitorInfo)); SecureZeroMemory(&monitorInfo, sizeof(monitorInfo));
monitorInfo.cbSize = sizeof(monitorInfo); monitorInfo.cbSize = sizeof(monitorInfo);
@ -1165,8 +1161,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
break; break;
} }
} }
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2); if (WindowsVersionHelper::isWin11OrGreater() && data.fallbackTitleBarWindowId) {
if (isWin11OrGreater && data.fallbackTitleBarWindowId) {
switch (uMsg) { switch (uMsg) {
case WM_SIZE: // Sent to a window after its size has changed. case WM_SIZE: // Sent to a window after its size has changed.
case WM_DISPLAYCHANGE: // Sent to a window when the display resolution has changed. case WM_DISPLAYCHANGE: // Sent to a window when the display resolution has changed.
@ -1183,8 +1178,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
const bool wallpaperChanged = ((uMsg == WM_SETTINGCHANGE) && (wParam == SPI_SETDESKWALLPAPER)); const bool wallpaperChanged = ((uMsg == WM_SETTINGCHANGE) && (wParam == SPI_SETDESKWALLPAPER));
bool systemThemeChanged = ((uMsg == WM_THEMECHANGED) || (uMsg == WM_SYSCOLORCHANGE) bool systemThemeChanged = ((uMsg == WM_THEMECHANGED) || (uMsg == WM_SYSCOLORCHANGE)
|| (uMsg == WM_DWMCOLORIZATIONCOLORCHANGED)); || (uMsg == WM_DWMCOLORIZATIONCOLORCHANGED));
static const bool isWin10RS1OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607); if (WindowsVersionHelper::isWin10RS1OrGreater()) {
if (isWin10RS1OrGreater) {
if (uMsg == WM_SETTINGCHANGE) { if (uMsg == WM_SETTINGCHANGE) {
if ((wParam == 0) && (lParam != 0) // lParam sometimes may be NULL. if ((wParam == 0) && (lParam != 0) // lParam sometimes may be NULL.
&& (std::wcscmp(reinterpret_cast<LPCWSTR>(lParam), kThemeSettingChangeEventName) == 0)) { && (std::wcscmp(reinterpret_cast<LPCWSTR>(lParam), kThemeSettingChangeEventName) == 0)) {
@ -1193,8 +1187,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
Utils::updateWindowFrameBorderColor(windowId, dark); Utils::updateWindowFrameBorderColor(windowId, dark);
#endif #endif
static const bool isWin10RS5OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809); if (WindowsVersionHelper::isWin10RS5OrGreater()) {
if (isWin10RS5OrGreater) {
static const bool isQtQuickApplication = (data.params.getCurrentApplicationType() == ApplicationType::Quick); static const bool isQtQuickApplication = (data.params.getCurrentApplicationType() == ApplicationType::Quick);
if (isQtQuickApplication) { if (isQtQuickApplication) {
// Causes some QtWidgets paint incorrectly, so only apply to Qt Quick applications. // Causes some QtWidgets paint incorrectly, so only apply to Qt Quick applications.

View File

@ -38,6 +38,7 @@
#include "utils.h" #include "utils.h"
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
# include "framelesshelper_win.h" # include "framelesshelper_win.h"
# include "winverhelper_p.h"
#endif #endif
// The "Q_INIT_RESOURCE()" macro can't be used within a namespace, // The "Q_INIT_RESOURCE()" macro can't be used within a namespace,
@ -89,12 +90,10 @@ FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb")
{ {
static const QString result = []() -> QString { static const QString result = []() -> QString {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2); if (WindowsVersionHelper::isWin11OrGreater()) {
if (isWin11OrGreater) {
return kIconFontFamilyName_win11; return kIconFontFamilyName_win11;
} }
static const bool isWin10OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507); if (WindowsVersionHelper::isWin10OrGreater()) {
if (isWin10OrGreater) {
return kIconFontFamilyName_win10; return kIconFontFamilyName_win10;
} }
#endif #endif

View File

@ -42,6 +42,7 @@
#include "framelessconfig_p.h" #include "framelessconfig_p.h"
#include "sysapiloader_p.h" #include "sysapiloader_p.h"
#include "registrykey_p.h" #include "registrykey_p.h"
#include "winverhelper_p.h"
#include <uxtheme.h> #include <uxtheme.h>
#include <d2d1.h> #include <d2d1.h>
@ -390,8 +391,7 @@ struct SYSTEM_METRIC
return titleBarHeight; return titleBarHeight;
} }
const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true); const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true);
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2); if (WindowsVersionHelper::isWin11OrGreater()) {
if (isWin11OrGreater) {
if (maxOrFull) { if (maxOrFull) {
return (titleBarHeight + frameSizeY); return (titleBarHeight + frameSizeY);
} }

203
src/core/winverhelper.cpp Normal file
View File

@ -0,0 +1,203 @@
/*
* MIT License
*
* Copyright (C) 2022 by wangwenx190 (Yuhang Zhao)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "winverhelper_p.h"
#include "utils.h"
FRAMELESSHELPER_BEGIN_NAMESPACE
using namespace Global;
namespace WindowsVersionHelper
{
bool isWin2KOrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_2000);
return result;
}
bool isWinXPOrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_XP);
return result;
}
bool isWinXP64OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_XP_64);
return result;
}
bool isWinVistaOrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_Vista);
return result;
}
bool isWinVistaSP1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_Vista_SP1);
return result;
}
bool isWinVistaSP2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_Vista_SP2);
return result;
}
bool isWin7OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_7);
return result;
}
bool isWin7SP1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_7_SP1);
return result;
}
bool isWin8OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_8);
return result;
}
bool isWin8Point1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1);
return result;
}
bool isWin8Point1Update1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1_Update1);
return result;
}
bool isWin10OrGreater()
{
return isWin10TH1OrGreater();
}
bool isWin10TH1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return result;
}
bool isWin10TH2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1511);
return result;
}
bool isWin10RS1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607);
return result;
}
bool isWin10RS2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1703);
return result;
}
bool isWin10RS3OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1709);
return result;
}
bool isWin10RS4OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1803);
return result;
}
bool isWin10RS5OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809);
return result;
}
bool isWin1019H1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1903);
return result;
}
bool isWin1019H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1909);
return result;
}
bool isWin1020H1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_2004);
return result;
}
bool isWin1020H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_20H2);
return result;
}
bool isWin21H1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_21H1);
return result;
}
bool isWin21H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_21H2);
return result;
}
bool isWin11OrGreater()
{
return isWin1121H2OrGreater();
}
bool isWin1121H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
return result;
}
bool isWin1122H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_22H2);
return result;
}
} // namespace WindowsVersionHelper
FRAMELESSHELPER_END_NAMESPACE

View File

@ -0,0 +1 @@
#include "../../include/FramelessHelper/Core/private/winverhelper_p.h"

View File

@ -39,6 +39,9 @@
#include <framelessmanager.h> #include <framelessmanager.h>
#include <framelessconfig_p.h> #include <framelessconfig_p.h>
#include <utils.h> #include <utils.h>
#ifdef Q_OS_WINDOWS
# include <winverhelper_p.h>
#endif // Q_OS_WINDOWS
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE
@ -562,21 +565,20 @@ bool FramelessQuickHelperPrivate::eventFilter(QObject *object, QEvent *event)
} }
const auto window = qobject_cast<QQuickWindow *>(object); const auto window = qobject_cast<QQuickWindow *>(object);
const WId windowId = window->winId(); const WId windowId = window->winId();
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
const bool roundCorner = FramelessConfig::instance()->isSet(Option::WindowUseRoundCorners); const bool roundCorner = FramelessConfig::instance()->isSet(Option::WindowUseRoundCorners);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
if (Utils::windowStatesToWindowState(window->windowStates()) == Qt::WindowFullScreen) { if (Utils::windowStatesToWindowState(window->windowStates()) == Qt::WindowFullScreen) {
#else #else
if (window->windowState() == Qt::WindowFullScreen) { if (window->windowState() == Qt::WindowFullScreen) {
#endif #endif
if (isWin11OrGreater && roundCorner) { if (WindowsVersionHelper::isWin11OrGreater() && roundCorner) {
Utils::forceSquareCornersForWindow(windowId, true); Utils::forceSquareCornersForWindow(windowId, true);
} }
} else { } else {
const auto changeEvent = static_cast<QWindowStateChangeEvent *>(event); const auto changeEvent = static_cast<QWindowStateChangeEvent *>(event);
if (Utils::windowStatesToWindowState(changeEvent->oldState()) == Qt::WindowFullScreen) { if (Utils::windowStatesToWindowState(changeEvent->oldState()) == Qt::WindowFullScreen) {
Utils::maybeFixupQtInternals(windowId); Utils::maybeFixupQtInternals(windowId);
if (isWin11OrGreater && roundCorner) { if (WindowsVersionHelper::isWin11OrGreater() && roundCorner) {
Utils::forceSquareCornersForWindow(windowId, false); Utils::forceSquareCornersForWindow(windowId, false);
} }
} }

View File

@ -25,6 +25,9 @@
#include "framelessquickutils.h" #include "framelessquickutils.h"
#include <framelessmanager.h> #include <framelessmanager.h>
#include <utils.h> #include <utils.h>
#ifdef Q_OS_WINDOWS
# include <winverhelper_p.h>
#endif // Q_OS_WINDOWS
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE
@ -55,8 +58,7 @@ qreal FramelessQuickUtils::titleBarHeight() const
bool FramelessQuickUtils::frameBorderVisible() const bool FramelessQuickUtils::frameBorderVisible() const
{ {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2); return (Utils::isWindowFrameBorderVisible() && !WindowsVersionHelper::isWin11OrGreater());
return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater);
#else #else
return false; return false;
#endif #endif

View File

@ -31,6 +31,9 @@
#include <QtQuick/private/qquickanchors_p.h> #include <QtQuick/private/qquickanchors_p.h>
#include <framelessmanager.h> #include <framelessmanager.h>
#include <utils.h> #include <utils.h>
#ifdef Q_OS_WINDOWS
# include <winverhelper_p.h>
#endif // Q_OS_WINDOWS
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE
@ -193,8 +196,7 @@ void FramelessQuickWindowPrivate::initialize()
bool FramelessQuickWindowPrivate::shouldDrawFrameBorder() const bool FramelessQuickWindowPrivate::shouldDrawFrameBorder() const
{ {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2); return (Utils::isWindowFrameBorderVisible() && !WindowsVersionHelper::isWin11OrGreater());
return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater);
#else #else
return false; return false;
#endif #endif

View File

@ -32,6 +32,9 @@
#include <micamaterial.h> #include <micamaterial.h>
#include <micamaterial_p.h> #include <micamaterial_p.h>
#include <utils.h> #include <utils.h>
#ifdef Q_OS_WINDOWS
# include <winverhelper_p.h>
#endif // Q_OS_WINDOWS
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE
@ -159,17 +162,16 @@ void WidgetsSharedHelper::changeEventHandler(QEvent *event)
} }
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
const WId windowId = m_targetWidget->winId(); const WId windowId = m_targetWidget->winId();
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
const bool roundCorner = FramelessConfig::instance()->isSet(Option::WindowUseRoundCorners); const bool roundCorner = FramelessConfig::instance()->isSet(Option::WindowUseRoundCorners);
if (Utils::windowStatesToWindowState(m_targetWidget->windowState()) == Qt::WindowFullScreen) { if (Utils::windowStatesToWindowState(m_targetWidget->windowState()) == Qt::WindowFullScreen) {
if (isWin11OrGreater && roundCorner) { if (WindowsVersionHelper::isWin11OrGreater() && roundCorner) {
Utils::forceSquareCornersForWindow(windowId, true); Utils::forceSquareCornersForWindow(windowId, true);
} }
} else { } else {
const auto changeEvent = static_cast<QWindowStateChangeEvent *>(event); const auto changeEvent = static_cast<QWindowStateChangeEvent *>(event);
if (Utils::windowStatesToWindowState(changeEvent->oldState()) == Qt::WindowFullScreen) { if (Utils::windowStatesToWindowState(changeEvent->oldState()) == Qt::WindowFullScreen) {
Utils::maybeFixupQtInternals(windowId); Utils::maybeFixupQtInternals(windowId);
if (isWin11OrGreater && roundCorner) { if (WindowsVersionHelper::isWin11OrGreater() && roundCorner) {
Utils::forceSquareCornersForWindow(windowId, false); Utils::forceSquareCornersForWindow(windowId, false);
} }
} }
@ -215,8 +217,7 @@ void WidgetsSharedHelper::paintEventHandler(QPaintEvent *event)
bool WidgetsSharedHelper::shouldDrawFrameBorder() const bool WidgetsSharedHelper::shouldDrawFrameBorder() const
{ {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2); return (Utils::isWindowFrameBorderVisible() && !WindowsVersionHelper::isWin11OrGreater()
return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater
&& (Utils::windowStatesToWindowState(m_targetWidget->windowState()) == Qt::WindowNoState)); && (Utils::windowStatesToWindowState(m_targetWidget->windowState()) == Qt::WindowNoState));
#else #else
return false; return false;