2006-07-04 20:51:01 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#include "effects.h"
|
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
#include "toplevel.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "scene.h"
|
|
|
|
|
2006-07-04 20:51:01 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
2006-07-05 12:56:04 +00:00
|
|
|
//****************************************
|
|
|
|
// Matrix
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
Matrix::Matrix()
|
|
|
|
{
|
|
|
|
m[ 0 ][ 0 ] = 1;
|
|
|
|
m[ 0 ][ 1 ] = 0;
|
|
|
|
m[ 0 ][ 2 ] = 0;
|
|
|
|
m[ 0 ][ 3 ] = 0;
|
|
|
|
m[ 1 ][ 0 ] = 0;
|
|
|
|
m[ 1 ][ 1 ] = 1;
|
|
|
|
m[ 1 ][ 2 ] = 0;
|
|
|
|
m[ 1 ][ 3 ] = 0;
|
|
|
|
m[ 2 ][ 0 ] = 0;
|
|
|
|
m[ 2 ][ 1 ] = 0;
|
|
|
|
m[ 2 ][ 2 ] = 1;
|
|
|
|
m[ 2 ][ 3 ] = 0;
|
|
|
|
m[ 3 ][ 0 ] = 0;
|
|
|
|
m[ 3 ][ 1 ] = 0;
|
|
|
|
m[ 3 ][ 2 ] = 0;
|
|
|
|
m[ 3 ][ 3 ] = 1;
|
|
|
|
}
|
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
Matrix operator*( const Matrix& m1, const Matrix& m2 )
|
|
|
|
{
|
|
|
|
Matrix r;
|
|
|
|
for( int i = 0;
|
|
|
|
i < 4;
|
|
|
|
++i )
|
|
|
|
for( int j = 0;
|
|
|
|
j < 4;
|
|
|
|
++j )
|
|
|
|
{
|
|
|
|
double s = 0;
|
|
|
|
for( int k = 0;
|
|
|
|
k < 4;
|
|
|
|
++k )
|
2006-07-06 14:20:03 +00:00
|
|
|
s += m1.m[ k ][ j ] * m2.m[ i ][ k ];
|
2006-07-06 13:17:44 +00:00
|
|
|
r.m[ i ][ j ] = s;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Matrix::isIdentity() const
|
|
|
|
{
|
|
|
|
return m[ 0 ][ 0 ] == 1
|
|
|
|
&& m[ 0 ][ 1 ] == 0
|
|
|
|
&& m[ 0 ][ 2 ] == 0
|
|
|
|
&& m[ 0 ][ 3 ] == 0
|
|
|
|
&& m[ 1 ][ 0 ] == 0
|
|
|
|
&& m[ 1 ][ 1 ] == 1
|
|
|
|
&& m[ 1 ][ 2 ] == 0
|
|
|
|
&& m[ 1 ][ 3 ] == 0
|
|
|
|
&& m[ 2 ][ 0 ] == 0
|
|
|
|
&& m[ 2 ][ 1 ] == 0
|
|
|
|
&& m[ 2 ][ 2 ] == 1
|
|
|
|
&& m[ 2 ][ 3 ] == 0
|
|
|
|
&& m[ 3 ][ 0 ] == 0
|
|
|
|
&& m[ 3 ][ 1 ] == 0
|
|
|
|
&& m[ 3 ][ 2 ] == 0
|
|
|
|
&& m[ 3 ][ 3 ] == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Matrix::isOnlyTranslate() const
|
|
|
|
{
|
|
|
|
return m[ 0 ][ 0 ] == 1
|
|
|
|
&& m[ 0 ][ 1 ] == 0
|
|
|
|
&& m[ 0 ][ 2 ] == 0
|
|
|
|
// && m[ 0 ][ 3 ] ==
|
|
|
|
&& m[ 1 ][ 0 ] == 0
|
|
|
|
&& m[ 1 ][ 1 ] == 1
|
|
|
|
&& m[ 1 ][ 2 ] == 0
|
|
|
|
// && m[ 1 ][ 3 ] ==
|
|
|
|
&& m[ 2 ][ 0 ] == 0
|
|
|
|
&& m[ 2 ][ 1 ] == 0
|
|
|
|
&& m[ 2 ][ 2 ] == 1
|
|
|
|
// && m[ 2 ][ 3 ] ==
|
|
|
|
&& m[ 3 ][ 0 ] == 0
|
|
|
|
&& m[ 3 ][ 1 ] == 0
|
|
|
|
&& m[ 3 ][ 2 ] == 0
|
|
|
|
&& m[ 3 ][ 3 ] == 1;
|
|
|
|
}
|
|
|
|
|
2006-07-06 14:20:03 +00:00
|
|
|
QPoint Matrix::transform( const QPoint& p ) const
|
|
|
|
{
|
|
|
|
int vec[ 4 ] = { p.x(), p.y(), 0, 1 };
|
|
|
|
int res[ 4 ];
|
|
|
|
for( int i = 0;
|
|
|
|
i < 4;
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
double s = 0;
|
|
|
|
for( int j = 0;
|
|
|
|
j < 4;
|
|
|
|
++j )
|
|
|
|
s += m[ i ][ j ] * vec[ j ];
|
|
|
|
res[ i ] = int( s );
|
|
|
|
}
|
|
|
|
return QPoint( res[ 0 ], res[ 1 ] );
|
|
|
|
}
|
|
|
|
|
2006-07-04 20:51:01 +00:00
|
|
|
//****************************************
|
|
|
|
// Effect
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
Effect::~Effect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void Effect::windowUserMovedResized( Toplevel* , bool, bool )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-07-06 18:22:01 +00:00
|
|
|
void Effect::transformWindow( Toplevel*, Matrix&, EffectData& )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-07-06 19:02:14 +00:00
|
|
|
void Effect::transformWorkspace( Matrix&, EffectData& )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void Effect::windowDeleted( Toplevel* )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-07-06 18:22:01 +00:00
|
|
|
void MakeHalfTransparent::transformWindow( Toplevel* c, Matrix&, EffectData& data )
|
2006-07-06 13:17:44 +00:00
|
|
|
{
|
|
|
|
if( c->isDialog())
|
|
|
|
data.opacity *= 0.8;
|
|
|
|
if( Client* c2 = dynamic_cast< Client* >( c ))
|
|
|
|
if( c2->isMove() || c2->isResize())
|
|
|
|
data.opacity *= 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MakeHalfTransparent::windowUserMovedResized( Toplevel* c, bool first, bool last )
|
|
|
|
{
|
|
|
|
if( first || last )
|
|
|
|
c->workspace()->addDamage( c, c->geometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
ShakyMove::ShakyMove()
|
|
|
|
{
|
|
|
|
connect( &timer, SIGNAL( timeout()), SLOT( tick()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int shaky_diff[] = { 0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1 };
|
|
|
|
static const int SHAKY_MAX = sizeof( shaky_diff ) / sizeof( shaky_diff[ 0 ] );
|
|
|
|
|
2006-07-06 18:22:01 +00:00
|
|
|
void ShakyMove::transformWindow( Toplevel* c, Matrix& matrix, EffectData& )
|
2006-07-06 13:17:44 +00:00
|
|
|
{
|
|
|
|
if( windows.contains( c ))
|
|
|
|
{
|
|
|
|
Matrix m;
|
|
|
|
m.m[ 0 ][ 3 ] = shaky_diff[ windows[ c ]];
|
2006-07-06 18:22:01 +00:00
|
|
|
matrix *= m;
|
2006-07-06 13:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShakyMove::windowUserMovedResized( Toplevel* c, bool first, bool last )
|
|
|
|
{
|
|
|
|
if( first )
|
|
|
|
{
|
|
|
|
if( windows.isEmpty())
|
|
|
|
timer.start( 50 );
|
|
|
|
windows[ c ] = 0;
|
|
|
|
}
|
|
|
|
else if( last )
|
|
|
|
{
|
|
|
|
windows.remove( c );
|
|
|
|
scene->updateTransformation( c );
|
|
|
|
c->workspace()->addDamage( c, c->geometry().adjusted( -3, 7, 0, 0 ));
|
|
|
|
if( windows.isEmpty())
|
|
|
|
timer.stop();
|
|
|
|
}
|
|
|
|
}
|
2006-07-04 20:51:01 +00:00
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void ShakyMove::windowDeleted( Toplevel* c )
|
2006-07-06 09:55:10 +00:00
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
windows.remove( c );
|
|
|
|
if( windows.isEmpty())
|
|
|
|
timer.stop();
|
|
|
|
}
|
2006-07-06 09:55:10 +00:00
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void ShakyMove::tick()
|
2006-07-06 09:55:10 +00:00
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
for( QMap< Toplevel*, int >::Iterator it = windows.begin();
|
|
|
|
it != windows.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
if( *it == SHAKY_MAX - 1 )
|
|
|
|
*it = 0;
|
|
|
|
else
|
|
|
|
++(*it);
|
|
|
|
scene->updateTransformation( it.key());
|
|
|
|
it.key()->workspace()->addDamage( it.key(), it.key()->geometry().adjusted( -1, 2, 0, 0 ));
|
|
|
|
}
|
2006-07-06 09:55:10 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 18:22:01 +00:00
|
|
|
void GrowMove::transformWindow( Toplevel* c, Matrix& matrix, EffectData& )
|
|
|
|
{
|
|
|
|
if( Client* c2 = dynamic_cast< Client* >( c ))
|
|
|
|
if( c2->isMove())
|
|
|
|
{
|
|
|
|
Matrix m;
|
|
|
|
m.m[ 0 ][ 0 ] = 1.2;
|
|
|
|
m.m[ 1 ][ 1 ] = 1.4;
|
|
|
|
matrix *= m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrowMove::windowUserMovedResized( Toplevel* c, bool first, bool last )
|
|
|
|
{
|
|
|
|
if( first || last )
|
|
|
|
{
|
|
|
|
c->workspace()->addDamage( c, c->geometry());
|
|
|
|
scene->updateTransformation( c );
|
|
|
|
c->workspace()->addDamage( c, c->geometry());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-06 19:02:14 +00:00
|
|
|
ShiftWorkspaceUp::ShiftWorkspaceUp( Workspace* ws )
|
|
|
|
: up( false )
|
|
|
|
, wspace( ws )
|
|
|
|
{
|
|
|
|
connect( &timer, SIGNAL( timeout()), SLOT( tick()));
|
|
|
|
timer.start( 2000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShiftWorkspaceUp::transformWorkspace( Matrix& matrix, EffectData& )
|
|
|
|
{
|
|
|
|
if( !up )
|
|
|
|
return;
|
|
|
|
Matrix m;
|
|
|
|
m.m[ 1 ][ 3 ] = -10;
|
|
|
|
matrix *= m;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShiftWorkspaceUp::tick()
|
|
|
|
{
|
|
|
|
up = !up;
|
|
|
|
wspace->addDamage( 0, 0, displayWidth(), displayHeight());
|
|
|
|
}
|
|
|
|
|
2006-07-06 09:55:10 +00:00
|
|
|
static MakeHalfTransparent* mht;
|
2006-07-06 13:17:44 +00:00
|
|
|
static ShakyMove* sm;
|
2006-07-06 18:22:01 +00:00
|
|
|
static GrowMove* gm;
|
2006-07-06 19:02:14 +00:00
|
|
|
static ShiftWorkspaceUp* swu;
|
2006-07-06 13:17:44 +00:00
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// EffectsHandler
|
|
|
|
//****************************************
|
|
|
|
|
2006-07-06 19:02:14 +00:00
|
|
|
EffectsHandler::EffectsHandler( Workspace* ws )
|
2006-07-06 09:55:10 +00:00
|
|
|
{
|
2006-07-10 18:34:57 +00:00
|
|
|
if( !compositing())
|
|
|
|
return;
|
2006-07-06 09:55:10 +00:00
|
|
|
mht = new MakeHalfTransparent;
|
2006-07-06 13:17:44 +00:00
|
|
|
sm = new ShakyMove;
|
2006-07-06 18:22:01 +00:00
|
|
|
// gm = new GrowMove;
|
2006-07-06 19:02:14 +00:00
|
|
|
swu = new ShiftWorkspaceUp( ws );
|
2006-07-06 09:55:10 +00:00
|
|
|
}
|
2006-07-10 18:34:57 +00:00
|
|
|
|
|
|
|
EffectsHandler::~EffectsHandler()
|
|
|
|
{
|
|
|
|
delete mht;
|
|
|
|
mht = NULL;
|
|
|
|
delete sm;
|
|
|
|
sm = NULL;
|
|
|
|
delete gm;
|
|
|
|
gm = NULL;
|
|
|
|
delete swu;
|
|
|
|
swu = NULL;
|
|
|
|
}
|
2006-07-06 09:55:10 +00:00
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void EffectsHandler::windowUserMovedResized( Toplevel* c, bool first, bool last )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
if( mht )
|
|
|
|
mht->windowUserMovedResized( c, first, last );
|
|
|
|
if( sm )
|
|
|
|
sm->windowUserMovedResized( c, first, last );
|
2006-07-06 18:22:01 +00:00
|
|
|
if( gm )
|
|
|
|
gm->windowUserMovedResized( c, first, last );
|
2006-07-06 19:02:14 +00:00
|
|
|
if( swu )
|
|
|
|
swu->windowUserMovedResized( c, first, last );
|
2006-07-04 20:51:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 18:22:01 +00:00
|
|
|
void EffectsHandler::transformWindow( Toplevel* c, Matrix& matrix, EffectData& data )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
if( mht )
|
2006-07-06 18:22:01 +00:00
|
|
|
mht->transformWindow( c, matrix, data );
|
2006-07-06 13:17:44 +00:00
|
|
|
if( sm )
|
2006-07-06 18:22:01 +00:00
|
|
|
sm->transformWindow( c, matrix, data );
|
|
|
|
if( gm )
|
|
|
|
gm->transformWindow( c, matrix, data );
|
2006-07-06 19:02:14 +00:00
|
|
|
if( swu )
|
|
|
|
swu->transformWindow( c, matrix, data );
|
2006-07-04 20:51:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 19:02:14 +00:00
|
|
|
void EffectsHandler::transformWorkspace( Matrix& matrix, EffectData& data )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
if( mht )
|
2006-07-06 19:02:14 +00:00
|
|
|
mht->transformWorkspace( matrix, data );
|
2006-07-06 13:17:44 +00:00
|
|
|
if( sm )
|
2006-07-06 19:02:14 +00:00
|
|
|
sm->transformWorkspace( matrix, data );
|
2006-07-06 18:22:01 +00:00
|
|
|
if( gm )
|
2006-07-06 19:02:14 +00:00
|
|
|
gm->transformWorkspace( matrix, data );
|
|
|
|
if( swu )
|
|
|
|
swu->transformWorkspace( matrix, data );
|
2006-07-04 20:51:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void EffectsHandler::windowDeleted( Toplevel* c )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
if( mht )
|
|
|
|
mht->windowDeleted( c );
|
|
|
|
if( sm )
|
|
|
|
sm->windowDeleted( c );
|
2006-07-06 18:22:01 +00:00
|
|
|
if( gm )
|
|
|
|
gm->windowDeleted( c );
|
2006-07-06 19:02:14 +00:00
|
|
|
if( swu )
|
|
|
|
swu->windowDeleted( c );
|
2006-07-04 20:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EffectsHandler* effects;
|
|
|
|
|
|
|
|
} // namespace
|
2006-07-06 13:17:44 +00:00
|
|
|
|
|
|
|
#include "effects.moc"
|