2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "minimizeanimation.h"
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QTimeLine>
|
2012-05-28 10:00:31 +00:00
|
|
|
#include <QtGui/QVector2D>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
MinimizeAnimationEffect::MinimizeAnimationEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
mActiveAnimations = 0;
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowMinimized(KWin::EffectWindow*)), this, SLOT(slotWindowMinimized(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowUnminimized(KWin::EffectWindow*)), this, SLOT(slotWindowUnminimized(KWin::EffectWindow*)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2017-11-23 09:34:06 +00:00
|
|
|
bool MinimizeAnimationEffect::supported()
|
|
|
|
{
|
|
|
|
return effects->animationsSupported();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void MinimizeAnimationEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-03-14 21:50:05 +00:00
|
|
|
QHash< EffectWindow*, QTimeLine* >::iterator entry = mTimeLineWindows.begin();
|
2009-11-25 16:29:18 +00:00
|
|
|
bool erase = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
while (entry != mTimeLineWindows.end()) {
|
2011-03-14 21:50:05 +00:00
|
|
|
QTimeLine *timeline = entry.value();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (entry.key()->isMinimized()) {
|
2011-03-14 21:50:05 +00:00
|
|
|
timeline->setCurrentTime(timeline->currentTime() + time);
|
|
|
|
erase = (timeline->currentValue() >= 1.0f);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-03-14 21:50:05 +00:00
|
|
|
timeline->setCurrentTime(timeline->currentTime() - time);
|
|
|
|
erase = (timeline->currentValue() <= 0.0f);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-03-14 21:50:05 +00:00
|
|
|
if (erase) {
|
|
|
|
delete timeline;
|
2011-01-30 14:34:42 +00:00
|
|
|
entry = mTimeLineWindows.erase(entry);
|
2011-03-14 21:50:05 +00:00
|
|
|
} else
|
2009-11-25 16:29:18 +00:00
|
|
|
++entry;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-11-25 17:48:01 +00:00
|
|
|
mActiveAnimations = mTimeLineWindows.count();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mActiveAnimations > 0)
|
2009-11-25 17:48:01 +00:00
|
|
|
// 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;
|
|
|
|
|
2009-11-25 16:29:18 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-25 16:29:18 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void MinimizeAnimationEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
2009-11-25 16:29:18 +00:00
|
|
|
// Schedule window for transformation if the animation is still in
|
|
|
|
// progress
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mTimeLineWindows.contains(w)) {
|
2009-11-25 16:29:18 +00:00
|
|
|
// We'll transform this window
|
|
|
|
data.setTransformed();
|
2011-01-30 14:34:42 +00:00
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_MINIMIZE);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2011-03-14 21:50:05 +00:00
|
|
|
QHash< EffectWindow*, QTimeLine* >::const_iterator entry = mTimeLineWindows.constFind(w);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (entry != mTimeLineWindows.constEnd()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
// 0 = not minimized, 1 = fully minimized
|
2011-03-14 21:50:05 +00:00
|
|
|
double progress = entry.value()->currentValue();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QRect geo = w->geometry();
|
|
|
|
QRect icon = w->iconGeometry();
|
|
|
|
// If there's no icon geometry, minimize to the center of the screen
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!icon.isValid())
|
2014-02-24 15:13:30 +00:00
|
|
|
icon = QRect(effects->virtualScreenGeometry().center(), QSize(0, 0));
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-05-28 10:00:31 +00:00
|
|
|
data *= QVector2D(interpolate(1.0, icon.width() / (double)geo.width(), progress),
|
|
|
|
interpolate(1.0, icon.height() / (double)geo.height(), progress));
|
2012-05-28 12:45:46 +00:00
|
|
|
data.setXTranslation((int)interpolate(data.xTranslation(), icon.x() - geo.x(), progress));
|
|
|
|
data.setYTranslation((int)interpolate(data.yTranslation(), icon.y() - geo.y(), progress));
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity(0.1 + (1 - progress) * 0.9);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call the next effect.
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void MinimizeAnimationEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (mActiveAnimations > 0)
|
2007-04-29 17:35:43 +00:00
|
|
|
// Repaint the workspace so that everything would be repainted next time
|
|
|
|
effects->addRepaintFull();
|
2008-04-19 00:12:28 +00:00
|
|
|
mActiveAnimations = mTimeLineWindows.count();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-27 09:47:42 +00:00
|
|
|
void MinimizeAnimationEffect::slotWindowDeleted(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-14 21:50:05 +00:00
|
|
|
delete mTimeLineWindows.take(w);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-25 16:29:18 +00:00
|
|
|
|
2011-03-06 09:55:27 +00:00
|
|
|
void MinimizeAnimationEffect::slotWindowMinimized(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (effects->activeFullScreenEffect())
|
2011-01-01 18:56:12 +00:00
|
|
|
return;
|
2011-03-14 21:50:05 +00:00
|
|
|
QTimeLine *timeline;
|
|
|
|
if (mTimeLineWindows.contains(w)) {
|
|
|
|
timeline = mTimeLineWindows[w];
|
|
|
|
} else {
|
|
|
|
timeline = new QTimeLine(animationTime(250), this);
|
|
|
|
mTimeLineWindows.insert(w, timeline);
|
|
|
|
}
|
|
|
|
timeline->setCurveShape(QTimeLine::EaseInCurve);
|
|
|
|
timeline->setCurrentTime(0.0);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-03-06 10:08:19 +00:00
|
|
|
void MinimizeAnimationEffect::slotWindowUnminimized(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (effects->activeFullScreenEffect())
|
2011-01-01 18:56:12 +00:00
|
|
|
return;
|
2011-03-14 21:50:05 +00:00
|
|
|
QTimeLine *timeline;
|
|
|
|
if (mTimeLineWindows.contains(w)) {
|
|
|
|
timeline = mTimeLineWindows[w];
|
|
|
|
} else {
|
|
|
|
timeline = new QTimeLine(animationTime(250), this);
|
|
|
|
mTimeLineWindows.insert(w, timeline);
|
|
|
|
}
|
|
|
|
timeline->setCurveShape(QTimeLine::EaseInOutCurve);
|
|
|
|
timeline->setCurrentTime(timeline->duration());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool MinimizeAnimationEffect::isActive() const
|
|
|
|
{
|
|
|
|
return !mTimeLineWindows.isEmpty();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|