1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWAYLANDSCREEN_H
5#define QWAYLANDSCREEN_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <qpa/qplatformscreen.h>
19#include <qpa/qplatformscreen_p.h>
20#include <QtWaylandClient/qtwaylandclientglobal.h>
21
22#include <QtWaylandClient/private/qwayland-wayland.h>
23#include <QtWaylandClient/private/qwayland-xdg-output-unstable-v1.h>
24#include <QtCore/private/qglobal_p.h>
25
26QT_BEGIN_NAMESPACE
27
28namespace QtWaylandClient {
29
30class QWaylandDisplay;
31class QWaylandCursor;
32
33class Q_WAYLANDCLIENT_EXPORT QWaylandXdgOutputManagerV1 : public QtWayland::zxdg_output_manager_v1 {
34public:
35 QWaylandXdgOutputManagerV1(QWaylandDisplay *display, uint id, uint version);
36};
37
38class Q_WAYLANDCLIENT_EXPORT QWaylandScreen : public QPlatformScreen,
39 QtWayland::wl_output,
40 QtWayland::zxdg_output_v1,
41 public QNativeInterface::Private::QWaylandScreen
42{
43public:
44 QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id);
45 ~QWaylandScreen() override;
46
47 void maybeInitialize();
48
49 void initXdgOutput(QWaylandXdgOutputManagerV1 *xdgOutputManager);
50
51 QWaylandDisplay *display() const;
52
53 QString manufacturer() const override;
54 QString model() const override;
55
56 QRect geometry() const override;
57 int depth() const override;
58 QImage::Format format() const override;
59
60 QSizeF physicalSize() const override;
61
62 QDpi logicalDpi() const override;
63 QList<QPlatformScreen *> virtualSiblings() const override;
64
65 Qt::ScreenOrientation orientation() const override;
66 int scale() const;
67 qreal devicePixelRatio() const override;
68 qreal refreshRate() const override;
69
70 QString name() const override { return mOutputName; }
71
72#if QT_CONFIG(cursor)
73 QPlatformCursor *cursor() const override;
74#endif
75
76 uint32_t outputId() const { return m_outputId; }
77 ::wl_output *output() const override
78 {
79 return const_cast<::wl_output *>(QtWayland::wl_output::object());
80 }
81
82 static QWaylandScreen *waylandScreenFromWindow(QWindow *window);
83 static QWaylandScreen *fromWlOutput(::wl_output *output);
84
85protected:
86 enum Event : uint {
87 XdgOutputDoneEvent = 0x1,
88 OutputDoneEvent = 0x2,
89 XdgOutputNameEvent = 0x4,
90 };
91 uint requiredEvents() const;
92
93 void output_mode(uint32_t flags, int width, int height, int refresh) override;
94 void output_geometry(int32_t x, int32_t y,
95 int32_t width, int32_t height,
96 int subpixel,
97 const QString &make,
98 const QString &model,
99 int32_t transform) override;
100 void output_scale(int32_t factor) override;
101 void output_done() override;
102 void updateOutputProperties();
103
104 // XdgOutput
105 void zxdg_output_v1_logical_position(int32_t x, int32_t y) override;
106 void zxdg_output_v1_logical_size(int32_t width, int32_t height) override;
107 void zxdg_output_v1_done() override;
108 void zxdg_output_v1_name(const QString &name) override;
109 void updateXdgOutputProperties();
110
111 int m_outputId;
112 QWaylandDisplay *mWaylandDisplay = nullptr;
113 QString mManufacturer;
114 QString mModel;
115 QRect mGeometry;
116 QRect mXdgGeometry;
117 int mScale = 1;
118 int mDepth = 32;
119 int mRefreshRate = 60000;
120 int mTransform = -1;
121 QImage::Format mFormat = QImage::Format_ARGB32_Premultiplied;
122 QSize mPhysicalSize;
123 QString mOutputName;
124 Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation;
125 uint mProcessedEvents = 0;
126 bool mInitialized = false;
127};
128
129}
130
131QT_END_NAMESPACE
132
133#endif // QWAYLANDSCREEN_H
134

source code of qtwayland/src/client/qwaylandscreen_p.h