2010-05-11 18:45:39 +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>
|
|
|
|
Copyright (C) 2010 Alexandre Pereira <pereira.alex@gmail.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 "glide.h"
|
|
|
|
|
|
|
|
#include <kconfiggroup.h>
|
|
|
|
|
|
|
|
// Effect is based on fade effect by Philip Falkner
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWIN_EFFECT( glide, GlideEffect )
|
|
|
|
KWIN_EFFECT_SUPPORTED( glide, GlideEffect::supported() )
|
|
|
|
|
2010-11-02 20:33:54 +00:00
|
|
|
static const int IsGlideWindow = 0x22A982D4;
|
|
|
|
|
2010-05-11 18:45:39 +00:00
|
|
|
GlideEffect::GlideEffect()
|
|
|
|
{
|
|
|
|
reconfigure( ReconfigureAll );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GlideEffect::supported()
|
|
|
|
{
|
|
|
|
return effects->compositingType() == OpenGLCompositing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::reconfigure( ReconfigureFlags )
|
|
|
|
{
|
|
|
|
KConfigGroup conf = effects->effectConfig( "Glide" );
|
|
|
|
duration = animationTime( conf, "AnimationTime", 350 );
|
|
|
|
effect = (EffectStyle) conf.readEntry( "GlideEffect", 0 );
|
|
|
|
angle = conf.readEntry( "GlideAngle", -90 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
if( !windows.isEmpty() )
|
2010-05-11 18:45:39 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
effects->prePaintScreen( data, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
InfoHash::iterator info = windows.find( w );
|
|
|
|
if( info != windows.end() )
|
2010-05-11 18:45:39 +00:00
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
data.setTransformed();
|
|
|
|
if( info->added )
|
|
|
|
info->timeLine.addTime( time );
|
|
|
|
else if( info->closed )
|
2010-05-11 18:45:39 +00:00
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
info->timeLine.removeTime( time );
|
|
|
|
if( info->deleted )
|
2010-05-11 18:45:39 +00:00
|
|
|
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DELETE );
|
|
|
|
}
|
|
|
|
}
|
2010-11-02 20:33:54 +00:00
|
|
|
|
2010-05-11 18:45:39 +00:00
|
|
|
effects->prePaintWindow( w, data, time );
|
2010-11-02 20:33:54 +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();
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
2010-11-03 08:34:01 +00:00
|
|
|
InfoHash::const_iterator info = windows.constFind( w );
|
2010-11-02 20:33:54 +00:00
|
|
|
if( info != windows.constEnd() )
|
2010-05-11 18:45:39 +00:00
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
const double progress = info->timeLine.value();
|
2010-05-11 18:45:39 +00:00
|
|
|
RotationData rot;
|
|
|
|
rot.axis = RotationData::XAxis;
|
2010-11-02 20:33:54 +00:00
|
|
|
rot.angle = angle * ( 1 - progress );
|
2010-05-11 18:45:39 +00:00
|
|
|
data.rotation = &rot;
|
2010-11-02 20:33:54 +00:00
|
|
|
data.opacity *= progress;
|
|
|
|
switch ( effect )
|
2010-05-11 18:45:39 +00:00
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
default:
|
|
|
|
case GlideInOut:
|
|
|
|
if( info->added )
|
|
|
|
glideIn( w, data );
|
|
|
|
else if( info->closed )
|
|
|
|
glideOut( w, data );
|
|
|
|
break;
|
|
|
|
case GlideOutIn:
|
|
|
|
if( info->added )
|
|
|
|
glideOut( w, data );
|
|
|
|
if( info->closed )
|
|
|
|
glideIn( w, data );
|
|
|
|
break;
|
|
|
|
case GlideIn: glideIn( w, data ); break;
|
|
|
|
case GlideOut: glideOut( w, data ); break;
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-02 20:33:54 +00:00
|
|
|
effects->paintWindow( w, mask, region, data );
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::glideIn(EffectWindow* w, WindowPaintData& data )
|
|
|
|
{
|
2010-11-03 08:34:01 +00:00
|
|
|
InfoHash::const_iterator info = windows.constFind( w );
|
2010-11-02 20:33:54 +00:00
|
|
|
if ( info == windows.constEnd() )
|
|
|
|
return;
|
|
|
|
const double progress = info->timeLine.value();
|
|
|
|
data.xScale *= progress;
|
|
|
|
data.yScale *= progress;
|
|
|
|
data.zScale *= progress;
|
|
|
|
data.xTranslate += int( w->width() / 2 * ( 1 - progress ) );
|
|
|
|
data.yTranslate += int( w->height() / 2 * ( 1 - progress ) );
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::glideOut(EffectWindow* w, WindowPaintData& data )
|
|
|
|
{
|
2010-11-03 08:34:01 +00:00
|
|
|
InfoHash::const_iterator info = windows.constFind( w );
|
2010-11-02 20:33:54 +00:00
|
|
|
if ( info == windows.constEnd() )
|
|
|
|
return;
|
|
|
|
const double progress = info->timeLine.value();
|
|
|
|
data.xScale *= ( 2 - progress );
|
|
|
|
data.yScale *= ( 2 - progress );
|
|
|
|
data.zScale *= ( 2 - progress );
|
|
|
|
data.xTranslate -= int( w->width() / 2 * ( 1 - progress ) );
|
|
|
|
data.yTranslate -= int( w->height() / 2 * ( 1 - progress ) );
|
2010-05-11 18:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::postPaintWindow( EffectWindow* w )
|
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
InfoHash::iterator info = windows.find( w );
|
|
|
|
if( info != windows.end() )
|
2010-05-11 18:45:39 +00:00
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
if( info->added && info->timeLine.value() == 1.0 )
|
2010-05-11 18:45:39 +00:00
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
windows.remove( w );
|
2010-05-11 18:45:39 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2010-11-02 20:33:54 +00:00
|
|
|
else if( info->closed && info->timeLine.value() == 0.0 )
|
2010-05-11 18:45:39 +00:00
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
info->closed = false;
|
|
|
|
if( info->deleted )
|
2010-05-11 18:45:39 +00:00
|
|
|
{
|
|
|
|
windows.remove( w );
|
|
|
|
w->unrefWindow();
|
|
|
|
}
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2010-11-02 20:33:54 +00:00
|
|
|
if( info->added || info->closed )
|
2010-05-11 18:45:39 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
effects->postPaintWindow( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::windowAdded( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if( !isGlideWindow( w ) )
|
|
|
|
return;
|
2010-11-02 20:33:54 +00:00
|
|
|
w->setData( IsGlideWindow, true );
|
|
|
|
const void *addGrab = w->data( WindowAddedGrabRole ).value<void*>();
|
|
|
|
if ( addGrab && addGrab != this )
|
|
|
|
return;
|
2010-05-11 18:45:39 +00:00
|
|
|
w->setData( WindowAddedGrabRole, QVariant::fromValue( static_cast<void*>( this )));
|
2010-11-02 20:33:54 +00:00
|
|
|
|
|
|
|
InfoHash::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 );
|
|
|
|
info->timeLine.setCurveShape( TimeLine::EaseOutCurve );
|
2010-05-11 18:45:39 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::windowClosed( EffectWindow* w )
|
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
if ( !isGlideWindow( w ) )
|
|
|
|
return;
|
|
|
|
const void *closeGrab = w->data( WindowClosedGrabRole ).value<void*>();
|
|
|
|
if ( closeGrab && closeGrab != this )
|
2010-05-11 18:45:39 +00:00
|
|
|
return;
|
|
|
|
w->refWindow();
|
2010-11-02 20:33:54 +00:00
|
|
|
w->setData( WindowClosedGrabRole, QVariant::fromValue( static_cast<void*>( this )));
|
|
|
|
|
|
|
|
InfoHash::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.setCurveShape( TimeLine::EaseInCurve );
|
|
|
|
info->timeLine.setProgress( 1.0 );
|
2010-05-11 18:45:39 +00:00
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlideEffect::windowDeleted( EffectWindow* w )
|
|
|
|
{
|
|
|
|
windows.remove( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GlideEffect::isGlideWindow( EffectWindow* w )
|
|
|
|
{
|
2010-11-02 20:33:54 +00:00
|
|
|
if ( effects->activeFullScreenEffect() )
|
|
|
|
return false;
|
|
|
|
if ( w->data( IsGlideWindow ).toBool() )
|
|
|
|
return true;
|
|
|
|
if ( w->hasDecoration() )
|
|
|
|
return true;
|
|
|
|
if ( !w->isManaged() || w->isMenu() || w->isNotification() || w->isDesktop() ||
|
|
|
|
w->isDock() || w->isSplash() || w->isTopMenu() || w->isToolbar() )
|
2010-05-11 18:45:39 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} // namespace
|