Skip to content

Commit

Permalink
Use setBlurRegion API to enable blur, fixing kornerbug
Browse files Browse the repository at this point in the history
The setBlurRegion API function is to be available only in Plasma 5.25
Opaque is now always set to false for non-maximized windows
(if opaque is set true for non-maximixed then the kornerbug presents)
The blur setting is also removed from the .json file
  • Loading branch information
paulmcauley committed May 2, 2022
1 parent b21107a commit fe48c05
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 39 deletions.
1 change: 0 additions & 1 deletion kdecoration/breeze.json
Expand Up @@ -9,7 +9,6 @@
]
},
"org.kde.kdecoration2": {
"blur": true,
"kcmodule": true,
"recommendedBorderSize": "NoSides"
}
Expand Down
103 changes: 67 additions & 36 deletions kdecoration/breezedecoration.cpp
Expand Up @@ -156,6 +156,7 @@ namespace Breeze
static QSharedPointer<KDecoration2::DecorationShadow> g_sShadow;
static QSharedPointer<KDecoration2::DecorationShadow> g_sShadowInactive;


//________________________________________________________________
Decoration::Decoration(QObject *parent, const QVariantList &args)
: KDecoration2::Decoration(parent, args)
Expand Down Expand Up @@ -303,7 +304,6 @@ namespace Breeze
{
auto c = client().toStrongRef();
Q_ASSERT(c);

// active state change animation
// It is important start and end value are of the same type, hence 0.0 and not just 0
m_animation->setStartValue( 0.0 );
Expand Down Expand Up @@ -333,10 +333,13 @@ namespace Breeze
updateTitleBar();
auto s = settings();
connect(s.data(), &KDecoration2::DecorationSettings::borderSizeChanged, this, &Decoration::recalculateBorders);
connect(s.data(), &KDecoration2::DecorationSettings::borderSizeChanged, this, &Decoration::updateBlur); //for the case when a border with transparency

// a change in font might cause the borders to change
connect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &Decoration::recalculateBorders);
connect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &Decoration::updateBlur); //for the case when a border with transparency
connect(s.data(), &KDecoration2::DecorationSettings::spacingChanged, this, &Decoration::recalculateBorders);
connect(s.data(), &KDecoration2::DecorationSettings::spacingChanged, this, &Decoration::updateBlur); //for the case when a border with transparency

// buttons
connect(s.data(), &KDecoration2::DecorationSettings::spacingChanged, this, &Decoration::updateButtonsGeometryDelayed);
Expand All @@ -362,11 +365,14 @@ namespace Breeze
);

connect(c.data(), &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateAnimationState);
connect(c.data(), &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateOpaque);
connect(c.data(), &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateBlur);
connect(c.data(), &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateTitleBar);

connect(c.data(), &KDecoration2::DecoratedClient::sizeChanged, this, &Decoration::updateBlur);

connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::setAddedTitleBarOpacity);
connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateTitleBar);
connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateOpaque);

connect(c.data(), &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonsGeometry);
connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonsGeometry);
Expand All @@ -391,7 +397,6 @@ namespace Breeze
int width, height, x, y;
setScaledTitleBarTopBottomMargins();
setScaledTitleBarSideMargins();
updateBlur();

//prevents resize handles appearing in button at top window edge for large full-height buttons
if( m_buttonSize == ButtonSize::FullHeight && !(m_internalSettings->drawBorderOnMaximizedWindows() && c->isMaximizedVertically()) )
Expand Down Expand Up @@ -508,7 +513,6 @@ namespace Breeze
setScaledCornerRadius();
setScaledTitleBarTopBottomMargins();
setScaledTitleBarSideMargins();
updateBlur();
setSystemAccentColors();

if( m_internalSettings->buttonShape() == InternalSettings::EnumButtonShape::ShapeFullHeightRectangle
Expand Down Expand Up @@ -536,17 +540,20 @@ namespace Breeze
m_shadowAnimation->setDuration(0);
}

setAddedTitleBarOpacity();

// borders
recalculateBorders();

updateOpaque();
updateBlur();

// shadow
updateShadow();

// size grip
if( hasNoBorders() && m_internalSettings->drawSizeGrip() ) createSizeGrip();
else deleteSizeGrip();

setAddedTitleBarOpacity();
else deleteSizeGrip();;
}

//________________________________________________________________
Expand Down Expand Up @@ -806,42 +813,45 @@ namespace Breeze

}

