forked from github_mirror/framelesshelper
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:
parent
39232babdd
commit
8ebf9cfc58
|
@ -50,6 +50,7 @@ Window {
|
|||
AcrylicItem {
|
||||
id: acrylicItem
|
||||
anchors.fill: parent
|
||||
acrylicEnabled: true
|
||||
frameVisible: true
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
Q_INVOKABLE void moveToDesktopCenter();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -83,5 +83,5 @@ private:
|
|||
QtAcrylicEffectHelper m_acrylicHelper;
|
||||
bool m_frameVisible = true;
|
||||
QMetaObject::Connection m_repaintConnection = {};
|
||||
bool m_acrylicEnabled = true;
|
||||
bool m_acrylicEnabled = false;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue