From 605f00d03a40e8313023e6d82d0477832426aba3 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sat, 5 Jun 2021 21:11:04 +0300 Subject: [PATCH] effects/backgroundcontrast: Properly handle empty regions set by internal windows --- src/effects/backgroundcontrast/contrast.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/effects/backgroundcontrast/contrast.cpp b/src/effects/backgroundcontrast/contrast.cpp index fddd00d0cf..e9648f7c5e 100644 --- a/src/effects/backgroundcontrast/contrast.cpp +++ b/src/effects/backgroundcontrast/contrast.cpp @@ -91,10 +91,10 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w) { QRegion region; float colorTransform[16]; - QByteArray value; + bool valid = false; if (net_wm_contrast_region != XCB_ATOM_NONE) { - value = w->readProperty(net_wm_contrast_region, net_wm_contrast_region, 32); + const QByteArray value = w->readProperty(net_wm_contrast_region, net_wm_contrast_region, 32); if (value.size() > 0 && !((value.size() - (16 * sizeof(uint32_t))) % ((4 * sizeof(uint32_t))))) { const uint32_t *cardinals = reinterpret_cast(value.constData()); @@ -115,6 +115,8 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w) QMatrix4x4 colorMatrix(colorTransform); m_colorMatrices[w] = colorMatrix; } + + valid = !value.isNull(); } KWaylandServer::SurfaceInterface *surf = w->surface(); @@ -122,6 +124,7 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w) if (surf && surf->contrast()) { region = surf->contrast()->region(); m_colorMatrices[w] = colorMatrix(surf->contrast()->contrast(), surf->contrast()->intensity(), surf->contrast()->saturation()); + valid = true; } if (auto internal = w->internalWindow()) { @@ -142,18 +145,19 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w) saturation = 1.0; } m_colorMatrices[w] = colorMatrix(contrast, intensity, saturation); + valid = true; } } - //!value.isNull() full window in X11 case, surf->contrast() - //valid, full window in wayland case - if (region.isEmpty() && (!value.isNull() || (surf && surf->contrast()))) { + // If the specified region is empty, enable the contrast effect for the whole window. + if (region.isEmpty() && valid) { // Set the data to a dummy value. // This is needed to be able to distinguish between the value not // being set, and being set to an empty region. w->setData(WindowBackgroundContrastRole, 1); - } else + } else { w->setData(WindowBackgroundContrastRole, region); + } } void ContrastEffect::slotWindowAdded(EffectWindow *w)