common: minor tweaks

Code simplification, format changes, etc ...

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-05-11 17:32:14 +08:00
parent aad6957a52
commit a1acc3e06f
11 changed files with 105 additions and 121 deletions

View File

@ -283,6 +283,14 @@ enum class WindowsVersion
}; };
Q_ENUM_NS(WindowsVersion) Q_ENUM_NS(WindowsVersion)
enum class ApplicationType
{
Widgets = 0, // Pure QtWidgets applications
Quick = 1, // Pure QtQuick applications
Hybrid = 2 // Use both QtWidgets and QtQuick
};
Q_ENUM_NS(ApplicationType)
struct VersionNumber struct VersionNumber
{ {
int major = 0; int major = 0;
@ -347,75 +355,51 @@ struct VersionNumber
using GetWindowFlagsCallback = std::function<Qt::WindowFlags()>; using GetWindowFlagsCallback = std::function<Qt::WindowFlags()>;
using SetWindowFlagsCallback = std::function<void(const Qt::WindowFlags)>; using SetWindowFlagsCallback = std::function<void(const Qt::WindowFlags)>;
using GetWindowSizeCallback = std::function<QSize()>; using GetWindowSizeCallback = std::function<QSize()>;
using SetWindowSizeCallback = std::function<void(const QSize &)>; using SetWindowSizeCallback = std::function<void(const QSize &)>;
using GetWindowPositionCallback = std::function<QPoint()>; using GetWindowPositionCallback = std::function<QPoint()>;
using SetWindowPositionCallback = std::function<void(const QPoint &)>; using SetWindowPositionCallback = std::function<void(const QPoint &)>;
using GetWindowScreenCallback = std::function<QScreen *()>; using GetWindowScreenCallback = std::function<QScreen *()>;
using IsWindowFixedSizeCallback = std::function<bool()>; using IsWindowFixedSizeCallback = std::function<bool()>;
using SetWindowFixedSizeCallback = std::function<void(const bool)>; using SetWindowFixedSizeCallback = std::function<void(const bool)>;
using GetWindowStateCallback = std::function<Qt::WindowState()>; using GetWindowStateCallback = std::function<Qt::WindowState()>;
using SetWindowStateCallback = std::function<void(const Qt::WindowState)>; using SetWindowStateCallback = std::function<void(const Qt::WindowState)>;
using GetWindowHandleCallback = std::function<QWindow *()>; using GetWindowHandleCallback = std::function<QWindow *()>;
using WindowToScreenCallback = std::function<QPoint(const QPoint &)>; using WindowToScreenCallback = std::function<QPoint(const QPoint &)>;
using ScreenToWindowCallback = std::function<QPoint(const QPoint &)>; using ScreenToWindowCallback = std::function<QPoint(const QPoint &)>;
using IsInsideSystemButtonsCallback = std::function<bool(const QPoint &, SystemButtonType *)>; using IsInsideSystemButtonsCallback = std::function<bool(const QPoint &, SystemButtonType *)>;
using IsInsideTitleBarDraggableAreaCallback = std::function<bool(const QPoint &)>; using IsInsideTitleBarDraggableAreaCallback = std::function<bool(const QPoint &)>;
using GetWindowDevicePixelRatioCallback = std::function<qreal()>; using GetWindowDevicePixelRatioCallback = std::function<qreal()>;
using SetSystemButtonStateCallback = std::function<void(const SystemButtonType, const ButtonState)>; using SetSystemButtonStateCallback = std::function<void(const SystemButtonType, const ButtonState)>;
using GetWindowIdCallback = std::function<WId()>; using GetWindowIdCallback = std::function<WId()>;
using ShouldIgnoreMouseEventsCallback = std::function<bool(const QPoint &)>; using ShouldIgnoreMouseEventsCallback = std::function<bool(const QPoint &)>;
using ShowSystemMenuCallback = std::function<void(const QPoint &)>; using ShowSystemMenuCallback = std::function<void(const QPoint &)>;
using GetCurrentApplicationTypeCallback = std::function<ApplicationType()>;
struct SystemParameters struct SystemParameters
{ {
GetWindowFlagsCallback getWindowFlags = nullptr; GetWindowFlagsCallback getWindowFlags = nullptr;
SetWindowFlagsCallback setWindowFlags = nullptr; SetWindowFlagsCallback setWindowFlags = nullptr;
GetWindowSizeCallback getWindowSize = nullptr; GetWindowSizeCallback getWindowSize = nullptr;
SetWindowSizeCallback setWindowSize = nullptr; SetWindowSizeCallback setWindowSize = nullptr;
GetWindowPositionCallback getWindowPosition = nullptr; GetWindowPositionCallback getWindowPosition = nullptr;
SetWindowPositionCallback setWindowPosition = nullptr; SetWindowPositionCallback setWindowPosition = nullptr;
GetWindowScreenCallback getWindowScreen = nullptr; GetWindowScreenCallback getWindowScreen = nullptr;
IsWindowFixedSizeCallback isWindowFixedSize = nullptr; IsWindowFixedSizeCallback isWindowFixedSize = nullptr;
SetWindowFixedSizeCallback setWindowFixedSize = nullptr; SetWindowFixedSizeCallback setWindowFixedSize = nullptr;
GetWindowStateCallback getWindowState = nullptr; GetWindowStateCallback getWindowState = nullptr;
SetWindowStateCallback setWindowState = nullptr; SetWindowStateCallback setWindowState = nullptr;
GetWindowHandleCallback getWindowHandle = nullptr; GetWindowHandleCallback getWindowHandle = nullptr;
WindowToScreenCallback windowToScreen = nullptr; WindowToScreenCallback windowToScreen = nullptr;
ScreenToWindowCallback screenToWindow = nullptr; ScreenToWindowCallback screenToWindow = nullptr;
IsInsideSystemButtonsCallback isInsideSystemButtons = nullptr; IsInsideSystemButtonsCallback isInsideSystemButtons = nullptr;
IsInsideTitleBarDraggableAreaCallback isInsideTitleBarDraggableArea = nullptr; IsInsideTitleBarDraggableAreaCallback isInsideTitleBarDraggableArea = nullptr;
GetWindowDevicePixelRatioCallback getWindowDevicePixelRatio = nullptr; GetWindowDevicePixelRatioCallback getWindowDevicePixelRatio = nullptr;
SetSystemButtonStateCallback setSystemButtonState = nullptr; SetSystemButtonStateCallback setSystemButtonState = nullptr;
GetWindowIdCallback getWindowId = nullptr; GetWindowIdCallback getWindowId = nullptr;
ShouldIgnoreMouseEventsCallback shouldIgnoreMouseEvents = nullptr; ShouldIgnoreMouseEventsCallback shouldIgnoreMouseEvents = nullptr;
ShowSystemMenuCallback showSystemMenu = nullptr; ShowSystemMenuCallback showSystemMenu = nullptr;
GetCurrentApplicationTypeCallback getCurrentApplicationType = nullptr;
[[nodiscard]] inline bool isValid() const [[nodiscard]] inline bool isValid() const
{ {
@ -440,6 +424,7 @@ struct SystemParameters
Q_ASSERT(getWindowId); Q_ASSERT(getWindowId);
Q_ASSERT(shouldIgnoreMouseEvents); Q_ASSERT(shouldIgnoreMouseEvents);
Q_ASSERT(showSystemMenu); Q_ASSERT(showSystemMenu);
Q_ASSERT(getCurrentApplicationType);
return (getWindowFlags && setWindowFlags && getWindowSize return (getWindowFlags && setWindowFlags && getWindowSize
&& setWindowSize && getWindowPosition && setWindowPosition && setWindowSize && getWindowPosition && setWindowPosition
&& getWindowScreen && isWindowFixedSize && setWindowFixedSize && getWindowScreen && isWindowFixedSize && setWindowFixedSize
@ -447,7 +432,7 @@ struct SystemParameters
&& windowToScreen && screenToWindow && isInsideSystemButtons && windowToScreen && screenToWindow && isInsideSystemButtons
&& isInsideTitleBarDraggableArea && getWindowDevicePixelRatio && isInsideTitleBarDraggableArea && getWindowDevicePixelRatio
&& setSystemButtonState && getWindowId && shouldIgnoreMouseEvents && setSystemButtonState && getWindowId && shouldIgnoreMouseEvents
&& showSystemMenu); && showSystemMenu && getCurrentApplicationType);
} }
}; };

View File

@ -135,6 +135,44 @@ struct FRAMELESSHELPER_QUICK_API QuickGlobal
}; };
Q_ENUM(ButtonState) Q_ENUM(ButtonState)
enum class WindowsVersion
{
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _2000)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _XP)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _XP_64)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _Vista)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _Vista_SP1)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _Vista_SP2)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _7)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _7_SP1)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _8)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _8_1)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _8_1_Update1)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1507)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1511)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1607)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1703)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1709)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1803)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1809)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1903)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_1909)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_2004)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_20H2)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_21H1)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _10_21H2)
FRAMELESSHELPER_QUICK_ENUM_VALUE(WindowsVersion, _11_21H2)
};
Q_ENUM(WindowsVersion)
enum class ApplicationType
{
FRAMELESSHELPER_QUICK_ENUM_VALUE(ApplicationType, Widgets)
FRAMELESSHELPER_QUICK_ENUM_VALUE(ApplicationType, Quick)
FRAMELESSHELPER_QUICK_ENUM_VALUE(ApplicationType, Hybrid)
};
Q_ENUM(ApplicationType)
private: private:
Q_GADGET Q_GADGET
#ifdef QML_NAMED_ELEMENT #ifdef QML_NAMED_ELEMENT

