| 1 | // Copyright (C) 2016 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 QPLATFORMSCREEN_H |
| 5 | #define QPLATFORMSCREEN_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is part of the QPA API and is not meant to be used |
| 12 | // in applications. Usage of this API may make your code |
| 13 | // source and binary incompatible with future versions of Qt. |
| 14 | // |
| 15 | |
| 16 | #include <QtGui/qtguiglobal.h> |
| 17 | #include <QtCore/qmetatype.h> |
| 18 | #include <QtCore/qnamespace.h> |
| 19 | #include <QtCore/qcoreevent.h> |
| 20 | #include <QtCore/qvariant.h> |
| 21 | #include <QtCore/qrect.h> |
| 22 | #include <QtCore/qobject.h> |
| 23 | |
| 24 | #include <QtGui/qcolorspace.h> |
| 25 | #include <QtGui/qcursor.h> |
| 26 | #include <QtGui/qimage.h> |
| 27 | #include <QtGui/qwindowdefs.h> |
| 28 | #include <qpa/qplatformpixmap.h> |
| 29 | |
| 30 | QT_BEGIN_NAMESPACE |
| 31 | |
| 32 | |
| 33 | class QPlatformBackingStore; |
| 34 | class QPlatformScreenPrivate; |
| 35 | class QPlatformWindow; |
| 36 | class QPlatformCursor; |
| 37 | class QScreen; |
| 38 | class QSurfaceFormat; |
| 39 | |
| 40 | typedef QPair<qreal, qreal> QDpi; |
| 41 | |
| 42 | |
| 43 | class Q_GUI_EXPORT QPlatformScreen |
| 44 | { |
| 45 | Q_GADGET |
| 46 | Q_DECLARE_PRIVATE(QPlatformScreen) |
| 47 | |
| 48 | public: |
| 49 | Q_DISABLE_COPY_MOVE(QPlatformScreen) |
| 50 | |
| 51 | enum SubpixelAntialiasingType { // copied from qfontengine_p.h since we can't include private headers |
| 52 | Subpixel_None, |
| 53 | Subpixel_RGB, |
| 54 | Subpixel_BGR, |
| 55 | Subpixel_VRGB, |
| 56 | Subpixel_VBGR |
| 57 | }; |
| 58 | |
| 59 | enum PowerState { |
| 60 | PowerStateOn, |
| 61 | PowerStateStandby, |
| 62 | PowerStateSuspend, |
| 63 | PowerStateOff |
| 64 | }; |
| 65 | |
| 66 | struct Mode { |
| 67 | QSize size; |
| 68 | qreal refreshRate; |
| 69 | }; |
| 70 | |
| 71 | QPlatformScreen(); |
| 72 | virtual ~QPlatformScreen(); |
| 73 | |
| 74 | virtual bool isPlaceholder() const { return false; } |
| 75 | |
| 76 | virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const; |
| 77 | |
| 78 | virtual QRect geometry() const = 0; |
| 79 | virtual QRect availableGeometry() const {return geometry();} |
| 80 | |
| 81 | virtual int depth() const = 0; |
| 82 | virtual QImage::Format format() const = 0; |
| 83 | virtual QColorSpace colorSpace() const { return QColorSpace::SRgb; } |
| 84 | |
| 85 | virtual QSizeF physicalSize() const; |
| 86 | virtual QDpi logicalDpi() const; |
| 87 | virtual QDpi logicalBaseDpi() const; |
| 88 | virtual qreal devicePixelRatio() const; |
| 89 | |
| 90 | virtual qreal refreshRate() const; |
| 91 | |
| 92 | virtual Qt::ScreenOrientation nativeOrientation() const; |
| 93 | virtual Qt::ScreenOrientation orientation() const; |
| 94 | |
| 95 | virtual QWindow *topLevelAt(const QPoint &point) const; |
| 96 | QWindowList windows() const; |
| 97 | |
| 98 | virtual QList<QPlatformScreen *> virtualSiblings() const; |
| 99 | const QPlatformScreen *screenForPosition(const QPoint &point) const; |
| 100 | |
| 101 | QScreen *screen() const; |
| 102 | |
| 103 | //jl: should this function be in QPlatformIntegration |
| 104 | //jl: maybe screenForWindow is a better name? |
| 105 | static QPlatformScreen *platformScreenForWindow(const QWindow *window); |
| 106 | |
| 107 | virtual QString name() const { return QString(); } |
| 108 | |
| 109 | virtual QString manufacturer() const; |
| 110 | virtual QString model() const; |
| 111 | virtual QString serialNumber() const; |
| 112 | |
| 113 | virtual QPlatformCursor *cursor() const; |
| 114 | virtual SubpixelAntialiasingType subpixelAntialiasingTypeHint() const; |
| 115 | |
| 116 | virtual PowerState powerState() const; |
| 117 | virtual void setPowerState(PowerState state); |
| 118 | |
| 119 | virtual QList<Mode> modes() const; |
| 120 | |
| 121 | virtual int currentMode() const; |
| 122 | virtual int preferredMode() const; |
| 123 | |
| 124 | static int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b); |
| 125 | static QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target); |
| 126 | static QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect); |
| 127 | |
| 128 | static QDpi overrideDpi(const QDpi &in); |
| 129 | |
| 130 | protected: |
| 131 | void resizeMaximizedWindows(); |
| 132 | |
| 133 | QScopedPointer<QPlatformScreenPrivate> d_ptr; |
| 134 | |
| 135 | private: |
| 136 | friend class QScreen; |
| 137 | }; |
| 138 | |
| 139 | // Qt doesn't currently support running with no platform screen |
| 140 | // QPA plugins can use this class to create a fake screen |
| 141 | class Q_GUI_EXPORT QPlatformPlaceholderScreen : public QPlatformScreen { |
| 142 | public: |
| 143 | // virtualSibling can be passed in to make the placeholder a sibling with other screens during |
| 144 | // the transitioning phase when the real screen is about to be removed, or the first real screen |
| 145 | // is about to be added. This is useful because Qt will currently recreate (but now show!) |
| 146 | // windows when they are moved from one virtual desktop to another, so if the last monitor is |
| 147 | // unplugged, then plugged in again, windows will be hidden unless the placeholder belongs to |
| 148 | // the same virtual desktop as the other screens. |
| 149 | QPlatformPlaceholderScreen(bool virtualSibling = true) : m_virtualSibling(virtualSibling) {} |
| 150 | bool isPlaceholder() const override { return true; } |
| 151 | QRect geometry() const override { return QRect(); } |
| 152 | QRect availableGeometry() const override { return QRect(); } |
| 153 | int depth() const override { return 32; } |
| 154 | QImage::Format format() const override { return QImage::Format::Format_RGB32; } |
| 155 | QList<QPlatformScreen *> virtualSiblings() const override; |
| 156 | private: |
| 157 | bool m_virtualSibling = true; |
| 158 | }; |
| 159 | |
| 160 | QT_END_NAMESPACE |
| 161 | |
| 162 | #endif // QPLATFORMSCREEN_H |
| 163 | |