2007-11-27 22:40:25 +03:00
|
|
|
/********************************************************************
|
2007-04-29 21:35:43 +04: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 22:40:25 +03: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/>.
|
|
|
|
*********************************************************************/
|
2012-08-30 10:20:26 +04:00
|
|
|
#include "composite.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2014-06-02 10:51:28 +04:00
|
|
|
#include "dbusinterface.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
#include "utils.h"
|
2007-10-06 02:21:25 +04:00
|
|
|
#include <QTextStream>
|
2007-04-29 21:35:43 +04:00
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "unmanaged.h"
|
|
|
|
#include "deleted.h"
|
|
|
|
#include "effects.h"
|
2011-07-06 13:58:23 +04:00
|
|
|
#include "overlaywindow.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
#include "scene.h"
|
|
|
|
#include "scene_xrender.h"
|
|
|
|
#include "scene_opengl.h"
|
2013-06-21 12:03:31 +04:00
|
|
|
#include "scene_qpainter.h"
|
2014-11-25 10:40:23 +03:00
|
|
|
#include "screens.h"
|
2011-03-27 14:33:07 +04:00
|
|
|
#include "shadow.h"
|
2012-08-19 14:00:53 +04:00
|
|
|
#include "useractions.h"
|
2007-09-18 17:59:06 +04:00
|
|
|
#include "compositingprefs.h"
|
2013-01-07 17:10:00 +04:00
|
|
|
#include "xcbutils.h"
|
2015-05-05 20:02:52 +03:00
|
|
|
#include "abstract_backend.h"
|
2015-03-04 11:21:10 +03:00
|
|
|
#include "shell_client.h"
|
2015-03-23 16:29:07 +03:00
|
|
|
#include "wayland_server.h"
|
2014-07-25 09:14:21 +04:00
|
|
|
#include "decorations/decoratedclient.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-02-24 13:50:01 +03:00
|
|
|
#include <KWayland/Server/surface_interface.h>
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-02-26 12:00:51 +04:00
|
|
|
#include <QtConcurrentRun>
|
|
|
|
#include <QFutureWatcher>
|
2007-04-29 21:35:43 +04:00
|
|
|
#include <QMenu>
|
2010-12-18 19:51:43 +03:00
|
|
|
#include <QTimerEvent>
|
2011-08-21 23:50:23 +04:00
|
|
|
#include <QDateTime>
|
2015-10-30 15:18:30 +03:00
|
|
|
#include <QOpenGLContext>
|
2014-03-17 19:24:10 +04:00
|
|
|
#include <KGlobalAccel>
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KNotification>
|
|
|
|
#include <KSelectionWatcher>
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-12-12 00:21:35 +04:00
|
|
|
#include <xcb/composite.h>
|
2012-03-28 22:29:33 +04:00
|
|
|
#include <xcb/damage.h>
|
|
|
|
|
2013-01-09 19:03:54 +04:00
|
|
|
Q_DECLARE_METATYPE(KWin::Compositor::SuspendReason)
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2010-11-27 18:27:54 +03:00
|
|
|
extern int currentRefreshRate();
|
|
|
|
|
2015-02-20 13:00:48 +03:00
|
|
|
CompositorSelectionOwner::CompositorSelectionOwner(const char *selection) : KSelectionOwner(selection, connection(), rootWindow()), owning(false)
|
2013-04-26 19:11:37 +04:00
|
|
|
{
|
|
|
|
connect (this, SIGNAL(lostOwnership()), SLOT(looseOwnership()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositorSelectionOwner::looseOwnership()
|
|
|
|
{
|
|
|
|
owning = false;
|
|
|
|
}
|
|
|
|
|
2013-04-05 11:41:25 +04:00
|
|
|
KWIN_SINGLETON_FACTORY_VARIABLE(Compositor, s_compositor)
|
2012-08-28 21:31:17 +04:00
|
|
|
|
2015-12-28 05:52:47 +03:00
|
|
|
static inline qint64 milliToNano(int milli) { return qint64(milli) * 1000 * 1000; }
|
2013-03-29 00:53:25 +04:00
|
|
|
static inline qint64 nanoToMilli(int nano) { return nano / (1000*1000); }
|
|
|
|
|
2012-08-16 19:10:47 +04:00
|
|
|
Compositor::Compositor(QObject* workspace)
|
2011-08-21 23:50:23 +04:00
|
|
|
: QObject(workspace)
|
2013-01-09 19:03:54 +04:00
|
|
|
, m_suspended(options->isUseCompositing() ? NoReasonSuspend : UserSuspend)
|
2012-08-27 21:45:01 +04:00
|
|
|
, cm_selection(NULL)
|
|
|
|
, vBlankInterval(0)
|
|
|
|
, fpsInterval(0)
|
2011-08-21 23:50:23 +04:00
|
|
|
, m_xrrRefreshRate(0)
|
2012-08-27 21:45:01 +04:00
|
|
|
, forceUnredirectCheck(false)
|
|
|
|
, m_finishing(false)
|
|
|
|
, m_timeSinceLastVBlank(0)
|
2012-08-16 23:19:54 +04:00
|
|
|
, m_scene(NULL)
|
2014-08-27 20:24:43 +04:00
|
|
|
, m_bufferSwapPending(false)
|
|
|
|
, m_composeAtSwapCompletion(false)
|
2011-08-21 23:50:23 +04:00
|
|
|
{
|
2013-01-09 19:03:54 +04:00
|
|
|
qRegisterMetaType<Compositor::SuspendReason>("Compositor::SuspendReason");
|
2011-08-21 23:50:23 +04:00
|
|
|
connect(&unredirectTimer, SIGNAL(timeout()), SLOT(delayedCheckUnredirect()));
|
2012-08-17 10:18:36 +04:00
|
|
|
connect(&compositeResetTimer, SIGNAL(timeout()), SLOT(restart()));
|
2015-02-23 16:50:22 +03:00
|
|
|
connect(options, &Options::configChanged, this, &Compositor::slotConfigChanged);
|
2013-08-04 00:13:14 +04:00
|
|
|
connect(options, SIGNAL(unredirectFullscreenChanged()), SLOT(delayedCheckUnredirect()));
|
2011-08-21 23:50:23 +04:00
|
|
|
unredirectTimer.setSingleShot(true);
|
|
|
|
compositeResetTimer.setSingleShot(true);
|
|
|
|
nextPaintReference.invalidate(); // Initialize the timer
|
2012-10-14 14:18:35 +04:00
|
|
|
|
|
|
|
// 2 sec which should be enough to restart the compositor
|
2013-04-27 02:00:23 +04:00
|
|
|
static const int compositorLostMessageDelay = 2000;
|
|
|
|
|
|
|
|
m_releaseSelectionTimer.setSingleShot(true);
|
|
|
|
m_releaseSelectionTimer.setInterval(compositorLostMessageDelay);
|
2012-10-14 14:18:35 +04:00
|
|
|
connect(&m_releaseSelectionTimer, SIGNAL(timeout()), SLOT(releaseCompositorSelection()));
|
2013-04-27 02:00:23 +04:00
|
|
|
|
|
|
|
m_unusedSupportPropertyTimer.setInterval(compositorLostMessageDelay);
|
|
|
|
m_unusedSupportPropertyTimer.setSingleShot(true);
|
|
|
|
connect(&m_unusedSupportPropertyTimer, SIGNAL(timeout()), SLOT(deleteUnusedSupportProperties()));
|
2013-07-03 13:56:05 +04:00
|
|
|
if (kwinApp()->operationMode() != Application::OperationModeX11) {
|
2015-05-05 20:02:52 +03:00
|
|
|
if (waylandServer()->backend()->isReady()) {
|
2015-03-19 10:29:34 +03:00
|
|
|
QMetaObject::invokeMethod(this, "setup", Qt::QueuedConnection);
|
|
|
|
}
|
2015-05-05 20:02:52 +03:00
|
|
|
connect(waylandServer()->backend(), &AbstractBackend::readyChanged, this,
|
|
|
|
[this] (bool ready) {
|
|
|
|
if (ready) {
|
|
|
|
setup();
|
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}, Qt::QueuedConnection
|
|
|
|
);
|
2015-11-12 17:13:42 +03:00
|
|
|
connect(kwinApp(), &Application::x11ConnectionAboutToBeDestroyed, this,
|
|
|
|
[this] {
|
|
|
|
delete cm_selection;
|
|
|
|
cm_selection = nullptr;
|
|
|
|
}
|
|
|
|
);
|
2015-08-10 17:31:45 +03:00
|
|
|
} else {
|
|
|
|
// delay the call to setup by one event cycle
|
|
|
|
// The ctor of this class is invoked from the Workspace ctor, that means before
|
|
|
|
// Workspace is completely constructed, so calling Workspace::self() would result
|
|
|
|
// in undefined behavior. This is fixed by using a delayed invocation.
|
|
|
|
QMetaObject::invokeMethod(this, "setup", Qt::QueuedConnection);
|
2014-08-13 14:54:02 +04:00
|
|
|
}
|
2014-06-02 10:51:28 +04:00
|
|
|
|
|
|
|
// register DBus
|
|
|
|
new CompositorDBusInterface(this);
|
2011-08-21 23:50:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Compositor::~Compositor()
|
|
|
|
{
|
2014-12-03 15:10:35 +03:00
|
|
|
emit aboutToDestroy();
|
2012-08-17 10:18:36 +04:00
|
|
|
finish();
|
2013-04-27 02:00:23 +04:00
|
|
|
deleteUnusedSupportProperties();
|
2012-10-14 14:18:35 +04:00
|
|
|
delete cm_selection;
|
2012-12-29 20:01:05 +04:00
|
|
|
s_compositor = NULL;
|
2011-08-21 23:50:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 10:18:36 +04:00
|
|
|
void Compositor::setup()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 23:19:54 +04:00
|
|
|
if (hasScene())
|
2008-02-08 13:31:40 +03:00
|
|
|
return;
|
2012-08-17 10:18:36 +04:00
|
|
|
if (m_suspended) {
|
2014-05-15 11:19:21 +04:00
|
|
|
QStringList reasons;
|
|
|
|
if (m_suspended & UserSuspend) {
|
|
|
|
reasons << QStringLiteral("Disabled by User");
|
|
|
|
}
|
|
|
|
if (m_suspended & BlockRuleSuspend) {
|
|
|
|
reasons << QStringLiteral("Disabled by Window");
|
|
|
|
}
|
|
|
|
if (m_suspended & ScriptSuspend) {
|
|
|
|
reasons << QStringLiteral("Disabled by Script");
|
|
|
|
}
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Compositing is suspended, reason:" << reasons;
|
2008-05-20 01:48:47 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
} else if (!CompositingPrefs::compositingPossible()) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCCritical(KWIN_CORE) << "Compositing is not possible";
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-10-14 14:18:35 +04:00
|
|
|
m_starting = true;
|
2011-02-28 01:39:32 +03:00
|
|
|
|
2012-04-13 11:12:13 +04:00
|
|
|
if (!options->isCompositingInitialized()) {
|
2011-02-28 01:39:32 +03:00
|
|
|
options->reloadCompositingSettings(true);
|
2012-04-13 11:12:13 +04:00
|
|
|
slotCompositingOptionsInitialized();
|
|
|
|
} else {
|
|
|
|
slotCompositingOptionsInitialized();
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 20:20:05 +04:00
|
|
|
|
2013-02-13 03:40:11 +04:00
|
|
|
extern int screen_number; // main.cpp
|
2013-05-24 16:50:17 +04:00
|
|
|
extern bool is_multihead;
|
2013-02-13 03:40:11 +04:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::slotCompositingOptionsInitialized()
|
2012-04-13 11:12:13 +04:00
|
|
|
{
|
2015-02-23 17:57:00 +03:00
|
|
|
claimCompositorSelection();
|
2014-04-14 11:19:43 +04:00
|
|
|
|
|
|
|
// There might still be a deleted around, needs to be cleared before creating the scene (BUG 333275)
|
2015-02-23 17:57:00 +03:00
|
|
|
if (Workspace::self()) {
|
|
|
|
while (!Workspace::self()->deletedList().isEmpty()) {
|
|
|
|
Workspace::self()->deletedList().first()->discard();
|
|
|
|
}
|
2014-04-14 11:19:43 +04:00
|
|
|
}
|
|
|
|
|
2012-02-20 13:25:13 +04:00
|
|
|
switch(options->compositingMode()) {
|
2011-01-30 17:34:42 +03:00
|
|
|
case OpenGLCompositing: {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Initializing OpenGL compositing";
|
2011-01-30 17:34:42 +03:00
|
|
|
|
|
|
|
// Some broken drivers crash on glXQuery() so to prevent constant KWin crashes:
|
2016-01-29 13:24:18 +03:00
|
|
|
KSharedConfigPtr unsafeConfigPtr = kwinApp()->config();
|
2011-01-30 17:34:42 +03:00
|
|
|
KConfigGroup unsafeConfig(unsafeConfigPtr, "Compositing");
|
2015-11-05 17:14:06 +03:00
|
|
|
const QString openGLIsUnsafe = QLatin1String("OpenGLIsUnsafe") + (is_multihead ? QString::number(screen_number) : QString());
|
2013-02-13 03:40:11 +04:00
|
|
|
if (unsafeConfig.readEntry(openGLIsUnsafe, false))
|
2014-12-05 13:42:15 +03:00
|
|
|
qCWarning(KWIN_CORE) << "KWin has detected that your OpenGL library is unsafe to use";
|
2011-01-30 17:34:42 +03:00
|
|
|
else {
|
2013-02-13 03:40:11 +04:00
|
|
|
unsafeConfig.writeEntry(openGLIsUnsafe, true);
|
2011-01-30 17:34:42 +03:00
|
|
|
unsafeConfig.sync();
|
2015-10-30 15:18:30 +03:00
|
|
|
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL && !kwinApp()->shouldUseWaylandForCompositing() && !CompositingPrefs::hasGlx()) {
|
2013-02-13 03:40:11 +04:00
|
|
|
unsafeConfig.writeEntry(openGLIsUnsafe, false);
|
2011-07-21 00:10:03 +04:00
|
|
|
unsafeConfig.sync();
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "No glx extensions available";
|
2011-07-21 00:10:03 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
|
2015-02-23 16:41:45 +03:00
|
|
|
m_scene = SceneOpenGL::createScene(this);
|
2011-01-30 17:34:42 +03:00
|
|
|
|
|
|
|
// TODO: Add 30 second delay to protect against screen freezes as well
|
2013-02-13 03:40:11 +04:00
|
|
|
unsafeConfig.writeEntry(openGLIsUnsafe, false);
|
2011-01-30 17:34:42 +03:00
|
|
|
unsafeConfig.sync();
|
|
|
|
|
2014-06-02 09:58:06 +04:00
|
|
|
if (m_scene && !m_scene->initFailed()) {
|
|
|
|
connect(static_cast<SceneOpenGL*>(m_scene), &SceneOpenGL::resetCompositing, this, &Compositor::restart);
|
2011-01-30 17:34:42 +03:00
|
|
|
break; // -->
|
2014-06-02 09:58:06 +04:00
|
|
|
}
|
2012-08-16 23:19:54 +04:00
|
|
|
delete m_scene;
|
|
|
|
m_scene = NULL;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-01-25 13:02:08 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
// Do not Fall back to XRender - it causes problems when selfcheck fails during startup, but works later on
|
|
|
|
break;
|
|
|
|
}
|
2007-12-17 17:14:53 +03:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 17:34:42 +03:00
|
|
|
case XRenderCompositing:
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Initializing XRender compositing";
|
2015-02-23 16:41:45 +03:00
|
|
|
m_scene = SceneXrender::createScene(this);
|
2011-01-30 17:34:42 +03:00
|
|
|
break;
|
2007-04-29 21:35:43 +04:00
|
|
|
#endif
|
2013-06-21 12:03:31 +04:00
|
|
|
case QPainterCompositing:
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Initializing QPainter compositing";
|
2015-02-23 16:41:45 +03:00
|
|
|
m_scene = SceneQPainter::createScene(this);
|
2013-06-21 12:03:31 +04:00
|
|
|
break;
|
2011-01-30 17:34:42 +03:00
|
|
|
default:
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "No compositing enabled";
|
2012-10-14 14:18:35 +04:00
|
|
|
m_starting = false;
|
2015-02-23 17:57:00 +03:00
|
|
|
if (cm_selection) {
|
|
|
|
cm_selection->owning = false;
|
|
|
|
cm_selection->release();
|
|
|
|
}
|
2013-06-25 12:39:13 +04:00
|
|
|
if (kwinApp()->requiresCompositing()) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCCritical(KWIN_CORE) << "The used windowing system requires compositing";
|
|
|
|
qCCritical(KWIN_CORE) << "We are going to quit KWin now as it is broken";
|
2013-06-25 12:39:13 +04:00
|
|
|
qApp->quit();
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2012-08-16 23:19:54 +04:00
|
|
|
if (m_scene == NULL || m_scene->initFailed()) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCCritical(KWIN_CORE) << "Failed to initialize compositing, compositing disabled";
|
2012-08-16 23:19:54 +04:00
|
|
|
delete m_scene;
|
|
|
|
m_scene = NULL;
|
2012-10-14 14:18:35 +04:00
|
|
|
m_starting = false;
|
2015-02-23 17:57:00 +03:00
|
|
|
if (cm_selection) {
|
|
|
|
cm_selection->owning = false;
|
|
|
|
cm_selection->release();
|
|
|
|
}
|
2013-06-25 12:39:13 +04:00
|
|
|
if (kwinApp()->requiresCompositing()) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCCritical(KWIN_CORE) << "The used windowing system requires compositing";
|
|
|
|
qCCritical(KWIN_CORE) << "We are going to quit KWin now as it is broken";
|
2013-06-25 12:39:13 +04:00
|
|
|
qApp->quit();
|
|
|
|
}
|
2007-05-30 18:22:09 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2015-02-23 17:57:00 +03:00
|
|
|
|
|
|
|
if (Workspace::self()) {
|
|
|
|
startupWithWorkspace();
|
|
|
|
} else {
|
|
|
|
connect(kwinApp(), &Application::workspaceCreated, this, &Compositor::startupWithWorkspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::claimCompositorSelection()
|
|
|
|
{
|
|
|
|
if (!cm_selection && kwinApp()->x11Connection()) {
|
|
|
|
char selection_name[ 100 ];
|
|
|
|
sprintf(selection_name, "_NET_WM_CM_S%d", Application::x11ScreenNumber());
|
|
|
|
cm_selection = new CompositorSelectionOwner(selection_name);
|
|
|
|
connect(cm_selection, SIGNAL(lostOwnership()), SLOT(finish()));
|
|
|
|
}
|
2015-05-17 23:13:25 +03:00
|
|
|
|
|
|
|
if (!cm_selection) // no X11 yet
|
|
|
|
return;
|
|
|
|
|
2015-02-23 17:57:00 +03:00
|
|
|
if (!cm_selection->owning) {
|
|
|
|
cm_selection->claim(true); // force claiming
|
|
|
|
cm_selection->owning = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::startupWithWorkspace()
|
|
|
|
{
|
|
|
|
if (!m_starting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Q_ASSERT(m_scene);
|
|
|
|
claimCompositorSelection();
|
2011-08-21 23:50:23 +04:00
|
|
|
m_xrrRefreshRate = KWin::currentRefreshRate();
|
2013-03-29 00:53:25 +04:00
|
|
|
fpsInterval = options->maxFpsInterval();
|
2013-03-29 00:52:26 +04:00
|
|
|
if (m_scene->syncsToVBlank()) { // if we do vsync, set the fps to the next multiple of the vblank rate
|
2013-03-29 00:53:25 +04:00
|
|
|
vBlankInterval = milliToNano(1000) / m_xrrRefreshRate;
|
2012-03-30 00:11:28 +04:00
|
|
|
fpsInterval = qMax((fpsInterval / vBlankInterval) * vBlankInterval, vBlankInterval);
|
2011-01-30 17:34:42 +03:00
|
|
|
} else
|
2013-03-29 00:53:25 +04:00
|
|
|
vBlankInterval = milliToNano(1); // no sync - DO NOT set "0", would cause div-by-zero segfaults.
|
|
|
|
m_timeSinceLastVBlank = fpsInterval - (options->vBlankTime() + 1); // means "start now" - we don't have even a slight idea when the first vsync will occur
|
2012-08-23 15:42:59 +04:00
|
|
|
scheduleRepaint();
|
2012-12-12 01:49:16 +04:00
|
|
|
xcb_composite_redirect_subwindows(connection(), rootWindow(), XCB_COMPOSITE_REDIRECT_MANUAL);
|
2012-08-23 20:04:36 +04:00
|
|
|
new EffectsHandlerImpl(this, m_scene); // sets also the 'effects' pointer
|
2016-01-15 03:37:51 +03:00
|
|
|
connect(Workspace::self(), &Workspace::deletedRemoved, m_scene, &Scene::windowDeleted);
|
2012-08-23 15:42:59 +04:00
|
|
|
connect(effects, SIGNAL(screenGeometryChanged(QSize)), SLOT(addRepaintFull()));
|
2007-04-29 21:35:43 +04:00
|
|
|
addRepaintFull();
|
2012-12-28 00:57:40 +04:00
|
|
|
foreach (Client * c, Workspace::self()->clientList()) {
|
2012-03-30 00:11:28 +04:00
|
|
|
c->setupCompositing();
|
2012-12-28 00:57:40 +04:00
|
|
|
c->getShadow();
|
|
|
|
}
|
2012-08-16 19:10:47 +04:00
|
|
|
foreach (Client * c, Workspace::self()->desktopList())
|
2012-03-30 00:11:28 +04:00
|
|
|
c->setupCompositing();
|
2012-12-28 00:57:40 +04:00
|
|
|
foreach (Unmanaged * c, Workspace::self()->unmanagedList()) {
|
2012-03-30 00:11:28 +04:00
|
|
|
c->setupCompositing();
|
2012-12-28 00:57:40 +04:00
|
|
|
c->getShadow();
|
|
|
|
}
|
2012-04-13 13:36:48 +04:00
|
|
|
|
2012-09-01 11:10:56 +04:00
|
|
|
emit compositingToggled(true);
|
|
|
|
|
2012-10-14 14:18:35 +04:00
|
|
|
m_starting = false;
|
|
|
|
if (m_releaseSelectionTimer.isActive()) {
|
|
|
|
m_releaseSelectionTimer.stop();
|
|
|
|
}
|
|
|
|
|
2012-04-13 13:36:48 +04:00
|
|
|
// render at least once
|
|
|
|
performCompositing();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-08-23 15:42:59 +04:00
|
|
|
void Compositor::scheduleRepaint()
|
2011-08-21 23:50:23 +04:00
|
|
|
{
|
|
|
|
if (!compositeTimer.isActive())
|
|
|
|
setCompositeTimer();
|
|
|
|
}
|
|
|
|
|
2012-08-17 10:18:36 +04:00
|
|
|
void Compositor::finish()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 23:19:54 +04:00
|
|
|
if (!hasScene())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2012-08-17 10:18:36 +04:00
|
|
|
m_finishing = true;
|
2012-10-14 14:18:35 +04:00
|
|
|
m_releaseSelectionTimer.start();
|
2015-05-27 10:12:07 +03:00
|
|
|
if (Workspace::self()) {
|
|
|
|
foreach (Client * c, Workspace::self()->clientList())
|
|
|
|
m_scene->windowClosed(c, NULL);
|
|
|
|
foreach (Client * c, Workspace::self()->desktopList())
|
|
|
|
m_scene->windowClosed(c, NULL);
|
|
|
|
foreach (Unmanaged * c, Workspace::self()->unmanagedList())
|
|
|
|
m_scene->windowClosed(c, NULL);
|
|
|
|
foreach (Deleted * c, Workspace::self()->deletedList())
|
|
|
|
m_scene->windowDeleted(c);
|
|
|
|
foreach (Client * c, Workspace::self()->clientList())
|
|
|
|
c->finishCompositing();
|
|
|
|
foreach (Client * c, Workspace::self()->desktopList())
|
|
|
|
c->finishCompositing();
|
|
|
|
foreach (Unmanaged * c, Workspace::self()->unmanagedList())
|
|
|
|
c->finishCompositing();
|
|
|
|
foreach (Deleted * c, Workspace::self()->deletedList())
|
|
|
|
c->finishCompositing();
|
|
|
|
xcb_composite_unredirect_subwindows(connection(), rootWindow(), XCB_COMPOSITE_REDIRECT_MANUAL);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
delete effects;
|
|
|
|
effects = NULL;
|
2012-08-16 23:19:54 +04:00
|
|
|
delete m_scene;
|
|
|
|
m_scene = NULL;
|
2011-02-01 18:35:51 +03:00
|
|
|
compositeTimer.stop();
|
2007-04-29 21:35:43 +04:00
|
|
|
repaints_region = QRegion();
|
2015-05-27 10:12:07 +03:00
|
|
|
if (Workspace::self()) {
|
|
|
|
for (ClientList::ConstIterator it = Workspace::self()->clientList().constBegin();
|
|
|
|
it != Workspace::self()->clientList().constEnd();
|
|
|
|
++it) {
|
|
|
|
// forward all opacity values to the frame in case there'll be other CM running
|
|
|
|
if ((*it)->opacity() != 1.0) {
|
|
|
|
NETWinInfo i(connection(), (*it)->frameId(), rootWindow(), 0, 0);
|
|
|
|
i.setOpacity(static_cast< unsigned long >((*it)->opacity() * 0xffffffff));
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2015-05-27 10:12:07 +03:00
|
|
|
// discard all Deleted windows (#152914)
|
|
|
|
while (!Workspace::self()->deletedList().isEmpty())
|
|
|
|
Workspace::self()->deletedList().first()->discard();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-08-17 10:18:36 +04:00
|
|
|
m_finishing = false;
|
2012-09-01 11:10:56 +04:00
|
|
|
emit compositingToggled(false);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-10-14 14:18:35 +04:00
|
|
|
void Compositor::releaseCompositorSelection()
|
|
|
|
{
|
|
|
|
if (hasScene() && !m_finishing) {
|
|
|
|
// compositor is up and running again, no need to release the selection
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_starting) {
|
|
|
|
// currently still starting the compositor, it might fail, so restart the timer to test again
|
|
|
|
m_releaseSelectionTimer.start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_finishing) {
|
|
|
|
// still shutting down, a restart might follow, so restart the timer to test again
|
|
|
|
m_releaseSelectionTimer.start();
|
|
|
|
return;
|
|
|
|
}
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Releasing compositor selection";
|
2015-02-23 17:57:00 +03:00
|
|
|
if (cm_selection) {
|
|
|
|
cm_selection->owning = false;
|
|
|
|
cm_selection->release();
|
|
|
|
}
|
2012-10-14 14:18:35 +04:00
|
|
|
}
|
|
|
|
|
2013-04-27 02:00:23 +04:00
|
|
|
void Compositor::keepSupportProperty(xcb_atom_t atom)
|
|
|
|
{
|
|
|
|
m_unusedSupportProperties.removeAll(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::removeSupportProperty(xcb_atom_t atom)
|
|
|
|
{
|
|
|
|
m_unusedSupportProperties << atom;
|
|
|
|
m_unusedSupportPropertyTimer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::deleteUnusedSupportProperties()
|
|
|
|
{
|
|
|
|
if (m_starting) {
|
|
|
|
// currently still starting the compositor
|
|
|
|
m_unusedSupportPropertyTimer.start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_finishing) {
|
|
|
|
// still shutting down, a restart might follow
|
|
|
|
m_unusedSupportPropertyTimer.start();
|
|
|
|
return;
|
|
|
|
}
|
2015-11-10 15:54:26 +03:00
|
|
|
if (kwinApp()->x11Connection()) {
|
|
|
|
foreach (const xcb_atom_t &atom, m_unusedSupportProperties) {
|
|
|
|
// remove property from root window
|
|
|
|
xcb_delete_property(connection(), rootWindow(), atom);
|
|
|
|
}
|
2013-04-27 02:00:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-25 13:02:08 +03:00
|
|
|
// OpenGL self-check failed, fallback to XRender
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::fallbackToXRenderCompositing()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-17 10:18:36 +04:00
|
|
|
finish();
|
2016-01-29 13:24:18 +03:00
|
|
|
KConfigGroup config(kwinApp()->config(), "Compositing");
|
2011-12-16 20:36:27 +04:00
|
|
|
config.writeEntry("Backend", "XRender");
|
|
|
|
config.sync();
|
2013-07-22 17:51:56 +04:00
|
|
|
options->setCompositingMode(XRenderCompositing);
|
|
|
|
setup();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-01-25 13:02:08 +03:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::slotConfigChanged()
|
|
|
|
{
|
2012-08-17 10:18:36 +04:00
|
|
|
if (!m_suspended) {
|
|
|
|
setup();
|
2011-08-21 23:50:23 +04:00
|
|
|
if (effects) // setupCompositing() may fail
|
|
|
|
effects->reconfigure();
|
|
|
|
addRepaintFull();
|
|
|
|
} else
|
2012-08-17 10:18:36 +04:00
|
|
|
finish();
|
2011-08-21 23:50:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::slotReinitialize()
|
|
|
|
{
|
2012-08-17 12:15:33 +04:00
|
|
|
// Reparse config. Config options will be reloaded by setup()
|
2016-01-29 13:24:18 +03:00
|
|
|
kwinApp()->config()->reparseConfiguration();
|
2012-08-17 12:15:33 +04:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
// Restart compositing
|
2012-08-17 10:18:36 +04:00
|
|
|
finish();
|
2011-08-21 23:50:23 +04:00
|
|
|
// resume compositing if suspended
|
2013-01-09 19:03:54 +04:00
|
|
|
m_suspended = NoReasonSuspend;
|
2011-08-21 23:50:23 +04:00
|
|
|
options->setCompositingInitialized(false);
|
2012-08-17 10:18:36 +04:00
|
|
|
setup();
|
2012-08-17 12:15:33 +04:00
|
|
|
|
|
|
|
if (effects) { // setup() may fail
|
|
|
|
effects->reconfigure();
|
|
|
|
}
|
2011-08-21 23:50:23 +04:00
|
|
|
}
|
|
|
|
|
2008-05-20 01:48:47 +04:00
|
|
|
// for the shortcut
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::slotToggleCompositing()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-06-25 12:39:13 +04:00
|
|
|
if (kwinApp()->requiresCompositing()) {
|
|
|
|
// we are not allowed to turn on/off compositing
|
|
|
|
return;
|
|
|
|
}
|
2013-01-09 19:03:54 +04:00
|
|
|
if (m_suspended) { // direct user call; clear all bits
|
|
|
|
resume(AllReasonSuspend);
|
|
|
|
} else { // but only set the user one (sufficient to suspend)
|
|
|
|
suspend(UserSuspend);
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-04-02 23:14:48 +04:00
|
|
|
|
2012-08-23 15:42:59 +04:00
|
|
|
void Compositor::updateCompositeBlocking()
|
|
|
|
{
|
|
|
|
updateCompositeBlocking(NULL);
|
|
|
|
}
|
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::updateCompositeBlocking(Client *c)
|
2011-03-20 17:42:05 +03:00
|
|
|
{
|
2013-06-25 12:39:13 +04:00
|
|
|
if (kwinApp()->requiresCompositing()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-20 17:42:05 +03:00
|
|
|
if (c) { // if c == 0 we just check if we can resume
|
|
|
|
if (c->isBlockingCompositing()) {
|
2013-01-09 19:03:54 +04:00
|
|
|
if (!(m_suspended & BlockRuleSuspend)) // do NOT attempt to call suspend(true); from within the eventchain!
|
|
|
|
QMetaObject::invokeMethod(this, "suspend", Qt::QueuedConnection, Q_ARG(Compositor::SuspendReason, BlockRuleSuspend));
|
2011-03-20 17:42:05 +03:00
|
|
|
}
|
|
|
|
}
|
2013-01-09 19:03:54 +04:00
|
|
|
else if (m_suspended & BlockRuleSuspend) { // lost a client and we're blocked - can we resume?
|
2011-03-20 17:42:05 +03:00
|
|
|
bool resume = true;
|
2012-08-16 19:10:47 +04:00
|
|
|
for (ClientList::ConstIterator it = Workspace::self()->clientList().constBegin(); it != Workspace::self()->clientList().constEnd(); ++it) {
|
2011-03-20 17:42:05 +03:00
|
|
|
if ((*it)->isBlockingCompositing()) {
|
|
|
|
resume = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-08-17 10:18:36 +04:00
|
|
|
if (resume) { // do NOT attempt to call suspend(false); from within the eventchain!
|
2013-01-09 19:03:54 +04:00
|
|
|
QMetaObject::invokeMethod(this, "resume", Qt::QueuedConnection, Q_ARG(Compositor::SuspendReason, BlockRuleSuspend));
|
2011-03-20 17:42:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 19:03:54 +04:00
|
|
|
void Compositor::suspend(Compositor::SuspendReason reason)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-06-25 12:39:13 +04:00
|
|
|
if (kwinApp()->requiresCompositing()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-09 19:03:54 +04:00
|
|
|
Q_ASSERT(reason != NoReasonSuspend);
|
|
|
|
m_suspended |= reason;
|
2014-06-02 10:51:28 +04:00
|
|
|
if (reason & KWin::Compositor::ScriptSuspend) {
|
|
|
|
// when disabled show a shortcut how the user can get back compositing
|
|
|
|
const auto shortcuts = KGlobalAccel::self()->shortcut(workspace()->findChild<QAction*>(QStringLiteral("Suspend Compositing")));
|
|
|
|
if (!shortcuts.isEmpty()) {
|
|
|
|
// display notification only if there is the shortcut
|
|
|
|
const QString message = i18n("Desktop effects have been suspended by another application.<br/>"
|
|
|
|
"You can resume using the '%1' shortcut.", shortcuts.first().toString(QKeySequence::NativeText));
|
|
|
|
KNotification::event(QStringLiteral("compositingsuspendeddbus"), message);
|
|
|
|
}
|
|
|
|
}
|
2012-08-17 10:18:36 +04:00
|
|
|
finish();
|
2012-09-01 11:10:56 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 19:03:54 +04:00
|
|
|
void Compositor::resume(Compositor::SuspendReason reason)
|
2012-09-01 11:10:56 +04:00
|
|
|
{
|
2013-01-09 19:03:54 +04:00
|
|
|
Q_ASSERT(reason != NoReasonSuspend);
|
|
|
|
m_suspended &= ~reason;
|
|
|
|
setup(); // signal "toggled" is eventually emitted from within setup
|
2012-09-01 11:10:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:18:36 +04:00
|
|
|
void Compositor::restart()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 23:19:54 +04:00
|
|
|
if (hasScene()) {
|
2012-08-17 10:18:36 +04:00
|
|
|
finish();
|
|
|
|
QTimer::singleShot(0, this, SLOT(setup()));
|
2009-02-11 17:29:32 +03:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2009-02-11 17:29:32 +03:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::addRepaint(int x, int y, int w, int h)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 23:19:54 +04:00
|
|
|
if (!hasScene())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
repaints_region += QRegion(x, y, w, h);
|
2012-08-23 15:42:59 +04:00
|
|
|
scheduleRepaint();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::addRepaint(const QRect& r)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 23:19:54 +04:00
|
|
|
if (!hasScene())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
|
|
|
repaints_region += r;
|
2012-08-23 15:42:59 +04:00
|
|
|
scheduleRepaint();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::addRepaint(const QRegion& r)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 23:19:54 +04:00
|
|
|
if (!hasScene())
|
2008-06-19 18:16:21 +04:00
|
|
|
return;
|
|
|
|
repaints_region += r;
|
2012-08-23 15:42:59 +04:00
|
|
|
scheduleRepaint();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::addRepaintFull()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 23:19:54 +04:00
|
|
|
if (!hasScene())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2014-11-25 10:40:23 +03:00
|
|
|
const QSize &s = screens()->size();
|
|
|
|
repaints_region = QRegion(0, 0, s.width(), s.height());
|
2012-08-23 15:42:59 +04:00
|
|
|
scheduleRepaint();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::timerEvent(QTimerEvent *te)
|
2010-12-18 19:51:43 +03:00
|
|
|
{
|
2011-02-01 18:35:51 +03:00
|
|
|
if (te->timerId() == compositeTimer.timerId()) {
|
2010-12-18 19:51:43 +03:00
|
|
|
performCompositing();
|
2011-01-30 17:34:42 +03:00
|
|
|
} else
|
|
|
|
QObject::timerEvent(te);
|
2010-12-18 19:51:43 +03:00
|
|
|
}
|
2012-07-18 03:50:43 +04:00
|
|
|
|
2014-08-27 20:24:43 +04:00
|
|
|
void Compositor::aboutToSwapBuffers()
|
2013-06-19 13:12:57 +04:00
|
|
|
{
|
2014-08-27 20:24:43 +04:00
|
|
|
assert(!m_bufferSwapPending);
|
|
|
|
|
|
|
|
m_bufferSwapPending = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::bufferSwapComplete()
|
|
|
|
{
|
|
|
|
assert(m_bufferSwapPending);
|
|
|
|
m_bufferSwapPending = false;
|
|
|
|
|
|
|
|
if (m_composeAtSwapCompletion) {
|
|
|
|
m_composeAtSwapCompletion = false;
|
|
|
|
performCompositing();
|
2013-06-19 13:12:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::performCompositing()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-06-19 14:26:34 +04:00
|
|
|
if (m_scene->usesOverlayWindow() && !isOverlayWindowVisible())
|
2012-03-30 00:11:28 +04:00
|
|
|
return; // nothing is visible anyway
|
2014-08-27 20:24:43 +04:00
|
|
|
|
|
|
|
// If a buffer swap is still pending, we return to the event loop and
|
|
|
|
// continue processing events until the swap has completed.
|
|
|
|
if (m_bufferSwapPending) {
|
|
|
|
m_composeAtSwapCompletion = true;
|
|
|
|
compositeTimer.stop();
|
|
|
|
return;
|
2013-06-19 13:12:57 +04:00
|
|
|
}
|
2012-03-30 00:11:28 +04:00
|
|
|
|
2015-08-31 14:54:50 +03:00
|
|
|
// If outputs are disabled, we return to the event loop and
|
|
|
|
// continue processing events until the outputs are enabled again
|
|
|
|
if (waylandServer() && !waylandServer()->backend()->areOutputsEnabled()) {
|
|
|
|
compositeTimer.stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-28 22:29:33 +04:00
|
|
|
// Create a list of all windows in the stacking order
|
|
|
|
ToplevelList windows = Workspace::self()->xStackingOrder();
|
|
|
|
ToplevelList damaged;
|
|
|
|
|
|
|
|
// Reset the damage state of each window and fetch the damage region
|
|
|
|
// without waiting for a reply
|
|
|
|
foreach (Toplevel *win, windows) {
|
|
|
|
if (win->resetAndFetchDamage())
|
|
|
|
damaged << win;
|
|
|
|
}
|
|
|
|
|
2014-09-03 20:43:38 +04:00
|
|
|
if (damaged.count() > 0) {
|
|
|
|
m_scene->triggerFence();
|
2012-03-28 22:29:33 +04:00
|
|
|
xcb_flush(connection());
|
2014-09-03 20:43:38 +04:00
|
|
|
}
|
2012-03-28 22:29:33 +04:00
|
|
|
|
|
|
|
// Move elevated windows to the top of the stacking order
|
|
|
|
foreach (EffectWindow *c, static_cast<EffectsHandlerImpl *>(effects)->elevatedWindows()) {
|
|
|
|
Toplevel* t = static_cast< EffectWindowImpl* >(c)->window();
|
|
|
|
windows.removeAll(t);
|
|
|
|
windows.append(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the replies
|
|
|
|
foreach (Toplevel *win, damaged) {
|
|
|
|
// Discard the cached lanczos texture
|
|
|
|
if (win->effectWindow()) {
|
|
|
|
const QVariant texture = win->effectWindow()->data(LanczosCacheRole);
|
|
|
|
if (texture.isValid()) {
|
|
|
|
delete static_cast<GLTexture *>(texture.value<void*>());
|
|
|
|
win->effectWindow()->setData(LanczosCacheRole, QVariant());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
win->getDamageRegionReply();
|
|
|
|
}
|
|
|
|
|
2013-02-19 02:17:46 +04:00
|
|
|
if (repaints_region.isEmpty() && !windowRepaintsPending()) {
|
2012-08-16 23:19:54 +04:00
|
|
|
m_scene->idle();
|
2013-08-30 03:30:13 +04:00
|
|
|
m_timeSinceLastVBlank = fpsInterval - (options->vBlankTime() + 1); // means "start now"
|
2015-02-24 13:50:01 +03:00
|
|
|
m_timeSinceStart += m_timeSinceLastVBlank;
|
2008-08-24 17:32:57 +04: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.
|
2013-08-30 03:30:13 +04:00
|
|
|
compositeTimer.stop();
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-08-23 18:51:40 +04:00
|
|
|
|
2015-11-16 13:46:20 +03:00
|
|
|
// skip windows that are not yet ready for being painted and if screen is locked skip windows that are
|
|
|
|
// neither lockscreen nor inputmethod windows
|
2011-08-13 18:39:58 +04:00
|
|
|
// TODO ?
|
2008-06-29 17:11:01 +04:00
|
|
|
// this cannot be used so carelessly - needs protections against broken clients, the window
|
2008-08-24 17:32:57 +04:00
|
|
|
// should not get focus before it's displayed, handle unredirected windows properly and so on.
|
2015-11-16 13:46:20 +03:00
|
|
|
foreach (Toplevel *t, windows) {
|
|
|
|
if (!t->readyForPainting()) {
|
2011-08-13 18:39:58 +04:00
|
|
|
windows.removeAll(t);
|
2015-11-16 13:46:20 +03:00
|
|
|
}
|
|
|
|
if (waylandServer() && waylandServer()->isScreenLocked()) {
|
|
|
|
if(!t->isLockScreen() && !t->isInputMethod()) {
|
|
|
|
windows.removeAll(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-13 18:39:58 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
QRegion repaints = repaints_region;
|
|
|
|
// clear all repaints, so that post-pass can add repaints for the next repaint
|
|
|
|
repaints_region = QRegion();
|
2012-03-30 00:11:28 +04:00
|
|
|
|
2012-08-16 23:19:54 +04:00
|
|
|
m_timeSinceLastVBlank = m_scene->paint(repaints, windows);
|
2015-02-24 13:50:01 +03:00
|
|
|
m_timeSinceStart += m_timeSinceLastVBlank;
|
|
|
|
|
|
|
|
if (kwinApp()->shouldUseWaylandForCompositing()) {
|
|
|
|
for (Toplevel *win : damaged) {
|
|
|
|
if (auto surface = win->surface()) {
|
|
|
|
surface->frameRendered(m_timeSinceStart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-28 22:29:33 +04:00
|
|
|
|
2013-08-30 03:30:13 +04:00
|
|
|
compositeTimer.stop(); // stop here to ensure *we* cause the next repaint schedule - not some effect through m_scene->paint()
|
|
|
|
|
2008-08-30 19:28:47 +04: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
|
2012-03-28 22:29:33 +04:00
|
|
|
// scheduleRepaint() would restart it again somewhen later, called from functions that
|
2008-08-30 19:28:47 +04:00
|
|
|
// would again add something pending.
|
2014-12-13 16:26:23 +03:00
|
|
|
if (m_bufferSwapPending && m_scene->syncsToVBlank()) {
|
|
|
|
m_composeAtSwapCompletion = true;
|
|
|
|
} else {
|
|
|
|
scheduleRepaint();
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
bool Compositor::windowRepaintsPending() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 19:10:47 +04:00
|
|
|
foreach (Toplevel * c, Workspace::self()->clientList())
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!c->repaints().isEmpty())
|
|
|
|
return true;
|
2012-08-16 19:10:47 +04:00
|
|
|
foreach (Toplevel * c, Workspace::self()->desktopList())
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!c->repaints().isEmpty())
|
|
|
|
return true;
|
2012-08-16 19:10:47 +04:00
|
|
|
foreach (Toplevel * c, Workspace::self()->unmanagedList())
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!c->repaints().isEmpty())
|
|
|
|
return true;
|
2012-08-16 19:10:47 +04:00
|
|
|
foreach (Toplevel * c, Workspace::self()->deletedList())
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!c->repaints().isEmpty())
|
|
|
|
return true;
|
2015-03-04 11:21:10 +03:00
|
|
|
if (auto w = waylandServer()) {
|
|
|
|
const auto &clients = w->clients();
|
|
|
|
for (auto c : clients) {
|
2015-07-17 21:39:57 +03:00
|
|
|
if (c->isShown(true) && !c->repaints().isEmpty()) {
|
2015-03-04 11:21:10 +03:00
|
|
|
return true;
|
2015-06-06 18:36:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto &internalClients = w->internalClients();
|
|
|
|
for (auto c : internalClients) {
|
2015-07-17 21:39:57 +03:00
|
|
|
if (c->isShown(true) && !c->repaints().isEmpty()) {
|
2015-06-06 18:36:04 +03:00
|
|
|
return true;
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::setCompositeResetTimer(int msecs)
|
|
|
|
{
|
|
|
|
compositeResetTimer.start(msecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::setCompositeTimer()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-16 23:19:54 +04:00
|
|
|
if (!hasScene()) // should not really happen, but there may be e.g. some damage events still pending
|
2008-08-30 19:28:47 +04:00
|
|
|
return;
|
2015-10-20 12:41:04 +03:00
|
|
|
if (m_starting || !Workspace::self()) {
|
2015-03-18 18:27:22 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
|
2014-08-27 20:24:43 +04:00
|
|
|
// Don't start the timer if we're waiting for a swap event
|
|
|
|
if (m_bufferSwapPending && m_composeAtSwapCompletion)
|
|
|
|
return;
|
|
|
|
|
2015-08-31 14:54:50 +03:00
|
|
|
// Don't start the timer if all outputs are disabled
|
|
|
|
if (waylandServer() && !waylandServer()->backend()->areOutputsEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-29 00:53:25 +04:00
|
|
|
uint waitTime = 1;
|
2012-03-30 00:11:28 +04:00
|
|
|
|
2013-03-29 00:52:26 +04:00
|
|
|
if (m_scene->blocksForRetrace()) {
|
2012-03-30 00:11:28 +04:00
|
|
|
|
|
|
|
// TODO: make vBlankTime dynamic?!
|
|
|
|
// It's required because glXWaitVideoSync will *likely* block a full frame if one enters
|
|
|
|
// a retrace pass which can last a variable amount of time, depending on the actual screen
|
|
|
|
// Now, my ooold 19" CRT can do such retrace so that 2ms are entirely sufficient,
|
|
|
|
// while another ooold 15" TFT requires about 6ms
|
|
|
|
|
2013-03-29 00:53:25 +04:00
|
|
|
qint64 padding = m_timeSinceLastVBlank;
|
2012-03-30 00:11:28 +04:00
|
|
|
if (padding > fpsInterval) {
|
|
|
|
// we're at low repaints or spent more time in painting than the user wanted to wait for that frame
|
|
|
|
padding = vBlankInterval - (padding%vBlankInterval); // -> align to next vblank
|
|
|
|
} else { // -> align to the next maxFps tick
|
|
|
|
padding = ((vBlankInterval - padding%vBlankInterval) + (fpsInterval/vBlankInterval-1)*vBlankInterval);
|
|
|
|
// "remaining time of the first vsync" + "time for the other vsyncs of the frame"
|
2010-12-31 16:14:11 +03:00
|
|
|
}
|
2011-02-01 18:35:51 +03:00
|
|
|
|
2012-03-30 00:11:28 +04:00
|
|
|
if (padding < options->vBlankTime()) { // we'll likely miss this frame
|
2013-03-29 00:53:25 +04:00
|
|
|
waitTime = nanoToMilli(padding + vBlankInterval - options->vBlankTime()); // so we add one
|
2012-03-30 00:11:28 +04:00
|
|
|
} else {
|
2013-03-29 00:53:25 +04:00
|
|
|
waitTime = nanoToMilli(padding - options->vBlankTime());
|
2012-03-30 00:11:28 +04:00
|
|
|
}
|
|
|
|
}
|
2013-08-30 03:30:13 +04:00
|
|
|
else { // w/o blocking vsync we just jump to the next demanded tick
|
|
|
|
if (fpsInterval > m_timeSinceLastVBlank) {
|
|
|
|
waitTime = nanoToMilli(fpsInterval - m_timeSinceLastVBlank);
|
|
|
|
if (!waitTime) {
|
|
|
|
waitTime = 1; // will ensure we don't block out the eventloop - the system's just not faster ...
|
|
|
|
}
|
|
|
|
}/* else if (m_scene->syncsToVBlank() && m_timeSinceLastVBlank - fpsInterval < (vBlankInterval<<1)) {
|
|
|
|
// NOTICE - "for later" ------------------------------------------------------------------
|
|
|
|
// It can happen that we push two frames within one refresh cycle.
|
|
|
|
// Swapping will then block even with triple buffering when the GPU does not discard but
|
|
|
|
// queues frames
|
|
|
|
// now here's the mean part: if we take that as "OMG, we're late - next frame ASAP",
|
|
|
|
// there'll immediately be 2 frames in the pipe, swapping will block, we think we're
|
|
|
|
// late ... ewww
|
|
|
|
// so instead we pad to the clock again and add 2ms safety to ensure the pipe is really
|
|
|
|
// free
|
|
|
|
// NOTICE: obviously m_timeSinceLastVBlank can be too big because we're too slow as well
|
|
|
|
// So if this code was enabled, we'd needlessly half the framerate once more (15 instead of 30)
|
|
|
|
waitTime = nanoToMilli(vBlankInterval - (m_timeSinceLastVBlank - fpsInterval)%vBlankInterval) + 2;
|
|
|
|
}*/ else {
|
|
|
|
waitTime = 1; // ... "0" would be sufficient, but the compositor isn't the WMs only task
|
|
|
|
}
|
|
|
|
}
|
2013-03-29 00:53:25 +04:00
|
|
|
compositeTimer.start(qMin(waitTime, 250u), this); // force 4fps minimum
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-30 19:28:47 +04:00
|
|
|
|
2012-08-17 10:18:36 +04:00
|
|
|
bool Compositor::isActive()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-08-17 10:18:36 +04:00
|
|
|
return !m_finishing && hasScene();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-15 15:09:07 +04:00
|
|
|
|
2012-08-23 15:42:59 +04:00
|
|
|
void Compositor::checkUnredirect()
|
|
|
|
{
|
|
|
|
checkUnredirect(false);
|
|
|
|
}
|
|
|
|
|
2008-08-24 17:32:57 +04:00
|
|
|
// force is needed when the list of windows changes (e.g. a window goes away)
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::checkUnredirect(bool force)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-06-19 14:26:34 +04:00
|
|
|
if (!hasScene() || !m_scene->overlayWindow() || m_scene->overlayWindow()->window() == None || !options->isUnredirectFullscreen())
|
2008-08-24 17:32:57 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (force)
|
2008-08-24 17:32:57 +04:00
|
|
|
forceUnredirectCheck = true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!unredirectTimer.isActive())
|
|
|
|
unredirectTimer.start(0);
|
|
|
|
}
|
2008-08-24 17:32:57 +04:00
|
|
|
|
2011-08-21 23:50:23 +04:00
|
|
|
void Compositor::delayedCheckUnredirect()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-06-19 14:26:34 +04:00
|
|
|
if (!hasScene() || !m_scene->overlayWindow() || m_scene->overlayWindow()->window() == None || !(options->isUnredirectFullscreen() || sender() == options))
|
2008-08-25 23:49:42 +04:00
|
|
|
return;
|
2008-08-24 17:32:57 +04:00
|
|
|
ToplevelList list;
|
|
|
|
bool changed = forceUnredirectCheck;
|
2012-08-16 19:10:47 +04:00
|
|
|
foreach (Client * c, Workspace::self()->clientList())
|
2015-08-28 23:58:31 +03:00
|
|
|
list.append(c);
|
2012-08-16 19:10:47 +04:00
|
|
|
foreach (Unmanaged * c, Workspace::self()->unmanagedList())
|
2015-08-28 23:58:31 +03:00
|
|
|
list.append(c);
|
2011-01-30 17:34:42 +03:00
|
|
|
foreach (Toplevel * c, list) {
|
2015-08-28 23:58:31 +03:00
|
|
|
if (c->updateUnredirectedState()) {
|
2008-08-24 17:32:57 +04:00
|
|
|
changed = true;
|
2015-08-28 23:58:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-24 17:32:57 +04:00
|
|
|
// no desktops, no Deleted ones
|
2011-01-30 17:34:42 +03:00
|
|
|
if (!changed)
|
2008-08-24 17:32:57 +04:00
|
|
|
return;
|
|
|
|
forceUnredirectCheck = false;
|
|
|
|
// Cut out parts from the overlay window where unredirected windows are,
|
|
|
|
// so that they are actually visible.
|
2014-11-25 10:40:23 +03:00
|
|
|
const QSize &s = screens()->size();
|
|
|
|
QRegion reg(0, 0, s.width(), s.height());
|
2011-01-30 17:34:42 +03:00
|
|
|
foreach (Toplevel * c, list) {
|
|
|
|
if (c->unredirected())
|
2008-08-24 17:32:57 +04:00
|
|
|
reg -= c->geometry();
|
|
|
|
}
|
2012-08-16 23:19:54 +04:00
|
|
|
m_scene->overlayWindow()->setShape(reg);
|
2015-08-28 23:58:31 +03:00
|
|
|
addRepaint(reg);
|
2012-08-16 23:19:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Compositor::checkForOverlayWindow(WId w) const
|
|
|
|
{
|
|
|
|
if (!hasScene()) {
|
|
|
|
// no scene, so it cannot be the overlay window
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!m_scene->overlayWindow()) {
|
|
|
|
// no overlay window, it cannot be the overlay
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// and compare the window ID's
|
|
|
|
return w == m_scene->overlayWindow()->window();
|
|
|
|
}
|
|
|
|
|
|
|
|
WId Compositor::overlayWindow() const
|
|
|
|
{
|
|
|
|
if (!hasScene()) {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
if (!m_scene->overlayWindow()) {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
return m_scene->overlayWindow()->window();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compositor::isOverlayWindowVisible() const
|
|
|
|
{
|
|
|
|
if (!hasScene()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!m_scene->overlayWindow()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return m_scene->overlayWindow()->isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::setOverlayWindowVisibility(bool visible)
|
|
|
|
{
|
|
|
|
if (hasScene() && m_scene->overlayWindow()) {
|
|
|
|
m_scene->overlayWindow()->setVisibility(visible);
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-24 17:32:57 +04:00
|
|
|
|
2012-08-30 10:20:26 +04:00
|
|
|
/*****************************************************
|
|
|
|
* Workspace
|
|
|
|
****************************************************/
|
|
|
|
|
2012-08-16 23:19:54 +04:00
|
|
|
bool Workspace::compositing() const
|
|
|
|
{
|
|
|
|
return m_compositor && m_compositor->hasScene();
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
//****************************************
|
|
|
|
// Toplevel
|
|
|
|
//****************************************
|
|
|
|
|
2012-04-28 11:39:39 +04:00
|
|
|
bool Toplevel::setupCompositing()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!compositing())
|
2012-04-28 11:39:39 +04:00
|
|
|
return false;
|
2012-03-28 22:29:33 +04:00
|
|
|
|
2013-04-26 13:12:52 +04:00
|
|
|
if (damage_handle != XCB_NONE)
|
2012-04-28 11:39:39 +04:00
|
|
|
return false;
|
2012-03-28 22:29:33 +04:00
|
|
|
|
2015-02-24 12:54:28 +03:00
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
|
|
|
damage_handle = xcb_generate_id(connection());
|
|
|
|
xcb_damage_create(connection(), damage_handle, frameId(), XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY);
|
|
|
|
}
|
2012-03-28 22:29:33 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
damage_region = QRegion(0, 0, width(), height());
|
2011-12-29 13:31:37 +04:00
|
|
|
effect_window = new EffectWindowImpl(this);
|
2008-08-24 17:32:57 +04:00
|
|
|
unredirect = false;
|
2012-03-28 22:29:33 +04:00
|
|
|
|
2012-08-28 21:31:17 +04:00
|
|
|
Compositor::self()->checkUnredirect(true);
|
|
|
|
Compositor::self()->scene()->windowAdded(this);
|
2012-03-28 22:29:33 +04:00
|
|
|
|
|
|
|
// With unmanaged windows there is a race condition between the client painting the window
|
|
|
|
// and us setting up damage tracking. If the client wins we won't get a damage event even
|
|
|
|
// though the window has been painted. To avoid this we mark the whole window as damaged
|
|
|
|
// and schedule a repaint immediately after creating the damage object.
|
|
|
|
if (dynamic_cast<Unmanaged*>(this))
|
|
|
|
addDamageFull();
|
|
|
|
|
2012-04-28 11:39:39 +04:00
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2014-04-07 18:23:17 +04:00
|
|
|
void Toplevel::finishCompositing(ReleaseReason releaseReason)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2015-02-24 12:54:28 +03:00
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11 && damage_handle == XCB_NONE)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2012-08-28 21:31:17 +04:00
|
|
|
Compositor::self()->checkUnredirect(true);
|
2011-01-30 17:34:42 +03:00
|
|
|
if (effect_window->window() == this) { // otherwise it's already passed to Deleted, don't free data
|
2007-04-29 21:35:43 +04:00
|
|
|
discardWindowPixmap();
|
|
|
|
delete effect_window;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-03-28 22:29:33 +04:00
|
|
|
|
2015-02-24 12:54:28 +03:00
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11 &&
|
|
|
|
releaseReason != ReleaseReason::Destroyed) {
|
2014-04-07 18:23:17 +04:00
|
|
|
xcb_damage_destroy(connection(), damage_handle);
|
|
|
|
}
|
2012-03-28 22:29:33 +04:00
|
|
|
|
|
|
|
damage_handle = XCB_NONE;
|
2007-04-29 21:35:43 +04:00
|
|
|
damage_region = QRegion();
|
|
|
|
repaints_region = QRegion();
|
|
|
|
effect_window = NULL;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Toplevel::discardWindowPixmap()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
addDamageFull();
|
2011-01-30 17:34:42 +03:00
|
|
|
if (effectWindow() != NULL && effectWindow()->sceneWindow() != NULL)
|
2007-07-05 23:59:55 +04:00
|
|
|
effectWindow()->sceneWindow()->pixmapDiscarded();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-04-26 13:00:08 +04:00
|
|
|
void Toplevel::damageNotifyEvent()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-03-28 22:29:33 +04:00
|
|
|
m_isDamaged = true;
|
2011-07-09 03:26:58 +04:00
|
|
|
|
2012-03-28 22:29:33 +04:00
|
|
|
// Note: The rect is supposed to specify the damage extents,
|
2012-12-29 10:54:12 +04:00
|
|
|
// but we don't know it at this point. No one who connects
|
2012-03-28 22:29:33 +04:00
|
|
|
// to this signal uses the rect however.
|
|
|
|
emit damaged(this, QRect());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-06-25 12:51:44 +04:00
|
|
|
|
2012-08-16 23:19:54 +04:00
|
|
|
bool Toplevel::compositing() const
|
|
|
|
{
|
2013-01-10 13:10:35 +04:00
|
|
|
return Workspace::self()->compositing();
|
2012-08-16 23:19:54 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 13:00:08 +04:00
|
|
|
void Client::damageNotifyEvent()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-03-28 22:29:33 +04:00
|
|
|
if (syncRequest.isPending && isResize()) {
|
|
|
|
emit damaged(this, QRect());
|
|
|
|
m_isDamaged = true;
|
2011-08-13 18:39:58 +04:00
|
|
|
return;
|
2012-03-28 22:29:33 +04:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:00:40 +04:00
|
|
|
if (!ready_for_painting) { // avoid "setReadyForPainting()" function calling overhead
|
2015-07-09 10:10:33 +03:00
|
|
|
if (syncRequest.counter == XCB_NONE) { // cannot detect complete redraw, consider done now
|
2012-01-24 20:00:40 +04:00
|
|
|
setReadyForPainting();
|
2015-07-09 10:10:33 +03:00
|
|
|
setupWindowManagementInterface();
|
|
|
|
}
|
2012-02-26 12:42:17 +04:00
|
|
|
}
|
2011-08-13 18:39:58 +04:00
|
|
|
|
2013-04-26 13:00:08 +04:00
|
|
|
Toplevel::damageNotifyEvent();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-03-28 22:29:33 +04:00
|
|
|
bool Toplevel::resetAndFetchDamage()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-03-28 22:29:33 +04:00
|
|
|
if (!m_isDamaged)
|
|
|
|
return false;
|
|
|
|
|
2015-02-24 12:54:28 +03:00
|
|
|
if (kwinApp()->operationMode() != Application::OperationModeX11) {
|
|
|
|
m_isDamaged = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-28 22:29:33 +04:00
|
|
|
xcb_connection_t *conn = connection();
|
|
|
|
|
|
|
|
// Create a new region and copy the damage region to it,
|
|
|
|
// resetting the damaged state.
|
|
|
|
xcb_xfixes_region_t region = xcb_generate_id(conn);
|
|
|
|
xcb_xfixes_create_region(conn, region, 0, 0);
|
|
|
|
xcb_damage_subtract(conn, damage_handle, 0, region);
|
|
|
|
|
|
|
|
// Send a fetch-region request and destroy the region
|
|
|
|
m_regionCookie = xcb_xfixes_fetch_region_unchecked(conn, region);
|
|
|
|
xcb_xfixes_destroy_region(conn, region);
|
|
|
|
|
|
|
|
m_isDamaged = false;
|
|
|
|
m_damageReplyPending = true;
|
|
|
|
|
|
|
|
return m_damageReplyPending;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-03-28 22:29:33 +04:00
|
|
|
void Toplevel::getDamageRegionReply()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-03-28 22:29:33 +04:00
|
|
|
if (!m_damageReplyPending)
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2012-03-28 22:29:33 +04:00
|
|
|
|
|
|
|
m_damageReplyPending = false;
|
|
|
|
|
|
|
|
// Get the fetch-region reply
|
|
|
|
xcb_xfixes_fetch_region_reply_t *reply =
|
|
|
|
xcb_xfixes_fetch_region_reply(connection(), m_regionCookie, 0);
|
|
|
|
|
|
|
|
if (!reply)
|
2011-11-08 23:53:17 +04:00
|
|
|
return;
|
2012-03-28 22:29:33 +04:00
|
|
|
|
|
|
|
// Convert the reply to a QRegion
|
|
|
|
int count = xcb_xfixes_fetch_region_rectangles_length(reply);
|
|
|
|
QRegion region;
|
|
|
|
|
|
|
|
if (count > 1 && count < 16) {
|
|
|
|
xcb_rectangle_t *rects = xcb_xfixes_fetch_region_rectangles(reply);
|
|
|
|
|
|
|
|
QVector<QRect> qrects;
|
|
|
|
qrects.reserve(count);
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
qrects << QRect(rects[i].x, rects[i].y, rects[i].width, rects[i].height);
|
|
|
|
|
|
|
|
region.setRects(qrects.constData(), count);
|
|
|
|
} else
|
|
|
|
region += QRect(reply->extents.x, reply->extents.y,
|
|
|
|
reply->extents.width, reply->extents.height);
|
|
|
|
|
|
|
|
damage_region += region;
|
|
|
|
repaints_region += region;
|
|
|
|
|
|
|
|
free(reply);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void Toplevel::addDamageFull()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2012-03-28 22:29:33 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
damage_region = rect();
|
2013-09-12 01:27:30 +04:00
|
|
|
repaints_region |= rect();
|
2012-03-28 22:29:33 +04:00
|
|
|
|
2011-03-12 17:04:22 +03:00
|
|
|
emit damaged(this, rect());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2013-05-15 15:07:10 +04:00
|
|
|
void Toplevel::resetDamage()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-05-15 15:07:10 +04:00
|
|
|
damage_region = QRegion();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Toplevel::addRepaint(const QRect& r)
|
|
|
|
{
|
2012-02-07 20:01:41 +04:00
|
|
|
if (!compositing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
repaints_region += r;
|
2012-08-23 15:42:59 +04:00
|
|
|
emit needsRepaint();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Toplevel::addRepaint(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
QRect r(x, y, w, h);
|
2012-02-07 20:01:41 +04:00
|
|
|
addRepaint(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toplevel::addRepaint(const QRegion& r)
|
|
|
|
{
|
|
|
|
if (!compositing()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
repaints_region += r;
|
2012-08-23 15:42:59 +04:00
|
|
|
emit needsRepaint();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-02-07 20:01:41 +04:00
|
|
|
void Toplevel::addLayerRepaint(const QRect& r)
|
|
|
|
{
|
|
|
|
if (!compositing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
layer_repaints_region += r;
|
2012-08-23 15:42:59 +04:00
|
|
|
emit needsRepaint();
|
2012-02-07 20:01:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 12:27:11 +04:00
|
|
|
{
|
|
|
|
if (!compositing())
|
|
|
|
return;
|
2012-02-07 20:01:41 +04:00
|
|
|
layer_repaints_region += r;
|
2012-08-23 15:42:59 +04:00
|
|
|
emit needsRepaint();
|
2011-07-15 12:27:11 +04:00
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
void Toplevel::addRepaintFull()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-03-10 14:34:56 +04:00
|
|
|
repaints_region = visibleRect().translated(-pos());
|
2012-08-23 15:42:59 +04:00
|
|
|
emit needsRepaint();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2012-02-07 20:01:41 +04:00
|
|
|
void Toplevel::resetRepaints()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-02-07 20:01:41 +04:00
|
|
|
repaints_region = QRegion();
|
|
|
|
layer_repaints_region = QRegion();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Toplevel::addWorkspaceRepaint(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
addWorkspaceRepaint(QRect(x, y, w, h));
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Toplevel::addWorkspaceRepaint(const QRect& r2)
|
|
|
|
{
|
|
|
|
if (!compositing())
|
2007-04-29 21:35:43 +04:00
|
|
|
return;
|
2012-08-28 21:31:17 +04:00
|
|
|
Compositor::self()->addRepaint(r2);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2008-08-24 17:32:57 +04:00
|
|
|
bool Toplevel::updateUnredirectedState()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
assert(compositing());
|
2013-08-04 00:13:14 +04:00
|
|
|
bool should = options->isUnredirectFullscreen() && shouldUnredirect() && !unredirectSuspend &&
|
|
|
|
!shape() && !hasAlpha() && opacity() == 1.0 &&
|
2011-01-30 17:34:42 +03:00
|
|
|
!static_cast<EffectsHandlerImpl*>(effects)->activeFullScreenEffect();
|
2013-03-30 04:11:51 +04:00
|
|
|
if (should == unredirect)
|
|
|
|
return false;
|
|
|
|
static QElapsedTimer lastUnredirect;
|
|
|
|
static const qint64 msecRedirectInterval = 100;
|
|
|
|
if (!lastUnredirect.hasExpired(msecRedirectInterval)) {
|
|
|
|
QTimer::singleShot(msecRedirectInterval, Compositor::self(), SLOT(checkUnredirect()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
lastUnredirect.start();
|
|
|
|
unredirect = should;
|
|
|
|
if (unredirect) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Unredirecting:" << this;
|
2012-12-12 01:49:16 +04:00
|
|
|
xcb_composite_unredirect_window(connection(), frameId(), XCB_COMPOSITE_REDIRECT_MANUAL);
|
2013-03-30 04:11:51 +04:00
|
|
|
} else {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Redirecting:" << this;
|
2012-12-12 01:49:16 +04:00
|
|
|
xcb_composite_redirect_window(connection(), frameId(), XCB_COMPOSITE_REDIRECT_MANUAL);
|
2008-08-24 17:32:57 +04:00
|
|
|
discardWindowPixmap();
|
|
|
|
}
|
2013-03-30 04:11:51 +04:00
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-24 17:32:57 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void Toplevel::suspendUnredirect(bool suspend)
|
|
|
|
{
|
|
|
|
if (unredirectSuspend == suspend)
|
2008-09-23 18:51:21 +04:00
|
|
|
return;
|
2008-08-24 17:32:57 +04:00
|
|
|
unredirectSuspend = suspend;
|
2012-08-28 21:31:17 +04:00
|
|
|
Compositor::self()->checkUnredirect();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-24 17:32:57 +04:00
|
|
|
|
2008-08-12 15:02:58 +04:00
|
|
|
//****************************************
|
|
|
|
// Client
|
|
|
|
//****************************************
|
|
|
|
|
2012-04-28 11:39:39 +04:00
|
|
|
bool Client::setupCompositing()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2012-04-28 11:39:39 +04:00
|
|
|
if (!Toplevel::setupCompositing()){
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-21 09:46:44 +04:00
|
|
|
if (isDecorated()) {
|
2014-07-25 09:14:21 +04:00
|
|
|
decoratedClient()->destroyRenderer();
|
2012-04-27 18:25:06 +04:00
|
|
|
}
|
2008-08-12 15:02:58 +04:00
|
|
|
updateVisibility(); // for internalKeep()
|
2012-04-28 11:39:39 +04:00
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-12 15:02:58 +04:00
|
|
|
|
2014-04-07 18:23:17 +04:00
|
|
|
void Client::finishCompositing(ReleaseReason releaseReason)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2014-04-07 18:23:17 +04:00
|
|
|
Toplevel::finishCompositing(releaseReason);
|
2008-08-12 15:02:58 +04:00
|
|
|
updateVisibility();
|
2012-04-13 19:46:17 +04:00
|
|
|
if (!deleting) {
|
2014-10-21 09:46:44 +04:00
|
|
|
if (isDecorated()) {
|
2014-07-25 09:14:21 +04:00
|
|
|
decoratedClient()->destroyRenderer();
|
|
|
|
}
|
2012-04-13 19:46:17 +04:00
|
|
|
}
|
2011-12-09 23:44:06 +04:00
|
|
|
// for safety in case KWin is just resizing the window
|
2015-10-22 18:08:17 +03:00
|
|
|
resetHaveResizeEffect();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-12 15:02:58 +04:00
|
|
|
|
2008-08-24 17:32:57 +04:00
|
|
|
bool Client::shouldUnredirect() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (isActiveFullScreen()) {
|
2008-08-24 17:32:57 +04:00
|
|
|
ToplevelList stacking = workspace()->xStackingOrder();
|
2011-01-30 17:34:42 +03: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 17:32:57 +04:00
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (c->geometry().intersects(geometry()))
|
2008-08-24 17:32:57 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
abort();
|
2008-08-24 17:32:57 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return false;
|
|
|
|
}
|
2008-08-24 17:32:57 +04:00
|
|
|
|
2009-07-29 15:48:55 +04:00
|
|
|
|
2008-08-24 17:32:57 +04:00
|
|
|
//****************************************
|
|
|
|
// Unmanaged
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
bool Unmanaged::shouldUnredirect() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2008-10-14 14:34:35 +04: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 18:17:21 +04:00
|
|
|
if (resourceClass() == "ksplashx"
|
|
|
|
|| resourceClass() == "ksplashsimple"
|
|
|
|
|| resourceClass() == "ksplashqml"
|
|
|
|
)
|
2008-10-14 14:34:35 +04:00
|
|
|
return false;
|
2008-08-24 17:32:57 +04:00
|
|
|
// it must cover whole display or one xinerama screen, and be the topmost there
|
2012-11-16 11:23:47 +04:00
|
|
|
const int desktop = VirtualDesktopManager::self()->current();
|
|
|
|
if (geometry() == workspace()->clientArea(FullArea, geometry().center(), desktop)
|
|
|
|
|| geometry() == workspace()->clientArea(ScreenArea, geometry().center(), desktop)) {
|
2008-08-24 17:32:57 +04:00
|
|
|
ToplevelList stacking = workspace()->xStackingOrder();
|
2011-01-30 17:34:42 +03: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 17:32:57 +04:00
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (c->geometry().intersects(geometry()))
|
2008-08-24 17:32:57 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
abort();
|
2008-08-24 17:32:57 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
return false;
|
|
|
|
}
|
2008-08-24 17:32:57 +04:00
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Deleted
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
bool Deleted::shouldUnredirect() const
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2008-08-24 17:32:57 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-08-24 17:32:57 +04:00
|
|
|
|
2009-07-29 15:07:28 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
} // namespace
|