fix: 修复点击快捷面板之外的区域快捷面板不关闭的问题

将DockPopupWindow中的DRegionMonitor换成XEventMonitor,监控它的鼠标点击和释放鼠标的事件

Log:
Influence: 进入wayland,打开快捷面板,点击快捷面板之外的其他区域,观察快捷面板是否关闭
Bug: https://pms.uniontech.com/bug-view-171545.html
Bug: https://pms.uniontech.com/bug-view-171583.html
Change-Id: I5dda27170316132812c546d8c362d3dc4546e35a
This commit is contained in:
donghualin 2022-11-17 10:49:48 +08:00
parent a406ebb68a
commit ac9de7ef51
3 changed files with 40 additions and 36 deletions

View File

@ -22,6 +22,7 @@
#include "dockpopupwindow.h"
#include "imageutil.h"
#include "utils.h"
#include "dbusutil.h"
#include <QScreen>
#include <QApplication>
@ -34,10 +35,10 @@
DWIDGET_USE_NAMESPACE
DockPopupWindow::DockPopupWindow(QWidget *parent)
: DArrowRectangle(ArrowBottom, parent),
m_model(false),
m_regionInter(new DRegionMonitor(this)),
m_enableMouseRelease(true)
: DArrowRectangle(ArrowBottom, parent)
, m_model(false)
, m_eventMonitor(new XEventMonitor(xEventMonitorService, xEventMonitorPath, QDBusConnection::sessionBus(), this))
, m_enableMouseRelease(true)
{
setMargin(0);
m_wmHelper = DWindowManagerHelper::instance();
@ -53,7 +54,10 @@ DockPopupWindow::DockPopupWindow(QWidget *parent)
}
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DockPopupWindow::compositeChanged);
connect(m_regionInter, &DRegionMonitor::buttonRelease, this, &DockPopupWindow::onGlobMouseRelease);
connect(m_eventMonitor, &XEventMonitor::ButtonPress, this, &DockPopupWindow::onButtonPress);
if (Utils::IS_WAYLAND_DISPLAY)
QDBusConnection::sessionBus().connect("com.deepin.dde.lockFront", "/com/deepin/dde/lockFront", "com.deepin.dde.lockFront", "Visible", "b", this, SLOT(hide()));
}
DockPopupWindow::~DockPopupWindow()
@ -88,13 +92,15 @@ void DockPopupWindow::show(const QPoint &pos, const bool model)
show(pos.x(), pos.y());
if (m_regionInter->registered()) {
m_regionInter->unregisterRegion();
if (!m_eventKey.isEmpty()) {
m_eventMonitor->UnregisterArea(m_eventKey);
m_eventKey.clear();
}
if (m_model) {
m_regionInter->registerRegion();
m_eventKey = m_eventMonitor->RegisterFullScreen();
}
blockButtonRelease();
}
@ -117,8 +123,10 @@ void DockPopupWindow::blockButtonRelease()
void DockPopupWindow::hide()
{
if (m_regionInter->registered())
m_regionInter->unregisterRegion();
if (!m_eventKey.isEmpty()) {
m_eventMonitor->UnregisterArea(m_eventKey);
m_eventKey.clear();
}
DArrowRectangle::hide();
}
@ -149,8 +157,7 @@ bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)
return false;
// FIXME: ensure position move after global mouse release event
if (isVisible())
{
if (isVisible()) {
QTimer::singleShot(10, this, [=] {
// NOTE(sbw): double check is necessary, in this time, the popup maybe already hided.
if (isVisible())
@ -161,27 +168,6 @@ bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)
return false;
}
void DockPopupWindow::onGlobMouseRelease(const QPoint &mousePos, const int flag)
{
Q_ASSERT(m_model);
if (!m_enableMouseRelease)
return;
if (!((flag == DRegionMonitor::WatchedFlags::Button_Left) ||
(flag == DRegionMonitor::WatchedFlags::Button_Right))) {
return;
}
const QRect rect = QRect(pos(), size());
if (rect.contains(mousePos))
return;
emit accept();
m_regionInter->unregisterRegion();
}
void DockPopupWindow::compositeChanged()
{
if (m_wmHelper->hasComposite())
@ -195,3 +181,16 @@ void DockPopupWindow::ensureRaised()
if (isVisible())
raise();
}
void DockPopupWindow::onButtonPress(int type, int x, int y, const QString &key)
{
if (!m_enableMouseRelease)
return;
QRect popupRect(pos(), size());
if (popupRect.contains(x, y))
return;
emit accept();
hide();
}

View File

@ -22,6 +22,8 @@
#ifndef DOCKPOPUPWINDOW_H
#define DOCKPOPUPWINDOW_H
#include "org_deepin_api_xeventmonitor.h"
#include <darrowrectangle.h>
#include <dregionmonitor.h>
#include <DWindowManagerHelper>
@ -29,6 +31,8 @@
DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE
using XEventMonitor = ::org::deepin::api::XEventMonitor1;
class DockPopupWindow : public Dtk::Widget::DArrowRectangle
{
Q_OBJECT
@ -61,15 +65,16 @@ protected:
void blockButtonRelease();
private slots:
void onGlobMouseRelease(const QPoint &mousePos, const int flag);
void compositeChanged();
void ensureRaised();
void onButtonPress(int type, int x, int y, const QString &key);
private:
bool m_model;
QPoint m_lastPoint;
DRegionMonitor *m_regionInter;
XEventMonitor *m_eventMonitor;
QString m_eventKey;
DWindowManagerHelper *m_wmHelper;
bool m_enableMouseRelease;
};

View File

@ -216,7 +216,7 @@ bool QuickPluginWindow::eventFilter(QObject *watched, QEvent *event)
dockItem->hideToolTip();
}
}
popWindow->show(popupPoint());
popWindow->show(popupPoint(), true);
}
m_dragInfo->reset();
break;