Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandsurface.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 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// Qt-Security score:significant reason:default
4
8
9#include <QtGui/QGuiApplication>
10
12
13namespace QtWaylandClient {
14
15QWaylandSurface::QWaylandSurface(QWaylandDisplay *display)
16 : wl_surface(display->createSurface(this))
17{
18 connect(qApp, &QGuiApplication::screenRemoved, this, &QWaylandSurface::handleScreenRemoved);
19 connect(qApp, &QGuiApplication::screenAdded, this, &QWaylandSurface::screensChanged);
20}
21
23{
24 destroy();
25}
26
28{
29 for (auto *screen : std::as_const(m_screens)) {
30 // only report valid screens
31 // we can have some ouptuts waiting for xdg output information
32 // that are valid QPlatformScreens, but not valid QScreens
33 if (screen->screen())
34 return screen;
35 }
36 return nullptr;
37}
38
39QWaylandSurface *QWaylandSurface::fromWlSurface(::wl_surface *surface)
40{
41 if (auto *s = QtWayland::wl_surface::fromObject(surface))
42 return static_cast<QWaylandSurface *>(s);
43 return nullptr;
44}
45
46void QWaylandSurface::handleScreenRemoved(QScreen *qScreen)
47{
48 auto *platformScreen = qScreen->handle();
49 if (platformScreen->isPlaceholder())
50 return;
51
52 auto *waylandScreen = static_cast<QWaylandScreen *>(qScreen->handle());
53 if (m_screens.removeOne(waylandScreen))
54 emit screensChanged();
55}
56
57void QWaylandSurface::surface_enter(wl_output *output)
58{
59 if (!output)
60 return;
61
62 auto addedScreen = QWaylandScreen::fromWlOutput(output);
63 if (!addedScreen)
64 return;
65
66 if (m_screens.contains(addedScreen)) {
67 qCWarning(lcQpaWayland)
68 << "Ignoring unexpected wl_surface.enter received for output with id:"
69 << wl_proxy_get_id(reinterpret_cast<wl_proxy *>(output))
70 << "screen name:" << addedScreen->name() << "screen model:" << addedScreen->model()
71 << "This is most likely a bug in the compositor.";
72 return;
73 }
74
75 m_screens.append(addedScreen);
76 emit screensChanged();
77}
78
79void QWaylandSurface::surface_leave(wl_output *output)
80{
81 if (!output)
82 return;
83
84 auto *removedScreen = QWaylandScreen::fromWlOutput(output);
85 if (!removedScreen)
86 return;
87
88 bool wasRemoved = m_screens.removeOne(removedScreen);
89 if (!wasRemoved) {
90 qCWarning(lcQpaWayland)
91 << "Ignoring unexpected wl_surface.leave received for output with id:"
92 << wl_proxy_get_id(reinterpret_cast<wl_proxy *>(output))
93 << "screen name:" << removedScreen->name()
94 << "screen model:" << removedScreen->model()
95 << "This is most likely a bug in the compositor.";
96 return;
97 }
98 emit screensChanged();
99}
100
102{
103 if (m_preferredBufferScale == scale)
104 return;
105 m_preferredBufferScale = scale;
106 Q_EMIT preferredBufferScaleChanged();
107}
108
110{
111 if (m_preferredBufferTransform == transform)
112 return;
113 m_preferredBufferTransform = static_cast<wl_output_transform>(transform);
114 Q_EMIT preferredBufferTransformChanged();
115}
116
117} // namespace QtWaylandClient
118
119QT_END_NAMESPACE
120
121#include "moc_qwaylandsurface_p.cpp"
void surface_preferred_buffer_transform(uint32_t transform) override
void surface_preferred_buffer_scale(int32_t scale) override
Combined button and popup list for selecting options.