Files
xembed-fluff/traymanager1.cpp

110 lines
2.4 KiB
C++
Raw Permalink Normal View History

2025-12-29 18:09:38 +08:00
// Deepin DDE TrayManager1 implementation
//
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
2025-12-18 16:52:13 +08:00
#include "traymanager1.h"
#include "traymanager1adaptor.h"
2025-12-29 18:09:38 +08:00
#include "util.h"
2025-12-18 21:10:53 +08:00
#include <KWindowInfo>
#include <QGuiApplication>
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(TRAYMGR, "org.deepin.dde.trayloader.traymgr")
2025-12-18 16:52:13 +08:00
TrayManager1::TrayManager1(QObject *parent)
: QObject(parent)
, m_adaptor(new TrayManager1Adaptor(this))
{
qCDebug(TRAYMGR) << "TrayManager1 created";
2025-12-18 16:52:13 +08:00
}
TrayManager1::~TrayManager1()
{
qCDebug(TRAYMGR) << "TrayManager1 destroyed";
2025-12-18 16:52:13 +08:00
}
2025-12-18 21:10:53 +08:00
void TrayManager1::registerIcon(xcb_window_t win)
2025-12-18 16:52:13 +08:00
{
if (m_icons.contains(win)) {
qCWarning(TRAYMGR) << "Icon already registered:" << win;
2025-12-18 16:52:13 +08:00
return;
}
2025-12-18 21:10:53 +08:00
m_icons[win] = true;
qCDebug(TRAYMGR) << "Icon registered:" << win ;//<< "name:" << proxy->name();
2025-12-18 16:52:13 +08:00
Q_EMIT Added(static_cast<uint32_t>(win));
}
void TrayManager1::unregisterIcon(xcb_window_t win)
{
if (!m_icons.contains(win)) {
qCWarning(TRAYMGR) << "Icon not found for removal:" << win;
2025-12-18 16:52:13 +08:00
return;
}
m_icons.remove(win);
qCDebug(TRAYMGR) << "Icon unregistered:" << win;
2025-12-18 16:52:13 +08:00
Q_EMIT Removed(static_cast<uint32_t>(win));
}
void TrayManager1::notifyIconChanged(xcb_window_t win)
{
if (!m_icons.contains(win)) {
return;
}
2025-12-19 16:03:06 +08:00
if (!m_icons[win]) {
qCDebug(TRAYMGR) << "EnableNotification is false, not sending changed signal for:" << win;
2025-12-19 16:03:06 +08:00
return;
}
qCDebug(TRAYMGR) << "Icon changed:" << win;
2025-12-18 16:52:13 +08:00
Q_EMIT Changed(static_cast<uint32_t>(win));
}
TrayList TrayManager1::trayIcons() const
{
qDebug() << "trayIcons:" << m_icons.keys();
TrayList result;
for (xcb_window_t win : m_icons.keys()) {
result << static_cast<uint>(win);
}
return result;
}
2025-12-18 21:10:53 +08:00
bool TrayManager1::haveIcon(xcb_window_t win) const
2025-12-18 16:52:13 +08:00
{
2025-12-18 21:10:53 +08:00
return m_icons.contains(win);
2025-12-18 16:52:13 +08:00
}
// DBus method implementations
bool TrayManager1::Manage()
{
qCDebug(TRAYMGR) << "Manage() called via DBus";
2025-12-29 18:09:38 +08:00
emit reclainRequested();
2025-12-18 16:52:13 +08:00
return true;
}
QString TrayManager1::GetName(uint32_t win)
{
2025-12-29 18:09:38 +08:00
using Util = tray::Util;
return UTIL->getX11WindowName(win);
2025-12-18 16:52:13 +08:00
}
void TrayManager1::EnableNotification(uint32_t win, bool enabled)
{
2025-12-19 16:03:06 +08:00
if (!m_icons.contains(win)) {
return;
}
m_icons[win] = enabled;
qCDebug(TRAYMGR) << "EnableNotification for" << win << "=" << enabled;
2025-12-18 16:52:13 +08:00
}