2009-02-17 21:13:00 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Philip Falkner <philip.falkner@gmail.com>
|
2013-03-12 12:17:53 +00:00
|
|
|
Copyright (C) 2009 Martin Gräßlin <mgraesslin@kde.org>
|
2009-02-17 21:13:00 +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.
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "sheet.h"
|
2013-03-01 10:00:11 +00:00
|
|
|
#include "sheetconfig.h"
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QTimeLine>
|
2013-02-26 07:02:27 +00:00
|
|
|
#include <QGraphicsRotation>
|
|
|
|
#include <QVector3D>
|
2009-02-17 21:13:00 +00:00
|
|
|
|
|
|
|
// Effect is based on fade effect by Philip Falkner
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2010-11-02 20:35:28 +00:00
|
|
|
static const int IsSheetWindow = 0x22A982D5;
|
|
|
|
|
2009-02-17 21:13:00 +00:00
|
|
|
SheetEffect::SheetEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
reconfigure(ReconfigureAll);
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
|
|
|
bool SheetEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-09-20 09:33:32 +00:00
|
|
|
return effects->isOpenGLCompositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SheetEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2013-03-01 10:00:11 +00:00
|
|
|
SheetConfig::self()->readConfig();
|
|
|
|
duration = animationTime(SheetConfig::animationTime() != 0 ? SheetConfig::animationTime() : 500);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SheetEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (!windows.isEmpty()) {
|
2009-02-17 21:13:00 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
screenTime = time;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SheetEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
InfoMap::iterator info = windows.find(w);
|
|
|
|
if (info != windows.end()) {
|
2010-11-02 20:35:28 +00:00
|
|
|
data.setTransformed();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->added)
|
2011-03-14 21:50:05 +00:00
|
|
|
info->timeLine->setCurrentTime(info->timeLine->currentTime() + screenTime);
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (info->closed) {
|
2011-03-14 21:50:05 +00:00
|
|
|
info->timeLine->setCurrentTime(info->timeLine->currentTime() - screenTime);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->deleted)
|
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
|
2010-11-02 20:35:28 +00:00
|
|
|
// if the window isn't to be painted, then let's make sure
|
|
|
|
// to track its progress
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info != windows.end() && !w->isPaintingEnabled() && !effects->activeFullScreenEffect())
|
2010-11-02 20:35:28 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SheetEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
InfoMap::const_iterator info = windows.constFind(w);
|
|
|
|
if (info != windows.constEnd()) {
|
2011-03-14 21:50:05 +00:00
|
|
|
const double progress = info->timeLine->currentValue();
|
2012-05-27 17:28:02 +00:00
|
|
|
QGraphicsRotation rot;
|
2012-06-02 19:54:18 +00:00
|
|
|
data.setRotationAxis(Qt::XAxis);
|
|
|
|
data.setRotationAngle(60.0 * (1.0 - progress));
|
2012-05-28 10:00:31 +00:00
|
|
|
data *= QVector3D(1.0, progress, progress);
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(0.0, - (w->y() - info->parentY) * (1.0 - progress));
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SheetEffect::postPaintWindow(EffectWindow* w)
|
|
|
|
{
|
|
|
|
InfoMap::iterator info = windows.find(w);
|
|
|
|
if (info != windows.end()) {
|
2011-03-14 21:50:05 +00:00
|
|
|
if (info->added && info->timeLine->currentValue() == 1.0) {
|
2011-01-30 14:34:42 +00:00
|
|
|
windows.remove(w);
|
2009-02-17 21:13:00 +00:00
|
|
|
effects->addRepaintFull();
|
2011-03-14 21:50:05 +00:00
|
|
|
} else if (info->closed && info->timeLine->currentValue() == 0.0) {
|
2010-11-02 20:35:28 +00:00
|
|
|
info->closed = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->deleted) {
|
|
|
|
windows.remove(w);
|
2009-02-17 21:13:00 +00:00
|
|
|
w->unrefWindow();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->added || info->closed)
|
|
|
|
w->addRepaintFull();
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintWindow(w);
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void SheetEffect::slotWindowAdded(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!isSheetWindow(w))
|
2009-02-17 21:13:00 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
w->setData(IsSheetWindow, true);
|
|
|
|
|
|
|
|
InfoMap::iterator it = windows.find(w);
|
|
|
|
WindowInfo *info = (it == windows.end()) ? &windows[w] : &it.value();
|
2010-11-02 20:35:28 +00:00
|
|
|
info->added = true;
|
|
|
|
info->closed = false;
|
|
|
|
info->deleted = false;
|
2011-03-14 21:50:05 +00:00
|
|
|
delete info->timeLine;
|
|
|
|
info->timeLine = new QTimeLine(duration);
|
2010-11-02 20:35:28 +00:00
|
|
|
const EffectWindowList stack = effects->stackingOrder();
|
2009-02-17 21:13:00 +00:00
|
|
|
// find parent
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (EffectWindow * window, stack) {
|
|
|
|
if (window->findModal() == w) {
|
2010-11-02 20:35:28 +00:00
|
|
|
info->parentY = window->y();
|
2009-02-17 21:13:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void SheetEffect::slotWindowClosed(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!isSheetWindow(w))
|
2009-02-17 21:13:00 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2010-11-02 20:35:28 +00:00
|
|
|
w->refWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
InfoMap::iterator it = windows.find(w);
|
|
|
|
WindowInfo *info = (it == windows.end()) ? &windows[w] : &it.value();
|
2010-11-02 20:35:28 +00:00
|
|
|
info->added = false;
|
|
|
|
info->closed = true;
|
|
|
|
info->deleted = true;
|
2011-03-14 21:50:05 +00:00
|
|
|
delete info->timeLine;
|
|
|
|
info->timeLine = new QTimeLine(duration);
|
|
|
|
info->timeLine->setCurrentTime(duration);
|
2010-11-02 20:35:28 +00:00
|
|
|
|
2009-02-17 21:13:00 +00:00
|
|
|
bool found = false;
|
|
|
|
// find parent
|
2010-11-02 20:35:28 +00:00
|
|
|
const EffectWindowList stack = effects->stackingOrder();
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (EffectWindow * window, stack) {
|
|
|
|
if (window->findModal() == w) {
|
2010-11-02 20:35:28 +00:00
|
|
|
info->parentY = window->y();
|
2009-02-17 21:13:00 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (!found)
|
2010-11-02 20:35:28 +00:00
|
|
|
info->parentY = 0;
|
2009-02-17 21:13:00 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-02-27 09:47:42 +00:00
|
|
|
void SheetEffect::slotWindowDeleted(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
windows.remove(w);
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool SheetEffect::isSheetWindow(EffectWindow* w)
|
|
|
|
{
|
|
|
|
return (w->isModal() || w->data(IsSheetWindow).toBool());
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool SheetEffect::isActive() const
|
|
|
|
{
|
|
|
|
return !windows.isEmpty();
|
|
|
|
}
|
|
|
|
|
2011-03-14 21:50:05 +00:00
|
|
|
SheetEffect::WindowInfo::WindowInfo()
|
|
|
|
: deleted(false)
|
|
|
|
, added(false)
|
|
|
|
, closed(false)
|
|
|
|
, timeLine(0)
|
|
|
|
, parentY(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SheetEffect::WindowInfo::~WindowInfo()
|
|
|
|
{
|
|
|
|
delete timeLine;
|
|
|
|
}
|
|
|
|
|
2009-02-17 21:13:00 +00:00
|
|
|
} // namespace
|