Commit 47897e24 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Add ServerDecorationInterface::preferredMode()

This change adds the preferred decoration mode similar to what
XdgToplevelDecorationV1Interface has. It's needed to clean up some kwin
code.
parent 1e84a56d
......@@ -244,8 +244,8 @@ void TestServerSideDecoration::testRequest()
auto serverDeco = decorationCreated.first().first().value<ServerSideDecorationInterface *>();
QVERIFY(serverDeco);
QSignalSpy modeSpy(serverDeco, &ServerSideDecorationInterface::modeRequested);
QVERIFY(modeSpy.isValid());
QSignalSpy preferredModeChangedSpy(serverDeco, &ServerSideDecorationInterface::preferredModeChanged);
QVERIFY(preferredModeChangedSpy.isValid());
// after binding the client should get the default mode
QVERIFY(modeChangedSpy.wait());
......@@ -258,10 +258,10 @@ void TestServerSideDecoration::testRequest()
// mode not yet changed
QTEST(serverSideDecoration->mode(), "clientMode");
QVERIFY(modeSpy.wait());
QCOMPARE(modeSpy.count(), 1);
QVERIFY(preferredModeChangedSpy.wait());
QCOMPARE(preferredModeChangedSpy.count(), 1);
QFETCH(ServerSideDecorationManagerInterface::Mode, serverRequestedMode);
QCOMPARE(modeSpy.first().first().value<ServerSideDecorationManagerInterface::Mode>(), serverRequestedMode);
QCOMPARE(serverDeco->preferredMode(), serverRequestedMode);
// mode not yet changed
QCOMPARE(serverDeco->mode(), defaultMode);
......
......@@ -10,6 +10,8 @@
#include <QVector>
#include <optional>
#include <qwayland-server-server-decoration.h>
namespace KWaylandServer
......@@ -57,7 +59,7 @@ void ServerSideDecorationManagerInterfacePrivate::org_kde_kwin_server_decoration
wl_client_post_no_memory(resource->client());
return;
}
auto decoration = new ServerSideDecorationInterface(s, decorationResource);
auto decoration = new ServerSideDecorationInterface(q, s, decorationResource);
decoration->setMode(defaultMode);
Q_EMIT q->decorationCreated(decoration);
}
......@@ -105,13 +107,18 @@ ServerSideDecorationManagerInterface::Mode ServerSideDecorationManagerInterface:
class ServerSideDecorationInterfacePrivate : public QtWaylandServer::org_kde_kwin_server_decoration
{
public:
ServerSideDecorationInterfacePrivate(ServerSideDecorationInterface *_q, SurfaceInterface *surface, wl_resource *resource);
ServerSideDecorationInterfacePrivate(ServerSideDecorationManagerInterface *manager,
ServerSideDecorationInterface *_q,
SurfaceInterface *surface,
wl_resource *resource);
~ServerSideDecorationInterfacePrivate();
static ServerSideDecorationInterface *get(SurfaceInterface *surface);
void setMode(ServerSideDecorationManagerInterface::Mode mode);
ServerSideDecorationManagerInterface *manager;
ServerSideDecorationManagerInterface::Mode mode = ServerSideDecorationManagerInterface::Mode::None;
std::optional<ServerSideDecorationManagerInterface::Mode> preferredMode;
SurfaceInterface *surface;
private:
......@@ -145,7 +152,8 @@ void ServerSideDecorationInterfacePrivate::org_kde_kwin_server_decoration_reques
qCWarning(KWAYLAND_SERVER) << "Invalid mode:" << mode;
return;
}
Q_EMIT q->modeRequested(m);
preferredMode = m;
Q_EMIT q->preferredModeChanged();
}
void ServerSideDecorationInterfacePrivate::org_kde_kwin_server_decoration_release(Resource *resource)
......@@ -169,8 +177,12 @@ ServerSideDecorationInterface *ServerSideDecorationInterfacePrivate::get(Surface
return nullptr;
}
ServerSideDecorationInterfacePrivate::ServerSideDecorationInterfacePrivate(ServerSideDecorationInterface *_q, SurfaceInterface *surface, wl_resource *resource)
ServerSideDecorationInterfacePrivate::ServerSideDecorationInterfacePrivate(ServerSideDecorationManagerInterface *manager,
ServerSideDecorationInterface *_q,
SurfaceInterface *surface,
wl_resource *resource)
: QtWaylandServer::org_kde_kwin_server_decoration(resource)
, manager(manager)
, surface(surface)
, q(_q)
{
......@@ -188,9 +200,9 @@ void ServerSideDecorationInterfacePrivate::setMode(ServerSideDecorationManagerIn
send_mode(modeWayland(mode));
}
ServerSideDecorationInterface::ServerSideDecorationInterface(SurfaceInterface *surface, wl_resource *resource)
ServerSideDecorationInterface::ServerSideDecorationInterface(ServerSideDecorationManagerInterface *manager, SurfaceInterface *surface, wl_resource *resource)
: QObject()
, d(new ServerSideDecorationInterfacePrivate(this, surface, resource))
, d(new ServerSideDecorationInterfacePrivate(manager, this, surface, resource))
{
}
......@@ -206,6 +218,11 @@ ServerSideDecorationManagerInterface::Mode ServerSideDecorationInterface::mode()
return d->mode;
}
ServerSideDecorationManagerInterface::Mode ServerSideDecorationInterface::preferredMode() const
{
return d->preferredMode.value_or(d->manager->defaultMode());
}
SurfaceInterface *ServerSideDecorationInterface::surface() const
{
return d->surface;
......
......@@ -94,6 +94,10 @@ public:
* @see modeRequested
*/
ServerSideDecorationManagerInterface::Mode mode() const;
/**
* Returns the preferred decoration mode as specified by the client.
*/
ServerSideDecorationManagerInterface::Mode preferredMode() const;
/**
* @returns The SurfaceInterface this ServerSideDecorationInterface references.
......@@ -112,10 +116,10 @@ Q_SIGNALS:
* @see setMode
* @see mode
*/
void modeRequested(KWaylandServer::ServerSideDecorationManagerInterface::Mode);
void preferredModeChanged();
private:
explicit ServerSideDecorationInterface(SurfaceInterface *surface, wl_resource *resource);
explicit ServerSideDecorationInterface(ServerSideDecorationManagerInterface *manager, SurfaceInterface *surface, wl_resource *resource);
friend class ServerSideDecorationManagerInterfacePrivate;
QScopedPointer<ServerSideDecorationInterfacePrivate> d;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment