From 64d492cb3a192d2da2aa8a68352aa4d207b61d6c Mon Sep 17 00:00:00 2001 From: ck Date: Tue, 26 Apr 2022 20:55:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20wayland=20=E6=8F=92=E4=BB=B6=E5=8F=B3?= =?UTF-8?q?=E9=94=AE=E8=8F=9C=E5=8D=95=E6=98=BE=E7=A4=BA=E5=90=8E=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=A1=8C=E9=9D=A2=E4=B8=8D=E4=BC=9A=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 点击菜单区域以外关闭菜单的逻辑: 1. 有parent的kwin会关闭 2. 没有parent的Qt会在失去焦点时关闭 由于dock无焦点,wayland 菜单无焦点,无父对象的菜单就关闭不了。 规避方案给菜单加上parent,后续如果菜单的role改变应该可以彻底避免。 Bug: https://pms.uniontech.com/bug-view-124531.html Influence: wayland plugin menu close Log: Change-Id: Id9c80f5131f0171469a279e6c7c7b54a0a3e8791 --- frame/item/dockitem.cpp | 3 +++ plugins/tray/snitraywidget.cpp | 2 ++ plugins/tray/system-trays/systemtrayitem.cpp | 3 +++ 3 files changed, 8 insertions(+) diff --git a/frame/item/dockitem.cpp b/frame/item/dockitem.cpp index ca7894b80..358f5e398 100644 --- a/frame/item/dockitem.cpp +++ b/frame/item/dockitem.cpp @@ -249,6 +249,9 @@ void DockItem::showContextMenu() hidePopup(); emit requestWindowAutoHide(false); + if (!m_contextMenu.parentWidget()) + m_contextMenu.setParent(topLevelWidget(), Qt::Popup); + m_contextMenu.exec(QCursor::pos()); onContextMenuAccepted(); diff --git a/plugins/tray/snitraywidget.cpp b/plugins/tray/snitraywidget.cpp index 8d0ded231..581df6488 100644 --- a/plugins/tray/snitraywidget.cpp +++ b/plugins/tray/snitraywidget.cpp @@ -284,6 +284,8 @@ void SNITrayWidget::initMenu() qDebug() << "generate the sni menu object"; m_menu = m_dbusMenuImporter->menu(); + if (m_menu && !m_menu->parentWidget()) + m_menu->setParent(topLevelWidget(), Qt::Popup); qDebug() << "the sni menu obect is:" << m_menu; } diff --git a/plugins/tray/system-trays/systemtrayitem.cpp b/plugins/tray/system-trays/systemtrayitem.cpp index 6dc8ff29b..e9eb0902a 100644 --- a/plugins/tray/system-trays/systemtrayitem.cpp +++ b/plugins/tray/system-trays/systemtrayitem.cpp @@ -451,6 +451,9 @@ void SystemTrayItem::showContextMenu() hidePopup(); emit requestWindowAutoHide(false); + if (!m_contextMenu.parentWidget()) + m_contextMenu.setParent(topLevelWidget(), Qt::Popup); + m_contextMenu.exec(QCursor::pos()); onContextMenuAccepted();