From 1cb0d180bdda8bf06b77daf7a404d9213270752b Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Sun, 28 Jan 2018 09:07:33 +0000 Subject: [PATCH] Fix autohide panels on wayland Summary: To test if the panel is under the cursor we used: if (geometry().contains(QCursor::pos(screenToFollow()))) { Unsurprisingly in wayland we don't know the cursor position once it's left our window. Behaviour seems to be undefined. We were already using enter and leave events to start the autohide timer, so we may as well rely on that for tracking state too. BUG: 377838 Test Plan: Tested mouse in, mouse out Tested mouse in and waiting and panel stayed open Tested opening wifi applet and closing it That will trigger the restoreAutoHide method as an applet status changed The panel stayed open because the mouse was on it. Reviewers: #plasma, mart Reviewed By: #plasma, mart Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D10101 --- shell/panelview.cpp | 38 ++++++++++++++++++++------------------ shell/panelview.h | 1 + 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/shell/panelview.cpp b/shell/panelview.cpp index 1ab7d9ab3..7c87cec05 100644 --- a/shell/panelview.cpp +++ b/shell/panelview.cpp @@ -624,7 +624,7 @@ void PanelView::restoreAutoHide() if (!edgeActivated()) { autoHide = false; } - else if (geometry().contains(QCursor::pos(screenToFollow()))) { + else if (m_containsMouse) { autoHide = false; } else if (containment() && containment()->isUserConfiguring()) { @@ -802,18 +802,25 @@ void PanelView::adaptToScreen() bool PanelView::event(QEvent *e) { - if (edgeActivated()) { - if (e->type() == QEvent::Enter) { - m_unhideTimer.stop(); - } else if (e->type() == QEvent::Leave) { - m_unhideTimer.start(); - } - } - - /*Fitt's law: if the containment has margins, and the mouse cursor clicked - * on the mouse edge, forward the click in the containment boundaries - */ switch (e->type()) { + case QEvent::Enter: + m_containsMouse = true; + if (edgeActivated()) { + m_unhideTimer.stop(); + } + break; + + case QEvent::Leave: + m_containsMouse = false; + if (edgeActivated()) { + m_unhideTimer.start(); + } + break; + + /*Fitt's law: if the containment has margins, and the mouse cursor clicked + * on the mouse edge, forward the click in the containment boundaries + */ + case QEvent::MouseMove: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: { @@ -839,12 +846,6 @@ bool PanelView::event(QEvent *e) break; } - case QEvent::Enter: - case QEvent::Leave: - // QtQuick < 5.6 issue: - // QEvent::Leave is triggered on MouseButtonPress Qt::LeftButton - break; - case QEvent::Wheel: { QWheelEvent *we = static_cast(e); @@ -901,6 +902,7 @@ bool PanelView::event(QEvent *e) if (m_panelConfigView && m_panelConfigView.data()->isVisible()) { m_panelConfigView.data()->hide(); } + m_containsMouse = false; break; } case QEvent::PlatformSurface: diff --git a/shell/panelview.h b/shell/panelview.h index befae202b..adb4403b9 100644 --- a/shell/panelview.h +++ b/shell/panelview.h @@ -221,6 +221,7 @@ private: int m_distance; int m_thickness; bool m_initCompleted; + bool m_containsMouse = false; Qt::Alignment m_alignment; QPointer m_panelConfigView; ShellCorona *m_corona;