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.
|
|
|
|
******************************************************************/
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
/*
|
|
|
|
Code related to compositing (redirecting windows to pixmaps and tracking
|
|
|
|
window damage).
|
|
|
|
|
|
|
|
Docs:
|
|
|
|
|
|
|
|
XComposite (the protocol, but the function calls map to it):
|
2007-01-15 14:58:35 +00:00
|
|
|
http://gitweb.freedesktop.org/?p=xorg/proto/compositeproto.git;a=blob_plain;hb=HEAD;f=compositeproto.txt
|
2006-10-29 19:23:45 +00:00
|
|
|
|
|
|
|
XDamage (again the protocol):
|
2007-01-15 14:58:35 +00:00
|
|
|
http://gitweb.freedesktop.org/?p=xorg/proto/damageproto.git;a=blob_plain;hb=HEAD;f=damageproto.txt
|
2006-10-29 19:23:45 +00:00
|
|
|
|
|
|
|
Composite HOWTO from Fredrik:
|
|
|
|
http://ktown.kde.org/~fredrik/composite_howto.html
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-07-04 20:02:07 +00:00
|
|
|
#include "utils.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "unmanaged.h"
|
2007-01-22 22:51:30 +00:00
|
|
|
#include "deleted.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
|
|
|
|
2006-11-08 15:08:20 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
2006-11-07 22:44:39 +00:00
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
|
2006-07-04 20:02:07 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Workspace
|
|
|
|
//****************************************
|
|
|
|
|
2006-11-04 12:26:59 +00:00
|
|
|
#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE )
|
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-11-08 15:08:20 +00:00
|
|
|
char selection_name[ 100 ];
|
|
|
|
sprintf( selection_name, "_NET_WM_CM_S%d", DefaultScreen( display()));
|
|
|
|
cm_selection = new KSelectionOwner( selection_name );
|
|
|
|
connect( cm_selection, SIGNAL( lostOwnership()), SLOT( lostCMSelection()));
|
|
|
|
cm_selection->claim( true ); // force claiming
|
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:
|
2006-11-16 09:05:40 +00:00
|
|
|
kDebug( 1212 ) << "No compositing" << endl;
|
2006-10-07 21:17:30 +00:00
|
|
|
return;
|
2006-10-24 18:31:33 +00:00
|
|
|
}
|
2006-11-23 21:16:49 +00:00
|
|
|
int rate = 0;
|
|
|
|
if( options->refreshRate > 0 )
|
|
|
|
{ // use manually configured refresh rate
|
|
|
|
rate = options->refreshRate;
|
|
|
|
}
|
|
|
|
#ifdef HAVE_XRANDR
|
|
|
|
else
|
|
|
|
{ // autoconfigure refresh rate based on XRandR info
|
|
|
|
if( Extensions::randrAvailable() )
|
|
|
|
{
|
|
|
|
XRRScreenConfiguration *config;
|
|
|
|
|
|
|
|
config = XRRGetScreenInfo( display(), rootWindow() );
|
|
|
|
rate = XRRConfigCurrentRate( config );
|
|
|
|
XRRFreeScreenConfigInfo( config );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// 0Hz or less is invalid, so we fallback to a default rate
|
|
|
|
if( rate <= 0 )
|
|
|
|
rate = 50;
|
|
|
|
// QTimer gives us 1msec (1000Hz) at best, so we ignore anything higher;
|
|
|
|
// however, since compositing is limited to no more than once per 5msec,
|
|
|
|
// 200Hz to 1000Hz are effectively identical
|
|
|
|
else if( rate > 1000 )
|
|
|
|
rate = 1000;
|
|
|
|
kDebug( 1212 ) << "Refresh rate " << rate << "Hz" << endl;
|
2006-12-03 13:29:14 +00:00
|
|
|
compositeRate = 1000 / rate;
|
|
|
|
compositeTimer.start( compositeRate );
|
2006-10-24 18:31:33 +00:00
|
|
|
lastCompositePaint.start();
|
2006-07-04 20:02:07 +00:00
|
|
|
XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
|
2006-09-30 15:48:31 +00:00
|
|
|
if( dynamic_cast< SceneOpenGL* >( scene ))
|
2006-11-16 09:05:40 +00:00
|
|
|
kDebug( 1212 ) << "OpenGL compositing" << endl;
|
2006-09-30 15:48:31 +00:00
|
|
|
else if( dynamic_cast< SceneXrender* >( scene ))
|
2006-11-16 09:05:40 +00:00
|
|
|
kDebug( 1212 ) << "XRender compositing" << endl;
|
2006-09-30 15:48:31 +00:00
|
|
|
else if( dynamic_cast< SceneBasic* >( scene ))
|
2006-11-16 09:05:40 +00:00
|
|
|
kDebug( 1212 ) << "X compositing" << endl;
|
2007-01-05 16:45:56 +00:00
|
|
|
new EffectsHandler( this ); // sets also the 'effects' pointer
|
2006-10-24 19:28:17 +00:00
|
|
|
addDamageFull();
|
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-11-08 14:45:30 +00:00
|
|
|
delete popup; // force re-creation of the Alt+F3 popup (opacity option)
|
|
|
|
popup = NULL;
|
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-11-08 15:08:20 +00:00
|
|
|
delete cm_selection;
|
2006-09-29 19:05:36 +00:00
|
|
|
foreach( Client* c, clients )
|
2007-01-22 22:51:30 +00:00
|
|
|
scene->windowClosed( c, NULL );
|
2006-09-29 19:05:36 +00:00
|
|
|
foreach( Unmanaged* c, unmanaged )
|
2007-01-22 22:51:30 +00:00
|
|
|
scene->windowClosed( c, NULL );
|
|
|
|
foreach( Deleted* c, deleted )
|
2006-09-29 19:05:36 +00:00
|
|
|
scene->windowDeleted( c );
|
2006-07-05 21:46:01 +00:00
|
|
|
foreach( Client* c, clients )
|
|
|
|
c->finishCompositing();
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
c->finishCompositing();
|
2007-01-22 22:51:30 +00:00
|
|
|
foreach( Deleted* c, deleted )
|
|
|
|
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-11-08 14:45:30 +00:00
|
|
|
delete popup; // force re-creation of the Alt+F3 popup (opacity option)
|
|
|
|
popup = NULL;
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2006-11-08 15:08:20 +00:00
|
|
|
void Workspace::lostCMSelection()
|
|
|
|
{
|
|
|
|
kDebug( 1212 ) << "Lost compositing manager selection" << endl;
|
|
|
|
finishCompositing();
|
|
|
|
}
|
|
|
|
|
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-10-24 19:28:17 +00:00
|
|
|
|
|
|
|
void Workspace::addDamageFull()
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
damage_region = QRegion( 0, 0, displayWidth(), displayHeight());
|
|
|
|
}
|
2006-07-06 13:17:44 +00:00
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
void Workspace::performCompositing()
|
2006-07-04 20:02:07 +00:00
|
|
|
{
|
2006-10-24 18:31:33 +00:00
|
|
|
// The event loop apparently tries to fire a QTimer as often as possible, even
|
|
|
|
// at the expense of not processing many X events. This means that the composite
|
|
|
|
// repaints can seriously impact performance of everything else, therefore throttle
|
|
|
|
// them - leave at least 5msec time after one repaint is finished and next one
|
|
|
|
// is started.
|
|
|
|
if( lastCompositePaint.elapsed() < 5 )
|
|
|
|
return;
|
2006-10-24 19:17:48 +00:00
|
|
|
if( damage_region.isEmpty()) // no damage
|
|
|
|
{
|
|
|
|
scene->idle();
|
|
|
|
return;
|
|
|
|
}
|
2006-10-29 19:23:45 +00:00
|
|
|
// create a list of all windows in the stacking order
|
|
|
|
// TODO keep this list like now a stacking order of Client window is kept
|
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 ] )))
|
2007-01-08 17:05:58 +00:00
|
|
|
windows.append( c );
|
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
|
|
|
}
|
2007-01-22 22:51:30 +00:00
|
|
|
foreach( Deleted* c, deleted ) // TODO remember stacking order somehow
|
2007-01-15 18:03:04 +00:00
|
|
|
windows.append( c );
|
2006-11-24 21:28:00 +00:00
|
|
|
QRegion damage = damage_region;
|
|
|
|
// clear all damage, so that post-pass can add damage for the next repaint
|
2006-10-24 19:17:48 +00:00
|
|
|
damage_region = QRegion();
|
2006-11-24 21:28:00 +00:00
|
|
|
scene->paint( damage, windows );
|
2006-12-03 13:29:14 +00:00
|
|
|
if( scene->waitSyncAvailable() && options->glVSync )
|
|
|
|
{ // if we're using vsync, then time the next paint pass to
|
|
|
|
// before the next available sync
|
|
|
|
int paintTime = ( lastCompositePaint.elapsed() % compositeRate ) +
|
|
|
|
( compositeRate / 2 );
|
|
|
|
if( paintTime >= compositeRate )
|
|
|
|
compositeTimer.start( paintTime );
|
|
|
|
else if( paintTime < compositeRate )
|
|
|
|
compositeTimer.start( compositeRate - paintTime );
|
|
|
|
}
|
2006-10-24 18:31:33 +00:00
|
|
|
lastCompositePaint.start();
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2006-11-07 22:44:39 +00:00
|
|
|
bool Workspace::createOverlay()
|
|
|
|
{
|
|
|
|
assert( overlay == None );
|
|
|
|
if( !Extensions::compositeOverlayAvailable())
|
|
|
|
return false;
|
|
|
|
#ifdef HAVE_XCOMPOSITE_OVERLAY
|
|
|
|
overlay = XCompositeGetOverlayWindow( display(), rootWindow());
|
|
|
|
if( overlay == None )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::setupOverlay( Window w )
|
|
|
|
{
|
|
|
|
assert( overlay != None );
|
|
|
|
XShapeCombineRectangles( display(), overlay, ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted );
|
2006-12-03 13:38:16 +00:00
|
|
|
if( w != None )
|
|
|
|
{
|
|
|
|
XShapeCombineRectangles( display(), w, ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted );
|
|
|
|
XMapWindow( display(), w );
|
|
|
|
}
|
2006-11-07 22:44:39 +00:00
|
|
|
XMapRaised( display(), overlay );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::destroyOverlay()
|
|
|
|
{
|
|
|
|
if( overlay == None )
|
|
|
|
return;
|
|
|
|
#ifdef HAVE_XCOMPOSITE_OVERLAY
|
|
|
|
XCompositeReleaseOverlayWindow( display(), overlay );
|
|
|
|
#endif
|
|
|
|
overlay = 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-09-30 15:40:03 +00:00
|
|
|
damage_region = QRegion( 0, 0, width(), height());
|
2007-01-22 22:57:22 +00:00
|
|
|
effect_window = new EffectWindow();
|
|
|
|
effect_window->setWindow( this );
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 22:51:30 +00:00
|
|
|
void Toplevel::finishCompositing()
|
2006-07-04 20:02:07 +00:00
|
|
|
{
|
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 );
|
2007-01-22 22:51:30 +00:00
|
|
|
discardWindowPixmap();
|
2006-07-05 16:04:11 +00:00
|
|
|
damage_handle = None;
|
2006-09-30 15:40:03 +00:00
|
|
|
damage_region = QRegion();
|
2007-01-22 22:57:22 +00:00
|
|
|
delete effect_window;
|
|
|
|
effect_window = NULL;
|
2006-07-04 20:02:07 +00:00
|
|
|
}
|
|
|
|
|
2007-01-12 23:21:36 +00:00
|
|
|
void Toplevel::discardWindowPixmap()
|
|
|
|
{
|
|
|
|
if( window_pix == None )
|
|
|
|
return;
|
|
|
|
XFreePixmap( display(), window_pix );
|
|
|
|
window_pix = None;
|
|
|
|
}
|
|
|
|
|
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 );
|
2006-11-24 21:50:10 +00:00
|
|
|
// resizing the decoration may lag behind a bit and when shrinking there
|
|
|
|
// may be a damage event coming with size larger than the current window size
|
|
|
|
r &= rect();
|
2006-09-30 15:40:03 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-10-24 19:28:17 +00:00
|
|
|
void Toplevel::addDamageFull()
|
|
|
|
{
|
2006-11-24 21:50:10 +00:00
|
|
|
damage_region = QRegion(); // first reset e.g. in case of shrinking
|
2006-10-24 19:28:17 +00:00
|
|
|
addDamage( rect());
|
|
|
|
}
|
|
|
|
|
2006-11-24 21:28:00 +00:00
|
|
|
void Toplevel::resetDamage( const QRect& r )
|
2006-07-13 18:17:49 +00:00
|
|
|
{
|
2006-11-24 21:28:00 +00:00
|
|
|
damage_region -= r;
|
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
|