diff --git a/effects/magiclamp/magiclamp.cpp b/effects/magiclamp/magiclamp.cpp
index 1c4321d37e..ed95884a6c 100644
--- a/effects/magiclamp/magiclamp.cpp
+++ b/effects/magiclamp/magiclamp.cpp
@@ -24,18 +24,12 @@ along with this program. If not, see .
// KConfigSkeleton
#include "magiclampconfig.h"
-#include
-#include
-#include
-#include
-
namespace KWin
{
MagicLampEffect::MagicLampEffect()
{
initConfig();
- mActiveAnimations = 0;
reconfigure(ReconfigureAll);
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
connect(effects, SIGNAL(windowMinimized(KWin::EffectWindow*)), this, SLOT(slotWindowMinimized(KWin::EffectWindow*)));
@@ -50,36 +44,28 @@ bool MagicLampEffect::supported()
void MagicLampEffect::reconfigure(ReconfigureFlags)
{
MagicLampConfig::self()->read();
- // TODO: rename animationDuration to duration
- mAnimationDuration = animationTime(MagicLampConfig::animationDuration() != 0 ? MagicLampConfig::animationDuration() : 250);
+
+ // TODO: Rename animationDuration to duration so we can use
+ // animationTime(250).
+ const int d = MagicLampConfig::animationDuration() != 0
+ ? MagicLampConfig::animationDuration()
+ : 250;
+ m_duration = std::chrono::milliseconds(static_cast(animationTime(d)));
}
void MagicLampEffect::prePaintScreen(ScreenPrePaintData& data, int time)
{
+ const std::chrono::milliseconds delta(time);
- QHash< EffectWindow*, QTimeLine* >::iterator entry = mTimeLineWindows.begin();
- bool erase = false;
- while (entry != mTimeLineWindows.end()) {
- QTimeLine *timeline = entry.value();
- if (entry.key()->isMinimized()) {
- timeline->setCurrentTime(timeline->currentTime() + time);
- erase = (timeline->currentValue() >= 1.0f);
- } else {
- timeline->setCurrentTime(timeline->currentTime() - time);
- erase = (timeline->currentValue() <= 0.0f);
- }
- if (erase) {
- delete timeline;
- entry = mTimeLineWindows.erase(entry);
- } else
- ++entry;
+ auto animationIt = m_animations.begin();
+ while (animationIt != m_animations.end()) {
+ (*animationIt).update(delta);
+ ++animationIt;
}
- mActiveAnimations = mTimeLineWindows.count();
- if (mActiveAnimations > 0)
- // We need to mark the screen windows as transformed. Otherwise the
- // whole screen won't be repainted, resulting in artefacts
- data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
+ // We need to mark the screen windows as transformed. Otherwise the
+ // whole screen won't be repainted, resulting in artefacts.
+ data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
effects->prePaintScreen(data, time);
}
@@ -88,7 +74,7 @@ void MagicLampEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data,
{
// Schedule window for transformation if the animation is still in
// progress
- if (mTimeLineWindows.contains(w)) {
+ if (m_animations.contains(w)) {
// We'll transform this window
data.setTransformed();
data.quads = data.quads.makeGrid(40);
@@ -100,9 +86,10 @@ void MagicLampEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data,
void MagicLampEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
- if (mTimeLineWindows.contains(w)) {
+ auto animationIt = m_animations.constFind(w);
+ if (animationIt != m_animations.constEnd()) {
// 0 = not minimized, 1 = fully minimized
- float progress = mTimeLineWindows[w]->currentValue();
+ const qreal progress = (*animationIt).value();
QRect geo = w->geometry();
QRect icon = w->iconGeometry();
@@ -322,10 +309,16 @@ void MagicLampEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Win
void MagicLampEffect::postPaintScreen()
{
- if (mActiveAnimations > 0)
- // Repaint the workspace so that everything would be repainted next time
- effects->addRepaintFull();
- mActiveAnimations = mTimeLineWindows.count();
+ auto animationIt = m_animations.begin();
+ while (animationIt != m_animations.end()) {
+ if ((*animationIt).done()) {
+ animationIt = m_animations.erase(animationIt);
+ } else {
+ ++animationIt;
+ }
+ }
+
+ effects->addRepaintFull();
// Call the next effect.
effects->postPaintScreen();
@@ -333,34 +326,48 @@ void MagicLampEffect::postPaintScreen()
void MagicLampEffect::slotWindowDeleted(EffectWindow* w)
{
- delete mTimeLineWindows.take(w);
+ m_animations.remove(w);
}
void MagicLampEffect::slotWindowMinimized(EffectWindow* w)
{
if (effects->activeFullScreenEffect())
return;
- if (!mTimeLineWindows.contains(w)) {
- mTimeLineWindows.insert(w, new QTimeLine(mAnimationDuration, this));
- mTimeLineWindows[w]->setCurrentTime(0);
- mTimeLineWindows[w]->setCurveShape(QTimeLine::LinearCurve);
+
+ TimeLine &timeLine = m_animations[w];
+
+ if (timeLine.running()) {
+ timeLine.toggleDirection();
+ } else {
+ timeLine.setDirection(TimeLine::Forward);
+ timeLine.setDuration(m_duration);
+ timeLine.setEasingCurve(QEasingCurve::Linear);
}
+
+ effects->addRepaintFull();
}
void MagicLampEffect::slotWindowUnminimized(EffectWindow* w)
{
if (effects->activeFullScreenEffect())
return;
- if (!mTimeLineWindows.contains(w)) {
- mTimeLineWindows.insert(w, new QTimeLine(mAnimationDuration, this));
- mTimeLineWindows[w]->setCurrentTime(mAnimationDuration);
- mTimeLineWindows[w]->setCurveShape(QTimeLine::LinearCurve);
+
+ TimeLine &timeLine = m_animations[w];
+
+ if (timeLine.running()) {
+ timeLine.toggleDirection();
+ } else {
+ timeLine.setDirection(TimeLine::Backward);
+ timeLine.setDuration(m_duration);
+ timeLine.setEasingCurve(QEasingCurve::Linear);
}
+
+ effects->addRepaintFull();
}
bool MagicLampEffect::isActive() const
{
- return !mTimeLineWindows.isEmpty();
+ return !m_animations.isEmpty();
}
} // namespace
diff --git a/effects/magiclamp/magiclamp.h b/effects/magiclamp/magiclamp.h
index 95865d4c19..0bd900b2cf 100644
--- a/effects/magiclamp/magiclamp.h
+++ b/effects/magiclamp/magiclamp.h
@@ -23,8 +23,6 @@ along with this program. If not, see .
#include
-class QTimeLine;
-
namespace KWin
{
@@ -32,7 +30,7 @@ class MagicLampEffect
: public Effect
{
Q_OBJECT
- Q_PROPERTY(int animationDuration READ animationDuration)
+
public:
MagicLampEffect();
@@ -49,19 +47,14 @@ public:
static bool supported();
- // for properties
- int animationDuration() const {
- return mAnimationDuration;
- }
public Q_SLOTS:
void slotWindowDeleted(KWin::EffectWindow *w);
void slotWindowMinimized(KWin::EffectWindow *w);
void slotWindowUnminimized(KWin::EffectWindow *w);
private:
- QHash< EffectWindow*, QTimeLine* > mTimeLineWindows;
- int mActiveAnimations;
- int mAnimationDuration;
+ std::chrono::milliseconds m_duration;
+ QHash m_animations;
enum IconPosition {
Top,