View File

@ -359,9 +359,7 @@ FRAMELESSHELPER_STRING_CONSTANT(FindWindowW)
if (!parentWindowId) { if (!parentWindowId) {
return false; return false;
} }
static const bool isWin10OrGreater = []() -> bool { static const bool isWin10OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
}();
if (!isWin10OrGreater) { if (!isWin10OrGreater) {
qWarning() << "The drag bar window is only supported on Windows 10 and onwards."; qWarning() << "The drag bar window is only supported on Windows 10 and onwards.";
return false; return false;
@ -446,9 +444,7 @@ void FramelessHelperWin::addWindow(const SystemParameters &params)
Utils::fixupQtInternals(windowId); Utils::fixupQtInternals(windowId);
Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true); Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true);
Utils::updateWindowFrameMargins(windowId, false); Utils::updateWindowFrameMargins(windowId, false);
static const bool isWin10OrGreater = []() -> bool { static const bool isWin10OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
}();
if (isWin10OrGreater) { if (isWin10OrGreater) {
const FramelessConfig * const config = FramelessConfig::instance(); const FramelessConfig * const config = FramelessConfig::instance();
if (!config->isSet(Option::DisableWindowsSnapLayouts)) { if (!config->isSet(Option::DisableWindowsSnapLayouts)) {
@ -456,20 +452,18 @@ void FramelessHelperWin::addWindow(const SystemParameters &params)
qWarning() << "Failed to create the drag bar window."; qWarning() << "Failed to create the drag bar window.";
} }
} }
static const bool isWin10RS1OrGreater = []() -> bool { static const bool isWin10RS1OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607);
}();
if (isWin10RS1OrGreater) { if (isWin10RS1OrGreater) {
const bool dark = Utils::shouldAppsUseDarkMode(); const bool dark = Utils::shouldAppsUseDarkMode();
Utils::updateWindowFrameBorderColor(windowId, dark); Utils::updateWindowFrameBorderColor(windowId, dark);
static const bool isWin10RS5OrGreater = []() -> bool { static const bool isWin10RS5OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809);
}();
if (isWin10RS5OrGreater) { if (isWin10RS5OrGreater) {
//Utils::updateGlobalWin32ControlsTheme(windowId, dark); // Causes some QtWidgets paint incorrectly. static const bool isQtQuickApplication = (params.getCurrentApplicationType() == ApplicationType::Quick);
static const bool isWin11OrGreater = []() -> bool { if (isQtQuickApplication) {
return Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2); // Causes some QtWidgets paint incorrectly, so only apply to Qt Quick applications.
}(); Utils::updateGlobalWin32ControlsTheme(windowId, dark);
}
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
if (isWin11OrGreater) { if (isWin11OrGreater) {
Utils::forceSquareCornersForWindow(windowId, !config->isSet(Option::WindowUseRoundCorners)); Utils::forceSquareCornersForWindow(windowId, !config->isSet(Option::WindowUseRoundCorners));
} }
@ -650,9 +644,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 = []() -> bool { static const bool isWin8Point1OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1);
}();
if (isWin8Point1OrGreater) { if (isWin8Point1OrGreater) {
MONITORINFO monitorInfo; MONITORINFO monitorInfo;
SecureZeroMemory(&monitorInfo, sizeof(monitorInfo)); SecureZeroMemory(&monitorInfo, sizeof(monitorInfo));
@ -1034,9 +1026,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
break; break;
} }
} }
static const bool isWin10OrGreater = []() -> bool { static const bool isWin10OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
}();
if (isWin10OrGreater && data.dragBarWindowId) { if (isWin10OrGreater && data.dragBarWindowId) {
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.
@ -1052,9 +1042,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
} }
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 = []() -> bool { static const bool isWin10RS1OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607);
}();
if (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.
@ -1062,11 +1050,13 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
systemThemeChanged = true; systemThemeChanged = true;
const bool dark = Utils::shouldAppsUseDarkMode(); const bool dark = Utils::shouldAppsUseDarkMode();
Utils::updateWindowFrameBorderColor(windowId, dark); Utils::updateWindowFrameBorderColor(windowId, dark);
static const bool isWin10RS5OrGreater = []() -> bool { static const bool isWin10RS5OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809);
}();
if (isWin10RS5OrGreater) { if (isWin10RS5OrGreater) {
//Utils::updateGlobalWin32ControlsTheme(windowId, dark); // Causes some QtWidgets paint incorrectly. static const bool isQtQuickApplication = (data.params.getCurrentApplicationType() == ApplicationType::Quick);
if (isQtQuickApplication) {
// Causes some QtWidgets paint incorrectly, so only apply to Qt Quick applications.
Utils::updateGlobalWin32ControlsTheme(windowId, dark);
}
} }
} }
} }

