diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6fcbf2dd80..00151a19f7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -427,6 +427,7 @@ if(Wayland_Client_FOUND AND XKB_FOUND)
${kwin_KDEINIT_SRCS}
wayland_backend.cpp
wayland_client/buffer.cpp
+ wayland_client/compositor.cpp
wayland_client/connection_thread.cpp
wayland_client/registry.cpp
wayland_client/fullscreen_shell.cpp
diff --git a/autotests/wayland_client/CMakeLists.txt b/autotests/wayland_client/CMakeLists.txt
index 98938f3cff..e14fc85ab9 100644
--- a/autotests/wayland_client/CMakeLists.txt
+++ b/autotests/wayland_client/CMakeLists.txt
@@ -62,6 +62,7 @@ ecm_mark_as_test(testWaylandOutput)
########################################################
set( testWaylandShell_SRCS
test_wayland_shell.cpp
+ ${KWIN_SOURCE_DIR}/wayland_client/compositor.cpp
${KWIN_SOURCE_DIR}/wayland_client/connection_thread.cpp
${KWIN_SOURCE_DIR}/wayland_client/registry.cpp
${KWIN_SOURCE_DIR}/wayland_client/fullscreen_shell.cpp
diff --git a/autotests/wayland_client/test_wayland_shell.cpp b/autotests/wayland_client/test_wayland_shell.cpp
index 09ff052403..7dcb95b198 100644
--- a/autotests/wayland_client/test_wayland_shell.cpp
+++ b/autotests/wayland_client/test_wayland_shell.cpp
@@ -20,6 +20,7 @@ along with this program. If not, see .
// Qt
#include
// KWin
+#include "../../wayland_client/compositor.h"
#include "../../wayland_client/connection_thread.h"
#include "../../wayland_client/shell.h"
#include "../../wayland_client/surface.h"
@@ -147,14 +148,16 @@ void TestWaylandShell::testShell()
if (compositorSpy.isEmpty()) {
QVERIFY(compositorSpy.wait());
}
- wl_compositor *compositor = registry.bindCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value());
+ KWin::Wayland::Compositor compositor;
+ compositor.setup(registry.bindCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value()));
KWin::Wayland::Shell shell;
shell.setup(registry.bindShell(announced.first().first().value(), announced.first().last().value()));
wl_display_flush(connection.display());
- KWin::Wayland::Surface s;
- s.setup(wl_compositor_create_surface(compositor));
- KWin::Wayland::ShellSurface *surface = shell.createSurface(&s, &shell);
+ QScopedPointer s(compositor.createSurface());
+ QVERIFY(!s.isNull());
+ QVERIFY(s->isValid());
+ KWin::Wayland::ShellSurface *surface = shell.createSurface(s.data(), &shell);
QSignalSpy sizeSpy(surface, SIGNAL(sizeChanged(QSize)));
QVERIFY(sizeSpy.isValid());
QCOMPARE(surface->size(), QSize());
@@ -170,8 +173,7 @@ void TestWaylandShell::testShell()
shell.release();
QVERIFY(!surface->isValid());
- s.release();
- wl_compositor_destroy(compositor);
+ compositor.release();
}
QTEST_MAIN(TestWaylandShell)
diff --git a/wayland_backend.cpp b/wayland_backend.cpp
index 0588ffc1fe..147d97a4d6 100644
--- a/wayland_backend.cpp
+++ b/wayland_backend.cpp
@@ -23,6 +23,7 @@ along with this program. If not, see .
#include "cursor.h"
#include "input.h"
#include "wayland_client/buffer.h"
+#include "wayland_client/compositor.h"
#include "wayland_client/connection_thread.h"
#include "wayland_client/fullscreen_shell.h"
#include "wayland_client/output.h"
@@ -284,9 +285,6 @@ WaylandSeat::~WaylandSeat()
if (m_seat) {
wl_seat_destroy(m_seat);
}
- if (m_cursor) {
- wl_surface_destroy(m_cursor);
- }
destroyTheme();
}
@@ -342,12 +340,15 @@ void WaylandSeat::installCursorImage(wl_buffer *image, const QSize &size, const
return;
}
if (!m_cursor) {
- m_cursor = wl_compositor_create_surface(m_backend->compositor());
+ m_cursor = m_backend->compositor()->createSurface(this);
}
- wl_pointer_set_cursor(m_pointer, m_enteredSerial, m_cursor, hotSpot.x(), hotSpot.y());
- wl_surface_attach(m_cursor, image, 0, 0);
- wl_surface_damage(m_cursor, 0, 0, size.width(), size.height());
- wl_surface_commit(m_cursor);
+ if (!m_cursor || !m_cursor->isValid()) {
+ return;
+ }
+ wl_pointer_set_cursor(m_pointer, m_enteredSerial, *m_cursor, hotSpot.x(), hotSpot.y());
+ m_cursor->attachBuffer(image);
+ m_cursor->damage(QRect(QPoint(0,0), size));
+ m_cursor->commit(Surface::CommitFlag::None);
}
void WaylandSeat::installCursorImage(Qt::CursorShape shape)
@@ -403,9 +404,9 @@ WaylandBackend::WaylandBackend(QObject *parent)
, m_display(nullptr)
, m_eventQueue(nullptr)
, m_registry(new Registry(this))
- , m_compositor(NULL)
+ , m_compositor(new Compositor(this))
, m_shell(new Shell(this))
- , m_surface(new Surface(this))
+ , m_surface(nullptr)
, m_shellSurface(NULL)
, m_seat()
, m_shm(new ShmPool(this))
@@ -425,7 +426,7 @@ WaylandBackend::WaylandBackend(QObject *parent)
connect(this, &WaylandBackend::shellSurfaceSizeChanged, this, &WaylandBackend::checkBackendReady);
connect(m_registry, &Registry::compositorAnnounced, this,
[this](quint32 name) {
- setCompositor(m_registry->bindCompositor(name, 1));
+ m_compositor->setup(m_registry->bindCompositor(name, 1));
}
);
connect(m_registry, &Registry::shellAnnounced, this,
@@ -461,11 +462,11 @@ WaylandBackend::~WaylandBackend()
m_shellSurface->release();
}
m_fullscreenShell->release();
- m_surface->release();
- m_shell->release();
- if (m_compositor) {
- wl_compositor_destroy(m_compositor);
+ if (m_surface) {
+ m_surface->release();
}
+ m_shell->release();
+ m_compositor->release();
m_registry->release();
m_seat.reset();
m_shm->release();
@@ -519,14 +520,15 @@ void WaylandBackend::initConnection()
m_shellSurface = nullptr;
}
m_fullscreenShell->destroy();
- m_surface->destroy();
+ if (m_surface) {
+ m_surface->destroy();
+ delete m_surface;
+ m_surface = nullptr;
+ }
if (m_shell) {
m_shell->destroy();
}
- if (m_compositor) {
- free(m_compositor);
- m_compositor = nullptr;
- }
+ m_compositor->destroy();
m_registry->destroy();
if (m_display) {
m_display = nullptr;
@@ -557,8 +559,8 @@ void WaylandBackend::installCursorImage(Qt::CursorShape shape)
void WaylandBackend::createSurface()
{
- m_surface->setup(wl_compositor_create_surface(m_compositor));
- if (!m_surface->isValid()) {
+ m_surface = m_compositor->createSurface(this);
+ if (!m_surface || !m_surface->isValid()) {
qCritical() << "Creating Wayland Surface failed";
return;
}
diff --git a/wayland_backend.h b/wayland_backend.h
index f9b9a3fdb1..34a92fc2b5 100644
--- a/wayland_backend.h
+++ b/wayland_backend.h
@@ -45,6 +45,7 @@ namespace Wayland
class ShmPool;
class WaylandBackend;
class WaylandSeat;
+class Compositor;
class ConnectionThread;
class FullscreenShell;
class Output;
@@ -108,7 +109,7 @@ private:
wl_seat *m_seat;
wl_pointer *m_pointer;
wl_keyboard *m_keyboard;
- wl_surface *m_cursor;
+ Surface *m_cursor;
wl_cursor_theme *m_theme;
uint32_t m_enteredSerial;
QScopedPointer m_cursorTracker;
@@ -128,8 +129,7 @@ public:
virtual ~WaylandBackend();
wl_display *display();
wl_registry *registry();
- void setCompositor(wl_compositor *c);
- wl_compositor *compositor();
+ Compositor *compositor();
void addOutput(wl_output *o);
const QList