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) 2006 Lubos Lunak <l.lunak@kde.org>
|
2009-02-21 04:53:13 +00:00
|
|
|
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
|
2019-09-29 14:03:25 +00:00
|
|
|
Copyright (C) 2018 Vlad Zahorodnii <vladzzag@gmail.com>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
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.
|
|
|
|
|
|
|
|
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 "kwineffects.h"
|
|
|
|
|
2012-03-16 07:37:09 +00:00
|
|
|
#include "config-kwin.h"
|
2014-03-16 14:31:23 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
#include "kwinxrenderutils.h"
|
|
|
|
#endif
|
2007-09-02 18:20:36 +00:00
|
|
|
|
2007-05-29 11:46:12 +00:00
|
|
|
#include <QVariant>
|
|
|
|
#include <QList>
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QTimeLine>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QFontMetrics>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QVector2D>
|
2013-02-26 07:02:27 +00:00
|
|
|
#include <QGraphicsRotation>
|
|
|
|
#include <QGraphicsScale>
|
2019-07-09 19:19:26 +00:00
|
|
|
#include <QtMath>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-05-29 11:46:12 +00:00
|
|
|
#include <ksharedconfig.h>
|
2007-10-05 22:21:25 +00:00
|
|
|
#include <kconfiggroup.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2015-08-31 13:47:01 +00:00
|
|
|
#include <KWayland/Server/surface_interface.h>
|
|
|
|
|
2008-01-03 15:22:19 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2013-02-06 06:58:33 +00:00
|
|
|
#include <xcb/xfixes.h>
|
2008-03-03 21:12:48 +00:00
|
|
|
#endif
|
2007-09-02 18:20:36 +00:00
|
|
|
|
2019-08-14 07:31:16 +00:00
|
|
|
#if defined(__SSE2__)
|
2013-03-19 15:59:43 +00:00
|
|
|
# include <emmintrin.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-07-19 13:32:46 +00:00
|
|
|
void WindowPrePaintData::setTranslucent()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-19 13:32:46 +00:00
|
|
|
mask |= Effect::PAINT_WINDOW_TRANSLUCENT;
|
|
|
|
mask &= ~Effect::PAINT_WINDOW_OPAQUE;
|
|
|
|
clip = QRegion(); // cannot clip, will be transparent
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-19 13:32:46 +00:00
|
|
|
|
2007-07-19 14:05:59 +00:00
|
|
|
void WindowPrePaintData::setTransformed()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-19 14:05:59 +00:00
|
|
|
mask |= Effect::PAINT_WINDOW_TRANSFORMED;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
class PaintDataPrivate {
|
|
|
|
public:
|
|
|
|
QGraphicsScale scale;
|
|
|
|
QVector3D translation;
|
|
|
|
QGraphicsRotation rotation;
|
|
|
|
};
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
PaintData::PaintData()
|
|
|
|
: d(new PaintDataPrivate())
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
PaintData::~PaintData()
|
2012-05-27 17:28:02 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
delete d;
|
2012-05-27 17:28:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
qreal PaintData::xScale() const
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->scale.xScale();
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
qreal PaintData::yScale() const
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->scale.yScale();
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
qreal PaintData::zScale() const
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->scale.zScale();
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setScale(const QVector2D &scale)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->scale.setXScale(scale.x());
|
|
|
|
d->scale.setYScale(scale.y());
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setScale(const QVector3D &scale)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->scale.setXScale(scale.x());
|
|
|
|
d->scale.setYScale(scale.y());
|
|
|
|
d->scale.setZScale(scale.z());
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setXScale(qreal scale)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->scale.setXScale(scale);
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setYScale(qreal scale)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->scale.setYScale(scale);
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setZScale(qreal scale)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->scale.setZScale(scale);
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
const QGraphicsScale &PaintData::scale() const
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->scale;
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setXTranslation(qreal translate)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->translation.setX(translate);
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setYTranslation(qreal translate)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->translation.setY(translate);
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setZTranslation(qreal translate)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->translation.setZ(translate);
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::translate(qreal x, qreal y, qreal z)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
translate(QVector3D(x, y, z));
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::translate(const QVector3D &t)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->translation += t;
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
qreal PaintData::xTranslation() const
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->translation.x();
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
qreal PaintData::yTranslation() const
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->translation.y();
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
2012-05-27 17:28:02 +00:00
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
qreal PaintData::zTranslation() const
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->translation.z();
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
const QVector3D &PaintData::translation() const
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->translation;
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
qreal PaintData::rotationAngle() const
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->rotation.angle();
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
QVector3D PaintData::rotationAxis() const
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->rotation.axis();
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
QVector3D PaintData::rotationOrigin() const
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return d->rotation.origin();
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setRotationAngle(qreal angle)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->rotation.setAngle(angle);
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setRotationAxis(Qt::Axis axis)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->rotation.setAxis(axis);
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setRotationAxis(const QVector3D &axis)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->rotation.setAxis(axis);
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
void PaintData::setRotationOrigin(const QVector3D &origin)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
d->rotation.setOrigin(origin);
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 15:20:17 +00:00
|
|
|
class WindowPaintDataPrivate {
|
|
|
|
public:
|
|
|
|
qreal opacity;
|
|
|
|
qreal saturation;
|
|
|
|
qreal brightness;
|
2012-11-13 20:41:02 +00:00
|
|
|
int screen;
|
2013-05-13 06:17:28 +00:00
|
|
|
qreal crossFadeProgress;
|
2014-04-01 16:08:48 +00:00
|
|
|
QMatrix4x4 pMatrix;
|
|
|
|
QMatrix4x4 mvMatrix;
|
2015-11-30 13:35:12 +00:00
|
|
|
QMatrix4x4 screenProjectionMatrix;
|
2012-07-12 15:20:17 +00:00
|
|
|
};
|
|
|
|
|
2015-11-30 13:35:12 +00:00
|
|
|
WindowPaintData::WindowPaintData(EffectWindow *w)
|
|
|
|
: WindowPaintData(w, QMatrix4x4())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowPaintData::WindowPaintData(EffectWindow* w, const QMatrix4x4 &screenProjectionMatrix)
|
2012-06-02 19:54:18 +00:00
|
|
|
: PaintData()
|
2014-01-08 10:43:02 +00:00
|
|
|
, shader(nullptr)
|
2012-07-12 15:20:17 +00:00
|
|
|
, d(new WindowPaintDataPrivate())
|
2012-05-27 17:28:02 +00:00
|
|
|
{
|
2015-11-30 13:35:12 +00:00
|
|
|
d->screenProjectionMatrix = screenProjectionMatrix;
|
2012-06-02 19:54:18 +00:00
|
|
|
quads = w->buildQuads();
|
2012-07-12 15:20:17 +00:00
|
|
|
setOpacity(w->opacity());
|
|
|
|
setSaturation(1.0);
|
|
|
|
setBrightness(1.0);
|
2012-11-13 20:41:02 +00:00
|
|
|
setScreen(0);
|
2013-05-13 06:17:28 +00:00
|
|
|
setCrossFadeProgress(1.0);
|
2012-05-27 17:28:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
WindowPaintData::WindowPaintData(const WindowPaintData &other)
|
|
|
|
: PaintData()
|
|
|
|
, quads(other.quads)
|
|
|
|
, shader(other.shader)
|
2012-07-12 15:20:17 +00:00
|
|
|
, d(new WindowPaintDataPrivate())
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
setXScale(other.xScale());
|
|
|
|
setYScale(other.yScale());
|
|
|
|
setZScale(other.zScale());
|
|
|
|
translate(other.translation());
|
|
|
|
setRotationOrigin(other.rotationOrigin());
|
|
|
|
setRotationAxis(other.rotationAxis());
|
|
|
|
setRotationAngle(other.rotationAngle());
|
2012-07-12 15:20:17 +00:00
|
|
|
setOpacity(other.opacity());
|
|
|
|
setSaturation(other.saturation());
|
|
|
|
setBrightness(other.brightness());
|
2012-11-13 20:41:02 +00:00
|
|
|
setScreen(other.screen());
|
2013-05-13 06:17:28 +00:00
|
|
|
setCrossFadeProgress(other.crossFadeProgress());
|
2014-04-01 16:08:48 +00:00
|
|
|
setProjectionMatrix(other.projectionMatrix());
|
|
|
|
setModelViewMatrix(other.modelViewMatrix());
|
2015-11-30 13:35:12 +00:00
|
|
|
d->screenProjectionMatrix = other.d->screenProjectionMatrix;
|
2012-07-12 15:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WindowPaintData::~WindowPaintData()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal WindowPaintData::opacity() const
|
|
|
|
{
|
|
|
|
return d->opacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal WindowPaintData::saturation() const
|
|
|
|
{
|
|
|
|
return d->saturation;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal WindowPaintData::brightness() const
|
|
|
|
{
|
|
|
|
return d->brightness;
|
|
|
|
}
|
|
|
|
|
2012-11-13 20:41:02 +00:00
|
|
|
int WindowPaintData::screen() const
|
|
|
|
{
|
|
|
|
return d->screen;
|
|
|
|
}
|
|
|
|
|
2012-07-12 15:20:17 +00:00
|
|
|
void WindowPaintData::setOpacity(qreal opacity)
|
|
|
|
{
|
|
|
|
d->opacity = opacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowPaintData::setSaturation(qreal saturation) const
|
|
|
|
{
|
|
|
|
d->saturation = saturation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowPaintData::setBrightness(qreal brightness)
|
|
|
|
{
|
|
|
|
d->brightness = brightness;
|
|
|
|
}
|
|
|
|
|
2012-11-13 20:41:02 +00:00
|
|
|
void WindowPaintData::setScreen(int screen) const
|
|
|
|
{
|
|
|
|
d->screen = screen;
|
|
|
|
}
|
|
|
|
|
2013-05-13 06:17:28 +00:00
|
|
|
qreal WindowPaintData::crossFadeProgress() const
|
|
|
|
{
|
|
|
|
return d->crossFadeProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowPaintData::setCrossFadeProgress(qreal factor)
|
|
|
|
{
|
2013-06-26 08:13:33 +00:00
|
|
|
d->crossFadeProgress = qBound(qreal(0.0), factor, qreal(1.0));
|
2013-05-13 06:17:28 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 15:20:17 +00:00
|
|
|
qreal WindowPaintData::multiplyOpacity(qreal factor)
|
|
|
|
{
|
|
|
|
d->opacity *= factor;
|
|
|
|
return d->opacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal WindowPaintData::multiplySaturation(qreal factor)
|
|
|
|
{
|
|
|
|
d->saturation *= factor;
|
|
|
|
return d->saturation;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal WindowPaintData::multiplyBrightness(qreal factor)
|
|
|
|
{
|
|
|
|
d->brightness *= factor;
|
|
|
|
return d->brightness;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2014-04-01 16:08:48 +00:00
|
|
|
void WindowPaintData::setProjectionMatrix(const QMatrix4x4 &matrix)
|
|
|
|
{
|
|
|
|
d->pMatrix = matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix4x4 WindowPaintData::projectionMatrix() const
|
|
|
|
{
|
|
|
|
return d->pMatrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix4x4 &WindowPaintData::rprojectionMatrix()
|
|
|
|
{
|
|
|
|
return d->pMatrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowPaintData::setModelViewMatrix(const QMatrix4x4 &matrix)
|
|
|
|
{
|
|
|
|
d->mvMatrix = matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix4x4 WindowPaintData::modelViewMatrix() const
|
|
|
|
{
|
|
|
|
return d->mvMatrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix4x4 &WindowPaintData::rmodelViewMatrix()
|
|
|
|
{
|
|
|
|
return d->mvMatrix;
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
WindowPaintData &WindowPaintData::operator*=(qreal scale)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
this->setXScale(this->xScale() * scale);
|
|
|
|
this->setYScale(this->yScale() * scale);
|
|
|
|
this->setZScale(this->zScale() * scale);
|
2012-05-28 10:00:31 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
WindowPaintData &WindowPaintData::operator*=(const QVector2D &scale)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
this->setXScale(this->xScale() * scale.x());
|
|
|
|
this->setYScale(this->yScale() * scale.y());
|
2012-05-28 10:00:31 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
WindowPaintData &WindowPaintData::operator*=(const QVector3D &scale)
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
this->setXScale(this->xScale() * scale.x());
|
|
|
|
this->setYScale(this->yScale() * scale.y());
|
|
|
|
this->setZScale(this->zScale() * scale.z());
|
2012-05-28 10:00:31 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
WindowPaintData &WindowPaintData::operator+=(const QPointF &translation)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
|
|
|
return this->operator+=(QVector3D(translation));
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
WindowPaintData &WindowPaintData::operator+=(const QPoint &translation)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
|
|
|
return this->operator+=(QVector3D(translation));
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
WindowPaintData &WindowPaintData::operator+=(const QVector2D &translation)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
|
|
|
return this->operator+=(QVector3D(translation));
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
WindowPaintData &WindowPaintData::operator+=(const QVector3D &translation)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
translate(translation);
|
2012-05-28 12:45:46 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-30 13:35:12 +00:00
|
|
|
QMatrix4x4 WindowPaintData::screenProjectionMatrix() const
|
|
|
|
{
|
|
|
|
return d->screenProjectionMatrix;
|
|
|
|
}
|
|
|
|
|
2015-11-26 15:12:12 +00:00
|
|
|
class ScreenPaintData::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QMatrix4x4 projectionMatrix;
|
2016-10-14 13:49:57 +00:00
|
|
|
QRect outputGeometry;
|
2015-11-26 15:12:12 +00:00
|
|
|
};
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData::ScreenPaintData()
|
|
|
|
: PaintData()
|
2015-11-26 15:12:12 +00:00
|
|
|
, d(new Private())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-14 13:49:57 +00:00
|
|
|
ScreenPaintData::ScreenPaintData(const QMatrix4x4 &projectionMatrix, const QRect &outputGeometry)
|
2015-11-26 15:12:12 +00:00
|
|
|
: PaintData()
|
|
|
|
, d(new Private())
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2015-11-26 15:12:12 +00:00
|
|
|
d->projectionMatrix = projectionMatrix;
|
2016-10-14 13:49:57 +00:00
|
|
|
d->outputGeometry = outputGeometry;
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 15:12:12 +00:00
|
|
|
ScreenPaintData::~ScreenPaintData() = default;
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData::ScreenPaintData(const ScreenPaintData &other)
|
|
|
|
: PaintData()
|
2015-11-26 15:12:12 +00:00
|
|
|
, d(new Private())
|
2012-05-28 10:00:31 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
translate(other.translation());
|
|
|
|
setXScale(other.xScale());
|
|
|
|
setYScale(other.yScale());
|
|
|
|
setZScale(other.zScale());
|
|
|
|
setRotationOrigin(other.rotationOrigin());
|
|
|
|
setRotationAxis(other.rotationAxis());
|
|
|
|
setRotationAngle(other.rotationAngle());
|
2015-11-26 15:12:12 +00:00
|
|
|
d->projectionMatrix = other.d->projectionMatrix;
|
2016-10-14 13:49:57 +00:00
|
|
|
d->outputGeometry = other.d->outputGeometry;
|
2012-05-28 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData &ScreenPaintData::operator=(const ScreenPaintData &rhs)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
setXScale(rhs.xScale());
|
|
|
|
setYScale(rhs.yScale());
|
|
|
|
setZScale(rhs.zScale());
|
|
|
|
setXTranslation(rhs.xTranslation());
|
|
|
|
setYTranslation(rhs.yTranslation());
|
|
|
|
setZTranslation(rhs.zTranslation());
|
|
|
|
setRotationOrigin(rhs.rotationOrigin());
|
|
|
|
setRotationAxis(rhs.rotationAxis());
|
|
|
|
setRotationAngle(rhs.rotationAngle());
|
2015-11-26 15:12:12 +00:00
|
|
|
d->projectionMatrix = rhs.d->projectionMatrix;
|
2016-10-14 13:49:57 +00:00
|
|
|
d->outputGeometry = rhs.d->outputGeometry;
|
2012-06-02 19:54:18 +00:00
|
|
|
return *this;
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData &ScreenPaintData::operator*=(qreal scale)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
setXScale(this->xScale() * scale);
|
|
|
|
setYScale(this->yScale() * scale);
|
|
|
|
setZScale(this->zScale() * scale);
|
|
|
|
return *this;
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData &ScreenPaintData::operator*=(const QVector2D &scale)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
setXScale(this->xScale() * scale.x());
|
|
|
|
setYScale(this->yScale() * scale.y());
|
|
|
|
return *this;
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData &ScreenPaintData::operator*=(const QVector3D &scale)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
setXScale(this->xScale() * scale.x());
|
|
|
|
setYScale(this->yScale() * scale.y());
|
|
|
|
setZScale(this->zScale() * scale.z());
|
|
|
|
return *this;
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData &ScreenPaintData::operator+=(const QPointF &translation)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return this->operator+=(QVector3D(translation));
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData &ScreenPaintData::operator+=(const QPoint &translation)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return this->operator+=(QVector3D(translation));
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData &ScreenPaintData::operator+=(const QVector2D &translation)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
return this->operator+=(QVector3D(translation));
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 19:54:18 +00:00
|
|
|
ScreenPaintData &ScreenPaintData::operator+=(const QVector3D &translation)
|
2012-05-28 12:45:46 +00:00
|
|
|
{
|
2012-06-02 19:54:18 +00:00
|
|
|
translate(translation);
|
|
|
|
return *this;
|
2012-05-28 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 15:12:12 +00:00
|
|
|
QMatrix4x4 ScreenPaintData::projectionMatrix() const
|
|
|
|
{
|
|
|
|
return d->projectionMatrix;
|
|
|
|
}
|
|
|
|
|
2016-10-14 13:49:57 +00:00
|
|
|
QRect ScreenPaintData::outputGeometry() const
|
|
|
|
{
|
|
|
|
return d->outputGeometry;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// Effect
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
Effect::Effect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Effect::~Effect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
|
|
|
}
|
2008-10-02 09:27:32 +00:00
|
|
|
|
2009-09-02 02:30:22 +00:00
|
|
|
void* Effect::proxy()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-01-08 10:43:02 +00:00
|
|
|
return nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-06 10:15:06 +00:00
|
|
|
|
2013-04-24 14:51:04 +00:00
|
|
|
void Effect::windowInputMouseEvent(QEvent*)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::grabbedKeyboardEvent(QKeyEvent*)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool Effect::borderActivated(ElectricBorder)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void Effect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Effect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::postPaintWindow(EffectWindow* w)
|
|
|
|
{
|
|
|
|
effects->postPaintWindow(w);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void Effect::paintEffectFrame(KWin::EffectFrame* frame, const QRegion ®ion, double opacity, double frameOpacity)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->paintEffectFrame(frame, region, opacity, frameOpacity);
|
|
|
|
}
|
2010-07-24 16:29:16 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool Effect::provides(Feature)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool Effect::isActive() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-27 21:35:19 +00:00
|
|
|
QString Effect::debug(const QString &) const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void Effect::drawWindow(EffectWindow* w, int mask, const QRegion ®ion, WindowPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->drawWindow(w, mask, region, data);
|
|
|
|
}
|
2008-10-17 10:30:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::buildQuads(EffectWindow* w, WindowQuadList& quadList)
|
|
|
|
{
|
|
|
|
effects->buildQuads(w, quadList);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::setPositionTransformations(WindowPaintData& data, QRect& region, EffectWindow* w,
|
|
|
|
const QRect& r, Qt::AspectRatioMode aspect)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
QSize size = w->size();
|
2011-01-30 14:34:42 +00:00
|
|
|
size.scale(r.size(), aspect);
|
2012-05-28 10:00:31 +00:00
|
|
|
data.setXScale(size.width() / double(w->width()));
|
|
|
|
data.setYScale(size.height() / double(w->height()));
|
|
|
|
int width = int(w->width() * data.xScale());
|
|
|
|
int height = int(w->height() * data.yScale());
|
2011-01-30 14:34:42 +00:00
|
|
|
int x = r.x() + (r.width() - width) / 2;
|
|
|
|
int y = r.y() + (r.height() - height) / 2;
|
|
|
|
region = QRect(x, y, width, height);
|
2012-05-28 12:45:46 +00:00
|
|
|
data.setXTranslation(x - w->x());
|
|
|
|
data.setYTranslation(y - w->y());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QPoint Effect::cursorPos()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return effects->cursorPos();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
double Effect::animationTime(const KConfigGroup& cfg, const QString& key, int defaultTime)
|
|
|
|
{
|
|
|
|
int time = cfg.readEntry(key, 0);
|
|
|
|
return time != 0 ? time : qMax(defaultTime * effects->animationTimeFactor(), 1.);
|
|
|
|
}
|
2008-08-30 07:25:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
double Effect::animationTime(int defaultTime)
|
|
|
|
{
|
|
|
|
// at least 1ms, otherwise 0ms times can break some things
|
|
|
|
return qMax(defaultTime * effects->animationTimeFactor(), 1.);
|
|
|
|
}
|
2008-08-30 07:25:54 +00:00
|
|
|
|
2014-03-24 10:50:09 +00:00
|
|
|
int Effect::requestedEffectChainPosition() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_connection_t *Effect::xcbConnection() const
|
|
|
|
{
|
|
|
|
return effects->xcbConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_window_t Effect::x11RootWindow() const
|
|
|
|
{
|
|
|
|
return effects->x11RootWindow();
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool Effect::touchDown(qint32 id, const QPointF &pos, quint32 time)
|
2016-08-15 13:44:10 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(pos)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool Effect::touchMotion(qint32 id, const QPointF &pos, quint32 time)
|
2016-08-15 13:44:10 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(pos)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool Effect::touchUp(qint32 id, quint32 time)
|
2016-08-15 13:44:10 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-30 13:50:31 +00:00
|
|
|
bool Effect::perform(Feature feature, const QVariantList &arguments)
|
|
|
|
{
|
|
|
|
Q_UNUSED(feature)
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-25 10:34:11 +00:00
|
|
|
//****************************************
|
|
|
|
// EffectFactory
|
|
|
|
//****************************************
|
2014-03-28 19:50:46 +00:00
|
|
|
EffectPluginFactory::EffectPluginFactory()
|
2014-03-25 10:34:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EffectPluginFactory::~EffectPluginFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EffectPluginFactory::enabledByDefault() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EffectPluginFactory::isSupported() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// EffectsHandler
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
EffectsHandler::EffectsHandler(CompositingType type)
|
2011-08-27 09:21:31 +00:00
|
|
|
: compositing_type(type)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (compositing_type == NoCompositing)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
KWin::effects = this;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
EffectsHandler::~EffectsHandler()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// All effects should already be unloaded by Impl dtor
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(loaded_effects.count() == 0);
|
2018-08-30 13:34:59 +00:00
|
|
|
KWin::effects = nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-07-26 07:51:16 +00:00
|
|
|
CompositingType EffectsHandler::compositingType() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-26 07:51:16 +00:00
|
|
|
return compositing_type;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-26 07:51:16 +00:00
|
|
|
|
2012-09-20 09:33:32 +00:00
|
|
|
bool EffectsHandler::isOpenGLCompositing() const
|
|
|
|
{
|
|
|
|
return compositing_type & OpenGLCompositing;
|
|
|
|
}
|
|
|
|
|
2014-01-08 10:43:02 +00:00
|
|
|
EffectsHandler* effects = nullptr;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// EffectWindow
|
|
|
|
//****************************************
|
|
|
|
|
2018-06-24 11:08:44 +00:00
|
|
|
class Q_DECL_HIDDEN EffectWindow::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private(EffectWindow *q);
|
|
|
|
|
|
|
|
EffectWindow *q;
|
|
|
|
};
|
|
|
|
|
|
|
|
EffectWindow::Private::Private(EffectWindow *q)
|
|
|
|
: q(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-29 09:31:37 +00:00
|
|
|
EffectWindow::EffectWindow(QObject *parent)
|
|
|
|
: QObject(parent)
|
2018-06-24 11:08:44 +00:00
|
|
|
, d(new Private(this))
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
EffectWindow::~EffectWindow()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
bool EffectWindow::isOnActivity(const QString &activity) const
|
2011-12-29 09:36:51 +00:00
|
|
|
{
|
2018-11-30 09:58:45 +00:00
|
|
|
const QStringList _activities = activities();
|
|
|
|
return _activities.isEmpty() || _activities.contains(activity);
|
2011-12-29 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EffectWindow::isOnAllActivities() const
|
|
|
|
{
|
2018-11-30 09:58:45 +00:00
|
|
|
return activities().isEmpty();
|
2011-12-29 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 09:48:12 +00:00
|
|
|
void EffectWindow::setMinimized(bool min)
|
|
|
|
{
|
|
|
|
if (min) {
|
|
|
|
minimize();
|
|
|
|
} else {
|
|
|
|
unminimize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-24 12:20:47 +00:00
|
|
|
bool EffectWindow::isOnCurrentActivity() const
|
|
|
|
{
|
|
|
|
return isOnActivity(effects->currentActivity());
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
bool EffectWindow::isOnCurrentDesktop() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
return isOnDesktop(effects->currentDesktop());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool EffectWindow::isOnDesktop(int d) const
|
|
|
|
{
|
2018-11-13 16:18:46 +00:00
|
|
|
const QVector<uint> ds = desktops();
|
[wayland] Use the new plasma virtual desktop protocol
Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)
Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)
Test Plan: used a bit a plasma session together with D12820, D13748 and D13746
Reviewers: #plasma, #kwin, graesslin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: hein, zzag, davidedmundson, kwin
Tags: #kwin
Maniphest Tasks: T4457
Differential Revision: https://phabricator.kde.org/D13887
2018-10-29 22:29:15 +00:00
|
|
|
return ds.isEmpty() || ds.contains(d);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-12-29 09:36:51 +00:00
|
|
|
bool EffectWindow::isOnAllDesktops() const
|
|
|
|
{
|
[wayland] Use the new plasma virtual desktop protocol
Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)
Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)
Test Plan: used a bit a plasma session together with D12820, D13748 and D13746
Reviewers: #plasma, #kwin, graesslin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: hein, zzag, davidedmundson, kwin
Tags: #kwin
Maniphest Tasks: T4457
Differential Revision: https://phabricator.kde.org/D13887
2018-10-29 22:29:15 +00:00
|
|
|
return desktops().isEmpty();
|
2011-12-29 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 13:32:46 +00:00
|
|
|
bool EffectWindow::hasDecoration() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
return contentsRect() != QRect(0, 0, width(), height());
|
|
|
|
}
|
2007-07-19 13:32:46 +00:00
|
|
|
|
2013-01-11 09:06:14 +00:00
|
|
|
bool EffectWindow::isVisible() const
|
|
|
|
{
|
|
|
|
return !isMinimized()
|
|
|
|
&& isOnCurrentDesktop()
|
|
|
|
&& isOnCurrentActivity();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// EffectWindowGroup
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
EffectWindowGroup::~EffectWindowGroup()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
/***************************************************************
|
|
|
|
WindowQuad
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuad WindowQuad::makeSubQuad(double x1, double y1, double x2, double y2) const
|
|
|
|
{
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(x1 < x2 && y1 < y2 && x1 >= left() && x2 <= right() && y1 >= top() && y2 <= bottom());
|
|
|
|
#if !defined(QT_NO_DEBUG)
|
2011-01-30 14:34:42 +00:00
|
|
|
if (isTransformed())
|
2013-09-02 16:42:20 +00:00
|
|
|
qFatal("Splitting quads is allowed only in pre-paint calls!");
|
2007-07-19 16:11:27 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuad ret(*this);
|
2007-07-19 14:56:25 +00:00
|
|
|
// vertices are clockwise starting from topleft
|
2007-07-07 14:01:32 +00:00
|
|
|
ret.verts[ 0 ].px = x1;
|
|
|
|
ret.verts[ 3 ].px = x1;
|
|
|
|
ret.verts[ 1 ].px = x2;
|
|
|
|
ret.verts[ 2 ].px = x2;
|
|
|
|
ret.verts[ 0 ].py = y1;
|
|
|
|
ret.verts[ 1 ].py = y1;
|
|
|
|
ret.verts[ 2 ].py = y2;
|
|
|
|
ret.verts[ 3 ].py = y2;
|
2007-07-19 14:53:37 +00:00
|
|
|
// original x/y are supposed to be the same, no transforming is done here
|
|
|
|
ret.verts[ 0 ].ox = x1;
|
|
|
|
ret.verts[ 3 ].ox = x1;
|
|
|
|
ret.verts[ 1 ].ox = x2;
|
|
|
|
ret.verts[ 2 ].ox = x2;
|
|
|
|
ret.verts[ 0 ].oy = y1;
|
|
|
|
ret.verts[ 1 ].oy = y1;
|
|
|
|
ret.verts[ 2 ].oy = y2;
|
|
|
|
ret.verts[ 3 ].oy = y2;
|
2013-09-16 17:30:35 +00:00
|
|
|
|
|
|
|
const double my_u0 = verts[0].tx;
|
|
|
|
const double my_u1 = verts[2].tx;
|
|
|
|
const double my_v0 = verts[0].ty;
|
|
|
|
const double my_v1 = verts[2].ty;
|
|
|
|
|
|
|
|
const double width = right() - left();
|
|
|
|
const double height = bottom() - top();
|
|
|
|
|
|
|
|
const double texWidth = my_u1 - my_u0;
|
|
|
|
const double texHeight = my_v1 - my_v0;
|
|
|
|
|
|
|
|
if (!uvAxisSwapped()) {
|
|
|
|
const double u0 = (x1 - left()) / width * texWidth + my_u0;
|
|
|
|
const double u1 = (x2 - left()) / width * texWidth + my_u0;
|
|
|
|
const double v0 = (y1 - top()) / height * texHeight + my_v0;
|
|
|
|
const double v1 = (y2 - top()) / height * texHeight + my_v0;
|
|
|
|
|
|
|
|
ret.verts[0].tx = u0;
|
|
|
|
ret.verts[3].tx = u0;
|
|
|
|
ret.verts[1].tx = u1;
|
|
|
|
ret.verts[2].tx = u1;
|
|
|
|
ret.verts[0].ty = v0;
|
|
|
|
ret.verts[1].ty = v0;
|
|
|
|
ret.verts[2].ty = v1;
|
|
|
|
ret.verts[3].ty = v1;
|
|
|
|
} else {
|
|
|
|
const double u0 = (y1 - top()) / height * texWidth + my_u0;
|
|
|
|
const double u1 = (y2 - top()) / height * texWidth + my_u0;
|
|
|
|
const double v0 = (x1 - left()) / width * texHeight + my_v0;
|
|
|
|
const double v1 = (x2 - left()) / width * texHeight + my_v0;
|
|
|
|
|
|
|
|
ret.verts[0].tx = u0;
|
|
|
|
ret.verts[1].tx = u0;
|
|
|
|
ret.verts[2].tx = u1;
|
|
|
|
ret.verts[3].tx = u1;
|
|
|
|
ret.verts[0].ty = v0;
|
|
|
|
ret.verts[3].ty = v0;
|
|
|
|
ret.verts[1].ty = v1;
|
|
|
|
ret.verts[2].ty = v1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.setUVAxisSwapped(uvAxisSwapped());
|
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
return ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
|
2007-07-19 15:55:04 +00:00
|
|
|
bool WindowQuad::smoothNeeded() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-19 15:55:04 +00:00
|
|
|
// smoothing is needed if the width or height of the quad does not match the original size
|
2007-09-03 15:00:43 +00:00
|
|
|
double width = verts[ 1 ].ox - verts[ 0 ].ox;
|
|
|
|
double height = verts[ 2 ].oy - verts[ 1 ].oy;
|
2011-01-30 14:34:42 +00:00
|
|
|
return(verts[ 1 ].px - verts[ 0 ].px != width || verts[ 2 ].px - verts[ 3 ].px != width
|
|
|
|
|| verts[ 2 ].py - verts[ 1 ].py != height || verts[ 3 ].py - verts[ 0 ].py != height);
|
|
|
|
}
|
2007-07-19 15:55:04 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
/***************************************************************
|
|
|
|
WindowQuadList
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::splitAtX(double x) const
|
|
|
|
{
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & quad, *this) {
|
2019-08-31 14:28:37 +00:00
|
|
|
#if !defined(QT_NO_DEBUG)
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad.isTransformed())
|
2013-09-02 16:42:20 +00:00
|
|
|
qFatal("Splitting quads is allowed only in pre-paint calls!");
|
2007-07-19 16:11:27 +00:00
|
|
|
#endif
|
2007-07-07 14:01:32 +00:00
|
|
|
bool wholeleft = true;
|
|
|
|
bool wholeright = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < 4;
|
|
|
|
++i) {
|
|
|
|
if (quad[ i ].x() < x)
|
2007-07-07 14:01:32 +00:00
|
|
|
wholeright = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad[ i ].x() > x)
|
2007-07-07 14:01:32 +00:00
|
|
|
wholeleft = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (wholeleft || wholeright) { // is whole in one split part
|
|
|
|
ret.append(quad);
|
2007-07-07 14:01:32 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2015-09-10 08:38:54 +00:00
|
|
|
if (quad.top() == quad.bottom() || quad.left() == quad.right()) { // quad has no size
|
2011-01-30 14:34:42 +00:00
|
|
|
ret.append(quad);
|
2008-12-16 20:48:34 +00:00
|
|
|
continue;
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
ret.append(quad.makeSubQuad(quad.left(), quad.top(), x, quad.bottom()));
|
|
|
|
ret.append(quad.makeSubQuad(x, quad.top(), quad.right(), quad.bottom()));
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::splitAtY(double y) const
|
|
|
|
{
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & quad, *this) {
|
2019-08-31 14:28:37 +00:00
|
|
|
#if !defined(QT_NO_DEBUG)
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad.isTransformed())
|
2013-09-02 16:42:20 +00:00
|
|
|
qFatal("Splitting quads is allowed only in pre-paint calls!");
|
2007-07-19 16:11:27 +00:00
|
|
|
#endif
|
2007-07-07 14:01:32 +00:00
|
|
|
bool wholetop = true;
|
|
|
|
bool wholebottom = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < 4;
|
|
|
|
++i) {
|
|
|
|
if (quad[ i ].y() < y)
|
2007-07-07 14:01:32 +00:00
|
|
|
wholebottom = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad[ i ].y() > y)
|
2007-07-07 14:01:32 +00:00
|
|
|
wholetop = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (wholetop || wholebottom) { // is whole in one split part
|
|
|
|
ret.append(quad);
|
2007-07-07 14:01:32 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2015-09-10 08:38:54 +00:00
|
|
|
if (quad.top() == quad.bottom() || quad.left() == quad.right()) { // quad has no size
|
2011-01-30 14:34:42 +00:00
|
|
|
ret.append(quad);
|
2008-12-16 20:48:34 +00:00
|
|
|
continue;
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
ret.append(quad.makeSubQuad(quad.left(), quad.top(), quad.right(), y));
|
|
|
|
ret.append(quad.makeSubQuad(quad.left(), y, quad.right(), quad.bottom()));
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
|
2013-09-09 15:28:46 +00:00
|
|
|
WindowQuadList WindowQuadList::makeGrid(int maxQuadSize) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (empty())
|
2007-07-07 14:01:32 +00:00
|
|
|
return *this;
|
2013-09-09 15:28:46 +00:00
|
|
|
|
|
|
|
// Find the bounding rectangle
|
|
|
|
double left = first().left();
|
|
|
|
double right = first().right();
|
|
|
|
double top = first().top();
|
2007-09-03 15:00:43 +00:00
|
|
|
double bottom = first().bottom();
|
2013-09-09 15:28:46 +00:00
|
|
|
|
|
|
|
foreach (const WindowQuad &quad, *this) {
|
2019-08-31 14:28:37 +00:00
|
|
|
#if !defined(QT_NO_DEBUG)
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad.isTransformed())
|
2013-09-02 16:42:20 +00:00
|
|
|
qFatal("Splitting quads is allowed only in pre-paint calls!");
|
2007-07-19 16:11:27 +00:00
|
|
|
#endif
|
2013-09-09 15:28:46 +00:00
|
|
|
left = qMin(left, quad.left());
|
|
|
|
right = qMax(right, quad.right());
|
|
|
|
top = qMin(top, quad.top());
|
2011-01-30 14:34:42 +00:00
|
|
|
bottom = qMax(bottom, quad.bottom());
|
|
|
|
}
|
2013-09-09 15:28:46 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowQuadList ret;
|
2013-09-09 15:28:46 +00:00
|
|
|
|
|
|
|
foreach (const WindowQuad &quad, *this) {
|
|
|
|
const double quadLeft = quad.left();
|
|
|
|
const double quadRight = quad.right();
|
|
|
|
const double quadTop = quad.top();
|
|
|
|
const double quadBottom = quad.bottom();
|
|
|
|
|
2018-03-04 10:23:28 +00:00
|
|
|
// sanity check, see BUG 390953
|
|
|
|
if (quadLeft == quadRight || quadTop == quadBottom) {
|
|
|
|
ret.append(quad);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-09 15:28:46 +00:00
|
|
|
// Compute the top-left corner of the first intersecting grid cell
|
|
|
|
const double xBegin = left + qFloor((quadLeft - left) / maxQuadSize) * maxQuadSize;
|
|
|
|
const double yBegin = top + qFloor((quadTop - top) / maxQuadSize) * maxQuadSize;
|
|
|
|
|
|
|
|
// Loop over all intersecting cells and add sub-quads
|
|
|
|
for (double y = yBegin; y < quadBottom; y += maxQuadSize) {
|
|
|
|
const double y0 = qMax(y, quadTop);
|
|
|
|
const double y1 = qMin(quadBottom, y + maxQuadSize);
|
|
|
|
|
|
|
|
for (double x = xBegin; x < quadRight; x += maxQuadSize) {
|
|
|
|
const double x0 = qMax(x, quadLeft);
|
|
|
|
const double x1 = qMin(quadRight, x + maxQuadSize);
|
|
|
|
|
|
|
|
ret.append(quad.makeSubQuad(x0, y0, x1, y1));
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-09 15:28:46 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::makeRegularGrid(int xSubdivisions, int ySubdivisions) const
|
|
|
|
{
|
|
|
|
if (empty())
|
2008-03-02 22:28:50 +00:00
|
|
|
return *this;
|
2013-09-09 15:26:23 +00:00
|
|
|
|
|
|
|
// Find the bounding rectangle
|
|
|
|
double left = first().left();
|
|
|
|
double right = first().right();
|
|
|
|
double top = first().top();
|
2008-03-02 22:28:50 +00:00
|
|
|
double bottom = first().bottom();
|
2013-09-09 15:26:23 +00:00
|
|
|
|
|
|
|
foreach (const WindowQuad &quad, *this) {
|
2019-08-31 14:28:37 +00:00
|
|
|
#if !defined(QT_NO_DEBUG)
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad.isTransformed())
|
2013-09-02 16:42:20 +00:00
|
|
|
qFatal("Splitting quads is allowed only in pre-paint calls!");
|
2008-03-02 22:28:50 +00:00
|
|
|
#endif
|
2013-09-09 15:26:23 +00:00
|
|
|
left = qMin(left, quad.left());
|
|
|
|
right = qMax(right, quad.right());
|
|
|
|
top = qMin(top, quad.top());
|
2011-01-30 14:34:42 +00:00
|
|
|
bottom = qMax(bottom, quad.bottom());
|
|
|
|
}
|
2008-03-02 22:28:50 +00:00
|
|
|
|
2013-09-09 15:26:23 +00:00
|
|
|
double xIncrement = (right - left) / xSubdivisions;
|
|
|
|
double yIncrement = (bottom - top) / ySubdivisions;
|
|
|
|
|
2008-03-02 22:28:50 +00:00
|
|
|
WindowQuadList ret;
|
2013-09-09 15:26:23 +00:00
|
|
|
|
|
|
|
foreach (const WindowQuad &quad, *this) {
|
|
|
|
const double quadLeft = quad.left();
|
|
|
|
const double quadRight = quad.right();
|
|
|
|
const double quadTop = quad.top();
|
|
|
|
const double quadBottom = quad.bottom();
|
|
|
|
|
2018-03-04 10:23:28 +00:00
|
|
|
// sanity check, see BUG 390953
|
|
|
|
if (quadLeft == quadRight || quadTop == quadBottom) {
|
|
|
|
ret.append(quad);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-09 15:26:23 +00:00
|
|
|
// Compute the top-left corner of the first intersecting grid cell
|
|
|
|
const double xBegin = left + qFloor((quadLeft - left) / xIncrement) * xIncrement;
|
|
|
|
const double yBegin = top + qFloor((quadTop - top) / yIncrement) * yIncrement;
|
|
|
|
|
|
|
|
// Loop over all intersecting cells and add sub-quads
|
|
|
|
for (double y = yBegin; y < quadBottom; y += yIncrement) {
|
|
|
|
const double y0 = qMax(y, quadTop);
|
|
|
|
const double y1 = qMin(quadBottom, y + yIncrement);
|
|
|
|
|
|
|
|
for (double x = xBegin; x < quadRight; x += xIncrement) {
|
|
|
|
const double x0 = qMax(x, quadLeft);
|
|
|
|
const double x1 = qMin(quadRight, x + xIncrement);
|
|
|
|
|
|
|
|
ret.append(quad.makeSubQuad(x0, y0, x1, y1));
|
2008-03-02 22:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-09 15:26:23 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2008-03-02 22:28:50 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
#ifndef GL_TRIANGLES
|
|
|
|
# define GL_TRIANGLES 0x0004
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_QUADS
|
|
|
|
# define GL_QUADS 0x0007
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void WindowQuadList::makeInterleavedArrays(unsigned int type, GLVertex2D *vertices, const QMatrix4x4 &textureMatrix) const
|
2012-09-17 21:35:52 +00:00
|
|
|
{
|
|
|
|
// Since we know that the texture matrix just scales and translates
|
|
|
|
// we can use this information to optimize the transformation
|
|
|
|
const QVector2D coeff(textureMatrix(0, 0), textureMatrix(1, 1));
|
|
|
|
const QVector2D offset(textureMatrix(0, 3), textureMatrix(1, 3));
|
|
|
|
|
|
|
|
GLVertex2D *vertex = vertices;
|
|
|
|
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(type == GL_QUADS || type == GL_TRIANGLES);
|
2013-03-21 19:22:29 +00:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GL_QUADS:
|
2019-08-14 07:31:16 +00:00
|
|
|
#if defined(__SSE2__)
|
2013-03-21 19:22:29 +00:00
|
|
|
if (!(intptr_t(vertex) & 0xf)) {
|
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
const WindowQuad &quad = at(i);
|
2019-08-14 07:31:16 +00:00
|
|
|
alignas(16) GLVertex2D v[4];
|
2013-03-19 15:59:43 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
const WindowVertex &wv = quad[j];
|
2013-03-19 15:59:43 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
v[j].position = QVector2D(wv.x(), wv.y());
|
|
|
|
v[j].texcoord = QVector2D(wv.u(), wv.v()) * coeff + offset;
|
|
|
|
}
|
|
|
|
|
2019-08-13 06:42:09 +00:00
|
|
|
const __m128i *srcP = reinterpret_cast<const __m128i *>(&v);
|
|
|
|
__m128i *dstP = reinterpret_cast<__m128i *>(vertex);
|
2013-03-19 15:59:43 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
_mm_stream_si128(&dstP[0], _mm_load_si128(&srcP[0])); // Top-left
|
|
|
|
_mm_stream_si128(&dstP[1], _mm_load_si128(&srcP[1])); // Top-right
|
|
|
|
_mm_stream_si128(&dstP[2], _mm_load_si128(&srcP[2])); // Bottom-right
|
|
|
|
_mm_stream_si128(&dstP[3], _mm_load_si128(&srcP[3])); // Bottom-left
|
2013-03-19 15:59:43 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
vertex += 4;
|
|
|
|
}
|
|
|
|
} else
|
2019-08-14 07:31:16 +00:00
|
|
|
#endif // __SSE2__
|
2013-03-21 19:22:29 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
const WindowQuad &quad = at(i);
|
2012-09-17 21:35:52 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
const WindowVertex &wv = quad[j];
|
2012-09-17 21:35:52 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
GLVertex2D v;
|
|
|
|
v.position = QVector2D(wv.x(), wv.y());
|
|
|
|
v.texcoord = QVector2D(wv.u(), wv.v()) * coeff + offset;
|
2013-03-19 15:59:43 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
*(vertex++) = v;
|
|
|
|
}
|
|
|
|
}
|
2012-09-17 21:35:52 +00:00
|
|
|
}
|
2013-03-21 19:22:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TRIANGLES:
|
2019-08-14 07:31:16 +00:00
|
|
|
#if defined(__SSE2__)
|
2013-03-21 19:22:29 +00:00
|
|
|
if (!(intptr_t(vertex) & 0xf)) {
|
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
const WindowQuad &quad = at(i);
|
2019-08-14 07:31:16 +00:00
|
|
|
alignas(16) GLVertex2D v[4];
|
2013-03-21 19:22:29 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
const WindowVertex &wv = quad[j];
|
|
|
|
|
|
|
|
v[j].position = QVector2D(wv.x(), wv.y());
|
|
|
|
v[j].texcoord = QVector2D(wv.u(), wv.v()) * coeff + offset;
|
|
|
|
}
|
2012-09-17 21:35:52 +00:00
|
|
|
|
2019-08-13 06:42:09 +00:00
|
|
|
const __m128i *srcP = reinterpret_cast<const __m128i *>(&v);
|
|
|
|
__m128i *dstP = reinterpret_cast<__m128i *>(vertex);
|
2012-09-17 21:35:52 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
__m128i src[4];
|
|
|
|
src[0] = _mm_load_si128(&srcP[0]); // Top-left
|
|
|
|
src[1] = _mm_load_si128(&srcP[1]); // Top-right
|
|
|
|
src[2] = _mm_load_si128(&srcP[2]); // Bottom-right
|
|
|
|
src[3] = _mm_load_si128(&srcP[3]); // Bottom-left
|
|
|
|
|
|
|
|
// First triangle
|
|
|
|
_mm_stream_si128(&dstP[0], src[1]); // Top-right
|
|
|
|
_mm_stream_si128(&dstP[1], src[0]); // Top-left
|
|
|
|
_mm_stream_si128(&dstP[2], src[3]); // Bottom-left
|
|
|
|
|
|
|
|
// Second triangle
|
|
|
|
_mm_stream_si128(&dstP[3], src[3]); // Bottom-left
|
|
|
|
_mm_stream_si128(&dstP[4], src[2]); // Bottom-right
|
|
|
|
_mm_stream_si128(&dstP[5], src[1]); // Top-right
|
|
|
|
|
|
|
|
vertex += 6;
|
2013-03-19 15:59:43 +00:00
|
|
|
}
|
2013-03-21 19:22:29 +00:00
|
|
|
} else
|
2019-08-14 07:31:16 +00:00
|
|
|
#endif // __SSE2__
|
2013-03-21 19:22:29 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
const WindowQuad &quad = at(i);
|
|
|
|
GLVertex2D v[4]; // Four unique vertices / quad
|
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
const WindowVertex &wv = quad[j];
|
|
|
|
|
|
|
|
v[j].position = QVector2D(wv.x(), wv.y());
|
|
|
|
v[j].texcoord = QVector2D(wv.u(), wv.v()) * coeff + offset;
|
|
|
|
}
|
2013-03-19 15:59:43 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
// First triangle
|
|
|
|
*(vertex++) = v[1]; // Top-right
|
|
|
|
*(vertex++) = v[0]; // Top-left
|
|
|
|
*(vertex++) = v[3]; // Bottom-left
|
2013-03-19 15:59:43 +00:00
|
|
|
|
2013-03-21 19:22:29 +00:00
|
|
|
// Second triangle
|
|
|
|
*(vertex++) = v[3]; // Bottom-left
|
|
|
|
*(vertex++) = v[2]; // Bottom-right
|
|
|
|
*(vertex++) = v[1]; // Top-right
|
|
|
|
}
|
2013-03-19 15:59:43 +00:00
|
|
|
}
|
2013-03-21 19:22:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2012-09-17 21:35:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:13:27 +00:00
|
|
|
void WindowQuadList::makeArrays(float **vertices, float **texcoords, const QSizeF &size, bool yInverted) const
|
|
|
|
{
|
|
|
|
*vertices = new float[count() * 6 * 2];
|
|
|
|
*texcoords = new float[count() * 6 * 2];
|
|
|
|
|
|
|
|
float *vpos = *vertices;
|
|
|
|
float *tpos = *texcoords;
|
|
|
|
|
|
|
|
// Note: The positions in a WindowQuad are stored in clockwise order
|
|
|
|
const int index[] = { 1, 0, 3, 3, 2, 1 };
|
|
|
|
|
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
const WindowQuad &quad = at(i);
|
|
|
|
|
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
const WindowVertex &wv = quad[index[j]];
|
|
|
|
|
|
|
|
*vpos++ = wv.x();
|
|
|
|
*vpos++ = wv.y();
|
|
|
|
|
|
|
|
*tpos++ = wv.u() / size.width();
|
|
|
|
*tpos++ = yInverted ? (wv.v() / size.height()) : (1.0 - wv.v() / size.height());
|
2011-06-16 18:33:06 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowQuadList WindowQuadList::select(WindowQuadType type) const
|
|
|
|
{
|
|
|
|
foreach (const WindowQuad & q, *this) {
|
|
|
|
if (q.type() != type) { // something else than ones to select, make a copy and filter
|
2007-07-19 10:07:49 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & q, *this) {
|
|
|
|
if (q.type() == type)
|
|
|
|
ret.append(q);
|
2007-07-19 10:07:49 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
2007-07-19 10:07:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return *this; // nothing to filter out
|
|
|
|
}
|
2007-07-19 10:07:49 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::filterOut(WindowQuadType type) const
|
|
|
|
{
|
|
|
|
foreach (const WindowQuad & q, *this) {
|
|
|
|
if (q.type() == type) { // something to filter out, make a copy and filter
|
2007-07-18 15:01:59 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & q, *this) {
|
|
|
|
if (q.type() != type)
|
|
|
|
ret.append(q);
|
2007-07-18 15:01:59 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
2007-07-18 15:01:59 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return *this; // nothing to filter out
|
|
|
|
}
|
2007-07-18 15:01:59 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
bool WindowQuadList::smoothNeeded() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
foreach (const WindowQuad & q, *this)
|
|
|
|
if (q.smoothNeeded())
|
|
|
|
return true;
|
2007-07-19 15:55:04 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-09-18 15:26:17 +00:00
|
|
|
bool WindowQuadList::isTransformed() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
foreach (const WindowQuad & q, *this)
|
|
|
|
if (q.isTransformed())
|
|
|
|
return true;
|
2008-09-18 15:26:17 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-18 15:26:17 +00:00
|
|
|
|
2008-02-25 11:32:21 +00:00
|
|
|
/***************************************************************
|
|
|
|
PaintClipper
|
|
|
|
***************************************************************/
|
|
|
|
|
2014-01-08 10:43:02 +00:00
|
|
|
QStack< QRegion >* PaintClipper::areas = nullptr;
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
PaintClipper::PaintClipper(const QRegion& allowed_area)
|
|
|
|
: area(allowed_area)
|
|
|
|
{
|
|
|
|
push(area);
|
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
PaintClipper::~PaintClipper()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
pop(area);
|
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void PaintClipper::push(const QRegion& allowed_area)
|
|
|
|
{
|
|
|
|
if (allowed_area == infiniteRegion()) // don't push these
|
2008-02-25 11:32:21 +00:00
|
|
|
return;
|
2014-01-08 10:43:02 +00:00
|
|
|
if (areas == nullptr)
|
2008-02-25 11:32:21 +00:00
|
|
|
areas = new QStack< QRegion >;
|
2011-01-30 14:34:42 +00:00
|
|
|
areas->push(allowed_area);
|
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void PaintClipper::pop(const QRegion& allowed_area)
|
|
|
|
{
|
|
|
|
if (allowed_area == infiniteRegion())
|
2008-02-25 11:32:21 +00:00
|
|
|
return;
|
2014-01-08 10:43:02 +00:00
|
|
|
Q_ASSERT(areas != nullptr);
|
2011-01-30 14:34:42 +00:00
|
|
|
Q_ASSERT(areas->top() == allowed_area);
|
2008-02-25 11:32:21 +00:00
|
|
|
areas->pop();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (areas->isEmpty()) {
|
2008-02-25 11:32:21 +00:00
|
|
|
delete areas;
|
2014-01-08 10:43:02 +00:00
|
|
|
areas = nullptr;
|
2008-02-25 11:32:21 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
bool PaintClipper::clip()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-01-08 10:43:02 +00:00
|
|
|
return areas != nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
QRegion PaintClipper::paintArea()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(areas != nullptr); // can be called only with clip() == true
|
2014-11-25 07:40:23 +00:00
|
|
|
const QSize &s = effects->virtualScreenSize();
|
|
|
|
QRegion ret = QRegion(0, 0, s.width(), s.height());
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const QRegion & r, *areas)
|
|
|
|
ret &= r;
|
2008-02-25 11:32:21 +00:00
|
|
|
return ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
struct PaintClipper::Iterator::Data {
|
|
|
|
Data() : index(0) {}
|
2008-02-25 11:32:21 +00:00
|
|
|
int index;
|
2017-12-03 15:14:25 +00:00
|
|
|
QRegion region;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
PaintClipper::Iterator::Iterator()
|
2011-01-30 14:34:42 +00:00
|
|
|
: data(new Data)
|
|
|
|
{
|
2012-09-20 09:33:32 +00:00
|
|
|
if (clip() && effects->isOpenGLCompositing()) {
|
2017-12-03 15:14:25 +00:00
|
|
|
data->region = paintArea();
|
2008-02-25 11:32:21 +00:00
|
|
|
data->index = -1;
|
|
|
|
next(); // move to the first one
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (clip() && effects->compositingType() == XRenderCompositing) {
|
2013-02-06 06:58:33 +00:00
|
|
|
XFixesRegion region(paintArea());
|
|
|
|
xcb_xfixes_set_picture_clip_region(connection(), effects->xrenderBufferPicture(), region, 0, 0);
|
2008-02-25 11:32:21 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
PaintClipper::Iterator::~Iterator()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-02-25 11:32:21 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (clip() && effects->compositingType() == XRenderCompositing)
|
2013-02-06 06:58:33 +00:00
|
|
|
xcb_xfixes_set_picture_clip_region(connection(), effects->xrenderBufferPicture(), XCB_XFIXES_REGION_NONE, 0, 0);
|
2008-02-25 11:32:21 +00:00
|
|
|
#endif
|
|
|
|
delete data;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
bool PaintClipper::Iterator::isDone()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!clip())
|
2008-02-25 11:32:21 +00:00
|
|
|
return data->index == 1; // run once
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing())
|
2017-12-03 15:14:25 +00:00
|
|
|
return data->index >= data->region.rectCount(); // run once per each area
|
2008-02-25 11:32:21 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing)
|
2008-02-25 11:32:21 +00:00
|
|
|
return data->index == 1; // run once
|
|
|
|
#endif
|
2008-06-27 12:06:29 +00:00
|
|
|
abort();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
void PaintClipper::Iterator::next()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-02-25 11:32:21 +00:00
|
|
|
data->index++;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
QRect PaintClipper::Iterator::boundingRect() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!clip())
|
2008-02-25 11:32:21 +00:00
|
|
|
return infiniteRegion();
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing())
|
2017-12-03 15:14:25 +00:00
|
|
|
return *(data->region.begin() + data->index);
|
2008-02-25 11:32:21 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing)
|
2017-12-03 15:14:25 +00:00
|
|
|
return data->region.boundingRect();
|
2008-02-25 11:32:21 +00:00
|
|
|
#endif
|
2008-06-27 12:06:29 +00:00
|
|
|
abort();
|
2008-07-07 20:56:56 +00:00
|
|
|
return infiniteRegion();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2009-02-04 15:10:20 +00:00
|
|
|
/***************************************************************
|
|
|
|
Motion1D
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Motion1D::Motion1D(double initial, double strength, double smoothness)
|
|
|
|
: Motion<double>(initial, strength, smoothness)
|
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Motion1D::Motion1D(const Motion1D &other)
|
|
|
|
: Motion<double>(other)
|
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
|
|
|
Motion1D::~Motion1D()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Motion2D
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Motion2D::Motion2D(QPointF initial, double strength, double smoothness)
|
|
|
|
: Motion<QPointF>(initial, strength, smoothness)
|
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Motion2D::Motion2D(const Motion2D &other)
|
|
|
|
: Motion<QPointF>(other)
|
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
|
|
|
Motion2D::~Motion2D()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
2008-09-22 13:03:00 +00:00
|
|
|
/***************************************************************
|
|
|
|
WindowMotionManager
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowMotionManager::WindowMotionManager(bool useGlobalAnimationModifier)
|
|
|
|
: m_useGlobalAnimationModifier(useGlobalAnimationModifier)
|
2009-12-14 08:48:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
// TODO: Allow developer to modify motion attributes
|
|
|
|
} // TODO: What happens when the window moves by an external force?
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
WindowMotionManager::~WindowMotionManager()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::manage(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (m_managedWindows.contains(w))
|
2008-09-22 13:03:00 +00:00
|
|
|
return;
|
|
|
|
|
2009-02-04 15:10:20 +00:00
|
|
|
double strength = 0.08;
|
|
|
|
double smoothness = 4.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_useGlobalAnimationModifier && effects->animationTimeFactor()) {
|
|
|
|
// If the factor is == 0 then we just skip the calculation completely
|
2009-02-04 15:10:20 +00:00
|
|
|
strength = 0.08 / effects->animationTimeFactor();
|
|
|
|
smoothness = effects->animationTimeFactor() * 4.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion &motion = m_managedWindows[ w ];
|
|
|
|
motion.translation.setStrength(strength);
|
|
|
|
motion.translation.setSmoothness(smoothness);
|
|
|
|
motion.scale.setStrength(strength * 1.33);
|
|
|
|
motion.scale.setSmoothness(smoothness / 2.0);
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
motion.translation.setValue(w->pos());
|
|
|
|
motion.scale.setValue(QPointF(1.0, 1.0));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::unmanage(EffectWindow *w)
|
|
|
|
{
|
|
|
|
m_movingWindowsSet.remove(w);
|
|
|
|
m_managedWindows.remove(w);
|
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
void WindowMotionManager::unmanageAll()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-09-22 13:03:00 +00:00
|
|
|
m_managedWindows.clear();
|
2009-12-14 08:48:54 +00:00
|
|
|
m_movingWindowsSet.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::calculate(int time)
|
|
|
|
{
|
|
|
|
if (!effects->animationTimeFactor()) {
|
|
|
|
// Just skip it completely if the user wants no animation
|
2009-12-14 08:48:54 +00:00
|
|
|
m_movingWindowsSet.clear();
|
2008-09-22 13:03:00 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.begin();
|
2011-08-02 15:21:56 +00:00
|
|
|
for (; it != m_managedWindows.end(); ++it) {
|
2008-09-22 13:03:00 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
motion->translation.finish();
|
|
|
|
motion->scale.finish();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.begin();
|
2011-08-02 15:21:56 +00:00
|
|
|
for (; it != m_managedWindows.end(); ++it) {
|
2008-09-22 13:03:00 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
2011-04-25 23:00:37 +00:00
|
|
|
int stopped = 0;
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
// TODO: What happens when distance() == 0 but we are still moving fast?
|
|
|
|
// TODO: Motion needs to be calculated from the window's center
|
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
Motion2D *trans = &motion->translation;
|
|
|
|
if (trans->distance().isNull())
|
|
|
|
++stopped;
|
|
|
|
else {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Still moving
|
2011-04-25 23:00:37 +00:00
|
|
|
trans->calculate(time);
|
2011-06-20 19:56:56 +00:00
|
|
|
const short fx = trans->target().x() <= trans->startValue().x() ? -1 : 1;
|
|
|
|
const short fy = trans->target().y() <= trans->startValue().y() ? -1 : 1;
|
2011-04-25 23:00:37 +00:00
|
|
|
if (trans->distance().x()*fx/0.5 < 1.0 && trans->velocity().x()*fx/0.2 < 1.0 &&
|
|
|
|
trans->distance().y()*fy/0.5 < 1.0 && trans->velocity().y()*fy/0.2 < 1.0) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Hide tiny oscillations
|
2008-09-22 13:03:00 +00:00
|
|
|
motion->translation.finish();
|
2011-04-25 23:00:37 +00:00
|
|
|
++stopped;
|
2008-09-22 13:03:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
Motion2D *scale = &motion->scale;
|
|
|
|
if (scale->distance().isNull())
|
|
|
|
++stopped;
|
|
|
|
else {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Still scaling
|
2011-04-25 23:00:37 +00:00
|
|
|
scale->calculate(time);
|
|
|
|
const short fx = scale->target().x() < 1.0 ? -1 : 1;
|
|
|
|
const short fy = scale->target().y() < 1.0 ? -1 : 1;
|
|
|
|
if (scale->distance().x()*fx/0.001 < 1.0 && scale->velocity().x()*fx/0.05 < 1.0 &&
|
|
|
|
scale->distance().y()*fy/0.001 < 1.0 && scale->velocity().y()*fy/0.05 < 1.0) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Hide tiny oscillations
|
2008-09-22 13:03:00 +00:00
|
|
|
motion->scale.finish();
|
2011-04-25 23:00:37 +00:00
|
|
|
++stopped;
|
2008-09-22 13:03:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
// We just finished this window's motion
|
2011-04-25 23:00:37 +00:00
|
|
|
if (stopped == 2)
|
2011-01-30 14:34:42 +00:00
|
|
|
m_movingWindowsSet.remove(it.key());
|
2008-09-22 13:03:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2008-09-29 02:25:02 +00:00
|
|
|
void WindowMotionManager::reset()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.begin();
|
2011-08-02 15:21:56 +00:00
|
|
|
for (; it != m_managedWindows.end(); ++it) {
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
EffectWindow *window = it.key();
|
|
|
|
motion->translation.setTarget(window->pos());
|
|
|
|
motion->translation.finish();
|
|
|
|
motion->scale.setTarget(QPointF(1.0, 1.0));
|
|
|
|
motion->scale.finish();
|
2008-09-29 02:25:02 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-29 02:25:02 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::reset(EffectWindow *w)
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.find(w);
|
|
|
|
if (it == m_managedWindows.end())
|
2008-09-29 02:25:02 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
motion->translation.setTarget(w->pos());
|
|
|
|
motion->translation.finish();
|
|
|
|
motion->scale.setTarget(QPointF(1.0, 1.0));
|
|
|
|
motion->scale.finish();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-29 02:25:02 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::apply(EffectWindow *w, WindowPaintData &data)
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.find(w);
|
|
|
|
if (it == m_managedWindows.end())
|
2008-09-22 13:03:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid)
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
2012-05-28 12:45:46 +00:00
|
|
|
data += (motion->translation.value() - QPointF(w->x(), w->y()));
|
2012-05-28 10:00:31 +00:00
|
|
|
data *= QVector2D(motion->scale.value());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::moveWindow(EffectWindow *w, QPoint target, double scale, double yScale)
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.find(w);
|
|
|
|
if (it == m_managedWindows.end())
|
2008-09-22 13:03:00 +00:00
|
|
|
abort(); // Notify the effect author that they did something wrong
|
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (yScale == 0.0)
|
2008-09-22 13:03:00 +00:00
|
|
|
yScale = scale;
|
2011-01-30 14:34:42 +00:00
|
|
|
QPointF scalePoint(scale, yScale);
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
if (motion->translation.value() == target && motion->scale.value() == scalePoint)
|
2008-09-22 13:03:00 +00:00
|
|
|
return; // Window already at that position
|
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
motion->translation.setTarget(target);
|
|
|
|
motion->scale.setTarget(scalePoint);
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2009-12-14 08:48:54 +00:00
|
|
|
m_movingWindowsSet << w;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRectF WindowMotionManager::transformedGeometry(EffectWindow *w) const
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::const_iterator it = m_managedWindows.constFind(w);
|
|
|
|
if (it == m_managedWindows.end())
|
|
|
|
return w->geometry();
|
|
|
|
|
|
|
|
const WindowMotion *motion = &it.value();
|
2011-01-30 14:34:42 +00:00
|
|
|
QRectF geometry(w->geometry());
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
// TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid)
|
2011-04-25 23:00:37 +00:00
|
|
|
geometry.moveTo(motion->translation.value());
|
|
|
|
geometry.setWidth(geometry.width() * motion->scale.value().x());
|
|
|
|
geometry.setHeight(geometry.height() * motion->scale.value().y());
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
return geometry;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::setTransformedGeometry(EffectWindow *w, const QRectF &geometry)
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.find(w);
|
|
|
|
if (it == m_managedWindows.end())
|
|
|
|
return;
|
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
motion->translation.setValue(geometry.topLeft());
|
|
|
|
motion->scale.setValue(QPointF(geometry.width() / qreal(w->width()), geometry.height() / qreal(w->height())));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-03-18 09:27:01 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRectF WindowMotionManager::targetGeometry(EffectWindow *w) const
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::const_iterator it = m_managedWindows.constFind(w);
|
|
|
|
if (it == m_managedWindows.end())
|
|
|
|
return w->geometry();
|
|
|
|
|
|
|
|
const WindowMotion *motion = &it.value();
|
2011-01-30 14:34:42 +00:00
|
|
|
QRectF geometry(w->geometry());
|
2009-02-22 13:04:16 +00:00
|
|
|
|
|
|
|
// TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid)
|
2011-04-25 23:00:37 +00:00
|
|
|
geometry.moveTo(motion->translation.target());
|
|
|
|
geometry.setWidth(geometry.width() * motion->scale.target().x());
|
|
|
|
geometry.setHeight(geometry.height() * motion->scale.target().y());
|
2009-02-22 13:04:16 +00:00
|
|
|
|
|
|
|
return geometry;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-22 13:04:16 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
EffectWindow* WindowMotionManager::windowAtPoint(QPoint point, bool useStackingOrder) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(useStackingOrder);
|
2008-09-22 13:03:00 +00:00
|
|
|
// TODO: Stacking order uses EffectsHandler::stackingOrder() then filters by m_managedWindows
|
2009-12-08 08:37:01 +00:00
|
|
|
QHash< EffectWindow*, WindowMotion >::ConstIterator it = m_managedWindows.constBegin();
|
2011-01-30 14:34:42 +00:00
|
|
|
while (it != m_managedWindows.constEnd()) {
|
|
|
|
if (transformedGeometry(it.key()).contains(point))
|
2009-12-08 08:37:01 +00:00
|
|
|
return it.key();
|
|
|
|
++it;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2014-01-08 10:43:02 +00:00
|
|
|
return nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2010-08-07 14:08:34 +00:00
|
|
|
/***************************************************************
|
|
|
|
EffectFramePrivate
|
|
|
|
***************************************************************/
|
|
|
|
class EffectFramePrivate
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
EffectFramePrivate();
|
|
|
|
~EffectFramePrivate();
|
2010-08-07 14:08:34 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool crossFading;
|
|
|
|
qreal crossFadeProgress;
|
2015-12-03 08:50:40 +00:00
|
|
|
QMatrix4x4 screenProjectionMatrix;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2010-08-07 14:08:34 +00:00
|
|
|
|
|
|
|
EffectFramePrivate::EffectFramePrivate()
|
2011-01-30 14:34:42 +00:00
|
|
|
: crossFading(false)
|
|
|
|
, crossFadeProgress(1.0)
|
|
|
|
{
|
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
|
|
|
EffectFramePrivate::~EffectFramePrivate()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
2009-02-21 04:53:13 +00:00
|
|
|
/***************************************************************
|
|
|
|
EffectFrame
|
|
|
|
***************************************************************/
|
2010-07-18 16:32:37 +00:00
|
|
|
EffectFrame::EffectFrame()
|
2011-01-30 14:34:42 +00:00
|
|
|
: d(new EffectFramePrivate)
|
|
|
|
{
|
|
|
|
}
|
2009-02-21 04:53:13 +00:00
|
|
|
|
|
|
|
EffectFrame::~EffectFrame()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
delete d;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
|
|
|
qreal EffectFrame::crossFadeProgress() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
return d->crossFadeProgress;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void EffectFrame::setCrossFadeProgress(qreal progress)
|
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
d->crossFadeProgress = progress;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
|
|
|
bool EffectFrame::isCrossFade() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
return d->crossFading;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void EffectFrame::enableCrossFade(bool enable)
|
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
d->crossFading = enable;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-21 04:53:13 +00:00
|
|
|
|
2015-12-03 08:50:40 +00:00
|
|
|
QMatrix4x4 EffectFrame::screenProjectionMatrix() const
|
|
|
|
{
|
|
|
|
return d->screenProjectionMatrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectFrame::setScreenProjectionMatrix(const QMatrix4x4 &spm)
|
|
|
|
{
|
|
|
|
d->screenProjectionMatrix = spm;
|
|
|
|
}
|
|
|
|
|
[libkwineffects] Add TimeLine helper
Summary:
Most effects use QTimeLine in the following manner
```lang=cpp
if (...) {
m_timeline->setCurrentTime(m_timeline->currentTime() + time);
} else {
m_timeline->setCurrentTime(m_timeline->currentTime() - time);
}
```
Because effects do not rely on a timer that QTimeLine has, they can't
toggle direction of the QTimeLine, which makes somewhat harder to write
effects. In some cases that's obvious what condition to use to figure
out whether to add or subtract `time`, but there are cases when it's
not. In addition to that, setCurrentTime allows to have negative
currentTime, which in some cases causes bugs.
And overall, the way effects use QTimeLine is really hack-ish. It makes
more sense just to use an integer accumulator(like the Fall Apart
effect is doing) than to use QTimeLine.
Another problem with QTimeLine is that it's a QObject and some effects
do
```lang=cpp
class WindowInfo
{
public:
~WindowInfo();
QTimeLine *timeLine;
};
WindowInfo::~WindowInfo()
{
delete timeLine;
}
// ...
QHash<EffectWindow*, WindowInfo> m_windows;
```
which is unsafe.
This change adds the TimeLine class. The TimeLine class is a timeline
helper that designed specifically for needs of effects.
Demo
```lang=cpp
TimeLine timeLine(1000, TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // false
timeLine.update(420);
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.toggleDirection();
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(100);
timeLine.value(); // 0.32
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(1000);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // true
```
Test Plan: Ran tests.
Reviewers: #kwin, davidedmundson, graesslin
Reviewed By: #kwin, davidedmundson, graesslin
Subscribers: romangg, graesslin, anthonyfieroni, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D13740
2018-06-28 18:13:43 +00:00
|
|
|
/***************************************************************
|
|
|
|
TimeLine
|
|
|
|
***************************************************************/
|
|
|
|
|
|
|
|
class Q_DECL_HIDDEN TimeLine::Data : public QSharedData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::chrono::milliseconds duration;
|
|
|
|
Direction direction;
|
|
|
|
QEasingCurve easingCurve;
|
|
|
|
|
|
|
|
std::chrono::milliseconds elapsed = std::chrono::milliseconds::zero();
|
|
|
|
bool done = false;
|
[libkwineffects] Introduce timeline redirect modes
Summary:
The redirect modes control behavior of the timeline when its direction
is changed at the start or target position. For example, consider the
following piece of code:
TimeLine timeLine(1000ms, TimeLine::Forward);
timeLine.setDirection(TimeLine::Backward);
What should happen when the direction of the timeline was changed to go
backward? Should the current value of the timeline go from 1 to 0, or
should the timeline stop its "execution"?
In the relaxed mode, the timeline will go from 1 to 0.
In the strict mode, the timeline will stop its execution.
Different effects may prefer different modes for source and target
positions. For example, most C++ effect would prefer relaxed mode for
source position, and strict mode for target position. On the other side,
scripted effects(AnimationEffect) would prefer strict mode for source
position, and relaxed mode for target position(because of set).
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16447
2018-10-24 09:11:17 +00:00
|
|
|
RedirectMode sourceRedirectMode = RedirectMode::Relaxed;
|
|
|
|
RedirectMode targetRedirectMode = RedirectMode::Strict;
|
[libkwineffects] Add TimeLine helper
Summary:
Most effects use QTimeLine in the following manner
```lang=cpp
if (...) {
m_timeline->setCurrentTime(m_timeline->currentTime() + time);
} else {
m_timeline->setCurrentTime(m_timeline->currentTime() - time);
}
```
Because effects do not rely on a timer that QTimeLine has, they can't
toggle direction of the QTimeLine, which makes somewhat harder to write
effects. In some cases that's obvious what condition to use to figure
out whether to add or subtract `time`, but there are cases when it's
not. In addition to that, setCurrentTime allows to have negative
currentTime, which in some cases causes bugs.
And overall, the way effects use QTimeLine is really hack-ish. It makes
more sense just to use an integer accumulator(like the Fall Apart
effect is doing) than to use QTimeLine.
Another problem with QTimeLine is that it's a QObject and some effects
do
```lang=cpp
class WindowInfo
{
public:
~WindowInfo();
QTimeLine *timeLine;
};
WindowInfo::~WindowInfo()
{
delete timeLine;
}
// ...
QHash<EffectWindow*, WindowInfo> m_windows;
```
which is unsafe.
This change adds the TimeLine class. The TimeLine class is a timeline
helper that designed specifically for needs of effects.
Demo
```lang=cpp
TimeLine timeLine(1000, TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // false
timeLine.update(420);
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.toggleDirection();
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(100);
timeLine.value(); // 0.32
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(1000);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // true
```
Test Plan: Ran tests.
Reviewers: #kwin, davidedmundson, graesslin
Reviewed By: #kwin, davidedmundson, graesslin
Subscribers: romangg, graesslin, anthonyfieroni, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D13740
2018-06-28 18:13:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TimeLine::TimeLine(std::chrono::milliseconds duration, Direction direction)
|
|
|
|
: d(new Data)
|
|
|
|
{
|
|
|
|
Q_ASSERT(duration > std::chrono::milliseconds::zero());
|
|
|
|
d->duration = duration;
|
|
|
|
d->direction = direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeLine::TimeLine(const TimeLine &other)
|
|
|
|
: d(other.d)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeLine::~TimeLine() = default;
|
|
|
|
|
|
|
|
qreal TimeLine::progress() const
|
|
|
|
{
|
|
|
|
return static_cast<qreal>(d->elapsed.count()) / d->duration.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal TimeLine::value() const
|
|
|
|
{
|
|
|
|
const qreal t = progress();
|
|
|
|
return d->easingCurve.valueForProgress(
|
|
|
|
d->direction == Backward ? 1.0 - t : t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::update(std::chrono::milliseconds delta)
|
|
|
|
{
|
|
|
|
Q_ASSERT(delta >= std::chrono::milliseconds::zero());
|
|
|
|
if (d->done) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->elapsed += delta;
|
|
|
|
if (d->elapsed >= d->duration) {
|
|
|
|
d->done = true;
|
|
|
|
d->elapsed = d->duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::chrono::milliseconds TimeLine::elapsed() const
|
|
|
|
{
|
|
|
|
return d->elapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::setElapsed(std::chrono::milliseconds elapsed)
|
|
|
|
{
|
|
|
|
Q_ASSERT(elapsed >= std::chrono::milliseconds::zero());
|
|
|
|
if (elapsed == d->elapsed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reset();
|
|
|
|
update(elapsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::chrono::milliseconds TimeLine::duration() const
|
|
|
|
{
|
|
|
|
return d->duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::setDuration(std::chrono::milliseconds duration)
|
|
|
|
{
|
|
|
|
Q_ASSERT(duration > std::chrono::milliseconds::zero());
|
|
|
|
if (duration == d->duration) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->elapsed = std::chrono::milliseconds(qRound(progress() * duration.count()));
|
|
|
|
d->duration = duration;
|
|
|
|
if (d->elapsed == d->duration) {
|
|
|
|
d->done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeLine::Direction TimeLine::direction() const
|
|
|
|
{
|
|
|
|
return d->direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::setDirection(TimeLine::Direction direction)
|
|
|
|
{
|
|
|
|
if (d->direction == direction) {
|
|
|
|
return;
|
|
|
|
}
|
[libkwineffects] Introduce timeline redirect modes
Summary:
The redirect modes control behavior of the timeline when its direction
is changed at the start or target position. For example, consider the
following piece of code:
TimeLine timeLine(1000ms, TimeLine::Forward);
timeLine.setDirection(TimeLine::Backward);
What should happen when the direction of the timeline was changed to go
backward? Should the current value of the timeline go from 1 to 0, or
should the timeline stop its "execution"?
In the relaxed mode, the timeline will go from 1 to 0.
In the strict mode, the timeline will stop its execution.
Different effects may prefer different modes for source and target
positions. For example, most C++ effect would prefer relaxed mode for
source position, and strict mode for target position. On the other side,
scripted effects(AnimationEffect) would prefer strict mode for source
position, and relaxed mode for target position(because of set).
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16447
2018-10-24 09:11:17 +00:00
|
|
|
|
|
|
|
d->direction = direction;
|
|
|
|
|
|
|
|
if (d->elapsed > std::chrono::milliseconds::zero()
|
|
|
|
|| d->sourceRedirectMode == RedirectMode::Strict) {
|
[libkwineffects] Add TimeLine helper
Summary:
Most effects use QTimeLine in the following manner
```lang=cpp
if (...) {
m_timeline->setCurrentTime(m_timeline->currentTime() + time);
} else {
m_timeline->setCurrentTime(m_timeline->currentTime() - time);
}
```
Because effects do not rely on a timer that QTimeLine has, they can't
toggle direction of the QTimeLine, which makes somewhat harder to write
effects. In some cases that's obvious what condition to use to figure
out whether to add or subtract `time`, but there are cases when it's
not. In addition to that, setCurrentTime allows to have negative
currentTime, which in some cases causes bugs.
And overall, the way effects use QTimeLine is really hack-ish. It makes
more sense just to use an integer accumulator(like the Fall Apart
effect is doing) than to use QTimeLine.
Another problem with QTimeLine is that it's a QObject and some effects
do
```lang=cpp
class WindowInfo
{
public:
~WindowInfo();
QTimeLine *timeLine;
};
WindowInfo::~WindowInfo()
{
delete timeLine;
}
// ...
QHash<EffectWindow*, WindowInfo> m_windows;
```
which is unsafe.
This change adds the TimeLine class. The TimeLine class is a timeline
helper that designed specifically for needs of effects.
Demo
```lang=cpp
TimeLine timeLine(1000, TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // false
timeLine.update(420);
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.toggleDirection();
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(100);
timeLine.value(); // 0.32
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(1000);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // true
```
Test Plan: Ran tests.
Reviewers: #kwin, davidedmundson, graesslin
Reviewed By: #kwin, davidedmundson, graesslin
Subscribers: romangg, graesslin, anthonyfieroni, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D13740
2018-06-28 18:13:43 +00:00
|
|
|
d->elapsed = d->duration - d->elapsed;
|
|
|
|
}
|
[libkwineffects] Introduce timeline redirect modes
Summary:
The redirect modes control behavior of the timeline when its direction
is changed at the start or target position. For example, consider the
following piece of code:
TimeLine timeLine(1000ms, TimeLine::Forward);
timeLine.setDirection(TimeLine::Backward);
What should happen when the direction of the timeline was changed to go
backward? Should the current value of the timeline go from 1 to 0, or
should the timeline stop its "execution"?
In the relaxed mode, the timeline will go from 1 to 0.
In the strict mode, the timeline will stop its execution.
Different effects may prefer different modes for source and target
positions. For example, most C++ effect would prefer relaxed mode for
source position, and strict mode for target position. On the other side,
scripted effects(AnimationEffect) would prefer strict mode for source
position, and relaxed mode for target position(because of set).
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16447
2018-10-24 09:11:17 +00:00
|
|
|
|
|
|
|
if (d->done && d->targetRedirectMode == RedirectMode::Relaxed) {
|
|
|
|
d->done = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->elapsed >= d->duration) {
|
|
|
|
d->done = true;
|
|
|
|
}
|
[libkwineffects] Add TimeLine helper
Summary:
Most effects use QTimeLine in the following manner
```lang=cpp
if (...) {
m_timeline->setCurrentTime(m_timeline->currentTime() + time);
} else {
m_timeline->setCurrentTime(m_timeline->currentTime() - time);
}
```
Because effects do not rely on a timer that QTimeLine has, they can't
toggle direction of the QTimeLine, which makes somewhat harder to write
effects. In some cases that's obvious what condition to use to figure
out whether to add or subtract `time`, but there are cases when it's
not. In addition to that, setCurrentTime allows to have negative
currentTime, which in some cases causes bugs.
And overall, the way effects use QTimeLine is really hack-ish. It makes
more sense just to use an integer accumulator(like the Fall Apart
effect is doing) than to use QTimeLine.
Another problem with QTimeLine is that it's a QObject and some effects
do
```lang=cpp
class WindowInfo
{
public:
~WindowInfo();
QTimeLine *timeLine;
};
WindowInfo::~WindowInfo()
{
delete timeLine;
}
// ...
QHash<EffectWindow*, WindowInfo> m_windows;
```
which is unsafe.
This change adds the TimeLine class. The TimeLine class is a timeline
helper that designed specifically for needs of effects.
Demo
```lang=cpp
TimeLine timeLine(1000, TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // false
timeLine.update(420);
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.toggleDirection();
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(100);
timeLine.value(); // 0.32
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(1000);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // true
```
Test Plan: Ran tests.
Reviewers: #kwin, davidedmundson, graesslin
Reviewed By: #kwin, davidedmundson, graesslin
Subscribers: romangg, graesslin, anthonyfieroni, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D13740
2018-06-28 18:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::toggleDirection()
|
|
|
|
{
|
|
|
|
setDirection(d->direction == Forward ? Backward : Forward);
|
|
|
|
}
|
|
|
|
|
|
|
|
QEasingCurve TimeLine::easingCurve() const
|
|
|
|
{
|
|
|
|
return d->easingCurve;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::setEasingCurve(const QEasingCurve &easingCurve)
|
|
|
|
{
|
|
|
|
d->easingCurve = easingCurve;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::setEasingCurve(QEasingCurve::Type type)
|
|
|
|
{
|
|
|
|
d->easingCurve.setType(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TimeLine::running() const
|
|
|
|
{
|
|
|
|
return d->elapsed != std::chrono::milliseconds::zero()
|
|
|
|
&& d->elapsed != d->duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TimeLine::done() const
|
|
|
|
{
|
|
|
|
return d->done;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::reset()
|
|
|
|
{
|
|
|
|
d->elapsed = std::chrono::milliseconds::zero();
|
|
|
|
d->done = false;
|
|
|
|
}
|
|
|
|
|
[libkwineffects] Introduce timeline redirect modes
Summary:
The redirect modes control behavior of the timeline when its direction
is changed at the start or target position. For example, consider the
following piece of code:
TimeLine timeLine(1000ms, TimeLine::Forward);
timeLine.setDirection(TimeLine::Backward);
What should happen when the direction of the timeline was changed to go
backward? Should the current value of the timeline go from 1 to 0, or
should the timeline stop its "execution"?
In the relaxed mode, the timeline will go from 1 to 0.
In the strict mode, the timeline will stop its execution.
Different effects may prefer different modes for source and target
positions. For example, most C++ effect would prefer relaxed mode for
source position, and strict mode for target position. On the other side,
scripted effects(AnimationEffect) would prefer strict mode for source
position, and relaxed mode for target position(because of set).
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16447
2018-10-24 09:11:17 +00:00
|
|
|
TimeLine::RedirectMode TimeLine::sourceRedirectMode() const
|
|
|
|
{
|
|
|
|
return d->sourceRedirectMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::setSourceRedirectMode(RedirectMode mode)
|
|
|
|
{
|
|
|
|
d->sourceRedirectMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeLine::RedirectMode TimeLine::targetRedirectMode() const
|
|
|
|
{
|
|
|
|
return d->targetRedirectMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeLine::setTargetRedirectMode(RedirectMode mode)
|
|
|
|
{
|
|
|
|
d->targetRedirectMode = mode;
|
|
|
|
}
|
|
|
|
|
[libkwineffects] Add TimeLine helper
Summary:
Most effects use QTimeLine in the following manner
```lang=cpp
if (...) {
m_timeline->setCurrentTime(m_timeline->currentTime() + time);
} else {
m_timeline->setCurrentTime(m_timeline->currentTime() - time);
}
```
Because effects do not rely on a timer that QTimeLine has, they can't
toggle direction of the QTimeLine, which makes somewhat harder to write
effects. In some cases that's obvious what condition to use to figure
out whether to add or subtract `time`, but there are cases when it's
not. In addition to that, setCurrentTime allows to have negative
currentTime, which in some cases causes bugs.
And overall, the way effects use QTimeLine is really hack-ish. It makes
more sense just to use an integer accumulator(like the Fall Apart
effect is doing) than to use QTimeLine.
Another problem with QTimeLine is that it's a QObject and some effects
do
```lang=cpp
class WindowInfo
{
public:
~WindowInfo();
QTimeLine *timeLine;
};
WindowInfo::~WindowInfo()
{
delete timeLine;
}
// ...
QHash<EffectWindow*, WindowInfo> m_windows;
```
which is unsafe.
This change adds the TimeLine class. The TimeLine class is a timeline
helper that designed specifically for needs of effects.
Demo
```lang=cpp
TimeLine timeLine(1000, TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // false
timeLine.update(420);
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.toggleDirection();
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(100);
timeLine.value(); // 0.32
timeLine.running(); // true
timeLine.done(); // false
timeLine.update(1000);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // true
```
Test Plan: Ran tests.
Reviewers: #kwin, davidedmundson, graesslin
Reviewed By: #kwin, davidedmundson, graesslin
Subscribers: romangg, graesslin, anthonyfieroni, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D13740
2018-06-28 18:13:43 +00:00
|
|
|
TimeLine &TimeLine::operator=(const TimeLine &other)
|
|
|
|
{
|
|
|
|
d = other.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
2011-02-25 19:25:21 +00:00
|
|
|
|
2019-11-01 17:14:55 +00:00
|
|
|
#include "moc_kwinglobals.cpp"
|