From bcb38f366daec8e82b935c3e4074536c3975915c Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 15 Nov 2022 10:21:21 +0200 Subject: [PATCH] backends/wayland: Port to xdg-decoration-v1 The server-decoration protocol is deprecated, and the clients should use the xdg-decoration-v1 protocol instead. kwin will indicate that it wants server side decoration. If the host compositor insists on client-side decorations, the wayland backend will render no csd. However, this is de-facto state at the moment too, perhaps it can be improved by using libdecor? Regardless, no csd is the current state too, except that both host and nested compositors can enter a loop where one side says to use CSD and the other side says that they want SSD. --- src/backends/wayland/wayland_display.cpp | 16 ++++++++-------- src/backends/wayland/wayland_display.h | 6 +++--- src/backends/wayland/wayland_output.cpp | 17 +++++++---------- src/backends/wayland/wayland_output.h | 4 ++-- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/backends/wayland/wayland_display.cpp b/src/backends/wayland/wayland_display.cpp index 04da98acba..3f483e6424 100644 --- a/src/backends/wayland/wayland_display.cpp +++ b/src/backends/wayland/wayland_display.cpp @@ -13,9 +13,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -30,7 +30,7 @@ #include "wayland-pointer-constraints-unstable-v1-client-protocol.h" #include "wayland-pointer-gestures-unstable-v1-server-protocol.h" #include "wayland-relative-pointer-unstable-v1-client-protocol.h" -#include "wayland-server-decoration-client-protocol.h" +#include "wayland-xdg-decoration-unstable-v1-client-protocol.h" #include "wayland-xdg-shell-client-protocol.h" namespace KWin @@ -160,7 +160,7 @@ WaylandDisplay::~WaylandDisplay() m_pointerGestures.reset(); m_relativePointerManager.reset(); m_seat.reset(); - m_serverSideDecorationManager.reset(); + m_xdgDecorationManager.reset(); m_shmPool.reset(); m_subCompositor.reset(); m_xdgShell.reset(); @@ -245,9 +245,9 @@ KWayland::Client::XdgShell *WaylandDisplay::xdgShell() const return m_xdgShell.get(); } -KWayland::Client::ServerSideDecorationManager *WaylandDisplay::serverSideDecorationManager() const +KWayland::Client::XdgDecorationManager *WaylandDisplay::xdgDecorationManager() const { - return m_serverSideDecorationManager.get(); + return m_xdgDecorationManager.get(); } void WaylandDisplay::registry_global(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t version) @@ -281,9 +281,9 @@ void WaylandDisplay::registry_global(void *data, wl_registry *registry, uint32_t } else if (strcmp(interface, zwp_relative_pointer_manager_v1_interface.name) == 0) { display->m_relativePointerManager = std::make_unique(); display->m_relativePointerManager->setup(static_cast(wl_registry_bind(registry, name, &zwp_relative_pointer_manager_v1_interface, std::min(version, 1u)))); - } else if (strcmp(interface, org_kde_kwin_server_decoration_manager_interface.name) == 0) { - display->m_serverSideDecorationManager = std::make_unique(); - display->m_serverSideDecorationManager->setup(static_cast(wl_registry_bind(registry, name, &org_kde_kwin_server_decoration_manager_interface, std::min(version, 1u)))); + } else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) { + display->m_xdgDecorationManager = std::make_unique(); + display->m_xdgDecorationManager->setup(static_cast(wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, std::min(version, 1u)))); } } diff --git a/src/backends/wayland/wayland_display.h b/src/backends/wayland/wayland_display.h index 8f34f799b7..0975321ce4 100644 --- a/src/backends/wayland/wayland_display.h +++ b/src/backends/wayland/wayland_display.h @@ -22,9 +22,9 @@ class PointerConstraints; class PointerGestures; class RelativePointerManager; class Seat; -class ServerSideDecorationManager; class ShmPool; class SubCompositor; +class XdgDecorationManager; class XdgShell; } } @@ -52,7 +52,7 @@ public: KWayland::Client::PointerGestures *pointerGestures() const; KWayland::Client::RelativePointerManager *relativePointerManager() const; KWayland::Client::Seat *seat() const; - KWayland::Client::ServerSideDecorationManager *serverSideDecorationManager() const; + KWayland::Client::XdgDecorationManager *xdgDecorationManager() const; KWayland::Client::ShmPool *shmPool() const; KWayland::Client::SubCompositor *subCompositor() const; KWayland::Client::XdgShell *xdgShell() const; @@ -72,7 +72,7 @@ private: std::unique_ptr m_pointerGestures; std::unique_ptr m_relativePointerManager; std::unique_ptr m_seat; - std::unique_ptr m_serverSideDecorationManager; + std::unique_ptr m_xdgDecorationManager; std::unique_ptr m_shmPool; std::unique_ptr m_subCompositor; std::unique_ptr m_xdgShell; diff --git a/src/backends/wayland/wayland_output.cpp b/src/backends/wayland/wayland_output.cpp index 9d4c9c55d7..0a42b477ab 100644 --- a/src/backends/wayland/wayland_output.cpp +++ b/src/backends/wayland/wayland_output.cpp @@ -14,8 +14,8 @@ #include #include -#include #include +#include #include @@ -34,13 +34,9 @@ WaylandOutput::WaylandOutput(const QString &name, WaylandBackend *backend) , m_xdgShellSurface(backend->display()->xdgShell()->createSurface(m_surface.get())) , m_backend(backend) { - if (KWayland::Client::ServerSideDecorationManager *ssdManager = backend->display()->serverSideDecorationManager()) { - m_serverDecoration.reset(ssdManager->create(m_surface.get())); - connect(m_serverDecoration.get(), &KWayland::Client::ServerSideDecoration::modeChanged, this, [this] { - if (m_serverDecoration->mode() != KWayland::Client::ServerSideDecoration::Mode::Server) { - m_serverDecoration->requestMode(KWayland::Client::ServerSideDecoration::Mode::Server); - } - }); + if (KWayland::Client::XdgDecorationManager *manager = m_backend->display()->xdgDecorationManager()) { + m_xdgDecoration.reset(manager->getToplevelDecoration(m_xdgShellSurface.get())); + m_xdgDecoration->setMode(KWayland::Client::XdgDecoration::Mode::ServerSide); } setInformation(Information{ @@ -87,8 +83,9 @@ WaylandOutput::WaylandOutput(const QString &name, WaylandBackend *backend) WaylandOutput::~WaylandOutput() { - m_xdgShellSurface->destroy(); - m_surface->destroy(); + m_xdgDecoration.reset(); + m_xdgShellSurface.reset(); + m_surface.reset(); } bool WaylandOutput::isReady() const diff --git a/src/backends/wayland/wayland_output.h b/src/backends/wayland/wayland_output.h index f53d3b0fc6..932ca22054 100644 --- a/src/backends/wayland/wayland_output.h +++ b/src/backends/wayland/wayland_output.h @@ -22,7 +22,7 @@ namespace Client class Surface; class Pointer; class LockedPointer; -class ServerSideDecoration; +class XdgDecoration; } } @@ -63,7 +63,7 @@ private: std::unique_ptr m_surface; std::unique_ptr m_xdgShellSurface; std::unique_ptr m_pointerLock; - std::unique_ptr m_serverDecoration; + std::unique_ptr m_xdgDecoration; WaylandBackend *const m_backend; QTimer m_turnOffTimer; bool m_hasPointerLock = false;