| 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 | |
| 4 | #include "qwaylandsurface_p.h" |
| 5 | #include "qwaylanddisplay_p.h" |
| 6 | #include "qwaylandscreen_p.h" |
| 7 | |
| 8 | #include <QtGui/QGuiApplication> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | namespace QtWaylandClient { |
| 13 | |
| 14 | QWaylandSurface::QWaylandSurface(QWaylandDisplay *display) |
| 15 | : wl_surface(display->createSurface(this)) |
| 16 | { |
| 17 | connect(qApp, &QGuiApplication::screenRemoved, this, &QWaylandSurface::handleScreenRemoved); |
| 18 | connect(qApp, &QGuiApplication::screenAdded, this, &QWaylandSurface::screensChanged); |
| 19 | } |
| 20 | |
| 21 | QWaylandSurface::~QWaylandSurface() |
| 22 | { |
| 23 | destroy(); |
| 24 | } |
| 25 | |
| 26 | QWaylandScreen *QWaylandSurface::oldestEnteredScreen() |
| 27 | { |
| 28 | for (auto *screen : std::as_const(t&: m_screens)) { |
| 29 | // only report valid screens |
| 30 | // we can have some ouptuts waiting for xdg output information |
| 31 | // that are valid QPlatformScreens, but not valid QScreens |
| 32 | if (screen->screen()) |
| 33 | return screen; |
| 34 | } |
| 35 | return nullptr; |
| 36 | } |
| 37 | |
| 38 | QWaylandSurface *QWaylandSurface::fromWlSurface(::wl_surface *surface) |
| 39 | { |
| 40 | if (auto *s = QtWayland::wl_surface::fromObject(surface)) |
| 41 | return static_cast<QWaylandSurface *>(s); |
| 42 | return nullptr; |
| 43 | } |
| 44 | |
| 45 | void QWaylandSurface::handleScreenRemoved(QScreen *qScreen) |
| 46 | { |
| 47 | auto *platformScreen = qScreen->handle(); |
| 48 | if (platformScreen->isPlaceholder()) |
| 49 | return; |
| 50 | |
| 51 | auto *waylandScreen = static_cast<QWaylandScreen *>(qScreen->handle()); |
| 52 | if (m_screens.removeOne(t: waylandScreen)) |
| 53 | emit screensChanged(); |
| 54 | } |
| 55 | |
| 56 | void QWaylandSurface::surface_enter(wl_output *output) |
| 57 | { |
| 58 | auto addedScreen = QWaylandScreen::fromWlOutput(output); |
| 59 | |
| 60 | if (!addedScreen) |
| 61 | return; |
| 62 | |
| 63 | if (m_screens.contains(t: addedScreen)) { |
| 64 | qCWarning(lcQpaWayland) |
| 65 | << "Ignoring unexpected wl_surface.enter received for output with id:" |
| 66 | << wl_proxy_get_id(reinterpret_cast<wl_proxy *>(output)) |
| 67 | << "screen name:"<< addedScreen->name() << "screen model:"<< addedScreen->model() |
| 68 | << "This is most likely a bug in the compositor."; |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | m_screens.append(t: addedScreen); |
| 73 | emit screensChanged(); |
| 74 | } |
| 75 | |
| 76 | void QWaylandSurface::surface_leave(wl_output *output) |
| 77 | { |
| 78 | auto *removedScreen = QWaylandScreen::fromWlOutput(output); |
| 79 | |
| 80 | if (!removedScreen) |
| 81 | return; |
| 82 | |
| 83 | bool wasRemoved = m_screens.removeOne(t: removedScreen); |
| 84 | if (!wasRemoved) { |
| 85 | qCWarning(lcQpaWayland) |
| 86 | << "Ignoring unexpected wl_surface.leave received for output with id:" |
| 87 | << wl_proxy_get_id(reinterpret_cast<wl_proxy *>(output)) |
| 88 | << "screen name:"<< removedScreen->name() |
| 89 | << "screen model:"<< removedScreen->model() |
| 90 | << "This is most likely a bug in the compositor."; |
| 91 | return; |
| 92 | } |
| 93 | emit screensChanged(); |
| 94 | } |
| 95 | |
| 96 | void QWaylandSurface::surface_preferred_buffer_scale(int32_t scale) |
| 97 | { |
| 98 | if (m_preferredBufferScale == scale) |
| 99 | return; |
| 100 | m_preferredBufferScale = scale; |
| 101 | Q_EMIT preferredBufferScaleChanged(); |
| 102 | } |
| 103 | |
| 104 | void QWaylandSurface::surface_preferred_buffer_transform(uint32_t transform) |
| 105 | { |
| 106 | if (m_preferredBufferTransform == transform) |
| 107 | return; |
| 108 | m_preferredBufferTransform = static_cast<wl_output_transform>(transform); |
| 109 | Q_EMIT preferredBufferTransformChanged(); |
| 110 | } |
| 111 | |
| 112 | } // namespace QtWaylandClient |
| 113 | |
| 114 | QT_END_NAMESPACE |
| 115 | |
| 116 | #include "moc_qwaylandsurface_p.cpp" |
| 117 |
