1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Philip Falkner <philip.falkner@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 *********************************************************************/
23 #include <kconfiggroup.h>
28 KWIN_EFFECT( fade
, FadeEffect
)
30 FadeEffect::FadeEffect()
32 reconfigure( ReconfigureAll
);
35 void FadeEffect::reconfigure( ReconfigureFlags
)
37 KConfigGroup conf
= effects
->effectConfig( "Fade" );
38 fadeInTime
= animationTime( conf
, "FadeInTime", 150 );
39 fadeOutTime
= animationTime( conf
, "FadeOutTime", 150 );
40 fadeWindows
= conf
.readEntry( "FadeWindows", true );
42 // Add all existing windows to the window list
43 // TODO: Enabling desktop effects should trigger windowAdded() on all windows
45 foreach( EffectWindow
*w
, effects
->stackingOrder() )
46 windows
[ w
].opacity
= 1.0;
49 void FadeEffect::prePaintScreen( ScreenPrePaintData
& data
, int time
)
51 if( !windows
.isEmpty())
53 fadeInStep
= time
/ double( fadeInTime
);
54 fadeOutStep
= time
/ double( fadeOutTime
);
56 effects
->prePaintScreen( data
, time
);
59 void FadeEffect::prePaintWindow( EffectWindow
* w
, WindowPrePaintData
& data
, int time
)
61 if( windows
.contains( w
))
63 windows
[ w
].fadeInStep
+= fadeInStep
;
64 windows
[ w
].fadeOutStep
+= fadeOutStep
;
65 if( windows
[ w
].opacity
< 1.0 )
66 data
.setTranslucent();
67 if( windows
[ w
].deleted
)
69 if( windows
[ w
].opacity
<= 0.0 )
75 w
->enablePainting( EffectWindow::PAINT_DISABLED_BY_DELETE
);
78 effects
->prePaintWindow( w
, data
, time
);
79 if( windows
.contains( w
) && !w
->isPaintingEnabled())
80 { // if the window isn't to be painted, then let's make sure
81 // to track its progress
82 if( windows
[ w
].fadeInStep
< 1.0
83 || windows
[ w
].fadeOutStep
< 1.0 )
84 { // but only if the total change is less than the
85 // maximum possible change
91 void FadeEffect::paintWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
)
93 if( windows
.contains( w
))
95 if( windows
[ w
].deleted
96 || windows
[ w
].opacity
!= data
.opacity
97 || windows
[ w
].saturation
!= data
.saturation
98 || windows
[ w
].brightness
!= data
.brightness
)
100 WindowPaintData new_data
= data
;
102 if( windows
[ w
].deleted
)
103 new_data
.opacity
= 0.0;
105 if( new_data
.opacity
> windows
[ w
].opacity
)
107 windows
[ w
].opacity
= qMin( new_data
.opacity
,
108 windows
[ w
].opacity
+ windows
[ w
].fadeInStep
);
110 else if( new_data
.opacity
< windows
[ w
].opacity
)
112 windows
[ w
].opacity
= qMax( new_data
.opacity
,
113 windows
[ w
].opacity
- windows
[ w
].fadeOutStep
);
116 if( new_data
.saturation
> windows
[ w
].saturation
)
118 windows
[ w
].saturation
= qMin( new_data
.saturation
,
119 windows
[ w
].saturation
+ windows
[ w
].fadeInStep
);
121 else if( new_data
.saturation
< windows
[ w
].saturation
)
123 windows
[ w
].saturation
= qMax( new_data
.saturation
,
124 windows
[ w
].saturation
- windows
[ w
].fadeOutStep
);
127 if( new_data
.brightness
> windows
[ w
].brightness
)
129 windows
[ w
].brightness
= qMin( new_data
.brightness
,
130 windows
[ w
].brightness
+ windows
[ w
].fadeInStep
);
132 else if( new_data
.brightness
< windows
[ w
].brightness
)
134 windows
[ w
].brightness
= qMax( new_data
.brightness
,
135 windows
[ w
].brightness
- windows
[ w
].fadeOutStep
);
138 windows
[ w
].opacity
= qBound( 0.0, windows
[ w
].opacity
, 1.0 );
139 windows
[ w
].saturation
= qBound( 0.0, windows
[ w
].saturation
, 1.0 );
140 windows
[ w
].brightness
= qBound( 0.0, windows
[ w
].brightness
, 1.0 );
141 windows
[ w
].fadeInStep
= 0.0;
142 windows
[ w
].fadeOutStep
= 0.0;
144 new_data
.opacity
= windows
[ w
].opacity
;
145 new_data
.saturation
= windows
[ w
].saturation
;
146 new_data
.brightness
= windows
[ w
].brightness
;
147 effects
->paintWindow( w
, mask
, region
, new_data
);
148 if( windows
[ w
].opacity
!= data
.opacity
149 || windows
[ w
].saturation
!= data
.saturation
150 || windows
[ w
].brightness
!= data
.brightness
)
154 windows
[ w
].fadeInStep
= 0.0;
155 windows
[ w
].fadeOutStep
= 0.0;
157 effects
->paintWindow( w
, mask
, region
, data
);
160 void FadeEffect::windowOpacityChanged( EffectWindow
* w
, double old_opacity
)
162 if( !windows
.contains( w
))
163 windows
[ w
].opacity
= old_opacity
;
164 if( windows
[ w
].opacity
== 1.0 )
165 windows
[ w
].opacity
-= 0.1 / fadeOutTime
;
169 void FadeEffect::windowAdded( EffectWindow
* w
)
171 if( !fadeWindows
|| !isFadeWindow( w
))
173 windows
[ w
].opacity
= 0.0;
177 void FadeEffect::windowClosed( EffectWindow
* w
)
179 if( !fadeWindows
|| !isFadeWindow( w
))
181 if( !windows
.contains( w
))
182 windows
[ w
].opacity
= w
->opacity();
183 if( windows
[ w
].opacity
== 1.0 )
184 windows
[ w
].opacity
-= 0.1 / fadeOutTime
;
185 windows
[ w
].deleted
= true;
190 void FadeEffect::windowDeleted( EffectWindow
* w
)
195 bool FadeEffect::isFadeWindow( EffectWindow
* w
)
197 if( w
->windowClass() == "ksplashx ksplashx"
198 || w
->windowClass() == "ksplashsimple ksplashsimple" )
199 { // see login effect
202 return ( !w
->isDesktop() && !w
->isUtility() );