Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
# SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0

Expand Down Expand Up @@ -40,6 +40,9 @@ endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

find_package(PkgConfig REQUIRED)
pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir)

add_subdirectory(plugins)
add_subdirectory(src)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<arg direction="in" type="i" name="x"/>
<arg direction="in" type="i" name="y"/>
</method>
<method name="ProvideXdgActivationToken">
<arg direction="in" type="s" name="token"/>
</method>
<method name="SecondaryActivate">
<arg direction="in" type="i" name="x"/>
<arg direction="in" type="i" name="y"/>
Expand Down
23 changes: 22 additions & 1 deletion plugins/application-tray/sniprotocolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include "statusnotifieriteminterface.h"

#include "util.h"
#include "plugin.h"

Check warning on line 10 in plugins/application-tray/sniprotocolhandler.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "plugin.h" not found.
#include "xdgactivation.h"

Check warning on line 11 in plugins/application-tray/sniprotocolhandler.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "xdgactivation.h" not found.

#include "dbusmenuimporter.h"

Check warning on line 13 in plugins/application-tray/sniprotocolhandler.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dbusmenuimporter.h" not found.

#include <QMouseEvent>
#include <QWindow>
Expand Down Expand Up @@ -317,7 +318,27 @@
if (event->type() == QEvent::MouseButtonRelease) {
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::LeftButton) {
m_sniInter->Activate(0, 0);
auto *activation = new XdgActivation(this);
if (activation->isActive()) {
auto *win = window()->windowHandle();
if (!win) {
activation->deleteLater();
return false;
}

auto sniInter = m_sniInter;
connect(activation, &XdgActivation::tokenReady, this, [sniInter, activation](const QString &token) {
if (!token.isEmpty()) {
sniInter->ProvideXdgActivationToken(token);
}
sniInter->Activate(0, 0);
activation->deleteLater();
}, Qt::SingleShotConnection);
activation->requestToken(win);
} else {
m_sniInter->Activate(0, 0);
activation->deleteLater();
}
} else if (mouseEvent->button() == Qt::RightButton) {
if (!menuImporter()) {
m_sniInter->ContextMenu(0, 0);
Expand Down
23 changes: 21 additions & 2 deletions src/tray-wayland-integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
# SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0

find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui WaylandClient)
if(Qt${QT_VERSION_MAJOR}_VERSION VERSION_GREATER_EQUAL 6.10)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS GuiPrivate WaylandClientPrivate REQUIRED)
endif()
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Gui Widget)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widget)

find_package(ECM REQUIRED MO_MODULE)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ECM_MODULE_PATH}")
Expand All @@ -17,6 +17,15 @@ include(KDEInstallDirs)
add_library(dockpluginmanager-interface SHARED
plugin.h
plugin.cpp
xdgactivation.h
xdgactivation_p.h
xdgactivation.cpp
)

qt_generate_wayland_protocol_client_sources(dockpluginmanager-interface
NO_INCLUDE_CORE_ONLY
FILES
${WAYLAND_PROTOCOLS_DATADIR}/staging/xdg-activation/xdg-activation-v1.xml
)

target_include_directories(dockpluginmanager-interface PUBLIC
Expand All @@ -28,6 +37,14 @@ PUBLIC
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
Dtk${DTK_VERSION_MAJOR}::Widget
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::WaylandClient
Qt${QT_VERSION_MAJOR}::WaylandClientPrivate
Dtk${DTK_VERSION_MAJOR}::Core
Dtk${DTK_VERSION_MAJOR}::Gui
Wayland::Client
)

add_library(dockpluginmanager SHARED
Expand All @@ -53,6 +70,8 @@ PRIVATE
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::WaylandClient
Qt${QT_VERSION_MAJOR}::WaylandClientPrivate
Dtk${DTK_VERSION_MAJOR}::Core
Dtk${DTK_VERSION_MAJOR}::Gui
Wayland::Client
)

Expand Down
173 changes: 173 additions & 0 deletions src/tray-wayland-integration/xdgactivation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "xdgactivation_p.h"

#include <DSGApplication>

Check warning on line 7 in src/tray-wayland-integration/xdgactivation.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DSGApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QGuiApplication>

Check warning on line 8 in src/tray-wayland-integration/xdgactivation.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGuiApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Check warning on line 9 in src/tray-wayland-integration/xdgactivation.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMetaObject>

Check warning on line 10 in src/tray-wayland-integration/xdgactivation.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMetaObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPointer>

Check warning on line 11 in src/tray-wayland-integration/xdgactivation.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtWaylandClient/QWaylandClientExtension>

Check warning on line 12 in src/tray-wayland-integration/xdgactivation.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtWaylandClient/QWaylandClientExtension> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "qwayland-xdg-activation-v1.h"

Check warning on line 14 in src/tray-wayland-integration/xdgactivation.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "qwayland-xdg-activation-v1.h" not found.
#include <private/qwaylanddisplay_p.h>
#include <private/qwaylandinputdevice_p.h>
#include <private/qwaylandwindow_p.h>

Q_LOGGING_CATEGORY(trayXdgActivation, "dde.tray.xdgactivation")

namespace tray {

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<XdgActivationV1>,
public QtWayland::xdg_activation_v1
{
public:
XdgActivationV1()
: QWaylandClientExtensionTemplate<XdgActivationV1>(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<QtWaylandClient::QWaylandWindow *>(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<XdgActivationV1> 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
{
auto *activation = activationV1();
const bool active = activation && activation->isActive();
qCDebug(trayXdgActivation) << "isActive:" << active;
return active;
}

void XdgActivation::requestToken(QWindow *window, const QString &appId)
{
D_D(XdgActivation);

if (d->provider) {
qCWarning(trayXdgActivation) << "XDG activation token request already started";
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;
if (effectiveAppId.isEmpty())
qCWarning(trayXdgActivation) << "XDG activation request has empty app id";

auto effectiveWindow = window ? window : QGuiApplication::focusWindow();
if (!effectiveWindow) {
qCWarning(trayXdgActivation) << "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(trayXdgActivation) << "XDG activation token missing for app:" << effectiveAppId;
else
qCDebug(trayXdgActivation) << "XDG activation token received for app:" << effectiveAppId;

provider->deleteLater();
Q_EMIT tokenReady(token);
}, Qt::SingleShotConnection);
}

} // namespace tray

#include "xdgactivation.moc"
30 changes: 30 additions & 0 deletions src/tray-wayland-integration/xdgactivation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <DObject>
#include <QObject>
#include <QWindow>

namespace tray {

class XdgActivationPrivate;
class 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);
};

} // namespace tray
28 changes: 28 additions & 0 deletions src/tray-wayland-integration/xdgactivation_p.h
Original file line number Diff line number Diff line change
@@ -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 <dobject_p.h>

#include <QPointer>

namespace tray {

class XdgActivationTokenV1;

class XdgActivationPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
{
public:
explicit XdgActivationPrivate(XdgActivation *qq);
~XdgActivationPrivate() override;

QPointer<XdgActivationTokenV1> provider;

D_DECLARE_PUBLIC(XdgActivation)
};

} // namespace tray
Loading