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
|
|
|
|
{
|
|
|
|
|
|
|
|
SheetEffect::SheetEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<SheetConfig>();
|
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
|
|
|
{
|
2016-08-10 07:24:53 +00:00
|
|
|
return effects->isOpenGLCompositing() && effects->animationsSupported();
|
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)
|
|
|
|
{
|
2014-03-25 15:29:03 +00:00
|
|
|
SheetConfig::self()->read();
|
2013-03-01 10:00:11 +00:00
|
|
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 13:44:31 +00:00
|
|
|
|
|
|
|
w->setData(WindowAddedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
|
|
|
|
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;
|
2018-08-02 13:44:31 +00:00
|
|
|
|
|
|
|
w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
|
|
|
|
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)
|
|
|
|
{
|
[effects/sheet] Drop IsSheetWindow hack
Summary:
When the Sheet effect was written, isModal worked only for Client
windows, not Deleted windows:
bool EffectWindowImpl::isModal() const
{
if( Client* c = dynamic_cast< Client* >( toplevel ))
return c->isModal();
return false;
}
so the Sheet effect had to track windows by using WindowInfo class, e.g.
class WindowInfo
{
public:
bool deleted;
bool added;
bool closed;
};
the biggest drawback of that method is that WindowInfo for each modal kept around
as long as those modals existed. It also was adding little overhead, e.g.
void SheetEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
{
if( windows.contains( w ) && ( windows[ w ].added || windows[ w ].closed ) )
Things changed with a8160b3c31afa1db24084147ad4ce50cf3c0314a. With that
commit, WindowInfo kept only for modals that are currently being
animated, but isModal still worked only with Client windows, so
IsSheetWindow hack had been introduced.
Long story short: we don't need IsSheetWindow hack anymore because
isModal now works with Deleted windows.
Test Plan: Pressed Ctrl+O in Kate.
Reviewers: #kwin, graesslin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14246
2018-07-20 08:17:49 +00:00
|
|
|
return w->isModal();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
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
|