1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QXCBSCREEN_H
41#define QXCBSCREEN_H
42
43#include <qpa/qplatformscreen.h>
44#include <QtCore/QString>
45
46#include <xcb/xcb.h>
47#include <xcb/randr.h>
48#include <xcb/xfixes.h>
49#include <xcb/xinerama.h>
50
51#include "qxcbobject.h"
52#include "qxcbscreen.h"
53
54#include <private/qfontengine_p.h>
55
56#include <QtEdidSupport/private/qedidparser_p.h>
57
58QT_BEGIN_NAMESPACE
59
60class QXcbConnection;
61class QXcbCursor;
62class QXcbXSettings;
63#ifndef QT_NO_DEBUG_STREAM
64class QDebug;
65#endif
66
67class QXcbVirtualDesktop : public QXcbObject
68{
69public:
70 QXcbVirtualDesktop(QXcbConnection *connection, xcb_screen_t *screen, int number);
71 ~QXcbVirtualDesktop();
72
73 xcb_screen_t *screen() const { return m_screen; }
74 int number() const { return m_number; }
75 QSize size() const { return QSize(m_screen->width_in_pixels, m_screen->height_in_pixels); }
76 QSize physicalSize() const { return QSize(m_screen->width_in_millimeters, m_screen->height_in_millimeters); }
77 QDpi dpi() const;
78 xcb_window_t root() const { return m_screen->root; }
79 QXcbScreen *screenAt(const QPoint &pos) const;
80
81 QList<QPlatformScreen *> screens() const { return m_screens; }
82 void setScreens(QList<QPlatformScreen *> &&sl) { m_screens = std::move(sl); }
83 void removeScreen(QPlatformScreen *s) { m_screens.removeOne(s); }
84 void addScreen(QPlatformScreen *s);
85 void setPrimaryScreen(QPlatformScreen *s);
86
87 QXcbXSettings *xSettings() const;
88
89 bool compositingActive() const;
90
91 QRect workArea() const { return m_workArea; }
92 void updateWorkArea();
93
94 void handleXFixesSelectionNotify(xcb_xfixes_selection_notify_event_t *notify_event);
95 void subscribeToXFixesSelectionNotify();
96
97 void handleScreenChange(xcb_randr_screen_change_notify_event_t *change_event);
98
99 int forcedDpi() const { return m_forcedDpi; }
100 QFontEngine::HintStyle hintStyle() const { return m_hintStyle; }
101 QFontEngine::SubpixelAntialiasingType subpixelType() const { return m_subpixelType; }
102 int antialiasingEnabled() const { return m_antialiasingEnabled; }
103
104 QString windowManagerName() const { return m_windowManagerName; }
105
106 QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &format) const;
107
108 const xcb_visualtype_t *visualForFormat(const QSurfaceFormat &format) const;
109 const xcb_visualtype_t *visualForId(xcb_visualid_t) const;
110 quint8 depthOfVisual(xcb_visualid_t) const;
111
112private:
113 QRect getWorkArea() const;
114
115 static bool xResource(const QByteArray &identifier,
116 const QByteArray &expectedIdentifier,
117 QByteArray &stringValue);
118 void readXResources();
119
120 xcb_screen_t *m_screen;
121 const int m_number;
122 QList<QPlatformScreen *> m_screens;
123
124 QXcbXSettings *m_xSettings = nullptr;
125 xcb_atom_t m_net_wm_cm_atom = 0;
126 bool m_compositingActive = false;
127
128 QRect m_workArea;
129
130 int m_forcedDpi = -1;
131 QFontEngine::HintStyle m_hintStyle = QFontEngine::HintStyle(-1);
132 QFontEngine::SubpixelAntialiasingType m_subpixelType = QFontEngine::SubpixelAntialiasingType(-1);
133 int m_antialiasingEnabled = -1;
134 QString m_windowManagerName;
135 QMap<xcb_visualid_t, xcb_visualtype_t> m_visuals;
136 QMap<xcb_visualid_t, quint8> m_visualDepths;
137 uint16_t m_rotation = 0;
138};
139
140class Q_XCB_EXPORT QXcbScreen : public QXcbObject, public QPlatformScreen
141{
142public:
143 QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDesktop,
144 xcb_randr_output_t outputId, xcb_randr_get_output_info_reply_t *outputInfo,
145 const xcb_xinerama_screen_info_t *xineramaScreenInfo = nullptr, int xineramaScreenIdx = -1);
146 ~QXcbScreen();
147
148 QString getOutputName(xcb_randr_get_output_info_reply_t *outputInfo);
149
150 QPixmap grabWindow(WId window, int x, int y, int width, int height) const override;
151
152 QWindow *topLevelAt(const QPoint &point) const override;
153
154 QString manufacturer() const override;
155 QString model() const override;
156 QString serialNumber() const override;
157
158 QRect geometry() const override { return m_geometry; }
159 QRect availableGeometry() const override;
160 int depth() const override { return screen()->root_depth; }
161 QImage::Format format() const override;
162 QSizeF physicalSize() const override { return m_sizeMillimeters; }
163 QDpi logicalDpi() const override;
164 qreal pixelDensity() const override;
165 QPlatformCursor *cursor() const override;
166 qreal refreshRate() const override { return m_refreshRate; }
167 Qt::ScreenOrientation orientation() const override { return m_orientation; }
168 QList<QPlatformScreen *> virtualSiblings() const override { return m_virtualDesktop->screens(); }
169 QXcbVirtualDesktop *virtualDesktop() const { return m_virtualDesktop; }
170
171 void setPrimary(bool primary) { m_primary = primary; }
172 bool isPrimary() const { return m_primary; }
173
174 int screenNumber() const { return m_virtualDesktop->number(); }
175 static int virtualDesktopNumberStatic(const QScreen *screen);
176
177 xcb_screen_t *screen() const { return m_virtualDesktop->screen(); }
178 xcb_window_t root() const { return screen()->root; }
179 xcb_randr_output_t output() const { return m_output; }
180 xcb_randr_crtc_t crtc() const { return m_crtc; }
181 xcb_randr_mode_t mode() const { return m_mode; }
182
183 void setOutput(xcb_randr_output_t outputId,
184 xcb_randr_get_output_info_reply_t *outputInfo);
185 void setCrtc(xcb_randr_crtc_t crtc) { m_crtc = crtc; }
186
187 void windowShown(QXcbWindow *window);
188 QString windowManagerName() const { return m_virtualDesktop->windowManagerName(); }
189
190 QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &format) const;
191
192 const xcb_visualtype_t *visualForFormat(const QSurfaceFormat &format) const { return m_virtualDesktop->visualForFormat(format); }
193 const xcb_visualtype_t *visualForId(xcb_visualid_t visualid) const;
194 quint8 depthOfVisual(xcb_visualid_t visualid) const { return m_virtualDesktop->depthOfVisual(visualid); }
195
196 QString name() const override { return m_outputName; }
197
198 void updateGeometry(const QRect &geometry, uint8_t rotation);
199 void updateGeometry(xcb_timestamp_t timestamp = XCB_TIME_CURRENT_TIME);
200 void updateAvailableGeometry();
201 void updateRefreshRate(xcb_randr_mode_t mode);
202
203 QFontEngine::HintStyle hintStyle() const { return m_virtualDesktop->hintStyle(); }
204 QFontEngine::SubpixelAntialiasingType subpixelType() const { return m_virtualDesktop->subpixelType(); }
205 int antialiasingEnabled() const { return m_virtualDesktop->antialiasingEnabled(); }
206
207 QXcbXSettings *xSettings() const;
208
209private:
210 void sendStartupMessage(const QByteArray &message) const;
211 int forcedDpi() const;
212
213 QByteArray getOutputProperty(xcb_atom_t atom) const;
214 QByteArray getEdid() const;
215
216 QXcbVirtualDesktop *m_virtualDesktop;
217 xcb_randr_output_t m_output;
218 xcb_randr_crtc_t m_crtc;
219 xcb_randr_mode_t m_mode = XCB_NONE;
220 bool m_primary = false;
221
222 QString m_outputName;
223 QSizeF m_outputSizeMillimeters;
224 QSizeF m_sizeMillimeters;
225 QRect m_geometry;
226 QRect m_availableGeometry;
227 Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation;
228 QXcbCursor *m_cursor;
229 int m_refreshRate = 60;
230 int m_pixelDensity = 1;
231 QEdidParser m_edid;
232};
233
234#ifndef QT_NO_DEBUG_STREAM
235Q_GUI_EXPORT QDebug operator<<(QDebug, const QXcbScreen *);
236#endif
237
238QT_END_NAMESPACE
239
240#endif
241