diff --git a/CMakeLists.txt b/CMakeLists.txt index 691610831a..2f3c76cc5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,7 @@ set(kwin_KDEINIT_SRCS effects/desktopchangeslide.cpp effects/boxswitch.cpp effects/fallapart.cpp + effects/drunken.cpp effects/test_input.cpp effects/test_thumbnail.cpp ) diff --git a/effects.cpp b/effects.cpp index 06bbb83f16..021020e143 100644 --- a/effects.cpp +++ b/effects.cpp @@ -18,6 +18,7 @@ License. See the file "COPYING" for the exact licensing terms. #include "effects/boxswitch.h" #include "effects/desktopchangeslide.h" #include "effects/dialogparent.h" +#include "effects/drunken.h" #include "effects/fade.h" #include "effects/howto.h" #include "effects/maketransparent.h" @@ -194,6 +195,7 @@ EffectsHandler::EffectsHandler() registerEffect("DialogParent", new GenericEffectFactory); registerEffect("DesktopChangeSlide", new GenericEffectFactory); registerEffect("BoxSwitch", new GenericEffectFactory); + registerEffect("Drunken", new GenericEffectFactory); registerEffect("TestInput", new GenericEffectFactory); registerEffect("TestThumbnail", new GenericEffectFactory); diff --git a/effects/drunken.cpp b/effects/drunken.cpp new file mode 100644 index 0000000000..2d6e814823 --- /dev/null +++ b/effects/drunken.cpp @@ -0,0 +1,75 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Lubos Lunak + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#include "drunken.h" + +#include + +namespace KWinInternal +{ + +void DrunkenEffect::prePaintScreen( int* mask, QRegion* region, int time ) + { + if( !windows.isEmpty()) + *mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; + effects->prePaintScreen( mask, region, time ); + } + +void DrunkenEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* region, int time ) + { + if( windows.contains( w )) + { + windows[ w ] += time / 1000.; + if( windows[ w ] < 1 ) + *mask |= Scene::PAINT_WINDOW_TRANSFORMED; + else + windows.remove( w ); + } + effects->prePaintWindow( w, mask, region, time ); + } + +void DrunkenEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) + { + if( !windows.contains( w )) + { + effects->paintWindow( w, mask, region, data ); + return; + } + WindowPaintData d1 = data; + // 4 cycles, decreasing amplitude + int diff = int( sin( windows[ w ] * 8 * M_PI ) * ( 1 - windows[ w ] ) * 10 ); + d1.xTranslate -= diff; + d1.opacity *= 0.5; + effects->paintWindow( w, mask, region, d1 ); + WindowPaintData d2 = data; + d2.xTranslate += diff; + d2.opacity *= 0.5; + effects->paintWindow( w, mask, region, d2 ); + } + +void DrunkenEffect::postPaintWindow( EffectWindow* w ) + { + if( windows.contains( w )) + w->window()->addRepaintFull(); + effects->postPaintWindow( w ); + } + +void DrunkenEffect::windowAdded( EffectWindow* w ) + { + windows[ w ] = 0; + w->window()->addRepaintFull(); + } + +void DrunkenEffect::windowClosed( EffectWindow* w ) + { + windows.remove( w ); + } + +} // namespace diff --git a/effects/drunken.h b/effects/drunken.h new file mode 100644 index 0000000000..e4d5be95ed --- /dev/null +++ b/effects/drunken.h @@ -0,0 +1,35 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Lubos Lunak + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#ifndef KWIN_DRUNKEN_H +#define KWIN_DRUNKEN_H + +#include + +namespace KWinInternal +{ + +class DrunkenEffect + : public Effect + { + public: + virtual void prePaintScreen( int* mask, QRegion* region, int time ); + virtual void prePaintWindow( EffectWindow* w, int* mask, QRegion* region, int time ); + virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); + virtual void postPaintWindow( EffectWindow* w ); + virtual void windowAdded( EffectWindow* w ); + virtual void windowClosed( EffectWindow* w ); + private: + QHash< EffectWindow*, double > windows; // progress + }; + +} // namespace + +#endif