diff --git a/frame/CMakeLists.txt b/frame/CMakeLists.txt index 1bfc03365..b54909545 100644 --- a/frame/CMakeLists.txt +++ b/frame/CMakeLists.txt @@ -15,6 +15,7 @@ set(PUBLIC_HEADERS appletbridge.h qmlengine.h layershell/dlayershellwindow.h + wayland/xdgactivation.h models/listtotableproxymodel.h dsutility.h ) @@ -29,6 +30,7 @@ set(PRIVATE_HEADERS private/dsqmlglobal_p.h layershell/qwaylandlayershellsurface_p.h layershell/qwaylandlayershellintegration_p.h + wayland/xdgactivation_p.h models/kextracolumnsproxymodel.h quick/dsquickdrag_p.h ) @@ -58,6 +60,7 @@ add_library(dde-shell-frame SHARED panel.cpp appletproxy.cpp appletbridge.cpp + wayland/xdgactivation.cpp appletitem.cpp containmentitem.cpp qmlengine.cpp @@ -83,6 +86,7 @@ set_target_properties(dde-shell-frame PROPERTIES qt_generate_wayland_protocol_client_sources(dde-shell-frame FILES ${CMAKE_CURRENT_SOURCE_DIR}/layershell/protocol/wlr-layer-shell-unstable-v1.xml ${WaylandProtocols_DATADIR}/stable/xdg-shell/xdg-shell.xml + ${WaylandProtocols_DATADIR}/staging/xdg-activation/xdg-activation-v1.xml ) set_target_properties(dde-shell-frame PROPERTIES diff --git a/frame/wayland/xdgactivation.cpp b/frame/wayland/xdgactivation.cpp new file mode 100644 index 000000000..ca5675cf2 --- /dev/null +++ b/frame/wayland/xdgactivation.cpp @@ -0,0 +1,179 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "xdgactivation_p.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "qwayland-xdg-activation-v1.h" +#include +#include +#include + +Q_LOGGING_CATEGORY(dsXdgActivation, "org.deepin.ds.xdgactivation") + +DS_BEGIN_NAMESPACE + +class XdgActivationTokenV1 : public QObject, public QtWayland::xdg_activation_token_v1 +{ + Q_OBJECT + +public: + ~XdgActivationTokenV1() override + { + destroy(); + } + +Q_SIGNALS: + void done(const QString &token); + +protected: + void xdg_activation_token_v1_done(const QString &token) override + { + Q_EMIT done(token); + } +}; + +namespace { + +class XdgActivationV1 : public QWaylandClientExtensionTemplate, + public QtWayland::xdg_activation_v1 +{ +public: + XdgActivationV1() + : QWaylandClientExtensionTemplate(1) + { + initialize(); + } + + ~XdgActivationV1() override + { + if (isInitialized()) + destroy(); + } + + XdgActivationTokenV1 *createTokenProvider(QWindow *window, const QString &appId) + { + auto *provider = new XdgActivationTokenV1; + provider->init(get_activation_token()); + + if (window) { + if (auto *waylandWindow = dynamic_cast(window->handle())) { + if (auto *surface = waylandWindow->wlSurface()) + provider->set_surface(surface); + if (auto *inputDevice = waylandWindow->display()->lastInputDevice()) + provider->set_serial(inputDevice->serial(), inputDevice->wl_seat()); + } + } + + if (!appId.isEmpty()) + provider->set_app_id(appId); + + provider->commit(); + return provider; + } +}; + +XdgActivationV1 *activationV1() +{ + static QPointer activation; + if (activation) + return activation; + + activation = new XdgActivationV1; + activation->setParent(qApp); + return activation; +} + +} // namespace + +// --------------------------------------------------------------------------- +// XdgActivationPrivate +// --------------------------------------------------------------------------- + +XdgActivationPrivate::XdgActivationPrivate(XdgActivation *qq) + : DObjectPrivate(qq) +{ +} + +XdgActivationPrivate::~XdgActivationPrivate() = default; + +// --------------------------------------------------------------------------- +// XdgActivation +// --------------------------------------------------------------------------- + +XdgActivation::XdgActivation(QObject *parent) + : QObject(parent) + , DObject(*new XdgActivationPrivate(this)) +{ +} + +XdgActivation::~XdgActivation() = default; + +bool XdgActivation::isActive() const +{ + if (!Dtk::Gui::DGuiApplicationHelper::testAttribute(Dtk::Gui::DGuiApplicationHelper::IsWaylandPlatform)) { + qCDebug(dsXdgActivation) << "not running on Wayland, isActive returns false"; + return false; + } + + auto *activation = activationV1(); + const bool active = activation && activation->isActive(); + qCDebug(dsXdgActivation) << "isActive:" << active; + return active; +} + +void XdgActivation::requestToken(QWindow *window, const QString &appId) +{ + D_D(XdgActivation); + + if (d->provider) { + qCWarning(dsXdgActivation) << "XDG activation token request already started"; + return; + } + + if (!isActive()) { + qCDebug(dsXdgActivation) << "xdg_activation_v1 is not active; token request skipped"; + Q_EMIT tokenReady({}); + return; + } + + const QString effectiveAppId = appId.isEmpty() ? QString::fromUtf8(Dtk::Core::DSGApplication::id()) : appId; + if (effectiveAppId.isEmpty()) + qCWarning(dsXdgActivation) << "XDG activation request has empty app id"; + + auto effectiveWindow = window ? window : QGuiApplication::focusWindow(); + if (!effectiveWindow) { + qCWarning(dsXdgActivation) << "XDG activation request has no target window"; + Q_EMIT tokenReady({}); + return; + } + + auto *provider = activationV1()->createTokenProvider(effectiveWindow, effectiveAppId); + provider->setParent(this); + d->provider = provider; + + connect(provider, &XdgActivationTokenV1::done, this, [this, provider, effectiveAppId](const QString &token) { + D_D(XdgActivation); + d->provider = nullptr; + + if (token.isEmpty()) + qCWarning(dsXdgActivation) << "XDG activation token missing for app:" << effectiveAppId; + else + qCDebug(dsXdgActivation) << "XDG activation token received for app:" << effectiveAppId; + + provider->deleteLater(); + Q_EMIT tokenReady(token); + }, Qt::SingleShotConnection); +} + +DS_END_NAMESPACE + +#include "xdgactivation.moc" diff --git a/frame/wayland/xdgactivation.h b/frame/wayland/xdgactivation.h new file mode 100644 index 000000000..7f0ecf918 --- /dev/null +++ b/frame/wayland/xdgactivation.h @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "dsglobal.h" + +#include +#include +#include + +DS_BEGIN_NAMESPACE + +class XdgActivationPrivate; +class DS_SHARE XdgActivation : public QObject, public DTK_CORE_NAMESPACE::DObject +{ + Q_OBJECT + D_DECLARE_PRIVATE(XdgActivation) +public: + explicit XdgActivation(QObject *parent = nullptr); + ~XdgActivation() override; + + bool isActive() const; + + void requestToken(QWindow *window = nullptr, const QString &appId = {}); + +Q_SIGNALS: + void tokenReady(const QString &token); +}; + +DS_END_NAMESPACE diff --git a/frame/wayland/xdgactivation_p.h b/frame/wayland/xdgactivation_p.h new file mode 100644 index 000000000..c7a7dad59 --- /dev/null +++ b/frame/wayland/xdgactivation_p.h @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "xdgactivation.h" + +#include + +#include + +DS_BEGIN_NAMESPACE + +class XdgActivationTokenV1; + +class XdgActivationPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate +{ +public: + explicit XdgActivationPrivate(XdgActivation *qq); + ~XdgActivationPrivate() override; + + QPointer provider; + + D_DECLARE_PUBLIC(XdgActivation) +}; + +DS_END_NAMESPACE