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

source code of qtbase/src/gui/kernel/qplatformscreen.h