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) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
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 "maketransparent.h"
|
|
|
|
|
2007-10-22 13:34:26 +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( maketransparent, MakeTransparentEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-07-19 10:07:49 +00:00
|
|
|
MakeTransparentEffect::MakeTransparentEffect()
|
2008-07-25 16:46:27 +00:00
|
|
|
: fadeout( NULL )
|
|
|
|
, current( NULL )
|
|
|
|
, previous( NULL )
|
2007-07-19 10:07:49 +00:00
|
|
|
{
|
2007-10-22 13:34:26 +00:00
|
|
|
KConfigGroup conf = effects->effectConfig("MakeTransparent");
|
2008-01-17 18:41:21 +00:00
|
|
|
decoration = conf.readEntry( "Decoration", 1.0 );
|
2007-10-22 13:34:26 +00:00
|
|
|
moveresize = conf.readEntry( "MoveResize", 0.8 );
|
|
|
|
dialogs = conf.readEntry( "Dialogs", 1.0 );
|
2008-01-14 15:34:39 +00:00
|
|
|
inactive = conf.readEntry( "Inactive", 1.0 );
|
2008-04-06 10:19:26 +00:00
|
|
|
comboboxpopups = conf.readEntry( "ComboboxPopups", 1.0 );
|
|
|
|
menus = conf.readEntry( "Menus", 1.0 );
|
|
|
|
individualmenuconfig = conf.readEntry( "IndividualMenuConfig", false );
|
|
|
|
if( individualmenuconfig )
|
|
|
|
{
|
|
|
|
dropdownmenus = conf.readEntry( "DropdownMenus", 1.0 );
|
|
|
|
popupmenus = conf.readEntry( "PopupMenus", 1.0 );
|
|
|
|
tornoffmenus = conf.readEntry( "TornOffMenus", 1.0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dropdownmenus = menus;
|
|
|
|
popupmenus = menus;
|
|
|
|
tornoffmenus = menus;
|
|
|
|
}
|
2008-01-14 15:34:39 +00:00
|
|
|
active = effects->activeWindow();
|
2008-04-28 16:10:10 +00:00
|
|
|
moveresize_timeline.setCurveShape( TimeLine::EaseOutCurve );
|
2008-08-30 07:25:54 +00:00
|
|
|
moveresize_timeline.setDuration( animationTime( conf, "Duration", 800 ) );
|
2008-04-28 16:10:10 +00:00
|
|
|
activeinactive_timeline.setCurveShape( TimeLine::EaseInOutCurve );
|
2008-08-30 07:25:54 +00:00
|
|
|
activeinactive_timeline.setDuration( animationTime( conf, "Duration", 800 ) );
|
2007-07-19 10:07:49 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
void MakeTransparentEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2008-04-28 16:10:10 +00:00
|
|
|
moveresize_timeline.addTime(time);
|
|
|
|
activeinactive_timeline.addTime(time);
|
|
|
|
|
2007-07-19 13:32:46 +00:00
|
|
|
if( decoration != 1.0 && w->hasDecoration())
|
2007-07-19 10:07:49 +00:00
|
|
|
{
|
|
|
|
data.mask |= PAINT_WINDOW_TRANSLUCENT;
|
2007-07-19 13:32:46 +00:00
|
|
|
// don't clear PAINT_WINDOW_OPAQUE, contents are not affected
|
|
|
|
data.clip &= w->contentsRect().translated( w->pos()); // decoration cannot clip
|
2007-07-19 10:07:49 +00:00
|
|
|
}
|
|
|
|
if(( moveresize != 1.0 && ( w->isUserMove() || w->isUserResize()))
|
|
|
|
|| ( dialogs != 1.0 && w->isDialog()))
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2007-07-19 13:32:46 +00:00
|
|
|
data.setTranslucent();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-04-06 10:19:26 +00:00
|
|
|
if( ( dropdownmenus != 1.0 && w->isDropdownMenu() )
|
|
|
|
|| ( popupmenus != 1.0 && w->isPopupMenu() )
|
|
|
|
|| ( tornoffmenus != 1.0 && w->isMenu() )
|
|
|
|
|| ( comboboxpopups != 1.0 && w->isComboBox() ) )
|
|
|
|
{
|
|
|
|
data.setTranslucent();
|
|
|
|
}
|
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
effects->prePaintWindow( w, data, time );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MakeTransparentEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
2008-04-28 16:10:10 +00:00
|
|
|
// We keep track of the windows that was last active so we know
|
|
|
|
// which one to fade out and which ones to paint as fully inactive
|
|
|
|
if ( w == active && w != current )
|
|
|
|
{
|
|
|
|
previous = current;
|
|
|
|
current = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( w->isDesktop() || w->isDock() )
|
|
|
|
{
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handling active and inactive windows
|
2008-01-14 15:34:39 +00:00
|
|
|
if( inactive != 1.0 && isInactive(w) )
|
|
|
|
{
|
|
|
|
data.opacity *= inactive;
|
2008-04-28 16:10:10 +00:00
|
|
|
|
|
|
|
if ( w == previous )
|
|
|
|
{
|
|
|
|
data.opacity *= (inactive + ((1.0 - inactive) * (1.0 - activeinactive_timeline.value())));
|
|
|
|
if ( activeinactive_timeline.value() < 1.0 )
|
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
2008-01-14 15:34:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-28 16:10:10 +00:00
|
|
|
// Fading in
|
|
|
|
if ( !isInactive(w) && !w->isDesktop() )
|
|
|
|
{
|
|
|
|
data.opacity *= (inactive + ((1.0 - inactive) * activeinactive_timeline.value()));
|
|
|
|
if ( activeinactive_timeline.value() < 1.0 )
|
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
// decoration and dialogs
|
2008-01-14 15:34:39 +00:00
|
|
|
if( decoration != 1.0 && w->hasDecoration())
|
|
|
|
data.decoration_opacity *= decoration;
|
|
|
|
if( dialogs != 1.0 && w->isDialog())
|
|
|
|
data.opacity *= dialogs;
|
2008-04-28 16:10:10 +00:00
|
|
|
|
|
|
|
// Handling moving and resizing
|
2008-06-13 09:35:57 +00:00
|
|
|
if( moveresize != 1.0 && !w->isDesktop() && !w->isDock())
|
2008-04-28 16:10:10 +00:00
|
|
|
{
|
|
|
|
double progress = moveresize_timeline.value();
|
|
|
|
if ( w->isUserMove() || w->isUserResize() )
|
|
|
|
{ // Fading to translucent
|
2008-06-13 09:35:57 +00:00
|
|
|
data.opacity *= (moveresize + ((1.0 - moveresize) * ( 1.0 - progress )));
|
|
|
|
if (progress < 1.0 && progress > 0.0)
|
2008-04-28 16:10:10 +00:00
|
|
|
{
|
2008-06-13 09:35:57 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
if ( fadeout != w )
|
|
|
|
fadeout = w;
|
2008-04-28 16:10:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Fading back to more opaque
|
2008-06-13 09:35:57 +00:00
|
|
|
if( w == fadeout && !w->isUserMove() && !w->isUserResize() )
|
2008-04-28 16:10:10 +00:00
|
|
|
{
|
|
|
|
data.opacity *= (moveresize + ((1.0 - moveresize) * (progress)));
|
2008-05-03 00:09:44 +00:00
|
|
|
if ( progress == 1.0 || progress == 0.0)
|
2008-04-28 16:10:10 +00:00
|
|
|
fadeout = NULL;
|
|
|
|
else
|
|
|
|
w->addRepaintFull();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Menues and combos
|
2008-04-06 10:19:26 +00:00
|
|
|
if( dropdownmenus != 1.0 && w->isDropdownMenu() )
|
|
|
|
data.opacity *= dropdownmenus;
|
|
|
|
if( popupmenus != 1.0 && w->isPopupMenu() )
|
|
|
|
data.opacity *= popupmenus;
|
|
|
|
if( tornoffmenus != 1.0 && w->isMenu() )
|
|
|
|
data.opacity *= tornoffmenus;
|
|
|
|
if( comboboxpopups != 1.0 && w->isComboBox() )
|
|
|
|
data.opacity *= comboboxpopups;
|
2008-04-28 16:10:10 +00:00
|
|
|
|
2008-01-14 15:34:39 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
2008-01-14 15:34:39 +00:00
|
|
|
bool MakeTransparentEffect::isInactive( const EffectWindow* w ) const
|
|
|
|
{
|
|
|
|
if( active == w || w->isDock() || !w->isManaged() )
|
|
|
|
return false;
|
|
|
|
if( NULL != active && NULL != active->group() )
|
|
|
|
if (active->group() == w->group() )
|
|
|
|
return false;
|
|
|
|
if( !w->isNormalWindow() && !w->isDialog() && !w->isDock() )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void MakeTransparentEffect::windowUserMovedResized( EffectWindow* w, bool first, bool last )
|
|
|
|
{
|
2007-07-19 10:07:49 +00:00
|
|
|
if( moveresize != 1.0 && ( first || last ))
|
2008-04-28 16:10:10 +00:00
|
|
|
{
|
|
|
|
moveresize_timeline.setProgress(0.0);
|
2007-04-29 17:35:43 +00:00
|
|
|
w->addRepaintFull();
|
2008-04-28 16:10:10 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-01-14 15:34:39 +00:00
|
|
|
void MakeTransparentEffect::windowActivated( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if( inactive != 1.0 )
|
|
|
|
{
|
2008-04-28 16:10:10 +00:00
|
|
|
activeinactive_timeline.setProgress(0.0);
|
2008-01-14 15:34:39 +00:00
|
|
|
if( NULL != active && active != w )
|
|
|
|
{
|
|
|
|
if( ( NULL == w || w->group() != active->group() ) &&
|
|
|
|
NULL != active->group() )
|
|
|
|
{
|
|
|
|
// Active group has changed. so repaint old group
|
|
|
|
foreach( EffectWindow *tmp, active->group()->members() )
|
|
|
|
tmp->addRepaintFull();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
active->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( NULL != w )
|
|
|
|
{
|
|
|
|
if (NULL != w->group() )
|
|
|
|
{
|
|
|
|
// Repaint windows in new group
|
|
|
|
foreach( EffectWindow *tmp, w->group()->members() )
|
|
|
|
tmp->addRepaintFull();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
active = w;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|