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, signal: &QGuiApplication::screenRemoved, context: this, slot: &QWaylandSurface::handleScreenRemoved); |
18 | } |
19 | |
20 | QWaylandSurface::~QWaylandSurface() |
21 | { |
22 | destroy(); |
23 | } |
24 | |
25 | QWaylandScreen *QWaylandSurface::oldestEnteredScreen() |
26 | { |
27 | return m_screens.value(i: 0, defaultValue: nullptr); |
28 | } |
29 | |
30 | QWaylandSurface *QWaylandSurface::fromWlSurface(::wl_surface *surface) |
31 | { |
32 | if (auto *s = QtWayland::wl_surface::fromObject(surface)) |
33 | return static_cast<QWaylandSurface *>(s); |
34 | return nullptr; |
35 | } |
36 | |
37 | void QWaylandSurface::handleScreenRemoved(QScreen *qScreen) |
38 | { |
39 | auto *platformScreen = qScreen->handle(); |
40 | if (platformScreen->isPlaceholder()) |
41 | return; |
42 | |
43 | auto *waylandScreen = static_cast<QWaylandScreen *>(qScreen->handle()); |
44 | if (m_screens.removeOne(t: waylandScreen)) |
45 | emit screensChanged(); |
46 | } |
47 | |
48 | void QWaylandSurface::surface_enter(wl_output *output) |
49 | { |
50 | auto addedScreen = QWaylandScreen::fromWlOutput(output); |
51 | |
52 | if (!addedScreen) |
53 | return; |
54 | |
55 | if (m_screens.contains(addedScreen)) { |
56 | qCWarning(lcQpaWayland) |
57 | << "Ignoring unexpected wl_surface.enter received for output with id:" |
58 | << wl_proxy_get_id(reinterpret_cast<wl_proxy *>(output)) |
59 | << "screen name:"<< addedScreen->name() << "screen model:"<< addedScreen->model() |
60 | << "This is most likely a bug in the compositor."; |
61 | return; |
62 | } |
63 | |
64 | m_screens.append(addedScreen); |
65 | emit screensChanged(); |
66 | } |
67 | |
68 | void QWaylandSurface::surface_leave(wl_output *output) |
69 | { |
70 | auto *removedScreen = QWaylandScreen::fromWlOutput(output); |
71 | |
72 | if (!removedScreen) |
73 | return; |
74 | |
75 | bool wasRemoved = m_screens.removeOne(removedScreen); |
76 | if (!wasRemoved) { |
77 | qCWarning(lcQpaWayland) |
78 | << "Ignoring unexpected wl_surface.leave received for output with id:" |
79 | << wl_proxy_get_id(reinterpret_cast<wl_proxy *>(output)) |
80 | << "screen name:"<< removedScreen->name() |
81 | << "screen model:"<< removedScreen->model() |
82 | << "This is most likely a bug in the compositor."; |
83 | return; |
84 | } |
85 | emit screensChanged(); |
86 | } |
87 | |
88 | } // namespace QtWaylandClient |
89 | |
90 | QT_END_NAMESPACE |
91 | |
92 | #include "moc_qwaylandsurface_p.cpp" |
93 |