Disable acrylic blur by default

If the user want to use it, the user should enable it.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2021-03-21 11:13:09 +08:00
parent 39232babdd
commit 8ebf9cfc58
9 changed files with 44 additions and 11 deletions

View File

@ -50,6 +50,7 @@ Window {
AcrylicItem {
id: acrylicItem
anchors.fill: parent
acrylicEnabled: true
frameVisible: true
}

View File

@ -49,6 +49,17 @@ void Widget::moveToDesktopCenter()
move(newX, newY);
}
void Widget::showEvent(QShowEvent *event)
{
QtAcrylicWidget::showEvent(event);
static bool inited = false;
if (!inited) {
FramelessWindowsManager::addWindow(windowHandle());
setAcrylicEnabled(true);
inited = true;
}
}
void Widget::timerEvent(QTimerEvent *event)
{
QtAcrylicWidget::timerEvent(event);

View File

@ -43,6 +43,7 @@ public:
Q_INVOKABLE void moveToDesktopCenter();
protected:
void showEvent(QShowEvent *event) override;
void timerEvent(QTimerEvent *event) override;
private:

View File

@ -227,7 +227,12 @@ void QtAcrylicEffectHelper::paintBackground(QPainter *painter, const QRect &rect
} else {
// Emulate blur behind window by blurring the desktop wallpaper.
updateBehindWindowBackground();
painter->drawPixmap(QPoint{0, 0}, m_bluredWallpaper, QRect{m_window->mapToGlobal(QPoint{0, 0}), rect.size()});
QPoint point = m_window->mapToGlobal(QPoint{0, 0});
const QRect geometry = Utilities::getScreenAvailableGeometry(m_window);
if (geometry.isValid()) {
point -= geometry.topLeft();
}
painter->drawPixmap(QPoint{0, 0}, m_bluredWallpaper, QRect{point, rect.size()});
}
painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
painter->setOpacity(1);
@ -299,10 +304,13 @@ void QtAcrylicEffectHelper::updateAcrylicBrush(const QColor &alternativeTintColo
void QtAcrylicEffectHelper::updateBehindWindowBackground()
{
if (!checkWindow()) {
return;
}
if (!m_bluredWallpaper.isNull()) {
return;
}
const QSize size = Utilities::getScreenAvailableGeometry().size();
const QSize size = Utilities::getScreenAvailableGeometry(m_window).size();
m_bluredWallpaper = QPixmap(size);
m_bluredWallpaper.fill(Qt::transparent);
QImage image = Utilities::getDesktopWallpaperImage();

View File

@ -30,8 +30,6 @@
QtAcrylicItem::QtAcrylicItem(QQuickItem *parent) : QQuickPaintedItem(parent)
{
m_acrylicHelper.showWarning();
connect(this, &QtAcrylicItem::windowChanged, this, [this](QQuickWindow *win){
if (m_repaintConnection) {
disconnect(m_repaintConnection);

View File

@ -83,5 +83,5 @@ private:
QtAcrylicEffectHelper m_acrylicHelper;
bool m_frameVisible = true;
QMetaObject::Connection m_repaintConnection = {};
bool m_acrylicEnabled = true;
bool m_acrylicEnabled = false;
};

View File

@ -24,14 +24,12 @@
#include "qtacrylicwidget.h"
#include "utilities.h"
#include "framelesswindowsmanager.h"
#include <QtCore/qdebug.h>
#include <QtGui/qevent.h>
#include <QtGui/qpainter.h>
QtAcrylicWidget::QtAcrylicWidget(QWidget *parent) : QWidget(parent)
{
m_acrylicHelper.showWarning();
}
QtAcrylicWidget::~QtAcrylicWidget() = default;
@ -163,11 +161,9 @@ void QtAcrylicWidget::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
if (!m_inited) {
FramelessWindowsManager::addWindow(windowHandle());
m_acrylicHelper.install(windowHandle());
m_acrylicHelper.updateAcrylicBrush(tintColor());
connect(&m_acrylicHelper, &QtAcrylicEffectHelper::needsRepaint, this, qOverload<>(&QtAcrylicWidget::update));
setAcrylicEnabled(true);
m_inited = true;
}
}

View File

@ -374,8 +374,14 @@ QWindow *Utilities::findWindow(const WId winId)
return nullptr;
}
QRect Utilities::getScreenAvailableGeometry()
QRect Utilities::getScreenAvailableGeometry(const QWindow *window)
{
if (window) {
const QScreen *screen = window->screen();
if (screen) {
return screen->availableGeometry();
}
}
return QGuiApplication::primaryScreen()->availableGeometry();
}
@ -470,3 +476,14 @@ bool Utilities::isMouseInSpecificObjects(const QPointF &mousePos, const QObjectL
}
return false;
}
QRect Utilities::getScreenAvailableGeometry(const QPoint &pos)
{
if (!pos.isNull()) {
const QScreen *screen = QGuiApplication::screenAt(pos);
if (screen) {
return screen->availableGeometry();
}
}
return QGuiApplication::primaryScreen()->availableGeometry();
}

View File

@ -61,7 +61,8 @@ 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 getScreenAvailableGeometry(const QWindow *window);
FRAMELESSHELPER_EXPORT QRect getScreenAvailableGeometry(const QPoint &pos);
FRAMELESSHELPER_EXPORT QRect alignedRect(const Qt::LayoutDirection direction, const Qt::Alignment alignment, const QSize &size, const QRect &rectangle);