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.
This commit is contained in:
Vlad Zahorodnii 2022-11-15 10:21:21 +02:00
parent be3146873f
commit bcb38f366d
4 changed files with 20 additions and 23 deletions

View file

@ -13,9 +13,9 @@
#include <KWayland/Client/registry.h> #include <KWayland/Client/registry.h>
#include <KWayland/Client/relativepointer.h> #include <KWayland/Client/relativepointer.h>
#include <KWayland/Client/seat.h> #include <KWayland/Client/seat.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/shm_pool.h> #include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/subcompositor.h> #include <KWayland/Client/subcompositor.h>
#include <KWayland/Client/xdgdecoration.h>
#include <KWayland/Client/xdgshell.h> #include <KWayland/Client/xdgshell.h>
#include <QMutex> #include <QMutex>
@ -30,7 +30,7 @@
#include "wayland-pointer-constraints-unstable-v1-client-protocol.h" #include "wayland-pointer-constraints-unstable-v1-client-protocol.h"
#include "wayland-pointer-gestures-unstable-v1-server-protocol.h" #include "wayland-pointer-gestures-unstable-v1-server-protocol.h"
#include "wayland-relative-pointer-unstable-v1-client-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" #include "wayland-xdg-shell-client-protocol.h"
namespace KWin namespace KWin
@ -160,7 +160,7 @@ WaylandDisplay::~WaylandDisplay()
m_pointerGestures.reset(); m_pointerGestures.reset();
m_relativePointerManager.reset(); m_relativePointerManager.reset();
m_seat.reset(); m_seat.reset();
m_serverSideDecorationManager.reset(); m_xdgDecorationManager.reset();
m_shmPool.reset(); m_shmPool.reset();
m_subCompositor.reset(); m_subCompositor.reset();
m_xdgShell.reset(); m_xdgShell.reset();
@ -245,9 +245,9 @@ KWayland::Client::XdgShell *WaylandDisplay::xdgShell() const
return m_xdgShell.get(); 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) 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) { } else if (strcmp(interface, zwp_relative_pointer_manager_v1_interface.name) == 0) {
display->m_relativePointerManager = std::make_unique<KWayland::Client::RelativePointerManager>(); display->m_relativePointerManager = std::make_unique<KWayland::Client::RelativePointerManager>();
display->m_relativePointerManager->setup(static_cast<zwp_relative_pointer_manager_v1 *>(wl_registry_bind(registry, name, &zwp_relative_pointer_manager_v1_interface, std::min(version, 1u)))); display->m_relativePointerManager->setup(static_cast<zwp_relative_pointer_manager_v1 *>(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) { } else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) {
display->m_serverSideDecorationManager = std::make_unique<KWayland::Client::ServerSideDecorationManager>(); display->m_xdgDecorationManager = std::make_unique<KWayland::Client::XdgDecorationManager>();
display->m_serverSideDecorationManager->setup(static_cast<org_kde_kwin_server_decoration_manager *>(wl_registry_bind(registry, name, &org_kde_kwin_server_decoration_manager_interface, std::min(version, 1u)))); display->m_xdgDecorationManager->setup(static_cast<zxdg_decoration_manager_v1 *>(wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, std::min(version, 1u))));
} }
} }

View file

@ -22,9 +22,9 @@ class PointerConstraints;
class PointerGestures; class PointerGestures;
class RelativePointerManager; class RelativePointerManager;
class Seat; class Seat;
class ServerSideDecorationManager;
class ShmPool; class ShmPool;
class SubCompositor; class SubCompositor;
class XdgDecorationManager;
class XdgShell; class XdgShell;
} }
} }
@ -52,7 +52,7 @@ public:
KWayland::Client::PointerGestures *pointerGestures() const; KWayland::Client::PointerGestures *pointerGestures() const;
KWayland::Client::RelativePointerManager *relativePointerManager() const; KWayland::Client::RelativePointerManager *relativePointerManager() const;
KWayland::Client::Seat *seat() const; KWayland::Client::Seat *seat() const;
KWayland::Client::ServerSideDecorationManager *serverSideDecorationManager() const; KWayland::Client::XdgDecorationManager *xdgDecorationManager() const;
KWayland::Client::ShmPool *shmPool() const; KWayland::Client::ShmPool *shmPool() const;
KWayland::Client::SubCompositor *subCompositor() const; KWayland::Client::SubCompositor *subCompositor() const;
KWayland::Client::XdgShell *xdgShell() const; KWayland::Client::XdgShell *xdgShell() const;
@ -72,7 +72,7 @@ private:
std::unique_ptr<KWayland::Client::PointerGestures> m_pointerGestures; std::unique_ptr<KWayland::Client::PointerGestures> m_pointerGestures;
std::unique_ptr<KWayland::Client::RelativePointerManager> m_relativePointerManager; std::unique_ptr<KWayland::Client::RelativePointerManager> m_relativePointerManager;
std::unique_ptr<KWayland::Client::Seat> m_seat; std::unique_ptr<KWayland::Client::Seat> m_seat;
std::unique_ptr<KWayland::Client::ServerSideDecorationManager> m_serverSideDecorationManager; std::unique_ptr<KWayland::Client::XdgDecorationManager> m_xdgDecorationManager;
std::unique_ptr<KWayland::Client::ShmPool> m_shmPool; std::unique_ptr<KWayland::Client::ShmPool> m_shmPool;
std::unique_ptr<KWayland::Client::SubCompositor> m_subCompositor; std::unique_ptr<KWayland::Client::SubCompositor> m_subCompositor;
std::unique_ptr<KWayland::Client::XdgShell> m_xdgShell; std::unique_ptr<KWayland::Client::XdgShell> m_xdgShell;

