Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwaylandscreen.cpp
Go to the documentation of this file.
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#include "qwaylandscreen_p.h"
5
6#include "qwaylanddisplay_p.h"
8#include "qwaylandcursor_p.h"
9#include "qwaylandwindow_p.h"
10
11#include <QtGui/QGuiApplication>
12
13#include <qpa/qwindowsysteminterface.h>
14#include <qpa/qplatformwindow.h>
15
17
18namespace QtWaylandClient {
19
21 : QtWayland::zxdg_output_manager_v1(display->wl_registry(), id, qMin(3u, version))
22{
23}
24
29
30QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id)
31 : QtWayland::wl_output(waylandDisplay->wl_registry(), id, qMin(version, 3))
32 , m_outputId(id)
33 , mWaylandDisplay(waylandDisplay)
34 , mOutputName(QStringLiteral("Screen%1").arg(id))
35{
36 if (auto *xdgOutputManager = waylandDisplay->xdgOutputManager())
37 initXdgOutput(xdgOutputManager);
38
39 if (version < WL_OUTPUT_DONE_SINCE_VERSION) {
40 qCWarning(lcQpaWayland) << "wl_output done event not supported by compositor,"
41 << "QScreen may not work correctly";
42 mWaylandDisplay->forceRoundTrip(); // Give the compositor a chance to send geometry etc.
43 mProcessedEvents |= OutputDoneEvent; // Fake the done event
45 }
46}
47
49{
50 if (zxdg_output_v1::isInitialized())
51 zxdg_output_v1::destroy();
52 if (wl_output::version() >= WL_OUTPUT_RELEASE_SINCE_VERSION)
53 wl_output::release();
54 else
55 wl_output_destroy(wl_output::object());
56}
57
59{
61
63 if (mWaylandDisplay->xdgOutputManager()->version() >= 2)
65
66 if (mWaylandDisplay->xdgOutputManager()->version() < 3)
68 }
69 return ret;
70}
71
73{
75
76 const uint requiredEvents = this->requiredEvents();
77 if ((mProcessedEvents & requiredEvents) != requiredEvents)
78 return;
79
80 mInitialized = true;
82
84 if (zxdg_output_v1::isInitialized())
86}
87
89{
90 Q_ASSERT(xdgOutputManager);
91 if (zxdg_output_v1::isInitialized())
92 return;
93
94 zxdg_output_v1::init(xdgOutputManager->get_xdg_output(wl_output::object()));
95}
96
101
106
108{
109 return mModel;
110}
111
113{
114 if (zxdg_output_v1::isInitialized()) {
115 return mXdgGeometry;
116 } else {
117 // Scale geometry for QScreen. This makes window and screen
118 // geometry be in the same coordinate system.
120 }
121}
122
124{
125 return mDepth;
126}
127
129{
130 return mFormat;
131}
132
134{
137 else
138 return mPhysicalSize;
139}
140
142{
143 static bool physicalDpi = qEnvironmentVariable("QT_WAYLAND_FORCE_DPI") == QStringLiteral("physical");
144 if (physicalDpi)
146
147 static int forceDpi = qgetenv("QT_WAYLAND_FORCE_DPI").toInt();
148 if (forceDpi)
149 return QDpi(forceDpi, forceDpi);
150
151 return QDpi(96, 96);
152}
153
154QList<QPlatformScreen *> QWaylandScreen::virtualSiblings() const
155{
156 QList<QPlatformScreen *> list;
157 const QList<QWaylandScreen*> screens = mWaylandDisplay->screens();
158 auto *placeholder = mWaylandDisplay->placeholderScreen();
159
160 list.reserve(screens.size() + (placeholder ? 1 : 0));
161
162 for (QWaylandScreen *screen : std::as_const(screens)) {
163 if (screen->screen())
164 list << screen;
165 }
166
167 if (placeholder)
168 list << placeholder;
169
170 return list;
171}
172
174{
176 Q_UNUSED(pos);
177 return nullptr;
178 }
179
181}
182
187
189{
190 return mScale;
191}
192
194{
195 return qreal(mScale);
196}
197
199{
200 return mRefreshRate / 1000.f;
201}
202
203#if QT_CONFIG(cursor)
205{
206 return mWaylandDisplay->waylandCursor();
207}
208#endif // QT_CONFIG(cursor)
209
211{
214 switch (mSubpixel) {
215 case wl_output::subpixel_unknown:
216 case wl_output::subpixel_none:
218 break;
219 case wl_output::subpixel_horizontal_rgb:
221 break;
222 case wl_output::subpixel_horizontal_bgr:
224 break;
225 case wl_output::subpixel_vertical_rgb:
227 break;
228 case wl_output::subpixel_vertical_bgr:
230 break;
231 }
232 }
233 return type;
234}
235
237{
239 if (platformScreen->isPlaceholder())
240 return nullptr;
241 return static_cast<QWaylandScreen *>(platformScreen);
242}
243
245{
246 if (auto *o = QtWayland::wl_output::fromObject(output))
247 return static_cast<QWaylandScreen *>(o);
248 return nullptr;
249}
250
252 Qt::ScreenOrientation fallback) const
253{
254 auto orientation = fallback;
255 bool isPortrait = mGeometry.height() > mGeometry.width();
256 switch (wlTransform) {
257 case WL_OUTPUT_TRANSFORM_NORMAL:
259 break;
260 case WL_OUTPUT_TRANSFORM_90:
262 break;
263 case WL_OUTPUT_TRANSFORM_180:
265 break;
266 case WL_OUTPUT_TRANSFORM_270:
268 break;
269 // Ignore these ones, at least for now
270 case WL_OUTPUT_TRANSFORM_FLIPPED:
271 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
272 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
273 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
274 break;
275 }
276
277 return orientation;
278}
279
280void QWaylandScreen::output_mode(uint32_t flags, int width, int height, int refresh)
281{
282 if (!(flags & WL_OUTPUT_MODE_CURRENT))
283 return;
284
286 if (size != mGeometry.size())
288
289 if (refresh != mRefreshRate)
290 mRefreshRate = refresh;
291}
292
293void QWaylandScreen::output_geometry(int32_t x, int32_t y,
294 int32_t width, int32_t height,
295 int subpixel,
296 const QString &make,
297 const QString &model,
298 int32_t transform)
299{
300 mManufacturer = make;
301 mModel = model;
302
303 mSubpixel = subpixel;
305
308}
309
311{
312 mScale = factor;
313}
314
316{
318
319 if (mInitialized) {
321 if (zxdg_output_v1::isInitialized())
323 } else {
325 }
326}
327
329{
330 if (mTransform >= 0) {
331 auto newOrientation = toScreenOrientation(mTransform, m_orientation);
332 if (m_orientation != newOrientation) {
333 m_orientation = newOrientation;
335 }
336 mTransform = -1;
337 }
338
340
341 if (!zxdg_output_v1::isInitialized())
343}
344
345
350
355
357{
358 if (Q_UNLIKELY(mWaylandDisplay->xdgOutputManager()->version() >= 3))
359 qWarning(lcQpaWayland) << "zxdg_output_v1.done received on version 3 or newer, this is most likely a bug in the compositor";
360
362 if (mInitialized)
364 else
366}
367
369{
371 qWarning(lcQpaWayland) << "zxdg_output_v1.name received after output has been initialized, this is most likely a bug in the compositor";
372
375}
376
382
383} // namespace QtWaylandClient
384
Format
The following image formats are available in Qt.
Definition qimage.h:41
void reserve(qsizetype size)
Definition qlist.h:753
The QPlatformCursor class provides information about pointer device events (movement,...
The QPlatformScreen class provides an abstraction for visual displays.
static QPlatformScreen * platformScreenForWindow(const QWindow *window)
virtual QPlatformCursor * cursor() const
Reimplement this function in subclass to return the cursor of the screen.
QScreen * screen() const
virtual bool isPlaceholder() const
virtual QDpi logicalDpi() const
Reimplement this function in subclass to return the logical horizontal and vertical dots per inch met...
virtual SubpixelAntialiasingType subpixelAntialiasingTypeHint() const
Returns a hint about this screen's subpixel layout structure.
virtual QWindow * topLevelAt(const QPoint &point) const
Return the given top level window for a given position.
virtual QSizeF physicalSize() const
Reimplement this function in subclass to return the physical size of the screen, in millimeters.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void moveTopLeft(const QPoint &p) noexcept
Moves the rectangle, leaving the top-left corner at the given position.
Definition qrect.h:304
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:387
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
Definition qsize.h:124
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QWaylandXdgOutputManagerV1()
Constructs a QWaylandXdgOutputManagerV1 object.
static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry)
static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation)
static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
\inmodule QtGui
Definition qwindow.h:63
QPlatformPlaceholderScreen * placeholderScreen() const
void handleScreenInitialized(QWaylandScreen *screen)
QWaylandXdgOutputManagerV1 * xdgOutputManager() const
QList< QWaylandScreen * > screens() const
void zxdg_output_v1_name(const QString &name) override
QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id)
QWindow * topLevelAt(const QPoint &point) const override
Return the given top level window for a given position.
void output_mode(uint32_t flags, int width, int height, int refresh) override
qreal refreshRate() const override
Reimplement this function in subclass to return the vertical refresh rate of the screen,...
void output_geometry(int32_t x, int32_t y, int32_t width, int32_t height, int subpixel, const QString &make, const QString &model, int32_t transform) override
QString manufacturer() const override
Reimplement this function in subclass to return the manufacturer of this screen.
QWaylandDisplay * display() const
void initXdgOutput(QWaylandXdgOutputManagerV1 *xdgOutputManager)
void output_scale(int32_t factor) override
int depth() const override
Reimplement in subclass to return current depth of the screen.
QSizeF physicalSize() const override
Reimplement this function in subclass to return the physical size of the screen, in millimeters.
QString model() const override
Reimplement this function in subclass to return the model of this screen.
QString name() const override
QDpi logicalDpi() const override
Reimplement this function in subclass to return the logical horizontal and vertical dots per inch met...
static QWaylandScreen * waylandScreenFromWindow(QWindow *window)
void zxdg_output_v1_logical_position(int32_t x, int32_t y) override
qreal devicePixelRatio() const override
Reimplement this function in subclass to return the device pixel ratio for the screen.
::wl_output * output() const override
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
static QWaylandScreen * fromWlOutput(::wl_output *output)
QList< QPlatformScreen * > virtualSiblings() const override
Returns a list of all the platform screens that are part of the same virtual desktop.
void zxdg_output_v1_logical_size(int32_t width, int32_t height) override
QImage::Format format() const override
Reimplement in subclass to return the image format which corresponds to the screen format.
Qt::ScreenOrientation orientation() const override
Reimplement this function in subclass to return the current orientation of the screen,...
Qt::ScreenOrientation m_orientation
SubpixelAntialiasingType subpixelAntialiasingTypeHint() const override
Returns a hint about this screen's subpixel layout structure.
Qt::ScreenOrientation toScreenOrientation(int wlTransform, Qt::ScreenOrientation fallback) const
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
ScreenOrientation
Definition qnamespace.h:271
@ InvertedLandscapeOrientation
Definition qnamespace.h:276
@ InvertedPortraitOrientation
Definition qnamespace.h:275
@ LandscapeOrientation
Definition qnamespace.h:274
@ PortraitOrientation
Definition qnamespace.h:273
#define Q_UNLIKELY(x)
QPair< qreal, qreal > QDpi
#define qWarning
Definition qlogging.h:166
#define qCWarning(category,...)
return ret
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint id
[7]
GLint GLsizei width
GLenum type
GLbitfield flags
GLuint name
GLint y
GLuint GLenum GLenum transform
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int void * arg
#define QStringLiteral(str)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
QT_BEGIN_NAMESPACE typedef uchar * output
QSqlQueryModel * model
[16]
QList< int > list
[14]
aWidget window() -> setWindowTitle("New Window Title")
[2]