View File

@ -284,6 +284,7 @@ void FramelessHelper::Core::initialize()
qRegisterMetaType<Anchor>(); qRegisterMetaType<Anchor>();
qRegisterMetaType<ButtonState>(); qRegisterMetaType<ButtonState>();
qRegisterMetaType<WindowsVersion>(); qRegisterMetaType<WindowsVersion>();
qRegisterMetaType<ApplicationType>();
qRegisterMetaType<VersionNumber>(); qRegisterMetaType<VersionNumber>();
qRegisterMetaType<SystemParameters>(); qRegisterMetaType<SystemParameters>();
} }

View File

@ -259,9 +259,7 @@ FRAMELESSHELPER_STRING_CONSTANT2(HKEY_CURRENT_USER, "HKEY_CURRENT_USER")
return titleBarHeight; return titleBarHeight;
} }
const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true); const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true);
static const bool isWin11OrGreater = []() -> bool { static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
}();
if (isWin11OrGreater) { if (isWin11OrGreater) {
if (maxOrFull) { if (maxOrFull) {
return (titleBarHeight + frameSizeY); return (titleBarHeight + frameSizeY);
@ -347,9 +345,7 @@ bool Utils::isWindowsVersionOrGreater(const WindowsVersion version)
bool Utils::isDwmCompositionEnabled() bool Utils::isDwmCompositionEnabled()
{ {
// DWM composition is always enabled and can't be disabled since Windows 8. // DWM composition is always enabled and can't be disabled since Windows 8.
static const bool isWin8OrGreater = []() -> bool { static const bool isWin8OrGreater = isWindowsVersionOrGreater(WindowsVersion::_8);
return isWindowsVersionOrGreater(WindowsVersion::_8);
}();
if (isWin8OrGreater) { if (isWin8OrGreater) {
return true; return true;
} }
@ -500,9 +496,7 @@ QColor Utils::getDwmColorizationColor()
DwmColorizationArea Utils::getDwmColorizationArea() DwmColorizationArea Utils::getDwmColorizationArea()
{ {
// It's a Win10 only feature. (TO BE VERIFIED) // It's a Win10 only feature. (TO BE VERIFIED)
static const bool isWin10OrGreater = []() -> bool { static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return isWindowsVersionOrGreater(WindowsVersion::_10_1507);
}();
if (!isWin10OrGreater) { if (!isWin10OrGreater) {
return DwmColorizationArea::None_; return DwmColorizationArea::None_;
} }
@ -862,9 +856,7 @@ quint32 Utils::getFrameBorderThickness(const WId windowId, const bool scaled)
return 0; return 0;
} }
// There's no window frame border before Windows 10. // There's no window frame border before Windows 10.
static const bool isWin10OrGreater = []() -> bool { static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return isWindowsVersionOrGreater(WindowsVersion::_10_1507);
}();
if (!isWin10OrGreater) { if (!isWin10OrGreater) {
return 0; return 0;
} }
@ -891,9 +883,7 @@ QColor Utils::getFrameBorderColor(const bool active)
{ {
// There's no window frame border before Windows 10. // There's no window frame border before Windows 10.
// So we just return a default value which is based on most window managers. // So we just return a default value which is based on most window managers.
static const bool isWin10OrGreater = []() -> bool { static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return isWindowsVersionOrGreater(WindowsVersion::_10_1507);
}();
if (!isWin10OrGreater) { if (!isWin10OrGreater) {
return (active ? kDefaultBlackColor : kDefaultDarkGrayColor); return (active ? kDefaultBlackColor : kDefaultDarkGrayColor);
} }
@ -916,9 +906,7 @@ void Utils::updateWindowFrameBorderColor(const WId windowId, const bool dark)
return; return;
} }
// There's no global dark theme before Win10 1607. // There's no global dark theme before Win10 1607.
static const bool isWin10RS1OrGreater = []() -> bool { static const bool isWin10RS1OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1607);
return isWindowsVersionOrGreater(WindowsVersion::_10_1607);
}();
if (!isWin10RS1OrGreater) { if (!isWin10RS1OrGreater) {
return; return;
} }
@ -929,9 +917,7 @@ void Utils::updateWindowFrameBorderColor(const WId windowId, const bool dark)
return; return;
} }
const auto hwnd = reinterpret_cast<HWND>(windowId); const auto hwnd = reinterpret_cast<HWND>(windowId);
static const bool isWin1020H1OrGreater = []() -> bool { static const bool isWin1020H1OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_2004);
return isWindowsVersionOrGreater(WindowsVersion::_10_2004);
}();
const DWORD mode = (isWin1020H1OrGreater ? _DWMWA_USE_IMMERSIVE_DARK_MODE : _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1); const DWORD mode = (isWin1020H1OrGreater ? _DWMWA_USE_IMMERSIVE_DARK_MODE : _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1);
const BOOL value = (dark ? TRUE : FALSE); const BOOL value = (dark ? TRUE : FALSE);
const HRESULT hr = pDwmSetWindowAttribute(hwnd, mode, &value, sizeof(value)); const HRESULT hr = pDwmSetWindowAttribute(hwnd, mode, &value, sizeof(value));
@ -1041,9 +1027,7 @@ bool Utils::isWindowFrameBorderVisible()
if (config->isSet(Option::ForceHideWindowFrameBorder)) { if (config->isSet(Option::ForceHideWindowFrameBorder)) {
return false; return false;
} }
static const bool isWin10OrGreater = []() -> bool { static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return isWindowsVersionOrGreater(WindowsVersion::_10_1507);
}();
return isWin10OrGreater; return isWin10OrGreater;
}(); }();
return result; return result;
@ -1052,9 +1036,7 @@ bool Utils::isWindowFrameBorderVisible()
bool Utils::isTitleBarColorized() bool Utils::isTitleBarColorized()
{ {
// CHECK: is it supported on win7? // CHECK: is it supported on win7?
static const bool isWin10OrGreater = []() -> bool { static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return isWindowsVersionOrGreater(WindowsVersion::_10_1507);
}();
if (!isWin10OrGreater) { if (!isWin10OrGreater) {
return false; return false;
} }
@ -1268,9 +1250,7 @@ SystemTheme Utils::getSystemTheme()
if (isHighContrastModeEnabled()) { if (isHighContrastModeEnabled()) {
return SystemTheme::HighContrast; return SystemTheme::HighContrast;
} }
static const bool isWin10RS1OrGreater = []() -> bool { static const bool isWin10RS1OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1607);
return isWindowsVersionOrGreater(WindowsVersion::_10_1607);
}();
if (isWin10RS1OrGreater && shouldAppsUseDarkMode()) { if (isWin10RS1OrGreater && shouldAppsUseDarkMode()) {
return SystemTheme::Dark; return SystemTheme::Dark;
} }
@ -1284,9 +1264,7 @@ void Utils::updateGlobalWin32ControlsTheme(const WId windowId, const bool dark)
return; return;
} }
// There's no global dark theme for common Win32 controls before Win10 1809. // There's no global dark theme for common Win32 controls before Win10 1809.
static const bool isWin10RS5OrGreater = []() -> bool { static const bool isWin10RS5OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1809);
return isWindowsVersionOrGreater(WindowsVersion::_10_1809);
}();
if (!isWin10RS5OrGreater) { if (!isWin10RS5OrGreater) {
return; return;
} }
@ -1306,9 +1284,7 @@ void Utils::updateGlobalWin32ControlsTheme(const WId windowId, const bool dark)
bool Utils::shouldAppsUseDarkMode_windows() bool Utils::shouldAppsUseDarkMode_windows()
{ {
// The global dark mode was first introduced in Windows 10 1607. // The global dark mode was first introduced in Windows 10 1607.
static const bool isWin10RS1OrGreater = []() -> bool { static const bool isWin10RS1OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1607);
return isWindowsVersionOrGreater(WindowsVersion::_10_1607);
}();
if (!isWin10RS1OrGreater) { if (!isWin10RS1OrGreater) {
return false; return false;
} }
@ -1321,9 +1297,7 @@ bool Utils::shouldAppsUseDarkMode_windows()
static const auto pShouldAppsUseDarkMode = static const auto pShouldAppsUseDarkMode =
reinterpret_cast<BOOL(WINAPI *)(VOID)>( reinterpret_cast<BOOL(WINAPI *)(VOID)>(
QSystemLibrary::resolve(kuxtheme, MAKEINTRESOURCEA(132))); QSystemLibrary::resolve(kuxtheme, MAKEINTRESOURCEA(132)));
static const bool isWin1019H1OrGreater = []() -> bool { static const bool isWin1019H1OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1903);
return isWindowsVersionOrGreater(WindowsVersion::_10_1903);
}();
if (pShouldAppsUseDarkMode && !isWin1019H1OrGreater) { if (pShouldAppsUseDarkMode && !isWin1019H1OrGreater) {
return (pShouldAppsUseDarkMode() != FALSE); return (pShouldAppsUseDarkMode() != FALSE);
} }
@ -1345,9 +1319,7 @@ void Utils::forceSquareCornersForWindow(const WId windowId, const bool force)
return; return;
} }
// We cannot change the window corner style until Windows 11. // We cannot change the window corner style until Windows 11.
static const bool isWin11OrGreater = []() -> bool { static const bool isWin11OrGreater = isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
return isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
}();
if (!isWin11OrGreater) { if (!isWin11OrGreater) {
return; return;
} }

