Some refactor
Rename some functions to make it more clear. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
bc9edaf78a
commit
0931b73671
|
@ -118,7 +118,7 @@ Window {
|
|||
|
||||
Component.onCompleted: {
|
||||
framelessHelper.removeWindowFrame()
|
||||
framelessHelper.setAcrylicEffectEnabled(true)
|
||||
framelessHelper.setBlurEffectEnabled(true)
|
||||
}
|
||||
|
||||
// Re-draw the window frame.
|
||||
|
|
|
@ -445,7 +445,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
|||
case WM_NCPAINT: {
|
||||
// 边框阴影处于非客户区的范围,因此如果直接阻止非客户区的绘制,会导致边框阴影丢失
|
||||
|
||||
if (!Utilities::isBlurEffectSupported() && !shouldHaveWindowFrame()) {
|
||||
if (!Utilities::isDwmBlurAvailable() && !shouldHaveWindowFrame()) {
|
||||
// Only block WM_NCPAINT when DWM composition is disabled. If
|
||||
// it's blocked when DWM composition is enabled, the frame
|
||||
// shadow won't be drawn.
|
||||
|
@ -459,7 +459,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
|||
if (shouldHaveWindowFrame()) {
|
||||
break;
|
||||
} else {
|
||||
if (Utilities::isBlurEffectSupported()) {
|
||||
if (Utilities::isDwmBlurAvailable()) {
|
||||
// DefWindowProc won't repaint the window border if lParam
|
||||
// (normally a HRGN) is -1. See the following link's "lParam"
|
||||
// section:
|
||||
|
|
|
@ -76,16 +76,6 @@ void FramelessQuickHelper::setResizable(const bool val)
|
|||
Q_EMIT resizableChanged(val);
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::colorizationEnabled() const
|
||||
{
|
||||
return Utilities::isColorizationEnabled();
|
||||
}
|
||||
|
||||
QColor FramelessQuickHelper::colorizationColor() const
|
||||
{
|
||||
return Utilities::getColorizationColor();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::lightThemeEnabled() const
|
||||
{
|
||||
return Utilities::isLightThemeEnabled();
|
||||
|
@ -96,6 +86,17 @@ bool FramelessQuickHelper::darkThemeEnabled() const
|
|||
return Utilities::isDarkThemeEnabled();
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
bool FramelessQuickHelper::colorizationEnabled() const
|
||||
{
|
||||
return Utilities::isColorizationEnabled();
|
||||
}
|
||||
|
||||
QColor FramelessQuickHelper::colorizationColor() const
|
||||
{
|
||||
return Utilities::getColorizationColor();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::highContrastModeEnabled() const
|
||||
{
|
||||
return Utilities::isHighContrastModeEnabled();
|
||||
|
@ -110,6 +111,7 @@ bool FramelessQuickHelper::transparencyEffectEnabled() const
|
|||
{
|
||||
return Utilities::isTransparencyEffectEnabled();
|
||||
}
|
||||
#endif
|
||||
|
||||
void FramelessQuickHelper::removeWindowFrame()
|
||||
{
|
||||
|
@ -128,16 +130,18 @@ void FramelessQuickHelper::addIgnoreObject(QQuickItem *val)
|
|||
void FramelessQuickHelper::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
QQuickItem::timerEvent(event);
|
||||
Q_EMIT colorizationEnabledChanged(colorizationEnabled());
|
||||
Q_EMIT colorizationColorChanged(colorizationColor());
|
||||
Q_EMIT lightThemeEnabledChanged(lightThemeEnabled());
|
||||
Q_EMIT darkThemeEnabledChanged(darkThemeEnabled());
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_EMIT colorizationEnabledChanged(colorizationEnabled());
|
||||
Q_EMIT colorizationColorChanged(colorizationColor());
|
||||
Q_EMIT highContrastModeEnabledChanged(highContrastModeEnabled());
|
||||
Q_EMIT darkFrameEnabledChanged(darkFrameEnabled());
|
||||
Q_EMIT transparencyEffectEnabledChanged(transparencyEffectEnabled());
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setAcrylicEffectEnabled(const bool enabled, const QColor &gradientColor)
|
||||
void FramelessQuickHelper::setBlurEffectEnabled(const bool enabled, const QColor &gradientColor)
|
||||
{
|
||||
Utilities::setAcrylicEffectEnabled(window(), enabled, gradientColor);
|
||||
Utilities::setBlurEffectEnabled(window(), enabled, gradientColor);
|
||||
}
|
||||
|
|
|
@ -38,13 +38,15 @@ class FRAMELESSHELPER_EXPORT FramelessQuickHelper : public QQuickItem
|
|||
Q_PROPERTY(int borderHeight READ borderHeight WRITE setBorderHeight NOTIFY borderHeightChanged)
|
||||
Q_PROPERTY(int titleBarHeight READ titleBarHeight WRITE setTitleBarHeight NOTIFY titleBarHeightChanged)
|
||||
Q_PROPERTY(bool resizable READ resizable WRITE setResizable NOTIFY resizableChanged)
|
||||
Q_PROPERTY(bool colorizationEnabled READ colorizationEnabled NOTIFY colorizationEnabledChanged)
|
||||
Q_PROPERTY(QColor colorizationColor READ colorizationColor NOTIFY colorizationColorChanged)
|
||||
Q_PROPERTY(bool lightThemeEnabled READ lightThemeEnabled NOTIFY lightThemeEnabledChanged)
|
||||
Q_PROPERTY(bool darkThemeEnabled READ darkThemeEnabled NOTIFY darkThemeEnabledChanged)
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_PROPERTY(bool colorizationEnabled READ colorizationEnabled NOTIFY colorizationEnabledChanged)
|
||||
Q_PROPERTY(QColor colorizationColor READ colorizationColor NOTIFY colorizationColorChanged)
|
||||
Q_PROPERTY(bool highContrastModeEnabled READ highContrastModeEnabled NOTIFY highContrastModeEnabledChanged)
|
||||
Q_PROPERTY(bool darkFrameEnabled READ darkFrameEnabled NOTIFY darkFrameEnabledChanged)
|
||||
Q_PROPERTY(bool transparencyEffectEnabled READ transparencyEffectEnabled NOTIFY transparencyEffectEnabledChanged)
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit FramelessQuickHelper(QQuickItem *parent = nullptr);
|
||||
|
@ -62,18 +64,21 @@ public:
|
|||
bool resizable() const;
|
||||
void setResizable(const bool val);
|
||||
|
||||
bool colorizationEnabled() const;
|
||||
QColor colorizationColor() const;
|
||||
bool lightThemeEnabled() const;
|
||||
bool darkThemeEnabled() const;
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
bool colorizationEnabled() const;
|
||||
QColor colorizationColor() const;
|
||||
bool highContrastModeEnabled() const;
|
||||
bool darkFrameEnabled() const;
|
||||
bool transparencyEffectEnabled() const;
|
||||
#endif
|
||||
|
||||
public Q_SLOTS:
|
||||
void removeWindowFrame();
|
||||
void addIgnoreObject(QQuickItem *val);
|
||||
void setAcrylicEffectEnabled(const bool enabled = true, const QColor &gradientColor = {});
|
||||
void setBlurEffectEnabled(const bool enabled = true, const QColor &gradientColor = {});
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
|
@ -83,11 +88,13 @@ Q_SIGNALS:
|
|||
void borderHeightChanged(int);
|
||||
void titleBarHeightChanged(int);
|
||||
void resizableChanged(bool);
|
||||
void colorizationEnabledChanged(bool);
|
||||
void colorizationColorChanged(const QColor &);
|
||||
void lightThemeEnabledChanged(bool);
|
||||
void darkThemeEnabledChanged(bool);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
void colorizationEnabledChanged(bool);
|
||||
void colorizationColorChanged(const QColor &);
|
||||
void highContrastModeEnabledChanged(bool);
|
||||
void darkFrameEnabledChanged(bool);
|
||||
void transparencyEffectEnabledChanged(bool);
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -34,11 +34,15 @@ QtAcrylicEffectHelper::QtAcrylicEffectHelper()
|
|||
Q_INIT_RESOURCE(qtacrylichelper);
|
||||
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
||||
#ifdef Q_OS_MACOS
|
||||
if (Utilities::isAcrylicEffectSupported()) {
|
||||
if (Utilities::shouldUseTraditionalBlur()) {
|
||||
m_tintOpacity = 0.6;
|
||||
}
|
||||
#endif
|
||||
#ifdef Q_OS_WINDOWS
|
||||
m_frameColor = Utilities::getNativeWindowFrameColor(true);
|
||||
#else
|
||||
m_frameColor = Qt::black;
|
||||
#endif
|
||||
}
|
||||
|
||||
void QtAcrylicEffectHelper::install(const QWindow *window)
|
||||
|
@ -189,7 +193,7 @@ void QtAcrylicEffectHelper::paintBackground(QPainter *painter, const QRect &rect
|
|||
qWarning() << "m_window is null, forgot to call \"QtAcrylicEffectHelper::install()\"?";
|
||||
return;
|
||||
}
|
||||
if (Utilities::isAcrylicEffectSupported()) {
|
||||
if (Utilities::shouldUseTraditionalBlur()) {
|
||||
const QPainter::CompositionMode mode = painter->compositionMode();
|
||||
painter->setCompositionMode(QPainter::CompositionMode_Clear);
|
||||
painter->fillRect(rect, Qt::white);
|
||||
|
@ -254,7 +258,7 @@ void QtAcrylicEffectHelper::updateAcrylicBrush(const QColor &alternativeTintColo
|
|||
QImage acrylicTexture({64, 64}, QImage::Format_ARGB32_Premultiplied);
|
||||
QColor fillColor = Qt::transparent;
|
||||
#ifdef Q_OS_WINDOWS
|
||||
if (!Utilities::isMSWin10AcrylicEffectAvailable()) {
|
||||
if (!Utilities::isOfficialMSWin10AcrylicBlurAvailable()) {
|
||||
// Add a soft light layer for the background.
|
||||
fillColor = Qt::white;
|
||||
fillColor.setAlpha(150);
|
||||
|
|
|
@ -145,7 +145,7 @@ void QtAcrylicWidget::showEvent(QShowEvent *event)
|
|||
if (!inited) {
|
||||
const QWindow *win = windowHandle();
|
||||
FramelessWindowsManager::addWindow(win);
|
||||
Utilities::setAcrylicEffectEnabled(win, true);
|
||||
Utilities::setBlurEffectEnabled(win, true);
|
||||
m_acrylicHelper.install(win);
|
||||
m_acrylicHelper.updateAcrylicBrush(tintColor());
|
||||
update();
|
||||
|
|
150
utilities.cpp
150
utilities.cpp
|
@ -25,21 +25,8 @@
|
|||
#include "utilities.h"
|
||||
#include <QtGui/private/qguiapplication_p.h>
|
||||
#include <QtGui/qscreen.h>
|
||||
#include <QtGui/qpa/qplatformwindow.h>
|
||||
#include <QtGui/qpainter.h>
|
||||
#include <QtGui/private/qmemrotate_p.h>
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <QtGui/qpa/qplatformnativeinterface.h>
|
||||
#else
|
||||
#include <QtGui/qpa/qplatformwindow_p.h>
|
||||
#endif
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
#include <QtCore/qoperatingsystemversion.h>
|
||||
#else
|
||||
#include <QtCore/qsysinfo.h>
|
||||
#endif
|
||||
|
||||
Q_DECLARE_METATYPE(QMargins)
|
||||
|
||||
/*
|
||||
* Copied from https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/effects/qpixmapfilter.cpp
|
||||
|
@ -369,96 +356,6 @@ QRect Utilities::alignedRect(const Qt::LayoutDirection direction, const Qt::Alig
|
|||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
bool Utilities::isWin7OrGreater()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows7;
|
||||
#else
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS7;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin8OrGreater()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8;
|
||||
#else
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin8Point1OrGreater()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8_1;
|
||||
#else
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8_1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin10OrGreater()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10;
|
||||
#else
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS10;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin10OrGreater(const int subVer)
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, subVer);
|
||||
#else
|
||||
Q_UNUSED(ver);
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS10;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline bool forceEnableDwmBlur()
|
||||
{
|
||||
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceDWMBlur_flag);
|
||||
}
|
||||
|
||||
static inline bool forceDisableWallpaperBlur()
|
||||
{
|
||||
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceDisableWallpaperBlur_flag);
|
||||
}
|
||||
|
||||
static inline bool forceEnableOfficialMSWin10AcrylicBlur()
|
||||
{
|
||||
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceOfficialMSWin10Blur_flag);
|
||||
}
|
||||
|
||||
static inline bool shouldUseOfficialMSWin10AcrylicBlur()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
const QOperatingSystemVersion currentVersion = QOperatingSystemVersion::current();
|
||||
if (currentVersion > QOperatingSystemVersion::Windows10) {
|
||||
return true;
|
||||
}
|
||||
return ((currentVersion.microVersion() >= 16190) && (currentVersion.microVersion() < 18362));
|
||||
#else
|
||||
// TODO
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isMSWin10AcrylicEffectAvailable()
|
||||
{
|
||||
if (!isWin10OrGreater()) {
|
||||
return false;
|
||||
}
|
||||
if (!forceEnableDwmBlur() && !forceDisableWallpaperBlur()) {
|
||||
// We can't enable the official Acrylic blur in wallpaper blur mode.
|
||||
return false;
|
||||
}
|
||||
if (forceEnableOfficialMSWin10AcrylicBlur()) {
|
||||
return true;
|
||||
}
|
||||
return shouldUseOfficialMSWin10AcrylicBlur();
|
||||
}
|
||||
|
||||
QWindow *Utilities::findWindow(const WId winId)
|
||||
{
|
||||
Q_ASSERT(winId);
|
||||
|
@ -476,49 +373,12 @@ QWindow *Utilities::findWindow(const WId winId)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static inline bool shouldUseTraditionalDwmBlur()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return Utilities::isWin10OrGreater() || (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite);
|
||||
#else
|
||||
// TODO
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isAcrylicEffectSupported()
|
||||
{
|
||||
if ((forceEnableDwmBlur() || forceDisableWallpaperBlur()) && shouldUseTraditionalDwmBlur()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Utilities::updateQtFrameMargins(QWindow *window, const bool enable)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
const int tbh = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, true, true) : 0;
|
||||
const QMargins margins = {0, -tbh, 0, 0};
|
||||
const QVariant marginsVar = QVariant::fromValue(margins);
|
||||
window->setProperty("_q_windowsCustomMargins", marginsVar);
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QPlatformWindow *platformWindow = window->handle();
|
||||
if (platformWindow) {
|
||||
QGuiApplication::platformNativeInterface()->setWindowProperty(platformWindow, QStringLiteral("WindowsCustomMargins"), marginsVar);
|
||||
}
|
||||
#else
|
||||
auto *platformWindow = dynamic_cast<QNativeInterface::Private::QWindowsWindow *>(
|
||||
window->handle());
|
||||
if (platformWindow) {
|
||||
platformWindow->setCustomMargins(margins);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QRect Utilities::getScreenAvailableGeometry()
|
||||
{
|
||||
return QGuiApplication::primaryScreen()->availableGeometry();
|
||||
}
|
||||
|
||||
bool Utilities::shouldUseWallpaperBlur()
|
||||
{
|
||||
return !shouldUseTraditionalBlur();
|
||||
}
|
||||
|
|
46
utilities.h
46
utilities.h
|
@ -46,35 +46,53 @@ enum class DesktopWallpaperAspectStyle
|
|||
KeepRatioByExpanding
|
||||
};
|
||||
|
||||
// Common
|
||||
FRAMELESSHELPER_EXPORT bool shouldUseWallpaperBlur();
|
||||
FRAMELESSHELPER_EXPORT bool shouldUseTraditionalBlur();
|
||||
FRAMELESSHELPER_EXPORT bool setBlurEffectEnabled(const QWindow *window, const bool enabled, const QColor &gradientColor = {});
|
||||
|
||||
FRAMELESSHELPER_EXPORT int getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiAware, const bool forceSystemValue = false);
|
||||
|
||||
FRAMELESSHELPER_EXPORT bool isLightThemeEnabled();
|
||||
FRAMELESSHELPER_EXPORT bool isDarkThemeEnabled();
|
||||
|
||||
FRAMELESSHELPER_EXPORT QWindow *findWindow(const WId winId);
|
||||
|
||||
FRAMELESSHELPER_EXPORT QImage getDesktopWallpaperImage(const int screen = -1);
|
||||
FRAMELESSHELPER_EXPORT DesktopWallpaperAspectStyle getDesktopWallpaperAspectStyle(const int screen = -1);
|
||||
|
||||
FRAMELESSHELPER_EXPORT QRect getScreenAvailableGeometry();
|
||||
|
||||
FRAMELESSHELPER_EXPORT QRect alignedRect(const Qt::LayoutDirection direction, const Qt::Alignment alignment, const QSize &size, const QRect &rectangle);
|
||||
|
||||
FRAMELESSHELPER_EXPORT void blurImage(QImage &blurImage, const qreal radius, const bool quality, const int transposed = 0);
|
||||
FRAMELESSHELPER_EXPORT void blurImage(QPainter *painter, QImage &blurImage, const qreal radius, const bool quality, const bool alphaOnly, const int transposed = 0);
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
// Windows specific
|
||||
FRAMELESSHELPER_EXPORT bool isWin7OrGreater();
|
||||
FRAMELESSHELPER_EXPORT bool isWin8OrGreater();
|
||||
FRAMELESSHELPER_EXPORT bool isWin8Point1OrGreater();
|
||||
FRAMELESSHELPER_EXPORT bool isWin10OrGreater();
|
||||
FRAMELESSHELPER_EXPORT bool isWin10OrGreater(const int subVer);
|
||||
FRAMELESSHELPER_EXPORT bool isMSWin10AcrylicEffectAvailable();
|
||||
FRAMELESSHELPER_EXPORT bool isBlurEffectSupported();
|
||||
FRAMELESSHELPER_EXPORT bool isAcrylicEffectSupported();
|
||||
FRAMELESSHELPER_EXPORT int getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiAware, const bool forceSystemValue = false);
|
||||
FRAMELESSHELPER_EXPORT bool setAcrylicEffectEnabled(const QWindow *window, const bool enabled, const QColor &gradientColor = {});
|
||||
|
||||
FRAMELESSHELPER_EXPORT bool isDwmBlurAvailable();
|
||||
FRAMELESSHELPER_EXPORT bool isOfficialMSWin10AcrylicBlurAvailable();
|
||||
|
||||
FRAMELESSHELPER_EXPORT bool isColorizationEnabled();
|
||||
FRAMELESSHELPER_EXPORT QColor getColorizationColor();
|
||||
FRAMELESSHELPER_EXPORT bool isLightThemeEnabled();
|
||||
FRAMELESSHELPER_EXPORT bool isDarkThemeEnabled();
|
||||
|
||||
FRAMELESSHELPER_EXPORT bool isHighContrastModeEnabled();
|
||||
FRAMELESSHELPER_EXPORT bool isDarkFrameEnabled(const QWindow *window);
|
||||
FRAMELESSHELPER_EXPORT bool isTransparencyEffectEnabled();
|
||||
FRAMELESSHELPER_EXPORT QWindow *findWindow(const WId winId);
|
||||
|
||||
FRAMELESSHELPER_EXPORT void triggerFrameChange(const QWindow *window);
|
||||
FRAMELESSHELPER_EXPORT void updateFrameMargins(const QWindow *window, const bool reset);
|
||||
FRAMELESSHELPER_EXPORT void updateQtFrameMargins(QWindow *window, const bool enable);
|
||||
FRAMELESSHELPER_EXPORT QImage getDesktopWallpaperImage(const int screen = -1);
|
||||
FRAMELESSHELPER_EXPORT DesktopWallpaperAspectStyle getDesktopWallpaperAspectStyle(const int screen = -1);
|
||||
|
||||
FRAMELESSHELPER_EXPORT quint32 getWindowDpi(const QWindow *window);
|
||||
FRAMELESSHELPER_EXPORT QMargins getWindowNativeFrameMargins(const QWindow *window);
|
||||
FRAMELESSHELPER_EXPORT QRect getScreenAvailableGeometry();
|
||||
FRAMELESSHELPER_EXPORT QRect alignedRect(const Qt::LayoutDirection direction, const Qt::Alignment alignment, const QSize &size, const QRect &rectangle);
|
||||
FRAMELESSHELPER_EXPORT void blurImage(QImage &blurImage, const qreal radius, const bool quality, const int transposed = 0);
|
||||
FRAMELESSHELPER_EXPORT void blurImage(QPainter *painter, QImage &blurImage, const qreal radius, const bool quality, const bool alphaOnly, const int transposed = 0);
|
||||
FRAMELESSHELPER_EXPORT QColor getNativeWindowFrameColor(const bool isActive = true);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,19 @@
|
|||
#include <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <dwmapi.h>
|
||||
#include <QtGui/qpa/qplatformwindow.h>
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <QtGui/qpa/qplatformnativeinterface.h>
|
||||
#else
|
||||
#include <QtGui/qpa/qplatformwindow_p.h>
|
||||
#endif
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
#include <QtCore/qoperatingsystemversion.h>
|
||||
#else
|
||||
#include <QtCore/qsysinfo.h>
|
||||
#endif
|
||||
|
||||
Q_DECLARE_METATYPE(QMargins)
|
||||
|
||||
#ifndef USER_DEFAULT_SCREEN_DPI
|
||||
// Only available since Windows Vista
|
||||
|
@ -188,7 +201,7 @@ using Win32Data = struct _FLH_UTILITIES_WIN32_DATA
|
|||
|
||||
Q_GLOBAL_STATIC(Win32Data, win32Data)
|
||||
|
||||
bool Utilities::isBlurEffectSupported()
|
||||
bool Utilities::isDwmBlurAvailable()
|
||||
{
|
||||
if (isWin8OrGreater()) {
|
||||
return true;
|
||||
|
@ -272,7 +285,7 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric,
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Utilities::setAcrylicEffectEnabled(const QWindow *window, const bool enabled, const QColor &gradientColor)
|
||||
bool Utilities::setBlurEffectEnabled(const QWindow *window, const bool enabled, const QColor &gradientColor)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
if (!window) {
|
||||
|
@ -301,7 +314,7 @@ bool Utilities::setAcrylicEffectEnabled(const QWindow *window, const bool enable
|
|||
qRound(colorizationColor.green() * (colorizationColor.alpha() / 255.0) + 255 - colorizationColor.alpha()),
|
||||
qRound(colorizationColor.blue() * (colorizationColor.alpha() / 255.0) + 255 - colorizationColor.alpha()));
|
||||
}
|
||||
if (isMSWin10AcrylicEffectAvailable()) {
|
||||
if (isOfficialMSWin10AcrylicBlurAvailable()) {
|
||||
accentPolicy.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
|
||||
if (!gradientColor.isValid()) {
|
||||
accentPolicy.GradientColor = 0x01FFFFFF;
|
||||
|
@ -542,3 +555,135 @@ QColor Utilities::getNativeWindowFrameColor(const bool isActive)
|
|||
}
|
||||
return isColorizationEnabled() ? getColorizationColor() : (isDarkThemeEnabled() ? Qt::white : Qt::black);
|
||||
}
|
||||
|
||||
void Utilities::updateQtFrameMargins(QWindow *window, const bool enable)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
const int tbh = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, true, true) : 0;
|
||||
const QMargins margins = {0, -tbh, 0, 0};
|
||||
const QVariant marginsVar = QVariant::fromValue(margins);
|
||||
window->setProperty("_q_windowsCustomMargins", marginsVar);
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QPlatformWindow *platformWindow = window->handle();
|
||||
if (platformWindow) {
|
||||
QGuiApplication::platformNativeInterface()->setWindowProperty(platformWindow, QStringLiteral("WindowsCustomMargins"), marginsVar);
|
||||
}
|
||||
#else
|
||||
auto *platformWindow = dynamic_cast<QNativeInterface::Private::QWindowsWindow *>(
|
||||
window->handle());
|
||||
if (platformWindow) {
|
||||
platformWindow->setCustomMargins(margins);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin7OrGreater()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows7;
|
||||
#else
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS7;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin8OrGreater()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8;
|
||||
#else
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin8Point1OrGreater()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8_1;
|
||||
#else
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8_1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin10OrGreater()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10;
|
||||
#else
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS10;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isWin10OrGreater(const int subVer)
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, subVer);
|
||||
#else
|
||||
Q_UNUSED(ver);
|
||||
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS10;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline bool forceEnableDwmBlur()
|
||||
{
|
||||
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceDWMBlur_flag);
|
||||
}
|
||||
|
||||
static inline bool forceDisableWallpaperBlur()
|
||||
{
|
||||
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceDisableWallpaperBlur_flag);
|
||||
}
|
||||
|
||||
static inline bool forceEnableOfficialMSWin10AcrylicBlur()
|
||||
{
|
||||
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceOfficialMSWin10Blur_flag);
|
||||
}
|
||||
|
||||
static inline bool shouldUseOfficialMSWin10AcrylicBlur()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
const QOperatingSystemVersion currentVersion = QOperatingSystemVersion::current();
|
||||
if (currentVersion > QOperatingSystemVersion::Windows10) {
|
||||
return true;
|
||||
}
|
||||
return ((currentVersion.microVersion() >= 16190) && (currentVersion.microVersion() < 18362));
|
||||
#else
|
||||
// TODO
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::isOfficialMSWin10AcrylicBlurAvailable()
|
||||
{
|
||||
if (!isWin10OrGreater()) {
|
||||
return false;
|
||||
}
|
||||
if (!forceEnableDwmBlur() && !forceDisableWallpaperBlur()) {
|
||||
// We can't enable the official Acrylic blur in wallpaper blur mode.
|
||||
return false;
|
||||
}
|
||||
if (forceEnableOfficialMSWin10AcrylicBlur()) {
|
||||
return true;
|
||||
}
|
||||
return shouldUseOfficialMSWin10AcrylicBlur();
|
||||
}
|
||||
|
||||
static inline bool shouldUseOriginalDwmBlur()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
return Utilities::isWin10OrGreater() || (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite);
|
||||
#else
|
||||
// TODO
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::shouldUseTraditionalBlur()
|
||||
{
|
||||
if ((forceEnableDwmBlur() || forceDisableWallpaperBlur()) && shouldUseOriginalDwmBlur()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue