Compare commits

..

10 Commits

Author SHA1 Message Date
Zhao Yuhang 00a442de54 minor tweaks 2023-09-30 19:18:56 +08:00
Sine Striker cb37fc66f4 Inline ExtraDataType hash function 2023-09-30 19:00:20 +08:00
Sine Striker 361f6a1184 Add hash function for ExtraDataType 2023-09-30 19:00:20 +08:00
Yuhang Zhao 8382372a29 refactor 2023-09-30 19:00:18 +08:00
Zhao Yuhang e62885fefc cmake: update submodule 2023-09-30 13:00:43 +08:00
Zhao Yuhang ba7aab0276 win: improve blur mode 2023-09-29 16:06:06 +08:00
Zhao Yuhang 786926e7ab cmake: update submodule 2023-09-29 15:03:04 +08:00
Yuhang Zhao 8f98ab865c win: minor tweaks 2023-09-28 18:06:47 +08:00
Yuhang Zhao 27a9e0857c widget: minor simply 2023-09-26 12:47:23 +08:00
Yuhang Zhao 79d5087df5 quick: fix qml import error
Fixes: #288
Fixes: #233
2023-09-26 12:42:32 +08:00
7 changed files with 61 additions and 26 deletions

2
cmake

@ -1 +1 @@
Subproject commit d32871be6542a9e9a066aaa1ddea8fe1a6cd2d86 Subproject commit dca88aa06c080f5b6abbb8be9c0d2d8a0ee8a165

View File

@ -819,19 +819,14 @@ using ACCENT_STATE = enum ACCENT_STATE
using ACCENT_FLAG = enum ACCENT_FLAG using ACCENT_FLAG = enum ACCENT_FLAG
{ {
ACCENT_NONE = 0, ACCENT_NONE = 0,
ACCENT_ENABLE_LUMINOSITY = 1 << 1, ACCENT_ENABLE_ACRYLIC = 1,
ACCENT_ENABLE_BORDER_LEFT = 1 << 5, ACCENT_ENABLE_ACRYLIC_WITH_LUMINOSITY = 482
ACCENT_ENABLE_BORDER_TOP = 1 << 6,
ACCENT_ENABLE_BORDER_RIGHT = 1 << 7,
ACCENT_ENABLE_BORDER_BOTTOM = 1 << 8,
ACCENT_ENABLE_BORDER = ACCENT_ENABLE_BORDER_LEFT | ACCENT_ENABLE_BORDER_TOP | ACCENT_ENABLE_BORDER_RIGHT | ACCENT_ENABLE_BORDER_BOTTOM,
ACCENT_ENABLE_ALL = ACCENT_ENABLE_BORDER
}; };
using ACCENT_POLICY = struct ACCENT_POLICY using ACCENT_POLICY = struct ACCENT_POLICY
{ {
ACCENT_STATE AccentState; DWORD dwAccentState;
ACCENT_FLAG AccentFlags; DWORD dwAccentFlags;
DWORD dwGradientColor; // #AABBGGRR DWORD dwGradientColor; // #AABBGGRR
DWORD dwAnimationId; DWORD dwAnimationId;
}; };

View File

@ -117,7 +117,7 @@ enum class ExtraDataType : quint8
}; };
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
inline uint qHash(ExtraDataType key, uint seed = 0) noexcept { inline uint qHash(const ExtraDataType key, const uint seed = 0) noexcept {
return ::qHash(static_cast<quint8>(key), seed); return ::qHash(static_cast<quint8>(key), seed);
} }
#endif #endif

View File

@ -253,11 +253,13 @@ void FramelessHelperWin::addWindow(const QObject *window)
// Windows, which means only the top level windows can be scaled to the correct // Windows, which means only the top level windows can be scaled to the correct
// size, we of course don't want such thing from happening. // size, we of course don't want such thing from happening.
std::ignore = Utils::fixupChildWindowsDpiMessage(data->windowId); std::ignore = Utils::fixupChildWindowsDpiMessage(data->windowId);
#if 0 // Conflicts with our blur mode setting.
// If we are using 3D APIs (D3D, Vulkan, OpenGL, etc) to draw the window content, // If we are using 3D APIs (D3D, Vulkan, OpenGL, etc) to draw the window content,
// we need to setup the DWM rendering policy as well. // we need to setup the DWM rendering policy as well.
if (Utils::isWindowAccelerated(qWindow) && Utils::isWindowTransparent(qWindow)) { if (Utils::isWindowAccelerated(qWindow) && Utils::isWindowTransparent(qWindow)) {
std::ignore = Utils::updateFramebufferTransparency(data->windowId); std::ignore = Utils::updateFramebufferTransparency(data->windowId);
} }
#endif
if (WindowsVersionHelper::isWin10RS1OrGreater()) { if (WindowsVersionHelper::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).
FramelessHelperEnableThemeAware(); FramelessHelperEnableThemeAware();
@ -1277,11 +1279,13 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
} }
} }
#if 0 // Conflicts with our blur mode setting.
if ((uMsg == WM_DWMCOMPOSITIONCHANGED) || (uMsg == WM_DWMCOLORIZATIONCOLORCHANGED)) { if ((uMsg == WM_DWMCOMPOSITIONCHANGED) || (uMsg == WM_DWMCOLORIZATIONCOLORCHANGED)) {
if (Utils::isWindowAccelerated(qWindow) && Utils::isWindowTransparent(qWindow)) { if (Utils::isWindowAccelerated(qWindow) && Utils::isWindowTransparent(qWindow)) {
std::ignore = Utils::updateFramebufferTransparency(windowId); std::ignore = Utils::updateFramebufferTransparency(windowId);
} }
} }
#endif
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)

View File

@ -1221,9 +1221,9 @@ QString Utils::getSystemErrorMessage(const QString &function)
if (function.isEmpty()) { if (function.isEmpty()) {
return {}; return {};
} }
const DWORD code = GetLastError(); const DWORD code = ::GetLastError();
if (code == ERROR_SUCCESS) { if (code == ERROR_SUCCESS) {
return {}; return kSuccessMessageText;
} }
return getSystemErrorMessageImpl(function, code); return getSystemErrorMessageImpl(function, code);
} }
@ -2314,8 +2314,40 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
extraData->mica = false; extraData->mica = false;
std::ignore = updateWindowFrameMargins(windowId, false); std::ignore = updateWindowFrameMargins(windowId, false);
}; };
static const auto userPreferredBlurMode = []() -> std::optional<BlurMode> {
const QString option = qEnvironmentVariable("FRAMELESSHELPER_BLUR_MODE");
if (option.isEmpty()) {
return std::nullopt;
}
if (option.contains(FRAMELESSHELPER_STRING_LITERAL("MICAALT"), Qt::CaseInsensitive)) {
return BlurMode::Windows_MicaAlt;
}
if (option.contains(FRAMELESSHELPER_STRING_LITERAL("MICA"), Qt::CaseInsensitive)) {
return BlurMode::Windows_Mica;
}
if (option.contains(FRAMELESSHELPER_STRING_LITERAL("ACRYLIC"), Qt::CaseInsensitive)) {
return BlurMode::Windows_Acrylic;
}
if (option.contains(FRAMELESSHELPER_STRING_LITERAL("AERO"), Qt::CaseInsensitive)) {
return BlurMode::Windows_Aero;
}
return std::nullopt;
}();
static constexpr const auto kDefaultAcrylicOpacity = 0.8f;
static const auto acrylicOpacity = []() -> float {
const QString option = qEnvironmentVariable("FRAMELESSHELPER_ACRYLIC_OPACITY");
if (option.isEmpty()) {
return kDefaultAcrylicOpacity;
}
bool ok = false;
const float num = option.toFloat(&ok);
if (ok && !qIsNaN(num) && (num > float(0)) && (num < float(1))) {
return num;
}
return kDefaultAcrylicOpacity;
}();
static const bool preferMicaAlt = (qEnvironmentVariableIntValue("FRAMELESSHELPER_PREFER_MICA_ALT") != 0); static const bool preferMicaAlt = (qEnvironmentVariableIntValue("FRAMELESSHELPER_PREFER_MICA_ALT") != 0);
const auto blurMode = [mode]() -> BlurMode { const auto recommendedBlurMode = [mode]() -> BlurMode {
if ((mode == BlurMode::Disable) || (mode == BlurMode::Windows_Aero)) { if ((mode == BlurMode::Disable) || (mode == BlurMode::Windows_Aero)) {
return mode; return mode;
} }
@ -2346,6 +2378,7 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
Q_UNREACHABLE_RETURN(BlurMode::Default); Q_UNREACHABLE_RETURN(BlurMode::Default);
QT_WARNING_POP QT_WARNING_POP
}(); }();
const BlurMode blurMode = ((recommendedBlurMode == BlurMode::Disable) ? BlurMode::Disable : userPreferredBlurMode.value_or(recommendedBlurMode));
if (blurMode == BlurMode::Disable) { if (blurMode == BlurMode::Disable) {
bool result = true; bool result = true;
if (WindowsVersionHelper::isWin1122H2OrGreater()) { if (WindowsVersionHelper::isWin1122H2OrGreater()) {
@ -2367,8 +2400,8 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
} else { } else {
ACCENT_POLICY policy; ACCENT_POLICY policy;
SecureZeroMemory(&policy, sizeof(policy)); SecureZeroMemory(&policy, sizeof(policy));
policy.AccentState = ACCENT_DISABLED; policy.dwAccentState = ACCENT_DISABLED;
policy.AccentFlags = ACCENT_NONE; policy.dwAccentFlags = ACCENT_NONE;
WINDOWCOMPOSITIONATTRIBDATA wcad; WINDOWCOMPOSITIONATTRIBDATA wcad;
SecureZeroMemory(&wcad, sizeof(wcad)); SecureZeroMemory(&wcad, sizeof(wcad));
wcad.Attrib = WCA_ACCENT_POLICY; wcad.Attrib = WCA_ACCENT_POLICY;
@ -2433,22 +2466,22 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
ACCENT_POLICY policy; ACCENT_POLICY policy;
SecureZeroMemory(&policy, sizeof(policy)); SecureZeroMemory(&policy, sizeof(policy));
if (blurMode == BlurMode::Windows_Acrylic) { if (blurMode == BlurMode::Windows_Acrylic) {
policy.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND; policy.dwAccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
policy.AccentFlags = ACCENT_ENABLE_LUMINOSITY; policy.dwAccentFlags = ACCENT_ENABLE_ACRYLIC_WITH_LUMINOSITY;
const auto gradientColor = [&color]() -> QColor { const auto gradientColor = [&color]() -> QColor {
if (color.isValid()) { if (color.isValid()) {
return color; return color;
} }
QColor clr = ((FramelessManager::instance()->systemTheme() == SystemTheme::Dark) ? kDefaultSystemDarkColor : kDefaultSystemLightColor); QColor clr = ((FramelessManager::instance()->systemTheme() == SystemTheme::Dark) ? kDefaultSystemDarkColor : kDefaultSystemLightColor);
clr.setAlphaF(0.9f); clr.setAlphaF(acrylicOpacity);
return clr; return clr;
}(); }();
// This API expects the #AABBGGRR format. // This API expects the #AABBGGRR format.
policy.dwGradientColor = DWORD(qRgba(gradientColor.blue(), policy.dwGradientColor = DWORD(qRgba(gradientColor.blue(),
gradientColor.green(), gradientColor.red(), gradientColor.alpha())); gradientColor.green(), gradientColor.red(), gradientColor.alpha()));
} else if (blurMode == BlurMode::Windows_Aero) { } else if (blurMode == BlurMode::Windows_Aero) {
policy.AccentState = ACCENT_ENABLE_BLURBEHIND; policy.dwAccentState = ACCENT_ENABLE_BLURBEHIND;
policy.AccentFlags = ACCENT_NONE; policy.dwAccentFlags = ACCENT_NONE;
} else { } else {
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_MSVC(4702) QT_WARNING_DISABLE_MSVC(4702)
@ -2577,7 +2610,10 @@ bool Utils::isBlurBehindWindowSupported()
if (FramelessConfig::instance()->isSet(Option::ForceNonNativeBackgroundBlur)) { if (FramelessConfig::instance()->isSet(Option::ForceNonNativeBackgroundBlur)) {
return false; return false;
} }
return WindowsVersionHelper::isWin11OrGreater(); // Enabling Mica on Win11 make it very hard to hide the original three caption buttons,
// and enabling Acrylic on Win10 makes the window very laggy during moving and resizing.
//return WindowsVersionHelper::isWin10OrGreater();
return false;
}(); }();
return result; return result;
} }

View File

@ -155,9 +155,9 @@ if(QT_VERSION VERSION_GREATER_EQUAL "6.3")
#NO_RESOURCE_TARGET_PATH # Can't be used for non-executable targets. #NO_RESOURCE_TARGET_PATH # Can't be used for non-executable targets.
OUTPUT_TARGETS __qml_targets OUTPUT_TARGETS __qml_targets
IMPORTS IMPORTS
QtQml/auto QtQml
QtQuick/auto QtQuick
QtQuick.Controls.Basic/auto QtQuick.Controls.Basic
) )
if(__qml_targets) if(__qml_targets)
list(APPEND __export_targets ${__qml_targets}) list(APPEND __export_targets ${__qml_targets})

View File

@ -69,7 +69,7 @@ static inline void emulateLeaveEvent(QWidget *widget)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QScreen *screen = widget->screen(); const QScreen *screen = widget->screen();
#else #else
const QScreen *screen = QGuiApplication::primaryScreen(); const QScreen *screen = widget->windowHandle()->screen();
#endif #endif
const QPoint globalPos = QCursor::pos(screen); const QPoint globalPos = QCursor::pos(screen);
if (!QRect(widget->mapToGlobal(QPoint{ 0, 0 }), widget->size()).contains(globalPos)) { if (!QRect(widget->mapToGlobal(QPoint{ 0, 0 }), widget->size()).contains(globalPos)) {