sync back changes from dde-tray-loader

This commit is contained in:
2025-12-29 18:09:38 +08:00
parent cb3830e6c7
commit b7bcf428ee
4 changed files with 29 additions and 20 deletions

View File

@@ -31,11 +31,11 @@ using Util = tray::Util;
Q_LOGGING_CATEGORY(SELECTIONMGR, "org.deepin.dde.trayloader.selectionmgr") Q_LOGGING_CATEGORY(SELECTIONMGR, "org.deepin.dde.trayloader.selectionmgr")
FdoSelectionManager::FdoSelectionManager() FdoSelectionManager::FdoSelectionManager(QObject *parent)
: QObject() : QObject(parent)
, m_selectionOwner(new KSelectionOwner(UTIL->getAtomFromDisplay("_NET_SYSTEM_TRAY"), UTIL->getX11Connection(), UTIL->getRootWindow(), this)) , m_selectionOwner(new KSelectionOwner(UTIL->getAtomFromDisplay("_NET_SYSTEM_TRAY"), UTIL->getX11Connection(), UTIL->getRootWindow(), this))
{ {
qDebug(SELECTIONMGR) << "starting"; qCDebug(SELECTIONMGR) << "starting";
// we may end up calling QCoreApplication::quit() in this method, at which point we need the event loop running // we may end up calling QCoreApplication::quit() in this method, at which point we need the event loop running
QTimer::singleShot(0, this, &FdoSelectionManager::init); QTimer::singleShot(0, this, &FdoSelectionManager::init);
@@ -67,7 +67,11 @@ void FdoSelectionManager::init()
connect(m_selectionOwner, &KSelectionOwner::claimedOwnership, this, &FdoSelectionManager::onClaimedOwnership); connect(m_selectionOwner, &KSelectionOwner::claimedOwnership, this, &FdoSelectionManager::onClaimedOwnership);
connect(m_selectionOwner, &KSelectionOwner::failedToClaimOwnership, this, &FdoSelectionManager::onFailedToClaimOwnership); connect(m_selectionOwner, &KSelectionOwner::failedToClaimOwnership, this, &FdoSelectionManager::onFailedToClaimOwnership);
connect(m_selectionOwner, &KSelectionOwner::lostOwnership, this, &FdoSelectionManager::onLostOwnership); connect(m_selectionOwner, &KSelectionOwner::lostOwnership, this, &FdoSelectionManager::onLostOwnership);
m_selectionOwner->claim(false); m_selectionOwner->claim(true);
connect(m_trayManager, &TrayManager1::reclainRequested, this, [this](){
m_selectionOwner->claim(true);
});
} }
bool FdoSelectionManager::addDamageWatch(xcb_window_t client) bool FdoSelectionManager::addDamageWatch(xcb_window_t client)
@@ -171,10 +175,11 @@ void FdoSelectionManager::undock(xcb_window_t winId)
Q_CHECK_PTR(m_trayManager); Q_CHECK_PTR(m_trayManager);
qCDebug(SELECTIONMGR) << "trying to undock window " << winId; qCDebug(SELECTIONMGR) << "trying to undock window " << winId;
if (m_trayManager->haveIcon(winId)) { if (!m_trayManager->haveIcon(winId)) {
qCDebug(SELECTIONMGR) << "failed to find winId to undock:" << winId;
return; return;
} }
// Unregister from TrayManager1 if available // Unregister from TrayManager1 if available
m_trayManager->unregisterIcon(winId); m_trayManager->unregisterIcon(winId);
@@ -193,13 +198,11 @@ void FdoSelectionManager::onClaimedOwnership()
void FdoSelectionManager::onFailedToClaimOwnership() void FdoSelectionManager::onFailedToClaimOwnership()
{ {
qCWarning(SELECTIONMGR) << "failed to claim ownership of Systray Manager"; qCWarning(SELECTIONMGR) << "failed to claim ownership of Systray Manager";
qApp->exit(-1);
} }
void FdoSelectionManager::onLostOwnership() void FdoSelectionManager::onLostOwnership()
{ {
qCWarning(SELECTIONMGR) << "lost ownership of Systray Manager"; qCWarning(SELECTIONMGR) << "lost ownership of Systray Manager";
qApp->exit(-1);
} }
void FdoSelectionManager::setSystemTrayVisual() void FdoSelectionManager::setSystemTrayVisual()

View File

@@ -23,7 +23,7 @@ class FdoSelectionManager : public QObject, public QAbstractNativeEventFilter
Q_OBJECT Q_OBJECT
public: public:
FdoSelectionManager(); FdoSelectionManager(QObject *parent = nullptr);
~FdoSelectionManager() override; ~FdoSelectionManager() override;
protected: protected:

View File

@@ -1,11 +1,14 @@
/* // Deepin DDE TrayManager1 implementation
Deepin DDE TrayManager1 implementation //
SPDX-License-Identifier: LGPL-2.1-or-later // SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
*/ //
// SPDX-License-Identifier: GPL-3.0-or-later
#include "traymanager1.h" #include "traymanager1.h"
#include "traymanager1adaptor.h" #include "traymanager1adaptor.h"
#include "util.h"
#include <KWindowInfo> #include <KWindowInfo>
#include <QGuiApplication> #include <QGuiApplication>
#include <QLoggingCategory> #include <QLoggingCategory>
@@ -84,14 +87,14 @@ bool TrayManager1::haveIcon(xcb_window_t win) const
bool TrayManager1::Manage() bool TrayManager1::Manage()
{ {
qCDebug(TRAYMGR) << "Manage() called via DBus"; qCDebug(TRAYMGR) << "Manage() called via DBus";
emit reclainRequested();
return true; return true;
} }
QString TrayManager1::GetName(uint32_t win) QString TrayManager1::GetName(uint32_t win)
{ {
auto connection = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection(); using Util = tray::Util;
KWindowInfo info(win, NET::WMName | NET::WMIconName); return UTIL->getX11WindowName(win);
return info.name();
} }
void TrayManager1::EnableNotification(uint32_t win, bool enabled) void TrayManager1::EnableNotification(uint32_t win, bool enabled)

View File

@@ -1,7 +1,8 @@
/* // Deepin DDE TrayManager1 implementation
Deepin DDE TrayManager1 implementation //
SPDX-License-Identifier: LGPL-2.1-or-later // SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
*/ //
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once #pragma once
@@ -74,6 +75,8 @@ Q_SIGNALS:
void Changed(uint32_t id); void Changed(uint32_t id);
void Inited(); void Inited();
void reclainRequested();
private: private:
TrayManager1Adaptor * m_adaptor; TrayManager1Adaptor * m_adaptor;
QHash<xcb_window_t, bool> m_icons; // <winid, enableNotify> QHash<xcb_window_t, bool> m_icons; // <winid, enableNotify>