Fix menu blur in HiDPI

main
reionwong 4 years ago
parent 901150a736
commit 0af0d85642

4
debian/changelog vendored

@ -1,5 +1,5 @@
cutefish-qtplugins (0.5) UNRELEASED; urgency=high
cutefish-qt-plugins (0.5) UNRELEASED; urgency=high
* Initial release (CutefishOS) <support@cutefishos.com>
-- CutefishOS Packaging Team <support@cutefishos.com> Thu, 16 Sep 2021 02:31:42 +0800
-- CutefishOS Packaging Team <support@cutefishos.com> Thu, 16 Sep 2021 02:31:42 +0800

4
debian/control vendored

@ -1,4 +1,4 @@
Source: cutefish-qtplugins
Source: cutefish-qt-plugins
Section: devel
Priority: optional
Maintainer: CutefishOS <support@cutefishos.com>
@ -20,7 +20,7 @@ Build-Depends: cmake,
Standards-Version: 4.5.0
Homepage: https://cutefishos.com
Package: cutefish-qtplugins
Package: cutefish-qt-plugins
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends}

@ -2170,10 +2170,12 @@ void BaseStyle::drawPrimitive(PrimitiveElement elem,
// blur
if (widget && widget->window()) {
QPainterPath path;
path.addRoundedRect(option->rect, Phantom::DefaultFrame_Radius, Phantom::DefaultFrame_Radius);
const_cast<QWidget *>(widget)->setMask(path.toFillPolygon().toPolygon());
m_blurHelper->update(const_cast<QWidget *>(widget));
// QPainterPath path;
// path.addRoundedRect(option->rect, Phantom::DefaultFrame_Radius, Phantom::DefaultFrame_Radius);
// const_cast<QWidget *>(widget)->setMask(path.toFillPolygon().toPolygon());
// m_blurHelper->update(const_cast<QWidget *>(widget));
m_blurHelper->enableBlurBehind(const_cast<QWidget *>(widget), true, Phantom::DefaultFrame_Radius);
}
painter->restore();
@ -4481,7 +4483,7 @@ void BaseStyle::polish(QWidget *widget)
if (qobject_cast<QMenu *>(widget)) {
widget->setAttribute(Qt::WA_TranslucentBackground, true);
m_blurHelper->registerWidget(widget);
// m_blurHelper->registerWidget(widget);
}
if (widget->inherits("QTipLabel") || widget->inherits("QComboBoxPrivateContainer")) {
@ -4510,7 +4512,7 @@ void BaseStyle::unpolish(QWidget *widget)
if (qobject_cast<QMenu *>(widget)) {
widget->setAttribute(Qt::WA_TranslucentBackground, false);
m_blurHelper->unregisterWidget(widget);
// m_blurHelper->unregisterWidget(widget);
}
if (widget->inherits("QTipLabel")) {

@ -36,6 +36,8 @@
// Qt
#include <QWidget>
#include <QScreen>
#include <QRect>
#include <QVariant>
#include <QEvent>
#include <QPainterPath>
@ -110,3 +112,41 @@ void BlurHelper::update(QWidget *widget) const
widget->update();
}
}
void BlurHelper::enableBlurBehind(QWidget *widget, bool enable, qreal windowRadius)
{
if (!widget)
return;
xcb_connection_t *c = QX11Info::connection();
if (!c)
return;
const QByteArray effectName = QByteArrayLiteral("_KDE_NET_WM_BLUR_BEHIND_REGION");
xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData());
QScopedPointer<xcb_intern_atom_reply_t, QScopedPointerPodDeleter> atom(xcb_intern_atom_reply(c, atomCookie, nullptr));
if (!atom)
return;
if (enable) {
qreal devicePixelRatio = widget->screen()->devicePixelRatio();
QPainterPath path;
path.addRoundedRect(QRectF(QPoint(0, 0), widget->size() * devicePixelRatio),
windowRadius * devicePixelRatio,
windowRadius * devicePixelRatio);
QVector<uint32_t> data;
for (const QPolygonF &polygon : path.toFillPolygons()) {
QRegion region = polygon.toPolygon();
for (auto i = region.begin(); i != region.end(); ++i) {
data << i->x() << i->y() << i->width() << i->height();
}
}
xcb_change_property(c, XCB_PROP_MODE_REPLACE, widget->winId(),
atom->atom, XCB_ATOM_CARDINAL,
32, data.size(), data.constData());
} else {
xcb_delete_property(c, widget->winId(), atom->atom);
}
}

@ -46,6 +46,8 @@ public:
void update(QWidget *) const;
void enableBlurBehind(QWidget *widget, bool enable = true, qreal windowRadius = 0.0);
protected:
void addEventFilter(QObject *object) {
object->removeEventFilter(this);

Loading…
Cancel
Save