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
|
|
|
|
{
|
|
|
|
|
2007-05-28 11:16:18 +00:00
|
|
|
KWIN_EFFECT( diminactive, DimInactiveEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
DimInactiveEffect::DimInactiveEffect()
|
|
|
|
{
|
2008-10-02 09:27:32 +00:00
|
|
|
reconfigure( ReconfigureAll );
|
2009-02-07 09:53:17 +00:00
|
|
|
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;
|
2008-10-02 09:27:32 +00:00
|
|
|
}
|
2007-11-13 16:20:52 +00:00
|
|
|
|
2008-10-02 09:27:32 +00:00
|
|
|
void DimInactiveEffect::reconfigure( ReconfigureFlags )
|
|
|
|
{
|
|
|
|
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);
|
2007-11-13 16:20:52 +00:00
|
|
|
dim_by_group = conf.readEntry("DimByGroup", true);
|
|
|
|
dim_strength = conf.readEntry("Strength", 25);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 09:48:20 +00:00
|
|
|
void DimInactiveEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
|
|
|
{
|
|
|
|
double oldValue = timeline.value();
|
|
|
|
if( effects->activeFullScreenEffect() )
|
|
|
|
timeline.removeTime( time );
|
|
|
|
else
|
|
|
|
timeline.addTime( time );
|
|
|
|
if( oldValue != timeline.value() )
|
|
|
|
effects->addRepaintFull();
|
|
|
|
if( previousActive )
|
|
|
|
{ // We are fading out the previous window
|
|
|
|
previousActive->addRepaintFull();
|
|
|
|
previousActiveTimeline.addTime( time );
|
|
|
|
}
|
|
|
|
effects->prePaintScreen( data, time );
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void DimInactiveEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
2009-02-07 09:48:20 +00:00
|
|
|
if( dimWindow( w ) || w == previousActive )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2009-02-07 09:48:20 +00:00
|
|
|
double previous = 1.0;
|
|
|
|
if( w == previousActive )
|
|
|
|
previous = previousActiveTimeline.value();
|
|
|
|
if( previousActiveTimeline.value() == 1.0 )
|
|
|
|
previousActive = NULL;
|
|
|
|
data.brightness *= (1.0 - (dim_strength / 100.0) * timeline.value() * previous );
|
|
|
|
data.saturation *= (1.0 - (dim_strength / 100.0) * timeline.value() * previous );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
2008-01-02 15:17:58 +00:00
|
|
|
bool DimInactiveEffect::dimWindow( const EffectWindow* w ) const
|
|
|
|
{
|
2009-12-06 18:14:15 +00:00
|
|
|
if( effects->activeWindow() == w )
|
2008-01-02 15:17:58 +00:00
|
|
|
return false; // never dim active window
|
|
|
|
if( active && dim_by_group && active->group() == w->group())
|
|
|
|
return false; // don't dim in active group if configured so
|
|
|
|
if( w->isDock() && !dim_panels )
|
|
|
|
return false; // don't dim panels if configured so
|
2008-09-05 09:01:44 +00:00
|
|
|
if( w->isDesktop() && !dim_desktop )
|
|
|
|
return false; // don't dim the desktop if configured so
|
|
|
|
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)
|
|
|
|
if( !w->isManaged())
|
|
|
|
return false;
|
|
|
|
return true; // dim the rest
|
|
|
|
}
|
|
|
|
|
2009-02-09 14:36:47 +00:00
|
|
|
void DimInactiveEffect::windowDeleted( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if( w == previousActive )
|
|
|
|
previousActive = NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void DimInactiveEffect::windowActivated( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if( active != NULL )
|
|
|
|
{
|
2009-02-07 09:48:20 +00:00
|
|
|
previousActive = active;
|
|
|
|
previousActiveTimeline.setProgress( 0.0 );
|
2009-05-28 08:56:05 +00:00
|
|
|
if( !dimWindow( previousActive ) )
|
|
|
|
previousActive = NULL;
|
2009-02-07 09:48:20 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
if( dim_by_group )
|
|
|
|
{
|
|
|
|
if(( w == NULL || w->group() != active->group()) && active->group() != NULL )
|
2008-01-02 15:17:58 +00:00
|
|
|
{ // repaint windows that are no longer in the active group
|
2007-04-29 17:35:43 +00:00
|
|
|
foreach( EffectWindow* tmp, active->group()->members())
|
|
|
|
tmp->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
active->addRepaintFull();
|
|
|
|
}
|
|
|
|
active = w;
|
|
|
|
if( active != NULL )
|
2008-12-08 03:49:44 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
if( dim_by_group )
|
|
|
|
{
|
|
|
|
if( active->group() != NULL )
|
|
|
|
{ // repaint newly active windows
|
|
|
|
foreach( EffectWindow* tmp, active->group()->members())
|
|
|
|
tmp->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
active->addRepaintFull();
|
2008-12-08 03:49:44 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|