Create interface for passing server decoration palettes
Summary: It's kept separate in case we ever merge the server decoration manager interface upstream, and this is too kwin specific to have in a potentially shared spec. Code is a copy+paste of existing boilerplate. Replaces use of the deprecated qt extended surface. I'd like to target 5.42 as otherwise we'll have a regression when we release Plasma 5.12 as Qt's XDGv6 doesn't have a working qt extended surface. Test Plan: Attached unit test Reviewers: #plasma, graesslin Reviewed By: #plasma, graesslin Subscribers: plasma-devel, #frameworks Tags: #frameworks, #plasma Differential Revision: https://phabricator.kde.org/D9599
This commit is contained in:
parent
231dc9cba5
commit
eb52e81eed
6 changed files with 361 additions and 0 deletions
|
@ -40,6 +40,7 @@ set(SERVER_LIB_SRCS
|
|||
blur_interface.cpp
|
||||
contrast_interface.cpp
|
||||
server_decoration_interface.cpp
|
||||
server_decoration_palette_interface.cpp
|
||||
shell_interface.cpp
|
||||
surface_interface.cpp
|
||||
subcompositor_interface.cpp
|
||||
|
@ -167,6 +168,12 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
|
|||
PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/appmenu.xml
|
||||
BASENAME appmenu
|
||||
)
|
||||
|
||||
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
|
||||
PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/server-decoration-palette.xml
|
||||
BASENAME server_decoration_palette
|
||||
)
|
||||
|
||||
set(SERVER_GENERATED_SRCS
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-output-management-client-protocol.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-output-management-server-protocol.h
|
||||
|
@ -196,6 +203,8 @@ set(SERVER_GENERATED_SRCS
|
|||
${CMAKE_CURRENT_BINARY_DIR}/wayland-slide-server-protocol.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-server_decoration-client-protocol.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-server_decoration-server-protocol.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-server_decoration_palette-client-protocol.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-server_decoration_palette-server-protocol.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-text-client-protocol.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-text-server-protocol.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/wayland-text-input-unstable-v2-client-protocol.h
|
||||
|
@ -280,6 +289,7 @@ set(SERVER_LIB_HEADERS
|
|||
resource.h
|
||||
seat_interface.h
|
||||
server_decoration_interface.h
|
||||
server_decoration_palette_interface.h
|
||||
shadow_interface.h
|
||||
shell_interface.h
|
||||
slide_interface.h
|
||||
|
|
|
@ -407,3 +407,15 @@ add_executable(testAppmenu ${testAppmenu_SRCS})
|
|||
target_link_libraries( testAppmenu Qt5::Test Qt5::Gui KF5::WaylandClient KF5::WaylandServer)
|
||||
add_test(NAME kwayland-testAppmenu COMMAND testAppmenu)
|
||||
ecm_mark_as_test(testAppmenu)
|
||||
|
||||
########################################################
|
||||
# Test Appmenu
|
||||
########################################################
|
||||
set( testServerSideDecorationPalette_SRCS
|
||||
test_server_side_decoration_palette.cpp
|
||||
)
|
||||
add_executable(testServerSideDecorationPalette ${testServerSideDecorationPalette_SRCS})
|
||||
target_link_libraries( testServerSideDecorationPalette Qt5::Test Qt5::Gui KF5::WaylandClient KF5::WaylandServer)
|
||||
add_test(NAME kwayland-testServerSideDecorationPalette COMMAND testServerSideDecorationPalette)
|
||||
ecm_mark_as_test(testServerSideDecorationPalette)
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "xdgforeign_interface.h"
|
||||
#include "xdgshell_v6_interface_p.h"
|
||||
#include "appmenu_interface.h"
|
||||
#include "server_decoration_palette_interface.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
@ -441,6 +442,13 @@ AppMenuManagerInterface *Display::createAppMenuManagerInterface(QObject *parent)
|
|||
return b;
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteManagerInterface *Display::createServerSideDecorationPaletteManager(QObject *parent)
|
||||
{
|
||||
auto b = new ServerSideDecorationPaletteManagerInterface(this, parent);
|
||||
connect(this, &Display::aboutToTerminate, b, [this, b] { delete b; });
|
||||
return b;
|
||||
}
|
||||
|
||||
void Display::createShm()
|
||||
{
|
||||
Q_ASSERT(d->display);
|
||||
|
|
|
@ -84,6 +84,7 @@ enum class PointerConstraintsInterfaceVersion;
|
|||
class PointerConstraintsInterface;
|
||||
class XdgForeignInterface;
|
||||
class AppMenuManagerInterface;
|
||||
class ServerSideDecorationPaletteManagerInterface;
|
||||
|
||||
/**
|
||||
* @brief Class holding the Wayland server display loop.
|
||||
|
@ -247,6 +248,14 @@ public:
|
|||
**/
|
||||
AppMenuManagerInterface *createAppMenuManagerInterface(QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* Creates the ServerSideDecorationPaletteManagerInterface in interface @p version.
|
||||
*
|
||||
* @returns The created manager object
|
||||
* @since 5.42
|
||||
**/
|
||||
ServerSideDecorationPaletteManagerInterface *createServerSideDecorationPaletteManager(QObject *parent = nullptr);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the ClientConnection for the given @p client.
|
||||
|
|
216
src/wayland/server_decoration_palette_interface.cpp
Normal file
216
src/wayland/server_decoration_palette_interface.cpp
Normal file
|
@ -0,0 +1,216 @@
|
|||
/****************************************************************************
|
||||
Copyright 2017 David Edmundson <kde@davidedmundson.co.uk>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "server_decoration_palette_interface.h"
|
||||
#include "display.h"
|
||||
#include "surface_interface.h"
|
||||
#include "global_p.h"
|
||||
#include "resource_p.h"
|
||||
#include "logging_p.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <wayland-server_decoration_palette-server-protocol.h>
|
||||
|
||||
namespace KWayland
|
||||
{
|
||||
namespace Server
|
||||
{
|
||||
class ServerSideDecorationPaletteManagerInterface::Private : public Global::Private
|
||||
{
|
||||
public:
|
||||
Private(ServerSideDecorationPaletteManagerInterface *q, Display *d);
|
||||
|
||||
QVector<ServerSideDecorationPaletteInterface*> palettes;
|
||||
private:
|
||||
void bind(wl_client *client, uint32_t version, uint32_t id) override;
|
||||
|
||||
static void unbind(wl_resource *resource);
|
||||
static Private *cast(wl_resource *r) {
|
||||
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
|
||||
}
|
||||
|
||||
static void createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface);
|
||||
|
||||
ServerSideDecorationPaletteManagerInterface *q;
|
||||
static const struct org_kde_kwin_server_decoration_palette_manager_interface s_interface;
|
||||
static const quint32 s_version;
|
||||
};
|
||||
|
||||
const quint32 ServerSideDecorationPaletteManagerInterface::Private::s_version = 1;
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
const struct org_kde_kwin_server_decoration_palette_manager_interface ServerSideDecorationPaletteManagerInterface::Private::s_interface = {
|
||||
createCallback
|
||||
};
|
||||
#endif
|
||||
|
||||
void ServerSideDecorationPaletteManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface)
|
||||
{
|
||||
auto p = reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
|
||||
Q_ASSERT(p);
|
||||
|
||||
SurfaceInterface *s = SurfaceInterface::get(surface);
|
||||
if (!s) {
|
||||
// TODO: send error?
|
||||
qCWarning(KWAYLAND_SERVER) << "ServerSideDecorationPaletteInterface requested for non existing SurfaceInterface";
|
||||
return;
|
||||
}
|
||||
auto palette = new ServerSideDecorationPaletteInterface(p->q, s, resource);
|
||||
palette->create(p->display->getConnection(client), wl_resource_get_version(resource), id);
|
||||
if (!palette->resource()) {
|
||||
wl_resource_post_no_memory(resource);
|
||||
delete palette;
|
||||
return;
|
||||
}
|
||||
p->palettes.append(palette);
|
||||
QObject::connect(palette, &QObject::destroyed, p->q, [=]() {
|
||||
p->palettes.removeOne(palette);
|
||||
});
|
||||
emit p->q->paletteCreated(palette);
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteManagerInterface::Private::Private(ServerSideDecorationPaletteManagerInterface *q, Display *d)
|
||||
: Global::Private(d, &org_kde_kwin_server_decoration_palette_manager_interface, s_version)
|
||||
, q(q)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerSideDecorationPaletteManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
|
||||
{
|
||||
auto c = display->getConnection(client);
|
||||
wl_resource *resource = c->createResource(&org_kde_kwin_server_decoration_palette_manager_interface, qMin(version, s_version), id);
|
||||
if (!resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
||||
}
|
||||
|
||||
void ServerSideDecorationPaletteManagerInterface::Private::unbind(wl_resource *resource)
|
||||
{
|
||||
Q_UNUSED(resource)
|
||||
}
|
||||
|
||||
class ServerSideDecorationPaletteInterface::Private : public Resource::Private
|
||||
{
|
||||
public:
|
||||
Private(ServerSideDecorationPaletteInterface *q, ServerSideDecorationPaletteManagerInterface *c, SurfaceInterface *surface, wl_resource *parentResource);
|
||||
~Private();
|
||||
|
||||
|
||||
SurfaceInterface *surface;
|
||||
QString palette;
|
||||
private:
|
||||
static void setPaletteCallback(wl_client *client, wl_resource *resource, const char * palette);
|
||||
|
||||
ServerSideDecorationPaletteInterface *q_func() {
|
||||
return reinterpret_cast<ServerSideDecorationPaletteInterface *>(q);
|
||||
}
|
||||
static ServerSideDecorationPaletteInterface *get(SurfaceInterface *s);
|
||||
static const struct org_kde_kwin_server_decoration_palette_interface s_interface;
|
||||
};
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
const struct org_kde_kwin_server_decoration_palette_interface ServerSideDecorationPaletteInterface::Private::s_interface = {
|
||||
setPaletteCallback,
|
||||
resourceDestroyedCallback
|
||||
};
|
||||
#endif
|
||||
|
||||
void ServerSideDecorationPaletteInterface::Private::setPaletteCallback(wl_client *client, wl_resource *resource, const char * palette)
|
||||
{
|
||||
Q_UNUSED(client);
|
||||
auto p = reinterpret_cast<Private*>(wl_resource_get_user_data(resource));
|
||||
Q_ASSERT(p);
|
||||
|
||||
if (p->palette == QLatin1String(palette)) {
|
||||
return;
|
||||
}
|
||||
p->palette = QString::fromUtf8(palette);
|
||||
emit p->q_func()->paletteChanged(p->palette);
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteInterface::Private::Private(ServerSideDecorationPaletteInterface *q, ServerSideDecorationPaletteManagerInterface *c, SurfaceInterface *s, wl_resource *parentResource)
|
||||
: Resource::Private(q, c, parentResource, &org_kde_kwin_server_decoration_palette_interface, &s_interface),
|
||||
surface(s)
|
||||
{
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteInterface::Private::~Private()
|
||||
{
|
||||
if (resource) {
|
||||
wl_resource_destroy(resource);
|
||||
resource = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteManagerInterface::ServerSideDecorationPaletteManagerInterface(Display *display, QObject *parent)
|
||||
: Global(new Private(this, display), parent)
|
||||
{
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteManagerInterface::~ServerSideDecorationPaletteManagerInterface()
|
||||
{
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteManagerInterface::Private *ServerSideDecorationPaletteManagerInterface::d_func() const
|
||||
{
|
||||
return reinterpret_cast<ServerSideDecorationPaletteManagerInterface::Private*>(d.data());
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteInterface* ServerSideDecorationPaletteManagerInterface::paletteForSurface(SurfaceInterface *surface)
|
||||
{
|
||||
Q_D();
|
||||
for (ServerSideDecorationPaletteInterface* menu: d->palettes) {
|
||||
if (menu->surface() == surface) {
|
||||
return menu;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteInterface::ServerSideDecorationPaletteInterface(ServerSideDecorationPaletteManagerInterface *parent, SurfaceInterface *s, wl_resource *parentResource):
|
||||
Resource(new Private(this, parent, s, parentResource))
|
||||
{
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteInterface::Private *ServerSideDecorationPaletteInterface::d_func() const
|
||||
{
|
||||
return reinterpret_cast<ServerSideDecorationPaletteInterface::Private*>(d.data());
|
||||
}
|
||||
|
||||
ServerSideDecorationPaletteInterface::~ServerSideDecorationPaletteInterface()
|
||||
{}
|
||||
|
||||
QString ServerSideDecorationPaletteInterface::palette() const
|
||||
{
|
||||
Q_D();
|
||||
return d->palette;
|
||||
}
|
||||
|
||||
SurfaceInterface* ServerSideDecorationPaletteInterface::surface() const
|
||||
{
|
||||
Q_D();
|
||||
return d->surface;
|
||||
}
|
||||
|
||||
}//namespace
|
||||
}
|
||||
|
106
src/wayland/server_decoration_palette_interface.h
Normal file
106
src/wayland/server_decoration_palette_interface.h
Normal file
|
@ -0,0 +1,106 @@
|
|||
/****************************************************************************
|
||||
Copyright 2017 David Edmundson <kde@davidedmundson.co.uk>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef KWAYLAND_SERVER_DECORATION_PALETTE_H
|
||||
#define KWAYLAND_SERVER_DECORATION_PALETTE_H
|
||||
|
||||
#include "global.h"
|
||||
#include "resource.h"
|
||||
|
||||
#include <KWayland/Server/kwaylandserver_export.h>
|
||||
|
||||
namespace KWayland
|
||||
{
|
||||
namespace Server
|
||||
{
|
||||
|
||||
class Display;
|
||||
class SurfaceInterface;
|
||||
class ServerSideDecorationPaletteInterface;
|
||||
|
||||
/**
|
||||
* Allows a client to specify a preferred palette to use for server-side window decorations
|
||||
*
|
||||
* This global can be used for clients to bind ServerSideDecorationPaletteInterface instances
|
||||
* and notifies when a new one is created
|
||||
* @since 5.42
|
||||
*/
|
||||
class KWAYLANDSERVER_EXPORT ServerSideDecorationPaletteManagerInterface : public Global
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~ServerSideDecorationPaletteManagerInterface();
|
||||
/**
|
||||
* Returns any existing palette for a given surface
|
||||
* This returns a null pointer if no ServerSideDecorationPaletteInterface exists.
|
||||
*/
|
||||
ServerSideDecorationPaletteInterface* paletteForSurface(SurfaceInterface *);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Emitted whenever a new ServerSideDecorationPaletteInterface is created.
|
||||
**/
|
||||
void paletteCreated(KWayland::Server::ServerSideDecorationPaletteInterface*);
|
||||
|
||||
private:
|
||||
explicit ServerSideDecorationPaletteManagerInterface(Display *display, QObject *parent = nullptr);
|
||||
friend class Display;
|
||||
class Private;
|
||||
Private *d_func() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides the palette
|
||||
* This interface is attached to a wl_surface and informs the server of a requested palette
|
||||
* @since 5.42
|
||||
*/
|
||||
class KWAYLANDSERVER_EXPORT ServerSideDecorationPaletteInterface : public Resource
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~ServerSideDecorationPaletteInterface();
|
||||
|
||||
/**
|
||||
* @returns the palette or an empty string if unset
|
||||
*/
|
||||
QString palette() const;
|
||||
|
||||
/**
|
||||
* @returns The SurfaceInterface this ServerSideDecorationPaletteInterface references.
|
||||
**/
|
||||
SurfaceInterface *surface() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Emitted when the palette changes or is first received
|
||||
*/
|
||||
void paletteChanged(const QString &palette);
|
||||
|
||||
private:
|
||||
explicit ServerSideDecorationPaletteInterface(ServerSideDecorationPaletteManagerInterface *parent, SurfaceInterface *s, wl_resource *parentResource);
|
||||
friend class ServerSideDecorationPaletteManagerInterface;
|
||||
|
||||
class Private;
|
||||
Private *d_func() const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue