From b7bcf428eea1c610c3120c50cd01bb73b5090667 Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Mon, 29 Dec 2025 18:09:38 +0800 Subject: [PATCH] sync back changes from dde-tray-loader --- fdoselectionmanager.cpp | 19 +++++++++++-------- fdoselectionmanager.h | 2 +- traymanager1.cpp | 17 ++++++++++------- traymanager1.h | 11 +++++++---- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/fdoselectionmanager.cpp b/fdoselectionmanager.cpp index 37a1fdc..acd40b5 100644 --- a/fdoselectionmanager.cpp +++ b/fdoselectionmanager.cpp @@ -31,11 +31,11 @@ using Util = tray::Util; Q_LOGGING_CATEGORY(SELECTIONMGR, "org.deepin.dde.trayloader.selectionmgr") -FdoSelectionManager::FdoSelectionManager() - : QObject() +FdoSelectionManager::FdoSelectionManager(QObject *parent) + : QObject(parent) , 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 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::failedToClaimOwnership, this, &FdoSelectionManager::onFailedToClaimOwnership); 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) @@ -171,10 +175,11 @@ void FdoSelectionManager::undock(xcb_window_t winId) Q_CHECK_PTR(m_trayManager); 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; } - + // Unregister from TrayManager1 if available m_trayManager->unregisterIcon(winId); @@ -193,13 +198,11 @@ void FdoSelectionManager::onClaimedOwnership() void FdoSelectionManager::onFailedToClaimOwnership() { qCWarning(SELECTIONMGR) << "failed to claim ownership of Systray Manager"; - qApp->exit(-1); } void FdoSelectionManager::onLostOwnership() { qCWarning(SELECTIONMGR) << "lost ownership of Systray Manager"; - qApp->exit(-1); } void FdoSelectionManager::setSystemTrayVisual() diff --git a/fdoselectionmanager.h b/fdoselectionmanager.h index 1d24448..6eebed1 100644 --- a/fdoselectionmanager.h +++ b/fdoselectionmanager.h @@ -23,7 +23,7 @@ class FdoSelectionManager : public QObject, public QAbstractNativeEventFilter Q_OBJECT public: - FdoSelectionManager(); + FdoSelectionManager(QObject *parent = nullptr); ~FdoSelectionManager() override; protected: diff --git a/traymanager1.cpp b/traymanager1.cpp index 18a934c..f3bf648 100644 --- a/traymanager1.cpp +++ b/traymanager1.cpp @@ -1,11 +1,14 @@ -/* - Deepin DDE TrayManager1 implementation - SPDX-License-Identifier: LGPL-2.1-or-later -*/ +// Deepin DDE TrayManager1 implementation +// +// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later #include "traymanager1.h" #include "traymanager1adaptor.h" +#include "util.h" + #include #include #include @@ -84,14 +87,14 @@ bool TrayManager1::haveIcon(xcb_window_t win) const bool TrayManager1::Manage() { qCDebug(TRAYMGR) << "Manage() called via DBus"; + emit reclainRequested(); return true; } QString TrayManager1::GetName(uint32_t win) { - auto connection = qGuiApp->nativeInterface()->connection(); - KWindowInfo info(win, NET::WMName | NET::WMIconName); - return info.name(); + using Util = tray::Util; + return UTIL->getX11WindowName(win); } void TrayManager1::EnableNotification(uint32_t win, bool enabled) diff --git a/traymanager1.h b/traymanager1.h index 4f41eff..2fcb281 100644 --- a/traymanager1.h +++ b/traymanager1.h @@ -1,7 +1,8 @@ -/* - Deepin DDE TrayManager1 implementation - SPDX-License-Identifier: LGPL-2.1-or-later -*/ +// Deepin DDE TrayManager1 implementation +// +// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later #pragma once @@ -74,6 +75,8 @@ Q_SIGNALS: void Changed(uint32_t id); void Inited(); + void reclainRequested(); + private: TrayManager1Adaptor * m_adaptor; QHash m_icons; //