Qt 6.x
The Qt SDK
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
25QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id)
26 : QtWayland::wl_output(waylandDisplay->wl_registry(), id, qMin(version, 3))
27 , m_outputId(id)
28 , mWaylandDisplay(waylandDisplay)
29 , mOutputName(QStringLiteral("Screen%1").arg(id))
30{
31 if (auto *xdgOutputManager = waylandDisplay->xdgOutputManager())
32 initXdgOutput(xdgOutputManager);
33
34 if (version < WL_OUTPUT_DONE_SINCE_VERSION) {
35 qCWarning(lcQpaWayland) << "wl_output done event not supported by compositor,"
36 << "QScreen may not work correctly";
37 mWaylandDisplay->forceRoundTrip(); // Give the compositor a chance to send geometry etc.
38 mProcessedEvents |= OutputDoneEvent; // Fake the done event
40 }
41}
42
44{
45 if (zxdg_output_v1::isInitialized())
46 zxdg_output_v1::destroy();
47 if (wl_output::isInitialized() && wl_output::version() >= WL_OUTPUT_RELEASE_SINCE_VERSION)
48 wl_output::release();
49}
50
52{
54
56 if (mWaylandDisplay->xdgOutputManager()->version() >= 2)
58
59 if (mWaylandDisplay->xdgOutputManager()->version() < 3)
61 }
62 return ret;
63}
64
66{
68
69 const uint requiredEvents = this->requiredEvents();
70 if ((mProcessedEvents & requiredEvents) != requiredEvents)
71 return;
72
73 mInitialized = true;
75
77 if (zxdg_output_v1::isInitialized())
79}
80
82{
83 Q_ASSERT(xdgOutputManager);
84 if (zxdg_output_v1::isInitialized())
85 return;
86
87 zxdg_output_v1::init(xdgOutputManager->get_xdg_output(wl_output::object()));
88}
89
91{
92 return mWaylandDisplay;
93}
94
96{
97 return mManufacturer;
98}
99
101{
102 return mModel;
103}
104
106{
107 if (zxdg_output_v1::isInitialized()) {
108 return mXdgGeometry;
109 } else {
110 // Scale geometry for QScreen. This makes window and screen
111 // geometry be in the same coordinate system.
113 }
114}
115
117{
118 return mDepth;
119}
120
122{
123 return mFormat;
124}
125
127{
130 else
131 return mPhysicalSize;
132}
133
135{
136 static bool physicalDpi = qEnvironmentVariable("QT_WAYLAND_FORCE_DPI") == QStringLiteral("physical");
137 if (physicalDpi)
139
140 static int forceDpi = qgetenv("QT_WAYLAND_FORCE_DPI").toInt();
141 if (forceDpi)
142 return QDpi(forceDpi, forceDpi);
143
144 return QDpi(96, 96);
145}
146
148{
151 auto *placeholder = mWaylandDisplay->placeholderScreen();
152
153 list.reserve(screens.size() + (placeholder ? 1 : 0));
154
155 for (QWaylandScreen *screen : std::as_const(screens)) {
156 if (screen->screen())
157 list << screen;
158 }
159
160 if (placeholder)
161 list << placeholder;
162
163 return list;
164}
165
167{
168 return m_orientation;
169}
170
172{
173 return mScale;
174}
175
177{
178 return qreal(mScale);
179}
180
182{
183 return mRefreshRate / 1000.f;
184}
185
186#if QT_CONFIG(cursor)
188{
189 return mWaylandDisplay->waylandCursor();
190}
191#endif // QT_CONFIG(cursor)
192
194{
196 if (platformScreen->isPlaceholder())
197 return nullptr;
198 return static_cast<QWaylandScreen *>(platformScreen);
199}
200
202{
203 if (auto *o = QtWayland::wl_output::fromObject(output))
204 return static_cast<QWaylandScreen *>(o);
205 return nullptr;
206}
207
208void QWaylandScreen::output_mode(uint32_t flags, int width, int height, int refresh)
209{
210 if (!(flags & WL_OUTPUT_MODE_CURRENT))
211 return;
212
214 if (size != mGeometry.size())
216
217 if (refresh != mRefreshRate)
218 mRefreshRate = refresh;
219}
220
221void QWaylandScreen::output_geometry(int32_t x, int32_t y,
222 int32_t width, int32_t height,
223 int subpixel,
224 const QString &make,
225 const QString &model,
226 int32_t transform)
227{
228 Q_UNUSED(subpixel);
229
230 mManufacturer = make;
231 mModel = model;
232
234
237}
238
240{
241 mScale = factor;
242}
243
245{
247
248 if (mInitialized) {
250 if (zxdg_output_v1::isInitialized())
252 } else {
254 }
255}
256
258{
259 if (mTransform >= 0) {
260 bool isPortrait = mGeometry.height() > mGeometry.width();
261 switch (mTransform) {
262 case WL_OUTPUT_TRANSFORM_NORMAL:
264 break;
265 case WL_OUTPUT_TRANSFORM_90:
267 break;
268 case WL_OUTPUT_TRANSFORM_180:
270 break;
271 case WL_OUTPUT_TRANSFORM_270:
273 break;
274 // Ignore these ones, at least for now
275 case WL_OUTPUT_TRANSFORM_FLIPPED:
276 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
277 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
278 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
279 break;
280 }
281
283 mTransform = -1;
284 }
285
287
288 if (!zxdg_output_v1::isInitialized())
290}
291
292
294{
296}
297
299{
301}
302
304{
305 if (Q_UNLIKELY(mWaylandDisplay->xdgOutputManager()->version() >= 3))
306 qWarning(lcQpaWayland) << "zxdg_output_v1.done received on version 3 or newer, this is most likely a bug in the compositor";
307
309 if (mInitialized)
311 else
313}
314
316{
318 qWarning(lcQpaWayland) << "zxdg_output_v1.name received after output has been initialized, this is most likely a bug in the compositor";
319
322}
323
325{
326 Q_ASSERT(zxdg_output_v1::isInitialized());
328}
329
330} // namespace QtWaylandClient
331
int toInt(bool *ok=nullptr, int base=10) const
Returns the byte array converted to an int using base base, which is ten by default.
Format
The following image formats are available in Qt.
Definition qimage.h:41
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
void reserve(qsizetype size)
Definition qlist.h:746
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 QSizeF physicalSize() const
Reimplement this function in subclass to return the physical size of the screen, in millimeters.
\inmodule QtCore\reentrant
Definition qpoint.h:23
\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:303
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:386
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:241
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
\inmodule QtCore
Definition qsize.h:207
\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:123
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
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)
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
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
ScreenOrientation
Definition qnamespace.h:270
@ InvertedLandscapeOrientation
Definition qnamespace.h:275
@ InvertedPortraitOrientation
Definition qnamespace.h:274
@ LandscapeOrientation
Definition qnamespace.h:273
@ PortraitOrientation
Definition qnamespace.h:272
#define Q_UNLIKELY(x)
QPair< qreal, qreal > QDpi
#define qWarning
Definition qlogging.h:162
#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
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:29
double qreal
Definition qtypes.h:92
QT_BEGIN_NAMESPACE typedef uchar * output
QSqlQueryModel * model
[16]
QList< int > list
[14]
aWidget window() -> setWindowTitle("New Window Title")
[2]