diff --git a/effects/shadow.cpp b/effects/shadow.cpp
index 0e6ce06a8d..6570e36faa 100644
--- a/effects/shadow.cpp
+++ b/effects/shadow.cpp
@@ -19,6 +19,7 @@ along with this program. If not, see .
*********************************************************************/
#include "shadow.h"
+#include "shadow_helper.h"
#include
@@ -26,6 +27,7 @@ along with this program. If not, see .
#include
#include
#include
+#include
namespace KWin
{
@@ -40,11 +42,20 @@ ShadowEffect::ShadowEffect()
shadowOpacity = conf.readEntry( "Opacity", 0.25 );
shadowFuzzyness = conf.readEntry( "Fuzzyness", 10 );
shadowSize = conf.readEntry( "Size", 5 );
- shadowColor = conf.readEntry( "Color", KColorScheme::shade( Qt::white, KColorScheme::ShadowShade ) );
intensifyActiveShadow = conf.readEntry( "IntensifyActiveShadow", true );
QString shadowtexture = KGlobal::dirs()->findResource("data", "kwin/shadow-texture.png");
mShadowTexture = new GLTexture(shadowtexture);
+
+ updateShadowColor();
+ connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
+ this, SLOT(updateShadowColor()));
+ }
+
+void ShadowEffect::updateShadowColor()
+ {
+ KConfigGroup conf = effects->effectConfig("Shadow");
+ shadowColor = conf.readEntry( "Color", schemeShadowColor() );
}
QRect ShadowEffect::shadowRectangle(const QRect& windowRectangle) const
@@ -229,3 +240,5 @@ void ShadowEffect::drawShadow( EffectWindow* window, int mask, QRegion region, W
}
} // namespace
+
+#include "shadow.h"
diff --git a/effects/shadow.h b/effects/shadow.h
index b34669ae29..2789353744 100644
--- a/effects/shadow.h
+++ b/effects/shadow.h
@@ -30,8 +30,9 @@ namespace KWin
class GLTexture;
class ShadowEffect
- : public Effect
+ : public QObject, public Effect
{
+ Q_OBJECT
public:
ShadowEffect();
virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time );
@@ -39,6 +40,10 @@ class ShadowEffect
virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
virtual void windowClosed( EffectWindow* c );
virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
+
+ private slots:
+ void updateShadowColor();
+
private:
void drawShadow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
void addQuadVertices(QVector& verts, float x1, float y1, float x2, float y2) const;
diff --git a/effects/shadow_config.cpp b/effects/shadow_config.cpp
index dd09b2c8fd..792a158f84 100644
--- a/effects/shadow_config.cpp
+++ b/effects/shadow_config.cpp
@@ -19,6 +19,7 @@ along with this program. If not, see .
*********************************************************************/
#include "shadow_config.h"
+#include "shadow_helper.h"
#include
@@ -38,12 +39,6 @@ along with this program. If not, see .
KWIN_EFFECT_CONFIG_FACTORY
#endif
-// Save some typing
-static QColor schemeShadowColor()
-{
- return KColorScheme::shade(Qt::white, KColorScheme::ShadowShade);
-}
-
namespace KWin
{
diff --git a/effects/shadow_helper.h b/effects/shadow_helper.h
new file mode 100644
index 0000000000..dbc178bdae
--- /dev/null
+++ b/effects/shadow_helper.h
@@ -0,0 +1,70 @@
+/********************************************************************
+KWin - the KDE window manager
+This file is part of the KDE project.
+
+Copyright (C) 2008 Louai Al-Khanji
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*********************************************************************/
+
+// This contains code shared by the shadow effect and shadow effect configurator
+// Mark all functions static so the symbols are not exported!
+
+#ifndef KWIN_SHADOW_HELPER_H
+#define KWIN_SHADOW_HELPER_H
+
+#include
+#include
+
+static const int MAX_ITERS = 10; // should be enough
+static const qreal LUMA_THRESHOLD = 0.05;
+static const qreal MINIMUM_CONTRAST = 3.0;
+
+static bool contrastTooLow(const QColor& one, const QColor& two)
+ {
+ return KColorUtils::contrastRatio(one, two) < MINIMUM_CONTRAST;
+ }
+
+static QColor schemeShadowColor()
+ {
+ QPalette palette;
+ QColor shadowColor;
+ QPalette::ColorRole shadowRole;
+ QColor windowColor;
+
+ windowColor = palette.color(QPalette::Window);
+
+ if (KColorUtils::luma(windowColor) >= LUMA_THRESHOLD)
+ shadowRole = QPalette::Shadow;
+ else
+ shadowRole = QPalette::Light;
+
+ shadowColor = palette.color(shadowRole);
+
+ // Some styles might set a weird shadow or light color. Make sure we
+ // dont't end up looping forever or we might lock up the desktop!!
+ int iters = 0;
+ while (contrastTooLow(shadowColor, windowColor) && iters < MAX_ITERS)
+ {
+ iters++;
+ if (shadowRole == QPalette::Shadow)
+ shadowColor = KColorUtils::darken(shadowColor);
+ else
+ shadowColor = KColorUtils::lighten(shadowColor);
+ }
+
+ return shadowColor;
+ }
+
+#endif // KWIN_SHADOW_HELPER_H