forked from github_mirror/framelesshelper
fix Qt5 compilation error
And change to lazy initialization for Mica Material. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
f6e9bd895c
commit
b50a2dcd72
|
@ -240,7 +240,8 @@ enum class Option
|
|||
WindowUseRoundCorners = 4,
|
||||
CenterWindowBeforeShow = 5,
|
||||
EnableBlurBehindWindow = 6,
|
||||
ForceNonNativeBackgroundBlur = 7
|
||||
ForceNonNativeBackgroundBlur = 7,
|
||||
DisableLazyInitializationForMicaMaterial = 8
|
||||
};
|
||||
Q_ENUM_NS(Option)
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
void setNoiseOpacity(const qreal value);
|
||||
|
||||
public Q_SLOTS:
|
||||
void paint(QPainter *painter, const QSize &size, const QPoint &pos) const;
|
||||
void paint(QPainter *painter, const QSize &size, const QPoint &pos);
|
||||
Q_NODISCARD static MicaMaterial *attach(QObject *target);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
|
@ -48,11 +48,12 @@ public:
|
|||
public Q_SLOTS:
|
||||
void maybeGenerateBlurredWallpaper(const bool force = false);
|
||||
void updateMaterialBrush();
|
||||
void paint(QPainter *painter, const QSize &size, const QPoint &pos) const;
|
||||
void paint(QPainter *painter, const QSize &size, const QPoint &pos);
|
||||
Q_NODISCARD static MicaMaterial *attach(QObject *target);
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
void prepareGraphicsResources();
|
||||
|
||||
private:
|
||||
QPointer<MicaMaterial> q_ptr = nullptr;
|
||||
|
|
|
@ -196,4 +196,4 @@ FRAMELESSHELPER_QUICK_API void uninitialize();
|
|||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickGlobal))
|
||||
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickGlobal))
|
||||
|
|
|
@ -60,7 +60,9 @@ static const struct
|
|||
{FRAMELESSHELPER_BYTEARRAY_LITERAL("FRAMELESSHELPER_ENABLE_BLUR_BEHIND_WINDOW"),
|
||||
FRAMELESSHELPER_BYTEARRAY_LITERAL("Options/EnableBlurBehindWindow")},
|
||||
{FRAMELESSHELPER_BYTEARRAY_LITERAL("FRAMELESSHELPER_FORCE_NON_NATIVE_BACKGROUND_BLUR"),
|
||||
FRAMELESSHELPER_BYTEARRAY_LITERAL("Options/ForceNonNativeBackgroundBlur")}
|
||||
FRAMELESSHELPER_BYTEARRAY_LITERAL("Options/ForceNonNativeBackgroundBlur")},
|
||||
{FRAMELESSHELPER_BYTEARRAY_LITERAL("FRAMELESSHELPER_DISABLE_LAZY_INITIALIZATION_FOR_MICA_MATERIAL"),
|
||||
FRAMELESSHELPER_BYTEARRAY_LITERAL("Options/DisableLazyInitializationForMicaMaterial")}
|
||||
};
|
||||
|
||||
static constexpr const auto OptionCount = std::size(OptionsTable);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "micamaterial_p.h"
|
||||
#include "framelessmanager.h"
|
||||
#include "utils.h"
|
||||
#include "framelessconfig_p.h"
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qsysinfo.h>
|
||||
#include <QtCore/qmutex.h>
|
||||
|
@ -68,6 +69,7 @@ struct MicaMaterialData
|
|||
{
|
||||
QMutex mutex;
|
||||
QPixmap blurredWallpaper = {};
|
||||
bool graphicsResourcesReady = false;
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(MicaMaterialData, g_micaMaterialData)
|
||||
|
@ -572,12 +574,13 @@ void MicaMaterialPrivate::updateMaterialBrush()
|
|||
Q_EMIT q->shouldRedraw();
|
||||
}
|
||||
|
||||
void MicaMaterialPrivate::paint(QPainter *painter, const QSize &size, const QPoint &pos) const
|
||||
void MicaMaterialPrivate::paint(QPainter *painter, const QSize &size, const QPoint &pos)
|
||||
{
|
||||
Q_ASSERT(painter);
|
||||
if (!painter) {
|
||||
return;
|
||||
}
|
||||
prepareGraphicsResources();
|
||||
static constexpr const QPoint originPoint = {0, 0};
|
||||
painter->save();
|
||||
painter->setRenderHints(QPainter::Antialiasing |
|
||||
|
@ -617,6 +620,20 @@ void MicaMaterialPrivate::initialize()
|
|||
maybeGenerateBlurredWallpaper(true);
|
||||
});
|
||||
|
||||
if (FramelessConfig::instance()->isSet(Option::DisableLazyInitializationForMicaMaterial)) {
|
||||
prepareGraphicsResources();
|
||||
}
|
||||
}
|
||||
|
||||
void MicaMaterialPrivate::prepareGraphicsResources()
|
||||
{
|
||||
g_micaMaterialData()->mutex.lock();
|
||||
if (g_micaMaterialData()->graphicsResourcesReady) {
|
||||
g_micaMaterialData()->mutex.unlock();
|
||||
return;
|
||||
}
|
||||
g_micaMaterialData()->graphicsResourcesReady = true;
|
||||
g_micaMaterialData()->mutex.unlock();
|
||||
maybeGenerateBlurredWallpaper();
|
||||
updateMaterialBrush();
|
||||
}
|
||||
|
@ -644,6 +661,7 @@ void MicaMaterial::setTintColor(const QColor &value)
|
|||
if (d->tintColor == value) {
|
||||
return;
|
||||
}
|
||||
d->prepareGraphicsResources();
|
||||
d->tintColor = value;
|
||||
d->updateMaterialBrush();
|
||||
Q_EMIT tintColorChanged();
|
||||
|
@ -661,6 +679,7 @@ void MicaMaterial::setTintOpacity(const qreal value)
|
|||
if (qFuzzyCompare(d->tintOpacity, value)) {
|
||||
return;
|
||||
}
|
||||
d->prepareGraphicsResources();
|
||||
d->tintOpacity = value;
|
||||
d->updateMaterialBrush();
|
||||
Q_EMIT tintOpacityChanged();
|
||||
|
@ -678,14 +697,15 @@ void MicaMaterial::setNoiseOpacity(const qreal value)
|
|||
if (qFuzzyCompare(d->noiseOpacity, value)) {
|
||||
return;
|
||||
}
|
||||
d->prepareGraphicsResources();
|
||||
d->noiseOpacity = value;
|
||||
d->updateMaterialBrush();
|
||||
Q_EMIT noiseOpacityChanged();
|
||||
}
|
||||
|
||||
void MicaMaterial::paint(QPainter *painter, const QSize &size, const QPoint &pos) const
|
||||
void MicaMaterial::paint(QPainter *painter, const QSize &size, const QPoint &pos)
|
||||
{
|
||||
Q_D(const MicaMaterial);
|
||||
Q_D(MicaMaterial);
|
||||
d->paint(painter, size, pos);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,9 +77,8 @@ void initialize()
|
|||
qRegisterMetaType<QuickGlobal::ApplicationType>();
|
||||
qRegisterMetaType<QuickGlobal::BlurMode>();
|
||||
|
||||
qRegisterMetaType<QuickGlobal>();
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
qRegisterMetaType<QuickGlobal>();
|
||||
qRegisterMetaType<FramelessQuickHelper>();
|
||||
qRegisterMetaType<FramelessQuickHelper *>();
|
||||
qRegisterMetaType<FramelessQuickHelperPrivate>();
|
||||
|
|
Loading…
Reference in New Issue