|
|
|
|
@ -18,9 +18,62 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "windowblur.h"
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QPainterPath>
|
|
|
|
|
#include <KWindowEffects>
|
|
|
|
|
|
|
|
|
|
static QRegion roundedRegion(const QRect &rect, int radius, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight)
|
|
|
|
|
{
|
|
|
|
|
QRegion region(rect, QRegion::Rectangle);
|
|
|
|
|
|
|
|
|
|
if (topLeft) {
|
|
|
|
|
// Round top-left corner.
|
|
|
|
|
const QRegion topLeftCorner(rect.x(), rect.y(), radius, radius, QRegion::Rectangle);
|
|
|
|
|
const QRegion topLeftRounded(rect.x(), rect.y(), 2 * radius, 2 * radius, QRegion::Ellipse);
|
|
|
|
|
const QRegion topLeftEar = topLeftCorner - topLeftRounded;
|
|
|
|
|
region -= topLeftEar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (topRight) {
|
|
|
|
|
// Round top-right corner.
|
|
|
|
|
const QRegion topRightCorner(
|
|
|
|
|
rect.x() + rect.width() - radius, rect.y(),
|
|
|
|
|
radius, radius, QRegion::Rectangle);
|
|
|
|
|
const QRegion topRightRounded(
|
|
|
|
|
rect.x() + rect.width() - 2 * radius, rect.y(),
|
|
|
|
|
2 * radius, 2 * radius, QRegion::Ellipse);
|
|
|
|
|
const QRegion topRightEar = topRightCorner - topRightRounded;
|
|
|
|
|
region -= topRightEar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bottomRight) {
|
|
|
|
|
// Round bottom-right corner.
|
|
|
|
|
const QRegion bottomRightCorner(
|
|
|
|
|
rect.x() + rect.width() - radius, rect.y() + rect.height() - radius,
|
|
|
|
|
radius, radius, QRegion::Rectangle);
|
|
|
|
|
const QRegion bottomRightRounded(
|
|
|
|
|
rect.x() + rect.width() - 2 * radius, rect.y() + rect.height() - 2 * radius,
|
|
|
|
|
2 * radius, 2 * radius, QRegion::Ellipse);
|
|
|
|
|
const QRegion bottomRightEar = bottomRightCorner - bottomRightRounded;
|
|
|
|
|
region -= bottomRightEar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bottomLeft){
|
|
|
|
|
// Round bottom-left corner.
|
|
|
|
|
const QRegion bottomLeftCorner(
|
|
|
|
|
rect.x(), rect.y() + rect.height() - radius,
|
|
|
|
|
radius, radius, QRegion::Rectangle);
|
|
|
|
|
const QRegion bottomLeftRounded(
|
|
|
|
|
rect.x(), rect.y() + rect.height() - 2 * radius,
|
|
|
|
|
2 * radius, 2 * radius, QRegion::Ellipse);
|
|
|
|
|
const QRegion bottomLeftEar = bottomLeftCorner - bottomLeftRounded;
|
|
|
|
|
region -= bottomLeftEar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return region;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WindowBlur::WindowBlur(QObject *parent) noexcept
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, m_view(nullptr)
|
|
|
|
|
@ -111,10 +164,7 @@ void WindowBlur::updateBlur()
|
|
|
|
|
if (m_view) {
|
|
|
|
|
if (m_enabled) {
|
|
|
|
|
QRect rect = QRect(0, 0, m_rect.width(), m_rect.height());
|
|
|
|
|
QPainterPath path;
|
|
|
|
|
rect.adjust(1, 1, -1, -1);
|
|
|
|
|
path.addRoundedRect(rect, m_windowRadius, m_windowRadius);
|
|
|
|
|
KWindowEffects::enableBlurBehind(m_view->winId(), true, path.toFillPolygon().toPolygon());
|
|
|
|
|
KWindowEffects::enableBlurBehind(m_view->winId(), true, roundedRegion(rect, m_windowRadius, true, true, true, true));
|
|
|
|
|
} else {
|
|
|
|
|
KWindowEffects::enableBlurBehind(m_view->winId(), false);
|
|
|
|
|
}
|
|
|
|
|
|