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>
|
2020-01-14 16:17:18 +00:00
|
|
|
Copyright (C) 2018 Vlad Zahorodnii <vlad.zahorodnii@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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
// own
|
2009-02-17 21:13:00 +00:00
|
|
|
#include "sheet.h"
|
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "sheetconfig.h"
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
// Qt
|
|
|
|
#include <QMatrix4x4>
|
2009-02-17 21:13:00 +00:00
|
|
|
|
|
|
|
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);
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
connect(effects, &EffectsHandler::windowAdded, this, &SheetEffect::slotWindowAdded);
|
|
|
|
connect(effects, &EffectsHandler::windowClosed, this, &SheetEffect::slotWindowClosed);
|
|
|
|
connect(effects, &EffectsHandler::windowDeleted, this, &SheetEffect::slotWindowDeleted);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
void SheetEffect::reconfigure(ReconfigureFlags flags)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-08 09:00:24 +00:00
|
|
|
Q_UNUSED(flags)
|
|
|
|
|
2014-03-25 15:29:03 +00:00
|
|
|
SheetConfig::self()->read();
|
2018-08-08 09:00:24 +00:00
|
|
|
|
|
|
|
// TODO: Rename AnimationTime config key to Duration.
|
|
|
|
const int d = animationTime(SheetConfig::animationTime() != 0
|
|
|
|
? SheetConfig::animationTime()
|
2018-10-21 16:46:51 +00:00
|
|
|
: 300);
|
2018-08-08 09:00:24 +00:00
|
|
|
m_duration = std::chrono::milliseconds(static_cast<int>(d));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
void SheetEffect::prePaintScreen(ScreenPrePaintData &data, int time)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-08 09:00:24 +00:00
|
|
|
const std::chrono::milliseconds delta(time);
|
|
|
|
|
|
|
|
auto animationIt = m_animations.begin();
|
|
|
|
while (animationIt != m_animations.end()) {
|
|
|
|
(*animationIt).timeLine.update(delta);
|
|
|
|
++animationIt;
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
2018-08-08 09:00:24 +00:00
|
|
|
|
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
void SheetEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-08 09:00:24 +00:00
|
|
|
if (m_animations.contains(w)) {
|
2010-11-02 20:35:28 +00:00
|
|
|
data.setTransformed();
|
2018-08-08 09:00:24 +00:00
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
void SheetEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-08 09:00:24 +00:00
|
|
|
auto animationIt = m_animations.constFind(w);
|
|
|
|
if (animationIt == m_animations.constEnd()) {
|
[effects/sheet] Fix undesired perspective distortion
Summary:
If a modal window is near some of screen edges, it will be distorted
in undesired way when it's being animated.
In order to keep perspective distortions invariant, no matter where
the modal window is on the screen, we have to move that modal window
to the origin, scale it, rotate it, translate it, apply perspective projection,
and then move it back.
Test Plan:
* Opened Kate
* Opened "Open File" dialog (during the in animation, it was distorted as expected)
* Closed that dialog (during the out animation, it was distorted as expected)
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14687
2018-08-08 09:46:21 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
return;
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
[effects/sheet] Fix undesired perspective distortion
Summary:
If a modal window is near some of screen edges, it will be distorted
in undesired way when it's being animated.
In order to keep perspective distortions invariant, no matter where
the modal window is on the screen, we have to move that modal window
to the origin, scale it, rotate it, translate it, apply perspective projection,
and then move it back.
Test Plan:
* Opened Kate
* Opened "Open File" dialog (during the in animation, it was distorted as expected)
* Closed that dialog (during the out animation, it was distorted as expected)
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14687
2018-08-08 09:46:21 +00:00
|
|
|
|
|
|
|
// Perspective projection distorts objects near edges of the viewport
|
|
|
|
// in undesired way. To fix this, the center of the window will be
|
|
|
|
// moved to the origin, after applying perspective projection, the
|
|
|
|
// center is moved back to its "original" projected position. Overall,
|
|
|
|
// this is how the window will be transformed:
|
|
|
|
// [move to the origin] -> [scale] -> [rotate] -> [translate] ->
|
|
|
|
// -> [perspective projection] -> [reverse "move to the origin"]
|
|
|
|
const QMatrix4x4 oldProjMatrix = data.screenProjectionMatrix();
|
|
|
|
const QRectF windowGeo = w->geometry();
|
|
|
|
const QVector3D invOffset = oldProjMatrix.map(QVector3D(windowGeo.center()));
|
|
|
|
QMatrix4x4 invOffsetMatrix;
|
|
|
|
invOffsetMatrix.translate(invOffset.x(), invOffset.y());
|
|
|
|
data.setProjectionMatrix(invOffsetMatrix * oldProjMatrix);
|
|
|
|
|
|
|
|
// Move the center of the window to the origin.
|
|
|
|
const QRectF screenGeo = effects->virtualScreenGeometry();
|
|
|
|
const QPointF offset = screenGeo.center() - windowGeo.center();
|
|
|
|
data.translate(offset.x(), offset.y());
|
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
const qreal t = (*animationIt).timeLine.value();
|
[effects/sheet] Fix undesired perspective distortion
Summary:
If a modal window is near some of screen edges, it will be distorted
in undesired way when it's being animated.
In order to keep perspective distortions invariant, no matter where
the modal window is on the screen, we have to move that modal window
to the origin, scale it, rotate it, translate it, apply perspective projection,
and then move it back.
Test Plan:
* Opened Kate
* Opened "Open File" dialog (during the in animation, it was distorted as expected)
* Closed that dialog (during the out animation, it was distorted as expected)
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14687
2018-08-08 09:46:21 +00:00
|
|
|
data.setRotationAxis(Qt::XAxis);
|
2018-08-08 09:00:24 +00:00
|
|
|
data.setRotationAngle(interpolate(60.0, 0.0, t));
|
|
|
|
data *= QVector3D(1.0, t, t);
|
|
|
|
data.translate(0.0, -interpolate(w->y() - (*animationIt).parentY, 0.0, t));
|
[effects/sheet] Fix undesired perspective distortion
Summary:
If a modal window is near some of screen edges, it will be distorted
in undesired way when it's being animated.
In order to keep perspective distortions invariant, no matter where
the modal window is on the screen, we have to move that modal window
to the origin, scale it, rotate it, translate it, apply perspective projection,
and then move it back.
Test Plan:
* Opened Kate
* Opened "Open File" dialog (during the in animation, it was distorted as expected)
* Closed that dialog (during the out animation, it was distorted as expected)
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14687
2018-08-08 09:46:21 +00:00
|
|
|
|
2018-10-21 16:46:51 +00:00
|
|
|
data.multiplyOpacity(t);
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
void SheetEffect::postPaintWindow(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-08 09:00:24 +00:00
|
|
|
auto animationIt = m_animations.begin();
|
|
|
|
while (animationIt != m_animations.end()) {
|
|
|
|
EffectWindow *w = animationIt.key();
|
|
|
|
w->addRepaintFull();
|
|
|
|
if ((*animationIt).timeLine.done()) {
|
|
|
|
if (w->isDeleted()) {
|
2009-02-17 21:13:00 +00:00
|
|
|
w->unrefWindow();
|
|
|
|
}
|
2018-08-08 09:00:24 +00:00
|
|
|
animationIt = m_animations.erase(animationIt);
|
|
|
|
} else {
|
|
|
|
++animationIt;
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 09:00:24 +00:00
|
|
|
|
|
|
|
if (m_animations.isEmpty()) {
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintWindow(w);
|
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
bool SheetEffect::isActive() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-08 09:00:24 +00:00
|
|
|
return !m_animations.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SheetEffect::supported()
|
|
|
|
{
|
|
|
|
return effects->isOpenGLCompositing()
|
|
|
|
&& effects->animationsSupported();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::slotWindowAdded(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (effects->activeFullScreenEffect()) {
|
2009-02-17 21:13:00 +00:00
|
|
|
return;
|
2018-08-08 09:00:24 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
if (!isSheetWindow(w)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Animation &animation = m_animations[w];
|
|
|
|
animation.parentY = 0;
|
|
|
|
animation.timeLine.reset();
|
|
|
|
animation.timeLine.setDuration(m_duration);
|
|
|
|
animation.timeLine.setDirection(TimeLine::Forward);
|
|
|
|
animation.timeLine.setEasingCurve(QEasingCurve::Linear);
|
|
|
|
|
|
|
|
const auto windows = effects->stackingOrder();
|
|
|
|
auto parentIt = std::find_if(windows.constBegin(), windows.constEnd(),
|
|
|
|
[w](EffectWindow *p) {
|
|
|
|
return p->findModal() == w;
|
|
|
|
});
|
|
|
|
if (parentIt != windows.constEnd()) {
|
|
|
|
animation.parentY = (*parentIt)->y();
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
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
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
void SheetEffect::slotWindowClosed(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-08 09:00:24 +00:00
|
|
|
if (effects->activeFullScreenEffect()) {
|
2009-02-17 21:13:00 +00:00
|
|
|
return;
|
2018-08-08 09:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isSheetWindow(w)) {
|
|
|
|
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
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
Animation &animation = m_animations[w];
|
|
|
|
|
|
|
|
animation.timeLine.reset();
|
|
|
|
animation.parentY = 0;
|
|
|
|
animation.timeLine.setDuration(m_duration);
|
|
|
|
animation.timeLine.setDirection(TimeLine::Backward);
|
|
|
|
animation.timeLine.setEasingCurve(QEasingCurve::Linear);
|
|
|
|
|
|
|
|
const auto windows = effects->stackingOrder();
|
|
|
|
auto parentIt = std::find_if(windows.constBegin(), windows.constEnd(),
|
|
|
|
[w](EffectWindow *p) {
|
|
|
|
return p->findModal() == w;
|
|
|
|
});
|
|
|
|
if (parentIt != windows.constEnd()) {
|
|
|
|
animation.parentY = (*parentIt)->y();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
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
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
void SheetEffect::slotWindowDeleted(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-08 09:00:24 +00:00
|
|
|
m_animations.remove(w);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-17 21:13:00 +00:00
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
bool SheetEffect::isSheetWindow(EffectWindow *w) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
[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
|
|
|
|
2018-08-08 09:00:24 +00:00
|
|
|
} // namespace KWin
|