not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / effects / diminactive.cpp
blob5f6daac1d2bafb9b2271334ec76288f890eed8d2
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
6 Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #include "diminactive.h"
24 #include <kconfiggroup.h>
26 namespace KWin
29 KWIN_EFFECT( diminactive, DimInactiveEffect )
31 DimInactiveEffect::DimInactiveEffect()
33 reconfigure( ReconfigureAll );
34 active = effects->activeWindow();
37 void DimInactiveEffect::reconfigure( ReconfigureFlags )
39 KConfigGroup conf = EffectsHandler::effectConfig("DimInactive");
40 dim_panels = conf.readEntry("DimPanels", false);
41 dim_desktop = conf.readEntry("DimDesktop", false);
42 dim_by_group = conf.readEntry("DimByGroup", true);
43 dim_strength = conf.readEntry("Strength", 25);
46 void DimInactiveEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
48 if( dimWindow( w ))
50 data.brightness *= (1.0 - (dim_strength / 100.0));
51 data.saturation *= (1.0 - (dim_strength / 100.0));
53 effects->paintWindow( w, mask, region, data );
56 bool DimInactiveEffect::dimWindow( const EffectWindow* w ) const
58 if( active == w )
59 return false; // never dim active window
60 if( active && dim_by_group && active->group() == w->group())
61 return false; // don't dim in active group if configured so
62 if( w->isDock() && !dim_panels )
63 return false; // don't dim panels if configured so
64 if( w->isDesktop() && !dim_desktop )
65 return false; // don't dim the desktop if configured so
66 if( !w->isNormalWindow() && !w->isDialog() && !w->isDock() && !w->isDesktop())
67 return false; // don't dim more special window types
68 // don't dim unmanaged windows, grouping doesn't work for them and maybe dimming
69 // them doesn't make sense in general (they should be short-lived anyway)
70 if( !w->isManaged())
71 return false;
72 return true; // dim the rest
75 void DimInactiveEffect::windowActivated( EffectWindow* w )
77 if( active != NULL )
79 if( dim_by_group )
81 if(( w == NULL || w->group() != active->group()) && active->group() != NULL )
82 { // repaint windows that are no longer in the active group
83 foreach( EffectWindow* tmp, active->group()->members())
84 tmp->addRepaintFull();
87 else
88 active->addRepaintFull();
90 active = w;
91 if( active != NULL )
93 if( dim_by_group )
95 if( active->group() != NULL )
96 { // repaint newly active windows
97 foreach( EffectWindow* tmp, active->group()->members())
98 tmp->addRepaintFull();
101 else
102 active->addRepaintFull();
106 } // namespace