not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / effects / test / demo_shakymove.cpp
bloba3a7a2e15e1b25133f8602d9ec707900dcef95a3
1 /*****************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7 You can Freely distribute this program under the GNU General Public
8 License. See the file "COPYING" for the exact licensing terms.
9 ******************************************************************/
11 #include "demo_shakymove.h"
13 namespace KWin
16 KWIN_EFFECT( demo_shakymove, ShakyMoveEffect )
18 ShakyMoveEffect::ShakyMoveEffect()
20 connect( &timer, SIGNAL( timeout()), SLOT( tick()));
23 static const int shaky_diff[] = { 0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1 };
24 static const int SHAKY_MAX = sizeof( shaky_diff ) / sizeof( shaky_diff[ 0 ] );
26 void ShakyMoveEffect::prePaintScreen( ScreenPrePaintData& data, int time )
28 if( !windows.isEmpty())
29 data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
30 effects->prePaintScreen( data, time );
33 void ShakyMoveEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
35 if( windows.contains( w ))
36 data.setTransformed();
37 effects->prePaintWindow( w, data, time );
40 void ShakyMoveEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
42 if( windows.contains( w ))
43 data.xTranslate += shaky_diff[ windows[ w ]];
44 effects->paintWindow( w, mask, region, data );
47 void ShakyMoveEffect::windowUserMovedResized( EffectWindow* c, bool first, bool last )
49 if( first )
51 if( windows.isEmpty())
52 timer.start( 50 );
53 windows[ c ] = 0;
55 else if( last )
57 windows.remove( c );
58 // just repaint whole screen, transformation is involved
59 effects->addRepaintFull();
60 if( windows.isEmpty())
61 timer.stop();
65 void ShakyMoveEffect::windowClosed( EffectWindow* c )
67 windows.remove( c );
68 if( windows.isEmpty())
69 timer.stop();
72 // TODO use time provided with prePaintWindow() instead
73 void ShakyMoveEffect::tick()
75 for( QHash< const EffectWindow*, int >::Iterator it = windows.begin();
76 it != windows.end();
77 ++it )
79 if( *it == SHAKY_MAX - 1 )
80 *it = 0;
81 else
82 ++(*it);
83 // just repaint whole screen, transformation is involved
84 effects->addRepaintFull();
88 } // namespace
90 #include "demo_shakymove.moc"