|
|
|
|
@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
*********************************************************************/ |
|
|
|
|
|
|
|
|
|
#include "minimizeanimation.h" |
|
|
|
|
#include <QTimeLine> |
|
|
|
|
|
|
|
|
|
#include <QVector2D> |
|
|
|
|
|
|
|
|
|
namespace KWin |
|
|
|
|
@ -27,12 +27,20 @@ namespace KWin |
|
|
|
|
|
|
|
|
|
MinimizeAnimationEffect::MinimizeAnimationEffect() |
|
|
|
|
{ |
|
|
|
|
mActiveAnimations = 0; |
|
|
|
|
reconfigure(ReconfigureAll); |
|
|
|
|
|
|
|
|
|
connect(effects, &EffectsHandler::windowDeleted, this, &MinimizeAnimationEffect::windowDeleted); |
|
|
|
|
connect(effects, &EffectsHandler::windowMinimized, this, &MinimizeAnimationEffect::windowMinimized); |
|
|
|
|
connect(effects, &EffectsHandler::windowUnminimized, this, &MinimizeAnimationEffect::windowUnminimized); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::reconfigure(ReconfigureFlags flags) |
|
|
|
|
{ |
|
|
|
|
Q_UNUSED(flags) |
|
|
|
|
|
|
|
|
|
m_duration = std::chrono::milliseconds(static_cast<int>(animationTime(250))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool MinimizeAnimationEffect::supported() |
|
|
|
|
{ |
|
|
|
|
return effects->animationsSupported(); |
|
|
|
|
@ -40,30 +48,17 @@ bool MinimizeAnimationEffect::supported() |
|
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::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); |
|
|
|
|
} |
|
|
|
|
@ -72,7 +67,7 @@ void MinimizeAnimationEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData |
|
|
|
|
{ |
|
|
|
|
// 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(); |
|
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_MINIMIZE); |
|
|
|
|
@ -83,10 +78,10 @@ void MinimizeAnimationEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData |
|
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) |
|
|
|
|
{ |
|
|
|
|
QHash< EffectWindow*, QTimeLine* >::const_iterator entry = mTimeLineWindows.constFind(w); |
|
|
|
|
if (entry != mTimeLineWindows.constEnd()) { |
|
|
|
|
const auto animationIt = m_animations.constFind(w); |
|
|
|
|
if (animationIt != m_animations.constEnd()) { |
|
|
|
|
// 0 = not minimized, 1 = fully minimized
|
|
|
|
|
double progress = entry.value()->currentValue(); |
|
|
|
|
const qreal progress = (*animationIt).value(); |
|
|
|
|
|
|
|
|
|
QRect geo = w->geometry(); |
|
|
|
|
QRect icon = w->iconGeometry(); |
|
|
|
|
@ -107,10 +102,16 @@ void MinimizeAnimationEffect::paintWindow(EffectWindow* w, int mask, QRegion reg |
|
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::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(); |
|
|
|
|
@ -118,7 +119,7 @@ void MinimizeAnimationEffect::postPaintScreen() |
|
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::windowDeleted(EffectWindow *w) |
|
|
|
|
{ |
|
|
|
|
delete mTimeLineWindows.take(w); |
|
|
|
|
m_animations.remove(w); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::windowMinimized(EffectWindow *w) |
|
|
|
|
@ -126,12 +127,17 @@ void MinimizeAnimationEffect::windowMinimized(EffectWindow *w) |
|
|
|
|
if (effects->activeFullScreenEffect()) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (!mTimeLineWindows.contains(w)) { |
|
|
|
|
auto *timeline = new QTimeLine(animationTime(250), this); |
|
|
|
|
timeline->setCurrentTime(0); |
|
|
|
|
timeline->setCurveShape(QTimeLine::EaseInOutCurve); |
|
|
|
|
mTimeLineWindows.insert(w, timeline); |
|
|
|
|
TimeLine &timeLine = m_animations[w]; |
|
|
|
|
|
|
|
|
|
if (timeLine.running()) { |
|
|
|
|
timeLine.toggleDirection(); |
|
|
|
|
} else { |
|
|
|
|
timeLine.setDirection(TimeLine::Forward); |
|
|
|
|
timeLine.setDuration(m_duration); |
|
|
|
|
timeLine.setEasingCurve(QEasingCurve::InOutSine); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
effects->addRepaintFull(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::windowUnminimized(EffectWindow *w) |
|
|
|
|
@ -139,17 +145,22 @@ void MinimizeAnimationEffect::windowUnminimized(EffectWindow *w) |
|
|
|
|
if (effects->activeFullScreenEffect()) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (!mTimeLineWindows.contains(w)) { |
|
|
|
|
auto *timeline = new QTimeLine(animationTime(250), this); |
|
|
|
|
timeline->setCurrentTime(timeline->duration()); |
|
|
|
|
timeline->setCurveShape(QTimeLine::EaseInOutCurve); |
|
|
|
|
mTimeLineWindows.insert(w, timeline); |
|
|
|
|
TimeLine &timeLine = m_animations[w]; |
|
|
|
|
|
|
|
|
|
if (timeLine.running()) { |
|
|
|
|
timeLine.toggleDirection(); |
|
|
|
|
} else { |
|
|
|
|
timeLine.setDirection(TimeLine::Backward); |
|
|
|
|
timeLine.setDuration(m_duration); |
|
|
|
|
timeLine.setEasingCurve(QEasingCurve::InOutSine); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
effects->addRepaintFull(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool MinimizeAnimationEffect::isActive() const |
|
|
|
|
{ |
|
|
|
|
return !mTimeLineWindows.isEmpty(); |
|
|
|
|
return !m_animations.isEmpty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|