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 QXCBSCREEN_H |
5 | #define QXCBSCREEN_H |
6 | |
7 | #include <qpa/qplatformscreen.h> |
8 | #include <qpa/qplatformscreen_p.h> |
9 | #include <QtCore/QString> |
10 | |
11 | #include <xcb/xcb.h> |
12 | #include <xcb/randr.h> |
13 | #include <xcb/xfixes.h> |
14 | |
15 | #include "qxcbobject.h" |
16 | |
17 | #include <private/qfontengine_p.h> |
18 | |
19 | #include <QtGui/private/qedidparser_p.h> |
20 | |
21 | #include <memory> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QXcbConnection; |
26 | class QXcbCursor; |
27 | class QXcbXSettings; |
28 | #ifndef QT_NO_DEBUG_STREAM |
29 | class QDebug; |
30 | #endif |
31 | |
32 | class QXcbVirtualDesktop : public QXcbObject |
33 | { |
34 | public: |
35 | QXcbVirtualDesktop(QXcbConnection *connection, xcb_screen_t *screen, int number); |
36 | ~QXcbVirtualDesktop(); |
37 | |
38 | xcb_screen_t *screen() const { return m_screen; } |
39 | int number() const { return m_number; } |
40 | QSize size() const { return QSize(m_screen->width_in_pixels, m_screen->height_in_pixels); } |
41 | QSize physicalSize() const { return QSize(m_screen->width_in_millimeters, m_screen->height_in_millimeters); } |
42 | QDpi dpi() const; |
43 | xcb_window_t root() const { return m_screen->root; } |
44 | QXcbScreen *screenAt(const QPoint &pos) const; |
45 | |
46 | QList<QPlatformScreen *> screens() const { return m_screens; } |
47 | void setScreens(QList<QPlatformScreen *> &&sl) { m_screens = std::move(sl); } |
48 | void removeScreen(QPlatformScreen *s) { m_screens.removeOne(t: s); } |
49 | void addScreen(QPlatformScreen *s); |
50 | void setPrimaryScreen(QPlatformScreen *s); |
51 | |
52 | QXcbXSettings *xSettings() const; |
53 | |
54 | bool compositingActive() const; |
55 | |
56 | void updateWorkArea(); |
57 | QRect availableGeometry(const QRect &screenGeometry) const; |
58 | |
59 | void handleXFixesSelectionNotify(xcb_xfixes_selection_notify_event_t *notify_event); |
60 | void subscribeToXFixesSelectionNotify(); |
61 | |
62 | void handleScreenChange(xcb_randr_screen_change_notify_event_t *change_event); |
63 | |
64 | int forcedDpi() const { return m_forcedDpi; } |
65 | QFontEngine::HintStyle hintStyle() const { return m_hintStyle; } |
66 | QFontEngine::SubpixelAntialiasingType subpixelType() const { return m_subpixelType; } |
67 | int antialiasingEnabled() const { return m_antialiasingEnabled; } |
68 | |
69 | QString windowManagerName() const { return m_windowManagerName; } |
70 | |
71 | QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &format) const; |
72 | |
73 | const xcb_visualtype_t *visualForFormat(const QSurfaceFormat &format) const; |
74 | const xcb_visualtype_t *visualForId(xcb_visualid_t) const; |
75 | quint8 depthOfVisual(xcb_visualid_t) const; |
76 | xcb_colormap_t colormapForVisual(xcb_visualid_t) const; |
77 | |
78 | private: |
79 | QRect getWorkArea() const; |
80 | |
81 | static bool xResource(const QByteArray &identifier, |
82 | const QByteArray &expectedIdentifier, |
83 | QByteArray &stringValue); |
84 | void readXResources(); |
85 | |
86 | bool setDpiFromXSettings(const QVariant &property); |
87 | |
88 | xcb_screen_t *m_screen; |
89 | const int m_number; |
90 | QList<QPlatformScreen *> m_screens; |
91 | |
92 | QXcbXSettings *m_xSettings = nullptr; |
93 | xcb_atom_t m_net_wm_cm_atom = 0; |
94 | bool m_compositingActive = false; |
95 | |
96 | QRect m_workArea; |
97 | |
98 | int m_forcedDpi = -1; |
99 | QFontEngine::HintStyle m_hintStyle = QFontEngine::HintStyle(-1); |
100 | QFontEngine::SubpixelAntialiasingType m_subpixelType = QFontEngine::SubpixelAntialiasingType(-1); |
101 | int m_antialiasingEnabled = -1; |
102 | QString m_windowManagerName; |
103 | QMap<xcb_visualid_t, xcb_visualtype_t> m_visuals; |
104 | QMap<xcb_visualid_t, quint8> m_visualDepths; |
105 | mutable QMap<xcb_visualid_t, xcb_colormap_t> m_visualColormaps; |
106 | uint16_t m_rotation = 0; |
107 | |
108 | friend class QXcbConnection; |
109 | }; |
110 | |
111 | class Q_XCB_EXPORT QXcbScreen : public QXcbObject, public QPlatformScreen |
112 | , public QNativeInterface::Private::QXcbScreen |
113 | { |
114 | public: |
115 | QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDesktop, |
116 | xcb_randr_output_t outputId, xcb_randr_get_output_info_reply_t *outputInfo); |
117 | QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDesktop, |
118 | xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp_t timestamp = XCB_NONE); |
119 | ~QXcbScreen(); |
120 | |
121 | QString getOutputName(xcb_randr_get_output_info_reply_t *outputInfo); |
122 | QString getName(xcb_randr_monitor_info_t *monitorInfo); |
123 | |
124 | QPixmap grabWindow(WId window, int x, int y, int width, int height) const override; |
125 | |
126 | QWindow *topLevelAt(const QPoint &point) const override; |
127 | |
128 | QString manufacturer() const override; |
129 | QString model() const override; |
130 | QString serialNumber() const override; |
131 | |
132 | QRect geometry() const override { return m_geometry; } |
133 | QRect availableGeometry() const override; |
134 | int depth() const override { return screen()->root_depth; } |
135 | QImage::Format format() const override; |
136 | QColorSpace colorSpace() const override { return m_colorSpace; } |
137 | QSizeF physicalSize() const override { return m_sizeMillimeters; } |
138 | QDpi logicalDpi() const override; |
139 | QDpi logicalBaseDpi() const override { return QDpi(96, 96); } |
140 | QPlatformCursor *cursor() const override; |
141 | qreal refreshRate() const override { return m_refreshRate; } |
142 | Qt::ScreenOrientation orientation() const override { return m_orientation; } |
143 | QList<QPlatformScreen *> virtualSiblings() const override { return m_virtualDesktop->screens(); } |
144 | QXcbVirtualDesktop *virtualDesktop() const { return m_virtualDesktop; } |
145 | |
146 | void setPrimary(bool primary) { m_primary = primary; } |
147 | bool isPrimary() const { return m_primary; } |
148 | |
149 | int screenNumber() const { return m_virtualDesktop->number(); } |
150 | int virtualDesktopNumber() const override { return screenNumber(); } |
151 | |
152 | xcb_screen_t *screen() const { return m_virtualDesktop->screen(); } |
153 | xcb_window_t root() const { return screen()->root; } |
154 | xcb_randr_output_t output() const { return m_output; } |
155 | xcb_randr_crtc_t crtc() const { return m_crtc; } |
156 | xcb_randr_mode_t mode() const { return m_mode; } |
157 | |
158 | QList<xcb_randr_output_t> outputs() const { return m_outputs; } |
159 | QList<xcb_randr_crtc_t> crtcs() const { return m_crtcs; } |
160 | |
161 | void setOutput(xcb_randr_output_t outputId, |
162 | xcb_randr_get_output_info_reply_t *outputInfo); |
163 | void setCrtc(xcb_randr_crtc_t crtc) { m_crtc = crtc; } |
164 | void setMonitor(xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp_t timestamp = XCB_NONE); |
165 | QString defaultName(); |
166 | bool isPrimaryInXScreen(); |
167 | |
168 | void windowShown(QXcbWindow *window); |
169 | QString windowManagerName() const { return m_virtualDesktop->windowManagerName(); } |
170 | |
171 | QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &format) const; |
172 | |
173 | const xcb_visualtype_t *visualForFormat(const QSurfaceFormat &format) const { return m_virtualDesktop->visualForFormat(format); } |
174 | const xcb_visualtype_t *visualForId(xcb_visualid_t visualid) const; |
175 | xcb_colormap_t colormapForVisual(xcb_visualid_t visualid) const { return m_virtualDesktop->colormapForVisual(visualid); } |
176 | quint8 depthOfVisual(xcb_visualid_t visualid) const { return m_virtualDesktop->depthOfVisual(visualid); } |
177 | |
178 | QString name() const override { return m_outputName; } |
179 | |
180 | void updateGeometry(const QRect &geometry, uint8_t rotation); |
181 | void updateGeometry(xcb_timestamp_t timestamp = XCB_TIME_CURRENT_TIME); |
182 | void updateAvailableGeometry(); |
183 | void updateRefreshRate(xcb_randr_mode_t mode); |
184 | |
185 | QFontEngine::HintStyle hintStyle() const { return m_virtualDesktop->hintStyle(); } |
186 | QFontEngine::SubpixelAntialiasingType subpixelType() const { return m_virtualDesktop->subpixelType(); } |
187 | int antialiasingEnabled() const { return m_virtualDesktop->antialiasingEnabled(); } |
188 | |
189 | QXcbXSettings *xSettings() const; |
190 | |
191 | private: |
192 | void sendStartupMessage(const QByteArray &message) const; |
193 | int forcedDpi() const; |
194 | |
195 | void updateColorSpaceAndEdid(); |
196 | QByteArray getOutputProperty(xcb_atom_t atom) const; |
197 | QByteArray getEdid() const; |
198 | |
199 | QXcbVirtualDesktop *m_virtualDesktop; |
200 | xcb_randr_monitor_info_t *m_monitor; |
201 | xcb_randr_output_t m_output; |
202 | xcb_randr_crtc_t m_crtc; |
203 | xcb_randr_mode_t m_mode = XCB_NONE; |
204 | bool m_primary = false; |
205 | |
206 | bool m_singlescreen = false; |
207 | |
208 | QList<xcb_randr_output_t> m_outputs; |
209 | QList<xcb_randr_crtc_t> m_crtcs; |
210 | |
211 | QString m_outputName; |
212 | QSizeF m_outputSizeMillimeters; |
213 | QSizeF m_sizeMillimeters; |
214 | QRect m_geometry; |
215 | QRect m_availableGeometry; |
216 | QColorSpace m_colorSpace; |
217 | Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; |
218 | std::unique_ptr<QXcbCursor> m_cursor; |
219 | qreal m_refreshRate = 60.0; |
220 | QEdidParser m_edid; |
221 | |
222 | friend class QXcbConnection; |
223 | friend class QXcbVirtualDesktop; |
224 | }; |
225 | |
226 | #ifndef QT_NO_DEBUG_STREAM |
227 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QXcbScreen *); |
228 | #endif |
229 | |
230 | QT_END_NAMESPACE |
231 | |
232 | #endif |
233 | |