2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +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):
|
|
|
|
http://gitweb.freedesktop.org/?p=xorg/proto/compositeproto.git;a=blob_plain;hb=HEAD;f=compositeproto.txt
|
|
|
|
|
|
|
|
XDamage (again the protocol):
|
|
|
|
http://gitweb.freedesktop.org/?p=xorg/proto/damageproto.git;a=blob_plain;hb=HEAD;f=damageproto.txt
|
|
|
|
|
2008-05-14 19:49:29 +00:00
|
|
|
Paper including basics on compositing, XGL vs AIGLX, XRender vs OpenGL, etc.:
|
|
|
|
http://www.vis.uni-stuttgart.de/~hopf/pub/LinuxTag2007_compiz_NextGenerationDesktop_Paper.pdf
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
Composite HOWTO from Fredrik:
|
|
|
|
http://ktown.kde.org/~fredrik/composite_howto.html
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-05-30 14:22:09 +00:00
|
|
|
#include <config-X11.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "utils.h"
|
2007-10-05 22:21:25 +00:00
|
|
|
#include <QTextStream>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "unmanaged.h"
|
|
|
|
#include "deleted.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "scene.h"
|
|
|
|
#include "scene_basic.h"
|
|
|
|
#include "scene_xrender.h"
|
|
|
|
#include "scene_opengl.h"
|
2007-09-18 13:59:06 +00:00
|
|
|
#include "compositingprefs.h"
|
2008-09-17 13:42:12 +00:00
|
|
|
#include "notifications.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <QMenu>
|
2008-09-17 13:42:12 +00:00
|
|
|
#include <kaction.h>
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
#include <klocale.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kxerrorhandler.h>
|
|
|
|
|
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
|
2007-05-30 14:22:09 +00:00
|
|
|
#ifdef HAVE_XCOMPOSITE
|
|
|
|
#include <X11/extensions/Xcomposite.h>
|
|
|
|
#if XCOMPOSITE_MAJOR > 0 || XCOMPOSITE_MINOR >= 3
|
|
|
|
#define HAVE_XCOMPOSITE_OVERLAY
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_XRANDR
|
|
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
#endif
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Workspace
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
void Workspace::setupCompositing()
|
|
|
|
{
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_COMPOSITING
|
2008-02-08 10:31:40 +00:00
|
|
|
if( scene != NULL )
|
|
|
|
return;
|
|
|
|
if( !options->useCompositing && getenv( "KWIN_COMPOSE") == NULL )
|
2007-06-06 15:24:17 +00:00
|
|
|
{
|
2009-01-01 21:17:58 +00:00
|
|
|
kDebug( 1212 ) << "Compositing is turned off in options or disabled";
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2007-06-06 15:24:17 +00:00
|
|
|
}
|
2008-05-19 21:48:47 +00:00
|
|
|
else if( compositingSuspended )
|
|
|
|
{
|
|
|
|
kDebug( 1212 ) << "Compositing is suspended";
|
|
|
|
return;
|
|
|
|
}
|
2007-09-26 16:34:08 +00:00
|
|
|
else if( !CompositingPrefs::compositingPossible() )
|
2008-01-14 22:16:29 +00:00
|
|
|
{
|
2008-01-29 14:23:26 +00:00
|
|
|
kError( 1212 ) << "Compositing is not possible";
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2008-01-14 22:16:29 +00:00
|
|
|
}
|
2007-07-19 16:20:05 +00:00
|
|
|
CompositingType type = options->compositingMode;
|
2007-04-29 17:35:43 +00:00
|
|
|
if( getenv( "KWIN_COMPOSE" ))
|
2007-07-19 16:20:05 +00:00
|
|
|
{
|
|
|
|
char c = getenv( "KWIN_COMPOSE" )[ 0 ];
|
|
|
|
switch( c )
|
|
|
|
{
|
|
|
|
case 'O':
|
|
|
|
type = OpenGLCompositing;
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
type = XRenderCompositing;
|
|
|
|
break;
|
|
|
|
default:
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "No compositing";
|
2007-07-19 16:20:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 10:31:40 +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
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
switch( type )
|
|
|
|
{
|
2007-07-19 16:20:05 +00:00
|
|
|
/*case 'B':
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "X compositing";
|
2007-05-30 14:22:09 +00:00
|
|
|
scene = new SceneBasic( this );
|
2007-07-19 16:20:05 +00:00
|
|
|
break; // don't fall through (this is a testing one) */
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2007-07-19 16:20:05 +00:00
|
|
|
case OpenGLCompositing:
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "OpenGL compositing";
|
2007-05-30 14:22:09 +00:00
|
|
|
scene = new SceneOpenGL( this );
|
2007-06-05 12:50:18 +00:00
|
|
|
if( !scene->initFailed())
|
|
|
|
break; // -->
|
|
|
|
delete scene;
|
|
|
|
scene = NULL;
|
2008-01-03 16:51:20 +00:00
|
|
|
break; // do not fall back to XRender for now, maybe in the future
|
2007-06-05 12:50:18 +00:00
|
|
|
#endif
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2007-07-19 16:20:05 +00:00
|
|
|
case XRenderCompositing:
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "XRender compositing";
|
2007-06-05 12:50:18 +00:00
|
|
|
scene = new SceneXrender( this );
|
2007-04-29 17:35:43 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifndef KWIN_HAVE_COMPOSITING
|
2007-11-21 15:46:58 +00:00
|
|
|
kDebug( 1212 ) << "Compositing was not available at compile time";
|
|
|
|
#else
|
2007-11-13 23:51:46 +00:00
|
|
|
kDebug( 1212 ) << "No compositing";
|
2007-11-21 15:46:58 +00:00
|
|
|
#endif
|
2007-11-13 23:51:46 +00:00
|
|
|
delete cm_selection;
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-06-05 12:50:18 +00:00
|
|
|
if( scene == NULL || scene->initFailed())
|
2007-05-30 14:22:09 +00:00
|
|
|
{
|
2008-01-29 14:23:26 +00:00
|
|
|
kError( 1212 ) << "Failed to initialize compositing, compositing disabled";
|
|
|
|
kError( 1212 ) << "Consult http://techbase.kde.org/Projects/KWin/4.0-release-notes#Setting_up";
|
2007-05-30 14:22:09 +00:00
|
|
|
delete scene;
|
|
|
|
scene = NULL;
|
|
|
|
delete cm_selection;
|
|
|
|
return;
|
|
|
|
}
|
2007-04-29 17:35:43 +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() )
|
|
|
|
{
|
2009-02-09 14:31:42 +00:00
|
|
|
XRRScreenConfiguration *config = XRRGetScreenInfo( display(), rootWindow() );
|
|
|
|
rate = xrrRefreshRate = XRRConfigCurrentRate( config );
|
2007-04-29 17:35:43 +00:00
|
|
|
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;
|
2008-09-09 23:14:52 +00:00
|
|
|
// however, additional throttling prevents very high rates from taking place anyway
|
2007-04-29 17:35:43 +00:00
|
|
|
else if( rate > 1000 )
|
|
|
|
rate = 1000;
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "Refresh rate " << rate << "Hz";
|
2007-04-29 17:35:43 +00:00
|
|
|
compositeRate = 1000 / rate;
|
|
|
|
lastCompositePaint.start();
|
2008-08-30 15:28:47 +00:00
|
|
|
// fake a previous paint, so that the next starts right now
|
|
|
|
nextPaintReference = QTime::currentTime().addMSecs( -compositeRate );
|
|
|
|
compositeTimer.setSingleShot( true );
|
|
|
|
checkCompositeTimer();
|
2008-09-17 13:42:12 +00:00
|
|
|
composite_paint_times.clear();
|
2007-04-29 17:35:43 +00:00
|
|
|
XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
|
|
|
|
new EffectsHandlerImpl( scene->compositingType() ); // sets also the 'effects' pointer
|
|
|
|
addRepaintFull();
|
|
|
|
foreach( Client* c, clients )
|
|
|
|
c->setupCompositing();
|
|
|
|
foreach( Client* c, desktops )
|
|
|
|
c->setupCompositing();
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
c->setupCompositing();
|
|
|
|
foreach( Client* c, clients )
|
|
|
|
scene->windowAdded( c );
|
|
|
|
foreach( Client* c, desktops )
|
|
|
|
scene->windowAdded( c );
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
scene->windowAdded( c );
|
2008-08-07 11:51:20 +00:00
|
|
|
discardPopup(); // force re-creation of the Alt+F3 popup (opacity option)
|
2007-06-06 15:24:17 +00:00
|
|
|
#else
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "Compositing was not available at compile time";
|
2007-04-29 17:35:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::finishCompositing()
|
|
|
|
{
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
if( scene == NULL )
|
|
|
|
return;
|
|
|
|
delete cm_selection;
|
|
|
|
foreach( Client* c, clients )
|
|
|
|
scene->windowClosed( c, NULL );
|
|
|
|
foreach( Client* c, desktops )
|
|
|
|
scene->windowClosed( c, NULL );
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
scene->windowClosed( c, NULL );
|
|
|
|
foreach( Deleted* c, deleted )
|
|
|
|
scene->windowDeleted( c );
|
|
|
|
foreach( Client* c, clients )
|
|
|
|
c->finishCompositing();
|
|
|
|
foreach( Client* c, desktops )
|
|
|
|
c->finishCompositing();
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
c->finishCompositing();
|
|
|
|
foreach( Deleted* c, deleted )
|
|
|
|
c->finishCompositing();
|
|
|
|
XCompositeUnredirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
|
|
|
|
delete effects;
|
|
|
|
effects = NULL;
|
|
|
|
delete scene;
|
|
|
|
scene = NULL;
|
2008-08-30 15:28:47 +00:00
|
|
|
compositeTimer.stop();
|
2009-02-04 07:09:47 +00:00
|
|
|
mousePollingTimer.stop();
|
2007-04-29 17:35:43 +00:00
|
|
|
repaints_region = QRegion();
|
2008-11-11 23:09:11 +00:00
|
|
|
for( ClientList::ConstIterator it = clients.constBegin();
|
|
|
|
it != clients.constEnd();
|
2007-04-29 17:35:43 +00:00
|
|
|
++it )
|
|
|
|
{ // forward all opacity values to the frame in case there'll be other CM running
|
|
|
|
if( (*it)->opacity() != 1.0 )
|
|
|
|
{
|
2008-11-17 08:03:39 +00:00
|
|
|
NETWinInfo2 i( display(), (*it)->frameId(), rootWindow(), 0 );
|
2007-04-29 17:35:43 +00:00
|
|
|
i.setOpacity( static_cast< unsigned long >((*it)->opacity() * 0xffffffff ));
|
|
|
|
}
|
|
|
|
}
|
2008-08-07 11:51:20 +00:00
|
|
|
discardPopup(); // force re-creation of the Alt+F3 popup (opacity option)
|
2008-07-28 11:49:43 +00:00
|
|
|
// discard all Deleted windows (#152914)
|
|
|
|
while( !deleted.isEmpty())
|
|
|
|
deleted.first()->discard( Allowed );
|
2007-04-29 17:35:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::lostCMSelection()
|
|
|
|
{
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "Lost compositing manager selection";
|
2007-04-29 17:35:43 +00:00
|
|
|
finishCompositing();
|
|
|
|
}
|
|
|
|
|
2008-05-19 21:48:47 +00:00
|
|
|
// for the shortcut
|
|
|
|
void Workspace::slotToggleCompositing()
|
|
|
|
{
|
2008-09-17 13:42:12 +00:00
|
|
|
suspendCompositing( !compositingSuspended );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::suspendCompositing()
|
|
|
|
{
|
|
|
|
suspendCompositing( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::suspendCompositing( bool suspend )
|
|
|
|
{
|
|
|
|
compositingSuspended = suspend;
|
2008-05-19 21:48:47 +00:00
|
|
|
finishCompositing();
|
|
|
|
setupCompositing(); // will do nothing if suspended
|
|
|
|
}
|
|
|
|
|
2009-02-11 14:29:32 +00:00
|
|
|
void Workspace::resetCompositing()
|
|
|
|
{
|
|
|
|
if( compositing())
|
|
|
|
{
|
|
|
|
finishCompositing();
|
|
|
|
QTimer::singleShot( 0, this, SLOT( setupCompositing()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Workspace::addRepaint( int x, int y, int w, int h )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
repaints_region += QRegion( x, y, w, h );
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addRepaint( const QRect& r )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
repaints_region += r;
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2008-06-19 14:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addRepaint( const QRegion& r )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
repaints_region += r;
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addRepaintFull()
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
repaints_region = QRegion( 0, 0, displayWidth(), displayHeight());
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::performCompositing()
|
|
|
|
{
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_COMPOSITING
|
2007-04-29 17:35:43 +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
|
2007-10-16 10:17:14 +00:00
|
|
|
// them - leave at least 1msec time after one repaint is finished and next one
|
2007-04-29 17:35:43 +00:00
|
|
|
// is started.
|
2007-10-16 10:17:14 +00:00
|
|
|
if( lastCompositePaint.elapsed() < 1 )
|
2008-08-30 15:28:47 +00:00
|
|
|
{
|
|
|
|
compositeTimer.start( 1 );
|
2007-10-16 10:17:14 +00:00
|
|
|
return;
|
2008-08-30 15:28:47 +00:00
|
|
|
}
|
|
|
|
if( !scene->waitSyncAvailable())
|
|
|
|
nextPaintReference = QTime::currentTime();
|
2009-01-05 13:34:41 +00:00
|
|
|
if((( repaints_region.isEmpty() && !windowRepaintsPending()) // no damage
|
2009-02-01 15:16:52 +00:00
|
|
|
|| !overlay_visible )) // nothing is visible anyway
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
scene->idle();
|
2008-08-24 13:32:57 +00:00
|
|
|
// Note: It would seem here we should undo suspended unredirect, but when scenes need
|
|
|
|
// it for some reason, e.g. transformations or translucency, the next pass that does not
|
|
|
|
// need this anymore and paints normally will also reset the suspended unredirect.
|
|
|
|
// Otherwise the window would not be painted normally anyway.
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// create a list of all windows in the stacking order
|
2008-08-24 10:35:45 +00:00
|
|
|
ToplevelList windows = xStackingOrder();
|
2008-01-13 13:00:15 +00:00
|
|
|
foreach( EffectWindow* c, static_cast< EffectsHandlerImpl* >( effects )->elevatedWindows())
|
2007-05-24 14:41:56 +00:00
|
|
|
{
|
2008-01-13 13:00:15 +00:00
|
|
|
Toplevel* t = static_cast< EffectWindowImpl* >( c )->window();
|
|
|
|
windows.removeAll( t );
|
|
|
|
windows.append( t );
|
2007-05-24 14:41:56 +00:00
|
|
|
}
|
2008-05-13 20:49:56 +00:00
|
|
|
// skip windows that are not yet ready for being painted
|
|
|
|
ToplevelList tmp = windows;
|
|
|
|
windows.clear();
|
2008-06-29 13:11:01 +00:00
|
|
|
#if 0
|
|
|
|
// There is a bug somewhere that prevents this from working properly (#160393), but additionally
|
|
|
|
// this cannot be used so carelessly - needs protections against broken clients, the window
|
2008-08-24 13:32:57 +00:00
|
|
|
// should not get focus before it's displayed, handle unredirected windows properly and so on.
|
2008-05-13 20:49:56 +00:00
|
|
|
foreach( Toplevel* c, tmp )
|
|
|
|
if( c->readyForPainting())
|
|
|
|
windows.append( c );
|
2008-06-29 13:11:01 +00:00
|
|
|
#else
|
|
|
|
foreach( Toplevel* c, tmp )
|
|
|
|
windows.append( c );
|
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
foreach( Toplevel* c, windows )
|
|
|
|
{ // This could be possibly optimized WRT obscuring, but that'd need being already
|
|
|
|
// past prePaint() phase - probably not worth it.
|
|
|
|
// TODO I think effects->transformWindowDamage() doesn't need to be called here,
|
|
|
|
// pre-paint will extend painted window areas as necessary.
|
|
|
|
repaints_region |= c->repaints().translated( c->pos());
|
|
|
|
c->resetRepaints( c->rect());
|
|
|
|
}
|
|
|
|
QRegion repaints = repaints_region;
|
|
|
|
// clear all repaints, so that post-pass can add repaints for the next repaint
|
|
|
|
repaints_region = QRegion();
|
2008-09-17 13:42:12 +00:00
|
|
|
QTime t = QTime::currentTime();
|
2007-04-29 17:35:43 +00:00
|
|
|
scene->paint( repaints, windows );
|
2008-05-11 12:03:42 +00:00
|
|
|
if( scene->waitSyncAvailable())
|
|
|
|
{
|
2008-08-30 15:28:47 +00:00
|
|
|
// If vsync is used, schedule the next repaint slightly in advance of the next sync,
|
|
|
|
// so that there is still time for the drawing to take place. We have just synced, and
|
|
|
|
// nextPaintReference is time from which multiples of compositeRate should be added,
|
|
|
|
// so set it 10ms back (meaning next paint will be in 'compositeRate - 10').
|
|
|
|
// However, make sure the reserve is smaller than the composite rate.
|
|
|
|
int reserve = compositeRate <= 10 ? compositeRate - 1 : 10;
|
|
|
|
nextPaintReference = QTime::currentTime().addMSecs( -reserve );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2008-08-30 15:28:47 +00:00
|
|
|
// Trigger at least one more pass even if there would be nothing to paint, so that scene->idle()
|
|
|
|
// is called the next time. If there would be nothing pending, it will not restart the timer and
|
|
|
|
// checkCompositeTime() would restart it again somewhen later, called from functions that
|
|
|
|
// would again add something pending.
|
|
|
|
checkCompositeTimer();
|
2008-09-17 13:42:12 +00:00
|
|
|
checkCompositePaintTime( t.elapsed());
|
2007-04-29 17:35:43 +00:00
|
|
|
lastCompositePaint.start();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-01 15:16:52 +00:00
|
|
|
void Workspace::performMousePoll()
|
|
|
|
{
|
|
|
|
checkCursorPos();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
bool Workspace::windowRepaintsPending() const
|
|
|
|
{
|
|
|
|
foreach( Toplevel* c, clients )
|
|
|
|
if( !c->repaints().isEmpty())
|
|
|
|
return true;
|
|
|
|
foreach( Toplevel* c, desktops )
|
|
|
|
if( !c->repaints().isEmpty())
|
|
|
|
return true;
|
|
|
|
foreach( Toplevel* c, unmanaged )
|
|
|
|
if( !c->repaints().isEmpty())
|
|
|
|
return true;
|
|
|
|
foreach( Toplevel* c, deleted )
|
|
|
|
if( !c->repaints().isEmpty())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-08-30 15:28:47 +00:00
|
|
|
void Workspace::setCompositeTimer()
|
|
|
|
{
|
|
|
|
if( !compositing()) // should not really happen, but there may be e.g. some damage events still pending
|
|
|
|
return;
|
2008-09-09 23:14:52 +00:00
|
|
|
// The last paint set nextPaintReference as a reference time to which multiples of compositeRate
|
2008-09-10 04:35:28 +00:00
|
|
|
// should be added for the next paint. qBound() for protection; system time can change without notice.
|
|
|
|
compositeTimer.start( qBound( 0, nextPaintReference.msecsTo( QTime::currentTime() ), 250 ) % compositeRate );
|
2008-08-30 15:28:47 +00:00
|
|
|
}
|
|
|
|
|
2009-02-01 15:16:52 +00:00
|
|
|
void Workspace::startMousePolling()
|
|
|
|
{
|
|
|
|
mousePollingTimer.start( 20 ); // 50Hz. TODO: How often do we really need to poll?
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::stopMousePolling()
|
|
|
|
{
|
|
|
|
mousePollingTimer.stop();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
bool Workspace::createOverlay()
|
|
|
|
{
|
|
|
|
assert( overlay == None );
|
|
|
|
if( !Extensions::compositeOverlayAvailable())
|
|
|
|
return false;
|
2007-07-04 09:52:03 +00:00
|
|
|
if( !Extensions::shapeInputAvailable()) // needed in setupOverlay()
|
|
|
|
return false;
|
2007-04-29 17:35:43 +00:00
|
|
|
#ifdef HAVE_XCOMPOSITE_OVERLAY
|
|
|
|
overlay = XCompositeGetOverlayWindow( display(), rootWindow());
|
|
|
|
if( overlay == None )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-09-17 13:42:12 +00:00
|
|
|
void Workspace::checkCompositePaintTime( int msec )
|
|
|
|
{
|
|
|
|
if( options->disableCompositingChecks )
|
|
|
|
return;
|
2008-10-01 14:29:56 +00:00
|
|
|
composite_paint_times.prepend( msec );
|
|
|
|
bool tooslow = false;
|
2008-09-17 13:42:12 +00:00
|
|
|
// If last 3 paints were way too slow, disable and warn.
|
|
|
|
// 1 second seems reasonable, it's not that difficult to get relatively high times
|
|
|
|
// with high system load.
|
2008-10-01 14:29:56 +00:00
|
|
|
const int MAX_LONG_PAINT = 1000;
|
|
|
|
if( composite_paint_times.count() >= 3 && composite_paint_times[ 0 ] > MAX_LONG_PAINT
|
|
|
|
&& composite_paint_times[ 1 ] > MAX_LONG_PAINT && composite_paint_times[ 2 ] > MAX_LONG_PAINT )
|
2008-09-17 13:42:12 +00:00
|
|
|
{
|
|
|
|
kDebug( 1212 ) << "Too long paint times, suspending";
|
2008-10-01 14:29:56 +00:00
|
|
|
tooslow = true;
|
|
|
|
}
|
|
|
|
// If last 15 seconds all paints (all of them) were quite slow, disable and warn too. Quite slow being 0,1s
|
|
|
|
// should be reasonable, that's 10fps and having constant 10fps is bad.
|
|
|
|
// This may possibly trigger also when activating an expensive effect, so this may need tweaking.
|
|
|
|
const int MAX_SHORT_PAINT = 100;
|
|
|
|
const int SHORT_TIME = 15000; // 15 sec
|
|
|
|
int time = 0;
|
|
|
|
foreach( int t, composite_paint_times )
|
|
|
|
{
|
|
|
|
if( t < MAX_SHORT_PAINT )
|
|
|
|
break;
|
|
|
|
time += t;
|
|
|
|
if( time > SHORT_TIME ) // all paints in the given time were long
|
|
|
|
{
|
|
|
|
kDebug( 1212 ) << "Long paint times for long time, suspending";
|
|
|
|
tooslow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( composite_paint_times.count() > 1000 )
|
|
|
|
composite_paint_times.removeLast();
|
|
|
|
if( tooslow )
|
|
|
|
{
|
2008-09-17 13:42:12 +00:00
|
|
|
QTimer::singleShot( 0, this, SLOT( suspendCompositing()));
|
2008-10-31 23:54:52 +00:00
|
|
|
QString shortcut, message;
|
2008-09-17 13:42:12 +00:00
|
|
|
if( KAction* action = qobject_cast<KAction*>( keys->action("Suspend Compositing")))
|
2008-10-31 23:49:17 +00:00
|
|
|
shortcut = action->globalShortcut().primary().toString(QKeySequence::NativeText);
|
2008-10-31 23:54:52 +00:00
|
|
|
if (shortcut.isEmpty())
|
|
|
|
message = i18n( "Compositing was too slow and has been suspended.\n"
|
|
|
|
"You can disable functionality checks in advanced compositing settings." );
|
|
|
|
else
|
|
|
|
message = i18n( "Compositing was too slow and has been suspended.\n"
|
|
|
|
"If this was only a temporary problem, you can resume using the '%1' shortcut.\n"
|
|
|
|
"You can also disable functionality checks in advanced compositing settings.", shortcut );
|
2008-09-17 13:42:12 +00:00
|
|
|
Notify::raise( Notify::CompositingSlow, message );
|
|
|
|
compositeTimer.start( 1000 ); // so that it doesn't trigger sooner than suspendCompositing()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Workspace::setupOverlay( Window w )
|
|
|
|
{
|
|
|
|
assert( overlay != None );
|
2007-07-04 09:52:03 +00:00
|
|
|
assert( Extensions::shapeInputAvailable());
|
2008-07-24 13:00:06 +00:00
|
|
|
XSetWindowBackgroundPixmap( display(), overlay, None );
|
2008-09-23 15:22:25 +00:00
|
|
|
overlay_shape = QRegion();
|
2008-09-11 16:37:26 +00:00
|
|
|
setOverlayShape( QRect( 0, 0, displayWidth(), displayHeight()));
|
2007-04-29 17:35:43 +00:00
|
|
|
if( w != None )
|
2008-07-24 13:00:06 +00:00
|
|
|
{
|
|
|
|
XSetWindowBackgroundPixmap( display(), w, None );
|
2007-04-29 17:35:43 +00:00
|
|
|
XShapeCombineRectangles( display(), w, ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted );
|
2008-07-24 13:00:06 +00:00
|
|
|
}
|
2007-10-18 17:58:08 +00:00
|
|
|
XSelectInput( display(), overlay, VisibilityChangeMask );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 09:48:34 +00:00
|
|
|
void Workspace::showOverlay()
|
|
|
|
{
|
|
|
|
assert( overlay != None );
|
|
|
|
if( overlay_shown )
|
|
|
|
return;
|
|
|
|
XMapSubwindows( display(), overlay );
|
|
|
|
XMapWindow( display(), overlay );
|
|
|
|
overlay_shown = true;
|
|
|
|
}
|
|
|
|
|
2008-09-11 16:37:26 +00:00
|
|
|
void Workspace::hideOverlay()
|
|
|
|
{
|
|
|
|
assert( overlay != None );
|
|
|
|
XUnmapWindow( display(), overlay );
|
|
|
|
overlay_shown = false;
|
|
|
|
setOverlayShape( QRect( 0, 0, displayWidth(), displayHeight()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::setOverlayShape( const QRegion& reg )
|
|
|
|
{
|
2008-09-23 15:22:25 +00:00
|
|
|
// Avoid setting the same shape again, it causes flicker (apparently it is not a no-op
|
|
|
|
// and triggers something).
|
|
|
|
if( reg == overlay_shape )
|
|
|
|
return;
|
2008-09-11 16:37:26 +00:00
|
|
|
QVector< QRect > rects = reg.rects();
|
|
|
|
XRectangle* xrects = new XRectangle[ rects.count() ];
|
|
|
|
for( int i = 0;
|
|
|
|
i < rects.count();
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
xrects[ i ].x = rects[ i ].x();
|
|
|
|
xrects[ i ].y = rects[ i ].y();
|
|
|
|
xrects[ i ].width = rects[ i ].width();
|
|
|
|
xrects[ i ].height = rects[ i ].height();
|
|
|
|
}
|
|
|
|
XShapeCombineRectangles( display(), overlay, ShapeBounding, 0, 0,
|
|
|
|
xrects, rects.count(), ShapeSet, Unsorted );
|
|
|
|
delete[] xrects;
|
|
|
|
XShapeCombineRectangles( display(), overlay, ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted );
|
|
|
|
overlay_shape = reg;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Workspace::destroyOverlay()
|
|
|
|
{
|
|
|
|
if( overlay == None )
|
|
|
|
return;
|
2008-08-24 13:32:57 +00:00
|
|
|
// reset the overlay shape
|
|
|
|
XRectangle rec = { 0, 0, displayWidth(), displayHeight() };
|
|
|
|
XShapeCombineRectangles( display(), overlay, ShapeBounding, 0, 0, &rec, 1, ShapeSet, Unsorted );
|
|
|
|
XShapeCombineRectangles( display(), overlay, ShapeInput, 0, 0, &rec, 1, ShapeSet, Unsorted );
|
2007-04-29 17:35:43 +00:00
|
|
|
#ifdef HAVE_XCOMPOSITE_OVERLAY
|
|
|
|
XCompositeReleaseOverlayWindow( display(), overlay );
|
|
|
|
#endif
|
|
|
|
overlay = None;
|
2008-05-11 09:48:34 +00:00
|
|
|
overlay_shown = false;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-08-15 11:09:07 +00:00
|
|
|
bool Workspace::compositingActive()
|
|
|
|
{
|
|
|
|
return compositing();
|
|
|
|
}
|
|
|
|
|
2008-08-24 13:32:57 +00:00
|
|
|
// force is needed when the list of windows changes (e.g. a window goes away)
|
|
|
|
void Workspace::checkUnredirect( bool force )
|
|
|
|
{
|
|
|
|
if( !compositing() || overlay == None || !options->unredirectFullscreen )
|
|
|
|
return;
|
|
|
|
if( force )
|
|
|
|
forceUnredirectCheck = true;
|
|
|
|
if( !unredirectTimer.isActive())
|
|
|
|
unredirectTimer.start( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::delayedCheckUnredirect()
|
|
|
|
{
|
2008-08-25 19:49:42 +00:00
|
|
|
if( !compositing() || overlay == None || !options->unredirectFullscreen )
|
|
|
|
return;
|
2008-08-24 13:32:57 +00:00
|
|
|
ToplevelList list;
|
|
|
|
bool changed = forceUnredirectCheck;
|
|
|
|
foreach( Client* c, clients )
|
|
|
|
list.append( c );
|
|
|
|
foreach( Unmanaged* c, unmanaged )
|
|
|
|
list.append( c );
|
|
|
|
foreach( Toplevel* c, list )
|
|
|
|
{
|
|
|
|
if( c->updateUnredirectedState())
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
// no desktops, no Deleted ones
|
|
|
|
if( !changed )
|
|
|
|
return;
|
|
|
|
forceUnredirectCheck = false;
|
|
|
|
// Cut out parts from the overlay window where unredirected windows are,
|
|
|
|
// so that they are actually visible.
|
|
|
|
QRegion reg( 0, 0, displayWidth(), displayHeight());
|
|
|
|
foreach( Toplevel* c, list )
|
|
|
|
{
|
|
|
|
if( c->unredirected())
|
|
|
|
reg -= c->geometry();
|
|
|
|
}
|
2008-09-23 15:22:25 +00:00
|
|
|
setOverlayShape( reg );
|
2008-08-24 13:32:57 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// Toplevel
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
void Toplevel::setupCompositing()
|
|
|
|
{
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
if( damage_handle != None )
|
|
|
|
return;
|
|
|
|
damage_handle = XDamageCreate( display(), frameId(), XDamageReportRawRectangles );
|
|
|
|
damage_region = QRegion( 0, 0, width(), height());
|
|
|
|
effect_window = new EffectWindowImpl();
|
|
|
|
effect_window->setWindow( this );
|
2008-08-24 13:32:57 +00:00
|
|
|
unredirect = false;
|
|
|
|
workspace()->checkUnredirect( true );
|
2007-04-29 17:35:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::finishCompositing()
|
|
|
|
{
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
if( damage_handle == None )
|
|
|
|
return;
|
2008-08-24 13:32:57 +00:00
|
|
|
workspace()->checkUnredirect( true );
|
2007-04-29 17:35:43 +00:00
|
|
|
if( effect_window->window() == this ) // otherwise it's already passed to Deleted, don't free data
|
|
|
|
{
|
|
|
|
discardWindowPixmap();
|
|
|
|
delete effect_window;
|
|
|
|
}
|
|
|
|
XDamageDestroy( display(), damage_handle );
|
|
|
|
damage_handle = None;
|
|
|
|
damage_region = QRegion();
|
|
|
|
repaints_region = QRegion();
|
|
|
|
effect_window = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::discardWindowPixmap()
|
|
|
|
{
|
|
|
|
addDamageFull();
|
|
|
|
if( window_pix == None )
|
|
|
|
return;
|
|
|
|
XFreePixmap( display(), window_pix );
|
|
|
|
window_pix = None;
|
2007-07-05 19:59:55 +00:00
|
|
|
if( effectWindow() != NULL && effectWindow()->sceneWindow() != NULL )
|
|
|
|
effectWindow()->sceneWindow()->pixmapDiscarded();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Pixmap Toplevel::createWindowPixmap()
|
|
|
|
{
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
assert( compositing());
|
2008-08-24 13:32:57 +00:00
|
|
|
if( unredirected())
|
|
|
|
return None;
|
2007-04-29 17:35:43 +00:00
|
|
|
grabXServer();
|
|
|
|
KXErrorHandler err;
|
2008-08-12 11:45:06 +00:00
|
|
|
Pixmap pix = XCompositeNameWindowPixmap( display(), frameId());
|
2007-04-29 17:35:43 +00:00
|
|
|
// check that the received pixmap is valid and actually matches what we
|
|
|
|
// know about the window (i.e. size)
|
|
|
|
XWindowAttributes attrs;
|
2008-07-02 10:11:16 +00:00
|
|
|
if( !XGetWindowAttributes( display(), frameId(), &attrs )
|
|
|
|
|| err.error( false )
|
|
|
|
|| attrs.width != width() || attrs.height != height() || attrs.map_state != IsViewable )
|
2008-07-01 14:51:38 +00:00
|
|
|
{
|
2007-08-03 06:59:24 +00:00
|
|
|
kDebug( 1212 ) << "Creating window pixmap failed: " << this;
|
2008-08-12 11:45:06 +00:00
|
|
|
XFreePixmap( display(), pix );
|
|
|
|
pix = None;
|
2008-07-01 14:51:38 +00:00
|
|
|
}
|
2008-07-02 10:11:16 +00:00
|
|
|
ungrabXServer();
|
2008-08-12 11:45:06 +00:00
|
|
|
return pix;
|
2007-04-29 17:35:43 +00:00
|
|
|
#else
|
|
|
|
return None;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_XDAMAGE
|
|
|
|
void Toplevel::damageNotifyEvent( XDamageNotifyEvent* e )
|
|
|
|
{
|
2008-07-22 18:20:42 +00:00
|
|
|
QRegion damage( e->area.x, e->area.y, e->area.width, e->area.height );
|
2007-04-29 17:35:43 +00:00
|
|
|
// compress
|
2008-07-22 18:20:42 +00:00
|
|
|
int cnt = 1;
|
2007-04-29 17:35:43 +00:00
|
|
|
while( XPending( display()))
|
|
|
|
{
|
|
|
|
XEvent e2;
|
|
|
|
if( XPeekEvent( display(), &e2 ) && e2.type == Extensions::damageNotifyEvent()
|
|
|
|
&& e2.xany.window == frameId())
|
|
|
|
{
|
|
|
|
XNextEvent( display(), &e2 );
|
2008-07-22 18:20:42 +00:00
|
|
|
if( cnt > 200 )
|
|
|
|
{
|
|
|
|
// If there are way too many damage events in the queue, just discard them
|
|
|
|
// and damage the whole window. Otherwise the X server can just overload
|
|
|
|
// us with a flood of damage events. Should be probably optimized
|
|
|
|
// in the X server, as this is rather lame.
|
|
|
|
damage = rect();
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
XDamageNotifyEvent* e = reinterpret_cast< XDamageNotifyEvent* >( &e2 );
|
2008-07-22 18:20:42 +00:00
|
|
|
QRect r( e->area.x, e->area.y, e->area.width, e->area.height );
|
|
|
|
++cnt;
|
|
|
|
// If there are too many damaged rectangles, increase them
|
|
|
|
// to be multiples of 100x100 px grid, since QRegion get quite
|
|
|
|
// slow with many rectangles, and there is little to gain by using
|
|
|
|
// many small rectangles (rather the opposite, several large should
|
|
|
|
// be often faster).
|
|
|
|
if( cnt > 50 )
|
|
|
|
{
|
|
|
|
r.setLeft( r.left() / 100 * 100 );
|
|
|
|
r.setRight(( r.right() + 99 ) / 100 * 100 );
|
|
|
|
r.setTop( r.top() / 100 * 100 );
|
|
|
|
r.setBottom(( r.bottom() + 99 ) / 100 * 100 );
|
|
|
|
}
|
|
|
|
damage += r;
|
2007-04-29 17:35:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-10-11 12:38:46 +00:00
|
|
|
foreach( const QRect& r, damage.rects())
|
2008-07-22 18:20:42 +00:00
|
|
|
addDamage( r );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2007-06-25 08:51:44 +00:00
|
|
|
|
|
|
|
void Client::damageNotifyEvent( XDamageNotifyEvent* e )
|
|
|
|
{
|
|
|
|
Toplevel::damageNotifyEvent( e );
|
|
|
|
#ifdef HAVE_XSYNC
|
|
|
|
if( sync_counter == None ) // cannot detect complete redraw, consider done now
|
|
|
|
ready_for_painting = true;
|
|
|
|
#else
|
|
|
|
ready_for_painting = true; // no sync at all, consider done now
|
|
|
|
#endif
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
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;
|
|
|
|
QRect r( x, y, w, h );
|
|
|
|
// 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();
|
|
|
|
damage_region += r;
|
|
|
|
repaints_region += r;
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->windowDamaged( effectWindow(), r );
|
2008-08-30 15:28:47 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addDamageFull()
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
damage_region = rect();
|
|
|
|
repaints_region = rect();
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->windowDamaged( effectWindow(), rect());
|
2008-08-30 15:28:47 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::resetDamage( const QRect& r )
|
|
|
|
{
|
|
|
|
damage_region -= r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addRepaint( const QRect& r )
|
|
|
|
{
|
|
|
|
addRepaint( r.x(), r.y(), r.width(), r.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addRepaint( int x, int y, int w, int h )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
|
|
|
QRect r( x, y, w, h );
|
|
|
|
r &= rect();
|
|
|
|
repaints_region += r;
|
2008-08-30 15:28:47 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addRepaintFull()
|
|
|
|
{
|
|
|
|
repaints_region = rect();
|
2008-08-30 15:28:47 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::resetRepaints( const QRect& r )
|
|
|
|
{
|
|
|
|
repaints_region -= r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addWorkspaceRepaint( int x, int y, int w, int h )
|
|
|
|
{
|
|
|
|
addWorkspaceRepaint( QRect( x, y, w, h ));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addWorkspaceRepaint( const QRect& r2 )
|
|
|
|
{
|
|
|
|
if( !compositing())
|
|
|
|
return;
|
2007-10-23 13:07:15 +00:00
|
|
|
if( effectWindow() == NULL ) // TODO - this can happen during window destruction
|
|
|
|
return workspace()->addRepaint( r2 );
|
2007-04-29 17:35:43 +00:00
|
|
|
QRect r = effects->transformWindowDamage( effectWindow(), r2 );
|
|
|
|
workspace()->addRepaint( r );
|
|
|
|
}
|
|
|
|
|
2008-08-24 13:32:57 +00:00
|
|
|
bool Toplevel::updateUnredirectedState()
|
|
|
|
{
|
|
|
|
assert( compositing());
|
2009-01-05 12:52:27 +00:00
|
|
|
bool should = shouldUnredirect() && !unredirectSuspend && !shape() && !hasAlpha() && opacity() == 1.0 &&
|
|
|
|
!static_cast<EffectsHandlerImpl*>( effects )->activeFullScreenEffect();
|
2008-08-24 13:32:57 +00:00
|
|
|
if( should && !unredirect )
|
|
|
|
{
|
|
|
|
unredirect = true;
|
|
|
|
kDebug( 1212 ) << "Unredirecting:" << this;
|
2008-10-13 09:56:13 +00:00
|
|
|
#ifdef HAVE_XCOMPOSITE
|
2008-08-24 13:32:57 +00:00
|
|
|
XCompositeUnredirectWindow( display(), frameId(), CompositeRedirectManual );
|
2008-10-13 09:56:13 +00:00
|
|
|
#endif
|
2008-08-24 13:32:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( !should && unredirect )
|
|
|
|
{
|
|
|
|
unredirect = false;
|
|
|
|
kDebug( 1212 ) << "Redirecting:" << this;
|
2008-10-13 09:56:13 +00:00
|
|
|
#ifdef HAVE_XCOMPOSITE
|
2008-08-24 13:32:57 +00:00
|
|
|
XCompositeRedirectWindow( display(), frameId(), CompositeRedirectManual );
|
2008-10-13 09:56:13 +00:00
|
|
|
#endif
|
2008-08-24 13:32:57 +00:00
|
|
|
discardWindowPixmap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::suspendUnredirect( bool suspend )
|
|
|
|
{
|
2008-09-23 14:51:21 +00:00
|
|
|
if( unredirectSuspend == suspend )
|
|
|
|
return;
|
2008-08-24 13:32:57 +00:00
|
|
|
unredirectSuspend = suspend;
|
|
|
|
workspace()->checkUnredirect();
|
|
|
|
}
|
|
|
|
|
2008-08-12 11:02:58 +00:00
|
|
|
//****************************************
|
|
|
|
// Client
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
void Client::setupCompositing()
|
|
|
|
{
|
|
|
|
Toplevel::setupCompositing();
|
|
|
|
updateVisibility(); // for internalKeep()
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::finishCompositing()
|
|
|
|
{
|
|
|
|
Toplevel::finishCompositing();
|
|
|
|
updateVisibility();
|
|
|
|
}
|
|
|
|
|
2008-08-24 13:32:57 +00:00
|
|
|
bool Client::shouldUnredirect() const
|
|
|
|
{
|
|
|
|
if( isActiveFullScreen())
|
|
|
|
{
|
|
|
|
ToplevelList stacking = workspace()->xStackingOrder();
|
|
|
|
for( int pos = stacking.count() - 1;
|
|
|
|
pos >= 0;
|
|
|
|
--pos )
|
|
|
|
{
|
|
|
|
Toplevel* c = stacking.at( pos );
|
|
|
|
if( c == this ) // is not covered by any other window, ok to unredirect
|
|
|
|
return true;
|
|
|
|
if( c->geometry().intersects( geometry()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Unmanaged
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
bool Unmanaged::shouldUnredirect() const
|
|
|
|
{
|
2008-10-14 10:34:35 +00:00
|
|
|
// the pixmap is needed for the login effect, a nicer solution would be the login effect increasing
|
|
|
|
// refcount for the window pixmap (which would prevent unredirect), avoiding this hack
|
|
|
|
if( resourceClass() == "ksplashx" || resourceClass() == "ksplashsimple" )
|
|
|
|
return false;
|
2008-08-24 13:32:57 +00:00
|
|
|
// it must cover whole display or one xinerama screen, and be the topmost there
|
|
|
|
if( geometry() == workspace()->clientArea( FullArea, geometry().center(), workspace()->currentDesktop())
|
|
|
|
|| geometry() == workspace()->clientArea( ScreenArea, geometry().center(), workspace()->currentDesktop()))
|
|
|
|
{
|
|
|
|
ToplevelList stacking = workspace()->xStackingOrder();
|
|
|
|
for( int pos = stacking.count() - 1;
|
|
|
|
pos >= 0;
|
|
|
|
--pos )
|
|
|
|
{
|
|
|
|
Toplevel* c = stacking.at( pos );
|
|
|
|
if( c == this ) // is not covered by any other window, ok to unredirect
|
|
|
|
return true;
|
|
|
|
if( c->geometry().intersects( geometry()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Deleted
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
bool Deleted::shouldUnredirect() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|