2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2015-09-09 11:04:11 +00:00
|
|
|
#include "slide_interface.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "surface_interface_p.h"
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
#include <qwayland-server-slide.h>
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
2020-12-01 11:03:48 +00:00
|
|
|
static const quint32 s_version = 1;
|
|
|
|
|
|
|
|
class SlideManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_slide_manager
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-12-01 11:03:48 +00:00
|
|
|
SlideManagerInterfacePrivate(SlideManagerInterface *_q, Display *display);
|
2015-09-09 11:04:11 +00:00
|
|
|
|
|
|
|
SlideManagerInterface *q;
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
protected:
|
2021-05-02 14:46:13 +00:00
|
|
|
void org_kde_kwin_slide_manager_destroy_global() override;
|
2020-12-01 11:03:48 +00:00
|
|
|
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;
|
2015-09-09 11:04:11 +00:00
|
|
|
};
|
|
|
|
|
2021-05-02 14:46:13 +00:00
|
|
|
void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_destroy_global()
|
|
|
|
{
|
|
|
|
delete q;
|
|
|
|
}
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
|
|
|
SurfaceInterface *s = SurfaceInterface::get(surface);
|
|
|
|
if (!s) {
|
2020-12-01 11:03:48 +00:00
|
|
|
wl_resource_post_error(resource->handle, 0, "Invalid surface");
|
2015-09-09 11:04:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
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());
|
2015-09-09 11:04:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-12-01 11:03:48 +00:00
|
|
|
|
|
|
|
auto slide = new SlideInterface(q, slide_resource);
|
2020-07-04 07:51:33 +00:00
|
|
|
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
|
|
|
|
surfacePrivate->setSlide(QPointer<SlideInterface>(slide));
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_unset(Resource *resource, wl_resource *surface)
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
2020-12-01 11:03:48 +00:00
|
|
|
SurfaceInterface *s = SurfaceInterface::get(surface);
|
|
|
|
if (!s) {
|
|
|
|
wl_resource_post_error(resource->handle, 0, "Invalid surface");
|
2015-09-09 11:04:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-12-01 11:03:48 +00:00
|
|
|
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
|
|
|
|
surfacePrivate->setSlide(QPointer<SlideInterface>());
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
SlideManagerInterfacePrivate::SlideManagerInterfacePrivate(SlideManagerInterface *_q, Display *display)
|
|
|
|
: QtWaylandServer::org_kde_kwin_slide_manager(*display, s_version)
|
|
|
|
, q(_q)
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SlideManagerInterface::SlideManagerInterface(Display *display, QObject *parent)
|
2020-12-01 11:03:48 +00:00
|
|
|
: QObject(parent)
|
|
|
|
, d(new SlideManagerInterfacePrivate(this, display))
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-01-29 13:25:54 +00:00
|
|
|
SlideManagerInterface::~SlideManagerInterface()
|
2021-05-02 14:46:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlideManagerInterface::remove()
|
2021-01-29 13:25:54 +00:00
|
|
|
{
|
|
|
|
d->globalRemove();
|
|
|
|
}
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
class SlideInterfacePrivate : public QtWaylandServer::org_kde_kwin_slide
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-12-01 11:03:48 +00:00
|
|
|
SlideInterfacePrivate(SlideInterface *_q, wl_resource *resource);
|
2015-09-09 11:04:11 +00:00
|
|
|
|
|
|
|
SlideInterface::Location pendingLocation;
|
|
|
|
SlideInterface::Location currentLocation;
|
|
|
|
uint32_t pendingOffset;
|
|
|
|
uint32_t currentOffset;
|
2020-12-01 11:03:48 +00:00
|
|
|
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;
|
2015-09-09 11:04:11 +00:00
|
|
|
};
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
void SlideInterfacePrivate::org_kde_kwin_slide_commit(Resource *resource)
|
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
currentLocation = pendingLocation;
|
|
|
|
currentOffset = pendingOffset;
|
|
|
|
}
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
void SlideInterfacePrivate::org_kde_kwin_slide_set_location(Resource *resource, uint32_t location)
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
2020-12-01 11:03:48 +00:00
|
|
|
Q_UNUSED(resource)
|
|
|
|
pendingLocation = (SlideInterface::Location)location;
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
void SlideInterfacePrivate::org_kde_kwin_slide_set_offset(Resource *resource, int32_t offset)
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
2020-12-01 11:03:48 +00:00
|
|
|
Q_UNUSED(resource)
|
|
|
|
pendingOffset = offset;
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
void SlideInterfacePrivate::org_kde_kwin_slide_release(Resource *resource)
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
2020-12-01 11:03:48 +00:00
|
|
|
wl_resource_destroy(resource->handle);
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
void SlideInterfacePrivate::org_kde_kwin_slide_destroy_resource(Resource *resource)
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
2020-12-01 11:03:48 +00:00
|
|
|
Q_UNUSED(resource)
|
|
|
|
delete q;
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
SlideInterfacePrivate::SlideInterfacePrivate(SlideInterface *_q, wl_resource *resource)
|
|
|
|
: QtWaylandServer::org_kde_kwin_slide(resource)
|
|
|
|
, q(_q)
|
|
|
|
{
|
|
|
|
}
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2020-12-01 11:03:48 +00:00
|
|
|
SlideInterface::SlideInterface(SlideManagerInterface *manager, wl_resource *resource)
|
|
|
|
: QObject(manager)
|
|
|
|
, d(new SlideInterfacePrivate(this, resource))
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SlideInterface::~SlideInterface() = default;
|
|
|
|
|
|
|
|
SlideInterface::Location SlideInterface::location() const
|
|
|
|
{
|
|
|
|
return d->currentLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint32 SlideInterface::offset() const
|
|
|
|
{
|
|
|
|
return d->currentOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|