| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include <QWindow> |
| 10 | |
| 11 | #include <QGuiApplication> |
| 12 | #include <QVersionNumber> |
| 13 | |
| 14 | #include <qpa/qplatformnativeinterface.h> |
| 15 | |
| 16 | struct wl_surface; |
| 17 | struct xdg_toplevel; |
| 18 | |
| 19 | inline wl_surface *surfaceForWindow(QWindow *window) |
| 20 | { |
| 21 | if (!window) { |
| 22 | return nullptr; |
| 23 | } |
| 24 | |
| 25 | QPlatformNativeInterface *native = qGuiApp->platformNativeInterface(); |
| 26 | if (!native) { |
| 27 | return nullptr; |
| 28 | } |
| 29 | |
| 30 | // NotificationWindow incorrectly relied on a side effect of an older version of this class |
| 31 | // In order to remain bug-compatiable, with that older usage, this is |
| 32 | // it can be dropped when we no longer support 6.3.0 or 6.3.1 |
| 33 | static bool isBuggyPlasma = |
| 34 | qApp->applicationName() == QLatin1String("plasmashell" ) && QVersionNumber::fromString(qApp->applicationVersion()) < QVersionNumber(6, 3, 4); |
| 35 | |
| 36 | if (isBuggyPlasma) { |
| 37 | window->create(); |
| 38 | } |
| 39 | |
| 40 | return reinterpret_cast<wl_surface *>(native->nativeResourceForWindow(QByteArrayLiteral("surface" ), window)); |
| 41 | } |
| 42 | |
| 43 | inline xdg_toplevel *xdgToplevelForWindow(QWindow *window) |
| 44 | { |
| 45 | if (!window) { |
| 46 | return nullptr; |
| 47 | } |
| 48 | |
| 49 | QPlatformNativeInterface *native = qGuiApp->platformNativeInterface(); |
| 50 | if (!native) { |
| 51 | return nullptr; |
| 52 | } |
| 53 | |
| 54 | return reinterpret_cast<xdg_toplevel *>(native->nativeResourceForWindow(QByteArrayLiteral("xdg_toplevel" ), window)); |
| 55 | } |
| 56 | |
| 57 | /*! |
| 58 | * \internal |
| 59 | * |
| 60 | * Some objects are children of the application object and therefore they are deleted after the QPA. |
| 61 | * |
| 62 | * The problem is that the wl_display object will be gone after the QPA is shut down. This can make the |
| 63 | * app crash when it attempts to clean up its proxy objects. The wl_proxy memory won't be released by |
| 64 | * wl_display_disconnect(), but wl_proxy objects will contain dangling display pointers. |
| 65 | * |
| 66 | * We need something better, but as of now, there is not a lot to work with. If you know that an object |
| 67 | * will live as long as the app, you may need to use this function before calling the destructor request. |
| 68 | */ |
| 69 | inline bool isQpaAlive() |
| 70 | { |
| 71 | return qGuiApp; |
| 72 | } |
| 73 | |