From 44285de0e1484423b51ce0bdfc45f96f367b5bed Mon Sep 17 00:00:00 2001 From: xinbo wang Date: Thu, 2 Dec 2021 14:55:39 +0800 Subject: [PATCH] fix: touch down to close popup window. when a popup window is shown,use touch to operation window or touch to move client,the popup window not be closed and be showing state. --- src/popup_input_filter.cpp | 25 +++++++++++++++++++++++++ src/popup_input_filter.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/popup_input_filter.cpp b/src/popup_input_filter.cpp index 1646e1b123..9d4336ffd8 100644 --- a/src/popup_input_filter.cpp +++ b/src/popup_input_filter.cpp @@ -95,6 +95,31 @@ bool PopupInputFilter::keyEvent(QKeyEvent *event) return true; } +bool PopupInputFilter::touchDown(qint32 id, const QPointF &pos, quint32 time) +{ + Q_UNUSED(id) + Q_UNUSED(time) + if (m_popupClients.isEmpty()) { + return false; + } + auto pointerFocus = qobject_cast(input()->findToplevel(pos.toPoint())); + if (!pointerFocus || !AbstractClient::belongToSameApplication(pointerFocus, qobject_cast(m_popupClients.constLast()))) { + // a touch on a window (or no window) not belonging to the popup window + cancelPopups(); + // filter out this touch + return true; + } + if (pointerFocus && pointerFocus->isDecorated()) { + // test whether it is on the decoration + const QRect clientRect = QRect(pointerFocus->clientPos(), pointerFocus->clientSize()).translated(pointerFocus->pos()); + if (!clientRect.contains(pos.toPoint())) { + cancelPopups(); + return true; + } + } + return false; +} + void PopupInputFilter::cancelPopups() { while (!m_popupClients.isEmpty()) { diff --git a/src/popup_input_filter.h b/src/popup_input_filter.h index a0a95446d2..7356ee595a 100644 --- a/src/popup_input_filter.h +++ b/src/popup_input_filter.h @@ -23,6 +23,7 @@ public: explicit PopupInputFilter(); bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override; bool keyEvent(QKeyEvent *event) override; + bool touchDown(qint32 id, const QPointF &pos, quint32 time) override; private: void handleClientAdded(Toplevel *client); void handleClientRemoved(Toplevel *client);