View File

@ -175,21 +175,21 @@ void FramelessQuickHelperPrivate::attachToWindow()
} }
SystemParameters params = {}; SystemParameters params = {};
params.getWindowId = [q]() -> WId { return q->window()->winId(); }; params.getWindowId = [window]() -> WId { return window->winId(); };
params.getWindowFlags = [q]() -> Qt::WindowFlags { return q->window()->flags(); }; params.getWindowFlags = [window]() -> Qt::WindowFlags { return window->flags(); };
params.setWindowFlags = [q](const Qt::WindowFlags flags) -> void { q->window()->setFlags(flags); }; params.setWindowFlags = [window](const Qt::WindowFlags flags) -> void { window->setFlags(flags); };
params.getWindowSize = [q]() -> QSize { return q->window()->size(); }; params.getWindowSize = [window]() -> QSize { return window->size(); };
params.setWindowSize = [q](const QSize &size) -> void { q->window()->resize(size); }; params.setWindowSize = [window](const QSize &size) -> void { window->resize(size); };
params.getWindowPosition = [q]() -> QPoint { return q->window()->position(); }; params.getWindowPosition = [window]() -> QPoint { return window->position(); };
params.setWindowPosition = [q](const QPoint &pos) -> void { q->window()->setX(pos.x()); q->window()->setY(pos.y()); }; params.setWindowPosition = [window](const QPoint &pos) -> void { window->setX(pos.x()); window->setY(pos.y()); };
params.getWindowScreen = [q]() -> QScreen * { return q->window()->screen(); }; params.getWindowScreen = [window]() -> QScreen * { return window->screen(); };
params.isWindowFixedSize = [this]() -> bool { return isWindowFixedSize(); }; params.isWindowFixedSize = [this]() -> bool { return isWindowFixedSize(); };
params.setWindowFixedSize = [this](const bool value) -> void { setWindowFixedSize(value); }; params.setWindowFixedSize = [this](const bool value) -> void { setWindowFixedSize(value); };
params.getWindowState = [q]() -> Qt::WindowState { return q->window()->windowState(); }; params.getWindowState = [window]() -> Qt::WindowState { return window->windowState(); };
params.setWindowState = [q](const Qt::WindowState state) -> void { q->window()->setWindowState(state); }; params.setWindowState = [window](const Qt::WindowState state) -> void { window->setWindowState(state); };
params.getWindowHandle = [q]() -> QWindow * { return q->window(); }; params.getWindowHandle = [window]() -> QWindow * { return window; };
params.windowToScreen = [q](const QPoint &pos) -> QPoint { return q->window()->mapToGlobal(pos); }; params.windowToScreen = [window](const QPoint &pos) -> QPoint { return window->mapToGlobal(pos); };
params.screenToWindow = [q](const QPoint &pos) -> QPoint { return q->window()->mapFromGlobal(pos); }; params.screenToWindow = [window](const QPoint &pos) -> QPoint { return window->mapFromGlobal(pos); };
params.isInsideSystemButtons = [this](const QPoint &pos, SystemButtonType *button) -> bool { params.isInsideSystemButtons = [this](const QPoint &pos, SystemButtonType *button) -> bool {
QuickGlobal::SystemButtonType button2 = QuickGlobal::SystemButtonType::Unknown; QuickGlobal::SystemButtonType button2 = QuickGlobal::SystemButtonType::Unknown;
const bool result = isInSystemButtons(pos, &button2); const bool result = isInSystemButtons(pos, &button2);
@ -197,13 +197,14 @@ void FramelessQuickHelperPrivate::attachToWindow()
return result; return result;
}; };
params.isInsideTitleBarDraggableArea = [this](const QPoint &pos) -> bool { return isInTitleBarDraggableArea(pos); }; params.isInsideTitleBarDraggableArea = [this](const QPoint &pos) -> bool { return isInTitleBarDraggableArea(pos); };
params.getWindowDevicePixelRatio = [q]() -> qreal { return q->window()->effectiveDevicePixelRatio(); }; params.getWindowDevicePixelRatio = [window]() -> qreal { return window->effectiveDevicePixelRatio(); };
params.setSystemButtonState = [this](const SystemButtonType button, const ButtonState state) -> void { params.setSystemButtonState = [this](const SystemButtonType button, const ButtonState state) -> void {
setSystemButtonState(FRAMELESSHELPER_ENUM_CORE_TO_QUICK(SystemButtonType, button), setSystemButtonState(FRAMELESSHELPER_ENUM_CORE_TO_QUICK(SystemButtonType, button),
FRAMELESSHELPER_ENUM_CORE_TO_QUICK(ButtonState, state)); FRAMELESSHELPER_ENUM_CORE_TO_QUICK(ButtonState, state));
}; };
params.shouldIgnoreMouseEvents = [this](const QPoint &pos) -> bool { return shouldIgnoreMouseEvents(pos); }; params.shouldIgnoreMouseEvents = [this](const QPoint &pos) -> bool { return shouldIgnoreMouseEvents(pos); };
params.showSystemMenu = [this](const QPoint &pos) -> void { showSystemMenu(pos); }; params.showSystemMenu = [this](const QPoint &pos) -> void { showSystemMenu(pos); };
params.getCurrentApplicationType = []() -> ApplicationType { return ApplicationType::Quick; };
g_quickHelper()->mutex.lock(); g_quickHelper()->mutex.lock();
data->params = params; data->params = params;

