diff --git a/abstract_backend.h b/abstract_backend.h
index 9136f088b1..54465e4c8f 100644
--- a/abstract_backend.h
+++ b/abstract_backend.h
@@ -19,12 +19,13 @@ along with this program. If not, see .
*********************************************************************/
#ifndef KWIN_ABSTRACT_BACKEND_H
#define KWIN_ABSTRACT_BACKEND_H
+#include
#include
namespace KWin
{
-class AbstractBackend : public QObject
+class KWIN_EXPORT AbstractBackend : public QObject
{
Q_OBJECT
public:
diff --git a/composite.cpp b/composite.cpp
index b3d7439718..a62ab3033d 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -39,6 +39,7 @@ along with this program. If not, see .
#include "xcbutils.h"
#if HAVE_WAYLAND
#include "wayland_backend.h"
+#include "wayland_server.h"
#endif
#include "decorations/decoratedclient.h"
@@ -118,9 +119,9 @@ Compositor::Compositor(QObject* workspace)
connect(&m_unusedSupportPropertyTimer, SIGNAL(timeout()), SLOT(deleteUnusedSupportProperties()));
#if HAVE_WAYLAND
if (kwinApp()->operationMode() != Application::OperationModeX11) {
- if (Wayland::WaylandBackend::self()) {
- connect(Wayland::WaylandBackend::self(), &Wayland::WaylandBackend::systemCompositorDied, this, &Compositor::finish);
- connect(Wayland::WaylandBackend::self(), &Wayland::WaylandBackend::backendReady, this, &Compositor::setup);
+ if (Wayland::WaylandBackend *w = dynamic_cast(waylandServer()->backend())) {
+ connect(w, &Wayland::WaylandBackend::systemCompositorDied, this, &Compositor::finish);
+ connect(w, &Wayland::WaylandBackend::backendReady, this, &Compositor::setup);
} else {
QMetaObject::invokeMethod(this, "setup", Qt::QueuedConnection);
}
diff --git a/egl_wayland_backend.cpp b/egl_wayland_backend.cpp
index 853664526c..eebfb66162 100644
--- a/egl_wayland_backend.cpp
+++ b/egl_wayland_backend.cpp
@@ -37,11 +37,11 @@ along with this program. If not, see .
namespace KWin
{
-EglWaylandBackend::EglWaylandBackend()
+EglWaylandBackend::EglWaylandBackend(Wayland::WaylandBackend *b)
: QObject(NULL)
, AbstractEglBackend()
, m_bufferAge(0)
- , m_wayland(Wayland::WaylandBackend::self())
+ , m_wayland(b)
, m_overlay(NULL)
{
if (!m_wayland) {
diff --git a/egl_wayland_backend.h b/egl_wayland_backend.h
index 5a44936c4c..af2a4972d8 100644
--- a/egl_wayland_backend.h
+++ b/egl_wayland_backend.h
@@ -51,7 +51,7 @@ class EglWaylandBackend : public QObject, public AbstractEglBackend
{
Q_OBJECT
public:
- EglWaylandBackend();
+ EglWaylandBackend(Wayland::WaylandBackend *b);
virtual ~EglWaylandBackend();
virtual void screenGeometryChanged(const QSize &size);
virtual SceneOpenGL::TexturePrivate *createBackendTexture(SceneOpenGL::Texture *texture);
diff --git a/main_wayland.cpp b/main_wayland.cpp
index 5983d45ec3..d7a1fe5837 100644
--- a/main_wayland.cpp
+++ b/main_wayland.cpp
@@ -88,7 +88,7 @@ void ApplicationWayland::performStartup()
// try creating the Wayland Backend
createInput();
createBackend();
- if (X11WindowedBackend::self()) {
+ if (dynamic_cast(waylandServer()->backend())) {
continueStartupWithScreens();
}
}
@@ -98,7 +98,7 @@ void ApplicationWayland::createBackend()
AbstractBackend *backend = nullptr;
if (m_windowed) {
if (!m_waylandDisplay.isEmpty()) {
- Wayland::WaylandBackend *b = Wayland::WaylandBackend::create(m_waylandDisplay, this);
+ Wayland::WaylandBackend *b = new Wayland::WaylandBackend(m_waylandDisplay, this);
connect(b, &Wayland::WaylandBackend::connectionFailed, this,
[] () {
fputs(i18n("kwin_wayland: could not connect to Wayland Server, ensure WAYLAND_DISPLAY is set.\n").toLocal8Bit().constData(), stderr);
@@ -109,7 +109,7 @@ void ApplicationWayland::createBackend()
backend = b;
}
if (!backend && !m_x11Display.isEmpty()) {
- KWin::X11WindowedBackend *x11Backend = KWin::X11WindowedBackend::create(m_x11Display, m_backendSize, this);
+ KWin::X11WindowedBackend *x11Backend = new KWin::X11WindowedBackend(m_x11Display, m_backendSize, this);
if (x11Backend->isValid()) {
backend = x11Backend;
waylandServer()->seat()->setHasPointer(true);
@@ -128,8 +128,8 @@ void ApplicationWayland::createBackend()
void ApplicationWayland::continueStartupWithScreens()
{
- if (Wayland::WaylandBackend::self()) {
- disconnect(Wayland::WaylandBackend::self(), &Wayland::WaylandBackend::outputsChanged, this, &ApplicationWayland::continueStartupWithScreens);
+ if (Wayland::WaylandBackend *w = dynamic_cast(waylandServer()->backend())) {
+ disconnect(w, &Wayland::WaylandBackend::outputsChanged, this, &ApplicationWayland::continueStartupWithScreens);
}
createScreens();
waylandServer()->initOutputs();
diff --git a/scene_opengl.cpp b/scene_opengl.cpp
index 1793004c7a..2a4e4f40c8 100644
--- a/scene_opengl.cpp
+++ b/scene_opengl.cpp
@@ -33,6 +33,7 @@ along with this program. If not, see .
#if HAVE_WAYLAND_EGL
#include "egl_wayland_backend.h"
#include "wayland_backend.h"
+#include "wayland_server.h"
#endif
#if HAVE_X11_XCB
#include "x11windowed_backend.h"
@@ -500,13 +501,15 @@ SceneOpenGL *SceneOpenGL::createScene(QObject *parent)
#ifdef KWIN_HAVE_EGL
if (kwinApp()->shouldUseWaylandForCompositing()) {
#if HAVE_WAYLAND_EGL
- if (Wayland::WaylandBackend::self()) {
- backend = new EglWaylandBackend();
+ if (Wayland::WaylandBackend *b = dynamic_cast(waylandServer()->backend())) {
+ backend = new EglWaylandBackend(b);
}
#endif
#if HAVE_X11_XCB
- if (!backend && X11WindowedBackend::self()) {
- backend = new EglOnXBackend(X11WindowedBackend::self());
+ if (!backend) {
+ if (X11WindowedBackend *b = dynamic_cast(waylandServer()->backend())) {
+ backend = new EglOnXBackend(b);
+ }
}
#endif
} else {
diff --git a/scene_qpainter.cpp b/scene_qpainter.cpp
index 3aea1deeae..0bafc01ffd 100644
--- a/scene_qpainter.cpp
+++ b/scene_qpainter.cpp
@@ -27,6 +27,7 @@ along with this program. If not, see .
#include "toplevel.h"
#if HAVE_WAYLAND
#include "wayland_backend.h"
+#include "wayland_server.h"
#include "x11windowed_backend.h"
#include
#include
@@ -81,16 +82,17 @@ void QPainterBackend::setFailed(const QString &reason)
// WaylandQPainterBackend
//****************************************
-WaylandQPainterBackend::WaylandQPainterBackend()
+WaylandQPainterBackend::WaylandQPainterBackend(Wayland::WaylandBackend *b)
: QPainterBackend()
+ , m_backend(b)
, m_needsFullRepaint(true)
, m_backBuffer(QImage(QSize(), QImage::Format_RGB32))
, m_buffer()
{
- connect(Wayland::WaylandBackend::self()->shmPool(), SIGNAL(poolResized()), SLOT(remapBuffer()));
- connect(Wayland::WaylandBackend::self(), &Wayland::WaylandBackend::shellSurfaceSizeChanged,
+ connect(b->shmPool(), SIGNAL(poolResized()), SLOT(remapBuffer()));
+ connect(b, &Wayland::WaylandBackend::shellSurfaceSizeChanged,
this, &WaylandQPainterBackend::screenGeometryChanged);
- connect(Wayland::WaylandBackend::self()->surface(), &KWayland::Client::Surface::frameRendered,
+ connect(b->surface(), &KWayland::Client::Surface::frameRendered,
Compositor::self(), &Compositor::bufferSwapComplete);
}
@@ -114,7 +116,7 @@ void WaylandQPainterBackend::present(int mask, const QRegion &damage)
}
Compositor::self()->aboutToSwapBuffers();
m_needsFullRepaint = false;
- auto s = Wayland::WaylandBackend::self()->surface();
+ auto s = m_backend->surface();
s->attachBuffer(m_buffer);
s->damage(damage);
s->commit();
@@ -149,8 +151,8 @@ void WaylandQPainterBackend::prepareRenderingFrame()
}
}
m_buffer.clear();
- const QSize size(Wayland::WaylandBackend::self()->shellSurfaceSize());
- m_buffer = Wayland::WaylandBackend::self()->shmPool()->getBuffer(size, size.width() * 4);
+ const QSize size(m_backend->shellSurfaceSize());
+ m_buffer = m_backend->shmPool()->getBuffer(size, size.width() * 4);
if (!m_buffer) {
qCDebug(KWIN_CORE) << "Did not get a new Buffer from Shm Pool";
m_backBuffer = QImage();
@@ -186,16 +188,17 @@ bool WaylandQPainterBackend::needsFullRepaint() const
//****************************************
// X11WindowedBackend
//****************************************
-X11WindowedQPainterBackend::X11WindowedQPainterBackend()
+X11WindowedQPainterBackend::X11WindowedQPainterBackend(X11WindowedBackend *backend)
: QPainterBackend()
- , m_backBuffer(X11WindowedBackend::self()->size(), QImage::Format_RGB32)
+ , m_backBuffer(backend->size(), QImage::Format_RGB32)
+ , m_backend(backend)
{
}
X11WindowedQPainterBackend::~X11WindowedQPainterBackend()
{
if (m_gc) {
- xcb_free_gc(X11WindowedBackend::self()->connection(), m_gc);
+ xcb_free_gc(m_backend->connection(), m_gc);
}
}
@@ -226,8 +229,8 @@ void X11WindowedQPainterBackend::present(int mask, const QRegion &damage)
{
Q_UNUSED(mask)
Q_UNUSED(damage)
- xcb_connection_t *c = X11WindowedBackend::self()->connection();
- const xcb_window_t window = X11WindowedBackend::self()->window();
+ xcb_connection_t *c = m_backend->connection();
+ const xcb_window_t window = m_backend->window();
if (m_gc == XCB_NONE) {
m_gc = xcb_generate_id(c);
xcb_create_gc(c, m_gc, window, 0, nullptr);
@@ -253,10 +256,10 @@ SceneQPainter *SceneQPainter::createScene(QObject *parent)
QScopedPointer backend;
#if HAVE_WAYLAND
if (kwinApp()->shouldUseWaylandForCompositing()) {
- if (X11WindowedBackend::self()) {
- backend.reset(new X11WindowedQPainterBackend);
- } else {
- backend.reset(new WaylandQPainterBackend);
+ if (X11WindowedBackend *b = dynamic_cast(waylandServer()->backend())) {
+ backend.reset(new X11WindowedQPainterBackend(b));
+ } else if (Wayland::WaylandBackend *b = dynamic_cast(waylandServer()->backend())) {
+ backend.reset(new WaylandQPainterBackend(b));
}
if (backend->isFailed()) {
return NULL;
diff --git a/scene_qpainter.h b/scene_qpainter.h
index e80d599d1d..5106c1fc09 100644
--- a/scene_qpainter.h
+++ b/scene_qpainter.h
@@ -40,6 +40,12 @@ namespace Xcb {
class Shm;
}
+namespace Wayland
+{
+class WaylandBackend;
+}
+class X11WindowedBackend;
+
class QPainterBackend
{
public:
@@ -108,7 +114,7 @@ class WaylandQPainterBackend : public QObject, public QPainterBackend
{
Q_OBJECT
public:
- WaylandQPainterBackend();
+ explicit WaylandQPainterBackend(Wayland::WaylandBackend *b);
virtual ~WaylandQPainterBackend();
virtual void present(int mask, const QRegion& damage) override;
@@ -120,6 +126,7 @@ public:
private Q_SLOTS:
void remapBuffer();
private:
+ Wayland::WaylandBackend *m_backend;
bool m_needsFullRepaint;
QImage m_backBuffer;
QWeakPointer m_buffer;
@@ -129,7 +136,7 @@ class X11WindowedQPainterBackend : public QObject, public QPainterBackend
{
Q_OBJECT
public:
- X11WindowedQPainterBackend();
+ X11WindowedQPainterBackend(X11WindowedBackend *backend);
virtual ~X11WindowedQPainterBackend();
QImage *buffer() override;
@@ -143,6 +150,7 @@ private:
bool m_needsFullRepaint = true;
xcb_gcontext_t m_gc = XCB_NONE;
QImage m_backBuffer;
+ X11WindowedBackend *m_backend;
};
#endif
diff --git a/screens.cpp b/screens.cpp
index 2890832dbe..d2473ce9b7 100644
--- a/screens.cpp
+++ b/screens.cpp
@@ -27,6 +27,7 @@ along with this program. If not, see .
#if HAVE_WAYLAND
#include "screens_wayland.h"
#include "wayland_backend.h"
+#include "wayland_server.h"
#include "x11windowed_backend.h"
#include "screens_x11windowed.h"
#endif
@@ -46,10 +47,10 @@ Screens *Screens::create(QObject *parent)
#else
#if HAVE_WAYLAND
if (kwinApp()->shouldUseWaylandForCompositing()) {
- if (X11WindowedBackend::self()) {
- s_self = new X11WindowedScreens(parent);
- } else if (Wayland::WaylandBackend::self()) {
- s_self = new WaylandScreens(parent);
+ if (X11WindowedBackend *b = dynamic_cast(waylandServer()->backend())) {
+ s_self = new X11WindowedScreens(b, parent);
+ } else if (Wayland::WaylandBackend *b = dynamic_cast(waylandServer()->backend())) {
+ s_self = new WaylandScreens(b, parent);
}
}
#endif
diff --git a/screens_wayland.cpp b/screens_wayland.cpp
index ed5b051a47..07f0e41b77 100644
--- a/screens_wayland.cpp
+++ b/screens_wayland.cpp
@@ -32,8 +32,9 @@ along with this program. If not, see .
namespace KWin
{
-WaylandScreens::WaylandScreens(QObject* parent)
+WaylandScreens::WaylandScreens(Wayland::WaylandBackend *backend, QObject* parent)
: Screens(parent)
+ , m_backend(backend)
{
}
@@ -44,7 +45,7 @@ WaylandScreens::~WaylandScreens()
void WaylandScreens::init()
{
Screens::init();
- connect(Wayland::WaylandBackend::self(), &Wayland::WaylandBackend::outputsChanged,
+ connect(m_backend, &Wayland::WaylandBackend::outputsChanged,
this, &WaylandScreens::startChangedTimer);
updateCount();
}
@@ -87,7 +88,7 @@ void WaylandScreens::updateCount()
{
m_geometries.clear();
int count = 0;
- const QList &outputs = Wayland::WaylandBackend::self()->outputs();
+ const QList &outputs = m_backend->outputs();
for (auto it = outputs.begin(); it != outputs.end(); ++it) {
if ((*it)->pixelSize().isEmpty()) {
continue;
diff --git a/screens_wayland.h b/screens_wayland.h
index 0063df1b0b..ae3c05bcd4 100644
--- a/screens_wayland.h
+++ b/screens_wayland.h
@@ -25,11 +25,16 @@ along with this program. If not, see .
namespace KWin
{
+namespace Wayland
+{
+class WaylandBackend;
+}
+
class WaylandScreens : public Screens
{
Q_OBJECT
public:
- explicit WaylandScreens(QObject *parent);
+ explicit WaylandScreens(Wayland::WaylandBackend *backend, QObject *parent);
virtual ~WaylandScreens();
void init() override;
QRect geometry(int screen) const override;
@@ -40,6 +45,7 @@ protected Q_SLOTS:
void updateCount() override;
private:
void updateXRandr();
+ Wayland::WaylandBackend *m_backend;
QList m_geometries;
};
diff --git a/screens_x11windowed.cpp b/screens_x11windowed.cpp
index 8e8039c0bc..ef8f10dfe9 100644
--- a/screens_x11windowed.cpp
+++ b/screens_x11windowed.cpp
@@ -23,8 +23,9 @@ along with this program. If not, see .
namespace KWin
{
-X11WindowedScreens::X11WindowedScreens(QObject *parent)
+X11WindowedScreens::X11WindowedScreens(X11WindowedBackend *backend, QObject *parent)
: Screens(parent)
+ , m_backend(backend)
{
}
@@ -33,7 +34,7 @@ X11WindowedScreens::~X11WindowedScreens() = default;
void X11WindowedScreens::init()
{
KWin::Screens::init();
- connect(X11WindowedBackend::self(), &X11WindowedBackend::sizeChanged,
+ connect(m_backend, &X11WindowedBackend::sizeChanged,
this, &X11WindowedScreens::startChangedTimer);
updateCount();
emit changed();
@@ -50,7 +51,7 @@ QRect X11WindowedScreens::geometry(int screen) const
QSize X11WindowedScreens::size(int screen) const
{
if (screen == 0) {
- return X11WindowedBackend::self()->size();
+ return m_backend->size();
}
return QSize();
}
diff --git a/screens_x11windowed.h b/screens_x11windowed.h
index 5b47d86771..a1b21f5042 100644
--- a/screens_x11windowed.h
+++ b/screens_x11windowed.h
@@ -23,18 +23,22 @@ along with this program. If not, see .
namespace KWin
{
+class X11WindowedBackend;
class X11WindowedScreens : public Screens
{
Q_OBJECT
public:
- X11WindowedScreens(QObject *parent = nullptr);
+ X11WindowedScreens(X11WindowedBackend *backend, QObject *parent = nullptr);
virtual ~X11WindowedScreens();
void init() override;
QRect geometry(int screen) const override;
int number(const QPoint &pos) const override;
QSize size(int screen) const override;
void updateCount() override;
+
+private:
+ X11WindowedBackend *m_backend;
};
}
diff --git a/wayland_backend.cpp b/wayland_backend.cpp
index 4587a06e28..b7d7983329 100644
--- a/wayland_backend.cpp
+++ b/wayland_backend.cpp
@@ -355,14 +355,6 @@ void WaylandCursor::setCursorImage(Qt::CursorShape shape)
#endif
}
-WaylandBackend *WaylandBackend::s_self = 0;
-WaylandBackend *WaylandBackend::create(const QByteArray &display, QObject *parent)
-{
- Q_ASSERT(!s_self);
- s_self = new WaylandBackend(display, parent);
- return s_self;
-}
-
WaylandBackend::WaylandBackend(const QByteArray &display, QObject *parent)
: AbstractBackend(parent)
, m_display(nullptr)
@@ -449,7 +441,6 @@ WaylandBackend::~WaylandBackend()
m_connectionThread->wait();
qCDebug(KWIN_CORE) << "Destroyed Wayland display";
- s_self = NULL;
}
void WaylandBackend::destroyOutputs()
diff --git a/wayland_backend.h b/wayland_backend.h
index 7a6ca5f7bb..c8b756e23e 100644
--- a/wayland_backend.h
+++ b/wayland_backend.h
@@ -153,6 +153,7 @@ class KWIN_EXPORT WaylandBackend : public AbstractBackend
{
Q_OBJECT
public:
+ explicit WaylandBackend(const QByteArray &display, QObject *parent = nullptr);
virtual ~WaylandBackend();
wl_display *display();
KWayland::Client::Compositor *compositor();
@@ -165,11 +166,6 @@ public:
void installCursorImage(Qt::CursorShape shape) override;
void installCursorFromServer() override;
- static WaylandBackend *create(const QByteArray &display, QObject *parent = nullptr);
- static WaylandBackend *self() {
- return s_self;
- }
-
protected:
void connectNotify(const QMetaMethod &signal) override;
@@ -180,7 +176,6 @@ Q_SIGNALS:
void outputsChanged();
void connectionFailed();
private:
- explicit WaylandBackend(const QByteArray &display, QObject *parent = nullptr);
void initConnection();
void createSurface();
void destroyOutputs();
@@ -201,7 +196,6 @@ private:
KWayland::Client::SubCompositor *m_subCompositor;
WaylandCursor *m_cursor;
bool m_ready = false;
- static WaylandBackend *s_self;
};
inline
diff --git a/x11windowed_backend.cpp b/x11windowed_backend.cpp
index bc455afa74..005c37696f 100644
--- a/x11windowed_backend.cpp
+++ b/x11windowed_backend.cpp
@@ -41,15 +41,6 @@ along with this program. If not, see .
namespace KWin
{
-X11WindowedBackend *X11WindowedBackend::s_self = nullptr;
-
-X11WindowedBackend *X11WindowedBackend::create(const QByteArray &display, const QSize &size, QObject *parent)
-{
- Q_ASSERT(!s_self);
- s_self = new X11WindowedBackend(display, size, parent);
- return s_self;
-}
-
X11WindowedBackend::X11WindowedBackend(const QByteArray &display, const QSize &size, QObject *parent)
: AbstractBackend(parent)
, m_size(size)
@@ -97,7 +88,6 @@ X11WindowedBackend::~X11WindowedBackend()
}
xcb_disconnect(m_connection);
}
- s_self = nullptr;
}
void X11WindowedBackend::createWindow()
diff --git a/x11windowed_backend.h b/x11windowed_backend.h
index 135f199089..b00a53e643 100644
--- a/x11windowed_backend.h
+++ b/x11windowed_backend.h
@@ -39,6 +39,7 @@ class KWIN_EXPORT X11WindowedBackend : public AbstractBackend
Q_OBJECT
Q_PROPERTY(QSize size READ size NOTIFY sizeChanged)
public:
+ X11WindowedBackend(const QByteArray &display, const QSize &size, QObject *parent);
virtual ~X11WindowedBackend();
xcb_connection_t *connection() const {
@@ -65,14 +66,10 @@ public:
void installCursorFromServer() override;
- static X11WindowedBackend *self();
- static X11WindowedBackend *create(const QByteArray &display, const QSize &size, QObject *parent);
-
Q_SIGNALS:
void sizeChanged();
private:
- X11WindowedBackend(const QByteArray &display, const QSize &size, QObject *parent);
void createWindow();
void startEventReading();
void handleEvent(xcb_generic_event_t *event);
@@ -90,14 +87,8 @@ private:
xcb_atom_t m_deleteWindowProtocol = XCB_ATOM_NONE;
xcb_cursor_t m_cursor = XCB_CURSOR_NONE;
Display *m_display = nullptr;
- static X11WindowedBackend *s_self;
};
-inline X11WindowedBackend *X11WindowedBackend::self()
-{
- return s_self;
-}
-
}
#endif