2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2012-08-30 06:20:26 +00:00
|
|
|
#include "composite.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2014-06-02 06:51:28 +00:00
|
|
|
#include "dbusinterface.h"
|
2019-09-24 08:48:08 +00:00
|
|
|
#include "x11client.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "decorations/decoratedclient.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "deleted.h"
|
|
|
|
#include "effects.h"
|
2019-08-26 07:44:04 +00:00
|
|
|
#include "internal_client.h"
|
2011-07-06 09:58:23 +00:00
|
|
|
#include "overlaywindow.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "platform.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "scene.h"
|
2014-11-25 07:40:23 +00:00
|
|
|
#include "screens.h"
|
2011-03-27 10:33:07 +00:00
|
|
|
#include "shadow.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "unmanaged.h"
|
|
|
|
#include "useractions.h"
|
|
|
|
#include "utils.h"
|
2015-03-23 13:29:07 +00:00
|
|
|
#include "wayland_server.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
#include "xcbutils.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
#include <kwingltexture.h>
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/surface_interface.h>
|
2015-02-24 10:50:01 +00:00
|
|
|
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KGlobalAccel>
|
|
|
|
#include <KLocalizedString>
|
2017-08-10 16:13:42 +00:00
|
|
|
#include <KPluginLoader>
|
|
|
|
#include <KPluginMetaData>
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KNotification>
|
2019-06-22 10:40:12 +00:00
|
|
|
#include <KSelectionOwner>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-06-22 10:00:56 +00:00
|
|
|
#include <QDateTime>
|
|
|
|
#include <QFutureWatcher>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QTimerEvent>
|
|
|
|
|
2012-12-11 20:21:35 +00:00
|
|
|
#include <xcb/composite.h>
|
2012-03-28 18:29:33 +00:00
|
|
|
#include <xcb/damage.h>
|
|
|
|
|
2019-06-22 10:00:56 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
Q_DECLARE_METATYPE(KWin::X11Compositor::SuspendReason)
|
2013-01-09 15:03:54 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
// See main.cpp:
|
|
|
|
extern int screen_number;
|
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
extern bool is_multihead;
|
2010-11-27 15:27:54 +00:00
|
|
|
extern int currentRefreshRate();
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
Compositor *Compositor::s_compositor = nullptr;
|
|
|
|
Compositor *Compositor::self()
|
|
|
|
{
|
|
|
|
return s_compositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandCompositor *WaylandCompositor::create(QObject *parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!s_compositor);
|
|
|
|
auto *compositor = new WaylandCompositor(parent);
|
|
|
|
s_compositor = compositor;
|
|
|
|
return compositor;
|
|
|
|
}
|
|
|
|
X11Compositor *X11Compositor::create(QObject *parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!s_compositor);
|
|
|
|
auto *compositor = new X11Compositor(parent);
|
|
|
|
s_compositor = compositor;
|
|
|
|
return compositor;
|
|
|
|
}
|
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
class CompositorSelectionOwner : public KSelectionOwner
|
2013-04-26 15:11:37 +00:00
|
|
|
{
|
2019-06-22 10:40:12 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
CompositorSelectionOwner(const char *selection)
|
|
|
|
: KSelectionOwner(selection, connection(), rootWindow())
|
|
|
|
, m_owning(false)
|
|
|
|
{
|
|
|
|
connect (this, &CompositorSelectionOwner::lostOwnership,
|
|
|
|
this, [this]() { m_owning = false; });
|
|
|
|
}
|
|
|
|
bool owning() const {
|
|
|
|
return m_owning;
|
|
|
|
}
|
|
|
|
void setOwning(bool own) {
|
|
|
|
m_owning = own;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
bool m_owning;
|
|
|
|
};
|
2013-04-26 15:11:37 +00:00
|
|
|
|
2015-12-28 02:52:47 +00:00
|
|
|
static inline qint64 milliToNano(int milli) { return qint64(milli) * 1000 * 1000; }
|
2013-03-28 20:53:25 +00:00
|
|
|
static inline qint64 nanoToMilli(int nano) { return nano / (1000*1000); }
|
|
|
|
|
2012-08-16 15:10:47 +00:00
|
|
|
Compositor::Compositor(QObject* workspace)
|
2011-08-21 19:50:23 +00:00
|
|
|
: QObject(workspace)
|
2019-07-04 01:19:18 +00:00
|
|
|
, m_state(State::Off)
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
, m_selectionOwner(nullptr)
|
2020-01-09 17:05:36 +00:00
|
|
|
, vBlankInterval(0)
|
|
|
|
, fpsInterval(0)
|
|
|
|
, m_timeSinceLastVBlank(0)
|
2019-12-24 23:54:40 +00:00
|
|
|
, m_scene(nullptr)
|
2020-01-09 17:05:36 +00:00
|
|
|
, m_bufferSwapPending(false)
|
|
|
|
, m_composeAtSwapCompletion(false)
|
2011-08-21 19:50:23 +00:00
|
|
|
{
|
2019-08-07 17:33:20 +00:00
|
|
|
connect(options, &Options::configChanged, this, &Compositor::configChanged);
|
2019-09-25 13:31:48 +00:00
|
|
|
connect(options, &Options::animationSpeedChanged, this, &Compositor::configChanged);
|
2019-07-02 22:57:53 +00:00
|
|
|
|
[wayland] Send correct current time in the frame callback
Summary:
Currently, each frame callback sent by KWin has the current time in
nanoseconds, but the protocol spec states that we have to send the time
in milliseconds. This is the reason why animations that are driven by
frame callbacks are too fast.
In addition to that, m_timeSinceStart isn't actually "time since start,"
it's rather accumulated duration of all painting cycles. If there is
something to draw and it takes quite a while to compose the scene, maybe
m_timeSinceStart will be close enough to the current time. So, it has
been replaced with QElapsedTimer, this makes the current time correct
and also simplifies code a little bit.
Test Plan: The triangle in weston-subsurfaces no longer spins very fast.
Reviewers: #kwin, romangg
Reviewed By: #kwin, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18656
2019-02-01 21:39:22 +00:00
|
|
|
m_monotonicClock.start();
|
2012-10-14 10:18:35 +00:00
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
// 2 sec which should be enough to restart the compositor.
|
2013-04-26 22:00:23 +00:00
|
|
|
static const int compositorLostMessageDelay = 2000;
|
|
|
|
|
|
|
|
m_releaseSelectionTimer.setSingleShot(true);
|
|
|
|
m_releaseSelectionTimer.setInterval(compositorLostMessageDelay);
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(&m_releaseSelectionTimer, &QTimer::timeout,
|
|
|
|
this, &Compositor::releaseCompositorSelection);
|
2013-04-26 22:00:23 +00:00
|
|
|
|
|
|
|
m_unusedSupportPropertyTimer.setInterval(compositorLostMessageDelay);
|
|
|
|
m_unusedSupportPropertyTimer.setSingleShot(true);
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(&m_unusedSupportPropertyTimer, &QTimer::timeout,
|
|
|
|
this, &Compositor::deleteUnusedSupportProperties);
|
2016-04-15 09:19:12 +00:00
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
// Delay the call to start by one event cycle.
|
2016-04-15 09:19:12 +00:00
|
|
|
// 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.
|
|
|
|
if (kwinApp()->platform()->isReady()) {
|
2019-08-07 17:33:20 +00:00
|
|
|
QTimer::singleShot(0, this, &Compositor::start);
|
2014-08-13 10:54:02 +00:00
|
|
|
}
|
2016-04-15 09:19:12 +00:00
|
|
|
connect(kwinApp()->platform(), &Platform::readyChanged, this,
|
|
|
|
[this] (bool ready) {
|
|
|
|
if (ready) {
|
2019-07-04 01:19:18 +00:00
|
|
|
start();
|
2016-04-15 09:19:12 +00:00
|
|
|
} else {
|
2019-07-04 01:19:18 +00:00
|
|
|
stop();
|
2016-04-15 09:19:12 +00:00
|
|
|
}
|
|
|
|
}, Qt::QueuedConnection
|
|
|
|
);
|
2014-06-02 06:51:28 +00:00
|
|
|
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
if (qEnvironmentVariableIsSet("KWIN_MAX_FRAMES_TESTED"))
|
|
|
|
m_framesToTestForSafety = qEnvironmentVariableIntValue("KWIN_MAX_FRAMES_TESTED");
|
|
|
|
|
2014-06-02 06:51:28 +00:00
|
|
|
// register DBus
|
|
|
|
new CompositorDBusInterface(this);
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Compositor::~Compositor()
|
|
|
|
{
|
2014-12-03 12:10:35 +00:00
|
|
|
emit aboutToDestroy();
|
2019-07-04 01:19:18 +00:00
|
|
|
stop();
|
2013-04-26 22:00:23 +00:00
|
|
|
deleteUnusedSupportProperties();
|
2019-08-07 17:33:20 +00:00
|
|
|
destroyCompositorSelection();
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
s_compositor = nullptr;
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
bool Compositor::setupStart()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-01-06 16:05:10 +00:00
|
|
|
if (kwinApp()->isTerminating()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Don't start while KWin is terminating. An event to restart might be lingering
|
|
|
|
// in the event queue due to graphics reset.
|
2019-08-07 17:33:20 +00:00
|
|
|
return false;
|
2019-01-06 16:05:10 +00:00
|
|
|
}
|
2019-07-04 01:19:18 +00:00
|
|
|
if (m_state != State::Off) {
|
2019-08-07 17:33:20 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2019-07-04 01:19:18 +00:00
|
|
|
m_state = State::Starting;
|
2011-02-27 22:39:32 +00:00
|
|
|
|
2019-07-02 19:09:23 +00:00
|
|
|
options->reloadCompositingSettings(true);
|
2007-07-19 16:20:05 +00:00
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
initializeX11();
|
2014-04-14 07:19:43 +00:00
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
// There might still be a deleted around, needs to be cleared before
|
|
|
|
// creating the scene (BUG 333275).
|
2015-02-23 14:57:00 +00:00
|
|
|
if (Workspace::self()) {
|
|
|
|
while (!Workspace::self()->deletedList().isEmpty()) {
|
|
|
|
Workspace::self()->deletedList().first()->discard();
|
|
|
|
}
|
2014-04-14 07:19:43 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 13:09:37 +00:00
|
|
|
emit aboutToToggleCompositing();
|
|
|
|
|
2017-10-18 19:56:13 +00:00
|
|
|
auto supportedCompositors = kwinApp()->platform()->supportedCompositors();
|
2019-08-08 12:34:22 +00:00
|
|
|
const auto userConfigIt = std::find(supportedCompositors.begin(), supportedCompositors.end(),
|
|
|
|
options->compositingMode());
|
|
|
|
|
2017-10-18 19:56:13 +00:00
|
|
|
if (userConfigIt != supportedCompositors.end()) {
|
|
|
|
supportedCompositors.erase(userConfigIt);
|
|
|
|
supportedCompositors.prepend(options->compositingMode());
|
|
|
|
} else {
|
2019-08-08 12:34:22 +00:00
|
|
|
qCWarning(KWIN_CORE)
|
|
|
|
<< "Configured compositor not supported by Platform. Falling back to defaults";
|
2017-10-18 19:56:13 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 16:13:42 +00:00
|
|
|
const auto availablePlugins = KPluginLoader::findPlugins(QStringLiteral("org.kde.kwin.scenes"));
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2020-04-28 17:19:08 +00:00
|
|
|
for (const KPluginMetaData &pluginMetaData : availablePlugins) {
|
|
|
|
qCDebug(KWIN_CORE) << "Available scene plugin:" << pluginMetaData.fileName();
|
|
|
|
}
|
|
|
|
|
2017-10-18 19:56:13 +00:00
|
|
|
for (auto type : qAsConst(supportedCompositors)) {
|
2020-04-28 17:19:08 +00:00
|
|
|
switch (type) {
|
|
|
|
case XRenderCompositing:
|
|
|
|
qCDebug(KWIN_CORE) << "Attempting to load the XRender scene";
|
|
|
|
break;
|
|
|
|
case OpenGLCompositing:
|
|
|
|
case OpenGL2Compositing:
|
|
|
|
qCDebug(KWIN_CORE) << "Attempting to load the OpenGL scene";
|
|
|
|
break;
|
|
|
|
case QPainterCompositing:
|
|
|
|
qCDebug(KWIN_CORE) << "Attempting to load the QPainter scene";
|
|
|
|
break;
|
|
|
|
case NoCompositing:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
2017-10-18 19:56:13 +00:00
|
|
|
const auto pluginIt = std::find_if(availablePlugins.begin(), availablePlugins.end(),
|
|
|
|
[type] (const auto &plugin) {
|
|
|
|
const auto &metaData = plugin.rawData();
|
|
|
|
auto it = metaData.find(QStringLiteral("CompositingType"));
|
|
|
|
if (it != metaData.end()) {
|
|
|
|
if ((*it).toInt() == int{type}) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
if (pluginIt != availablePlugins.end()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
std::unique_ptr<SceneFactory>
|
|
|
|
factory{ qobject_cast<SceneFactory*>(pluginIt->instantiate()) };
|
2017-10-18 19:56:13 +00:00
|
|
|
if (factory) {
|
|
|
|
m_scene = factory->create(this);
|
|
|
|
if (m_scene) {
|
|
|
|
if (!m_scene->initFailed()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Instantiated compositing plugin:"
|
|
|
|
<< pluginIt->name();
|
2017-10-18 19:56:13 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
delete m_scene;
|
|
|
|
m_scene = nullptr;
|
|
|
|
}
|
2017-08-10 16:13:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (m_scene == nullptr || m_scene->initFailed()) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCCritical(KWIN_CORE) << "Failed to initialize compositing, compositing disabled";
|
2019-07-04 01:19:18 +00:00
|
|
|
m_state = State::Off;
|
|
|
|
|
2012-08-16 19:19:54 +00:00
|
|
|
delete m_scene;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
m_scene = nullptr;
|
2019-07-04 01:19:18 +00:00
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
if (m_selectionOwner) {
|
|
|
|
m_selectionOwner->setOwning(false);
|
|
|
|
m_selectionOwner->release();
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2017-10-18 19:56:13 +00:00
|
|
|
if (!supportedCompositors.contains(NoCompositing)) {
|
2014-12-05 10:42:15 +00: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 08:39:13 +00:00
|
|
|
qApp->quit();
|
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2017-11-05 10:07:04 +00:00
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
CompositingType compositingType = m_scene->compositingType();
|
|
|
|
if (compositingType & OpenGLCompositing) {
|
|
|
|
// Override for OpenGl sub-type OpenGL2Compositing.
|
|
|
|
compositingType = OpenGLCompositing;
|
|
|
|
}
|
|
|
|
kwinApp()->platform()->setSelectedCompositor(compositingType);
|
2019-02-16 19:50:46 +00:00
|
|
|
|
2017-11-05 10:07:04 +00:00
|
|
|
if (!Workspace::self() && m_scene && m_scene->compositingType() == QPainterCompositing) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Force Software QtQuick on first startup with QPainter.
|
2017-11-05 10:07:04 +00:00
|
|
|
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
|
|
|
|
}
|
|
|
|
|
2019-07-02 20:30:27 +00:00
|
|
|
connect(m_scene, &Scene::resetCompositing, this, &Compositor::reinitialize);
|
2016-04-14 06:51:16 +00:00
|
|
|
emit sceneCreated();
|
2015-02-23 14:57:00 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
return true;
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
void Compositor::initializeX11()
|
2015-02-23 14:57:00 +00:00
|
|
|
{
|
2020-07-20 08:07:08 +00:00
|
|
|
xcb_connection_t *connection = kwinApp()->x11Connection();
|
|
|
|
if (!connection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
if (!m_selectionOwner) {
|
2015-02-23 14:57:00 +00:00
|
|
|
char selection_name[ 100 ];
|
|
|
|
sprintf(selection_name, "_NET_WM_CM_S%d", Application::x11ScreenNumber());
|
2019-06-22 10:40:12 +00:00
|
|
|
m_selectionOwner = new CompositorSelectionOwner(selection_name);
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(m_selectionOwner, &CompositorSelectionOwner::lostOwnership,
|
|
|
|
this, &Compositor::stop);
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2019-06-22 10:40:12 +00:00
|
|
|
if (!m_selectionOwner->owning()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Force claim ownership.
|
|
|
|
m_selectionOwner->claim(true);
|
2019-06-22 10:40:12 +00:00
|
|
|
m_selectionOwner->setOwning(true);
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2020-07-20 08:07:08 +00:00
|
|
|
|
|
|
|
xcb_composite_redirect_subwindows(connection, kwinApp()->x11RootWindow(),
|
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
void Compositor::cleanupX11()
|
2017-08-24 08:43:38 +00:00
|
|
|
{
|
2020-07-20 08:07:08 +00:00
|
|
|
delete m_selectionOwner;
|
|
|
|
m_selectionOwner = nullptr;
|
2017-08-24 08:43:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 14:57:00 +00:00
|
|
|
void Compositor::startupWithWorkspace()
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(kwinApp(), &Application::x11ConnectionChanged,
|
2020-07-20 08:07:08 +00:00
|
|
|
this, &Compositor::initializeX11, Qt::UniqueConnection);
|
|
|
|
connect(kwinApp(), &Application::x11ConnectionAboutToBeDestroyed,
|
|
|
|
this, &Compositor::cleanupX11, Qt::UniqueConnection);
|
|
|
|
initializeX11();
|
|
|
|
|
2017-06-21 19:10:12 +00:00
|
|
|
Workspace::self()->markXStackingOrderAsDirty();
|
2015-02-23 14:57:00 +00:00
|
|
|
Q_ASSERT(m_scene);
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2016-06-29 06:34:10 +00:00
|
|
|
connect(workspace(), &Workspace::destroyed, this, [this] { compositeTimer.stop(); });
|
2020-01-09 17:05:36 +00:00
|
|
|
fpsInterval = options->maxFpsInterval();
|
|
|
|
|
2020-01-09 17:18:22 +00:00
|
|
|
if (m_scene->syncsToVBlank()) {
|
|
|
|
// If we do vsync, set the fps to the next multiple of the vblank rate.
|
|
|
|
vBlankInterval = milliToNano(1000) / currentRefreshRate();
|
|
|
|
fpsInterval = qMax((fpsInterval / vBlankInterval) * vBlankInterval, vBlankInterval);
|
|
|
|
} else {
|
|
|
|
// No vsync - DO NOT set "0", would cause div-by-zero segfaults.
|
|
|
|
vBlankInterval = milliToNano(1);
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
|
|
|
// Sets also the 'effects' pointer.
|
|
|
|
kwinApp()->platform()->createEffectsHandler(this, m_scene);
|
2019-01-11 18:55:17 +00:00
|
|
|
connect(Workspace::self(), &Workspace::deletedRemoved, m_scene, &Scene::removeToplevel);
|
2019-07-02 18:28:45 +00:00
|
|
|
connect(effects, &EffectsHandler::screenGeometryChanged, this, &Compositor::addRepaintFull);
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
for (X11Client *c : Workspace::self()->clientList()) {
|
2012-03-29 20:11:28 +00:00
|
|
|
c->setupCompositing();
|
2019-09-29 11:26:04 +00:00
|
|
|
c->updateShadow();
|
2012-12-27 20:57:40 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
|
2012-03-29 20:11:28 +00:00
|
|
|
c->setupCompositing();
|
2019-09-29 11:26:04 +00:00
|
|
|
c->updateShadow();
|
2012-12-27 20:57:40 +00:00
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
for (InternalClient *client : workspace()->internalClients()) {
|
|
|
|
client->setupCompositing();
|
2019-09-29 11:26:04 +00:00
|
|
|
client->updateShadow();
|
2019-08-26 07:44:04 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
|
|
|
if (auto *server = waylandServer()) {
|
|
|
|
const auto clients = server->clients();
|
2020-03-04 07:55:26 +00:00
|
|
|
for (AbstractClient *c : clients) {
|
2016-07-15 14:06:09 +00:00
|
|
|
c->setupCompositing();
|
2019-09-29 11:26:04 +00:00
|
|
|
c->updateShadow();
|
2016-07-15 14:06:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-13 09:36:48 +00:00
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
m_state = State::On;
|
2012-09-01 07:10:56 +00:00
|
|
|
emit compositingToggled(true);
|
|
|
|
|
2012-10-14 10:18:35 +00:00
|
|
|
if (m_releaseSelectionTimer.isActive()) {
|
|
|
|
m_releaseSelectionTimer.stop();
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
// Render at least once.
|
2019-09-05 07:39:20 +00:00
|
|
|
addRepaintFull();
|
2012-04-13 09:36:48 +00:00
|
|
|
performCompositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-08-23 11:42:59 +00:00
|
|
|
void Compositor::scheduleRepaint()
|
2011-08-21 19:50:23 +00:00
|
|
|
{
|
2020-01-09 17:06:09 +00:00
|
|
|
if (!compositeTimer.isActive())
|
2020-01-09 17:05:36 +00:00
|
|
|
setCompositeTimer();
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
void Compositor::stop()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
if (m_state == State::Off || m_state == State::Stopping) {
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2019-07-04 01:19:18 +00:00
|
|
|
}
|
|
|
|
m_state = State::Stopping;
|
2019-02-20 13:09:37 +00:00
|
|
|
emit aboutToToggleCompositing();
|
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
m_releaseSelectionTimer.start();
|
|
|
|
|
2018-12-01 16:23:37 +00:00
|
|
|
// Some effects might need access to effect windows when they are about to
|
|
|
|
// be destroyed, for example to unreference deleted windows, so we have to
|
|
|
|
// make sure that effect windows outlive effects.
|
|
|
|
delete effects;
|
|
|
|
effects = nullptr;
|
|
|
|
|
2015-05-27 07:12:07 +00:00
|
|
|
if (Workspace::self()) {
|
2019-09-24 08:48:08 +00:00
|
|
|
for (X11Client *c : Workspace::self()->clientList()) {
|
2019-01-11 18:55:17 +00:00
|
|
|
m_scene->removeToplevel(c);
|
2019-08-08 12:34:22 +00:00
|
|
|
}
|
|
|
|
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
|
2019-01-11 18:55:17 +00:00
|
|
|
m_scene->removeToplevel(c);
|
2019-08-08 12:34:22 +00:00
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
for (InternalClient *client : workspace()->internalClients()) {
|
|
|
|
m_scene->removeToplevel(client);
|
|
|
|
}
|
2019-09-24 08:48:08 +00:00
|
|
|
for (X11Client *c : Workspace::self()->clientList()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
c->finishCompositing();
|
|
|
|
}
|
|
|
|
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
|
|
|
|
c->finishCompositing();
|
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
for (InternalClient *client : workspace()->internalClients()) {
|
|
|
|
client->finishCompositing();
|
|
|
|
}
|
2019-12-02 17:36:13 +00:00
|
|
|
if (auto *con = kwinApp()->x11Connection()) {
|
|
|
|
xcb_composite_unredirect_subwindows(con, kwinApp()->x11RootWindow(),
|
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
|
|
|
}
|
2019-02-10 21:37:06 +00:00
|
|
|
while (!workspace()->deletedList().isEmpty()) {
|
|
|
|
workspace()->deletedList().first()->discard();
|
|
|
|
}
|
2015-05-27 07:12:07 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2016-08-18 09:51:54 +00:00
|
|
|
if (waylandServer()) {
|
2020-03-04 07:55:26 +00:00
|
|
|
for (AbstractClient *c : waylandServer()->clients()) {
|
2019-01-11 18:55:17 +00:00
|
|
|
m_scene->removeToplevel(c);
|
2016-08-18 09:51:54 +00:00
|
|
|
}
|
2020-03-04 07:55:26 +00:00
|
|
|
for (AbstractClient *c : waylandServer()->clients()) {
|
2016-08-18 09:51:54 +00:00
|
|
|
c->finishCompositing();
|
|
|
|
}
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2012-08-16 19:19:54 +00:00
|
|
|
delete m_scene;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
m_scene = nullptr;
|
2011-02-01 15:35:51 +00:00
|
|
|
compositeTimer.stop();
|
2007-04-29 17:35:43 +00:00
|
|
|
repaints_region = QRegion();
|
2019-07-04 01:19:18 +00:00
|
|
|
|
|
|
|
m_state = State::Off;
|
2012-09-01 07:10:56 +00:00
|
|
|
emit compositingToggled(false);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
void Compositor::destroyCompositorSelection()
|
|
|
|
{
|
|
|
|
delete m_selectionOwner;
|
|
|
|
m_selectionOwner = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-10-14 10:18:35 +00:00
|
|
|
void Compositor::releaseCompositorSelection()
|
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
switch (m_state) {
|
|
|
|
case State::On:
|
|
|
|
// We are compositing at the moment. Don't release.
|
|
|
|
break;
|
|
|
|
case State::Off:
|
|
|
|
if (m_selectionOwner) {
|
|
|
|
qCDebug(KWIN_CORE) << "Releasing compositor selection";
|
|
|
|
m_selectionOwner->setOwning(false);
|
|
|
|
m_selectionOwner->release();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case State::Starting:
|
|
|
|
case State::Stopping:
|
|
|
|
// Still starting or shutting down the compositor. Starting might fail
|
|
|
|
// or after stopping a restart might follow. So test again later on.
|
2012-10-14 10:18:35 +00:00
|
|
|
m_releaseSelectionTimer.start();
|
2019-07-04 01:19:18 +00:00
|
|
|
break;
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2012-10-14 10:18:35 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 22:00:23 +00: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()
|
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
if (m_state == State::Starting || m_state == State::Stopping) {
|
|
|
|
// Currently still maybe restarting the compositor.
|
2013-04-26 22:00:23 +00:00
|
|
|
m_unusedSupportPropertyTimer.start();
|
|
|
|
return;
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
if (auto *con = kwinApp()->x11Connection()) {
|
|
|
|
for (const xcb_atom_t &atom : qAsConst(m_unusedSupportProperties)) {
|
2015-11-10 12:54:26 +00:00
|
|
|
// remove property from root window
|
2019-08-08 12:34:22 +00:00
|
|
|
xcb_delete_property(con, kwinApp()->x11RootWindow(), atom);
|
2015-11-10 12:54:26 +00:00
|
|
|
}
|
2019-09-05 07:55:31 +00:00
|
|
|
m_unusedSupportProperties.clear();
|
2013-04-26 22:00:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
void Compositor::configChanged()
|
2011-08-21 19:50:23 +00:00
|
|
|
{
|
2019-08-07 17:33:20 +00:00
|
|
|
reinitialize();
|
|
|
|
addRepaintFull();
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 20:30:27 +00:00
|
|
|
void Compositor::reinitialize()
|
2011-08-21 19:50:23 +00:00
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
// Reparse config. Config options will be reloaded by start()
|
2016-01-29 10:24:18 +00:00
|
|
|
kwinApp()->config()->reparseConfiguration();
|
2012-08-17 08:15:33 +00:00
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
// Restart compositing
|
2019-07-04 01:19:18 +00:00
|
|
|
stop();
|
|
|
|
start();
|
2012-08-17 08:15:33 +00:00
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
if (effects) { // start() may fail
|
2012-08-17 08:15:33 +00:00
|
|
|
effects->reconfigure();
|
|
|
|
}
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::addRepaint(int x, int y, int w, int h)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-09-05 16:06:03 +00:00
|
|
|
if (m_state != State::On) {
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2019-09-05 16:06:03 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
repaints_region += QRegion(x, y, w, h);
|
2012-08-23 11:42:59 +00:00
|
|
|
scheduleRepaint();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
void Compositor::addRepaint(const QRect& r)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-09-05 16:06:03 +00:00
|
|
|
if (m_state != State::On) {
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2019-09-05 16:06:03 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
repaints_region += r;
|
2012-08-23 11:42:59 +00:00
|
|
|
scheduleRepaint();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
void Compositor::addRepaint(const QRegion& r)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-09-05 16:06:03 +00:00
|
|
|
if (m_state != State::On) {
|
2008-06-19 14:16:21 +00:00
|
|
|
return;
|
2019-09-05 16:06:03 +00:00
|
|
|
}
|
2008-06-19 14:16:21 +00:00
|
|
|
repaints_region += r;
|
2012-08-23 11:42:59 +00:00
|
|
|
scheduleRepaint();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
void Compositor::addRepaintFull()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-09-05 16:06:03 +00:00
|
|
|
if (m_state != State::On) {
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2019-09-05 16:06:03 +00:00
|
|
|
}
|
2014-11-25 07:40:23 +00:00
|
|
|
const QSize &s = screens()->size();
|
|
|
|
repaints_region = QRegion(0, 0, s.width(), s.height());
|
2012-08-23 11:42:59 +00:00
|
|
|
scheduleRepaint();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
void Compositor::timerEvent(QTimerEvent *te)
|
2010-12-18 16:51:43 +00:00
|
|
|
{
|
2011-02-01 15:35:51 +00:00
|
|
|
if (te->timerId() == compositeTimer.timerId()) {
|
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
|
|
|
}
|
2012-07-17 23:50:43 +00:00
|
|
|
|
2014-08-27 16:24:43 +00:00
|
|
|
void Compositor::aboutToSwapBuffers()
|
2013-06-19 09:12:57 +00:00
|
|
|
{
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(!m_bufferSwapPending);
|
2020-01-09 17:05:52 +00:00
|
|
|
|
2014-08-27 16:24:43 +00:00
|
|
|
m_bufferSwapPending = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::bufferSwapComplete()
|
|
|
|
{
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(m_bufferSwapPending);
|
2014-08-27 16:24:43 +00:00
|
|
|
m_bufferSwapPending = false;
|
2020-01-09 17:05:36 +00:00
|
|
|
|
2019-02-21 22:25:19 +00:00
|
|
|
emit bufferSwapCompleted();
|
2020-01-09 17:05:36 +00:00
|
|
|
|
|
|
|
if (m_composeAtSwapCompletion) {
|
|
|
|
m_composeAtSwapCompletion = false;
|
|
|
|
performCompositing();
|
|
|
|
}
|
2013-06-19 09:12:57 +00:00
|
|
|
}
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
void Compositor::performCompositing()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-08-27 16:24:43 +00: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) {
|
2020-01-09 17:05:36 +00:00
|
|
|
m_composeAtSwapCompletion = true;
|
|
|
|
compositeTimer.stop();
|
2014-08-27 16:24:43 +00:00
|
|
|
return;
|
2013-06-19 09:12:57 +00:00
|
|
|
}
|
2012-03-29 20:11:28 +00:00
|
|
|
|
2015-08-31 11:54:50 +00:00
|
|
|
// If outputs are disabled, we return to the event loop and
|
|
|
|
// continue processing events until the outputs are enabled again
|
2016-04-15 09:19:12 +00:00
|
|
|
if (!kwinApp()->platform()->areOutputsEnabled()) {
|
2020-01-09 17:05:36 +00:00
|
|
|
compositeTimer.stop();
|
2015-08-31 11:54:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-28 18:29:33 +00:00
|
|
|
// Create a list of all windows in the stacking order
|
Drop some custom list typedefs
Summary:
Qt has its own thing where a type might also have corresponding list
alias, e.g. QObject and QObjectList, QWidget and QWidgetList. I don't
know why Qt does that, maybe for some historical reasons, but what
matters is that we copy this pattern here in KWin. While this pattern
might be useful with some long list types, for example
QList<QWeakPointer<TabBoxClient>> TabBoxClientList
in general, it causes more harm than good. For example, we've got two
new client types, do we need corresponding list typedefs for them? If
no, why do we have ClientList and so on?
Another problem with these typedefs is that you need to include utils.h
header in order to use them. A better way to handle such things is to
just forward declare a client class (if that's possible) and use it
directly with QList or QVector. This way translation units don't get
"bloated" with utils.h stuff for no apparent reason.
So, in order to make code more consistent and easier to follow, this
change drops some of our custom typedefs. Namely ConstClientList,
ClientList, DeletedList, UnmanagedList, ToplevelList, and GroupList.
Test Plan: Compiles.
Reviewers: #kwin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24950
2019-10-16 09:11:04 +00:00
|
|
|
QList<Toplevel *> windows = Workspace::self()->xStackingOrder();
|
|
|
|
QList<Toplevel *> damaged;
|
2012-03-28 18:29:33 +00:00
|
|
|
|
|
|
|
// Reset the damage state of each window and fetch the damage region
|
|
|
|
// without waiting for a reply
|
2020-09-23 00:01:21 +00:00
|
|
|
for (Toplevel *win : qAsConst(windows)) {
|
2019-08-08 12:34:22 +00:00
|
|
|
if (win->resetAndFetchDamage()) {
|
2012-03-28 18:29:33 +00:00
|
|
|
damaged << win;
|
2019-08-08 12:34:22 +00:00
|
|
|
}
|
2012-03-28 18:29:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-03 16:43:38 +00:00
|
|
|
if (damaged.count() > 0) {
|
|
|
|
m_scene->triggerFence();
|
2017-09-20 17:32:54 +00:00
|
|
|
if (auto c = kwinApp()->x11Connection()) {
|
|
|
|
xcb_flush(c);
|
|
|
|
}
|
2014-09-03 16:43:38 +00:00
|
|
|
}
|
2012-03-28 18:29:33 +00:00
|
|
|
|
|
|
|
// Move elevated windows to the top of the stacking order
|
2019-08-08 12:34:22 +00:00
|
|
|
for (EffectWindow *c : static_cast<EffectsHandlerImpl *>(effects)->elevatedWindows()) {
|
|
|
|
Toplevel *t = static_cast<EffectWindowImpl *>(c)->window();
|
2012-03-28 18:29:33 +00:00
|
|
|
windows.removeAll(t);
|
|
|
|
windows.append(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the replies
|
2020-09-23 00:01:21 +00:00
|
|
|
for (Toplevel *win : qAsConst(damaged)) {
|
2012-03-28 18:29:33 +00:00
|
|
|
// 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-18 22:17:46 +00:00
|
|
|
if (repaints_region.isEmpty() && !windowRepaintsPending()) {
|
2012-08-16 19:19:54 +00:00
|
|
|
m_scene->idle();
|
2020-01-09 17:05:36 +00:00
|
|
|
m_timeSinceLastVBlank = fpsInterval - (options->vBlankTime() + 1); // means "start now"
|
|
|
|
// 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.
|
|
|
|
compositeTimer.stop();
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-08-23 14:51:40 +00:00
|
|
|
|
2019-08-08 12:34:22 +00: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.
|
|
|
|
//
|
|
|
|
// TODO? This cannot be used so carelessly - needs protections against broken clients, the
|
|
|
|
// window should not get focus before it's displayed, handle unredirected windows properly and
|
|
|
|
// so on.
|
|
|
|
for (Toplevel *win : windows) {
|
|
|
|
if (!win->readyForPainting()) {
|
|
|
|
windows.removeAll(win);
|
2015-11-16 10:46:20 +00:00
|
|
|
}
|
|
|
|
if (waylandServer() && waylandServer()->isScreenLocked()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
if(!win->isLockScreen() && !win->isInputMethod()) {
|
|
|
|
windows.removeAll(win);
|
2015-11-16 10:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-13 14:39:58 +00:00
|
|
|
|
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();
|
2012-03-29 20:11:28 +00:00
|
|
|
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
if (m_framesToTestForSafety > 0 && (m_scene->compositingType() & OpenGLCompositing)) {
|
|
|
|
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreFrame);
|
|
|
|
}
|
2020-01-09 17:05:36 +00:00
|
|
|
m_timeSinceLastVBlank = m_scene->paint(repaints, windows);
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
if (m_framesToTestForSafety > 0) {
|
|
|
|
if (m_scene->compositingType() & OpenGLCompositing) {
|
|
|
|
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostFrame);
|
|
|
|
}
|
|
|
|
m_framesToTestForSafety--;
|
|
|
|
if (m_framesToTestForSafety == 0 && (m_scene->compositingType() & OpenGLCompositing)) {
|
2019-08-08 12:34:22 +00:00
|
|
|
kwinApp()->platform()->createOpenGLSafePoint(
|
|
|
|
Platform::OpenGLSafePoint::PostLastGuardedFrame);
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-24 10:50:01 +00:00
|
|
|
|
2016-05-12 10:17:27 +00:00
|
|
|
if (waylandServer()) {
|
[wayland] Send correct current time in the frame callback
Summary:
Currently, each frame callback sent by KWin has the current time in
nanoseconds, but the protocol spec states that we have to send the time
in milliseconds. This is the reason why animations that are driven by
frame callbacks are too fast.
In addition to that, m_timeSinceStart isn't actually "time since start,"
it's rather accumulated duration of all painting cycles. If there is
something to draw and it takes quite a while to compose the scene, maybe
m_timeSinceStart will be close enough to the current time. So, it has
been replaced with QElapsedTimer, this makes the current time correct
and also simplifies code a little bit.
Test Plan: The triangle in weston-subsurfaces no longer spins very fast.
Reviewers: #kwin, romangg
Reviewed By: #kwin, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18656
2019-02-01 21:39:22 +00:00
|
|
|
const auto currentTime = static_cast<quint32>(m_monotonicClock.elapsed());
|
2019-01-29 20:37:17 +00:00
|
|
|
for (Toplevel *win : qAsConst(windows)) {
|
2015-02-24 10:50:01 +00:00
|
|
|
if (auto surface = win->surface()) {
|
[wayland] Send correct current time in the frame callback
Summary:
Currently, each frame callback sent by KWin has the current time in
nanoseconds, but the protocol spec states that we have to send the time
in milliseconds. This is the reason why animations that are driven by
frame callbacks are too fast.
In addition to that, m_timeSinceStart isn't actually "time since start,"
it's rather accumulated duration of all painting cycles. If there is
something to draw and it takes quite a while to compose the scene, maybe
m_timeSinceStart will be close enough to the current time. So, it has
been replaced with QElapsedTimer, this makes the current time correct
and also simplifies code a little bit.
Test Plan: The triangle in weston-subsurfaces no longer spins very fast.
Reviewers: #kwin, romangg
Reviewed By: #kwin, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18656
2019-02-01 21:39:22 +00:00
|
|
|
surface->frameRendered(currentTime);
|
2015-02-24 10:50:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-26 08:02:17 +00:00
|
|
|
if (!kwinApp()->platform()->isCursorHidden()) {
|
|
|
|
Cursors::self()->currentCursor()->markAsRendered();
|
|
|
|
}
|
2015-02-24 10:50:01 +00:00
|
|
|
}
|
2012-03-28 18:29:33 +00:00
|
|
|
|
2020-01-09 17:05:36 +00:00
|
|
|
// Stop here to ensure *we* cause the next repaint schedule - not some effect
|
|
|
|
// through m_scene->paint().
|
2019-08-08 12:34:22 +00:00
|
|
|
compositeTimer.stop();
|
2020-01-09 17:05:36 +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
|
|
|
|
// scheduleRepaint() would restart it again somewhen later, called from functions that
|
|
|
|
// would again add something pending.
|
2020-01-09 17:18:22 +00:00
|
|
|
if (m_bufferSwapPending && m_scene->syncsToVBlank()) {
|
2020-01-09 17:05:58 +00:00
|
|
|
m_composeAtSwapCompletion = true;
|
|
|
|
} else {
|
|
|
|
scheduleRepaint();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2016-11-17 09:34:11 +00:00
|
|
|
template <class T>
|
|
|
|
static bool repaintsPending(const QList<T*> &windows)
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
return std::any_of(windows.begin(), windows.end(),
|
|
|
|
[](T *t) { return !t->repaints().isEmpty(); });
|
2016-11-17 09:34:11 +00:00
|
|
|
}
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
bool Compositor::windowRepaintsPending() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-11-17 09:34:11 +00:00
|
|
|
if (repaintsPending(Workspace::self()->clientList())) {
|
2011-01-30 14:34:42 +00:00
|
|
|
return true;
|
2016-11-17 09:34:11 +00:00
|
|
|
}
|
|
|
|
if (repaintsPending(Workspace::self()->unmanagedList())) {
|
2011-01-30 14:34:42 +00:00
|
|
|
return true;
|
2016-11-17 09:34:11 +00:00
|
|
|
}
|
|
|
|
if (repaintsPending(Workspace::self()->deletedList())) {
|
2011-01-30 14:34:42 +00:00
|
|
|
return true;
|
2016-11-17 09:34:11 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
if (auto *server = waylandServer()) {
|
|
|
|
const auto &clients = server->clients();
|
2020-03-04 07:55:26 +00:00
|
|
|
auto test = [](AbstractClient *c) {
|
2016-11-17 09:34:11 +00:00
|
|
|
return c->readyForPainting() && !c->repaints().isEmpty();
|
|
|
|
};
|
|
|
|
if (std::any_of(clients.begin(), clients.end(), test)) {
|
|
|
|
return true;
|
2015-06-06 15:36:04 +00:00
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
}
|
|
|
|
const auto &internalClients = workspace()->internalClients();
|
|
|
|
auto internalTest = [] (InternalClient *client) {
|
|
|
|
return client->isShown(true) && !client->repaints().isEmpty();
|
|
|
|
};
|
|
|
|
if (std::any_of(internalClients.begin(), internalClients.end(), internalTest)) {
|
|
|
|
return true;
|
2015-03-04 08:21:10 +00:00
|
|
|
}
|
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
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
void Compositor::setCompositeTimer()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2020-01-09 17:06:09 +00:00
|
|
|
if (m_state != State::On) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't start the timer if we're waiting for a swap event
|
|
|
|
if (m_bufferSwapPending && m_composeAtSwapCompletion)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Don't start the timer if all outputs are disabled
|
|
|
|
if (!kwinApp()->platform()->areOutputsEnabled()) {
|
2015-08-31 11:54:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-09 17:06:14 +00:00
|
|
|
uint waitTime = 1;
|
|
|
|
|
|
|
|
if (m_scene->blocksForRetrace()) {
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
qint64 padding = m_timeSinceLastVBlank;
|
|
|
|
if (padding > fpsInterval) {
|
|
|
|
// We're at low repaints or spent more time in painting than the user wanted to wait
|
|
|
|
// for that frame. Align to next vblank:
|
|
|
|
padding = vBlankInterval - (padding % vBlankInterval);
|
|
|
|
} else {
|
|
|
|
// Align to the next maxFps tick:
|
|
|
|
// "remaining time of the first vsync" + "time for the other vsyncs of the frame"
|
|
|
|
padding = ((vBlankInterval - padding % vBlankInterval) +
|
|
|
|
(fpsInterval / vBlankInterval - 1) * vBlankInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (padding < options->vBlankTime()) {
|
|
|
|
// We'll likely miss this frame so we add one:
|
|
|
|
waitTime = nanoToMilli(padding + vBlankInterval - options->vBlankTime());
|
|
|
|
} else {
|
|
|
|
waitTime = nanoToMilli(padding - options->vBlankTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // w/o blocking vsync we just jump to the next demanded tick
|
|
|
|
if (fpsInterval > m_timeSinceLastVBlank) {
|
|
|
|
waitTime = nanoToMilli(fpsInterval - m_timeSinceLastVBlank);
|
|
|
|
if (!waitTime) {
|
|
|
|
// Will ensure we don't block out the eventloop - the system's just not faster ...
|
|
|
|
waitTime = 1;
|
|
|
|
}
|
|
|
|
}
|
2020-01-09 17:18:22 +00:00
|
|
|
/* else if (m_scene->syncsToVBlank() && m_timeSinceLastVBlank - fpsInterval < (vBlankInterval<<1)) {
|
2020-01-09 17:06:14 +00:00
|
|
|
// 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 {
|
|
|
|
// "0" would be sufficient here, but the compositor isn't the WMs only task.
|
|
|
|
waitTime = 1;
|
|
|
|
}
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
// Force 4fps minimum:
|
|
|
|
compositeTimer.start(qMin(waitTime, 250u), this);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-30 15:28:47 +00:00
|
|
|
|
2012-08-17 06:18:36 +00:00
|
|
|
bool Compositor::isActive()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
return m_state == State::On;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-15 11:09:07 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
WaylandCompositor::WaylandCompositor(QObject *parent)
|
|
|
|
: Compositor(parent)
|
|
|
|
{
|
|
|
|
connect(kwinApp(), &Application::x11ConnectionAboutToBeDestroyed,
|
|
|
|
this, &WaylandCompositor::destroyCompositorSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandCompositor::toggleCompositing()
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
// For the shortcut. Not possible on Wayland because we always composite.
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandCompositor::start()
|
|
|
|
{
|
|
|
|
if (!Compositor::setupStart()) {
|
|
|
|
// Internal setup failed, abort.
|
|
|
|
return;
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
if (Workspace::self()) {
|
|
|
|
startupWithWorkspace();
|
|
|
|
} else {
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(kwinApp(), &Application::workspaceCreated,
|
|
|
|
this, &WaylandCompositor::startupWithWorkspace);
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int WaylandCompositor::refreshRate() const
|
|
|
|
{
|
2020-01-09 17:06:14 +00:00
|
|
|
// TODO: This makes no sense on Wayland. First step would be to atleast
|
|
|
|
// set the refresh rate to the highest available one. Second step
|
|
|
|
// would be to not use a uniform value at all but per screen.
|
|
|
|
return KWin::currentRefreshRate();
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
X11Compositor::X11Compositor(QObject *parent)
|
|
|
|
: Compositor(parent)
|
|
|
|
, m_suspended(options->isUseCompositing() ? NoReasonSuspend : UserSuspend)
|
|
|
|
, m_xrrRefreshRate(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::toggleCompositing()
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
if (m_suspended) {
|
|
|
|
// Direct user call; clear all bits.
|
2019-08-07 17:33:20 +00:00
|
|
|
resume(AllReasonSuspend);
|
2019-08-08 12:34:22 +00:00
|
|
|
} else {
|
|
|
|
// But only set the user one (sufficient to suspend).
|
2019-08-07 17:33:20 +00:00
|
|
|
suspend(UserSuspend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::reinitialize()
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
// Resume compositing if suspended.
|
2019-08-07 17:33:20 +00:00
|
|
|
m_suspended = NoReasonSuspend;
|
|
|
|
Compositor::reinitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::configChanged()
|
|
|
|
{
|
|
|
|
if (m_suspended) {
|
|
|
|
stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Compositor::configChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::suspend(X11Compositor::SuspendReason reason)
|
|
|
|
{
|
|
|
|
Q_ASSERT(reason != NoReasonSuspend);
|
|
|
|
m_suspended |= reason;
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
if (reason & ScriptSuspend) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// When disabled show a shortcut how the user can get back compositing.
|
|
|
|
const auto shortcuts = KGlobalAccel::self()->shortcut(
|
|
|
|
workspace()->findChild<QAction*>(QStringLiteral("Suspend Compositing")));
|
2019-08-07 17:33:20 +00:00
|
|
|
if (!shortcuts.isEmpty()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// 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));
|
2019-08-07 17:33:20 +00:00
|
|
|
KNotification::event(QStringLiteral("compositingsuspendeddbus"), message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::resume(X11Compositor::SuspendReason reason)
|
|
|
|
{
|
|
|
|
Q_ASSERT(reason != NoReasonSuspend);
|
|
|
|
m_suspended &= ~reason;
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::start()
|
|
|
|
{
|
|
|
|
if (m_suspended) {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
qCDebug(KWIN_CORE) << "Compositing is suspended, reason:" << reasons;
|
|
|
|
return;
|
|
|
|
} else if (!kwinApp()->platform()->compositingPossible()) {
|
|
|
|
qCCritical(KWIN_CORE) << "Compositing is not possible";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Compositor::setupStart()) {
|
|
|
|
// Internal setup failed, abort.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_xrrRefreshRate = KWin::currentRefreshRate();
|
|
|
|
startupWithWorkspace();
|
|
|
|
}
|
|
|
|
void X11Compositor::performCompositing()
|
|
|
|
{
|
|
|
|
if (scene()->usesOverlayWindow() && !isOverlayWindowVisible()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Return since nothing is visible.
|
|
|
|
return;
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
Compositor::performCompositing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool X11Compositor::checkForOverlayWindow(WId w) const
|
2012-08-16 19:19:54 +00:00
|
|
|
{
|
2019-09-05 16:06:03 +00:00
|
|
|
if (!scene()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// No scene, so it cannot be the overlay window.
|
2012-08-16 19:19:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
if (!scene()->overlayWindow()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// No overlay window, it cannot be the overlay.
|
2012-08-16 19:19:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
// Compare the window ID's.
|
2019-08-07 17:33:20 +00:00
|
|
|
return w == scene()->overlayWindow()->window();
|
2012-08-16 19:19:54 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
bool X11Compositor::isOverlayWindowVisible() const
|
2012-08-16 19:19:54 +00:00
|
|
|
{
|
2019-09-05 16:06:03 +00:00
|
|
|
if (!scene()) {
|
2012-08-16 19:19:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
if (!scene()->overlayWindow()) {
|
2012-08-16 19:19:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
return scene()->overlayWindow()->isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
int X11Compositor::refreshRate() const
|
|
|
|
{
|
|
|
|
return m_xrrRefreshRate;
|
|
|
|
}
|
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
void X11Compositor::updateClientCompositeBlocking(X11Client *c)
|
2019-08-07 17:33:20 +00:00
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
if (c) {
|
2019-08-07 17:33:20 +00:00
|
|
|
if (c->isBlockingCompositing()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Do NOT attempt to call suspend(true) from within the eventchain!
|
|
|
|
if (!(m_suspended & BlockRuleSuspend))
|
2019-09-26 15:09:16 +00:00
|
|
|
QMetaObject::invokeMethod(this, [this]() {
|
|
|
|
suspend(BlockRuleSuspend);
|
|
|
|
}, Qt::QueuedConnection);
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
else if (m_suspended & BlockRuleSuspend) {
|
|
|
|
// If !c we just check if we can resume in case a blocking client was lost.
|
2019-09-26 15:09:16 +00:00
|
|
|
bool shouldResume = true;
|
2019-08-08 12:34:22 +00:00
|
|
|
|
Drop some custom list typedefs
Summary:
Qt has its own thing where a type might also have corresponding list
alias, e.g. QObject and QObjectList, QWidget and QWidgetList. I don't
know why Qt does that, maybe for some historical reasons, but what
matters is that we copy this pattern here in KWin. While this pattern
might be useful with some long list types, for example
QList<QWeakPointer<TabBoxClient>> TabBoxClientList
in general, it causes more harm than good. For example, we've got two
new client types, do we need corresponding list typedefs for them? If
no, why do we have ClientList and so on?
Another problem with these typedefs is that you need to include utils.h
header in order to use them. A better way to handle such things is to
just forward declare a client class (if that's possible) and use it
directly with QList or QVector. This way translation units don't get
"bloated" with utils.h stuff for no apparent reason.
So, in order to make code more consistent and easier to follow, this
change drops some of our custom typedefs. Namely ConstClientList,
ClientList, DeletedList, UnmanagedList, ToplevelList, and GroupList.
Test Plan: Compiles.
Reviewers: #kwin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24950
2019-10-16 09:11:04 +00:00
|
|
|
for (auto it = Workspace::self()->clientList().constBegin();
|
2019-08-08 12:34:22 +00:00
|
|
|
it != Workspace::self()->clientList().constEnd(); ++it) {
|
2019-08-07 17:33:20 +00:00
|
|
|
if ((*it)->isBlockingCompositing()) {
|
2019-09-26 15:09:16 +00:00
|
|
|
shouldResume = false;
|
2019-08-07 17:33:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-26 15:09:16 +00:00
|
|
|
if (shouldResume) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Do NOT attempt to call suspend(false) from within the eventchain!
|
2019-09-26 15:09:16 +00:00
|
|
|
QMetaObject::invokeMethod(this, [this]() {
|
|
|
|
resume(BlockRuleSuspend);
|
|
|
|
}, Qt::QueuedConnection);
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-16 19:19:54 +00:00
|
|
|
}
|
|
|
|
|
[x11] Fix crash during tear down
Summary:
Any call made to a virtual method in constructor/destructor of a base
class won't go to a derived class because the base class may access
uninitialized or destroyed resources.
For example, let's consider the following two classes
class Base {
public:
Base() { foo()->bar(); }
virtual ~Base() { foo()->bar(); }
virtual Foo* foo() const { return nullptr; }
};
class Derived : public Base {
public:
Derived() : mFoo(new Foo) {}
~Derived() override { delete mFoo; }
Foo* foo() const override { return mFoo; }
private:
Foo* mFoo;
};
When an instance of Derived class is created, constructors will run in
the following order:
Base()
Derived()
It's not safe to dispatch foo() method call to Derived class because
constructor of Derived hasn't initialized yet mFoo.
Same story with destructors, they'll run in the following order:
~Derived()
~Base()
It's not safe to dispatch foo() method call in the destructor of Base
class to Derived class because mFoo was deleted.
So, what does that weird C++ behavior has something to do with KWin? Well,
recently Compositor class was split into two classes - WaylandCompositor,
and X11Compositor. Some functionality from X11 doesn't make sense on
Wayland. Therefore methods that implement that stuff were "purified," i.e.
they became pure virtual methods. Unfortunately, when Compositor tears
down it may call pure virtual methods on itself. Given that those calls
cannot be dispatched to X11Compositor or WaylandCompositor, the only
choice that C++ runtime has is to throw an exception.
The fix for this very delicate problem is very simple - do not call virtual
methods from constructors and the destructor. Avoid doing that if you can!
This change moves Compositor::updateClientCompositeBlocking to X11Compositor
so it longer has to be a virtual method. Also, it kind of doesn't make sense
to keep it in base Compositor class because compositing can be blocked only
on X11.
BUG: 411049
Test Plan: KWin no longer crashes when running kwin_x11 --replace command.
Reviewers: #kwin, romangg
Reviewed By: #kwin, romangg
Subscribers: anthonyfieroni, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23098
2019-08-30 16:28:50 +00:00
|
|
|
X11Compositor *X11Compositor::self()
|
|
|
|
{
|
|
|
|
return qobject_cast<X11Compositor *>(Compositor::self());
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
}
|
2019-06-22 10:40:12 +00:00
|
|
|
|
|
|
|
// included for CompositorSelectionOwner
|
|
|
|
#include "composite.moc"
|