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).
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
Docs:
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
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
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
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
|
2011-01-30 14:34:42 +00:00
|
|
|
|
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"
|
2011-07-06 09:58:23 +00:00
|
|
|
#include "overlaywindow.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "scene.h"
|
|
|
|
#include "scene_xrender.h"
|
|
|
|
#include "scene_opengl.h"
|
2011-03-27 10:33:07 +00:00
|
|
|
#include "shadow.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>
|
2010-12-18 16:51:43 +00:00
|
|
|
#include <QTimerEvent>
|
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
|
|
|
#include <X11/extensions/Xcomposite.h>
|
|
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2010-11-27 15:27:54 +00:00
|
|
|
extern int currentRefreshRate();
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// Workspace
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
void Workspace::setupCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (scene != NULL)
|
2008-02-08 10:31:40 +00:00
|
|
|
return;
|
2011-02-27 22:39:32 +00:00
|
|
|
if (compositingSuspended) {
|
2011-01-30 14:34:42 +00:00
|
|
|
kDebug(1212) << "Compositing is suspended";
|
2008-05-19 21:48:47 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (!CompositingPrefs::compositingPossible()) {
|
|
|
|
kError(1212) << "Compositing is not possible";
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-02-27 22:39:32 +00:00
|
|
|
|
|
|
|
if (!options->compositingInitialized)
|
|
|
|
options->reloadCompositingSettings(true);
|
2007-07-19 16:20:05 +00:00
|
|
|
|
2008-02-08 10:31:40 +00:00
|
|
|
char selection_name[ 100 ];
|
2011-01-30 14:34:42 +00:00
|
|
|
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
|
2008-02-08 10:31:40 +00:00
|
|
|
|
2011-02-27 22:39:32 +00:00
|
|
|
switch(options->compositingMode) {
|
2011-01-30 14:34:42 +00:00
|
|
|
case OpenGLCompositing: {
|
|
|
|
kDebug(1212) << "Initializing OpenGL compositing";
|
|
|
|
|
|
|
|
// Some broken drivers crash on glXQuery() so to prevent constant KWin crashes:
|
|
|
|
KSharedConfigPtr unsafeConfigPtr(KSharedConfig::openConfig("kwinrc"));
|
|
|
|
KConfigGroup unsafeConfig(unsafeConfigPtr, "Compositing");
|
|
|
|
if (unsafeConfig.readEntry("OpenGLIsUnsafe", false))
|
2011-04-03 19:59:57 +00:00
|
|
|
kWarning(1212) << "KWin has detected that your OpenGL library is unsafe to use";
|
2011-01-30 14:34:42 +00:00
|
|
|
else {
|
|
|
|
unsafeConfig.writeEntry("OpenGLIsUnsafe", true);
|
|
|
|
unsafeConfig.sync();
|
2011-07-20 20:10:03 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
|
|
|
if (!CompositingPrefs::hasGlx()) {
|
|
|
|
unsafeConfig.writeEntry("OpenGLIsUnsafe", false);
|
|
|
|
unsafeConfig.sync();
|
|
|
|
kDebug(1212) << "No glx extensions available";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
scene = new SceneOpenGL(this);
|
|
|
|
|
|
|
|
// TODO: Add 30 second delay to protect against screen freezes as well
|
|
|
|
unsafeConfig.writeEntry("OpenGLIsUnsafe", false);
|
|
|
|
unsafeConfig.sync();
|
|
|
|
|
|
|
|
if (!scene->initFailed())
|
|
|
|
break; // -->
|
|
|
|
delete scene;
|
|
|
|
scene = NULL;
|
|
|
|
}
|
2010-01-25 10:02:08 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
// Do not Fall back to XRender - it causes problems when selfcheck fails during startup, but works later on
|
|
|
|
break;
|
|
|
|
}
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
case XRenderCompositing:
|
|
|
|
kDebug(1212) << "Initializing XRender compositing";
|
|
|
|
scene = new SceneXrender(this);
|
|
|
|
break;
|
2007-04-29 17:35:43 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
default:
|
|
|
|
kDebug(1212) << "No compositing enabled";
|
|
|
|
delete cm_selection;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (scene == NULL || scene->initFailed()) {
|
|
|
|
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;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-12-18 16:51:43 +00:00
|
|
|
xrrRefreshRate = KWin::currentRefreshRate();
|
2011-01-30 14:34:42 +00:00
|
|
|
fpsInterval = (options->maxFpsInterval << 10);
|
|
|
|
if (scene->waitSyncAvailable()) { // if we do vsync, set the fps to the next multiple of the vblank rate
|
|
|
|
vBlankInterval = (1000 << 10) / xrrRefreshRate;
|
2010-12-31 13:14:11 +00:00
|
|
|
fpsInterval -= (fpsInterval % vBlankInterval);
|
|
|
|
fpsInterval = qMax(fpsInterval, vBlankInterval);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
|
|
|
vBlankInterval = 1 << 10; // no sync - DO NOT set "0", would cause div-by-zero segfaults.
|
2010-12-31 13:14:11 +00:00
|
|
|
vBlankPadding = 3; // vblank rounding errors... :-(
|
2011-10-29 15:36:26 +00:00
|
|
|
nextPaintReference.start();
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2011-01-30 14:34:42 +00:00
|
|
|
XCompositeRedirectSubwindows(display(), rootWindow(), CompositeRedirectManual);
|
|
|
|
new EffectsHandlerImpl(scene->compositingType()); // sets also the 'effects' pointer
|
2007-04-29 17:35:43 +00:00
|
|
|
addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Client * c, clients)
|
|
|
|
c->setupCompositing();
|
|
|
|
foreach (Client * c, desktops)
|
|
|
|
c->setupCompositing();
|
|
|
|
foreach (Unmanaged * c, unmanaged)
|
|
|
|
c->setupCompositing();
|
2008-08-07 11:51:20 +00:00
|
|
|
discardPopup(); // force re-creation of the Alt+F3 popup (opacity option)
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Workspace::finishCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (scene == NULL)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-05-15 11:22:28 +00:00
|
|
|
m_finishingCompositing = true;
|
2007-04-29 17:35:43 +00:00
|
|
|
delete cm_selection;
|
2011-01-30 14:34:42 +00:00
|
|
|
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);
|
2007-04-29 17:35:43 +00:00
|
|
|
delete effects;
|
|
|
|
effects = NULL;
|
|
|
|
delete scene;
|
|
|
|
scene = NULL;
|
2011-02-01 15:35:51 +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();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (ClientList::ConstIterator it = clients.constBegin();
|
|
|
|
it != clients.constEnd();
|
|
|
|
++it) {
|
|
|
|
// forward all opacity values to the frame in case there'll be other CM running
|
|
|
|
if ((*it)->opacity() != 1.0) {
|
|
|
|
NETWinInfo2 i(display(), (*it)->frameId(), rootWindow(), 0);
|
|
|
|
i.setOpacity(static_cast< unsigned long >((*it)->opacity() * 0xffffffff));
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
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)
|
2011-01-30 14:34:42 +00:00
|
|
|
while (!deleted.isEmpty())
|
|
|
|
deleted.first()->discard(Allowed);
|
2011-05-15 11:22:28 +00:00
|
|
|
m_finishingCompositing = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-25 10:02:08 +00:00
|
|
|
// OpenGL self-check failed, fallback to XRender
|
|
|
|
void Workspace::fallbackToXRenderCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-01-25 10:02:08 +00:00
|
|
|
finishCompositing();
|
2011-12-16 16:36:27 +00:00
|
|
|
KConfigGroup config(KSharedConfig::openConfig("kwinrc"), "Compositing");
|
|
|
|
config.writeEntry("Backend", "XRender");
|
|
|
|
config.writeEntry("GraphicsSystem", "native");
|
|
|
|
config.sync();
|
|
|
|
if (Extensions::nonNativePixmaps()) { // must restart to change the graphicssystem
|
|
|
|
restartKWin("automatic graphicssystem change for XRender backend");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
options->compositingMode = XRenderCompositing;
|
|
|
|
setupCompositing();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-25 10:02:08 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Workspace::lostCMSelection()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
kDebug(1212) << "Lost compositing manager selection";
|
2007-04-29 17:35:43 +00:00
|
|
|
finishCompositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-05-19 21:48:47 +00:00
|
|
|
// for the shortcut
|
|
|
|
void Workspace::slotToggleCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
suspendCompositing(!compositingSuspended);
|
|
|
|
}
|
2009-04-02 19:14:48 +00:00
|
|
|
|
|
|
|
// for the dbus call
|
|
|
|
void Workspace::toggleCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-04-02 19:14:48 +00:00
|
|
|
slotToggleCompositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (compositingSuspended) {
|
2009-04-02 19:14:48 +00:00
|
|
|
// when disabled show a shortcut how the user can get back compositing
|
|
|
|
QString shortcut, message;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (KAction* action = qobject_cast<KAction*>(keys->action("Suspend Compositing")))
|
2009-04-02 19:14:48 +00:00
|
|
|
shortcut = action->globalShortcut().primary().toString(QKeySequence::NativeText);
|
2011-02-27 22:39:32 +00:00
|
|
|
if (!shortcut.isEmpty()) {
|
2009-04-02 19:14:48 +00:00
|
|
|
// display notification only if there is the shortcut
|
2011-01-30 14:34:42 +00:00
|
|
|
message = i18n("Desktop effects have been suspended by another application.<br/>"
|
|
|
|
"You can resume using the '%1' shortcut.", shortcut);
|
|
|
|
Notify::raise(Notify::CompositingSuspendedDbus, message);
|
2009-04-02 19:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-04-02 19:14:48 +00:00
|
|
|
|
2011-12-29 22:33:45 +00:00
|
|
|
QStringList Workspace::activeEffects() const
|
|
|
|
{
|
|
|
|
if (effects)
|
|
|
|
return static_cast< EffectsHandlerImpl* >(effects)->activeEffects();
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2011-03-20 14:42:05 +00:00
|
|
|
void Workspace::updateCompositeBlocking(Client *c)
|
|
|
|
{
|
|
|
|
if (c) { // if c == 0 we just check if we can resume
|
|
|
|
if (c->isBlockingCompositing()) {
|
2011-11-23 19:22:57 +00:00
|
|
|
if (!compositingBlocked) // do NOT attempt to call suspendCompositing(true); from within the eventchain!
|
|
|
|
QMetaObject::invokeMethod(this, "slotToggleCompositing", Qt::QueuedConnection);
|
2011-03-20 14:42:05 +00:00
|
|
|
compositingBlocked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (compositingBlocked) { // lost a client and we're blocked - can we resume?
|
|
|
|
// NOTICE do NOT check for "compositingSuspended" or "!compositing()"
|
|
|
|
// only "resume" if it was really disabled for a block
|
|
|
|
bool resume = true;
|
|
|
|
for (ClientList::ConstIterator it = clients.constBegin(); it != clients.constEnd(); ++it) {
|
|
|
|
if ((*it)->isBlockingCompositing()) {
|
|
|
|
resume = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resume) { // do NOT attempt to call suspendCompositing(false); from within the eventchain!
|
|
|
|
compositingBlocked = false;
|
|
|
|
if (compositingSuspended)
|
|
|
|
QMetaObject::invokeMethod(this, "slotToggleCompositing", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-17 13:42:12 +00:00
|
|
|
void Workspace::suspendCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
suspendCompositing(true);
|
|
|
|
}
|
2008-09-17 13:42:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::suspendCompositing(bool suspend)
|
|
|
|
{
|
2008-09-17 13:42:12 +00:00
|
|
|
compositingSuspended = suspend;
|
2008-05-19 21:48:47 +00:00
|
|
|
finishCompositing();
|
|
|
|
setupCompositing(); // will do nothing if suspended
|
2009-09-10 05:05:44 +00:00
|
|
|
// notify decorations that composition state has changed
|
2011-04-28 13:56:50 +00:00
|
|
|
if (hasDecorationPlugin()) {
|
|
|
|
KDecorationFactory* factory = mgr->factory();
|
|
|
|
factory->reset(SettingCompositing);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
emit compositingToggled(!compositingSuspended);
|
|
|
|
}
|
2008-05-19 21:48:47 +00:00
|
|
|
|
2009-02-11 14:29:32 +00:00
|
|
|
void Workspace::resetCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (compositing()) {
|
2009-02-11 14:29:32 +00:00
|
|
|
finishCompositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
QTimer::singleShot(0, this, SLOT(setupCompositing()));
|
2009-02-11 14:29:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-11 14:29:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::addRepaint(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
repaints_region += QRegion(x, y, w, h);
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::addRepaint(const QRect& r)
|
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
repaints_region += r;
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addRepaint(const QRegion& r)
|
|
|
|
{
|
|
|
|
if (!compositing())
|
2008-06-19 14:16:21 +00:00
|
|
|
return;
|
|
|
|
repaints_region += r;
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Workspace::addRepaintFull()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
repaints_region = QRegion(0, 0, displayWidth(), displayHeight());
|
2008-08-30 15:28:47 +00:00
|
|
|
checkCompositeTimer();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::timerEvent(QTimerEvent *te)
|
2010-12-18 16:51:43 +00:00
|
|
|
{
|
2011-02-01 15:35:51 +00:00
|
|
|
if (te->timerId() == compositeTimer.timerId()) {
|
|
|
|
compositeTimer.stop();
|
2010-12-18 16:51:43 +00:00
|
|
|
performCompositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
|
|
|
QObject::timerEvent(te);
|
2010-12-18 16:51:43 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Workspace::performCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (((repaints_region.isEmpty() && !windowRepaintsPending()) // no damage
|
2011-07-06 09:58:23 +00:00
|
|
|
|| !scene->overlayWindow()->isVisible())) { // nothing is visible anyway
|
2010-12-31 13:14:11 +00:00
|
|
|
vBlankPadding += 3;
|
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;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
// create a list of all windows in the stacking order
|
2008-08-24 10:35:45 +00:00
|
|
|
ToplevelList windows = xStackingOrder();
|
2011-08-13 14:39:58 +00:00
|
|
|
foreach (EffectWindow *c, static_cast< EffectsHandlerImpl* >(effects)->elevatedWindows()) {
|
2011-01-30 14:34:42 +00:00
|
|
|
Toplevel* t = static_cast< EffectWindowImpl* >(c)->window();
|
|
|
|
windows.removeAll(t);
|
|
|
|
windows.append(t);
|
|
|
|
}
|
2011-08-13 14:39:58 +00:00
|
|
|
|
2008-05-13 20:49:56 +00:00
|
|
|
// skip windows that are not yet ready for being painted
|
2011-08-13 14:39:58 +00:00
|
|
|
// TODO ?
|
2008-06-29 13:11:01 +00:00
|
|
|
// 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.
|
2011-08-13 14:39:58 +00:00
|
|
|
foreach (Toplevel *t, windows)
|
|
|
|
if (!t->readyForPainting())
|
|
|
|
windows.removeAll(t);
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
QRegion repaints = repaints_region;
|
|
|
|
// clear all repaints, so that post-pass can add repaints for the next repaint
|
|
|
|
repaints_region = QRegion();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (scene->waitSyncAvailable()) {
|
|
|
|
// vsync: paint the scene, than rebase the timer and use the duration for next timeout estimation
|
|
|
|
scene->paint(repaints, windows);
|
2011-10-29 15:36:26 +00:00
|
|
|
nextPaintReference.start();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
// no vsyc -> inversion: reset the timer, then paint the scene, this way we can provide a constant framerate
|
2011-10-29 15:36:26 +00:00
|
|
|
nextPaintReference.start();
|
2011-01-30 14:34:42 +00:00
|
|
|
scene->paint(repaints, windows);
|
2010-12-31 13:14:11 +00:00
|
|
|
}
|
|
|
|
// reset the roundin error corrective... :-(
|
|
|
|
vBlankPadding = 3;
|
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();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-02-01 15:16:52 +00:00
|
|
|
void Workspace::performMousePoll()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-02-01 15:16:52 +00:00
|
|
|
checkCursorPos();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-01 15:16:52 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
bool Workspace::windowRepaintsPending() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
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;
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-08-30 15:28:47 +00:00
|
|
|
void Workspace::setCompositeTimer()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!compositing()) // should not really happen, but there may be e.g. some damage events still pending
|
2008-08-30 15:28:47 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2010-12-31 13:14:11 +00:00
|
|
|
// interval - "time since last paint completion" - "time we need to paint"
|
2011-08-29 04:47:07 +00:00
|
|
|
uint passed = nextPaintReference.elapsed() << 10;
|
2010-12-31 13:14:11 +00:00
|
|
|
uint delay = fpsInterval;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (scene->waitSyncAvailable()) {
|
|
|
|
if (passed > fpsInterval) {
|
2010-12-31 13:14:11 +00:00
|
|
|
delay = vBlankInterval;
|
|
|
|
passed %= vBlankInterval;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
delay -= ((passed + ((scene->estimatedRenderTime() + vBlankPadding) << 10)) % vBlankInterval);
|
|
|
|
} else
|
|
|
|
delay = qBound(0, int(delay - passed), 250 << 10);
|
2011-02-01 15:35:51 +00:00
|
|
|
|
|
|
|
compositeTimer.start(delay >> 10, this);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-30 15:28:47 +00:00
|
|
|
|
2009-02-01 15:16:52 +00:00
|
|
|
void Workspace::startMousePolling()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
mousePollingTimer.start(20); // 50Hz. TODO: How often do we really need to poll?
|
|
|
|
}
|
2009-02-01 15:16:52 +00:00
|
|
|
|
|
|
|
void Workspace::stopMousePolling()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-02-01 15:16:52 +00:00
|
|
|
mousePollingTimer.stop();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-01 15:16:52 +00:00
|
|
|
|
2008-08-15 11:09:07 +00:00
|
|
|
bool Workspace::compositingActive()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-05-15 11:22:28 +00:00
|
|
|
return !m_finishingCompositing && compositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-15 11:09:07 +00:00
|
|
|
|
2008-08-24 13:32:57 +00:00
|
|
|
// force is needed when the list of windows changes (e.g. a window goes away)
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::checkUnredirect(bool force)
|
|
|
|
{
|
2011-07-06 09:58:23 +00:00
|
|
|
if (!compositing() || scene->overlayWindow()->window() == None || !options->unredirectFullscreen)
|
2008-08-24 13:32:57 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (force)
|
2008-08-24 13:32:57 +00:00
|
|
|
forceUnredirectCheck = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!unredirectTimer.isActive())
|
|
|
|
unredirectTimer.start(0);
|
|
|
|
}
|
2008-08-24 13:32:57 +00:00
|
|
|
|
|
|
|
void Workspace::delayedCheckUnredirect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-06 09:58:23 +00:00
|
|
|
if (!compositing() || scene->overlayWindow()->window() == None || !options->unredirectFullscreen)
|
2008-08-25 19:49:42 +00:00
|
|
|
return;
|
2008-08-24 13:32:57 +00:00
|
|
|
ToplevelList list;
|
|
|
|
bool changed = forceUnredirectCheck;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Client * c, clients)
|
|
|
|
list.append(c);
|
|
|
|
foreach (Unmanaged * c, unmanaged)
|
|
|
|
list.append(c);
|
|
|
|
foreach (Toplevel * c, list) {
|
|
|
|
if (c->updateUnredirectedState())
|
2008-08-24 13:32:57 +00:00
|
|
|
changed = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-24 13:32:57 +00:00
|
|
|
// no desktops, no Deleted ones
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!changed)
|
2008-08-24 13:32:57 +00:00
|
|
|
return;
|
|
|
|
forceUnredirectCheck = false;
|
|
|
|
// Cut out parts from the overlay window where unredirected windows are,
|
|
|
|
// so that they are actually visible.
|
2011-01-30 14:34:42 +00:00
|
|
|
QRegion reg(0, 0, displayWidth(), displayHeight());
|
|
|
|
foreach (Toplevel * c, list) {
|
|
|
|
if (c->unredirected())
|
2008-08-24 13:32:57 +00:00
|
|
|
reg -= c->geometry();
|
|
|
|
}
|
2011-07-06 09:58:23 +00:00
|
|
|
scene->overlayWindow()->setShape(reg);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-24 13:32:57 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// Toplevel
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
void Toplevel::setupCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-08-13 08:36:35 +00:00
|
|
|
damageRatio = 0.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (damage_handle != None)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
damage_handle = XDamageCreate(display(), frameId(), XDamageReportRawRectangles);
|
|
|
|
damage_region = QRegion(0, 0, width(), height());
|
2011-12-29 09:31:37 +00:00
|
|
|
effect_window = new EffectWindowImpl(this);
|
2008-08-24 13:32:57 +00:00
|
|
|
unredirect = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
workspace()->checkUnredirect(true);
|
2011-07-22 09:03:22 +00:00
|
|
|
scene->windowAdded(this);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Toplevel::finishCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-08-13 08:36:35 +00:00
|
|
|
damageRatio = 0.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (damage_handle == None)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
workspace()->checkUnredirect(true);
|
|
|
|
if (effect_window->window() == this) { // otherwise it's already passed to Deleted, don't free data
|
2007-04-29 17:35:43 +00:00
|
|
|
discardWindowPixmap();
|
|
|
|
delete effect_window;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
XDamageDestroy(display(), damage_handle);
|
2007-04-29 17:35:43 +00:00
|
|
|
damage_handle = None;
|
|
|
|
damage_region = QRegion();
|
|
|
|
repaints_region = QRegion();
|
|
|
|
effect_window = NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Toplevel::discardWindowPixmap()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-08-13 08:36:35 +00:00
|
|
|
damageRatio = 0.0;
|
2007-04-29 17:35:43 +00:00
|
|
|
addDamageFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (window_pix == None)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
XFreePixmap(display(), window_pix);
|
2007-04-29 17:35:43 +00:00
|
|
|
window_pix = None;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effectWindow() != NULL && effectWindow()->sceneWindow() != NULL)
|
2007-07-05 19:59:55 +00:00
|
|
|
effectWindow()->sceneWindow()->pixmapDiscarded();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Pixmap Toplevel::createWindowPixmap()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
assert(compositing());
|
|
|
|
if (unredirected())
|
2008-08-24 13:32:57 +00:00
|
|
|
return None;
|
2011-11-08 19:53:17 +00:00
|
|
|
damageRatio = 0.0;
|
2007-04-29 17:35:43 +00:00
|
|
|
grabXServer();
|
|
|
|
KXErrorHandler err;
|
2011-01-30 14:34:42 +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;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!XGetWindowAttributes(display(), frameId(), &attrs)
|
|
|
|
|| err.error(false)
|
|
|
|
|| attrs.width != width() || attrs.height != height() || attrs.map_state != IsViewable) {
|
|
|
|
kDebug(1212) << "Creating window pixmap failed: " << this;
|
|
|
|
XFreePixmap(display(), pix);
|
2008-08-12 11:45:06 +00:00
|
|
|
pix = None;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-07-02 10:11:16 +00:00
|
|
|
ungrabXServer();
|
2008-08-12 11:45:06 +00:00
|
|
|
return pix;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-10-05 09:47:13 +00:00
|
|
|
// We must specify that the two events are a union so the compiler doesn't
|
|
|
|
// complain about strict aliasing rules.
|
2011-01-30 14:34:42 +00:00
|
|
|
typedef union {
|
|
|
|
XEvent e;
|
|
|
|
XDamageNotifyEvent de;
|
|
|
|
} EventUnion;
|
2009-10-05 09:47:13 +00:00
|
|
|
|
2011-07-08 23:26:58 +00:00
|
|
|
static QVector<QRect> damageRects;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::damageNotifyEvent(XDamageNotifyEvent* e)
|
|
|
|
{
|
2011-08-28 18:25:58 +00:00
|
|
|
if (damageRatio == 1.0) { // we know that we're completely damaged, no need to tell us again
|
|
|
|
while (XPending(display())) { // drop events
|
2011-08-28 12:23:34 +00:00
|
|
|
EventUnion e2;
|
|
|
|
if (XPeekEvent(display(), &e2.e) && e2.e.type == Extensions::damageNotifyEvent() &&
|
|
|
|
e2.e.xany.window == frameId()) {
|
|
|
|
XNextEvent(display(), &e2.e);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-08 23:26:58 +00:00
|
|
|
return;
|
2011-08-28 12:23:34 +00:00
|
|
|
}
|
2011-07-08 23:26:58 +00:00
|
|
|
|
|
|
|
const float area = rect().width()*rect().height();
|
|
|
|
damageRects.reserve(16);
|
|
|
|
damageRects.clear();
|
|
|
|
damageRects << QRect(e->area.x, e->area.y, e->area.width, e->area.height);
|
|
|
|
|
|
|
|
// we can not easily say anything about the overall ratio since the new rects may intersect the present
|
|
|
|
float newDamageRatio = damageRects.last().width()*damageRects.last().height() / area;
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// compress
|
2011-01-30 14:34:42 +00:00
|
|
|
while (XPending(display())) {
|
2009-10-05 09:47:13 +00:00
|
|
|
EventUnion e2;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (XPeekEvent(display(), &e2.e) && e2.e.type == Extensions::damageNotifyEvent()
|
|
|
|
&& e2.e.xany.window == frameId()) {
|
|
|
|
XNextEvent(display(), &e2.e);
|
2011-07-08 23:26:58 +00:00
|
|
|
if (damageRatio >= 0.8 || newDamageRatio > 0.8 || damageRects.count() > 15) {
|
|
|
|
// If there are too many damage events in the queue, just discard them
|
2008-07-22 18:20:42 +00:00
|
|
|
// 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.
|
2011-07-08 23:26:58 +00:00
|
|
|
newDamageRatio = 1.0;
|
|
|
|
damageRects.clear();
|
2008-07-22 18:20:42 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-07-08 23:26:58 +00:00
|
|
|
damageRects << QRect(e2.de.area.x, e2.de.area.y, e2.de.area.width, e2.de.area.height);
|
|
|
|
newDamageRatio += damageRects.last().width()*damageRects.last().height() / area;
|
2007-04-29 17:35:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-07-08 23:26:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
if ((damageRects.count() == 1 && damageRects.last() == rect()) ||
|
|
|
|
(damageRects.isEmpty() && newDamageRatio == 1.0)) {
|
|
|
|
addDamageFull();
|
|
|
|
} else {
|
|
|
|
foreach (const QRect &r, damageRects)
|
|
|
|
addDamage(r);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-06-25 08:51:44 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Client::damageNotifyEvent(XDamageNotifyEvent* e)
|
|
|
|
{
|
2007-06-25 08:51:44 +00:00
|
|
|
#ifdef HAVE_XSYNC
|
2011-08-13 14:39:58 +00:00
|
|
|
if (syncRequest.isPending && isResize())
|
|
|
|
return;
|
2012-01-24 16:00:40 +00:00
|
|
|
if (!ready_for_painting) { // avoid "setReadyForPainting()" function calling overhead
|
|
|
|
if (syncRequest.counter == None) // cannot detect complete redraw, consider done now
|
|
|
|
setReadyForPainting();
|
2012-02-26 08:42:17 +00:00
|
|
|
}
|
2007-06-25 08:51:44 +00:00
|
|
|
#else
|
2012-01-24 16:00:40 +00:00
|
|
|
setReadyForPainting();
|
2007-06-25 08:51:44 +00:00
|
|
|
#endif
|
2011-08-13 14:39:58 +00:00
|
|
|
|
|
|
|
Toplevel::damageNotifyEvent(e);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::addDamage(const QRect& r)
|
|
|
|
{
|
|
|
|
addDamage(r.x(), r.y(), r.width(), r.height());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::addDamage(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
QRect r(x, y, w, h);
|
2007-04-29 17:35:43 +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();
|
2011-11-08 19:53:17 +00:00
|
|
|
if (r.isEmpty())
|
|
|
|
return;
|
2007-04-29 17:35:43 +00:00
|
|
|
damage_region += r;
|
2011-07-08 23:26:58 +00:00
|
|
|
int damageArea = 0;
|
|
|
|
foreach (const QRect &r2, damage_region.rects())
|
|
|
|
damageArea += r2.width()*r2.height();
|
|
|
|
damageRatio = float(damageArea) / float(rect().width()*rect().height());
|
2007-04-29 17:35:43 +00:00
|
|
|
repaints_region += r;
|
2011-03-12 14:04:22 +00:00
|
|
|
emit damaged(this, r);
|
2010-11-01 10:46:11 +00:00
|
|
|
// discard lanczos texture
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effect_window) {
|
|
|
|
QVariant cachedTextureVariant = effect_window->data(LanczosCacheRole);
|
|
|
|
if (cachedTextureVariant.isValid()) {
|
2010-11-01 10:46:11 +00:00
|
|
|
GLTexture *cachedTexture = static_cast< GLTexture*>(cachedTextureVariant.value<void*>());
|
|
|
|
delete cachedTexture;
|
|
|
|
cachedTexture = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
effect_window->setData(LanczosCacheRole, QVariant());
|
2010-11-01 10:46:11 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Toplevel::addDamageFull()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
damage_region = rect();
|
|
|
|
repaints_region = rect();
|
2011-07-08 23:26:58 +00:00
|
|
|
damageRatio = 1.0;
|
2011-03-12 14:04:22 +00:00
|
|
|
emit damaged(this, rect());
|
2010-11-01 10:46:11 +00:00
|
|
|
// discard lanczos texture
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effect_window) {
|
|
|
|
QVariant cachedTextureVariant = effect_window->data(LanczosCacheRole);
|
|
|
|
if (cachedTextureVariant.isValid()) {
|
2010-11-01 10:46:11 +00:00
|
|
|
GLTexture *cachedTexture = static_cast< GLTexture*>(cachedTextureVariant.value<void*>());
|
|
|
|
delete cachedTexture;
|
|
|
|
cachedTexture = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
effect_window->setData(LanczosCacheRole, QVariant());
|
2010-11-01 10:46:11 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::resetDamage(const QRect& r)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
damage_region -= r;
|
2011-07-08 23:26:58 +00:00
|
|
|
int damageArea = 0;
|
|
|
|
foreach (const QRect &r2, damage_region.rects())
|
|
|
|
damageArea += r2.width()*r2.height();
|
|
|
|
damageRatio = float(damageArea) / float(rect().width()*rect().height());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::addRepaint(const QRect& r)
|
|
|
|
{
|
2012-02-07 16:01:41 +00:00
|
|
|
if (!compositing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
repaints_region += r;
|
|
|
|
workspace()->checkCompositeTimer();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::addRepaint(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
QRect r(x, y, w, h);
|
2012-02-07 16:01:41 +00:00
|
|
|
addRepaint(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addRepaint(const QRegion& r)
|
|
|
|
{
|
|
|
|
if (!compositing()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
repaints_region += r;
|
2008-08-30 15:28:47 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-02-07 16:01:41 +00:00
|
|
|
void Toplevel::addLayerRepaint(const QRect& r)
|
|
|
|
{
|
|
|
|
if (!compositing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
layer_repaints_region += r;
|
|
|
|
workspace()->checkCompositeTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addLayerRepaint(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
QRect r(x, y, w, h);
|
|
|
|
addLayerRepaint(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addLayerRepaint(const QRegion& r)
|
2011-07-15 08:27:11 +00:00
|
|
|
{
|
|
|
|
if (!compositing())
|
|
|
|
return;
|
2012-02-07 16:01:41 +00:00
|
|
|
layer_repaints_region += r;
|
2011-07-15 08:27:11 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Toplevel::addRepaintFull()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-13 20:50:31 +00:00
|
|
|
repaints_region = decorationRect();
|
2008-08-30 15:28:47 +00:00
|
|
|
workspace()->checkCompositeTimer();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-02-07 16:01:41 +00:00
|
|
|
void Toplevel::resetRepaints()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-02-07 16:01:41 +00:00
|
|
|
repaints_region = QRegion();
|
|
|
|
layer_repaints_region = QRegion();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::addWorkspaceRepaint(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
addWorkspaceRepaint(QRect(x, y, w, h));
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::addWorkspaceRepaint(const QRect& r2)
|
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-03-15 19:38:37 +00:00
|
|
|
workspace()->addRepaint(r2);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-08-24 13:32:57 +00:00
|
|
|
bool Toplevel::updateUnredirectedState()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
assert(compositing());
|
2009-01-05 12:52:27 +00:00
|
|
|
bool should = shouldUnredirect() && !unredirectSuspend && !shape() && !hasAlpha() && opacity() == 1.0 &&
|
2011-01-30 14:34:42 +00:00
|
|
|
!static_cast<EffectsHandlerImpl*>(effects)->activeFullScreenEffect();
|
|
|
|
if (should && !unredirect) {
|
2008-08-24 13:32:57 +00:00
|
|
|
unredirect = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
kDebug(1212) << "Unredirecting:" << this;
|
|
|
|
XCompositeUnredirectWindow(display(), frameId(), CompositeRedirectManual);
|
2008-08-24 13:32:57 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (!should && unredirect) {
|
2008-08-24 13:32:57 +00:00
|
|
|
unredirect = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
kDebug(1212) << "Redirecting:" << this;
|
|
|
|
XCompositeRedirectWindow(display(), frameId(), CompositeRedirectManual);
|
2008-08-24 13:32:57 +00:00
|
|
|
discardWindowPixmap();
|
|
|
|
return true;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-08-24 13:32:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Toplevel::suspendUnredirect(bool suspend)
|
|
|
|
{
|
|
|
|
if (unredirectSuspend == suspend)
|
2008-09-23 14:51:21 +00:00
|
|
|
return;
|
2008-08-24 13:32:57 +00:00
|
|
|
unredirectSuspend = suspend;
|
|
|
|
workspace()->checkUnredirect();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-24 13:32:57 +00:00
|
|
|
|
2008-08-12 11:02:58 +00:00
|
|
|
//****************************************
|
|
|
|
// Client
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
void Client::setupCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-08-12 11:02:58 +00:00
|
|
|
Toplevel::setupCompositing();
|
|
|
|
updateVisibility(); // for internalKeep()
|
2011-05-15 11:22:28 +00:00
|
|
|
updateDecoration(true, true);
|
2011-12-12 02:17:37 +00:00
|
|
|
move(calculateGravitation(true)); // we just polluted the gravity because the window likely has no decoration yet
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-12 11:02:58 +00:00
|
|
|
|
|
|
|
void Client::finishCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-08-12 11:02:58 +00:00
|
|
|
Toplevel::finishCompositing();
|
|
|
|
updateVisibility();
|
2011-05-15 11:22:28 +00:00
|
|
|
updateDecoration(true, true);
|
2011-12-09 19:44:06 +00:00
|
|
|
// for safety in case KWin is just resizing the window
|
|
|
|
s_haveResizeEffect = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-12 11:02:58 +00:00
|
|
|
|
2008-08-24 13:32:57 +00:00
|
|
|
bool Client::shouldUnredirect() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (isActiveFullScreen()) {
|
2008-08-24 13:32:57 +00:00
|
|
|
ToplevelList stacking = workspace()->xStackingOrder();
|
2011-01-30 14:34:42 +00:00
|
|
|
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
|
2008-08-24 13:32:57 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->geometry().intersects(geometry()))
|
2008-08-24 13:32:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
abort();
|
2008-08-24 13:32:57 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-08-24 13:32:57 +00:00
|
|
|
|
2009-07-29 11:48:55 +00:00
|
|
|
|
2008-08-24 13:32:57 +00:00
|
|
|
//****************************************
|
|
|
|
// Unmanaged
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
bool Unmanaged::shouldUnredirect() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
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
|
2011-05-01 14:17:21 +00:00
|
|
|
if (resourceClass() == "ksplashx"
|
|
|
|
|| resourceClass() == "ksplashsimple"
|
|
|
|
|| resourceClass() == "ksplashqml"
|
|
|
|
)
|
2008-10-14 10:34:35 +00:00
|
|
|
return false;
|
2008-08-24 13:32:57 +00:00
|
|
|
// it must cover whole display or one xinerama screen, and be the topmost there
|
2011-01-30 14:34:42 +00:00
|
|
|
if (geometry() == workspace()->clientArea(FullArea, geometry().center(), workspace()->currentDesktop())
|
|
|
|
|| geometry() == workspace()->clientArea(ScreenArea, geometry().center(), workspace()->currentDesktop())) {
|
2008-08-24 13:32:57 +00:00
|
|
|
ToplevelList stacking = workspace()->xStackingOrder();
|
2011-01-30 14:34:42 +00:00
|
|
|
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
|
2008-08-24 13:32:57 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->geometry().intersects(geometry()))
|
2008-08-24 13:32:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
abort();
|
2008-08-24 13:32:57 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-08-24 13:32:57 +00:00
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Deleted
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
bool Deleted::shouldUnredirect() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-08-24 13:32:57 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-24 13:32:57 +00:00
|
|
|
|
2009-07-29 11:07:28 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|