2007-04-29 17:35:43 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
2007-07-03 14:44:38 +00:00
|
|
|
#include "demo_shakymove.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(demo_shakymove, ShakyMoveEffect)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
ShakyMoveEffect::ShakyMoveEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
connect(&timer, SIGNAL(timeout()), SLOT(tick()));
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
static const int shaky_diff[] = { 0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1 };
|
2011-01-30 14:34:42 +00:00
|
|
|
static const int SHAKY_MAX = sizeof(shaky_diff) / sizeof(shaky_diff[ 0 ]);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ShakyMoveEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (!windows.isEmpty())
|
2007-07-07 14:01:32 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ShakyMoveEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (windows.contains(w))
|
2007-07-19 14:05:59 +00:00
|
|
|
data.setTransformed();
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ShakyMoveEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
if (windows.contains(w))
|
2007-04-29 17:35:43 +00:00
|
|
|
data.xTranslate += shaky_diff[ windows[ w ]];
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ShakyMoveEffect::windowUserMovedResized(EffectWindow* c, bool first, bool last)
|
|
|
|
{
|
|
|
|
if (first) {
|
|
|
|
if (windows.isEmpty())
|
|
|
|
timer.start(50);
|
2007-04-29 17:35:43 +00:00
|
|
|
windows[ c ] = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (last) {
|
|
|
|
windows.remove(c);
|
2007-04-29 17:35:43 +00:00
|
|
|
// just repaint whole screen, transformation is involved
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows.isEmpty())
|
2007-04-29 17:35:43 +00:00
|
|
|
timer.stop();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ShakyMoveEffect::windowClosed(EffectWindow* c)
|
|
|
|
{
|
|
|
|
windows.remove(c);
|
|
|
|
if (windows.isEmpty())
|
2007-04-29 17:35:43 +00:00
|
|
|
timer.stop();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// TODO use time provided with prePaintWindow() instead
|
|
|
|
void ShakyMoveEffect::tick()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
for (QHash< const EffectWindow*, int >::Iterator it = windows.begin();
|
|
|
|
it != windows.end();
|
|
|
|
++it) {
|
|
|
|
if (*it == SHAKY_MAX - 1)
|
2007-04-29 17:35:43 +00:00
|
|
|
*it = 0;
|
|
|
|
else
|
|
|
|
++(*it);
|
|
|
|
// just repaint whole screen, transformation is involved
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2007-07-03 14:44:38 +00:00
|
|
|
#include "demo_shakymove.moc"
|