abstract_wayland_output.h 4.54 KB
Newer Older
Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
1
2
3
/*
    KWin - the KDE window manager
    This file is part of the KDE project.
4

Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
5
    SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
6

Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
7
8
    SPDX-License-Identifier: GPL-2.0-or-later
*/
9
10
11
12
#ifndef KWIN_ABSTRACT_WAYLAND_OUTPUT_H
#define KWIN_ABSTRACT_WAYLAND_OUTPUT_H

#include "abstract_output.h"
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
13
#include "utils.h"
14
15
16
17
18
19
20
21
22
#include <kwin_export.h>

#include <QObject>
#include <QPoint>
#include <QPointer>
#include <QRect>
#include <QSize>
#include <QVector>

23
24
#include <KWaylandServer/output_interface.h>
#include <KWaylandServer/outputdevice_interface.h>
25

26
namespace KWaylandServer
27
28
29
30
31
{
class OutputInterface;
class OutputDeviceInterface;
class OutputChangeSet;
class OutputManagementInterface;
32
class XdgOutputV1Interface;
33
34
35
36
37
38
39
}

namespace KWin
{

/**
 * Generic output representation in a Wayland session
40
 */
41
42
43
44
class KWIN_EXPORT AbstractWaylandOutput : public AbstractOutput
{
    Q_OBJECT
public:
Roman Gilg's avatar
Roman Gilg committed
45
46
47
48
49
50
51
52
53
54
55
    enum class Transform {
        Normal,
        Rotated90,
        Rotated180,
        Rotated270,
        Flipped,
        Flipped90,
        Flipped180,
        Flipped270
    };

56
    explicit AbstractWaylandOutput(QObject *parent = nullptr);
57
    ~AbstractWaylandOutput() override;
58
59

    QString name() const override;
60
    QByteArray uuid() const override;
61

Roman Gilg's avatar
Roman Gilg committed
62
63
64
    QSize modeSize() const;

    // TODO: The name is ambiguous. Rename this function.
65
    QSize pixelSize() const override;
Roman Gilg's avatar
Roman Gilg committed
66

67
68
    qreal scale() const override;

69
70
    /**
     * The geometry of this output in global compositor co-ordinates (i.e scaled)
71
     */
72
73
74
    QRect geometry() const override;
    QSize physicalSize() const override;

75
76
77
78
79
80
81
82
83
84
85
    /**
     * Returns the orientation of this output.
     *
     * - Flipped along the vertical axis is landscape + inv. portrait.
     * - Rotated 90° and flipped along the horizontal axis is portrait + inv. landscape
     * - Rotated 180° and flipped along the vertical axis is inv. landscape + inv. portrait
     * - Rotated 270° and flipped along the horizontal axis is inv. portrait + inv. landscape +
     *   portrait
     */
    Transform transform() const;

86
87
    /**
     * Current refresh rate in 1/ms.
88
     */
89
90
91
92
93
94
95
96
97
    int refreshRate() const override;

    bool isInternal() const override {
        return m_internal;
    }

    void setGlobalPos(const QPoint &pos);
    void setScale(qreal scale);

98
    void applyChanges(const KWaylandServer::OutputChangeSet *changeSet) override;
99

100
    QPointer<KWaylandServer::OutputInterface> waylandOutput() const {
101
102
103
        return m_waylandOutput;
    }

104
    bool isEnabled() const;
105
106
107
108
109
    /**
     * Enable or disable the output.
     *
     * This differs from updateDpms as it also removes the wl_output.
     * The default is on.
110
     */
111
    void setEnabled(bool enable) override;
112

113
114
    QString description() const;

115
116
117
118
119
120
121
122
123
124
125
126
    /**
     * The current rotation of the output
     *
     * @return rotation in degrees
     */
    int rotation() const;

    /**
     * Returns a matrix that can translate into the display's coordinates system
     */
    QMatrix4x4 transformation() const;

127
128
Q_SIGNALS:
    void modeChanged();
129
    void outputChange(const QRegion &damagedRegion);
130
131

protected:
132
133
    void initInterfaces(const QString &model, const QString &manufacturer,
                        const QByteArray &uuid, const QSize &physicalSize,
134
                        const QVector<KWaylandServer::OutputDeviceInterface::Mode> &modes);
135

136
    QPoint globalPos() const;
137
138
139
140

    bool internal() const {
        return m_internal;
    }
141
142
143
    void setName(const QString &name) {
        m_name = name;
    }
144
145
146
147
    void setInternal(bool set) {
        m_internal = set;
    }
    void setDpmsSupported(bool set) {
148
        m_waylandOutput->setDpmsSupported(set);
149
    }
150
151
152
153

    virtual void updateEnablement(bool enable) {
        Q_UNUSED(enable);
    }
154
    virtual void updateDpms(KWaylandServer::OutputInterface::DpmsMode mode) {
155
156
157
158
159
        Q_UNUSED(mode);
    }
    virtual void updateMode(int modeIndex) {
        Q_UNUSED(modeIndex);
    }
Roman Gilg's avatar
Roman Gilg committed
160
    virtual void updateTransform(Transform transform) {
161
162
163
164
        Q_UNUSED(transform);
    }

    void setWaylandMode(const QSize &size, int refreshRate);
Roman Gilg's avatar
Roman Gilg committed
165
    void setTransform(Transform transform);
166
167
168
169

    QSize orientateSize(const QSize &size) const;

private:
170
    void setTransform(KWaylandServer::OutputDeviceInterface::Transform transform);
171

172
    KWaylandServer::OutputInterface *m_waylandOutput;
173
    KWaylandServer::XdgOutputV1Interface *m_xdgOutputV1;
174
175
    KWaylandServer::OutputDeviceInterface *m_waylandOutputDevice;
    KWaylandServer::OutputInterface::DpmsMode m_dpms = KWaylandServer::OutputInterface::DpmsMode::On;
176

177
    QString m_name;
178
179
180
181
182
183
    bool m_internal = false;
};

}

#endif // KWIN_OUTPUT_H