summaryrefslogtreecommitdiffstats
path: root/tests/auto/client/shared/xdgoutputv1.h
blob: 8c6276741b76b1ad0d0f4f93b2c26f69d49dfd60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#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 send_logical_size(int32_t width, int32_t height) = delete;
    void sendLogicalSize(const QSize &size);

    void send_done() = delete; // zxdg_output_v1.done has been deprecated (in protocol version 3)

    void addResource(wl_client *client, int id, int version);
    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 = 3)
        : 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