diff --git a/plugins/platforms/wayland/wayland_backend.h b/plugins/platforms/wayland/wayland_backend.h --- a/plugins/platforms/wayland/wayland_backend.h +++ b/plugins/platforms/wayland/wayland_backend.h @@ -53,6 +53,8 @@ class ShellSurface; class Surface; class Touch; +class XdgShell; +class XdgShellSurface; } } @@ -132,13 +134,17 @@ private: void initConnection(); void createSurface(); + template + void setupSurface(T *surface); wl_display *m_display; KWayland::Client::EventQueue *m_eventQueue; KWayland::Client::Registry *m_registry; KWayland::Client::Compositor *m_compositor; KWayland::Client::Shell *m_shell; KWayland::Client::Surface *m_surface; KWayland::Client::ShellSurface *m_shellSurface; + KWayland::Client::XdgShell *m_xdgShell = nullptr; + KWayland::Client::XdgShellSurface *m_xdgShellSurface = nullptr; QScopedPointer m_seat; KWayland::Client::ShmPool *m_shm; KWayland::Client::ConnectionThread *m_connectionThreadObject; diff --git a/plugins/platforms/wayland/wayland_backend.cpp b/plugins/platforms/wayland/wayland_backend.cpp --- a/plugins/platforms/wayland/wayland_backend.cpp +++ b/plugins/platforms/wayland/wayland_backend.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -281,12 +282,18 @@ WaylandBackend::~WaylandBackend() { + if (m_xdgShellSurface) { + m_xdgShellSurface->release(); + } if (m_shellSurface) { m_shellSurface->release(); } if (m_surface) { m_surface->release(); } + if (m_xdgShell) { + m_xdgShell->release(); + } m_shell->release(); m_compositor->release(); m_registry->release(); @@ -361,6 +368,11 @@ emit systemCompositorDied(); m_seat.reset(); m_shm->destroy(); + if (m_xdgShellSurface) { + m_xdgShellSurface->destroy(); + delete m_xdgShellSurface; + m_xdgShellSurface = nullptr; + } if (m_shellSurface) { m_shellSurface->destroy(); delete m_shellSurface; @@ -374,6 +386,9 @@ if (m_shell) { m_shell->destroy(); } + if (m_xdgShell) { + m_xdgShell->destroy(); + } m_compositor->destroy(); m_registry->destroy(); m_eventQueue->destroy(); @@ -414,21 +429,41 @@ if (m_seat) { m_seat->setInstallCursor(true); } + // check for xdg shell + auto xdgIface = m_registry->interface(Registry::Interface::XdgShellUnstableV5); + if (xdgIface.name != 0) { + m_xdgShell = m_registry->createXdgShell(xdgIface.name, xdgIface.version, this); + if (m_xdgShell && m_xdgShell->isValid()) { + m_xdgShellSurface = m_xdgShell->createSurface(m_surface, this); + connect(m_xdgShellSurface, &XdgShellSurface::closeRequested, qApp, &QCoreApplication::quit); + setupSurface(m_xdgShellSurface); + return; + } + } if (m_shell->isValid()) { m_shellSurface = m_shell->createSurface(m_surface, this); - connect(m_shellSurface, &ShellSurface::sizeChanged, this, &WaylandBackend::shellSurfaceSizeChanged); - m_shellSurface->setSize(initialWindowSize()); + setupSurface(m_shellSurface); m_shellSurface->setToplevel(); - setReady(true); - emit screensQueried(); } } +template +void WaylandBackend::setupSurface(T *surface) +{ + connect(surface, &T::sizeChanged, this, &WaylandBackend::shellSurfaceSizeChanged); + surface->setSize(initialWindowSize()); + setReady(true); + emit screensQueried(); +} + QSize WaylandBackend::shellSurfaceSize() const { if (m_shellSurface) { return m_shellSurface->size(); } + if (m_xdgShellSurface) { + return m_xdgShellSurface->size(); + } return QSize(); }