-
Notifications
You must be signed in to change notification settings - Fork 54
feat: adopt xdg-activation protocol for Treeland dock plugin #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,13 @@ | |
| #ifndef DOCKCONTENTWIDGET_H | ||
| #define DOCKCONTENTWIDGET_H | ||
|
|
||
| #include "netmanager.h" | ||
| #include "netview.h" | ||
| #include "widget/jumpsettingbutton.h" | ||
| #include "xdgactivation.h" | ||
| #include "constants.h" | ||
|
|
||
| #include <QDebug> | ||
| #include <QEvent> | ||
| #include <QStyleOption> | ||
| #include <QStylePainter> | ||
|
|
@@ -45,7 +46,15 @@ | |
| m_netSetBtn = new JumpSettingButton(this); | ||
| m_netSetBtn->setIcon(QIcon::fromTheme("network-setting")); | ||
| m_netSetBtn->setDescription(tr("Network settings")); | ||
| connect(m_netSetBtn, &JumpSettingButton::clicked, netManager, &NetManager::gotoControlCenter); | ||
| connect(m_netSetBtn, &JumpSettingButton::clicked, this, [this, netManager]() { | ||
| auto *activation = new XdgActivation(this); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里有重复代码,建议在NetworkPlugin里加个函数,DockContentWidget里加个信号,NetworkPlugin里调用函数
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个不加函数吧,本身也是简单的组合,它跟NetworkPlugin也没有公共的东西, |
||
| connect(activation, &XdgActivation::tokenReady, this, | ||
| [netManager, activation](const QString &token) { | ||
| netManager->gotoControlCenter(token); | ||
| activation->deleteLater(); | ||
| }, Qt::SingleShotConnection); | ||
| activation->requestToken(); | ||
| }); | ||
|
|
||
| m_netCheckBtn = new JumpSettingButton(this); | ||
| m_netCheckBtn->setIcon(QIcon::fromTheme("network-check")); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "xdgactivation.h" | ||
|
|
||
| #include <DSGApplication> | ||
| #include <QGuiApplication> | ||
| #include <QLoggingCategory> | ||
| #include <QMetaObject> | ||
| #include <QtWaylandClient/QWaylandClientExtension> | ||
|
|
||
| #include "qwayland-xdg-activation-v1.h" | ||
|
|
||
| #include <private/qwaylanddisplay_p.h> | ||
| #include <private/qwaylandinputdevice_p.h> | ||
| #include <private/qwaylandwindow_p.h> | ||
|
|
||
| Q_LOGGING_CATEGORY(trayXdgActivation, "dde.network.xdgactivation") | ||
|
|
||
| namespace dde { | ||
| namespace network { | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // XdgActivationTokenV1 | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| 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); | ||
| } | ||
| }; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // XdgActivationV1 (singleton extension) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| namespace { | ||
|
|
||
| class XdgActivationV1 : public QWaylandClientExtensionTemplate<XdgActivationV1>, | ||
| public QtWayland::xdg_activation_v1 | ||
| { | ||
| public: | ||
| XdgActivationV1() | ||
| : QWaylandClientExtensionTemplate<XdgActivationV1>(1) | ||
| { | ||
| qCDebug(trayXdgActivation) << "Initializing xdg_activation_v1 extension, version:"; | ||
| initialize(); | ||
| qCDebug(trayXdgActivation) << "xdg_activation_v1 initialized, isActive:" << isActive(); | ||
| } | ||
|
|
||
| ~XdgActivationV1() override | ||
| { | ||
| if (isInitialized()) | ||
| destroy(); | ||
| } | ||
|
|
||
| XdgActivationTokenV1 *createTokenProvider(QWindow *window, const QString &appId) | ||
| { | ||
| qCDebug(trayXdgActivation) << "Creating token provider, window:" << window << "appId:" << appId; | ||
| auto *provider = new XdgActivationTokenV1; | ||
| provider->init(get_activation_token()); | ||
|
|
||
| if (window) { | ||
| if (auto *waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle())) { | ||
| if (auto *surface = waylandWindow->wlSurface()) { | ||
| qCDebug(trayXdgActivation) << "Setting surface for token request"; | ||
| provider->set_surface(surface); | ||
| } else { | ||
| qCWarning(trayXdgActivation) << "WaylandWindow has no wlSurface"; | ||
| } | ||
| if (auto *inputDevice = waylandWindow->display()->lastInputDevice()) { | ||
| qCDebug(trayXdgActivation) << "Setting serial:" << inputDevice->serial() << "seat:" << inputDevice->wl_seat(); | ||
| provider->set_serial(inputDevice->serial(), inputDevice->wl_seat()); | ||
| } else { | ||
| qCWarning(trayXdgActivation) << "No lastInputDevice available"; | ||
| } | ||
| } else { | ||
| qCWarning(trayXdgActivation) << "Window handle is not a QWaylandWindow"; | ||
| } | ||
| } else { | ||
| qCWarning(trayXdgActivation) << "No window provided for token request"; | ||
| } | ||
|
|
||
| if (!appId.isEmpty()) | ||
| provider->set_app_id(appId); | ||
|
|
||
| provider->commit(); | ||
| qCDebug(trayXdgActivation) << "Token provider committed"; | ||
| return provider; | ||
| } | ||
| }; | ||
|
|
||
| XdgActivationV1 *activationV1() | ||
| { | ||
| static QPointer<XdgActivationV1> activation; | ||
| if (activation) | ||
| return activation; | ||
|
|
||
| activation = new XdgActivationV1; | ||
| activation->setParent(qApp); | ||
| return activation; | ||
| } | ||
|
|
||
| } // anonymous namespace | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // XdgActivation | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| XdgActivation::XdgActivation(QObject *parent) | ||
| : QObject(parent) | ||
| { | ||
| } | ||
|
|
||
| XdgActivation::~XdgActivation() = default; | ||
|
|
||
| bool XdgActivation::isActive() const | ||
| { | ||
| auto *activation = activationV1(); | ||
| const bool active = activation && activation->isActive(); | ||
| qCDebug(trayXdgActivation) << "isActive:" << active; | ||
| return active; | ||
| } | ||
|
|
||
| void XdgActivation::requestToken(QWindow *window, const QString &appId) | ||
| { | ||
| qCDebug(trayXdgActivation) << "requestToken called, window:" << window << "appId:" << appId; | ||
|
|
||
| if (m_provider) { | ||
| qCWarning(trayXdgActivation) << "XDG activation token request already started, ignoring"; | ||
| return; | ||
| } | ||
|
|
||
| if (!isActive()) { | ||
| qCDebug(trayXdgActivation) << "xdg_activation_v1 is not active; token request skipped"; | ||
| Q_EMIT tokenReady({}); | ||
| return; | ||
| } | ||
|
|
||
| const QString effectiveAppId = appId.isEmpty() ? QString::fromUtf8(DTK_CORE_NAMESPACE::DSGApplication::id()) : appId; | ||
| qCDebug(trayXdgActivation) << "effectiveAppId:" << effectiveAppId; | ||
|
|
||
| if (effectiveAppId.isEmpty()) | ||
| qCWarning(trayXdgActivation) << "XDG activation request has empty app id"; | ||
|
|
||
| auto effectiveWindow = window ? window : QGuiApplication::focusWindow(); | ||
| qCDebug(trayXdgActivation) << "effectiveWindow:" << effectiveWindow; | ||
| auto *provider = activationV1()->createTokenProvider(effectiveWindow, effectiveAppId); | ||
| provider->setParent(this); | ||
| m_provider = provider; | ||
|
|
||
| connect(provider, &XdgActivationTokenV1::done, this, [this, provider, effectiveAppId](const QString &token) { | ||
| m_provider = nullptr; | ||
| if (token.isEmpty()) | ||
| qCWarning(trayXdgActivation) << "XDG activation token missing for app:" << effectiveAppId; | ||
| else | ||
| qCDebug(trayXdgActivation) << "XDG activation token received for app:" << effectiveAppId << "token length:" << token.length(); | ||
| provider->deleteLater(); | ||
| Q_EMIT tokenReady(token); | ||
| }, Qt::SingleShotConnection); | ||
| } | ||
|
|
||
| } // namespace network | ||
| } // namespace dde | ||
|
|
||
| #include "xdgactivation.moc" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.