View File

@ -61,6 +61,8 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
qRegisterMetaType<QuickGlobal::DwmColorizationArea>(); qRegisterMetaType<QuickGlobal::DwmColorizationArea>();
qRegisterMetaType<QuickGlobal::Anchor>(); qRegisterMetaType<QuickGlobal::Anchor>();
qRegisterMetaType<QuickGlobal::ButtonState>(); qRegisterMetaType<QuickGlobal::ButtonState>();
qRegisterMetaType<QuickGlobal::WindowsVersion>();
qRegisterMetaType<QuickGlobal::ApplicationType>();
qmlRegisterUncreatableType<QuickGlobal>(QUICK_URI_FULL, "FramelessHelperConstants", qmlRegisterUncreatableType<QuickGlobal>(QUICK_URI_FULL, "FramelessHelperConstants",
FRAMELESSHELPER_STRING_LITERAL("The FramelessHelperConstants namespace is not creatable, you can only use it to access it's enums.")); FRAMELESSHELPER_STRING_LITERAL("The FramelessHelperConstants namespace is not creatable, you can only use it to access it's enums."));
qmlRegisterSingletonType<FramelessQuickUtils>(QUICK_URI_EXPAND("FramelessUtils"), qmlRegisterSingletonType<FramelessQuickUtils>(QUICK_URI_EXPAND("FramelessUtils"),

View File

@ -49,9 +49,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 = []() -> bool { static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
}();
return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater); return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater);
#else #else
return false; return false;

