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 13:17:44 +00:00
|
|
|
void Effect::transformWindow( Toplevel*, EffectData& )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void Effect::transformWorkspace( Workspace*, 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 13:17:44 +00:00
|
|
|
void MakeHalfTransparent::transformWindow( Toplevel* c, EffectData& data )
|
|
|
|
{
|
|
|
|
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 ] );
|
|
|
|
|
|
|
|
void ShakyMove::transformWindow( Toplevel* c, EffectData& data )
|
|
|
|
{
|
|
|
|
if( windows.contains( c ))
|
|
|
|
{
|
|
|
|
Matrix m;
|
|
|
|
m.m[ 0 ][ 3 ] = shaky_diff[ windows[ c ]];
|
|
|
|
data.matrix *= m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static MakeHalfTransparent* mht;
|
2006-07-06 13:17:44 +00:00
|
|
|
static ShakyMove* sm;
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// EffectsHandler
|
|
|
|
//****************************************
|
|
|
|
|
2006-07-06 09:55:10 +00:00
|
|
|
EffectsHandler::EffectsHandler()
|
|
|
|
{
|
|
|
|
mht = new MakeHalfTransparent;
|
2006-07-06 13:17:44 +00:00
|
|
|
sm = new ShakyMove;
|
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-04 20:51:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void EffectsHandler::transformWindow( Toplevel* c, EffectData& data )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
if( mht )
|
|
|
|
mht->transformWindow( c, data );
|
|
|
|
if( sm )
|
|
|
|
sm->transformWindow( c, data );
|
2006-07-04 20:51:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 13:17:44 +00:00
|
|
|
void EffectsHandler::transformWorkspace( Workspace* w, EffectData& data )
|
2006-07-04 20:51:01 +00:00
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
if( mht )
|
|
|
|
mht->transformWorkspace( w, data );
|
|
|
|
if( sm )
|
|
|
|
sm->transformWorkspace( w, 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-04 20:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EffectsHandler* effects;
|
|
|
|
|
|
|
|
} // namespace
|
2006-07-06 13:17:44 +00:00
|
|
|
|
|
|
|
#include "effects.moc"
|