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) 2007 Philip Falkner <philip.falkner@gmail.com>
|
|
|
|
|
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 "fade.h"
|
|
|
|
|
2007-07-05 20:19:10 +00:00
|
|
|
#include <kconfiggroup.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(fade, FadeEffect)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
FadeEffect::FadeEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
reconfigure(ReconfigureAll);
|
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-02-27 09:47:42 +00:00
|
|
|
connect(effects, SIGNAL(windowDeleted(EffectWindow*)), this, SLOT(slotWindowDeleted(EffectWindow*)));
|
2011-03-06 09:30:23 +00:00
|
|
|
connect(effects, SIGNAL(windowOpacityChanged(EffectWindow*,qreal,qreal)), this, SLOT(slotWindowOpacityChanged(EffectWindow*,qreal)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-10-02 09:27:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FadeEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
|
|
|
KConfigGroup conf = effects->effectConfig("Fade");
|
|
|
|
fadeInTime = animationTime(conf, "FadeInTime", 150);
|
|
|
|
fadeOutTime = animationTime(conf, "FadeOutTime", 150);
|
|
|
|
fadeWindows = conf.readEntry("FadeWindows", true);
|
2008-12-15 08:05:24 +00:00
|
|
|
|
|
|
|
// Add all existing windows to the window list
|
|
|
|
// TODO: Enabling desktop effects should trigger windowAdded() on all windows
|
|
|
|
windows.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-05 20:19:10 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FadeEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (!windows.isEmpty()) {
|
|
|
|
fadeInStep = time / double(fadeInTime);
|
|
|
|
fadeOutStep = time / double(fadeOutTime);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FadeEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (windows.contains(w)) {
|
2007-07-05 20:19:10 +00:00
|
|
|
windows[ w ].fadeInStep += fadeInStep;
|
|
|
|
windows[ w ].fadeOutStep += fadeOutStep;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows[ w ].opacity < 1.0)
|
2007-07-19 13:32:46 +00:00
|
|
|
data.setTranslucent();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows[ w ].deleted) {
|
|
|
|
if (windows[ w ].opacity <= 0.0) {
|
|
|
|
windows.remove(w);
|
2007-07-05 20:19:10 +00:00
|
|
|
w->unrefWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
if (windows.contains(w) && !w->isPaintingEnabled() && !effects->activeFullScreenEffect()) {
|
|
|
|
// if the window isn't to be painted, then let's make sure
|
|
|
|
// to track its progress
|
|
|
|
if (windows[ w ].fadeInStep < 1.0
|
|
|
|
|| windows[ w ].fadeOutStep < 1.0) {
|
|
|
|
// but only if the total change is less than the
|
|
|
|
// maximum possible change
|
2007-07-05 20:19:10 +00:00
|
|
|
w->addRepaintFull();
|
2011-08-27 11:19:56 +00:00
|
|
|
} else {
|
|
|
|
if (windows[w].deleted) {
|
|
|
|
w->unrefWindow();
|
|
|
|
}
|
|
|
|
windows.remove(w);
|
2007-07-05 20:19:10 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
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 FadeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
if (windows.contains(w)) {
|
|
|
|
if (windows[ w ].deleted
|
|
|
|
|| windows[ w ].opacity != data.opacity
|
|
|
|
|| windows[ w ].saturation != data.saturation
|
|
|
|
|| windows[ w ].brightness != data.brightness) {
|
2007-07-05 20:19:10 +00:00
|
|
|
WindowPaintData new_data = data;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows[ w ].deleted)
|
2007-07-05 20:19:10 +00:00
|
|
|
new_data.opacity = 0.0;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (new_data.opacity > windows[ w ].opacity) {
|
|
|
|
windows[ w ].opacity = qMin(new_data.opacity,
|
|
|
|
windows[ w ].opacity + windows[ w ].fadeInStep);
|
|
|
|
} else if (new_data.opacity < windows[ w ].opacity) {
|
|
|
|
windows[ w ].opacity = qMax(new_data.opacity,
|
|
|
|
windows[ w ].opacity - windows[ w ].fadeOutStep);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_data.saturation > windows[ w ].saturation) {
|
|
|
|
windows[ w ].saturation = qMin(new_data.saturation,
|
|
|
|
windows[ w ].saturation + windows[ w ].fadeInStep);
|
|
|
|
} else if (new_data.saturation < windows[ w ].saturation) {
|
|
|
|
windows[ w ].saturation = qMax(new_data.saturation,
|
|
|
|
windows[ w ].saturation - windows[ w ].fadeOutStep);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_data.brightness > windows[ w ].brightness) {
|
|
|
|
windows[ w ].brightness = qMin(new_data.brightness,
|
|
|
|
windows[ w ].brightness + windows[ w ].fadeInStep);
|
|
|
|
} else if (new_data.brightness < windows[ w ].brightness) {
|
|
|
|
windows[ w ].brightness = qMax(new_data.brightness,
|
|
|
|
windows[ w ].brightness - windows[ w ].fadeOutStep);
|
|
|
|
}
|
|
|
|
|
|
|
|
windows[ w ].opacity = qBound(0.0, windows[ w ].opacity, 1.0);
|
|
|
|
windows[ w ].saturation = qBound(0.0, windows[ w ].saturation, 1.0);
|
|
|
|
windows[ w ].brightness = qBound(0.0, windows[ w ].brightness, 1.0);
|
2007-07-05 20:19:10 +00:00
|
|
|
windows[ w ].fadeInStep = 0.0;
|
|
|
|
windows[ w ].fadeOutStep = 0.0;
|
|
|
|
|
|
|
|
new_data.opacity = windows[ w ].opacity;
|
|
|
|
new_data.saturation = windows[ w ].saturation;
|
|
|
|
new_data.brightness = windows[ w ].brightness;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, new_data);
|
|
|
|
if (windows[ w ].opacity != data.opacity
|
|
|
|
|| windows[ w ].saturation != data.saturation
|
|
|
|
|| windows[ w ].brightness != data.brightness)
|
2007-07-05 20:19:10 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
return;
|
2011-08-27 11:19:56 +00:00
|
|
|
} else {
|
|
|
|
windows.remove(w);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-03-06 09:30:23 +00:00
|
|
|
void FadeEffect::slotWindowOpacityChanged(EffectWindow* w, qreal old_opacity)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-08-27 11:19:56 +00:00
|
|
|
if (!windows.contains(w) || !isFadeWindow(w))
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows[ w ].opacity == 1.0)
|
2007-07-05 20:19:10 +00:00
|
|
|
windows[ w ].opacity -= 0.1 / fadeOutTime;
|
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void FadeEffect::slotWindowAdded(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!fadeWindows || !isFadeWindow(w))
|
2007-07-05 20:19:10 +00:00
|
|
|
return;
|
|
|
|
windows[ w ].opacity = 0.0;
|
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void FadeEffect::slotWindowClosed(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 19:40:34 +00:00
|
|
|
// In the cases, where we are still fading in or are not responsible, we do not fade out.
|
|
|
|
if (!fadeWindows || !isFadeWindow(w) || windows.contains(w)) {
|
2007-07-05 20:19:10 +00:00
|
|
|
return;
|
2012-01-12 19:40:34 +00:00
|
|
|
}
|
|
|
|
windows[ w ].opacity = w->opacity();
|
|
|
|
if (windows[ w ].opacity == 1.0) {
|
2007-07-05 20:19:10 +00:00
|
|
|
windows[ w ].opacity -= 0.1 / fadeOutTime;
|
2012-01-12 19:40:34 +00:00
|
|
|
}
|
2007-07-05 20:19:10 +00:00
|
|
|
windows[ w ].deleted = true;
|
|
|
|
w->refWindow();
|
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-27 09:47:42 +00:00
|
|
|
void FadeEffect::slotWindowDeleted(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
windows.remove(w);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool FadeEffect::isFadeWindow(EffectWindow* w)
|
|
|
|
{
|
2010-01-11 04:52:19 +00:00
|
|
|
void* e;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isDeleted())
|
|
|
|
e = w->data(WindowClosedGrabRole).value<void*>();
|
2010-01-11 04:52:19 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
e = w->data(WindowAddedGrabRole).value<void*>();
|
|
|
|
if (w->windowClass() == "ksplashx ksplashx"
|
|
|
|
|| w->windowClass() == "ksplashsimple ksplashsimple"
|
2011-05-01 14:17:21 +00:00
|
|
|
|| w->windowClass() == "qt-subapplication ksplashqml"
|
2011-01-30 14:34:42 +00:00
|
|
|
|| (e && e != this)) {
|
|
|
|
// see login effect
|
2007-11-14 14:55:23 +00:00
|
|
|
return false;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return (!w->isDesktop() && !w->isUtility());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool FadeEffect::isActive() const
|
|
|
|
{
|
|
|
|
return !windows.isEmpty();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|