1 /*
2     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #ifndef WAYLAND_SERVER_OUTPUT_INTERFACE_H
7 #define WAYLAND_SERVER_OUTPUT_INTERFACE_H
8 
9 #include <QObject>
10 #include <QPoint>
11 #include <QSize>
12 
13 #include "global.h"
14 #include <KWayland/Server/kwaylandserver_export.h>
15 
16 struct wl_global;
17 struct wl_client;
18 struct wl_resource;
19 
20 namespace KWayland
21 {
22 namespace Server
23 {
24 class ClientConnection;
25 class Display;
26 
27 /**
28  * @brief Global for the wl_output interface.
29  *
30  **/
31 class KWAYLANDSERVER_EXPORT OutputInterface : public Global
32 {
33     Q_OBJECT
34     Q_PROPERTY(QSize physicalSize READ physicalSize WRITE setPhysicalSize NOTIFY physicalSizeChanged)
35     Q_PROPERTY(QPoint globalPosition READ globalPosition WRITE setGlobalPosition NOTIFY globalPositionChanged)
36     Q_PROPERTY(QString manufacturer READ manufacturer WRITE setManufacturer NOTIFY manufacturerChanged)
37     Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged)
38     Q_PROPERTY(QSize pixelSize READ pixelSize NOTIFY pixelSizeChanged)
39     Q_PROPERTY(int refreshRate READ refreshRate NOTIFY refreshRateChanged)
40     Q_PROPERTY(int scale READ scale WRITE setScale NOTIFY scaleChanged)
41 public:
42     enum class SubPixel {
43         Unknown,
44         None,
45         HorizontalRGB,
46         HorizontalBGR,
47         VerticalRGB,
48         VerticalBGR,
49     };
50     enum class Transform {
51         Normal,
52         Rotated90,
53         Rotated180,
54         Rotated270,
55         Flipped,
56         Flipped90,
57         Flipped180,
58         Flipped270,
59     };
60     enum class ModeFlag {
61         Current = 1,
62         Preferred = 2,
63     };
64     Q_DECLARE_FLAGS(ModeFlags, ModeFlag)
65     struct Mode {
66         QSize size = QSize();
67         int refreshRate = 60000;
68         ModeFlags flags;
69     };
70     enum class DpmsMode {
71         On,
72         Standby,
73         Suspend,
74         Off,
75     };
76     ~OutputInterface() override;
77 
78     QSize physicalSize() const;
79     QPoint globalPosition() const;
80     QString manufacturer() const;
81     QString model() const;
82     QSize pixelSize() const;
83     int refreshRate() const;
84     int scale() const;
85     SubPixel subPixel() const;
86     Transform transform() const;
87     QList<Mode> modes() const;
88     bool isDpmsSupported() const;
89     DpmsMode dpmsMode() const;
90 
91     void setPhysicalSize(const QSize &size);
92     void setGlobalPosition(const QPoint &pos);
93     void setManufacturer(const QString &manufacturer);
94     void setModel(const QString &model);
95     void setScale(int scale);
96     void setSubPixel(SubPixel subPixel);
97     void setTransform(Transform transform);
98     void addMode(const QSize &size, ModeFlags flags = ModeFlags(), int refreshRate = 60000);
99     void setCurrentMode(const QSize &size, int refreshRate = 60000);
100 
101     /**
102      * Sets whether Dpms is supported for this output.
103      * Default is @c false.
104      * @since 5.5
105      **/
106     void setDpmsSupported(bool supported);
107     /**
108      * Sets the currently used dpms mode.
109      * Default is @c DpmsMode::On.
110      * @since 5.5
111      **/
112     void setDpmsMode(DpmsMode mode);
113 
114     /**
115      * @returns all wl_resources bound for the @p client
116      * @since 5.27
117      **/
118     QVector<wl_resource *> clientResources(ClientConnection *client) const;
119 
120     static OutputInterface *get(wl_resource *native);
121 
122 Q_SIGNALS:
123     void physicalSizeChanged(const QSize &);
124     void globalPositionChanged(const QPoint &);
125     void manufacturerChanged(const QString &);
126     void modelChanged(const QString &);
127     void pixelSizeChanged(const QSize &);
128     void refreshRateChanged(int);
129     void scaleChanged(int);
130     void subPixelChanged(SubPixel);
131     void transformChanged(Transform);
132     void modesChanged();
133     void currentModeChanged();
134     void dpmsModeChanged();
135     void dpmsSupportedChanged();
136 
137     /**
138      * Change of dpms @p mode is requested.
139      * A server is free to ignore this request.
140      * @since 5.5
141      **/
142     void dpmsModeRequested(KWayland::Server::OutputInterface::DpmsMode mode);
143 
144 private:
145     friend class Display;
146     explicit OutputInterface(Display *display, QObject *parent = nullptr);
147     class Private;
148     Private *d_func() const;
149 };
150 
151 Q_DECLARE_OPERATORS_FOR_FLAGS(OutputInterface::ModeFlags)
152 
153 }
154 }
155 
156 Q_DECLARE_METATYPE(KWayland::Server::OutputInterface::SubPixel)
157 Q_DECLARE_METATYPE(KWayland::Server::OutputInterface::Transform)
158 Q_DECLARE_METATYPE(KWayland::Server::OutputInterface::DpmsMode)
159 
160 #endif
161