2014-10-14 12:04:35 +00:00
|
|
|
/********************************************************************
|
|
|
|
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
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 "subcompositor_interface.h"
|
|
|
|
#include "subsurface_interface_p.h"
|
2014-11-13 14:07:31 +00:00
|
|
|
#include "global_p.h"
|
2014-10-14 12:04:35 +00:00
|
|
|
#include "display.h"
|
|
|
|
#include "surface_interface_p.h"
|
|
|
|
// Wayland
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
|
|
|
namespace KWayland
|
|
|
|
{
|
|
|
|
namespace Server
|
|
|
|
{
|
|
|
|
|
2014-11-13 14:07:31 +00:00
|
|
|
class SubCompositorInterface::Private : public Global::Private
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private(SubCompositorInterface *q, Display *d);
|
|
|
|
|
|
|
|
private:
|
2014-11-13 17:43:18 +00:00
|
|
|
void bind(wl_client *client, uint32_t version, uint32_t id) override;
|
2014-10-14 12:04:35 +00:00
|
|
|
void subsurface(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface, wl_resource *parent);
|
|
|
|
|
|
|
|
static void unbind(wl_resource *resource);
|
|
|
|
static void destroyCallback(wl_client *client, wl_resource *resource);
|
|
|
|
static void subsurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface, wl_resource *parent);
|
|
|
|
|
|
|
|
static Private *cast(wl_resource *r) {
|
|
|
|
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
|
|
|
|
}
|
|
|
|
|
|
|
|
SubCompositorInterface *q;
|
|
|
|
static const struct wl_subcompositor_interface s_interface;
|
2015-09-10 07:23:36 +00:00
|
|
|
static const quint32 s_version;
|
2014-10-14 12:04:35 +00:00
|
|
|
};
|
|
|
|
|
2015-09-10 07:23:36 +00:00
|
|
|
const quint32 SubCompositorInterface::Private::s_version = 1;
|
|
|
|
|
2015-09-09 14:39:50 +00:00
|
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
2014-10-14 12:04:35 +00:00
|
|
|
const struct wl_subcompositor_interface SubCompositorInterface::Private::s_interface = {
|
|
|
|
destroyCallback,
|
|
|
|
subsurfaceCallback
|
|
|
|
};
|
2015-09-09 14:39:50 +00:00
|
|
|
#endif
|
2014-10-14 12:04:35 +00:00
|
|
|
|
|
|
|
SubCompositorInterface::Private::Private(SubCompositorInterface *q, Display *d)
|
2014-11-13 17:43:18 +00:00
|
|
|
: Global::Private(d, &wl_subcompositor_interface, s_version)
|
2014-10-14 12:04:35 +00:00
|
|
|
, q(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubCompositorInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
|
|
|
|
{
|
2014-11-19 18:01:15 +00:00
|
|
|
auto c = display->getConnection(client);
|
|
|
|
wl_resource *resource = c->createResource(&wl_subcompositor_interface, qMin(version, s_version), id);
|
2014-10-14 12:04:35 +00:00
|
|
|
if (!resource) {
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubCompositorInterface::Private::unbind(wl_resource *resource)
|
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubCompositorInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
|
|
|
Q_UNUSED(resource)
|
2015-04-20 11:56:41 +00:00
|
|
|
wl_resource_destroy(resource);
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubCompositorInterface::Private::subsurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface, wl_resource *sparent)
|
|
|
|
{
|
|
|
|
cast(resource)->subsurface(client, resource, id, surface, sparent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubCompositorInterface::Private::subsurface(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *nativeSurface, wl_resource *nativeParentSurface)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
|
|
|
SurfaceInterface *surface = SurfaceInterface::get(nativeSurface);
|
|
|
|
SurfaceInterface *parentSurface = SurfaceInterface::get(nativeParentSurface);
|
|
|
|
if (!surface || !parentSurface) {
|
|
|
|
wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Surface or parent surface not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (surface == parentSurface) {
|
|
|
|
wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Cannot become sub composite to same surface");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// TODO: add check that surface is not already used in an interface (e.g. Shell)
|
|
|
|
// TODO: add check that parentSurface is not a child of surface
|
2014-11-20 15:40:14 +00:00
|
|
|
SubSurfaceInterface *s = new SubSurfaceInterface(q, resource);
|
2014-11-19 15:53:56 +00:00
|
|
|
s->d_func()->create(display->getConnection(client), wl_resource_get_version(resource), id, surface, parentSurface);
|
2014-11-13 12:05:01 +00:00
|
|
|
if (!s->resource()) {
|
2014-10-14 12:04:35 +00:00
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
delete s;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emit q->subSurfaceCreated(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
SubCompositorInterface::SubCompositorInterface(Display *display, QObject *parent)
|
2014-11-13 14:07:31 +00:00
|
|
|
: Global(new Private(this, display), parent)
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:07:31 +00:00
|
|
|
SubCompositorInterface::~SubCompositorInterface() = default;
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2015-09-09 14:39:50 +00:00
|
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
2014-10-14 12:04:35 +00:00
|
|
|
const struct wl_subsurface_interface SubSurfaceInterface::Private::s_interface = {
|
|
|
|
destroyCallback,
|
|
|
|
setPositionCallback,
|
|
|
|
placeAboveCallback,
|
|
|
|
placeBelowCallback,
|
|
|
|
setSyncCallback,
|
|
|
|
setDeSyncCallback
|
|
|
|
};
|
2015-09-09 14:39:50 +00:00
|
|
|
#endif
|
2014-10-14 12:04:35 +00:00
|
|
|
|
2014-11-20 15:40:14 +00:00
|
|
|
SubSurfaceInterface::Private::Private(SubSurfaceInterface *q, SubCompositorInterface *compositor, wl_resource *parentResource)
|
|
|
|
: Resource::Private(q, compositor, parentResource, &wl_subsurface_interface, &s_interface)
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SubSurfaceInterface::Private::~Private()
|
|
|
|
{
|
|
|
|
// no need to notify the surface as it's tracking a QPointer which will be reset automatically
|
|
|
|
if (parent) {
|
2014-11-14 09:55:06 +00:00
|
|
|
Q_Q(SubSurfaceInterface);
|
2014-11-14 08:45:02 +00:00
|
|
|
reinterpret_cast<SurfaceInterface::Private*>(parent->d.data())->removeChild(QPointer<SubSurfaceInterface>(q));
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
2014-11-14 08:45:02 +00:00
|
|
|
}
|
|
|
|
|
2014-11-19 15:53:56 +00:00
|
|
|
void SubSurfaceInterface::Private::create(ClientConnection *client, quint32 version, quint32 id, SurfaceInterface *s, SurfaceInterface *p)
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
create(client, version, id);
|
|
|
|
if (!resource) {
|
2014-10-14 12:04:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
surface = s;
|
|
|
|
parent = p;
|
2014-11-14 09:55:06 +00:00
|
|
|
Q_Q(SubSurfaceInterface);
|
2014-11-14 08:45:02 +00:00
|
|
|
surface->d_func()->subSurface = QPointer<SubSurfaceInterface>(q);
|
|
|
|
parent->d_func()->addChild(QPointer<SubSurfaceInterface>(q));
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::commit()
|
|
|
|
{
|
|
|
|
if (scheduledPosChange) {
|
|
|
|
scheduledPosChange = false;
|
|
|
|
pos = scheduledPos;
|
|
|
|
scheduledPos = QPoint();
|
2014-11-14 09:55:06 +00:00
|
|
|
Q_Q(SubSurfaceInterface);
|
2014-10-14 12:04:35 +00:00
|
|
|
emit q->positionChanged(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
2015-04-20 11:56:41 +00:00
|
|
|
wl_resource_destroy(resource);
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::setPositionCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
|
|
|
// TODO: is this a fixed position?
|
2014-11-14 09:20:43 +00:00
|
|
|
cast<Private>(resource)->setPosition(QPoint(x, y));
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::setPosition(const QPoint &p)
|
|
|
|
{
|
|
|
|
if (scheduledPos == p) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
scheduledPos = p;
|
|
|
|
scheduledPosChange = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::placeAboveCallback(wl_client *client, wl_resource *resource, wl_resource *sibling)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
2014-11-14 09:20:43 +00:00
|
|
|
cast<Private>(resource)->placeAbove(SurfaceInterface::get(sibling));
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::placeAbove(SurfaceInterface *sibling)
|
|
|
|
{
|
|
|
|
if (parent.isNull()) {
|
|
|
|
// TODO: raise error
|
|
|
|
return;
|
|
|
|
}
|
2014-11-14 09:55:06 +00:00
|
|
|
Q_Q(SubSurfaceInterface);
|
2014-11-14 08:45:02 +00:00
|
|
|
if (!parent->d_func()->raiseChild(QPointer<SubSurfaceInterface>(q), sibling)) {
|
|
|
|
wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Incorrect sibling");
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::placeBelowCallback(wl_client *client, wl_resource *resource, wl_resource *sibling)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
2014-11-14 09:20:43 +00:00
|
|
|
cast<Private>(resource)->placeBelow(SurfaceInterface::get(sibling));
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::placeBelow(SurfaceInterface *sibling)
|
|
|
|
{
|
|
|
|
if (parent.isNull()) {
|
|
|
|
// TODO: raise error
|
|
|
|
return;
|
|
|
|
}
|
2014-11-14 09:55:06 +00:00
|
|
|
Q_Q(SubSurfaceInterface);
|
2014-11-14 08:45:02 +00:00
|
|
|
if (!parent->d_func()->lowerChild(QPointer<SubSurfaceInterface>(q), sibling)) {
|
|
|
|
wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Incorrect sibling");
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::setSyncCallback(wl_client *client, wl_resource *resource)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
2014-11-14 09:20:43 +00:00
|
|
|
cast<Private>(resource)->setMode(Mode::Synchronized);
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::setDeSyncCallback(wl_client *client, wl_resource *resource)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
2014-11-14 09:20:43 +00:00
|
|
|
cast<Private>(resource)->setMode(Mode::Desynchronized);
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubSurfaceInterface::Private::setMode(Mode m)
|
|
|
|
{
|
|
|
|
if (mode == m) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mode = m;
|
2014-11-14 09:55:06 +00:00
|
|
|
Q_Q(SubSurfaceInterface);
|
2014-10-14 12:04:35 +00:00
|
|
|
emit q->modeChanged(m);
|
|
|
|
}
|
|
|
|
|
2014-11-20 15:40:14 +00:00
|
|
|
SubSurfaceInterface::SubSurfaceInterface(SubCompositorInterface *parent, wl_resource *parentResource)
|
|
|
|
: Resource(new Private(this, parent, parentResource))
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
}
|
|
|
|
|
|
|
|
SubSurfaceInterface::~SubSurfaceInterface() = default;
|
|
|
|
|
|
|
|
QPoint SubSurfaceInterface::position() const
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-10-14 12:04:35 +00:00
|
|
|
return d->pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointer<SurfaceInterface> SubSurfaceInterface::surface()
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-10-14 12:04:35 +00:00
|
|
|
return d->surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointer<SurfaceInterface> SubSurfaceInterface::parentSurface()
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-10-14 12:04:35 +00:00
|
|
|
return d->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubSurfaceInterface::Mode SubSurfaceInterface::mode() const
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-10-14 12:04:35 +00:00
|
|
|
return d->mode;
|
|
|
|
}
|
|
|
|
|
2016-03-18 09:41:56 +00:00
|
|
|
bool SubSurfaceInterface::isSynchronized() const
|
|
|
|
{
|
|
|
|
Q_D();
|
|
|
|
if (d->mode == Mode::Synchronized) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (d->parent.isNull()) {
|
|
|
|
// that shouldn't happen, but let's assume false
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!d->parent->subSurface().isNull()) {
|
|
|
|
// follow parent's mode
|
|
|
|
return d->parent->subSurface()->isSynchronized();
|
|
|
|
}
|
|
|
|
// parent is no subsurface, thus parent is in desync mode and this surface is in desync mode
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
SubSurfaceInterface::Private *SubSurfaceInterface::d_func() const
|
|
|
|
{
|
|
|
|
return reinterpret_cast<SubSurfaceInterface::Private*>(d.data());
|
|
|
|
}
|
|
|
|
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
}
|