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 Lubos Lunak <l.lunak@kde.org>
|
2007-11-13 16:20:52 +00:00
|
|
|
Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
|
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 "diminactive.h"
|
|
|
|
|
2008-05-30 17:47:24 +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(diminactive, DimInactiveEffect)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
DimInactiveEffect::DimInactiveEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
reconfigure(ReconfigureAll);
|
|
|
|
timeline.setDuration(animationTime(250));
|
|
|
|
previousActiveTimeline.setDuration(animationTime(250));
|
2008-10-02 09:27:32 +00:00
|
|
|
active = effects->activeWindow();
|
2009-02-07 09:48:20 +00:00
|
|
|
previousActive = NULL;
|
2012-01-29 11:29:24 +00:00
|
|
|
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
|
|
|
}
|
2007-11-13 16:20:52 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DimInactiveEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2008-10-02 09:27:32 +00:00
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig("DimInactive");
|
2007-11-13 16:20:52 +00:00
|
|
|
dim_panels = conf.readEntry("DimPanels", false);
|
2008-09-05 09:01:44 +00:00
|
|
|
dim_desktop = conf.readEntry("DimDesktop", false);
|
2010-04-13 18:42:05 +00:00
|
|
|
dim_keepabove = conf.readEntry("DimKeepAbove", false);
|
2007-11-13 16:20:52 +00:00
|
|
|
dim_by_group = conf.readEntry("DimByGroup", true);
|
|
|
|
dim_strength = conf.readEntry("Strength", 25);
|
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 DimInactiveEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
2011-03-14 21:50:05 +00:00
|
|
|
double oldValue = timeline.currentValue();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->activeFullScreenEffect())
|
2011-03-14 21:50:05 +00:00
|
|
|
timeline.setCurrentTime(timeline.currentTime() - time);
|
2009-02-07 09:48:20 +00:00
|
|
|
else
|
2011-03-14 21:50:05 +00:00
|
|
|
timeline.setCurrentTime(timeline.currentTime() + time);
|
|
|
|
if (oldValue != timeline.currentValue())
|
2009-02-07 09:48:20 +00:00
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (previousActive) {
|
|
|
|
// We are fading out the previous window
|
2009-02-07 09:48:20 +00:00
|
|
|
previousActive->addRepaintFull();
|
2011-03-14 21:50:05 +00:00
|
|
|
previousActiveTimeline.setCurrentTime(previousActiveTimeline.currentTime() + time);
|
2009-02-07 09:48:20 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2009-02-07 09:48:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DimInactiveEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
if (dimWindow(w) || w == previousActive) {
|
2009-02-07 09:48:20 +00:00
|
|
|
double previous = 1.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w == previousActive)
|
2011-03-14 21:50:05 +00:00
|
|
|
previous = previousActiveTimeline.currentValue();
|
|
|
|
if (previousActiveTimeline.currentValue() == 1.0)
|
2009-02-07 09:48:20 +00:00
|
|
|
previousActive = NULL;
|
2011-03-14 21:50:05 +00:00
|
|
|
data.brightness *= (1.0 - (dim_strength / 100.0) * timeline.currentValue() * previous);
|
|
|
|
data.saturation *= (1.0 - (dim_strength / 100.0) * timeline.currentValue() * previous);
|
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-01-30 14:34:42 +00:00
|
|
|
bool DimInactiveEffect::dimWindow(const EffectWindow* w) const
|
|
|
|
{
|
|
|
|
if (effects->activeWindow() == w)
|
2008-01-02 15:17:58 +00:00
|
|
|
return false; // never dim active window
|
2011-01-30 14:34:42 +00:00
|
|
|
if (active && dim_by_group && active->group() == w->group())
|
2008-01-02 15:17:58 +00:00
|
|
|
return false; // don't dim in active group if configured so
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isDock() && !dim_panels)
|
2008-01-02 15:17:58 +00:00
|
|
|
return false; // don't dim panels if configured so
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isDesktop() && !dim_desktop)
|
2008-09-05 09:01:44 +00:00
|
|
|
return false; // don't dim the desktop if configured so
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->keepAbove() && !dim_keepabove)
|
2010-04-13 18:42:05 +00:00
|
|
|
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())
|
2008-01-02 15:17:58 +00:00
|
|
|
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())
|
2008-01-02 15:17:58 +00:00
|
|
|
return false;
|
|
|
|
return true; // dim the rest
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-02 15:17:58 +00:00
|
|
|
|
2011-02-27 09:47:42 +00:00
|
|
|
void DimInactiveEffect::slotWindowDeleted(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (w == previousActive)
|
2009-02-09 14:36:47 +00:00
|
|
|
previousActive = NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-09 14:36:47 +00:00
|
|
|
|
2011-02-27 09:05:04 +00:00
|
|
|
void DimInactiveEffect::slotWindowActivated(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (active != NULL) {
|
2009-02-07 09:48:20 +00:00
|
|
|
previousActive = active;
|
2011-03-14 21:50:05 +00:00
|
|
|
previousActiveTimeline.setCurrentTime(0);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!dimWindow(previousActive))
|
2009-05-28 08:56:05 +00:00
|
|
|
previousActive = NULL;
|
2009-02-07 09:48:20 +00:00
|
|
|
|
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();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
2007-04-29 17:35:43 +00:00
|
|
|
active->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +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();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
2007-04-29 17:35:43 +00:00
|
|
|
active->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
} // namespace
|