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 | |