| 1 | /* |
|---|---|
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2021 Aleix Pol <aleixpol@kde.org> |
| 4 | SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 7 | */ |
| 8 | |
| 9 | #include "kwaylandextras.h" |
| 10 | |
| 11 | #include "kwindowsystem.h" |
| 12 | #include "kwindowsystem_p.h" |
| 13 | |
| 14 | #include <QTimer> |
| 15 | |
| 16 | KWaylandExtras::KWaylandExtras() |
| 17 | : QObject() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | KWaylandExtras::~KWaylandExtras() = default; |
| 22 | |
| 23 | KWaylandExtras *KWaylandExtras::self() |
| 24 | { |
| 25 | static KWaylandExtras instance; |
| 26 | return &instance; |
| 27 | } |
| 28 | |
| 29 | void KWaylandExtras::requestXdgActivationToken(QWindow *window, uint32_t serial, const QString &app_id) |
| 30 | { |
| 31 | auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(KWindowSystem::d_func()); |
| 32 | if (!dv2) { |
| 33 | // Ensure that xdgActivationTokenArrived is always emitted asynchronously |
| 34 | QTimer::singleShot(interval: 0, slot: [serial] { |
| 35 | Q_EMIT KWaylandExtras::self()->xdgActivationTokenArrived(serial, token: {}); |
| 36 | }); |
| 37 | |
| 38 | return; |
| 39 | } |
| 40 | dv2->requestToken(win: window, serial, app_id); |
| 41 | } |
| 42 | |
| 43 | quint32 KWaylandExtras::lastInputSerial(QWindow *window) |
| 44 | { |
| 45 | auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(KWindowSystem::d_func()); |
| 46 | if (!dv2) { |
| 47 | return 0; |
| 48 | } |
| 49 | return dv2->lastInputSerial(window); |
| 50 | } |
| 51 | |
| 52 | void KWaylandExtras::exportWindow(QWindow *window) |
| 53 | { |
| 54 | if (auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(KWindowSystem::d_func())) { |
| 55 | dv2->exportWindow(window); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void KWaylandExtras::unexportWindow(QWindow *window) |
| 60 | { |
| 61 | if (auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(KWindowSystem::d_func())) { |
| 62 | dv2->unexportWindow(window); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | #include "moc_kwaylandextras.cpp" |
| 67 |
