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
11 changes: 7 additions & 4 deletions plugins/application-tray/ddeindicatortrayprotocol.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -178,7 +178,7 @@ void DDEindicatorProtocolHandlerPrivate::updateContent()
Q_Q(DDEindicatorProtocolHandler);
if (!enabled) return;

auto widget = static_cast<QWidget*>(q->parent());
auto widget = q->window();

if (widget) {
widget->update();
Expand Down Expand Up @@ -333,9 +333,12 @@ bool DDEindicatorProtocolHandler::eventFilter(QObject *watched, QEvent *event)
{
Q_D(DDEindicatorProtocolHandler);

if (watched == parent()) {
if (watched == window()) {
if (event->type() == QEvent::Paint) {
auto widget = static_cast<QWidget*>(parent());
auto widget = window();
if (!widget)
return false;

QPainter painter(widget);
QFontMetrics qfm = QFontMetrics(widget->font());
QRect tightTextRect = qfm.tightBoundingRect(d->m_text);
Expand Down
7 changes: 5 additions & 2 deletions plugins/application-tray/sniprotocolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,11 @@ bool SniTrayProtocolHandler::eventFilter(QObject *watched, QEvent *event)
menu->setFixedSize(menu->sizeHint());
menu->winId();

auto widget = static_cast<QWidget*>(parent());
auto plugin = Plugin::EmbedPlugin::get(widget->window()->windowHandle());
auto *win = window()->windowHandle();
Comment thread
18202781743 marked this conversation as resolved.
if (!win)
return false;

auto plugin = Plugin::EmbedPlugin::get(win);
auto geometry = plugin->pluginPos();
auto pluginPopup = Plugin::PluginPopup::get(menu->windowHandle());
pluginPopup->setPluginId("application-tray");
Expand Down
8 changes: 6 additions & 2 deletions plugins/application-tray/trayplugin.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -83,14 +83,18 @@ void TrayPlugin::onTrayhandlerCreatd(QPointer<AbstractTrayProtocolHandler> handl
m_widget.insert(id, new TrayWidget(handler));

auto remove = [this, id]() {
// 清理 tooltip 指针,因为 tooltip widget 是 handler 的成员变量,
// 当 handler 被销毁时会被删除,所以需要先从 map 中移除悬空指针
m_tooltip.remove(id);

m_proyInter->itemRemoved(this, id);

auto widget = m_widget.value(id);
if (widget) {
widget->deleteLater();
}

m_widget.remove(id);
m_tooltip.remove(id);
};

auto showWidget = [this, handler, id](){
Expand Down
11 changes: 9 additions & 2 deletions plugins/application-tray/traywidget.cpp
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: GPL-3.0-or-later

Expand Down Expand Up @@ -28,7 +28,8 @@ TrayWidget::TrayWidget(QPointer<AbstractTrayProtocolHandler> handler)
setWindowTitle(m_handler->id());
setFixedSize(trayIconSize, trayIconSize);

m_handler->setParent(this);
// Note: Do NOT set parent here - handler lifecycle is managed by QSharedPointer
// Setting parent would cause double-delete when QSharedPointer destroys the handler

connect(m_handler, &AbstractTrayProtocolHandler::iconChanged, this, [this](){update();});
connect(m_handler, &AbstractTrayProtocolHandler::overlayIconChanged, this, [this](){update();});
Expand All @@ -47,6 +48,9 @@ TrayWidget::~TrayWidget()
void TrayWidget::showEvent(QShowEvent* event)
{
Q_UNUSED(event)
if (!m_handler)
return;

m_handler->setWindow(window());
window()->installEventFilter(m_handler);
Comment thread
18202781743 marked this conversation as resolved.
window()->setMouseTracking(true);
Expand All @@ -56,6 +60,9 @@ void TrayWidget::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event)

if (!m_handler)
return;

// TODO: support attentionIcon/overlayIcon
QPalette palette;
auto textColor = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? Qt::black : Qt::white;
Expand Down
Loading