Move XdgOutput mocking to shared folder

Change-Id: Ia4fe187d33ddfd25a87dac8567143de6466c75a2
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Johan Klokkhammer Helsing 2020-01-09 10:28:24 +01:00
parent ea3a3638e6
commit d4027bc3fe
4 changed files with 133 additions and 58 deletions

View File

@ -4,6 +4,7 @@ QMAKE_USE += wayland-server
WAYLANDSERVERSOURCES += \
$$PWD/../../../../src/3rdparty/protocol/wayland.xml \
$$PWD/../../../../src/3rdparty/protocol/xdg-output-unstable-v1.xml \
$$PWD/../../../../src/3rdparty/protocol/xdg-shell.xml \
$$PWD/../../../../src/3rdparty/protocol/text-input-unstable-v2.xml
@ -14,6 +15,7 @@ HEADERS += \
$$PWD/coreprotocol.h \
$$PWD/datadevice.h \
$$PWD/mockcompositor.h \
$$PWD/xdgoutputv1.h \
$$PWD/xdgshell.h \
$$PWD/textinput.h
@ -22,5 +24,6 @@ SOURCES += \
$$PWD/coreprotocol.cpp \
$$PWD/datadevice.cpp \
$$PWD/mockcompositor.cpp \
$$PWD/xdgoutputv1.cpp \
$$PWD/xdgshell.cpp \
$$PWD/textinput.cpp

View File

@ -0,0 +1,35 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "xdgoutputv1.h"
namespace MockCompositor {
int XdgOutputV1::s_nextId = 1;
} // namespace MockCompositor

View File

@ -0,0 +1,93 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MOCKCOMPOSITOR_XDGOUTPUTV1_H
#define MOCKCOMPOSITOR_XDGOUTPUTV1_H
#include "coreprotocol.h"
#include <qwayland-server-xdg-output-unstable-v1.h>
namespace MockCompositor {
class XdgOutputV1 : public QObject, public QtWaylandServer::zxdg_output_v1
{
public:
explicit XdgOutputV1(Output *output)
: m_output(output)
, m_logicalGeometry(m_output->m_data.position, QSize(m_output->m_data.mode.resolution / m_output->m_data.scale))
, m_name(QString("WL-%1").arg(s_nextId++))
{}
void addResource(wl_client *client, int id, int version)
{
auto *resource = add(client, id, version)->handle;
send_logical_size(resource, m_logicalGeometry.width(), m_logicalGeometry.height());
send_logical_position(resource, m_logicalGeometry.x(), m_logicalGeometry.y());
if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)
send_name(resource, m_name);
if (version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION)
send_description(resource, m_description);
send_done(resource);
}
Output *m_output = nullptr;
QRect m_logicalGeometry;
QString m_name;
QString m_description = "This is an Xdg Output description";
static int s_nextId;
};
class XdgOutputManagerV1 : public Global, public QtWaylandServer::zxdg_output_manager_v1
{
Q_OBJECT
public:
explicit XdgOutputManagerV1(CoreCompositor *compositor, int version = 2)
: QtWaylandServer::zxdg_output_manager_v1(compositor->m_display, version)
, m_version(version)
{}
int m_version = 1; // TODO: remove on libwayland upgrade
QMap<Output *, XdgOutputV1 *> m_xdgOutputs;
XdgOutputV1 *getXdgOutput(Output *output)
{
if (auto *xdgOutput = m_xdgOutputs.value(output))
return xdgOutput;
return m_xdgOutputs[output] = new XdgOutputV1(output); // TODO: free memory
}
protected:
void zxdg_output_manager_v1_get_xdg_output(Resource *resource, uint32_t id, wl_resource *outputResource) override
{
auto *output = fromResource<Output>(outputResource);
auto *xdgOutput = getXdgOutput(output);
xdgOutput->addResource(resource->client(), id, resource->version());
}
};
} // namespace MockCompositor
#endif // MOCKCOMPOSITOR_XDGOUTPUTV1_H

View File

@ -26,71 +26,15 @@
**
****************************************************************************/
#include "xdgoutputv1.h"
#include "mockcompositor.h"
#include <QtGui/QRasterWindow>
#include <QtGui/QOpenGLWindow>
#include <QtGui/QScreen>
#include <qwayland-server-xdg-output-unstable-v1.h>
using namespace MockCompositor;
// TODO: move to shared folder?
class XdgOutputV1 : public QObject, public QtWaylandServer::zxdg_output_v1
{
public:
explicit XdgOutputV1(Output *output)
: m_output(output)
, m_logicalGeometry(m_output->m_data.position, QSize(m_output->m_data.mode.resolution / m_output->m_data.scale))
, m_name(QString("WL-%1").arg(s_nextId++))
{}
void addResource(wl_client *client, int id, int version)
{
auto *resource = add(client, id, version)->handle;
send_logical_size(resource, m_logicalGeometry.width(), m_logicalGeometry.height());
send_logical_position(resource, m_logicalGeometry.x(), m_logicalGeometry.y());
if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)
send_name(resource, m_name);
if (version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION)
send_description(resource, m_description);
send_done(resource);
}
Output *m_output = nullptr;
QRect m_logicalGeometry;
QString m_name;
QString m_description = "This is an Xdg Output description";
static int s_nextId;
};
int XdgOutputV1::s_nextId = 1;
class XdgOutputManagerV1 : public Global, public QtWaylandServer::zxdg_output_manager_v1
{
Q_OBJECT
public:
explicit XdgOutputManagerV1(CoreCompositor *compositor, int version = 2)
: QtWaylandServer::zxdg_output_manager_v1(compositor->m_display, version)
, m_version(version)
{}
int m_version = 1; // TODO: remove on libwayland upgrade
QMap<Output *, XdgOutputV1 *> m_xdgOutputs;
XdgOutputV1 *getXdgOutput(Output *output)
{
if (auto *xdgOutput = m_xdgOutputs.value(output))
return xdgOutput;
return m_xdgOutputs[output] = new XdgOutputV1(output); // TODO: free memory
}
protected:
void zxdg_output_manager_v1_get_xdg_output(Resource *resource, uint32_t id, wl_resource *outputResource) override
{
auto *output = fromResource<Output>(outputResource);
auto *xdgOutput = getXdgOutput(output);
xdgOutput->addResource(resource->client(), id, resource->version());
}
};
class XdgOutputV1Compositor : public DefaultCompositor {
public:
explicit XdgOutputV1Compositor()