kwin/effects/diminactive/diminactive.cpp

142 lines
5.2 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
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 "diminactive.h"
// KConfigSkeleton
#include "diminactiveconfig.h"
#include <kconfiggroup.h>
namespace KWin
{
DimInactiveEffect::DimInactiveEffect()
2011-01-30 14:34:42 +00:00
{
reconfigure(ReconfigureAll);
timeline.setDuration(animationTime(250));
previousActiveTimeline.setDuration(animationTime(250));
active = effects->activeWindow();
previousActive = NULL;
connect(effects, SIGNAL(windowActivated(KWin::EffectWindow*)), this, SLOT(slotWindowActivated(KWin::EffectWindow*)));
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void DimInactiveEffect::reconfigure(ReconfigureFlags)
{
DimInactiveConfig::self()->read();
dim_panels = DimInactiveConfig::dimPanels();
dim_desktop = DimInactiveConfig::dimDesktop();
dim_keepabove = DimInactiveConfig::dimKeepAbove();
dim_by_group = DimInactiveConfig::dimByGroup();
dim_strength = DimInactiveConfig::strength();
effects->addRepaintFull();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void DimInactiveEffect::prePaintScreen(ScreenPrePaintData& data, int time)
{
double oldValue = timeline.currentValue();
2011-01-30 14:34:42 +00:00
if (effects->activeFullScreenEffect())
timeline.setCurrentTime(timeline.currentTime() - time);
else
timeline.setCurrentTime(timeline.currentTime() + time);
if (oldValue != timeline.currentValue())
effects->addRepaintFull();
2011-01-30 14:34:42 +00:00
if (previousActive) {
// We are fading out the previous window
previousActive->addRepaintFull();
previousActiveTimeline.setCurrentTime(previousActiveTimeline.currentTime() + time);
}
2011-01-30 14:34:42 +00:00
effects->prePaintScreen(data, time);
}
2011-01-30 14:34:42 +00:00
void DimInactiveEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
if (dimWindow(w) || w == previousActive) {
double previous = 1.0;
2011-01-30 14:34:42 +00:00
if (w == previousActive)
previous = previousActiveTimeline.currentValue();
if (previousActiveTimeline.currentValue() == 1.0)
previousActive = NULL;
data.multiplyBrightness((1.0 - (dim_strength / 100.0) * timeline.currentValue() * previous));
data.multiplySaturation((1.0 - (dim_strength / 100.0) * timeline.currentValue() * previous));
}
2011-01-30 14:34:42 +00:00
effects->paintWindow(w, mask, region, data);
}
2011-01-30 14:34:42 +00:00
bool DimInactiveEffect::dimWindow(const EffectWindow* w) const
{
if (effects->activeWindow() == w)
return false; // never dim active window
2011-01-30 14:34:42 +00:00
if (active && dim_by_group && active->group() == w->group())
return false; // don't dim in active group if configured so
2011-01-30 14:34:42 +00:00
if (w->isDock() && !dim_panels)
return false; // don't dim panels if configured so
2011-01-30 14:34:42 +00:00
if (w->isDesktop() && !dim_desktop)
return false; // don't dim the desktop if configured so
2011-01-30 14:34:42 +00:00
if (w->keepAbove() && !dim_keepabove)
return false; // don't dim keep-above windows if configured so
2011-01-30 14:34:42 +00:00
if (!w->isNormalWindow() && !w->isDialog() && !w->isDock() && !w->isDesktop())
return false; // don't dim more special window types
// don't dim unmanaged windows, grouping doesn't work for them and maybe dimming
// them doesn't make sense in general (they should be short-lived anyway)
2011-01-30 14:34:42 +00:00
if (!w->isManaged())
return false;
return true; // dim the rest
2011-01-30 14:34:42 +00:00
}
void DimInactiveEffect::slotWindowDeleted(EffectWindow* w)
2011-01-30 14:34:42 +00:00
{
if (w == previousActive)
previousActive = NULL;
2011-01-30 14:34:42 +00:00
}
void DimInactiveEffect::slotWindowActivated(EffectWindow* w)
2011-01-30 14:34:42 +00:00
{
if (active != NULL) {
previousActive = active;
previousActiveTimeline.setCurrentTime(0);
2011-01-30 14:34:42 +00:00
if (!dimWindow(previousActive))
previousActive = NULL;
2011-01-30 14:34:42 +00:00
if (dim_by_group) {
if ((w == NULL || w->group() != active->group()) && active->group() != NULL) {
// repaint windows that are no longer in the active group
foreach (EffectWindow * tmp, active->group()->members())
tmp->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
} else
active->addRepaintFull();
2011-01-30 14:34:42 +00:00
}
active = w;
2011-01-30 14:34:42 +00:00
if (active != NULL) {
if (dim_by_group) {
if (active->group() != NULL) {
// repaint newly active windows
foreach (EffectWindow * tmp, active->group()->members())
tmp->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
} else
active->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
}
} // namespace