View File

@ -186,9 +186,7 @@ void FramelessQuickWindowPrivate::initialize()
bool FramelessQuickWindowPrivate::shouldDrawFrameBorder() const bool FramelessQuickWindowPrivate::shouldDrawFrameBorder() const
{ {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
static const bool isWin11OrGreater = []() -> bool { static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
}();
return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater); return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater);
#else #else
return false; return false;

View File

@ -233,6 +233,7 @@ void FramelessWidgetsHelperPrivate::attachToWindow()
params.setSystemButtonState = [this](const SystemButtonType button, const ButtonState state) -> void { setSystemButtonState(button, state); }; params.setSystemButtonState = [this](const SystemButtonType button, const ButtonState state) -> void { setSystemButtonState(button, state); };
params.shouldIgnoreMouseEvents = [this](const QPoint &pos) -> bool { return shouldIgnoreMouseEvents(pos); }; params.shouldIgnoreMouseEvents = [this](const QPoint &pos) -> bool { return shouldIgnoreMouseEvents(pos); };
params.showSystemMenu = [this](const QPoint &pos) -> void { showSystemMenu(pos); }; params.showSystemMenu = [this](const QPoint &pos) -> void { showSystemMenu(pos); };
params.getCurrentApplicationType = []() -> ApplicationType { return ApplicationType::Widgets; };
g_widgetsHelper()->mutex.lock(); g_widgetsHelper()->mutex.lock();
data->params = params; data->params = params;

View File

@ -127,9 +127,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 = []() -> bool { static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
return Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
}();
return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater return (Utils::isWindowFrameBorderVisible() && !isWin11OrGreater
&& (Utils::windowStatesToWindowState(m_targetWidget->windowState()) == Qt::WindowNoState)); && (Utils::windowStatesToWindowState(m_targetWidget->windowState()) == Qt::WindowNoState));
#else #else