Skip to content

Commit

Permalink
Disable blurring with windowOpacity set to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
tsujan committed Nov 8, 2024
1 parent fa08584 commit 13bc18c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 10 deletions.
1 change: 1 addition & 0 deletions Kvantum/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ V1.1.4
---------
* Exclude the opaque list from blurring of hard-coded translucency.
* Use a translucent background in "PE_Widget" if needed and existing.
* Disable and re-enable blurring if `windowOpacity` switches between 0 and 1 respectively.

V1.1.3
---------
Expand Down
2 changes: 1 addition & 1 deletion Kvantum/NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Latest version:

6 Nov 2024, V1.1.4
8 Nov 2024, V1.1.4

See "ChangeLog" for changes.
86 changes: 77 additions & 9 deletions Kvantum/style/blur/blurhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@ void BlurHelper::registerWidget (QWidget* widget)
&& !widget->inherits ("QSplashScreen")
&& !widget->windowFlags().testFlag(Qt::FramelessWindowHint))*/

widget->installEventFilter (this);
widget->installEventFilter (this);

#ifndef NO_KF
/* We want to disable blurring with a zero opacity and enable it with full opacity,
but there is no QEvent for that. Hence using "QWindow::opacityChanged" here. */
if (isNormalWindow (widget))
{
if (QWindow *win = widget->windowHandle())
connect (win, &QWindow::opacityChanged, this, &BlurHelper::onOpacityChange);
}
#endif
}
/*************************/
void BlurHelper::unregisterWidget (QWidget* widget)
Expand All @@ -86,8 +96,57 @@ void BlurHelper::unregisterWidget (QWidget* widget)
{
widget->removeEventFilter (this);
clear (widget);
#ifndef NO_KF
if (isNormalWindow (widget))
{
if (QWindow *win = widget->windowHandle())
disconnect (win, &QWindow::opacityChanged, this, &BlurHelper::onOpacityChange);
}
#endif
}
}
/*************************/
#ifndef NO_KF
void BlurHelper::onOpacityChange (qreal opacity)
{
if (opacity != static_cast<qreal>(0) && opacity != static_cast<qreal>(1))
return;
if (QWindow *win = qobject_cast<QWindow*>(QObject::sender()))
{
if (win->isVisible())
{
bool enable (opacity == static_cast<qreal>(1)
&& (!onlyActiveWindow_
|| win->flags().testFlag(Qt::WindowDoesNotAcceptFocus)
|| win->flags().testFlag(Qt::X11BypassWindowManagerHint)
|| win->isActive()));
if (enable)
{
QRegion wMask = win->mask();
if (!wMask.isEmpty() && wMask != QRegion(QRect(QPoint(0, 0), win->geometry().size())))
enable = false;
}

KWindowEffects::enableBlurBehind (win, enable);

if (contrast_ != static_cast<qreal>(1)
|| intensity_ != static_cast<qreal>(1)
|| saturation_ != static_cast<qreal>(1))
{
if (enable)
{
KWindowEffects::enableBackgroundContrast (win, true,
contrast_, intensity_, saturation_);
}
else
KWindowEffects::enableBackgroundContrast (win, false);
}

win->requestUpdate();
}
}
}
#endif
/*************************/
bool BlurHelper::isWidgetActive (const QWidget *widget) const
{
Expand All @@ -100,6 +159,16 @@ bool BlurHelper::isWidgetActive (const QWidget *widget) const
&& !qobject_cast<const QFrame*>(widget)));
}
/*************************/
bool BlurHelper::isNormalWindow (const QWidget *widget) const
{
return (widget->isWindow()
&& !qobject_cast<const QMenu*>(widget)
&& !widget->inherits("QComboBoxPrivateContainer")
&& !widget->inherits("QTipLabel")
&& ((widget->windowFlags() & Qt::WindowType_Mask) != Qt::ToolTip
|| qobject_cast<const QFrame*>(widget)));
}
/*************************/
bool BlurHelper::eventFilter (QObject* object, QEvent* event)
{
switch (event->type())
Expand Down Expand Up @@ -158,6 +227,11 @@ QRegion BlurHelper::blurRegion (QWidget* widget) const
if (!widget->isVisible())
return QRegion();

#ifndef NO_KF
if (widget->windowOpacity() == 0.0)
return QRegion();
#endif

if (onlyActiveWindow_ && !isWidgetActive (widget))
return QRegion();

Expand Down Expand Up @@ -290,10 +364,7 @@ void BlurHelper::update (QWidget* widget) const
if ((contrast_ != static_cast<qreal>(1)
|| intensity_ != static_cast<qreal>(1)
|| saturation_ != static_cast<qreal>(1))
&& !qobject_cast<QMenu*>(widget)
&& !widget->inherits("QTipLabel")
&& ((widget->windowFlags() & Qt::WindowType_Mask) != Qt::ToolTip
|| qobject_cast<QFrame*>(widget)))
&& isNormalWindow (widget))
{
KWindowEffects::enableBackgroundContrast (win, true,
contrast_, intensity_, saturation_,
Expand Down Expand Up @@ -324,10 +395,7 @@ void BlurHelper::clear (QWidget* widget) const
if ((contrast_ != static_cast<qreal>(1)
|| intensity_ != static_cast<qreal>(1)
|| saturation_ != static_cast<qreal>(1))
&& !qobject_cast<QMenu*>(widget)
&& !widget->inherits("QTipLabel")
&& ((widget->windowFlags() & Qt::WindowType_Mask) != Qt::ToolTip
|| qobject_cast<QFrame*>(widget)))
&& isNormalWindow (widget))
{
KWindowEffects::enableBackgroundContrast (win, false);
}
Expand Down
5 changes: 5 additions & 0 deletions Kvantum/style/blur/blurhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class BlurHelper: public QObject
private:

bool isWidgetActive (const QWidget *widget) const;
bool isNormalWindow (const QWidget *widget) const;

#ifndef NO_KF
void onOpacityChange (qreal opacity);
#endif

/* List of widgets for which blur region must be updated. */
typedef QPointer<QWidget> WidgetPointer;
Expand Down

0 comments on commit 13bc18c

Please sign in to comment.