2010-05-11 18:45:39 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Philip Falkner <philip.falkner@gmail.com>
|
2013-03-12 12:17:53 +00:00
|
|
|
Copyright (C) 2009 Martin Gräßlin <mgraesslin@kde.org>
|
2010-05-11 18:45:39 +00:00
|
|
|
Copyright (C) 2010 Alexandre Pereira <pereira.alex@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "glide.h"
|
2012-09-12 18:31:37 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "glideconfig.h"
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QTimeLine>
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2013-11-18 12:52:38 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <fixx11h.h>
|
|
|
|
|
2010-05-11 18:45:39 +00:00
|
|
|
// Effect is based on fade effect by Philip Falkner
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(glide, GlideEffect)
|
|
|
|
KWIN_EFFECT_SUPPORTED(glide, GlideEffect::supported())
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2010-11-02 20:33:54 +00:00
|
|
|
static const int IsGlideWindow = 0x22A982D4;
|
2011-11-22 21:35:44 +00:00
|
|
|
static Atom slideAtom;
|
2010-11-02 20:33:54 +00:00
|
|
|
|
2010-05-11 18:45:39 +00:00
|
|
|
GlideEffect::GlideEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-11-22 21:35:44 +00:00
|
|
|
slideAtom = XInternAtom( display(), "_KDE_SLIDE", False );
|
|
|
|
effects->registerPropertyType( slideAtom, true );
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-11-22 21:35:44 +00:00
|
|
|
GlideEffect::~GlideEffect()
|
|
|
|
{
|
|
|
|
effects->registerPropertyType( slideAtom, false );
|
|
|
|
}
|
|
|
|
|
2010-05-11 18:45:39 +00:00
|
|
|
bool GlideEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-09-20 09:33:32 +00:00
|
|
|
return effects->isOpenGLCompositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void GlideEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2012-09-12 18:31:37 +00:00
|
|
|
// Fetch config with KConfigXT
|
|
|
|
GlideConfig::self()->readConfig();
|
2012-11-25 17:46:13 +00:00
|
|
|
duration = animationTime<GlideConfig>(350);
|
2012-09-12 18:31:37 +00:00
|
|
|
effect = (EffectStyle) GlideConfig::glideEffect();
|
|
|
|
angle = GlideConfig::glideAngle();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void GlideEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (!windows.isEmpty())
|
2010-05-11 18:45:39 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void GlideEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
InfoHash::iterator info = windows.find(w);
|
|
|
|
if (info != windows.end()) {
|
2010-11-02 20:33:54 +00:00
|
|
|
data.setTransformed();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->added)
|
2011-03-14 21:50:05 +00:00
|
|
|
info->timeLine->setCurrentTime(info->timeLine->currentTime() + time);
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (info->closed) {
|
2011-03-14 21:50:05 +00:00
|
|
|
info->timeLine->setCurrentTime(info->timeLine->currentTime() - time);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->deleted)
|
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
|
2010-11-02 20:33:54 +00:00
|
|
|
// if the window isn't to be painted, then let's make sure
|
|
|
|
// to track its progress
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info != windows.end() && !w->isPaintingEnabled() && !effects->activeFullScreenEffect())
|
2010-11-02 20:33:54 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void GlideEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
InfoHash::const_iterator info = windows.constFind(w);
|
|
|
|
if (info != windows.constEnd()) {
|
2011-03-14 21:50:05 +00:00
|
|
|
const double progress = info->timeLine->currentValue();
|
2012-06-02 19:54:18 +00:00
|
|
|
data.setRotationAxis(Qt::XAxis);
|
|
|
|
data.setRotationAngle(angle * (1 - progress));
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity(progress);
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(effect) {
|
|
|
|
default:
|
|
|
|
case GlideInOut:
|
|
|
|
if (info->added)
|
2013-11-19 11:49:17 +00:00
|
|
|
glideIn(w, data, info);
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (info->closed)
|
2013-11-19 11:49:17 +00:00
|
|
|
glideOut(w, data, info);
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
|
|
|
case GlideOutIn:
|
|
|
|
if (info->added)
|
2013-11-19 11:49:17 +00:00
|
|
|
glideOut(w, data, info);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->closed)
|
2013-11-19 11:49:17 +00:00
|
|
|
glideIn(w, data, info);
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
2013-11-19 11:49:17 +00:00
|
|
|
case GlideIn: glideIn(w, data, info); break;
|
|
|
|
case GlideOut: glideOut(w, data, info); break;
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2013-11-19 11:49:17 +00:00
|
|
|
void GlideEffect::glideIn(EffectWindow* w, WindowPaintData& data, const InfoHash::const_iterator &info)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-14 21:50:05 +00:00
|
|
|
const double progress = info->timeLine->currentValue();
|
2012-05-28 10:00:31 +00:00
|
|
|
data *= progress;
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(int(w->width() / 2 * (1 - progress)), int(w->height() / 2 * (1 - progress)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2013-11-19 11:49:17 +00:00
|
|
|
void GlideEffect::glideOut(EffectWindow* w, WindowPaintData& data, const InfoHash::const_iterator &info)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-14 21:50:05 +00:00
|
|
|
const double progress = info->timeLine->currentValue();
|
2012-05-28 10:00:31 +00:00
|
|
|
data *= (2 - progress);
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(- int(w->width() / 2 * (1 - progress)), - int(w->height() / 2 * (1 - progress)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::postPaintWindow(EffectWindow* w)
|
|
|
|
{
|
|
|
|
InfoHash::iterator info = windows.find(w);
|
|
|
|
if (info != windows.end()) {
|
2011-03-14 21:50:05 +00:00
|
|
|
if (info->added && info->timeLine->currentValue() == 1.0) {
|
2011-01-30 14:34:42 +00:00
|
|
|
windows.remove(w);
|
2010-05-11 18:45:39 +00:00
|
|
|
effects->addRepaintFull();
|
2011-03-14 21:50:05 +00:00
|
|
|
} else if (info->closed && info->timeLine->currentValue() == 0.0) {
|
2010-11-02 20:33:54 +00:00
|
|
|
info->closed = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->deleted) {
|
|
|
|
windows.remove(w);
|
2010-05-11 18:45:39 +00:00
|
|
|
w->unrefWindow();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->added || info->closed)
|
|
|
|
w->addRepaintFull();
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintWindow(w);
|
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void GlideEffect::slotWindowAdded(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!isGlideWindow(w))
|
2010-05-11 18:45:39 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
w->setData(IsGlideWindow, true);
|
|
|
|
const void *addGrab = w->data(WindowAddedGrabRole).value<void*>();
|
|
|
|
if (addGrab && addGrab != this)
|
2010-11-02 20:33:54 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
w->setData(WindowAddedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
|
|
|
|
|
|
|
InfoHash::iterator it = windows.find(w);
|
|
|
|
WindowInfo *info = (it == windows.end()) ? &windows[w] : &it.value();
|
2010-11-02 20:33:54 +00:00
|
|
|
info->added = true;
|
|
|
|
info->closed = false;
|
|
|
|
info->deleted = false;
|
2011-03-14 21:50:05 +00:00
|
|
|
delete info->timeLine;
|
|
|
|
info->timeLine = new QTimeLine(duration);
|
|
|
|
info->timeLine->setCurveShape(QTimeLine::EaseOutCurve);
|
2010-05-11 18:45:39 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void GlideEffect::slotWindowClosed(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!isGlideWindow(w))
|
2010-11-02 20:33:54 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
const void *closeGrab = w->data(WindowClosedGrabRole).value<void*>();
|
|
|
|
if (closeGrab && closeGrab != this)
|
2010-05-11 18:45:39 +00:00
|
|
|
return;
|
|
|
|
w->refWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
|
|
|
|
|
|
|
InfoHash::iterator it = windows.find(w);
|
|
|
|
WindowInfo *info = (it == windows.end()) ? &windows[w] : &it.value();
|
2010-11-02 20:33:54 +00:00
|
|
|
info->added = false;
|
|
|
|
info->closed = true;
|
|
|
|
info->deleted = true;
|
2011-03-14 21:50:05 +00:00
|
|
|
delete info->timeLine;
|
|
|
|
info->timeLine = new QTimeLine(duration);
|
|
|
|
info->timeLine->setCurveShape(QTimeLine::EaseInCurve);
|
|
|
|
info->timeLine->setCurrentTime(info->timeLine->duration());
|
2010-05-11 18:45:39 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-02-27 09:47:42 +00:00
|
|
|
void GlideEffect::slotWindowDeleted(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
windows.remove(w);
|
|
|
|
}
|
2010-05-11 18:45:39 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool GlideEffect::isGlideWindow(EffectWindow* w)
|
|
|
|
{
|
|
|
|
if (effects->activeFullScreenEffect())
|
2010-11-02 20:33:54 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->data(IsGlideWindow).toBool())
|
2010-11-02 20:33:54 +00:00
|
|
|
return true;
|
2011-11-22 21:35:44 +00:00
|
|
|
if (!w->readProperty( slideAtom, slideAtom, 32 ).isNull())
|
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->hasDecoration())
|
2010-11-02 20:33:54 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!w->isManaged() || w->isMenu() || w->isNotification() || w->isDesktop() ||
|
2011-06-24 10:19:47 +00:00
|
|
|
w->isDock() || w->isSplash() || w->isToolbar() ||
|
2013-07-23 05:02:52 +00:00
|
|
|
w->windowClass() == QStringLiteral("dashboard dashboard"))
|
2010-05-11 18:45:39 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-03-14 21:50:05 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool GlideEffect::isActive() const
|
|
|
|
{
|
|
|
|
return !windows.isEmpty();
|
|
|
|
}
|
|
|
|
|
2011-03-14 21:50:05 +00:00
|
|
|
GlideEffect::WindowInfo::WindowInfo()
|
|
|
|
: deleted(false)
|
|
|
|
, added(false)
|
|
|
|
, closed(false)
|
|
|
|
, timeLine(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-29 09:15:15 +00:00
|
|
|
GlideEffect::WindowInfo::~WindowInfo()
|
|
|
|
{
|
|
|
|
delete timeLine;
|
|
|
|
}
|
|
|
|
|
2010-05-11 18:45:39 +00:00
|
|
|
} // namespace
|