415 lines
14 KiB
Diff
415 lines
14 KiB
Diff
From 9d0ffb13d290d76df03d199b50c3b3364d4b93bc Mon Sep 17 00:00:00 2001
|
|
From: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
Date: Wed, 17 Sep 2025 10:14:15 +0300
|
|
Subject: [PATCH 1/2] Add QFuture-based xdg-activation token helpers
|
|
|
|
QFuture can be used to make the code that needs activation tokens cleaner.
|
|
---
|
|
src/kwaylandextras.cpp | 14 +++++++++++
|
|
src/kwaylandextras.h | 21 ++++++++++++++++
|
|
src/kwindowsystem_p.h | 8 ++++++
|
|
.../wayland/waylandxdgactivationv1_p.h | 19 ++++++++++++++
|
|
src/platforms/wayland/windowsystem.cpp | 25 ++++++++++++++++---
|
|
src/platforms/wayland/windowsystem.h | 3 ++-
|
|
tests/activationtest.cpp | 13 +++++-----
|
|
tests/kwaylandextrastest.cpp | 12 +++------
|
|
8 files changed, 95 insertions(+), 20 deletions(-)
|
|
|
|
diff --git a/src/kwaylandextras.cpp b/src/kwaylandextras.cpp
|
|
index 036d57d3..a5f8af8f 100644
|
|
--- a/src/kwaylandextras.cpp
|
|
+++ b/src/kwaylandextras.cpp
|
|
@@ -63,4 +63,18 @@ void KWaylandExtras::unexportWindow(QWindow *window)
|
|
}
|
|
}
|
|
|
|
+QFuture<QString> KWaylandExtras::xdgActivationToken(QWindow *window, uint32_t serial, const QString &appId)
|
|
+{
|
|
+ if (auto dv3 = dynamic_cast<KWindowSystemPrivateV3 *>(KWindowSystem::d_func())) {
|
|
+ return dv3->xdgActivationToken(window, serial, appId);
|
|
+ } else {
|
|
+ return QFuture<QString>();
|
|
+ }
|
|
+}
|
|
+
|
|
+QFuture<QString> KWaylandExtras::xdgActivationToken(QWindow *window, const QString &appId)
|
|
+{
|
|
+ return xdgActivationToken(window, lastInputSerial(window), appId);
|
|
+}
|
|
+
|
|
#include "moc_kwaylandextras.cpp"
|
|
diff --git a/src/kwaylandextras.h b/src/kwaylandextras.h
|
|
index f43135d0..2f763dd5 100644
|
|
--- a/src/kwaylandextras.h
|
|
+++ b/src/kwaylandextras.h
|
|
@@ -9,6 +9,7 @@
|
|
#ifndef KWAYLANDEXTRAS_H
|
|
#define KWAYLANDEXTRAS_H
|
|
|
|
+#include <QFuture>
|
|
#include <QObject>
|
|
#include <QWindow>
|
|
|
|
@@ -61,6 +62,26 @@ public:
|
|
*/
|
|
Q_INVOKABLE static void unexportWindow(QWindow *window);
|
|
|
|
+ /*!
|
|
+ * Requests an xdg_activation_v1 token for a specific window \a window with the given \a appId.
|
|
+ * The \a serial indicates an event that triggered the request.
|
|
+ *
|
|
+ * \note No xdgActivationTokenArrived() signal will be emitted for this token.
|
|
+ *
|
|
+ * \since 6.19
|
|
+ */
|
|
+ static QFuture<QString> xdgActivationToken(QWindow *window, uint32_t serial, const QString &appId);
|
|
+
|
|
+ /*!
|
|
+ * Requests an xdg_activation_v1 token for a specific window \a window with the given \a appId.
|
|
+ * The last received input serial will be used to request the token.
|
|
+ *
|
|
+ * \note No xdgActivationTokenArrived() signal will be emitted for this token.
|
|
+ *
|
|
+ * \since 6.19
|
|
+ */
|
|
+ static QFuture<QString> xdgActivationToken(QWindow *window, const QString &appId);
|
|
+
|
|
Q_SIGNALS:
|
|
/*!
|
|
* Activation \a token to pass to the client.
|
|
diff --git a/src/kwindowsystem_p.h b/src/kwindowsystem_p.h
|
|
index eb9348ba..e4b51e3e 100644
|
|
--- a/src/kwindowsystem_p.h
|
|
+++ b/src/kwindowsystem_p.h
|
|
@@ -7,6 +7,8 @@
|
|
#define KWINDOWSYSTEM_P_H
|
|
|
|
#include "netwm_def.h"
|
|
+
|
|
+#include <QFuture>
|
|
#include <QStringList>
|
|
#include <QWidgetList> //For WId
|
|
#include <kwindowsystem_export.h>
|
|
@@ -33,4 +35,10 @@ public:
|
|
virtual void unexportWindow(QWindow *window) = 0;
|
|
};
|
|
|
|
+class KWINDOWSYSTEM_EXPORT KWindowSystemPrivateV3 : public KWindowSystemPrivateV2
|
|
+{
|
|
+public:
|
|
+ virtual QFuture<QString> xdgActivationToken(QWindow *window, uint32_t serial, const QString &appId) = 0;
|
|
+};
|
|
+
|
|
#endif
|
|
diff --git a/src/platforms/wayland/waylandxdgactivationv1_p.h b/src/platforms/wayland/waylandxdgactivationv1_p.h
|
|
index 077ccd93..629d45ef 100644
|
|
--- a/src/platforms/wayland/waylandxdgactivationv1_p.h
|
|
+++ b/src/platforms/wayland/waylandxdgactivationv1_p.h
|
|
@@ -8,7 +8,10 @@
|
|
#define WAYLANDXDGACTIVATIONV1_P_H
|
|
|
|
#include "qwayland-xdg-activation-v1.h"
|
|
+
|
|
+#include <QFuture>
|
|
#include <QObject>
|
|
+#include <QPromise>
|
|
#include <QtWaylandClient/QWaylandClientExtension>
|
|
|
|
class QWaylandSurface;
|
|
@@ -18,20 +21,36 @@ class WaylandXdgActivationTokenV1 : public QObject, public QtWayland::xdg_activa
|
|
Q_OBJECT
|
|
|
|
public:
|
|
+ WaylandXdgActivationTokenV1()
|
|
+ {
|
|
+ m_promise.start();
|
|
+ }
|
|
+
|
|
~WaylandXdgActivationTokenV1() override
|
|
{
|
|
destroy();
|
|
}
|
|
|
|
+ QFuture<QString> future() const
|
|
+ {
|
|
+ return m_promise.future();
|
|
+ }
|
|
+
|
|
protected:
|
|
void xdg_activation_token_v1_done(const QString &token) override
|
|
{
|
|
+ m_promise.addResult(token);
|
|
+ m_promise.finish();
|
|
+
|
|
Q_EMIT done(token);
|
|
deleteLater();
|
|
}
|
|
|
|
Q_SIGNALS:
|
|
void done(const QString &token);
|
|
+
|
|
+private:
|
|
+ QPromise<QString> m_promise;
|
|
};
|
|
|
|
class WaylandXdgActivationV1 : public QWaylandClientExtensionTemplate<WaylandXdgActivationV1>, public QtWayland::xdg_activation_v1
|
|
diff --git a/src/platforms/wayland/windowsystem.cpp b/src/platforms/wayland/windowsystem.cpp
|
|
index f2d8b4f2..ebb22d78 100644
|
|
--- a/src/platforms/wayland/windowsystem.cpp
|
|
+++ b/src/platforms/wayland/windowsystem.cpp
|
|
@@ -50,9 +50,7 @@ public:
|
|
};
|
|
|
|
WindowSystem::WindowSystem()
|
|
- : QObject()
|
|
- , KWindowSystemPrivateV2()
|
|
- , m_lastToken(qEnvironmentVariable("XDG_ACTIVATION_TOKEN"))
|
|
+ : m_lastToken(qEnvironmentVariable("XDG_ACTIVATION_TOKEN"))
|
|
{
|
|
m_windowManagement = new WindowManagement;
|
|
}
|
|
@@ -303,4 +301,25 @@ void WindowSystem::doSetMainWindow(QWindow *window, const QString &handle)
|
|
}
|
|
}
|
|
|
|
+QFuture<QString> WindowSystem::xdgActivationToken(QWindow *window, uint32_t serial, const QString &appId)
|
|
+{
|
|
+ WaylandXdgActivationV1 *activation = WaylandXdgActivationV1::self();
|
|
+ if (!activation->isActive()) {
|
|
+ return QFuture<QString>();
|
|
+ }
|
|
+
|
|
+ auto waylandApp = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
|
|
+ if (!waylandApp) {
|
|
+ return QFuture<QString>();
|
|
+ }
|
|
+
|
|
+ if (window) {
|
|
+ window->create();
|
|
+ }
|
|
+ wl_surface *wlSurface = surfaceForWindow(window);
|
|
+
|
|
+ auto token = activation->requestXdgActivationToken(waylandApp->lastInputSeat(), wlSurface, serial, appId);
|
|
+ return token->future();
|
|
+}
|
|
+
|
|
#include "moc_windowsystem.cpp"
|
|
diff --git a/src/platforms/wayland/windowsystem.h b/src/platforms/wayland/windowsystem.h
|
|
index 87bf23ed..4df82388 100644
|
|
--- a/src/platforms/wayland/windowsystem.h
|
|
+++ b/src/platforms/wayland/windowsystem.h
|
|
@@ -12,7 +12,7 @@
|
|
|
|
class WindowManagement;
|
|
|
|
-class WindowSystem : public QObject, public KWindowSystemPrivateV2
|
|
+class WindowSystem : public QObject, public KWindowSystemPrivateV3
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
@@ -27,6 +27,7 @@ public:
|
|
void exportWindow(QWindow *window) override;
|
|
void unexportWindow(QWindow *window) override;
|
|
void setMainWindow(QWindow *window, const QString &handle) override;
|
|
+ QFuture<QString> xdgActivationToken(QWindow *window, uint32_t serial, const QString &appId) override;
|
|
|
|
protected:
|
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
|
diff --git a/tests/activationtest.cpp b/tests/activationtest.cpp
|
|
index 306c6048..7aaae4ea 100644
|
|
--- a/tests/activationtest.cpp
|
|
+++ b/tests/activationtest.cpp
|
|
@@ -28,13 +28,12 @@ public:
|
|
pushButton->setText("Raise other");
|
|
layout()->addWidget(pushButton);
|
|
|
|
- connect(pushButton, &QPushButton::clicked, this, [this] {
|
|
- KWaylandExtras::requestXdgActivationToken(windowHandle(), KWaylandExtras::lastInputSerial(windowHandle()), QString());
|
|
- });
|
|
-
|
|
- connect(KWaylandExtras::self(), &KWaylandExtras::xdgActivationTokenArrived, this, [otherWindow](int /*serial*/, const QString &token) {
|
|
- KWindowSystem::setCurrentXdgActivationToken(token);
|
|
- KWindowSystem::activateWindow(otherWindow->windowHandle());
|
|
+ connect(pushButton, &QPushButton::clicked, this, [this, otherWindow] {
|
|
+ KWaylandExtras::xdgActivationToken(windowHandle(), KWaylandExtras::lastInputSerial(windowHandle()), QString())
|
|
+ .then(otherWindow, [otherWindow](const QString &token) {
|
|
+ KWindowSystem::setCurrentXdgActivationToken(token);
|
|
+ KWindowSystem::activateWindow(otherWindow->windowHandle());
|
|
+ });
|
|
});
|
|
}
|
|
};
|
|
diff --git a/tests/kwaylandextrastest.cpp b/tests/kwaylandextrastest.cpp
|
|
index 3048cb37..2ee86a82 100644
|
|
--- a/tests/kwaylandextrastest.cpp
|
|
+++ b/tests/kwaylandextrastest.cpp
|
|
@@ -79,16 +79,10 @@ void Window::updateSerial()
|
|
|
|
void Window::requestToken()
|
|
{
|
|
- connect(
|
|
- KWaylandExtras::self(),
|
|
- &KWaylandExtras::xdgActivationTokenArrived,
|
|
- this,
|
|
- [this](int /*serial*/, const QString &token) {
|
|
+ KWaylandExtras::xdgActivationToken(windowHandle(), KWaylandExtras::self()->lastInputSerial(windowHandle()), QString())
|
|
+ .then(this, [this](const QString &token) {
|
|
m_tokenLabel->setText("XDG actvation token: " + token);
|
|
- },
|
|
- Qt::SingleShotConnection);
|
|
-
|
|
- KWaylandExtras::requestXdgActivationToken(windowHandle(), KWaylandExtras::self()->lastInputSerial(windowHandle()), QString());
|
|
+ });
|
|
}
|
|
|
|
void Window::exportWindow()
|
|
--
|
|
GitLab
|
|
|
|
|
|
From 1b16c417c697b5d30724ce37d0364af894f6680d Mon Sep 17 00:00:00 2001
|
|
From: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
Date: Wed, 17 Sep 2025 12:01:53 +0300
|
|
Subject: [PATCH 2/2] Deprecate KWaylandExtras::requestXdgActivationToken()
|
|
|
|
KWaylandExtras::xdgActivationToken() provides a more convenient way to
|
|
retrieve an xdg activation token.
|
|
|
|
Note that the QML side has no corresponding counterpart, however on the
|
|
other hand, there is no QML code that uses this function too. If the need
|
|
arises, the QML specific API could provide a Promise-like object.
|
|
---
|
|
src/CMakeLists.txt | 2 +-
|
|
src/kwaylandextras.cpp | 2 ++
|
|
src/kwaylandextras.h | 9 ++++++++-
|
|
src/kwindowsystem_p.h | 2 ++
|
|
src/platforms/wayland/windowsystem.cpp | 2 ++
|
|
src/platforms/wayland/windowsystem.h | 2 ++
|
|
6 files changed, 17 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
|
index fd72063b..ba748c2c 100644
|
|
--- a/src/CMakeLists.txt
|
|
+++ b/src/CMakeLists.txt
|
|
@@ -88,7 +88,7 @@ ecm_generate_export_header(KF6WindowSystem
|
|
VERSION ${KF_VERSION}
|
|
USE_VERSION_HEADER
|
|
DEPRECATED_BASE_VERSION 0
|
|
- DEPRECATION_VERSIONS 6.0
|
|
+ DEPRECATION_VERSIONS 6.0 6.19
|
|
EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
|
|
)
|
|
|
|
diff --git a/src/kwaylandextras.cpp b/src/kwaylandextras.cpp
|
|
index a5f8af8f..241f80be 100644
|
|
--- a/src/kwaylandextras.cpp
|
|
+++ b/src/kwaylandextras.cpp
|
|
@@ -26,6 +26,7 @@ KWaylandExtras *KWaylandExtras::self()
|
|
return &instance;
|
|
}
|
|
|
|
+#if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 19)
|
|
void KWaylandExtras::requestXdgActivationToken(QWindow *window, uint32_t serial, const QString &app_id)
|
|
{
|
|
auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(KWindowSystem::d_func());
|
|
@@ -39,6 +40,7 @@ void KWaylandExtras::requestXdgActivationToken(QWindow *window, uint32_t serial,
|
|
}
|
|
dv2->requestToken(window, serial, app_id);
|
|
}
|
|
+#endif
|
|
|
|
quint32 KWaylandExtras::lastInputSerial(QWindow *window)
|
|
{
|
|
diff --git a/src/kwaylandextras.h b/src/kwaylandextras.h
|
|
index 2f763dd5..56424b89 100644
|
|
--- a/src/kwaylandextras.h
|
|
+++ b/src/kwaylandextras.h
|
|
@@ -31,14 +31,18 @@ public:
|
|
*/
|
|
static KWaylandExtras *self();
|
|
|
|
+#if KWINDOWSYSTEM_ENABLE_DEPRECATED_SINCE(6, 19)
|
|
/*!
|
|
* Requests an xdg_activation_v1 token for a specific window \a win with the given \a app_id.
|
|
*
|
|
* \a serial Serial of the event that triggered the request.
|
|
*
|
|
* \sa lastInputSerial
|
|
+ * \deprecated [6.19] Use xdgActivationToken() instead.
|
|
*/
|
|
+ KWINDOWSYSTEM_DEPRECATED_VERSION(6, 19, "Use xdgActivationToken()")
|
|
Q_INVOKABLE static void requestXdgActivationToken(QWindow *win, uint32_t serial, const QString &app_id);
|
|
+#endif
|
|
|
|
/*!
|
|
* Offers the seat's current serial for the given \a window.
|
|
@@ -83,14 +87,17 @@ public:
|
|
static QFuture<QString> xdgActivationToken(QWindow *window, const QString &appId);
|
|
|
|
Q_SIGNALS:
|
|
+#if KWINDOWSYSTEM_ENABLE_DEPRECATED_SINCE(6, 19)
|
|
/*!
|
|
* Activation \a token to pass to the client.
|
|
*
|
|
* \a serial Serial of the event that triggered the request
|
|
*
|
|
* \sa requestXdgActivationToken
|
|
+ * \deprecated [6.19] Use xdgActivationToken() instead.
|
|
*/
|
|
- void xdgActivationTokenArrived(int serial, const QString &token);
|
|
+ KWINDOWSYSTEM_DEPRECATED_VERSION(6, 19, "Use xdgActivationToken()") void xdgActivationTokenArrived(int serial, const QString &token);
|
|
+#endif
|
|
|
|
/*!
|
|
* The \a handle of the given \a window to pass to the client.
|
|
diff --git a/src/kwindowsystem_p.h b/src/kwindowsystem_p.h
|
|
index e4b51e3e..92997120 100644
|
|
--- a/src/kwindowsystem_p.h
|
|
+++ b/src/kwindowsystem_p.h
|
|
@@ -27,7 +27,9 @@ public:
|
|
class KWINDOWSYSTEM_EXPORT KWindowSystemPrivateV2 : public KWindowSystemPrivate
|
|
{
|
|
public:
|
|
+#if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 19)
|
|
virtual void requestToken(QWindow *win, uint32_t serial, const QString &app_id) = 0;
|
|
+#endif
|
|
virtual void setCurrentToken(const QString &token) = 0;
|
|
virtual quint32 lastInputSerial(QWindow *window) = 0;
|
|
virtual void setMainWindow(QWindow *window, const QString &handle) = 0;
|
|
diff --git a/src/platforms/wayland/windowsystem.cpp b/src/platforms/wayland/windowsystem.cpp
|
|
index ebb22d78..bc803a4f 100644
|
|
--- a/src/platforms/wayland/windowsystem.cpp
|
|
+++ b/src/platforms/wayland/windowsystem.cpp
|
|
@@ -74,6 +74,7 @@ void WindowSystem::activateWindow(QWindow *win, long int time)
|
|
activation->activate(m_lastToken, s);
|
|
}
|
|
|
|
+#if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 19)
|
|
void WindowSystem::requestToken(QWindow *window, uint32_t serial, const QString &app_id)
|
|
{
|
|
if (window) {
|
|
@@ -97,6 +98,7 @@ void WindowSystem::requestToken(QWindow *window, uint32_t serial, const QString
|
|
Q_EMIT KWaylandExtras::self()->xdgActivationTokenArrived(serial, token);
|
|
});
|
|
}
|
|
+#endif
|
|
|
|
void WindowSystem::setCurrentToken(const QString &token)
|
|
{
|
|
diff --git a/src/platforms/wayland/windowsystem.h b/src/platforms/wayland/windowsystem.h
|
|
index 4df82388..e9dca128 100644
|
|
--- a/src/platforms/wayland/windowsystem.h
|
|
+++ b/src/platforms/wayland/windowsystem.h
|
|
@@ -19,7 +19,9 @@ public:
|
|
WindowSystem();
|
|
~WindowSystem() override;
|
|
void activateWindow(QWindow *win, long time) override;
|
|
+#if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 19)
|
|
void requestToken(QWindow *win, uint32_t serial, const QString &app_id) override;
|
|
+#endif
|
|
quint32 lastInputSerial(QWindow *window) override;
|
|
void setCurrentToken(const QString &token) override;
|
|
bool showingDesktop() override;
|
|
--
|
|
GitLab
|
|
|