View file

@ -14,8 +14,8 @@
#include <KWayland/Client/compositor.h> #include <KWayland/Client/compositor.h>
#include <KWayland/Client/pointerconstraints.h> #include <KWayland/Client/pointerconstraints.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/surface.h> #include <KWayland/Client/surface.h>
#include <KWayland/Client/xdgdecoration.h>
#include <KLocalizedString> #include <KLocalizedString>
@ -34,13 +34,9 @@ WaylandOutput::WaylandOutput(const QString &name, WaylandBackend *backend)
, m_xdgShellSurface(backend->display()->xdgShell()->createSurface(m_surface.get())) , m_xdgShellSurface(backend->display()->xdgShell()->createSurface(m_surface.get()))
, m_backend(backend) , m_backend(backend)
{ {
if (KWayland::Client::ServerSideDecorationManager *ssdManager = backend->display()->serverSideDecorationManager()) { if (KWayland::Client::XdgDecorationManager *manager = m_backend->display()->xdgDecorationManager()) {
m_serverDecoration.reset(ssdManager->create(m_surface.get())); m_xdgDecoration.reset(manager->getToplevelDecoration(m_xdgShellSurface.get()));
connect(m_serverDecoration.get(), &KWayland::Client::ServerSideDecoration::modeChanged, this, [this] { m_xdgDecoration->setMode(KWayland::Client::XdgDecoration::Mode::ServerSide);
if (m_serverDecoration->mode() != KWayland::Client::ServerSideDecoration::Mode::Server) {
m_serverDecoration->requestMode(KWayland::Client::ServerSideDecoration::Mode::Server);
}
});
} }
setInformation(Information{ setInformation(Information{
@ -87,8 +83,9 @@ WaylandOutput::WaylandOutput(const QString &name, WaylandBackend *backend)
WaylandOutput::~WaylandOutput() WaylandOutput::~WaylandOutput()
{ {
m_xdgShellSurface->destroy(); m_xdgDecoration.reset();
m_surface->destroy(); m_xdgShellSurface.reset();
m_surface.reset();
} }
bool WaylandOutput::isReady() const bool WaylandOutput::isReady() const

View file

@ -22,7 +22,7 @@ namespace Client
class Surface; class Surface;
class Pointer; class Pointer;
class LockedPointer; class LockedPointer;
class ServerSideDecoration; class XdgDecoration;
} }
} }
@ -63,7 +63,7 @@ private:
std::unique_ptr<KWayland::Client::Surface> m_surface; std::unique_ptr<KWayland::Client::Surface> m_surface;
std::unique_ptr<KWayland::Client::XdgShellSurface> m_xdgShellSurface; std::unique_ptr<KWayland::Client::XdgShellSurface> m_xdgShellSurface;
std::unique_ptr<KWayland::Client::LockedPointer> m_pointerLock; std::unique_ptr<KWayland::Client::LockedPointer> m_pointerLock;
std::unique_ptr<KWayland::Client::ServerSideDecoration> m_serverDecoration; std::unique_ptr<KWayland::Client::XdgDecoration> m_xdgDecoration;
WaylandBackend *const m_backend; WaylandBackend *const m_backend;
QTimer m_turnOffTimer; QTimer m_turnOffTimer;
bool m_hasPointerLock = false; bool m_hasPointerLock = false;