2006-07-04 20:02:07 +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 "utils.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "unmanaged.h"
|
2006-07-10 18:34:57 +00:00
|
|
|
#include "effects.h"
|
2006-07-05 12:30:03 +00:00
|
|
|
#include "scene.h"
|
|
|
|
#include "scene_basic.h"
|
2006-07-05 13:26:08 +00:00
|
|
|
#include "scene_xrender.h"
|
2006-09-29 16:49:34 +00:00
|
|
|
#include "scene_opengl.h"
|
2006-07-04 20:02:07 +00:00
|
|
|
|
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Workspace
|
|
|
|
//****************************************
|
|
|
|
|
2006-07-05 16:04:11 +00:00
|
|
|
#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE ) && defined( HAVE_XFIXES )
|
2006-07-04 20:02:07 +00:00
|
|
|
void Workspace::setupCompositing()
|
|
|
|
{
|
2006-07-05 21:46:01 +00:00
|
|
|
if( !options->useTranslucency )
|
|
|
|
return;
|
2006-07-04 20:02:07 +00:00
|
|
|
if( !Extensions::compositeAvailable() || !Extensions::damageAvailable())
|
|
|
|
return;
|
2006-07-05 12:30:03 +00:00
|
|
|
if( scene != NULL )
|
2006-07-04 20:02:07 +00:00
|
|
|
return;
|
2006-10-07 21:17:30 +00:00
|
|
|
char type = 'O';
|
|
|
|
if( getenv( "KWIN_COMPOSE" ))
|
|
|
|
type = getenv( "KWIN_COMPOSE" )[ 0 ];
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case 'B':
|
|
|
|
scene = new SceneBasic( this );
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
scene = new SceneXrender( this );
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
scene = new SceneOpenGL( this );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
kDebug() << "No compositing" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2006-07-04 20:02:07 +00:00
|
|
|
compositeTimer.start( 20 );
|
|
|
|
XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
|
2006-09-30 15:48:31 +00:00
|
|
|
if( dynamic_cast< SceneOpenGL* >( scene ))
|
|
|
|
kDebug() << "OpenGL compositing" << endl;
|
|
|
|
else if( dynamic_cast< SceneXrender* >( scene ))
|
|
|
|
kDebug() << "XRender compositing" << endl;
|
|
|
|
else if( dynamic_cast< SceneBasic* >( scene ))
|
|
|
|
kDebug() << "X compositing" << endl;
|
2006-07-10 18:34:57 +00:00
|
|
|
effects = new EffectsHandler( this );
|
2006-07-05 16:04:11 +00:00
|
|
|
addDamage( 0, 0, displayWidth(), displayHeight());
|
2006-07-05 21:46:01 +00:00
|
|
|
foreach( Client* c, clients )
|
|
|
|
c->setupCompositing();
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
c->setupCompositing();
|
2006-09-29 19:05:36 +00:00
|
|
|
foreach( Client* c, clients )
|
|
|
|
scene->windowAdded( c );
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
scene->windowAdded( c );
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::finishCompositing()
|
|
|
|
{
|
2006-07-05 12:30:03 +00:00
|
|
|
if( scene == NULL )
|
2006-07-04 20:02:07 +00:00
|
|
|
return;
|
2006-09-29 19:05:36 +00:00
|
|
|
foreach( Client* c, clients )
|
|
|
|
scene->windowDeleted( c );
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
scene->windowDeleted( c );
|
2006-07-05 21:46:01 +00:00
|
|
|
foreach( Client* c, clients )
|
|
|
|
c->finishCompositing();
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
c->finishCompositing();
|
2006-07-04 20:02:07 +00:00
|
|
|
XCompositeUnredirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
|
|
|
|
compositeTimer.stop();
|
2006-07-10 18:34:57 +00:00
|
|
|
delete effects;
|
|
|
|
effects = NULL;
|
2006-07-05 12:30:03 +00:00
|
|
|
delete scene;
|
|
|
|
scene = NULL;
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region = QRegion();
|
2006-07-05 20:52:57 +00:00
|
|
|
for( ClientList::ConstIterator it = clients.begin();
|
|
|
|
it != clients.end();
|
|
|
|
++it )
|
|
|
|
{ // forward all opacity values to the frame in case there'll be other CM running
|
|
|
|
if( (*it)->opacity() != 1.0 )
|
|
|
|
{
|
|
|
|
NETWinInfo i( display(), (*it)->frameId(), rootWindow(), 0 );
|
2006-07-05 22:26:34 +00:00
|
|
|
i.setOpacity( static_cast< unsigned long >((*it)->opacity() * 0xffffffff ));
|
2006-07-05 20:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2006-07-05 16:04:11 +00:00
|
|
|
void Workspace::addDamage( int x, int y, int w, int h )
|
|
|
|
{
|
2006-07-06 13:17:44 +00:00
|
|
|
if( !compositing())
|
|
|
|
return;
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region += QRegion( x, y, w, h );
|
2006-07-05 16:04:11 +00:00
|
|
|
}
|
|
|
|
|
2006-09-30 15:40:03 +00:00
|
|
|
void Workspace::addDamage( const QRect& r )
|
2006-07-04 20:02:07 +00:00
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region += r;
|
2006-07-06 13:17:44 +00:00
|
|
|
}
|
|
|
|
|
2006-07-04 20:02:07 +00:00
|
|
|
void Workspace::compositeTimeout()
|
|
|
|
{
|
2006-09-30 15:40:03 +00:00
|
|
|
if( damage_region.isEmpty()) // no damage
|
2006-07-13 18:17:49 +00:00
|
|
|
return;
|
2006-09-30 15:40:03 +00:00
|
|
|
ToplevelList windows;
|
2006-07-05 12:00:13 +00:00
|
|
|
Window* children;
|
|
|
|
unsigned int children_count;
|
|
|
|
Window dummy;
|
|
|
|
XQueryTree( display(), rootWindow(), &dummy, &dummy, &children, &children_count );
|
|
|
|
for( unsigned int i = 0;
|
|
|
|
i < children_count;
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
if( Client* c = findClient( FrameIdMatchPredicate( children[ i ] )))
|
2006-07-04 20:02:07 +00:00
|
|
|
{
|
2006-07-05 12:30:03 +00:00
|
|
|
if( c->isShown( true ) && c->isOnCurrentDesktop())
|
|
|
|
windows.append( c );
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
2006-07-05 12:30:03 +00:00
|
|
|
else if( Unmanaged* c = findUnmanaged( HandleMatchPredicate( children[ i ] )))
|
|
|
|
windows.append( c );
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
2006-07-13 18:17:49 +00:00
|
|
|
scene->paint( damage_region, windows );
|
2006-09-30 16:17:54 +00:00
|
|
|
foreach( Toplevel* c, windows )
|
|
|
|
c->resetDamage();
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region = QRegion();
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Toplevel
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
void Toplevel::setupCompositing()
|
|
|
|
{
|
2006-07-05 12:30:03 +00:00
|
|
|
if( !compositing())
|
2006-07-04 20:02:07 +00:00
|
|
|
return;
|
2006-07-05 16:04:11 +00:00
|
|
|
if( damage_handle != None )
|
2006-07-04 20:02:07 +00:00
|
|
|
return;
|
2006-07-05 16:04:11 +00:00
|
|
|
damage_handle = XDamageCreate( display(), handle(), XDamageReportRawRectangles );
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region = QRegion( 0, 0, width(), height());
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::finishCompositing()
|
|
|
|
{
|
2006-07-05 16:04:11 +00:00
|
|
|
if( damage_handle == None )
|
2006-07-04 20:02:07 +00:00
|
|
|
return;
|
2006-07-05 16:04:11 +00:00
|
|
|
XDamageDestroy( display(), damage_handle );
|
|
|
|
damage_handle = None;
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region = QRegion();
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2006-10-08 21:17:38 +00:00
|
|
|
Pixmap Toplevel::createWindowPixmap() const
|
2006-07-04 20:02:07 +00:00
|
|
|
{
|
2006-10-08 21:17:38 +00:00
|
|
|
assert( compositing());
|
|
|
|
return XCompositeNameWindowPixmap( display(), handle());
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2006-07-05 16:04:11 +00:00
|
|
|
void Toplevel::damageNotifyEvent( XDamageNotifyEvent* e )
|
2006-07-04 20:02:07 +00:00
|
|
|
{
|
2006-09-30 15:40:03 +00:00
|
|
|
addDamage( e->area.x, e->area.y, e->area.width, e->area.height );
|
2006-07-13 18:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addDamage( const QRect& r )
|
|
|
|
{
|
|
|
|
addDamage( r.x(), r.y(), r.width(), r.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addDamage( int x, int y, int w, int h )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
2006-09-30 15:40:03 +00:00
|
|
|
QRect r( x, y, w, h );
|
|
|
|
damage_region += r;
|
|
|
|
r.translate( this->x(), this->y());
|
|
|
|
// this could be possibly optimized to damage Workspace only if the toplevel
|
|
|
|
// is actually visible there and not obscured by something, but I guess
|
|
|
|
// that's not really worth it
|
2006-10-07 21:18:36 +00:00
|
|
|
workspace()->addDamage( r );
|
2006-07-13 18:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::resetDamage()
|
|
|
|
{
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region = QRegion();
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
2006-07-06 13:17:44 +00:00
|
|
|
|
2006-07-04 20:02:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace
|