fix: wayland 插件右键菜单显示后点击桌面不会关闭

点击菜单区域以外关闭菜单的逻辑:
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
This commit is contained in:
ck 2022-04-26 20:55:25 +08:00 committed by chenke
parent 1163836f16
commit 64d492cb3a
3 changed files with 8 additions and 0 deletions

View File

@ -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();

View File

@ -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;
}

View File

@ -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();