2009-02-17 21:13:00 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Philip Falkner <philip.falkner@gmail.com>
|
|
|
|
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
|
|
|
|
|
|
|
|
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 "sheet.h"
|
|
|
|
|
|
|
|
#include <kconfiggroup.h>
|
|
|
|
|
|
|
|
// Effect is based on fade effect by Philip Falkner
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWIN_EFFECT( sheet, SheetEffect )
|
|
|
|
KWIN_EFFECT_SUPPORTED( sheet, SheetEffect::supported() )
|
|
|
|
|
2010-11-02 20:35:28 +00:00
|
|
|
static const int IsSheetWindow = 0x22A982D5;
|
|
|
|
|
2009-02-17 21:13:00 +00:00
|
|
|
SheetEffect::SheetEffect()
|
|
|
|
{
|
|
|
|
reconfigure( ReconfigureAll );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SheetEffect::supported()
|
|
|
|
{
|
|
|
|
return effects->compositingType() == OpenGLCompositing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::reconfigure( ReconfigureFlags )
|
|
|
|
{
|
|
|
|
KConfigGroup conf = effects->effectConfig( "Sheet" );
|
|
|
|
duration = animationTime( conf, "AnimationTime", 500 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
if( !windows.isEmpty() )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
screenTime = time;
|
|
|
|
}
|
|
|
|
effects->prePaintScreen( data, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
InfoMap::iterator info = windows.find( w );
|
|
|
|
if( info != windows.end() )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
data.setTransformed();
|
|
|
|
if( info->added )
|
|
|
|
info->timeLine.addTime( screenTime );
|
|
|
|
else if( info->closed )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
info->timeLine.removeTime( screenTime );
|
|
|
|
if( info->deleted )
|
2009-02-17 21:13:00 +00:00
|
|
|
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DELETE );
|
|
|
|
}
|
|
|
|
}
|
2010-11-02 20:35:28 +00:00
|
|
|
|
2009-02-17 21:13:00 +00:00
|
|
|
effects->prePaintWindow( w, data, time );
|
2010-11-02 20:35:28 +00:00
|
|
|
|
|
|
|
// if the window isn't to be painted, then let's make sure
|
|
|
|
// to track its progress
|
|
|
|
if( info != windows.end() && !w->isPaintingEnabled() && !effects->activeFullScreenEffect() )
|
|
|
|
w->addRepaintFull();
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
2010-11-03 08:34:01 +00:00
|
|
|
InfoMap::const_iterator info = windows.constFind( w );
|
2010-11-02 20:35:28 +00:00
|
|
|
if( info != windows.constEnd() )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
const double progress = info->timeLine.value();
|
2009-02-17 21:13:00 +00:00
|
|
|
RotationData rot;
|
|
|
|
rot.axis = RotationData::XAxis;
|
2010-11-02 20:35:28 +00:00
|
|
|
rot.angle = 60.0 * ( 1.0 - progress );
|
2009-02-17 21:13:00 +00:00
|
|
|
data.rotation = &rot;
|
2010-11-02 20:35:28 +00:00
|
|
|
data.yScale *= progress;
|
|
|
|
data.zScale *= progress;
|
|
|
|
data.yTranslate -= (w->y() - info->parentY) * ( 1.0 - progress );
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
2010-11-02 20:35:28 +00:00
|
|
|
effects->paintWindow( w, mask, region, data );
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::postPaintWindow( EffectWindow* w )
|
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
InfoMap::iterator info = windows.find( w );
|
|
|
|
if( info != windows.end() )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
if( info->added && info->timeLine.value() == 1.0 )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
windows.remove( w );
|
2009-02-17 21:13:00 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2010-11-02 20:35:28 +00:00
|
|
|
else if( info->closed && info->timeLine.value() == 0.0 )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
info->closed = false;
|
|
|
|
if( info->deleted )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
|
|
|
windows.remove( w );
|
|
|
|
w->unrefWindow();
|
|
|
|
}
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2010-11-02 20:35:28 +00:00
|
|
|
if( info->added || info->closed )
|
2009-02-17 21:13:00 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
effects->postPaintWindow( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::windowAdded( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if( !isSheetWindow( w ) )
|
|
|
|
return;
|
2010-11-02 20:35:28 +00:00
|
|
|
w->setData( IsSheetWindow, true );
|
|
|
|
|
|
|
|
InfoMap::iterator it = windows.find( w );
|
|
|
|
WindowInfo *info = ( it == windows.end() ) ? &windows[w] : &it.value();
|
|
|
|
info->added = true;
|
|
|
|
info->closed = false;
|
|
|
|
info->deleted = false;
|
|
|
|
info->timeLine.setDuration( duration );
|
|
|
|
const EffectWindowList stack = effects->stackingOrder();
|
2009-02-17 21:13:00 +00:00
|
|
|
// find parent
|
2010-11-02 20:35:28 +00:00
|
|
|
foreach( EffectWindow* window, stack )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
|
|
|
if( window->findModal() == w )
|
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
info->parentY = window->y();
|
2009-02-17 21:13:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::windowClosed( EffectWindow* w )
|
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
if( !isSheetWindow( w ) )
|
2009-02-17 21:13:00 +00:00
|
|
|
return;
|
2010-11-02 20:35:28 +00:00
|
|
|
|
|
|
|
w->refWindow();
|
|
|
|
|
|
|
|
InfoMap::iterator it = windows.find( w );
|
|
|
|
WindowInfo *info = ( it == windows.end() ) ? &windows[w] : &it.value();
|
|
|
|
info->added = false;
|
|
|
|
info->closed = true;
|
|
|
|
info->deleted = true;
|
|
|
|
info->timeLine.setDuration( duration );
|
|
|
|
info->timeLine.setProgress( 1.0 );
|
|
|
|
|
2009-02-17 21:13:00 +00:00
|
|
|
bool found = false;
|
|
|
|
// find parent
|
2010-11-02 20:35:28 +00:00
|
|
|
const EffectWindowList stack = effects->stackingOrder();
|
|
|
|
foreach( EffectWindow* window, stack )
|
2009-02-17 21:13:00 +00:00
|
|
|
{
|
|
|
|
if( window->findModal() == w )
|
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
info->parentY = window->y();
|
2009-02-17 21:13:00 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !found )
|
2010-11-02 20:35:28 +00:00
|
|
|
info->parentY = 0;
|
2009-02-17 21:13:00 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SheetEffect::windowDeleted( EffectWindow* w )
|
|
|
|
{
|
|
|
|
windows.remove( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SheetEffect::isSheetWindow( EffectWindow* w )
|
|
|
|
{
|
2010-11-02 20:35:28 +00:00
|
|
|
return ( w->isModal() || w->data( IsSheetWindow ).toBool() );
|
2009-02-17 21:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|