1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2008 Louai Al-Khanji <louai.khanji@gmail.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 // This contains code shared by the shadow effect and shadow effect configurator
22 // Mark all functions static so the symbols are not exported!
24 #ifndef KWIN_SHADOW_HELPER_H
25 #define KWIN_SHADOW_HELPER_H
27 #include <KColorScheme>
28 #include <KColorUtils>
30 static const int MAX_ITERS
= 10; // should be enough
31 static const qreal LUMA_THRESHOLD
= 0.05;
32 static const qreal MINIMUM_CONTRAST
= 3.0;
34 static bool contrastTooLow(const QColor
& one
, const QColor
& two
)
36 return KColorUtils::contrastRatio(one
, two
) < MINIMUM_CONTRAST
;
39 static QColor
schemeShadowColor()
43 QPalette::ColorRole shadowRole
;
46 windowColor
= palette
.color(QPalette::Window
);
48 if (KColorUtils::luma(windowColor
) >= LUMA_THRESHOLD
)
49 shadowRole
= QPalette::Shadow
;
51 shadowRole
= QPalette::Light
;
53 shadowColor
= palette
.color(shadowRole
);
55 // Some styles might set a weird shadow or light color. Make sure we
56 // do not end up looping forever or we might lock up the desktop!!
58 while (contrastTooLow(shadowColor
, windowColor
) && iters
< MAX_ITERS
)
61 if (shadowRole
== QPalette::Shadow
)
62 shadowColor
= KColorUtils::darken(shadowColor
);
64 shadowColor
= KColorUtils::lighten(shadowColor
);
70 #endif // KWIN_SHADOW_HELPER_H