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-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 );
|
|
|
|
scene = new SceneXrender( 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-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-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-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( const QRect& r )
|
|
|
|
{
|
2006-07-05 20:52:57 +00:00
|
|
|
addDamage( r.x(), r.y(), r.width(), r.height());
|
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-07-05 16:04:11 +00:00
|
|
|
XRectangle r;
|
|
|
|
r.x = x;
|
|
|
|
r.y = y;
|
|
|
|
r.width = w;
|
|
|
|
r.height = h;
|
|
|
|
addDamage( XFixesCreateRegion( display(), &r, 1 ), true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addDamage( XserverRegion r, bool destroy )
|
2006-07-04 20:02:07 +00:00
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
2006-07-05 16:04:11 +00:00
|
|
|
if( damage != None )
|
|
|
|
{
|
|
|
|
XFixesUnionRegion( display(), damage, damage, r );
|
|
|
|
if( destroy )
|
|
|
|
XFixesDestroyRegion( display(), r );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( destroy )
|
|
|
|
damage = r;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
damage = XFixesCreateRegion( display(), NULL, 0 );
|
|
|
|
XFixesCopyRegion( display(), damage, r );
|
|
|
|
}
|
|
|
|
}
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
2006-07-06 13:17:44 +00:00
|
|
|
|
|
|
|
void Workspace::addDamage( Toplevel* c, const QRect& r )
|
|
|
|
{
|
|
|
|
addDamage( c, r.x(), r.y(), r.width(), r.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addDamage( Toplevel* c, int x, int y, int w, int h )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
XRectangle r;
|
|
|
|
r.x = x;
|
|
|
|
r.y = y;
|
|
|
|
r.width = w;
|
|
|
|
r.height = h;
|
|
|
|
addDamage( c, XFixesCreateRegion( display(), &r, 1 ), true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addDamage( Toplevel* c, XserverRegion r, bool destroy )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
if( !destroy )
|
|
|
|
{
|
|
|
|
XserverRegion r2 = XFixesCreateRegion( display(), NULL, 0 );
|
|
|
|
XFixesCopyRegion( display(), r2, r );
|
|
|
|
r = r2;
|
|
|
|
destroy = true;
|
|
|
|
}
|
|
|
|
scene->transformWindowDamage( c, r );
|
|
|
|
if( damage != None )
|
|
|
|
{
|
|
|
|
XFixesUnionRegion( display(), damage, damage, r );
|
|
|
|
XFixesDestroyRegion( display(), r );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
damage = r;
|
|
|
|
}
|
|
|
|
|
2006-07-04 20:02:07 +00:00
|
|
|
void Workspace::compositeTimeout()
|
|
|
|
{
|
2006-07-05 16:04:11 +00:00
|
|
|
if( damage == None )
|
2006-07-04 20:02:07 +00:00
|
|
|
return;
|
2006-07-05 12:00:13 +00:00
|
|
|
ToplevelList windows;
|
|
|
|
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-06 18:22:01 +00:00
|
|
|
scene->paint( damage, windows );
|
2006-07-05 16:04:11 +00:00
|
|
|
XFixesDestroyRegion( display(), damage );
|
|
|
|
damage = None;
|
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-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 );
|
|
|
|
window_pixmap = None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-05 16:04:11 +00:00
|
|
|
XserverRegion r = XFixesCreateRegion( display(), &e->area, 1 );
|
|
|
|
XFixesTranslateRegion( display(), r, x(), y());
|
2006-07-06 13:17:44 +00:00
|
|
|
workspace()->addDamage( this, r, true );
|
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
|