void Decoration::calculateWindowAndTitleBarShapes()
void Decoration::calculateWindowAndTitleBarShapes(const bool windowShapeOnly)
{
auto c = client().toStrongRef();
Q_ASSERT(c);
auto s = settings();

//set titleBar geometry and path
m_titleRect = QRect(QPoint(0, 0), QSize(size().width(), borderTop()));
m_titleBarPath->clear(); //clear the path for subsequent calls to this function
if( isMaximized() || !s->isAlphaChannelSupported() )
if( !windowShapeOnly || c->isShaded() )
{
m_titleBarPath->addRect(m_titleRect);
//set titleBar geometry and path
m_titleRect = QRect(QPoint(0, 0), QSize(size().width(), borderTop()));
m_titleBarPath->clear(); //clear the path for subsequent calls to this function
if( isMaximized() || !s->isAlphaChannelSupported() )
{
m_titleBarPath->addRect(m_titleRect);

} else if( c->isShaded() ) {
m_titleBarPath->addRoundedRect(m_titleRect, m_scaledCornerRadius, m_scaledCornerRadius);
} else if( c->isShaded() ) {
m_titleBarPath->addRoundedRect(m_titleRect, m_scaledCornerRadius, m_scaledCornerRadius);

} else {
QPainterPath clipRect;
clipRect.addRect(m_titleRect);

// the rect is made a little bit larger to be able to clip away the rounded corners at the bottom and sides
m_titleBarPath->addRoundedRect(m_titleRect.adjusted(
isLeftEdge() ? -m_scaledCornerRadius:0,
isTopEdge() ? -m_scaledCornerRadius:0,
isRightEdge() ? m_scaledCornerRadius:0,
m_scaledCornerRadius),
m_scaledCornerRadius, m_scaledCornerRadius);

*m_titleBarPath = m_titleBarPath->intersected(clipRect);
} else {
QPainterPath clipRect;
clipRect.addRect(m_titleRect);

// the rect is made a little bit larger to be able to clip away the rounded corners at the bottom and sides
m_titleBarPath->addRoundedRect(m_titleRect.adjusted(
isLeftEdge() ? -m_scaledCornerRadius:0,
isTopEdge() ? -m_scaledCornerRadius:0,
isRightEdge() ? m_scaledCornerRadius:0,
m_scaledCornerRadius),
m_scaledCornerRadius, m_scaledCornerRadius);

*m_titleBarPath = m_titleBarPath->intersected(clipRect);
}
}

//set windowPath
m_windowPath->clear(); //clear the path for subsequent calls to this function
if( !c->isShaded() )
{
if( s->isAlphaChannelSupported() ) m_windowPath->addRoundedRect(rect(), m_scaledCornerRadius, m_scaledCornerRadius);
if( s->isAlphaChannelSupported() && !isMaximized() ) m_windowPath->addRoundedRect(rect(), m_scaledCornerRadius, m_scaledCornerRadius);
else m_windowPath->addRect( rect() );

} else {
Expand Down Expand Up @@ -1271,23 +1281,44 @@ namespace Breeze
m_scaledCornerRadius = m_internalSettings->cornerRadius() * settings()->smallSpacing();
}

void Decoration::updateOpaque()
{
// access client
auto c = client().toStrongRef();
Q_ASSERT(c);
int titleBarOpacityToAdd = c->isActive() ? m_internalSettings->activeTitlebarOpacity() : m_internalSettings->inactiveTitlebarOpacity();

if( (m_internalSettings->opaqueMaximizedTitlebars() && c->isMaximized() )
|| ( titleBarOpacityToAdd == 100 && titleBarColor(true).alpha() == 255 )
){ //opaque titlebar colours
if( c->isMaximized() ) setOpaque(true);
else setOpaque(false);
}
else { //transparent titlebar colours
setOpaque(false);
}

}

void Decoration::updateBlur()
{
// access client
auto c = client().toStrongRef();
Q_ASSERT(c);

int titleBarOpacityToAdd = c->isActive() ? m_internalSettings->activeTitlebarOpacity() : m_internalSettings->inactiveTitlebarOpacity();

//disable blur if the titlebar is opaque
if( (m_internalSettings->opaqueMaximizedTitlebars() && c->isMaximized() )
|| !m_internalSettings->blurTransparentTitlebars()
|| ( titleBarOpacityToAdd == 100 && titleBarColor(true).alpha() == 255 )
){ //disable blur by setting opaque true
setOpaque(true);
){ //opaque titlebar colours
setBlurRegion( QRegion() );
}
else { //enable blur by setting opaque false
setOpaque(false);
else { //transparent titlebar colours
if( m_internalSettings->blurTransparentTitlebars() ){// enable blur
calculateWindowAndTitleBarShapes(true); //refreshes m_windowPath
setBlurRegion( QRegion( m_windowPath->toFillPolygon().toPolygon()) ) ;
} else setBlurRegion( QRegion() );

}
}

Expand Down
3 changes: 2 additions & 1 deletion kdecoration/breezedecoration.h
Expand Up @@ -119,6 +119,7 @@ namespace Breeze
private Q_SLOTS:
void reconfigure();
void recalculateBorders();
void updateOpaque();
void updateBlur();
void updateButtonsGeometry();
void updateButtonsGeometryDelayed();
Expand All @@ -133,7 +134,7 @@ namespace Breeze
QPair<QRect,Qt::Alignment> captionRect() const;

void createButtons();
void calculateWindowAndTitleBarShapes();
void calculateWindowAndTitleBarShapes(const bool windowShapeOnly=false);
void paintTitleBar(QPainter *painter, const QRect &repaintRegion);
void updateShadow( const bool force = false );
QSharedPointer<KDecoration2::DecorationShadow> createShadowObject( const float strengthScale );
Expand Down
2 changes: 1 addition & 1 deletion kdecoration/config/ui/breezeconfigurationui.ui
Expand Up @@ -2029,7 +2029,7 @@ side margins:</string>
<item row="3" column="0">
<widget class="QCheckBox" name="blurTransparentTitlebars">
<property name="text">
<string>Blur titlebars that have transparency (introduces infamous Plasma Kornerbug #395725)</string>
<string>Blur titlebars that have transparency</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit fe48c05

Please sign in to comment.