| 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 <QtGui/qscreen_platform.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 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | namespace QtWaylandClient { |
| 29 | |
| 30 | class QWaylandDisplay; |
| 31 | class QWaylandCursor; |
| 32 | |
| 33 | class Q_WAYLANDCLIENT_EXPORT QWaylandXdgOutputManagerV1 : public QtWayland::zxdg_output_manager_v1 { |
| 34 | public: |
| 35 | QWaylandXdgOutputManagerV1(QWaylandDisplay *display, uint id, uint version); |
| 36 | ~QWaylandXdgOutputManagerV1(); |
| 37 | }; |
| 38 | |
| 39 | class Q_WAYLANDCLIENT_EXPORT QWaylandScreen : public QPlatformScreen, |
| 40 | QtWayland::wl_output, |
| 41 | QtWayland::zxdg_output_v1, |
| 42 | public QNativeInterface::QWaylandScreen |
| 43 | { |
| 44 | public: |
| 45 | QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id); |
| 46 | ~QWaylandScreen() override; |
| 47 | |
| 48 | void maybeInitialize(); |
| 49 | |
| 50 | void initXdgOutput(QWaylandXdgOutputManagerV1 *xdgOutputManager); |
| 51 | |
| 52 | QWaylandDisplay *display() const; |
| 53 | |
| 54 | QString manufacturer() const override; |
| 55 | QString model() const override; |
| 56 | |
| 57 | QRect geometry() const override; |
| 58 | int depth() const override; |
| 59 | QImage::Format format() const override; |
| 60 | |
| 61 | QSizeF physicalSize() const override; |
| 62 | |
| 63 | QDpi logicalDpi() const override; |
| 64 | QList<QPlatformScreen *> virtualSiblings() const override; |
| 65 | |
| 66 | Qt::ScreenOrientation orientation() const override; |
| 67 | int scale() const; |
| 68 | qreal devicePixelRatio() const override; |
| 69 | qreal refreshRate() const override; |
| 70 | |
| 71 | QString name() const override { return mOutputName; } |
| 72 | |
| 73 | #if QT_CONFIG(cursor) |
| 74 | QPlatformCursor *cursor() const override; |
| 75 | #endif |
| 76 | |
| 77 | SubpixelAntialiasingType subpixelAntialiasingTypeHint() const override; |
| 78 | |
| 79 | uint32_t outputId() const { return m_outputId; } |
| 80 | ::wl_output *output() const override |
| 81 | { |
| 82 | return const_cast<::wl_output *>(QtWayland::wl_output::object()); |
| 83 | } |
| 84 | |
| 85 | static QWaylandScreen *waylandScreenFromWindow(QWindow *window); |
| 86 | static QWaylandScreen *fromWlOutput(::wl_output *output); |
| 87 | |
| 88 | Qt::ScreenOrientation toScreenOrientation(int wlTransform, |
| 89 | Qt::ScreenOrientation fallback) const; |
| 90 | |
| 91 | protected: |
| 92 | enum Event : uint { |
| 93 | XdgOutputDoneEvent = 0x1, |
| 94 | OutputDoneEvent = 0x2, |
| 95 | XdgOutputNameEvent = 0x4, |
| 96 | }; |
| 97 | uint requiredEvents() const; |
| 98 | |
| 99 | void output_mode(uint32_t flags, int width, int height, int refresh) override; |
| 100 | void output_geometry(int32_t x, int32_t y, |
| 101 | int32_t width, int32_t height, |
| 102 | int subpixel, |
| 103 | const QString &make, |
| 104 | const QString &model, |
| 105 | int32_t transform) override; |
| 106 | void output_scale(int32_t factor) override; |
| 107 | void output_done() override; |
| 108 | void updateOutputProperties(); |
| 109 | |
| 110 | // XdgOutput |
| 111 | void zxdg_output_v1_logical_position(int32_t x, int32_t y) override; |
| 112 | void zxdg_output_v1_logical_size(int32_t width, int32_t height) override; |
| 113 | void zxdg_output_v1_done() override; |
| 114 | void zxdg_output_v1_name(const QString &name) override; |
| 115 | void updateXdgOutputProperties(); |
| 116 | |
| 117 | int m_outputId; |
| 118 | QWaylandDisplay *mWaylandDisplay = nullptr; |
| 119 | QString mManufacturer; |
| 120 | QString mModel; |
| 121 | QRect mGeometry; |
| 122 | QRect mXdgGeometry; |
| 123 | int mScale = 1; |
| 124 | int mDepth = 32; |
| 125 | int mRefreshRate = 60000; |
| 126 | int mSubpixel = -1; |
| 127 | int mTransform = -1; |
| 128 | QImage::Format mFormat = QImage::Format_ARGB32_Premultiplied; |
| 129 | QSize mPhysicalSize; |
| 130 | QString mOutputName; |
| 131 | Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; |
| 132 | uint mProcessedEvents = 0; |
| 133 | bool mInitialized = false; |
| 134 | }; |
| 135 | |
| 136 | } |
| 137 | |
| 138 | QT_END_NAMESPACE |
| 139 | |
| 140 | #endif // QWAYLANDSCREEN_H |
| 141 | |