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;
|
|
|
|
compositeTimer.start( 20 );
|
|
|
|
XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
|
2006-07-05 13:26:08 +00:00
|
|
|
// scene = new SceneBasic( this );
|
2006-09-29 16:49:34 +00:00
|
|
|
// scene = new SceneXrender( this );
|
|
|
|
scene = new SceneOpenGL( this );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addDamage( Toplevel* c, int x, int y, int w, int h )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
2006-09-30 15:40:03 +00:00
|
|
|
addDamage( c, QRect( x, y, w, h ));
|
2006-07-06 13:17:44 +00:00
|
|
|
}
|
|
|
|
|
2006-09-30 15:40:03 +00:00
|
|
|
void Workspace::addDamage( Toplevel* c, const QRect& r )
|
2006-07-06 13:17:44 +00:00
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
2006-09-30 15:40:03 +00:00
|
|
|
QRegion r2( r );
|
|
|
|
scene->transformWindowDamage( c, r2 );
|
|
|
|
damage_region += r2;
|
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 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-07-04 20:02:07 +00:00
|
|
|
if( window_pixmap != None )
|
|
|
|
XFreePixmap( display(), window_pixmap );
|
2006-07-13 18:17:49 +00:00
|
|
|
window_pixmap = None;
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region = QRegion();
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::resetWindowPixmap()
|
|
|
|
{
|
2006-07-05 12:30:03 +00:00
|
|
|
if( !compositing())
|
2006-07-04 20:02:07 +00:00
|
|
|
return;
|
|
|
|
if( window_pixmap != None )
|
|
|
|
XFreePixmap( display(), window_pixmap );
|
|
|
|
window_pixmap = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
Pixmap Toplevel::windowPixmap() const
|
|
|
|
{
|
2006-07-05 12:30:03 +00:00
|
|
|
if( window_pixmap == None && compositing())
|
2006-07-04 20:02:07 +00:00
|
|
|
window_pixmap = XCompositeNameWindowPixmap( display(), handle());
|
|
|
|
return window_pixmap;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
workspace()->addDamage( this, 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
|