client: Synthesize enter/leave event for popup in xdg-shell - 2

This amends 179d0d34fa6b7d8d90ea766ac146c4b6485f3803.

We can't depend on QGuiApplication::topLevelAt(). For security
reason, Wayland doesn't provide global position for top level
windows in most cases.

We just synthesize enter/leave event for popup between it and the
parent.

Task-number: QTBUG-100148
Task-number: QTBUG-113404
Pick-to: 6.7 6.5 6.2 5.15
Change-Id: I9de1d413cdbc43486c1a110df4517750983e4fda
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Liang Qi 2024-04-22 11:30:17 +02:00
parent d3ea4de423
commit f53c249d06

View File

@ -252,7 +252,9 @@ QWaylandXdgSurface::Popup::~Popup()
leave = m_xdgSurface->window()->window();
QWindowSystemInterface::handleLeaveEvent(leave);
if (QWindow *enter = QGuiApplication::topLevelAt(QCursor::pos())) {
QWindow *enter = nullptr;
if (m_parentXdgSurface && m_parentXdgSurface->window()) {
enter = m_parentXdgSurface->window()->window();
const auto pos = m_xdgSurface->window()->display()->waylandCursor()->pos();
QWindowSystemInterface::handleEnterEvent(enter, enter->handle()->mapFromGlobal(pos), pos);
}
@ -595,11 +597,7 @@ void QWaylandXdgSurface::setGrabPopup(QWaylandWindow *parent, QWaylandInputDevic
// Synthesize Qt enter/leave events for popup
if (!parent)
return;
QWindow *current = QGuiApplication::topLevelAt(QCursor::pos());
QWindow *leave = parent->window();
if (current != leave)
return;
QWindowSystemInterface::handleLeaveEvent(leave);
QWindow *enter = nullptr;