94 lines
2.1 KiB
C++
94 lines
2.1 KiB
C++
/*
|
|
Deepin DDE TrayManager1 implementation
|
|
SPDX-License-Identifier: LGPL-2.1-or-later
|
|
*/
|
|
|
|
#include "traymanager1.h"
|
|
#include "debug.h"
|
|
#include "traymanager1adaptor.h"
|
|
|
|
#include <KWindowInfo>
|
|
#include <QGuiApplication>
|
|
TrayManager1::TrayManager1(QObject *parent)
|
|
: QObject(parent)
|
|
, m_adaptor(new TrayManager1Adaptor(this))
|
|
{
|
|
qCDebug(SNIPROXY) << "TrayManager1 created";
|
|
}
|
|
|
|
TrayManager1::~TrayManager1()
|
|
{
|
|
qCDebug(SNIPROXY) << "TrayManager1 destroyed";
|
|
}
|
|
|
|
void TrayManager1::registerIcon(xcb_window_t win)
|
|
{
|
|
if (m_icons.contains(win)) {
|
|
qCWarning(SNIPROXY) << "Icon already registered:" << win;
|
|
return;
|
|
}
|
|
|
|
m_icons[win] = true;
|
|
qCDebug(SNIPROXY) << "Icon registered:" << win ;//<< "name:" << proxy->name();
|
|
|
|
Q_EMIT Added(static_cast<uint32_t>(win));
|
|
}
|
|
|
|
void TrayManager1::unregisterIcon(xcb_window_t win)
|
|
{
|
|
if (!m_icons.contains(win)) {
|
|
qCWarning(SNIPROXY) << "Icon not found for removal:" << win;
|
|
return;
|
|
}
|
|
|
|
m_icons.remove(win);
|
|
qCDebug(SNIPROXY) << "Icon unregistered:" << win;
|
|
|
|
Q_EMIT Removed(static_cast<uint32_t>(win));
|
|
}
|
|
|
|
void TrayManager1::notifyIconChanged(xcb_window_t win)
|
|
{
|
|
if (!m_icons.contains(win)) {
|
|
return;
|
|
}
|
|
|
|
qCDebug(SNIPROXY) << "Icon changed:" << win;
|
|
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;
|
|
}
|
|
|
|
bool TrayManager1::haveIcon(xcb_window_t win) const
|
|
{
|
|
return m_icons.contains(win);
|
|
}
|
|
|
|
// DBus method implementations
|
|
bool TrayManager1::Manage()
|
|
{
|
|
qCDebug(SNIPROXY) << "Manage() called via DBus";
|
|
return true;
|
|
}
|
|
|
|
QString TrayManager1::GetName(uint32_t win)
|
|
{
|
|
auto connection = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
|
|
KWindowInfo info(win, NET::WMName | NET::WMIconName);
|
|
return info.name();
|
|
}
|
|
|
|
void TrayManager1::EnableNotification(uint32_t win, bool enabled)
|
|
{
|
|
// TODO: Implement
|
|
qCDebug(SNIPROXY) << "TODO: EnableNotification for" << win << "=" << enabled;
|
|
}
|