2009-07-23 19:06:50 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Marco Martin notmart@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 "slidingpopups.h"
|
|
|
|
|
|
|
|
#include <kdebug.h>
|
2011-02-17 18:35:08 +00:00
|
|
|
#include <KDE/KConfigGroup>
|
2009-07-23 19:06:50 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(slidingpopups, SlidingPopupsEffect)
|
2009-07-23 19:06:50 +00:00
|
|
|
|
|
|
|
SlidingPopupsEffect::SlidingPopupsEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
KConfigGroup conf = effects->effectConfig("SlidingPopups");
|
|
|
|
mFadeInTime = animationTime(conf, "SlideInTime", 250);
|
|
|
|
mFadeOutTime = animationTime(conf, "SlideOutTime", 250);
|
|
|
|
mAtom = XInternAtom(display(), "_KDE_SLIDE", False);
|
|
|
|
effects->registerPropertyType(mAtom, true);
|
2009-07-23 19:06:50 +00:00
|
|
|
// TODO hackish way to announce support, make better after 4.0
|
|
|
|
unsigned char dummy = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
XChangeProperty(display(), rootWindow(), mAtom, mAtom, 8, PropModeReplace, &dummy, 1);
|
2011-02-25 21:06:02 +00:00
|
|
|
connect(effects, SIGNAL(windowAdded(EffectWindow*)), this, SLOT(slotWindowAdded(EffectWindow*)));
|
2011-02-27 08:25:45 +00:00
|
|
|
connect(effects, SIGNAL(windowClosed(EffectWindow*)), this, SLOT(slotWindowClosed(EffectWindow*)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
|
|
|
SlidingPopupsEffect::~SlidingPopupsEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
XDeleteProperty(display(), rootWindow(), mAtom);
|
|
|
|
effects->registerPropertyType(mAtom, false);
|
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SlidingPopupsEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (!mAppearingWindows.isEmpty() || !mDisappearingWindows.isEmpty())
|
2010-08-03 21:33:27 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SlidingPopupsEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (mAppearingWindows.contains(w)) {
|
|
|
|
mAppearingWindows[ w ].addTime(time);
|
|
|
|
if (mAppearingWindows[ w ].value() < 1)
|
2009-07-23 19:06:50 +00:00
|
|
|
data.setTransformed();
|
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
mAppearingWindows.remove(w);
|
|
|
|
} else if (mDisappearingWindows.contains(w)) {
|
2009-10-03 06:40:10 +00:00
|
|
|
data.setTransformed();
|
2011-01-30 14:34:42 +00:00
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
|
2009-07-27 13:27:16 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
mDisappearingWindows[ w ].addTime(time);
|
2009-07-23 19:06:50 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SlidingPopupsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2009-07-23 19:06:50 +00:00
|
|
|
bool animating = false;
|
|
|
|
bool appearing = false;
|
|
|
|
QRegion clippedRegion = region;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mAppearingWindows.contains(w)) {
|
2009-07-23 19:06:50 +00:00
|
|
|
appearing = true;
|
|
|
|
animating = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (mDisappearingWindows.contains(w) && w->isDeleted()) {
|
2009-07-23 19:06:50 +00:00
|
|
|
appearing = false;
|
|
|
|
animating = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (animating) {
|
2009-10-19 05:04:35 +00:00
|
|
|
qreal progress;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (appearing)
|
2009-10-19 05:04:35 +00:00
|
|
|
progress = 1.0 - mAppearingWindows[ w ].value();
|
2011-01-30 14:34:42 +00:00
|
|
|
else {
|
|
|
|
if (mDisappearingWindows.contains(w))
|
2009-10-19 05:04:35 +00:00
|
|
|
progress = mDisappearingWindows[ w ].value();
|
|
|
|
else
|
|
|
|
progress = 1.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
const int start = mWindowsData[ w ].start;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(mWindowsData[ w ].from) {
|
|
|
|
case West:
|
|
|
|
data.xTranslate += (start - w->width()) * progress;
|
|
|
|
clippedRegion = clippedRegion.subtracted(QRegion(start - w->width(), w->y(), w->width(), w->height()));
|
|
|
|
break;
|
|
|
|
case North:
|
|
|
|
data.yTranslate += (start - w->height()) * progress;
|
|
|
|
clippedRegion = clippedRegion.subtracted(QRegion(w->x(), start - w->height(), w->width(), w->height()));
|
|
|
|
break;
|
|
|
|
case East:
|
|
|
|
data.xTranslate += (start - w->x()) * progress;
|
|
|
|
clippedRegion = clippedRegion.subtracted(QRegion(w->x() + w->width(), w->y(), w->width(), w->height()));
|
|
|
|
break;
|
|
|
|
case South:
|
|
|
|
default:
|
|
|
|
data.yTranslate += (start - w->y()) * progress;
|
|
|
|
clippedRegion = clippedRegion.subtracted(QRegion(w->x(), start, w->width(), w->height()));
|
2009-07-23 19:06:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, clippedRegion, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlidingPopupsEffect::postPaintWindow(EffectWindow* w)
|
|
|
|
{
|
|
|
|
if (mAppearingWindows.contains(w) || mDisappearingWindows.contains(w))
|
2009-07-23 19:06:50 +00:00
|
|
|
w->addRepaintFull(); // trigger next animation repaint
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintWindow(w);
|
|
|
|
if (mDisappearingWindows.contains(w) && mDisappearingWindows[ w ].value() >= 1) {
|
|
|
|
mDisappearingWindows.remove(w);
|
2009-10-16 10:20:43 +00:00
|
|
|
w->unrefWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaint(w->geometry());
|
2009-07-23 19:06:50 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void SlidingPopupsEffect::slotWindowAdded(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
propertyNotify(w, mAtom);
|
|
|
|
if (w->isOnCurrentDesktop() && mWindowsData.contains(w)) {
|
|
|
|
mAppearingWindows[ w ].setDuration(mWindowsData[ w ].fadeInDuration);
|
|
|
|
mAppearingWindows[ w ].setProgress(0.0);
|
|
|
|
mAppearingWindows[ w ].setCurveShape(TimeLine::EaseOutCurve);
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2010-01-11 04:52:19 +00:00
|
|
|
// Tell other windowAdded() effects to ignore this window
|
2011-01-30 14:34:42 +00:00
|
|
|
w->setData(WindowAddedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
2009-09-08 20:42:45 +00:00
|
|
|
|
2009-07-23 19:06:50 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void SlidingPopupsEffect::slotWindowClosed(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
propertyNotify(w, mAtom);
|
|
|
|
if (w->isOnCurrentDesktop() && !w->isMinimized() && mWindowsData.contains(w)) {
|
2009-07-23 19:06:50 +00:00
|
|
|
w->refWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
mAppearingWindows.remove(w);
|
|
|
|
mDisappearingWindows[ w ].setDuration(mWindowsData[ w ].fadeOutDuration);
|
|
|
|
mDisappearingWindows[ w ].setProgress(0.0);
|
|
|
|
mDisappearingWindows[ w ].setCurveShape(TimeLine::EaseOutCurve);
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2010-01-11 04:52:19 +00:00
|
|
|
// Tell other windowClosed() effects to ignore this window
|
2011-01-30 14:34:42 +00:00
|
|
|
w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
2010-01-11 04:52:19 +00:00
|
|
|
|
2009-07-23 19:06:50 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SlidingPopupsEffect::windowDeleted(EffectWindow* w)
|
|
|
|
{
|
|
|
|
mAppearingWindows.remove(w);
|
|
|
|
mDisappearingWindows.remove(w);
|
|
|
|
mWindowsData.remove(w);
|
|
|
|
effects->addRepaint(w->geometry());
|
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SlidingPopupsEffect::propertyNotify(EffectWindow* w, long a)
|
|
|
|
{
|
|
|
|
if (!w || a != mAtom)
|
2009-07-23 19:06:50 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QByteArray data = w->readProperty(mAtom, mAtom, 32);
|
2009-07-27 13:27:16 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (data.length() < 1) {
|
2010-11-30 20:03:03 +00:00
|
|
|
// Property was removed, thus also remove the effect for window
|
2011-01-30 14:34:42 +00:00
|
|
|
mAppearingWindows.remove(w);
|
|
|
|
mDisappearingWindows.remove(w);
|
|
|
|
mWindowsData.remove(w);
|
2009-07-23 19:06:50 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-09 10:05:52 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
long* d = reinterpret_cast< long* >(data.data());
|
2009-07-23 19:06:50 +00:00
|
|
|
Data animData;
|
|
|
|
animData.start = d[ 0 ];
|
|
|
|
animData.from = (Position)d[ 1 ];
|
2011-01-30 14:34:42 +00:00
|
|
|
if (data.length() >= (int)(sizeof(long) * 3)) {
|
2010-08-07 11:41:01 +00:00
|
|
|
animData.fadeInDuration = d[2];
|
2011-01-30 14:34:42 +00:00
|
|
|
if (data.length() >= (int)(sizeof(long) * 4))
|
2010-08-07 11:41:01 +00:00
|
|
|
animData.fadeOutDuration = d[3];
|
|
|
|
else
|
|
|
|
animData.fadeOutDuration = d[2];
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
animData.fadeInDuration = animationTime(mFadeInTime);
|
|
|
|
animData.fadeOutDuration = animationTime(mFadeOutTime);
|
2009-07-23 19:06:50 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
mWindowsData[ w ] = animData;
|
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
} // namespace
|