add more spacing
[personal-kdebase.git] / workspace / kwin / effects / fadedesktop.cpp
blobfb142b3f153df2dc0342f8e1599359d94b242844
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.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 #include "fadedesktop.h"
23 #include <math.h>
25 namespace KWin
28 KWIN_EFFECT( fadedesktop, FadeDesktopEffect )
30 FadeDesktopEffect::FadeDesktopEffect()
31 : m_fading( false )
33 m_timeline.setCurveShape( TimeLine::LinearCurve );
34 reconfigure( ReconfigureAll );
37 void FadeDesktopEffect::reconfigure( ReconfigureFlags )
39 m_timeline.setDuration( animationTime( 250 ));
42 void FadeDesktopEffect::prePaintScreen( ScreenPrePaintData &data, int time )
44 if( m_fading )
46 m_timeline.addTime( time );
48 // PAINT_SCREEN_BACKGROUND_FIRST is needed because screen will be actually painted more than once,
49 // so with normal screen painting second screen paint would erase parts of the first paint
50 if( m_timeline.value() != 1.0 )
51 data.mask |= PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_BACKGROUND_FIRST;
52 else
54 m_fading = false;
55 m_timeline.setProgress( 0.0 );
56 effects->setActiveFullScreenEffect( NULL );
59 effects->prePaintScreen( data, time );
62 void FadeDesktopEffect::postPaintScreen()
64 if( m_fading )
65 effects->addRepaintFull();
66 effects->postPaintScreen();
69 void FadeDesktopEffect::prePaintWindow( EffectWindow *w, WindowPrePaintData &data, int time )
71 if( m_fading )
73 if( w->isOnDesktop( m_oldDesktop ))
74 w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DESKTOP );
75 data.setTranslucent();
77 effects->prePaintWindow( w, data, time );
80 void FadeDesktopEffect::paintWindow( EffectWindow *w, int mask, QRegion region, WindowPaintData &data )
82 if( m_fading && !( w->isOnCurrentDesktop() && w->isOnDesktop( m_oldDesktop )))
84 if( w->isOnDesktop( m_oldDesktop ))
85 data.opacity *= 1 - m_timeline.value();
86 else
87 data.opacity *= m_timeline.value();
89 effects->paintWindow( w, mask, region, data );
92 void FadeDesktopEffect::desktopChanged( int old )
94 if( effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this )
95 return;
97 // TODO: Fix glitches when fading while a previous fade is still happening
99 effects->setActiveFullScreenEffect( this );
100 m_fading = true;
101 m_timeline.setProgress( 0 );
102 m_oldDesktop = old;
104 effects->addRepaintFull();
107 } // namespace
109 #include "fadedesktop.moc"