kwin/effects/_test/demo_shakymove.cpp

87 lines
2.3 KiB
C++
Raw Normal View History

/*****************************************************************
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.
******************************************************************/
#include "demo_shakymove.h"
namespace KWin
{
2011-01-30 14:34:42 +00:00
KWIN_EFFECT(demo_shakymove, ShakyMoveEffect)
ShakyMoveEffect::ShakyMoveEffect()
2011-01-30 14:34:42 +00:00
{
connect(&timer, SIGNAL(timeout()), SLOT(tick()));
}
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 ]);
2011-01-30 14:34:42 +00:00
void ShakyMoveEffect::prePaintScreen(ScreenPrePaintData& data, int time)
{
if (!windows.isEmpty())
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
2011-01-30 14:34:42 +00:00
effects->prePaintScreen(data, time);
}
2011-01-30 14:34:42 +00:00
void ShakyMoveEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
{
if (windows.contains(w))
data.setTransformed();
2011-01-30 14:34:42 +00:00
effects->prePaintWindow(w, data, time);
}
2011-01-30 14:34:42 +00:00
void ShakyMoveEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
if (windows.contains(w))
data.xTranslate += shaky_diff[ windows[ w ]];
2011-01-30 14:34:42 +00:00
effects->paintWindow(w, mask, region, data);
}
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);
windows[ c ] = 0;
2011-01-30 14:34:42 +00:00
} else if (last) {
windows.remove(c);
// just repaint whole screen, transformation is involved
effects->addRepaintFull();
2011-01-30 14:34:42 +00:00
if (windows.isEmpty())
timer.stop();
}
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void ShakyMoveEffect::windowClosed(EffectWindow* c)
{
windows.remove(c);
if (windows.isEmpty())
timer.stop();
2011-01-30 14:34:42 +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)
*it = 0;
else
++(*it);
// just repaint whole screen, transformation is involved
effects->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
}
} // namespace
#include "demo_shakymove.moc"