Commit 22dac774 authored by adrien faveraux's avatar adrien faveraux
Browse files

Move slide interface to the new approach

parent 42e2cdf7
Pipeline #43229 passed with stage
in 6 minutes and 18 seconds
......@@ -101,8 +101,6 @@ void TestSlide::init()
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
m_slideManagerInterface = m_display->createSlideManager(m_display);
m_slideManagerInterface->create();
QVERIFY(m_slideManagerInterface->isValid());
QVERIFY(slideSpy.wait());
m_slideManager = registry.createSlideManager(slideSpy.first().first().value<quint32>(), slideSpy.first().last().value<quint32>(), this);
......@@ -128,10 +126,12 @@ void TestSlide::cleanup()
delete m_thread;
m_thread = nullptr;
}
CLEANUP(m_compositorInterface)
CLEANUP(m_slideManagerInterface)
CLEANUP(m_display)
#undef CLEANUP
// these are the children of the display
m_compositorInterface = nullptr;
m_slideManagerInterface = nullptr;
}
void TestSlide::testCreate()
......
......@@ -144,7 +144,7 @@ ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
BASENAME relative-pointer-unstable-v1
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/slide.xml
BASENAME slide
)
......
......@@ -5,196 +5,146 @@
*/
#include "slide_interface.h"
#include "display.h"
#include "global_p.h"
#include "surface_interface.h"
#include "resource_p.h"
#include "surface_interface_p.h"
#include <wayland-server.h>
#include <wayland-slide-server-protocol.h>
#include <qwayland-server-slide.h>
namespace KWaylandServer
{
class SlideManagerInterface::Private : public Global::Private
static const quint32 s_version = 1;
class SlideManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_slide_manager
{
public:
Private(SlideManagerInterface *q, Display *d);
SlideManagerInterfacePrivate(SlideManagerInterface *_q, Display *display);
private:
void bind(wl_client *client, uint32_t version, uint32_t id) override;
void createSlide(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
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);
static void unsetCallback(wl_client *client, wl_resource *resource, wl_resource * surface);
SlideManagerInterface *q;
static const struct org_kde_kwin_slide_manager_interface s_interface;
//initializing here doesn't link
static const quint32 s_version;
};
const quint32 SlideManagerInterface::Private::s_version = 1;
#ifndef K_DOXYGEN
const struct org_kde_kwin_slide_manager_interface SlideManagerInterface::Private::s_interface = {
createCallback,
unsetCallback
protected:
void org_kde_kwin_slide_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override;
void org_kde_kwin_slide_manager_unset(Resource *resource, wl_resource *surface) override;
};
#endif
void SlideManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface)
{
cast(resource)->createSlide(client, resource, id, surface);
}
void SlideManagerInterface::Private::createSlide(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface)
void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
{
SurfaceInterface *s = SurfaceInterface::get(surface);
if (!s) {
wl_resource_post_error(resource->handle, 0, "Invalid surface");
return;
}
SlideInterface *slide = new SlideInterface(q, resource);
slide->create(display->getConnection(client), wl_resource_get_version(resource), id);
if (!slide->resource()) {
wl_resource_post_no_memory(resource);
delete slide;
wl_resource *slide_resource = wl_resource_create(resource->client(), &org_kde_kwin_slide_interface, resource->version(), id);
if (!slide_resource) {
wl_client_post_no_memory(resource->client());
return;
}
auto slide = new SlideInterface(q, slide_resource);
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setSlide(QPointer<SlideInterface>(slide));
}
void SlideManagerInterface::Private::unsetCallback(wl_client *client, wl_resource *resource, wl_resource * surface)
{
Q_UNUSED(client)
Q_UNUSED(resource)
Q_UNUSED(surface)
// TODO: implement
}
SlideManagerInterface::Private::Private(SlideManagerInterface *q, Display *d)
: Global::Private(d, &org_kde_kwin_slide_manager_interface, s_version)
, q(q)
void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_unset(Resource *resource, wl_resource *surface)
{
}
void SlideManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
auto c = display->getConnection(client);
wl_resource *resource = c->createResource(&org_kde_kwin_slide_manager_interface, qMin(version, s_version), id);
if (!resource) {
wl_client_post_no_memory(client);
SurfaceInterface *s = SurfaceInterface::get(surface);
if (!s) {
wl_resource_post_error(resource->handle, 0, "Invalid surface");
return;
}
wl_resource_set_implementation(resource, &s_interface, this, unbind);
// TODO: should we track?
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->setSlide(QPointer<SlideInterface>());
}
void SlideManagerInterface::Private::unbind(wl_resource *resource)
SlideManagerInterfacePrivate::SlideManagerInterfacePrivate(SlideManagerInterface *_q, Display *display)
: QtWaylandServer::org_kde_kwin_slide_manager(*display, s_version)
, q(_q)
{
Q_UNUSED(resource)
// TODO: implement?
}
SlideManagerInterface::SlideManagerInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
: QObject(parent)
, d(new SlideManagerInterfacePrivate(this, display))
{
}
SlideManagerInterface::~SlideManagerInterface() = default;
class SlideInterface::Private : public Resource::Private
class SlideInterfacePrivate : public QtWaylandServer::org_kde_kwin_slide
{
public:
Private(SlideInterface *q, SlideManagerInterface *c, wl_resource *parentResource);
~Private();
SlideInterfacePrivate(SlideInterface *_q, wl_resource *resource);
SlideInterface::Location pendingLocation;
SlideInterface::Location currentLocation;
uint32_t pendingOffset;
uint32_t currentOffset;
private:
static void commitCallback(wl_client *client, wl_resource *resource);
static void setLocationCallback(wl_client *client, wl_resource *resource, uint32_t location);
static void setOffsetCallback(wl_client *client, wl_resource *resource, int32_t offset);
SlideInterface *q_func() {
return reinterpret_cast<SlideInterface *>(q);
}
static const struct org_kde_kwin_slide_interface s_interface;
SlideInterface *q;
protected:
void org_kde_kwin_slide_commit(Resource *resource) override;
void org_kde_kwin_slide_set_location(Resource *resource, uint32_t location) override;
void org_kde_kwin_slide_set_offset(Resource *resource, int32_t offset) override;
void org_kde_kwin_slide_release(Resource *resource) override;
void org_kde_kwin_slide_destroy_resource(Resource *resource) override;
};
#ifndef K_DOXYGEN
const struct org_kde_kwin_slide_interface SlideInterface::Private::s_interface = {
commitCallback,
setLocationCallback,
setOffsetCallback,
resourceDestroyedCallback
};
#endif
void SlideInterfacePrivate::org_kde_kwin_slide_commit(Resource *resource)
{
Q_UNUSED(resource)
currentLocation = pendingLocation;
currentOffset = pendingOffset;
}
void SlideInterface::Private::commitCallback(wl_client *client, wl_resource *resource)
void SlideInterfacePrivate::org_kde_kwin_slide_set_location(Resource *resource, uint32_t location)
{
Q_UNUSED(client)
Private *p = cast<Private>(resource);
p->currentLocation = p->pendingLocation;
p->currentOffset = p->pendingOffset;
Q_UNUSED(resource)
pendingLocation = (SlideInterface::Location)location;
}
void SlideInterface::Private::setLocationCallback(wl_client *client, wl_resource *resource, uint32_t location)
void SlideInterfacePrivate::org_kde_kwin_slide_set_offset(Resource *resource, int32_t offset)
{
Q_UNUSED(client)
Private *p = cast<Private>(resource);
p->pendingLocation = (SlideInterface::Location)location;
Q_UNUSED(resource)
pendingOffset = offset;
}
void SlideInterface::Private::setOffsetCallback(wl_client *client, wl_resource *resource, int32_t offset)
void SlideInterfacePrivate::org_kde_kwin_slide_release(Resource *resource)
{
Q_UNUSED(client)
Private *p = cast<Private>(resource);
p->pendingOffset = offset;
wl_resource_destroy(resource->handle);
}
SlideInterface::Private::Private(SlideInterface *q, SlideManagerInterface *c, wl_resource *parentResource)
: Resource::Private(q, c, parentResource, &org_kde_kwin_slide_interface, &s_interface)
void SlideInterfacePrivate::org_kde_kwin_slide_destroy_resource(Resource *resource)
{
Q_UNUSED(resource)
delete q;
}
SlideInterface::Private::~Private() = default;
SlideInterfacePrivate::SlideInterfacePrivate(SlideInterface *_q, wl_resource *resource)
: QtWaylandServer::org_kde_kwin_slide(resource)
, q(_q)
{
}
SlideInterface::SlideInterface(SlideManagerInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, parent, parentResource))
SlideInterface::SlideInterface(SlideManagerInterface *manager, wl_resource *resource)
: QObject(manager)
, d(new SlideInterfacePrivate(this, resource))
{
}
SlideInterface::~SlideInterface() = default;
SlideInterface::Location SlideInterface::location() const
{
Q_D();
return d->currentLocation;
}
qint32 SlideInterface::offset() const
{
Q_D();
return d->currentOffset;
}
SlideInterface::Private *SlideInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
}
......@@ -6,46 +6,43 @@
#ifndef KWAYLAND_SERVER_SLIDE_INTERFACE_H
#define KWAYLAND_SERVER_SLIDE_INTERFACE_H
#include "global.h"
#include "resource.h"
#include <QObject>
#include <KWaylandServer/kwaylandserver_export.h>
struct wl_resource;
namespace KWaylandServer
{
class Display;
class SlideManagerInterfacePrivate;
class SlideInterfacePrivate;
/**
* TODO
*/
class KWAYLANDSERVER_EXPORT SlideManagerInterface : public Global
class KWAYLANDSERVER_EXPORT SlideManagerInterface : public QObject
{
Q_OBJECT
public:
virtual ~SlideManagerInterface();
~SlideManagerInterface() override;
private:
explicit SlideManagerInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
QScopedPointer<SlideManagerInterfacePrivate> d;
};
/**
* TODO
*/
class KWAYLANDSERVER_EXPORT SlideInterface : public Resource
class KWAYLANDSERVER_EXPORT SlideInterface : public QObject
{
Q_OBJECT
public:
enum Location {
Left = 0, /**< Slide from the left edge of the screen */
Top, /**< Slide from the top edge of the screen */
Right, /**< Slide from the bottom edge of the screen */
Bottom /**< Slide from the bottom edge of the screen */
Top = 1, /**< Slide from the top edge of the screen */
Right = 2, /**< Slide from the bottom edge of the screen */
Bottom = 3 /**< Slide from the bottom edge of the screen */
};
virtual ~SlideInterface();
~SlideInterface() override;
/**
* @returns the location the window will be slided from
......@@ -59,11 +56,10 @@ public:
qint32 offset() const;
private:
explicit SlideInterface(SlideManagerInterface *parent, wl_resource *parentResource);
friend class SlideManagerInterface;
explicit SlideInterface(SlideManagerInterface *manager, wl_resource *resource);
friend class SlideManagerInterfacePrivate;
class Private;
Private *d_func() const;
QScopedPointer<SlideInterfacePrivate> d;
};
......
Markdown is supported
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